[Libreoffice-commits] core.git: svx/inc svx/source

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Tue Jul 28 10:12:23 UTC 2020


 svx/inc/tbxcolorupdate.hxx             |    7 +--
 svx/source/tbxctrls/tbxcolorupdate.cxx |   67 ++++++++-------------------------
 2 files changed, 22 insertions(+), 52 deletions(-)

New commits:
commit f67554d23c2efbdd0e70a8a35a694661ea4e054a
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Mon Jul 27 20:27:23 2020 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Tue Jul 28 12:11:36 2020 +0200

    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
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99561
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/svx/inc/tbxcolorupdate.hxx b/svx/inc/tbxcolorupdate.hxx
index d413b31d9c44..9912ea2db53e 100644
--- a/svx/inc/tbxcolorupdate.hxx
+++ b/svx/inc/tbxcolorupdate.hxx
@@ -70,6 +70,7 @@ namespace svx
         Color       maCurColor;
         tools::Rectangle   maUpdRect;
         Size        maBmpSize;
+        vcl::ImageType meImageType;
         OUString    maCommandLabel;
         OUString    maCommandURL;
         css::uno::Reference<css::frame::XFrame> mxFrame;
@@ -81,7 +82,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
@@ -101,7 +102,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
@@ -119,7 +120,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/tbxcolorupdate.cxx b/svx/source/tbxctrls/tbxcolorupdate.cxx
index 12c25038602f..f716a4e1f7c9 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()


More information about the Libreoffice-commits mailing list