summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorMaxim Monastirsky <momonasmon@gmail.com>2023-07-02 17:31:38 +0300
committerXisco Fauli <xiscofauli@libreoffice.org>2023-09-06 09:37:18 +0200
commit1345619e0b3c2825c2ae50ada2c209d4ad8461ad (patch)
tree6c3c5166ed8e8912e79b6a39d1fae3b228fbe68a /svx
parente233f4616d6a6b7ca54e3028f77bdee4061bbfab (diff)
tdf#154270 Sync toolbar button recent colors
As the last used color is stored per button instance, these will go out of sync with several buttons being visible (e.g. a toolbar and a sidebar, or a toolbar overflow popup), and will reset whenever the toolbar resets (e.g. change in selection, switch from print preview, or customization). Fix that by storing the last colors per-document, and notifying other buttons on changes. Keep the last color also stored per-button for now, as a fallback for reportdesign (which isn't sfx2 based). Change-Id: I866f1de5c8ff6f56c47dc4b6b5acf52957d4e6c5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153943 Tested-by: Jenkins Reviewed-by: Maxim Monastirsky <momonasmon@gmail.com> Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156519
Diffstat (limited to 'svx')
-rw-r--r--svx/inc/tbxcolorupdate.hxx8
-rw-r--r--svx/source/tbxctrls/PaletteManager.cxx9
-rw-r--r--svx/source/tbxctrls/tbcontrl.cxx15
-rw-r--r--svx/source/tbxctrls/tbxcolorupdate.cxx57
4 files changed, 62 insertions, 27 deletions
diff --git a/svx/inc/tbxcolorupdate.hxx b/svx/inc/tbxcolorupdate.hxx
index 81aa1c9c12fb..075c7b28dde7 100644
--- a/svx/inc/tbxcolorupdate.hxx
+++ b/svx/inc/tbxcolorupdate.hxx
@@ -25,6 +25,7 @@
#include <vcl/vclptr.hxx>
#include <vcl/toolbox.hxx>
#include <vcl/toolboxid.hxx>
+#include <svl/lstner.hxx>
#include <svx/Palette.hxx>
#include <com/sun/star/drawing/LineStyle.hpp>
#include <com/sun/star/frame/FeatureStateEvent.hpp>
@@ -48,15 +49,17 @@ namespace svx
formerly known as SvxTbxButtonColorUpdater_Impl, residing in svx/source/tbxctrls/colorwindow.hxx.
*/
- class ToolboxButtonColorUpdaterBase
+ class ToolboxButtonColorUpdaterBase : public SfxListener
{
public:
ToolboxButtonColorUpdaterBase(bool bWideButton, OUString aCommandLabel,
- OUString aCommandURL,
+ OUString aCommandURL, sal_uInt16 nSlotId,
css::uno::Reference<css::frame::XFrame> xFrame);
virtual ~ToolboxButtonColorUpdaterBase();
+ void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override;
+ void SetRecentColor(const NamedColor& rNamedColor);
void Update( const NamedColor& rNamedColor );
void Update( const Color& rColor, bool bForceUpdate = false );
Color const & GetCurrentColor() const { return maCurColor; }
@@ -69,6 +72,7 @@ namespace svx
protected:
bool mbWideButton;
bool mbWasHiContrastMode;
+ sal_uInt16 mnSlotId;
Color maCurColor;
tools::Rectangle maUpdRect;
Size maBmpSize;
diff --git a/svx/source/tbxctrls/PaletteManager.cxx b/svx/source/tbxctrls/PaletteManager.cxx
index 343448c8e788..1a48c403feb2 100644
--- a/svx/source/tbxctrls/PaletteManager.cxx
+++ b/svx/source/tbxctrls/PaletteManager.cxx
@@ -382,6 +382,12 @@ void PaletteManager::AddRecentColor(const Color& rRecentColor, const OUString& r
batch->commit();
}
+void PaletteManager::SetSplitButtonColor(const NamedColor& rColor)
+{
+ if (mpBtnUpdater)
+ mpBtnUpdater->SetRecentColor(rColor);
+}
+
void PaletteManager::SetBtnUpdater(svx::ToolboxButtonColorUpdaterBase* pBtnUpdater)
{
mpBtnUpdater = pBtnUpdater;
@@ -405,8 +411,7 @@ void PaletteManager::PopupColorPicker(weld::Window* pParent, const OUString& aCo
Color aLastColor = m_pColorDlg->GetColor();
OUString sColorName = "#" + aLastColor.AsRGBHexString().toAsciiUpperCase();
NamedColor aNamedColor(aLastColor, sColorName);
- if (mpBtnUpdater)
- mpBtnUpdater->Update(aNamedColor);
+ SetSplitButtonColor(aNamedColor);
AddRecentColor(aLastColor, sColorName);
maColorSelectFunction(aCommandCopy, aNamedColor);
}
diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx
index eb7ab2e61410..06cefd08062a 100644
--- a/svx/source/tbxctrls/tbcontrl.cxx
+++ b/svx/source/tbxctrls/tbcontrl.cxx
@@ -2226,7 +2226,7 @@ IMPL_LINK(ColorWindow, SelectHdl, ValueSet*, pColorSet, void)
mxPaletteManager->ReloadRecentColorSet(*mxRecentColorSet);
}
- maSelectedLink.Call(aNamedColor);
+ mxPaletteManager->SetSplitButtonColor(aNamedColor);
// deliberate take a copy here in case maMenuButton.set_inactive
// triggers a callback that destroys ourself
@@ -2272,7 +2272,7 @@ IMPL_LINK(ColorWindow, AutoColorClickHdl, weld::Button&, rButton, void)
mxRecentColorSet->SetNoSelection();
mpDefaultButton = &rButton;
- maSelectedLink.Call(aNamedColor);
+ mxPaletteManager->SetSplitButtonColor(aNamedColor);
// deliberate take a copy here in case maMenuButton.set_inactive
// triggers a callback that destroys ourself
@@ -3636,9 +3636,6 @@ std::unique_ptr<WeldToolbarPopup> SvxColorToolBoxControl::weldPopupWindow()
[this] { return GetParentFrame(); },
m_aColorSelectFunction);
- if ( m_bSplitButton )
- xPopover->SetSelectedHdl( LINK( this, SvxColorToolBoxControl, SelectedHdl ) );
-
return xPopover;
}
@@ -3661,9 +3658,6 @@ VclPtr<vcl::Window> SvxColorToolBoxControl::createVclPopupWindow( vcl::Window* p
[this] { return GetParentFrame(); },
m_aColorSelectFunction);
- if ( m_bSplitButton )
- xPopover->SetSelectedHdl( LINK( this, SvxColorToolBoxControl, SelectedHdl ) );
-
mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent,
std::move(xPopover), true);
@@ -3676,11 +3670,6 @@ VclPtr<vcl::Window> SvxColorToolBoxControl::createVclPopupWindow( vcl::Window* p
return mxInterimPopover;
}
-IMPL_LINK(SvxColorToolBoxControl, SelectedHdl, const NamedColor&, rColor, void)
-{
- m_xBtnUpdater->Update(rColor);
-}
-
void SvxColorToolBoxControl::statusChanged( const css::frame::FeatureStateEvent& rEvent )
{
ToolBox* pToolBox = nullptr;
diff --git a/svx/source/tbxctrls/tbxcolorupdate.cxx b/svx/source/tbxctrls/tbxcolorupdate.cxx
index 7a27b5a12f8e..edd835736268 100644
--- a/svx/source/tbxctrls/tbxcolorupdate.cxx
+++ b/svx/source/tbxctrls/tbxcolorupdate.cxx
@@ -17,6 +17,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sfx2/sfxbasemodel.hxx>
#include <sfx2/objsh.hxx>
#include <svx/drawitem.hxx>
#include <tbxcolorupdate.hxx>
@@ -40,10 +41,11 @@
namespace svx
{
ToolboxButtonColorUpdaterBase::ToolboxButtonColorUpdaterBase(bool bWideButton, OUString aCommandLabel,
- OUString aCommandURL,
+ OUString aCommandURL, sal_uInt16 nSlotId,
css::uno::Reference<css::frame::XFrame> xFrame)
: mbWideButton(bWideButton)
, mbWasHiContrastMode(Application::GetSettings().GetStyleSettings().GetHighContrastMode())
+ , mnSlotId(nSlotId)
, maCurColor(COL_TRANSPARENT)
, meImageType(vcl::ImageType::Size16)
, maCommandLabel(std::move(aCommandLabel))
@@ -54,6 +56,23 @@ namespace svx
void ToolboxButtonColorUpdaterBase::Init(sal_uInt16 nSlotId)
{
+ if (mbWideButton)
+ {
+ Update(COL_TRANSPARENT, true);
+ return;
+ }
+
+ if (rtl::Reference xModel = dynamic_cast<SfxBaseModel*>(mxFrame->getController()->getModel().get()))
+ {
+ auto pDocSh = xModel->GetObjectShell();
+ StartListening(*pDocSh);
+ if (auto oColor = pDocSh->GetRecentColor(nSlotId))
+ {
+ Update(*oColor);
+ return;
+ }
+ }
+
switch (nSlotId)
{
case SID_ATTR_CHAR_COLOR:
@@ -80,11 +99,32 @@ namespace svx
}
}
+ void ToolboxButtonColorUpdaterBase::Notify(SfxBroadcaster& rBC, const SfxHint& rHint)
+ {
+ if (rHint.GetId() == SfxHintId::Dying)
+ {
+ EndListeningAll();
+ }
+ else if (rHint.GetId() == SfxHintId::ColorsChanged)
+ {
+ if (auto oColor = static_cast<SfxObjectShell&>(rBC).GetRecentColor(mnSlotId))
+ Update(*oColor);
+ }
+ }
+
+ void ToolboxButtonColorUpdaterBase::SetRecentColor(const NamedColor &rNamedColor)
+ {
+ if (rtl::Reference xModel = dynamic_cast<SfxBaseModel*>(mxFrame->getController()->getModel().get()))
+ xModel->GetObjectShell()->SetRecentColor(mnSlotId, rNamedColor);
+ else if (!mbWideButton)
+ Update(rNamedColor);
+ }
+
VclToolboxButtonColorUpdater::VclToolboxButtonColorUpdater(
sal_uInt16 nSlotId, ToolBoxItemId nTbxBtnId, ToolBox* pToolBox, bool bWideButton,
const OUString& rCommandLabel, const OUString& rCommandURL,
const css::uno::Reference<css::frame::XFrame>& rFrame)
- : ToolboxButtonColorUpdaterBase(bWideButton, rCommandLabel, rCommandURL, rFrame)
+ : ToolboxButtonColorUpdaterBase(bWideButton, rCommandLabel, rCommandURL, nSlotId, rFrame)
, mnBtnId(nTbxBtnId)
, mpTbx(pToolBox)
{
@@ -138,14 +178,11 @@ namespace svx
void ToolboxButtonColorUpdaterBase::Update(const NamedColor &rNamedColor)
{
Update(rNamedColor.m_aColor);
- if (!mbWideButton)
- {
- // Also show the current color as QuickHelpText
- OUString colorSuffix = OUString(" (%1)").replaceFirst("%1", rNamedColor.m_aName);
- OUString colorHelpText = maCommandLabel + colorSuffix;
- SetQuickHelpText(colorHelpText);
- }
+ // Also show the current color as QuickHelpText
+ OUString colorSuffix = OUString(" (%1)").replaceFirst("%1", rNamedColor.m_aName);
+ OUString colorHelpText = maCommandLabel + colorSuffix;
+ SetQuickHelpText(colorHelpText);
}
void ToolboxButtonColorUpdaterBase::Update(const Color& rColor, bool bForceUpdate)
@@ -250,7 +287,7 @@ namespace svx
ToolboxButtonColorUpdater::ToolboxButtonColorUpdater(sal_uInt16 nSlotId, const OUString& rTbxBtnId, weld::Toolbar* ptrTbx, bool bWideButton,
const OUString& rCommandLabel, const css::uno::Reference<css::frame::XFrame>& rFrame)
- : ToolboxButtonColorUpdaterBase(bWideButton, rCommandLabel, rTbxBtnId, rFrame)
+ : ToolboxButtonColorUpdaterBase(bWideButton, rCommandLabel, rTbxBtnId, nSlotId, rFrame)
, msBtnId(rTbxBtnId)
, mpTbx(ptrTbx)
{