[Libreoffice-commits] core.git: Branch 'feature/lok_dialog' - 3 commits - include/sfx2 include/vcl sc/source sfx2/source sw/inc sw/source vcl/inc vcl/source

Jan Holesovsky kendy at collabora.com
Fri Nov 24 11:59:33 UTC 2017


 include/sfx2/lokhelper.hxx        |    4 +--
 include/sfx2/viewsh.hxx           |   16 ++++++------
 include/vcl/IDialogRenderable.hxx |   24 ++++++++----------
 include/vcl/dialog.hxx            |    8 ------
 include/vcl/window.hxx            |    8 ++++++
 sc/source/ui/view/gridwin.cxx     |    1 
 sfx2/source/dialog/basedlgs.cxx   |   20 +++++++--------
 sfx2/source/dialog/tabdlg.cxx     |   10 +++----
 sfx2/source/view/lokhelper.cxx    |   12 ++++-----
 sfx2/source/view/viewsh.cxx       |   14 +++++-----
 sw/inc/unotxdoc.hxx               |   12 ++++-----
 sw/source/uibase/uno/unotxdoc.cxx |   24 +++++++++---------
 vcl/inc/window.h                  |    4 +++
 vcl/source/window/dialog.cxx      |   50 +++++++++++++++-----------------------
 vcl/source/window/floatwin.cxx    |    9 ++++++
 vcl/source/window/window.cxx      |   29 ++++++++++++++++++++++
 vcl/source/window/winproc.cxx     |    4 +--
 17 files changed, 139 insertions(+), 110 deletions(-)

New commits:
commit 1f6ead92f501b22e794f140d98a16ad0c4799a05
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Fri Nov 24 12:06:42 2017 +0100

    lokdialogs: Assign the LOK window id only when necessary.
    
    Change-Id: Id48957a8c2bde068f30bb26e66df81972fe38e0f

diff --git a/sfx2/source/dialog/basedlgs.cxx b/sfx2/source/dialog/basedlgs.cxx
index 9d30c8596e33..18d2a395631d 100644
--- a/sfx2/source/dialog/basedlgs.cxx
+++ b/sfx2/source/dialog/basedlgs.cxx
@@ -176,8 +176,8 @@ short SfxModalDialog::Execute()
     SfxViewShell* pViewShell = SfxViewShell::Current();
     if (comphelper::LibreOfficeKit::isActive() && pViewShell)
     {
-        pViewShell->RegisterDlg(GetLOKWindowId(), this);
         SetLOKNotifier(pViewShell);
+        pViewShell->RegisterDlg(GetLOKWindowId(), this);
         const Size aSize = GetOptimalSize();
         std::vector<vcl::LOKPayloadItem> aItems;
         aItems.emplace_back(std::make_pair("size", aSize.toString()));
@@ -248,8 +248,8 @@ void SfxModelessDialog::StateChanged( StateChangedType nStateChange )
         SfxViewShell* pViewShell = SfxViewShell::Current();
         if (comphelper::LibreOfficeKit::isActive() && pViewShell)
         {
-            pViewShell->RegisterDlg(GetLOKWindowId(), this);
             SetLOKNotifier(pViewShell);
+            pViewShell->RegisterDlg(GetLOKWindowId(), this);
             // Below method doesn't really give the exact dimensions,
             // Check GetSizePixel() ?
             const Size aOptimalSize = GetOptimalSize();
diff --git a/sfx2/source/dialog/tabdlg.cxx b/sfx2/source/dialog/tabdlg.cxx
index a12d76a14ae1..7b53bbc32ff3 100644
--- a/sfx2/source/dialog/tabdlg.cxx
+++ b/sfx2/source/dialog/tabdlg.cxx
@@ -521,8 +521,8 @@ short SfxTabDialog::Execute()
     SfxViewShell* pViewShell = SfxViewShell::Current();
     if (comphelper::LibreOfficeKit::isActive() && pViewShell)
     {
-        pViewShell->RegisterDlg(GetLOKWindowId(), this);
         SetLOKNotifier(pViewShell);
+        pViewShell->RegisterDlg(GetLOKWindowId(), this);
         const Size aSize = GetOptimalSize();
         std::vector<vcl::LOKPayloadItem> aItems;
         aItems.emplace_back(std::make_pair("size", aSize.toString()));
diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx
index b6b529cc4256..142712791f4f 100644
--- a/vcl/source/window/window.cxx
+++ b/vcl/source/window/window.cxx
@@ -740,7 +740,7 @@ WindowImpl::WindowImpl( WindowType nType )
     static bool bDoubleBuffer = getenv("VCL_DOUBLEBUFFERING_FORCE_ENABLE");
     mbDoubleBufferingRequested = bDoubleBuffer; // when we are not sure, assume it cannot do double-buffering via RenderContext
     mpLOKNotifier                       = nullptr;
-    mnLOKWindowId                       = mnLastWindowId++;
+    mnLOKWindowId                       = 0;
 }
 
 WindowImpl::~WindowImpl()
@@ -3171,6 +3171,13 @@ void Window::SetComponentInterface( Reference< css::awt::XWindowPeer > const & x
 
 void Window::SetLOKNotifier(const vcl::ILibreOfficeKitNotifier* pNotifier)
 {
+    // don't allow setting this twice
+    assert(mpWindowImpl->mpLOKNotifier == nullptr);
+    assert(pNotifier);
+
+    // assign the LOK window id
+    mpWindowImpl->mnLOKWindowId = WindowImpl::mnLastWindowId++;
+
     mpWindowImpl->mpLOKNotifier = pNotifier;
 }
 
@@ -3181,6 +3188,8 @@ const vcl::ILibreOfficeKitNotifier* Window::GetLOKNotifier() const
 
 vcl::LOKWindowId Window::GetLOKWindowId() const
 {
+    assert(mpWindowImpl->mnLOKWindowId > 0);
+
     return mpWindowImpl->mnLOKWindowId;
 }
 
commit df908218ba43faaea53de05eeaa5ded7ed69e5e6
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Fri Nov 24 11:21:13 2017 +0100

    lokdialog: Make the Autofilter popup notify about its creation.
    
    Change-Id: Ib4062fa887b44eb1368205a414f4ac162f648c5c

diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index 3db50f96447b..21b320c5b91a 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -627,6 +627,7 @@ void ScGridWindow::LaunchAutoFilterMenu(SCCOL nCol, SCROW nRow)
 
     mpAutoFilterPopup.disposeAndClear();
     mpAutoFilterPopup.reset(VclPtr<ScCheckListMenuWindow>::Create(this, pDoc));
+    mpAutoFilterPopup->SetLOKNotifier(SfxViewShell::Current());
     mpAutoFilterPopup->setOKAction(new AutoFilterAction(this, Normal));
     mpAutoFilterPopup->setPopupEndAction(
         new AutoFilterPopupEndAction(this, ScAddress(nCol, nRow, nTab)));
diff --git a/vcl/source/window/floatwin.cxx b/vcl/source/window/floatwin.cxx
index 936f55d401e3..b00da3a18a77 100644
--- a/vcl/source/window/floatwin.cxx
+++ b/vcl/source/window/floatwin.cxx
@@ -720,6 +720,13 @@ void FloatingWindow::StartPopupMode( const tools::Rectangle& rRect, FloatWinPopu
         GrabFocus();
     }
     Show( true, ShowFlags::NoActivate );
+
+    if (const vcl::ILibreOfficeKitNotifier* pNotifier = GetLOKNotifier())
+    {
+        std::vector<vcl::LOKPayloadItem> aItems;
+        aItems.emplace_back(std::make_pair("size", rRect.GetSize().toString()));
+        pNotifier->notifyDialog(GetLOKWindowId(), "created", aItems);
+    }
 }
 
 void FloatingWindow::StartPopupMode( ToolBox* pBox, FloatWinPopupFlags nFlags )
commit 4de3a635e79fa9adbc66aef72be2cde3db0d2d81
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Fri Nov 24 10:20:47 2017 +0100

    lokdialog: Move the Notifier down to vcl::Window.
    
    We need to tunnel more than just dialogs, so this is the 1st step to get the
    Autofilter popup rendered.
    
    Change-Id: I6523a39ddc7a6eb2a204e48ab364130a5822f548

diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
index 24e59d097393..170d65a794d0 100644
--- a/include/sfx2/lokhelper.hxx
+++ b/include/sfx2/lokhelper.hxx
@@ -42,11 +42,11 @@ public:
     /// Same as notifyOtherViews(), but works on a selected "other" view, not on all of them.
     static void notifyOtherView(SfxViewShell* pThisView, SfxViewShell const* pOtherView, int nType, const OString& rKey, const OString& rPayload);
     /// Emits a LOK_CALLBACK_DIALOG
-    static void notifyDialog(vcl::DialogID nDialogId,
+    static void notifyDialog(vcl::LOKWindowId nDialogId,
                              const OUString& rAction,
                              const std::vector<vcl::LOKPayloadItem>& rPayload = std::vector<vcl::LOKPayloadItem>());
     /// Emits a LOK_CALLBACK_DIALOG_CHILD
-    static void notifyDialogChild(vcl::DialogID nDialogId, const OUString& rAction, const Point& rPos);
+    static void notifyDialogChild(vcl::LOKWindowId nDialogId, const OUString& rAction, const Point& rPos);
     /// Emits a LOK_CALLBACK_INVALIDATE_TILES, but tweaks it according to setOptionalFeatures() if needed.
     static void notifyInvalidation(SfxViewShell const* pThisView, const OString& rPayload);
     /// A special value to signify 'infinity'.
diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx
index e91148e7b8fa..3068fb15e2cd 100644
--- a/include/sfx2/viewsh.hxx
+++ b/include/sfx2/viewsh.hxx
@@ -142,7 +142,7 @@ template<class T> bool checkSfxViewShell(const SfxViewShell* pShell)
     return dynamic_cast<const T*>(pShell) != nullptr;
 }
 
-class SFX2_DLLPUBLIC SfxViewShell: public SfxShell, public SfxListener, public OutlinerViewShell, public vcl::IDialogNotifier
+class SFX2_DLLPUBLIC SfxViewShell: public SfxShell, public SfxListener, public OutlinerViewShell, public vcl::ILibreOfficeKitNotifier
 {
 #ifdef INCLUDED_SFX2_VIEWSH_HXX
 friend class SfxViewFrame;
@@ -155,7 +155,7 @@ friend class SfxPrinterController;
     VclPtr<vcl::Window>         pWindow;
     bool                        bNoNewWindow;
     bool                        mbPrinterSettingsModified;
-    std::vector<std::pair<vcl::DialogID, VclPtr<Dialog> > > maOpenedDialogs;
+    std::vector<std::pair<vcl::LOKWindowId, VclPtr<Dialog> > > maOpenedDialogs;
 
 protected:
     virtual void                Activate(bool IsMDIActivate) override;
@@ -224,13 +224,13 @@ public:
     virtual       SfxShell*     GetFormShell()       { return nullptr; };
     virtual const SfxShell*     GetFormShell() const { return nullptr; };
 
-    void                        RegisterDlg(vcl::DialogID nDialogId, VclPtr<Dialog> pDlg);
-    VclPtr<Dialog>              GetOpenedDlg(vcl::DialogID nDialogId);
-    void                        UnregisterDlg(vcl::DialogID nDialogId);
+    void                        RegisterDlg(vcl::LOKWindowId nDialogId, VclPtr<Dialog> pDlg);
+    VclPtr<Dialog>              GetOpenedDlg(vcl::LOKWindowId nDialogId);
+    void                        UnregisterDlg(vcl::LOKWindowId nDialogId);
 
-    // IDialogNotifier
-    virtual void                notifyDialog(const vcl::DialogID& rDialogId, const OUString& rAction, const std::vector<vcl::LOKPayloadItem>& rPayload = std::vector<vcl::LOKPayloadItem>()) override;
-    virtual void                notifyDialogChild(const vcl::DialogID& rDialogId, const OUString& rAction, const Point& rPos) override;
+    // ILibreOfficeKitNotifier
+    virtual void                notifyDialog(const vcl::LOKWindowId& rDialogId, const OUString& rAction, const std::vector<vcl::LOKPayloadItem>& rPayload = std::vector<vcl::LOKPayloadItem>()) const override;
+    virtual void                notifyDialogChild(const vcl::LOKWindowId& rDialogId, const OUString& rAction, const Point& rPos) const override;
 
     // Focus, KeyInput, Cursor
     virtual void                ShowCursor( bool bOn = true );
diff --git a/include/vcl/IDialogRenderable.hxx b/include/vcl/IDialogRenderable.hxx
index f606782692e3..20515c86d2a6 100644
--- a/include/vcl/IDialogRenderable.hxx
+++ b/include/vcl/IDialogRenderable.hxx
@@ -23,41 +23,39 @@ namespace vcl
 
 typedef std::pair<const OString, const OString> LOKPayloadItem;
 
-typedef sal_uInt32 DialogID;
-
 class VCL_DLLPUBLIC IDialogRenderable
 {
 public:
     virtual ~IDialogRenderable();
 
-    virtual void paintDialog(const DialogID& rDialogID, VirtualDevice &rDevice) = 0;
+    virtual void paintDialog(const LOKWindowId& rLOKWindowId, VirtualDevice &rDevice) = 0;
 
-    virtual void getDialogInfo(const DialogID& rDialogID, OUString& rDialogTitle, int& rWidth, int& rHeight) = 0;
+    virtual void getDialogInfo(const LOKWindowId& rLOKWindowId, OUString& rDialogTitle, int& rWidth, int& rHeight) = 0;
 
-    virtual void paintActiveFloatingWindow(const DialogID& rDialogID, VirtualDevice &rDevice,
+    virtual void paintActiveFloatingWindow(const LOKWindowId& rLOKWindowId, VirtualDevice &rDevice,
                                            int& nOutputWidth, int& nOutputHeight) = 0;
 
-    virtual void postDialogKeyEvent(const DialogID& rDialogID, int nType,
+    virtual void postDialogKeyEvent(const LOKWindowId& rLOKWindowId, int nType,
                                     int nCharCode, int nKeyCode) = 0;
 
-    virtual void postDialogMouseEvent(const DialogID& rDialogID, int nType, int nX, int nY,
+    virtual void postDialogMouseEvent(const LOKWindowId& rLOKWindowId, int nType, int nX, int nY,
                                       int nCount, int nButtons, int nModifier) = 0;
 
-    virtual void postDialogChildMouseEvent(const DialogID& rDialogID, int nType, int nX, int nY,
+    virtual void postDialogChildMouseEvent(const LOKWindowId& rLOKWindowId, int nType, int nX, int nY,
                                            int nCount, int nButtons, int nModifier) = 0;
 };
 
-class VCL_DLLPUBLIC IDialogNotifier
+class VCL_DLLPUBLIC ILibreOfficeKitNotifier
 {
 public:
-    virtual ~IDialogNotifier() {}
+    virtual ~ILibreOfficeKitNotifier() {}
 
     // Callbacks
-    virtual void notifyDialog(const DialogID& rDialogID,
+    virtual void notifyDialog(const LOKWindowId& rLOKWindowId,
                               const OUString& rAction,
-                              const std::vector<LOKPayloadItem>& rPayload = std::vector<LOKPayloadItem>()) = 0;
+                              const std::vector<LOKPayloadItem>& rPayload = std::vector<LOKPayloadItem>()) const = 0;
 
-    virtual void notifyDialogChild(const DialogID& rDialogID, const OUString& rAction, const Point& rPos) = 0;
+    virtual void notifyDialogChild(const LOKWindowId& rLOKWindowId, const OUString& rAction, const Point& rPos) const = 0;
 };
 
 } // namespace vcl
diff --git a/include/vcl/dialog.hxx b/include/vcl/dialog.hxx
index e4d9f88f6d83..4347917b7675 100644
--- a/include/vcl/dialog.hxx
+++ b/include/vcl/dialog.hxx
@@ -57,10 +57,6 @@ private:
     VclPtr<VclButtonBox> mpActionArea;
     VclPtr<VclBox>       mpContentArea;
 
-    vcl::IDialogNotifier*  mpDialogNotifier; // to emit LOK callbacks
-
-    static vcl::DialogID   mnLastDialogId;
-
     SAL_DLLPRIVATE void    ImplInitDialogData();
     SAL_DLLPRIVATE void    ImplInitSettings();
     SAL_DLLPRIVATE VclPtr<vcl::Window> AddBorderWindow(vcl::Window* pParent, WinBits nBits);
@@ -75,10 +71,6 @@ private:
 protected:
     using Window::ImplInit;
     SAL_DLLPRIVATE void    ImplInit( vcl::Window* pParent, WinBits nStyle, InitFlag eFlag = InitFlag::Default );
-    /// Dialog ID (used for LOK)
-    vcl::DialogID          maID;
-    /// Necessary to register dialog notifier instance to emit LOK callbacks
-    void                   registerDialogNotifier(vcl::IDialogNotifier* pDialogNotifier);
 
 public:
     SAL_DLLPRIVATE bool    IsInClose() const { return mbInClose; }
diff --git a/include/vcl/window.hxx b/include/vcl/window.hxx
index bc51c1f8de3d..3a8d8fd341a0 100644
--- a/include/vcl/window.hxx
+++ b/include/vcl/window.hxx
@@ -430,6 +430,7 @@ const char* ImplDbgCheckWindow( const void* pObj );
 
 namespace vcl { class Window; }
 namespace vcl { class Cursor; }
+namespace vcl { class ILibreOfficeKitNotifier; }
 class Dialog;
 class WindowImpl;
 class PaintHelper;
@@ -488,6 +489,8 @@ public:
                                         Color const * pPaintColor = nullptr);
 };
 
+typedef sal_uInt32 LOKWindowId;
+
 class VCL_DLLPUBLIC Window : public ::OutputDevice
 {
     friend class ::vcl::Cursor;
@@ -1203,6 +1206,11 @@ public:
 
     void                        SetComponentInterface( css::uno::Reference< css::awt::XWindowPeer > const & xIFace );
 
+    /// Interface to register for dialog tunneling.
+    void                                SetLOKNotifier(const vcl::ILibreOfficeKitNotifier* pNotifier);
+    const vcl::ILibreOfficeKitNotifier* GetLOKNotifier() const;
+    vcl::LOKWindowId                    GetLOKWindowId() const;
+
     /** @name Accessibility
      */
     ///@{
diff --git a/sfx2/source/dialog/basedlgs.cxx b/sfx2/source/dialog/basedlgs.cxx
index 73a110038d95..9d30c8596e33 100644
--- a/sfx2/source/dialog/basedlgs.cxx
+++ b/sfx2/source/dialog/basedlgs.cxx
@@ -164,8 +164,8 @@ void SfxModalDialog::dispose()
     SfxViewShell* pViewShell = SfxViewShell::Current();
     if (comphelper::LibreOfficeKit::isActive() && pViewShell)
     {
-        pViewShell->notifyDialog(maID, "close");
-        pViewShell->UnregisterDlg(maID);
+        pViewShell->notifyDialog(GetLOKWindowId(), "close");
+        pViewShell->UnregisterDlg(GetLOKWindowId());
     }
 
     ModalDialog::dispose();
@@ -176,12 +176,12 @@ short SfxModalDialog::Execute()
     SfxViewShell* pViewShell = SfxViewShell::Current();
     if (comphelper::LibreOfficeKit::isActive() && pViewShell)
     {
-        pViewShell->RegisterDlg(maID, this);
-        registerDialogNotifier(static_cast<vcl::IDialogNotifier*>(pViewShell));
+        pViewShell->RegisterDlg(GetLOKWindowId(), this);
+        SetLOKNotifier(pViewShell);
         const Size aSize = GetOptimalSize();
         std::vector<vcl::LOKPayloadItem> aItems;
         aItems.emplace_back(std::make_pair("size", aSize.toString()));
-        pViewShell->notifyDialog(maID, "created", aItems);
+        pViewShell->notifyDialog(GetLOKWindowId(), "created", aItems);
     }
 
     return ModalDialog::Execute();
@@ -248,14 +248,14 @@ void SfxModelessDialog::StateChanged( StateChangedType nStateChange )
         SfxViewShell* pViewShell = SfxViewShell::Current();
         if (comphelper::LibreOfficeKit::isActive() && pViewShell)
         {
-            pViewShell->RegisterDlg(maID, this);
-            registerDialogNotifier(static_cast<vcl::IDialogNotifier*>(pViewShell));
+            pViewShell->RegisterDlg(GetLOKWindowId(), this);
+            SetLOKNotifier(pViewShell);
             // Below method doesn't really give the exact dimensions,
             // Check GetSizePixel() ?
             const Size aOptimalSize = GetOptimalSize();
             std::vector<vcl::LOKPayloadItem> aItems;
             aItems.emplace_back(std::make_pair("size", aOptimalSize.toString()));
-            pViewShell->notifyDialog(maID, "created", aItems);
+            pViewShell->notifyDialog(GetLOKWindowId(), "created", aItems);
         }
 
         pImpl->bConstructed = true;
@@ -393,8 +393,8 @@ void SfxModelessDialog::dispose()
     SfxViewShell* pViewShell = SfxViewShell::Current();
     if (comphelper::LibreOfficeKit::isActive() && pViewShell)
     {
-        pViewShell->notifyDialog(maID, "close");
-        pViewShell->UnregisterDlg(maID);
+        pViewShell->notifyDialog(GetLOKWindowId(), "close");
+        pViewShell->UnregisterDlg(GetLOKWindowId());
     }
 
     ModelessDialog::dispose();
diff --git a/sfx2/source/dialog/tabdlg.cxx b/sfx2/source/dialog/tabdlg.cxx
index 17f64d51a063..a12d76a14ae1 100644
--- a/sfx2/source/dialog/tabdlg.cxx
+++ b/sfx2/source/dialog/tabdlg.cxx
@@ -406,8 +406,8 @@ void SfxTabDialog::dispose()
     SfxViewShell* pViewShell = SfxViewShell::Current();
     if (comphelper::LibreOfficeKit::isActive() && pViewShell)
     {
-        pViewShell->notifyDialog(maID, "close");
-        pViewShell->UnregisterDlg(maID);
+        pViewShell->notifyDialog(GetLOKWindowId(), "close");
+        pViewShell->UnregisterDlg(GetLOKWindowId());
     }
 
     TabDialog::dispose();
@@ -521,12 +521,12 @@ short SfxTabDialog::Execute()
     SfxViewShell* pViewShell = SfxViewShell::Current();
     if (comphelper::LibreOfficeKit::isActive() && pViewShell)
     {
-        pViewShell->RegisterDlg(maID, this);
-        registerDialogNotifier(static_cast<vcl::IDialogNotifier*>(pViewShell));
+        pViewShell->RegisterDlg(GetLOKWindowId(), this);
+        SetLOKNotifier(pViewShell);
         const Size aSize = GetOptimalSize();
         std::vector<vcl::LOKPayloadItem> aItems;
         aItems.emplace_back(std::make_pair("size", aSize.toString()));
-        pViewShell->notifyDialog(maID, "created", aItems);
+        pViewShell->notifyDialog(GetLOKWindowId(), "created", aItems);
     }
 
     return TabDialog::Execute();
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index 9af028916b69..cfd9041ab421 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -144,15 +144,15 @@ void SfxLokHelper::notifyOtherViews(SfxViewShell* pThisView, int nType, const OS
     }
 }
 
-void SfxLokHelper::notifyDialog(vcl::DialogID nDialogID,
+void SfxLokHelper::notifyDialog(vcl::LOKWindowId nLOKWindowId,
                                 const OUString& rAction,
                                 const std::vector<vcl::LOKPayloadItem>& rPayload)
 {
-    if (SfxLokHelper::getViewsCount() <= 0 || nDialogID == 0)
+    if (SfxLokHelper::getViewsCount() <= 0 || nLOKWindowId == 0)
         return;
 
     SfxViewShell* pViewShell = SfxViewShell::GetFirst();
-    OString aPayload = OString("{ \"dialogId\": \"") + OString::number(nDialogID) + OString("\"");
+    OString aPayload = OString("{ \"dialogId\": \"") + OString::number(nLOKWindowId) + OString("\"");
     aPayload += OString(", \"action\": \"") + OUStringToOString(rAction, RTL_TEXTENCODING_UTF8).getStr() + OString("\"");
 
     for (const auto& rItem: rPayload)
@@ -172,13 +172,13 @@ void SfxLokHelper::notifyDialog(vcl::DialogID nDialogID,
     }
 }
 
-void SfxLokHelper::notifyDialogChild(vcl::DialogID nDialogID, const OUString& rAction, const Point& rPos)
+void SfxLokHelper::notifyDialogChild(vcl::LOKWindowId nLOKWindowId, const OUString& rAction, const Point& rPos)
 {
-    if (SfxLokHelper::getViewsCount() <= 0 || nDialogID == 0)
+    if (SfxLokHelper::getViewsCount() <= 0 || nLOKWindowId == 0)
         return;
 
     SfxViewShell* pViewShell = SfxViewShell::GetFirst();
-    const OString aPayload = OString("{ \"dialogId\": \"") + OString::number(nDialogID) +
+    const OString aPayload = OString("{ \"dialogId\": \"") + OString::number(nLOKWindowId) +
         OString("\", \"action\": \"") + OUStringToOString(rAction, RTL_TEXTENCODING_UTF8).getStr() +
         OString("\", \"position\": \"") + OString::number(rPos.getX()) + OString(", ") + OString::number(rPos.getY()) +
         + "\" }";
diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx
index 986a640d1625..778a9d9f68b7 100644
--- a/sfx2/source/view/viewsh.cxx
+++ b/sfx2/source/view/viewsh.cxx
@@ -1948,27 +1948,27 @@ Reference< view::XRenderable > SfxViewShell::GetRenderable()
     return xRender;
 }
 
-void SfxViewShell::notifyDialog(const vcl::DialogID& rDialogId, const OUString& rAction, const std::vector<vcl::LOKPayloadItem>& rPayload)
+void SfxViewShell::notifyDialog(const vcl::LOKWindowId& rDialogId, const OUString& rAction, const std::vector<vcl::LOKPayloadItem>& rPayload) const
 {
     SfxLokHelper::notifyDialog(rDialogId, rAction, rPayload);
 }
 
-void SfxViewShell::notifyDialogChild(const vcl::DialogID& rDialogId, const OUString& rAction, const Point& rPos)
+void SfxViewShell::notifyDialogChild(const vcl::LOKWindowId& rDialogId, const OUString& rAction, const Point& rPos) const
 {
     SfxLokHelper::notifyDialogChild(rDialogId, rAction, rPos);
 }
 
-void SfxViewShell::RegisterDlg(vcl::DialogID nDialogId, VclPtr<Dialog> pDlg)
+void SfxViewShell::RegisterDlg(vcl::LOKWindowId nDialogId, VclPtr<Dialog> pDlg)
 {
     if (pDlg)
         maOpenedDialogs.push_back(std::make_pair(nDialogId, pDlg));
 }
 
-VclPtr<Dialog> SfxViewShell::GetOpenedDlg(vcl::DialogID nDialogId)
+VclPtr<Dialog> SfxViewShell::GetOpenedDlg(vcl::LOKWindowId nDialogId)
 {
     const auto it = std::find_if(maOpenedDialogs.begin(),
                                  maOpenedDialogs.end(),
-                                 [&nDialogId](const std::pair<vcl::DialogID, VclPtr<Dialog>> aItem) {
+                                 [&nDialogId](const std::pair<vcl::LOKWindowId, VclPtr<Dialog>> aItem) {
                                      return nDialogId == aItem.first;
                                  });
 
@@ -1980,11 +1980,11 @@ VclPtr<Dialog> SfxViewShell::GetOpenedDlg(vcl::DialogID nDialogId)
     return ret;
 }
 
-void SfxViewShell::UnregisterDlg(vcl::DialogID nDialogId)
+void SfxViewShell::UnregisterDlg(vcl::LOKWindowId nDialogId)
 {
     maOpenedDialogs.erase(std::remove_if(maOpenedDialogs.begin(),
                                          maOpenedDialogs.end(),
-                                         [&nDialogId](const std::pair<vcl::DialogID, VclPtr<Dialog>> aItem) {
+                                         [&nDialogId](const std::pair<vcl::LOKWindowId, VclPtr<Dialog>> aItem) {
                                              return aItem.first == nDialogId;
                                          }));
 }
diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx
index 81b9165cfa15..85c1d4a4ead6 100644
--- a/sw/inc/unotxdoc.hxx
+++ b/sw/inc/unotxdoc.hxx
@@ -431,16 +431,16 @@ public:
     /// @see vcl::ITiledRenderable::getPostIts().
     OUString getPostIts() override;
 
-    void paintDialog(const vcl::DialogID& rDialogID, VirtualDevice& rDevice) override;
-    void getDialogInfo(const vcl::DialogID& rDialogID, OUString& rDialogTitle, int& rWidth, int& rHeight) override;
-    void paintActiveFloatingWindow(const vcl::DialogID& rDialogID, VirtualDevice& rDevice, int& nWidth, int& nHeight) override;
-    void postDialogKeyEvent(const vcl::DialogID& rDialogID, int nType,
+    void paintDialog(const vcl::LOKWindowId& rLOKWindowId, VirtualDevice& rDevice) override;
+    void getDialogInfo(const vcl::LOKWindowId& rLOKWindowId, OUString& rDialogTitle, int& rWidth, int& rHeight) override;
+    void paintActiveFloatingWindow(const vcl::LOKWindowId& rLOKWindowId, VirtualDevice& rDevice, int& nWidth, int& nHeight) override;
+    void postDialogKeyEvent(const vcl::LOKWindowId& rLOKWindowId, int nType,
                             int nCharCode, int nKeyCode) override;
 
-    void postDialogMouseEvent(const vcl::DialogID& rDialogID, int nType, int nX, int nY,
+    void postDialogMouseEvent(const vcl::LOKWindowId& rLOKWindowId, int nType, int nX, int nY,
                               int nCount, int nButtons, int nModifier) override;
 
-    void postDialogChildMouseEvent(const vcl::DialogID& rDialogID, int nType, int nX, int nY,
+    void postDialogChildMouseEvent(const vcl::LOKWindowId& rLOKWindowId, int nType, int nX, int nY,
                                    int nCount, int nButtons, int nModifier) override;
 
     // css::tiledrendering::XTiledRenderable
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index be27093a9876..b593434431d8 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3639,18 +3639,18 @@ void SAL_CALL SwXTextDocument::paintTile( const ::css::uno::Any& Parent, ::sal_I
     #endif
 }
 
-void SwXTextDocument::paintDialog(const vcl::DialogID& rDialogID, VirtualDevice& rDevice)
+void SwXTextDocument::paintDialog(const vcl::LOKWindowId& rLOKWindowId, VirtualDevice& rDevice)
 {
     SfxViewShell* pViewShell = SfxViewShell::Current();
-    VclPtr<Dialog> pDlg = pViewShell->GetOpenedDlg(rDialogID);
+    VclPtr<Dialog> pDlg = pViewShell->GetOpenedDlg(rLOKWindowId);
     if (pDlg)
         pDlg->paintDialog(rDevice);
 }
 
-void SwXTextDocument::getDialogInfo(const vcl::DialogID& rDialogID, OUString& rDialogTitle, int& rWidth, int& rHeight)
+void SwXTextDocument::getDialogInfo(const vcl::LOKWindowId& rLOKWindowId, OUString& rDialogTitle, int& rWidth, int& rHeight)
 {
     SfxViewShell* pViewShell = SfxViewShell::Current();
-    VclPtr<Dialog> pDlg = pViewShell->GetOpenedDlg(rDialogID);
+    VclPtr<Dialog> pDlg = pViewShell->GetOpenedDlg(rLOKWindowId);
     if (pDlg)
     {
         rDialogTitle = pDlg->GetText();
@@ -3660,12 +3660,12 @@ void SwXTextDocument::getDialogInfo(const vcl::DialogID& rDialogID, OUString& rD
     }
 }
 
-void SwXTextDocument::postDialogKeyEvent(const vcl::DialogID& rDialogID, int nType, int nCharCode, int nKeyCode)
+void SwXTextDocument::postDialogKeyEvent(const vcl::LOKWindowId& rLOKWindowId, int nType, int nCharCode, int nKeyCode)
 {
     SolarMutexGuard aGuard;
 
     SfxViewShell* pViewShell = SfxViewShell::Current();
-    VclPtr<Dialog> pDialog = pViewShell->GetOpenedDlg(rDialogID);
+    VclPtr<Dialog> pDialog = pViewShell->GetOpenedDlg(rLOKWindowId);
     if (pDialog)
     {
         KeyEvent aEvent(nCharCode, nKeyCode, 0);
@@ -3685,13 +3685,13 @@ void SwXTextDocument::postDialogKeyEvent(const vcl::DialogID& rDialogID, int nTy
     }
 }
 
-void SwXTextDocument::postDialogMouseEvent(const vcl::DialogID& rDialogID, int nType, int nX, int nY,
+void SwXTextDocument::postDialogMouseEvent(const vcl::LOKWindowId& rLOKWindowId, int nType, int nX, int nY,
                                            int nCount, int nButtons, int nModifier)
 {
     SolarMutexGuard aGuard;
 
     SfxViewShell* pViewShell = SfxViewShell::Current();
-    VclPtr<Dialog> pDialog = pViewShell->GetOpenedDlg(rDialogID);
+    VclPtr<Dialog> pDialog = pViewShell->GetOpenedDlg(rLOKWindowId);
     if (pDialog)
     {
         Point aPos(nX , nY);
@@ -3716,13 +3716,13 @@ void SwXTextDocument::postDialogMouseEvent(const vcl::DialogID& rDialogID, int n
 }
 
 
-void SwXTextDocument::postDialogChildMouseEvent(const vcl::DialogID& rDialogID, int nType, int nX, int nY,
+void SwXTextDocument::postDialogChildMouseEvent(const vcl::LOKWindowId& rLOKWindowId, int nType, int nX, int nY,
                                                 int nCount, int nButtons, int nModifier)
 {
     SolarMutexGuard aGuard;
 
     SfxViewShell* pViewShell = SfxViewShell::Current();
-    VclPtr<Dialog> pDialog = pViewShell->GetOpenedDlg(rDialogID);
+    VclPtr<Dialog> pDialog = pViewShell->GetOpenedDlg(rLOKWindowId);
     if (pDialog)
     {
         Point aPos(nX , nY);
@@ -3746,10 +3746,10 @@ void SwXTextDocument::postDialogChildMouseEvent(const vcl::DialogID& rDialogID,
     }
 }
 
-void SwXTextDocument::paintActiveFloatingWindow(const vcl::DialogID& rDialogID, VirtualDevice& rDevice, int& nWidth, int& nHeight)
+void SwXTextDocument::paintActiveFloatingWindow(const vcl::LOKWindowId& rLOKWindowId, VirtualDevice& rDevice, int& nWidth, int& nHeight)
 {
     SfxViewShell* pViewShell = SfxViewShell::Current();
-    VclPtr<Dialog> pDialog = pViewShell->GetOpenedDlg(rDialogID);
+    VclPtr<Dialog> pDialog = pViewShell->GetOpenedDlg(rLOKWindowId);
     if (pDialog)
     {
         const Size aSize = pDialog->PaintActiveFloatingWindow(rDevice);
diff --git a/vcl/inc/window.h b/vcl/inc/window.h
index d9108e71cf1f..7b2222b3718b 100644
--- a/vcl/inc/window.h
+++ b/vcl/inc/window.h
@@ -376,6 +376,10 @@ public:
                         mbDoubleBufferingRequested:1;
 
     css::uno::Reference< css::uno::XInterface > mxDNDListenerContainer;
+
+    const vcl::ILibreOfficeKitNotifier* mpLOKNotifier; ///< To emit the LOK callbacks eg. for dialog tunneling.
+    static vcl::LOKWindowId mnLastWindowId; ///< To be able to have an unique ID for each dealog / window we tunnel.
+    vcl::LOKWindowId mnLOKWindowId; ///< ID of this specific window.
 };
 
 /// Sets up the buffer to have settings matching the window, and restores the original state in the dtor.
diff --git a/vcl/source/window/dialog.cxx b/vcl/source/window/dialog.cxx
index 017a0015fee1..3f1997aca9e9 100644
--- a/vcl/source/window/dialog.cxx
+++ b/vcl/source/window/dialog.cxx
@@ -53,6 +53,7 @@
 #include <vcl/uitest/uiobject.hxx>
 #include <vcl/uitest/logger.hxx>
 #include <vcl/virdev.hxx>
+#include <vcl/IDialogRenderable.hxx>
 #include <salframe.hxx>
 
 #include <iostream>
@@ -346,8 +347,6 @@ struct DialogImpl
 
 void Dialog::ImplInitDialogData()
 {
-    maID                    = mnLastDialogId++;
-    mpDialogNotifier        = nullptr;
     mpWindowImpl->mbDialog  = true;
     mpPrevExecuteDlg        = nullptr;
     mbInExecute             = false;
@@ -491,8 +490,6 @@ void Dialog::ImplInitSettings()
         SetBackground(GetSettings().GetStyleSettings().GetDialogColor());
 }
 
-vcl::DialogID Dialog::mnLastDialogId = 1;
-
 Dialog::Dialog( WindowType nType )
     : SystemWindow( nType )
     , mbForceBorderWindow(false)
@@ -872,14 +869,6 @@ bool Dialog::selectPageByUIXMLDescription(const OString& /*rUIXMLDescription*/)
     return true;
 }
 
-void Dialog::registerDialogNotifier(vcl::IDialogNotifier* pDialogNotifier)
-{
-    if (pDialogNotifier && !mpDialogNotifier)
-    {
-        mpDialogNotifier = pDialogNotifier;
-    }
-}
-
 void Dialog::paintDialog(VirtualDevice& rDevice)
 {
     setDeferredProperties();
@@ -952,29 +941,28 @@ void Dialog::LogicMouseMoveChild(const MouseEvent& rMouseEvent)
 
 void Dialog::InvalidateFloatingWindow(const Point& rPos)
 {
-    if (comphelper::LibreOfficeKit::isActive() && mpDialogNotifier && maID != 0)
-    {
-        mpDialogNotifier->notifyDialogChild(maID, "invalidate", rPos);
-    }
+    if (const vcl::ILibreOfficeKitNotifier* pNotifier = GetLOKNotifier())
+        pNotifier->notifyDialogChild(GetLOKWindowId(), "invalidate", rPos);
 }
 
 void Dialog::CloseFloatingWindow()
 {
-    if (comphelper::LibreOfficeKit::isActive() && mpDialogNotifier && maID != 0)
-    {
-        mpDialogNotifier->notifyDialogChild(maID, "close", Point(0, 0));
-    }
+    if (const vcl::ILibreOfficeKitNotifier* pNotifier = GetLOKNotifier())
+        pNotifier->notifyDialogChild(GetLOKWindowId(), "close", Point(0, 0));
 }
 
 void Dialog::LogicInvalidate(const tools::Rectangle* pRectangle)
 {
-    if (!comphelper::LibreOfficeKit::isDialogPainting() && mpDialogNotifier && maID != 0)
+    if (comphelper::LibreOfficeKit::isDialogPainting())
+        return;
+
+    if (const vcl::ILibreOfficeKitNotifier* pNotifier = GetLOKNotifier())
     {
         std::vector<vcl::LOKPayloadItem> aPayload;
         if (pRectangle)
             aPayload.push_back(std::make_pair(OString("rectangle"), pRectangle->toString()));
 
-        mpDialogNotifier->notifyDialog(maID, "invalidate", aPayload);
+        pNotifier->notifyDialog(GetLOKWindowId(), "invalidate", aPayload);
     }
 }
 
@@ -1020,10 +1008,11 @@ void Dialog::LOKCursor(const OUString& rAction, const std::vector<vcl::LOKPayloa
 {
     assert(comphelper::LibreOfficeKit::isActive());
 
-    if (!comphelper::LibreOfficeKit::isDialogPainting() && mpDialogNotifier && maID != 0)
-    {
-        mpDialogNotifier->notifyDialog(maID, rAction, rPayload);
-    }
+    if (comphelper::LibreOfficeKit::isDialogPainting())
+        return;
+
+    if (const vcl::ILibreOfficeKitNotifier* pNotifier = GetLOKNotifier())
+        pNotifier->notifyDialog(GetLOKWindowId(), rAction, rPayload);
 }
 
 void Dialog::ensureRepaint()
@@ -1340,11 +1329,12 @@ void Dialog::Resize()
 {
     SystemWindow::Resize();
 
+    if (comphelper::LibreOfficeKit::isDialogPainting())
+        return;
+
     // inform LOK clients
-    if (!comphelper::LibreOfficeKit::isDialogPainting() && mpDialogNotifier && maID != 0)
-    {
-        mpDialogNotifier->notifyDialog(maID, "invalidate");
-    }
+    if (const vcl::ILibreOfficeKitNotifier* pNotifier = GetLOKNotifier())
+        pNotifier->notifyDialog(GetLOKWindowId(), "invalidate");
 }
 
 bool Dialog::set_property(const OString &rKey, const OUString &rValue)
diff --git a/vcl/source/window/floatwin.cxx b/vcl/source/window/floatwin.cxx
index 57c5f7ec26a8..936f55d401e3 100644
--- a/vcl/source/window/floatwin.cxx
+++ b/vcl/source/window/floatwin.cxx
@@ -29,7 +29,7 @@
 #include <vcl/toolbox.hxx>
 #include <vcl/floatwin.hxx>
 #include <vcl/settings.hxx>
-
+#include <vcl/IDialogRenderable.hxx>
 
 class FloatingWindow::ImplData
 {
diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx
index 5083f418b2c2..b6b529cc4256 100644
--- a/vcl/source/window/window.cxx
+++ b/vcl/source/window/window.cxx
@@ -42,6 +42,7 @@
 #include <vcl/virdev.hxx>
 #include <vcl/settings.hxx>
 #include <vcl/sysdata.hxx>
+#include <vcl/IDialogRenderable.hxx>
 
 #include <vcl/uitest/uiobject.hxx>
 #include <vcl/uitest/uitest.hxx>
@@ -590,6 +591,8 @@ Window::~Window()
 
 } /* namespace vcl */
 
+vcl::LOKWindowId WindowImpl::mnLastWindowId = 1;
+
 WindowImpl::WindowImpl( WindowType nType )
 {
     maZoom                              = Fraction( 1, 1 );
@@ -736,6 +739,8 @@ WindowImpl::WindowImpl( WindowType nType )
     mbNonHomogeneous                    = false;
     static bool bDoubleBuffer = getenv("VCL_DOUBLEBUFFERING_FORCE_ENABLE");
     mbDoubleBufferingRequested = bDoubleBuffer; // when we are not sure, assume it cannot do double-buffering via RenderContext
+    mpLOKNotifier                       = nullptr;
+    mnLOKWindowId                       = mnLastWindowId++;
 }
 
 WindowImpl::~WindowImpl()
@@ -3164,6 +3169,21 @@ void Window::SetComponentInterface( Reference< css::awt::XWindowPeer > const & x
         pWrapper->SetWindowInterface( this, xIFace );
 }
 
+void Window::SetLOKNotifier(const vcl::ILibreOfficeKitNotifier* pNotifier)
+{
+    mpWindowImpl->mpLOKNotifier = pNotifier;
+}
+
+const vcl::ILibreOfficeKitNotifier* Window::GetLOKNotifier() const
+{
+    return mpWindowImpl->mpLOKNotifier;
+}
+
+vcl::LOKWindowId Window::GetLOKWindowId() const
+{
+    return mpWindowImpl->mnLOKWindowId;
+}
+
 void Window::ImplCallDeactivateListeners( vcl::Window *pNew )
 {
     // no deactivation if the newly activated window is my child
diff --git a/vcl/source/window/winproc.cxx b/vcl/source/window/winproc.cxx
index bf64ef132cc7..ad4c6920a738 100644
--- a/vcl/source/window/winproc.cxx
+++ b/vcl/source/window/winproc.cxx
@@ -2493,8 +2493,8 @@ bool ImplWindowFrameProc( vcl::Window* _pWindow, SalEvent nEvent, const void* pE
             break;
         case SalEvent::ShowDialog:
             {
-                ShowDialogId nDialogID = static_cast<ShowDialogId>(reinterpret_cast<sal_IntPtr>(pEvent));
-                bRet = ImplHandleShowDialog( pWindow, nDialogID );
+                ShowDialogId nLOKWindowId = static_cast<ShowDialogId>(reinterpret_cast<sal_IntPtr>(pEvent));
+                bRet = ImplHandleShowDialog( pWindow, nLOKWindowId );
             }
             break;
         case SalEvent::SurroundingTextRequest:


More information about the Libreoffice-commits mailing list