comphelper/source/misc/dispatchcommand.cxx | 7 +++- desktop/source/lib/init.cxx | 33 +++++++++------------- include/comphelper/dispatchcommand.hxx | 4 +- include/sfx2/lokcomponenthelpers.hxx | 11 ++++--- sfx2/source/view/lokcharthelper.cxx | 42 ++++++++++++++++------------- starmath/source/SmPropertiesPanel.hxx | 5 +++ 6 files changed, 57 insertions(+), 45 deletions(-)
New commits: commit 45798d61397c4df22229554595e9bad03d9ed03c Author: Mike Kaganski <[email protected]> AuthorDate: Mon Jul 7 13:50:27 2025 +0500 Commit: Mike Kaganski <[email protected]> CommitDate: Thu Jul 10 08:54:18 2025 +0200 Introduce LokChartHelper::Dispatch Let it handle conversion from string to URL object. Hide GetXDispatcher. Make LokChartHelper's mxController and mxDispatcher mutable, and mark GetXDispatcher and GetXController const. Change-Id: I2bc8cecfc4f38d66121d9a39313b37a51d7f0aff Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187355 Tested-by: Jenkins Reviewed-by: Mike Kaganski <[email protected]> diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 549d72786ccc..18a75ca58e9c 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -5531,10 +5531,8 @@ static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pComma } } } - util::URL aCommandURL; - aCommandURL.Path = u"LOKTransform"_ustr; - css::uno::Reference<css::frame::XDispatch>& aChartDispatcher = aChartHelper.GetXDispatcher(); - aChartDispatcher->dispatch(aCommandURL, comphelper::containerToSequence(aPropertyValuesVector)); + aChartHelper.Dispatch(u".uno:LOKTransform"_ustr, + comphelper::containerToSequence(aPropertyValuesVector)); return; } } @@ -5560,23 +5558,20 @@ static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pComma return; } - bool bResult = false; - LokChartHelper aChartHelper(SfxViewShell::Current()); - - if (aChartHelper.GetWindow() && aCommand != ".uno:Save" ) + if (aCommand != ".uno:Save") { - util::URL aCommandURL; - aCommandURL.Path = aCommand.copy(5); - css::uno::Reference<css::frame::XDispatch>& aChartDispatcher = aChartHelper.GetXDispatcher(); - aChartDispatcher->dispatch(aCommandURL, comphelper::containerToSequence(aPropertyValuesVector)); - return; - } - if (LokStarMathHelper aMathHelper(SfxViewShell::Current()); - aMathHelper.GetGraphicWindow() && aCommand != ".uno:Save") - { - aMathHelper.Dispatch(aCommand, comphelper::containerToSequence(aPropertyValuesVector)); - return; + if (LokChartHelper aChartHelper(SfxViewShell::Current()); aChartHelper.GetWindow()) + { + aChartHelper.Dispatch(aCommand, comphelper::containerToSequence(aPropertyValuesVector)); + return; + } + if (LokStarMathHelper aMathHelper(SfxViewShell::Current()); aMathHelper.GetGraphicWindow()) + { + aMathHelper.Dispatch(aCommand, comphelper::containerToSequence(aPropertyValuesVector)); + return; + } } + bool bResult = false; if (bNotifyWhenFinished && pDocument->mpCallbackFlushHandlers.count(nView)) { bResult = comphelper::dispatchCommand(aCommand, comphelper::containerToSequence(aPropertyValuesVector), diff --git a/include/sfx2/lokcomponenthelpers.hxx b/include/sfx2/lokcomponenthelpers.hxx index 6a8c05fcfd70..fac978e87232 100644 --- a/include/sfx2/lokcomponenthelpers.hxx +++ b/include/sfx2/lokcomponenthelpers.hxx @@ -29,11 +29,13 @@ class SFX2_DLLPUBLIC LokChartHelper { private: SfxViewShell* mpViewShell; - css::uno::Reference<css::frame::XController> mxController; - css::uno::Reference<css::frame::XDispatch> mxDispatcher; + mutable css::uno::Reference<css::frame::XController> mxController; + mutable css::uno::Reference<css::frame::XDispatch> mxDispatcher; VclPtr<vcl::Window> mpWindow; bool mbNegativeX; + css::uno::Reference<css::frame::XDispatch>& GetXDispatcher() const; + public: LokChartHelper(SfxViewShell* pViewShell, bool bNegativeX = false) : mpViewShell(pViewShell) @@ -41,12 +43,13 @@ public: , mbNegativeX(bNegativeX) {} - css::uno::Reference<css::frame::XController>& GetXController(); - css::uno::Reference<css::frame::XDispatch>& GetXDispatcher(); + css::uno::Reference<css::frame::XController>& GetXController() const; vcl::Window* GetWindow(); tools::Rectangle GetChartBoundingBox(); void Invalidate(); + void Dispatch(const OUString& cmd, const css::uno::Sequence<css::beans::PropertyValue>& rArguments) const; + bool Hit(const Point& aPos); static bool HitAny(const Point& aPos, bool bNegativeX = false); void PaintTile(VirtualDevice& rRenderContext, const tools::Rectangle& rTileRect); diff --git a/sfx2/source/view/lokcharthelper.cxx b/sfx2/source/view/lokcharthelper.cxx index 38144cb5b436..8fe1f45cc817 100644 --- a/sfx2/source/view/lokcharthelper.cxx +++ b/sfx2/source/view/lokcharthelper.cxx @@ -10,6 +10,7 @@ #include <sfx2/lokcomponenthelpers.hxx> #include <comphelper/lok.hxx> +#include <comphelper/processfactory.hxx> #include <comphelper/propertyvalue.hxx> #include <LibreOfficeKit/LibreOfficeKitEnums.h> #include <sfx2/ipclient.hxx> @@ -23,10 +24,11 @@ #include <com/sun/star/embed/XEmbeddedObject.hpp> #include <com/sun/star/frame/XDispatch.hpp> #include <com/sun/star/chart2/XChartDocument.hpp> +#include <com/sun/star/util/URLTransformer.hpp> using namespace com::sun::star; -css::uno::Reference<css::frame::XController>& LokChartHelper::GetXController() +css::uno::Reference<css::frame::XController>& LokChartHelper::GetXController() const { if(!mxController.is() && mpViewShell) { @@ -52,7 +54,7 @@ css::uno::Reference<css::frame::XController>& LokChartHelper::GetXController() return mxController; } -css::uno::Reference<css::frame::XDispatch>& LokChartHelper::GetXDispatcher() +css::uno::Reference<css::frame::XDispatch>& LokChartHelper::GetXDispatcher() const { if( !mxDispatcher.is() ) { @@ -148,6 +150,16 @@ tools::Rectangle LokChartHelper::GetChartBoundingBox() return aBBox; } +void LokChartHelper::Dispatch(const OUString& cmd, + const css::uno::Sequence<css::beans::PropertyValue>& rArguments) const +{ + util::URL aCmdURL; + aCmdURL.Complete = cmd; + util::URLTransformer::create(comphelper::getProcessComponentContext())->parseStrict(aCmdURL); + + GetXDispatcher()->dispatch(aCmdURL, rArguments); +} + void LokChartHelper::Invalidate() { mpWindow = nullptr; @@ -305,23 +317,17 @@ bool LokChartHelper::setTextSelection(int nType, int nX, int nY) tools::Rectangle rChartBBox = GetChartBoundingBox(); if (rChartBBox.Contains(Point(nX, nY))) { - css::uno::Reference<css::frame::XDispatch> xDispatcher = GetXDispatcher(); - if (xDispatcher.is()) - { - int nChartWinX = nX - rChartBBox.Left(); - int nChartWinY = nY - rChartBBox.Top(); + int nChartWinX = nX - rChartBBox.Left(); + int nChartWinY = nY - rChartBBox.Top(); - // no scale here the chart controller expects twips - // that are converted to hmm - util::URL aURL; - aURL.Path = "LOKSetTextSelection"; - uno::Sequence< beans::PropertyValue > aArgs{ - comphelper::makePropertyValue({}, static_cast<sal_Int32>(nType)), // Why no name? - comphelper::makePropertyValue({}, static_cast<sal_Int32>(nChartWinX)), - comphelper::makePropertyValue({}, static_cast<sal_Int32>(nChartWinY)) - }; - xDispatcher->dispatch(aURL, aArgs); - } + // no scale here the chart controller expects twips + // that are converted to hmm + uno::Sequence< beans::PropertyValue > aArgs{ + comphelper::makePropertyValue({}, static_cast<sal_Int32>(nType)), // Why no name? + comphelper::makePropertyValue({}, static_cast<sal_Int32>(nChartWinX)), + comphelper::makePropertyValue({}, static_cast<sal_Int32>(nChartWinY)) + }; + Dispatch(u".uno:LOKSetTextSelection"_ustr, aArgs); return true; } return false; commit 8c2c39b941870a95aca61c0e00dbaef1c68aa785 Author: Mike Kaganski <[email protected]> AuthorDate: Mon Jul 7 13:33:34 2025 +0500 Commit: Mike Kaganski <[email protected]> CommitDate: Thu Jul 10 08:54:08 2025 +0200 Let comphelper::dispatchCommand take XInterface Not only XFrame can represent an object implementing XDispatchProvider. Useful for a follow-up change passing a controller there. Change-Id: I883c6a6905e78da0c083323b5ef641fa27f133b4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187470 Tested-by: Jenkins Reviewed-by: Mike Kaganski <[email protected]> diff --git a/comphelper/source/misc/dispatchcommand.cxx b/comphelper/source/misc/dispatchcommand.cxx index 6fa212ab7f05..2ea452c18ead 100644 --- a/comphelper/source/misc/dispatchcommand.cxx +++ b/comphelper/source/misc/dispatchcommand.cxx @@ -31,9 +31,12 @@ using namespace css; namespace comphelper { -bool dispatchCommand(const OUString& rCommand, const uno::Reference<css::frame::XFrame>& rFrame, const css::uno::Sequence<css::beans::PropertyValue>& rArguments, const uno::Reference<css::frame::XDispatchResultListener>& rListener) +bool dispatchCommand(const OUString& rCommand, + const uno::Reference<uno::XInterface>& xDispatchSource, + const uno::Sequence<beans::PropertyValue>& rArguments, + const uno::Reference<frame::XDispatchResultListener>& rListener) { - uno::Reference<frame::XDispatchProvider> xDispatchProvider(rFrame, uno::UNO_QUERY); + uno::Reference<frame::XDispatchProvider> xDispatchProvider(xDispatchSource, uno::UNO_QUERY); if (!xDispatchProvider.is()) return false; diff --git a/include/comphelper/dispatchcommand.hxx b/include/comphelper/dispatchcommand.hxx index 384536952789..0e127d526108 100644 --- a/include/comphelper/dispatchcommand.hxx +++ b/include/comphelper/dispatchcommand.hxx @@ -15,7 +15,7 @@ #include <com/sun/star/uno/Reference.hxx> namespace com::sun::star::beans { struct PropertyValue; } -namespace com::sun::star::frame { class XDispatchResultListener; class XFrame; } +namespace com::sun::star::frame { class XDispatchResultListener; } namespace com::sun::star::uno { template <typename > class Sequence; } namespace comphelper @@ -32,7 +32,7 @@ COMPHELPER_DLLPUBLIC bool dispatchCommand(const OUString& rCommand, const css::uno::Reference<css::frame::XDispatchResultListener>& rListener = css::uno::Reference<css::frame::XDispatchResultListener>()); COMPHELPER_DLLPUBLIC bool dispatchCommand(const OUString& rCommand, - const css::uno::Reference<css::frame::XFrame>& rFrame, + const css::uno::Reference<css::uno::XInterface>& xDispatchSource, const css::uno::Sequence<css::beans::PropertyValue>& rArguments, const css::uno::Reference<css::frame::XDispatchResultListener>& rListener = css::uno::Reference<css::frame::XDispatchResultListener>()); diff --git a/starmath/source/SmPropertiesPanel.hxx b/starmath/source/SmPropertiesPanel.hxx index f19316e3fac1..69ad4da635d5 100644 --- a/starmath/source/SmPropertiesPanel.hxx +++ b/starmath/source/SmPropertiesPanel.hxx @@ -26,6 +26,11 @@ #include <map> #include <memory> +namespace com::sun::star::frame +{ +class XFrame; +} + namespace sm::sidebar { class SmPropertiesPanel : public PanelLayout
