X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fsp-item-group.cpp;h=f43f4ded952fd4c9f0be6a3a41969fa5a98f5b10;hb=1c2557cd7259a8166f07b7982a44e040a44d4db1;hp=0f288a372a9600f562afc47c51a1db1c17eb183f;hpb=7e2d535c37ea0830491ca84263aa3793a07904e0;p=inkscape.git diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp index 0f288a372..f43f4ded9 100644 --- a/src/sp-item-group.cpp +++ b/src/sp-item-group.cpp @@ -6,8 +6,9 @@ * Authors: * Lauris Kaplinski * bulia byak + * Johan Engelen * - * 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 @@ -28,10 +29,12 @@ #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" static void sp_group_class_init (SPGroupClass *klass); static void sp_group_init (SPGroup *group); @@ -203,7 +206,10 @@ sp_group_write (SPObject *object, Inkscape::XML::Node *repr, guint flags) if (flags & SP_OBJECT_WRITE_BUILD) { GSList *l; - if (!repr) repr = sp_repr_new ("svg:g"); + if (!repr) { + Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(object)); + 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); @@ -292,8 +298,10 @@ static void sp_group_snappoints (SPItem const *item, SnapPointsIter p) o != NULL; o = SP_OBJECT_NEXT(o)) { - if (SP_IS_ITEM(o)) { - sp_item_snappoints(SP_ITEM(o), p); + if (SP_IS_ITEM(o) && !SP_IS_PATH(o)) { + // getSnapPoints() and sp_group_snappoints are only being used in the selector tool, + // which should not snap path nodes. Only the node tool should snap those. + sp_item_snappoints(SP_ITEM(o), p); } } } @@ -359,7 +367,7 @@ sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done) 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; @@ -382,17 +390,14 @@ sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done) // 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); } } @@ -415,7 +420,6 @@ sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done) } /* 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 @@ -425,26 +429,19 @@ sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done) 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")); } /* @@ -591,18 +588,27 @@ void CGroup::onChildRemoved(Inkscape::XML::Node */*child*/) { } void CGroup::onUpdate(SPCtx *ctx, unsigned int flags) { - SPObject *child; SPItemCtx *ictx, cctx; ictx = (SPItemCtx *) ctx; cctx = *ictx; - if (flags & SP_OBJECT_MODIFIED_FLAG) flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; + if (flags & SP_OBJECT_MODIFIED_FLAG) { + flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; + } + flags &= SP_OBJECT_MODIFIED_CASCADE; - GSList *l = g_slist_reverse(_childList(true, ActionUpdate)); + 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) { - child = SP_OBJECT (l->data); + 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)) { @@ -618,24 +624,20 @@ void CGroup::onUpdate(SPCtx *ctx, unsigned int flags) { } } -GSList *CGroup::_childList(bool add_ref, Action) { - GSList *l = NULL; - for (SPObject *child = sp_object_first_child(_group) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) { - if (add_ref) - g_object_ref (G_OBJECT (child)); - - l = g_slist_prepend (l, child); - } - return l; -} - void CGroup::onModified(guint flags) { SPObject *child; if (flags & SP_OBJECT_MODIFIED_FLAG) flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; flags &= SP_OBJECT_MODIFIED_CASCADE; - GSList *l = g_slist_reverse(_childList(true)); + 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); @@ -647,7 +649,7 @@ void CGroup::onModified(guint flags) { } void CGroup::calculateBBox(NRRect *bbox, NR::Matrix const &transform, unsigned const flags) { - GSList *l = _childList(false, ActionBBox); + GSList *l = _group->childList(false, SPObject::ActionBBox); while (l) { SPObject *o = SP_OBJECT (l->data); if (SP_IS_ITEM(o)) { @@ -660,7 +662,7 @@ void CGroup::calculateBBox(NRRect *bbox, NR::Matrix const &transform, unsigned c } void CGroup::onPrint(SPPrintContext *ctx) { - GSList *l = g_slist_reverse(_childList(false)); + GSList *l = g_slist_reverse(_group->childList(false)); while (l) { SPObject *o = SP_OBJECT (l->data); if (SP_IS_ITEM(o)) { @@ -691,11 +693,14 @@ gchar *CGroup::getDescription() { 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; @@ -705,7 +710,7 @@ void CGroup::_showChildren (NRArena *arena, NRArenaItem *ai, unsigned int key, u NRArenaItem *ac = NULL; NRArenaItem *ar = NULL; SPItem * child = NULL; - GSList *l = g_slist_reverse(_childList(false, ActionShow)); + GSList *l = g_slist_reverse(_group->childList(false, SPObject::ActionShow)); while (l) { SPObject *o = SP_OBJECT (l->data); if (SP_IS_ITEM (o)) { @@ -724,7 +729,7 @@ void CGroup::_showChildren (NRArena *arena, NRArenaItem *ai, unsigned int key, u void CGroup::hide (unsigned int key) { SPItem * child; - GSList *l = g_slist_reverse(_childList(false, ActionShow)); + GSList *l = g_slist_reverse(_group->childList(false, SPObject::ActionShow)); while (l) { SPObject *o = SP_OBJECT (l->data); if (SP_IS_ITEM (o)) { @@ -752,3 +757,14 @@ void CGroup::onOrderChanged (Inkscape::XML::Node *child, Inkscape::XML::Node *, _group->requestModified(SP_OBJECT_MODIFIED_FLAG); } + +/* + 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 :