gimp/libgimpwidgets/gimpcellrenderertoggle.c

445 lines
16 KiB
C
Raw Normal View History

/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpcellrenderertoggle.c
* Copyright (C) 2003-2004 Sven Neumann <sven@gimp.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <config.h>
#include <gtk/gtk.h>
#include "gimpwidgetstypes.h"
Made drawable/layer properties (visibility, opacity etc.) undoable (fixes 2003-03-17 Michael Natterer <mitch@gimp.org> Made drawable/layer properties (visibility, opacity etc.) undoable (fixes bug #73893). * app/core/core-enums.[ch]: added undo types/groups for visibility, mode, opacity, linked and preserve_trans. * app/core/Makefile.am * app/core/core-types.h * app/core/gimpitemundo.[ch]: new GimpUndo subclass which holds a ref'ed GimpItem pointer so (1) this doesn't need to be done by all undo steps related to an item and (2) the item the undo step is for can be determined from outside the undo system. * app/core/gimpimage-undo.[ch]: added gimp_image_undo_push_item() which returns a new GimpItemUndo. * app/core/gimpimage-undo-push.[ch]: use it for all item related undo steps. Removed lots of GimpItem, GimpLayer, GimpDrawable and GimpVectors pointers from the private undo structs. Added undo push functions for the new undo types added above. * app/core/gimpdrawable.[ch] (gimp_drawable_set_visible): added "gboolean push_undo" parameter. * app/core/gimplayer.[ch] (gimp_layer_set_opacity, _mode, _preserve_trans, _linked): added "gboolean push_undo" parameters. * app/core/gimpimage-mask.c * app/core/gimpimage-merge.c * app/core/gimplayer-floating-sel.c * app/tools/gimpmovetool.c * app/xcf/xcf-load.c * app/widgets/gimpdrawablelistitem.c * app/widgets/gimplayerlistitem.c * app/widgets/gimplayerlistview.c: changed accordingly. * tools/pdbgen/pdb/channel.pdb * tools/pdbgen/pdb/layer.pdb: ditto. Added '$undo' paramaters to the foo_accessors() functions. Removed $func from foo_accesors() because we don't manipulate items without using getters/setters any longer. * app/pdb/channel_cmds.c * app/pdb/layer_cmds.c: regenerated. * app/widgets/gimpcellrenderertoggle.[ch]: added "clicked" signal which carries an additional "GdkModifierType state" parameter as in GimpCellRendererViewable . * app/widgets/gimpcontainertreeview.c: emit "clicked" from the toggle renderer, not "toggled" so the callbacks get the modifier state. * app/widgets/gimpdrawabletreeview.c: resurrected the "exclusive visible by <shift>+click" feature as in 1.2. * app/widgets/gimplayertreeview.c: compress layer opacity undos by looking at the top of the undo stack and not pushing an undo if there already is a GIMP_UNDO_DRAWABLE_OPACITY for the active layer.
2003-03-18 02:02:41 +08:00
#include "gimpwidgetsmarshal.h"
#include "gimpcellrenderertoggle.h"
#define DEFAULT_ICON_SIZE GTK_ICON_SIZE_BUTTON
Made drawable/layer properties (visibility, opacity etc.) undoable (fixes 2003-03-17 Michael Natterer <mitch@gimp.org> Made drawable/layer properties (visibility, opacity etc.) undoable (fixes bug #73893). * app/core/core-enums.[ch]: added undo types/groups for visibility, mode, opacity, linked and preserve_trans. * app/core/Makefile.am * app/core/core-types.h * app/core/gimpitemundo.[ch]: new GimpUndo subclass which holds a ref'ed GimpItem pointer so (1) this doesn't need to be done by all undo steps related to an item and (2) the item the undo step is for can be determined from outside the undo system. * app/core/gimpimage-undo.[ch]: added gimp_image_undo_push_item() which returns a new GimpItemUndo. * app/core/gimpimage-undo-push.[ch]: use it for all item related undo steps. Removed lots of GimpItem, GimpLayer, GimpDrawable and GimpVectors pointers from the private undo structs. Added undo push functions for the new undo types added above. * app/core/gimpdrawable.[ch] (gimp_drawable_set_visible): added "gboolean push_undo" parameter. * app/core/gimplayer.[ch] (gimp_layer_set_opacity, _mode, _preserve_trans, _linked): added "gboolean push_undo" parameters. * app/core/gimpimage-mask.c * app/core/gimpimage-merge.c * app/core/gimplayer-floating-sel.c * app/tools/gimpmovetool.c * app/xcf/xcf-load.c * app/widgets/gimpdrawablelistitem.c * app/widgets/gimplayerlistitem.c * app/widgets/gimplayerlistview.c: changed accordingly. * tools/pdbgen/pdb/channel.pdb * tools/pdbgen/pdb/layer.pdb: ditto. Added '$undo' paramaters to the foo_accessors() functions. Removed $func from foo_accesors() because we don't manipulate items without using getters/setters any longer. * app/pdb/channel_cmds.c * app/pdb/layer_cmds.c: regenerated. * app/widgets/gimpcellrenderertoggle.[ch]: added "clicked" signal which carries an additional "GdkModifierType state" parameter as in GimpCellRendererViewable . * app/widgets/gimpcontainertreeview.c: emit "clicked" from the toggle renderer, not "toggled" so the callbacks get the modifier state. * app/widgets/gimpdrawabletreeview.c: resurrected the "exclusive visible by <shift>+click" feature as in 1.2. * app/widgets/gimplayertreeview.c: compress layer opacity undos by looking at the top of the undo stack and not pushing an undo if there already is a GIMP_UNDO_DRAWABLE_OPACITY for the active layer.
2003-03-18 02:02:41 +08:00
enum
{
CLICKED,
LAST_SIGNAL
};
enum
{
PROP_0,
PROP_STOCK_ID,
PROP_STOCK_SIZE
};
static void gimp_cell_renderer_toggle_finalize (GObject *object);
static void gimp_cell_renderer_toggle_get_property (GObject *object,
guint param_id,
GValue *value,
GParamSpec *pspec);
static void gimp_cell_renderer_toggle_set_property (GObject *object,
guint param_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_cell_renderer_toggle_get_size (GtkCellRenderer *cell,
GtkWidget *widget,
GdkRectangle *rectangle,
gint *x_offset,
gint *y_offset,
gint *width,
gint *height);
static void gimp_cell_renderer_toggle_render (GtkCellRenderer *cell,
GdkWindow *window,
GtkWidget *widget,
GdkRectangle *background_area,
GdkRectangle *cell_area,
GdkRectangle *expose_area,
GtkCellRendererState flags);
Made drawable/layer properties (visibility, opacity etc.) undoable (fixes 2003-03-17 Michael Natterer <mitch@gimp.org> Made drawable/layer properties (visibility, opacity etc.) undoable (fixes bug #73893). * app/core/core-enums.[ch]: added undo types/groups for visibility, mode, opacity, linked and preserve_trans. * app/core/Makefile.am * app/core/core-types.h * app/core/gimpitemundo.[ch]: new GimpUndo subclass which holds a ref'ed GimpItem pointer so (1) this doesn't need to be done by all undo steps related to an item and (2) the item the undo step is for can be determined from outside the undo system. * app/core/gimpimage-undo.[ch]: added gimp_image_undo_push_item() which returns a new GimpItemUndo. * app/core/gimpimage-undo-push.[ch]: use it for all item related undo steps. Removed lots of GimpItem, GimpLayer, GimpDrawable and GimpVectors pointers from the private undo structs. Added undo push functions for the new undo types added above. * app/core/gimpdrawable.[ch] (gimp_drawable_set_visible): added "gboolean push_undo" parameter. * app/core/gimplayer.[ch] (gimp_layer_set_opacity, _mode, _preserve_trans, _linked): added "gboolean push_undo" parameters. * app/core/gimpimage-mask.c * app/core/gimpimage-merge.c * app/core/gimplayer-floating-sel.c * app/tools/gimpmovetool.c * app/xcf/xcf-load.c * app/widgets/gimpdrawablelistitem.c * app/widgets/gimplayerlistitem.c * app/widgets/gimplayerlistview.c: changed accordingly. * tools/pdbgen/pdb/channel.pdb * tools/pdbgen/pdb/layer.pdb: ditto. Added '$undo' paramaters to the foo_accessors() functions. Removed $func from foo_accesors() because we don't manipulate items without using getters/setters any longer. * app/pdb/channel_cmds.c * app/pdb/layer_cmds.c: regenerated. * app/widgets/gimpcellrenderertoggle.[ch]: added "clicked" signal which carries an additional "GdkModifierType state" parameter as in GimpCellRendererViewable . * app/widgets/gimpcontainertreeview.c: emit "clicked" from the toggle renderer, not "toggled" so the callbacks get the modifier state. * app/widgets/gimpdrawabletreeview.c: resurrected the "exclusive visible by <shift>+click" feature as in 1.2. * app/widgets/gimplayertreeview.c: compress layer opacity undos by looking at the top of the undo stack and not pushing an undo if there already is a GIMP_UNDO_DRAWABLE_OPACITY for the active layer.
2003-03-18 02:02:41 +08:00
static gboolean gimp_cell_renderer_toggle_activate (GtkCellRenderer *cell,
GdkEvent *event,
GtkWidget *widget,
const gchar *path,
GdkRectangle *background_area,
GdkRectangle *cell_area,
GtkCellRendererState flags);
static void gimp_cell_renderer_toggle_create_pixbuf (GimpCellRendererToggle *toggle,
GtkWidget *widget);
G_DEFINE_TYPE (GimpCellRendererToggle, gimp_cell_renderer_toggle,
GTK_TYPE_CELL_RENDERER_TOGGLE)
#define parent_class gimp_cell_renderer_toggle_parent_class
static guint toggle_cell_signals[LAST_SIGNAL] = { 0 };
static void
gimp_cell_renderer_toggle_class_init (GimpCellRendererToggleClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (klass);
Made drawable/layer properties (visibility, opacity etc.) undoable (fixes 2003-03-17 Michael Natterer <mitch@gimp.org> Made drawable/layer properties (visibility, opacity etc.) undoable (fixes bug #73893). * app/core/core-enums.[ch]: added undo types/groups for visibility, mode, opacity, linked and preserve_trans. * app/core/Makefile.am * app/core/core-types.h * app/core/gimpitemundo.[ch]: new GimpUndo subclass which holds a ref'ed GimpItem pointer so (1) this doesn't need to be done by all undo steps related to an item and (2) the item the undo step is for can be determined from outside the undo system. * app/core/gimpimage-undo.[ch]: added gimp_image_undo_push_item() which returns a new GimpItemUndo. * app/core/gimpimage-undo-push.[ch]: use it for all item related undo steps. Removed lots of GimpItem, GimpLayer, GimpDrawable and GimpVectors pointers from the private undo structs. Added undo push functions for the new undo types added above. * app/core/gimpdrawable.[ch] (gimp_drawable_set_visible): added "gboolean push_undo" parameter. * app/core/gimplayer.[ch] (gimp_layer_set_opacity, _mode, _preserve_trans, _linked): added "gboolean push_undo" parameters. * app/core/gimpimage-mask.c * app/core/gimpimage-merge.c * app/core/gimplayer-floating-sel.c * app/tools/gimpmovetool.c * app/xcf/xcf-load.c * app/widgets/gimpdrawablelistitem.c * app/widgets/gimplayerlistitem.c * app/widgets/gimplayerlistview.c: changed accordingly. * tools/pdbgen/pdb/channel.pdb * tools/pdbgen/pdb/layer.pdb: ditto. Added '$undo' paramaters to the foo_accessors() functions. Removed $func from foo_accesors() because we don't manipulate items without using getters/setters any longer. * app/pdb/channel_cmds.c * app/pdb/layer_cmds.c: regenerated. * app/widgets/gimpcellrenderertoggle.[ch]: added "clicked" signal which carries an additional "GdkModifierType state" parameter as in GimpCellRendererViewable . * app/widgets/gimpcontainertreeview.c: emit "clicked" from the toggle renderer, not "toggled" so the callbacks get the modifier state. * app/widgets/gimpdrawabletreeview.c: resurrected the "exclusive visible by <shift>+click" feature as in 1.2. * app/widgets/gimplayertreeview.c: compress layer opacity undos by looking at the top of the undo stack and not pushing an undo if there already is a GIMP_UNDO_DRAWABLE_OPACITY for the active layer.
2003-03-18 02:02:41 +08:00
toggle_cell_signals[CLICKED] =
g_signal_new ("clicked",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GimpCellRendererToggleClass, clicked),
NULL, NULL,
_gimp_widgets_marshal_VOID__STRING_FLAGS,
G_TYPE_NONE, 2,
G_TYPE_STRING,
GDK_TYPE_MODIFIER_TYPE);
Made drawable/layer properties (visibility, opacity etc.) undoable (fixes 2003-03-17 Michael Natterer <mitch@gimp.org> Made drawable/layer properties (visibility, opacity etc.) undoable (fixes bug #73893). * app/core/core-enums.[ch]: added undo types/groups for visibility, mode, opacity, linked and preserve_trans. * app/core/Makefile.am * app/core/core-types.h * app/core/gimpitemundo.[ch]: new GimpUndo subclass which holds a ref'ed GimpItem pointer so (1) this doesn't need to be done by all undo steps related to an item and (2) the item the undo step is for can be determined from outside the undo system. * app/core/gimpimage-undo.[ch]: added gimp_image_undo_push_item() which returns a new GimpItemUndo. * app/core/gimpimage-undo-push.[ch]: use it for all item related undo steps. Removed lots of GimpItem, GimpLayer, GimpDrawable and GimpVectors pointers from the private undo structs. Added undo push functions for the new undo types added above. * app/core/gimpdrawable.[ch] (gimp_drawable_set_visible): added "gboolean push_undo" parameter. * app/core/gimplayer.[ch] (gimp_layer_set_opacity, _mode, _preserve_trans, _linked): added "gboolean push_undo" parameters. * app/core/gimpimage-mask.c * app/core/gimpimage-merge.c * app/core/gimplayer-floating-sel.c * app/tools/gimpmovetool.c * app/xcf/xcf-load.c * app/widgets/gimpdrawablelistitem.c * app/widgets/gimplayerlistitem.c * app/widgets/gimplayerlistview.c: changed accordingly. * tools/pdbgen/pdb/channel.pdb * tools/pdbgen/pdb/layer.pdb: ditto. Added '$undo' paramaters to the foo_accessors() functions. Removed $func from foo_accesors() because we don't manipulate items without using getters/setters any longer. * app/pdb/channel_cmds.c * app/pdb/layer_cmds.c: regenerated. * app/widgets/gimpcellrenderertoggle.[ch]: added "clicked" signal which carries an additional "GdkModifierType state" parameter as in GimpCellRendererViewable . * app/widgets/gimpcontainertreeview.c: emit "clicked" from the toggle renderer, not "toggled" so the callbacks get the modifier state. * app/widgets/gimpdrawabletreeview.c: resurrected the "exclusive visible by <shift>+click" feature as in 1.2. * app/widgets/gimplayertreeview.c: compress layer opacity undos by looking at the top of the undo stack and not pushing an undo if there already is a GIMP_UNDO_DRAWABLE_OPACITY for the active layer.
2003-03-18 02:02:41 +08:00
object_class->finalize = gimp_cell_renderer_toggle_finalize;
object_class->get_property = gimp_cell_renderer_toggle_get_property;
object_class->set_property = gimp_cell_renderer_toggle_set_property;
cell_class->get_size = gimp_cell_renderer_toggle_get_size;
cell_class->render = gimp_cell_renderer_toggle_render;
cell_class->activate = gimp_cell_renderer_toggle_activate;
g_object_class_install_property (object_class,
PROP_STOCK_ID,
g_param_spec_string ("stock-id",
NULL, NULL,
NULL,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class,
PROP_STOCK_SIZE,
g_param_spec_int ("stock-size",
NULL, NULL,
0, G_MAXINT,
DEFAULT_ICON_SIZE,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
}
static void
gimp_cell_renderer_toggle_init (GimpCellRendererToggle *toggle)
{
}
static void
gimp_cell_renderer_toggle_finalize (GObject *object)
{
GimpCellRendererToggle *toggle = GIMP_CELL_RENDERER_TOGGLE (object);
if (toggle->stock_id)
{
g_free (toggle->stock_id);
toggle->stock_id = NULL;
}
if (toggle->pixbuf)
{
g_object_unref (toggle->pixbuf);
toggle->pixbuf = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_cell_renderer_toggle_get_property (GObject *object,
guint param_id,
GValue *value,
GParamSpec *pspec)
{
GimpCellRendererToggle *toggle = GIMP_CELL_RENDERER_TOGGLE (object);
switch (param_id)
{
case PROP_STOCK_ID:
g_value_set_string (value, toggle->stock_id);
break;
case PROP_STOCK_SIZE:
g_value_set_int (value, toggle->stock_size);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
}
}
static void
gimp_cell_renderer_toggle_set_property (GObject *object,
guint param_id,
const GValue *value,
GParamSpec *pspec)
{
GimpCellRendererToggle *toggle = GIMP_CELL_RENDERER_TOGGLE (object);
switch (param_id)
{
case PROP_STOCK_ID:
if (toggle->stock_id)
g_free (toggle->stock_id);
toggle->stock_id = g_value_dup_string (value);
break;
case PROP_STOCK_SIZE:
toggle->stock_size = g_value_get_int (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
}
if (toggle->pixbuf)
{
g_object_unref (toggle->pixbuf);
toggle->pixbuf = NULL;
}
}
static void
gimp_cell_renderer_toggle_get_size (GtkCellRenderer *cell,
GtkWidget *widget,
GdkRectangle *cell_area,
gint *x_offset,
gint *y_offset,
gint *width,
gint *height)
{
GimpCellRendererToggle *toggle = GIMP_CELL_RENDERER_TOGGLE (cell);
gint calc_width;
gint calc_height;
gint pixbuf_width;
gint pixbuf_height;
if (! toggle->stock_id)
{
GTK_CELL_RENDERER_CLASS (parent_class)->get_size (cell,
widget,
cell_area,
x_offset, y_offset,
width, height);
return;
}
if (! toggle->pixbuf)
gimp_cell_renderer_toggle_create_pixbuf (toggle, widget);
pixbuf_width = gdk_pixbuf_get_width (toggle->pixbuf);
pixbuf_height = gdk_pixbuf_get_height (toggle->pixbuf);
calc_width = (pixbuf_width +
(gint) cell->xpad * 2 + widget->style->xthickness * 2);
calc_height = (pixbuf_height +
(gint) cell->ypad * 2 + widget->style->ythickness * 2);
if (width)
*width = calc_width;
if (height)
*height = calc_height;
if (cell_area)
{
if (x_offset)
{
*x_offset = (((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ?
(1.0 - cell->xalign) : cell->xalign) *
(cell_area->width - calc_width));
*x_offset = MAX (*x_offset, 0);
}
if (y_offset)
{
*y_offset = cell->yalign * (cell_area->height - calc_height);
*y_offset = MAX (*y_offset, 0);
}
}
}
static void
gimp_cell_renderer_toggle_render (GtkCellRenderer *cell,
GdkWindow *window,
GtkWidget *widget,
GdkRectangle *background_area,
GdkRectangle *cell_area,
GdkRectangle *expose_area,
GtkCellRendererState flags)
{
GimpCellRendererToggle *toggle = GIMP_CELL_RENDERER_TOGGLE (cell);
GdkRectangle toggle_rect;
GdkRectangle draw_rect;
GtkStateType state;
gboolean active;
if (! toggle->stock_id)
{
GTK_CELL_RENDERER_CLASS (parent_class)->render (cell, window, widget,
background_area,
cell_area, expose_area,
flags);
return;
}
gimp_cell_renderer_toggle_get_size (cell, widget, cell_area,
&toggle_rect.x,
&toggle_rect.y,
&toggle_rect.width,
&toggle_rect.height);
toggle_rect.x += cell_area->x + cell->xpad;
toggle_rect.y += cell_area->y + cell->ypad;
toggle_rect.width -= cell->xpad * 2;
toggle_rect.height -= cell->ypad * 2;
if (toggle_rect.width <= 0 || toggle_rect.height <= 0)
return;
active =
gtk_cell_renderer_toggle_get_active (GTK_CELL_RENDERER_TOGGLE (cell));
if ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED)
{
if (GTK_WIDGET_HAS_FOCUS (widget))
state = GTK_STATE_SELECTED;
else
state = GTK_STATE_ACTIVE;
}
else
{
if (GTK_CELL_RENDERER_TOGGLE (cell)->activatable)
state = GTK_STATE_NORMAL;
else
state = GTK_STATE_INSENSITIVE;
}
Added GtkTreeView versions of layers/channels/vectors: 2003-03-16 Michael Natterer <mitch@gimp.org> Added GtkTreeView versions of layers/channels/vectors: * app/core/core-enums.[ch]: renamed GIMP_UNDO_GROUP_LAYER_PROPERTIES to GIMP_UNDO_GROUP_ITEM_PROPERTIES. * app/core/gimpcontainer.c (gimp_container_reorder): don't try to reorder containers with num_children == 1. * app/core/gimpmarshal.list: added VOID: STRING, UINT marshaller. * app/widgets/Makefile.am * app/widgets/widgets-types.h * app/widgets/gimpchanneltreeview.[ch] * app/widgets/gimpdrawabletreeview.[ch] * app/widgets/gimpitemtreeview.[ch] * app/widgets/gimplayertreeview.[ch] * app/widgets/gimpvectorstreeview.[ch]: new widgets. * app/widgets/gimpcellrenderertoggle.c: draw the frame only if the cell is prelit. * app/widgets/gimpcellrendererviewable.[ch]: added "clicked" signal, unref the renderer in finalize(). Set the renderer's border color to black if the cell is not selected (a hack that saves tons of code in GimpLayerTreeView). * app/widgets/gimpcomponenteditor.c: no need to gtk_list_store_set() stuff we just got from the store. * app/widgets/gimpcontainertreeview.[ch]: added lots of state used by the new subclasses to the GimpContainerTreeView struct. Create the GtkListStore/GtkTreeView in GObject::constructor() and only collect parameters in init() so subclasses can modify store/view creation. Do most of the button_press_event stuff manually and return TRUE from the handler. * app/widgets/gimpcontainerview.c: cleanup. * app/widgets/gimpitemlistview.h * app/widgets/gimpvectorslistview.h: temp hacks before they die. * app/widgets/gimppreviewrenderer.[ch]: added gimp_preview_renderer_update_idle() which idle-emits "update" without invalidating. * app/gui/dialogs-constructors.[ch] * app/gui/dialogs.c: added constructors for the new dialogs. * app/gui/channels-commands.c * app/gui/channels-menu.c * app/gui/layers-commands.c * app/gui/layers-menu.c * app/gui/vectors-commands.c * app/gui/vectors-menu.c: accept tree views as callback data.
2003-03-16 19:14:29 +08:00
if (gdk_rectangle_intersect (expose_area, cell_area, &draw_rect) &&
(flags & GTK_CELL_RENDERER_PRELIT))
gtk_paint_shadow (widget->style,
window,
state,
active ? GTK_SHADOW_IN : GTK_SHADOW_OUT,
&draw_rect,
widget, NULL,
toggle_rect.x, toggle_rect.y,
toggle_rect.width, toggle_rect.height);
if (active)
{
toggle_rect.x += widget->style->xthickness;
toggle_rect.y += widget->style->ythickness;
toggle_rect.width -= widget->style->xthickness * 2;
toggle_rect.height -= widget->style->ythickness * 2;
if (gdk_rectangle_intersect (&draw_rect, &toggle_rect, &draw_rect))
gdk_draw_pixbuf (window,
widget->style->black_gc,
toggle->pixbuf,
/* pixbuf 0, 0 is at toggle_rect.x, toggle_rect.y */
draw_rect.x - toggle_rect.x,
draw_rect.y - toggle_rect.y,
draw_rect.x,
draw_rect.y,
draw_rect.width,
draw_rect.height,
GDK_RGB_DITHER_NORMAL,
0, 0);
}
}
Made drawable/layer properties (visibility, opacity etc.) undoable (fixes 2003-03-17 Michael Natterer <mitch@gimp.org> Made drawable/layer properties (visibility, opacity etc.) undoable (fixes bug #73893). * app/core/core-enums.[ch]: added undo types/groups for visibility, mode, opacity, linked and preserve_trans. * app/core/Makefile.am * app/core/core-types.h * app/core/gimpitemundo.[ch]: new GimpUndo subclass which holds a ref'ed GimpItem pointer so (1) this doesn't need to be done by all undo steps related to an item and (2) the item the undo step is for can be determined from outside the undo system. * app/core/gimpimage-undo.[ch]: added gimp_image_undo_push_item() which returns a new GimpItemUndo. * app/core/gimpimage-undo-push.[ch]: use it for all item related undo steps. Removed lots of GimpItem, GimpLayer, GimpDrawable and GimpVectors pointers from the private undo structs. Added undo push functions for the new undo types added above. * app/core/gimpdrawable.[ch] (gimp_drawable_set_visible): added "gboolean push_undo" parameter. * app/core/gimplayer.[ch] (gimp_layer_set_opacity, _mode, _preserve_trans, _linked): added "gboolean push_undo" parameters. * app/core/gimpimage-mask.c * app/core/gimpimage-merge.c * app/core/gimplayer-floating-sel.c * app/tools/gimpmovetool.c * app/xcf/xcf-load.c * app/widgets/gimpdrawablelistitem.c * app/widgets/gimplayerlistitem.c * app/widgets/gimplayerlistview.c: changed accordingly. * tools/pdbgen/pdb/channel.pdb * tools/pdbgen/pdb/layer.pdb: ditto. Added '$undo' paramaters to the foo_accessors() functions. Removed $func from foo_accesors() because we don't manipulate items without using getters/setters any longer. * app/pdb/channel_cmds.c * app/pdb/layer_cmds.c: regenerated. * app/widgets/gimpcellrenderertoggle.[ch]: added "clicked" signal which carries an additional "GdkModifierType state" parameter as in GimpCellRendererViewable . * app/widgets/gimpcontainertreeview.c: emit "clicked" from the toggle renderer, not "toggled" so the callbacks get the modifier state. * app/widgets/gimpdrawabletreeview.c: resurrected the "exclusive visible by <shift>+click" feature as in 1.2. * app/widgets/gimplayertreeview.c: compress layer opacity undos by looking at the top of the undo stack and not pushing an undo if there already is a GIMP_UNDO_DRAWABLE_OPACITY for the active layer.
2003-03-18 02:02:41 +08:00
static gboolean
gimp_cell_renderer_toggle_activate (GtkCellRenderer *cell,
GdkEvent *event,
GtkWidget *widget,
const gchar *path,
GdkRectangle *background_area,
GdkRectangle *cell_area,
GtkCellRendererState flags)
{
GtkCellRendererToggle *toggle = GTK_CELL_RENDERER_TOGGLE (cell);
Made drawable/layer properties (visibility, opacity etc.) undoable (fixes 2003-03-17 Michael Natterer <mitch@gimp.org> Made drawable/layer properties (visibility, opacity etc.) undoable (fixes bug #73893). * app/core/core-enums.[ch]: added undo types/groups for visibility, mode, opacity, linked and preserve_trans. * app/core/Makefile.am * app/core/core-types.h * app/core/gimpitemundo.[ch]: new GimpUndo subclass which holds a ref'ed GimpItem pointer so (1) this doesn't need to be done by all undo steps related to an item and (2) the item the undo step is for can be determined from outside the undo system. * app/core/gimpimage-undo.[ch]: added gimp_image_undo_push_item() which returns a new GimpItemUndo. * app/core/gimpimage-undo-push.[ch]: use it for all item related undo steps. Removed lots of GimpItem, GimpLayer, GimpDrawable and GimpVectors pointers from the private undo structs. Added undo push functions for the new undo types added above. * app/core/gimpdrawable.[ch] (gimp_drawable_set_visible): added "gboolean push_undo" parameter. * app/core/gimplayer.[ch] (gimp_layer_set_opacity, _mode, _preserve_trans, _linked): added "gboolean push_undo" parameters. * app/core/gimpimage-mask.c * app/core/gimpimage-merge.c * app/core/gimplayer-floating-sel.c * app/tools/gimpmovetool.c * app/xcf/xcf-load.c * app/widgets/gimpdrawablelistitem.c * app/widgets/gimplayerlistitem.c * app/widgets/gimplayerlistview.c: changed accordingly. * tools/pdbgen/pdb/channel.pdb * tools/pdbgen/pdb/layer.pdb: ditto. Added '$undo' paramaters to the foo_accessors() functions. Removed $func from foo_accesors() because we don't manipulate items without using getters/setters any longer. * app/pdb/channel_cmds.c * app/pdb/layer_cmds.c: regenerated. * app/widgets/gimpcellrenderertoggle.[ch]: added "clicked" signal which carries an additional "GdkModifierType state" parameter as in GimpCellRendererViewable . * app/widgets/gimpcontainertreeview.c: emit "clicked" from the toggle renderer, not "toggled" so the callbacks get the modifier state. * app/widgets/gimpdrawabletreeview.c: resurrected the "exclusive visible by <shift>+click" feature as in 1.2. * app/widgets/gimplayertreeview.c: compress layer opacity undos by looking at the top of the undo stack and not pushing an undo if there already is a GIMP_UNDO_DRAWABLE_OPACITY for the active layer.
2003-03-18 02:02:41 +08:00
if (toggle->activatable)
Made drawable/layer properties (visibility, opacity etc.) undoable (fixes 2003-03-17 Michael Natterer <mitch@gimp.org> Made drawable/layer properties (visibility, opacity etc.) undoable (fixes bug #73893). * app/core/core-enums.[ch]: added undo types/groups for visibility, mode, opacity, linked and preserve_trans. * app/core/Makefile.am * app/core/core-types.h * app/core/gimpitemundo.[ch]: new GimpUndo subclass which holds a ref'ed GimpItem pointer so (1) this doesn't need to be done by all undo steps related to an item and (2) the item the undo step is for can be determined from outside the undo system. * app/core/gimpimage-undo.[ch]: added gimp_image_undo_push_item() which returns a new GimpItemUndo. * app/core/gimpimage-undo-push.[ch]: use it for all item related undo steps. Removed lots of GimpItem, GimpLayer, GimpDrawable and GimpVectors pointers from the private undo structs. Added undo push functions for the new undo types added above. * app/core/gimpdrawable.[ch] (gimp_drawable_set_visible): added "gboolean push_undo" parameter. * app/core/gimplayer.[ch] (gimp_layer_set_opacity, _mode, _preserve_trans, _linked): added "gboolean push_undo" parameters. * app/core/gimpimage-mask.c * app/core/gimpimage-merge.c * app/core/gimplayer-floating-sel.c * app/tools/gimpmovetool.c * app/xcf/xcf-load.c * app/widgets/gimpdrawablelistitem.c * app/widgets/gimplayerlistitem.c * app/widgets/gimplayerlistview.c: changed accordingly. * tools/pdbgen/pdb/channel.pdb * tools/pdbgen/pdb/layer.pdb: ditto. Added '$undo' paramaters to the foo_accessors() functions. Removed $func from foo_accesors() because we don't manipulate items without using getters/setters any longer. * app/pdb/channel_cmds.c * app/pdb/layer_cmds.c: regenerated. * app/widgets/gimpcellrenderertoggle.[ch]: added "clicked" signal which carries an additional "GdkModifierType state" parameter as in GimpCellRendererViewable . * app/widgets/gimpcontainertreeview.c: emit "clicked" from the toggle renderer, not "toggled" so the callbacks get the modifier state. * app/widgets/gimpdrawabletreeview.c: resurrected the "exclusive visible by <shift>+click" feature as in 1.2. * app/widgets/gimplayertreeview.c: compress layer opacity undos by looking at the top of the undo stack and not pushing an undo if there already is a GIMP_UNDO_DRAWABLE_OPACITY for the active layer.
2003-03-18 02:02:41 +08:00
{
GdkModifierType state = 0;
if (event && ((GdkEventAny *) event)->type == GDK_BUTTON_PRESS)
Made drawable/layer properties (visibility, opacity etc.) undoable (fixes 2003-03-17 Michael Natterer <mitch@gimp.org> Made drawable/layer properties (visibility, opacity etc.) undoable (fixes bug #73893). * app/core/core-enums.[ch]: added undo types/groups for visibility, mode, opacity, linked and preserve_trans. * app/core/Makefile.am * app/core/core-types.h * app/core/gimpitemundo.[ch]: new GimpUndo subclass which holds a ref'ed GimpItem pointer so (1) this doesn't need to be done by all undo steps related to an item and (2) the item the undo step is for can be determined from outside the undo system. * app/core/gimpimage-undo.[ch]: added gimp_image_undo_push_item() which returns a new GimpItemUndo. * app/core/gimpimage-undo-push.[ch]: use it for all item related undo steps. Removed lots of GimpItem, GimpLayer, GimpDrawable and GimpVectors pointers from the private undo structs. Added undo push functions for the new undo types added above. * app/core/gimpdrawable.[ch] (gimp_drawable_set_visible): added "gboolean push_undo" parameter. * app/core/gimplayer.[ch] (gimp_layer_set_opacity, _mode, _preserve_trans, _linked): added "gboolean push_undo" parameters. * app/core/gimpimage-mask.c * app/core/gimpimage-merge.c * app/core/gimplayer-floating-sel.c * app/tools/gimpmovetool.c * app/xcf/xcf-load.c * app/widgets/gimpdrawablelistitem.c * app/widgets/gimplayerlistitem.c * app/widgets/gimplayerlistview.c: changed accordingly. * tools/pdbgen/pdb/channel.pdb * tools/pdbgen/pdb/layer.pdb: ditto. Added '$undo' paramaters to the foo_accessors() functions. Removed $func from foo_accesors() because we don't manipulate items without using getters/setters any longer. * app/pdb/channel_cmds.c * app/pdb/layer_cmds.c: regenerated. * app/widgets/gimpcellrenderertoggle.[ch]: added "clicked" signal which carries an additional "GdkModifierType state" parameter as in GimpCellRendererViewable . * app/widgets/gimpcontainertreeview.c: emit "clicked" from the toggle renderer, not "toggled" so the callbacks get the modifier state. * app/widgets/gimpdrawabletreeview.c: resurrected the "exclusive visible by <shift>+click" feature as in 1.2. * app/widgets/gimplayertreeview.c: compress layer opacity undos by looking at the top of the undo stack and not pushing an undo if there already is a GIMP_UNDO_DRAWABLE_OPACITY for the active layer.
2003-03-18 02:02:41 +08:00
state = ((GdkEventButton *) event)->state;
gimp_cell_renderer_toggle_clicked (GIMP_CELL_RENDERER_TOGGLE (cell),
path, state);
Made drawable/layer properties (visibility, opacity etc.) undoable (fixes 2003-03-17 Michael Natterer <mitch@gimp.org> Made drawable/layer properties (visibility, opacity etc.) undoable (fixes bug #73893). * app/core/core-enums.[ch]: added undo types/groups for visibility, mode, opacity, linked and preserve_trans. * app/core/Makefile.am * app/core/core-types.h * app/core/gimpitemundo.[ch]: new GimpUndo subclass which holds a ref'ed GimpItem pointer so (1) this doesn't need to be done by all undo steps related to an item and (2) the item the undo step is for can be determined from outside the undo system. * app/core/gimpimage-undo.[ch]: added gimp_image_undo_push_item() which returns a new GimpItemUndo. * app/core/gimpimage-undo-push.[ch]: use it for all item related undo steps. Removed lots of GimpItem, GimpLayer, GimpDrawable and GimpVectors pointers from the private undo structs. Added undo push functions for the new undo types added above. * app/core/gimpdrawable.[ch] (gimp_drawable_set_visible): added "gboolean push_undo" parameter. * app/core/gimplayer.[ch] (gimp_layer_set_opacity, _mode, _preserve_trans, _linked): added "gboolean push_undo" parameters. * app/core/gimpimage-mask.c * app/core/gimpimage-merge.c * app/core/gimplayer-floating-sel.c * app/tools/gimpmovetool.c * app/xcf/xcf-load.c * app/widgets/gimpdrawablelistitem.c * app/widgets/gimplayerlistitem.c * app/widgets/gimplayerlistview.c: changed accordingly. * tools/pdbgen/pdb/channel.pdb * tools/pdbgen/pdb/layer.pdb: ditto. Added '$undo' paramaters to the foo_accessors() functions. Removed $func from foo_accesors() because we don't manipulate items without using getters/setters any longer. * app/pdb/channel_cmds.c * app/pdb/layer_cmds.c: regenerated. * app/widgets/gimpcellrenderertoggle.[ch]: added "clicked" signal which carries an additional "GdkModifierType state" parameter as in GimpCellRendererViewable . * app/widgets/gimpcontainertreeview.c: emit "clicked" from the toggle renderer, not "toggled" so the callbacks get the modifier state. * app/widgets/gimpdrawabletreeview.c: resurrected the "exclusive visible by <shift>+click" feature as in 1.2. * app/widgets/gimplayertreeview.c: compress layer opacity undos by looking at the top of the undo stack and not pushing an undo if there already is a GIMP_UNDO_DRAWABLE_OPACITY for the active layer.
2003-03-18 02:02:41 +08:00
return TRUE;
}
return FALSE;
}
static void
gimp_cell_renderer_toggle_create_pixbuf (GimpCellRendererToggle *toggle,
GtkWidget *widget)
{
if (toggle->pixbuf)
g_object_unref (toggle->pixbuf);
toggle->pixbuf = gtk_widget_render_icon (widget,
toggle->stock_id,
toggle->stock_size, NULL);
}
/**
* gimp_cell_renderer_toggle_new:
* @stock_id: the stock_id of the icon to use for the active state
*
* Creates a custom version of the #GtkCellRendererToggle. Instead of
* showing the standard toggle button, it shows a stock icon if the
* cell is active and no icon otherwise. This cell renderer is for
* example used in the Layers treeview to indicate and control the
* layer's visibility by showing %GIMP_STOCK_VISIBLE.
*
* Return value: a new #GimpCellRendererToggle
*
* Since: GIMP 2.2
**/
GtkCellRenderer *
gimp_cell_renderer_toggle_new (const gchar *stock_id)
{
return g_object_new (GIMP_TYPE_CELL_RENDERER_TOGGLE,
"stock_id", stock_id,
NULL);
}
/**
* gimp_cell_renderer_toggle_clicked:
* @cell: a #GimpCellRendererToggle
* @path:
* @state:
*
* Emits the "clicked" signal from a #GimpCellRendererToggle.
*
* Since: GIMP 2.2
**/
void
gimp_cell_renderer_toggle_clicked (GimpCellRendererToggle *cell,
const gchar *path,
GdkModifierType state)
{
g_return_if_fail (GIMP_IS_CELL_RENDERER_TOGGLE (cell));
g_return_if_fail (path != NULL);
g_signal_emit (cell, toggle_cell_signals[CLICKED], 0, path, state);
}