diff options
author | Caolán McNamara <caolanm@redhat.com> | 2021-07-07 16:33:48 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2021-07-07 18:37:36 +0200 |
commit | 7d180d713392b98e40bc3778d9434a9b6fd0aa8b (patch) | |
tree | b020a400dfbb8957e16166a6960ce16f1a96c3ec | |
parent | e3c1460462ce1fdb7073b876c1d802e4b2cb49c6 (diff) |
gtk4: implement Menu::get_n_children for gtk4
Change-Id: I6a6202783d30da2487e4033bcbe859e72f959f12
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118579
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | vcl/unx/gtk3/gtkinst.cxx | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx index 79cabe5f3ec0..05bbdb1eb30c 100644 --- a/vcl/unx/gtk3/gtkinst.cxx +++ b/vcl/unx/gtk3/gtkinst.cxx @@ -4900,7 +4900,7 @@ public: #if GTK_CHECK_VERSION(4, 0, 0) /* LibreOffice likes to think of separators between menu entries, while gtk likes to think of sections of menus with separators drawn between sections. We always - arrange to have a section in a menua so toplevel menumodels comprise of + arrange to have a section in a menu so toplevel menumodels comprise of sections and we move entries between sections on pretending to insert separators */ static std::pair<GMenuModel*, int> get_section_and_pos_for(GMenuModel* pMenuModel, int pos) { @@ -4927,6 +4927,27 @@ public: return std::make_pair(pSectionModel, nIndexWithinSection); } + + static int count_immediate_children(GMenuModel* pMenuModel) + { + int nSectionCount = g_menu_model_get_n_items(pMenuModel); + assert(nSectionCount); + + int nExternalPos = 0; + for (int nSection = 0; nSection < nSectionCount; ++nSection) + { + GMenuModel* pSectionModel = g_menu_model_get_item_link(pMenuModel, nSection, G_MENU_LINK_SECTION); + assert(pSectionModel); + int nCount = g_menu_model_get_n_items(pSectionModel); + for (int nIndexWithinSection = 0; nIndexWithinSection < nCount; ++nIndexWithinSection) + { + ++nExternalPos; + } + ++nExternalPos; + } + + return nExternalPos - 1; + } #endif #if GTK_CHECK_VERSION(4, 0, 0) @@ -5272,6 +5293,20 @@ public: #endif } + int get_n_children() const + { +#if !GTK_CHECK_VERSION(4, 0, 0) + GList* pChildren = gtk_container_get_children(GTK_CONTAINER(m_pMenu)); + int nLen = g_list_length(pChildren); + g_list_free(pChildren); + return nLen; +#else + if (GMenuModel* pMenuModel = gtk_popover_menu_get_menu_model(m_pMenu)) + return count_immediate_children(pMenuModel); + return 0; +#endif + } + void clear_items() { #if !GTK_CHECK_VERSION(4, 0, 0) @@ -10519,14 +10554,7 @@ public: virtual int n_children() const override { -#if !GTK_CHECK_VERSION(4, 0, 0) - GList* pChildren = gtk_container_get_children(GTK_CONTAINER(m_pMenu)); - int nLen = g_list_length(pChildren); - g_list_free(pChildren); - return nLen; -#else - return 0; -#endif + return get_n_children(); } void remove(const OString& rIdent) override |