| File: | ctk/ctkcellrendererspinner.c |
| Warning: | line 362, column 3 Value stored to 'state' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* CTK - The GIMP Toolkit |
| 2 | * |
| 3 | * Copyright (C) 2009 Matthias Clasen <mclasen@redhat.com> |
| 4 | * Copyright (C) 2008 Richard Hughes <richard@hughsie.com> |
| 5 | * Copyright (C) 2009 Bastien Nocera <hadess@hadess.net> |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation; either |
| 10 | * version 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | /* |
| 22 | * Modified by the CTK+ Team and others 2007. See the AUTHORS |
| 23 | * file for a list of people on the CTK+ Team. See the ChangeLog |
| 24 | * files for a list of changes. These files are distributed with |
| 25 | * CTK+ at ftp://ftp.ctk.org/pub/ctk/. |
| 26 | */ |
| 27 | |
| 28 | #include "config.h" |
| 29 | |
| 30 | #include "ctkcellrendererspinner.h" |
| 31 | #include "ctkiconfactory.h" |
| 32 | #include "ctkicontheme.h" |
| 33 | #include "ctkintl.h" |
| 34 | #include "ctksettings.h" |
| 35 | #include "ctktypebuiltins.h" |
| 36 | |
| 37 | #undef CDK_DEPRECATED |
| 38 | #undef CDK_DEPRECATED_FOR |
| 39 | #define CDK_DEPRECATED |
| 40 | #define CDK_DEPRECATED_FOR(f) |
| 41 | |
| 42 | #include "ctkstyle.h" |
| 43 | |
| 44 | |
| 45 | /** |
| 46 | * SECTION:ctkcellrendererspinner |
| 47 | * @Short_description: Renders a spinning animation in a cell |
| 48 | * @Title: CtkCellRendererSpinner |
| 49 | * @See_also: #CtkSpinner, #CtkCellRendererProgress |
| 50 | * |
| 51 | * CtkCellRendererSpinner renders a spinning animation in a cell, very |
| 52 | * similar to #CtkSpinner. It can often be used as an alternative |
| 53 | * to a #CtkCellRendererProgress for displaying indefinite activity, |
| 54 | * instead of actual progress. |
| 55 | * |
| 56 | * To start the animation in a cell, set the #CtkCellRendererSpinner:active |
| 57 | * property to %TRUE and increment the #CtkCellRendererSpinner:pulse property |
| 58 | * at regular intervals. The usual way to set the cell renderer properties |
| 59 | * for each cell is to bind them to columns in your tree model using e.g. |
| 60 | * ctk_tree_view_column_add_attribute(). |
| 61 | */ |
| 62 | |
| 63 | |
| 64 | enum { |
| 65 | PROP_0, |
| 66 | PROP_ACTIVE, |
| 67 | PROP_PULSE, |
| 68 | PROP_SIZE |
| 69 | }; |
| 70 | |
| 71 | struct _CtkCellRendererSpinnerPrivate |
| 72 | { |
| 73 | gboolean active; |
| 74 | guint pulse; |
| 75 | CtkIconSize icon_size, old_icon_size; |
| 76 | gint size; |
| 77 | }; |
| 78 | |
| 79 | |
| 80 | static void ctk_cell_renderer_spinner_get_property (GObject *object, |
| 81 | guint param_id, |
| 82 | GValue *value, |
| 83 | GParamSpec *pspec); |
| 84 | static void ctk_cell_renderer_spinner_set_property (GObject *object, |
| 85 | guint param_id, |
| 86 | const GValue *value, |
| 87 | GParamSpec *pspec); |
| 88 | static void ctk_cell_renderer_spinner_get_size (CtkCellRenderer *cell, |
| 89 | CtkWidget *widget, |
| 90 | const CdkRectangle *cell_area, |
| 91 | gint *x_offset, |
| 92 | gint *y_offset, |
| 93 | gint *width, |
| 94 | gint *height); |
| 95 | static void ctk_cell_renderer_spinner_render (CtkCellRenderer *cell, |
| 96 | cairo_t *cr, |
| 97 | CtkWidget *widget, |
| 98 | const CdkRectangle *background_area, |
| 99 | const CdkRectangle *cell_area, |
| 100 | CtkCellRendererState flags); |
| 101 | |
| 102 | G_DEFINE_TYPE_WITH_PRIVATE (CtkCellRendererSpinner, ctk_cell_renderer_spinner, CTK_TYPE_CELL_RENDERER)static void ctk_cell_renderer_spinner_init (CtkCellRendererSpinner *self); static void ctk_cell_renderer_spinner_class_init (CtkCellRendererSpinnerClass *klass); static GType ctk_cell_renderer_spinner_get_type_once (void); static gpointer ctk_cell_renderer_spinner_parent_class = ((void*)0); static gint CtkCellRendererSpinner_private_offset ; static void ctk_cell_renderer_spinner_class_intern_init (gpointer klass) { ctk_cell_renderer_spinner_parent_class = g_type_class_peek_parent (klass); if (CtkCellRendererSpinner_private_offset != 0) g_type_class_adjust_private_offset (klass, &CtkCellRendererSpinner_private_offset); ctk_cell_renderer_spinner_class_init ((CtkCellRendererSpinnerClass*) klass); } __attribute__ ((__unused__ )) static inline gpointer ctk_cell_renderer_spinner_get_instance_private (CtkCellRendererSpinner *self) { return (((gpointer) ((guint8 *) (self) + (glong) (CtkCellRendererSpinner_private_offset))) ); } GType ctk_cell_renderer_spinner_get_type (void) { static GType static_g_define_type_id = 0; if ((__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id) == sizeof (gpointer) , "Expression evaluates to false"); (void) (0 ? (gpointer) * ( &static_g_define_type_id) : ((void*)0)); (!(__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (*(&static_g_define_type_id)) gapg_temp_newval; __typeof__ ((&static_g_define_type_id)) gapg_temp_atomic = (&static_g_define_type_id ); __atomic_load (gapg_temp_atomic, &gapg_temp_newval, 5) ; gapg_temp_newval; })) && g_once_init_enter_pointer ( &static_g_define_type_id)); })) ) { GType g_define_type_id = ctk_cell_renderer_spinner_get_type_once (); (__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id) == sizeof (gpointer), "Expression evaluates to false"); 0 ? (void ) (*(&static_g_define_type_id) = (g_define_type_id)) : (void ) 0; g_once_init_leave_pointer ((&static_g_define_type_id ), (gpointer) (guintptr) (g_define_type_id)); })) ; } return static_g_define_type_id ; } __attribute__ ((__noinline__)) static GType ctk_cell_renderer_spinner_get_type_once (void) { GType g_define_type_id = g_type_register_static_simple ((ctk_cell_renderer_get_type ()), g_intern_static_string ("CtkCellRendererSpinner" ), sizeof (CtkCellRendererSpinnerClass), (GClassInitFunc)(void (*)(void)) ctk_cell_renderer_spinner_class_intern_init, sizeof (CtkCellRendererSpinner), (GInstanceInitFunc)(void (*)(void) ) ctk_cell_renderer_spinner_init, (GTypeFlags) 0); { {{ CtkCellRendererSpinner_private_offset = g_type_add_instance_private (g_define_type_id, sizeof (CtkCellRendererSpinnerPrivate )); };} } return g_define_type_id; } |
| 103 | |
| 104 | static void |
| 105 | ctk_cell_renderer_spinner_class_init (CtkCellRendererSpinnerClass *klass) |
| 106 | { |
| 107 | GObjectClass *object_class = G_OBJECT_CLASS (klass)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((klass)), (((GType) ((20) << (2)))))))); |
| 108 | CtkCellRendererClass *cell_class = CTK_CELL_RENDERER_CLASS (klass)((((CtkCellRendererClass*) (void *) g_type_check_class_cast ( (GTypeClass*) ((klass)), ((ctk_cell_renderer_get_type ()))))) ); |
| 109 | |
| 110 | object_class->get_property = ctk_cell_renderer_spinner_get_property; |
| 111 | object_class->set_property = ctk_cell_renderer_spinner_set_property; |
| 112 | |
| 113 | cell_class->get_size = ctk_cell_renderer_spinner_get_size; |
| 114 | cell_class->render = ctk_cell_renderer_spinner_render; |
| 115 | |
| 116 | /* CtkCellRendererSpinner:active: |
| 117 | * |
| 118 | * Whether the spinner is active (ie. shown) in the cell |
| 119 | * |
| 120 | * Since: 2.20 |
| 121 | */ |
| 122 | g_object_class_install_property (object_class, |
| 123 | PROP_ACTIVE, |
| 124 | g_param_spec_boolean ("active", |
| 125 | P_("Active")g_dgettext("ctk30" "-properties","Active"), |
| 126 | P_("Whether the spinner is active (ie. shown) in the cell")g_dgettext("ctk30" "-properties","Whether the spinner is active (ie. shown) in the cell" ), |
| 127 | FALSE(0), |
| 128 | G_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); |
| 129 | |
| 130 | /** |
| 131 | * CtkCellRendererSpinner:pulse: |
| 132 | * |
| 133 | * Pulse of the spinner. Increment this value to draw the next frame of the |
| 134 | * spinner animation. Usually, you would update this value in a timeout. |
| 135 | * |
| 136 | * By default, the #CtkSpinner widget draws one full cycle of the animation, |
| 137 | * consisting of 12 frames, in 750 milliseconds. |
| 138 | * |
| 139 | * Since: 2.20 |
| 140 | */ |
| 141 | g_object_class_install_property (object_class, |
| 142 | PROP_PULSE, |
| 143 | g_param_spec_uint ("pulse", |
| 144 | P_("Pulse")g_dgettext("ctk30" "-properties","Pulse"), |
| 145 | P_("Pulse of the spinner")g_dgettext("ctk30" "-properties","Pulse of the spinner"), |
| 146 | 0, G_MAXUINT(2147483647 *2U +1U), 0, |
| 147 | G_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); |
| 148 | |
| 149 | /** |
| 150 | * CtkCellRendererSpinner:size: |
| 151 | * |
| 152 | * The #CtkIconSize value that specifies the size of the rendered spinner. |
| 153 | * |
| 154 | * Since: 2.20 |
| 155 | */ |
| 156 | g_object_class_install_property (object_class, |
| 157 | PROP_SIZE, |
| 158 | g_param_spec_enum ("size", |
| 159 | P_("Size")g_dgettext("ctk30" "-properties","Size"), |
| 160 | P_("The CtkIconSize value that specifies the size of the rendered spinner")g_dgettext("ctk30" "-properties","The CtkIconSize value that specifies the size of the rendered spinner" ), |
| 161 | CTK_TYPE_ICON_SIZE(ctk_icon_size_get_type ()), CTK_ICON_SIZE_MENU, |
| 162 | G_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); |
| 163 | |
| 164 | } |
| 165 | |
| 166 | static void |
| 167 | ctk_cell_renderer_spinner_init (CtkCellRendererSpinner *cell) |
| 168 | { |
| 169 | cell->priv = ctk_cell_renderer_spinner_get_instance_private (cell); |
| 170 | cell->priv->pulse = 0; |
| 171 | cell->priv->old_icon_size = CTK_ICON_SIZE_INVALID; |
| 172 | cell->priv->icon_size = CTK_ICON_SIZE_MENU; |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * ctk_cell_renderer_spinner_new: |
| 177 | * |
| 178 | * Returns a new cell renderer which will show a spinner to indicate |
| 179 | * activity. |
| 180 | * |
| 181 | * Returns: a new #CtkCellRenderer |
| 182 | * |
| 183 | * Since: 2.20 |
| 184 | */ |
| 185 | CtkCellRenderer * |
| 186 | ctk_cell_renderer_spinner_new (void) |
| 187 | { |
| 188 | return g_object_new (CTK_TYPE_CELL_RENDERER_SPINNER(ctk_cell_renderer_spinner_get_type ()), NULL((void*)0)); |
| 189 | } |
| 190 | |
| 191 | static void |
| 192 | ctk_cell_renderer_spinner_update_size (CtkCellRendererSpinner *cell, |
| 193 | CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__))) |
| 194 | { |
| 195 | CtkCellRendererSpinnerPrivate *priv = cell->priv; |
| 196 | |
| 197 | if (priv->old_icon_size == priv->icon_size) |
| 198 | return; |
| 199 | |
| 200 | if (!ctk_icon_size_lookup (priv->icon_size, &priv->size, NULL((void*)0))) |
| 201 | { |
| 202 | g_warning ("Invalid icon size %u", priv->icon_size); |
| 203 | priv->size = 24; |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | static void |
| 208 | ctk_cell_renderer_spinner_get_property (GObject *object, |
| 209 | guint param_id, |
| 210 | GValue *value, |
| 211 | GParamSpec *pspec) |
| 212 | { |
| 213 | CtkCellRendererSpinner *cell = CTK_CELL_RENDERER_SPINNER (object)((((CtkCellRendererSpinner*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((object)), ((ctk_cell_renderer_spinner_get_type ())))))); |
| 214 | CtkCellRendererSpinnerPrivate *priv = cell->priv; |
| 215 | |
| 216 | switch (param_id) |
| 217 | { |
| 218 | case PROP_ACTIVE: |
| 219 | g_value_set_boolean (value, priv->active); |
| 220 | break; |
| 221 | case PROP_PULSE: |
| 222 | g_value_set_uint (value, priv->pulse); |
| 223 | break; |
| 224 | case PROP_SIZE: |
| 225 | g_value_set_enum (value, priv->icon_size); |
| 226 | break; |
| 227 | default: |
| 228 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec)do { GObject *_glib__object = (GObject*) ((object)); GParamSpec *_glib__pspec = (GParamSpec*) ((pspec)); guint _glib__property_id = ((param_id)); g_warning ("%s:%d: invalid %s id %u for \"%s\" of type '%s' in '%s'" , "ctkcellrendererspinner.c", 228, ("property"), _glib__property_id , _glib__pspec->name, g_type_name ((((((GTypeClass*) (((GTypeInstance *) (_glib__pspec))->g_class))->g_type)))), (g_type_name ((((((GTypeClass*) (((GTypeInstance*) (_glib__object))->g_class ))->g_type)))))); } while (0); |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | static void |
| 233 | ctk_cell_renderer_spinner_set_property (GObject *object, |
| 234 | guint param_id, |
| 235 | const GValue *value, |
| 236 | GParamSpec *pspec) |
| 237 | { |
| 238 | CtkCellRendererSpinner *cell = CTK_CELL_RENDERER_SPINNER (object)((((CtkCellRendererSpinner*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((object)), ((ctk_cell_renderer_spinner_get_type ())))))); |
| 239 | CtkCellRendererSpinnerPrivate *priv = cell->priv; |
| 240 | |
| 241 | switch (param_id) |
| 242 | { |
| 243 | case PROP_ACTIVE: |
| 244 | if (priv->active != g_value_get_boolean (value)) |
| 245 | { |
| 246 | priv->active = g_value_get_boolean (value); |
| 247 | g_object_notify (object, "active"); |
| 248 | } |
| 249 | break; |
| 250 | case PROP_PULSE: |
| 251 | if (priv->pulse != g_value_get_uint (value)) |
| 252 | { |
| 253 | priv->pulse = g_value_get_uint (value); |
| 254 | g_object_notify (object, "pulse"); |
| 255 | } |
| 256 | break; |
| 257 | case PROP_SIZE: |
| 258 | if (priv->icon_size != g_value_get_enum (value)) |
| 259 | { |
| 260 | priv->old_icon_size = priv->icon_size; |
| 261 | priv->icon_size = g_value_get_enum (value); |
| 262 | g_object_notify (object, "size"); |
| 263 | } |
| 264 | break; |
| 265 | default: |
| 266 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec)do { GObject *_glib__object = (GObject*) ((object)); GParamSpec *_glib__pspec = (GParamSpec*) ((pspec)); guint _glib__property_id = ((param_id)); g_warning ("%s:%d: invalid %s id %u for \"%s\" of type '%s' in '%s'" , "ctkcellrendererspinner.c", 266, ("property"), _glib__property_id , _glib__pspec->name, g_type_name ((((((GTypeClass*) (((GTypeInstance *) (_glib__pspec))->g_class))->g_type)))), (g_type_name ((((((GTypeClass*) (((GTypeInstance*) (_glib__object))->g_class ))->g_type)))))); } while (0); |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | static void |
| 271 | ctk_cell_renderer_spinner_get_size (CtkCellRenderer *cellr, |
| 272 | CtkWidget *widget, |
| 273 | const CdkRectangle *cell_area, |
| 274 | gint *x_offset, |
| 275 | gint *y_offset, |
| 276 | gint *width, |
| 277 | gint *height) |
| 278 | { |
| 279 | CtkCellRendererSpinner *cell = CTK_CELL_RENDERER_SPINNER (cellr)((((CtkCellRendererSpinner*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((cellr)), ((ctk_cell_renderer_spinner_get_type ())))))); |
| 280 | CtkCellRendererSpinnerPrivate *priv = cell->priv; |
| 281 | gdouble align; |
| 282 | gint w, h; |
| 283 | gint xpad, ypad; |
| 284 | gfloat xalign, yalign; |
| 285 | gboolean rtl; |
| 286 | |
| 287 | rtl = ctk_widget_get_direction (widget) == CTK_TEXT_DIR_RTL; |
| 288 | |
| 289 | ctk_cell_renderer_spinner_update_size (cell, widget); |
| 290 | |
| 291 | g_object_get (cellr, |
| 292 | "xpad", &xpad, |
| 293 | "ypad", &ypad, |
| 294 | "xalign", &xalign, |
| 295 | "yalign", &yalign, |
| 296 | NULL((void*)0)); |
| 297 | w = h = priv->size; |
| 298 | |
| 299 | if (cell_area) |
| 300 | { |
| 301 | if (x_offset) |
| 302 | { |
| 303 | align = rtl ? 1.0 - xalign : xalign; |
| 304 | *x_offset = align * (cell_area->width - w); |
| 305 | *x_offset = MAX (*x_offset, 0)(((*x_offset) > (0)) ? (*x_offset) : (0)); |
| 306 | } |
| 307 | if (y_offset) |
| 308 | { |
| 309 | align = rtl ? 1.0 - yalign : yalign; |
| 310 | *y_offset = align * (cell_area->height - h); |
| 311 | *y_offset = MAX (*y_offset, 0)(((*y_offset) > (0)) ? (*y_offset) : (0)); |
| 312 | } |
| 313 | } |
| 314 | else |
| 315 | { |
| 316 | if (x_offset) |
| 317 | *x_offset = 0; |
| 318 | if (y_offset) |
| 319 | *y_offset = 0; |
| 320 | } |
| 321 | |
| 322 | if (width) |
| 323 | *width = w; |
| 324 | if (height) |
| 325 | *height = h; |
| 326 | } |
| 327 | |
| 328 | static void |
| 329 | ctk_cell_renderer_spinner_render (CtkCellRenderer *cellr, |
| 330 | cairo_t *cr, |
| 331 | CtkWidget *widget, |
| 332 | const CdkRectangle *background_area G_GNUC_UNUSED__attribute__ ((__unused__)), |
| 333 | const CdkRectangle *cell_area, |
| 334 | CtkCellRendererState flags) |
| 335 | { |
| 336 | CtkCellRendererSpinner *cell = CTK_CELL_RENDERER_SPINNER (cellr)((((CtkCellRendererSpinner*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((cellr)), ((ctk_cell_renderer_spinner_get_type ())))))); |
| 337 | CtkCellRendererSpinnerPrivate *priv = cell->priv; |
| 338 | CtkStateType state; |
| 339 | CdkRectangle pix_rect; |
| 340 | CdkRectangle draw_rect; |
| 341 | gint xpad, ypad; |
| 342 | |
| 343 | if (!priv->active) |
| 344 | return; |
| 345 | |
| 346 | ctk_cell_renderer_spinner_get_size (cellr, widget, (CdkRectangle *) cell_area, |
| 347 | &pix_rect.x, &pix_rect.y, |
| 348 | &pix_rect.width, &pix_rect.height); |
| 349 | |
| 350 | g_object_get (cellr, |
| 351 | "xpad", &xpad, |
| 352 | "ypad", &ypad, |
| 353 | NULL((void*)0)); |
| 354 | pix_rect.x += cell_area->x + xpad; |
| 355 | pix_rect.y += cell_area->y + ypad; |
| 356 | pix_rect.width -= xpad * 2; |
| 357 | pix_rect.height -= ypad * 2; |
| 358 | |
| 359 | if (!cdk_rectangle_intersect (cell_area, &pix_rect, &draw_rect)) |
| 360 | return; |
| 361 | |
| 362 | state = CTK_STATE_NORMAL; |
Value stored to 'state' is never read | |
| 363 | if ((ctk_widget_get_state_flags (widget) & CTK_STATE_FLAG_INSENSITIVE) || |
| 364 | !ctk_cell_renderer_get_sensitive (cellr)) |
| 365 | { |
| 366 | state = CTK_STATE_INSENSITIVE; |
| 367 | } |
| 368 | else |
| 369 | { |
| 370 | if ((flags & CTK_CELL_RENDERER_SELECTED) != 0) |
| 371 | { |
| 372 | if (ctk_widget_has_focus (widget)) |
| 373 | state = CTK_STATE_SELECTED; |
| 374 | else |
| 375 | state = CTK_STATE_ACTIVE; |
| 376 | } |
| 377 | else |
| 378 | state = CTK_STATE_PRELIGHT; |
| 379 | } |
| 380 | |
| 381 | cairo_save (cr); |
| 382 | |
| 383 | cdk_cairo_rectangle (cr, cell_area); |
| 384 | cairo_clip (cr); |
| 385 | |
| 386 | ctk_paint_spinner (ctk_widget_get_style (widget), |
| 387 | cr, |
| 388 | state, |
| 389 | widget, |
| 390 | "cell", |
| 391 | priv->pulse, |
| 392 | draw_rect.x, draw_rect.y, |
| 393 | draw_rect.width, draw_rect.height); |
| 394 | |
| 395 | cairo_restore (cr); |
| 396 | } |