framework/inc/uielement/toolbarmanager.hxx | 1 + framework/source/uielement/toolbarmanager.cxx | 9 +++++++++ include/vcl/toolbox.hxx | 2 ++ include/vcl/toolkit/button.hxx | 4 ++-- vcl/inc/vclstatuslistener.hxx | 20 +++++--------------- vcl/source/control/button.cxx | 4 ++-- vcl/source/window/builder.cxx | 4 +++- vcl/source/window/toolbox.cxx | 12 +++++++++--- vcl/source/window/toolbox2.cxx | 23 +++++++++++++---------- 9 files changed, 46 insertions(+), 33 deletions(-)
New commits: commit e695b6d89a00c86fc35332213be42d5b29196eae Author: Maxim Monastirsky <momonas...@gmail.com> AuthorDate: Wed Jul 13 09:50:17 2022 +0300 Commit: Maxim Monastirsky <momonas...@gmail.com> CommitDate: Wed Jul 13 14:52:28 2022 +0200 Related: tdf#149956 Keep in sync after icon theme change We can't just refresh the listener for .uno:ImageOrientation, as that won't work for tdf#149741. Change-Id: Iee584c98f5b81542cd9be4760433b96e97981f45 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137015 Tested-by: Jenkins Reviewed-by: Maxim Monastirsky <momonas...@gmail.com> diff --git a/vcl/source/window/toolbox2.cxx b/vcl/source/window/toolbox2.cxx index 5237aec9365f..3913b5ee6321 100644 --- a/vcl/source/window/toolbox2.cxx +++ b/vcl/source/window/toolbox2.cxx @@ -943,6 +943,15 @@ void* ToolBox::GetItemData( ToolBoxItemId nItemId ) const return nullptr; } +static Image ImplMirrorImage( const Image& rImage ) +{ + BitmapEx aMirrBitmapEx( rImage.GetBitmapEx() ); + + aMirrBitmapEx.Mirror( BmpMirrorFlags::Horizontal ); + + return Image( aMirrBitmapEx ); +} + void ToolBox::SetItemImage( ToolBoxItemId nItemId, const Image& rImage ) { ImplToolItems::size_type nPos = GetItemPos( nItemId ); @@ -953,7 +962,10 @@ void ToolBox::SetItemImage( ToolBoxItemId nItemId, const Image& rImage ) ImplToolItem* pItem = &mpData->m_aItems[nPos]; Size aOldSize = pItem->maImage.GetSizePixel(); - pItem->maImage = rImage; + if (pItem->mbMirrorMode) + pItem->maImage = ImplMirrorImage(rImage); + else + pItem->maImage = rImage; // only once all is calculated, do extra work if (!mbCalc) @@ -1003,15 +1015,6 @@ void ToolBox::SetItemImageAngle( ToolBoxItemId nItemId, Degree10 nAngle10 ) } } -static Image ImplMirrorImage( const Image& rImage ) -{ - BitmapEx aMirrBitmapEx( rImage.GetBitmapEx() ); - - aMirrBitmapEx.Mirror( BmpMirrorFlags::Horizontal ); - - return Image( aMirrBitmapEx ); -} - void ToolBox::SetItemImageMirrorMode( ToolBoxItemId nItemId, bool bMirror ) { ImplToolItems::size_type nPos = GetItemPos( nItemId ); commit 421688a4c2fc64e64ce211d579bad2174e005db4 Author: Maxim Monastirsky <momonas...@gmail.com> AuthorDate: Tue Jul 12 23:19:47 2022 +0300 Commit: Maxim Monastirsky <momonas...@gmail.com> CommitDate: Wed Jul 13 14:52:18 2022 +0200 tdf#149956 Pass the correct frame to VclStatusListener Starting directly to Writer (i.e. with "--writer") will attempt to create VclStatusListeners for .uno:ImageOrientation before the frame is activated, causing the dispatcher to not be found. Also defer that stuff to after a toolbar is filled, so we get a correct initial state for toolbars which shown when the current paragraph is rtl already. (There is a similar problem with the NB, but it isn't handled in this patch.) Change-Id: Ie482007c10a4014b4a2fd4d53f05d433777ecfb6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137014 Tested-by: Jenkins Reviewed-by: Maxim Monastirsky <momonas...@gmail.com> diff --git a/framework/inc/uielement/toolbarmanager.hxx b/framework/inc/uielement/toolbarmanager.hxx index 746b40ebc787..17840c46fe95 100644 --- a/framework/inc/uielement/toolbarmanager.hxx +++ b/framework/inc/uielement/toolbarmanager.hxx @@ -87,6 +87,7 @@ public: virtual void Clear() = 0; virtual void SetName(const OUString& rName) = 0; virtual void SetHelpId(const OString& rHelpId) = 0; + virtual void TrackImageOrientation(const css::uno::Reference<css::frame::XFrame>& rFrame) = 0; virtual bool WillUsePopupMode() = 0; virtual bool IsReallyVisible() = 0; virtual void SetIconSize(ToolBoxButtonSize eSize) = 0; diff --git a/framework/source/uielement/toolbarmanager.cxx b/framework/source/uielement/toolbarmanager.cxx index e9de797e689a..a632828b5c8c 100644 --- a/framework/source/uielement/toolbarmanager.cxx +++ b/framework/source/uielement/toolbarmanager.cxx @@ -308,6 +308,11 @@ public: m_pToolBar->SetHelpId( rHelpId ); } + virtual void TrackImageOrientation(const css::uno::Reference<css::frame::XFrame>& rFrame) override + { + m_pToolBar->TrackImageOrientation(rFrame); + } + virtual bool WillUsePopupMode() override { return m_pToolBar->WillUsePopupMode(); @@ -508,6 +513,8 @@ public: virtual void SetHelpId(const OString& /*rHelpId*/) override {} + virtual void TrackImageOrientation(const css::uno::Reference<css::frame::XFrame>&) override {} + virtual bool WillUsePopupMode() override { return true; } virtual bool IsReallyVisible() override { return true; } @@ -1712,6 +1719,8 @@ void ToolBarManager::RequestImages() ++pIter; ++i; } + + m_pImpl->TrackImageOrientation(m_xFrame); } void ToolBarManager::notifyRegisteredControllers( const OUString& aUIElementName, const OUString& aCommand ) diff --git a/include/vcl/toolbox.hxx b/include/vcl/toolbox.hxx index dda33ff02025..e0f6f085fa66 100644 --- a/include/vcl/toolbox.hxx +++ b/include/vcl/toolbox.hxx @@ -509,6 +509,8 @@ public: void SetLineSpacing(bool b) { mbLineSpacing = b; } + void TrackImageOrientation(const css::uno::Reference<css::frame::XFrame>& rFrame); + virtual void DumpAsPropertyTree(tools::JsonWriter&) override; }; diff --git a/include/vcl/toolkit/button.hxx b/include/vcl/toolkit/button.hxx index e894f9e28bfb..df67a243c52c 100644 --- a/include/vcl/toolkit/button.hxx +++ b/include/vcl/toolkit/button.hxx @@ -30,7 +30,7 @@ #include <memory> #include <vector> -namespace com::sun::star::frame { struct FeatureStateEvent; } +namespace com::sun::star::frame { struct FeatureStateEvent; class XFrame; } template <class T> class VclPtr; class Color; @@ -80,7 +80,7 @@ public: const Link<Button*,void>& GetClickHdl() const { return maClickHdl; } /// Setup handler for UNO commands so that commands like .uno:Something are handled automagically by this button. - void SetCommandHandler(const OUString& aCommand); + void SetCommandHandler(const OUString& aCommand, const css::uno::Reference<css::frame::XFrame>& rFrame); OUString const & GetCommand() const { return maCommand; } void SetModeImage( const Image& rImage ); diff --git a/vcl/inc/vclstatuslistener.hxx b/vcl/inc/vclstatuslistener.hxx index fb6d876ef6a2..82834af84399 100644 --- a/vcl/inc/vclstatuslistener.hxx +++ b/vcl/inc/vclstatuslistener.hxx @@ -24,7 +24,7 @@ template <class T> class VclStatusListener final : public cppu::WeakImplHelper < css::frame::XStatusListener> { public: - VclStatusListener(T* widget, const OUString& aCommand); + VclStatusListener(T* widget, const css::uno::Reference<css::frame::XFrame>& rFrame, const OUString& aCommand); private: VclPtr<T> mWidget; /** The widget on which actions are performed */ @@ -47,18 +47,11 @@ public: }; template<class T> -VclStatusListener<T>::VclStatusListener(T* widget, const OUString& aCommand) { - mWidget = widget; - +VclStatusListener<T>::VclStatusListener(T* widget, const css::uno::Reference<css::frame::XFrame>& rFrame, const OUString& aCommand) : + mWidget(widget), + mxFrame(rFrame) +{ css::uno::Reference<css::uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext(); - css::uno::Reference<css::frame::XDesktop2> xDesktop = css::frame::Desktop::create(xContext); - - css::uno::Reference<css::frame::XFrame> xFrame(xDesktop->getActiveFrame()); - if (!xFrame.is()) - xFrame = xDesktop; - - mxFrame = xFrame; - maCommandURL.Complete = aCommand; css::uno::Reference<css::util::XURLTransformer> xParser = css::util::URLTransformer::create(xContext); xParser->parseStrict(maCommandURL); @@ -67,9 +60,6 @@ VclStatusListener<T>::VclStatusListener(T* widget, const OUString& aCommand) { template<class T> void VclStatusListener<T>::startListening() { - if (mxDispatch.is()) - mxDispatch->removeStatusListener(this, maCommandURL); - css::uno::Reference<css::frame::XDispatchProvider> xDispatchProvider(mxFrame, css::uno::UNO_QUERY); if (!xDispatchProvider.is()) return; diff --git a/vcl/source/control/button.cxx b/vcl/source/control/button.cxx index 24a8295ed824..7adf61b71ed8 100644 --- a/vcl/source/control/button.cxx +++ b/vcl/source/control/button.cxx @@ -116,12 +116,12 @@ void Button::dispose() Control::dispose(); } -void Button::SetCommandHandler(const OUString& aCommand) +void Button::SetCommandHandler(const OUString& aCommand, const css::uno::Reference<css::frame::XFrame>& rFrame) { maCommand = aCommand; SetClickHdl( LINK( this, Button, dispatchCommandHandler) ); - mpButtonData->mpStatusListener = new VclStatusListener<Button>(this, aCommand); + mpButtonData->mpStatusListener = new VclStatusListener<Button>(this, rFrame, aCommand); mpButtonData->mpStatusListener->startListening(); } diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index 0afa10535670..3aaefe33a477 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -1193,7 +1193,7 @@ namespace Image aImage(vcl::CommandInfoProvider::GetImageForCommand(aCommand, rFrame)); pButton->SetModeImage(aImage); - pButton->SetCommandHandler(aCommand); + pButton->SetCommandHandler(aCommand, rFrame); } VclPtr<Button> extractStockAndBuildPushButton(vcl::Window *pParent, VclBuilder::stringmap &rMap, bool bToggle) @@ -2156,6 +2156,8 @@ VclPtr<vcl::Window> VclBuilder::makeObject(vcl::Window *pParent, const OString & m_pParserState->m_aButtonMenuMaps.emplace_back(id, sMenu); setupFromActionName(static_cast<Button*>(xWindow.get()), rMap, m_xFrame); } + else if (xWindow->GetType() == WindowType::TOOLBOX) + static_cast<ToolBox*>(xWindow.get())->TrackImageOrientation(m_xFrame); } } diff --git a/vcl/source/window/toolbox.cxx b/vcl/source/window/toolbox.cxx index c2d42f51bf23..6223173c2d0b 100644 --- a/vcl/source/window/toolbox.cxx +++ b/vcl/source/window/toolbox.cxx @@ -1102,6 +1102,15 @@ IMPL_LINK( ImplTBDragMgr, SelectHdl, Accelerator&, rAccel, void ) EndDragging(); } +void ToolBox::TrackImageOrientation(const css::uno::Reference<css::frame::XFrame>& rFrame) +{ + if (mpStatusListener.is()) + mpStatusListener->dispose(); + + mpStatusListener = new VclStatusListener<ToolBox>(this, rFrame, ".uno:ImageOrientation"); + mpStatusListener->startListening(); +} + void ToolBox::ImplInitToolBoxData() { // initialize variables @@ -1158,9 +1167,6 @@ void ToolBox::ImplInitToolBoxData() mnActivateCount = 0; mnImagesRotationAngle = 0_deg10; - mpStatusListener = new VclStatusListener<ToolBox>(this, ".uno:ImageOrientation"); - mpStatusListener->startListening(); - mpIdle.reset(new Idle("vcl::ToolBox maIdle update")); mpIdle->SetPriority( TaskPriority::RESIZE ); mpIdle->SetInvokeHandler( LINK( this, ToolBox, ImplUpdateHdl ) );