diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp
index c093c569bf19059a01a6f6e74465d2fe9e9cb8bb..186b766635f1115ee63e0817401f4fd83af249c5 100644 (file)
--- a/src/sp-item-group.cpp
+++ b/src/sp-item-group.cpp
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
+ * Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
*
- * Copyright (C) 1999-2005 authors
+ * Copyright (C) 1999-2006 authors
* Copyright (C) 2000-2001 Ximian, Inc.
*
* Released under GNU GPL, read the file 'COPYING' for more information
# include "config.h"
#endif
-#if defined(WIN32) || defined(__APPLE__)
-# include <glibmm/i18n.h>
-#endif
+#include <glibmm/i18n.h>
+#include <cstring>
+#include <string>
#include "display/nr-arena-group.h"
+#include "display/curve.h"
#include "libnr/nr-matrix-ops.h"
#include "libnr/nr-matrix-fns.h"
#include "xml/repr.h"
#include "document.h"
#include "style.h"
#include "attributes.h"
-
+#include "sp-item-transform.h"
#include "sp-root.h"
#include "sp-use.h"
#include "prefs-utils.h"
+#include "sp-clippath.h"
+#include "sp-mask.h"
+#include "sp-path.h"
+#include "box3d.h"
+#include "persp3d.h"
+#include "inkscape.h"
+#include "desktop-handles.h"
+#include "selection.h"
+#include "live_effects/lpeobject.h"
+#include "live_effects/lpeobject-reference.h"
static void sp_group_class_init (SPGroupClass *klass);
static void sp_group_init (SPGroup *group);
static void sp_group_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
static void sp_group_release(SPObject *object);
-static void sp_group_dispose (GObject *object);
+static void sp_group_dispose(GObject *object);
static void sp_group_child_added (SPObject * object, Inkscape::XML::Node * child, Inkscape::XML::Node * ref);
static void sp_group_remove_child (SPObject * object, Inkscape::XML::Node * child);
static void sp_group_order_changed (SPObject * object, Inkscape::XML::Node * child, Inkscape::XML::Node * old_ref, Inkscape::XML::Node * new_ref);
static void sp_group_update (SPObject *object, SPCtx *ctx, guint flags);
static void sp_group_modified (SPObject *object, guint flags);
-static Inkscape::XML::Node *sp_group_write (SPObject *object, Inkscape::XML::Node *repr, guint flags);
+static Inkscape::XML::Node *sp_group_write (SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
static void sp_group_set(SPObject *object, unsigned key, char const *value);
static void sp_group_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags);
static void sp_group_print (SPItem * item, SPPrintContext *ctx);
static gchar * sp_group_description (SPItem * item);
+static NR::Matrix sp_group_set_transform(SPItem *item, NR::Matrix const &xform);
static NRArenaItem *sp_group_show (SPItem *item, NRArena *arena, unsigned int key, unsigned int flags);
static void sp_group_hide (SPItem * item, unsigned int key);
static void sp_group_snappoints (SPItem const *item, SnapPointsIter p);
-static SPItemClass * parent_class;
+static void sp_group_update_patheffect(SPLPEItem *lpeitem, bool write);
+static void sp_group_perform_patheffect(SPGroup *group, SPGroup *topgroup);
+
+static SPLPEItemClass * parent_class;
GType
sp_group_get_type (void)
(GInstanceInitFunc) sp_group_init,
NULL, /* value_table */
};
- group_type = g_type_register_static (SP_TYPE_ITEM, "SPGroup", &group_info, (GTypeFlags)0);
+ group_type = g_type_register_static (SP_TYPE_LPE_ITEM, "SPGroup", &group_info, (GTypeFlags)0);
}
return group_type;
}
GObjectClass * object_class;
SPObjectClass * sp_object_class;
SPItemClass * item_class;
+ SPLPEItemClass * lpe_item_class;
object_class = (GObjectClass *) klass;
sp_object_class = (SPObjectClass *) klass;
item_class = (SPItemClass *) klass;
+ lpe_item_class = (SPLPEItemClass *) klass;
- parent_class = (SPItemClass *)g_type_class_ref (SP_TYPE_ITEM);
+ parent_class = (SPLPEItemClass *)g_type_class_ref (SP_TYPE_LPE_ITEM);
object_class->dispose = sp_group_dispose;
item_class->bbox = sp_group_bbox;
item_class->print = sp_group_print;
item_class->description = sp_group_description;
+ item_class->set_transform = sp_group_set_transform;
item_class->show = sp_group_show;
item_class->hide = sp_group_hide;
item_class->snappoints = sp_group_snappoints;
+
+ lpe_item_class->update_patheffect = sp_group_update_patheffect;
}
static void
sp_group_init (SPGroup *group)
{
group->_layer_mode = SPGroup::GROUP;
+ group->group = new CGroup(group);
new (&group->_display_modes) std::map<unsigned int, SPGroup::LayerMode>();
}
sp_group_dispose(GObject *object)
{
SP_GROUP(object)->_display_modes.~map();
+ delete SP_GROUP(object)->group;
}
static void
@@ -153,46 +176,7 @@ sp_group_child_added (SPObject *object, Inkscape::XML::Node *child, Inkscape::XM
if (((SPObjectClass *) (parent_class))->child_added)
(* ((SPObjectClass *) (parent_class))->child_added) (object, child, ref);
- SPObject *last_child = object->lastChild();
- if (last_child && SP_OBJECT_REPR(last_child) == child) {
- // optimization for the common special case where the child is being added at the end
- SPObject *ochild = last_child;
- if ( SP_IS_ITEM(ochild) ) {
- /* TODO: this should be moved into SPItem somehow */
- SPItemView *v;
- NRArenaItem *ac;
-
- for (v = item->display; v != NULL; v = v->next) {
- ac = sp_item_invoke_show (SP_ITEM (ochild), NR_ARENA_ITEM_ARENA (v->arenaitem), v->key, v->flags);
-
- if (ac) {
- nr_arena_item_append_child (v->arenaitem, ac);
- nr_arena_item_unref (ac);
- }
- }
- }
- } else { // general case
- SPObject *ochild = sp_object_get_child_by_repr(object, child);
- if ( ochild && SP_IS_ITEM(ochild) ) {
- /* TODO: this should be moved into SPItem somehow */
- SPItemView *v;
- NRArenaItem *ac;
-
- unsigned position = sp_item_pos_in_parent(SP_ITEM(ochild));
-
- for (v = item->display; v != NULL; v = v->next) {
- ac = sp_item_invoke_show (SP_ITEM (ochild), NR_ARENA_ITEM_ARENA (v->arenaitem), v->key, v->flags);
-
- if (ac) {
- nr_arena_item_add_child (v->arenaitem, ac, NULL);
- nr_arena_item_set_order (ac, position);
- nr_arena_item_unref (ac);
- }
- }
- }
- }
-
- object->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ SP_GROUP(object)->group->onChildAdded(child);
}
/* fixme: hide (Lauris) */
if (((SPObjectClass *) (parent_class))->remove_child)
(* ((SPObjectClass *) (parent_class))->remove_child) (object, child);
- object->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ SP_GROUP(object)->group->onChildRemoved(child);
}
static void
@@ -212,90 +196,29 @@ sp_group_order_changed (SPObject *object, Inkscape::XML::Node *child, Inkscape::
if (((SPObjectClass *) (parent_class))->order_changed)
(* ((SPObjectClass *) (parent_class))->order_changed) (object, child, old_ref, new_ref);
- SPObject *ochild = sp_object_get_child_by_repr(object, child);
- if ( ochild && SP_IS_ITEM(ochild) ) {
- /* TODO: this should be moved into SPItem somehow */
- SPItemView *v;
- unsigned position = sp_item_pos_in_parent(SP_ITEM(ochild));
- for ( v = SP_ITEM (ochild)->display ; v != NULL ; v = v->next ) {
- nr_arena_item_set_order (v->arenaitem, position);
- }
- }
-
- object->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ SP_GROUP(object)->group->onOrderChanged(child, old_ref, new_ref);
}
static void
sp_group_update (SPObject *object, SPCtx *ctx, unsigned int flags)
{
- SPGroup *group;
- SPObject *child;
- SPItemCtx *ictx, cctx;
- GSList *l;
-
- group = SP_GROUP (object);
- ictx = (SPItemCtx *) ctx;
- cctx = *ictx;
-
- if (((SPObjectClass *) (parent_class))->update)
- ((SPObjectClass *) (parent_class))->update (object, ctx, flags);
-
- if (flags & SP_OBJECT_MODIFIED_FLAG) flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
- flags &= SP_OBJECT_MODIFIED_CASCADE;
+ if (((SPObjectClass *) (parent_class))->update)
+ ((SPObjectClass *) (parent_class))->update (object, ctx, flags);
- l = NULL;
- for (child = sp_object_first_child(object) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) {
- g_object_ref (G_OBJECT (child));
- l = g_slist_prepend (l, child);
- }
- l = g_slist_reverse (l);
- while (l) {
- child = SP_OBJECT (l->data);
- l = g_slist_remove (l, child);
- if (flags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
- if (SP_IS_ITEM (child)) {
- SPItem const &chi = *SP_ITEM(child);
- cctx.i2doc = chi.transform * ictx->i2doc;
- cctx.i2vp = chi.transform * ictx->i2vp;
- child->updateDisplay((SPCtx *)&cctx, flags);
- } else {
- child->updateDisplay(ctx, flags);
- }
- }
- g_object_unref (G_OBJECT (child));
- }
+ SP_GROUP(object)->group->onUpdate(ctx, flags);
}
static void
sp_group_modified (SPObject *object, guint flags)
{
- SPGroup *group;
- SPObject *child;
- GSList *l;
-
- group = SP_GROUP (object);
-
- if (flags & SP_OBJECT_MODIFIED_FLAG) flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
- flags &= SP_OBJECT_MODIFIED_CASCADE;
+ if (((SPObjectClass *) (parent_class))->modified)
+ ((SPObjectClass *) (parent_class))->modified (object, flags);
- l = NULL;
- for (child = sp_object_first_child(object) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) {
- g_object_ref (G_OBJECT (child));
- l = g_slist_prepend (l, child);
- }
- l = g_slist_reverse (l);
- while (l) {
- child = SP_OBJECT (l->data);
- l = g_slist_remove (l, child);
- if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
- child->emitModified(flags);
- }
- g_object_unref (G_OBJECT (child));
- }
+ SP_GROUP(object)->group->onModified(flags);
}
static Inkscape::XML::Node *
-sp_group_write (SPObject *object, Inkscape::XML::Node *repr, guint flags)
+sp_group_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
{
SPGroup *group;
SPObject *child;
if (flags & SP_OBJECT_WRITE_BUILD) {
GSList *l;
- if (!repr) repr = sp_repr_new ("svg:g");
+ if (!repr) {
+ repr = xml_doc->createElement("svg:g");
+ }
l = NULL;
for (child = sp_object_first_child(object); child != NULL; child = SP_OBJECT_NEXT(child) ) {
- crepr = child->updateRepr(NULL, flags);
+ crepr = child->updateRepr(xml_doc, NULL, flags);
if (crepr) l = g_slist_prepend (l, crepr);
}
while (l) {
}
if (((SPObjectClass *) (parent_class))->write)
- ((SPObjectClass *) (parent_class))->write (object, repr, flags);
+ ((SPObjectClass *) (parent_class))->write (object, xml_doc, repr, flags);
return repr;
}
static void
sp_group_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags)
{
- for (SPObject *o = sp_object_first_child(SP_OBJECT(item)); o != NULL; o = SP_OBJECT_NEXT(o)) {
- if (SP_IS_ITEM(o)) {
- SPItem *child = SP_ITEM(o);
- NR::Matrix const ct(child->transform * transform);
- sp_item_invoke_bbox_full(child, bbox, ct, flags, FALSE);
- }
- }
+ SP_GROUP(item)->group->calculateBBox(bbox, transform, flags);
}
static void
sp_group_print (SPItem * item, SPPrintContext *ctx)
{
- SPGroup * group;
- SPItem * child;
- SPObject * o;
-
- group = SP_GROUP (item);
-
- for (o = sp_object_first_child(SP_OBJECT(item)) ; o != NULL ; o = SP_OBJECT_NEXT(o) ) {
- if (SP_IS_ITEM (o)) {
- child = SP_ITEM (o);
- sp_item_invoke_print (SP_ITEM (o), ctx);
- }
- }
+ SP_GROUP(item)->group->onPrint(ctx);
}
static gchar * sp_group_description (SPItem * item)
{
- SPGroup * group;
- SPObject * o;
- gint len;
+ return SP_GROUP(item)->group->getDescription();
+}
- group = SP_GROUP (item);
+static NR::Matrix
+sp_group_set_transform(SPItem *item, NR::Matrix const &xform)
+{
+ Inkscape::Selection *selection = sp_desktop_selection(inkscape_active_desktop());
+ persp3d_split_perspectives_according_to_selection(selection);
- len = 0;
- for ( o = sp_object_first_child(SP_OBJECT(item)) ; o != NULL ; o = SP_OBJECT_NEXT(o) ) {
- if (SP_IS_ITEM(o)) {
- len += 1;
- }
- }
+ NR::Matrix last_trans;
+ sp_svg_transform_read(SP_OBJECT_REPR(item)->attribute("transform"), &last_trans);
+ NR::Matrix inc_trans = last_trans.inverse()*xform;
- return g_strdup_printf(
- ngettext("<b>Group</b> of <b>%d</b> object",
- "<b>Group</b> of <b>%d</b> objects",
- len), len);
+ std::list<Persp3D *> plist = selection->perspList();
+ for (std::list<Persp3D *>::iterator i = plist.begin(); i != plist.end(); ++i) {
+ persp3d_apply_affine_transformation(*i, inc_trans);
+ }
+
+ return xform;
}
static void sp_group_set(SPObject *object, unsigned key, char const *value) {
- SPGroup *group=SP_GROUP(object);
+ SPGroup *group = SP_GROUP(object);
switch (key) {
- case SP_ATTR_INKSCAPE_GROUPMODE: {
+ case SP_ATTR_INKSCAPE_GROUPMODE:
if ( value && !strcmp(value, "layer") ) {
group->setLayerMode(SPGroup::LAYER);
} else {
group->setLayerMode(SPGroup::GROUP);
}
- } break;
+ break;
default: {
if (((SPObjectClass *) (parent_class))->set) {
(* ((SPObjectClass *) (parent_class))->set)(object, key, value);
static NRArenaItem *
sp_group_show (SPItem *item, NRArena *arena, unsigned int key, unsigned int flags)
{
- SPGroup *group;
- NRArenaItem *ai, *ac, *ar;
- SPItem * child;
- SPObject * o;
-
- group = (SPGroup *) item;
-
- ai = NRArenaGroup::create(arena);
- nr_arena_group_set_transparent(NR_ARENA_GROUP (ai),
- group->effectiveLayerMode(key) ==
- SPGroup::LAYER);
-
- ar = NULL;
-
- for (o = sp_object_first_child(SP_OBJECT(item)) ; o != NULL; o = SP_OBJECT_NEXT(o) ) {
- if (SP_IS_ITEM (o)) {
- child = SP_ITEM (o);
- ac = sp_item_invoke_show (child, arena, key, flags);
- if (ac) {
- nr_arena_item_add_child (ai, ac, ar);
- ar = ac;
- nr_arena_item_unref (ac);
- }
- }
- }
-
- return ai;
+ return SP_GROUP(item)->group->show(arena, key, flags);
}
static void
sp_group_hide (SPItem *item, unsigned int key)
{
- SPGroup * group;
- SPItem * child;
- SPObject * o;
-
- group = (SPGroup *) item;
-
- for (o = sp_object_first_child(SP_OBJECT(item)) ; o != NULL; o = SP_OBJECT_NEXT(o) ) {
- if (SP_IS_ITEM (o)) {
- child = SP_ITEM (o);
- sp_item_invoke_hide (child, key);
- }
- }
-
- if (((SPItemClass *) parent_class)->hide)
- ((SPItemClass *) parent_class)->hide (item, key);
+ SP_GROUP(item)->group->hide(key);
}
static void sp_group_snappoints (SPItem const *item, SnapPointsIter p)
o = SP_OBJECT_NEXT(o))
{
if (SP_IS_ITEM(o)) {
- sp_item_snappoints(SP_ITEM(o), p);
+ sp_item_snappoints(SP_ITEM(o), false, p);
}
}
}
SPItem *pitem = SP_ITEM (SP_OBJECT_PARENT (gitem));
Inkscape::XML::Node *prepr = SP_OBJECT_REPR (pitem);
+ if (SP_IS_BOX3D(gitem)) {
+ group = box3d_convert_to_group(SP_BOX3D(gitem));
+ gitem = SP_ITEM(group);
+ }
+
+ sp_lpe_item_remove_all_path_effects(SP_LPE_ITEM(group), false);
+
/* Step 1 - generate lists of children objects */
GSList *items = NULL;
GSList *objects = NULL;
child->updateRepr();
- Inkscape::XML::Node *nrepr = SP_OBJECT_REPR (child)->duplicate();
+ Inkscape::XML::Node *nrepr = SP_OBJECT_REPR (child)->duplicate(prepr->document());
// Merging transform
NR::Matrix ctrans;
NR::Matrix const g(gitem->transform);
- if (SP_IS_USE(citem) && sp_use_get_original (SP_USE(citem)) &&
+ if (SP_IS_USE(citem) && sp_use_get_original (SP_USE(citem)) &&
SP_OBJECT_PARENT (sp_use_get_original (SP_USE(citem))) == SP_OBJECT(group)) {
// make sure a clone's effective transform is the same as was under group
ctrans = g.inverse() * citem->transform * g;
// This is just a way to temporarily remember the transform in repr. When repr is
// reattached outside of the group, the transform will be written more properly
// (i.e. optimized into the object if the corresponding preference is set)
- gchar affinestr[80];
- if (sp_svg_transform_write(affinestr, 79, ctrans)) {
- nrepr->setAttribute("transform", affinestr);
- } else {
- nrepr->setAttribute("transform", NULL);
- }
+ gchar *affinestr=sp_svg_transform_write(ctrans);
+ nrepr->setAttribute("transform", affinestr);
+ g_free(affinestr);
items = g_slist_prepend (items, nrepr);
} else {
- Inkscape::XML::Node *nrepr = SP_OBJECT_REPR (child)->duplicate();
+ Inkscape::XML::Node *nrepr = SP_OBJECT_REPR (child)->duplicate(prepr->document());
objects = g_slist_prepend (objects, nrepr);
}
}
if (objects) {
Inkscape::XML::Node *last_def = SP_OBJECT_REPR(defs)->lastChild();
while (objects) {
- SP_OBJECT_REPR(defs)->addChild((Inkscape::XML::Node *) objects->data, last_def);
- Inkscape::GC::release((Inkscape::XML::Node *) objects->data);
+ Inkscape::XML::Node *repr = (Inkscape::XML::Node *) objects->data;
+ if (!sp_repr_is_meta_element(repr))
+ SP_OBJECT_REPR(defs)->addChild(repr, last_def);
+ Inkscape::GC::release(repr);
objects = g_slist_remove (objects, objects->data);
}
}
/* Step 4 - add items */
- gint const preserve = prefs_get_int_attribute("options.preservetransform", "value", 0);
while (items) {
Inkscape::XML::Node *repr = (Inkscape::XML::Node *) items->data;
// add item
- prepr->appendChild(repr);
+ prepr->appendChild(repr);
// restore position; since the items list was prepended (i.e. reverse), we now add
// all children at the same pos, which inverts the order once again
repr->setPosition(pos > 0 ? pos : 0);
// fill in the children list if non-null
- SPItem *nitem = (SPItem *) doc->getObjectByRepr(repr);
-
- /* Optimize the transform matrix if requested. */
- // No compensations are required because this is supposed to be a non-transformation visually.
- if (!preserve) {
- NR::Matrix (*set_transform)(SPItem *, NR::Matrix const &) = ((SPItemClass *) G_OBJECT_GET_CLASS(nitem))->set_transform;
- if (set_transform) {
- sp_item_set_item_transform(nitem, set_transform(nitem, nitem->transform));
- nitem->updateRepr();
- }
- }
+ SPItem *item = (SPItem *) doc->getObjectByRepr(repr);
+
+ sp_item_write_transform(item, repr, item->transform, NULL, false);
Inkscape::GC::release(repr);
- if (children && SP_IS_ITEM (nitem))
- *children = g_slist_prepend (*children, nitem);
+ if (children && SP_IS_ITEM (item))
+ *children = g_slist_prepend (*children, item);
items = g_slist_remove (items, items->data);
}
- if (do_done) sp_document_done (doc);
+ if (do_done)
+ sp_document_done (doc, SP_VERB_NONE, _("Ungroup"));
}
/*
* some API for list aspect of SPGroup
*/
-GSList *
+GSList *
sp_item_group_item_list (SPGroup * group)
{
GSList *s;
}
}
}
+
+void SPGroup::translateChildItems(NR::translate const &tr)
+{
+ if (this->hasChildren())
+ {
+ SPObject *o = NULL;
+ for (o = sp_object_first_child(SP_OBJECT(this)) ; o != NULL ; o = SP_OBJECT_NEXT(o) ) {
+ if (SP_IS_ITEM (o)) {
+ sp_item_move_rel(static_cast<SPItem *>(o), tr);
+ }
+ }
+ }
+}
+
+CGroup::CGroup(SPGroup *group) {
+ _group = group;
+}
+
+CGroup::~CGroup() {
+}
+
+void CGroup::onChildAdded(Inkscape::XML::Node *child) {
+ SPObject *last_child = _group->lastChild();
+ if (last_child && SP_OBJECT_REPR(last_child) == child) {
+ // optimization for the common special case where the child is being added at the end
+ SPObject *ochild = last_child;
+ if ( SP_IS_ITEM(ochild) ) {
+ /* TODO: this should be moved into SPItem somehow */
+ SPItemView *v;
+ NRArenaItem *ac;
+
+ for (v = _group->display; v != NULL; v = v->next) {
+ ac = sp_item_invoke_show (SP_ITEM (ochild), NR_ARENA_ITEM_ARENA (v->arenaitem), v->key, v->flags);
+
+ if (ac) {
+ nr_arena_item_append_child (v->arenaitem, ac);
+ nr_arena_item_unref (ac);
+ }
+ }
+ }
+ } else { // general case
+ SPObject *ochild = sp_object_get_child_by_repr(_group, child);
+ if ( ochild && SP_IS_ITEM(ochild) ) {
+ /* TODO: this should be moved into SPItem somehow */
+ SPItemView *v;
+ NRArenaItem *ac;
+
+ unsigned position = sp_item_pos_in_parent(SP_ITEM(ochild));
+
+ for (v = _group->display; v != NULL; v = v->next) {
+ ac = sp_item_invoke_show (SP_ITEM (ochild), NR_ARENA_ITEM_ARENA (v->arenaitem), v->key, v->flags);
+
+ if (ac) {
+ nr_arena_item_add_child (v->arenaitem, ac, NULL);
+ nr_arena_item_set_order (ac, position);
+ nr_arena_item_unref (ac);
+ }
+ }
+ }
+ }
+
+ _group->requestModified(SP_OBJECT_MODIFIED_FLAG);
+}
+
+void CGroup::onChildRemoved(Inkscape::XML::Node */*child*/) {
+ _group->requestModified(SP_OBJECT_MODIFIED_FLAG);
+}
+
+void CGroup::onUpdate(SPCtx *ctx, unsigned int flags) {
+ SPItemCtx *ictx, cctx;
+
+ ictx = (SPItemCtx *) ctx;
+ cctx = *ictx;
+
+ if (flags & SP_OBJECT_MODIFIED_FLAG) {
+ flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
+ }
+
+ flags &= SP_OBJECT_MODIFIED_CASCADE;
+
+ if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) {
+ SPObject *object = SP_OBJECT(_group);
+ for (SPItemView *v = SP_ITEM(_group)->display; v != NULL; v = v->next) {
+ nr_arena_group_set_style(NR_ARENA_GROUP(v->arenaitem), SP_OBJECT_STYLE(object));
+ }
+ }
+
+ GSList *l = g_slist_reverse(_group->childList(true, SPObject::ActionUpdate));
+ while (l) {
+ SPObject *child = SP_OBJECT (l->data);
+ l = g_slist_remove (l, child);
+ if (flags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
+ if (SP_IS_ITEM (child)) {
+ SPItem const &chi = *SP_ITEM(child);
+ cctx.i2doc = chi.transform * ictx->i2doc;
+ cctx.i2vp = chi.transform * ictx->i2vp;
+ child->updateDisplay((SPCtx *)&cctx, flags);
+ } else {
+ child->updateDisplay(ctx, flags);
+ }
+ }
+ g_object_unref (G_OBJECT (child));
+ }
+}
+
+void CGroup::onModified(guint flags) {
+ SPObject *child;
+
+ if (flags & SP_OBJECT_MODIFIED_FLAG) flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
+ flags &= SP_OBJECT_MODIFIED_CASCADE;
+
+ if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) {
+ SPObject *object = SP_OBJECT(_group);
+ for (SPItemView *v = SP_ITEM(_group)->display; v != NULL; v = v->next) {
+ nr_arena_group_set_style(NR_ARENA_GROUP(v->arenaitem), SP_OBJECT_STYLE(object));
+ }
+ }
+
+ GSList *l = g_slist_reverse(_group->childList(true));
+ while (l) {
+ child = SP_OBJECT (l->data);
+ l = g_slist_remove (l, child);
+ if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
+ child->emitModified(flags);
+ }
+ g_object_unref (G_OBJECT (child));
+ }
+}
+
+void CGroup::calculateBBox(NRRect *bbox, NR::Matrix const &transform, unsigned const flags) {
+
+ boost::optional<NR::Rect> dummy_bbox;
+
+ GSList *l = _group->childList(false, SPObject::ActionBBox);
+ while (l) {
+ SPObject *o = SP_OBJECT (l->data);
+ if (SP_IS_ITEM(o) && !SP_ITEM(o)->isHidden()) {
+ SPItem *child = SP_ITEM(o);
+ NR::Matrix const ct(child->transform * transform);
+ sp_item_invoke_bbox_full(child, &dummy_bbox, ct, flags, FALSE);
+ }
+ l = g_slist_remove (l, o);
+ }
+
+ *bbox = NRRect(dummy_bbox);
+}
+
+void CGroup::onPrint(SPPrintContext *ctx) {
+ GSList *l = g_slist_reverse(_group->childList(false));
+ while (l) {
+ SPObject *o = SP_OBJECT (l->data);
+ if (SP_IS_ITEM(o)) {
+ sp_item_invoke_print (SP_ITEM (o), ctx);
+ }
+ l = g_slist_remove (l, o);
+ }
+}
+
+gint CGroup::getItemCount() {
+ gint len = 0;
+ for (SPObject *o = sp_object_first_child(SP_OBJECT(_group)) ; o != NULL ; o = SP_OBJECT_NEXT(o) ) {
+ if (SP_IS_ITEM(o)) {
+ len++;
+ }
+ }
+
+ return len;
+}
+
+gchar *CGroup::getDescription() {
+ gint len = getItemCount();
+ return g_strdup_printf(
+ ngettext("<b>Group</b> of <b>%d</b> object",
+ "<b>Group</b> of <b>%d</b> objects",
+ len), len);
+}
+
+NRArenaItem *CGroup::show (NRArena *arena, unsigned int key, unsigned int flags) {
+ NRArenaItem *ai;
+ SPObject *object = SP_OBJECT(_group);
+
+ ai = NRArenaGroup::create(arena);
+
+ nr_arena_group_set_transparent(NR_ARENA_GROUP (ai),
+ _group->effectiveLayerMode(key) ==
+ SPGroup::LAYER);
+ nr_arena_group_set_style(NR_ARENA_GROUP(ai), SP_OBJECT_STYLE(object));
+
+ _showChildren(arena, ai, key, flags);
+ return ai;
+}
+
+void CGroup::_showChildren (NRArena *arena, NRArenaItem *ai, unsigned int key, unsigned int flags) {
+ NRArenaItem *ac = NULL;
+ NRArenaItem *ar = NULL;
+ SPItem * child = NULL;
+ GSList *l = g_slist_reverse(_group->childList(false, SPObject::ActionShow));
+ while (l) {
+ SPObject *o = SP_OBJECT (l->data);
+ if (SP_IS_ITEM (o)) {
+ child = SP_ITEM (o);
+ ac = sp_item_invoke_show (child, arena, key, flags);
+ if (ac) {
+ nr_arena_item_add_child (ai, ac, ar);
+ ar = ac;
+ nr_arena_item_unref (ac);
+ }
+ }
+ l = g_slist_remove (l, o);
+ }
+}
+
+void CGroup::hide (unsigned int key) {
+ SPItem * child;
+
+ GSList *l = g_slist_reverse(_group->childList(false, SPObject::ActionShow));
+ while (l) {
+ SPObject *o = SP_OBJECT (l->data);
+ if (SP_IS_ITEM (o)) {
+ child = SP_ITEM (o);
+ sp_item_invoke_hide (child, key);
+ }
+ l = g_slist_remove (l, o);
+ }
+
+ if (((SPItemClass *) parent_class)->hide)
+ ((SPItemClass *) parent_class)->hide (_group, key);
+}
+
+void CGroup::onOrderChanged (Inkscape::XML::Node *child, Inkscape::XML::Node *, Inkscape::XML::Node *)
+{
+ SPObject *ochild = sp_object_get_child_by_repr(_group, child);
+ if ( ochild && SP_IS_ITEM(ochild) ) {
+ /* TODO: this should be moved into SPItem somehow */
+ SPItemView *v;
+ unsigned position = sp_item_pos_in_parent(SP_ITEM(ochild));
+ for ( v = SP_ITEM (ochild)->display ; v != NULL ; v = v->next ) {
+ nr_arena_item_set_order (v->arenaitem, position);
+ }
+ }
+
+ _group->requestModified(SP_OBJECT_MODIFIED_FLAG);
+}
+
+static void
+sp_group_update_patheffect (SPLPEItem *lpeitem, bool write)
+{
+#ifdef GROUP_VERBOSE
+ g_message("sp_group_update_patheffect: %p\n", lpeitem);
+#endif
+ g_return_if_fail (lpeitem != NULL);
+ g_return_if_fail (SP_IS_GROUP (lpeitem));
+
+ GSList const *item_list = sp_item_group_item_list(SP_GROUP(lpeitem));
+ for ( GSList const *iter = item_list; iter; iter = iter->next ) {
+ SPObject *subitem = static_cast<SPObject *>(iter->data);
+ if (SP_IS_LPE_ITEM(subitem)) {
+ if (SP_LPE_ITEM_CLASS (G_OBJECT_GET_CLASS (subitem))->update_patheffect) {
+ SP_LPE_ITEM_CLASS (G_OBJECT_GET_CLASS (subitem))->update_patheffect (SP_LPE_ITEM(subitem), write);
+ }
+ }
+ }
+
+ if (sp_lpe_item_has_path_effect(lpeitem) && sp_lpe_item_path_effects_enabled(lpeitem)) {
+ for (PathEffectList::iterator it = lpeitem->path_effect_list->begin(); it != lpeitem->path_effect_list->end(); it++)
+ {
+ LivePathEffectObject *lpeobj = (*it)->lpeobject;
+ lpeobj->lpe->doBeforeEffect(lpeitem);
+ }
+
+ sp_group_perform_patheffect(SP_GROUP(lpeitem), SP_GROUP(lpeitem));
+ }
+}
+
+static void
+sp_group_perform_patheffect(SPGroup *group, SPGroup *topgroup)
+{
+ GSList const *item_list = sp_item_group_item_list(SP_GROUP(group));
+ for ( GSList const *iter = item_list; iter; iter = iter->next ) {
+ SPObject *subitem = static_cast<SPObject *>(iter->data);
+ if (SP_IS_GROUP(subitem)) {
+ sp_group_perform_patheffect(SP_GROUP(subitem), topgroup);
+ } else if (SP_IS_SHAPE(subitem)) {
+ SPCurve * c = sp_shape_get_curve(SP_SHAPE(subitem));
+ sp_lpe_item_perform_path_effect(SP_LPE_ITEM(topgroup), c);
+ sp_shape_set_curve(SP_SHAPE(subitem), c, TRUE);
+
+ Inkscape::XML::Node *repr = SP_OBJECT_REPR(subitem);
+
+ gchar *str = sp_svg_write_path(c->get_pathvector());
+ repr->setAttribute("d", str);
+ g_free(str);
+
+ c->unref();
+ }
+ }
+}
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :