1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* gimpcontainereditor.c
5
* Copyright (C) 2001 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 "libgimpwidgets/gimpwidgets.h"
28
#include "widgets-types.h"
30
#include "core/gimpcontext.h"
31
#include "core/gimplist.h"
32
#include "core/gimpviewable.h"
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"
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);
48
static gboolean gimp_container_editor_select_item (GtkWidget *widget,
49
GimpViewable *viewable,
51
GimpContainerEditor *editor);
52
static void gimp_container_editor_activate_item (GtkWidget *widget,
53
GimpViewable *viewable,
55
GimpContainerEditor *editor);
56
static void gimp_container_editor_context_item (GtkWidget *widget,
57
GimpViewable *viewable,
59
GimpContainerEditor *editor);
60
static void gimp_container_editor_real_context_item(GimpContainerEditor *editor,
61
GimpViewable *viewable);
63
static GtkWidget * gimp_container_editor_get_preview (GimpDocked *docked,
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);
73
static GtkVBoxClass *parent_class = NULL;
77
gimp_container_editor_get_type (void)
79
static GType type = 0;
83
static const GTypeInfo view_info =
85
sizeof (GimpContainerEditorClass),
87
NULL, /* base_finalize */
88
(GClassInitFunc) gimp_container_editor_class_init,
89
NULL, /* class_finalize */
90
NULL, /* class_data */
91
sizeof (GimpContainerEditor),
93
(GInstanceInitFunc) gimp_container_editor_init,
96
static const GInterfaceInfo docked_iface_info =
98
(GInterfaceInitFunc) gimp_container_editor_docked_iface_init,
99
NULL, /* iface_finalize */
100
NULL /* iface_data */
103
type = g_type_register_static (GTK_TYPE_VBOX,
104
"GimpContainerEditor",
107
g_type_add_interface_static (type, GIMP_TYPE_DOCKED,
115
gimp_container_editor_class_init (GimpContainerEditorClass *klass)
117
parent_class = g_type_class_peek_parent (klass);
119
klass->select_item = NULL;
120
klass->activate_item = NULL;
121
klass->context_item = gimp_container_editor_real_context_item;
125
gimp_container_editor_init (GimpContainerEditor *view)
131
gimp_container_editor_docked_iface_init (GimpDockedInterface *docked_iface)
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;
139
gimp_container_editor_construct (GimpContainerEditor *editor,
140
GimpViewType view_type,
141
GimpContainer *container,
142
GimpContext *context,
144
gint preview_border_width,
145
GimpMenuFactory *menu_factory,
146
const gchar *menu_identifier,
147
const gchar *ui_identifier)
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,
157
g_return_val_if_fail (menu_factory == NULL ||
158
GIMP_IS_MENU_FACTORY (menu_factory), FALSE);
162
case GIMP_VIEW_TYPE_GRID:
164
GIMP_CONTAINER_VIEW (gimp_container_grid_view_new (container,
167
preview_border_width));
170
case GIMP_VIEW_TYPE_LIST:
172
GIMP_CONTAINER_VIEW (gimp_container_tree_view_new (container,
175
preview_border_width));
179
g_warning ("%s: unknown GimpViewType passed", G_STRFUNC);
183
if (GIMP_IS_LIST (container))
184
gimp_container_view_set_reorderable (GIMP_CONTAINER_VIEW (editor->view),
185
! GIMP_LIST (container)->sort_func);
187
if (menu_factory && menu_identifier && ui_identifier)
188
gimp_editor_create_menu (GIMP_EDITOR (editor->view),
189
menu_factory, menu_identifier, ui_identifier,
192
gtk_container_add (GTK_CONTAINER (editor), GTK_WIDGET (editor->view));
193
gtk_widget_show (GTK_WIDGET (editor->view));
195
g_signal_connect_object (editor->view, "select_item",
196
G_CALLBACK (gimp_container_editor_select_item),
198
g_signal_connect_object (editor->view, "activate_item",
199
G_CALLBACK (gimp_container_editor_activate_item),
201
g_signal_connect_object (editor->view, "context_item",
202
G_CALLBACK (gimp_container_editor_context_item),
206
GimpObject *object = gimp_context_get_by_type (context,
207
container->children_type);
209
gimp_container_editor_select_item (GTK_WIDGET (editor->view),
210
(GimpViewable *) object, NULL,
218
/* private functions */
221
gimp_container_editor_select_item (GtkWidget *widget,
222
GimpViewable *viewable,
223
gpointer insert_data,
224
GimpContainerEditor *editor)
226
GimpContainerEditorClass *klass = GIMP_CONTAINER_EDITOR_GET_CLASS (editor);
228
if (klass->select_item)
229
klass->select_item (editor, viewable);
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);
239
gimp_container_editor_activate_item (GtkWidget *widget,
240
GimpViewable *viewable,
241
gpointer insert_data,
242
GimpContainerEditor *editor)
244
GimpContainerEditorClass *klass = GIMP_CONTAINER_EDITOR_GET_CLASS (editor);
246
if (klass->activate_item)
247
klass->activate_item (editor, viewable);
251
gimp_container_editor_context_item (GtkWidget *widget,
252
GimpViewable *viewable,
253
gpointer insert_data,
254
GimpContainerEditor *editor)
256
GimpContainerEditorClass *klass = GIMP_CONTAINER_EDITOR_GET_CLASS (editor);
258
if (klass->context_item)
259
klass->context_item (editor, viewable);
263
gimp_container_editor_real_context_item (GimpContainerEditor *editor,
264
GimpViewable *viewable)
266
GimpContainer *container = gimp_container_view_get_container (editor->view);
268
if (viewable && gimp_container_have (container, GIMP_OBJECT (viewable)))
270
gimp_editor_popup_menu (GIMP_EDITOR (editor->view), NULL, NULL);
275
gimp_container_editor_get_preview (GimpDocked *docked,
276
GimpContext *context,
279
GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (docked);
281
return gimp_docked_get_preview (GIMP_DOCKED (editor->view),
286
gimp_container_editor_set_context (GimpDocked *docked,
287
GimpContext *context)
289
GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (docked);
291
gimp_docked_set_context (GIMP_DOCKED (editor->view), context);
294
static GimpUIManager *
295
gimp_container_editor_get_menu (GimpDocked *docked,
296
const gchar **ui_path,
297
gpointer *popup_data)
299
GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (docked);
301
return gimp_docked_get_menu (GIMP_DOCKED (editor->view), ui_path, popup_data);