Mercurial > pidgin
annotate src/gtkcellrendererprogress.c @ 12600:e856f985a0b9
[gaim-migrate @ 14934]
Enable the extra warnings regardless of --enable-debug.
Enable FORTIFY_SOURCE regardless of --enable-debug, adding a --disable-fortify flag to configure.
Enable (well, stop disabling) the missing initializer warnings.
This leads to warnings with: GValue v = {0,}; that must be worked around.
Basically, instead of:
GValue v = {0,};
...
g_value_init(&v, G_TYPE_FOO); /* or other use of the GValue */
We'd need to do:
GValue v;
...
v.g_type = 0;
g_value_init(&v, G_TYPE_FOO); /* or other use of the GValue */
Fix several cases of missing initializers. I don't think any of these are bugs, but having this warning seems like a good idea. It might prevent us from making a mistake in the future.
While I was fixing missing initializers, I optimized substitute_simple_word in plugins/spellchk.c, in the same way as I did substitute_word before. Yes, I'm bad for committing these together.
Added a --enable-fatal-asserts flag to configure. As the name implies, this makes g_return_... guards fatal. This is a useful flag to run on a debug copy of Gaim. It will make it very clear if your changes have triggered one of these guards. It's also useful in detecting g_return_... abuse, which helps prevent crashes if Gaim is compiled with G_DISABLE_ASSERT defined.
committer: Tailor Script <tailor@pidgin.im>
| author | Richard Laager <rlaager@wiktel.com> |
|---|---|
| date | Wed, 21 Dec 2005 18:36:19 +0000 |
| parents | ec140184437b |
| children |
| rev | line source |
|---|---|
| 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 | |
| 9898 | 33 static void gaim_gtk_cell_renderer_progress_get_property (GObject *object, |
| 3832 | 34 guint param_id, |
| 35 GValue *value, | |
| 36 GParamSpec *pspec); | |
| 9898 | 37 static void gaim_gtk_cell_renderer_progress_set_property (GObject *object, |
| 3832 | 38 guint param_id, |
| 39 const GValue *value, | |
| 40 GParamSpec *pspec); | |
| 9898 | 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, | |
| 3832 | 44 GtkWidget *widget, |
| 45 GdkRectangle *cell_area, | |
| 46 gint *x_offset, | |
| 47 gint *y_offset, | |
| 48 gint *width, | |
| 49 gint *height); | |
| 9898 | 50 static void gaim_gtk_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
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
3832
diff
changeset
|
57 #if 0 |
| 9898 | 58 static gboolean gaim_gtk_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
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
3832
diff
changeset
|
65 #endif |
| 9898 | 66 static void gaim_gtk_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
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
3832
diff
changeset
|
80 /* static guint progress_cell_renderer_signals [LAST_SIGNAL]; */ |
| 3832 | 81 |
| 9898 | 82 GType gaim_gtk_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 { | |
| 9898 | 90 sizeof (GaimGtkCellRendererProgressClass), |
| 3832 | 91 NULL, /* base_init */ |
| 92 NULL, /* base_finalize */ | |
| 9898 | 93 (GClassInitFunc) gaim_gtk_cell_renderer_progress_class_init, |
| 3832 | 94 NULL, /* class_finalize */ |
| 95 NULL, /* class_data */ | |
| 9898 | 96 sizeof (GaimGtkCellRendererProgress), |
| 3832 | 97 0, /* n_preallocs */ |
| 9898 | 98 (GInstanceInitFunc) gaim_gtk_cell_renderer_progress_init, |
|
12600
e856f985a0b9
[gaim-migrate @ 14934]
Richard Laager <rlaager@wiktel.com>
parents:
10297
diff
changeset
|
99 NULL /* value_table */ |
| 3832 | 100 }; |
| 101 | |
| 102 cell_progress_type = | |
| 9898 | 103 g_type_register_static (GTK_TYPE_CELL_RENDERER, |
| 104 "GaimGtkCellRendererProgress", | |
| 105 &cell_progress_info, 0); | |
| 3832 | 106 } |
| 107 | |
| 108 return cell_progress_type; | |
| 109 } | |
| 110 | |
| 9898 | 111 static void gaim_gtk_cell_renderer_progress_init (GaimGtkCellRendererProgress *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 | |
| 9898 | 118 static void gaim_gtk_cell_renderer_progress_class_init (GaimGtkCellRendererProgressClass *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); | |
| 9898 | 124 object_class->finalize = gaim_gtk_cell_renderer_progress_finalize; |
| 3832 | 125 |
| 9898 | 126 object_class->get_property = gaim_gtk_cell_renderer_progress_get_property; |
| 127 object_class->set_property = gaim_gtk_cell_renderer_progress_set_property; | |
| 3832 | 128 |
| 9898 | 129 cell_class->get_size = gaim_gtk_cell_renderer_progress_get_size; |
| 130 cell_class->render = gaim_gtk_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 | |
| 9898 | 155 static void gaim_gtk_cell_renderer_progress_finalize (GObject *object) |
| 3832 | 156 { |
|
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
3832
diff
changeset
|
157 /* |
| 9898 | 158 GaimGtkCellRendererProgress *cellprogress = GAIM_GTK_CELL_RENDERER_PROGRESS(object); |
|
4514
7521e29658bc
[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 | |
| 9898 | 164 static void gaim_gtk_cell_renderer_progress_get_property (GObject *object, |
| 3832 | 165 guint param_id, |
| 166 GValue *value, | |
| 167 GParamSpec *psec) | |
| 168 { | |
| 9898 | 169 GaimGtkCellRendererProgress *cellprogress = GAIM_GTK_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 | |
| 9898 | 188 static void gaim_gtk_cell_renderer_progress_set_property (GObject *object, |
| 3832 | 189 guint param_id, |
| 190 const GValue *value, | |
| 191 GParamSpec *pspec) | |
| 192 { | |
| 9898 | 193 GaimGtkCellRendererProgress *cellprogress = GAIM_GTK_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 | |
| 9898 | 215 GtkCellRenderer *gaim_gtk_cell_renderer_progress_new(void) |
| 3832 | 216 { |
| 9898 | 217 return g_object_new(GAIM_TYPE_GTK_CELL_RENDERER_PROGRESS, NULL); |
| 3832 | 218 } |
| 219 | |
| 9898 | 220 static void gaim_gtk_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 | |
| 9898 | 256 static void gaim_gtk_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 { | |
| 9898 | 264 GaimGtkCellRendererProgress *cellprogress = (GaimGtkCellRendererProgress *) 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 | 276 |
| 3832 | 277 width -= cell->xpad*2; |
| 278 height -= cell->ypad*2; | |
| 9898 | 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 } |
