Code

NR => Geom for (almost all of) event-context.h/.cpp
[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  *   Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
10  *
11  * Copyright (C) 1999-2006 authors
12  * Copyright (C) 2000-2001 Ximian, Inc.
13  *
14  * Released under GNU GPL, read the file 'COPYING' for more information
15  */
17 #ifdef HAVE_CONFIG_H
18 # include "config.h"
19 #endif
21 #include <glibmm/i18n.h>
22 #include <cstring>
23 #include <string>
25 #include "display/nr-arena-group.h"
26 #include "display/curve.h"
27 #include "libnr/nr-matrix-ops.h"
28 #include "libnr/nr-matrix-fns.h"
29 #include "xml/repr.h"
30 #include "svg/svg.h"
31 #include "document.h"
32 #include "style.h"
33 #include "attributes.h"
34 #include "sp-item-transform.h"
35 #include "sp-root.h"
36 #include "sp-use.h"
37 #include "prefs-utils.h"
38 #include "sp-clippath.h"
39 #include "sp-mask.h"
40 #include "sp-path.h"
41 #include "box3d.h"
42 #include "persp3d.h"
43 #include "inkscape.h"
44 #include "desktop-handles.h"
45 #include "selection.h"
46 #include "live_effects/lpeobject.h"
47 #include "live_effects/lpeobject-reference.h"
48 #include "sp-title.h"
49 #include "sp-desc.h"
51 static void sp_group_class_init (SPGroupClass *klass);
52 static void sp_group_init (SPGroup *group);
53 static void sp_group_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
54 static void sp_group_release(SPObject *object);
55 static void sp_group_dispose(GObject *object);
57 static void sp_group_child_added (SPObject * object, Inkscape::XML::Node * child, Inkscape::XML::Node * ref);
58 static void sp_group_remove_child (SPObject * object, Inkscape::XML::Node * child);
59 static void sp_group_order_changed (SPObject * object, Inkscape::XML::Node * child, Inkscape::XML::Node * old_ref, Inkscape::XML::Node * new_ref);
60 static void sp_group_update (SPObject *object, SPCtx *ctx, guint flags);
61 static void sp_group_modified (SPObject *object, guint flags);
62 static Inkscape::XML::Node *sp_group_write (SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
63 static void sp_group_set(SPObject *object, unsigned key, char const *value);
65 static void sp_group_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags);
66 static void sp_group_print (SPItem * item, SPPrintContext *ctx);
67 static gchar * sp_group_description (SPItem * item);
68 static NR::Matrix sp_group_set_transform(SPItem *item, NR::Matrix const &xform);
69 static NRArenaItem *sp_group_show (SPItem *item, NRArena *arena, unsigned int key, unsigned int flags);
70 static void sp_group_hide (SPItem * item, unsigned int key);
71 static void sp_group_snappoints (SPItem const *item, SnapPointsIter p);
73 static void sp_group_update_patheffect(SPLPEItem *lpeitem, bool write);
74 static void sp_group_perform_patheffect(SPGroup *group, SPGroup *topgroup);
76 static SPLPEItemClass * parent_class;
78 GType
79 sp_group_get_type (void)
80 {
81         static GType group_type = 0;
82         if (!group_type) {
83                 GTypeInfo group_info = {
84                         sizeof (SPGroupClass),
85                         NULL,   /* base_init */
86                         NULL,   /* base_finalize */
87                         (GClassInitFunc) sp_group_class_init,
88                         NULL,   /* class_finalize */
89                         NULL,   /* class_data */
90                         sizeof (SPGroup),
91                         16,     /* n_preallocs */
92                         (GInstanceInitFunc) sp_group_init,
93                         NULL,   /* value_table */
94                 };
95                 group_type = g_type_register_static (SP_TYPE_LPE_ITEM, "SPGroup", &group_info, (GTypeFlags)0);
96         }
97         return group_type;
98 }
100 static void
101 sp_group_class_init (SPGroupClass *klass)
103         GObjectClass * object_class;
104         SPObjectClass * sp_object_class;
105         SPItemClass * item_class;
106         SPLPEItemClass * lpe_item_class;
108         object_class = (GObjectClass *) klass;
109         sp_object_class = (SPObjectClass *) klass;
110         item_class = (SPItemClass *) klass;
111         lpe_item_class = (SPLPEItemClass *) klass;
113         parent_class = (SPLPEItemClass *)g_type_class_ref (SP_TYPE_LPE_ITEM);
115         object_class->dispose = sp_group_dispose;
117         sp_object_class->child_added = sp_group_child_added;
118         sp_object_class->remove_child = sp_group_remove_child;
119         sp_object_class->order_changed = sp_group_order_changed;
120         sp_object_class->update = sp_group_update;
121         sp_object_class->modified = sp_group_modified;
122         sp_object_class->set = sp_group_set;
123         sp_object_class->write = sp_group_write;
124         sp_object_class->release = sp_group_release;
125         sp_object_class->build = sp_group_build;
127         item_class->bbox = sp_group_bbox;
128         item_class->print = sp_group_print;
129         item_class->description = sp_group_description;
130         item_class->set_transform = sp_group_set_transform;
131         item_class->show = sp_group_show;
132         item_class->hide = sp_group_hide;
133         item_class->snappoints = sp_group_snappoints;
135         lpe_item_class->update_patheffect = sp_group_update_patheffect;
138 static void
139 sp_group_init (SPGroup *group)
141         group->_layer_mode = SPGroup::GROUP;
142     group->group = new CGroup(group);
143         new (&group->_display_modes) std::map<unsigned int, SPGroup::LayerMode>();
146 static void sp_group_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
148         sp_object_read_attr(object, "inkscape:groupmode");
150         if (((SPObjectClass *)parent_class)->build) {
151                 ((SPObjectClass *)parent_class)->build(object, document, repr);
152         }
155 static void sp_group_release(SPObject *object) {
156         if ( SP_GROUP(object)->_layer_mode == SPGroup::LAYER ) {
157                 sp_document_remove_resource(SP_OBJECT_DOCUMENT(object), "layer", object);
158         }
159         if (((SPObjectClass *)parent_class)->release) {
160                 ((SPObjectClass *)parent_class)->release(object);
161         }
164 static void
165 sp_group_dispose(GObject *object)
167         SP_GROUP(object)->_display_modes.~map();
168     delete SP_GROUP(object)->group;
171 static void
172 sp_group_child_added (SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
174         SPItem *item;
176         item = SP_ITEM (object);
178         if (((SPObjectClass *) (parent_class))->child_added)
179                 (* ((SPObjectClass *) (parent_class))->child_added) (object, child, ref);
181     SP_GROUP(object)->group->onChildAdded(child);
184 /* fixme: hide (Lauris) */
186 static void
187 sp_group_remove_child (SPObject * object, Inkscape::XML::Node * child)
189         if (((SPObjectClass *) (parent_class))->remove_child)
190                 (* ((SPObjectClass *) (parent_class))->remove_child) (object, child);
192     SP_GROUP(object)->group->onChildRemoved(child);
195 static void
196 sp_group_order_changed (SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *old_ref, Inkscape::XML::Node *new_ref)
198         if (((SPObjectClass *) (parent_class))->order_changed)
199                 (* ((SPObjectClass *) (parent_class))->order_changed) (object, child, old_ref, new_ref);
201     SP_GROUP(object)->group->onOrderChanged(child, old_ref, new_ref);
204 static void
205 sp_group_update (SPObject *object, SPCtx *ctx, unsigned int flags)
207     if (((SPObjectClass *) (parent_class))->update)
208         ((SPObjectClass *) (parent_class))->update (object, ctx, flags);
210     SP_GROUP(object)->group->onUpdate(ctx, flags);
213 static void
214 sp_group_modified (SPObject *object, guint flags)
216     if (((SPObjectClass *) (parent_class))->modified)
217         ((SPObjectClass *) (parent_class))->modified (object, flags);
219     SP_GROUP(object)->group->onModified(flags);
222 static Inkscape::XML::Node *
223 sp_group_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
225         SPGroup *group;
226         SPObject *child;
227         Inkscape::XML::Node *crepr;
229         group = SP_GROUP (object);
231         if (flags & SP_OBJECT_WRITE_BUILD) {
232                 GSList *l;
233                 if (!repr) {
234                     repr = xml_doc->createElement("svg:g");
235                 }
236                 l = NULL;
237                 for (child = sp_object_first_child(object); child != NULL; child = SP_OBJECT_NEXT(child) ) {
238                         if (SP_IS_TITLE(child) || SP_IS_DESC(child)) continue;
239                         crepr = child->updateRepr(xml_doc, NULL, flags);
240                         if (crepr) l = g_slist_prepend (l, crepr);
241                 }
242                 while (l) {
243                         repr->addChild((Inkscape::XML::Node *) l->data, NULL);
244                         Inkscape::GC::release((Inkscape::XML::Node *) l->data);
245                         l = g_slist_remove (l, l->data);
246                 }
247         } else {
248                 for (child = sp_object_first_child(object) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
249                         if (SP_IS_TITLE(child) || SP_IS_DESC(child)) continue;
250                         child->updateRepr(flags);
251                 }
252         }
254         if ( flags & SP_OBJECT_WRITE_EXT ) {
255                 const char *value;
256                 if ( group->_layer_mode == SPGroup::LAYER ) {
257                         value = "layer";
258                 } else if ( flags & SP_OBJECT_WRITE_ALL ) {
259                         value = "group";
260                 } else {
261                         value = NULL;
262                 }
263                 repr->setAttribute("inkscape:groupmode", value);
264         }
266         if (((SPObjectClass *) (parent_class))->write)
267                 ((SPObjectClass *) (parent_class))->write (object, xml_doc, repr, flags);
269         return repr;
272 static void
273 sp_group_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags)
275     SP_GROUP(item)->group->calculateBBox(bbox, transform, flags);
278 static void
279 sp_group_print (SPItem * item, SPPrintContext *ctx)
281     SP_GROUP(item)->group->onPrint(ctx);
284 static gchar * sp_group_description (SPItem * item)
286     return SP_GROUP(item)->group->getDescription();
289 static NR::Matrix
290 sp_group_set_transform(SPItem *item, NR::Matrix const &xform)
292     Inkscape::Selection *selection = sp_desktop_selection(inkscape_active_desktop());
293     persp3d_split_perspectives_according_to_selection(selection);
295     NR::Matrix last_trans;
296     sp_svg_transform_read(SP_OBJECT_REPR(item)->attribute("transform"), &last_trans);
297     NR::Matrix inc_trans = last_trans.inverse()*xform;
299     std::list<Persp3D *> plist = selection->perspList();
300     for (std::list<Persp3D *>::iterator i = plist.begin(); i != plist.end(); ++i) {
301         persp3d_apply_affine_transformation(*i, inc_trans);
302     }
304     return xform;
307 static void sp_group_set(SPObject *object, unsigned key, char const *value) {
308         SPGroup *group = SP_GROUP(object);
310         switch (key) {
311                 case SP_ATTR_INKSCAPE_GROUPMODE:
312                         if ( value && !strcmp(value, "layer") ) {
313                                 group->setLayerMode(SPGroup::LAYER);
314                         } else {
315                                 group->setLayerMode(SPGroup::GROUP);
316                         }
317                     break;
318                 default: {
319                         if (((SPObjectClass *) (parent_class))->set) {
320                                 (* ((SPObjectClass *) (parent_class))->set)(object, key, value);
321                         }
322                 }
323         }
326 static NRArenaItem *
327 sp_group_show (SPItem *item, NRArena *arena, unsigned int key, unsigned int flags)
329     return SP_GROUP(item)->group->show(arena, key, flags);
332 static void
333 sp_group_hide (SPItem *item, unsigned int key)
335     SP_GROUP(item)->group->hide(key);
338 static void sp_group_snappoints (SPItem const *item, SnapPointsIter p)
340         for (SPObject const *o = sp_object_first_child(SP_OBJECT(item));
341              o != NULL;
342              o = SP_OBJECT_NEXT(o))
343         {
344                 if (SP_IS_ITEM(o)) {
345             sp_item_snappoints(SP_ITEM(o), false, p);
346                 }
347         }
351 void
352 sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done)
354         g_return_if_fail (group != NULL);
355         g_return_if_fail (SP_IS_GROUP (group));
357         SPDocument *doc = SP_OBJECT_DOCUMENT (group);
358         SPObject *root = SP_DOCUMENT_ROOT (doc);
359         SPObject *defs = SP_OBJECT (SP_ROOT (root)->defs);
361         SPItem *gitem = SP_ITEM (group);
362         Inkscape::XML::Node *grepr = SP_OBJECT_REPR (gitem);
364         g_return_if_fail (!strcmp (grepr->name(), "svg:g") || !strcmp (grepr->name(), "svg:a") || !strcmp (grepr->name(), "svg:switch"));
366       // this converts the gradient/pattern fill/stroke on the group, if any, to userSpaceOnUse
367       sp_item_adjust_paint_recursive (gitem, NR::identity(), NR::identity(), false);
369         SPItem *pitem = SP_ITEM (SP_OBJECT_PARENT (gitem));
370         Inkscape::XML::Node *prepr = SP_OBJECT_REPR (pitem);
372         if (SP_IS_BOX3D(gitem)) {
373             group = box3d_convert_to_group(SP_BOX3D(gitem));
374             gitem = SP_ITEM(group);
375         }
377         sp_lpe_item_remove_all_path_effects(SP_LPE_ITEM(group), false);
379         /* Step 1 - generate lists of children objects */
380         GSList *items = NULL;
381         GSList *objects = NULL;
382         for (SPObject *child = sp_object_first_child(SP_OBJECT(group)) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
384                 if (SP_IS_ITEM (child)) {
386                         SPItem *citem = SP_ITEM (child);
388                         /* Merging of style */
389                         // this converts the gradient/pattern fill/stroke, if any, to userSpaceOnUse; we need to do
390                         // it here _before_ the new transform is set, so as to use the pre-transform bbox
391                         sp_item_adjust_paint_recursive (citem, NR::identity(), NR::identity(), false);
393                         sp_style_merge_from_dying_parent(SP_OBJECT_STYLE(child), SP_OBJECT_STYLE(gitem));
394                         /*
395                          * fixme: We currently make no allowance for the case where child is cloned
396                          * and the group has any style settings.
397                          *
398                          * (This should never occur with documents created solely with the current
399                          * version of inkscape without using the XML editor: we usually apply group
400                          * style changes to children rather than to the group itself.)
401                          *
402                          * If the group has no style settings, then
403                          * sp_style_merge_from_dying_parent should be a no-op.  Otherwise (i.e. if
404                          * we change the child's style to compensate for its parent going away)
405                          * then those changes will typically be reflected in any clones of child,
406                          * whereas we'd prefer for Ungroup not to affect the visual appearance.
407                          *
408                          * The only way of preserving styling appearance in general is for child to
409                          * be put into a new group -- a somewhat surprising response to an Ungroup
410                          * command.  We could add a new groupmode:transparent that would mostly
411                          * hide the existence of such groups from the user (i.e. editing behaves as
412                          * if the transparent group's children weren't in a group), though that's
413                          * extra complication & maintenance burden and this case is rare.
414                          */
416                         child->updateRepr();
418                         Inkscape::XML::Node *nrepr = SP_OBJECT_REPR (child)->duplicate(prepr->document());
420                         // Merging transform
421                         NR::Matrix ctrans;
422                         NR::Matrix const g(gitem->transform);
423                         if (SP_IS_USE(citem) && sp_use_get_original (SP_USE(citem)) &&
424                                         SP_OBJECT_PARENT (sp_use_get_original (SP_USE(citem))) == SP_OBJECT(group)) {
425                                 // make sure a clone's effective transform is the same as was under group
426                                 ctrans = g.inverse() * citem->transform * g;
427                         } else {
428                                 ctrans = citem->transform * g;
429                         }
431                         // FIXME: constructing a transform that would fully preserve the appearance of a
432                         // textpath if it is ungrouped with its path seems to be impossible in general
433                         // case. E.g. if the group was squeezed, to keep the ungrouped textpath squeezed
434                         // as well, we'll need to relink it to some "virtual" path which is inversely
435                         // stretched relative to the actual path, and then squeeze the textpath back so it
436                         // would both fit the actual path _and_ be squeezed as before. It's a bummer.
438                         // This is just a way to temporarily remember the transform in repr. When repr is
439                         // reattached outside of the group, the transform will be written more properly
440                         // (i.e. optimized into the object if the corresponding preference is set)
441                         gchar *affinestr=sp_svg_transform_write(ctrans);
442                         nrepr->setAttribute("transform", affinestr);
443                         g_free(affinestr);
445                         items = g_slist_prepend (items, nrepr);
447                 } else {
448                         Inkscape::XML::Node *nrepr = SP_OBJECT_REPR (child)->duplicate(prepr->document());
449                         objects = g_slist_prepend (objects, nrepr);
450                 }
451         }
453         /* Step 2 - clear group */
454         // remember the position of the group
455         gint pos = SP_OBJECT_REPR(group)->position();
457         // the group is leaving forever, no heir, clones should take note; its children however are going to reemerge
458         SP_OBJECT (group)->deleteObject(true, false);
460         /* Step 3 - add nonitems */
461         if (objects) {
462             Inkscape::XML::Node *last_def = SP_OBJECT_REPR(defs)->lastChild();
463             while (objects) {
464                 Inkscape::XML::Node *repr = (Inkscape::XML::Node *) objects->data;
465                 if (!sp_repr_is_meta_element(repr))
466                     SP_OBJECT_REPR(defs)->addChild(repr, last_def);
467                 Inkscape::GC::release(repr);
468                 objects = g_slist_remove (objects, objects->data);
469             }
470         }
472         /* Step 4 - add items */
473         while (items) {
474                 Inkscape::XML::Node *repr = (Inkscape::XML::Node *) items->data;
475                 // add item
476                 prepr->appendChild(repr);
477                 // restore position; since the items list was prepended (i.e. reverse), we now add
478                 // all children at the same pos, which inverts the order once again
479                 repr->setPosition(pos > 0 ? pos : 0);
481                 // fill in the children list if non-null
482                 SPItem *item = (SPItem *) doc->getObjectByRepr(repr);
484                 sp_item_write_transform(item, repr, item->transform, NULL, false);
486                 Inkscape::GC::release(repr);
487                 if (children && SP_IS_ITEM (item))
488                         *children = g_slist_prepend (*children, item);
490                 items = g_slist_remove (items, items->data);
491         }
493         if (do_done)
494                 sp_document_done (doc, SP_VERB_NONE, _("Ungroup"));
497 /*
498  * some API for list aspect of SPGroup
499  */
501 GSList *
502 sp_item_group_item_list (SPGroup * group)
504         GSList *s;
505         SPObject *o;
507         g_return_val_if_fail (group != NULL, NULL);
508         g_return_val_if_fail (SP_IS_GROUP (group), NULL);
510         s = NULL;
512         for ( o = sp_object_first_child(SP_OBJECT(group)) ; o != NULL ; o = SP_OBJECT_NEXT(o) ) {
513                 if (SP_IS_ITEM (o)) {
514                         s = g_slist_prepend (s, o);
515                 }
516         }
518         return g_slist_reverse (s);
521 SPObject *
522 sp_item_group_get_child_by_name (SPGroup *group, SPObject *ref, const gchar *name)
524         SPObject *child;
525         child = (ref) ? SP_OBJECT_NEXT(ref) : sp_object_first_child(SP_OBJECT(group));
526         while ( child && strcmp (SP_OBJECT_REPR(child)->name(), name) ) {
527                 child = SP_OBJECT_NEXT(child);
528         }
529         return child;
532 void SPGroup::setLayerMode(LayerMode mode) {
533         if ( _layer_mode != mode ) {
534                 if ( mode == LAYER ) {
535                         sp_document_add_resource(SP_OBJECT_DOCUMENT(this), "layer", this);
536                 } else {
537                         sp_document_remove_resource(SP_OBJECT_DOCUMENT(this), "layer", this);
538                 }
539                 _layer_mode = mode;
540                 _updateLayerMode();
541         }
544 SPGroup::LayerMode SPGroup::layerDisplayMode(unsigned int dkey) const {
545         std::map<unsigned int, LayerMode>::const_iterator iter;
546         iter = _display_modes.find(dkey);
547         if ( iter != _display_modes.end() ) {
548                 return (*iter).second;
549         } else {
550                 return GROUP;
551         }
554 void SPGroup::setLayerDisplayMode(unsigned int dkey, SPGroup::LayerMode mode) {
555         if ( layerDisplayMode(dkey) != mode ) {
556                 _display_modes[dkey] = mode;
557                 _updateLayerMode(dkey);
558         }
561 void SPGroup::_updateLayerMode(unsigned int display_key) {
562         SPItemView *view;
563         for ( view = this->display ; view ; view = view->next ) {
564                 if ( !display_key || view->key == display_key ) {
565                         NRArenaGroup *arena_group=NR_ARENA_GROUP(view->arenaitem);
566                         if (arena_group) {
567                                 nr_arena_group_set_transparent(arena_group, effectiveLayerMode(view->key) == SPGroup::LAYER);
568                         }
569                 }
570         }
573 void SPGroup::translateChildItems(NR::translate const &tr)
575         if (this->hasChildren())
576         {
577                 SPObject *o = NULL;
578                 for (o = sp_object_first_child(SP_OBJECT(this)) ; o != NULL ; o = SP_OBJECT_NEXT(o) ) {
579                         if (SP_IS_ITEM (o)) {
580                                 sp_item_move_rel(static_cast<SPItem *>(o), tr);
581                         }
582                 }
583         }
586 CGroup::CGroup(SPGroup *group) {
587     _group = group;
590 CGroup::~CGroup() {
593 void CGroup::onChildAdded(Inkscape::XML::Node *child) {
594     SPObject *last_child = _group->lastChild();
595     if (last_child && SP_OBJECT_REPR(last_child) == child) {
596         // optimization for the common special case where the child is being added at the end
597         SPObject *ochild = last_child;
598         if ( SP_IS_ITEM(ochild) ) {
599             /* TODO: this should be moved into SPItem somehow */
600             SPItemView *v;
601             NRArenaItem *ac;
603             for (v = _group->display; v != NULL; v = v->next) {
604                 ac = sp_item_invoke_show (SP_ITEM (ochild), NR_ARENA_ITEM_ARENA (v->arenaitem), v->key, v->flags);
606                 if (ac) {
607                     nr_arena_item_append_child (v->arenaitem, ac);
608                     nr_arena_item_unref (ac);
609                 }
610             }
611         }
612     } else {    // general case
613         SPObject *ochild = sp_object_get_child_by_repr(_group, child);
614         if ( ochild && SP_IS_ITEM(ochild) ) {
615             /* TODO: this should be moved into SPItem somehow */
616             SPItemView *v;
617             NRArenaItem *ac;
619             unsigned position = sp_item_pos_in_parent(SP_ITEM(ochild));
621             for (v = _group->display; v != NULL; v = v->next) {
622                 ac = sp_item_invoke_show (SP_ITEM (ochild), NR_ARENA_ITEM_ARENA (v->arenaitem), v->key, v->flags);
624                 if (ac) {
625                     nr_arena_item_add_child (v->arenaitem, ac, NULL);
626                     nr_arena_item_set_order (ac, position);
627                     nr_arena_item_unref (ac);
628                 }
629             }
630         }
631     }
633     _group->requestModified(SP_OBJECT_MODIFIED_FLAG);
636 void CGroup::onChildRemoved(Inkscape::XML::Node */*child*/) {
637     _group->requestModified(SP_OBJECT_MODIFIED_FLAG);
640 void CGroup::onUpdate(SPCtx *ctx, unsigned int flags) {
641     SPItemCtx *ictx, cctx;
643     ictx = (SPItemCtx *) ctx;
644     cctx = *ictx;
646     if (flags & SP_OBJECT_MODIFIED_FLAG) {
647       flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
648     }
650     flags &= SP_OBJECT_MODIFIED_CASCADE;
652     if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) {
653       SPObject *object = SP_OBJECT(_group);
654       for (SPItemView *v = SP_ITEM(_group)->display; v != NULL; v = v->next) {
655         nr_arena_group_set_style(NR_ARENA_GROUP(v->arenaitem), SP_OBJECT_STYLE(object));
656       }
657     }
659     GSList *l = g_slist_reverse(_group->childList(true, SPObject::ActionUpdate));
660     while (l) {
661         SPObject *child = SP_OBJECT (l->data);
662         l = g_slist_remove (l, child);
663         if (flags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
664             if (SP_IS_ITEM (child)) {
665                 SPItem const &chi = *SP_ITEM(child);
666                 cctx.i2doc = chi.transform * ictx->i2doc;
667                 cctx.i2vp = chi.transform * ictx->i2vp;
668                 child->updateDisplay((SPCtx *)&cctx, flags);
669             } else {
670                 child->updateDisplay(ctx, flags);
671             }
672         }
673         g_object_unref (G_OBJECT (child));
674     }
677 void CGroup::onModified(guint flags) {
678     SPObject *child;
680     if (flags & SP_OBJECT_MODIFIED_FLAG) flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
681     flags &= SP_OBJECT_MODIFIED_CASCADE;
683     if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) {
684       SPObject *object = SP_OBJECT(_group);
685       for (SPItemView *v = SP_ITEM(_group)->display; v != NULL; v = v->next) {
686         nr_arena_group_set_style(NR_ARENA_GROUP(v->arenaitem), SP_OBJECT_STYLE(object));
687       }
688     }
690     GSList *l = g_slist_reverse(_group->childList(true));
691     while (l) {
692         child = SP_OBJECT (l->data);
693         l = g_slist_remove (l, child);
694         if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
695             child->emitModified(flags);
696         }
697         g_object_unref (G_OBJECT (child));
698     }
701 void CGroup::calculateBBox(NRRect *bbox, NR::Matrix const &transform, unsigned const flags) {
703     boost::optional<NR::Rect> dummy_bbox;
705     GSList *l = _group->childList(false, SPObject::ActionBBox);
706     while (l) {
707         SPObject *o = SP_OBJECT (l->data);
708         if (SP_IS_ITEM(o) && !SP_ITEM(o)->isHidden()) {
709             SPItem *child = SP_ITEM(o);
710             NR::Matrix const ct(child->transform * transform);
711             sp_item_invoke_bbox_full(child, &dummy_bbox, ct, flags, FALSE);
712         }
713         l = g_slist_remove (l, o);
714     }
716     *bbox = NRRect(dummy_bbox);
719 void CGroup::onPrint(SPPrintContext *ctx) {
720     GSList *l = g_slist_reverse(_group->childList(false));
721     while (l) {
722         SPObject *o = SP_OBJECT (l->data);
723         if (SP_IS_ITEM(o)) {
724             sp_item_invoke_print (SP_ITEM (o), ctx);
725         }
726         l = g_slist_remove (l, o);
727     }
730 gint CGroup::getItemCount() {
731     gint len = 0;
732     for (SPObject *o = sp_object_first_child(SP_OBJECT(_group)) ; o != NULL ; o = SP_OBJECT_NEXT(o) ) {
733         if (SP_IS_ITEM(o)) {
734             len++;
735         }
736     }
738     return len;
741 gchar *CGroup::getDescription() {
742     gint len = getItemCount();
743     return g_strdup_printf(
744             ngettext("<b>Group</b> of <b>%d</b> object",
745                  "<b>Group</b> of <b>%d</b> objects",
746                  len), len);
749 NRArenaItem *CGroup::show (NRArena *arena, unsigned int key, unsigned int flags) {
750     NRArenaItem *ai;
751     SPObject *object = SP_OBJECT(_group);
753     ai = NRArenaGroup::create(arena);
755     nr_arena_group_set_transparent(NR_ARENA_GROUP (ai),
756                                    _group->effectiveLayerMode(key) ==
757                          SPGroup::LAYER);
758     nr_arena_group_set_style(NR_ARENA_GROUP(ai), SP_OBJECT_STYLE(object));
760     _showChildren(arena, ai, key, flags);
761     return ai;
764 void CGroup::_showChildren (NRArena *arena, NRArenaItem *ai, unsigned int key, unsigned int flags) {
765     NRArenaItem *ac = NULL;
766     NRArenaItem *ar = NULL;
767     SPItem * child = NULL;
768     GSList *l = g_slist_reverse(_group->childList(false, SPObject::ActionShow));
769     while (l) {
770         SPObject *o = SP_OBJECT (l->data);
771         if (SP_IS_ITEM (o)) {
772             child = SP_ITEM (o);
773             ac = sp_item_invoke_show (child, arena, key, flags);
774             if (ac) {
775                 nr_arena_item_add_child (ai, ac, ar);
776                 ar = ac;
777                 nr_arena_item_unref (ac);
778             }
779         }
780         l = g_slist_remove (l, o);
781     }
784 void CGroup::hide (unsigned int key) {
785     SPItem * child;
787     GSList *l = g_slist_reverse(_group->childList(false, SPObject::ActionShow));
788     while (l) {
789         SPObject *o = SP_OBJECT (l->data);
790         if (SP_IS_ITEM (o)) {
791             child = SP_ITEM (o);
792             sp_item_invoke_hide (child, key);
793         }
794         l = g_slist_remove (l, o);
795     }
797     if (((SPItemClass *) parent_class)->hide)
798         ((SPItemClass *) parent_class)->hide (_group, key);
801 void CGroup::onOrderChanged (Inkscape::XML::Node *child, Inkscape::XML::Node *, Inkscape::XML::Node *)
803     SPObject *ochild = sp_object_get_child_by_repr(_group, child);
804     if ( ochild && SP_IS_ITEM(ochild) ) {
805         /* TODO: this should be moved into SPItem somehow */
806         SPItemView *v;
807         unsigned position = sp_item_pos_in_parent(SP_ITEM(ochild));
808         for ( v = SP_ITEM (ochild)->display ; v != NULL ; v = v->next ) {
809             nr_arena_item_set_order (v->arenaitem, position);
810         }
811     }
813     _group->requestModified(SP_OBJECT_MODIFIED_FLAG);
816 static void
817 sp_group_update_patheffect (SPLPEItem *lpeitem, bool write)
819 #ifdef GROUP_VERBOSE
820     g_message("sp_group_update_patheffect: %p\n", lpeitem);
821 #endif
822     g_return_if_fail (lpeitem != NULL);
823     g_return_if_fail (SP_IS_GROUP (lpeitem));
825     GSList const *item_list = sp_item_group_item_list(SP_GROUP(lpeitem));
826     for ( GSList const *iter = item_list; iter; iter = iter->next ) {
827         SPObject *subitem = static_cast<SPObject *>(iter->data);
828         if (SP_IS_LPE_ITEM(subitem)) {
829             if (SP_LPE_ITEM_CLASS (G_OBJECT_GET_CLASS (subitem))->update_patheffect) {
830                 SP_LPE_ITEM_CLASS (G_OBJECT_GET_CLASS (subitem))->update_patheffect (SP_LPE_ITEM(subitem), write);
831             }
832         }
833     }
834     
835     if (sp_lpe_item_has_path_effect(lpeitem) && sp_lpe_item_path_effects_enabled(lpeitem)) {
836         for (PathEffectList::iterator it = lpeitem->path_effect_list->begin(); it != lpeitem->path_effect_list->end(); it++)
837         {
838             LivePathEffectObject *lpeobj = (*it)->lpeobject;
839             lpeobj->lpe->doBeforeEffect(lpeitem);
840         }
841         
842         sp_group_perform_patheffect(SP_GROUP(lpeitem), SP_GROUP(lpeitem));
843     }
846 static void
847 sp_group_perform_patheffect(SPGroup *group, SPGroup *topgroup)
849     GSList const *item_list = sp_item_group_item_list(SP_GROUP(group));
850     for ( GSList const *iter = item_list; iter; iter = iter->next ) {
851         SPObject *subitem = static_cast<SPObject *>(iter->data);
852         if (SP_IS_GROUP(subitem)) {
853             sp_group_perform_patheffect(SP_GROUP(subitem), topgroup);
854         } else if (SP_IS_SHAPE(subitem)) {
855             SPCurve * c = sp_shape_get_curve(SP_SHAPE(subitem));
856             sp_lpe_item_perform_path_effect(SP_LPE_ITEM(topgroup), c);
857             sp_shape_set_curve(SP_SHAPE(subitem), c, TRUE);
858             
859             Inkscape::XML::Node *repr = SP_OBJECT_REPR(subitem);
860  
861             gchar *str = sp_svg_write_path(c->get_pathvector());
862             repr->setAttribute("d", str);
863             g_free(str);
865             c->unref();
866         }
867     }
870 /*
871   Local Variables:
872   mode:c++
873   c-file-style:"stroustrup"
874   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
875   indent-tabs-mode:nil
876   fill-column:99
877   End:
878 */
879 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :