include/vcl/weld/IconView.hxx | 23 ----------------------- include/vcl/weld/ItemView.hxx | 11 +++++++++++ include/vcl/weld/TreeView.hxx | 27 ++++----------------------- sd/source/ui/sidebar/LayoutMenu.cxx | 18 +++++------------- sd/source/ui/sidebar/LayoutMenu.hxx | 4 ---- vcl/source/weld/ItemView.cxx | 14 ++++++++++++++ 6 files changed, 34 insertions(+), 63 deletions(-)
New commits: commit bd6cd1f780ef31546415f61d2f16c011e37d6005 Author: Michael Weghorn <[email protected]> AuthorDate: Wed Dec 17 20:16:29 2025 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Thu Dec 18 07:21:42 2025 +0100 weld: Move (un)select_all and n_children to ItemView base Those purely virtual methods are the same in weld::TreeView and weld::IconView. Deduplicate by moving to the weld::ItemView base class. Actual implementations can possibly also be deduplicated, but that can be handled separately. Change-Id: I1a458dfc2116d88705d4cbdc7c9a9d5d78429dbd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195809 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/include/vcl/weld/IconView.hxx b/include/vcl/weld/IconView.hxx index 52596a9ab383..b2e6a0029643 100644 --- a/include/vcl/weld/IconView.hxx +++ b/include/vcl/weld/IconView.hxx @@ -167,13 +167,6 @@ public: // call func on each selected element until func returns true or we run out of elements virtual void selected_foreach(const std::function<bool(TreeIter&)>& func) = 0; - //all of them. Don't select when frozen, select after thaw. Note selection doesn't survive a freeze. - virtual void select_all() = 0; - virtual void unselect_all() = 0; - - // return the number of toplevel nodes - virtual int n_children() const = 0; - void save_value() { m_sSavedValue = get_selected_text(); } OUString const& get_saved_value() const { return m_sSavedValue; } bool get_value_changed_from_saved() const { return m_sSavedValue != get_selected_text(); } diff --git a/include/vcl/weld/ItemView.hxx b/include/vcl/weld/ItemView.hxx index 40b94602e521..40e3e67cb597 100644 --- a/include/vcl/weld/ItemView.hxx +++ b/include/vcl/weld/ItemView.hxx @@ -30,8 +30,14 @@ public: virtual bool get_selected(TreeIter* pIter) const = 0; virtual bool get_cursor(TreeIter* pIter) const = 0; + // Don't select when frozen, select after thaw. Note selection doesn't survive a freeze. void select(int pos); void unselect(int pos); + virtual void select_all() = 0; + virtual void unselect_all() = 0; + + // return the number of toplevel nodes + virtual int n_children() const = 0; void clear(); }; diff --git a/include/vcl/weld/TreeView.hxx b/include/vcl/weld/TreeView.hxx index 46051b819e5b..047399bddc4c 100644 --- a/include/vcl/weld/TreeView.hxx +++ b/include/vcl/weld/TreeView.hxx @@ -519,13 +519,6 @@ public: void connect_drag_begin(const Link<bool&, bool>& rLink) { m_aDragBeginHdl = rLink; } - //all of them. Don't select when frozen, select after thaw. Note selection doesn't survive a freeze. - virtual void select_all() = 0; - virtual void unselect_all() = 0; - - // return the number of toplevel nodes - virtual int n_children() const = 0; - // afterwards, entries will be in default ascending sort order virtual void make_sorted() = 0; virtual void make_unsorted() = 0; commit 9fc51a5f84394dc3a7191843a7ff40cba9a26a88 Author: Michael Weghorn <[email protected]> AuthorDate: Wed Dec 17 19:47:09 2025 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Thu Dec 18 07:21:34 2025 +0100 weld: Deduplicate index-based ItemView (un)select Both, weld::TreeView and weld::IconView have the same methods/logic. Deduplicate that by moving it to the weld::ItemView base class. Change-Id: Ic7d722c4bfc856e2320e0d6910d4446805514d89 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195808 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/include/vcl/weld/IconView.hxx b/include/vcl/weld/IconView.hxx index f2ae0010dff3..52596a9ab383 100644 --- a/include/vcl/weld/IconView.hxx +++ b/include/vcl/weld/IconView.hxx @@ -56,8 +56,6 @@ protected: virtual void do_insert(int pos, const OUString* pStr, const OUString* pId, const Bitmap* pIcon, TreeIter* pRet) = 0; - virtual void do_select(int pos) = 0; - virtual void do_unselect(int pos) = 0; virtual void do_remove(int pos) = 0; virtual void do_set_cursor(const TreeIter& rIter) = 0; virtual void do_scroll_to_item(const TreeIter& rIter) = 0; @@ -129,20 +127,6 @@ public: //by index. Don't select when frozen, select after thaw. Note selection doesn't survive a freeze. virtual OUString get_id(int pos) const = 0; - void select(int pos) - { - disable_notify_events(); - do_select(pos); - enable_notify_events(); - } - - void unselect(int pos) - { - disable_notify_events(); - do_unselect(pos); - enable_notify_events(); - } - virtual void set_image(int pos, VirtualDevice& rDevice) = 0; virtual void set_text(int pos, const OUString& rText) = 0; virtual void set_id(int pos, const OUString& rId) = 0; diff --git a/include/vcl/weld/ItemView.hxx b/include/vcl/weld/ItemView.hxx index 45efb333fcb8..40b94602e521 100644 --- a/include/vcl/weld/ItemView.hxx +++ b/include/vcl/weld/ItemView.hxx @@ -18,6 +18,8 @@ namespace weld class VCL_DLLPUBLIC ItemView : virtual public Widget { protected: + virtual void do_select(int pos) = 0; + virtual void do_unselect(int pos) = 0; virtual void do_clear() = 0; public: @@ -28,6 +30,9 @@ public: virtual bool get_selected(TreeIter* pIter) const = 0; virtual bool get_cursor(TreeIter* pIter) const = 0; + void select(int pos); + void unselect(int pos); + void clear(); }; } diff --git a/include/vcl/weld/TreeView.hxx b/include/vcl/weld/TreeView.hxx index a30f9080eae7..46051b819e5b 100644 --- a/include/vcl/weld/TreeView.hxx +++ b/include/vcl/weld/TreeView.hxx @@ -132,14 +132,14 @@ protected: VirtualDevice* pImageSurface, bool bChildrenOnDemand, TreeIter* pRet) = 0; virtual void do_insert_separator(int pos, const OUString& rId) = 0; - virtual void do_select(int pos) = 0; - virtual void do_unselect(int pos) = 0; virtual void do_remove(int pos) = 0; virtual void do_scroll_to_row(int row) = 0; 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; @@ -235,20 +235,6 @@ public: //by index virtual int get_selected_index() const = 0; - //Don't select when frozen, select after thaw. Note selection doesn't survive a freeze. - void select(int pos) - { - disable_notify_events(); - do_select(pos); - enable_notify_events(); - } - - void unselect(int pos) - { - disable_notify_events(); - do_unselect(pos); - enable_notify_events(); - } void remove(int pos) { @@ -379,6 +365,7 @@ public: } //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(); @@ -386,6 +373,7 @@ public: enable_notify_events(); } + using ItemView::unselect; void unselect(const TreeIter& rIter) { disable_notify_events(); diff --git a/vcl/source/weld/ItemView.cxx b/vcl/source/weld/ItemView.cxx index c8628f9b093c..0a0776c5913b 100644 --- a/vcl/source/weld/ItemView.cxx +++ b/vcl/source/weld/ItemView.cxx @@ -11,6 +11,20 @@ namespace weld { +void ItemView::select(int pos) +{ + disable_notify_events(); + do_select(pos); + enable_notify_events(); +} + +void ItemView::unselect(int pos) +{ + disable_notify_events(); + do_unselect(pos); + enable_notify_events(); +} + void ItemView::clear() { disable_notify_events(); commit 06daff53d7a67ca51f86c0583fff371c267475bd Author: Michael Weghorn <[email protected]> AuthorDate: Wed Dec 17 17:57:38 2025 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Thu Dec 18 07:21:27 2025 +0100 sd: Simplify menu handling in LayoutMenu::ShowContextMenu weld::Menu::popup_at_rect returns the ID of the selected entry. Make use of that and pass it directly to LayoutMenu::MenuSelect instead of connecting a handler. Previous commit Change-Id: Iaae1b413b3b237f22c05d389f5960e1ae72a99e8 Author: Michael Weghorn <[email protected]> Date: Wed Dec 17 17:38:37 2025 +0100 sd a11y: Allow opening "Layout" context menu using keyboard describes how to trigger the relevant code path. This potentially also fixes occasional crashes seen previously while testing using the context menu using the keyboard with the gtk3 VCL plugin. stderr output: (soffice:2706178): GLib-GObject-CRITICAL **: 17:47:52.463: instance of invalid non-instantiatable type '(null)' (soffice:2706178): GLib-GObject-CRITICAL **: 17:47:52.463: g_signal_handler_disconnect: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed (soffice:2706178): Gtk-CRITICAL **: 17:47:52.463: gtk_menu_detach: assertion 'GTK_IS_MENU (menu)' failed Change-Id: Ic4c33c6a7cefb303eefbf5ef13892e3576d2a087 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195804 Reviewed-by: Michael Weghorn <[email protected]> Tested-by: Jenkins diff --git a/sd/source/ui/sidebar/LayoutMenu.cxx b/sd/source/ui/sidebar/LayoutMenu.cxx index 9b2a93a98977..95afba573d26 100644 --- a/sd/source/ui/sidebar/LayoutMenu.cxx +++ b/sd/source/ui/sidebar/LayoutMenu.cxx @@ -543,11 +543,6 @@ void LayoutMenu::Clear() mxLayoutIconView->clear(); } -IMPL_LINK(LayoutMenu, OnPopupEnd, const OUString&, sCommand, void) -{ - MenuSelect(sCommand); -} - void LayoutMenu::ShowContextMenu(const Point& pPos) { if (SdModule::get()->GetWaterCan()) @@ -555,9 +550,9 @@ void LayoutMenu::ShowContextMenu(const Point& pPos) // Setup the menu. ::tools::Rectangle aRect(pPos, Size(1, 1)); - mxMenu.reset(); - mxMenuBuilder = Application::CreateBuilder(mxLayoutIconView.get(), u"modules/simpress/ui/layoutmenu.ui"_ustr); - mxMenu = mxMenuBuilder->weld_menu(u"menu"_ustr); + std::unique_ptr<weld::Builder> xMenuBuilder = Application::CreateBuilder( + mxLayoutIconView.get(), u"modules/simpress/ui/layoutmenu.ui"_ustr); + std::unique_ptr<weld::Menu> xMenu = xMenuBuilder->weld_menu(u"menu"_ustr); // Disable the SID_INSERTPAGE_LAYOUT_MENU item when // the document is read-only. @@ -565,10 +560,9 @@ void LayoutMenu::ShowContextMenu(const Point& pPos) const SfxItemState aState ( mrBase.GetViewFrame().GetDispatcher()->QueryState(SID_INSERTPAGE, aResult)); if (aState == SfxItemState::DISABLED) - mxMenu->set_sensitive(u"insert"_ustr, false); + xMenu->set_sensitive(u"insert"_ustr, false); - mxMenu->connect_activate(LINK(this, LayoutMenu, OnPopupEnd)); - mxMenu->popup_at_rect(mxLayoutIconView.get(), aRect); + MenuSelect(xMenu->popup_at_rect(mxLayoutIconView.get(), aRect)); } void LayoutMenu::MenuSelect(const OUString& rIdent) @@ -607,8 +601,6 @@ void LayoutMenu::HandleMenuSelect(std::u16string_view rIdent) // shell. InsertPageWithLayout(GetSelectedAutoLayout()); } - mxMenu.reset(); - mxMenuBuilder.reset(); } // Selects an appropriate layout of the slide inside control. diff --git a/sd/source/ui/sidebar/LayoutMenu.hxx b/sd/source/ui/sidebar/LayoutMenu.hxx index 0a50f9a8cb38..67afecf595ec 100644 --- a/sd/source/ui/sidebar/LayoutMenu.hxx +++ b/sd/source/ui/sidebar/LayoutMenu.hxx @@ -101,9 +101,6 @@ private: css::uno::Reference<css::ui::XSidebar> mxSidebar; bool mbIsDisposed; - std::unique_ptr<weld::Builder> mxMenuBuilder; - std::unique_ptr<weld::Menu> mxMenu; - // Store the size of preview image Size maPreviewSize; @@ -167,7 +164,6 @@ private: DECL_LINK(StateChangeHandler, const OUString&, void); DECL_LINK(EventMultiplexerListener, ::sdtools::EventMultiplexerEvent&, void); DECL_LINK(MenuSelectAsyncHdl, void*, void); - DECL_LINK(OnPopupEnd, const OUString&, void); static VclPtr<VirtualDevice> GetVirtualDevice(Image pPreview); static Bitmap GetPreviewAsBitmap(const Image& rImage);
