summaryrefslogtreecommitdiff
path: root/svx/source
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2020-12-24 17:12:48 +0900
committerTomaž Vajngerl <quikee@gmail.com>2021-01-13 08:00:39 +0100
commit6d0ae96a158d8c883cf7cbbf300a92ca80c73284 (patch)
tree5c95ca267cd019ea7adc45d4fc0cf8368b92bea4 /svx/source
parente24cc814b5b6e50967116cb3908e4bf56b7aee4b (diff)
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 <quikee@gmail.com>
Diffstat (limited to 'svx/source')
-rw-r--r--svx/source/devtools/DevelopmentToolDockingWindow.cxx89
1 files changed, 87 insertions, 2 deletions
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(); }