vcl/source/app/salvtables.cxx |   19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

New commits:
commit 7bf9dd2ebf06763803dd4620e3e999d46ae79c59
Author:     Michael Weghorn <[email protected]>
AuthorDate: Fri Jan 16 12:54:40 2026 +0100
Commit:     Michael Weghorn <[email protected]>
CommitDate: Sat Jan 17 06:55:02 2026 +0100

    vcl weld: Take colum headers into account for col width
    
    In SalInstanceTreeView::columns_autosize, also consider
    the width required to fit the column header text
    into the column, to ensure the column is wide
    enough to show the full title.
    
    This matches what the GTK and Qt implementations also do.
    (See discussion in [1]. A modified PS 9 of that change was
    used for testing.)
    
    An alternative to implementing the logic directly in
    SalInstanceTreeView::columns_autosize might have been
    to override SvTreeListBox::getPreferredDimensions
    in the SvHeaderTabListBox subclass. However, the HeaderBar
    implementation it uses is currently based on hard-coded
    item widths being set when items are added and may use
    a dummy size of HEADERBAR_FULLSIZE for the last column,
    so it would be non-trivial to determine whether the
    size that was set for each column is the actually desired
    size or just some dummy size, without further refactoring
    that class.
    (For weld, the "GtkTreeViewColumn" case in
    VclBuilder::makeObject simply always passes a
    column width of 100 and the SalInstanceTreeView
    ctor sets HEADERBAR_FULLSIZE for the last colum.
    But this vcl widget is also used directly elsewhere,
    and expectations may be different there, so avoid
    messing with the underlying widget for now.)
    In addition, SalInstanceTreeView uses some special
    column indices for the SvTabListBox that are not
    necessarily used the same way in HeaderBar.
    
    [1] 
https://gerrit.libreoffice.org/c/core/+/195836/comment/5739cb42_368d600d/
    
    Change-Id: I150f7e70bee3f191c347046fd1dc011f663f8338
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197446
    Reviewed-by: Michael Weghorn <[email protected]>
    Tested-by: Jenkins

diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index 3d0458101750..d9f997d5f858 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -3971,6 +3971,25 @@ void SalInstanceTreeView::columns_autosize()
         aColWidths.push_back(aWidths[1] + aWidths[0]);
         for (size_t i = 2; i < aWidths.size(); ++i)
             aColWidths.push_back(aWidths[i]);
+
+        // take column headers into account
+        if (VclPtr<SvHeaderTabListBox> pTabListBox
+            = dynamic_cast<SvHeaderTabListBox*>(m_xTreeView.get()))
+        {
+            if (VclPtr<HeaderBar> pHeaderBar = pTabListBox->GetHeaderBar())
+            {
+                const size_t nCount
+                    = std::min(aColWidths.size(), 
size_t(pHeaderBar->GetItemCount()));
+                for (size_t i = 0; i < nCount; ++i)
+                {
+                    const OUString sHeaderText = 
pHeaderBar->GetItemText(pHeaderBar->GetItemId(i));
+                    constexpr int PADDING = 6;
+                    const int nHeaderColWidth = 
pHeaderBar->GetTextWidth(sHeaderText) + PADDING;
+                    aColWidths[i] = std::max(aColWidths.at(i), 
nHeaderColWidth);
+                }
+            }
+        }
+
         set_column_fixed_widths(aColWidths);
     }
 }

Reply via email to