Add gtk_widget_get_native

This is a common enough operation to deserve api.
This commit is contained in:
Matthias Clasen 2019-05-02 17:32:54 -04:00
parent d4257d20f8
commit 7dcb163ee6
4 changed files with 38 additions and 2 deletions

View File

@ -4445,6 +4445,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

View File

@ -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;

View File

@ -3652,8 +3652,18 @@ sync_widget_surface_transform (GtkWidget *widget)
}
else
{
g_warning ("Could not compute surface transform");
surface_transform_data->cached_surface_transform_valid = FALSE;
GtkWidget *native = GTK_WIDGET (gtk_widget_get_native (widget));
if (gtk_widget_compute_transform (widget, native,
&surface_transform_data->cached_surface_transform))
{
surface_transform_data->cached_surface_transform_valid = TRUE;
}
else
{
g_warning ("Could not compute surface transform");
surface_transform_data->cached_surface_transform_valid = FALSE;
}
}
if (was_valid != surface_transform_data->cached_surface_transform_valid ||
@ -6672,6 +6682,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)

View File

@ -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);