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);
222 gtk_cell_renderer_text_pixbuf_set_property (GObject *object,
226 const gchar *trailer)
228 GtkCellRendererTextPixbuf *celltextpixbuf = GTK_CELL_RENDERER_TEXT_PIXBUF (object);
233 g_object_set_property (G_OBJECT (celltextpixbuf->pixbuf),
237 case PROP_PIXBUF_POS:
238 celltextpixbuf->pixbuf_pos = g_value_get_int (value);
240 case PROP_PIXBUF_XALIGN:
241 g_object_set_property (G_OBJECT (celltextpixbuf->pixbuf),
245 case PROP_PIXBUF_YALIGN:
246 g_object_set_property (G_OBJECT (celltextpixbuf->pixbuf),
250 case PROP_PIXBUF_XPAD:
251 g_object_set_property (G_OBJECT (celltextpixbuf->pixbuf),
255 case PROP_PIXBUF_YPAD:
256 g_object_set_property (G_OBJECT (celltextpixbuf->pixbuf),
261 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
267 gtk_cell_renderer_text_pixbuf_new (void)
269 return GTK_CELL_RENDERER (gtk_type_new (gtk_cell_renderer_text_pixbuf_get_type ()));
272 typedef void (* CellSizeFunc) (GtkCellRenderer *cell,
276 typedef void (* CellRenderFunc) (GtkCellRenderer *cell,
279 GdkRectangle *background_area,
280 GdkRectangle *cell_area,
281 GdkRectangle *expose_area,
285 gtk_cell_renderer_text_pixbuf_get_size (GtkCellRenderer *cell,
290 GtkCellRendererTextPixbuf *celltextpixbuf = (GtkCellRendererTextPixbuf *)cell;
296 (* GTK_CELL_RENDERER_CLASS (parent_class)->get_size) (cell, widget, &text_width, &text_height);
297 (* GTK_CELL_RENDERER_CLASS (G_OBJECT_GET_CLASS (celltextpixbuf->pixbuf))->get_size) (GTK_CELL_RENDERER (celltextpixbuf->pixbuf),
301 if (celltextpixbuf->pixbuf_pos == GTK_POS_LEFT ||
302 celltextpixbuf->pixbuf_pos == GTK_POS_RIGHT)
304 *width = pixbuf_width + text_width;
305 *height = MAX (pixbuf_height, text_height);
309 *width = MAX (pixbuf_width, text_width);
310 *height = pixbuf_height + text_height;
315 gtk_cell_renderer_text_pixbuf_render (GtkCellRenderer *cell,
318 GdkRectangle *background_area,
319 GdkRectangle *cell_area,
320 GdkRectangle *expose_area,
324 GtkCellRendererTextPixbuf *celltextpixbuf = (GtkCellRendererTextPixbuf *) cell;
325 CellSizeFunc size_func1, size_func2;
326 CellRenderFunc render_func1, render_func2;
327 GtkCellRenderer *cell1, *cell2;
330 GdkRectangle real_cell_area;
332 if (celltextpixbuf->pixbuf_pos == GTK_POS_LEFT ||
333 celltextpixbuf->pixbuf_pos == GTK_POS_TOP)
335 size_func1 = GTK_CELL_RENDERER_CLASS (G_OBJECT_GET_CLASS (celltextpixbuf->pixbuf))->get_size;
336 render_func1 = GTK_CELL_RENDERER_CLASS (G_OBJECT_GET_CLASS (celltextpixbuf->pixbuf))->render;
337 cell1 = GTK_CELL_RENDERER (celltextpixbuf->pixbuf);
339 size_func2 = GTK_CELL_RENDERER_CLASS (parent_class)->get_size;
340 render_func2 = GTK_CELL_RENDERER_CLASS (parent_class)->render;
345 size_func1 = GTK_CELL_RENDERER_CLASS (parent_class)->get_size;
346 render_func1 = GTK_CELL_RENDERER_CLASS (parent_class)->render;
349 size_func2 = GTK_CELL_RENDERER_CLASS (G_OBJECT_GET_CLASS (celltextpixbuf->pixbuf))->get_size;
350 render_func2 = GTK_CELL_RENDERER_CLASS (G_OBJECT_GET_CLASS (celltextpixbuf->pixbuf))->render;
351 cell2 = GTK_CELL_RENDERER (celltextpixbuf->pixbuf);
354 (size_func1) (cell1, widget, &tmp_width, &tmp_height);
356 real_cell_area.x = cell_area->x;
357 real_cell_area.y = cell_area->y;
359 if (celltextpixbuf->pixbuf_pos == GTK_POS_LEFT ||
360 celltextpixbuf->pixbuf_pos == GTK_POS_RIGHT)
362 real_cell_area.width = MIN (tmp_width, cell_area->width);
363 real_cell_area.height = cell_area->height;
367 real_cell_area.height = MIN (tmp_height, cell_area->height);
368 real_cell_area.width = cell_area->width;
371 (render_func1) (cell1,
379 if (celltextpixbuf->pixbuf_pos == GTK_POS_LEFT ||
380 celltextpixbuf->pixbuf_pos == GTK_POS_RIGHT)
382 real_cell_area.x = real_cell_area.x + real_cell_area.width;
383 real_cell_area.width = cell_area->width - real_cell_area.width;
387 real_cell_area.y = real_cell_area.y + real_cell_area.height;
388 real_cell_area.height = cell_area->height - real_cell_area.height;
391 (render_func2 ) (cell2,