include/vcl/toolkit/svlbitm.hxx     |   27 ++++++++++-------------
 vcl/source/treelist/svlbitm.cxx     |   41 +++++++++---------------------------
 vcl/source/treelist/treelistbox.cxx |    4 +--
 3 files changed, 25 insertions(+), 47 deletions(-)

New commits:
commit 030446104b44f674b3dc84f9eaaa3aa33b7e572a
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Feb 21 12:22:41 2025 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Fri Feb 21 16:49:38 2025 +0100

    vcl: Use Size instead of width/height in SvLBoxButtonData
    
    Use Size directly instead of retrieving width and height from a Size
    to store them, call the getters for each of them to
    then create a Size object from them again.
    
    Change-Id: I161629b9fb731768010110715b4a78d0288c73e5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181997
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/include/vcl/toolkit/svlbitm.hxx b/include/vcl/toolkit/svlbitm.hxx
index 2590339ec7eb..5e2dd4794da4 100644
--- a/include/vcl/toolkit/svlbitm.hxx
+++ b/include/vcl/toolkit/svlbitm.hxx
@@ -62,8 +62,7 @@ class SvLBoxButtonData
 {
 private:
     Link<SvLBoxButtonData*,void> aLink;
-    tools::Long                    nWidth;
-    tools::Long                    nHeight;
+    Size                    m_aSize;
     bool                    bDataOk;
     std::map<SvBmp, Image> aBmps;
 
@@ -79,8 +78,7 @@ public:
                             ~SvLBoxButtonData();
 
     static SvBmp            GetIndex( SvItemStateFlags nItemState );
-    tools::Long                    Width();
-    tools::Long                    Height();
+    Size                    GetSize();
     void                    SetLink( const Link<SvLBoxButtonData*,void>& 
rLink) { aLink=rLink; }
     bool                    IsRadio() const;
     // as buttons are not derived from LinkHdl
diff --git a/vcl/source/treelist/svlbitm.cxx b/vcl/source/treelist/svlbitm.cxx
index 06f67a12826f..2cbc35b04613 100644
--- a/vcl/source/treelist/svlbitm.cxx
+++ b/vcl/source/treelist/svlbitm.cxx
@@ -33,8 +33,6 @@ SvLBoxButtonData::SvLBoxButtonData(const Control& 
rControlForSettings, bool _bRa
     , m_pBox(nullptr)
     , m_bShowRadioButton(false)
 {
-    nWidth = nHeight = 0;
-
     bDataOk = false;
     m_bShowRadioButton = _bRadioBtn;
 
@@ -70,11 +68,17 @@ SvBmp SvLBoxButtonData::GetIndex( SvItemStateFlags 
nItemState )
     return nIdx;
 }
 
+Size SvLBoxButtonData::GetSize()
+{
+    if (!bDataOk)
+        SetWidthAndHeight();
+
+    return m_aSize;
+}
+
 void SvLBoxButtonData::SetWidthAndHeight()
 {
-    Size aSize = aBmps.at(SvBmp::UNCHECKED).GetSizePixel();
-    nWidth = aSize.Width();
-    nHeight = aSize.Height();
+    m_aSize = aBmps.at(SvBmp::UNCHECKED).GetSizePixel();
     bDataOk = true;
 }
 
@@ -349,7 +353,7 @@ void SvLBoxButton::Paint(
     ControlType eCtrlType = (pData->IsRadio())? ControlType::Radiobutton : 
ControlType::Checkbox;
     if ( rRenderContext.IsNativeControlSupported( eCtrlType, 
ControlPart::Entire) )
     {
-        Size aSize(pData->Width(), pData->Height());
+        Size aSize = pData->GetSize();
         ImplAdjustBoxSize(aSize, eCtrlType, rRenderContext);
         ImplControlValue aControlValue;
         tools::Rectangle aCtrlRegion( rPos, aSize );
@@ -416,7 +420,7 @@ void SvLBoxButton::InitViewData(SvTreeListBox* 
pView,SvTreeListEntry* pEntry, Sv
 {
     if( !pViewData )
         pViewData = pView->GetViewDataItem( pEntry, this );
-    Size aSize( pData->Width(), pData->Height() );
+    Size aSize = pData->GetSize();
 
     ControlType eCtrlType = (pData->IsRadio())? ControlType::Radiobutton : 
ControlType::Checkbox;
     if ( pView )
@@ -511,18 +515,4 @@ std::unique_ptr<SvLBoxItem> 
SvLBoxContextBmp::Clone(SvLBoxItem const * pSource)
     return std::unique_ptr<SvLBoxItem>(pNew.release());
 }
 
-tools::Long SvLBoxButtonData::Width()
-{
-    if ( !bDataOk )
-        SetWidthAndHeight();
-    return nWidth;
-}
-
-tools::Long SvLBoxButtonData::Height()
-{
-    if ( !bDataOk )
-        SetWidthAndHeight();
-    return nHeight;
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit f04a5c65db2e9997c2a42a191cab09de9b1b6bba
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Feb 21 12:13:55 2025 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Fri Feb 21 16:49:29 2025 +0100

    vcl: Drop pointless SvLBoxButtonData::m_bDefaultImages and getter
    
    The member already gets set to `true` in the
    ctor and that value is never changed again after that.
    
    Change-Id: I5e26bf937d6bac757a7f0c1b8a3249e3c2500bc9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181996
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/include/vcl/toolkit/svlbitm.hxx b/include/vcl/toolkit/svlbitm.hxx
index aa6159381f5a..2590339ec7eb 100644
--- a/include/vcl/toolkit/svlbitm.hxx
+++ b/include/vcl/toolkit/svlbitm.hxx
@@ -69,7 +69,6 @@ private:
 
     SvTreeListEntry* m_pEntry;
     SvLBoxButton* m_pBox;
-    bool m_bDefaultImages;
     bool m_bShowRadioButton;
 
     void                    SetWidthAndHeight();
@@ -98,7 +97,6 @@ public:
 
     void                    SetDefaultImages(const Control& 
rControlForSettings);
                                 // set images according to the color scheme of 
the Control
-    bool                    HasDefaultImages() const;
 };
 
 // **********************************************************************
diff --git a/vcl/source/treelist/svlbitm.cxx b/vcl/source/treelist/svlbitm.cxx
index d43ee0b19788..06f67a12826f 100644
--- a/vcl/source/treelist/svlbitm.cxx
+++ b/vcl/source/treelist/svlbitm.cxx
@@ -31,13 +31,11 @@
 SvLBoxButtonData::SvLBoxButtonData(const Control& rControlForSettings, bool 
_bRadioBtn)
     : m_pEntry(nullptr)
     , m_pBox(nullptr)
-    , m_bDefaultImages(false)
     , m_bShowRadioButton(false)
 {
     nWidth = nHeight = 0;
 
     bDataOk = false;
-    m_bDefaultImages = true;
     m_bShowRadioButton = _bRadioBtn;
 
     SetDefaultImages(rControlForSettings);
@@ -138,11 +136,6 @@ void SvLBoxButtonData::SetDefaultImages(const Control& 
rCtrl)
     }
 }
 
-bool SvLBoxButtonData::HasDefaultImages() const
-{
-    return m_bDefaultImages;
-}
-
 bool SvLBoxButtonData::IsRadio() const {
     return m_bShowRadioButton;
 }
diff --git a/vcl/source/treelist/treelistbox.cxx 
b/vcl/source/treelist/treelistbox.cxx
index fa58641c6bfe..7b81eb7c82fe 100644
--- a/vcl/source/treelist/treelistbox.cxx
+++ b/vcl/source/treelist/treelistbox.cxx
@@ -3434,7 +3434,7 @@ void SvTreeListBox::ApplySettings(vcl::RenderContext& 
rRenderContext)
     rRenderContext.SetBackground(rStyleSettings.GetFieldColor());
 
     // always try to re-create default-SvLBoxButtonData
-    if (pCheckButtonData && pCheckButtonData->HasDefaultImages())
+    if (pCheckButtonData)
         pCheckButtonData->SetDefaultImages(*this);
 }
 
@@ -3451,7 +3451,7 @@ void SvTreeListBox::InitSettings()
     SetBackground(rStyleSettings.GetFieldColor());
 
     // always try to re-create default-SvLBoxButtonData
-    if( pCheckButtonData && pCheckButtonData->HasDefaultImages() )
+    if( pCheckButtonData)
         pCheckButtonData->SetDefaultImages(*this);
 }
 
commit 5b470b2ec4bcef2b295a9a16c8193a02da00f96d
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Feb 21 12:04:05 2025 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Fri Feb 21 16:49:23 2025 +0100

    vcl: Use a std::map for SvLBoxButtonData::aBmps
    
    ... instead of using a std::vector and casting
    the SvBmp enum class values to/from int.
    
    Drop the specific int values for the enum values
    as they are no longer relevant.
    
    Change-Id: I521970cd6f5c31934dc7376910124284f020974e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181995
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/include/vcl/toolkit/svlbitm.hxx b/include/vcl/toolkit/svlbitm.hxx
index 87ac3c9ee88b..aa6159381f5a 100644
--- a/include/vcl/toolkit/svlbitm.hxx
+++ b/include/vcl/toolkit/svlbitm.hxx
@@ -23,6 +23,7 @@
 #error "don't use this in new code"
 #endif
 
+#include <map>
 #include <memory>
 #include <vcl/dllapi.h>
 #include <tools/link.hxx>
@@ -36,12 +37,12 @@ class SvLBoxButton;
 
 enum class SvBmp
 {
-    UNCHECKED        = 0,
-    CHECKED          = 1,
-    TRISTATE         = 2,
-    HIUNCHECKED      = 3,
-    HICHECKED        = 4,
-    HITRISTATE       = 5
+    UNCHECKED,
+    CHECKED,
+    TRISTATE,
+    HIUNCHECKED,
+    HICHECKED,
+    HITRISTATE,
 };
 
 enum class SvItemStateFlags
@@ -64,7 +65,7 @@ private:
     tools::Long                    nWidth;
     tools::Long                    nHeight;
     bool                    bDataOk;
-    std::vector<Image>      aBmps;  // indices s. constants BMP_...
+    std::map<SvBmp, Image> aBmps;
 
     SvTreeListEntry* m_pEntry;
     SvLBoxButton* m_pBox;
@@ -92,8 +93,8 @@ public:
     SvTreeListEntry*        GetActEntry() const;
     SvLBoxButton*           GetActBox() const;
 
-    void                    SetImage(SvBmp nIndex, const Image& aImage) { 
aBmps[static_cast<int>(nIndex)] = aImage; }
-    Image&                  GetImage(SvBmp nIndex) { return 
aBmps[static_cast<int>(nIndex)]; }
+    void                    SetImage(SvBmp eIndex, const Image& aImage) { 
aBmps[eIndex] = aImage; }
+    Image&                  GetImage(SvBmp eIndex) { return aBmps.at(eIndex); }
 
     void                    SetDefaultImages(const Control& 
rControlForSettings);
                                 // set images according to the color scheme of 
the Control
diff --git a/vcl/source/treelist/svlbitm.cxx b/vcl/source/treelist/svlbitm.cxx
index 13b8d6d8be53..d43ee0b19788 100644
--- a/vcl/source/treelist/svlbitm.cxx
+++ b/vcl/source/treelist/svlbitm.cxx
@@ -36,8 +36,6 @@ SvLBoxButtonData::SvLBoxButtonData(const Control& 
rControlForSettings, bool _bRa
 {
     nWidth = nHeight = 0;
 
-    aBmps.resize(int(SvBmp::HITRISTATE)+1);
-
     bDataOk = false;
     m_bDefaultImages = true;
     m_bShowRadioButton = _bRadioBtn;
@@ -76,7 +74,7 @@ SvBmp SvLBoxButtonData::GetIndex( SvItemStateFlags nItemState 
)
 
 void SvLBoxButtonData::SetWidthAndHeight()
 {
-    Size aSize = aBmps[int(SvBmp::UNCHECKED)].GetSizePixel();
+    Size aSize = aBmps.at(SvBmp::UNCHECKED).GetSizePixel();
     nWidth = aSize.Width();
     nHeight = aSize.Height();
     bDataOk = true;

Reply via email to