include/vcl/weld.hxx | 5 +++++ vcl/source/app/salvtables.cxx | 5 ++++- vcl/unx/gtk3/gtk3gtkinst.cxx | 22 ++++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-)
New commits: commit 1327fa4b1dff932500c690c263840fde192988ed Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Thu Jan 9 10:11:18 2020 +0000 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Thu Jan 9 17:03:02 2020 +0100 add hook for on-demand welded toolbar popover creation Change-Id: I662976a62281909e30d5b256e10ddcf2ceee2595 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86474 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx index c8ccf4291338..e205ea2459c6 100644 --- a/include/vcl/weld.hxx +++ b/include/vcl/weld.hxx @@ -1956,8 +1956,10 @@ class VCL_DLLPUBLIC Toolbar : virtual public Widget { protected: Link<const OString&, void> m_aClickHdl; + Link<const OString&, void> m_aShowMenuHdl; void signal_clicked(const OString& rIdent) { m_aClickHdl.Call(rIdent); } + void signal_show_menu(const OString& rIdent) { m_aShowMenuHdl.Call(rIdent); } public: virtual void set_item_sensitive(const OString& rIdent, bool bSensitive) = 0; @@ -1995,6 +1997,9 @@ public: virtual vcl::ImageType get_icon_size() const = 0; void connect_clicked(const Link<const OString&, void>& rLink) { m_aClickHdl = rLink; } + // m_aShowMenuHdl is called before the menu is shown. + // It can be used to populate the menu on demand with set_item_popover/set_item_menu + void connect_show_menu(const Link<const OString&, void>& rLink) { m_aShowMenuHdl = rLink; } }; class VCL_DLLPUBLIC SizeGroup diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index 910778b2da6e..3ef767cb13fe 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -1160,7 +1160,10 @@ IMPL_LINK_NOARG(SalInstanceToolbar, ClickHdl, ToolBox*, void) IMPL_LINK_NOARG(SalInstanceToolbar, DropdownClick, ToolBox*, void) { sal_uInt16 nItemId = m_xToolBox->GetCurItemId(); - set_menu_item_active(m_xToolBox->GetItemCommand(nItemId).toUtf8(), true); + + OString sIdent = m_xToolBox->GetItemCommand(nItemId).toUtf8(); + signal_show_menu(sIdent); + set_menu_item_active(sIdent, true); } namespace { diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index bc7802987366..bc53e4cf3cce 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -7116,7 +7116,10 @@ private: OString id(pStr, pStr ? strlen(pStr) : 0); m_aMap[id] = pToolItem; if (pMenuButton) + { m_aMenuButtonMap[id] = std::make_unique<GtkInstanceMenuButton>(pMenuButton, m_pBuilder, false); + g_signal_connect(pToolItem, "show-menu", G_CALLBACK(signalItemShowMenu), this); + } g_signal_connect(pToolItem, "clicked", G_CALLBACK(signalItemClicked), this); } @@ -7133,6 +7136,19 @@ private: signal_clicked(OString(pStr, pStr ? strlen(pStr) : 0)); } + static void signalItemShowMenu(GtkMenuToolButton* pItem, gpointer widget) + { + GtkInstanceToolbar* pThis = static_cast<GtkInstanceToolbar*>(widget); + SolarMutexGuard aGuard; + pThis->signal_item_show_menu(pItem); + } + + void signal_item_show_menu(GtkMenuToolButton* pItem) + { + const gchar* pStr = gtk_buildable_get_name(GTK_BUILDABLE(pItem)); + signal_show_menu(OString(pStr, pStr ? strlen(pStr) : 0)); + } + static void set_item_image(GtkToolButton* pItem, const css::uno::Reference<css::graphic::XGraphic>& rIcon) { GtkWidget* pImage = nullptr; @@ -7171,13 +7187,19 @@ public: void disable_item_notify_events() { for (auto& a : m_aMap) + { g_signal_handlers_block_by_func(a.second, reinterpret_cast<void*>(signalItemClicked), this); + g_signal_handlers_block_by_func(a.second, reinterpret_cast<void*>(signalItemShowMenu), this); + } } void enable_item_notify_events() { for (auto& a : m_aMap) + { + g_signal_handlers_unblock_by_func(a.second, reinterpret_cast<void*>(signalItemShowMenu), this); g_signal_handlers_unblock_by_func(a.second, reinterpret_cast<void*>(signalItemClicked), this); + } } virtual void set_item_sensitive(const OString& rIdent, bool bSensitive) override _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits