28 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_BUTTON
56 const GdkRectangle *rectangle,
64 const GdkRectangle *background_area,
65 const GdkRectangle *cell_area,
66 GtkCellRendererState flags);
71 const GdkRectangle *background_area,
72 const GdkRectangle *cell_area,
73 GtkCellRendererState flags);
79 GTK_TYPE_CELL_RENDERER_TOGGLE)
81 #define parent_class gimp_cell_renderer_toggle_parent_class
83 static guint toggle_cell_signals[
LAST_SIGNAL] = { 0 };
89 GObjectClass *object_class = G_OBJECT_CLASS (klass);
90 GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (klass);
93 g_signal_new (
"clicked",
94 G_OBJECT_CLASS_TYPE (object_class),
98 g_cclosure_marshal_generic,
101 GDK_TYPE_MODIFIER_TYPE);
111 g_object_class_install_property (object_class,
113 g_param_spec_string (
"stock-id",
118 g_object_class_install_property (object_class,
120 g_param_spec_int (
"stock-size",
146 g_object_unref (toggle->
pixbuf);
164 g_value_set_string (value, toggle->
stock_id);
171 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, param_id, pspec);
189 toggle->
stock_id = g_value_dup_string (value);
196 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, param_id, pspec);
202 g_object_unref (toggle->
pixbuf);
210 const GdkRectangle *cell_area,
217 GtkStyleContext *context = gtk_widget_get_style_context (widget);
238 gtk_cell_renderer_get_alignment (cell, &xalign, &yalign);
239 gtk_cell_renderer_get_padding (cell, &xpad, &ypad);
241 gtk_style_context_get_border (context, 0, &border);
246 pixbuf_width = gdk_pixbuf_get_width (toggle->
pixbuf);
247 pixbuf_height = gdk_pixbuf_get_height (toggle->
pixbuf);
249 calc_width = (pixbuf_width + (gint) xpad * 2 + (border.left + border.right));
250 calc_height = (pixbuf_height + (gint) ypad * 2 + (border.top + border.bottom));
256 *height = calc_height;
262 *x_offset = (((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ?
263 (1.0 - xalign) : xalign) *
264 (cell_area->width - calc_width));
265 *x_offset = MAX (*x_offset, 0);
270 *y_offset = yalign * (cell_area->height - calc_height);
271 *y_offset = MAX (*y_offset, 0);
280 const GdkRectangle *background_area,
281 const GdkRectangle *cell_area,
282 GtkCellRendererState flags)
285 GtkStyleContext *context = gtk_widget_get_style_context (widget);
286 GdkRectangle toggle_rect;
287 GdkRectangle draw_rect;
288 GdkRectangle clip_rect;
305 gtk_cell_renderer_get_size (cell, widget, cell_area,
309 &toggle_rect.height);
311 gtk_cell_renderer_get_padding (cell, &xpad, &ypad);
312 toggle_rect.x += cell_area->x + xpad;
313 toggle_rect.y += cell_area->y + ypad;
314 toggle_rect.width -= xpad * 2;
315 toggle_rect.height -= ypad * 2;
317 if (toggle_rect.width <= 0 || toggle_rect.height <= 0)
321 gtk_cell_renderer_toggle_get_active (GTK_CELL_RENDERER_TOGGLE (cell));
323 if (!gtk_cell_renderer_get_sensitive (cell))
325 state = GTK_STATE_FLAG_INSENSITIVE;
327 else if ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED)
329 if (gtk_widget_has_focus (widget))
330 state = GTK_STATE_FLAG_SELECTED;
332 state = GTK_STATE_FLAG_ACTIVE;
336 if (gtk_cell_renderer_toggle_get_activatable (GTK_CELL_RENDERER_TOGGLE (cell)))
339 state = GTK_STATE_FLAG_INSENSITIVE;
342 if ((flags & GTK_CELL_RENDERER_PRELIT) &&
343 gdk_cairo_get_clip_rectangle(cr, &clip_rect) &&
344 gdk_rectangle_intersect (&clip_rect, cell_area, &draw_rect))
347 gtk_style_context_save (context);
348 gdk_cairo_rectangle (cr, &draw_rect);
350 gtk_render_frame (context,
352 toggle_rect.x, toggle_rect.y,
353 toggle_rect.width, toggle_rect.height);
354 gtk_style_context_restore (context);
360 GdkPixbuf *insensitive = NULL;
361 GdkPixbuf *pixbuf = toggle->
pixbuf;
362 GtkBorder border = { 1, 1, 1, 1 };
369 gtk_style_context_get_border (context, state, &border);
372 toggle_rect.x += border.left;
373 toggle_rect.y += border.top;
374 toggle_rect.width -= (border.left + border.right);
375 toggle_rect.height -= (border.top + border.bottom);
377 if (state & GTK_STATE_FLAG_INSENSITIVE)
379 GtkIconSource *source;
381 source = gtk_icon_source_new ();
382 gtk_icon_source_set_pixbuf (source, pixbuf);
387 gtk_icon_source_set_size (source, GTK_ICON_SIZE_SMALL_TOOLBAR);
388 gtk_icon_source_set_size_wildcarded (source,
FALSE);
390 gtk_style_context_save (context);
391 gtk_style_context_set_state (context, GTK_STATE_FLAG_INSENSITIVE);
392 insensitive = gtk_render_icon_pixbuf (context, source, (GtkIconSize)-1);
393 gtk_style_context_restore (context);
395 gtk_icon_source_free (source);
397 pixbuf = insensitive;
400 if (gdk_rectangle_intersect (&draw_rect, &toggle_rect, &draw_rect))
402 gdk_cairo_set_source_pixbuf (cr, pixbuf, toggle_rect.x, toggle_rect.y);
403 gdk_cairo_rectangle (cr, &draw_rect);
408 g_object_unref (insensitive);
417 const GdkRectangle *background_area,
418 const GdkRectangle *cell_area,
419 GtkCellRendererState flags)
421 GtkCellRendererToggle *toggle = GTK_CELL_RENDERER_TOGGLE (cell);
423 if (gtk_cell_renderer_toggle_get_activatable (toggle))
425 GdkModifierType state = 0;
427 GTK_CELL_RENDERER_CLASS (
parent_class)->activate (cell, event, widget,
428 path, background_area,
431 if (event && ((GdkEventAny *) event)->type == GDK_BUTTON_PRESS)
432 state = ((GdkEventButton *) event)->state;
448 g_object_unref (toggle->
pixbuf);
450 toggle->
pixbuf = gtk_widget_render_icon_pixbuf (widget,
474 "stock_id", stock_id,
491 GdkModifierType state)
494 g_return_if_fail (path != NULL);
496 g_signal_emit (cell, toggle_cell_signals[
CLICKED], 0, path, state);