1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 8 -*- */
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.
22 * SECTION:cell-renderer-captioned-image
23 * @short_description: Captioned image cell renderer
25 * @stability: Unstable
26 * @include: libanjuta/cell-renderer-captioned-image.h
31 #include <glib/gi18n.h>
33 #include "cell-renderer-captioned-image.h"
45 G_DEFINE_TYPE(AnjutaCellRendererCaptionedImage
, anjuta_cell_renderer_captioned_image
, GTK_TYPE_CELL_RENDERER
)
48 anjuta_cell_renderer_captioned_image_get_property (GObject
*object
,
53 AnjutaCellRendererCaptionedImage
*cell
= ANJUTA_CELL_RENDERER_CAPTIONED_IMAGE (object
);
57 g_object_get_property (G_OBJECT (cell
->caption
),
61 g_object_get_property (G_OBJECT (cell
->image
),
65 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, param_id
, pspec
);
71 anjuta_cell_renderer_captioned_image_set_property (GObject
*object
,
76 AnjutaCellRendererCaptionedImage
*cell
= ANJUTA_CELL_RENDERER_CAPTIONED_IMAGE (object
);
80 g_object_set_property (G_OBJECT (cell
->caption
), "text", value
);
84 g_object_set_property (G_OBJECT (cell
->image
), "pixbuf",
89 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, param_id
, pspec
);
95 anjuta_cell_renderer_captioned_image_new (void)
97 return GTK_CELL_RENDERER (g_object_new (anjuta_cell_renderer_captioned_image_get_type (), NULL
));
101 anjuta_cell_renderer_captioned_image_get_size (GtkCellRenderer
*gtk_cell
,
103 const GdkRectangle
*cell_area
,
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
,
127 *height
= *height
+ text_height
+ PAD
;
131 *width
= MAX (*width
, text_width
);
137 anjuta_cell_renderer_captioned_image_render (GtkCellRenderer
*gtk_cell
,
140 const GdkRectangle
*background_area
,
141 const GdkRectangle
*cell_area
,
142 GtkCellRendererState flags
)
145 AnjutaCellRendererCaptionedImage
*cell
= ANJUTA_CELL_RENDERER_CAPTIONED_IMAGE (gtk_cell
);
146 GdkRectangle text_area
;
147 GdkRectangle pixbuf_area
;
150 gtk_cell_renderer_get_size (cell
->image
, widget
, cell_area
,
151 NULL
, NULL
, &width
, &height
);
153 pixbuf_area
.y
= cell_area
->y
;
154 pixbuf_area
.x
= cell_area
->x
;
155 pixbuf_area
.height
= height
;
156 pixbuf_area
.width
= cell_area
->width
;
158 gtk_cell_renderer_get_size (cell
->caption
, widget
, cell_area
,
159 NULL
, NULL
, &width
, &height
);
161 text_area
.x
= cell_area
->x
+ (cell_area
->width
- width
) / 2;
162 text_area
.y
= cell_area
->y
+ (pixbuf_area
.height
+ PAD
);
163 text_area
.height
= height
;
164 text_area
.width
= width
;
166 gtk_cell_renderer_render (cell
->image
, cr
, widget
,
167 background_area
, &pixbuf_area
, flags
);
169 gtk_cell_renderer_render (cell
->caption
, cr
, widget
,
170 background_area
, &text_area
, flags
);
174 anjuta_cell_renderer_captioned_image_dispose (GObject
*obj
)
176 AnjutaCellRendererCaptionedImage
*cell
= ANJUTA_CELL_RENDERER_CAPTIONED_IMAGE (obj
);
178 g_object_unref (cell
->image
);
179 g_object_unref (cell
->caption
);
181 G_OBJECT_CLASS (anjuta_cell_renderer_captioned_image_parent_class
)->dispose (obj
);
185 anjuta_cell_renderer_captioned_image_finalize (GObject
*obj
)
187 G_OBJECT_CLASS (anjuta_cell_renderer_captioned_image_parent_class
)->finalize (obj
);
191 anjuta_cell_renderer_captioned_image_init (AnjutaCellRendererCaptionedImage
*cell
)
193 cell
->image
= gtk_cell_renderer_pixbuf_new ();
194 cell
->caption
= gtk_cell_renderer_text_new ();
198 anjuta_cell_renderer_captioned_image_class_init (AnjutaCellRendererCaptionedImageClass
*class)
200 GObjectClass
*object_class
= G_OBJECT_CLASS (class);
201 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (class);
203 object_class
->dispose
= anjuta_cell_renderer_captioned_image_dispose
;
204 object_class
->finalize
= anjuta_cell_renderer_captioned_image_finalize
;
206 object_class
->get_property
= anjuta_cell_renderer_captioned_image_get_property
;
207 object_class
->set_property
= anjuta_cell_renderer_captioned_image_set_property
;
209 cell_class
->get_size
= anjuta_cell_renderer_captioned_image_get_size
;
210 cell_class
->render
= anjuta_cell_renderer_captioned_image_render
;
212 g_object_class_install_property (object_class
,
214 g_param_spec_string ("text",
219 g_object_class_install_property (object_class
,
221 g_param_spec_object ("pixbuf",
223 _("The pixbuf to render."),