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

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Wed May 12 14:54:01 UTC 2021


 vcl/inc/unx/gtk/gtkdata.hxx |   15 ++++++++++++++-
 vcl/unx/gtk3/gtkinst.cxx    |   28 ++++++----------------------
 2 files changed, 20 insertions(+), 23 deletions(-)

New commits:
commit b5c21b95e4b9801902ef9ed3464d09d70d7d1dcf
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Wed May 12 14:32:08 2021 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Wed May 12 16:53:23 2021 +0200

    gtk4: add widget_get_first_child to wrap gtk_widget_get_first_child
    
    and equivalent gtk3 calls
    
    Change-Id: Iab6801466d6677ae5a7419470ce3bb32e16e68ac
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115486
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/vcl/inc/unx/gtk/gtkdata.hxx b/vcl/inc/unx/gtk/gtkdata.hxx
index d12138298b43..92f8f28c0b6d 100644
--- a/vcl/inc/unx/gtk/gtkdata.hxx
+++ b/vcl/inc/unx/gtk/gtkdata.hxx
@@ -77,7 +77,7 @@ inline GtkWidget* widget_get_root(GtkWidget* pWidget)
 #endif
 }
 
-inline const char * image_get_icon_name(GtkImage *pImage)
+inline const char* image_get_icon_name(GtkImage *pImage)
 {
 #if GTK_CHECK_VERSION(4, 0, 0)
     return gtk_image_get_icon_name(pImage);
@@ -88,6 +88,19 @@ inline const char * image_get_icon_name(GtkImage *pImage)
 #endif
 }
 
+inline GtkWidget* widget_get_first_child(GtkWidget *pWidget)
+{
+#if GTK_CHECK_VERSION(4, 0, 0)
+    return gtk_widget_get_first_child(pWidget);
+#else
+    GList* pChildren = gtk_container_get_children(GTK_CONTAINER(pWidget));
+    GList* pChild = g_list_first(pChildren);
+    GtkWidget* pRet = pChild ? static_cast<GtkWidget*>(pChild->data) : nullptr;
+    g_list_free(pChildren);
+    return pRet;
+#endif
+}
+
 class GtkSalTimer final : public SalTimer
 {
     struct SalGtkTimeoutSource *m_pTimeout;
diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx
index 29804f5677c3..67d8e2a897be 100644
--- a/vcl/unx/gtk3/gtkinst.cxx
+++ b/vcl/unx/gtk3/gtkinst.cxx
@@ -4417,17 +4417,12 @@ namespace
     {
 #if !GTK_CHECK_VERSION(4, 0, 0)
         // try and omit drawing CSD under wayland
-        GList* pChildren = gtk_container_get_children(GTK_CONTAINER(pTopLevel));
-        GList* pChild = g_list_first(pChildren);
+        GtkWidget* pChild = widget_get_first_child(pTopLevel);
 
         int x, y;
-        gtk_widget_translate_coordinates(GTK_WIDGET(pChild->data),
-                                         GTK_WIDGET(pTopLevel),
-                                         0, 0, &x, &y);
-
-        int innerborder = gtk_container_get_border_width(GTK_CONTAINER(pChild->data));
-        g_list_free(pChildren);
+        gtk_widget_translate_coordinates(pChild, pTopLevel, 0, 0, &x, &y);
 
+        int innerborder = gtk_container_get_border_width(GTK_CONTAINER(pChild));
         int outerborder = gtk_container_get_border_width(GTK_CONTAINER(pTopLevel));
         int totalborder = outerborder + innerborder;
         x -= totalborder;
@@ -17821,14 +17816,8 @@ public:
             if (GtkInstanceContainer* pPage = dynamic_cast<GtkInstanceContainer*>(xNotebook->get_page(xNotebook->get_current_page_ident())))
             {
                 GtkWidget* pContainer = pPage->getWidget();
-                GList* pChildren = gtk_container_get_children(GTK_CONTAINER(pContainer));
-                GList* pChild = g_list_first(pChildren);
-                if (pChild)
-                {
-                    GtkWidget* pPageWidget = static_cast<GtkWidget*>(pChild->data);
+                if (GtkWidget* pPageWidget = widget_get_first_child(pContainer))
                     sPageHelpId = ::get_help_id(pPageWidget);
-                }
-                g_list_free(pChildren);
             }
         }
         return sPageHelpId;
@@ -18317,14 +18306,9 @@ void GtkInstanceWindow::help()
             }
             if (pContainer)
             {
-                GList* pChildren = gtk_container_get_children(pContainer);
-                GList* pChild = g_list_first(pChildren);
-                if (pChild)
-                {
-                    GtkWidget* pContentWidget = static_cast<GtkWidget*>(pChild->data);
+                GtkWidget* pContentWidget = widget_get_first_child(GTK_WIDGET(pContainer));
+                if (pContentWidget)
                     sHelpId = ::get_help_id(pContentWidget);
-                }
-                g_list_free(pChildren);
             }
         }
     }


More information about the Libreoffice-commits mailing list