desktop/source/lib/init.cxx | 33 +++++++++++---------------- include/sfx2/lokcomponenthelpers.hxx | 11 +++++---- sfx2/source/view/lokcharthelper.cxx | 42 ++++++++++++++++++++--------------- 3 files changed, 45 insertions(+), 41 deletions(-)
New commits: commit 8d19cb2929bb8458430087a789a3b3d462af98d7 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Mon Jul 7 13:50:27 2025 +0500 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu Jul 10 08:40:21 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/+/187358 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 5408a92bb24a..b73ae8f426d9 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -5540,10 +5540,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; } } @@ -5569,23 +5567,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 0ae4d9ae8bf2..a96f0f74640d 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;