cui/source/dialogs/cuigaldlg.cxx | 2 +- cui/source/dialogs/dlgname.cxx | 2 +- cui/source/options/connpooloptions.cxx | 2 +- cui/source/options/optjava.cxx | 2 +- cui/source/tabpages/autocdlg.cxx | 2 +- cui/source/tabpages/numfmt.cxx | 8 ++++---- include/vcl/weld/ItemView.hxx | 8 ++++++++ include/vcl/weld/TreeView.hxx | 21 --------------------- svx/source/gallery2/galbrws1.cxx | 2 +- vcl/inc/jsdialog/jsdialogbuilder.hxx | 2 ++ vcl/inc/qt5/QtInstanceIconView.hxx | 5 +++++ vcl/inc/salvtables.hxx | 4 ++++ vcl/jsdialog/jsdialogbuilder.cxx | 17 +++++++++++++++++ vcl/qt5/QtInstanceIconView.cxx | 15 +++++++++------ vcl/source/app/salvtables.cxx | 21 +++++++++++++++++++++ vcl/source/weld/ItemView.cxx | 14 ++++++++++++++ vcl/unx/gtk3/gtkinst.cxx | 26 ++++++++++++++++++++++++++ 17 files changed, 116 insertions(+), 37 deletions(-)
New commits: commit d6f2dd532fa17f49efe640dbe214e0801f964691 Author: Michael Weghorn <[email protected]> AuthorDate: Thu Dec 18 19:12:33 2025 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Fri Dec 19 09:20:29 2025 +0100 weld: Replace calls to weld::ItemView::select(-1) with unselect_all() The GTK and vcl implementations have special handling to treat an index of -1 to deselect all entries, see their weld::ItemView::unselect_all implementations that themselves call weld::ItemView::select with an index of -1. weld::ItemView::unselect_all is clearer, though, so use that one instead. Change-Id: I936015e7ce3d95fb7c25358374d8d7c19cc1c8dc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195865 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/cui/source/dialogs/cuigaldlg.cxx b/cui/source/dialogs/cuigaldlg.cxx index dad1d0cb5be1..046a7a7257b5 100644 --- a/cui/source/dialogs/cuigaldlg.cxx +++ b/cui/source/dialogs/cuigaldlg.cxx @@ -325,7 +325,7 @@ IMPL_LINK_NOARG(TakeProgress, CleanUpHdl, void*, void) std::unique_ptr<weld::WaitObject> xWait(new weld::WaitObject(m_pParent)); - m_pTabPage->m_xLbxFound->select(-1); + m_pTabPage->m_xLbxFound->unselect_all(); m_pTabPage->m_xLbxFound->freeze(); // mark all taken positions in aRemoveEntries diff --git a/cui/source/dialogs/dlgname.cxx b/cui/source/dialogs/dlgname.cxx index 130de538b859..fe782e6f5309 100644 --- a/cui/source/dialogs/dlgname.cxx +++ b/cui/source/dialogs/dlgname.cxx @@ -182,7 +182,7 @@ IMPL_LINK_NOARG(SvxListDialog, AddHdl_Impl, weld::Button&, void) if (!sNewText.isEmpty()) { m_xList->insert_text(-1, sNewText); - m_xList->select(-1); + m_xList->unselect_all(); } } diff --git a/cui/source/options/connpooloptions.cxx b/cui/source/options/connpooloptions.cxx index c55b58449ace..fa11396e526f 100644 --- a/cui/source/options/connpooloptions.cxx +++ b/cui/source/options/connpooloptions.cxx @@ -283,7 +283,7 @@ namespace offapp m_xDriversLabel->set_sensitive(bGloballyEnabled); m_xDriverList->set_sensitive(bGloballyEnabled); if (!bGloballyEnabled) - m_xDriverList->select(-1); + m_xDriverList->unselect_all(); m_xDriverLabel->set_sensitive(bGloballyEnabled); m_xDriver->set_sensitive(bGloballyEnabled); m_xDriverPoolingEnabled->set_sensitive(bGloballyEnabled && !m_xDriverPoolingEnabledImg->get_visible()); diff --git a/cui/source/options/optjava.cxx b/cui/source/options/optjava.cxx index 8268526277a9..36c2b8852b39 100644 --- a/cui/source/options/optjava.cxx +++ b/cui/source/options/optjava.cxx @@ -771,7 +771,7 @@ void SvxJavaParameterDlg::EditParameter() short SvxJavaParameterDlg::run() { m_xParameterEdit->grab_focus(); - m_xAssignedList->select(-1); + m_xAssignedList->unselect_all(); return GenericDialogController::run(); } diff --git a/cui/source/tabpages/autocdlg.cxx b/cui/source/tabpages/autocdlg.cxx index 9ca743ed690f..c61ded70ebdb 100644 --- a/cui/source/tabpages/autocdlg.cxx +++ b/cui/source/tabpages/autocdlg.cxx @@ -1172,7 +1172,7 @@ IMPL_LINK(OfaAutocorrReplacePage, ModifyHdl, weld::Entry&, rEdt, void) }); if( !bFound ) { - m_xReplaceTLB->select(-1); + m_xReplaceTLB->unselect_all(); bFirstSelIterSet = false; m_xNewReplacePB->set_label(sNew); if( bReplaceEditChanged ) diff --git a/cui/source/tabpages/numfmt.cxx b/cui/source/tabpages/numfmt.cxx index 9a22e0ddecb0..c2ee75564bb5 100644 --- a/cui/source/tabpages/numfmt.cxx +++ b/cui/source/tabpages/numfmt.cxx @@ -543,7 +543,7 @@ void SvxNumberFormatTabPage::Reset( const SfxItemSet* rSet ) #************************************************************************/ void SvxNumberFormatTabPage::Obstructing() { - m_xLbFormat->select(-1); + m_xLbFormat->unselect_all(); m_xLbLocale->set_active(-1); m_xFtLocale->set_sensitive(false); m_xLbLocale->set_sensitive(false); @@ -862,7 +862,7 @@ void SvxNumberFormatTabPage::UpdateOptions_Impl( bool bCheckCatChange /*= sal_Fa sal_uInt32 nCurEntryKey=NUMKEY_UNDEFINED; if(!pNumFmtShell->FindEntry( m_xEdFormat->get_text(),&nCurEntryKey)) { - m_xLbFormat->select(-1); + m_xLbFormat->unselect_all(); } } if(bOneAreaFlag) @@ -1037,7 +1037,7 @@ void SvxNumberFormatTabPage::UpdateFormatListBox_Impl } else { - m_xLbFormat->select(-1); + m_xLbFormat->unselect_all(); } if ( bUpdateEdit ) @@ -1565,7 +1565,7 @@ void SvxNumberFormatTabPage::OptHdl_Impl(const weld::Widget* pOptCtrl) else { EditHdl_Impl( nullptr ); - m_xLbFormat->select(-1); + m_xLbFormat->unselect_all(); } } diff --git a/svx/source/gallery2/galbrws1.cxx b/svx/source/gallery2/galbrws1.cxx index 9048c64525ef..1f6ed31765cc 100644 --- a/svx/source/gallery2/galbrws1.cxx +++ b/svx/source/gallery2/galbrws1.cxx @@ -475,7 +475,7 @@ void GalleryBrowser::Notify( SfxBroadcaster&, const SfxHint& rHint ) else if( nCurSelectPos ) mxThemes->select( nCurSelectPos - 1 ); else - mxThemes->select(-1); + mxThemes->unselect_all(); SelectThemeHdl( *mxThemes ); } commit 149b2774c997cbb72f0870bbb1b834ae32edd55f Author: Michael Weghorn <[email protected]> AuthorDate: Thu Dec 18 18:53:52 2025 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Fri Dec 19 09:20:20 2025 +0100 weld: Add iter-based IconView::(un)select Both, weld::IconView and weld::TreeView have (un)select methods taking an index as a param. weld::TreeView already also has a TreeView::select/TreeView::unselect that takes an iter. Move those method declarations down into the common weld::ItemView base class. Implement the do_select/do_unselect overrides in all implementations (gtk, qt, vcl, JS) based on the existing index-based implementations. While this temporarily adds more duplication, this will be reduced again in an upcoming commit when the index-based implementations will be implemented in the weld::ItemView base class right away (based on the new one taking an iter, similar to what IconView::get_rect already does), allowing to drop the toolkit-specific implementations taking an index for both, weld::TreeView and weld::IconView. For JSIconView::do_select, get the index to send in the same way as the existing JSTreeView::do_select method taking a GtkTreeIter already does. Change-Id: Iec7a4704b89c42ec692c7a22beb0dfc0ecb98a8c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195864 Reviewed-by: Michael Weghorn <[email protected]> Tested-by: Jenkins diff --git a/include/vcl/weld/ItemView.hxx b/include/vcl/weld/ItemView.hxx index 91e2bbfd1c7c..27f1f3b82723 100644 --- a/include/vcl/weld/ItemView.hxx +++ b/include/vcl/weld/ItemView.hxx @@ -21,7 +21,11 @@ class VCL_DLLPUBLIC ItemView : virtual public Widget protected: virtual void do_select(int pos) = 0; + virtual void do_select(const TreeIter& rIter) = 0; + virtual void do_unselect(int pos) = 0; + virtual void do_unselect(const TreeIter& rIter) = 0; + virtual void do_clear() = 0; public: @@ -37,7 +41,11 @@ public: // Don't select when frozen, select after thaw. Note selection doesn't survive a freeze. void select(int pos); + void select(const TreeIter& rIter); + void unselect(int pos); + void unselect(const TreeIter& rIter); + virtual void select_all() = 0; virtual void unselect_all() = 0; diff --git a/include/vcl/weld/TreeView.hxx b/include/vcl/weld/TreeView.hxx index 67d5b5bf0033..951a601fc668 100644 --- a/include/vcl/weld/TreeView.hxx +++ b/include/vcl/weld/TreeView.hxx @@ -134,10 +134,6 @@ protected: virtual void do_set_cursor(int pos) = 0; virtual void do_set_cursor(const TreeIter& rIter) = 0; virtual void do_remove(const TreeIter& rIter) = 0; - using ItemView::do_select; - virtual void do_select(const TreeIter& rIter) = 0; - using ItemView::do_unselect; - virtual void do_unselect(const TreeIter& rIter) = 0; virtual void do_scroll_to_row(const TreeIter& rIter) = 0; virtual void do_set_children_on_demand(const TreeIter& rIter, bool bChildrenOnDemand) = 0; virtual void do_remove_selection() = 0; @@ -358,23 +354,6 @@ public: enable_notify_events(); } - //Don't select when frozen, select after thaw. Note selection doesn't survive a freeze. - using ItemView::select; - void select(const TreeIter& rIter) - { - disable_notify_events(); - do_select(rIter); - enable_notify_events(); - } - - using ItemView::unselect; - void unselect(const TreeIter& rIter) - { - disable_notify_events(); - do_unselect(rIter); - enable_notify_events(); - } - //visually indent this row as if it was at get_iter_depth() + nIndentLevel virtual void set_extra_row_indent(const TreeIter& rIter, int nIndentLevel) = 0; // col index -1 sets the first text column diff --git a/vcl/inc/jsdialog/jsdialogbuilder.hxx b/vcl/inc/jsdialog/jsdialogbuilder.hxx index ae13f2813742..6c84206f1c71 100644 --- a/vcl/inc/jsdialog/jsdialogbuilder.hxx +++ b/vcl/inc/jsdialog/jsdialogbuilder.hxx @@ -787,7 +787,9 @@ public: virtual void do_clear() override; virtual void do_select(int pos) override; + virtual void do_select(const weld::TreeIter& rIter) override; virtual void do_unselect(int pos) override; + virtual void do_unselect(const weld::TreeIter& rIter) override; // OnDemandRenderingHandler virtual void render_entry(int pos, int dpix, int dpiy) override; diff --git a/vcl/inc/qt5/QtInstanceIconView.hxx b/vcl/inc/qt5/QtInstanceIconView.hxx index ff98957e0cba..f14fdf20c47b 100644 --- a/vcl/inc/qt5/QtInstanceIconView.hxx +++ b/vcl/inc/qt5/QtInstanceIconView.hxx @@ -45,8 +45,13 @@ public: virtual OUString get_selected_text() const override; virtual OUString get_id(int nPos) const override; + virtual void do_select(int nPos) override; + virtual void do_select(const weld::TreeIter& rIter) override; + virtual void do_unselect(int nPos) override; + virtual void do_unselect(const weld::TreeIter& rIter) override; + virtual void set_image(int nPos, VirtualDevice& rDevice) override; virtual void set_text(int nPos, const OUString& rText) override; virtual void set_id(int nPos, const OUString& rId) override; diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx index f014377beecc..bbb9602b30c2 100644 --- a/vcl/inc/salvtables.hxx +++ b/vcl/inc/salvtables.hxx @@ -1497,7 +1497,11 @@ protected: bool bTakeOwnership); virtual void do_select(int pos) override; + virtual void do_select(const weld::TreeIter& rIter) override; + virtual void do_unselect(int pos) override; + virtual void do_unselect(const weld::TreeIter& rIter) override; + virtual void do_clear() override; public: diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx index 968a762b9b21..ae9d458bf797 100644 --- a/vcl/jsdialog/jsdialogbuilder.cxx +++ b/vcl/jsdialog/jsdialogbuilder.cxx @@ -1950,12 +1950,29 @@ void JSIconView::do_select(int pos) sendAction(std::move(pMap)); } +void JSIconView::do_select(const weld::TreeIter& rIter) +{ + SalInstanceIconView::do_select(rIter); + + std::unique_ptr<jsdialog::ActionDataMap> pMap = std::make_unique<jsdialog::ActionDataMap>(); + const SalInstanceTreeIter& rVclIter = static_cast<const SalInstanceTreeIter&>(rIter); + (*pMap)[ACTION_TYPE ""_ostr] = "select"; + (*pMap)["position"_ostr] = OUString::number(m_xIconView->GetEntryPos(rVclIter.iter)); + sendAction(std::move(pMap)); +} + void JSIconView::do_unselect(int pos) { SalInstanceIconView::do_unselect(pos); sendUpdate(); } +void JSIconView::do_unselect(const weld::TreeIter& rIter) +{ + SalInstanceIconView::do_unselect(rIter); + sendUpdate(); +} + void JSIconView::render_entry(int pos, int dpix, int dpiy) { OUString sImage = m_xIconView->renderEntry(pos, dpix, dpiy); diff --git a/vcl/qt5/QtInstanceIconView.cxx b/vcl/qt5/QtInstanceIconView.cxx index 9f43dba3eb4a..4d1753d33296 100644 --- a/vcl/qt5/QtInstanceIconView.cxx +++ b/vcl/qt5/QtInstanceIconView.cxx @@ -133,20 +133,23 @@ OUString QtInstanceIconView::get_selected_text() const OUString QtInstanceIconView::get_id(int nPos) const { return get_id(treeIter(nPos)); } -void QtInstanceIconView::do_select(int nPos) +void QtInstanceIconView::do_select(int nPos) { do_select(treeIter(nPos)); } + +void QtInstanceIconView::do_select(const weld::TreeIter& rIter) { SolarMutexGuard g; GetQtInstance().RunInMainThread( - [&] { m_pSelectionModel->select(m_pModel->index(nPos, 0), QItemSelectionModel::Select); }); + [&] { m_pSelectionModel->select(modelIndex(rIter), QItemSelectionModel::Select); }); } -void QtInstanceIconView::do_unselect(int nPos) +void QtInstanceIconView::do_unselect(int nPos) { do_unselect(treeIter(nPos)); } + +void QtInstanceIconView::do_unselect(const weld::TreeIter& rIter) { SolarMutexGuard g; - GetQtInstance().RunInMainThread([&] { - m_pSelectionModel->select(m_pModel->index(nPos, 0), QItemSelectionModel::Deselect); - }); + GetQtInstance().RunInMainThread( + [&] { m_pSelectionModel->select(modelIndex(rIter), QItemSelectionModel::Deselect); }); } void QtInstanceIconView::set_image(int nPos, VirtualDevice& rDevice) diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index adc7cc528daa..d328ac42e253 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -3576,6 +3576,17 @@ void SalInstanceItemView::do_select(int pos) } } +void SalInstanceItemView::do_select(const weld::TreeIter& rIter) +{ + assert(m_pTreeListBox->IsUpdateMode() + && "don't select when frozen, select after thaw. Note selection doesn't survive a " + "freeze"); + + const SalInstanceTreeIter& rVclIter = static_cast<const SalInstanceTreeIter&>(rIter); + m_pTreeListBox->Select(rVclIter.iter, true); + m_pTreeListBox->MakeVisible(rVclIter.iter); +} + void SalInstanceItemView::do_unselect(int pos) { assert(m_pTreeListBox->IsUpdateMode() @@ -3590,6 +3601,16 @@ void SalInstanceItemView::do_unselect(int pos) } } +void SalInstanceItemView::do_unselect(const weld::TreeIter& rIter) +{ + assert(m_pTreeListBox->IsUpdateMode() + && "don't select when frozen, select after thaw. Note selection doesn't survive a " + "freeze"); + + const SalInstanceTreeIter& rVclIter = static_cast<const SalInstanceTreeIter&>(rIter); + m_pTreeListBox->Select(rVclIter.iter, false); +} + void SalInstanceItemView::do_clear() { m_pTreeListBox->Clear(); diff --git a/vcl/source/weld/ItemView.cxx b/vcl/source/weld/ItemView.cxx index 0a0776c5913b..0b866abadfa8 100644 --- a/vcl/source/weld/ItemView.cxx +++ b/vcl/source/weld/ItemView.cxx @@ -18,6 +18,13 @@ void ItemView::select(int pos) enable_notify_events(); } +void ItemView::select(const TreeIter& rIter) +{ + disable_notify_events(); + do_select(rIter); + enable_notify_events(); +} + void ItemView::unselect(int pos) { disable_notify_events(); @@ -25,6 +32,13 @@ void ItemView::unselect(int pos) enable_notify_events(); } +void ItemView::unselect(const TreeIter& rIter) +{ + disable_notify_events(); + do_unselect(rIter); + enable_notify_events(); +} + void ItemView::clear() { disable_notify_events(); diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx index 17083b20a3f3..0a0ef160bb06 100644 --- a/vcl/unx/gtk3/gtkinst.cxx +++ b/vcl/unx/gtk3/gtkinst.cxx @@ -17192,6 +17192,19 @@ public: enable_notify_events(); } + virtual void do_select(const weld::TreeIter& rIter) override + { + disable_notify_events(); + const GtkInstanceTreeIter& rGtkIter = static_cast<const GtkInstanceTreeIter&>(rIter); + GtkTreeModel* pModel = GTK_TREE_MODEL(m_pTreeStore); + GtkTreePath* path + = gtk_tree_model_get_path(pModel, const_cast<GtkTreeIter*>(&rGtkIter.iter)); + gtk_icon_view_select_path(m_pIconView, path); + gtk_icon_view_scroll_to_path(m_pIconView, path, false, 0, 0); + gtk_tree_path_free(path); + enable_notify_events(); + } + virtual void do_unselect(int pos) override { assert(gtk_icon_view_get_model(m_pIconView) && "don't select when frozen, select after thaw. Note selection doesn't survive a freeze"); @@ -17209,6 +17222,19 @@ public: enable_notify_events(); } + virtual void do_unselect(const weld::TreeIter& rIter) override + { + disable_notify_events(); + const GtkInstanceTreeIter& rGtkIter = static_cast<const GtkInstanceTreeIter&>(rIter); + GtkTreeModel* pModel = GTK_TREE_MODEL(m_pTreeStore); + GtkTreePath* path + = gtk_tree_model_get_path(pModel, const_cast<GtkTreeIter*>(&rGtkIter.iter)); + gtk_icon_view_unselect_path(m_pIconView, path); + gtk_icon_view_scroll_to_path(m_pIconView, path, false, 0, 0); + gtk_tree_path_free(path); + enable_notify_events(); + } + virtual bool get_selected(weld::TreeIter* pIter) const override { GtkInstanceTreeIter* pGtkIter = static_cast<GtkInstanceTreeIter*>(pIter);
