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

« back to all changes in this revision

Viewing changes to app/widgets/gimpcontainereditor.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
 * gimpcontainereditor.c
 
5
 * Copyright (C) 2001 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 "libgimpwidgets/gimpwidgets.h"
 
27
 
 
28
#include "widgets-types.h"
 
29
 
 
30
#include "core/gimpcontext.h"
 
31
#include "core/gimplist.h"
 
32
#include "core/gimpviewable.h"
 
33
 
 
34
#include "gimpcontainereditor.h"
 
35
#include "gimpcontainergridview.h"
 
36
#include "gimpcontainertreeview.h"
 
37
#include "gimpcontainerview.h"
 
38
#include "gimpdocked.h"
 
39
#include "gimpmenufactory.h"
 
40
#include "gimpviewrenderer.h"
 
41
#include "gimpuimanager.h"
 
42
 
 
43
 
 
44
static void   gimp_container_editor_class_init        (GimpContainerEditorClass *klass);
 
45
static void   gimp_container_editor_init              (GimpContainerEditor      *view);
 
46
static void   gimp_container_editor_docked_iface_init (GimpDockedInterface      *docked_iface);
 
47
 
 
48
static gboolean gimp_container_editor_select_item    (GtkWidget           *widget,
 
49
                                                      GimpViewable        *viewable,
 
50
                                                      gpointer             insert_data,
 
51
                                                      GimpContainerEditor *editor);
 
52
static void   gimp_container_editor_activate_item    (GtkWidget           *widget,
 
53
                                                      GimpViewable        *viewable,
 
54
                                                      gpointer             insert_data,
 
55
                                                      GimpContainerEditor *editor);
 
56
static void   gimp_container_editor_context_item     (GtkWidget           *widget,
 
57
                                                      GimpViewable        *viewable,
 
58
                                                      gpointer             insert_data,
 
59
                                                      GimpContainerEditor *editor);
 
60
static void   gimp_container_editor_real_context_item(GimpContainerEditor *editor,
 
61
                                                      GimpViewable        *viewable);
 
62
 
 
63
static GtkWidget * gimp_container_editor_get_preview (GimpDocked       *docked,
 
64
                                                      GimpContext      *context,
 
65
                                                      GtkIconSize       size);
 
66
static void        gimp_container_editor_set_context (GimpDocked       *docked,
 
67
                                                      GimpContext      *context);
 
68
static GimpUIManager * gimp_container_editor_get_menu(GimpDocked       *docked,
 
69
                                                      const gchar     **ui_path,
 
70
                                                      gpointer         *popup_data);
 
71
 
 
72
 
 
73
static GtkVBoxClass *parent_class = NULL;
 
74
 
 
75
 
 
76
GType
 
77
gimp_container_editor_get_type (void)
 
78
{
 
79
  static GType type = 0;
 
80
 
 
81
  if (! type)
 
82
    {
 
83
      static const GTypeInfo view_info =
 
84
      {
 
85
        sizeof (GimpContainerEditorClass),
 
86
        NULL,           /* base_init */
 
87
        NULL,           /* base_finalize */
 
88
        (GClassInitFunc) gimp_container_editor_class_init,
 
89
        NULL,           /* class_finalize */
 
90
        NULL,           /* class_data */
 
91
        sizeof (GimpContainerEditor),
 
92
        0,              /* n_preallocs */
 
93
        (GInstanceInitFunc) gimp_container_editor_init,
 
94
      };
 
95
 
 
96
      static const GInterfaceInfo docked_iface_info =
 
97
      {
 
98
        (GInterfaceInitFunc) gimp_container_editor_docked_iface_init,
 
99
        NULL,           /* iface_finalize */
 
100
        NULL            /* iface_data     */
 
101
      };
 
102
 
 
103
      type = g_type_register_static (GTK_TYPE_VBOX,
 
104
                                     "GimpContainerEditor",
 
105
                                     &view_info, 0);
 
106
 
 
107
      g_type_add_interface_static (type, GIMP_TYPE_DOCKED,
 
108
                                   &docked_iface_info);
 
109
    }
 
110
 
 
111
  return type;
 
112
}
 
113
 
 
114
static void
 
115
gimp_container_editor_class_init (GimpContainerEditorClass *klass)
 
116
{
 
117
  parent_class = g_type_class_peek_parent (klass);
 
118
 
 
119
  klass->select_item     = NULL;
 
120
  klass->activate_item   = NULL;
 
121
  klass->context_item    = gimp_container_editor_real_context_item;
 
122
}
 
123
 
 
124
static void
 
125
gimp_container_editor_init (GimpContainerEditor *view)
 
126
{
 
127
  view->view = NULL;
 
128
}
 
129
 
 
130
static void
 
131
gimp_container_editor_docked_iface_init (GimpDockedInterface *docked_iface)
 
132
{
 
133
  docked_iface->get_preview = gimp_container_editor_get_preview;
 
134
  docked_iface->set_context = gimp_container_editor_set_context;
 
135
  docked_iface->get_menu    = gimp_container_editor_get_menu;
 
136
}
 
137
 
 
138
gboolean
 
139
gimp_container_editor_construct (GimpContainerEditor *editor,
 
140
                                 GimpViewType         view_type,
 
141
                                 GimpContainer       *container,
 
142
                                 GimpContext         *context,
 
143
                                 gint                 preview_size,
 
144
                                 gint                 preview_border_width,
 
145
                                 GimpMenuFactory     *menu_factory,
 
146
                                 const gchar         *menu_identifier,
 
147
                                 const gchar         *ui_identifier)
 
148
{
 
149
  g_return_val_if_fail (GIMP_IS_CONTAINER_EDITOR (editor), FALSE);
 
150
  g_return_val_if_fail (GIMP_IS_CONTAINER (container), FALSE);
 
151
  g_return_val_if_fail (GIMP_IS_CONTEXT (context), FALSE);
 
152
  g_return_val_if_fail (preview_size > 0 &&
 
153
                        preview_size <= GIMP_VIEWABLE_MAX_PREVIEW_SIZE, FALSE);
 
154
  g_return_val_if_fail (preview_border_width >= 0 &&
 
155
                        preview_border_width <= GIMP_VIEW_MAX_BORDER_WIDTH,
 
156
                        FALSE);
 
157
  g_return_val_if_fail (menu_factory == NULL ||
 
158
                        GIMP_IS_MENU_FACTORY (menu_factory), FALSE);
 
159
 
 
160
  switch (view_type)
 
161
    {
 
162
    case GIMP_VIEW_TYPE_GRID:
 
163
      editor->view =
 
164
        GIMP_CONTAINER_VIEW (gimp_container_grid_view_new (container,
 
165
                                                           context,
 
166
                                                           preview_size,
 
167
                                                           preview_border_width));
 
168
      break;
 
169
 
 
170
    case GIMP_VIEW_TYPE_LIST:
 
171
      editor->view =
 
172
        GIMP_CONTAINER_VIEW (gimp_container_tree_view_new (container,
 
173
                                                           context,
 
174
                                                           preview_size,
 
175
                                                           preview_border_width));
 
176
      break;
 
177
 
 
178
    default:
 
179
      g_warning ("%s: unknown GimpViewType passed", G_STRFUNC);
 
180
      return FALSE;
 
181
    }
 
182
 
 
183
  if (GIMP_IS_LIST (container))
 
184
    gimp_container_view_set_reorderable (GIMP_CONTAINER_VIEW (editor->view),
 
185
                                         ! GIMP_LIST (container)->sort_func);
 
186
 
 
187
  if (menu_factory && menu_identifier && ui_identifier)
 
188
    gimp_editor_create_menu (GIMP_EDITOR (editor->view),
 
189
                             menu_factory, menu_identifier, ui_identifier,
 
190
                             editor);
 
191
 
 
192
  gtk_container_add (GTK_CONTAINER (editor), GTK_WIDGET (editor->view));
 
193
  gtk_widget_show (GTK_WIDGET (editor->view));
 
194
 
 
195
  g_signal_connect_object (editor->view, "select_item",
 
196
                           G_CALLBACK (gimp_container_editor_select_item),
 
197
                           editor, 0);
 
198
  g_signal_connect_object (editor->view, "activate_item",
 
199
                           G_CALLBACK (gimp_container_editor_activate_item),
 
200
                           editor, 0);
 
201
  g_signal_connect_object (editor->view, "context_item",
 
202
                           G_CALLBACK (gimp_container_editor_context_item),
 
203
                           editor, 0);
 
204
 
 
205
  {
 
206
    GimpObject *object = gimp_context_get_by_type (context,
 
207
                                                   container->children_type);
 
208
 
 
209
    gimp_container_editor_select_item (GTK_WIDGET (editor->view),
 
210
                                       (GimpViewable *) object, NULL,
 
211
                                       editor);
 
212
  }
 
213
 
 
214
  return TRUE;
 
215
}
 
216
 
 
217
 
 
218
/*  private functions  */
 
219
 
 
220
static gboolean
 
221
gimp_container_editor_select_item (GtkWidget           *widget,
 
222
                                   GimpViewable        *viewable,
 
223
                                   gpointer             insert_data,
 
224
                                   GimpContainerEditor *editor)
 
225
{
 
226
  GimpContainerEditorClass *klass = GIMP_CONTAINER_EDITOR_GET_CLASS (editor);
 
227
 
 
228
  if (klass->select_item)
 
229
    klass->select_item (editor, viewable);
 
230
 
 
231
  if (GIMP_EDITOR (editor->view)->ui_manager)
 
232
    gimp_ui_manager_update (GIMP_EDITOR (editor->view)->ui_manager,
 
233
                            GIMP_EDITOR (editor->view)->popup_data);
 
234
 
 
235
  return TRUE;
 
236
}
 
237
 
 
238
static void
 
239
gimp_container_editor_activate_item (GtkWidget           *widget,
 
240
                                     GimpViewable        *viewable,
 
241
                                     gpointer             insert_data,
 
242
                                     GimpContainerEditor *editor)
 
243
{
 
244
  GimpContainerEditorClass *klass = GIMP_CONTAINER_EDITOR_GET_CLASS (editor);
 
245
 
 
246
  if (klass->activate_item)
 
247
    klass->activate_item (editor, viewable);
 
248
}
 
249
 
 
250
static void
 
251
gimp_container_editor_context_item (GtkWidget           *widget,
 
252
                                    GimpViewable        *viewable,
 
253
                                    gpointer             insert_data,
 
254
                                    GimpContainerEditor *editor)
 
255
{
 
256
  GimpContainerEditorClass *klass = GIMP_CONTAINER_EDITOR_GET_CLASS (editor);
 
257
 
 
258
  if (klass->context_item)
 
259
    klass->context_item (editor, viewable);
 
260
}
 
261
 
 
262
static void
 
263
gimp_container_editor_real_context_item (GimpContainerEditor *editor,
 
264
                                         GimpViewable        *viewable)
 
265
{
 
266
  GimpContainer *container = gimp_container_view_get_container (editor->view);
 
267
 
 
268
  if (viewable && gimp_container_have (container, GIMP_OBJECT (viewable)))
 
269
    {
 
270
      gimp_editor_popup_menu (GIMP_EDITOR (editor->view), NULL, NULL);
 
271
    }
 
272
}
 
273
 
 
274
static GtkWidget *
 
275
gimp_container_editor_get_preview (GimpDocked   *docked,
 
276
                                   GimpContext  *context,
 
277
                                   GtkIconSize   size)
 
278
{
 
279
  GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (docked);
 
280
 
 
281
  return gimp_docked_get_preview (GIMP_DOCKED (editor->view),
 
282
                                  context, size);
 
283
}
 
284
 
 
285
static void
 
286
gimp_container_editor_set_context (GimpDocked  *docked,
 
287
                                   GimpContext *context)
 
288
{
 
289
  GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (docked);
 
290
 
 
291
  gimp_docked_set_context (GIMP_DOCKED (editor->view), context);
 
292
}
 
293
 
 
294
static GimpUIManager *
 
295
gimp_container_editor_get_menu (GimpDocked   *docked,
 
296
                                const gchar **ui_path,
 
297
                                gpointer     *popup_data)
 
298
{
 
299
  GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (docked);
 
300
 
 
301
  return gimp_docked_get_menu (GIMP_DOCKED (editor->view), ui_path, popup_data);
 
302
}