include/vcl/weld.hxx | 3 +++ vcl/source/app/salvtables.cxx | 4 ++++ vcl/unx/gtk3/gtk3gtkinst.cxx | 31 ++++++++++++++++++++++++------- 3 files changed, 31 insertions(+), 7 deletions(-)
New commits: commit 6afb18bc5fbc530d6404eac1c9e7191e58de27fc Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Sun Jan 19 17:06:02 2020 +0000 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Sun Jan 19 20:24:18 2020 +0100 add api to determine number of menu items Change-Id: I69082c1b564c42be7a14fa36b0ba1dab34a3b5b8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87043 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx index 9890be5d4bc0..9aa93cbe84ec 100644 --- a/include/vcl/weld.hxx +++ b/include/vcl/weld.hxx @@ -1949,6 +1949,9 @@ public: insert(-1, rId, rStr, nullptr, &rImage, false); } + // return the number of toplevel nodes + virtual int n_children() const = 0; + virtual ~Menu() {} }; diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index 248a62090f06..1603033ded71 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -921,6 +921,10 @@ public: auto nInsertPos = pos == -1 ? MENU_APPEND : pos; m_xMenu->InsertSeparator(rId.toUtf8(), nInsertPos); } + virtual int n_children() const override + { + return m_xMenu->GetItemCount(); + } PopupMenu* getMenu() const { return m_xMenu.get(); diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index fdb8d66f68a2..f146049dffd2 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -7056,6 +7056,14 @@ public: gtk_menu_reorder_child(m_pMenu, pItem, pos); } + virtual int n_children() const override + { + GList* pChildren = gtk_container_get_children(GTK_CONTAINER(m_pMenu)); + int nLen = g_list_length(pChildren); + g_list_free(pChildren); + return nLen; + } + virtual ~GtkInstanceMenu() override { clear_extras(); commit 3ed742a0dbe2566007447f9adb0f54f5424bd05d Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Sun Jan 19 17:02:35 2020 +0000 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Sun Jan 19 20:24:04 2020 +0100 report submenu activatation the same with/without MenuButton as a toplevel Change-Id: I0883281291d2084d91c2c4b6f2d2d233c3448fcd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87042 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index fdc09fa45581..fdb8d66f68a2 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -6841,7 +6841,7 @@ class GtkInstanceMenu : public MenuHelper, public virtual weld::Menu protected: std::vector<GtkMenuItem*> m_aExtraItems; OString m_sActivated; - GtkInstanceMenuButton* m_pTopLevelMenuButton; + MenuHelper* m_pTopLevelMenuHelper; private: virtual void signal_activate(GtkMenuItem* pItem) override @@ -6855,10 +6855,10 @@ private: { if (m_aExtraItems.empty()) return; - if (m_pTopLevelMenuButton) + if (m_pTopLevelMenuHelper) { for (auto a : m_aExtraItems) - m_pTopLevelMenuButton->remove_from_map(a); + m_pTopLevelMenuHelper->remove_from_map(a); } m_aExtraItems.clear(); } @@ -6866,8 +6866,9 @@ private: public: GtkInstanceMenu(GtkMenu* pMenu, bool bTakeOwnership) : MenuHelper(pMenu, bTakeOwnership) - , m_pTopLevelMenuButton(nullptr) + , m_pTopLevelMenuHelper(nullptr) { + g_object_set_data(G_OBJECT(m_pMenu), "g-lo-GtkInstanceMenu", this); // tdf#122527 if we're welding a submenu of a menu of a MenuButton, // then find that MenuButton parent so that when adding items to this // menu we can inform the MenuButton of their addition @@ -6884,11 +6885,18 @@ public: } if (pTopLevelMenu != pMenu) { + // maybe the toplevel is a menubutton GtkWidget* pAttached = gtk_menu_get_attach_widget(pTopLevelMenu); if (pAttached && GTK_IS_MENU_BUTTON(pAttached)) { void* pData = g_object_get_data(G_OBJECT(pAttached), "g-lo-GtkInstanceButton"); - m_pTopLevelMenuButton = dynamic_cast<GtkInstanceMenuButton*>(static_cast<GtkInstanceButton*>(pData)); + m_pTopLevelMenuHelper = dynamic_cast<GtkInstanceMenuButton*>(static_cast<GtkInstanceButton*>(pData)); + } + // or maybe a menu + if (!m_pTopLevelMenuHelper) + { + void* pData = g_object_get_data(G_OBJECT(pTopLevelMenu), "g-lo-GtkInstanceMenu"); + m_pTopLevelMenuHelper = static_cast<GtkInstanceMenu*>(pData); } } } @@ -7042,8 +7050,8 @@ public: GtkMenuItem* pMenuItem = GTK_MENU_ITEM(pItem); m_aExtraItems.push_back(pMenuItem); add_to_map(pMenuItem); - if (m_pTopLevelMenuButton) - m_pTopLevelMenuButton->add_to_map(pMenuItem); + if (m_pTopLevelMenuHelper) + m_pTopLevelMenuHelper->add_to_map(pMenuItem); if (pos != -1) gtk_menu_reorder_child(m_pMenu, pItem, pos); } @@ -7051,6 +7059,7 @@ public: virtual ~GtkInstanceMenu() override { clear_extras(); + g_object_steal_data(G_OBJECT(m_pMenu), "g-lo-GtkInstanceMenu"); } }; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits