include/svx/devtools/DevelopmentToolDockingWindow.hxx |    5 -
 svx/source/devtools/DevelopmentToolDockingWindow.cxx  |   89 +++++++++++++++++-
 2 files changed, 91 insertions(+), 3 deletions(-)

New commits:
commit 6d0ae96a158d8c883cf7cbbf300a92ca80c73284
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Thu Dec 24 17:12:48 2020 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Wed Jan 13 08:00:39 2021 +0100

    devtools: Add selection change listener to DevTools
    
    Selection listener is needed so it is possible to react when the
    selection changes in the document.
    
    Change-Id: I94e9da06b3ceedbad13dd203f690037f3eafdb13
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108259
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/include/svx/devtools/DevelopmentToolDockingWindow.hxx 
b/include/svx/devtools/DevelopmentToolDockingWindow.hxx
index 89030c0652e1..30499379f32e 100644
--- a/include/svx/devtools/DevelopmentToolDockingWindow.hxx
+++ b/include/svx/devtools/DevelopmentToolDockingWindow.hxx
@@ -15,13 +15,15 @@
 #include <vcl/customweld.hxx>
 #include <vcl/weld.hxx>
 
+#include <com/sun/star/uno/XInterface.hpp>
+#include <com/sun/star/uno/Reference.hxx>
+
 class SAL_WARN_UNUSED SVX_DLLPUBLIC DevelopmentToolChildWindow final : public 
SfxChildWindow
 {
     SFX_DECL_CHILDWINDOW_WITHID(DevelopmentToolChildWindow);
 
     DevelopmentToolChildWindow(vcl::Window* pParentWindow, sal_uInt16 nId, 
SfxBindings* pBindings,
                                SfxChildWinInfo* pInfo);
-    virtual ~DevelopmentToolChildWindow() override;
 };
 
 class SAL_WARN_UNUSED SVX_DLLPUBLIC DevelopmentToolDockingWindow final : 
public SfxDockingWindow
@@ -29,6 +31,7 @@ class SAL_WARN_UNUSED SVX_DLLPUBLIC 
DevelopmentToolDockingWindow final : public
 public:
     DevelopmentToolDockingWindow(SfxBindings* pBindings, SfxChildWindow* 
pChildWindow,
                                  vcl::Window* pParent);
+
     virtual ~DevelopmentToolDockingWindow() override;
 
     virtual void ToggleFloatingMode() override;
diff --git a/svx/source/devtools/DevelopmentToolDockingWindow.cxx 
b/svx/source/devtools/DevelopmentToolDockingWindow.cxx
index a435cd9b9c04..7d2626ae7978 100644
--- a/svx/source/devtools/DevelopmentToolDockingWindow.cxx
+++ b/svx/source/devtools/DevelopmentToolDockingWindow.cxx
@@ -12,10 +12,85 @@
 
 #include <svx/devtools/DevelopmentToolDockingWindow.hxx>
 
+#include <com/sun/star/uno/XComponentContext.hpp>
+
+#include <com/sun/star/beans/theIntrospection.hpp>
+#include <com/sun/star/beans/XIntrospection.hpp>
+#include <com/sun/star/beans/XIntrospectionAccess.hpp>
+#include <com/sun/star/beans/Property.hpp>
+#include <com/sun/star/beans/PropertyConcept.hpp>
+#include <com/sun/star/beans/MethodConcept.hpp>
+#include <com/sun/star/reflection/XIdlMethod.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+
+#include <comphelper/processfactory.hxx>
+
 #include <sfx2/dispatch.hxx>
 #include <sfx2/sfxmodelfactory.hxx>
 #include <svx/svxids.hrc>
 
+#include <sfx2/objsh.hxx>
+
+#include <sfx2/viewfrm.hxx>
+
+#include <com/sun/star/frame/XController.hpp>
+#include <com/sun/star/view/XSelectionChangeListener.hpp>
+
+#include <cppuhelper/compbase.hxx>
+#include <cppuhelper/basemutex.hxx>
+
+#include <com/sun/star/view/XSelectionSupplier.hpp>
+
+using namespace css;
+
+namespace
+{
+void introspect(uno::Reference<uno::XInterface> const& xInterface)
+{
+    if (!xInterface.is())
+        return;
+
+    uno::Reference<uno::XComponentContext> xContext = 
comphelper::getProcessComponentContext();
+    if (!xContext.is())
+        return;
+}
+
+typedef cppu::WeakComponentImplHelper<css::view::XSelectionChangeListener>
+    SelectionChangeHandlerInterfaceBase;
+
+class SelectionChangeHandler final : private ::cppu::BaseMutex,
+                                     public SelectionChangeHandlerInterfaceBase
+{
+private:
+    css::uno::Reference<css::frame::XController> mxController;
+
+public:
+    SelectionChangeHandler(const css::uno::Reference<css::frame::XController>& 
rxController)
+        : SelectionChangeHandlerInterfaceBase(m_aMutex)
+        , mxController(rxController)
+    {
+    }
+
+    virtual void SAL_CALL selectionChanged(const css::lang::EventObject& 
/*rEvent*/) override
+    {
+        uno::Reference<view::XSelectionSupplier> xSupplier(mxController, 
uno::UNO_QUERY);
+        if (xSupplier.is())
+        {
+            uno::Any aAny = xSupplier->getSelection();
+            auto aRef = aAny.get<uno::Reference<uno::XInterface>>();
+            introspect(aRef);
+        }
+    }
+    virtual void SAL_CALL disposing(const css::lang::EventObject& /*rEvent*/) 
override {}
+    virtual void SAL_CALL disposing() override {}
+
+private:
+    SelectionChangeHandler(const SelectionChangeHandler&) = delete;
+    SelectionChangeHandler& operator=(const SelectionChangeHandler&) = delete;
+};
+
+} // end anonymous namespace
+
 SFX_IMPL_DOCKINGWINDOW_WITHID(DevelopmentToolChildWindow, 
SID_DEVELOPMENT_TOOLS_DOCKING_WINDOW);
 
 DevelopmentToolChildWindow::DevelopmentToolChildWindow(vcl::Window* 
pParentWindow, sal_uInt16 nId,
@@ -30,14 +105,24 @@ 
DevelopmentToolChildWindow::DevelopmentToolChildWindow(vcl::Window* pParentWindo
     pWin->Initialize(pInfo);
 }
 
-DevelopmentToolChildWindow::~DevelopmentToolChildWindow() {}
-
 DevelopmentToolDockingWindow::DevelopmentToolDockingWindow(SfxBindings* 
pInputBindings,
                                                            SfxChildWindow* 
pChildWindow,
                                                            vcl::Window* 
pParent)
     : SfxDockingWindow(pInputBindings, pChildWindow, pParent, 
"DevelopmentTool",
                        "svx/ui/developmenttool.ui")
 {
+    auto* pViewFrame = pInputBindings->GetDispatcher()->GetFrame();
+
+    uno::Reference<frame::XController> xCtrl = 
pViewFrame->GetFrame().GetController();
+
+    uno::Reference<view::XSelectionSupplier> xSupplier(xCtrl, uno::UNO_QUERY);
+    if (xSupplier.is())
+    {
+        uno::Reference<view::XSelectionChangeListener> xChangeListener(
+            new SelectionChangeHandler(xCtrl));
+        xSupplier->addSelectionChangeListener(xChangeListener);
+        
introspect(pInputBindings->GetDispatcher()->GetFrame()->GetObjectShell()->GetBaseModel());
+    }
 }
 
 DevelopmentToolDockingWindow::~DevelopmentToolDockingWindow() { disposeOnce(); 
}
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to