Merge branch 'master' into git-shell
[anjuta.git] / libanjuta / cell-renderer-captioned-image.c
blob2c65f9026165558f9f5b333d500a5c06ff216e99
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 "cell-renderer-captioned-image.h"
35 enum {
36 PROP_0,
38 PROP_TEXT,
39 PROP_PIXBUF
42 #define PAD 3
43 #define SPACE 5
45 G_DEFINE_TYPE(AnjutaCellRendererCaptionedImage, anjuta_cell_renderer_captioned_image, GTK_TYPE_CELL_RENDERER)
47 static void
48 anjuta_cell_renderer_captioned_image_get_property (GObject *object,
49 guint param_id,
50 GValue *value,
51 GParamSpec *pspec)
53 AnjutaCellRendererCaptionedImage *cell = ANJUTA_CELL_RENDERER_CAPTIONED_IMAGE (object);
55 switch (param_id) {
56 case PROP_TEXT:
57 g_object_get_property (G_OBJECT (cell->caption),
58 "text", value);
59 break;
60 case PROP_PIXBUF:
61 g_object_get_property (G_OBJECT (cell->image),
62 "pixbuf", value);
63 break;
64 default :
65 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
66 break;
70 static void
71 anjuta_cell_renderer_captioned_image_set_property (GObject *object,
72 guint param_id,
73 const GValue *value,
74 GParamSpec *pspec)
76 AnjutaCellRendererCaptionedImage *cell = ANJUTA_CELL_RENDERER_CAPTIONED_IMAGE (object);
78 switch (param_id) {
79 case PROP_TEXT:
80 g_object_set_property (G_OBJECT (cell->caption), "text", value);
81 break;
83 case PROP_PIXBUF:
84 g_object_set_property (G_OBJECT (cell->image), "pixbuf",
85 value);
86 break;
88 default:
89 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
90 break;
94 GtkCellRenderer *
95 anjuta_cell_renderer_captioned_image_new (void)
97 return GTK_CELL_RENDERER (g_object_new (anjuta_cell_renderer_captioned_image_get_type (), NULL));
100 static void
101 anjuta_cell_renderer_captioned_image_get_size (GtkCellRenderer *gtk_cell,
102 GtkWidget *widget,
103 GdkRectangle *cell_area,
104 int *x_offset,
105 int *y_offset,
106 int *width,
107 int *height)
109 int text_x_offset;
110 int text_y_offset;
111 int text_width;
112 int text_height;
114 AnjutaCellRendererCaptionedImage *cell = ANJUTA_CELL_RENDERER_CAPTIONED_IMAGE (gtk_cell);
116 gtk_cell_renderer_get_size (cell->image, widget, cell_area,
117 NULL, NULL, width, height);
119 gtk_cell_renderer_get_size (cell->caption, widget, cell_area,
120 &text_x_offset,
121 &text_y_offset,
122 &text_width,
123 &text_height);
126 if (height) {
127 *height = *height + text_height + PAD;
130 if (width) {
131 *width = MAX (*width, text_width);
132 *width += SPACE * 2;
136 static void
137 anjuta_cell_renderer_captioned_image_render (GtkCellRenderer *gtk_cell,
138 GdkWindow *window,
139 GtkWidget *widget,
140 GdkRectangle *background_area,
141 GdkRectangle *cell_area,
142 GdkRectangle *expose_area,
143 guint flags)
146 AnjutaCellRendererCaptionedImage *cell = ANJUTA_CELL_RENDERER_CAPTIONED_IMAGE (gtk_cell);
147 GdkRectangle text_area;
148 GdkRectangle pixbuf_area;
149 int width, height;
151 gtk_cell_renderer_get_size (cell->image, widget, cell_area,
152 NULL, NULL, &width, &height);
154 pixbuf_area.y = cell_area->y;
155 pixbuf_area.x = cell_area->x;
156 pixbuf_area.height = height;
157 pixbuf_area.width = cell_area->width;
159 gtk_cell_renderer_get_size (cell->caption, widget, cell_area,
160 NULL, NULL, &width, &height);
162 text_area.x = cell_area->x + (cell_area->width - width) / 2;
163 text_area.y = cell_area->y + (pixbuf_area.height + PAD);
164 text_area.height = height;
165 text_area.width = width;
167 gtk_cell_renderer_render (cell->image, window, widget,
168 background_area, &pixbuf_area,
169 expose_area, flags);
171 gtk_cell_renderer_render (cell->caption, window, widget,
172 background_area, &text_area,
173 expose_area, flags);
176 static void
177 anjuta_cell_renderer_captioned_image_dispose (GObject *obj)
179 AnjutaCellRendererCaptionedImage *cell = ANJUTA_CELL_RENDERER_CAPTIONED_IMAGE (obj);
181 g_object_unref (cell->image);
182 g_object_unref (cell->caption);
184 G_OBJECT_CLASS (anjuta_cell_renderer_captioned_image_parent_class)->dispose (obj);
187 static void
188 anjuta_cell_renderer_captioned_image_finalize (GObject *obj)
190 G_OBJECT_CLASS (anjuta_cell_renderer_captioned_image_parent_class)->finalize (obj);
193 static void
194 anjuta_cell_renderer_captioned_image_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 object_class->dispose = anjuta_cell_renderer_captioned_image_dispose;
207 object_class->finalize = anjuta_cell_renderer_captioned_image_finalize;
209 object_class->get_property = anjuta_cell_renderer_captioned_image_get_property;
210 object_class->set_property = anjuta_cell_renderer_captioned_image_set_property;
212 cell_class->get_size = anjuta_cell_renderer_captioned_image_get_size;
213 cell_class->render = anjuta_cell_renderer_captioned_image_render;
215 g_object_class_install_property (object_class,
216 PROP_TEXT,
217 g_param_spec_string ("text",
218 _("Text"),
219 _("Text to render"),
220 NULL,
221 G_PARAM_READWRITE));
222 g_object_class_install_property (object_class,
223 PROP_PIXBUF,
224 g_param_spec_object ("pixbuf",
225 _("Pixbuf Object"),
226 _("The pixbuf to render."),
227 GDK_TYPE_PIXBUF,
228 G_PARAM_READWRITE));