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