summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorMaxim Monastirsky <momonasmon@gmail.com>2022-07-29 09:56:51 +0300
committerMaxim Monastirsky <momonasmon@gmail.com>2022-08-30 13:08:39 +0200
commitdbeb697d62250e9429462c7f61b859893262a651 (patch)
treecda0cb7a6d7179971e2da8e174da3712d53a1767 /framework
parent4fb8c0d14cb2468f7336438004f699b9eb7e7e4a (diff)
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 <momonasmon@gmail.com>
Diffstat (limited to 'framework')
-rw-r--r--framework/inc/uielement/toolbarmanager.hxx2
-rw-r--r--framework/source/uielement/generictoolbarcontroller.cxx94
-rw-r--r--framework/source/uielement/toolbarmanager.cxx10
3 files changed, 105 insertions, 1 deletions
diff --git a/framework/inc/uielement/toolbarmanager.hxx b/framework/inc/uielement/toolbarmanager.hxx
index 865a1b54d5b4..debd898c9b45 100644
--- a/framework/inc/uielement/toolbarmanager.hxx
+++ b/framework/inc/uielement/toolbarmanager.hxx
@@ -55,6 +55,7 @@ class Menu;
namespace framework
{
+class ImageOrientationController;
class ToolBarManager;
class ToolBarManagerImpl
@@ -246,6 +247,7 @@ class ToolBarManager final : public ToolbarManager_Base
OUString m_sIconTheme;
rtl::Reference< ToolBarManager > m_aOverflowManager;
+ rtl::Reference< ImageOrientationController > m_aImageController;
};
}
diff --git a/framework/source/uielement/generictoolbarcontroller.cxx b/framework/source/uielement/generictoolbarcontroller.cxx
index 312b5ed9e77f..f61a0d0150b9 100644
--- a/framework/source/uielement/generictoolbarcontroller.cxx
+++ b/framework/source/uielement/generictoolbarcontroller.cxx
@@ -30,9 +30,9 @@
#include <svl/imageitm.hxx>
#include <vcl/commandinfoprovider.hxx>
#include <vcl/svapp.hxx>
-#include <vcl/toolbox.hxx>
#include <vcl/weld.hxx>
#include <tools/urlobj.hxx>
+#include <toolkit/helper/vclunohelper.hxx>
#include <strings.hrc>
#include <classes/fwkresid.hxx>
@@ -338,6 +338,98 @@ IMPL_STATIC_LINK( GenericToolbarController, ExecuteHdl_Impl, void*, p, void )
delete pExecuteInfo;
}
+ImageOrientationController::ImageOrientationController(const Reference<XComponentContext>& rContext,
+ const Reference<XFrame>& rFrame,
+ const Reference<css::awt::XWindow>& rParentWindow,
+ const OUString& rModuleName)
+ : ToolboxController(rContext, rFrame, ".uno:ImageOrientation")
+ , m_nRotationAngle(0_deg10)
+ , m_bMirrored(false)
+{
+ m_sModuleName = rModuleName;
+ m_xParentWindow = rParentWindow;
+ initialize({});
+ if (!m_pToolbar)
+ VCLUnoHelper::GetWindow(getParent())->AddEventListener(LINK(this, ImageOrientationController, WindowEventListener));
+}
+
+void ImageOrientationController::dispose()
+{
+ ToolboxController::dispose();
+ if (!m_pToolbar)
+ VCLUnoHelper::GetWindow(getParent())->RemoveEventListener(LINK(this, ImageOrientationController, WindowEventListener));
+}
+
+IMPL_LINK(ImageOrientationController, WindowEventListener, VclWindowEvent&, rWindowEvent, void)
+{
+ if (m_bDisposed || rWindowEvent.GetId() != VclEventId::ToolboxItemAdded)
+ return;
+
+ ToolBox* pToolBox = static_cast<ToolBox*>(rWindowEvent.GetWindow());
+ ToolBoxItemId nItemId = pToolBox->GetItemId(reinterpret_cast<sal_IntPtr>(rWindowEvent.GetData()));
+ OUString aCommand = pToolBox->GetItemCommand(nItemId);
+
+ if (vcl::CommandInfoProvider::IsMirrored(aCommand, getModuleName()))
+ pToolBox->SetItemImageMirrorMode(nItemId, m_bMirrored);
+ if (vcl::CommandInfoProvider::IsRotated(aCommand, getModuleName()))
+ pToolBox->SetItemImageAngle(nItemId, m_nRotationAngle);
+}
+
+void ImageOrientationController::statusChanged(const css::frame::FeatureStateEvent& rEvent)
+{
+ if (m_bDisposed)
+ throw DisposedException();
+
+ SfxImageItem aItem;
+ aItem.PutValue(rEvent.State, 0);
+
+ if (m_bMirrored == aItem.IsMirrored() && m_nRotationAngle == aItem.GetRotation())
+ return;
+
+ m_bMirrored = aItem.IsMirrored();
+ m_nRotationAngle = aItem.GetRotation();
+
+ if (m_pToolbar)
+ {
+ for (int i = 0, nCount = m_pToolbar->get_n_items(); i < nCount; ++i)
+ {
+ OString aCommand = m_pToolbar->get_item_ident(i);
+ if (vcl::CommandInfoProvider::IsMirrored(OUString::fromUtf8(aCommand), getModuleName()))
+ {
+ m_pToolbar->set_item_image_mirrored(aCommand, m_bMirrored);
+ auto xGraphic(vcl::CommandInfoProvider::GetXGraphicForCommand(
+ OUString::fromUtf8(aCommand), m_xFrame, m_pToolbar->get_icon_size()));
+ m_pToolbar->set_item_image(aCommand, xGraphic);
+ }
+ }
+ }
+ else
+ {
+ ToolBox* pToolBox = static_cast<ToolBox*>(VCLUnoHelper::GetWindow(getParent()));
+ for (ToolBox::ImplToolItems::size_type i = 0; i < pToolBox->GetItemCount(); ++i)
+ {
+ ToolBoxItemId nItemId = pToolBox->GetItemId(i);
+ OUString aCommand = pToolBox->GetItemCommand(nItemId);
+ bool bModified = false;
+ if (vcl::CommandInfoProvider::IsMirrored(aCommand, getModuleName()))
+ {
+ pToolBox->SetItemImageMirrorMode(nItemId, m_bMirrored);
+ bModified = true;
+ }
+ if (vcl::CommandInfoProvider::IsRotated(aCommand, getModuleName()))
+ {
+ pToolBox->SetItemImageAngle(nItemId, m_nRotationAngle);
+ bModified = true;
+ }
+ if (bModified)
+ {
+ Image aImage(vcl::CommandInfoProvider::GetImageForCommand(aCommand, m_xFrame, pToolBox->GetImageSize()));
+ pToolBox->SetItemImage(nItemId, aImage);
+ }
+ }
+ }
+}
+
} // namespace
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/framework/source/uielement/toolbarmanager.cxx b/framework/source/uielement/toolbarmanager.cxx
index d1251f96cb84..723afeb09977 100644
--- a/framework/source/uielement/toolbarmanager.cxx
+++ b/framework/source/uielement/toolbarmanager.cxx
@@ -766,6 +766,8 @@ void ToolBarManager::frameAction( const FrameActionEvent& Action )
SolarMutexGuard g;
if ( Action.Action == FrameAction_CONTEXT_CHANGED && !m_bDisposed )
{
+ if (m_aImageController)
+ m_aImageController->update();
m_aAsyncUpdateControllersTimer.Start();
}
}
@@ -998,6 +1000,10 @@ void ToolBarManager::RemoveControllers()
m_aSubToolBarControllerMap.clear();
+ if (m_aImageController)
+ m_aImageController->dispose();
+ m_aImageController.clear();
+
// i90033
// Remove item window pointers from the toolbar. They were
// destroyed by the dispose() at the XComponent. This is needed
@@ -1662,6 +1668,10 @@ void ToolBarManager::RequestImages()
++pIter;
++i;
}
+
+ assert(!m_aImageController); // an existing one isn't disposed here
+ m_aImageController = new ImageOrientationController(m_xContext, m_xFrame, m_pImpl->GetInterface(), m_aModuleIdentifier);
+ m_aImageController->update();
}
void ToolBarManager::notifyRegisteredControllers( const OUString& aUIElementName, const OUString& aCommand )