From 30e08c83e502562966351f4236e9dd9230ffa435 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Thu, 30 Jun 2022 06:09:23 +0300 Subject: [PATCH] lok: Enable sidebar in Math Change-Id: I1554a924eef0bfcaffa893057a37ef45321a0cf7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137246 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- desktop/source/lib/init.cxx | 8 ++++- include/sfx2/lokcomponenthelpers.hxx | 4 +++ include/sfx2/sidebar/SidebarController.hxx | 2 +- sc/source/ui/drawfunc/chartsh.cxx | 12 +++---- sc/source/ui/view/tabvwsh4.cxx | 6 ++-- .../ui/slidesorter/shell/SlideSorterViewShell.cxx | 8 ++--- sfx2/source/sidebar/SidebarController.cxx | 5 +-- sfx2/source/view/lokstarmathhelper.cxx | 9 +++++ starmath/source/view.cxx | 39 ++++++++++++++++++++-- sw/source/uibase/shells/olesh.cxx | 12 +++---- 10 files changed, 79 insertions(+), 26 deletions(-) diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 029e8b72c667..c0f129fef72f 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -4345,7 +4345,13 @@ static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pComma aChartDispatcher->dispatch(aCommandURL, comphelper::containerToSequence(aPropertyValuesVector)); return; } - else if (bNotifyWhenFinished && pDocument->mpCallbackFlushHandlers.count(nView)) + if (LokStarMathHelper aMathHelper(SfxViewShell::Current()); + aMathHelper.GetGraphicWindow() && aCommand != ".uno:Save") + { + aMathHelper.Dispatch(aCommand, comphelper::containerToSequence(aPropertyValuesVector)); + return; + } + if (bNotifyWhenFinished && pDocument->mpCallbackFlushHandlers.count(nView)) { bResult = comphelper::dispatchCommand(aCommand, comphelper::containerToSequence(aPropertyValuesVector), new DispatchResultListener(pCommand, pDocument->mpCallbackFlushHandlers[nView])); diff --git a/include/sfx2/lokcomponenthelpers.hxx b/include/sfx2/lokcomponenthelpers.hxx index 6a3d964689b4..02e8750ca381 100644 --- a/include/sfx2/lokcomponenthelpers.hxx +++ b/include/sfx2/lokcomponenthelpers.hxx @@ -15,8 +15,10 @@ #include #include +namespace com::sun::star::beans { struct PropertyValue; } namespace com::sun::star::frame { class XController; } namespace com::sun::star::frame { class XDispatch; } +namespace com::sun::star::uno { template class Sequence; } class SfxViewShell; class VirtualDevice; @@ -72,6 +74,8 @@ public: vcl::Window* GetGraphicWindow(); vcl::Window* GetWidgetWindow(); + void Dispatch(const OUString& cmd, const css::uno::Sequence& rArguments); + bool postMouseEvent(int nType, int nX, int nY, int nCount, int nButtons, int nModifier, double fScaleX = 1.0, double fScaleY = 1.0); diff --git a/include/sfx2/sidebar/SidebarController.hxx b/include/sfx2/sidebar/SidebarController.hxx index 8d8dcf215527..e996c853c5b0 100644 --- a/include/sfx2/sidebar/SidebarController.hxx +++ b/include/sfx2/sidebar/SidebarController.hxx @@ -170,7 +170,7 @@ public: void SyncUpdate(); - bool hasChartContextCurrently() const; + bool hasChartOrMathContextCurrently() const; static SidebarController* GetSidebarControllerForView(const SfxViewShell* pViewShell); diff --git a/sc/source/ui/drawfunc/chartsh.cxx b/sc/source/ui/drawfunc/chartsh.cxx index ac54c435eeea..e6378a5fa9cb 100644 --- a/sc/source/ui/drawfunc/chartsh.cxx +++ b/sc/source/ui/drawfunc/chartsh.cxx @@ -42,11 +42,11 @@ namespace drawing = com::sun::star::drawing; namespace { -bool inChartContext(const ScTabViewShell* pViewShell) +bool inChartOrMathContext(const ScTabViewShell* pViewShell) { SidebarController* pSidebar = SidebarController::GetSidebarControllerForView(pViewShell); if (pSidebar) - return pSidebar->hasChartContextCurrently(); + return pSidebar->hasChartOrMathContextCurrently(); return false; } @@ -66,11 +66,11 @@ void ScChartShell::InitInterface_Impl() void ScChartShell::Activate(bool bMDI) { - if(!inChartContext(GetViewData().GetViewShell())) + if(!inChartOrMathContext(GetViewData().GetViewShell())) ScDrawShell::Activate(bMDI); else { - // Avoid context changes for chart during activation / deactivation. + // Avoid context changes for chart/math during activation / deactivation. const bool bIsContextBroadcasterEnabled (SfxShell::SetContextBroadcasterEnabled(false)); SfxShell::Activate(bMDI); @@ -81,11 +81,11 @@ void ScChartShell::Activate(bool bMDI) void ScChartShell::Deactivate(bool bMDI) { - if(!inChartContext(GetViewData().GetViewShell())) + if(!inChartOrMathContext(GetViewData().GetViewShell())) ScDrawShell::Deactivate(bMDI); else { - // Avoid context changes for chart during activation / deactivation. + // Avoid context changes for chart/math during activation / deactivation. const bool bIsContextBroadcasterEnabled (SfxShell::SetContextBroadcasterEnabled(false)); SfxShell::Deactivate(bMDI); diff --git a/sc/source/ui/view/tabvwsh4.cxx b/sc/source/ui/view/tabvwsh4.cxx index 94db6ca12a13..9bd541a04d03 100644 --- a/sc/source/ui/view/tabvwsh4.cxx +++ b/sc/source/ui/view/tabvwsh4.cxx @@ -91,11 +91,11 @@ using namespace sfx2::sidebar; namespace { -bool inChartContext(const ScTabViewShell* pViewShell) +bool inChartOrMathContext(const ScTabViewShell* pViewShell) { SidebarController* pSidebar = SidebarController::GetSidebarControllerForView(pViewShell); if (pSidebar) - return pSidebar->hasChartContextCurrently(); + return pSidebar->hasChartOrMathContextCurrently(); return false; } @@ -218,7 +218,7 @@ void ScTabViewShell::Activate(bool bMDI) // don't call CheckSelectionTransfer here - activating a view should not change the // primary selection (may be happening just because the mouse was moved over the window) - if (!inChartContext(this)) + if (!inChartOrMathContext(this)) { ContextChangeEventMultiplexer::NotifyContextChange( GetController(), diff --git a/sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx b/sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx index af5bd5791ba4..4de3e6a1c095 100644 --- a/sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx +++ b/sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx @@ -74,7 +74,7 @@ namespace sd::slidesorter { namespace { -bool inChartContext(const sd::View* pView) +bool inChartOrMathContext(const sd::View* pView) { if (!pView) return false; @@ -82,7 +82,7 @@ bool inChartContext(const sd::View* pView) SfxViewShell* pViewShell = pView->GetSfxViewShell(); SidebarController* pSidebar = SidebarController::GetSidebarControllerForView(pViewShell); if (pSidebar) - return pSidebar->hasChartContextCurrently(); + return pSidebar->hasChartOrMathContextCurrently(); return false; } @@ -459,9 +459,9 @@ void SlideSorterViewShell::ArrangeGUIElements() void SlideSorterViewShell::Activate (bool bIsMDIActivate) { - if(inChartContext(GetView())) + if(inChartOrMathContext(GetView())) { - // Avoid context changes for chart during activation / deactivation. + // Avoid context changes for chart/math during activation / deactivation. const bool bIsContextBroadcasterEnabled (SfxShell::SetContextBroadcasterEnabled(false)); ViewShell::Activate(bIsMDIActivate); diff --git a/sfx2/source/sidebar/SidebarController.cxx b/sfx2/source/sidebar/SidebarController.cxx index 0bd71db0240d..6909f5c19d62 100644 --- a/sfx2/source/sidebar/SidebarController.cxx +++ b/sfx2/source/sidebar/SidebarController.cxx @@ -1609,9 +1609,10 @@ void SidebarController::saveDeckState() } } -bool SidebarController::hasChartContextCurrently() const +bool SidebarController::hasChartOrMathContextCurrently() const { - return GetCurrentContext().msApplication == "com.sun.star.chart2.ChartDocument"; + return GetCurrentContext().msApplication == "com.sun.star.chart2.ChartDocument" + || GetCurrentContext().msApplication == "com.sun.star.formula.FormulaProperties"; } sfx2::sidebar::SidebarController* SidebarController::GetSidebarControllerForView(const SfxViewShell* pViewShell) diff --git a/sfx2/source/view/lokstarmathhelper.cxx b/sfx2/source/view/lokstarmathhelper.cxx index 9df48759528d..9a704683aaec 100644 --- a/sfx2/source/view/lokstarmathhelper.cxx +++ b/sfx2/source/view/lokstarmathhelper.cxx @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -43,6 +44,14 @@ css::uno::Reference& LokStarMathHelper::GetXController( return mxController; } +void LokStarMathHelper::Dispatch(const OUString& cmd, + const css::uno::Sequence& rArguments) +{ + if (const css::uno::Reference& xController = GetXController()) + if (const css::uno::Reference xFrame = xController->getFrame()) + comphelper::dispatchCommand(cmd, xFrame, rArguments); +} + namespace { // Find a child SmGraphicWindow* diff --git a/starmath/source/view.cxx b/starmath/source/view.cxx index e2b60cb9c6bd..56896a030572 100644 --- a/starmath/source/view.cxx +++ b/starmath/source/view.cxx @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -44,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -2097,6 +2099,29 @@ void SmViewShell::GetState(SfxItemSet &rSet) namespace { +css::uno::Reference +getSidebarFromModel(const css::uno::Reference& xModel) +{ + css::uno::Reference xChild(xModel, css::uno::UNO_QUERY); + if (!xChild.is()) + return nullptr; + + css::uno::Reference xParent(xChild->getParent(), css::uno::UNO_QUERY); + if (!xParent.is()) + return nullptr; + + css::uno::Reference xController(xParent->getCurrentController(), + css::uno::UNO_QUERY); + if (!xController.is()) + return nullptr; + + css::uno::Reference xSidebarProvider = xController->getSidebar(); + if (!xSidebarProvider.is()) + return nullptr; + + return xSidebarProvider->getSidebar(); +} + class SmController : public SfxBaseController { public: @@ -2105,17 +2130,25 @@ public: , mpSelectionChangeHandler(new svx::sidebar::SelectionChangeHandler( GetContextName, this, vcl::EnumContext::Context::Math)) { - mpSelectionChangeHandler->Connect(); rViewShell.SetContextName(GetContextName()); } - ~SmController() { mpSelectionChangeHandler->Disconnect(); } + // No need to call mpSelectionChangeHandler->Disconnect() unless SmController implements XSelectionSupplier + // ~SmController() { mpSelectionChangeHandler->Disconnect(); } // css::frame::XController void SAL_CALL attachFrame(const css::uno::Reference& xFrame) override { SfxBaseController::attachFrame(xFrame); - mpSelectionChangeHandler->selectionChanged({}); // Installs the correct context + // No need to call mpSelectionChangeHandler->Connect() unless SmController implements XSelectionSupplier + if (auto xSidebar = getSidebarFromModel(getModel())) + { + auto pSidebar = dynamic_cast(xSidebar.get()); + assert(pSidebar); + sfx2::sidebar::SidebarController::registerSidebarForFrame(pSidebar, this); + pSidebar->updateModel(getModel()); + mpSelectionChangeHandler->selectionChanged({}); // Installs the correct context + } } private: diff --git a/sw/source/uibase/shells/olesh.cxx b/sw/source/uibase/shells/olesh.cxx index acddd3eb6975..28e8e153eeb1 100644 --- a/sw/source/uibase/shells/olesh.cxx +++ b/sw/source/uibase/shells/olesh.cxx @@ -34,11 +34,11 @@ using namespace sfx2::sidebar; namespace { -bool inChartContext(const SwView& rViewShell) +bool inChartOrMathContext(const SwView& rViewShell) { SidebarController* pSidebar = SidebarController::GetSidebarControllerForView(&rViewShell); if (pSidebar) - return pSidebar->hasChartContextCurrently(); + return pSidebar->hasChartOrMathContextCurrently(); return false; } @@ -56,11 +56,11 @@ void SwOleShell::InitInterface_Impl() void SwOleShell::Activate(bool bMDI) { - if(!inChartContext(GetView())) + if(!inChartOrMathContext(GetView())) SwFrameShell::Activate(bMDI); else { - // Avoid context changes for chart during activation / deactivation. + // Avoid context changes for chart/math during activation / deactivation. const bool bIsContextBroadcasterEnabled (SfxShell::SetContextBroadcasterEnabled(false)); SwFrameShell::Activate(bMDI); @@ -71,11 +71,11 @@ void SwOleShell::Activate(bool bMDI) void SwOleShell::Deactivate(bool bMDI) { - if(!inChartContext(GetView())) + if(!inChartOrMathContext(GetView())) SwFrameShell::Deactivate(bMDI); else { - // Avoid context changes for chart during activation / deactivation. + // Avoid context changes for chart/math during activation / deactivation. const bool bIsContextBroadcasterEnabled (SfxShell::SetContextBroadcasterEnabled(false)); SwFrameShell::Deactivate(bMDI); -- 2.11.4.GIT