1 /* gtkcellareacontext.c
3 * Copyright (C) 2010 Openismus GmbH
6 * Tristan Van Berkom <tristanvb@openismus.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
26 #include "gtkmarshalers.h"
27 #include "gtkcellareacontext.h"
28 #include "gtkprivate.h"
31 static void gtk_cell_area_context_dispose (GObject *object);
32 static void gtk_cell_area_context_get_property (GObject *object,
36 static void gtk_cell_area_context_set_property (GObject *object,
41 /* GtkCellAreaContextClass */
42 static void gtk_cell_area_context_real_flush_preferred_width (GtkCellAreaContext *context);
43 static void gtk_cell_area_context_real_flush_preferred_height (GtkCellAreaContext *context);
44 static void gtk_cell_area_context_real_flush_allocation (GtkCellAreaContext *context);
45 static void gtk_cell_area_context_real_allocate (GtkCellAreaContext *context,
49 struct _GtkCellAreaContextPrivate
51 GtkCellArea *cell_area;
70 G_DEFINE_TYPE (GtkCellAreaContext, gtk_cell_area_context, G_TYPE_OBJECT);
73 gtk_cell_area_context_init (GtkCellAreaContext *context)
75 GtkCellAreaContextPrivate *priv;
77 context->priv = G_TYPE_INSTANCE_GET_PRIVATE (context,
78 GTK_TYPE_CELL_AREA_CONTEXT,
79 GtkCellAreaContextPrivate);
84 priv->min_height = -1;
85 priv->nat_height = -1;
89 gtk_cell_area_context_class_init (GtkCellAreaContextClass *class)
91 GObjectClass *object_class = G_OBJECT_CLASS (class);
94 object_class->dispose = gtk_cell_area_context_dispose;
95 object_class->get_property = gtk_cell_area_context_get_property;
96 object_class->set_property = gtk_cell_area_context_set_property;
98 /* GtkCellAreaContextClass */
99 class->flush_preferred_width = gtk_cell_area_context_real_flush_preferred_width;
100 class->flush_preferred_height = gtk_cell_area_context_real_flush_preferred_height;
101 class->flush_allocation = gtk_cell_area_context_real_flush_allocation;
102 class->sum_preferred_width = NULL;
103 class->sum_preferred_height = NULL;
104 class->allocate = gtk_cell_area_context_real_allocate;
106 g_object_class_install_property (object_class,
108 g_param_spec_object ("area",
110 P_("The Cell Area this context was created for"),
112 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
114 g_object_class_install_property (object_class,
116 g_param_spec_int ("minimum-width",
118 P_("Minimum cached width"),
124 g_object_class_install_property (object_class,
126 g_param_spec_int ("natural-width",
128 P_("Minimum cached width"),
134 g_object_class_install_property (object_class,
136 g_param_spec_int ("minimum-height",
137 P_("Minimum Height"),
138 P_("Minimum cached height"),
144 g_object_class_install_property (object_class,
146 g_param_spec_int ("natural-height",
147 P_("Minimum Height"),
148 P_("Minimum cached height"),
154 g_type_class_add_private (object_class, sizeof (GtkCellAreaContextPrivate));
157 /*************************************************************
159 *************************************************************/
161 gtk_cell_area_context_dispose (GObject *object)
163 GtkCellAreaContext *context = GTK_CELL_AREA_CONTEXT (object);
164 GtkCellAreaContextPrivate *priv = context->priv;
168 g_object_unref (priv->cell_area);
170 priv->cell_area = NULL;
173 G_OBJECT_CLASS (gtk_cell_area_context_parent_class)->dispose (object);
177 gtk_cell_area_context_set_property (GObject *object,
182 GtkCellAreaContext *context = GTK_CELL_AREA_CONTEXT (object);
183 GtkCellAreaContextPrivate *priv = context->priv;
188 priv->cell_area = g_value_dup_object (value);
191 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
197 gtk_cell_area_context_get_property (GObject *object,
202 GtkCellAreaContext *context = GTK_CELL_AREA_CONTEXT (object);
203 GtkCellAreaContextPrivate *priv = context->priv;
208 g_value_set_object (value, priv->cell_area);
211 g_value_set_int (value, priv->min_width);
214 g_value_set_int (value, priv->nat_width);
216 case PROP_MIN_HEIGHT:
217 g_value_set_int (value, priv->min_height);
219 case PROP_NAT_HEIGHT:
220 g_value_set_int (value, priv->nat_height);
223 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
228 /*************************************************************
229 * GtkCellAreaContextClass *
230 *************************************************************/
232 gtk_cell_area_context_real_flush_preferred_width (GtkCellAreaContext *context)
234 GtkCellAreaContextPrivate *priv = context->priv;
236 priv->min_width = -1;
237 priv->nat_width = -1;
239 g_object_freeze_notify (G_OBJECT (context));
240 g_object_notify (G_OBJECT (context), "minimum-width");
241 g_object_notify (G_OBJECT (context), "natural-width");
242 g_object_thaw_notify (G_OBJECT (context));
246 gtk_cell_area_context_real_flush_preferred_height (GtkCellAreaContext *context)
248 GtkCellAreaContextPrivate *priv = context->priv;
250 priv->min_height = -1;
251 priv->nat_height = -1;
253 g_object_freeze_notify (G_OBJECT (context));
254 g_object_notify (G_OBJECT (context), "minimum-height");
255 g_object_notify (G_OBJECT (context), "natural-height");
256 g_object_thaw_notify (G_OBJECT (context));
260 gtk_cell_area_context_real_flush_allocation (GtkCellAreaContext *context)
262 GtkCellAreaContextPrivate *priv = context->priv;
264 priv->alloc_width = 0;
265 priv->alloc_height = 0;
269 gtk_cell_area_context_real_allocate (GtkCellAreaContext *context,
273 GtkCellAreaContextPrivate *priv = context->priv;
275 priv->alloc_width = width;
276 priv->alloc_height = height;
279 /*************************************************************
281 *************************************************************/
283 gtk_cell_area_context_get_area (GtkCellAreaContext *context)
285 GtkCellAreaContextPrivate *priv;
287 g_return_val_if_fail (GTK_IS_CELL_AREA_CONTEXT (context), NULL);
289 priv = context->priv;
291 return priv->cell_area;
295 gtk_cell_area_context_flush (GtkCellAreaContext *context)
297 g_return_if_fail (GTK_IS_CELL_AREA_CONTEXT (context));
299 gtk_cell_area_context_flush_preferred_width (context);
300 gtk_cell_area_context_flush_preferred_height (context);
301 gtk_cell_area_context_flush_allocation (context);
305 gtk_cell_area_context_flush_preferred_width (GtkCellAreaContext *context)
307 g_return_if_fail (GTK_IS_CELL_AREA_CONTEXT (context));
309 GTK_CELL_AREA_CONTEXT_GET_CLASS (context)->flush_preferred_width (context);
313 gtk_cell_area_context_flush_preferred_height (GtkCellAreaContext *context)
315 g_return_if_fail (GTK_IS_CELL_AREA_CONTEXT (context));
317 GTK_CELL_AREA_CONTEXT_GET_CLASS (context)->flush_preferred_height (context);
321 gtk_cell_area_context_flush_allocation (GtkCellAreaContext *context)
323 g_return_if_fail (GTK_IS_CELL_AREA_CONTEXT (context));
325 GTK_CELL_AREA_CONTEXT_GET_CLASS (context)->flush_allocation (context);
329 gtk_cell_area_context_sum_preferred_width (GtkCellAreaContext *context)
331 GtkCellAreaContextClass *class;
333 g_return_if_fail (GTK_IS_CELL_AREA_CONTEXT (context));
335 class = GTK_CELL_AREA_CONTEXT_GET_CLASS (context);
337 if (class->sum_preferred_width)
338 class->sum_preferred_width (context);
342 gtk_cell_area_context_sum_preferred_height (GtkCellAreaContext *context)
344 GtkCellAreaContextClass *class;
346 g_return_if_fail (GTK_IS_CELL_AREA_CONTEXT (context));
348 class = GTK_CELL_AREA_CONTEXT_GET_CLASS (context);
350 if (class->sum_preferred_height)
351 class->sum_preferred_height (context);
355 gtk_cell_area_context_allocate (GtkCellAreaContext *context,
359 GtkCellAreaContextClass *class;
361 g_return_if_fail (GTK_IS_CELL_AREA_CONTEXT (context));
363 class = GTK_CELL_AREA_CONTEXT_GET_CLASS (context);
365 class->allocate (context, width, height);
369 gtk_cell_area_context_get_preferred_width (GtkCellAreaContext *context,
373 GtkCellAreaContextPrivate *priv;
375 g_return_if_fail (GTK_IS_CELL_AREA_CONTEXT (context));
377 priv = context->priv;
380 *minimum_width = priv->min_width;
383 *natural_width = priv->nat_width;
387 gtk_cell_area_context_get_preferred_height (GtkCellAreaContext *context,
388 gint *minimum_height,
389 gint *natural_height)
391 GtkCellAreaContextPrivate *priv;
393 g_return_if_fail (GTK_IS_CELL_AREA_CONTEXT (context));
395 priv = context->priv;
398 *minimum_height = priv->min_height;
401 *natural_height = priv->nat_height;
405 gtk_cell_area_context_get_allocation (GtkCellAreaContext *context,
409 GtkCellAreaContextPrivate *priv;
411 g_return_if_fail (GTK_IS_CELL_AREA_CONTEXT (context));
413 priv = context->priv;
416 *width = priv->alloc_width;
419 *height = priv->alloc_height;
423 gtk_cell_area_context_push_preferred_width (GtkCellAreaContext *context,
427 GtkCellAreaContextPrivate *priv;
429 g_return_if_fail (GTK_IS_CELL_AREA_CONTEXT (context));
431 priv = context->priv;
433 g_object_freeze_notify (G_OBJECT (context));
435 if (minimum_width > priv->min_width)
437 priv->min_width = minimum_width;
439 g_object_notify (G_OBJECT (context), "minimum-width");
442 if (natural_width > priv->nat_width)
444 priv->nat_width = natural_width;
446 g_object_notify (G_OBJECT (context), "natural-width");
449 g_object_thaw_notify (G_OBJECT (context));
453 gtk_cell_area_context_push_preferred_height (GtkCellAreaContext *context,
457 GtkCellAreaContextPrivate *priv;
459 g_return_if_fail (GTK_IS_CELL_AREA_CONTEXT (context));
461 priv = context->priv;
463 g_object_freeze_notify (G_OBJECT (context));
465 if (minimum_height > priv->min_height)
467 priv->min_height = minimum_height;
469 g_object_notify (G_OBJECT (context), "minimum-height");
472 if (natural_height > priv->nat_height)
474 priv->nat_height = natural_height;
476 g_object_notify (G_OBJECT (context), "natural-height");
479 g_object_thaw_notify (G_OBJECT (context));