[gtk/wip/matthiasc/popup5: 27/120] Add gtk_widget_get_native



commit 955d6c41037fa65bdc7789bfe9d8d929e470a6c4
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu May 2 17:32:54 2019 -0400

    Add gtk_widget_get_native
    
    This is a common enough operation to deserve api.

 docs/reference/gtk/gtk4-sections.txt |  1 +
 gtk/gtktypes.h                       |  1 +
 gtk/gtkwidget.c                      | 23 ++++++++++++++++++++++-
 gtk/gtkwidget.h                      |  3 +++
 4 files changed, 27 insertions(+), 1 deletion(-)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index de3797b092..e41a2e166a 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -4441,6 +4441,7 @@ gtk_widget_set_sensitive
 gtk_widget_set_parent
 gtk_widget_get_toplevel
 gtk_widget_get_root
+gtk_widget_get_native
 gtk_widget_get_ancestor
 gtk_widget_is_ancestor
 gtk_widget_translate_coordinates
diff --git a/gtk/gtktypes.h b/gtk/gtktypes.h
index 8a48c1c4c8..2798bd1b02 100644
--- a/gtk/gtktypes.h
+++ b/gtk/gtktypes.h
@@ -39,6 +39,7 @@ typedef struct _GtkClipboard         GtkClipboard;
 typedef struct _GtkEventController     GtkEventController;
 typedef struct _GtkGesture             GtkGesture;
 typedef struct _GtkLayoutManager       GtkLayoutManager;
+typedef struct _GtkNative              GtkNative;
 typedef struct _GtkRequisition        GtkRequisition;
 typedef struct _GtkRoot               GtkRoot;
 typedef struct _GtkSelectionData       GtkSelectionData;
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 94bea67e50..666d014acc 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -3649,7 +3649,7 @@ sync_widget_surface_transform (GtkWidget *widget)
     }
   else
     {
-      GtkWidget *native = gtk_widget_get_ancestor (widget, GTK_TYPE_NATIVE);
+      GtkWidget *native = GTK_WIDGET (gtk_widget_get_native (widget));
 
       if (gtk_widget_compute_transform (widget, native,
                                         &surface_transform_data->cached_surface_transform))
@@ -6678,6 +6678,27 @@ gtk_widget_get_root (GtkWidget *widget)
   return _gtk_widget_get_root (widget);
 }
 
+/**
+ * gtk_widget_get_native:
+ * @widget: a #GtkWidget
+ *
+ * Returns the GtkNative widget that contains @widget,
+ * or %NULL if the widget is not contained inside a
+ * widget tree with a native ancestor.
+ *
+ * #GtkNative widgets will return themselves here.
+ *
+ * Returns: (transfer none) (nullable): the #GtkNative
+ *   widget of @widget, or %NULL
+ */
+GtkNative *
+gtk_widget_get_native (GtkWidget *widget)
+{
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
+
+  return GTK_NATIVE (gtk_widget_get_ancestor (widget, GTK_TYPE_NATIVE));
+}
+
 static void
 gtk_widget_real_direction_changed (GtkWidget        *widget,
                                    GtkTextDirection  previous_direction)
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index 8e1024fade..c34d962c1a 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -549,6 +549,9 @@ GtkWidget *           gtk_widget_get_parent             (GtkWidget    *widget);
 GDK_AVAILABLE_IN_ALL
 GtkRoot *             gtk_widget_get_root               (GtkWidget    *widget);
 
+GDK_AVAILABLE_IN_ALL
+GtkNative *           gtk_widget_get_native             (GtkWidget    *widget);
+
 GDK_AVAILABLE_IN_ALL
 void                  gtk_widget_set_child_visible      (GtkWidget    *widget,
                                                          gboolean      child_visible);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]