1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* gimpchanneltreeview.c
5
* Copyright (C) 2001-2004 Michael Natterer <mitch@gimp.org>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program 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
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
#include "libgimpcolor/gimpcolor.h"
27
#include "libgimpwidgets/gimpwidgets.h"
29
#include "widgets-types.h"
31
#include "core/gimpchannel.h"
32
#include "core/gimpcontainer.h"
33
#include "core/gimpimage.h"
34
#include "core/gimpimage-undo.h"
36
#include "gimpchanneltreeview.h"
37
#include "gimpcomponenteditor.h"
38
#include "gimpcontainerview.h"
40
#include "gimpdocked.h"
41
#include "gimphelp-ids.h"
42
#include "gimpwidgets-utils.h"
44
#include "gimp-intl.h"
47
static void gimp_channel_tree_view_class_init (GimpChannelTreeViewClass *klass);
48
static void gimp_channel_tree_view_init (GimpChannelTreeView *view);
50
static void gimp_channel_tree_view_view_iface_init (GimpContainerViewInterface *view_iface);
51
static void gimp_channel_tree_view_docked_iface_init (GimpDockedInterface *docked_iface);
53
static GObject * gimp_channel_tree_view_constructor (GType type,
55
GObjectConstructParam *params);
56
static void gimp_channel_tree_view_set_image (GimpItemTreeView *item_view,
58
static GimpItem * gimp_channel_tree_view_item_new (GimpImage *image);
60
static void gimp_channel_tree_view_set_preview_size (GimpContainerView *view);
62
static void gimp_channel_tree_view_set_context (GimpDocked *docked,
63
GimpContext *context);
66
static GimpDrawableTreeViewClass *parent_class = NULL;
67
static GimpContainerViewInterface *parent_view_iface = NULL;
68
static GimpDockedInterface *parent_docked_iface = NULL;
72
gimp_channel_tree_view_get_type (void)
74
static GType view_type = 0;
78
static const GTypeInfo view_info =
80
sizeof (GimpChannelTreeViewClass),
82
NULL, /* base_finalize */
83
(GClassInitFunc) gimp_channel_tree_view_class_init,
84
NULL, /* class_finalize */
85
NULL, /* class_data */
86
sizeof (GimpChannelTreeView),
88
(GInstanceInitFunc) gimp_channel_tree_view_init,
91
static const GInterfaceInfo view_iface_info =
93
(GInterfaceInitFunc) gimp_channel_tree_view_view_iface_init,
94
NULL, /* iface_finalize */
97
static const GInterfaceInfo docked_iface_info =
99
(GInterfaceInitFunc) gimp_channel_tree_view_docked_iface_init,
100
NULL, /* iface_finalize */
101
NULL /* iface_data */
104
view_type = g_type_register_static (GIMP_TYPE_DRAWABLE_TREE_VIEW,
105
"GimpChannelTreeView",
108
g_type_add_interface_static (view_type, GIMP_TYPE_CONTAINER_VIEW,
110
g_type_add_interface_static (view_type, GIMP_TYPE_DOCKED,
118
gimp_channel_tree_view_class_init (GimpChannelTreeViewClass *klass)
120
GObjectClass *object_class = G_OBJECT_CLASS (klass);
121
GimpItemTreeViewClass *item_view_class = GIMP_ITEM_TREE_VIEW_CLASS (klass);
123
parent_class = g_type_class_peek_parent (klass);
125
object_class->constructor = gimp_channel_tree_view_constructor;
127
item_view_class->set_image = gimp_channel_tree_view_set_image;
129
item_view_class->item_type = GIMP_TYPE_CHANNEL;
130
item_view_class->signal_name = "active-channel-changed";
132
item_view_class->get_container = gimp_image_get_channels;
133
item_view_class->get_active_item = (GimpGetItemFunc) gimp_image_get_active_channel;
134
item_view_class->set_active_item = (GimpSetItemFunc) gimp_image_set_active_channel;
135
item_view_class->reorder_item = (GimpReorderItemFunc) gimp_image_position_channel;
136
item_view_class->add_item = (GimpAddItemFunc) gimp_image_add_channel;
137
item_view_class->remove_item = (GimpRemoveItemFunc) gimp_image_remove_channel;
138
item_view_class->new_item = gimp_channel_tree_view_item_new;
140
item_view_class->action_group = "channels";
141
item_view_class->activate_action = "channels-edit-attributes";
142
item_view_class->edit_action = "channels-edit-attributes";
143
item_view_class->new_action = "channels-new";
144
item_view_class->new_default_action = "channels-new-last-values";
145
item_view_class->raise_action = "channels-raise";
146
item_view_class->raise_top_action = "channels-raise-to-top";
147
item_view_class->lower_action = "channels-lower";
148
item_view_class->lower_bottom_action = "channels-lower-to-bottom";
149
item_view_class->duplicate_action = "channels-duplicate";
150
item_view_class->delete_action = "channels-delete";
151
item_view_class->reorder_desc = _("Reorder Channel");
155
gimp_channel_tree_view_init (GimpChannelTreeView *view)
160
gimp_channel_tree_view_view_iface_init (GimpContainerViewInterface *view_iface)
162
parent_view_iface = g_type_interface_peek_parent (view_iface);
164
view_iface->set_preview_size = gimp_channel_tree_view_set_preview_size;
168
gimp_channel_tree_view_docked_iface_init (GimpDockedInterface *docked_iface)
170
parent_docked_iface = g_type_interface_peek_parent (docked_iface);
172
docked_iface->set_context = gimp_channel_tree_view_set_context;
176
gimp_channel_tree_view_constructor (GType type,
178
GObjectConstructParam *params)
182
GimpChannelTreeView *view;
184
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
186
editor = GIMP_EDITOR (object);
187
view = GIMP_CHANNEL_TREE_VIEW (object);
189
view->toselection_button =
190
gimp_editor_add_action_button (GIMP_EDITOR (view), "channels",
191
"channels-selection-replace",
192
"channels-selection-add",
194
"channels-selection-subtract",
196
"channels-selection-intersect",
197
GDK_SHIFT_MASK | GDK_CONTROL_MASK,
199
gimp_container_view_enable_dnd (GIMP_CONTAINER_VIEW (view),
200
GTK_BUTTON (view->toselection_button),
202
gtk_box_reorder_child (GTK_BOX (GIMP_EDITOR (view)->button_box),
203
view->toselection_button, 5);
209
/* GimpItemTreeView methods */
212
gimp_channel_tree_view_set_image (GimpItemTreeView *item_view,
215
GimpChannelTreeView *channel_view = GIMP_CHANNEL_TREE_VIEW (item_view);
217
if (! channel_view->component_editor)
219
GimpContainerView *view = GIMP_CONTAINER_VIEW (item_view);
222
preview_size = gimp_container_view_get_preview_size (view, NULL);
224
channel_view->component_editor =
225
gimp_component_editor_new (preview_size,
226
GIMP_EDITOR (item_view)->menu_factory);
227
gimp_docked_set_context (GIMP_DOCKED (channel_view->component_editor),
229
gtk_box_pack_start (GTK_BOX (item_view), channel_view->component_editor,
231
gtk_box_reorder_child (GTK_BOX (item_view),
232
channel_view->component_editor, 0);
236
gtk_widget_hide (channel_view->component_editor);
238
gimp_image_editor_set_image (GIMP_IMAGE_EDITOR (channel_view->component_editor),
241
GIMP_ITEM_TREE_VIEW_CLASS (parent_class)->set_image (item_view, gimage);
243
if (item_view->gimage)
244
gtk_widget_show (channel_view->component_editor);
248
gimp_channel_tree_view_item_new (GimpImage *image)
250
GimpChannel *new_channel;
253
gimp_rgba_set (&color, 0.0, 0.0, 0.0, 0.5);
255
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_EDIT_PASTE,
258
new_channel = gimp_channel_new (image,
259
gimp_image_get_width (image),
260
gimp_image_get_height (image),
261
_("Empty Channel"), &color);
263
gimp_image_add_channel (image, new_channel, -1);
265
gimp_image_undo_group_end (image);
267
return GIMP_ITEM (new_channel);
271
/* GimpContainerView methods */
274
gimp_channel_tree_view_set_preview_size (GimpContainerView *view)
276
GimpChannelTreeView *channel_view = GIMP_CHANNEL_TREE_VIEW (view);
279
parent_view_iface->set_preview_size (view);
281
preview_size = gimp_container_view_get_preview_size (view, NULL);
283
if (channel_view->component_editor)
284
gimp_component_editor_set_preview_size (GIMP_COMPONENT_EDITOR (channel_view->component_editor),
289
/* GimpDocked methods */
292
gimp_channel_tree_view_set_context (GimpDocked *docked,
293
GimpContext *context)
295
GimpChannelTreeView *channel_view = GIMP_CHANNEL_TREE_VIEW (docked);
297
parent_docked_iface->set_context (docked, context);
299
if (channel_view->component_editor)
300
gimp_docked_set_context (GIMP_DOCKED (channel_view->component_editor),