Merge branch 'issue-1863' into 'master'

Allow setting the GtkLayoutManager type per-class

Closes #1863

See merge request GNOME/gtk!821
This commit is contained in:
Emmanuele Bassi 2019-05-06 12:01:47 +00:00
commit ecc8f9cf72
8 changed files with 73 additions and 13 deletions

View File

@ -161,6 +161,7 @@ gtk_box_class_init (GtkBoxClass *class)
g_object_class_install_properties (object_class, LAST_PROP, props);
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_FILLER);
gtk_widget_class_set_css_name (widget_class, I_("box"));
}
@ -344,12 +345,9 @@ static void
gtk_box_init (GtkBox *box)
{
GtkBoxPrivate *priv = gtk_box_get_instance_private (box);
GtkLayoutManager *box_layout = gtk_box_layout_new (GTK_ORIENTATION_HORIZONTAL);
gtk_widget_set_has_surface (GTK_WIDGET (box), FALSE);
gtk_widget_set_layout_manager (GTK_WIDGET (box), box_layout);
priv->orientation = GTK_ORIENTATION_HORIZONTAL;
_gtk_orientable_set_style_classes (GTK_ORIENTABLE (box));
}

View File

@ -422,6 +422,8 @@ gtk_file_chooser_button_class_init (GtkFileChooserButtonClass * class)
_gtk_file_chooser_install_properties (gobject_class);
gtk_widget_class_set_css_name (widget_class, I_("filechooserbutton"));
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
}
static void
@ -497,8 +499,6 @@ gtk_file_chooser_button_init (GtkFileChooserButton *button)
target_list,
GDK_ACTION_COPY);
gdk_content_formats_unref (target_list);
gtk_widget_set_layout_manager (GTK_WIDGET (button), gtk_bin_layout_new ());
}

View File

@ -8326,6 +8326,8 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
gtk_widget_class_bind_template_callback (widget_class, widget_key_press_cb);
gtk_widget_class_set_css_name (widget_class, I_("filechooser"));
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
}
static void
@ -8467,8 +8469,6 @@ gtk_file_chooser_widget_init (GtkFileChooserWidget *impl)
*/
post_process_ui (impl);
gtk_widget_set_layout_manager (GTK_WIDGET (impl), gtk_bin_layout_new ());
profile_end ("end", NULL);
}

View File

@ -96,11 +96,14 @@ static void
gtk_fixed_class_init (GtkFixedClass *klass)
{
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
container_class->add = gtk_fixed_add;
container_class->remove = gtk_fixed_remove;
container_class->forall = gtk_fixed_forall;
container_class->child_type = gtk_fixed_child_type;
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_FIXED_LAYOUT);
}
static GType
@ -117,8 +120,7 @@ gtk_fixed_init (GtkFixed *self)
gtk_widget_set_has_surface (GTK_WIDGET (self), FALSE);
gtk_widget_set_overflow (GTK_WIDGET (self), GTK_OVERFLOW_HIDDEN);
priv->layout = gtk_fixed_layout_new ();
gtk_widget_set_layout_manager (GTK_WIDGET (self), priv->layout);
priv->layout = gtk_widget_get_layout_manager (GTK_WIDGET (self));
}
/**

View File

@ -380,6 +380,8 @@ gtk_grid_class_init (GtkGridClass *class)
g_object_class_install_properties (object_class, N_PROPERTIES, obj_properties);
gtk_widget_class_set_css_name (widget_class, I_("grid"));
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_GRID_LAYOUT);
}
static void
@ -389,8 +391,7 @@ gtk_grid_init (GtkGrid *grid)
gtk_widget_set_has_surface (GTK_WIDGET (grid), FALSE);
priv->layout_manager = gtk_grid_layout_new ();
gtk_widget_set_layout_manager (GTK_WIDGET (grid), priv->layout_manager);
priv->layout_manager = gtk_widget_get_layout_manager (GTK_WIDGET (grid));
priv->orientation = GTK_ORIENTATION_HORIZONTAL;
_gtk_orientable_set_style_classes (GTK_ORIENTABLE (grid));

View File

@ -302,6 +302,8 @@ gtk_overlay_class_init (GtkOverlayClass *klass)
GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
gtk_widget_class_set_css_name (widget_class, I_("overlay"));
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_OVERLAY_LAYOUT);
}
static void
@ -311,8 +313,7 @@ gtk_overlay_init (GtkOverlay *overlay)
gtk_widget_set_has_surface (GTK_WIDGET (overlay), FALSE);
priv->layout = gtk_overlay_layout_new ();
gtk_widget_set_layout_manager (GTK_WIDGET (overlay), priv->layout);
priv->layout = gtk_widget_get_layout_manager (GTK_WIDGET (overlay));
}
static GtkBuildableIface *parent_buildable_iface;

View File

@ -497,6 +497,7 @@ struct _GtkWidgetClassPrivate
GType accessible_type;
AtkRole accessible_role;
const char *css_name;
GType layout_manager_type;
};
enum {
@ -2740,6 +2741,7 @@ gtk_widget_init (GTypeInstance *instance, gpointer g_class)
{
GtkWidget *widget = GTK_WIDGET (instance);
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
GType layout_manager_type;
widget->priv = priv;
@ -2808,6 +2810,10 @@ gtk_widget_init (GTypeInstance *instance, gpointer g_class)
if (g_type_is_a (G_TYPE_FROM_CLASS (g_class), GTK_TYPE_ROOT))
priv->root = (GtkRoot *) widget;
layout_manager_type = gtk_widget_class_get_layout_manager_type (g_class);
if (layout_manager_type != G_TYPE_INVALID)
gtk_widget_set_layout_manager (widget, g_object_new (layout_manager_type, NULL));
}
/**
@ -13575,6 +13581,52 @@ gtk_widget_get_height (GtkWidget *widget)
return priv->height;
}
/**
* gtk_widget_class_set_layout_manager_type:
* @widget_class: class to set the layout manager type for
* @type: The object type that implements the #GtkLayoutManager for @widget_class
*
* Sets the type to be used for creating layout managers for widgets of
* @widget_class. The given @type must be a subtype of #GtkLayoutManager.
*
* This function should only be called from class init functions of widgets.
**/
void
gtk_widget_class_set_layout_manager_type (GtkWidgetClass *widget_class,
GType type)
{
GtkWidgetClassPrivate *priv;
g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
g_return_if_fail (g_type_is_a (type, GTK_TYPE_LAYOUT_MANAGER));
priv = widget_class->priv;
priv->layout_manager_type = type;
}
/**
* gtk_widget_class_get_layout_manager_type:
* @widget_class: a #GtkWidgetClass
*
* Retrieves the type of the #GtkLayoutManager used by the #GtkWidget class.
*
* See also: gtk_widget_class_set_layout_manager_type()
*
* Returns: a #GtkLayoutManager subclass, or %G_TYPE_INVALID
*/
GType
gtk_widget_class_get_layout_manager_type (GtkWidgetClass *widget_class)
{
GtkWidgetClassPrivate *priv;
g_return_val_if_fail (GTK_IS_WIDGET_CLASS (widget_class), G_TYPE_INVALID);
priv = widget_class->priv;
return priv->layout_manager_type;
}
/**
* gtk_widget_set_layout_manager:
* @widget: a #GtkWidget

View File

@ -414,6 +414,12 @@ void gtk_widget_set_layout_manager (GtkWidget *widge
GDK_AVAILABLE_IN_ALL
GtkLayoutManager * gtk_widget_get_layout_manager (GtkWidget *widget);
GDK_AVAILABLE_IN_ALL
void gtk_widget_class_set_layout_manager_type (GtkWidgetClass *widget_class,
GType type);
GDK_AVAILABLE_IN_ALL
GType gtk_widget_class_get_layout_manager_type (GtkWidgetClass *widget_class);
GDK_AVAILABLE_IN_ALL
void gtk_widget_add_accelerator (GtkWidget *widget,
const gchar *accel_signal,