Mon, 19 Mar 2007 06:11:46 +0000
According to etags, pidgin/ should be completely clean of references to 'gaim' as a client
| 10297 | 1 | /* |
| 2 | * @file gtkcellrendererprogress.c GTK+ Cell Renderer Progress | |
| 3 | * @ingroup gtkui | |
| 4 | * | |
| 5 | * gaim | |
| 6 | * | |
| 8046 | 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. | |
| 3832 | 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 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
33 | static void pidgin_cell_renderer_progress_get_property (GObject *object, |
| 3832 | 34 | guint param_id, |
| 35 | GValue *value, | |
| 36 | GParamSpec *pspec); | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
37 | static void pidgin_cell_renderer_progress_set_property (GObject *object, |
| 3832 | 38 | guint param_id, |
| 39 | const GValue *value, | |
| 40 | GParamSpec *pspec); | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
41 | static void pidgin_cell_renderer_progress_init (PidginCellRendererProgress *cellprogress); |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
42 | static void pidgin_cell_renderer_progress_class_init (PidginCellRendererProgressClass *class); |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
43 | static void pidgin_cell_renderer_progress_get_size (GtkCellRenderer *cell, |
| 3832 | 44 | GtkWidget *widget, |
| 45 | GdkRectangle *cell_area, | |
| 46 | gint *x_offset, | |
| 47 | gint *y_offset, | |
| 48 | gint *width, | |
| 49 | gint *height); | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
50 | static void pidgin_cell_renderer_progress_render (GtkCellRenderer *cell, |
| 3832 | 51 | GdkWindow *window, |
| 52 | GtkWidget *widget, | |
| 53 | GdkRectangle *background_area, | |
| 54 | GdkRectangle *cell_area, | |
| 55 | GdkRectangle *expose_area, | |
| 56 | guint flags); | |
|
4514
40e3588a280f
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
3832
diff
changeset
|
57 | #if 0 |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
58 | static gboolean pidgin_cell_renderer_progress_activate (GtkCellRenderer *cell, |
| 3832 | 59 | GdkEvent *event, |
| 60 | GtkWidget *widget, | |
| 61 | const gchar *path, | |
| 62 | GdkRectangle *background_area, | |
| 63 | GdkRectangle *cell_area, | |
| 64 | guint flags); | |
|
4514
40e3588a280f
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
3832
diff
changeset
|
65 | #endif |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
66 | static void pidgin_cell_renderer_progress_finalize (GObject *gobject); |
| 3832 | 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; | |
|
4514
40e3588a280f
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
3832
diff
changeset
|
80 | /* static guint progress_cell_renderer_signals [LAST_SIGNAL]; */ |
| 3832 | 81 | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
82 | GType pidgin_cell_renderer_progress_get_type (void) |
| 3832 | 83 | { |
| 84 | static GType cell_progress_type = 0; | |
| 85 | ||
| 86 | if (!cell_progress_type) | |
| 87 | { | |
| 88 | static const GTypeInfo cell_progress_info = | |
| 89 | { | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
90 | sizeof (PidginCellRendererProgressClass), |
| 3832 | 91 | NULL, /* base_init */ |
| 92 | NULL, /* base_finalize */ | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
93 | (GClassInitFunc) pidgin_cell_renderer_progress_class_init, |
| 3832 | 94 | NULL, /* class_finalize */ |
| 95 | NULL, /* class_data */ | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
96 | sizeof (PidginCellRendererProgress), |
| 3832 | 97 | 0, /* n_preallocs */ |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
98 | (GInstanceInitFunc) pidgin_cell_renderer_progress_init, |
|
12600
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
10297
diff
changeset
|
99 | NULL /* value_table */ |
| 3832 | 100 | }; |
| 101 | ||
| 102 | cell_progress_type = | |
|
9898
9d8d9e9ef1bc
[gaim-migrate @ 10788]
Mark Doliner <markdoliner@pidgin.im>
parents:
8046
diff
changeset
|
103 | g_type_register_static (GTK_TYPE_CELL_RENDERER, |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
104 | "PidginCellRendererProgress", |
|
9898
9d8d9e9ef1bc
[gaim-migrate @ 10788]
Mark Doliner <markdoliner@pidgin.im>
parents:
8046
diff
changeset
|
105 | &cell_progress_info, 0); |
| 3832 | 106 | } |
| 107 | ||
| 108 | return cell_progress_type; | |
| 109 | } | |
| 110 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
111 | static void pidgin_cell_renderer_progress_init (PidginCellRendererProgress *cellprogress) |
| 3832 | 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 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
118 | static void pidgin_cell_renderer_progress_class_init (PidginCellRendererProgressClass *class) |
| 3832 | 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); | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
124 | object_class->finalize = pidgin_cell_renderer_progress_finalize; |
| 3832 | 125 | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
126 | object_class->get_property = pidgin_cell_renderer_progress_get_property; |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
127 | object_class->set_property = pidgin_cell_renderer_progress_set_property; |
| 3832 | 128 | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
129 | cell_class->get_size = pidgin_cell_renderer_progress_get_size; |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
130 | cell_class->render = pidgin_cell_renderer_progress_render; |
| 3832 | 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 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
155 | static void pidgin_cell_renderer_progress_finalize (GObject *object) |
| 3832 | 156 | { |
|
4514
40e3588a280f
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
3832
diff
changeset
|
157 | /* |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
158 | PidginCellRendererProgress *cellprogress = PIDGIN_CELL_RENDERER_PROGRESS(object); |
|
4514
40e3588a280f
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
3832
diff
changeset
|
159 | */ |
| 3832 | 160 | |
| 161 | (* G_OBJECT_CLASS (parent_class)->finalize) (object); | |
| 162 | } | |
| 163 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
164 | static void pidgin_cell_renderer_progress_get_property (GObject *object, |
| 3832 | 165 | guint param_id, |
| 166 | GValue *value, | |
| 167 | GParamSpec *psec) | |
| 168 | { | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
169 | PidginCellRendererProgress *cellprogress = PIDGIN_CELL_RENDERER_PROGRESS(object); |
| 3832 | 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 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
188 | static void pidgin_cell_renderer_progress_set_property (GObject *object, |
| 3832 | 189 | guint param_id, |
| 190 | const GValue *value, | |
| 191 | GParamSpec *pspec) | |
| 192 | { | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
193 | PidginCellRendererProgress *cellprogress = PIDGIN_CELL_RENDERER_PROGRESS (object); |
| 3832 | 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 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
215 | GtkCellRenderer *pidgin_cell_renderer_progress_new(void) |
| 3832 | 216 | { |
|
15883
969b74a3e27a
According to etags, pidgin/ should be completely clean of references to 'gaim' as a client
Sean Egan <seanegan@pidgin.im>
parents:
15562
diff
changeset
|
217 | return g_object_new(PIDGIN_TYPE_GTK_CELL_RENDERER_PROGRESS, NULL); |
| 3832 | 218 | } |
| 219 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
220 | static void pidgin_cell_renderer_progress_get_size (GtkCellRenderer *cell, |
| 3832 | 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; | |
| 7705 | 232 | calc_height = (gint) cell->ypad * 2 + 12; |
| 3832 | 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 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
256 | static void pidgin_cell_renderer_progress_render (GtkCellRenderer *cell, |
| 3832 | 257 | GdkWindow *window, |
| 258 | GtkWidget *widget, | |
| 259 | GdkRectangle *background_area, | |
| 260 | GdkRectangle *cell_area, | |
| 261 | GdkRectangle *expose_area, | |
| 262 | guint flags) | |
| 263 | { | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
264 | PidginCellRendererProgress *cellprogress = (PidginCellRendererProgress *) cell; |
| 3832 | 265 | |
| 266 | gint width, height; | |
| 267 | GtkStateType state; | |
| 268 | ||
| 7738 | 269 | width = cell_area->width; |
| 270 | height = cell_area->height; | |
| 3832 | 271 | |
| 272 | if (GTK_WIDGET_HAS_FOCUS (widget)) | |
| 273 | state = GTK_STATE_ACTIVE; | |
| 274 | else | |
| 275 | state = GTK_STATE_NORMAL; | |
|
9898
9d8d9e9ef1bc
[gaim-migrate @ 10788]
Mark Doliner <markdoliner@pidgin.im>
parents:
8046
diff
changeset
|
276 | |
| 3832 | 277 | width -= cell->xpad*2; |
| 278 | height -= cell->ypad*2; | |
|
9898
9d8d9e9ef1bc
[gaim-migrate @ 10788]
Mark Doliner <markdoliner@pidgin.im>
parents:
8046
diff
changeset
|
279 | |
| 3832 | 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 | } |