include/svx/SvxColorValueSet.hxx         |    2 +-
 svx/source/tbxctrls/SvxColorValueSet.cxx |    8 +++++---
 svx/source/tbxctrls/colrctrl.cxx         |   18 ++++++++++--------
 3 files changed, 16 insertions(+), 12 deletions(-)

New commits:
commit f231f43422a577e4df65d670ab4e74c38198e70b
Author:     Michael Weghorn <[email protected]>
AuthorDate: Thu Feb 5 13:27:45 2026 +0100
Commit:     Michael Weghorn <[email protected]>
CommitDate: Thu Feb 5 16:00:51 2026 +0100

    svx: Drop start index param for SvxColorValueSet::addEntriesForXColorList
    
    Previous commit
    
        Change-Id: I5da60fbe58ba947a8f6d8c44ce56df488a556d0f
        Author: Michael Weghorn <[email protected]>
        Date:   Thu Feb 5 13:17:53 2026 +0100
    
            svx: Use ascending ValueSet IDs in SvxColorDockingWindow
    
    dropped the only use that was passing a non-default
    value for the param.
    
    Therefore, drop the param and always use a start index/ID
    of 1. This also aligns this more with
    SvxColorValueSet::addEntriesForColorSet.
    
    Change-Id: Ife76653a57fa746ddc8dfef8bb3d5345d351765a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198752
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <[email protected]>

diff --git a/include/svx/SvxColorValueSet.hxx b/include/svx/SvxColorValueSet.hxx
index 011e1c6c4811..10076027c356 100644
--- a/include/svx/SvxColorValueSet.hxx
+++ b/include/svx/SvxColorValueSet.hxx
@@ -38,7 +38,7 @@ public:
     static sal_uInt32 getEntryEdgeLength();
     static sal_uInt32 getColumnCount();
 
-    void addEntriesForXColorList(const XColorList& rXColorList, sal_uInt32 
nStartIndex = 1);
+    void addEntriesForXColorList(const XColorList& rXColorList);
     void addEntriesForColorSet(const std::set<Color>& rColorSet, 
std::u16string_view rNamePrefix);
     Size layoutAllVisible(sal_uInt32 nEntryCount);
     void layoutToGivenHeight(sal_uInt32 nHeight, sal_uInt32 nEntryCount);
diff --git a/svx/source/tbxctrls/SvxColorValueSet.cxx 
b/svx/source/tbxctrls/SvxColorValueSet.cxx
index ca65798f9a34..737b0ab93874 100644
--- a/svx/source/tbxctrls/SvxColorValueSet.cxx
+++ b/svx/source/tbxctrls/SvxColorValueSet.cxx
@@ -50,17 +50,19 @@ sal_uInt32 SvxColorValueSet::getColumnCount()
     return rStyleSettings.GetColorValueSetColumnCount();
 }
 
-void SvxColorValueSet::addEntriesForXColorList(const XColorList& rXColorList, 
sal_uInt32 nStartIndex)
+void SvxColorValueSet::addEntriesForXColorList(const XColorList& rXColorList)
 {
     const sal_uInt32 nColorCount(rXColorList.Count());
 
-    for(sal_uInt32 nIndex(0); nIndex < nColorCount; nIndex++, nStartIndex++)
+    sal_uInt32 nId = 1;
+    for (sal_uInt32 nIndex = 0; nIndex < nColorCount; nIndex++)
     {
         const XColorEntry* pEntry = rXColorList.GetColor(nIndex);
 
         if(pEntry)
         {
-            InsertItem(nStartIndex, pEntry->GetColor(), pEntry->GetName());
+            InsertItem(nId, pEntry->GetColor(), pEntry->GetName());
+            nId++;
         }
         else
         {
commit 7d1c78fd5dfbbb6249907624cc840953e25352bf
Author:     Michael Weghorn <[email protected]>
AuthorDate: Thu Feb 5 13:17:53 2026 +0100
Commit:     Michael Weghorn <[email protected]>
CommitDate: Thu Feb 5 16:00:43 2026 +0100

    svx: Use ascending ValueSet IDs in SvxColorDockingWindow
    
    Instead of letting the IDs for the "normal" colors
    in SvxColorDockingWindow start with 2 when inserting
    the entries into the color set in
    SvxColorDockingWindow::FillValueSet, let them start
    with 1 and don't use the special ID of 1 for the
    "none/invisible" entry, but simply give it an ID
    matching the item count, i.e. one greater than the
    last "normal" entry.
    
    This replaces the only use of
    SvxColorValueSet::addEntriesForXColorList passing
    a start index differing from the default one, and
    also aligns the IDs more with how indices are
    used in other controls like weld::IconView (and
    would therefore e.g. simplify switching to that one
    in an upcoming commit, which I'm currently evaluating).
    
    The now always default SvxColorValueSet::addEntriesForColorSet
    param will be dropped in an upcoming commit, which
    will also align that method more with
    SvxColorValueSet::addEntriesForColorSet.
    
    Sample scenario triggering the code path:
    
    * start Draw
    * insert a shape
    * enable the color bar via "View" -> "Color Bar"
    * with the shape selected, click on one of the
      colors in the color bar
    
    Change-Id: I5da60fbe58ba947a8f6d8c44ce56df488a556d0f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198751
    Reviewed-by: Michael Weghorn <[email protected]>
    Tested-by: Jenkins

diff --git a/svx/source/tbxctrls/colrctrl.cxx b/svx/source/tbxctrls/colrctrl.cxx
index 457a2c90b008..fa16afa2dcf9 100644
--- a/svx/source/tbxctrls/colrctrl.cxx
+++ b/svx/source/tbxctrls/colrctrl.cxx
@@ -158,9 +158,9 @@ bool SvxColorValueSet_docking::StartDrag()
     Color aItemColor( GetItemColor( nPos ) );
     OUString sItemText( GetItemText( nPos ) );
 
-    drawing::FillStyle eStyle = ((1 == nPos)
+    drawing::FillStyle eStyle = (nPos == GetItemCount())
                             ? drawing::FillStyle_NONE
-                            : drawing::FillStyle_SOLID);
+                            : drawing::FillStyle_SOLID;
 
     XFillColorItem const color(sItemText, aItemColor);
     XFillStyleItem const style(eStyle);
@@ -263,7 +263,7 @@ void SvxColorDockingWindow::FillValueSet()
 
     xColorSet->Clear();
 
-    xColorSet->addEntriesForXColorList(*pColorList, 2);
+    xColorSet->addEntriesForXColorList(*pColorList);
 
     // create the last entry for 'invisible/none'
     const Size aColorSize(SvxColorValueSet::getEntryEdgeLength(), 
SvxColorValueSet::getEntryEdgeLength());
@@ -279,7 +279,7 @@ void SvxColorDockingWindow::FillValueSet()
 
     Bitmap aBmp( pVD->GetBitmap( Point(), aColorSize ) );
 
-    xColorSet->InsertItem( sal_uInt16(1), Image(aBmp), SvxResId( 
RID_SVXSTR_INVISIBLE ) );
+    xColorSet->InsertItem(xColorSet->GetItemCount() + 1, Image(aBmp), 
SvxResId(RID_SVXSTR_INVISIBLE));
 }
 
 bool SvxColorDockingWindow::Close()
@@ -298,11 +298,13 @@ IMPL_LINK_NOARG(SvxColorDockingWindow, SelectHdl, 
ValueSet*, void)
     Color  aColor( xColorSet->GetItemColor( nPos ) );
     OUString aStr( xColorSet->GetItemText( nPos ) );
 
+    // ID of 'invisible/none' entry, see SvxColorDockingWindow::FillValueSet
+    const sal_uInt16 nIdNone = xColorSet->GetItemCount();
     if (xColorSet->IsLeftButton())
     {
         if ( gnLeftSlot == SID_ATTR_FILL_COLOR )
         {
-            if ( nPos == 1 )        // invisible
+            if (nPos == nIdNone)
             {
                 XFillStyleItem aXFillStyleItem( drawing::FillStyle_NONE );
                 pDispatcher->ExecuteList(gnLeftSlot, SfxCallMode::RECORD,
@@ -335,7 +337,7 @@ IMPL_LINK_NOARG(SvxColorDockingWindow, SelectHdl, 
ValueSet*, void)
                 }
             }
         }
-        else if ( nPos != 1 )       // invisible
+        else if (nPos != nIdNone)
         {
             SvxColorItem aLeftColorItem( aColor, gnLeftSlot );
             pDispatcher->ExecuteList(gnLeftSlot, SfxCallMode::RECORD,
@@ -346,7 +348,7 @@ IMPL_LINK_NOARG(SvxColorDockingWindow, SelectHdl, 
ValueSet*, void)
     {
         if ( gnRightSlot == SID_ATTR_LINE_COLOR )
         {
-            if( nPos == 1 )     // invisible
+            if (nPos == nIdNone)
             {
                 XLineStyleItem aXLineStyleItem( drawing::LineStyle_NONE );
                 pDispatcher->ExecuteList(gnRightSlot, SfxCallMode::RECORD,
@@ -382,7 +384,7 @@ IMPL_LINK_NOARG(SvxColorDockingWindow, SelectHdl, 
ValueSet*, void)
                         { &aXLineColorItem });
             }
         }
-        else if ( nPos != 1 )       // invisible
+        else if (nPos != nIdNone)
         {
             SvxColorItem aRightColorItem( aColor, gnRightSlot );
             pDispatcher->ExecuteList(gnRightSlot, SfxCallMode::RECORD,

Reply via email to