1 /* gtkcellrenderertextpixbuf.c
2 * Copyright (C) 2000 Red Hat, Inc., Jonathan Blandford <jrb@redhat.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 #include "gtkcellrenderertextpixbuf.h"
35 static void gtk_cell_renderer_text_pixbuf_get_property (GObject *object,
39 const gchar *trailer);
40 static void gtk_cell_renderer_text_pixbuf_set_property (GObject *object,
44 const gchar *trailer);
45 static void gtk_cell_renderer_text_pixbuf_init (GtkCellRendererTextPixbuf *celltextpixbuf);
46 static void gtk_cell_renderer_text_pixbuf_class_init (GtkCellRendererTextPixbufClass *class);
47 static void gtk_cell_renderer_text_pixbuf_get_size (GtkCellRenderer *cell,
51 static void gtk_cell_renderer_text_pixbuf_render (GtkCellRenderer *cell,
54 GdkRectangle *background_area,
55 GdkRectangle *cell_area,
56 GdkRectangle *expose_area,
60 static GtkCellRendererTextClass *parent_class = NULL;
64 gtk_cell_renderer_text_pixbuf_get_type (void)
66 static GtkType cell_text_pixbuf_type = 0;
68 if (!cell_text_pixbuf_type)
70 static const GTypeInfo cell_text_pixbuf_info =
72 sizeof (GtkCellRendererTextPixbufClass),
74 NULL, /* base_finalize */
75 (GClassInitFunc) gtk_cell_renderer_text_pixbuf_class_init,
76 NULL, /* class_finalize */
77 NULL, /* class_data */
78 sizeof (GtkCellRendererTextPixbuf),
80 (GInstanceInitFunc) gtk_cell_renderer_text_pixbuf_init,
83 cell_text_pixbuf_type = g_type_register_static (GTK_TYPE_CELL_RENDERER_TEXT, "GtkCellRendererTextPixbuf", &cell_text_pixbuf_info, 0);
86 return cell_text_pixbuf_type;
90 gtk_cell_renderer_text_pixbuf_init (GtkCellRendererTextPixbuf *celltextpixbuf)
92 celltextpixbuf->pixbuf = GTK_CELL_RENDERER_PIXBUF (gtk_cell_renderer_pixbuf_new ());
93 celltextpixbuf->pixbuf_pos = GTK_POS_LEFT;
97 gtk_cell_renderer_text_pixbuf_class_init (GtkCellRendererTextPixbufClass *class)
99 GObjectClass *object_class = G_OBJECT_CLASS (class);
100 GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (class);
102 parent_class = g_type_class_peek_parent (class);
104 object_class->get_property = gtk_cell_renderer_text_pixbuf_get_property;
105 object_class->set_property = gtk_cell_renderer_text_pixbuf_set_property;
107 cell_class->get_size = gtk_cell_renderer_text_pixbuf_get_size;
108 cell_class->render = gtk_cell_renderer_text_pixbuf_render;
110 g_object_class_install_property (object_class,
112 g_param_spec_int ("pixbufpos",
113 _("Pixbuf location"),
114 _("The relative location of the pixbuf to the text."),
121 g_object_class_install_property (object_class,
123 g_param_spec_object ("pixbuf",
125 _("The pixbuf to render."),
130 g_object_class_install_property (object_class,
132 g_param_spec_float ("pixbuf_xalign",
134 _("The x-align of the pixbuf."),
141 g_object_class_install_property (object_class,
143 g_param_spec_float ("pixbuf_yalign",
145 _("The y-align of the pixbuf."),
152 g_object_class_install_property (object_class,
154 g_param_spec_uint ("pixbuf_xpad",
156 _("The xpad of the pixbuf."),
163 g_object_class_install_property (object_class,
165 g_param_spec_uint ("pixbuf_ypad",
167 _("The ypad of the pixbuf."),
176 gtk_cell_renderer_text_pixbuf_get_property (GObject *object,
180 const gchar *trailer)
182 GtkCellRendererTextPixbuf *celltextpixbuf = GTK_CELL_RENDERER_TEXT_PIXBUF (object);
186 case PROP_PIXBUF_POS:
187 g_value_set_int (value, celltextpixbuf->pixbuf_pos);
190 g_object_get_property (G_OBJECT (celltextpixbuf->pixbuf),
194 case PROP_PIXBUF_XALIGN:
195 g_object_get_property (G_OBJECT (celltextpixbuf->pixbuf),
199 case PROP_PIXBUF_YALIGN:
200 g_object_get_property (G_OBJECT (celltextpixbuf->pixbuf),
204 case PROP_PIXBUF_XPAD:
205 g_object_get_property (G_OBJECT (celltextpixbuf->pixbuf),
209 case PROP_PIXBUF_YPAD:
210 g_object_get_property (G_OBJECT (celltextpixbuf->pixbuf),
215 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
221 gtk_cell_renderer_text_pixbuf_set_property (GObject *object,
225 const gchar *trailer)
227 GtkCellRendererTextPixbuf *celltextpixbuf = GTK_CELL_RENDERER_TEXT_PIXBUF (object);
232 g_object_set_property (G_OBJECT (celltextpixbuf->pixbuf),
236 case PROP_PIXBUF_POS:
237 celltextpixbuf->pixbuf_pos = g_value_get_int (value);
239 case PROP_PIXBUF_XALIGN:
240 g_object_set_property (G_OBJECT (celltextpixbuf->pixbuf),
244 case PROP_PIXBUF_YALIGN:
245 g_object_set_property (G_OBJECT (celltextpixbuf->pixbuf),
249 case PROP_PIXBUF_XPAD:
250 g_object_set_property (G_OBJECT (celltextpixbuf->pixbuf),
254 case PROP_PIXBUF_YPAD:
255 g_object_set_property (G_OBJECT (celltextpixbuf->pixbuf),
260 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
266 * gtk_cell_renderer_text_pixbuf_new:
268 * Creates a new #GtkCellRendererTextPixbuf. Adjust rendering
269 * parameters using object properties. Object properties can be set
270 * globally (with g_object_set()). Also, with #GtkTreeViewColumn, you
271 * can bind a property to a value in a #GtkTreeModel. For example, you
272 * can bind the "text" property on the cell renderer to a string value
273 * in the model, thus rendering a different string in each row of the
276 * Return value: the new cell renderer
279 gtk_cell_renderer_text_pixbuf_new (void)
281 return GTK_CELL_RENDERER (gtk_type_new (gtk_cell_renderer_text_pixbuf_get_type ()));
284 typedef void (* CellSizeFunc) (GtkCellRenderer *cell,
288 typedef void (* CellRenderFunc) (GtkCellRenderer *cell,
291 GdkRectangle *background_area,
292 GdkRectangle *cell_area,
293 GdkRectangle *expose_area,
297 gtk_cell_renderer_text_pixbuf_get_size (GtkCellRenderer *cell,
302 GtkCellRendererTextPixbuf *celltextpixbuf = (GtkCellRendererTextPixbuf *)cell;
308 (* GTK_CELL_RENDERER_CLASS (parent_class)->get_size) (cell, widget, &text_width, &text_height);
309 (* GTK_CELL_RENDERER_CLASS (G_OBJECT_GET_CLASS (celltextpixbuf->pixbuf))->get_size) (GTK_CELL_RENDERER (celltextpixbuf->pixbuf),
313 if (celltextpixbuf->pixbuf_pos == GTK_POS_LEFT ||
314 celltextpixbuf->pixbuf_pos == GTK_POS_RIGHT)
317 *width = pixbuf_width + text_width;
319 *height = MAX (pixbuf_height, text_height);
324 *width = MAX (pixbuf_width, text_width);
326 *height = pixbuf_height + text_height;
331 gtk_cell_renderer_text_pixbuf_render (GtkCellRenderer *cell,
334 GdkRectangle *background_area,
335 GdkRectangle *cell_area,
336 GdkRectangle *expose_area,
340 GtkCellRendererTextPixbuf *celltextpixbuf = (GtkCellRendererTextPixbuf *) cell;
341 CellSizeFunc size_func1, size_func2;
342 CellRenderFunc render_func1, render_func2;
343 GtkCellRenderer *cell1, *cell2;
346 GdkRectangle real_cell_area;
348 if (celltextpixbuf->pixbuf_pos == GTK_POS_LEFT ||
349 celltextpixbuf->pixbuf_pos == GTK_POS_TOP)
351 size_func1 = GTK_CELL_RENDERER_CLASS (G_OBJECT_GET_CLASS (celltextpixbuf->pixbuf))->get_size;
352 render_func1 = GTK_CELL_RENDERER_CLASS (G_OBJECT_GET_CLASS (celltextpixbuf->pixbuf))->render;
353 cell1 = GTK_CELL_RENDERER (celltextpixbuf->pixbuf);
355 size_func2 = GTK_CELL_RENDERER_CLASS (parent_class)->get_size;
356 render_func2 = GTK_CELL_RENDERER_CLASS (parent_class)->render;
361 size_func1 = GTK_CELL_RENDERER_CLASS (parent_class)->get_size;
362 render_func1 = GTK_CELL_RENDERER_CLASS (parent_class)->render;
365 size_func2 = GTK_CELL_RENDERER_CLASS (G_OBJECT_GET_CLASS (celltextpixbuf->pixbuf))->get_size;
366 render_func2 = GTK_CELL_RENDERER_CLASS (G_OBJECT_GET_CLASS (celltextpixbuf->pixbuf))->render;
367 cell2 = GTK_CELL_RENDERER (celltextpixbuf->pixbuf);
370 (size_func1) (cell1, widget, &tmp_width, &tmp_height);
372 real_cell_area.x = cell_area->x;
373 real_cell_area.y = cell_area->y;
375 if (celltextpixbuf->pixbuf_pos == GTK_POS_LEFT ||
376 celltextpixbuf->pixbuf_pos == GTK_POS_RIGHT)
378 real_cell_area.width = MIN (tmp_width, cell_area->width);
379 real_cell_area.height = cell_area->height;
383 real_cell_area.height = MIN (tmp_height, cell_area->height);
384 real_cell_area.width = cell_area->width;
387 (render_func1) (cell1,
395 if (celltextpixbuf->pixbuf_pos == GTK_POS_LEFT ||
396 celltextpixbuf->pixbuf_pos == GTK_POS_RIGHT)
398 real_cell_area.x = real_cell_area.x + real_cell_area.width;
399 real_cell_area.width = cell_area->width - real_cell_area.width;
403 real_cell_area.y = real_cell_area.y + real_cell_area.height;
404 real_cell_area.height = cell_area->height - real_cell_area.height;
407 (render_func2 ) (cell2,