cui/source/inc/cuitabarea.hxx  |   40 +++++++-----
 cui/source/tabpages/tparea.cxx |  133 ++++++++++++++++++-----------------------
 2 files changed, 85 insertions(+), 88 deletions(-)

New commits:
commit 8745219f608a95fa234b7a3028c1152f325e2977
Author:     Michael Weghorn <[email protected]>
AuthorDate: Mon Aug 11 16:23:12 2025 +0200
Commit:     Michael Weghorn <[email protected]>
CommitDate: Tue Aug 12 06:37:33 2025 +0200

    cui: Move some logic to SvxAreaTabPage::SelectFillType
    
    Move logic calling lcl_CreateFillStyleTabPage to
    SvxAreaTabPage::SelectFillType, also in preparation
    of simplifying lcl_CreateFillStyleTabPage in an
    upcoming commit.
    
    Change-Id: Idbe7757e05578d9cb5fe35a7a781881d0a55e7e9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189377
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <[email protected]>

diff --git a/cui/source/inc/cuitabarea.hxx b/cui/source/inc/cuitabarea.hxx
index f1aa5cb90d40..2cb4bc763658 100644
--- a/cui/source/inc/cuitabarea.hxx
+++ b/cui/source/inc/cuitabarea.hxx
@@ -270,7 +270,7 @@ private:
     template< typename TabPage >
     DeactivateRC DeactivatePage_Impl( SfxItemSet* pSet );
 
-    void CreatePage(FillType eFillType, SfxTabPage& rTab);
+    std::unique_ptr<SfxTabPage> CreatePage(FillType eFillType);
 
 public:
     SvxAreaTabPage(weld::Container* pPage, weld::DialogController* pController,
diff --git a/cui/source/tabpages/tparea.cxx b/cui/source/tabpages/tparea.cxx
index 6e4bde99d709..91208b1b12de 100644
--- a/cui/source/tabpages/tparea.cxx
+++ b/cui/source/tabpages/tparea.cxx
@@ -428,12 +428,7 @@ void SvxAreaTabPage::SelectFillType(weld::Toggleable& 
rButton, const SfxItemSet*
     {
         maBox.SelectButton(rButton);
         FillType eFillType = maBox.GetCurrentFillType();
-        m_xFillTabPage = lcl_CreateFillStyleTabPage(eFillType, 
m_xFillTab.get(), GetDialogController(), m_rXFSet);
-        if (m_xFillTabPage)
-        {
-            m_xFillTabPage->SetDialogController(GetDialogController());
-            CreatePage(eFillType, *m_xFillTabPage);
-        }
+        m_xFillTabPage = CreatePage(eFillType);
     }
 }
 
@@ -457,11 +452,18 @@ void SvxAreaTabPage::PageCreated(const SfxAllItemSet& 
aSet)
         SetPatternList(pPatternListItem->GetPatternList());
 }
 
-void SvxAreaTabPage::CreatePage(FillType eFillType, SfxTabPage& rTab)
+std::unique_ptr<SfxTabPage> SvxAreaTabPage::CreatePage(FillType eFillType)
 {
+    std::unique_ptr<SfxTabPage> pTabPage
+        = lcl_CreateFillStyleTabPage(eFillType, m_xFillTab.get(), 
GetDialogController(), m_rXFSet);
+    if (!pTabPage)
+        return nullptr;
+
+    pTabPage->SetDialogController(GetDialogController());
+
     if (eFillType == FillType::SOLID)
     {
-        auto& rColorTab = static_cast<SvxColorTabPage&>(rTab);
+        auto& rColorTab = static_cast<SvxColorTabPage&>(*pTabPage);
         rColorTab.SetColorList(m_pColorList);
         rColorTab.SetColorChgd(m_pnColorListState);
         rColorTab.Construct();
@@ -471,7 +473,7 @@ void SvxAreaTabPage::CreatePage(FillType eFillType, 
SfxTabPage& rTab)
     }
     else if (eFillType == FillType::GRADIENT)
     {
-        auto& rGradientTab = static_cast<SvxGradientTabPage&>(rTab);
+        auto& rGradientTab = static_cast<SvxGradientTabPage&>(*pTabPage);
         rGradientTab.SetColorList(m_pColorList);
         rGradientTab.SetGradientList(m_pGradientList);
         rGradientTab.SetColorChgd(m_pnColorListState);
@@ -482,7 +484,7 @@ void SvxAreaTabPage::CreatePage(FillType eFillType, 
SfxTabPage& rTab)
     }
     else if (eFillType == FillType::HATCH)
     {
-        auto& rHatchTab = static_cast<SvxHatchTabPage&>(rTab);
+        auto& rHatchTab = static_cast<SvxHatchTabPage&>(*pTabPage);
         rHatchTab.SetColorList(m_pColorList);
         rHatchTab.SetHatchingList(m_pHatchingList);
         rHatchTab.SetColorChgd(m_pnColorListState);
@@ -493,7 +495,7 @@ void SvxAreaTabPage::CreatePage(FillType eFillType, 
SfxTabPage& rTab)
     }
     else if (eFillType == FillType::BITMAP)
     {
-        auto& rBitmapTab = static_cast<SvxBitmapTabPage&>(rTab);
+        auto& rBitmapTab = static_cast<SvxBitmapTabPage&>(*pTabPage);
         rBitmapTab.SetBitmapList(m_pBitmapList);
         rBitmapTab.Construct();
         rBitmapTab.ActivatePage(m_rXFSet);
@@ -502,7 +504,7 @@ void SvxAreaTabPage::CreatePage(FillType eFillType, 
SfxTabPage& rTab)
     }
     else if (eFillType == FillType::PATTERN)
     {
-        auto& rPatternTab = static_cast<SvxPatternTabPage&>(rTab);
+        auto& rPatternTab = static_cast<SvxPatternTabPage&>(*pTabPage);
         rPatternTab.SetColorList(m_pColorList);
         rPatternTab.SetPatternList(m_pPatternList);
         rPatternTab.SetColorChgd(m_pnColorListState);
@@ -511,6 +513,8 @@ void SvxAreaTabPage::CreatePage(FillType eFillType, 
SfxTabPage& rTab)
         rPatternTab.Reset(&m_rXFSet);
         rPatternTab.set_visible(true);
     }
+
+    return pTabPage;
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit c4a51dda480fae007995f711116130a7427c379b
Author:     Michael Weghorn <[email protected]>
AuthorDate: Mon Aug 11 15:32:13 2025 +0200
Commit:     Michael Weghorn <[email protected]>
CommitDate: Tue Aug 12 06:37:27 2025 +0200

    cui: Make SvxAreaTabPage::CreatePage private
    
    It's only used internally to initialize a previously
    created tab page.
    
    Change-Id: If537e98a4c4684228b35260503fb3198f9366fb3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189374
    Reviewed-by: Michael Weghorn <[email protected]>
    Tested-by: Jenkins

diff --git a/cui/source/inc/cuitabarea.hxx b/cui/source/inc/cuitabarea.hxx
index 24bea6d56599..f1aa5cb90d40 100644
--- a/cui/source/inc/cuitabarea.hxx
+++ b/cui/source/inc/cuitabarea.hxx
@@ -270,6 +270,8 @@ private:
     template< typename TabPage >
     DeactivateRC DeactivatePage_Impl( SfxItemSet* pSet );
 
+    void CreatePage(FillType eFillType, SfxTabPage& rTab);
+
 public:
     SvxAreaTabPage(weld::Container* pPage, weld::DialogController* pController,
                    const SfxItemSet& rInAttrs, bool bSlideBackground = false);
@@ -296,7 +298,6 @@ public:
     void    SetBitmapList( XBitmapListRef const & pBmpLst) { m_pBitmapList = 
pBmpLst; }
     void    SetPatternList( XPatternListRef const &pPtrnLst ) { m_pPatternList 
= pPtrnLst; }
     virtual void PageCreated(const SfxAllItemSet& aSet) override;
-    void    CreatePage(FillType eFillType, SfxTabPage& rTab);
     void    SetColorChgd( ChangeType* pIn ) { m_pnColorListState = pIn; }
 };
 
commit cb74e3e10c32824e8aca65ccd60ec6e1527c5b96
Author:     Michael Weghorn <[email protected]>
AuthorDate: Mon Aug 11 15:11:08 2025 +0200
Commit:     Michael Weghorn <[email protected]>
CommitDate: Tue Aug 12 06:37:20 2025 +0200

    cui: Make FillType an enum class and use more in SvxAreaTabPage
    
    So far, both the FillType enum and integer types/indices were
    used to handle the fill type, with static_cast to the enum in
    some places.
    
    Switch the enum to an enum class and use it consistently
    for ButtonBox and the SvxAreaTabPage that owns it.
    Stop relying on indices altogether.
    Rename some methods accordingly.
    
    Introduce a new fallback value FillType::INVALID for the
    case where no fill type has been set.
    
    This is used e.g. for the "Area" tab page in Writer's
    "Format" -> "Page Style" dialog.
    
    Change-Id: I1effe0732bd0b334b3b922f2376d2059f99eb55a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189373
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <[email protected]>

diff --git a/cui/source/inc/cuitabarea.hxx b/cui/source/inc/cuitabarea.hxx
index 2fcdca1d628f..24bea6d56599 100644
--- a/cui/source/inc/cuitabarea.hxx
+++ b/cui/source/inc/cuitabarea.hxx
@@ -32,36 +32,45 @@ class ColorListBox;
 class SdrModel;
 class SvxBitmapCtl;
 
-/************************************************************************/
+enum class FillType
+{
+    TRANSPARENT,
+    SOLID,
+    GRADIENT,
+    HATCH,
+    BITMAP,
+    PATTERN,
+    USE_BACKGROUND_FILL,
+    // fallback value if no fill type has been set
+    INVALID,
+};
+
 class ButtonBox
 {
     private:
         weld::Toggleable* mpCurrentButton;
-        std::vector<weld::ToggleButton*> maButtonList;
-        std::map<weld::Toggleable*, sal_Int32 > maButtonToPos;
+        std::map<weld::Toggleable*, FillType > maButtonToFillType;
     public:
         ButtonBox()
             : mpCurrentButton(nullptr) {};
 
-        void AddButton(weld::ToggleButton* pButton)
+        void AddButton(weld::ToggleButton* pButton, FillType eFillType)
         {
-            maButtonList.push_back(pButton);
-            maButtonToPos.insert( std::make_pair(pButton, maButtonList.size() 
- 1) );
+            maButtonToFillType.insert( std::make_pair(pButton, eFillType) );
         }
 
-        sal_Int32 GetCurrentButtonPos() const
+        FillType GetCurrentFillType() const
         {
             if (mpCurrentButton)
-                return GetButtonPos(*mpCurrentButton);
-
-            return -1;
+                return GetFillType(*mpCurrentButton);
+            return FillType::INVALID;
         }
 
-        sal_Int32 GetButtonPos(weld::Toggleable& rButton) const
+        FillType GetFillType(weld::Toggleable& rButton) const
         {
-            std::map<weld::Toggleable*, sal_Int32>::const_iterator aBtnPos = 
maButtonToPos.find(&rButton);
-            assert(aBtnPos != maButtonToPos.end() && "Unknown button");
-            return aBtnPos->second;
+            auto aIt = maButtonToFillType.find(&rButton);
+            assert(aIt != maButtonToFillType.end() && "Unknown button");
+            return aIt->second;
         }
 
         void SelectButton(weld::Toggleable& rButton)
@@ -287,7 +296,7 @@ public:
     void    SetBitmapList( XBitmapListRef const & pBmpLst) { m_pBitmapList = 
pBmpLst; }
     void    SetPatternList( XPatternListRef const &pPtrnLst ) { m_pPatternList 
= pPtrnLst; }
     virtual void PageCreated(const SfxAllItemSet& aSet) override;
-    void    CreatePage(sal_Int32 nId, SfxTabPage& rTab);
+    void    CreatePage(FillType eFillType, SfxTabPage& rTab);
     void    SetColorChgd( ChangeType* pIn ) { m_pnColorListState = pIn; }
 };
 
diff --git a/cui/source/tabpages/tparea.cxx b/cui/source/tabpages/tparea.cxx
index 844c9b2fa646..6e4bde99d709 100644
--- a/cui/source/tabpages/tparea.cxx
+++ b/cui/source/tabpages/tparea.cxx
@@ -33,23 +33,6 @@
 
 using namespace com::sun::star;
 
-// static ----------------------------------------------------------------
-
-namespace {
-
-enum FillType
-{
-    TRANSPARENT,
-    SOLID,
-    GRADIENT,
-    HATCH,
-    BITMAP,
-    PATTERN,
-    USE_BACKGROUND_FILL
-};
-
-}
-
 const WhichRangesContainer SvxAreaTabPage::pAreaRanges(
     svl::Items<
     XATTR_GRADIENTSTEPCOUNT, XATTR_GRADIENTSTEPCOUNT,
@@ -106,12 +89,12 @@ SvxAreaTabPage::SvxAreaTabPage(weld::Container* pPage, 
weld::DialogController* p
     , m_xBtnPattern(m_xBuilder->weld_toggle_button(u"btnpattern"_ustr))
     , 
m_xBtnUseBackground(m_xBuilder->weld_toggle_button(u"btnusebackground"_ustr))
 {
-    maBox.AddButton(m_xBtnNone.get());
-    maBox.AddButton(m_xBtnColor.get());
-    maBox.AddButton(m_xBtnGradient.get());
-    maBox.AddButton(m_xBtnHatch.get());
-    maBox.AddButton(m_xBtnBitmap.get());
-    maBox.AddButton(m_xBtnPattern.get());
+    maBox.AddButton(m_xBtnNone.get(), FillType::TRANSPARENT);
+    maBox.AddButton(m_xBtnColor.get(), FillType::SOLID);
+    maBox.AddButton(m_xBtnGradient.get(), FillType::GRADIENT);
+    maBox.AddButton(m_xBtnHatch.get(), FillType::HATCH);
+    maBox.AddButton(m_xBtnBitmap.get(), FillType::BITMAP);
+    maBox.AddButton(m_xBtnPattern.get(), FillType::PATTERN);
 
     Link<weld::Toggleable&, void> aLink = LINK(this, SvxAreaTabPage, 
SelectFillTypeHdl_Impl);
     m_xBtnNone->connect_toggled(aLink);
@@ -122,7 +105,7 @@ SvxAreaTabPage::SvxAreaTabPage(weld::Container* pPage, 
weld::DialogController* p
     m_xBtnPattern->connect_toggled(aLink);
     if (bSlideBackground)
     {
-        maBox.AddButton(m_xBtnUseBackground.get());
+        maBox.AddButton(m_xBtnUseBackground.get(), 
FillType::USE_BACKGROUND_FILL);
         m_xBtnUseBackground->connect_toggled(aLink);
     }
     else
@@ -240,10 +223,10 @@ DeactivateRC SvxAreaTabPage::DeactivatePage_Impl( 
SfxItemSet* _pSet )
 
 DeactivateRC SvxAreaTabPage::DeactivatePage( SfxItemSet* _pSet )
 {
-    FillType eFillType = static_cast<FillType>(maBox.GetCurrentButtonPos());
+    const FillType eFillType = maBox.GetCurrentFillType();
     switch( eFillType )
     {
-        case TRANSPARENT:
+        case FillType::TRANSPARENT:
         {
             // Fill: None doesn't have its own tabpage and thus
             // implementation of FillItemSet, so we supply it here
@@ -256,17 +239,17 @@ DeactivateRC SvxAreaTabPage::DeactivatePage( SfxItemSet* 
_pSet )
             }
             break;
         }
-        case SOLID:
+        case FillType::SOLID:
             return DeactivatePage_Impl<SvxColorTabPage>(_pSet);
-        case GRADIENT:
+        case FillType::GRADIENT:
             return DeactivatePage_Impl<SvxGradientTabPage>(_pSet);
-        case HATCH:
+        case FillType::HATCH:
             return DeactivatePage_Impl<SvxHatchTabPage>(_pSet);
-        case BITMAP:
+        case FillType::BITMAP:
             return DeactivatePage_Impl<SvxBitmapTabPage&>(_pSet);
-        case PATTERN:
+        case FillType::PATTERN:
             return DeactivatePage_Impl<SvxPatternTabPage>(_pSet);
-        case USE_BACKGROUND_FILL:
+        case FillType::USE_BACKGROUND_FILL:
         {
             if ( m_bBtnClicked )
             {
@@ -306,36 +289,36 @@ OUString SvxAreaTabPage::GetAllStrings()
 
 bool SvxAreaTabPage::FillItemSet( SfxItemSet* rAttrs )
 {
-    FillType eFillType = static_cast<FillType>(maBox.GetCurrentButtonPos());
+    const FillType eFillType = maBox.GetCurrentFillType();
     switch( eFillType )
     {
-        case TRANSPARENT:
+        case FillType::TRANSPARENT:
         {
             rAttrs->Put( XFillStyleItem( drawing::FillStyle_NONE ) );
             rAttrs->Put( XFillUseSlideBackgroundItem( false ) );
             return true;
         }
-        case SOLID:
+        case FillType::SOLID:
         {
             return FillItemSet_Impl<SvxColorTabPage>( rAttrs );
         }
-        case GRADIENT:
+        case FillType::GRADIENT:
         {
             return FillItemSet_Impl<SvxGradientTabPage>( rAttrs );
         }
-        case HATCH:
+        case FillType::HATCH:
         {
             return FillItemSet_Impl<SvxHatchTabPage>( rAttrs );
         }
-        case BITMAP:
+        case FillType::BITMAP:
         {
             return FillItemSet_Impl<SvxBitmapTabPage>( rAttrs );
         }
-        case PATTERN:
+        case FillType::PATTERN:
         {
             return FillItemSet_Impl<SvxPatternTabPage>( rAttrs );
         }
-        case USE_BACKGROUND_FILL:
+        case FillType::USE_BACKGROUND_FILL:
         {
             rAttrs->Put( XFillStyleItem( drawing::FillStyle_NONE ) );
             rAttrs->Put( XFillUseSlideBackgroundItem( true ) );
@@ -355,30 +338,30 @@ void SvxAreaTabPage::Reset_Impl( const SfxItemSet* rAttrs 
)
 void SvxAreaTabPage::Reset( const SfxItemSet* rAttrs )
 {
     m_bBtnClicked = false;
-    auto eFillType = maBox.GetCurrentButtonPos();
+    const FillType eFillType = maBox.GetCurrentFillType();
     switch(eFillType)
     {
-        case SOLID:
+        case FillType::SOLID:
         {
             Reset_Impl<SvxColorTabPage>( rAttrs );
             break;
         }
-        case GRADIENT:
+        case FillType::GRADIENT:
         {
             Reset_Impl<SvxGradientTabPage>( rAttrs );
             break;
         }
-        case HATCH:
+        case FillType::HATCH:
         {
             Reset_Impl<SvxHatchTabPage>( rAttrs );
             break;
         }
-        case BITMAP:
+        case FillType::BITMAP:
         {
             Reset_Impl<SvxBitmapTabPage>( rAttrs );
             break;
         }
-        case PATTERN:
+        case FillType::PATTERN:
         {
             Reset_Impl<SvxPatternTabPage>( rAttrs );
             break;
@@ -412,13 +395,14 @@ std::unique_ptr<SfxTabPage> 
lcl_CreateFillStyleTabPage(FillType eFillType, weld:
     CreateTabPage fnCreate = nullptr;
     switch (eFillType)
     {
-        case TRANSPARENT: fnCreate = nullptr; break;
-        case SOLID: fnCreate = &SvxColorTabPage::Create; break;
-        case GRADIENT: fnCreate = &SvxGradientTabPage::Create; break;
-        case HATCH: fnCreate = &SvxHatchTabPage::Create; break;
-        case BITMAP: fnCreate = &SvxBitmapTabPage::Create; break;
-        case PATTERN: fnCreate = &SvxPatternTabPage::Create; break;
-        case USE_BACKGROUND_FILL: fnCreate = nullptr; break;
+        case FillType::TRANSPARENT: fnCreate = nullptr; break;
+        case FillType::SOLID: fnCreate = &SvxColorTabPage::Create; break;
+        case FillType::GRADIENT: fnCreate = &SvxGradientTabPage::Create; break;
+        case FillType::HATCH: fnCreate = &SvxHatchTabPage::Create; break;
+        case FillType::BITMAP: fnCreate = &SvxBitmapTabPage::Create; break;
+        case FillType::PATTERN: fnCreate = &SvxPatternTabPage::Create; break;
+        case FillType::USE_BACKGROUND_FILL: fnCreate = nullptr; break;
+        default: break;
     }
     return fnCreate ? (*fnCreate)( pPage, pController, &rSet ) : nullptr;
 }
@@ -440,11 +424,10 @@ void SvxAreaTabPage::SelectFillType(weld::Toggleable& 
rButton, const SfxItemSet*
     if (_pSet)
         m_rXFSet.Set(*_pSet);
 
-    sal_Int32 nPos = maBox.GetButtonPos(rButton);
-    if (nPos != -1 && (_pSet || nPos != maBox.GetCurrentButtonPos()))
+    if (_pSet || maBox.GetFillType(rButton) != maBox.GetCurrentFillType())
     {
         maBox.SelectButton(rButton);
-        FillType eFillType = 
static_cast<FillType>(maBox.GetCurrentButtonPos());
+        FillType eFillType = maBox.GetCurrentFillType();
         m_xFillTabPage = lcl_CreateFillStyleTabPage(eFillType, 
m_xFillTab.get(), GetDialogController(), m_rXFSet);
         if (m_xFillTabPage)
         {
@@ -474,9 +457,9 @@ void SvxAreaTabPage::PageCreated(const SfxAllItemSet& aSet)
         SetPatternList(pPatternListItem->GetPatternList());
 }
 
-void SvxAreaTabPage::CreatePage(sal_Int32 nId, SfxTabPage& rTab)
+void SvxAreaTabPage::CreatePage(FillType eFillType, SfxTabPage& rTab)
 {
-    if(nId == SOLID )
+    if (eFillType == FillType::SOLID)
     {
         auto& rColorTab = static_cast<SvxColorTabPage&>(rTab);
         rColorTab.SetColorList(m_pColorList);
@@ -486,7 +469,7 @@ void SvxAreaTabPage::CreatePage(sal_Int32 nId, SfxTabPage& 
rTab)
         rColorTab.Reset(&m_rXFSet);
         rColorTab.set_visible(true);
     }
-    else if(nId == GRADIENT)
+    else if (eFillType == FillType::GRADIENT)
     {
         auto& rGradientTab = static_cast<SvxGradientTabPage&>(rTab);
         rGradientTab.SetColorList(m_pColorList);
@@ -497,7 +480,7 @@ void SvxAreaTabPage::CreatePage(sal_Int32 nId, SfxTabPage& 
rTab)
         rGradientTab.Reset(&m_rXFSet);
         rGradientTab.set_visible(true);
     }
-    else if(nId == HATCH)
+    else if (eFillType == FillType::HATCH)
     {
         auto& rHatchTab = static_cast<SvxHatchTabPage&>(rTab);
         rHatchTab.SetColorList(m_pColorList);
@@ -508,7 +491,7 @@ void SvxAreaTabPage::CreatePage(sal_Int32 nId, SfxTabPage& 
rTab)
         rHatchTab.Reset(&m_rXFSet);
         rHatchTab.set_visible(true);
     }
-    else if(nId == BITMAP)
+    else if (eFillType == FillType::BITMAP)
     {
         auto& rBitmapTab = static_cast<SvxBitmapTabPage&>(rTab);
         rBitmapTab.SetBitmapList(m_pBitmapList);
@@ -517,7 +500,7 @@ void SvxAreaTabPage::CreatePage(sal_Int32 nId, SfxTabPage& 
rTab)
         rBitmapTab.Reset(&m_rXFSet);
         rBitmapTab.set_visible(true);
     }
-    else if(nId == PATTERN)
+    else if (eFillType == FillType::PATTERN)
     {
         auto& rPatternTab = static_cast<SvxPatternTabPage&>(rTab);
         rPatternTab.SetColorList(m_pColorList);

Reply via email to