Code

bulk whitespace removal patch #1198588 by gigaclon
[inkscape.git] / src / sp-item-group.cpp
1 #define __SP_GROUP_C__
3 /*
4  * SVG <g> implementation
5  *
6  * Authors:
7  *   Lauris Kaplinski <lauris@kaplinski.com>
8  *   bulia byak <buliabyak@users.sf.net>
9  *
10  * Copyright (C) 1999-2005 authors
11  * Copyright (C) 2000-2001 Ximian, Inc.
12  *
13  * Released under GNU GPL, read the file 'COPYING' for more information
14  */
16 #ifdef HAVE_CONFIG_H
17 # include "config.h"
18 #endif
20 #if defined(WIN32) || defined(__APPLE__)
21 # include <glibmm/i18n.h>
22 #endif
24 #include "display/nr-arena-group.h"
25 #include "libnr/nr-matrix-ops.h"
26 #include "libnr/nr-matrix-fns.h"
27 #include "xml/repr.h"
28 #include "svg/svg.h"
29 #include "document.h"
30 #include "style.h"
31 #include "attributes.h"
33 #include "sp-root.h"
34 #include "sp-use.h"
35 #include "prefs-utils.h"
37 static void sp_group_class_init (SPGroupClass *klass);
38 static void sp_group_init (SPGroup *group);
39 static void sp_group_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
40 static void sp_group_release(SPObject *object);
41 static void sp_group_dispose (GObject *object);
43 static void sp_group_child_added (SPObject * object, Inkscape::XML::Node * child, Inkscape::XML::Node * ref);
44 static void sp_group_remove_child (SPObject * object, Inkscape::XML::Node * child);
45 static void sp_group_order_changed (SPObject * object, Inkscape::XML::Node * child, Inkscape::XML::Node * old_ref, Inkscape::XML::Node * new_ref);
46 static void sp_group_update (SPObject *object, SPCtx *ctx, guint flags);
47 static void sp_group_modified (SPObject *object, guint flags);
48 static Inkscape::XML::Node *sp_group_write (SPObject *object, Inkscape::XML::Node *repr, guint flags);
49 static void sp_group_set(SPObject *object, unsigned key, char const *value);
51 static void sp_group_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags);
52 static void sp_group_print (SPItem * item, SPPrintContext *ctx);
53 static gchar * sp_group_description (SPItem * item);
54 static NRArenaItem *sp_group_show (SPItem *item, NRArena *arena, unsigned int key, unsigned int flags);
55 static void sp_group_hide (SPItem * item, unsigned int key);
56 static void sp_group_snappoints (SPItem const *item, SnapPointsIter p);
58 static SPItemClass * parent_class;
60 GType
61 sp_group_get_type (void)
62 {
63         static GType group_type = 0;
64         if (!group_type) {
65                 GTypeInfo group_info = {
66                         sizeof (SPGroupClass),
67                         NULL,   /* base_init */
68                         NULL,   /* base_finalize */
69                         (GClassInitFunc) sp_group_class_init,
70                         NULL,   /* class_finalize */
71                         NULL,   /* class_data */
72                         sizeof (SPGroup),
73                         16,     /* n_preallocs */
74                         (GInstanceInitFunc) sp_group_init,
75                         NULL,   /* value_table */
76                 };
77                 group_type = g_type_register_static (SP_TYPE_ITEM, "SPGroup", &group_info, (GTypeFlags)0);
78         }
79         return group_type;
80 }
82 static void
83 sp_group_class_init (SPGroupClass *klass)
84 {
85         GObjectClass * object_class;
86         SPObjectClass * sp_object_class;
87         SPItemClass * item_class;
89         object_class = (GObjectClass *) klass;
90         sp_object_class = (SPObjectClass *) klass;
91         item_class = (SPItemClass *) klass;
93         parent_class = (SPItemClass *)g_type_class_ref (SP_TYPE_ITEM);
95         object_class->dispose = sp_group_dispose;
97         sp_object_class->child_added = sp_group_child_added;
98         sp_object_class->remove_child = sp_group_remove_child;
99         sp_object_class->order_changed = sp_group_order_changed;
100         sp_object_class->update = sp_group_update;
101         sp_object_class->modified = sp_group_modified;
102         sp_object_class->set = sp_group_set;
103         sp_object_class->write = sp_group_write;
104         sp_object_class->release = sp_group_release;
105         sp_object_class->build = sp_group_build;
107         item_class->bbox = sp_group_bbox;
108         item_class->print = sp_group_print;
109         item_class->description = sp_group_description;
110         item_class->show = sp_group_show;
111         item_class->hide = sp_group_hide;
112         item_class->snappoints = sp_group_snappoints;
115 static void
116 sp_group_init (SPGroup *group)
118         group->_layer_mode = SPGroup::GROUP;
119         new (&group->_display_modes) std::map<unsigned int, SPGroup::LayerMode>();
122 static void sp_group_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
124         sp_object_read_attr(object, "inkscape:groupmode");
126         if (((SPObjectClass *)parent_class)->build) {
127                 ((SPObjectClass *)parent_class)->build(object, document, repr);
128         }
131 static void sp_group_release(SPObject *object) {
132         if ( SP_GROUP(object)->_layer_mode == SPGroup::LAYER ) {
133                 sp_document_remove_resource(SP_OBJECT_DOCUMENT(object), "layer", object);
134         }
135         if (((SPObjectClass *)parent_class)->release) {
136                 ((SPObjectClass *)parent_class)->release(object);
137         }
140 static void
141 sp_group_dispose(GObject *object)
143         SP_GROUP(object)->_display_modes.~map();
146 static void
147 sp_group_child_added (SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
149         SPItem *item;
151         item = SP_ITEM (object);
153         if (((SPObjectClass *) (parent_class))->child_added)
154                 (* ((SPObjectClass *) (parent_class))->child_added) (object, child, ref);
156     SPObject *last_child = object->lastChild();
157     if (last_child && SP_OBJECT_REPR(last_child) == child) {
158         // optimization for the common special case where the child is being added at the end
159             SPObject *ochild = last_child;
160             if ( SP_IS_ITEM(ochild) ) {
161                     /* TODO: this should be moved into SPItem somehow */
162                     SPItemView *v;
163                     NRArenaItem *ac;
165                     for (v = item->display; v != NULL; v = v->next) {
166                             ac = sp_item_invoke_show (SP_ITEM (ochild), NR_ARENA_ITEM_ARENA (v->arenaitem), v->key, v->flags);
168                             if (ac) {
169                                     nr_arena_item_append_child (v->arenaitem, ac);
170                                     nr_arena_item_unref (ac);
171                             }
172                     }
173             }
174     } else {    // general case
175             SPObject *ochild = sp_object_get_child_by_repr(object, child);
176             if ( ochild && SP_IS_ITEM(ochild) ) {
177                     /* TODO: this should be moved into SPItem somehow */
178                     SPItemView *v;
179                     NRArenaItem *ac;
181                     unsigned position = sp_item_pos_in_parent(SP_ITEM(ochild));
183                     for (v = item->display; v != NULL; v = v->next) {
184                             ac = sp_item_invoke_show (SP_ITEM (ochild), NR_ARENA_ITEM_ARENA (v->arenaitem), v->key, v->flags);
186                             if (ac) {
187                                     nr_arena_item_add_child (v->arenaitem, ac, NULL);
188                                     nr_arena_item_set_order (ac, position);
189                                     nr_arena_item_unref (ac);
190                             }
191                     }
192             }
193     }
195         object->requestModified(SP_OBJECT_MODIFIED_FLAG);
198 /* fixme: hide (Lauris) */
200 static void
201 sp_group_remove_child (SPObject * object, Inkscape::XML::Node * child)
203         if (((SPObjectClass *) (parent_class))->remove_child)
204                 (* ((SPObjectClass *) (parent_class))->remove_child) (object, child);
206         object->requestModified(SP_OBJECT_MODIFIED_FLAG);
209 static void
210 sp_group_order_changed (SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *old_ref, Inkscape::XML::Node *new_ref)
212         if (((SPObjectClass *) (parent_class))->order_changed)
213                 (* ((SPObjectClass *) (parent_class))->order_changed) (object, child, old_ref, new_ref);
215         SPObject *ochild = sp_object_get_child_by_repr(object, child);
216         if ( ochild && SP_IS_ITEM(ochild) ) {
217                 /* TODO: this should be moved into SPItem somehow */
218                 SPItemView *v;
219                 unsigned position = sp_item_pos_in_parent(SP_ITEM(ochild));
220                 for ( v = SP_ITEM (ochild)->display ; v != NULL ; v = v->next ) {
221                         nr_arena_item_set_order (v->arenaitem, position);
222                 }
223         }
225         object->requestModified(SP_OBJECT_MODIFIED_FLAG);
228 static void
229 sp_group_update (SPObject *object, SPCtx *ctx, unsigned int flags)
231         SPGroup *group;
232         SPObject *child;
233         SPItemCtx *ictx, cctx;
234         GSList *l;
236         group = SP_GROUP (object);
237         ictx = (SPItemCtx *) ctx;
238         cctx = *ictx;
240         if (((SPObjectClass *) (parent_class))->update)
241                 ((SPObjectClass *) (parent_class))->update (object, ctx, flags);
243         if (flags & SP_OBJECT_MODIFIED_FLAG) flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
244         flags &= SP_OBJECT_MODIFIED_CASCADE;
246         l = NULL;
247         for (child = sp_object_first_child(object) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) {
248                 g_object_ref (G_OBJECT (child));
249                 l = g_slist_prepend (l, child);
250         }
251         l = g_slist_reverse (l);
252         while (l) {
253                 child = SP_OBJECT (l->data);
254                 l = g_slist_remove (l, child);
255                 if (flags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
256                         if (SP_IS_ITEM (child)) {
257                                 SPItem const &chi = *SP_ITEM(child);
258                                 cctx.i2doc = chi.transform * ictx->i2doc;
259                                 cctx.i2vp = chi.transform * ictx->i2vp;
260                                 child->updateDisplay((SPCtx *)&cctx, flags);
261                         } else {
262                                 child->updateDisplay(ctx, flags);
263                         }
264                 }
265                 g_object_unref (G_OBJECT (child));
266         }
269 static void
270 sp_group_modified (SPObject *object, guint flags)
272         SPGroup *group;
273         SPObject *child;
274         GSList *l;
276         group = SP_GROUP (object);
278         if (flags & SP_OBJECT_MODIFIED_FLAG) flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
279         flags &= SP_OBJECT_MODIFIED_CASCADE;
281         l = NULL;
282         for (child = sp_object_first_child(object) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) {
283                 g_object_ref (G_OBJECT (child));
284                 l = g_slist_prepend (l, child);
285         }
286         l = g_slist_reverse (l);
287         while (l) {
288                 child = SP_OBJECT (l->data);
289                 l = g_slist_remove (l, child);
290                 if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
291                         child->emitModified(flags);
292                 }
293                 g_object_unref (G_OBJECT (child));
294         }
297 static Inkscape::XML::Node *
298 sp_group_write (SPObject *object, Inkscape::XML::Node *repr, guint flags)
300         SPGroup *group;
301         SPObject *child;
302         Inkscape::XML::Node *crepr;
304         group = SP_GROUP (object);
306         if (flags & SP_OBJECT_WRITE_BUILD) {
307                 GSList *l;
308                 if (!repr) repr = sp_repr_new ("svg:g");
309                 l = NULL;
310                 for (child = sp_object_first_child(object); child != NULL; child = SP_OBJECT_NEXT(child) ) {
311                         crepr = child->updateRepr(NULL, flags);
312                         if (crepr) l = g_slist_prepend (l, crepr);
313                 }
314                 while (l) {
315                         repr->addChild((Inkscape::XML::Node *) l->data, NULL);
316                         Inkscape::GC::release((Inkscape::XML::Node *) l->data);
317                         l = g_slist_remove (l, l->data);
318                 }
319         } else {
320                 for (child = sp_object_first_child(object) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
321                         child->updateRepr(flags);
322                 }
323         }
325         if ( flags & SP_OBJECT_WRITE_EXT ) {
326                 const char *value;
327                 if ( group->_layer_mode == SPGroup::LAYER ) {
328                         value = "layer";
329                 } else if ( flags & SP_OBJECT_WRITE_ALL ) {
330                         value = "group";
331                 } else {
332                         value = NULL;
333                 }
334                 repr->setAttribute("inkscape:groupmode", value);
335         }
337         if (((SPObjectClass *) (parent_class))->write)
338                 ((SPObjectClass *) (parent_class))->write (object, repr, flags);
340         return repr;
343 static void
344 sp_group_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags)
346         for (SPObject *o = sp_object_first_child(SP_OBJECT(item)); o != NULL; o = SP_OBJECT_NEXT(o)) {
347                 if (SP_IS_ITEM(o)) {
348                         SPItem *child = SP_ITEM(o);
349                         NR::Matrix const ct(child->transform * transform);
350                         sp_item_invoke_bbox_full(child, bbox, ct, flags, FALSE);
351                 }
352         }
355 static void
356 sp_group_print (SPItem * item, SPPrintContext *ctx)
358         SPGroup * group;
359         SPItem * child;
360         SPObject * o;
362         group = SP_GROUP (item);
364         for (o = sp_object_first_child(SP_OBJECT(item)) ; o != NULL ; o = SP_OBJECT_NEXT(o) ) {
365                 if (SP_IS_ITEM (o)) {
366                         child = SP_ITEM (o);
367                         sp_item_invoke_print (SP_ITEM (o), ctx);
368                 }
369         }
372 static gchar * sp_group_description (SPItem * item)
374         SPGroup * group;
375         SPObject * o;
376         gint len;
378         group = SP_GROUP (item);
380         len = 0;
381         for ( o = sp_object_first_child(SP_OBJECT(item)) ; o != NULL ; o = SP_OBJECT_NEXT(o) ) {
382                 if (SP_IS_ITEM(o)) {
383                         len += 1;
384                 }
385         }
387         return g_strdup_printf(
388                         ngettext("<b>Group</b> of <b>%d</b> object",
389                                  "<b>Group</b> of <b>%d</b> objects",
390                                  len), len);
393 static void sp_group_set(SPObject *object, unsigned key, char const *value) {
394         SPGroup *group=SP_GROUP(object);
396         switch (key) {
397                 case SP_ATTR_INKSCAPE_GROUPMODE: {
398                         if ( value && !strcmp(value, "layer") ) {
399                                 group->setLayerMode(SPGroup::LAYER);
400                         } else {
401                                 group->setLayerMode(SPGroup::GROUP);
402                         }
403                 } break;
404                 default: {
405                         if (((SPObjectClass *) (parent_class))->set) {
406                                 (* ((SPObjectClass *) (parent_class))->set)(object, key, value);
407                         }
408                 }
409         }
412 static NRArenaItem *
413 sp_group_show (SPItem *item, NRArena *arena, unsigned int key, unsigned int flags)
415         SPGroup *group;
416         NRArenaItem *ai, *ac, *ar;
417         SPItem * child;
418         SPObject * o;
420         group = (SPGroup *) item;
422         ai = NRArenaGroup::create(arena);
423         nr_arena_group_set_transparent(NR_ARENA_GROUP (ai),
424                                        group->effectiveLayerMode(key) ==
425                                          SPGroup::LAYER);
427         ar = NULL;
429         for (o = sp_object_first_child(SP_OBJECT(item)) ; o != NULL; o = SP_OBJECT_NEXT(o) ) {
430                 if (SP_IS_ITEM (o)) {
431                         child = SP_ITEM (o);
432                         ac = sp_item_invoke_show (child, arena, key, flags);
433                         if (ac) {
434                                 nr_arena_item_add_child (ai, ac, ar);
435                                 ar = ac;
436                                 nr_arena_item_unref (ac);
437                         }
438                 }
439         }
441         return ai;
444 static void
445 sp_group_hide (SPItem *item, unsigned int key)
447         SPGroup * group;
448         SPItem * child;
449         SPObject * o;
451         group = (SPGroup *) item;
453         for (o = sp_object_first_child(SP_OBJECT(item)) ; o != NULL; o = SP_OBJECT_NEXT(o) ) {
454                 if (SP_IS_ITEM (o)) {
455                         child = SP_ITEM (o);
456                         sp_item_invoke_hide (child, key);
457                 }
458         }
460         if (((SPItemClass *) parent_class)->hide)
461                 ((SPItemClass *) parent_class)->hide (item, key);
464 static void sp_group_snappoints (SPItem const *item, SnapPointsIter p)
466         for (SPObject const *o = sp_object_first_child(SP_OBJECT(item));
467              o != NULL;
468              o = SP_OBJECT_NEXT(o))
469         {
470                 if (SP_IS_ITEM(o)) {
471                         sp_item_snappoints(SP_ITEM(o), p);
472                 }
473         }
477 void
478 sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done)
480         g_return_if_fail (group != NULL);
481         g_return_if_fail (SP_IS_GROUP (group));
483         SPDocument *doc = SP_OBJECT_DOCUMENT (group);
484         SPObject *root = SP_DOCUMENT_ROOT (doc);
485         SPObject *defs = SP_OBJECT (SP_ROOT (root)->defs);
487         SPItem *gitem = SP_ITEM (group);
488         Inkscape::XML::Node *grepr = SP_OBJECT_REPR (gitem);
490         g_return_if_fail (!strcmp (grepr->name(), "svg:g") || !strcmp (grepr->name(), "svg:a") || !strcmp (grepr->name(), "svg:switch"));
492       // this converts the gradient/pattern fill/stroke on the group, if any, to userSpaceOnUse
493       sp_item_adjust_paint_recursive (gitem, NR::identity(), NR::identity(), false);
495         SPItem *pitem = SP_ITEM (SP_OBJECT_PARENT (gitem));
496         Inkscape::XML::Node *prepr = SP_OBJECT_REPR (pitem);
498         /* Step 1 - generate lists of children objects */
499         GSList *items = NULL;
500         GSList *objects = NULL;
501         for (SPObject *child = sp_object_first_child(SP_OBJECT(group)) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
503                 if (SP_IS_ITEM (child)) {
505                         SPItem *citem = SP_ITEM (child);
507                         /* Merging of style */
508                         // this converts the gradient/pattern fill/stroke, if any, to userSpaceOnUse; we need to do
509                         // it here _before_ the new transform is set, so as to use the pre-transform bbox
510                         sp_item_adjust_paint_recursive (citem, NR::identity(), NR::identity(), false);
512                         sp_style_merge_from_dying_parent(SP_OBJECT_STYLE(child), SP_OBJECT_STYLE(gitem));
513                         /*
514                          * fixme: We currently make no allowance for the case where child is cloned
515                          * and the group has any style settings.
516                          *
517                          * (This should never occur with documents created solely with the current
518                          * version of inkscape without using the XML editor: we usually apply group
519                          * style changes to children rather than to the group itself.)
520                          *
521                          * If the group has no style settings, then
522                          * sp_style_merge_from_dying_parent should be a no-op.  Otherwise (i.e. if
523                          * we change the child's style to compensate for its parent going away)
524                          * then those changes will typically be reflected in any clones of child,
525                          * whereas we'd prefer for Ungroup not to affect the visual appearance.
526                          *
527                          * The only way of preserving styling appearance in general is for child to
528                          * be put into a new group -- a somewhat surprising response to an Ungroup
529                          * command.  We could add a new groupmode:transparent that would mostly
530                          * hide the existence of such groups from the user (i.e. editing behaves as
531                          * if the transparent group's children weren't in a group), though that's
532                          * extra complication & maintenance burden and this case is rare.
533                          */
535                         child->updateRepr();
537                         Inkscape::XML::Node *nrepr = SP_OBJECT_REPR (child)->duplicate();
539                         // Merging transform
540                         NR::Matrix ctrans;
541                         NR::Matrix const g(gitem->transform);
542                         if (SP_IS_USE(citem) && sp_use_get_original (SP_USE(citem)) &&
543                                         SP_OBJECT_PARENT (sp_use_get_original (SP_USE(citem))) == SP_OBJECT(group)) {
544                                 // make sure a clone's effective transform is the same as was under group
545                                 ctrans = g.inverse() * citem->transform * g;
546                         } else {
547                                 ctrans = citem->transform * g;
548                         }
550                         // FIXME: constructing a transform that would fully preserve the appearance of a
551                         // textpath if it is ungrouped with its path seems to be impossible in general
552                         // case. E.g. if the group was squeezed, to keep the ungrouped textpath squeezed
553                         // as well, we'll need to relink it to some "virtual" path which is inversely
554                         // stretched relative to the actual path, and then squeeze the textpath back so it
555                         // would both fit the actual path _and_ be squeezed as before. It's a bummer.
557                         // This is just a way to temporarily remember the transform in repr. When repr is
558                         // reattached outside of the group, the transform will be written more properly
559                         // (i.e. optimized into the object if the corresponding preference is set)
560                         gchar affinestr[80];
561                         if (sp_svg_transform_write(affinestr, 79, ctrans)) {
562                                 nrepr->setAttribute("transform", affinestr);
563                         } else {
564                                 nrepr->setAttribute("transform", NULL);
565                         }
567                         items = g_slist_prepend (items, nrepr);
569                 } else {
570                         Inkscape::XML::Node *nrepr = SP_OBJECT_REPR (child)->duplicate();
571                         objects = g_slist_prepend (objects, nrepr);
572                 }
573         }
575         /* Step 2 - clear group */
576         // remember the position of the group
577         gint pos = SP_OBJECT_REPR(group)->position();
579         // the group is leaving forever, no heir, clones should take note; its children however are going to reemerge
580         SP_OBJECT (group)->deleteObject(true, false);
582         /* Step 3 - add nonitems */
583         if (objects) {
584             Inkscape::XML::Node *last_def = SP_OBJECT_REPR(defs)->lastChild();
585             while (objects) {
586                 SP_OBJECT_REPR(defs)->addChild((Inkscape::XML::Node *) objects->data, last_def);
587                 Inkscape::GC::release((Inkscape::XML::Node *) objects->data);
588                 objects = g_slist_remove (objects, objects->data);
589             }
590         }
592         /* Step 4 - add items */
593         gint const preserve = prefs_get_int_attribute("options.preservetransform", "value", 0);
594         while (items) {
595                 Inkscape::XML::Node *repr = (Inkscape::XML::Node *) items->data;
596                 // add item
597                 prepr->appendChild(repr);
598                 // restore position; since the items list was prepended (i.e. reverse), we now add
599                 // all children at the same pos, which inverts the order once again
600                 repr->setPosition(pos > 0 ? pos : 0);
602                 // fill in the children list if non-null
603                 SPItem *nitem = (SPItem *) doc->getObjectByRepr(repr);
605                 /* Optimize the transform matrix if requested. */
606                 // No compensations are required because this is supposed to be a non-transformation visually.
607                 if (!preserve) {
608                         NR::Matrix (*set_transform)(SPItem *, NR::Matrix const &) = ((SPItemClass *) G_OBJECT_GET_CLASS(nitem))->set_transform;
609                         if (set_transform) {
610                                 sp_item_set_item_transform(nitem, set_transform(nitem, nitem->transform));
611                                 nitem->updateRepr();
612                         }
613                 }
615                 Inkscape::GC::release(repr);
616                 if (children && SP_IS_ITEM (nitem)) 
617                         *children = g_slist_prepend (*children, nitem);
619                 items = g_slist_remove (items, items->data);
620         }
622         if (do_done) sp_document_done (doc);
625 /*
626  * some API for list aspect of SPGroup
627  */
629 GSList *
630 sp_item_group_item_list (SPGroup * group)
632         GSList *s;
633         SPObject *o;
635         g_return_val_if_fail (group != NULL, NULL);
636         g_return_val_if_fail (SP_IS_GROUP (group), NULL);
638         s = NULL;
640         for ( o = sp_object_first_child(SP_OBJECT(group)) ; o != NULL ; o = SP_OBJECT_NEXT(o) ) {
641                 if (SP_IS_ITEM (o)) {
642                         s = g_slist_prepend (s, o);
643                 }
644         }
646         return g_slist_reverse (s);
649 SPObject *
650 sp_item_group_get_child_by_name (SPGroup *group, SPObject *ref, const gchar *name)
652         SPObject *child;
653         child = (ref) ? SP_OBJECT_NEXT(ref) : sp_object_first_child(SP_OBJECT(group));
654         while ( child && strcmp (SP_OBJECT_REPR(child)->name(), name) ) {
655                 child = SP_OBJECT_NEXT(child);
656         }
657         return child;
660 void SPGroup::setLayerMode(LayerMode mode) {
661         if ( _layer_mode != mode ) {
662                 if ( mode == LAYER ) {
663                         sp_document_add_resource(SP_OBJECT_DOCUMENT(this), "layer", this);
664                 } else {
665                         sp_document_remove_resource(SP_OBJECT_DOCUMENT(this), "layer", this);
666                 }
667                 _layer_mode = mode;
668                 _updateLayerMode();
669         }
672 SPGroup::LayerMode SPGroup::layerDisplayMode(unsigned int dkey) const {
673         std::map<unsigned int, LayerMode>::const_iterator iter;
674         iter = _display_modes.find(dkey);
675         if ( iter != _display_modes.end() ) {
676                 return (*iter).second;
677         } else {
678                 return GROUP;
679         }
682 void SPGroup::setLayerDisplayMode(unsigned int dkey, SPGroup::LayerMode mode) {
683         if ( layerDisplayMode(dkey) != mode ) {
684                 _display_modes[dkey] = mode;
685                 _updateLayerMode(dkey);
686         }
689 void SPGroup::_updateLayerMode(unsigned int display_key) {
690         SPItemView *view;
691         for ( view = this->display ; view ; view = view->next ) {
692                 if ( !display_key || view->key == display_key ) {
693                         NRArenaGroup *arena_group=NR_ARENA_GROUP(view->arenaitem);
694                         if (arena_group) {
695                                 nr_arena_group_set_transparent(arena_group, effectiveLayerMode(view->key) == SPGroup::LAYER);
696                         }
697                 }
698         }