include/vcl/weld/ItemView.hxx | 1 + include/vcl/weld/TreeView.hxx | 1 - vcl/inc/qt5/QtInstanceTreeView.hxx | 1 - vcl/inc/salvtables.hxx | 2 -- vcl/qt5/QtInstanceTreeView.cxx | 15 --------------- vcl/source/app/salvtables.cxx | 8 -------- vcl/source/weld/ItemView.cxx | 9 +++++++++ vcl/unx/gtk3/gtkinst.cxx | 17 ----------------- 8 files changed, 10 insertions(+), 44 deletions(-)
New commits: commit 00c6c844b5ac444db2b01e74d7c575b8409fa1dd Author: Michael Weghorn <[email protected]> AuthorDate: Sun Dec 21 23:03:46 2025 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Mon Dec 22 11:30:46 2025 +0100 weld: Deduplicate TreeView::get_cursor_index implementations Instead of implementing it in every toolkit specific subclass, this can be implemented in the abstract base class by using the existing ItemView::get_cursor method that returns a GtkTreeIter. Also, move the method from weld::TreeView to the weld::ItemView base class, as it is applicable for the weld::IconView subclass in the same way. Change-Id: I907f6890de433634fba1b3fc5788add520c9ae46 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196056 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/include/vcl/weld/ItemView.hxx b/include/vcl/weld/ItemView.hxx index b029b47ea223..820a6224d0d1 100644 --- a/include/vcl/weld/ItemView.hxx +++ b/include/vcl/weld/ItemView.hxx @@ -53,6 +53,7 @@ public: virtual std::unique_ptr<weld::TreeIter> get_selected() const = 0; + int get_cursor_index() const; virtual bool get_cursor(TreeIter* pIter) const = 0; void set_cursor(const TreeIter& rIter); diff --git a/include/vcl/weld/TreeView.hxx b/include/vcl/weld/TreeView.hxx index 7fe7dfc24ee9..b578724304fb 100644 --- a/include/vcl/weld/TreeView.hxx +++ b/include/vcl/weld/TreeView.hxx @@ -260,7 +260,6 @@ public: } virtual bool is_selected(int pos) const = 0; - virtual int get_cursor_index() const = 0; using weld::ItemView::set_cursor; void set_cursor(int pos) diff --git a/vcl/inc/qt5/QtInstanceTreeView.hxx b/vcl/inc/qt5/QtInstanceTreeView.hxx index 0f2ba053b8fc..3d8254206765 100644 --- a/vcl/inc/qt5/QtInstanceTreeView.hxx +++ b/vcl/inc/qt5/QtInstanceTreeView.hxx @@ -70,7 +70,6 @@ public: virtual void set_font_color(int nPos, const Color& rColor) override; virtual void do_scroll_to_row(int nRow) override; virtual bool is_selected(int nPos) const override; - virtual int get_cursor_index() const override; using QtInstanceItemView::do_set_cursor; virtual void do_set_cursor(int pos) override; diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx index b957f0452f82..be1e2177b244 100644 --- a/vcl/inc/salvtables.hxx +++ b/vcl/inc/salvtables.hxx @@ -1663,8 +1663,6 @@ public: virtual int iter_n_children(const weld::TreeIter& rIter) const override; - virtual int get_cursor_index() const override; - using SalInstanceItemView::do_set_cursor; virtual void do_set_cursor(int pos) override; diff --git a/vcl/qt5/QtInstanceTreeView.cxx b/vcl/qt5/QtInstanceTreeView.cxx index 1872ba5c655e..e9ff99f84122 100644 --- a/vcl/qt5/QtInstanceTreeView.cxx +++ b/vcl/qt5/QtInstanceTreeView.cxx @@ -221,21 +221,6 @@ void QtInstanceTreeView::do_scroll_to_row(int nRow) { scroll_to_row(treeIter(nRo bool QtInstanceTreeView::is_selected(int nPos) const { return is_selected(treeIter(nPos)); } -int QtInstanceTreeView::get_cursor_index() const -{ - SolarMutexGuard g; - - int nIndex = -1; - GetQtInstance().RunInMainThread([&] { - const QModelIndex aCurrentIndex = m_pSelectionModel->currentIndex(); - if (aCurrentIndex.isValid()) - nIndex = aCurrentIndex.row(); - - }); - - return nIndex; -} - void QtInstanceTreeView::do_set_cursor(int nPos) { do_set_cursor(treeIter(nPos)); } int QtInstanceTreeView::find_text(const OUString& rText) const diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index 49131e56e77a..f10d9cdb2299 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -4196,14 +4196,6 @@ int SalInstanceTreeView::iter_n_children(const weld::TreeIter& rIter) const return m_xTreeView->GetModel()->GetChildList(rVclIter.iter).size(); } -int SalInstanceTreeView::get_cursor_index() const -{ - SvTreeListEntry* pEntry = m_xTreeView->GetCurEntry(); - if (!pEntry) - return -1; - return SvTreeList::GetRelPos(pEntry); -} - void SalInstanceTreeView::do_set_cursor(int pos) { if (pos == -1) diff --git a/vcl/source/weld/ItemView.cxx b/vcl/source/weld/ItemView.cxx index a8ec38592ab6..c9314a80d665 100644 --- a/vcl/source/weld/ItemView.cxx +++ b/vcl/source/weld/ItemView.cxx @@ -25,6 +25,15 @@ void ItemView::set_id(int pos, const OUString& rId) return set_id(*pIter, rId); } +int ItemView::get_cursor_index() const +{ + std::unique_ptr<weld::TreeIter> pIter = make_iterator(); + if (get_cursor(pIter.get())) + return get_iter_index_in_parent(*pIter); + + return -1; +} + void ItemView::set_cursor(const TreeIter& rIter) { disable_notify_events(); diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx index 828f1319d252..40579a1e032b 100644 --- a/vcl/unx/gtk3/gtkinst.cxx +++ b/vcl/unx/gtk3/gtkinst.cxx @@ -15758,23 +15758,6 @@ public: return true; } - virtual int get_cursor_index() const override - { - int nRet = -1; - - GtkTreePath* path; - gtk_tree_view_get_cursor(m_pTreeView, &path, nullptr); - if (path) - { - gint depth; - gint* indices = gtk_tree_path_get_indices_with_depth(path, &depth); - nRet = indices[depth-1]; - gtk_tree_path_free(path); - } - - return nRet; - } - virtual void do_set_cursor(const weld::TreeIter& rIter) override { disable_notify_events();
