Code

The deprecated version of sp_item_invoke_bbox_full (which still uses NRRects) returns...
[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 SPItemClass * parent_class;
70 GType
71 sp_group_get_type (void)
72 {
73         static GType group_type = 0;
74         if (!group_type) {
75                 GTypeInfo group_info = {
76                         sizeof (SPGroupClass),
77                         NULL,   /* base_init */
78                         NULL,   /* base_finalize */
79                         (GClassInitFunc) sp_group_class_init,
80                         NULL,   /* class_finalize */
81                         NULL,   /* class_data */
82                         sizeof (SPGroup),
83                         16,     /* n_preallocs */
84                         (GInstanceInitFunc) sp_group_init,
85                         NULL,   /* value_table */
86                 };
87                 group_type = g_type_register_static (SP_TYPE_ITEM, "SPGroup", &group_info, (GTypeFlags)0);
88         }
89         return group_type;
90 }
92 static void
93 sp_group_class_init (SPGroupClass *klass)
94 {
95         GObjectClass * object_class;
96         SPObjectClass * sp_object_class;
97         SPItemClass * item_class;
99         object_class = (GObjectClass *) klass;
100         sp_object_class = (SPObjectClass *) klass;
101         item_class = (SPItemClass *) klass;
103         parent_class = (SPItemClass *)g_type_class_ref (SP_TYPE_ITEM);
105         object_class->dispose = sp_group_dispose;
107         sp_object_class->child_added = sp_group_child_added;
108         sp_object_class->remove_child = sp_group_remove_child;
109         sp_object_class->order_changed = sp_group_order_changed;
110         sp_object_class->update = sp_group_update;
111         sp_object_class->modified = sp_group_modified;
112         sp_object_class->set = sp_group_set;
113         sp_object_class->write = sp_group_write;
114         sp_object_class->release = sp_group_release;
115         sp_object_class->build = sp_group_build;
117         item_class->bbox = sp_group_bbox;
118         item_class->print = sp_group_print;
119         item_class->description = sp_group_description;
120         item_class->set_transform = sp_group_set_transform;
121         item_class->show = sp_group_show;
122         item_class->hide = sp_group_hide;
123         item_class->snappoints = sp_group_snappoints;
126 static void
127 sp_group_init (SPGroup *group)
129         group->_layer_mode = SPGroup::GROUP;
130     group->group = new CGroup(group);
131         new (&group->_display_modes) std::map<unsigned int, SPGroup::LayerMode>();
134 static void sp_group_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
136         sp_object_read_attr(object, "inkscape:groupmode");
138         if (((SPObjectClass *)parent_class)->build) {
139                 ((SPObjectClass *)parent_class)->build(object, document, repr);
140         }
143 static void sp_group_release(SPObject *object) {
144         if ( SP_GROUP(object)->_layer_mode == SPGroup::LAYER ) {
145                 sp_document_remove_resource(SP_OBJECT_DOCUMENT(object), "layer", object);
146         }
147         if (((SPObjectClass *)parent_class)->release) {
148                 ((SPObjectClass *)parent_class)->release(object);
149         }
152 static void
153 sp_group_dispose(GObject *object)
155         SP_GROUP(object)->_display_modes.~map();
156     delete SP_GROUP(object)->group;
159 static void
160 sp_group_child_added (SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
162         SPItem *item;
164         item = SP_ITEM (object);
166         if (((SPObjectClass *) (parent_class))->child_added)
167                 (* ((SPObjectClass *) (parent_class))->child_added) (object, child, ref);
169     SP_GROUP(object)->group->onChildAdded(child);
172 /* fixme: hide (Lauris) */
174 static void
175 sp_group_remove_child (SPObject * object, Inkscape::XML::Node * child)
177         if (((SPObjectClass *) (parent_class))->remove_child)
178                 (* ((SPObjectClass *) (parent_class))->remove_child) (object, child);
180     SP_GROUP(object)->group->onChildRemoved(child);
183 static void
184 sp_group_order_changed (SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *old_ref, Inkscape::XML::Node *new_ref)
186         if (((SPObjectClass *) (parent_class))->order_changed)
187                 (* ((SPObjectClass *) (parent_class))->order_changed) (object, child, old_ref, new_ref);
189     SP_GROUP(object)->group->onOrderChanged(child, old_ref, new_ref);
192 static void
193 sp_group_update (SPObject *object, SPCtx *ctx, unsigned int flags)
195     if (((SPObjectClass *) (parent_class))->update)
196         ((SPObjectClass *) (parent_class))->update (object, ctx, flags);
198     SP_GROUP(object)->group->onUpdate(ctx, flags);
201 static void
202 sp_group_modified (SPObject *object, guint flags)
204     SP_GROUP(object)->group->onModified(flags);
207 static Inkscape::XML::Node *
208 sp_group_write (SPObject *object, Inkscape::XML::Node *repr, guint flags)
210         SPGroup *group;
211         SPObject *child;
212         Inkscape::XML::Node *crepr;
214         group = SP_GROUP (object);
216         if (flags & SP_OBJECT_WRITE_BUILD) {
217                 GSList *l;
218                 if (!repr) {
219                     Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(object));
220                     repr = xml_doc->createElement("svg:g");
221                 }
222                 l = NULL;
223                 for (child = sp_object_first_child(object); child != NULL; child = SP_OBJECT_NEXT(child) ) {
224                         crepr = child->updateRepr(NULL, flags);
225                         if (crepr) l = g_slist_prepend (l, crepr);
226                 }
227                 while (l) {
228                         repr->addChild((Inkscape::XML::Node *) l->data, NULL);
229                         Inkscape::GC::release((Inkscape::XML::Node *) l->data);
230                         l = g_slist_remove (l, l->data);
231                 }
232         } else {
233                 for (child = sp_object_first_child(object) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
234                         child->updateRepr(flags);
235                 }
236         }
238         if ( flags & SP_OBJECT_WRITE_EXT ) {
239                 const char *value;
240                 if ( group->_layer_mode == SPGroup::LAYER ) {
241                         value = "layer";
242                 } else if ( flags & SP_OBJECT_WRITE_ALL ) {
243                         value = "group";
244                 } else {
245                         value = NULL;
246                 }
247                 repr->setAttribute("inkscape:groupmode", value);
248         }
250         if (((SPObjectClass *) (parent_class))->write)
251                 ((SPObjectClass *) (parent_class))->write (object, repr, flags);
253         return repr;
256 static void
257 sp_group_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags)
259     SP_GROUP(item)->group->calculateBBox(bbox, transform, flags);
262 static void
263 sp_group_print (SPItem * item, SPPrintContext *ctx)
265     SP_GROUP(item)->group->onPrint(ctx);
268 static gchar * sp_group_description (SPItem * item)
270     return SP_GROUP(item)->group->getDescription();
273 static NR::Matrix
274 sp_group_set_transform(SPItem *item, NR::Matrix const &xform)
276     Inkscape::Selection *selection = sp_desktop_selection(inkscape_active_desktop());
277     persp3d_split_perspectives_according_to_selection(selection);
279     NR::Matrix last_trans;
280     sp_svg_transform_read(SP_OBJECT_REPR(item)->attribute("transform"), &last_trans);
281     NR::Matrix inc_trans = last_trans.inverse()*xform;
283     std::list<Persp3D *> plist = selection->perspList();
284     for (std::list<Persp3D *>::iterator i = plist.begin(); i != plist.end(); ++i) {
285         persp3d_apply_affine_transformation(*i, inc_trans);
286     }
288     return xform;
291 static void sp_group_set(SPObject *object, unsigned key, char const *value) {
292         SPGroup *group=SP_GROUP(object);
294         switch (key) {
295                 case SP_ATTR_INKSCAPE_GROUPMODE: {
296                         if ( value && !strcmp(value, "layer") ) {
297                                 group->setLayerMode(SPGroup::LAYER);
298                         } else {
299                                 group->setLayerMode(SPGroup::GROUP);
300                         }
301                 } break;
302                 default: {
303                         if (((SPObjectClass *) (parent_class))->set) {
304                                 (* ((SPObjectClass *) (parent_class))->set)(object, key, value);
305                         }
306                 }
307         }
310 static NRArenaItem *
311 sp_group_show (SPItem *item, NRArena *arena, unsigned int key, unsigned int flags)
313     return SP_GROUP(item)->group->show(arena, key, flags);
316 static void
317 sp_group_hide (SPItem *item, unsigned int key)
319     SP_GROUP(item)->group->hide(key);
322 static void sp_group_snappoints (SPItem const *item, SnapPointsIter p)
324         for (SPObject const *o = sp_object_first_child(SP_OBJECT(item));
325              o != NULL;
326              o = SP_OBJECT_NEXT(o))
327         {
328                 if (SP_IS_ITEM(o)) {
329             sp_item_snappoints(SP_ITEM(o), false, p);
330                 }
331         }
335 void
336 sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done)
338         g_return_if_fail (group != NULL);
339         g_return_if_fail (SP_IS_GROUP (group));
341         SPDocument *doc = SP_OBJECT_DOCUMENT (group);
342         SPObject *root = SP_DOCUMENT_ROOT (doc);
343         SPObject *defs = SP_OBJECT (SP_ROOT (root)->defs);
345         SPItem *gitem = SP_ITEM (group);
346         Inkscape::XML::Node *grepr = SP_OBJECT_REPR (gitem);
348         g_return_if_fail (!strcmp (grepr->name(), "svg:g") || !strcmp (grepr->name(), "svg:a") || !strcmp (grepr->name(), "svg:switch"));
350       // this converts the gradient/pattern fill/stroke on the group, if any, to userSpaceOnUse
351       sp_item_adjust_paint_recursive (gitem, NR::identity(), NR::identity(), false);
353         SPItem *pitem = SP_ITEM (SP_OBJECT_PARENT (gitem));
354         Inkscape::XML::Node *prepr = SP_OBJECT_REPR (pitem);
356   if (SP_IS_BOX3D(gitem)) {
357       grepr = box3d_convert_to_group(SP_BOX3D(gitem));
358       if (grepr) {
359           gitem = SP_ITEM(doc->getObjectByRepr(grepr));
360           group = SP_GROUP(gitem);
361       }
362   }
364         /* Step 1 - generate lists of children objects */
365         GSList *items = NULL;
366         GSList *objects = NULL;
367         for (SPObject *child = sp_object_first_child(SP_OBJECT(group)) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
369                 if (SP_IS_ITEM (child)) {
371                         SPItem *citem = SP_ITEM (child);
373                         /* Merging of style */
374                         // this converts the gradient/pattern fill/stroke, if any, to userSpaceOnUse; we need to do
375                         // it here _before_ the new transform is set, so as to use the pre-transform bbox
376                         sp_item_adjust_paint_recursive (citem, NR::identity(), NR::identity(), false);
378                         sp_style_merge_from_dying_parent(SP_OBJECT_STYLE(child), SP_OBJECT_STYLE(gitem));
379                         /*
380                          * fixme: We currently make no allowance for the case where child is cloned
381                          * and the group has any style settings.
382                          *
383                          * (This should never occur with documents created solely with the current
384                          * version of inkscape without using the XML editor: we usually apply group
385                          * style changes to children rather than to the group itself.)
386                          *
387                          * If the group has no style settings, then
388                          * sp_style_merge_from_dying_parent should be a no-op.  Otherwise (i.e. if
389                          * we change the child's style to compensate for its parent going away)
390                          * then those changes will typically be reflected in any clones of child,
391                          * whereas we'd prefer for Ungroup not to affect the visual appearance.
392                          *
393                          * The only way of preserving styling appearance in general is for child to
394                          * be put into a new group -- a somewhat surprising response to an Ungroup
395                          * command.  We could add a new groupmode:transparent that would mostly
396                          * hide the existence of such groups from the user (i.e. editing behaves as
397                          * if the transparent group's children weren't in a group), though that's
398                          * extra complication & maintenance burden and this case is rare.
399                          */
401                         child->updateRepr();
403                         Inkscape::XML::Node *nrepr = SP_OBJECT_REPR (child)->duplicate(prepr->document());
405                         // Merging transform
406                         NR::Matrix ctrans;
407                         NR::Matrix const g(gitem->transform);
408                         if (SP_IS_USE(citem) && sp_use_get_original (SP_USE(citem)) &&
409                                         SP_OBJECT_PARENT (sp_use_get_original (SP_USE(citem))) == SP_OBJECT(group)) {
410                                 // make sure a clone's effective transform is the same as was under group
411                                 ctrans = g.inverse() * citem->transform * g;
412                         } else {
413                                 ctrans = citem->transform * g;
414                         }
416                         // FIXME: constructing a transform that would fully preserve the appearance of a
417                         // textpath if it is ungrouped with its path seems to be impossible in general
418                         // case. E.g. if the group was squeezed, to keep the ungrouped textpath squeezed
419                         // as well, we'll need to relink it to some "virtual" path which is inversely
420                         // stretched relative to the actual path, and then squeeze the textpath back so it
421                         // would both fit the actual path _and_ be squeezed as before. It's a bummer.
423                         // This is just a way to temporarily remember the transform in repr. When repr is
424                         // reattached outside of the group, the transform will be written more properly
425                         // (i.e. optimized into the object if the corresponding preference is set)
426                         gchar *affinestr=sp_svg_transform_write(ctrans);
427                         nrepr->setAttribute("transform", affinestr);
428                         g_free(affinestr);
430                         items = g_slist_prepend (items, nrepr);
432                 } else {
433                         Inkscape::XML::Node *nrepr = SP_OBJECT_REPR (child)->duplicate(prepr->document());
434                         objects = g_slist_prepend (objects, nrepr);
435                 }
436         }
438         /* Step 2 - clear group */
439         // remember the position of the group
440         gint pos = SP_OBJECT_REPR(group)->position();
442         // the group is leaving forever, no heir, clones should take note; its children however are going to reemerge
443         SP_OBJECT (group)->deleteObject(true, false);
445         /* Step 3 - add nonitems */
446         if (objects) {
447             Inkscape::XML::Node *last_def = SP_OBJECT_REPR(defs)->lastChild();
448             while (objects) {
449                 SP_OBJECT_REPR(defs)->addChild((Inkscape::XML::Node *) objects->data, last_def);
450                 Inkscape::GC::release((Inkscape::XML::Node *) objects->data);
451                 objects = g_slist_remove (objects, objects->data);
452             }
453         }
455         /* Step 4 - add items */
456         while (items) {
457                 Inkscape::XML::Node *repr = (Inkscape::XML::Node *) items->data;
458                 // add item
459                 prepr->appendChild(repr);
460                 // restore position; since the items list was prepended (i.e. reverse), we now add
461                 // all children at the same pos, which inverts the order once again
462                 repr->setPosition(pos > 0 ? pos : 0);
464                 // fill in the children list if non-null
465                 SPItem *item = (SPItem *) doc->getObjectByRepr(repr);
467                 sp_item_write_transform(item, repr, item->transform, NULL, false);
468                 
469                 Inkscape::GC::release(repr);
470                 if (children && SP_IS_ITEM (item))
471                         *children = g_slist_prepend (*children, item);
473                 items = g_slist_remove (items, items->data);
474         }
476         if (do_done) 
477                 sp_document_done (doc, SP_VERB_NONE, _("Ungroup"));
480 /*
481  * some API for list aspect of SPGroup
482  */
484 GSList *
485 sp_item_group_item_list (SPGroup * group)
487         GSList *s;
488         SPObject *o;
490         g_return_val_if_fail (group != NULL, NULL);
491         g_return_val_if_fail (SP_IS_GROUP (group), NULL);
493         s = NULL;
495         for ( o = sp_object_first_child(SP_OBJECT(group)) ; o != NULL ; o = SP_OBJECT_NEXT(o) ) {
496                 if (SP_IS_ITEM (o)) {
497                         s = g_slist_prepend (s, o);
498                 }
499         }
501         return g_slist_reverse (s);
504 SPObject *
505 sp_item_group_get_child_by_name (SPGroup *group, SPObject *ref, const gchar *name)
507         SPObject *child;
508         child = (ref) ? SP_OBJECT_NEXT(ref) : sp_object_first_child(SP_OBJECT(group));
509         while ( child && strcmp (SP_OBJECT_REPR(child)->name(), name) ) {
510                 child = SP_OBJECT_NEXT(child);
511         }
512         return child;
515 void SPGroup::setLayerMode(LayerMode mode) {
516         if ( _layer_mode != mode ) {
517                 if ( mode == LAYER ) {
518                         sp_document_add_resource(SP_OBJECT_DOCUMENT(this), "layer", this);
519                 } else {
520                         sp_document_remove_resource(SP_OBJECT_DOCUMENT(this), "layer", this);
521                 }
522                 _layer_mode = mode;
523                 _updateLayerMode();
524         }
527 SPGroup::LayerMode SPGroup::layerDisplayMode(unsigned int dkey) const {
528         std::map<unsigned int, LayerMode>::const_iterator iter;
529         iter = _display_modes.find(dkey);
530         if ( iter != _display_modes.end() ) {
531                 return (*iter).second;
532         } else {
533                 return GROUP;
534         }
537 void SPGroup::setLayerDisplayMode(unsigned int dkey, SPGroup::LayerMode mode) {
538         if ( layerDisplayMode(dkey) != mode ) {
539                 _display_modes[dkey] = mode;
540                 _updateLayerMode(dkey);
541         }
544 void SPGroup::_updateLayerMode(unsigned int display_key) {
545         SPItemView *view;
546         for ( view = this->display ; view ; view = view->next ) {
547                 if ( !display_key || view->key == display_key ) {
548                         NRArenaGroup *arena_group=NR_ARENA_GROUP(view->arenaitem);
549                         if (arena_group) {
550                                 nr_arena_group_set_transparent(arena_group, effectiveLayerMode(view->key) == SPGroup::LAYER);
551                         }
552                 }
553         }
556 void SPGroup::translateChildItems(NR::translate const &tr)
558         if (this->hasChildren())
559         {
560                 SPObject *o = NULL;
561                 for (o = sp_object_first_child(SP_OBJECT(this)) ; o != NULL ; o = SP_OBJECT_NEXT(o) ) {
562                         if (SP_IS_ITEM (o)) {
563                                 sp_item_move_rel(static_cast<SPItem *>(o), tr);
564                         }
565                 }
566         }
569 CGroup::CGroup(SPGroup *group) {
570     _group = group;
573 CGroup::~CGroup() {
576 void CGroup::onChildAdded(Inkscape::XML::Node *child) {
577     SPObject *last_child = _group->lastChild();
578     if (last_child && SP_OBJECT_REPR(last_child) == child) {
579         // optimization for the common special case where the child is being added at the end
580         SPObject *ochild = last_child;
581         if ( SP_IS_ITEM(ochild) ) {
582             /* TODO: this should be moved into SPItem somehow */
583             SPItemView *v;
584             NRArenaItem *ac;
586             for (v = _group->display; v != NULL; v = v->next) {
587                 ac = sp_item_invoke_show (SP_ITEM (ochild), NR_ARENA_ITEM_ARENA (v->arenaitem), v->key, v->flags);
589                 if (ac) {
590                     nr_arena_item_append_child (v->arenaitem, ac);
591                     nr_arena_item_unref (ac);
592                 }
593             }
594         }
595     } else {    // general case
596         SPObject *ochild = sp_object_get_child_by_repr(_group, child);
597         if ( ochild && SP_IS_ITEM(ochild) ) {
598             /* TODO: this should be moved into SPItem somehow */
599             SPItemView *v;
600             NRArenaItem *ac;
602             unsigned position = sp_item_pos_in_parent(SP_ITEM(ochild));
604             for (v = _group->display; v != NULL; v = v->next) {
605                 ac = sp_item_invoke_show (SP_ITEM (ochild), NR_ARENA_ITEM_ARENA (v->arenaitem), v->key, v->flags);
607                 if (ac) {
608                     nr_arena_item_add_child (v->arenaitem, ac, NULL);
609                     nr_arena_item_set_order (ac, position);
610                     nr_arena_item_unref (ac);
611                 }
612             }
613         }
614     }
616     _group->requestModified(SP_OBJECT_MODIFIED_FLAG);
619 void CGroup::onChildRemoved(Inkscape::XML::Node */*child*/) {
620     _group->requestModified(SP_OBJECT_MODIFIED_FLAG);
623 void CGroup::onUpdate(SPCtx *ctx, unsigned int flags) {    
624     SPItemCtx *ictx, cctx;
626     ictx = (SPItemCtx *) ctx;
627     cctx = *ictx;
629     if (flags & SP_OBJECT_MODIFIED_FLAG) {
630       flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
631     }
633     flags &= SP_OBJECT_MODIFIED_CASCADE;
635     if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) {
636       SPObject *object = SP_OBJECT(_group);
637       for (SPItemView *v = SP_ITEM(_group)->display; v != NULL; v = v->next) {
638         nr_arena_group_set_style(NR_ARENA_GROUP(v->arenaitem), SP_OBJECT_STYLE(object));
639       }
640     }
642     GSList *l = g_slist_reverse(_group->childList(true, SPObject::ActionUpdate));
643     while (l) {
644         SPObject *child = SP_OBJECT (l->data);
645         l = g_slist_remove (l, child);
646         if (flags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
647             if (SP_IS_ITEM (child)) {
648                 SPItem const &chi = *SP_ITEM(child);
649                 cctx.i2doc = chi.transform * ictx->i2doc;
650                 cctx.i2vp = chi.transform * ictx->i2vp;
651                 child->updateDisplay((SPCtx *)&cctx, flags);
652             } else {
653                 child->updateDisplay(ctx, flags);
654             }
655         }
656         g_object_unref (G_OBJECT (child));
657     }
660 void CGroup::onModified(guint flags) {
661     SPObject *child;
663     if (flags & SP_OBJECT_MODIFIED_FLAG) flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
664     flags &= SP_OBJECT_MODIFIED_CASCADE;
666     if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) {
667       SPObject *object = SP_OBJECT(_group);
668       for (SPItemView *v = SP_ITEM(_group)->display; v != NULL; v = v->next) {
669         nr_arena_group_set_style(NR_ARENA_GROUP(v->arenaitem), SP_OBJECT_STYLE(object));
670       }
671     }
673     GSList *l = g_slist_reverse(_group->childList(true));
674     while (l) {
675         child = SP_OBJECT (l->data);
676         l = g_slist_remove (l, child);
677         if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
678             child->emitModified(flags);
679         }
680         g_object_unref (G_OBJECT (child));
681     }
684 void CGroup::calculateBBox(NRRect *bbox, NR::Matrix const &transform, unsigned const flags) {
685     
686     NR::Maybe<NR::Rect> dummy_bbox = NR::Nothing();
687     
688     GSList *l = _group->childList(false, SPObject::ActionBBox);
689     while (l) {
690         SPObject *o = SP_OBJECT (l->data);
691         if (SP_IS_ITEM(o)) {
692             SPItem *child = SP_ITEM(o);
693             NR::Matrix const ct(child->transform * transform);
694             sp_item_invoke_bbox_full(child, &dummy_bbox, ct, flags, FALSE);
695         }        
696         l = g_slist_remove (l, o);
697     }
698     
699     *bbox = NRRect(dummy_bbox);
702 void CGroup::onPrint(SPPrintContext *ctx) {
703     GSList *l = g_slist_reverse(_group->childList(false));
704     while (l) {
705         SPObject *o = SP_OBJECT (l->data);
706         if (SP_IS_ITEM(o)) {
707             sp_item_invoke_print (SP_ITEM (o), ctx);
708         }        
709         l = g_slist_remove (l, o);
710     }
713 gint CGroup::getItemCount() {
714     gint len = 0;
715     for (SPObject *o = sp_object_first_child(SP_OBJECT(_group)) ; o != NULL ; o = SP_OBJECT_NEXT(o) ) {
716         if (SP_IS_ITEM(o)) {
717             len++;
718         }
719     }
720     
721     return len;
724 gchar *CGroup::getDescription() {
725     gint len = getItemCount();
726     return g_strdup_printf(
727             ngettext("<b>Group</b> of <b>%d</b> object",
728                  "<b>Group</b> of <b>%d</b> objects",
729                  len), len);
732 NRArenaItem *CGroup::show (NRArena *arena, unsigned int key, unsigned int flags) {
733     NRArenaItem *ai;
734     SPObject *object = SP_OBJECT(_group);
736     ai = NRArenaGroup::create(arena);
738     nr_arena_group_set_transparent(NR_ARENA_GROUP (ai),
739                                    _group->effectiveLayerMode(key) ==
740                          SPGroup::LAYER);
741     nr_arena_group_set_style(NR_ARENA_GROUP(ai), SP_OBJECT_STYLE(object));
743     _showChildren(arena, ai, key, flags);
744     return ai;
747 void CGroup::_showChildren (NRArena *arena, NRArenaItem *ai, unsigned int key, unsigned int flags) {
748     NRArenaItem *ac = NULL;
749     NRArenaItem *ar = NULL;
750     SPItem * child = NULL;
751     GSList *l = g_slist_reverse(_group->childList(false, SPObject::ActionShow));
752     while (l) {
753         SPObject *o = SP_OBJECT (l->data);
754         if (SP_IS_ITEM (o)) {
755             child = SP_ITEM (o);
756             ac = sp_item_invoke_show (child, arena, key, flags);
757             if (ac) {
758                 nr_arena_item_add_child (ai, ac, ar);
759                 ar = ac;
760                 nr_arena_item_unref (ac);
761             }
762         }
763         l = g_slist_remove (l, o);
764     }
767 void CGroup::hide (unsigned int key) {
768     SPItem * child;
770     GSList *l = g_slist_reverse(_group->childList(false, SPObject::ActionShow));
771     while (l) {
772         SPObject *o = SP_OBJECT (l->data);
773         if (SP_IS_ITEM (o)) {
774             child = SP_ITEM (o);
775             sp_item_invoke_hide (child, key);
776         }
777         l = g_slist_remove (l, o);
778     }
780     if (((SPItemClass *) parent_class)->hide)
781         ((SPItemClass *) parent_class)->hide (_group, key);
784 void CGroup::onOrderChanged (Inkscape::XML::Node *child, Inkscape::XML::Node *, Inkscape::XML::Node *)
786     SPObject *ochild = sp_object_get_child_by_repr(_group, child);
787     if ( ochild && SP_IS_ITEM(ochild) ) {
788         /* TODO: this should be moved into SPItem somehow */
789         SPItemView *v;
790         unsigned position = sp_item_pos_in_parent(SP_ITEM(ochild));
791         for ( v = SP_ITEM (ochild)->display ; v != NULL ; v = v->next ) {
792             nr_arena_item_set_order (v->arenaitem, position);
793         }
794     }
796     _group->requestModified(SP_OBJECT_MODIFIED_FLAG);
799 /*
800   Local Variables:
801   mode:c++
802   c-file-style:"stroustrup"
803   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
804   indent-tabs-mode:nil
805   fill-column:99
806   End:
807 */
808 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :