~ubuntu-branches/ubuntu/hoary/gimp/hoary

« back to all changes in this revision

Viewing changes to app/widgets/gimpchanneltreeview.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2005-04-04 14:51:23 UTC
  • Revision ID: james.westby@ubuntu.com-20050404145123-9py049eeelfymur8
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* The GIMP -- an image manipulation program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
4
 * gimpchanneltreeview.c
 
5
 * Copyright (C) 2001-2004 Michael Natterer <mitch@gimp.org>
 
6
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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.
 
20
 */
 
21
 
 
22
#include "config.h"
 
23
 
 
24
#include <gtk/gtk.h>
 
25
 
 
26
#include "libgimpcolor/gimpcolor.h"
 
27
#include "libgimpwidgets/gimpwidgets.h"
 
28
 
 
29
#include "widgets-types.h"
 
30
 
 
31
#include "core/gimpchannel.h"
 
32
#include "core/gimpcontainer.h"
 
33
#include "core/gimpimage.h"
 
34
#include "core/gimpimage-undo.h"
 
35
 
 
36
#include "gimpchanneltreeview.h"
 
37
#include "gimpcomponenteditor.h"
 
38
#include "gimpcontainerview.h"
 
39
#include "gimpdnd.h"
 
40
#include "gimpdocked.h"
 
41
#include "gimphelp-ids.h"
 
42
#include "gimpwidgets-utils.h"
 
43
 
 
44
#include "gimp-intl.h"
 
45
 
 
46
 
 
47
static void   gimp_channel_tree_view_class_init (GimpChannelTreeViewClass *klass);
 
48
static void   gimp_channel_tree_view_init       (GimpChannelTreeView      *view);
 
49
 
 
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);
 
52
 
 
53
static GObject * gimp_channel_tree_view_constructor   (GType              type,
 
54
                                                       guint              n_params,
 
55
                                                       GObjectConstructParam *params);
 
56
static void   gimp_channel_tree_view_set_image        (GimpItemTreeView  *item_view,
 
57
                                                       GimpImage         *gimage);
 
58
static GimpItem * gimp_channel_tree_view_item_new     (GimpImage         *image);
 
59
 
 
60
static void   gimp_channel_tree_view_set_preview_size (GimpContainerView *view);
 
61
 
 
62
static void   gimp_channel_tree_view_set_context      (GimpDocked        *docked,
 
63
                                                       GimpContext       *context);
 
64
 
 
65
 
 
66
static GimpDrawableTreeViewClass  *parent_class        = NULL;
 
67
static GimpContainerViewInterface *parent_view_iface   = NULL;
 
68
static GimpDockedInterface        *parent_docked_iface = NULL;
 
69
 
 
70
 
 
71
GType
 
72
gimp_channel_tree_view_get_type (void)
 
73
{
 
74
  static GType view_type = 0;
 
75
 
 
76
  if (! view_type)
 
77
    {
 
78
      static const GTypeInfo view_info =
 
79
      {
 
80
        sizeof (GimpChannelTreeViewClass),
 
81
        NULL,           /* base_init */
 
82
        NULL,           /* base_finalize */
 
83
        (GClassInitFunc) gimp_channel_tree_view_class_init,
 
84
        NULL,           /* class_finalize */
 
85
        NULL,           /* class_data */
 
86
        sizeof (GimpChannelTreeView),
 
87
        0,              /* n_preallocs */
 
88
        (GInstanceInitFunc) gimp_channel_tree_view_init,
 
89
      };
 
90
 
 
91
      static const GInterfaceInfo view_iface_info =
 
92
      {
 
93
        (GInterfaceInitFunc) gimp_channel_tree_view_view_iface_init,
 
94
        NULL,           /* iface_finalize */
 
95
        NULL            /* iface_data     */
 
96
      };
 
97
      static const GInterfaceInfo docked_iface_info =
 
98
      {
 
99
        (GInterfaceInitFunc) gimp_channel_tree_view_docked_iface_init,
 
100
        NULL,           /* iface_finalize */
 
101
        NULL            /* iface_data     */
 
102
      };
 
103
 
 
104
      view_type = g_type_register_static (GIMP_TYPE_DRAWABLE_TREE_VIEW,
 
105
                                          "GimpChannelTreeView",
 
106
                                          &view_info, 0);
 
107
 
 
108
      g_type_add_interface_static (view_type, GIMP_TYPE_CONTAINER_VIEW,
 
109
                                   &view_iface_info);
 
110
      g_type_add_interface_static (view_type, GIMP_TYPE_DOCKED,
 
111
                                   &docked_iface_info);
 
112
    }
 
113
 
 
114
  return view_type;
 
115
}
 
116
 
 
117
static void
 
118
gimp_channel_tree_view_class_init (GimpChannelTreeViewClass *klass)
 
119
{
 
120
  GObjectClass          *object_class    = G_OBJECT_CLASS (klass);
 
121
  GimpItemTreeViewClass *item_view_class = GIMP_ITEM_TREE_VIEW_CLASS (klass);
 
122
 
 
123
  parent_class = g_type_class_peek_parent (klass);
 
124
 
 
125
  object_class->constructor        = gimp_channel_tree_view_constructor;
 
126
 
 
127
  item_view_class->set_image       = gimp_channel_tree_view_set_image;
 
128
 
 
129
  item_view_class->item_type       = GIMP_TYPE_CHANNEL;
 
130
  item_view_class->signal_name     = "active-channel-changed";
 
131
 
 
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;
 
139
 
 
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");
 
152
}
 
153
 
 
154
static void
 
155
gimp_channel_tree_view_init (GimpChannelTreeView *view)
 
156
{
 
157
}
 
158
 
 
159
static void
 
160
gimp_channel_tree_view_view_iface_init (GimpContainerViewInterface *view_iface)
 
161
{
 
162
  parent_view_iface = g_type_interface_peek_parent (view_iface);
 
163
 
 
164
  view_iface->set_preview_size = gimp_channel_tree_view_set_preview_size;
 
165
}
 
166
 
 
167
static void
 
168
gimp_channel_tree_view_docked_iface_init (GimpDockedInterface *docked_iface)
 
169
{
 
170
  parent_docked_iface = g_type_interface_peek_parent (docked_iface);
 
171
 
 
172
  docked_iface->set_context = gimp_channel_tree_view_set_context;
 
173
}
 
174
 
 
175
static GObject *
 
176
gimp_channel_tree_view_constructor (GType                  type,
 
177
                                    guint                  n_params,
 
178
                                    GObjectConstructParam *params)
 
179
{
 
180
  GObject             *object;
 
181
  GimpEditor          *editor;
 
182
  GimpChannelTreeView *view;
 
183
 
 
184
  object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
 
185
 
 
186
  editor = GIMP_EDITOR (object);
 
187
  view   = GIMP_CHANNEL_TREE_VIEW (object);
 
188
 
 
189
  view->toselection_button =
 
190
    gimp_editor_add_action_button (GIMP_EDITOR (view), "channels",
 
191
                                   "channels-selection-replace",
 
192
                                   "channels-selection-add",
 
193
                                   GDK_SHIFT_MASK,
 
194
                                   "channels-selection-subtract",
 
195
                                   GDK_CONTROL_MASK,
 
196
                                   "channels-selection-intersect",
 
197
                                   GDK_SHIFT_MASK | GDK_CONTROL_MASK,
 
198
                                   NULL);
 
199
  gimp_container_view_enable_dnd (GIMP_CONTAINER_VIEW (view),
 
200
                                  GTK_BUTTON (view->toselection_button),
 
201
                                  GIMP_TYPE_CHANNEL);
 
202
  gtk_box_reorder_child (GTK_BOX (GIMP_EDITOR (view)->button_box),
 
203
                         view->toselection_button, 5);
 
204
 
 
205
  return object;
 
206
}
 
207
 
 
208
 
 
209
/*  GimpItemTreeView methods  */
 
210
 
 
211
static void
 
212
gimp_channel_tree_view_set_image (GimpItemTreeView *item_view,
 
213
                                  GimpImage        *gimage)
 
214
{
 
215
  GimpChannelTreeView *channel_view = GIMP_CHANNEL_TREE_VIEW (item_view);
 
216
 
 
217
  if (! channel_view->component_editor)
 
218
    {
 
219
      GimpContainerView *view = GIMP_CONTAINER_VIEW (item_view);
 
220
      gint               preview_size;
 
221
 
 
222
      preview_size = gimp_container_view_get_preview_size (view, NULL);
 
223
 
 
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),
 
228
                               item_view->context);
 
229
      gtk_box_pack_start (GTK_BOX (item_view), channel_view->component_editor,
 
230
                          FALSE, FALSE, 0);
 
231
      gtk_box_reorder_child (GTK_BOX (item_view),
 
232
                             channel_view->component_editor, 0);
 
233
    }
 
234
 
 
235
  if (! gimage)
 
236
    gtk_widget_hide (channel_view->component_editor);
 
237
 
 
238
  gimp_image_editor_set_image (GIMP_IMAGE_EDITOR (channel_view->component_editor),
 
239
                               gimage);
 
240
 
 
241
  GIMP_ITEM_TREE_VIEW_CLASS (parent_class)->set_image (item_view, gimage);
 
242
 
 
243
  if (item_view->gimage)
 
244
    gtk_widget_show (channel_view->component_editor);
 
245
}
 
246
 
 
247
static GimpItem *
 
248
gimp_channel_tree_view_item_new (GimpImage *image)
 
249
{
 
250
  GimpChannel *new_channel;
 
251
  GimpRGB      color;
 
252
 
 
253
  gimp_rgba_set (&color, 0.0, 0.0, 0.0, 0.5);
 
254
 
 
255
  gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_EDIT_PASTE,
 
256
                               _("New Channel"));
 
257
 
 
258
  new_channel = gimp_channel_new (image,
 
259
                                  gimp_image_get_width (image),
 
260
                                  gimp_image_get_height (image),
 
261
                                  _("Empty Channel"), &color);
 
262
 
 
263
  gimp_image_add_channel (image, new_channel, -1);
 
264
 
 
265
  gimp_image_undo_group_end (image);
 
266
 
 
267
  return GIMP_ITEM (new_channel);
 
268
}
 
269
 
 
270
 
 
271
/*  GimpContainerView methods  */
 
272
 
 
273
static void
 
274
gimp_channel_tree_view_set_preview_size (GimpContainerView *view)
 
275
{
 
276
  GimpChannelTreeView *channel_view = GIMP_CHANNEL_TREE_VIEW (view);
 
277
  gint                 preview_size;
 
278
 
 
279
  parent_view_iface->set_preview_size (view);
 
280
 
 
281
  preview_size = gimp_container_view_get_preview_size (view, NULL);
 
282
 
 
283
  if (channel_view->component_editor)
 
284
    gimp_component_editor_set_preview_size (GIMP_COMPONENT_EDITOR (channel_view->component_editor),
 
285
                                            preview_size);
 
286
}
 
287
 
 
288
 
 
289
/*  GimpDocked methods  */
 
290
 
 
291
static void
 
292
gimp_channel_tree_view_set_context (GimpDocked  *docked,
 
293
                                    GimpContext *context)
 
294
{
 
295
  GimpChannelTreeView *channel_view = GIMP_CHANNEL_TREE_VIEW (docked);
 
296
 
 
297
  parent_docked_iface->set_context (docked, context);
 
298
 
 
299
  if (channel_view->component_editor)
 
300
    gimp_docked_set_context (GIMP_DOCKED (channel_view->component_editor),
 
301
                             context);
 
302
}