comparison gtk/gtkcellrendererprogress.c @ 14191:009db0b357b5

This is a hand-crafted commit to migrate across subversion revisions 16854:16861, due to some vagaries of the way the original renames were done. Witness that monotone can do in one revision what svn had to spread across several.
author Ethan Blanton <elb@pidgin.im>
date Sat, 16 Dec 2006 04:59:55 +0000
parents
children
comparison
equal deleted inserted replaced
14190:366be2ce35a7 14191:009db0b357b5
1 /*
2 * @file gtkcellrendererprogress.c GTK+ Cell Renderer Progress
3 * @ingroup gtkui
4 *
5 * gaim
6 *
7 * Gaim is the legal property of its developers, whose names are too numerous
8 * to list here. Please refer to the COPYRIGHT file distributed with this
9 * source distribution.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26
27 /* This is taken largely from GtkCellRenderer[Text|Pixbuf|Toggle] by
28 * Jonathon Blandford <jrb@redhat.com> for RedHat, Inc.
29 */
30
31 #include "gtkcellrendererprogress.h"
32
33 static void gaim_gtk_cell_renderer_progress_get_property (GObject *object,
34 guint param_id,
35 GValue *value,
36 GParamSpec *pspec);
37 static void gaim_gtk_cell_renderer_progress_set_property (GObject *object,
38 guint param_id,
39 const GValue *value,
40 GParamSpec *pspec);
41 static void gaim_gtk_cell_renderer_progress_init (GaimGtkCellRendererProgress *cellprogress);
42 static void gaim_gtk_cell_renderer_progress_class_init (GaimGtkCellRendererProgressClass *class);
43 static void gaim_gtk_cell_renderer_progress_get_size (GtkCellRenderer *cell,
44 GtkWidget *widget,
45 GdkRectangle *cell_area,
46 gint *x_offset,
47 gint *y_offset,
48 gint *width,
49 gint *height);
50 static void gaim_gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
51 GdkWindow *window,
52 GtkWidget *widget,
53 GdkRectangle *background_area,
54 GdkRectangle *cell_area,
55 GdkRectangle *expose_area,
56 guint flags);
57 #if 0
58 static gboolean gaim_gtk_cell_renderer_progress_activate (GtkCellRenderer *cell,
59 GdkEvent *event,
60 GtkWidget *widget,
61 const gchar *path,
62 GdkRectangle *background_area,
63 GdkRectangle *cell_area,
64 guint flags);
65 #endif
66 static void gaim_gtk_cell_renderer_progress_finalize (GObject *gobject);
67
68 enum {
69 LAST_SIGNAL
70 };
71
72 enum {
73 PROP_0,
74 PROP_PERCENTAGE,
75 PROP_TEXT,
76 PROP_SHOW_TEXT
77 };
78
79 static gpointer parent_class;
80 /* static guint progress_cell_renderer_signals [LAST_SIGNAL]; */
81
82 GType gaim_gtk_cell_renderer_progress_get_type (void)
83 {
84 static GType cell_progress_type = 0;
85
86 if (!cell_progress_type)
87 {
88 static const GTypeInfo cell_progress_info =
89 {
90 sizeof (GaimGtkCellRendererProgressClass),
91 NULL, /* base_init */
92 NULL, /* base_finalize */
93 (GClassInitFunc) gaim_gtk_cell_renderer_progress_class_init,
94 NULL, /* class_finalize */
95 NULL, /* class_data */
96 sizeof (GaimGtkCellRendererProgress),
97 0, /* n_preallocs */
98 (GInstanceInitFunc) gaim_gtk_cell_renderer_progress_init,
99 NULL /* value_table */
100 };
101
102 cell_progress_type =
103 g_type_register_static (GTK_TYPE_CELL_RENDERER,
104 "GaimGtkCellRendererProgress",
105 &cell_progress_info, 0);
106 }
107
108 return cell_progress_type;
109 }
110
111 static void gaim_gtk_cell_renderer_progress_init (GaimGtkCellRendererProgress *cellprogress)
112 {
113 GTK_CELL_RENDERER(cellprogress)->mode = GTK_CELL_RENDERER_MODE_INERT;
114 GTK_CELL_RENDERER(cellprogress)->xpad = 2;
115 GTK_CELL_RENDERER(cellprogress)->ypad = 2;
116 }
117
118 static void gaim_gtk_cell_renderer_progress_class_init (GaimGtkCellRendererProgressClass *class)
119 {
120 GObjectClass *object_class = G_OBJECT_CLASS(class);
121 GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS(class);
122
123 parent_class = g_type_class_peek_parent (class);
124 object_class->finalize = gaim_gtk_cell_renderer_progress_finalize;
125
126 object_class->get_property = gaim_gtk_cell_renderer_progress_get_property;
127 object_class->set_property = gaim_gtk_cell_renderer_progress_set_property;
128
129 cell_class->get_size = gaim_gtk_cell_renderer_progress_get_size;
130 cell_class->render = gaim_gtk_cell_renderer_progress_render;
131
132 g_object_class_install_property (object_class,
133 PROP_PERCENTAGE,
134 g_param_spec_double ("percentage",
135 "Percentage",
136 "The fractional progress to display",
137 0, 1, 0,
138 G_PARAM_READWRITE));
139 g_object_class_install_property (object_class,
140 PROP_TEXT,
141 g_param_spec_string ("text",
142 "Text",
143 "Text to overlay over progress bar",
144 NULL,
145 G_PARAM_READWRITE));
146 g_object_class_install_property(object_class,
147 PROP_SHOW_TEXT,
148 g_param_spec_string("text_set",
149 "Text set",
150 "Whether to overlay text on the progress bar",
151 FALSE,
152 G_PARAM_READABLE | G_PARAM_WRITABLE));
153 }
154
155 static void gaim_gtk_cell_renderer_progress_finalize (GObject *object)
156 {
157 /*
158 GaimGtkCellRendererProgress *cellprogress = GAIM_GTK_CELL_RENDERER_PROGRESS(object);
159 */
160
161 (* G_OBJECT_CLASS (parent_class)->finalize) (object);
162 }
163
164 static void gaim_gtk_cell_renderer_progress_get_property (GObject *object,
165 guint param_id,
166 GValue *value,
167 GParamSpec *psec)
168 {
169 GaimGtkCellRendererProgress *cellprogress = GAIM_GTK_CELL_RENDERER_PROGRESS(object);
170
171 switch (param_id)
172 {
173 case PROP_PERCENTAGE:
174 g_value_set_double(value, cellprogress->progress);
175 break;
176 case PROP_TEXT:
177 g_value_set_string(value, cellprogress->text);
178 break;
179 case PROP_SHOW_TEXT:
180 g_value_set_boolean(value, cellprogress->text_set);
181 break;
182 default:
183 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, psec);
184 break;
185 }
186 }
187
188 static void gaim_gtk_cell_renderer_progress_set_property (GObject *object,
189 guint param_id,
190 const GValue *value,
191 GParamSpec *pspec)
192 {
193 GaimGtkCellRendererProgress *cellprogress = GAIM_GTK_CELL_RENDERER_PROGRESS (object);
194
195 switch (param_id)
196 {
197 case PROP_PERCENTAGE:
198 cellprogress->progress = g_value_get_double(value);
199 break;
200 case PROP_TEXT:
201 if (cellprogress->text)
202 g_free(cellprogress->text);
203 cellprogress->text = g_strdup(g_value_get_string(value));
204 g_object_notify(object, "text");
205 break;
206 case PROP_SHOW_TEXT:
207 cellprogress->text_set = g_value_get_boolean(value);
208 break;
209 default:
210 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
211 break;
212 }
213 }
214
215 GtkCellRenderer *gaim_gtk_cell_renderer_progress_new(void)
216 {
217 return g_object_new(GAIM_TYPE_GTK_CELL_RENDERER_PROGRESS, NULL);
218 }
219
220 static void gaim_gtk_cell_renderer_progress_get_size (GtkCellRenderer *cell,
221 GtkWidget *widget,
222 GdkRectangle *cell_area,
223 gint *x_offset,
224 gint *y_offset,
225 gint *width,
226 gint *height)
227 {
228 gint calc_width;
229 gint calc_height;
230
231 calc_width = (gint) cell->xpad * 2 + 50;
232 calc_height = (gint) cell->ypad * 2 + 12;
233
234 if (width)
235 *width = calc_width;
236
237 if (height)
238 *height = calc_height;
239
240 if (cell_area)
241 {
242 if (x_offset)
243 {
244 *x_offset = cell->xalign * (cell_area->width - calc_width);
245 *x_offset = MAX (*x_offset, 0);
246 }
247 if (y_offset)
248 {
249 *y_offset = cell->yalign * (cell_area->height - calc_height);
250 *y_offset = MAX (*y_offset, 0);
251 }
252 }
253 }
254
255
256 static void gaim_gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
257 GdkWindow *window,
258 GtkWidget *widget,
259 GdkRectangle *background_area,
260 GdkRectangle *cell_area,
261 GdkRectangle *expose_area,
262 guint flags)
263 {
264 GaimGtkCellRendererProgress *cellprogress = (GaimGtkCellRendererProgress *) cell;
265
266 gint width, height;
267 GtkStateType state;
268
269 width = cell_area->width;
270 height = cell_area->height;
271
272 if (GTK_WIDGET_HAS_FOCUS (widget))
273 state = GTK_STATE_ACTIVE;
274 else
275 state = GTK_STATE_NORMAL;
276
277 width -= cell->xpad*2;
278 height -= cell->ypad*2;
279
280 gtk_paint_box (widget->style,
281 window,
282 GTK_STATE_NORMAL, GTK_SHADOW_IN,
283 NULL, widget, "trough",
284 cell_area->x + cell->xpad,
285 cell_area->y + cell->ypad,
286 width - 1, height - 1);
287 gtk_paint_box (widget->style,
288 window,
289 state, GTK_SHADOW_OUT,
290 NULL, widget, "bar",
291 cell_area->x + cell->xpad + 1,
292 cell_area->y + cell->ypad + 1,
293 (width - 3) * cellprogress->progress,
294 height - 3);
295 }