Add GtkWidget:layout-manager

We can use a constructor property for existing container widgets with
a layout policy, and move the layout policy implementation out of the
widget itself and into a LayoutManager subclass.
This commit is contained in:
Emmanuele Bassi 2018-12-13 14:04:00 +00:00
parent 1b8595b5f2
commit f7856e887e

View File

@ -543,6 +543,7 @@ enum {
PROP_EXPAND, PROP_EXPAND,
PROP_SCALE_FACTOR, PROP_SCALE_FACTOR,
PROP_CSS_NAME, PROP_CSS_NAME,
PROP_LAYOUT_MANAGER,
NUM_PROPERTIES NUM_PROPERTIES
}; };
@ -1403,6 +1404,19 @@ gtk_widget_class_init (GtkWidgetClass *klass)
NULL, NULL,
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
/**
* GtkWidget:layout-manager:
*
* The #GtkLayoutManager instance to use to compute the preferred size
* of the widget, and allocate its children.
*/
widget_props[PROP_LAYOUT_MANAGER] =
g_param_spec_object ("layout-manager",
P_("Layout Manager"),
P_("The layout manager used to layout children of the widget"),
GTK_TYPE_LAYOUT_MANAGER,
GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, widget_props); g_object_class_install_properties (gobject_class, NUM_PROPERTIES, widget_props);
/** /**
@ -2351,6 +2365,9 @@ gtk_widget_set_property (GObject *object,
else else
gtk_css_node_set_name (priv->cssnode, GTK_WIDGET_GET_CLASS (widget)->priv->css_name); gtk_css_node_set_name (priv->cssnode, GTK_WIDGET_GET_CLASS (widget)->priv->css_name);
break; break;
case PROP_LAYOUT_MANAGER:
gtk_widget_set_layout_manager (widget, g_value_get_object (value));
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -2500,6 +2517,9 @@ gtk_widget_get_property (GObject *object,
case PROP_CSS_NAME: case PROP_CSS_NAME:
g_value_set_string (value, gtk_css_node_get_name (priv->cssnode)); g_value_set_string (value, gtk_css_node_get_name (priv->cssnode));
break; break;
case PROP_LAYOUT_MANAGER:
g_value_set_object (value, gtk_widget_get_layout_manager (widget));
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -13402,6 +13422,8 @@ gtk_widget_set_layout_manager (GtkWidget *widget,
gtk_layout_manager_set_widget (priv->layout_manager, widget); gtk_layout_manager_set_widget (priv->layout_manager, widget);
gtk_widget_queue_resize (widget); gtk_widget_queue_resize (widget);
g_object_notify_by_pspec (G_OBJECT (widget), widget_props[PROP_LAYOUT_MANAGER]);
} }
} }