Updated Spanish translation
[anjuta-git-plugin.git] / libanjuta / cell-renderer-captioned-image.c
blob7ca11ea5b3e16fda704fc4c9269682e654b0f7af
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 8 -*- */
2 /*
3 * Copyright (C) 2002 Dave Camp
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
21 /**
22 * SECTION:cell-renderer-captioned-image
23 * @short_description: Captioned image cell renderer
24 * @see_also:
25 * @stability: Unstable
26 * @include: libanjuta/cell-renderer-captioned-image.h
30 #include <stdlib.h>
31 #include <glib/gi18n.h>
33 #include <libgnome/gnome-macros.h>
35 #include "cell-renderer-captioned-image.h"
38 static void anjuta_cell_renderer_captioned_image_instance_init (AnjutaCellRendererCaptionedImage *cell);
39 static void anjuta_cell_renderer_captioned_image_class_init (AnjutaCellRendererCaptionedImageClass *class);
41 enum {
42 PROP_0,
44 PROP_TEXT,
45 PROP_PIXBUF
48 #define PAD 3
49 #define SPACE 5
51 GNOME_CLASS_BOILERPLATE (AnjutaCellRendererCaptionedImage,
52 anjuta_cell_renderer_captioned_image,
53 GtkCellRenderer, GTK_TYPE_CELL_RENDERER);
55 static void
56 anjuta_cell_renderer_captioned_image_get_property (GObject *object,
57 guint param_id,
58 GValue *value,
59 GParamSpec *pspec)
61 AnjutaCellRendererCaptionedImage *cell = ANJUTA_CELL_RENDERER_CAPTIONED_IMAGE (object);
63 switch (param_id) {
64 case PROP_TEXT:
65 g_object_get_property (G_OBJECT (cell->caption),
66 "text", value);
67 break;
68 case PROP_PIXBUF:
69 g_object_get_property (G_OBJECT (cell->image),
70 "pixbuf", value);
71 break;
72 default :
73 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
74 break;
78 static void
79 anjuta_cell_renderer_captioned_image_set_property (GObject *object,
80 guint param_id,
81 const GValue *value,
82 GParamSpec *pspec)
84 AnjutaCellRendererCaptionedImage *cell = ANJUTA_CELL_RENDERER_CAPTIONED_IMAGE (object);
86 switch (param_id) {
87 case PROP_TEXT:
88 g_object_set_property (G_OBJECT (cell->caption), "text", value);
89 break;
91 case PROP_PIXBUF:
92 g_object_set_property (G_OBJECT (cell->image), "pixbuf",
93 value);
94 break;
96 default:
97 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
98 break;
102 GtkCellRenderer *
103 anjuta_cell_renderer_captioned_image_new (void)
105 return GTK_CELL_RENDERER (g_object_new (anjuta_cell_renderer_captioned_image_get_type (), NULL));
108 static void
109 anjuta_cell_renderer_captioned_image_get_size (GtkCellRenderer *gtk_cell,
110 GtkWidget *widget,
111 GdkRectangle *cell_area,
112 int *x_offset,
113 int *y_offset,
114 int *width,
115 int *height)
117 int text_x_offset;
118 int text_y_offset;
119 int text_width;
120 int text_height;
122 AnjutaCellRendererCaptionedImage *cell = ANJUTA_CELL_RENDERER_CAPTIONED_IMAGE (gtk_cell);
124 gtk_cell_renderer_get_size (cell->image, widget, cell_area,
125 NULL, NULL, width, height);
127 gtk_cell_renderer_get_size (cell->caption, widget, cell_area,
128 &text_x_offset,
129 &text_y_offset,
130 &text_width,
131 &text_height);
134 if (height) {
135 *height = *height + text_height + PAD;
138 if (width) {
139 *width = MAX (*width, text_width);
140 *width += SPACE * 2;
144 static void
145 anjuta_cell_renderer_captioned_image_render (GtkCellRenderer *gtk_cell,
146 GdkWindow *window,
147 GtkWidget *widget,
148 GdkRectangle *background_area,
149 GdkRectangle *cell_area,
150 GdkRectangle *expose_area,
151 guint flags)
154 AnjutaCellRendererCaptionedImage *cell = ANJUTA_CELL_RENDERER_CAPTIONED_IMAGE (gtk_cell);
155 GdkRectangle text_area;
156 GdkRectangle pixbuf_area;
157 int width, height;
159 gtk_cell_renderer_get_size (cell->image, widget, cell_area,
160 NULL, NULL, &width, &height);
162 pixbuf_area.y = cell_area->y;
163 pixbuf_area.x = cell_area->x;
164 pixbuf_area.height = height;
165 pixbuf_area.width = cell_area->width;
167 gtk_cell_renderer_get_size (cell->caption, widget, cell_area,
168 NULL, NULL, &width, &height);
170 text_area.x = cell_area->x + (cell_area->width - width) / 2;
171 text_area.y = cell_area->y + (pixbuf_area.height + PAD);
172 text_area.height = height;
173 text_area.width = width;
175 gtk_cell_renderer_render (cell->image, window, widget,
176 background_area, &pixbuf_area,
177 expose_area, flags);
179 gtk_cell_renderer_render (cell->caption, window, widget,
180 background_area, &text_area,
181 expose_area, flags);
184 static void
185 anjuta_cell_renderer_captioned_image_dispose (GObject *obj)
187 AnjutaCellRendererCaptionedImage *cell = ANJUTA_CELL_RENDERER_CAPTIONED_IMAGE (obj);
189 g_object_unref (cell->image);
190 g_object_unref (cell->caption);
193 static void
194 anjuta_cell_renderer_captioned_image_instance_init (AnjutaCellRendererCaptionedImage *cell)
196 cell->image = gtk_cell_renderer_pixbuf_new ();
197 cell->caption = gtk_cell_renderer_text_new ();
200 static void
201 anjuta_cell_renderer_captioned_image_class_init (AnjutaCellRendererCaptionedImageClass *class)
203 GObjectClass *object_class = G_OBJECT_CLASS (class);
204 GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (class);
206 parent_class = g_type_class_peek_parent (class);
208 object_class->dispose = anjuta_cell_renderer_captioned_image_dispose;
210 object_class->get_property = anjuta_cell_renderer_captioned_image_get_property;
211 object_class->set_property = anjuta_cell_renderer_captioned_image_set_property;
213 cell_class->get_size = anjuta_cell_renderer_captioned_image_get_size;
214 cell_class->render = anjuta_cell_renderer_captioned_image_render;
216 g_object_class_install_property (object_class,
217 PROP_TEXT,
218 g_param_spec_string ("text",
219 _("Text"),
220 _("Text to render"),
221 NULL,
222 G_PARAM_READWRITE));
223 g_object_class_install_property (object_class,
224 PROP_PIXBUF,
225 g_param_spec_object ("pixbuf",
226 _("Pixbuf Object"),
227 _("The pixbuf to render."),
228 GDK_TYPE_PIXBUF,
229 G_PARAM_READWRITE));