1
/* GIMP - The GNU Image Manipulation Program
2
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
5
* Copyright (C) 2008 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 3 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, see <http://www.gnu.org/licenses/>.
27
#include "core-types.h"
30
#include "gimpitemstack.h"
33
/* local function prototypes */
35
static void gimp_item_stack_constructed (GObject *object);
37
static void gimp_item_stack_add (GimpContainer *container,
39
static void gimp_item_stack_remove (GimpContainer *container,
43
G_DEFINE_TYPE (GimpItemStack, gimp_item_stack, GIMP_TYPE_LIST)
45
#define parent_class gimp_item_stack_parent_class
49
gimp_item_stack_class_init (GimpItemStackClass *klass)
51
GObjectClass *object_class = G_OBJECT_CLASS (klass);
52
GimpContainerClass *container_class = GIMP_CONTAINER_CLASS (klass);
54
object_class->constructed = gimp_item_stack_constructed;
56
container_class->add = gimp_item_stack_add;
57
container_class->remove = gimp_item_stack_remove;
61
gimp_item_stack_init (GimpItemStack *stack)
66
gimp_item_stack_constructed (GObject *object)
68
GimpContainer *container = GIMP_CONTAINER (object);
70
if (G_OBJECT_CLASS (parent_class)->constructed)
71
G_OBJECT_CLASS (parent_class)->constructed (object);
73
g_assert (g_type_is_a (gimp_container_get_children_type (container),
78
gimp_item_stack_add (GimpContainer *container,
81
g_object_ref_sink (object);
83
GIMP_CONTAINER_CLASS (parent_class)->add (container, object);
85
g_object_unref (object);
89
gimp_item_stack_remove (GimpContainer *container,
92
GIMP_CONTAINER_CLASS (parent_class)->remove (container, object);
96
/* public functions */
99
gimp_item_stack_new (GType item_type)
101
g_return_val_if_fail (g_type_is_a (item_type, GIMP_TYPE_ITEM), NULL);
103
return g_object_new (GIMP_TYPE_ITEM_STACK,
104
"name", g_type_name (item_type),
105
"children-type", item_type,
106
"policy", GIMP_CONTAINER_POLICY_STRONG,
111
gimp_item_stack_get_n_items (GimpItemStack *stack)
116
g_return_val_if_fail (GIMP_IS_ITEM_STACK (stack), 0);
118
for (list = GIMP_LIST (stack)->list; list; list = g_list_next (list))
120
GimpItem *item = list->data;
121
GimpContainer *children;
125
children = gimp_viewable_get_children (GIMP_VIEWABLE (item));
128
n_items += gimp_item_stack_get_n_items (GIMP_ITEM_STACK (children));
135
gimp_item_stack_is_flat (GimpItemStack *stack)
139
g_return_val_if_fail (GIMP_IS_ITEM_STACK (stack), TRUE);
141
for (list = GIMP_LIST (stack)->list; list; list = g_list_next (list))
143
GimpViewable *viewable = list->data;
145
if (gimp_viewable_get_children (viewable))
153
gimp_item_stack_get_item_iter (GimpItemStack *stack)
155
g_return_val_if_fail (GIMP_IS_ITEM_STACK (stack), NULL);
157
return GIMP_LIST (stack)->list;
161
gimp_item_stack_get_item_list (GimpItemStack *stack)
164
GList *result = NULL;
166
g_return_val_if_fail (GIMP_IS_ITEM_STACK (stack), NULL);
168
for (list = GIMP_LIST (stack)->list;
170
list = g_list_next (list))
172
GimpViewable *viewable = list->data;
173
GimpContainer *children;
175
result = g_list_prepend (result, viewable);
177
children = gimp_viewable_get_children (viewable);
183
child_list = gimp_item_stack_get_item_list (GIMP_ITEM_STACK (children));
187
result = g_list_prepend (result, child_list->data);
189
child_list = g_list_remove (child_list, child_list->data);
194
return g_list_reverse (result);
198
gimp_item_stack_get_item_by_tattoo (GimpItemStack *stack,
203
g_return_val_if_fail (GIMP_IS_ITEM_STACK (stack), NULL);
205
for (list = GIMP_LIST (stack)->list; list; list = g_list_next (list))
207
GimpItem *item = list->data;
208
GimpContainer *children;
210
if (gimp_item_get_tattoo (item) == tattoo)
213
children = gimp_viewable_get_children (GIMP_VIEWABLE (item));
217
item = gimp_item_stack_get_item_by_tattoo (GIMP_ITEM_STACK (children),
229
gimp_item_stack_get_item_by_path (GimpItemStack *stack,
232
GimpContainer *container;
233
GimpItem *item = NULL;
235
g_return_val_if_fail (GIMP_IS_ITEM_STACK (stack), NULL);
236
g_return_val_if_fail (path != NULL, NULL);
238
container = GIMP_CONTAINER (stack);
242
guint32 i = GPOINTER_TO_UINT (path->data);
244
item = GIMP_ITEM (gimp_container_get_child_by_index (container, i));
246
g_return_val_if_fail (GIMP_IS_ITEM (item), item);
250
container = gimp_viewable_get_children (GIMP_VIEWABLE (item));
252
g_return_val_if_fail (GIMP_IS_ITEM_STACK (container), item);
262
gimp_item_stack_get_parent_by_path (GimpItemStack *stack,
266
GimpItem *parent = NULL;
269
g_return_val_if_fail (GIMP_IS_ITEM_STACK (stack), NULL);
270
g_return_val_if_fail (path != NULL, NULL);
272
i = GPOINTER_TO_UINT (path->data);
280
GimpContainer *children;
282
child = gimp_container_get_child_by_index (GIMP_CONTAINER (stack), i);
284
g_return_val_if_fail (GIMP_IS_ITEM (child), parent);
286
children = gimp_viewable_get_children (GIMP_VIEWABLE (child));
288
g_return_val_if_fail (GIMP_IS_ITEM_STACK (children), parent);
290
parent = GIMP_ITEM (child);
291
stack = GIMP_ITEM_STACK (children);
295
i = GPOINTER_TO_UINT (path->data);
305
gimp_item_stack_invalidate_preview (GimpViewable *viewable)
307
GimpContainer *children = gimp_viewable_get_children (viewable);
310
gimp_item_stack_invalidate_previews (GIMP_ITEM_STACK (children));
312
gimp_viewable_invalidate_preview (viewable);
316
gimp_item_stack_invalidate_previews (GimpItemStack *stack)
318
g_return_if_fail (GIMP_IS_ITEM_STACK (stack));
320
gimp_container_foreach (GIMP_CONTAINER (stack),
321
(GFunc) gimp_item_stack_invalidate_preview,