include/vcl/toolkit/ivctrl.hxx  |    2 ++
 vcl/source/control/imivctl1.cxx |   19 +++++++++++++++++--
 vcl/source/control/ivctrl.cxx   |   17 ++++++++++++++++-
 3 files changed, 35 insertions(+), 3 deletions(-)

New commits:
commit cd4f6d6f284c27cf783ba413fdb3650808552640
Author:     Heiko Tietze <tietze.he...@gmail.com>
AuthorDate: Wed Jun 11 08:15:28 2025 +0200
Commit:     Heiko Tietze <heiko.tie...@documentfoundation.org>
CommitDate: Wed Jun 11 11:56:53 2025 +0200

    Related tdf#165474 - Size vertical tabs according the content
    
    Text should not become abbreviated
    
    Change-Id: I17d7631a277ca01d41e824aaac79a8f2bfa3afc5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186348
    Tested-by: Jenkins
    Reviewed-by: Heiko Tietze <heiko.tie...@documentfoundation.org>

diff --git a/include/vcl/toolkit/ivctrl.hxx b/include/vcl/toolkit/ivctrl.hxx
index 95b29933349e..0e605dc16268 100644
--- a/include/vcl/toolkit/ivctrl.hxx
+++ b/include/vcl/toolkit/ivctrl.hxx
@@ -128,6 +128,7 @@ class UNLESS_MERGELIBS_MORE(VCL_DLLPUBLIC) 
SvtIconChoiceCtrl final : public Cont
     virtual void        FillLayoutData() const override;
 
     void                CallImplEventListeners(VclEventId nEvent, void* pData);
+    long                m_nWidth;
 
 public:
 
@@ -144,6 +145,7 @@ public:
     void                SetBackground( const Wallpaper& rWallpaper );
 
     void                ArrangeIcons();
+    long                AdjustWidth(const long nWidth); // returns the 
effective width
 
 
     SvxIconChoiceCtrlEntry* InsertEntry( const OUString& rText,
diff --git a/vcl/source/control/imivctl1.cxx b/vcl/source/control/imivctl1.cxx
index c2aeca1faa63..a085d10c7729 100644
--- a/vcl/source/control/imivctl1.cxx
+++ b/vcl/source/control/imivctl1.cxx
@@ -80,8 +80,11 @@ SvxIconChoiceCtrl_Impl::SvxIconChoiceCtrl_Impl(
     
aVisRectChangedIdle.SetInvokeHandler(LINK(this,SvxIconChoiceCtrl_Impl,VisRectChangedHdl));
 
     Clear( true );
-    // TODO: gridSize and aImageSize depending on the actual image size
-    Size gridSize(140, (nWinStyle & WB_SMALLICON) ? 32 : 70);
+    Size gridSize;
+    if (nWinStyle & WB_SMALLICON)
+       gridSize = Size(-1, 32);
+    else
+       gridSize = Size(140, 70);
     if(pView->GetDPIScaleFactor() > 1)
     {
       gridSize.setHeight( gridSize.Height() * ( pView->GetDPIScaleFactor()) );
@@ -174,6 +177,13 @@ void SvxIconChoiceCtrl_Impl::InsertEntry( 
std::unique_ptr<SvxIconChoiceCtrlEntry
     // Thus, don't call InvalidateBoundingRect!
     pEntry->aRect.SetRight( LONG_MAX );
     FindBoundingRect(pEntry);
+    // initial calculation w/o icon yet to ensure the background is filled
+    if (nWinBits & WB_SMALLICON)
+    {
+        tools::Rectangle aTextRect = pView->GetTextRect( CalcMaxTextRect( 
pEntry ), pEntry->GetText(), nCurTextDrawFlags );
+        pView->AdjustWidth(32 + aTextRect.GetSize().Width() + 2 * 
HOR_DIST_BMP_STRING );
+    }
+
     tools::Rectangle aOutputArea(GetOutputRect());
     pGridMap->OccupyGrids(pEntry);
     if (!aOutputArea.Overlaps(pEntry->aRect))
@@ -1132,6 +1142,10 @@ tools::Rectangle SvxIconChoiceCtrl_Impl::CalcTextRect( 
SvxIconChoiceCtrlEntry* p
             aPos.AdjustX(aImageSize.Width() );
             aPos.AdjustX(HOR_DIST_BMP_STRING );
             aPos.AdjustY((nBoundHeight - aTextSize.Height()) / 2 );
+            // final calculation of width after initially done on insert
+            long nNewWidth = aImageSize.Width() + aTextSize.Width() + 
2*HOR_DIST_BMP_STRING;
+            nNewWidth = pView->AdjustWidth(nNewWidth);
+            pEntry->aRect.setWidth(nNewWidth);
             break;
     }
     return tools::Rectangle( aPos, aTextSize );
@@ -1563,6 +1577,7 @@ tools::Rectangle SvxIconChoiceCtrl_Impl::CalcMaxTextRect( 
const SvxIconChoiceCtr
         nHeight /= 2;
         aBoundRect.AdjustTop(nHeight );
         aBoundRect.AdjustBottom( -nHeight );
+        aBoundRect.setWidth(INT_MAX); // effective width calculated in 
CalcTextRect()
     }
     return aBoundRect;
 }
diff --git a/vcl/source/control/ivctrl.cxx b/vcl/source/control/ivctrl.cxx
index c0b76a11cc9e..9b24c5685c0c 100644
--- a/vcl/source/control/ivctrl.cxx
+++ b/vcl/source/control/ivctrl.cxx
@@ -68,7 +68,8 @@ SvtIconChoiceCtrl::SvtIconChoiceCtrl( vcl::Window* pParent, 
WinBits nWinStyle )
      // WB_CLIPCHILDREN on, as ScrollBars lie on the window!
     Control( pParent, nWinStyle | WB_CLIPCHILDREN ),
 
-    _pImpl           ( new SvxIconChoiceCtrl_Impl( this, nWinStyle ) )
+    _pImpl           ( new SvxIconChoiceCtrl_Impl( this, nWinStyle ) ),
+    m_nWidth(-1)
 {
     GetOutDev()->SetLineColor();
     _pImpl->InitSettings();
@@ -136,6 +137,20 @@ void SvtIconChoiceCtrl::ArrangeIcons()
 
     _pImpl->Arrange(1000);
 }
+
+long SvtIconChoiceCtrl::AdjustWidth(const long nWidth)
+{
+    const long cMargin = 9;
+
+    if (nWidth + cMargin > m_nWidth)
+    {
+        m_nWidth = nWidth + cMargin;
+        this->set_width_request(m_nWidth);
+        _pImpl->SetGrid(Size(m_nWidth, 32));
+    }
+    return m_nWidth - cMargin;
+}
+
 void SvtIconChoiceCtrl::Resize()
 {
     _pImpl->Resize();

Reply via email to