From dbeb697d62250e9429462c7f61b859893262a651 Mon Sep 17 00:00:00 2001 From: Maxim Monastirsky Date: Fri, 29 Jul 2022 09:56:51 +0300 Subject: tdf#149956 Rework toolbar image flipping An unified code, covering both vcl and weld cases. For SidebarToolBox, the controller is created before items are inserted, so we listen for item insert event to set initially correct state. Change-Id: I3841f21883104b4d3f8541c97ec7fa5fc0bec575 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139022 Tested-by: Jenkins Reviewed-by: Maxim Monastirsky --- sfx2/inc/sidebar/ControllerFactory.hxx | 4 ++++ sfx2/inc/sidebar/SidebarToolBox.hxx | 1 + sfx2/source/sidebar/ControllerFactory.cxx | 12 ++++++++++++ sfx2/source/sidebar/SidebarToolBox.cxx | 9 +++++++++ sfx2/source/toolbox/weldutils.cxx | 5 ++++- 5 files changed, 30 insertions(+), 1 deletion(-) (limited to 'sfx2') diff --git a/sfx2/inc/sidebar/ControllerFactory.hxx b/sfx2/inc/sidebar/ControllerFactory.hxx index 8d45a2e3b1ed..c30cec61425b 100644 --- a/sfx2/inc/sidebar/ControllerFactory.hxx +++ b/sfx2/inc/sidebar/ControllerFactory.hxx @@ -40,6 +40,10 @@ namespace sfx2::sidebar { class ControllerFactory { public: + static css::uno::Reference CreateImageController( + const css::uno::Reference& rxFrame, + const css::uno::Reference& rxParentWindow); + static css::uno::Reference CreateToolBoxController( ToolBox* pToolBox, const ToolBoxItemId nItemId, diff --git a/sfx2/inc/sidebar/SidebarToolBox.hxx b/sfx2/inc/sidebar/SidebarToolBox.hxx index acae7475e69a..f3c18c531455 100644 --- a/sfx2/inc/sidebar/SidebarToolBox.hxx +++ b/sfx2/inc/sidebar/SidebarToolBox.hxx @@ -54,6 +54,7 @@ public: void InitToolBox(VclBuilder::stringmap& rMap); protected: + css::uno::Reference mxImageController; typedef std::map> ControllerContainer; ControllerContainer maControllers; bool mbAreHandlersRegistered; diff --git a/sfx2/source/sidebar/ControllerFactory.cxx b/sfx2/source/sidebar/ControllerFactory.cxx index d904b5260420..cc453c53cd7e 100644 --- a/sfx2/source/sidebar/ControllerFactory.cxx +++ b/sfx2/source/sidebar/ControllerFactory.cxx @@ -38,6 +38,18 @@ using namespace css::uno; namespace sfx2::sidebar { +Reference ControllerFactory::CreateImageController( + const Reference& rxFrame, + const Reference& rxParentWindow) +{ + rtl::Reference xController(new framework::ImageOrientationController( + comphelper::getProcessComponentContext(), rxFrame, rxParentWindow, + vcl::CommandInfoProvider::GetModuleIdentifier(rxFrame))); + + xController->update(); + return xController; +} + Reference ControllerFactory::CreateToolBoxController( ToolBox* pToolBox, const ToolBoxItemId nItemId, diff --git a/sfx2/source/sidebar/SidebarToolBox.cxx b/sfx2/source/sidebar/SidebarToolBox.cxx index bb89d007bbb0..936fdbdd4ddc 100644 --- a/sfx2/source/sidebar/SidebarToolBox.cxx +++ b/sfx2/source/sidebar/SidebarToolBox.cxx @@ -67,6 +67,12 @@ SidebarToolBox::SidebarToolBox (vcl::Window* pParentWindow) SetToolboxButtonSize(GetDefaultButtonSize()); SvtMiscOptions().AddListenerLink(LINK(this, SidebarToolBox, ChangedIconSizeHandler)); + if (SfxViewFrame::Current()) + { + auto xFrame(SfxViewFrame::Current()->GetFrame().GetFrameInterface()); + auto xWidget(VCLUnoHelper::GetInterface(this)); + mxImageController = sfx2::sidebar::ControllerFactory::CreateImageController(xFrame, xWidget); + } #ifdef DEBUG SetText(OUString("SidebarToolBox")); @@ -91,6 +97,9 @@ void SidebarToolBox::dispose() xComponent->dispose(); } + if (mxImageController) + mxImageController->dispose(); + if (mbAreHandlersRegistered) { SetDropdownClickHdl(Link()); diff --git a/sfx2/source/toolbox/weldutils.cxx b/sfx2/source/toolbox/weldutils.cxx index 25b173de633f..eff86b0b857f 100644 --- a/sfx2/source/toolbox/weldutils.cxx +++ b/sfx2/source/toolbox/weldutils.cxx @@ -13,7 +13,7 @@ #include #include #include -#include +#include namespace { @@ -110,6 +110,8 @@ ToolbarUnoDispatcher::ToolbarUnoDispatcher(weld::Toolbar& rToolbar, weld::Builde CreateController(sCommand); } + rtl::Reference xWidget(new weld::TransportAsXWindow(m_pToolbar, m_pBuilder)); + m_xImageController = sfx2::sidebar::ControllerFactory::CreateImageController(m_xFrame, xWidget); m_aToolbarOptions.AddListenerLink(LINK(this, ToolbarUnoDispatcher, ChangedIconSizeHandler)); } @@ -194,6 +196,7 @@ void ToolbarUnoDispatcher::dispose() xComponent->dispose(); } + m_xImageController->dispose(); m_pToolbar->connect_clicked(Link()); m_pToolbar = nullptr; m_pBuilder = nullptr; -- cgit