1 #define __SP_GROUP_C__
3 /*
4 * SVG <g> implementation
5 *
6 * Authors:
7 * Lauris Kaplinski <lauris@kaplinski.com>
8 * bulia byak <buliabyak@users.sf.net>
9 *
10 * Copyright (C) 1999-2005 authors
11 * Copyright (C) 2000-2001 Ximian, Inc.
12 *
13 * Released under GNU GPL, read the file 'COPYING' for more information
14 */
16 #ifdef HAVE_CONFIG_H
17 # include "config.h"
18 #endif
20 #if defined(WIN32) || defined(__APPLE__)
21 # include <glibmm/i18n.h>
22 #endif
24 #include "display/nr-arena-group.h"
25 #include "libnr/nr-matrix-ops.h"
26 #include "libnr/nr-matrix-fns.h"
27 #include "xml/repr.h"
28 #include "svg/svg.h"
29 #include "document.h"
30 #include "style.h"
31 #include "attributes.h"
33 #include "sp-root.h"
34 #include "sp-use.h"
35 #include "prefs-utils.h"
37 static void sp_group_class_init (SPGroupClass *klass);
38 static void sp_group_init (SPGroup *group);
39 static void sp_group_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
40 static void sp_group_release(SPObject *object);
41 static void sp_group_dispose(GObject *object);
43 static void sp_group_child_added (SPObject * object, Inkscape::XML::Node * child, Inkscape::XML::Node * ref);
44 static void sp_group_remove_child (SPObject * object, Inkscape::XML::Node * child);
45 static void sp_group_order_changed (SPObject * object, Inkscape::XML::Node * child, Inkscape::XML::Node * old_ref, Inkscape::XML::Node * new_ref);
46 static void sp_group_update (SPObject *object, SPCtx *ctx, guint flags);
47 static void sp_group_modified (SPObject *object, guint flags);
48 static Inkscape::XML::Node *sp_group_write (SPObject *object, Inkscape::XML::Node *repr, guint flags);
49 static void sp_group_set(SPObject *object, unsigned key, char const *value);
51 static void sp_group_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags);
52 static void sp_group_print (SPItem * item, SPPrintContext *ctx);
53 static gchar * sp_group_description (SPItem * item);
54 static NRArenaItem *sp_group_show (SPItem *item, NRArena *arena, unsigned int key, unsigned int flags);
55 static void sp_group_hide (SPItem * item, unsigned int key);
56 static void sp_group_snappoints (SPItem const *item, SnapPointsIter p);
58 static SPItemClass * parent_class;
60 GType
61 sp_group_get_type (void)
62 {
63 static GType group_type = 0;
64 if (!group_type) {
65 GTypeInfo group_info = {
66 sizeof (SPGroupClass),
67 NULL, /* base_init */
68 NULL, /* base_finalize */
69 (GClassInitFunc) sp_group_class_init,
70 NULL, /* class_finalize */
71 NULL, /* class_data */
72 sizeof (SPGroup),
73 16, /* n_preallocs */
74 (GInstanceInitFunc) sp_group_init,
75 NULL, /* value_table */
76 };
77 group_type = g_type_register_static (SP_TYPE_ITEM, "SPGroup", &group_info, (GTypeFlags)0);
78 }
79 return group_type;
80 }
82 static void
83 sp_group_class_init (SPGroupClass *klass)
84 {
85 GObjectClass * object_class;
86 SPObjectClass * sp_object_class;
87 SPItemClass * item_class;
89 object_class = (GObjectClass *) klass;
90 sp_object_class = (SPObjectClass *) klass;
91 item_class = (SPItemClass *) klass;
93 parent_class = (SPItemClass *)g_type_class_ref (SP_TYPE_ITEM);
95 object_class->dispose = sp_group_dispose;
97 sp_object_class->child_added = sp_group_child_added;
98 sp_object_class->remove_child = sp_group_remove_child;
99 sp_object_class->order_changed = sp_group_order_changed;
100 sp_object_class->update = sp_group_update;
101 sp_object_class->modified = sp_group_modified;
102 sp_object_class->set = sp_group_set;
103 sp_object_class->write = sp_group_write;
104 sp_object_class->release = sp_group_release;
105 sp_object_class->build = sp_group_build;
107 item_class->bbox = sp_group_bbox;
108 item_class->print = sp_group_print;
109 item_class->description = sp_group_description;
110 item_class->show = sp_group_show;
111 item_class->hide = sp_group_hide;
112 item_class->snappoints = sp_group_snappoints;
113 }
115 static void
116 sp_group_init (SPGroup *group)
117 {
118 group->_layer_mode = SPGroup::GROUP;
119 group->group = new CGroup(group);
120 new (&group->_display_modes) std::map<unsigned int, SPGroup::LayerMode>();
121 }
123 static void sp_group_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
124 {
125 sp_object_read_attr(object, "inkscape:groupmode");
127 if (((SPObjectClass *)parent_class)->build) {
128 ((SPObjectClass *)parent_class)->build(object, document, repr);
129 }
130 }
132 static void sp_group_release(SPObject *object) {
133 if ( SP_GROUP(object)->_layer_mode == SPGroup::LAYER ) {
134 sp_document_remove_resource(SP_OBJECT_DOCUMENT(object), "layer", object);
135 }
136 if (((SPObjectClass *)parent_class)->release) {
137 ((SPObjectClass *)parent_class)->release(object);
138 }
139 }
141 static void
142 sp_group_dispose(GObject *object)
143 {
144 SP_GROUP(object)->_display_modes.~map();
145 delete SP_GROUP(object)->group;
146 }
148 static void
149 sp_group_child_added (SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
150 {
151 SPItem *item;
153 item = SP_ITEM (object);
155 if (((SPObjectClass *) (parent_class))->child_added)
156 (* ((SPObjectClass *) (parent_class))->child_added) (object, child, ref);
158 SP_GROUP(object)->group->onChildAdded(child);
159 }
161 /* fixme: hide (Lauris) */
163 static void
164 sp_group_remove_child (SPObject * object, Inkscape::XML::Node * child)
165 {
166 if (((SPObjectClass *) (parent_class))->remove_child)
167 (* ((SPObjectClass *) (parent_class))->remove_child) (object, child);
169 SP_GROUP(object)->group->onChildRemoved(child);
170 }
172 static void
173 sp_group_order_changed (SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *old_ref, Inkscape::XML::Node *new_ref)
174 {
175 if (((SPObjectClass *) (parent_class))->order_changed)
176 (* ((SPObjectClass *) (parent_class))->order_changed) (object, child, old_ref, new_ref);
178 SP_GROUP(object)->group->onOrderChanged(child, old_ref, new_ref);
179 }
181 static void
182 sp_group_update (SPObject *object, SPCtx *ctx, unsigned int flags)
183 {
184 if (((SPObjectClass *) (parent_class))->update)
185 ((SPObjectClass *) (parent_class))->update (object, ctx, flags);
187 SP_GROUP(object)->group->onUpdate(ctx, flags);
188 }
190 static void
191 sp_group_modified (SPObject *object, guint flags)
192 {
193 SP_GROUP(object)->group->onModified(flags);
194 }
196 static Inkscape::XML::Node *
197 sp_group_write (SPObject *object, Inkscape::XML::Node *repr, guint flags)
198 {
199 SPGroup *group;
200 SPObject *child;
201 Inkscape::XML::Node *crepr;
203 group = SP_GROUP (object);
205 if (flags & SP_OBJECT_WRITE_BUILD) {
206 GSList *l;
207 if (!repr) repr = sp_repr_new ("svg:g");
208 l = NULL;
209 for (child = sp_object_first_child(object); child != NULL; child = SP_OBJECT_NEXT(child) ) {
210 crepr = child->updateRepr(NULL, flags);
211 if (crepr) l = g_slist_prepend (l, crepr);
212 }
213 while (l) {
214 repr->addChild((Inkscape::XML::Node *) l->data, NULL);
215 Inkscape::GC::release((Inkscape::XML::Node *) l->data);
216 l = g_slist_remove (l, l->data);
217 }
218 } else {
219 for (child = sp_object_first_child(object) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
220 child->updateRepr(flags);
221 }
222 }
224 if ( flags & SP_OBJECT_WRITE_EXT ) {
225 const char *value;
226 if ( group->_layer_mode == SPGroup::LAYER ) {
227 value = "layer";
228 } else if ( flags & SP_OBJECT_WRITE_ALL ) {
229 value = "group";
230 } else {
231 value = NULL;
232 }
233 repr->setAttribute("inkscape:groupmode", value);
234 }
236 if (((SPObjectClass *) (parent_class))->write)
237 ((SPObjectClass *) (parent_class))->write (object, repr, flags);
239 return repr;
240 }
242 static void
243 sp_group_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags)
244 {
245 SP_GROUP(item)->group->calculateBBox(bbox, transform, flags);
246 }
248 static void
249 sp_group_print (SPItem * item, SPPrintContext *ctx)
250 {
251 SP_GROUP(item)->group->onPrint(ctx);
252 }
254 static gchar * sp_group_description (SPItem * item)
255 {
256 return SP_GROUP(item)->group->getDescription();
257 }
259 static void sp_group_set(SPObject *object, unsigned key, char const *value) {
260 SPGroup *group=SP_GROUP(object);
262 switch (key) {
263 case SP_ATTR_INKSCAPE_GROUPMODE: {
264 if ( value && !strcmp(value, "layer") ) {
265 group->setLayerMode(SPGroup::LAYER);
266 } else {
267 group->setLayerMode(SPGroup::GROUP);
268 }
269 } break;
270 default: {
271 if (((SPObjectClass *) (parent_class))->set) {
272 (* ((SPObjectClass *) (parent_class))->set)(object, key, value);
273 }
274 }
275 }
276 }
278 static NRArenaItem *
279 sp_group_show (SPItem *item, NRArena *arena, unsigned int key, unsigned int flags)
280 {
281 return SP_GROUP(item)->group->show(arena, key, flags);
282 }
284 static void
285 sp_group_hide (SPItem *item, unsigned int key)
286 {
287 SP_GROUP(item)->group->hide(key);
288 }
290 static void sp_group_snappoints (SPItem const *item, SnapPointsIter p)
291 {
292 for (SPObject const *o = sp_object_first_child(SP_OBJECT(item));
293 o != NULL;
294 o = SP_OBJECT_NEXT(o))
295 {
296 if (SP_IS_ITEM(o)) {
297 sp_item_snappoints(SP_ITEM(o), p);
298 }
299 }
300 }
303 void
304 sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done)
305 {
306 g_return_if_fail (group != NULL);
307 g_return_if_fail (SP_IS_GROUP (group));
309 SPDocument *doc = SP_OBJECT_DOCUMENT (group);
310 SPObject *root = SP_DOCUMENT_ROOT (doc);
311 SPObject *defs = SP_OBJECT (SP_ROOT (root)->defs);
313 SPItem *gitem = SP_ITEM (group);
314 Inkscape::XML::Node *grepr = SP_OBJECT_REPR (gitem);
316 g_return_if_fail (!strcmp (grepr->name(), "svg:g") || !strcmp (grepr->name(), "svg:a") || !strcmp (grepr->name(), "svg:switch"));
318 // this converts the gradient/pattern fill/stroke on the group, if any, to userSpaceOnUse
319 sp_item_adjust_paint_recursive (gitem, NR::identity(), NR::identity(), false);
321 SPItem *pitem = SP_ITEM (SP_OBJECT_PARENT (gitem));
322 Inkscape::XML::Node *prepr = SP_OBJECT_REPR (pitem);
324 /* Step 1 - generate lists of children objects */
325 GSList *items = NULL;
326 GSList *objects = NULL;
327 for (SPObject *child = sp_object_first_child(SP_OBJECT(group)) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
329 if (SP_IS_ITEM (child)) {
331 SPItem *citem = SP_ITEM (child);
333 /* Merging of style */
334 // this converts the gradient/pattern fill/stroke, if any, to userSpaceOnUse; we need to do
335 // it here _before_ the new transform is set, so as to use the pre-transform bbox
336 sp_item_adjust_paint_recursive (citem, NR::identity(), NR::identity(), false);
338 sp_style_merge_from_dying_parent(SP_OBJECT_STYLE(child), SP_OBJECT_STYLE(gitem));
339 /*
340 * fixme: We currently make no allowance for the case where child is cloned
341 * and the group has any style settings.
342 *
343 * (This should never occur with documents created solely with the current
344 * version of inkscape without using the XML editor: we usually apply group
345 * style changes to children rather than to the group itself.)
346 *
347 * If the group has no style settings, then
348 * sp_style_merge_from_dying_parent should be a no-op. Otherwise (i.e. if
349 * we change the child's style to compensate for its parent going away)
350 * then those changes will typically be reflected in any clones of child,
351 * whereas we'd prefer for Ungroup not to affect the visual appearance.
352 *
353 * The only way of preserving styling appearance in general is for child to
354 * be put into a new group -- a somewhat surprising response to an Ungroup
355 * command. We could add a new groupmode:transparent that would mostly
356 * hide the existence of such groups from the user (i.e. editing behaves as
357 * if the transparent group's children weren't in a group), though that's
358 * extra complication & maintenance burden and this case is rare.
359 */
361 child->updateRepr();
363 Inkscape::XML::Node *nrepr = SP_OBJECT_REPR (child)->duplicate();
365 // Merging transform
366 NR::Matrix ctrans;
367 NR::Matrix const g(gitem->transform);
368 if (SP_IS_USE(citem) && sp_use_get_original (SP_USE(citem)) &&
369 SP_OBJECT_PARENT (sp_use_get_original (SP_USE(citem))) == SP_OBJECT(group)) {
370 // make sure a clone's effective transform is the same as was under group
371 ctrans = g.inverse() * citem->transform * g;
372 } else {
373 ctrans = citem->transform * g;
374 }
376 // FIXME: constructing a transform that would fully preserve the appearance of a
377 // textpath if it is ungrouped with its path seems to be impossible in general
378 // case. E.g. if the group was squeezed, to keep the ungrouped textpath squeezed
379 // as well, we'll need to relink it to some "virtual" path which is inversely
380 // stretched relative to the actual path, and then squeeze the textpath back so it
381 // would both fit the actual path _and_ be squeezed as before. It's a bummer.
383 // This is just a way to temporarily remember the transform in repr. When repr is
384 // reattached outside of the group, the transform will be written more properly
385 // (i.e. optimized into the object if the corresponding preference is set)
386 gchar affinestr[80];
387 if (sp_svg_transform_write(affinestr, 79, ctrans)) {
388 nrepr->setAttribute("transform", affinestr);
389 } else {
390 nrepr->setAttribute("transform", NULL);
391 }
393 items = g_slist_prepend (items, nrepr);
395 } else {
396 Inkscape::XML::Node *nrepr = SP_OBJECT_REPR (child)->duplicate();
397 objects = g_slist_prepend (objects, nrepr);
398 }
399 }
401 /* Step 2 - clear group */
402 // remember the position of the group
403 gint pos = SP_OBJECT_REPR(group)->position();
405 // the group is leaving forever, no heir, clones should take note; its children however are going to reemerge
406 SP_OBJECT (group)->deleteObject(true, false);
408 /* Step 3 - add nonitems */
409 if (objects) {
410 Inkscape::XML::Node *last_def = SP_OBJECT_REPR(defs)->lastChild();
411 while (objects) {
412 SP_OBJECT_REPR(defs)->addChild((Inkscape::XML::Node *) objects->data, last_def);
413 Inkscape::GC::release((Inkscape::XML::Node *) objects->data);
414 objects = g_slist_remove (objects, objects->data);
415 }
416 }
418 /* Step 4 - add items */
419 gint const preserve = prefs_get_int_attribute("options.preservetransform", "value", 0);
420 while (items) {
421 Inkscape::XML::Node *repr = (Inkscape::XML::Node *) items->data;
422 // add item
423 prepr->appendChild(repr);
424 // restore position; since the items list was prepended (i.e. reverse), we now add
425 // all children at the same pos, which inverts the order once again
426 repr->setPosition(pos > 0 ? pos : 0);
428 // fill in the children list if non-null
429 SPItem *nitem = (SPItem *) doc->getObjectByRepr(repr);
431 /* Optimize the transform matrix if requested. */
432 // No compensations are required because this is supposed to be a non-transformation visually.
433 if (!preserve) {
434 NR::Matrix (*set_transform)(SPItem *, NR::Matrix const &) = ((SPItemClass *) G_OBJECT_GET_CLASS(nitem))->set_transform;
435 if (set_transform) {
436 sp_item_set_item_transform(nitem, set_transform(nitem, nitem->transform));
437 nitem->updateRepr();
438 }
439 }
441 Inkscape::GC::release(repr);
442 if (children && SP_IS_ITEM (nitem))
443 *children = g_slist_prepend (*children, nitem);
445 items = g_slist_remove (items, items->data);
446 }
448 if (do_done) sp_document_done (doc);
449 }
451 /*
452 * some API for list aspect of SPGroup
453 */
455 GSList *
456 sp_item_group_item_list (SPGroup * group)
457 {
458 GSList *s;
459 SPObject *o;
461 g_return_val_if_fail (group != NULL, NULL);
462 g_return_val_if_fail (SP_IS_GROUP (group), NULL);
464 s = NULL;
466 for ( o = sp_object_first_child(SP_OBJECT(group)) ; o != NULL ; o = SP_OBJECT_NEXT(o) ) {
467 if (SP_IS_ITEM (o)) {
468 s = g_slist_prepend (s, o);
469 }
470 }
472 return g_slist_reverse (s);
473 }
475 SPObject *
476 sp_item_group_get_child_by_name (SPGroup *group, SPObject *ref, const gchar *name)
477 {
478 SPObject *child;
479 child = (ref) ? SP_OBJECT_NEXT(ref) : sp_object_first_child(SP_OBJECT(group));
480 while ( child && strcmp (SP_OBJECT_REPR(child)->name(), name) ) {
481 child = SP_OBJECT_NEXT(child);
482 }
483 return child;
484 }
486 void SPGroup::setLayerMode(LayerMode mode) {
487 if ( _layer_mode != mode ) {
488 if ( mode == LAYER ) {
489 sp_document_add_resource(SP_OBJECT_DOCUMENT(this), "layer", this);
490 } else {
491 sp_document_remove_resource(SP_OBJECT_DOCUMENT(this), "layer", this);
492 }
493 _layer_mode = mode;
494 _updateLayerMode();
495 }
496 }
498 SPGroup::LayerMode SPGroup::layerDisplayMode(unsigned int dkey) const {
499 std::map<unsigned int, LayerMode>::const_iterator iter;
500 iter = _display_modes.find(dkey);
501 if ( iter != _display_modes.end() ) {
502 return (*iter).second;
503 } else {
504 return GROUP;
505 }
506 }
508 void SPGroup::setLayerDisplayMode(unsigned int dkey, SPGroup::LayerMode mode) {
509 if ( layerDisplayMode(dkey) != mode ) {
510 _display_modes[dkey] = mode;
511 _updateLayerMode(dkey);
512 }
513 }
515 void SPGroup::_updateLayerMode(unsigned int display_key) {
516 SPItemView *view;
517 for ( view = this->display ; view ; view = view->next ) {
518 if ( !display_key || view->key == display_key ) {
519 NRArenaGroup *arena_group=NR_ARENA_GROUP(view->arenaitem);
520 if (arena_group) {
521 nr_arena_group_set_transparent(arena_group, effectiveLayerMode(view->key) == SPGroup::LAYER);
522 }
523 }
524 }
525 }
527 CGroup::CGroup(SPGroup *group) {
528 _group = group;
529 }
531 CGroup::~CGroup() {
532 }
534 void CGroup::onChildAdded(Inkscape::XML::Node *child) {
535 SPObject *last_child = _group->lastChild();
536 if (last_child && SP_OBJECT_REPR(last_child) == child) {
537 // optimization for the common special case where the child is being added at the end
538 SPObject *ochild = last_child;
539 if ( SP_IS_ITEM(ochild) ) {
540 /* TODO: this should be moved into SPItem somehow */
541 SPItemView *v;
542 NRArenaItem *ac;
544 for (v = _group->display; v != NULL; v = v->next) {
545 ac = sp_item_invoke_show (SP_ITEM (ochild), NR_ARENA_ITEM_ARENA (v->arenaitem), v->key, v->flags);
547 if (ac) {
548 nr_arena_item_append_child (v->arenaitem, ac);
549 nr_arena_item_unref (ac);
550 }
551 }
552 }
553 } else { // general case
554 SPObject *ochild = sp_object_get_child_by_repr(_group, child);
555 if ( ochild && SP_IS_ITEM(ochild) ) {
556 /* TODO: this should be moved into SPItem somehow */
557 SPItemView *v;
558 NRArenaItem *ac;
560 unsigned position = sp_item_pos_in_parent(SP_ITEM(ochild));
562 for (v = _group->display; v != NULL; v = v->next) {
563 ac = sp_item_invoke_show (SP_ITEM (ochild), NR_ARENA_ITEM_ARENA (v->arenaitem), v->key, v->flags);
565 if (ac) {
566 nr_arena_item_add_child (v->arenaitem, ac, NULL);
567 nr_arena_item_set_order (ac, position);
568 nr_arena_item_unref (ac);
569 }
570 }
571 }
572 }
574 _group->requestModified(SP_OBJECT_MODIFIED_FLAG);
575 }
577 void CGroup::onChildRemoved(Inkscape::XML::Node */*child*/) {
578 _group->requestModified(SP_OBJECT_MODIFIED_FLAG);
579 }
581 void CGroup::onUpdate(SPCtx *ctx, unsigned int flags) {
582 SPObject *child;
583 SPItemCtx *ictx, cctx;
585 ictx = (SPItemCtx *) ctx;
586 cctx = *ictx;
588 if (flags & SP_OBJECT_MODIFIED_FLAG) flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
589 flags &= SP_OBJECT_MODIFIED_CASCADE;
591 GSList *l = g_slist_reverse(_childList(true, ActionUpdate));
592 while (l) {
593 child = SP_OBJECT (l->data);
594 l = g_slist_remove (l, child);
595 if (flags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
596 if (SP_IS_ITEM (child)) {
597 SPItem const &chi = *SP_ITEM(child);
598 cctx.i2doc = chi.transform * ictx->i2doc;
599 cctx.i2vp = chi.transform * ictx->i2vp;
600 child->updateDisplay((SPCtx *)&cctx, flags);
601 } else {
602 child->updateDisplay(ctx, flags);
603 }
604 }
605 g_object_unref (G_OBJECT (child));
606 }
607 }
609 GSList *CGroup::_childList(bool add_ref, Action) {
610 GSList *l = NULL;
611 for (SPObject *child = sp_object_first_child(_group) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) {
612 if (add_ref)
613 g_object_ref (G_OBJECT (child));
615 l = g_slist_prepend (l, child);
616 }
617 return l;
618 }
620 void CGroup::onModified(guint flags) {
621 SPObject *child;
623 if (flags & SP_OBJECT_MODIFIED_FLAG) flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
624 flags &= SP_OBJECT_MODIFIED_CASCADE;
626 GSList *l = g_slist_reverse(_childList(true));
627 while (l) {
628 child = SP_OBJECT (l->data);
629 l = g_slist_remove (l, child);
630 if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
631 child->emitModified(flags);
632 }
633 g_object_unref (G_OBJECT (child));
634 }
635 }
637 void CGroup::calculateBBox(NRRect *bbox, NR::Matrix const &transform, unsigned const flags) {
638 GSList *l = _childList(false, ActionBBox);
639 while (l) {
640 SPObject *o = SP_OBJECT (l->data);
641 if (SP_IS_ITEM(o)) {
642 SPItem *child = SP_ITEM(o);
643 NR::Matrix const ct(child->transform * transform);
644 sp_item_invoke_bbox_full(child, bbox, ct, flags, FALSE);
645 }
646 l = g_slist_remove (l, o);
647 }
648 }
650 void CGroup::onPrint(SPPrintContext *ctx) {
651 GSList *l = g_slist_reverse(_childList(false));
652 while (l) {
653 SPObject *o = SP_OBJECT (l->data);
654 if (SP_IS_ITEM(o)) {
655 sp_item_invoke_print (SP_ITEM (o), ctx);
656 }
657 l = g_slist_remove (l, o);
658 }
659 }
661 gint CGroup::getItemCount() {
662 gint len = 0;
663 for (SPObject *o = sp_object_first_child(SP_OBJECT(_group)) ; o != NULL ; o = SP_OBJECT_NEXT(o) ) {
664 if (SP_IS_ITEM(o)) {
665 len++;
666 }
667 }
669 return len;
670 }
672 gchar *CGroup::getDescription() {
673 gint len = getItemCount();
674 return g_strdup_printf(
675 ngettext("<b>Group</b> of <b>%d</b> object",
676 "<b>Group</b> of <b>%d</b> objects",
677 len), len);
678 }
680 NRArenaItem *CGroup::show (NRArena *arena, unsigned int key, unsigned int flags) {
681 NRArenaItem *ai;
683 ai = NRArenaGroup::create(arena);
684 nr_arena_group_set_transparent(NR_ARENA_GROUP (ai),
685 _group->effectiveLayerMode(key) ==
686 SPGroup::LAYER);
688 _showChildren(arena, ai, key, flags);
689 return ai;
690 }
692 void CGroup::_showChildren (NRArena *arena, NRArenaItem *ai, unsigned int key, unsigned int flags) {
693 NRArenaItem *ac = NULL;
694 NRArenaItem *ar = NULL;
695 SPItem * child = NULL;
696 GSList *l = g_slist_reverse(_childList(false, ActionShow));
697 while (l) {
698 SPObject *o = SP_OBJECT (l->data);
699 if (SP_IS_ITEM (o)) {
700 child = SP_ITEM (o);
701 ac = sp_item_invoke_show (child, arena, key, flags);
702 if (ac) {
703 nr_arena_item_add_child (ai, ac, ar);
704 ar = ac;
705 nr_arena_item_unref (ac);
706 }
707 }
708 l = g_slist_remove (l, o);
709 }
710 }
712 void CGroup::hide (unsigned int key) {
713 SPItem * child;
715 GSList *l = g_slist_reverse(_childList(false, ActionShow));
716 while (l) {
717 SPObject *o = SP_OBJECT (l->data);
718 if (SP_IS_ITEM (o)) {
719 child = SP_ITEM (o);
720 sp_item_invoke_hide (child, key);
721 }
722 l = g_slist_remove (l, o);
723 }
725 if (((SPItemClass *) parent_class)->hide)
726 ((SPItemClass *) parent_class)->hide (_group, key);
727 }
729 void CGroup::onOrderChanged (Inkscape::XML::Node *child, Inkscape::XML::Node *, Inkscape::XML::Node *)
730 {
731 SPObject *ochild = sp_object_get_child_by_repr(_group, child);
732 if ( ochild && SP_IS_ITEM(ochild) ) {
733 /* TODO: this should be moved into SPItem somehow */
734 SPItemView *v;
735 unsigned position = sp_item_pos_in_parent(SP_ITEM(ochild));
736 for ( v = SP_ITEM (ochild)->display ; v != NULL ; v = v->next ) {
737 nr_arena_item_set_order (v->arenaitem, position);
738 }
739 }
741 _group->requestModified(SP_OBJECT_MODIFIED_FLAG);
742 }