Mercurial > pidgin
annotate src/gtkcellrendererprogress.c @ 9251:45d2ad4ac1c1
[gaim-migrate @ 10050]
Stu Tomlinson has provided a nice patch to move the separation of IM
and Chat windows back into the core from the extplacement plugin.
It's awesome to have crazy patch writers, and even better to have
crazy patch writers who write what I want to write before I do it,
thus saving me the effort.
committer: Tailor Script <tailor@pidgin.im>
author | Ethan Blanton <elb@pidgin.im> |
---|---|
date | Wed, 09 Jun 2004 20:47:07 +0000 |
parents | fa6395637e2c |
children | 8974a8544279 |
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 | |
28 static void gtk_cell_renderer_progress_get_property (GObject *object, | |
29 guint param_id, | |
30 GValue *value, | |
31 GParamSpec *pspec); | |
32 static void gtk_cell_renderer_progress_set_property (GObject *object, | |
33 guint param_id, | |
34 const GValue *value, | |
35 GParamSpec *pspec); | |
36 static void gtk_cell_renderer_progress_init (GtkCellRendererProgress *cellprogress); | |
37 static void gtk_cell_renderer_progress_class_init (GtkCellRendererProgressClass *class); | |
38 static void gtk_cell_renderer_progress_get_size (GtkCellRenderer *cell, | |
39 GtkWidget *widget, | |
40 GdkRectangle *cell_area, | |
41 gint *x_offset, | |
42 gint *y_offset, | |
43 gint *width, | |
44 gint *height); | |
45 static void gtk_cell_renderer_progress_render (GtkCellRenderer *cell, | |
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 |
3832 | 53 static gboolean gtk_cell_renderer_progress_activate (GtkCellRenderer *cell, |
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 |
3832 | 61 static void gtk_cell_renderer_progress_finalize (GObject *gobject); |
62 | |
63 enum { | |
64 LAST_SIGNAL | |
65 }; | |
66 | |
67 enum { | |
68 PROP_0, | |
69 | |
70 PROP_PERCENTAGE, | |
71 PROP_TEXT, | |
72 PROP_SHOW_TEXT | |
73 }; | |
74 | |
75 static gpointer parent_class; | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
3832
diff
changeset
|
76 /* static guint progress_cell_renderer_signals [LAST_SIGNAL]; */ |
3832 | 77 |
78 GType gtk_cell_renderer_progress_get_type (void) | |
79 { | |
80 static GType cell_progress_type = 0; | |
81 | |
82 if (!cell_progress_type) | |
83 { | |
84 static const GTypeInfo cell_progress_info = | |
85 { | |
86 sizeof (GtkCellRendererProgressClass), | |
87 NULL, /* base_init */ | |
88 NULL, /* base_finalize */ | |
89 (GClassInitFunc) gtk_cell_renderer_progress_class_init, | |
90 NULL, /* class_finalize */ | |
91 NULL, /* class_data */ | |
92 sizeof (GtkCellRendererProgress), | |
93 0, /* n_preallocs */ | |
94 (GInstanceInitFunc) gtk_cell_renderer_progress_init, | |
95 }; | |
96 | |
97 cell_progress_type = | |
98 g_type_register_static (GTK_TYPE_CELL_RENDERER, "GtkCellRendererProgress", | |
99 &cell_progress_info, 0); | |
100 } | |
101 | |
102 return cell_progress_type; | |
103 } | |
104 | |
105 | |
106 static void gtk_cell_renderer_progress_init (GtkCellRendererProgress *cellprogress) | |
107 { | |
108 GTK_CELL_RENDERER(cellprogress)->mode = GTK_CELL_RENDERER_MODE_INERT; | |
109 GTK_CELL_RENDERER(cellprogress)->xpad = 2; | |
110 GTK_CELL_RENDERER(cellprogress)->ypad = 2; | |
111 } | |
112 | |
113 static void gtk_cell_renderer_progress_class_init (GtkCellRendererProgressClass *class) | |
114 { | |
115 GObjectClass *object_class = G_OBJECT_CLASS(class); | |
116 GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS(class); | |
117 | |
118 parent_class = g_type_class_peek_parent (class); | |
119 object_class->finalize = gtk_cell_renderer_progress_finalize; | |
120 | |
121 object_class->get_property = gtk_cell_renderer_progress_get_property; | |
122 object_class->set_property = gtk_cell_renderer_progress_set_property; | |
123 | |
124 cell_class->get_size = gtk_cell_renderer_progress_get_size; | |
125 cell_class->render = gtk_cell_renderer_progress_render; | |
126 | |
127 g_object_class_install_property (object_class, | |
128 PROP_PERCENTAGE, | |
129 g_param_spec_double ("percentage", | |
130 "Percentage", | |
131 "The fractional progress to display", | |
132 0, 1, 0, | |
133 G_PARAM_READWRITE)); | |
134 | |
135 g_object_class_install_property (object_class, | |
136 PROP_TEXT, | |
137 g_param_spec_string ("text", | |
138 "Text", | |
139 "Text to overlay over progress bar", | |
140 NULL, | |
141 G_PARAM_READWRITE)); | |
142 g_object_class_install_property(object_class, | |
143 PROP_SHOW_TEXT, | |
144 g_param_spec_string("text_set", | |
145 "Text set", | |
146 "Whether to overlay text on the progress bar", | |
147 FALSE, | |
148 G_PARAM_READABLE | G_PARAM_WRITABLE)); | |
149 } | |
150 | |
151 | |
152 | |
153 static void gtk_cell_renderer_progress_finalize (GObject *object) | |
154 { | |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
3832
diff
changeset
|
155 /* |
3832 | 156 GtkCellRendererProgress *cellprogress = GTK_CELL_RENDERER_PROGRESS(object); |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
3832
diff
changeset
|
157 */ |
3832 | 158 |
159 (* G_OBJECT_CLASS (parent_class)->finalize) (object); | |
160 } | |
161 | |
162 static void gtk_cell_renderer_progress_get_property (GObject *object, | |
163 guint param_id, | |
164 GValue *value, | |
165 GParamSpec *psec) | |
166 { | |
167 GtkCellRendererProgress *cellprogress = GTK_CELL_RENDERER_PROGRESS(object); | |
168 | |
169 switch (param_id) | |
170 { | |
171 case PROP_PERCENTAGE: | |
172 g_value_set_double(value, cellprogress->progress); | |
173 break; | |
174 case PROP_TEXT: | |
175 g_value_set_string(value, cellprogress->text); | |
176 break; | |
177 case PROP_SHOW_TEXT: | |
178 g_value_set_boolean(value, cellprogress->text_set); | |
179 break; | |
180 default: | |
181 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, psec); | |
182 break; | |
183 } | |
184 } | |
185 | |
186 static void gtk_cell_renderer_progress_set_property (GObject *object, | |
187 guint param_id, | |
188 const GValue *value, | |
189 GParamSpec *pspec) | |
190 { | |
191 GtkCellRendererProgress *cellprogress = GTK_CELL_RENDERER_PROGRESS (object); | |
192 | |
193 switch (param_id) | |
194 { | |
195 case PROP_PERCENTAGE: | |
196 cellprogress->progress = g_value_get_double(value); | |
197 break; | |
198 case PROP_TEXT: | |
199 if (cellprogress->text) | |
200 g_free(cellprogress->text); | |
201 cellprogress->text = g_strdup(g_value_get_string(value)); | |
202 g_object_notify(object, "text"); | |
203 break; | |
204 case PROP_SHOW_TEXT: | |
205 cellprogress->text_set = g_value_get_boolean(value); | |
206 break; | |
207 default: | |
208 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec); | |
209 break; | |
210 } | |
211 } | |
212 | |
213 GtkCellRenderer *gtk_cell_renderer_progress_new(void) | |
214 { | |
215 return g_object_new(GTK_TYPE_CELL_RENDERER_PROGRESS, NULL); | |
216 } | |
217 | |
218 static void gtk_cell_renderer_progress_get_size (GtkCellRenderer *cell, | |
219 GtkWidget *widget, | |
220 GdkRectangle *cell_area, | |
221 gint *x_offset, | |
222 gint *y_offset, | |
223 gint *width, | |
224 gint *height) | |
225 { | |
226 gint calc_width; | |
227 gint calc_height; | |
228 | |
229 calc_width = (gint) cell->xpad * 2 + 50; | |
7705 | 230 calc_height = (gint) cell->ypad * 2 + 12; |
3832 | 231 |
232 if (width) | |
233 *width = calc_width; | |
234 | |
235 if (height) | |
236 *height = calc_height; | |
237 | |
238 if (cell_area) | |
239 { | |
240 if (x_offset) | |
241 { | |
242 *x_offset = cell->xalign * (cell_area->width - calc_width); | |
243 *x_offset = MAX (*x_offset, 0); | |
244 } | |
245 if (y_offset) | |
246 { | |
247 *y_offset = cell->yalign * (cell_area->height - calc_height); | |
248 *y_offset = MAX (*y_offset, 0); | |
249 } | |
250 } | |
251 } | |
252 | |
253 | |
254 static void gtk_cell_renderer_progress_render (GtkCellRenderer *cell, | |
255 GdkWindow *window, | |
256 GtkWidget *widget, | |
257 GdkRectangle *background_area, | |
258 GdkRectangle *cell_area, | |
259 GdkRectangle *expose_area, | |
260 guint flags) | |
261 { | |
262 GtkCellRendererProgress *cellprogress = (GtkCellRendererProgress *) cell; | |
263 | |
264 gint width, height; | |
265 GtkStateType state; | |
266 | |
7738 | 267 width = cell_area->width; |
268 height = cell_area->height; | |
3832 | 269 |
270 if (GTK_WIDGET_HAS_FOCUS (widget)) | |
271 state = GTK_STATE_ACTIVE; | |
272 else | |
273 state = GTK_STATE_NORMAL; | |
274 | |
275 | |
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", | |
7738 | 284 cell_area->x + cell->xpad, |
285 cell_area->y + cell->ypad, | |
3832 | 286 width - 1, height - 1); |
287 gtk_paint_box (widget->style, | |
288 window, | |
289 state, GTK_SHADOW_OUT, | |
290 NULL, widget, "bar", | |
7738 | 291 cell_area->x + cell->xpad + 1, |
292 cell_area->y + cell->ypad + 1, | |
7705 | 293 (width - 3) * cellprogress->progress, |
294 height - 3); | |
3832 | 295 } |