cui/source/dialogs/widgettestdlg.cxx | 23 +++++++++++++++++------ cui/uiconfig/ui/widgettestdialog.ui | 21 +++++++++++++++++++-- 2 files changed, 36 insertions(+), 8 deletions(-)
New commits: commit 3647118ad52de46bc02253779ae673e7263ad7ce Author: Szymon Kłos <[email protected]> AuthorDate: Fri Jul 4 08:11:19 2025 +0000 Commit: Caolán McNamara <[email protected]> CommitDate: Fri Jul 4 12:39:08 2025 +0200 Fix out-of-bound crash in test dialog 2 It is visible in LOK case (only some backends). TreeView requires width declaration for columns to not fail on "you have only 2 columns" in GetTabs() call we introduced recently. Change-Id: Iae07f0813e962e413054794afc0228933af00dec Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187373 Tested-by: Caolán McNamara <[email protected]> Reviewed-by: Caolán McNamara <[email protected]> Tested-by: Jenkins CollaboraOffice <[email protected]> diff --git a/cui/source/dialogs/widgettestdlg.cxx b/cui/source/dialogs/widgettestdlg.cxx index 0d9eca2bd73a..690e474ded09 100644 --- a/cui/source/dialogs/widgettestdlg.cxx +++ b/cui/source/dialogs/widgettestdlg.cxx @@ -38,6 +38,17 @@ void WidgetTestDialog::FillTreeView() OUString aImage1(RID_SVXBMP_CELL_LR); OUString aImage2(RID_SVXBMP_SHADOW_BOT_LEFT); + // some backends might crash without proper widths set + std::vector<int> aWidths; + aWidths.push_back(m_xTreeView2->get_checkbox_column_width()); + for (int i = 0; i < 3 - 1; ++i) + { + int nWidth = m_xTreeView2->get_column_width(i); + assert(nWidth > 0 && "suspicious to get a value like this"); + aWidths.push_back(nWidth); + } + m_xTreeView2->set_column_fixed_widths(aWidths); + for (size_t nCount = 0; nCount < 4; nCount++) { OUString sText = OUString::Concat("Test ") + OUString::Concat(OUString::number(nCount)); @@ -45,13 +56,13 @@ void WidgetTestDialog::FillTreeView() m_xTreeView->insert(nullptr, -1, &sText, &sText, nullptr, nullptr, false, xEntry.get()); m_xTreeView->set_image(*xEntry, (nCount % 2 == 0) ? aImage1 : aImage2); + int nRow = m_xTreeView2->n_children(); m_xTreeView2->append(); - m_xTreeView2->set_image(nCount, (nCount % 2 == 0) ? aImage1 : aImage2); - m_xTreeView2->set_text(nCount, u"First Column"_ustr, 0); - // FIXME: crash out-of-bound - //m_xTreeView2->set_text( - // nCount, OUString::Concat("Row ") + OUString::Concat(OUString::number(nCount)), 1); - m_xTreeView2->set_id(nCount, OUString::number(nCount)); + m_xTreeView2->set_image(nRow, (nCount % 2 == 0) ? aImage1 : aImage2); + m_xTreeView2->set_text(nRow, u"First Column"_ustr, 0); + m_xTreeView2->set_text( + nRow, OUString::Concat("Row ") + OUString::Concat(OUString::number(nCount)), 1); + m_xTreeView2->set_id(nRow, OUString::number(nCount)); } } diff --git a/cui/uiconfig/ui/widgettestdialog.ui b/cui/uiconfig/ui/widgettestdialog.ui index 0441ae7c77b8..6308a83370b7 100644 --- a/cui/uiconfig/ui/widgettestdialog.ui +++ b/cui/uiconfig/ui/widgettestdialog.ui @@ -45,6 +45,8 @@ </object> <object class="GtkTreeStore" id="liststore3"> <columns> + <!-- column-name icon --> + <column type="GdkPixbuf"/> <!-- column-name text --> <column type="gchararray"/> <!-- column-name text1 --> @@ -613,6 +615,21 @@ <property name="reorderable">True</property> <property name="search-column">1</property> <property name="enable-tree-lines">True</property> + <child> + <object class="GtkTreeViewColumn" id="treeviewcolumn0"> + <property name="resizable">True</property> + <property name="spacing">6</property> + <property name="sort-indicator">True</property> + <property name="clickable">True</property> + <property name="title" translatable="no">.</property> + <child> + <object class="GtkCellRendererPixbuf" id="cellrenderer0"/> + <attributes> + <attribute name="pixbuf">0</attribute> + </attributes> + </child> + </object> + </child> <child> <object class="GtkTreeViewColumn" id="treeviewcolumn1"> <property name="resizable">True</property> @@ -623,7 +640,7 @@ <child> <object class="GtkCellRendererText" id="cellrenderer1"/> <attributes> - <attribute name="text">0</attribute> + <attribute name="text">1</attribute> </attributes> </child> </object> @@ -638,7 +655,7 @@ <child> <object class="GtkCellRendererText" id="cellrenderer2"/> <attributes> - <attribute name="text">1</attribute> + <attribute name="text">2</attribute> </attributes> </child> </object>
