Code

when applying LPE to rect, convert it to path first
[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 "libnr/nr-matrix-ops.h"
27 #include "libnr/nr-matrix-fns.h"
28 #include "xml/repr.h"
29 #include "svg/svg.h"
30 #include "document.h"
31 #include "style.h"
32 #include "attributes.h"
33 #include "sp-item-transform.h"
34 #include "sp-root.h"
35 #include "sp-use.h"
36 #include "prefs-utils.h"
37 #include "sp-clippath.h"
38 #include "sp-mask.h"
39 #include "sp-path.h"
40 #include "box3d.h"
41 #include "persp3d.h"
42 #include "inkscape.h"
43 #include "desktop-handles.h"
44 #include "selection.h"
46 static void sp_group_class_init (SPGroupClass *klass);
47 static void sp_group_init (SPGroup *group);
48 static void sp_group_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
49 static void sp_group_release(SPObject *object);
50 static void sp_group_dispose(GObject *object);
52 static void sp_group_child_added (SPObject * object, Inkscape::XML::Node * child, Inkscape::XML::Node * ref);
53 static void sp_group_remove_child (SPObject * object, Inkscape::XML::Node * child);
54 static void sp_group_order_changed (SPObject * object, Inkscape::XML::Node * child, Inkscape::XML::Node * old_ref, Inkscape::XML::Node * new_ref);
55 static void sp_group_update (SPObject *object, SPCtx *ctx, guint flags);
56 static void sp_group_modified (SPObject *object, guint flags);
57 static Inkscape::XML::Node *sp_group_write (SPObject *object, Inkscape::XML::Node *repr, guint flags);
58 static void sp_group_set(SPObject *object, unsigned key, char const *value);
60 static void sp_group_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags);
61 static void sp_group_print (SPItem * item, SPPrintContext *ctx);
62 static gchar * sp_group_description (SPItem * item);
63 static NR::Matrix sp_group_set_transform(SPItem *item, NR::Matrix const &xform);
64 static NRArenaItem *sp_group_show (SPItem *item, NRArena *arena, unsigned int key, unsigned int flags);
65 static void sp_group_hide (SPItem * item, unsigned int key);
66 static void sp_group_snappoints (SPItem const *item, SnapPointsIter p);
68 static void sp_group_update_patheffect(SPLPEItem *lpeitem, bool write);
70 static SPLPEItemClass * parent_class;
72 GType
73 sp_group_get_type (void)
74 {
75         static GType group_type = 0;
76         if (!group_type) {
77                 GTypeInfo group_info = {
78                         sizeof (SPGroupClass),
79                         NULL,   /* base_init */
80                         NULL,   /* base_finalize */
81                         (GClassInitFunc) sp_group_class_init,
82                         NULL,   /* class_finalize */
83                         NULL,   /* class_data */
84                         sizeof (SPGroup),
85                         16,     /* n_preallocs */
86                         (GInstanceInitFunc) sp_group_init,
87                         NULL,   /* value_table */
88                 };
89                 group_type = g_type_register_static (SP_TYPE_LPE_ITEM, "SPGroup", &group_info, (GTypeFlags)0);
90         }
91         return group_type;
92 }
94 static void
95 sp_group_class_init (SPGroupClass *klass)
96 {
97         GObjectClass * object_class;
98         SPObjectClass * sp_object_class;
99         SPItemClass * item_class;
100         SPLPEItemClass * lpe_item_class;
102         object_class = (GObjectClass *) klass;
103         sp_object_class = (SPObjectClass *) klass;
104         item_class = (SPItemClass *) klass;
105         lpe_item_class = (SPLPEItemClass *) klass;
107         parent_class = (SPLPEItemClass *)g_type_class_ref (SP_TYPE_LPE_ITEM);
109         object_class->dispose = sp_group_dispose;
111         sp_object_class->child_added = sp_group_child_added;
112         sp_object_class->remove_child = sp_group_remove_child;
113         sp_object_class->order_changed = sp_group_order_changed;
114         sp_object_class->update = sp_group_update;
115         sp_object_class->modified = sp_group_modified;
116         sp_object_class->set = sp_group_set;
117         sp_object_class->write = sp_group_write;
118         sp_object_class->release = sp_group_release;
119         sp_object_class->build = sp_group_build;
121         item_class->bbox = sp_group_bbox;
122         item_class->print = sp_group_print;
123         item_class->description = sp_group_description;
124         item_class->set_transform = sp_group_set_transform;
125         item_class->show = sp_group_show;
126         item_class->hide = sp_group_hide;
127         item_class->snappoints = sp_group_snappoints;
128         
129         lpe_item_class->update_patheffect = sp_group_update_patheffect;
132 static void
133 sp_group_init (SPGroup *group)
135         group->_layer_mode = SPGroup::GROUP;
136     group->group = new CGroup(group);
137         new (&group->_display_modes) std::map<unsigned int, SPGroup::LayerMode>();
140 static void sp_group_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
142         sp_object_read_attr(object, "inkscape:groupmode");
144         if (((SPObjectClass *)parent_class)->build) {
145                 ((SPObjectClass *)parent_class)->build(object, document, repr);
146         }
149 static void sp_group_release(SPObject *object) {
150         if ( SP_GROUP(object)->_layer_mode == SPGroup::LAYER ) {
151                 sp_document_remove_resource(SP_OBJECT_DOCUMENT(object), "layer", object);
152         }
153         if (((SPObjectClass *)parent_class)->release) {
154                 ((SPObjectClass *)parent_class)->release(object);
155         }
158 static void
159 sp_group_dispose(GObject *object)
161         SP_GROUP(object)->_display_modes.~map();
162     delete SP_GROUP(object)->group;
165 static void
166 sp_group_child_added (SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
168         SPItem *item;
170         item = SP_ITEM (object);
172         if (((SPObjectClass *) (parent_class))->child_added)
173                 (* ((SPObjectClass *) (parent_class))->child_added) (object, child, ref);
175     SP_GROUP(object)->group->onChildAdded(child);
178 /* fixme: hide (Lauris) */
180 static void
181 sp_group_remove_child (SPObject * object, Inkscape::XML::Node * child)
183         if (((SPObjectClass *) (parent_class))->remove_child)
184                 (* ((SPObjectClass *) (parent_class))->remove_child) (object, child);
186     SP_GROUP(object)->group->onChildRemoved(child);
189 static void
190 sp_group_order_changed (SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *old_ref, Inkscape::XML::Node *new_ref)
192         if (((SPObjectClass *) (parent_class))->order_changed)
193                 (* ((SPObjectClass *) (parent_class))->order_changed) (object, child, old_ref, new_ref);
195     SP_GROUP(object)->group->onOrderChanged(child, old_ref, new_ref);
198 static void
199 sp_group_update (SPObject *object, SPCtx *ctx, unsigned int flags)
201     if (((SPObjectClass *) (parent_class))->update)
202         ((SPObjectClass *) (parent_class))->update (object, ctx, flags);
204     SP_GROUP(object)->group->onUpdate(ctx, flags);
207 static void
208 sp_group_modified (SPObject *object, guint flags)
210     SP_GROUP(object)->group->onModified(flags);
213 static Inkscape::XML::Node *
214 sp_group_write (SPObject *object, Inkscape::XML::Node *repr, guint flags)
216         SPGroup *group;
217         SPObject *child;
218         Inkscape::XML::Node *crepr;
220         group = SP_GROUP (object);
222         if (flags & SP_OBJECT_WRITE_BUILD) {
223                 GSList *l;
224                 if (!repr) {
225                     Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(object));
226                     repr = xml_doc->createElement("svg:g");
227                 }
228                 l = NULL;
229                 for (child = sp_object_first_child(object); child != NULL; child = SP_OBJECT_NEXT(child) ) {
230                         crepr = child->updateRepr(NULL, flags);
231                         if (crepr) l = g_slist_prepend (l, crepr);
232                 }
233                 while (l) {
234                         repr->addChild((Inkscape::XML::Node *) l->data, NULL);
235                         Inkscape::GC::release((Inkscape::XML::Node *) l->data);
236                         l = g_slist_remove (l, l->data);
237                 }
238         } else {
239                 for (child = sp_object_first_child(object) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
240                         child->updateRepr(flags);
241                 }
242         }
244         if ( flags & SP_OBJECT_WRITE_EXT ) {
245                 const char *value;
246                 if ( group->_layer_mode == SPGroup::LAYER ) {
247                         value = "layer";
248                 } else if ( flags & SP_OBJECT_WRITE_ALL ) {
249                         value = "group";
250                 } else {
251                         value = NULL;
252                 }
253                 repr->setAttribute("inkscape:groupmode", value);
254         }
256         if (((SPObjectClass *) (parent_class))->write)
257                 ((SPObjectClass *) (parent_class))->write (object, repr, flags);
259         return repr;
262 static void
263 sp_group_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags)
265     SP_GROUP(item)->group->calculateBBox(bbox, transform, flags);
268 static void
269 sp_group_print (SPItem * item, SPPrintContext *ctx)
271     SP_GROUP(item)->group->onPrint(ctx);
274 static gchar * sp_group_description (SPItem * item)
276     return SP_GROUP(item)->group->getDescription();
279 static NR::Matrix
280 sp_group_set_transform(SPItem *item, NR::Matrix const &xform)
282     Inkscape::Selection *selection = sp_desktop_selection(inkscape_active_desktop());
283     persp3d_split_perspectives_according_to_selection(selection);
285     NR::Matrix last_trans;
286     sp_svg_transform_read(SP_OBJECT_REPR(item)->attribute("transform"), &last_trans);
287     NR::Matrix inc_trans = last_trans.inverse()*xform;
289     std::list<Persp3D *> plist = selection->perspList();
290     for (std::list<Persp3D *>::iterator i = plist.begin(); i != plist.end(); ++i) {
291         persp3d_apply_affine_transformation(*i, inc_trans);
292     }
294     return xform;
297 static void sp_group_set(SPObject *object, unsigned key, char const *value) {
298         SPGroup *group = SP_GROUP(object);
300         switch (key) {
301                 case SP_ATTR_INKSCAPE_GROUPMODE:
302                         if ( value && !strcmp(value, "layer") ) {
303                                 group->setLayerMode(SPGroup::LAYER);
304                         } else {
305                                 group->setLayerMode(SPGroup::GROUP);
306                         }
307                     break;
308                 default: {
309                         if (((SPObjectClass *) (parent_class))->set) {
310                                 (* ((SPObjectClass *) (parent_class))->set)(object, key, value);
311                         }
312                 }
313         }
316 static NRArenaItem *
317 sp_group_show (SPItem *item, NRArena *arena, unsigned int key, unsigned int flags)
319     return SP_GROUP(item)->group->show(arena, key, flags);
322 static void
323 sp_group_hide (SPItem *item, unsigned int key)
325     SP_GROUP(item)->group->hide(key);
328 static void sp_group_snappoints (SPItem const *item, SnapPointsIter p)
330         for (SPObject const *o = sp_object_first_child(SP_OBJECT(item));
331              o != NULL;
332              o = SP_OBJECT_NEXT(o))
333         {
334                 if (SP_IS_ITEM(o)) {
335             sp_item_snappoints(SP_ITEM(o), false, p);
336                 }
337         }
341 void
342 sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done)
344         g_return_if_fail (group != NULL);
345         g_return_if_fail (SP_IS_GROUP (group));
347         SPDocument *doc = SP_OBJECT_DOCUMENT (group);
348         SPObject *root = SP_DOCUMENT_ROOT (doc);
349         SPObject *defs = SP_OBJECT (SP_ROOT (root)->defs);
351         SPItem *gitem = SP_ITEM (group);
352         Inkscape::XML::Node *grepr = SP_OBJECT_REPR (gitem);
354         g_return_if_fail (!strcmp (grepr->name(), "svg:g") || !strcmp (grepr->name(), "svg:a") || !strcmp (grepr->name(), "svg:switch"));
356       // this converts the gradient/pattern fill/stroke on the group, if any, to userSpaceOnUse
357       sp_item_adjust_paint_recursive (gitem, NR::identity(), NR::identity(), false);
359         SPItem *pitem = SP_ITEM (SP_OBJECT_PARENT (gitem));
360         Inkscape::XML::Node *prepr = SP_OBJECT_REPR (pitem);
362   if (SP_IS_BOX3D(gitem)) {
363       grepr = box3d_convert_to_group(SP_BOX3D(gitem));
364       if (grepr) {
365           gitem = SP_ITEM(doc->getObjectByRepr(grepr));
366           group = SP_GROUP(gitem);
367       }
368   }
370     sp_lpe_item_remove_path_effect(SP_LPE_ITEM(group), false);
372         /* Step 1 - generate lists of children objects */
373         GSList *items = NULL;
374         GSList *objects = NULL;
375         for (SPObject *child = sp_object_first_child(SP_OBJECT(group)) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
377                 if (SP_IS_ITEM (child)) {
379                         SPItem *citem = SP_ITEM (child);
381                         /* Merging of style */
382                         // this converts the gradient/pattern fill/stroke, if any, to userSpaceOnUse; we need to do
383                         // it here _before_ the new transform is set, so as to use the pre-transform bbox
384                         sp_item_adjust_paint_recursive (citem, NR::identity(), NR::identity(), false);
386                         sp_style_merge_from_dying_parent(SP_OBJECT_STYLE(child), SP_OBJECT_STYLE(gitem));
387                         /*
388                          * fixme: We currently make no allowance for the case where child is cloned
389                          * and the group has any style settings.
390                          *
391                          * (This should never occur with documents created solely with the current
392                          * version of inkscape without using the XML editor: we usually apply group
393                          * style changes to children rather than to the group itself.)
394                          *
395                          * If the group has no style settings, then
396                          * sp_style_merge_from_dying_parent should be a no-op.  Otherwise (i.e. if
397                          * we change the child's style to compensate for its parent going away)
398                          * then those changes will typically be reflected in any clones of child,
399                          * whereas we'd prefer for Ungroup not to affect the visual appearance.
400                          *
401                          * The only way of preserving styling appearance in general is for child to
402                          * be put into a new group -- a somewhat surprising response to an Ungroup
403                          * command.  We could add a new groupmode:transparent that would mostly
404                          * hide the existence of such groups from the user (i.e. editing behaves as
405                          * if the transparent group's children weren't in a group), though that's
406                          * extra complication & maintenance burden and this case is rare.
407                          */
409                         child->updateRepr();
411                         Inkscape::XML::Node *nrepr = SP_OBJECT_REPR (child)->duplicate(prepr->document());
413                         // Merging transform
414                         NR::Matrix ctrans;
415                         NR::Matrix const g(gitem->transform);
416                         if (SP_IS_USE(citem) && sp_use_get_original (SP_USE(citem)) &&
417                                         SP_OBJECT_PARENT (sp_use_get_original (SP_USE(citem))) == SP_OBJECT(group)) {
418                                 // make sure a clone's effective transform is the same as was under group
419                                 ctrans = g.inverse() * citem->transform * g;
420                         } else {
421                                 ctrans = citem->transform * g;
422                         }
424                         // FIXME: constructing a transform that would fully preserve the appearance of a
425                         // textpath if it is ungrouped with its path seems to be impossible in general
426                         // case. E.g. if the group was squeezed, to keep the ungrouped textpath squeezed
427                         // as well, we'll need to relink it to some "virtual" path which is inversely
428                         // stretched relative to the actual path, and then squeeze the textpath back so it
429                         // would both fit the actual path _and_ be squeezed as before. It's a bummer.
431                         // This is just a way to temporarily remember the transform in repr. When repr is
432                         // reattached outside of the group, the transform will be written more properly
433                         // (i.e. optimized into the object if the corresponding preference is set)
434                         gchar *affinestr=sp_svg_transform_write(ctrans);
435                         nrepr->setAttribute("transform", affinestr);
436                         g_free(affinestr);
438                         items = g_slist_prepend (items, nrepr);
440                 } else {
441                         Inkscape::XML::Node *nrepr = SP_OBJECT_REPR (child)->duplicate(prepr->document());
442                         objects = g_slist_prepend (objects, nrepr);
443                 }
444         }
446         /* Step 2 - clear group */
447         // remember the position of the group
448         gint pos = SP_OBJECT_REPR(group)->position();
450         // the group is leaving forever, no heir, clones should take note; its children however are going to reemerge
451         SP_OBJECT (group)->deleteObject(true, false);
453         /* Step 3 - add nonitems */
454         if (objects) {
455             Inkscape::XML::Node *last_def = SP_OBJECT_REPR(defs)->lastChild();
456             while (objects) {
457                 SP_OBJECT_REPR(defs)->addChild((Inkscape::XML::Node *) objects->data, last_def);
458                 Inkscape::GC::release((Inkscape::XML::Node *) objects->data);
459                 objects = g_slist_remove (objects, objects->data);
460             }
461         }
463         /* Step 4 - add items */
464         while (items) {
465                 Inkscape::XML::Node *repr = (Inkscape::XML::Node *) items->data;
466                 // add item
467                 prepr->appendChild(repr);
468                 // restore position; since the items list was prepended (i.e. reverse), we now add
469                 // all children at the same pos, which inverts the order once again
470                 repr->setPosition(pos > 0 ? pos : 0);
472                 // fill in the children list if non-null
473                 SPItem *item = (SPItem *) doc->getObjectByRepr(repr);
475                 sp_item_write_transform(item, repr, item->transform, NULL, false);
476                 
477                 Inkscape::GC::release(repr);
478                 if (children && SP_IS_ITEM (item))
479                         *children = g_slist_prepend (*children, item);
481                 items = g_slist_remove (items, items->data);
482         }
484         if (do_done) 
485                 sp_document_done (doc, SP_VERB_NONE, _("Ungroup"));
488 /*
489  * some API for list aspect of SPGroup
490  */
492 GSList *
493 sp_item_group_item_list (SPGroup * group)
495         GSList *s;
496         SPObject *o;
498         g_return_val_if_fail (group != NULL, NULL);
499         g_return_val_if_fail (SP_IS_GROUP (group), NULL);
501         s = NULL;
503         for ( o = sp_object_first_child(SP_OBJECT(group)) ; o != NULL ; o = SP_OBJECT_NEXT(o) ) {
504                 if (SP_IS_ITEM (o)) {
505                         s = g_slist_prepend (s, o);
506                 }
507         }
509         return g_slist_reverse (s);
512 SPObject *
513 sp_item_group_get_child_by_name (SPGroup *group, SPObject *ref, const gchar *name)
515         SPObject *child;
516         child = (ref) ? SP_OBJECT_NEXT(ref) : sp_object_first_child(SP_OBJECT(group));
517         while ( child && strcmp (SP_OBJECT_REPR(child)->name(), name) ) {
518                 child = SP_OBJECT_NEXT(child);
519         }
520         return child;
523 void SPGroup::setLayerMode(LayerMode mode) {
524         if ( _layer_mode != mode ) {
525                 if ( mode == LAYER ) {
526                         sp_document_add_resource(SP_OBJECT_DOCUMENT(this), "layer", this);
527                 } else {
528                         sp_document_remove_resource(SP_OBJECT_DOCUMENT(this), "layer", this);
529                 }
530                 _layer_mode = mode;
531                 _updateLayerMode();
532         }
535 SPGroup::LayerMode SPGroup::layerDisplayMode(unsigned int dkey) const {
536         std::map<unsigned int, LayerMode>::const_iterator iter;
537         iter = _display_modes.find(dkey);
538         if ( iter != _display_modes.end() ) {
539                 return (*iter).second;
540         } else {
541                 return GROUP;
542         }
545 void SPGroup::setLayerDisplayMode(unsigned int dkey, SPGroup::LayerMode mode) {
546         if ( layerDisplayMode(dkey) != mode ) {
547                 _display_modes[dkey] = mode;
548                 _updateLayerMode(dkey);
549         }
552 void SPGroup::_updateLayerMode(unsigned int display_key) {
553         SPItemView *view;
554         for ( view = this->display ; view ; view = view->next ) {
555                 if ( !display_key || view->key == display_key ) {
556                         NRArenaGroup *arena_group=NR_ARENA_GROUP(view->arenaitem);
557                         if (arena_group) {
558                                 nr_arena_group_set_transparent(arena_group, effectiveLayerMode(view->key) == SPGroup::LAYER);
559                         }
560                 }
561         }
564 void SPGroup::translateChildItems(NR::translate const &tr)
566         if (this->hasChildren())
567         {
568                 SPObject *o = NULL;
569                 for (o = sp_object_first_child(SP_OBJECT(this)) ; o != NULL ; o = SP_OBJECT_NEXT(o) ) {
570                         if (SP_IS_ITEM (o)) {
571                                 sp_item_move_rel(static_cast<SPItem *>(o), tr);
572                         }
573                 }
574         }
577 CGroup::CGroup(SPGroup *group) {
578     _group = group;
581 CGroup::~CGroup() {
584 void CGroup::onChildAdded(Inkscape::XML::Node *child) {
585     SPObject *last_child = _group->lastChild();
586     if (last_child && SP_OBJECT_REPR(last_child) == child) {
587         // optimization for the common special case where the child is being added at the end
588         SPObject *ochild = last_child;
589         if ( SP_IS_ITEM(ochild) ) {
590             /* TODO: this should be moved into SPItem somehow */
591             SPItemView *v;
592             NRArenaItem *ac;
594             for (v = _group->display; v != NULL; v = v->next) {
595                 ac = sp_item_invoke_show (SP_ITEM (ochild), NR_ARENA_ITEM_ARENA (v->arenaitem), v->key, v->flags);
597                 if (ac) {
598                     nr_arena_item_append_child (v->arenaitem, ac);
599                     nr_arena_item_unref (ac);
600                 }
601             }
602         }
603     } else {    // general case
604         SPObject *ochild = sp_object_get_child_by_repr(_group, child);
605         if ( ochild && SP_IS_ITEM(ochild) ) {
606             /* TODO: this should be moved into SPItem somehow */
607             SPItemView *v;
608             NRArenaItem *ac;
610             unsigned position = sp_item_pos_in_parent(SP_ITEM(ochild));
612             for (v = _group->display; v != NULL; v = v->next) {
613                 ac = sp_item_invoke_show (SP_ITEM (ochild), NR_ARENA_ITEM_ARENA (v->arenaitem), v->key, v->flags);
615                 if (ac) {
616                     nr_arena_item_add_child (v->arenaitem, ac, NULL);
617                     nr_arena_item_set_order (ac, position);
618                     nr_arena_item_unref (ac);
619                 }
620             }
621         }
622     }
624     _group->requestModified(SP_OBJECT_MODIFIED_FLAG);
627 void CGroup::onChildRemoved(Inkscape::XML::Node */*child*/) {
628     _group->requestModified(SP_OBJECT_MODIFIED_FLAG);
631 void CGroup::onUpdate(SPCtx *ctx, unsigned int flags) {    
632     SPItemCtx *ictx, cctx;
634     ictx = (SPItemCtx *) ctx;
635     cctx = *ictx;
637     if (flags & SP_OBJECT_MODIFIED_FLAG) {
638       flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
639     }
641     flags &= SP_OBJECT_MODIFIED_CASCADE;
643     if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) {
644       SPObject *object = SP_OBJECT(_group);
645       for (SPItemView *v = SP_ITEM(_group)->display; v != NULL; v = v->next) {
646         nr_arena_group_set_style(NR_ARENA_GROUP(v->arenaitem), SP_OBJECT_STYLE(object));
647       }
648     }
650     GSList *l = g_slist_reverse(_group->childList(true, SPObject::ActionUpdate));
651     while (l) {
652         SPObject *child = SP_OBJECT (l->data);
653         l = g_slist_remove (l, child);
654         if (flags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
655             if (SP_IS_ITEM (child)) {
656                 SPItem const &chi = *SP_ITEM(child);
657                 cctx.i2doc = chi.transform * ictx->i2doc;
658                 cctx.i2vp = chi.transform * ictx->i2vp;
659                 child->updateDisplay((SPCtx *)&cctx, flags);
660             } else {
661                 child->updateDisplay(ctx, flags);
662             }
663         }
664         g_object_unref (G_OBJECT (child));
665     }
668 void CGroup::onModified(guint flags) {
669     SPObject *child;
671     if (flags & SP_OBJECT_MODIFIED_FLAG) flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
672     flags &= SP_OBJECT_MODIFIED_CASCADE;
674     if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) {
675       SPObject *object = SP_OBJECT(_group);
676       for (SPItemView *v = SP_ITEM(_group)->display; v != NULL; v = v->next) {
677         nr_arena_group_set_style(NR_ARENA_GROUP(v->arenaitem), SP_OBJECT_STYLE(object));
678       }
679     }
681     GSList *l = g_slist_reverse(_group->childList(true));
682     while (l) {
683         child = SP_OBJECT (l->data);
684         l = g_slist_remove (l, child);
685         if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
686             child->emitModified(flags);
687         }
688         g_object_unref (G_OBJECT (child));
689     }
692 void CGroup::calculateBBox(NRRect *bbox, NR::Matrix const &transform, unsigned const flags) {
693     
694     NR::Maybe<NR::Rect> dummy_bbox = NR::Nothing();
695     
696     GSList *l = _group->childList(false, SPObject::ActionBBox);
697     while (l) {
698         SPObject *o = SP_OBJECT (l->data);
699         if (SP_IS_ITEM(o)) {
700             SPItem *child = SP_ITEM(o);
701             NR::Matrix const ct(child->transform * transform);
702             sp_item_invoke_bbox_full(child, &dummy_bbox, ct, flags, FALSE);
703         }        
704         l = g_slist_remove (l, o);
705     }
706     
707     *bbox = NRRect(dummy_bbox);
710 void CGroup::onPrint(SPPrintContext *ctx) {
711     GSList *l = g_slist_reverse(_group->childList(false));
712     while (l) {
713         SPObject *o = SP_OBJECT (l->data);
714         if (SP_IS_ITEM(o)) {
715             sp_item_invoke_print (SP_ITEM (o), ctx);
716         }        
717         l = g_slist_remove (l, o);
718     }
721 gint CGroup::getItemCount() {
722     gint len = 0;
723     for (SPObject *o = sp_object_first_child(SP_OBJECT(_group)) ; o != NULL ; o = SP_OBJECT_NEXT(o) ) {
724         if (SP_IS_ITEM(o)) {
725             len++;
726         }
727     }
728     
729     return len;
732 gchar *CGroup::getDescription() {
733     gint len = getItemCount();
734     return g_strdup_printf(
735             ngettext("<b>Group</b> of <b>%d</b> object",
736                  "<b>Group</b> of <b>%d</b> objects",
737                  len), len);
740 NRArenaItem *CGroup::show (NRArena *arena, unsigned int key, unsigned int flags) {
741     NRArenaItem *ai;
742     SPObject *object = SP_OBJECT(_group);
744     ai = NRArenaGroup::create(arena);
746     nr_arena_group_set_transparent(NR_ARENA_GROUP (ai),
747                                    _group->effectiveLayerMode(key) ==
748                          SPGroup::LAYER);
749     nr_arena_group_set_style(NR_ARENA_GROUP(ai), SP_OBJECT_STYLE(object));
751     _showChildren(arena, ai, key, flags);
752     return ai;
755 void CGroup::_showChildren (NRArena *arena, NRArenaItem *ai, unsigned int key, unsigned int flags) {
756     NRArenaItem *ac = NULL;
757     NRArenaItem *ar = NULL;
758     SPItem * child = NULL;
759     GSList *l = g_slist_reverse(_group->childList(false, SPObject::ActionShow));
760     while (l) {
761         SPObject *o = SP_OBJECT (l->data);
762         if (SP_IS_ITEM (o)) {
763             child = SP_ITEM (o);
764             ac = sp_item_invoke_show (child, arena, key, flags);
765             if (ac) {
766                 nr_arena_item_add_child (ai, ac, ar);
767                 ar = ac;
768                 nr_arena_item_unref (ac);
769             }
770         }
771         l = g_slist_remove (l, o);
772     }
775 void CGroup::hide (unsigned int key) {
776     SPItem * child;
778     GSList *l = g_slist_reverse(_group->childList(false, SPObject::ActionShow));
779     while (l) {
780         SPObject *o = SP_OBJECT (l->data);
781         if (SP_IS_ITEM (o)) {
782             child = SP_ITEM (o);
783             sp_item_invoke_hide (child, key);
784         }
785         l = g_slist_remove (l, o);
786     }
788     if (((SPItemClass *) parent_class)->hide)
789         ((SPItemClass *) parent_class)->hide (_group, key);
792 void CGroup::onOrderChanged (Inkscape::XML::Node *child, Inkscape::XML::Node *, Inkscape::XML::Node *)
794     SPObject *ochild = sp_object_get_child_by_repr(_group, child);
795     if ( ochild && SP_IS_ITEM(ochild) ) {
796         /* TODO: this should be moved into SPItem somehow */
797         SPItemView *v;
798         unsigned position = sp_item_pos_in_parent(SP_ITEM(ochild));
799         for ( v = SP_ITEM (ochild)->display ; v != NULL ; v = v->next ) {
800             nr_arena_item_set_order (v->arenaitem, position);
801         }
802     }
804     _group->requestModified(SP_OBJECT_MODIFIED_FLAG);
807 static void
808 sp_group_update_patheffect (SPLPEItem *lpeitem, bool write)
810 #ifdef GROUP_VERBOSE
811     g_message("sp_group_update_patheffect: %p\n", lpeitem);
812 #endif
813     g_return_if_fail (lpeitem != NULL);
814     g_return_if_fail (SP_IS_GROUP (lpeitem));
816     GSList const *item_list = sp_item_group_item_list(SP_GROUP(lpeitem));
817     for ( GSList const *iter = item_list; iter; iter = iter->next ) {
818         SPObject *subitem = static_cast<SPObject *>(iter->data);
819         if (SP_IS_LPE_ITEM(subitem)) {
820             sp_lpe_item_update_patheffect(SP_LPE_ITEM(subitem), true);
821         }
822     }
826 /*
827   Local Variables:
828   mode:c++
829   c-file-style:"stroustrup"
830   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
831   indent-tabs-mode:nil
832   fill-column:99
833   End:
834 */
835 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :