1#include "config.h"
2
3#include "gtklayoutchild.h"
4
5#include "gtklayoutmanager.h"
6#include "gtkprivate.h"
7
8/**
9 * GtkLayoutChild:
10 *
11 * `GtkLayoutChild` is the base class for objects that are meant to hold
12 * layout properties.
13 *
14 * If a `GtkLayoutManager` has per-child properties, like their packing type,
15 * or the horizontal and vertical span, or the icon name, then the layout
16 * manager should use a `GtkLayoutChild` implementation to store those properties.
17 *
18 * A `GtkLayoutChild` instance is only ever valid while a widget is part
19 * of a layout.
20 */
21
22typedef struct {
23 GtkLayoutManager *manager;
24 GtkWidget *widget;
25} GtkLayoutChildPrivate;
26
27G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GtkLayoutChild, gtk_layout_child, G_TYPE_OBJECT)
28
29enum {
30 PROP_LAYOUT_MANAGER = 1,
31 PROP_CHILD_WIDGET,
32
33 N_PROPS
34};
35
36static GParamSpec *layout_child_properties[N_PROPS];
37
38static void
39gtk_layout_child_set_property (GObject *gobject,
40 guint prop_id,
41 const GValue *value,
42 GParamSpec *pspec)
43{
44 GtkLayoutChild *layout_child = GTK_LAYOUT_CHILD (ptr: gobject);
45 GtkLayoutChildPrivate *priv = gtk_layout_child_get_instance_private (self: layout_child);
46
47 switch (prop_id)
48 {
49 case PROP_LAYOUT_MANAGER:
50 priv->manager = g_value_get_object (value);
51 break;
52
53 case PROP_CHILD_WIDGET:
54 priv->widget = g_value_get_object (value);
55 break;
56
57 default:
58 G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
59 }
60}
61
62static void
63gtk_layout_child_get_property (GObject *gobject,
64 guint prop_id,
65 GValue *value,
66 GParamSpec *pspec)
67{
68 GtkLayoutChild *layout_child = GTK_LAYOUT_CHILD (ptr: gobject);
69 GtkLayoutChildPrivate *priv = gtk_layout_child_get_instance_private (self: layout_child);
70
71 switch (prop_id)
72 {
73 case PROP_LAYOUT_MANAGER:
74 g_value_set_object (value, v_object: priv->manager);
75 break;
76
77 case PROP_CHILD_WIDGET:
78 g_value_set_object (value, v_object: priv->widget);
79 break;
80
81 default:
82 G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
83 }
84}
85
86static void
87gtk_layout_child_constructed (GObject *gobject)
88{
89 GtkLayoutChild *layout_child = GTK_LAYOUT_CHILD (ptr: gobject);
90 GtkLayoutChildPrivate *priv = gtk_layout_child_get_instance_private (self: layout_child);
91
92 G_OBJECT_CLASS (gtk_layout_child_parent_class)->constructed (gobject);
93
94 if (priv->manager == NULL)
95 {
96 g_critical ("The layout child of type %s does not have "
97 "the GtkLayoutChild:layout-manager property set",
98 G_OBJECT_TYPE_NAME (gobject));
99 return;
100 }
101
102 if (priv->widget == NULL)
103 {
104 g_critical ("The layout child of type %s does not have "
105 "the GtkLayoutChild:child-widget property set",
106 G_OBJECT_TYPE_NAME (gobject));
107 return;
108 }
109}
110
111static void
112gtk_layout_child_class_init (GtkLayoutChildClass *klass)
113{
114 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
115
116 gobject_class->set_property = gtk_layout_child_set_property;
117 gobject_class->get_property = gtk_layout_child_get_property;
118 gobject_class->constructed = gtk_layout_child_constructed;
119
120 /**
121 * GtkLayoutChild:layout-manager: (attributes org.gtk.Property.get=gtk_layout_child_get_layout_manager)
122 *
123 * The layout manager that created the `GtkLayoutChild` instance.
124 */
125 layout_child_properties[PROP_LAYOUT_MANAGER] =
126 g_param_spec_object (name: "layout-manager",
127 nick: "Layout Manager",
128 blurb: "The layout manager that created this object",
129 GTK_TYPE_LAYOUT_MANAGER,
130 GTK_PARAM_READWRITE |
131 G_PARAM_CONSTRUCT_ONLY);
132
133 /**
134 * GtkLayoutChild:child-widget: (attributes org.gtk.Property.get=gtk_layout_child_get_child_widget)
135 *
136 * The widget that is associated to the `GtkLayoutChild` instance.
137 */
138 layout_child_properties[PROP_CHILD_WIDGET] =
139 g_param_spec_object (name: "child-widget",
140 nick: "Child Widget",
141 blurb: "The child widget that is associated to this object",
142 GTK_TYPE_WIDGET,
143 GTK_PARAM_READWRITE |
144 G_PARAM_CONSTRUCT_ONLY);
145
146 g_object_class_install_properties (oclass: gobject_class, n_pspecs: N_PROPS, pspecs: layout_child_properties);
147}
148
149static void
150gtk_layout_child_init (GtkLayoutChild *self)
151{
152}
153
154/**
155 * gtk_layout_child_get_layout_manager: (attributes org.gtk.Method.get_property=layout-manager)
156 * @layout_child: a `GtkLayoutChild`
157 *
158 * Retrieves the `GtkLayoutManager` instance that created the
159 * given @layout_child.
160 *
161 * Returns: (transfer none): a `GtkLayoutManager`
162 */
163GtkLayoutManager *
164gtk_layout_child_get_layout_manager (GtkLayoutChild *layout_child)
165{
166 GtkLayoutChildPrivate *priv = gtk_layout_child_get_instance_private (self: layout_child);
167
168 g_return_val_if_fail (GTK_IS_LAYOUT_CHILD (layout_child), NULL);
169
170 return priv->manager;
171}
172
173/**
174 * gtk_layout_child_get_child_widget: (attributes org.gtk.Method.get_property=child-widget)
175 * @layout_child: a `GtkLayoutChild`
176 *
177 * Retrieves the `GtkWidget` associated to the given @layout_child.
178 *
179 * Returns: (transfer none): a `GtkWidget`
180 */
181GtkWidget *
182gtk_layout_child_get_child_widget (GtkLayoutChild *layout_child)
183{
184 GtkLayoutChildPrivate *priv = gtk_layout_child_get_instance_private (self: layout_child);
185
186 g_return_val_if_fail (GTK_IS_LAYOUT_CHILD (layout_child), NULL);
187
188 return priv->widget;
189}
190

source code of gtk/gtk/gtklayoutchild.c