[Libreoffice-commits] core.git: vcl/unx

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Wed Jul 7 16:38:12 UTC 2021


 vcl/unx/gtk3/gtkinst.cxx |   46 +++++++++++++++++++++++++++++++++++++---------
 1 file changed, 37 insertions(+), 9 deletions(-)

New commits:
commit 7d180d713392b98e40bc3778d9434a9b6fd0aa8b
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Wed Jul 7 16:33:48 2021 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Wed Jul 7 18:37:36 2021 +0200

    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 at redhat.com>

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


More information about the Libreoffice-commits mailing list