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.
24 #include "gtkcelllayout.h"
25 #include "gtkcellarea.h"
27 /* GtkCellAreaClass */
28 static void gtk_cell_area_real_get_preferred_height_for_width (GtkCellArea *area,
32 gint *natural_height);
33 static void gtk_cell_area_real_get_preferred_width_for_height (GtkCellArea *area,
40 /* GtkCellLayoutIface */
41 static void gtk_cell_area_cell_layout_init (GtkCellLayoutIface *iface);
42 static void gtk_cell_area_pack_default (GtkCellLayout *cell_layout,
43 GtkCellRenderer *renderer,
45 static void gtk_cell_area_clear (GtkCellLayout *cell_layout);
46 static void gtk_cell_area_add_attribute (GtkCellLayout *cell_layout,
47 GtkCellRenderer *renderer,
48 const gchar *attribute,
50 static void gtk_cell_area_clear_attributes (GtkCellLayout *cell_layout,
51 GtkCellRenderer *renderer);
52 static GList *gtk_cell_area_get_cells (GtkCellLayout *cell_layout);
54 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GtkCellArea, gtk_cell_area, G_TYPE_INITIALLY_UNOWNED,
55 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
56 gtk_cell_area_cell_layout_init));
60 gtk_cell_area_init (GtkCellArea *area)
66 gtk_cell_area_class_init (GtkCellAreaClass *class)
76 class->attribute_connect = NULL;
77 class->attribute_disconnect = NULL;
78 class->attribute_apply = NULL;
79 class->attribute_forall = NULL;
82 class->get_request_mode = NULL;
83 class->get_preferred_width = NULL;
84 class->get_preferred_height = NULL;
85 class->get_preferred_height_for_width = gtk_cell_area_real_get_preferred_height_for_width;
86 class->get_preferred_width_for_height = gtk_cell_area_real_get_preferred_width_for_height;
90 /*************************************************************
91 * GtkCellLayoutIface *
92 *************************************************************/
94 gtk_cell_area_cell_layout_init (GtkCellLayoutIface *iface)
96 iface->pack_start = gtk_cell_area_pack_default;
97 iface->pack_end = gtk_cell_area_pack_default;
98 iface->clear = gtk_cell_area_clear;
99 iface->add_attribute = gtk_cell_area_add_attribute;
100 iface->clear_attributes = gtk_cell_area_clear_attributes;
101 iface->get_cells = gtk_cell_area_get_cells;
105 gtk_cell_area_pack_default (GtkCellLayout *cell_layout,
106 GtkCellRenderer *renderer,
109 gtk_cell_area_add (GTK_CELL_AREA (cell_layout), renderer);
113 gtk_cell_area_clear (GtkCellLayout *cell_layout)
115 GtkCellArea *area = GTK_CELL_AREA (cell_layout);
117 gtk_cell_layout_get_cells (cell_layout);
119 for (l = cells; l; l = l->next)
121 GtkCellRenderer *renderer = l->data;
122 gtk_cell_area_remove (area, renderer);
130 gtk_cell_area_add_attribute (GtkCellLayout *cell_layout,
131 GtkCellRenderer *renderer,
132 const gchar *attribute,
135 gtk_cell_area_attribute_connect (GTK_CELL_AREA (cell_layout),
136 renderer, attribute, id);
141 const gchar *attribute;
146 accum_attributes (GtkCellArea *area,
147 GtkCellRenderer *renderer,
148 const gchar *attribute,
152 CellAttribute *attrib = g_slice_new (CellAttribute);
154 attrib->attribute = attribute;
157 *accum = g_list_prepend (*accum, attrib);
161 gtk_cell_area_clear_attributes (GtkCellLayout *cell_layout,
162 GtkCellRenderer *renderer)
164 GtkCellArea *area = GTK_CELL_AREA (cell_layout);
165 GList *l, *attributes = NULL;
167 /* Get a list of attributes so we dont modify the list inline */
168 gtk_cell_area_attribute_forall (area, renderer,
169 (GtkCellAttributeCallback)accum_attributes,
172 for (l = attributes; l; l = l->next)
174 CellAttribute *attrib = l->data;
176 gtk_cell_area_attribute_disconnect (area, renderer,
177 attrib->attribute, attrib->id);
179 g_slice_free (CellAttribute, attrib);
182 g_list_free (attributes);
187 accum_cells (GtkCellRenderer *renderer,
190 *accum = g_list_prepend (*accum, renderer);
194 gtk_cell_area_get_cells (GtkCellLayout *cell_layout)
198 gtk_cell_area_forall (GTK_CELL_AREA (cell_layout),
199 (GtkCellCallback)accum_cells,
202 return g_list_reverse (cells);
206 /*************************************************************
208 *************************************************************/
210 gtk_cell_area_real_get_preferred_height_for_width (GtkCellArea *area,
213 gint *minimum_height,
214 gint *natural_height)
216 /* If the area doesnt do height-for-width, fallback on base preferred height */
217 GTK_CELL_AREA_GET_CLASS (area)->get_preferred_width (area, widget, minimum_height, natural_height);
221 gtk_cell_area_real_get_preferred_width_for_height (GtkCellArea *area,
227 /* If the area doesnt do width-for-height, fallback on base preferred width */
228 GTK_CELL_AREA_GET_CLASS (area)->get_preferred_width (area, widget, minimum_width, natural_width);
231 /*************************************************************
233 *************************************************************/
237 gtk_cell_area_add (GtkCellArea *area,
238 GtkCellRenderer *renderer)
240 GtkCellAreaClass *class;
242 g_return_if_fail (GTK_IS_CELL_AREA (area));
243 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
245 class = GTK_CELL_AREA_GET_CLASS (area);
248 class->add (area, renderer);
250 g_warning ("GtkCellAreaClass::add not implemented for `%s'",
251 g_type_name (G_TYPE_FROM_INSTANCE (area)));
255 gtk_cell_area_remove (GtkCellArea *area,
256 GtkCellRenderer *renderer)
258 GtkCellAreaClass *class;
260 g_return_if_fail (GTK_IS_CELL_AREA (area));
261 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
263 class = GTK_CELL_AREA_GET_CLASS (area);
266 class->remove (area, renderer);
268 g_warning ("GtkCellAreaClass::remove not implemented for `%s'",
269 g_type_name (G_TYPE_FROM_INSTANCE (area)));
273 gtk_cell_area_forall (GtkCellArea *area,
274 GtkCellCallback callback,
275 gpointer callback_data)
277 GtkCellAreaClass *class;
279 g_return_if_fail (GTK_IS_CELL_AREA (area));
280 g_return_if_fail (callback != NULL);
282 class = GTK_CELL_AREA_GET_CLASS (area);
285 class->forall (area, callback, callback_data);
287 g_warning ("GtkCellAreaClass::forall not implemented for `%s'",
288 g_type_name (G_TYPE_FROM_INSTANCE (area)));
292 gtk_cell_area_event (GtkCellArea *area,
295 const GdkRectangle *cell_area)
297 GtkCellAreaClass *class;
299 g_return_val_if_fail (GTK_IS_CELL_AREA (area), 0);
300 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
301 g_return_val_if_fail (event != NULL, 0);
302 g_return_val_if_fail (cell_area != NULL, 0);
304 class = GTK_CELL_AREA_GET_CLASS (area);
307 return class->event (area, widget, event, cell_area);
309 g_warning ("GtkCellAreaClass::event not implemented for `%s'",
310 g_type_name (G_TYPE_FROM_INSTANCE (area)));
315 gtk_cell_area_render (GtkCellArea *area,
318 const GdkRectangle *cell_area)
320 GtkCellAreaClass *class;
322 g_return_if_fail (GTK_IS_CELL_AREA (area));
323 g_return_if_fail (cr != NULL);
324 g_return_if_fail (GTK_IS_WIDGET (widget));
325 g_return_if_fail (cell_area != NULL);
327 class = GTK_CELL_AREA_GET_CLASS (area);
330 class->render (area, cr, widget, cell_area);
332 g_warning ("GtkCellAreaClass::render not implemented for `%s'",
333 g_type_name (G_TYPE_FROM_INSTANCE (area)));
339 gtk_cell_area_attribute_connect (GtkCellArea *area,
340 GtkCellRenderer *renderer,
341 const gchar *attribute,
344 GtkCellAreaClass *class;
346 g_return_if_fail (GTK_IS_CELL_AREA (area));
347 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
348 g_return_if_fail (attribute != NULL);
350 class = GTK_CELL_AREA_GET_CLASS (area);
352 if (class->attribute_connect)
353 class->attribute_connect (area, renderer, attribute, id);
355 g_warning ("GtkCellAreaClass::attribute_connect not implemented for `%s'",
356 g_type_name (G_TYPE_FROM_INSTANCE (area)));
360 gtk_cell_area_attribute_disconnect (GtkCellArea *area,
361 GtkCellRenderer *renderer,
362 const gchar *attribute,
365 GtkCellAreaClass *class;
367 g_return_if_fail (GTK_IS_CELL_AREA (area));
368 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
369 g_return_if_fail (attribute != NULL);
371 class = GTK_CELL_AREA_GET_CLASS (area);
373 if (class->attribute_disconnect)
374 class->attribute_disconnect (area, renderer, attribute, id);
376 g_warning ("GtkCellAreaClass::attribute_disconnect not implemented for `%s'",
377 g_type_name (G_TYPE_FROM_INSTANCE (area)));
381 gtk_cell_area_attribute_apply (GtkCellArea *area,
385 GtkCellAreaClass *class;
387 g_return_if_fail (GTK_IS_CELL_AREA (area));
388 g_return_if_fail (G_IS_VALUE (value));
390 class = GTK_CELL_AREA_GET_CLASS (area);
392 if (class->attribute_apply)
393 class->attribute_apply (area, id, value);
395 g_warning ("GtkCellAreaClass::attribute_apply not implemented for `%s'",
396 g_type_name (G_TYPE_FROM_INSTANCE (area)));
400 gtk_cell_area_attribute_forall (GtkCellArea *area,
401 GtkCellRenderer *renderer,
402 GtkCellAttributeCallback callback,
405 GtkCellAreaClass *class;
407 g_return_if_fail (GTK_IS_CELL_AREA (area));
408 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
409 g_return_if_fail (callback != NULL);
411 class = GTK_CELL_AREA_GET_CLASS (area);
413 if (class->attribute_forall)
414 class->attribute_forall (area, renderer, callback, user_data);
416 g_warning ("GtkCellAreaClass::attribute_forall not implemented for `%s'",
417 g_type_name (G_TYPE_FROM_INSTANCE (area)));
423 gtk_cell_area_get_request_mode (GtkCellArea *area)
425 GtkCellAreaClass *class;
427 g_return_val_if_fail (GTK_IS_CELL_AREA (area),
428 GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH);
430 class = GTK_CELL_AREA_GET_CLASS (area);
432 if (class->get_request_mode)
433 return class->get_request_mode (area);
435 g_warning ("GtkCellAreaClass::get_request_mode not implemented for `%s'",
436 g_type_name (G_TYPE_FROM_INSTANCE (area)));
438 return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
442 gtk_cell_area_get_preferred_width (GtkCellArea *area,
447 GtkCellAreaClass *class;
449 g_return_if_fail (GTK_IS_CELL_AREA (area));
450 g_return_if_fail (GTK_IS_WIDGET (widget));
452 class = GTK_CELL_AREA_GET_CLASS (area);
454 if (class->get_preferred_width)
455 class->get_preferred_width (area, widget, minimum_size, natural_size);
457 g_warning ("GtkCellAreaClass::get_preferred_width not implemented for `%s'",
458 g_type_name (G_TYPE_FROM_INSTANCE (area)));
462 gtk_cell_area_get_preferred_height_for_width (GtkCellArea *area,
465 gint *minimum_height,
466 gint *natural_height)
468 GtkCellAreaClass *class;
470 g_return_if_fail (GTK_IS_CELL_AREA (area));
471 g_return_if_fail (GTK_IS_WIDGET (widget));
473 class = GTK_CELL_AREA_GET_CLASS (area);
474 class->get_preferred_height_for_width (area, widget, width, minimum_height, natural_height);
478 gtk_cell_area_get_preferred_height (GtkCellArea *area,
483 GtkCellAreaClass *class;
485 g_return_if_fail (GTK_IS_CELL_AREA (area));
486 g_return_if_fail (GTK_IS_WIDGET (widget));
488 class = GTK_CELL_AREA_GET_CLASS (area);
490 if (class->get_preferred_height)
491 class->get_preferred_height (area, widget, minimum_size, natural_size);
493 g_warning ("GtkCellAreaClass::get_preferred_height not implemented for `%s'",
494 g_type_name (G_TYPE_FROM_INSTANCE (area)));
498 gtk_cell_area_get_preferred_width_for_height (GtkCellArea *area,
504 GtkCellAreaClass *class;
506 g_return_if_fail (GTK_IS_CELL_AREA (area));
507 g_return_if_fail (GTK_IS_WIDGET (widget));
509 class = GTK_CELL_AREA_GET_CLASS (area);
510 class->get_preferred_width_for_height (area, widget, height, minimum_width, natural_width);