summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2020-07-27 20:27:23 +0100
committerCaolán McNamara <caolanm@redhat.com>2020-07-28 12:12:19 +0200
commitd6d1c3c0a0a64170feb458cf6d00a8660700e0be (patch)
treebe3c75700dbff131068e5919ebdcb1986d6daaaa
parent6bb924a5d2b48336bbae47244210bbc78763b2ed (diff)
tdf#135121 ImageType::Size26 isn't always 26x26px
so use ImageType just to detect the user has selected a new size, and use the size of the returned image for the icon pixel size Change-Id: If101c586bd2f0d83f668637b48ce3d25a0873358 Related: tdf#135121 update widebuttons on icon-size change too as well as the split-buttons. We don't draw into the icon for widebuttons, but we do need to draw the icon into the replacement wider image so we want to update for widebuttons too Change-Id: Ia37f7de7faa08e63a498ff474a46a98566930acd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99576 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--include/svx/tbxcolorupdate.hxx7
-rw-r--r--svx/source/tbxctrls/tbcontrl.cxx8
-rw-r--r--svx/source/tbxctrls/tbxcolorupdate.cxx67
3 files changed, 26 insertions, 56 deletions
diff --git a/include/svx/tbxcolorupdate.hxx b/include/svx/tbxcolorupdate.hxx
index 1c2ff45e185a..5a7e64c22bfd 100644
--- a/include/svx/tbxcolorupdate.hxx
+++ b/include/svx/tbxcolorupdate.hxx
@@ -73,6 +73,7 @@ namespace svx
Color maCurColor;
tools::Rectangle maUpdRect;
Size maBmpSize;
+ vcl::ImageType meImageType;
OUString maCommandLabel;
OUString maCommandURL;
css::uno::Reference<css::frame::XFrame> mxFrame;
@@ -84,7 +85,7 @@ namespace svx
virtual void SetImage(VirtualDevice* pVirDev) = 0;
virtual VclPtr<VirtualDevice> CreateVirtualDevice() const = 0;
virtual vcl::ImageType GetImageSize() const = 0;
- virtual Size GetItemSize() const = 0;
+ virtual Size GetItemSize(const Size& rImageSize) const = 0;
};
class VclToolboxButtonColorUpdater : public ToolboxButtonColorUpdaterBase
@@ -104,7 +105,7 @@ namespace svx
virtual void SetImage(VirtualDevice* pVirDev) override;
virtual VclPtr<VirtualDevice> CreateVirtualDevice() const override;
virtual vcl::ImageType GetImageSize() const override;
- virtual Size GetItemSize() const override;
+ virtual Size GetItemSize(const Size& rImageSize) const override;
};
class ToolboxButtonColorUpdater : public ToolboxButtonColorUpdaterBase
@@ -122,7 +123,7 @@ namespace svx
virtual void SetImage(VirtualDevice* pVirDev) override;
virtual VclPtr<VirtualDevice> CreateVirtualDevice() const override;
virtual vcl::ImageType GetImageSize() const override;
- virtual Size GetItemSize() const override;
+ virtual Size GetItemSize(const Size& rImageSize) const override;
};
class ToolboxButtonLineStyleUpdater
diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx
index d64e033d6823..25f13f6fb214 100644
--- a/svx/source/tbxctrls/tbcontrl.cxx
+++ b/svx/source/tbxctrls/tbcontrl.cxx
@@ -3350,10 +3350,10 @@ void SvxColorToolBoxControl::execute(sal_Int16 /*nSelectModifier*/)
sal_Bool SvxColorToolBoxControl::opensSubToolbar()
{
- // For a split button, we mark this controller as a sub-toolbar controller,
- // so we get notified (through updateImage method) on button image changes,
- // and could redraw the last used color on top of it.
- return m_bSplitButton;
+ // We mark this controller as a sub-toolbar controller, so we get notified
+ // (through updateImage method) on button image changes, and could redraw
+ // the last used color on top of it.
+ return true;
}
void SvxColorToolBoxControl::updateImage()
diff --git a/svx/source/tbxctrls/tbxcolorupdate.cxx b/svx/source/tbxctrls/tbxcolorupdate.cxx
index f21ad6b9c0d0..f84cda150837 100644
--- a/svx/source/tbxctrls/tbxcolorupdate.cxx
+++ b/svx/source/tbxctrls/tbxcolorupdate.cxx
@@ -43,6 +43,7 @@ namespace svx
: mbWideButton(bWideButton)
, mbWasHiContrastMode(Application::GetSettings().GetStyleSettings().GetHighContrastMode())
, maCurColor(COL_TRANSPARENT)
+ , meImageType(vcl::ImageType::Size16)
, maCommandLabel(rCommandLabel)
, maCommandURL(rCommandURL)
, mxFrame(rFrame)
@@ -116,26 +117,11 @@ namespace svx
return mpTbx->GetImageSize();
}
- Size VclToolboxButtonColorUpdater::GetItemSize() const
+ Size VclToolboxButtonColorUpdater::GetItemSize(const Size& rImageSize) const
{
if (mbWideButton)
return mpTbx->GetItemContentSize(mnBtnId);
- vcl::ImageType eImageType = GetImageSize();
- int nHeight(16);
- switch (eImageType)
- {
- case vcl::ImageType::Size16:
- nHeight = 16;
- break;
- case vcl::ImageType::Size26:
- nHeight = 26;
- break;
- case vcl::ImageType::Size32:
- nHeight = 32;
- break;
- }
- int nWidth = nHeight;
- return Size(nWidth, nHeight);
+ return rImageSize;
}
ToolboxButtonColorUpdaterBase::~ToolboxButtonColorUpdaterBase()
@@ -156,22 +142,14 @@ namespace svx
void ToolboxButtonColorUpdaterBase::Update(const Color& rColor, bool bForceUpdate)
{
- Size aItemSize(GetItemSize());
+ vcl::ImageType eImageType = GetImageSize();
#ifdef IOS // tdf#126966
- // Oddly enough, it is in the "not wide button" case that we want the larger ones, hmm.
- if (!mbWideButton)
- {
- // usually the normal size is 16
- const long nIOSSize = 32;
- if (aItemSize.getWidth() < nIOSSize)
- {
- aItemSize.setWidth(nIOSSize);
- aItemSize.setHeight(nIOSSize);
- }
- }
+ eImageType = vcl::ImageType::Size32;
#endif
- const bool bSizeChanged = (maBmpSize != aItemSize);
+
+ const bool bSizeChanged = (meImageType != eImageType);
+ meImageType = eImageType;
const bool bDisplayModeChanged = (mbWasHiContrastMode != Application::GetSettings().GetStyleSettings().GetHighContrastMode());
Color aColor(rColor);
@@ -182,6 +160,10 @@ namespace svx
if ((maCurColor == aColor) && !bSizeChanged && !bDisplayModeChanged && !bForceUpdate)
return;
+ auto xImage = vcl::CommandInfoProvider::GetXGraphicForCommand(maCommandURL, mxFrame, meImageType);
+ Image aImage(xImage);
+
+ Size aItemSize = GetItemSize(aImage.GetSizePixel());
if (!aItemSize.Width() || !aItemSize.Height())
return;
@@ -189,8 +171,7 @@ namespace svx
pVirDev->SetOutputSizePixel(aItemSize);
maBmpSize = aItemSize;
- auto xImage = vcl::CommandInfoProvider::GetXGraphicForCommand(maCommandURL, mxFrame, GetImageSize());
- pVirDev->DrawImage(Point(0, 0), Image(xImage));
+ pVirDev->DrawImage(Point(0, 0), aImage);
const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
mbWasHiContrastMode = rStyleSettings.GetHighContrastMode();
@@ -272,24 +253,12 @@ namespace svx
return mpTbx->get_icon_size();
}
- Size ToolboxButtonColorUpdater::GetItemSize() const
+ Size ToolboxButtonColorUpdater::GetItemSize(const Size& rImageSize) const
{
- vcl::ImageType eImageType = GetImageSize();
- int nHeight(16);
- switch (eImageType)
- {
- case vcl::ImageType::Size16:
- nHeight = 16;
- break;
- case vcl::ImageType::Size26:
- nHeight = 26;
- break;
- case vcl::ImageType::Size32:
- nHeight = 32;
- break;
- }
- int nWidth = mbWideButton ? nHeight * 5 : nHeight;
- return Size(nWidth, nHeight);
+ auto nWidth = rImageSize.Width();
+ if (mbWideButton)
+ nWidth = nWidth * 5;
+ return Size(nWidth, rImageSize.Height());
}
ToolboxButtonLineStyleUpdater::ToolboxButtonLineStyleUpdater()