diff options
| author | Marc Jeanmougin <mc@localhost.localdomain> | 2015-02-17 02:00:37 +0000 |
|---|---|---|
| committer | Marc Jeanmougin <mc@localhost.localdomain> | 2015-02-17 02:00:37 +0000 |
| commit | a7f2b2ba3f13ceb60376802f4a31e104153839e8 (patch) | |
| tree | 6db393e9e5a0a9ab7916a0e7ed29d875efa39ea1 /src/selection-chemistry.cpp | |
| parent | device-manager: Get rid of GLists (diff) | |
| download | inkscape-a7f2b2ba3f13ceb60376802f4a31e104153839e8.tar.gz inkscape-a7f2b2ba3f13ceb60376802f4a31e104153839e8.zip | |
At first, I was thinking "I just have to go to the selection file, and change that GSList* with a std::list, then resolve the few problems"
So, i tried that.
And I will continue tomorrow, and the days after, on and on.
(bzr r13922.1.1)
Diffstat (limited to 'src/selection-chemistry.cpp')
| -rw-r--r-- | src/selection-chemistry.cpp | 779 |
1 files changed, 366 insertions, 413 deletions
diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index c9837aabe..f20df1594 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -279,25 +279,23 @@ void SelectionHelper::fixSelection(SPDesktop *dt) Inkscape::Selection *selection = dt->getSelection(); - GSList *items = NULL; + SelContainer items ; - GSList const *selList = selection->itemList(); + SelContainer const selList = selection->itemList(); - for( GSList const *i = selList; i; i = i->next ) { - SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(i->data)); + for( SelContainer::const_iterator i=selList.begin();i!=selList.end();i++ ) { + SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(*i)); if( item && !dt->isLayer(item) && (!item->isLocked())) { - items = g_slist_prepend(items, item); + items.push_front(item); } } selection->setList(items); - if(items) { - g_slist_free(items); - } + items.clear(); } } // namespace Inkscape @@ -307,7 +305,7 @@ void SelectionHelper::fixSelection(SPDesktop *dt) * Copies repr and its inherited css style elements, along with the accumulated transform 'full_t', * then prepends the copy to 'clip'. */ -static void sp_selection_copy_one(Inkscape::XML::Node *repr, Geom::Affine full_t, GSList **clip, Inkscape::XML::Document* xml_doc) +static void sp_selection_copy_one(Inkscape::XML::Node *repr, Geom::Affine full_t, SelContainer &clip, Inkscape::XML::Document* xml_doc) { Inkscape::XML::Node *copy = repr->duplicate(xml_doc); @@ -323,18 +321,18 @@ static void sp_selection_copy_one(Inkscape::XML::Node *repr, Geom::Affine full_t copy->setAttribute("transform", affinestr); g_free(affinestr); - *clip = g_slist_prepend(*clip, copy); + clip.push_front(dynamic_cast<SPObject*>(copy)); } -static void sp_selection_copy_impl(GSList const *items, GSList **clip, Inkscape::XML::Document* xml_doc) +static void sp_selection_copy_impl(SelContainer const &items, SelContainer &clip, Inkscape::XML::Document* xml_doc) { // Sort items: - GSList *sorted_items = g_slist_copy(const_cast<GSList *>(items)); - sorted_items = g_slist_sort(static_cast<GSList *>(sorted_items), (GCompareFunc) sp_object_compare_position); + SelContainer sorted_items(items); + sorted_items.sort(sp_object_compare_position); // Copy item reprs: - for (GSList *i = sorted_items; i != NULL; i = i->next) { - SPItem *item = dynamic_cast<SPItem *>(SP_OBJECT(i->data)); + for (SelContainer::const_iterator i = sorted_items.begin();i!=sorted_items.end();i++) { + SPItem *item = dynamic_cast<SPItem *>(SP_OBJECT(*i)); if (item) { sp_selection_copy_one(item->getRepr(), item->i2doc_affine(), clip, xml_doc); } else { @@ -342,22 +340,22 @@ static void sp_selection_copy_impl(GSList const *items, GSList **clip, Inkscape: } } - *clip = g_slist_reverse(*clip); - g_slist_free(static_cast<GSList *>(sorted_items)); + clip.reverse(); + sorted_items.clear(); } // TODO check if parent parameter should be changed to SPItem, of if the code should handle non-items. -static GSList *sp_selection_paste_impl(SPDocument *doc, SPObject *parent, GSList **clip) +static SelContainer sp_selection_paste_impl(SPDocument *doc, SPObject *parent, SelContainer &clip) { Inkscape::XML::Document *xml_doc = doc->getReprDoc(); SPItem *parentItem = dynamic_cast<SPItem *>(parent); g_assert(parentItem != NULL); - GSList *copied = NULL; + SelContainer copied; // add objects to document - for (GSList *l = *clip; l != NULL; l = l->next) { - Inkscape::XML::Node *repr = static_cast<Inkscape::XML::Node *>(l->data); + for (SelContainer::const_iterator l=clip.begin();l!=clip.end();l++) { + Inkscape::XML::Node *repr = dynamic_cast<Inkscape::XML::Node *>(*l); Inkscape::XML::Node *copy = repr->duplicate(xml_doc); // premultiply the item transform by the accumulated parent transform in the paste layer @@ -375,19 +373,19 @@ static GSList *sp_selection_paste_impl(SPDocument *doc, SPObject *parent, GSList } parent->appendChildRepr(copy); - copied = g_slist_prepend(copied, copy); + copied.push_front(dynamic_cast<SPObject*>(copy)); Inkscape::GC::release(copy); } return copied; } -static void sp_selection_delete_impl(GSList const *items, bool propagate = true, bool propagate_descendants = true) +static void sp_selection_delete_impl(SelContainer const &items, bool propagate = true, bool propagate_descendants = true) { - for (GSList const *i = items ; i ; i = i->next ) { - sp_object_ref(static_cast<SPItem *>(i->data), NULL); + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++) { + sp_object_ref(static_cast<SPItem *>(*i), NULL); } - for (GSList const *i = items; i != NULL; i = i->next) { - SPItem *item = static_cast<SPItem *>(i->data); + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++) { + SPItem *item = static_cast<SPItem *>(*i); item->deleteObject(propagate, propagate_descendants); sp_object_unref(item, NULL); } @@ -414,11 +412,10 @@ void sp_selection_delete(SPDesktop *desktop) desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("<b>Nothing</b> was deleted.")); return; } - - GSList *selected = g_slist_copy(const_cast<GSList *>(selection->itemList())); + SelContainer selected(selection->itemList()); selection->clear(); sp_selection_delete_impl(selected); - g_slist_free(selected); + selected.clear(); desktop->currentLayer()->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); /* a tool may have set up private information in it's selection context @@ -446,6 +443,10 @@ static void add_ids_recursive(std::vector<const gchar *> &ids, SPObject *obj) } } +bool sp_repr_compare_position_obj(SPObject* &a,SPObject* &b){ + return sp_repr_compare_position(dynamic_cast<Inkscape::XML::Node*>(a),dynamic_cast<Inkscape::XML::Node*>(b)); +} + void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) { if (desktop == NULL) { @@ -461,16 +462,15 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to duplicate.")); return; } - - GSList *reprs = g_slist_copy(const_cast<GSList *>(selection->reprList())); + SelContainer reprs(selection->reprList()); selection->clear(); // sorting items from different parents sorts each parent's subset without possibly mixing // them, just what we need - reprs = g_slist_sort(reprs, (GCompareFunc) sp_repr_compare_position); + reprs.sort(sp_repr_compare_position_obj); - GSList *newsel = NULL; + SelContainer newsel; std::vector<const gchar *> old_ids; std::vector<const gchar *> new_ids; @@ -478,8 +478,8 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) bool relink_clones = prefs->getBool("/options/relinkclonesonduplicate/value"); const bool fork_livepatheffects = prefs->getBool("/options/forklpeonduplicate/value", true); - while (reprs) { - Inkscape::XML::Node *old_repr = static_cast<Inkscape::XML::Node *>(reprs->data); + while (!reprs.empty()) { + Inkscape::XML::Node *old_repr = dynamic_cast<Inkscape::XML::Node *>(reprs.front()); Inkscape::XML::Node *parent = old_repr->parent(); Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); @@ -500,8 +500,8 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) } } - newsel = g_slist_prepend(newsel, copy); - reprs = g_slist_remove(reprs, reprs->data); + newsel.push_front(dynamic_cast<SPObject*>(copy)); + reprs.pop_front(); Inkscape::GC::release(copy); } @@ -548,7 +548,7 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) selection->setReprList(newsel); - g_slist_free(newsel); + newsel.clear(); } void sp_edit_clear_all(Inkscape::Selection *selection) @@ -561,11 +561,11 @@ void sp_edit_clear_all(Inkscape::Selection *selection) SPGroup *group = dynamic_cast<SPGroup *>(selection->layers()->currentLayer()); g_return_if_fail(group != NULL); - GSList *items = sp_item_group_item_list(group); + SelContainer items = sp_item_group_item_list(group); - while (items) { - reinterpret_cast<SPObject*>(items->data)->deleteObject(); - items = g_slist_remove(items, items->data); + while (!items.empty()) { + reinterpret_cast<SPObject*>(items.front())->deleteObject(); + items.pop_front(); } DocumentUndo::done(doc, SP_VERB_EDIT_CLEAR_ALL, @@ -582,7 +582,7 @@ void sp_edit_clear_all(Inkscape::Selection *selection) * onlysensitive - TRUE includes only non-locked items * ingroups - TRUE to recursively get grouped items children */ -GSList *get_all_items(GSList *list, SPObject *from, SPDesktop *desktop, bool onlyvisible, bool onlysensitive, bool ingroups, GSList const *exclude) +SelContainer &get_all_items(SelContainer &list, SPObject *from, SPDesktop *desktop, bool onlyvisible, bool onlysensitive, bool ingroups, SelContainer const &exclude) { for ( SPObject *child = from->firstChild() ; child; child = child->getNext() ) { SPItem *item = dynamic_cast<SPItem *>(child); @@ -590,10 +590,10 @@ GSList *get_all_items(GSList *list, SPObject *from, SPDesktop *desktop, bool onl !desktop->isLayer(item) && (!onlysensitive || !item->isLocked()) && (!onlyvisible || !desktop->itemIsHidden(item)) && - (!exclude || !g_slist_find(const_cast<GSList *>(exclude), child)) + (exclude.empty() || exclude.end() == std::find(exclude.begin(),exclude.end(),child)) ) { - list = g_slist_prepend(list, item); + list.push_front(item); } if (ingroups || (item && desktop->isLayer(item))) { @@ -618,9 +618,9 @@ static void sp_edit_select_all_full(SPDesktop *dt, bool force_all_layers, bool i bool onlyvisible = prefs->getBool("/options/kbselection/onlyvisible", true); bool onlysensitive = prefs->getBool("/options/kbselection/onlysensitive", true); - GSList *items = NULL; + SelContainer items ; - GSList const *exclude = NULL; + SelContainer exclude; if (invert) { exclude = selection->itemList(); } @@ -634,39 +634,41 @@ static void sp_edit_select_all_full(SPDesktop *dt, bool force_all_layers, bool i (onlyvisible && dt->itemIsHidden(dynamic_cast<SPItem *>(dt->currentLayer()))) ) return; - GSList *all_items = sp_item_group_item_list(dynamic_cast<SPGroup *>(dt->currentLayer())); + SelContainer all_items = sp_item_group_item_list(dynamic_cast<SPGroup *>(dt->currentLayer())); - for (GSList *i = all_items; i; i = i->next) { - SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(i->data)); + for (SelContainer::const_iterator i=all_items.begin();i!=all_items.end();i++) { + SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(*i)); if (item && (!onlysensitive || !item->isLocked())) { if (!onlyvisible || !dt->itemIsHidden(item)) { if (!dt->isLayer(item)) { - if (!invert || !g_slist_find(const_cast<GSList *>(exclude), item)) { - items = g_slist_prepend(items, item); // leave it in the list + if (!invert || exclude.end() == std::find(exclude.begin(),exclude.end(),item)) { + items.push_front(item); // leave it in the list } } } } } - g_slist_free(all_items); + all_items.clear(); break; } case PREFS_SELECTION_LAYER_RECURSIVE: { - items = get_all_items(NULL, dt->currentLayer(), dt, onlyvisible, onlysensitive, FALSE, exclude); + SelContainer x; + items = get_all_items(x, dt->currentLayer(), dt, onlyvisible, onlysensitive, FALSE, exclude); break; } default: { - items = get_all_items(NULL, dt->currentRoot(), dt, onlyvisible, onlysensitive, FALSE, exclude); + SelContainer x; + items = get_all_items(x, dt->currentRoot(), dt, onlyvisible, onlysensitive, FALSE, exclude); break; } } selection->setList(items); - if (items) { - g_slist_free(items); + if (!items.empty()) { + items.clear(); } } @@ -690,16 +692,16 @@ void sp_edit_invert_in_all_layers(SPDesktop *desktop) sp_edit_select_all_full(desktop, true, true); } -static void sp_selection_group_impl(GSList *p, Inkscape::XML::Node *group, Inkscape::XML::Document *xml_doc, SPDocument *doc) { +static void sp_selection_group_impl(SelContainer p, Inkscape::XML::Node *group, Inkscape::XML::Document *xml_doc, SPDocument *doc) { - p = g_slist_sort(p, (GCompareFunc) sp_repr_compare_position); + p.sort(sp_repr_compare_position_obj); // Remember the position and parent of the topmost object. - gint topmost = (static_cast<Inkscape::XML::Node *>(g_slist_last(p)->data))->position(); - Inkscape::XML::Node *topmost_parent = (static_cast<Inkscape::XML::Node *>(g_slist_last(p)->data))->parent(); + gint topmost = (dynamic_cast<Inkscape::XML::Node *>(p.back()))->position(); + Inkscape::XML::Node *topmost_parent = (dynamic_cast<Inkscape::XML::Node *>(p.back()))->parent(); - while (p) { - Inkscape::XML::Node *current = static_cast<Inkscape::XML::Node *>(p->data); + while (!p.empty()) { + Inkscape::XML::Node *current = dynamic_cast<Inkscape::XML::Node *>(p.front()); if (current->parent() == topmost_parent) { Inkscape::XML::Node *spnew = current->duplicate(xml_doc); @@ -708,7 +710,7 @@ static void sp_selection_group_impl(GSList *p, Inkscape::XML::Node *group, Inksc Inkscape::GC::release(spnew); topmost --; // only reduce count for those items deleted from topmost_parent } else { // move it to topmost_parent first - GSList *temp_clip = NULL; + SelContainer temp_clip; // At this point, current may already have no item, due to its being a clone whose original is already moved away // So we copy it artificially calculating the transform from its repr->attr("transform") and the parent transform @@ -724,15 +726,15 @@ static void sp_selection_group_impl(GSList *p, Inkscape::XML::Node *group, Inksc // then, if this is clone, looking up its original in that array and pre-multiplying // it by the inverse of that original's transform diff. - sp_selection_copy_one(current, item_t, &temp_clip, xml_doc); + sp_selection_copy_one(current, item_t, temp_clip, xml_doc); sp_repr_unparent(current); // paste into topmost_parent (temporarily) - GSList *copied = sp_selection_paste_impl(doc, doc->getObjectByRepr(topmost_parent), &temp_clip); - if (temp_clip) g_slist_free(temp_clip); - if (copied) { // if success, + SelContainer copied = sp_selection_paste_impl(doc, doc->getObjectByRepr(topmost_parent), temp_clip); + if (!temp_clip.empty())temp_clip.clear() ; + if (!copied.empty()) { // if success, // take pasted object (now in topmost_parent) - Inkscape::XML::Node *in_topmost = static_cast<Inkscape::XML::Node *>(copied->data); + Inkscape::XML::Node *in_topmost = dynamic_cast<Inkscape::XML::Node *>(copied.front()); // make a copy Inkscape::XML::Node *spnew = in_topmost->duplicate(xml_doc); // remove pasted @@ -740,10 +742,10 @@ static void sp_selection_group_impl(GSList *p, Inkscape::XML::Node *group, Inksc // put its copy into group group->appendChild(spnew); Inkscape::GC::release(spnew); - g_slist_free(copied); + copied.clear(); } } - p = g_slist_remove(p, current); + p.pop_front(); } // Add the new group to the topmost members' parent @@ -764,9 +766,7 @@ void sp_selection_group(Inkscape::Selection *selection, SPDesktop *desktop) return; } - GSList const *l = const_cast<GSList *>(selection->reprList()); - - GSList *p = g_slist_copy(const_cast<GSList *>(l)); + SelContainer p (selection->reprList()); selection->clear(); @@ -802,11 +802,11 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop) } // first check whether there is anything to ungroup - GSList *old_select = const_cast<GSList *>(selection->itemList()); - GSList *new_select = NULL; + SelContainer old_select = selection->itemList(); + SelContainer new_select; GSList *groups = NULL; - for (GSList *item = old_select; item; item = item->next) { - SPItem *obj = static_cast<SPItem*>(item->data); + for (SelContainer::const_iterator item = old_select.begin(); item!=old_select.end(); item++) { + SPItem *obj = static_cast<SPItem*>(*item); if (dynamic_cast<SPGroup *>(obj)) { groups = g_slist_prepend(groups, obj); } @@ -818,14 +818,14 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop) return; } - GSList *items = g_slist_copy(old_select); + SelContainer items(old_select); selection->clear(); // If any of the clones refer to the groups, unlink them and replace them with successors // in the items list. GSList *clones_to_unlink = NULL; - for (GSList *item = items; item; item = item->next) { - SPUse *use = dynamic_cast<SPUse *>(static_cast<SPItem *>(item->data)); + for (SelContainer::const_iterator item = items.begin(); item!=items.end(); item++) { + SPUse *use = dynamic_cast<SPUse *>(static_cast<SPItem *>(*item)); SPItem *original = use; while (dynamic_cast<SPUse *>(original)) { @@ -833,7 +833,7 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop) } if (g_slist_find(groups, original) != NULL) { - clones_to_unlink = g_slist_prepend(clones_to_unlink, item->data); + clones_to_unlink = g_slist_prepend(clones_to_unlink, *item); } } @@ -844,57 +844,57 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop) for (GSList *item = clones_to_unlink; item; item = item->next) { SPUse *use = static_cast<SPUse *>(item->data); - GSList *items_node = g_slist_find(items, item->data); - items_node->data = use->unlink(); + SelContainer::iterator items_node = std::find(items.begin(),items.end(), item->data); + (*items_node) = use->unlink(); } g_slist_free(clones_to_unlink); // do the actual work - for (GSList *item = items; item; item = item->next) { - SPItem *obj = static_cast<SPItem *>(item->data); + for (SelContainer::iterator item = items.begin(); item!=items.end(); item++) { + SPItem *obj = static_cast<SPItem *>(*item); // ungroup only the groups marked earlier - if (g_slist_find(groups, item->data) != NULL) { - GSList *children = NULL; - sp_item_group_ungroup(dynamic_cast<SPGroup *>(obj), &children, false); + if (g_slist_find(groups, *item) != NULL) { + SelContainer children; + sp_item_group_ungroup(dynamic_cast<SPGroup *>(obj), children, false); // add the items resulting from ungrouping to the selection - new_select = g_slist_concat(new_select, children); - item->data = NULL; // zero out the original pointer, which is no longer valid + new_select.splice(new_select.end(),children); + (*item) = NULL; // zero out the original pointer, which is no longer valid } else { // if not a group, keep in the selection - new_select = g_slist_append(new_select, item->data); + new_select.push_back(*item); } } selection->addList(new_select); - g_slist_free(new_select); - g_slist_free(items); + new_select.clear(); + items.clear(); DocumentUndo::done(selection->layers()->getDocument(), SP_VERB_SELECTION_UNGROUP, _("Ungroup")); } /** Replace all groups in the list with their member objects, recursively; returns a new list, frees old */ -GSList * -sp_degroup_list(GSList *items) +SelContainer +sp_degroup_list(SelContainer &items) { - GSList *out = NULL; + SelContainer out; bool has_groups = false; - for (GSList *item = items; item; item = item->next) { - SPGroup *group = dynamic_cast<SPGroup *>(static_cast<SPObject *>(item->data)); + for (SelContainer::const_iterator item=items.begin();item!=items.end();item++) { + SPGroup *group = dynamic_cast<SPGroup *>(static_cast<SPObject *>(*item)); if (!group) { - out = g_slist_prepend(out, item->data); + out.push_front(*item); } else { has_groups = true; - GSList *members = sp_item_group_item_list(group); - for (GSList *member = members; member; member = member->next) { - out = g_slist_prepend(out, member->data); + SelContainer members = sp_item_group_item_list(group); + for (SelContainer::const_iterator member=members.begin();member!=members.end();member++) { + out.push_front(*member); } - g_slist_free(members); + members.clear(); } } - out = g_slist_reverse(out); - g_slist_free(items); + out.reverse(); + items.clear(); if (has_groups) { // recurse if we unwrapped a group - it may have contained others out = sp_degroup_list(out); @@ -906,18 +906,19 @@ sp_degroup_list(GSList *items) /** If items in the list have a common parent, return it, otherwise return NULL */ static SPGroup * -sp_item_list_common_parent_group(GSList const *items) +sp_item_list_common_parent_group(SelContainer const items) { - if (!items) { + if (items.empty()) { return NULL; } - SPObject *parent = SP_OBJECT(items->data)->parent; + SPObject *parent = SP_OBJECT(items.front())->parent; // Strictly speaking this CAN happen, if user selects <svg> from Inkscape::XML editor if (!dynamic_cast<SPGroup *>(parent)) { return NULL; } - for (items = items->next; items; items = items->next) { - if (SP_OBJECT(items->data)->parent != parent) { + for (SelContainer::const_iterator item=items.begin();item!=items.end();item++) { + if((*item)==items.front())continue; + if (SP_OBJECT(*item)->parent != parent) { return NULL; } } @@ -927,13 +928,13 @@ sp_item_list_common_parent_group(GSList const *items) /** Finds out the minimum common bbox of the selected items. */ static Geom::OptRect -enclose_items(GSList const *items) +enclose_items(SelContainer const &items) { - g_assert(items != NULL); + g_assert(!items.empty()); Geom::OptRect r; - for (GSList const *i = items; i; i = i->next) { - r.unionWith(static_cast<SPItem *>(i->data)->desktopVisualBounds()); + for (SelContainer::const_iterator i = items.begin();i!=items.end();i++) { + r.unionWith(static_cast<SPItem *>(*i)->desktopVisualBounds()); } return r; } @@ -948,11 +949,17 @@ static SPObject *prev_sibling(SPObject *child) return prev; } +int sp_item_repr_compare_position_obj(SPObject const *first, SPObject const *second) +{ + return sp_repr_compare_position(((SPItem*)first)->getRepr(), + ((SPItem*)second)->getRepr())<0; +} + void sp_selection_raise(Inkscape::Selection *selection, SPDesktop *desktop) { - GSList const *items = const_cast<GSList *>(selection->itemList()); - if (!items) { + SelContainer items= selection->itemList(); + if (items.empty()) { selection_display_message(desktop, Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to raise.")); return; } @@ -966,16 +973,16 @@ sp_selection_raise(Inkscape::Selection *selection, SPDesktop *desktop) Inkscape::XML::Node *grepr = const_cast<Inkscape::XML::Node *>(group->getRepr()); /* Construct reverse-ordered list of selected children. */ - GSList *rev = g_slist_copy(const_cast<GSList *>(items)); - rev = g_slist_sort(rev, (GCompareFunc) sp_item_repr_compare_position); + SelContainer rev(items); + rev.sort(sp_item_repr_compare_position_obj); // Determine the common bbox of the selected items. Geom::OptRect selected = enclose_items(items); // Iterate over all objects in the selection (starting from top). if (selected) { - while (rev) { - SPObject *child = reinterpret_cast<SPObject*>(rev->data); + while (!rev.empty()) { + SPObject *child = reinterpret_cast<SPObject*>(rev.front()); // for each selected object, find the next sibling for (SPObject *newref = child->next; newref; newref = newref->next) { // if the sibling is an item AND overlaps our selection, @@ -984,7 +991,7 @@ sp_selection_raise(Inkscape::Selection *selection, SPDesktop *desktop) Geom::OptRect newref_bbox = newItem->desktopVisualBounds(); if ( newref_bbox && selected->intersects(*newref_bbox) ) { // AND if it's not one of our selected objects, - if (!g_slist_find(const_cast<GSList *>(items), newref)) { + if ( std::find(items.begin(),items.end(),newref)==items.end()) { // move the selected object after that sibling grepr->changeOrder(child->getRepr(), newref->getRepr()); } @@ -992,10 +999,10 @@ sp_selection_raise(Inkscape::Selection *selection, SPDesktop *desktop) } } } - rev = g_slist_remove(rev, child); + rev.pop_front(); } } else { - g_slist_free(rev); + rev.clear(); } DocumentUndo::done(selection->layers()->getDocument(), SP_VERB_SELECTION_RAISE, @@ -1012,7 +1019,7 @@ void sp_selection_raise_to_top(Inkscape::Selection *selection, SPDesktop *deskto return; } - GSList const *items = const_cast<GSList *>(selection->itemList()); + SelContainer items = selection->itemList(); SPGroup const *group = sp_item_list_common_parent_group(items); if (!group) { @@ -1020,15 +1027,15 @@ void sp_selection_raise_to_top(Inkscape::Selection *selection, SPDesktop *deskto return; } - GSList *rl = g_slist_copy(const_cast<GSList *>(selection->reprList())); - rl = g_slist_sort(rl, (GCompareFunc) sp_repr_compare_position); + SelContainer rl(selection->reprList()); + rl.sort(sp_repr_compare_position_obj); - for (GSList *l = rl; l != NULL; l = l->next) { - Inkscape::XML::Node *repr = static_cast<Inkscape::XML::Node *>(l->data); + for (SelContainer::iterator l=rl.begin(); l!=rl.end();l++) { + Inkscape::XML::Node *repr = dynamic_cast<Inkscape::XML::Node *>(*l); repr->setPosition(-1); } - g_slist_free(rl); + rl.clear(); DocumentUndo::done(document, SP_VERB_SELECTION_TO_FRONT, _("Raise to top")); @@ -1036,8 +1043,8 @@ void sp_selection_raise_to_top(Inkscape::Selection *selection, SPDesktop *deskto void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop) { - GSList const *items = const_cast<GSList *>(selection->itemList()); - if (!items) { + SelContainer items = selection->itemList(); + if (items.empty()) { selection_display_message(desktop, Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to lower.")); return; } @@ -1054,14 +1061,14 @@ void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop) Geom::OptRect selected = enclose_items(items); /* Construct direct-ordered list of selected children. */ - GSList *rev = g_slist_copy(const_cast<GSList *>(items)); - rev = g_slist_sort(rev, (GCompareFunc) sp_item_repr_compare_position); - rev = g_slist_reverse(rev); + SelContainer rev(items); + rev.sort(sp_item_repr_compare_position_obj); + rev.reverse(); // Iterate over all objects in the selection (starting from top). if (selected) { - while (rev) { - SPObject *child = reinterpret_cast<SPObject*>(rev->data); + while (!rev.empty()) { + SPObject *child = reinterpret_cast<SPObject*>(rev.front()); // for each selected object, find the prev sibling for (SPObject *newref = prev_sibling(child); newref; newref = prev_sibling(newref)) { // if the sibling is an item AND overlaps our selection, @@ -1070,7 +1077,7 @@ void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop) Geom::OptRect ref_bbox = newItem->desktopVisualBounds(); if ( ref_bbox && selected->intersects(*ref_bbox) ) { // AND if it's not one of our selected objects, - if (!g_slist_find(const_cast<GSList *>(items), newref)) { + if (items.end()==std::find(items.begin(),items.end(),newref)) { // move the selected object before that sibling SPObject *put_after = prev_sibling(newref); if (put_after) @@ -1082,10 +1089,10 @@ void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop) } } } - rev = g_slist_remove(rev, child); + rev.pop_front(); } } else { - g_slist_free(rev); + rev.clear(); } DocumentUndo::done(selection->layers()->getDocument(), SP_VERB_SELECTION_LOWER, @@ -1102,7 +1109,7 @@ void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *des return; } - GSList const *items = const_cast<GSList *>(selection->itemList()); + SelContainer items =selection->itemList(); SPGroup const *group = sp_item_list_common_parent_group(items); if (!group) { @@ -1110,15 +1117,14 @@ void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *des return; } - GSList *rl; - rl = g_slist_copy(const_cast<GSList *>(selection->reprList())); - rl = g_slist_sort(rl, (GCompareFunc) sp_repr_compare_position); - rl = g_slist_reverse(rl); + SelContainer rl(selection->reprList()); + rl.sort(sp_repr_compare_position_obj); + rl.reverse(); - for (GSList *l = rl; l != NULL; l = l->next) { + for (SelContainer::const_iterator l=rl.begin();l!=rl.end();l++) { gint minpos; SPObject *pp, *pc; - Inkscape::XML::Node *repr = static_cast<Inkscape::XML::Node *>(l->data); + Inkscape::XML::Node *repr = dynamic_cast<Inkscape::XML::Node *>(*l); pp = document->getObjectByRepr(repr->parent()); minpos = 0; g_assert(dynamic_cast<SPGroup *>(pp)); @@ -1130,7 +1136,7 @@ void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *des repr->setPosition(minpos); } - g_slist_free(rl); + rl.clear(); DocumentUndo::done(document, SP_VERB_SELECTION_TO_BACK, _("Lower to bottom")); @@ -1269,9 +1275,9 @@ void sp_selection_remove_livepatheffect(SPDesktop *desktop) desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to remove live path effects from.")); return; } - - for ( GSList const *itemlist = selection->itemList(); itemlist != NULL; itemlist = g_slist_next(itemlist) ) { - SPItem *item = reinterpret_cast<SPItem*>(itemlist->data); + SelContainer list=selection->itemList(); + for ( SelContainer::const_iterator itemlist=list.begin();itemlist!=list.end();itemlist++) { + SPItem *item = reinterpret_cast<SPItem*>(*itemlist); sp_selection_remove_livepatheffect_impl(item); @@ -1331,25 +1337,25 @@ void sp_selection_to_next_layer(SPDesktop *dt, bool suppressDone) return; } - GSList const *items = g_slist_copy(const_cast<GSList *>(selection->itemList())); + SelContainer items(selection->itemList()); bool no_more = false; // Set to true, if no more layers above SPObject *next=Inkscape::next_layer(dt->currentRoot(), dt->currentLayer()); if (next) { - GSList *temp_clip = NULL; - sp_selection_copy_impl(items, &temp_clip, dt->doc()->getReprDoc()); + SelContainer temp_clip; + sp_selection_copy_impl(items, temp_clip, dt->doc()->getReprDoc()); sp_selection_delete_impl(items, false, false); next=Inkscape::next_layer(dt->currentRoot(), dt->currentLayer()); // Fixes bug 1482973: crash while moving layers - GSList *copied; + SelContainer copied; if (next) { - copied = sp_selection_paste_impl(dt->getDocument(), next, &temp_clip); + copied = sp_selection_paste_impl(dt->getDocument(), next, temp_clip); } else { - copied = sp_selection_paste_impl(dt->getDocument(), dt->currentLayer(), &temp_clip); + copied = sp_selection_paste_impl(dt->getDocument(), dt->currentLayer(), temp_clip); no_more = true; } - selection->setReprList((GSList const *) copied); - g_slist_free(copied); - if (temp_clip) g_slist_free(temp_clip); + selection->setReprList(copied); + copied.clear(); + if (!temp_clip.empty()) temp_clip.clear(); if (next) dt->setCurrentLayer(next); if ( !suppressDone ) { DocumentUndo::done(dt->getDocument(), SP_VERB_LAYER_MOVE_TO_NEXT, @@ -1363,7 +1369,7 @@ void sp_selection_to_next_layer(SPDesktop *dt, bool suppressDone) dt->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("No more layers above.")); } - g_slist_free(const_cast<GSList *>(items)); + items.clear(); } void sp_selection_to_prev_layer(SPDesktop *dt, bool suppressDone) @@ -1376,25 +1382,25 @@ void sp_selection_to_prev_layer(SPDesktop *dt, bool suppressDone) return; } - GSList const *items = g_slist_copy(const_cast<GSList *>(selection->itemList())); + const SelContainer items(selection->itemList()); bool no_more = false; // Set to true, if no more layers below SPObject *next=Inkscape::previous_layer(dt->currentRoot(), dt->currentLayer()); if (next) { - GSList *temp_clip = NULL; - sp_selection_copy_impl(items, &temp_clip, dt->doc()->getReprDoc()); // we're in the same doc, so no need to copy defs + SelContainer temp_clip; + sp_selection_copy_impl(items, temp_clip, dt->doc()->getReprDoc()); // we're in the same doc, so no need to copy defs sp_selection_delete_impl(items, false, false); next=Inkscape::previous_layer(dt->currentRoot(), dt->currentLayer()); // Fixes bug 1482973: crash while moving layers - GSList *copied; + SelContainer copied; if (next) { - copied = sp_selection_paste_impl(dt->getDocument(), next, &temp_clip); + copied = sp_selection_paste_impl(dt->getDocument(), next, temp_clip); } else { - copied = sp_selection_paste_impl(dt->getDocument(), dt->currentLayer(), &temp_clip); + copied = sp_selection_paste_impl(dt->getDocument(), dt->currentLayer(), temp_clip); no_more = true; } - selection->setReprList((GSList const *) copied); - g_slist_free(copied); - if (temp_clip) g_slist_free(temp_clip); + selection->setReprList( copied); + copied.clear(); + if (!temp_clip.empty()) temp_clip.clear(); if (next) dt->setCurrentLayer(next); if ( !suppressDone ) { DocumentUndo::done(dt->getDocument(), SP_VERB_LAYER_MOVE_TO_PREV, @@ -1407,8 +1413,6 @@ void sp_selection_to_prev_layer(SPDesktop *dt, bool suppressDone) if (no_more) { dt->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("No more layers below.")); } - - g_slist_free(const_cast<GSList *>(items)); } void sp_selection_to_layer(SPDesktop *dt, SPObject *moveto, bool suppressDone) @@ -1421,24 +1425,22 @@ void sp_selection_to_layer(SPDesktop *dt, SPObject *moveto, bool suppressDone) return; } - GSList const *items = g_slist_copy(const_cast<GSList *>(selection->itemList())); + SelContainer items(selection->itemList()); if (moveto) { - GSList *temp_clip = NULL; - sp_selection_copy_impl(items, &temp_clip, dt->doc()->getReprDoc()); // we're in the same doc, so no need to copy defs + SelContainer temp_clip; + sp_selection_copy_impl(items, temp_clip, dt->doc()->getReprDoc()); // we're in the same doc, so no need to copy defs sp_selection_delete_impl(items, false, false); - GSList *copied = sp_selection_paste_impl(dt->getDocument(), moveto, &temp_clip); - selection->setReprList((GSList const *) copied); - g_slist_free(copied); - if (temp_clip) g_slist_free(temp_clip); + SelContainer copied = sp_selection_paste_impl(dt->getDocument(), moveto, temp_clip); + selection->setReprList(copied); + copied.clear(); + if (!temp_clip.empty()) temp_clip.clear(); if (moveto) dt->setCurrentLayer(moveto); if ( !suppressDone ) { DocumentUndo::done(dt->getDocument(), SP_VERB_LAYER_MOVE_TO, _("Move selection to layer")); } } - - g_slist_free(const_cast<GSList *>(items)); } static bool @@ -1473,8 +1475,9 @@ static bool selection_contains_both_clone_and_original(Inkscape::Selection *selection) { bool clone_with_original = false; - for (GSList const *l = selection->itemList(); l != NULL; l = l->next) { - SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(l->data)); + SelContainer items = selection->itemList(); + for (SelContainer::const_iterator l=items.begin();l!=items.end() ;l++) { + SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(*l)); if (item) { clone_with_original |= selection_contains_original(item, selection); if (clone_with_original) @@ -1517,9 +1520,9 @@ void sp_selection_apply_affine(Inkscape::Selection *selection, Geom::Affine cons persp3d_apply_affine_transformation(transf_persp, affine); } - - for (GSList const *l = selection->itemList(); l != NULL; l = l->next) { - SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(l->data)); + SelContainer items = selection->itemList(); + for (SelContainer::const_iterator l=items.begin();l!=items.end() ;l++) { + SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(*l)); if( dynamic_cast<SPRoot *>(item) ) { // An SVG element cannot have a transform. We could change 'x' and 'y' in response @@ -1688,10 +1691,9 @@ void sp_selection_remove_transform(SPDesktop *desktop) Inkscape::Selection *selection = desktop->getSelection(); - GSList const *l = const_cast<GSList *>(selection->reprList()); - while (l != NULL) { - ((Inkscape::XML::Node*)l->data)->setAttribute("transform", NULL, false); - l = l->next; + SelContainer items = selection->itemList(); + for (SelContainer::const_iterator l=items.begin();l!=items.end() ;l++) { + ((Inkscape::XML::Node*)*l)->setAttribute("transform", NULL, false); } DocumentUndo::done(desktop->getDocument(), SP_VERB_OBJECT_FLATTEN, @@ -1789,10 +1791,10 @@ void sp_selection_rotate_90(SPDesktop *desktop, bool ccw) if (selection->isEmpty()) return; - GSList const *l = selection->itemList(); + SelContainer items = selection->itemList(); Geom::Rotate const rot_90(Geom::Point(0, ccw ? 1 : -1)); // pos. or neg. rotation, depending on the value of ccw - for (GSList const *l2 = l ; l2 != NULL ; l2 = l2->next) { - SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(l2->data)); + for (SelContainer::const_iterator l=items.begin();l!=items.end() ;l++) { + SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(*l)); if (item) { sp_item_rotate_rel(item, rot_90); } else { @@ -1848,15 +1850,15 @@ void sp_select_same_fill_stroke_style(SPDesktop *desktop, gboolean fill, gboolea bool onlyvisible = prefs->getBool("/options/kbselection/onlyvisible", true); bool onlysensitive = prefs->getBool("/options/kbselection/onlysensitive", true); bool ingroups = TRUE; - - GSList *all_list = get_all_items(NULL, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, NULL); - GSList *all_matches = NULL; + SelContainer x,y; + SelContainer all_list = get_all_items(x, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, y); + SelContainer all_matches; Inkscape::Selection *selection = desktop->getSelection(); - - for (GSList const* sel_iter = selection->itemList(); sel_iter; sel_iter = sel_iter->next) { - SPItem *sel = dynamic_cast<SPItem *>(static_cast<SPObject *>(sel_iter->data)); - GSList *matches = all_list; + SelContainer items = selection->itemList(); + for (SelContainer::const_iterator sel_iter=items.begin();sel_iter!=items.end();sel_iter++) { + SPItem *sel = dynamic_cast<SPItem *>(static_cast<SPObject *>(*sel_iter)); + SelContainer matches = all_list; if (fill) { matches = sp_get_same_fill_or_stroke_color(sel, matches, SP_FILL_COLOR); } @@ -1868,19 +1870,12 @@ void sp_select_same_fill_stroke_style(SPDesktop *desktop, gboolean fill, gboolea matches = sp_get_same_stroke_style(sel, matches, SP_STROKE_STYLE_DASHES); matches = sp_get_same_stroke_style(sel, matches, SP_STROKE_STYLE_MARKERS); } - all_matches = g_slist_concat (all_matches, matches); + all_matches.splice(all_matches.end(), matches); } selection->clear(); selection->setList(all_matches); - if (all_matches) { - g_slist_free(all_matches); - } - if (all_list) { - g_slist_free(all_list); - } - } @@ -1901,14 +1896,15 @@ void sp_select_same_object_type(SPDesktop *desktop) bool onlyvisible = prefs->getBool("/options/kbselection/onlyvisible", true); bool onlysensitive = prefs->getBool("/options/kbselection/onlysensitive", true); bool ingroups = TRUE; - - GSList *all_list = get_all_items(NULL, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, NULL); - GSList *matches = all_list; + SelContainer x,y; + SelContainer all_list = get_all_items(x, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, y); + SelContainer matches = all_list; Inkscape::Selection *selection = desktop->getSelection(); - for (GSList const* sel_iter = selection->itemList(); sel_iter; sel_iter = sel_iter->next) { - SPItem *sel = dynamic_cast<SPItem *>(static_cast<SPObject *>(sel_iter->data)); + SelContainer items=selection->itemList(); + for (SelContainer::const_iterator sel_iter=items.begin();sel_iter!=items.end();sel_iter++) { + SPItem *sel = dynamic_cast<SPItem *>(static_cast<SPObject *>(*sel_iter)); if (sel) { matches = sp_get_same_object_type(sel, matches); } else { @@ -1919,12 +1915,6 @@ void sp_select_same_object_type(SPDesktop *desktop) selection->clear(); selection->setList(matches); - if (matches) { - g_slist_free(matches); - } - if (all_list) { - g_slist_free(all_list); - } } /* @@ -1944,13 +1934,14 @@ void sp_select_same_stroke_style(SPDesktop *desktop) bool onlysensitive = prefs->getBool("/options/kbselection/onlysensitive", true); bool ingroups = TRUE; - GSList *all_list = get_all_items(NULL, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, NULL); - GSList *matches = all_list; + SelContainer x,y; + SelContainer matches = get_all_items(x, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, y); Inkscape::Selection *selection = desktop->getSelection(); + SelContainer items=selection->itemList(); - for (GSList const* sel_iter = selection->itemList(); sel_iter; sel_iter = sel_iter->next) { - SPItem *sel = dynamic_cast<SPItem *>(static_cast<SPObject *>(sel_iter->data)); + for (SelContainer::const_iterator sel_iter=items.begin();sel_iter!=items.end();sel_iter++) { + SPItem *sel = dynamic_cast<SPItem *>(static_cast<SPObject *>(*sel_iter)); if (sel) { matches = sp_get_same_stroke_style(sel, matches, SP_STROKE_STYLE_WIDTH); matches = sp_get_same_stroke_style(sel, matches, SP_STROKE_STYLE_DASHES); @@ -1963,27 +1954,21 @@ void sp_select_same_stroke_style(SPDesktop *desktop) selection->clear(); selection->setList(matches); - if (matches) { - g_slist_free(matches); - } - if (all_list) { - g_slist_free(all_list); - } } /* * Find all items in src list that have the same fill or stroke style as sel * Return the list of matching items */ -GSList *sp_get_same_fill_or_stroke_color(SPItem *sel, GSList *src, SPSelectStrokeStyleType type) +SelContainer sp_get_same_fill_or_stroke_color(SPItem *sel, SelContainer &src, SPSelectStrokeStyleType type) { - GSList *matches = NULL; + SelContainer matches ; gboolean match = false; SPIPaint *sel_paint = (type == SP_FILL_COLOR) ? &(sel->style->fill) : &(sel->style->stroke); - for (GSList *i = src; i != NULL; i = i->next) { - SPItem *iter = dynamic_cast<SPItem *>(static_cast<SPObject *>(i->data)); + for (SelContainer::const_iterator i=src.begin();i!=src.end();i++) { + SPItem *iter = dynamic_cast<SPItem *>(static_cast<SPObject *>(*i)); if (iter) { SPIPaint *iter_paint = (type == SP_FILL_COLOR) ? &(iter->style->fill) : &(iter->style->stroke); match = false; @@ -2022,7 +2007,7 @@ GSList *sp_get_same_fill_or_stroke_color(SPItem *sel, GSList *src, SPSelectStrok } if (match) { - matches = g_slist_prepend(matches, iter); + matches.push_front(iter); } } else { g_assert_not_reached(); @@ -2073,17 +2058,16 @@ static bool item_type_match (SPItem *i, SPItem *j) * Find all items in src list that have the same object type as sel by type * Return the list of matching items */ -GSList *sp_get_same_object_type(SPItem *sel, GSList *src) +SelContainer sp_get_same_object_type(SPItem *sel, SelContainer &src) { - GSList *matches = NULL; + SelContainer matches; - for (GSList *i = src; i != NULL; i = i->next) { - SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(i->data)); + for (SelContainer::const_iterator i=src.begin();i!=src.end();i++) { + SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(*i)); if (item && item_type_match(sel, item)) { - matches = g_slist_prepend (matches, item); + matches.push_front(item); } } - return matches; } @@ -2091,9 +2075,9 @@ GSList *sp_get_same_object_type(SPItem *sel, GSList *src) * Find all items in src list that have the same stroke style as sel by type * Return the list of matching items */ -GSList *sp_get_same_stroke_style(SPItem *sel, GSList *src, SPSelectStrokeStyleType type) +SelContainer sp_get_same_stroke_style(SPItem *sel, SelContainer &src, SPSelectStrokeStyleType type) { - GSList *matches = NULL; + SelContainer matches; gboolean match = false; SPStyle *sel_style = sel->style; @@ -2106,16 +2090,15 @@ GSList *sp_get_same_stroke_style(SPItem *sel, GSList *src, SPSelectStrokeStyleTy * Stroke width needs to handle transformations, so call this function * to get the transformed stroke width */ - GSList *objects = NULL; + SelContainer objects; SPStyle *sel_style_for_width = NULL; if (type == SP_STROKE_STYLE_WIDTH) { - objects = g_slist_prepend(objects, sel); + objects.push_front(sel); sel_style_for_width = new SPStyle(SP_ACTIVE_DOCUMENT); objects_query_strokewidth (objects, sel_style_for_width); } - - for (GSList *i = src; i != NULL; i = i->next) { - SPItem *iter = dynamic_cast<SPItem *>(static_cast<SPObject *>(i->data)); + for (SelContainer::const_iterator i=src.begin();i!=src.end();i++) { + SPItem *iter = dynamic_cast<SPItem *>(static_cast<SPObject *>(*i)); if (iter) { SPStyle *iter_style = iter->style; match = false; @@ -2123,15 +2106,15 @@ GSList *sp_get_same_stroke_style(SPItem *sel, GSList *src, SPSelectStrokeStyleTy if (type == SP_STROKE_STYLE_WIDTH) { match = (sel_style->stroke_width.set == iter_style->stroke_width.set); if (sel_style->stroke_width.set && iter_style->stroke_width.set) { - GSList *objects = NULL; - objects = g_slist_prepend(objects, iter); + SelContainer objects; + objects.push_front(iter); SPStyle tmp_style(SP_ACTIVE_DOCUMENT); objects_query_strokewidth (objects, &tmp_style); if (sel_style_for_width) { match = (sel_style_for_width->stroke_width.computed == tmp_style.stroke_width.computed); } - g_slist_free(objects); + objects.clear(); } } else if (type == SP_STROKE_STYLE_DASHES ) { @@ -2154,7 +2137,7 @@ GSList *sp_get_same_stroke_style(SPItem *sel, GSList *src, SPSelectStrokeStyleTy } if (match) { - matches = g_slist_prepend(matches, iter); + matches.push_front(iter); } } else { g_assert_not_reached(); @@ -2162,8 +2145,6 @@ GSList *sp_get_same_stroke_style(SPItem *sel, GSList *src, SPSelectStrokeStyleTy } if( sel_style_for_width != NULL ) delete sel_style_for_width; - g_slist_free(objects); - return matches; } @@ -2320,11 +2301,11 @@ sp_selection_move_screen(Inkscape::Selection *selection, gdouble dx, gdouble dy) namespace { template <typename D> -SPItem *next_item(SPDesktop *desktop, GSList *path, SPObject *root, +SPItem *next_item(SPDesktop *desktop, SelContainer &path, SPObject *root, bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive); template <typename D> -SPItem *next_item_from_list(SPDesktop *desktop, GSList const *items, SPObject *root, +SPItem *next_item_from_list(SPDesktop *desktop, SelContainer const &items, SPObject *root, bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive); struct Forward { @@ -2618,17 +2599,17 @@ void sp_selection_clone(SPDesktop *desktop) return; } - GSList *reprs = g_slist_copy(const_cast<GSList *>(selection->reprList())); + SelContainer reprs (selection->reprList()); selection->clear(); // sorting items from different parents sorts each parent's subset without possibly mixing them, just what we need - reprs = g_slist_sort(reprs, (GCompareFunc) sp_repr_compare_position); + reprs.sort(sp_repr_compare_position_obj); - GSList *newsel = NULL; + SelContainer newsel; - while (reprs) { - Inkscape::XML::Node *sel_repr = static_cast<Inkscape::XML::Node *>(reprs->data); + while (!reprs.empty()) { + Inkscape::XML::Node *sel_repr = dynamic_cast<Inkscape::XML::Node *>(reprs.front()); Inkscape::XML::Node *parent = sel_repr->parent(); Inkscape::XML::Node *clone = xml_doc->createElement("svg:use"); @@ -2644,8 +2625,8 @@ void sp_selection_clone(SPDesktop *desktop) // add the new clone to the top of the original's parent parent->appendChild(clone); - newsel = g_slist_prepend(newsel, clone); - reprs = g_slist_remove(reprs, sel_repr); + newsel.push_front(dynamic_cast<SPObject*>(clone)); + reprs.pop_front(); Inkscape::GC::release(clone); } @@ -2653,8 +2634,6 @@ void sp_selection_clone(SPDesktop *desktop) C_("Action", "Clone")); selection->setReprList(newsel); - - g_slist_free(newsel); } void @@ -2680,11 +2659,9 @@ sp_selection_relink(SPDesktop *desktop) // Get a copy of current selection. bool relinked = false; - for (GSList *items = const_cast<GSList *>(selection->itemList()); - items != NULL; - items = items->next) - { - SPItem *item = static_cast<SPItem *>(items->data); + SelContainer items=selection->itemList(); + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + SPItem *item = static_cast<SPItem *>(*i); if (dynamic_cast<SPUse *>(item)) { item->getRepr()->setAttribute("xlink:href", newref); @@ -2718,13 +2695,11 @@ sp_selection_unlink(SPDesktop *desktop) } // Get a copy of current selection. - GSList *new_select = NULL; + SelContainer new_select; bool unlinked = false; - for (GSList *items = g_slist_copy(const_cast<GSList *>(selection->itemList())); - items != NULL; - items = items->next) - { - SPItem *item = static_cast<SPItem *>(items->data); + SelContainer items=selection->itemList(); + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + SPItem *item = static_cast<SPItem *>(*i); if (dynamic_cast<SPText *>(item)) { SPObject *tspan = sp_tref_convert_to_tspan(item); @@ -2740,7 +2715,7 @@ sp_selection_unlink(SPDesktop *desktop) if (!(dynamic_cast<SPUse *>(item) || dynamic_cast<SPTRef *>(item))) { // keep the non-use item in the new selection - new_select = g_slist_prepend(new_select, item); + new_select.push_front(item); continue; } @@ -2750,7 +2725,7 @@ sp_selection_unlink(SPDesktop *desktop) unlink = use->unlink(); // Unable to unlink use (external or invalid href?) if (!unlink) { - new_select = g_slist_prepend(new_select, item); + new_select.push_front(item); continue; } } else /*if (SP_IS_TREF(use))*/ { @@ -2760,13 +2735,12 @@ sp_selection_unlink(SPDesktop *desktop) unlinked = true; // Add ungrouped items to the new selection. - new_select = g_slist_prepend(new_select, unlink); + new_select.push_front(unlink); } - if (new_select) { // set new selection + if (!new_select.empty()) { // set new selection selection->clear(); selection->setList(new_select); - g_slist_free(new_select); } if (!unlinked) { desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No clones to unlink</b> in the selection.")); @@ -2789,7 +2763,9 @@ sp_select_clone_original(SPDesktop *desktop) gchar const *error = _("Select a <b>clone</b> to go to its original. Select a <b>linked offset</b> to go to its source. Select a <b>text on path</b> to go to the path. Select a <b>flowed text</b> to go to its frame."); // Check if other than two objects are selected - if (g_slist_length(const_cast<GSList *>(selection->itemList())) != 1 || !item) { + + SelContainer items=selection->itemList(); + if (items.size() != 1 || !item) { desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, error); return; } @@ -2886,14 +2862,15 @@ void sp_selection_clone_original_path_lpe(SPDesktop *desktop) Inkscape::SVGOStringStream os; SPObject * firstItem = NULL; - for (const GSList * item = selection->itemList(); item != NULL; item = item->next) { - if (SP_IS_SHAPE(item->data) || SP_IS_TEXT(item->data)) { + SelContainer items=selection->itemList(); + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + if (SP_IS_SHAPE(*i) || SP_IS_TEXT(*i)) { if (firstItem) { os << "|"; } else { - firstItem = SP_ITEM(item->data); + firstItem = SP_ITEM(*i); } - os << '#' << SP_ITEM(item->data)->getId() << ",0"; + os << '#' << SP_ITEM(*i)->getId() << ",0"; } } if (firstItem) { @@ -2970,12 +2947,12 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply) Geom::Point center( *c - corner ); // As defined by rotation center center[Geom::Y] = -center[Geom::Y]; - GSList *items = g_slist_copy(const_cast<GSList *>(selection->itemList())); + SelContainer items(selection->itemList()); //items = g_slist_sort(items, (GCompareFunc) sp_object_compare_position); // Why needed? // bottommost object, after sorting - SPObject *parent = SP_OBJECT(items->data)->parent; + SPObject *parent = SP_OBJECT(items.front())->parent; Geom::Affine parent_transform; { @@ -2988,10 +2965,10 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply) } // Create a list of duplicates, to be pasted inside marker element. - GSList *repr_copies = NULL; - for (GSList *i = items; i != NULL; i = i->next) { - Inkscape::XML::Node *dup = SP_OBJECT(i->data)->getRepr()->duplicate(xml_doc); - repr_copies = g_slist_prepend(repr_copies, dup); + SelContainer repr_copies; + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + Inkscape::XML::Node *dup = SP_OBJECT(*i)->getRepr()->duplicate(xml_doc); + repr_copies.push_front(dynamic_cast<SPObject*>(dup)); } Geom::Rect bbox(desktop->dt2doc(r->min()), desktop->dt2doc(r->max())); @@ -2999,8 +2976,8 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply) if (apply) { // Delete objects so that their clones don't get alerted; // the objects will be restored inside the marker element. - for (GSList *i = items; i != NULL; i = i->next) { - SPObject *item = reinterpret_cast<SPObject*>(i->data); + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + SPObject *item = reinterpret_cast<SPObject*>(*i); item->deleteObject(false); } } @@ -3019,7 +2996,6 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply) prefs->setInt("/options/clonecompensation/value", saved_compensation); - g_slist_free(items); DocumentUndo::done(doc, SP_VERB_EDIT_SELECTION_2_MARKER, _("Objects to marker")); @@ -3028,8 +3004,9 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply) static void sp_selection_to_guides_recursive(SPItem *item, bool wholegroups) { SPGroup *group = dynamic_cast<SPGroup *>(item); if (group && !dynamic_cast<SPBox3D *>(item) && !wholegroups) { - for (GSList *i = sp_item_group_item_list(group); i != NULL; i = i->next) { - sp_selection_to_guides_recursive(static_cast<SPItem*>(i->data), wholegroups); + SelContainer items=sp_item_group_item_list(group); + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + sp_selection_to_guides_recursive(static_cast<SPItem*>(*i), wholegroups); } } else { item->convert_to_guides(); @@ -3044,9 +3021,9 @@ void sp_selection_to_guides(SPDesktop *desktop) SPDocument *doc = desktop->getDocument(); Inkscape::Selection *selection = desktop->getSelection(); // we need to copy the list because it gets reset when objects are deleted - GSList *items = g_slist_copy(const_cast<GSList *>(selection->itemList())); + SelContainer items(selection->itemList()); - if (!items) { + if (items.empty()) { desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to convert to guides.")); return; } @@ -3059,8 +3036,8 @@ void sp_selection_to_guides(SPDesktop *desktop) // and its entry in the selection list is invalid (crash). // Therefore: first convert all, then delete all. - for (GSList const *i = items; i != NULL; i = i->next) { - sp_selection_to_guides_recursive(static_cast<SPItem*>(i->data), wholegroups); + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + sp_selection_to_guides_recursive(static_cast<SPItem*>(*i), wholegroups); } if (deleteitems) { @@ -3068,8 +3045,6 @@ void sp_selection_to_guides(SPDesktop *desktop) sp_selection_delete_impl(items); } - g_slist_free(items); - DocumentUndo::done(doc, SP_VERB_EDIT_SELECTION_2_GUIDES, _("Objects to guides")); } @@ -3112,18 +3087,18 @@ void sp_selection_symbol(SPDesktop *desktop, bool /*apply*/ ) doc->ensureUpToDate(); - GSList *items = g_slist_copy(const_cast<GSList *>(selection->list())); + SelContainer items(selection->list()); // Keep track of parent, this is where <use> will be inserted. - Inkscape::XML::Node *the_first_repr = reinterpret_cast<SPObject *>( items->data )->getRepr(); + Inkscape::XML::Node *the_first_repr = reinterpret_cast<SPObject *>( items.front() )->getRepr(); Inkscape::XML::Node *the_parent_repr = the_first_repr->parent(); // Find out if we have a single group bool single_group = false; SPGroup *the_group = NULL; Geom::Affine transform; - if( g_slist_length( items ) == 1 ) { - SPObject *object = reinterpret_cast<SPObject *>( items->data ); + if( items.size() == 1 ) { + SPObject *object = reinterpret_cast<SPObject *>( items.front() ); the_group = dynamic_cast<SPGroup *>(object); if ( the_group ) { single_group = true; @@ -3134,7 +3109,6 @@ void sp_selection_symbol(SPDesktop *desktop, bool /*apply*/ ) if( transform.isTranslation() ) { // Create new list from group children. - g_slist_free(items); items = object->childList(false); // Hack: Temporarily set clone compensation to unmoved, so that we can move clone-originals @@ -3180,8 +3154,8 @@ void sp_selection_symbol(SPDesktop *desktop, bool /*apply*/ ) } // Move selected items to new <symbol> - for (GSList *i = items; i != NULL; i = i->next) { - Inkscape::XML::Node *repr = SP_OBJECT(i->data)->getRepr(); + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + Inkscape::XML::Node *repr = SP_OBJECT(*i)->getRepr(); repr->parent()->removeChild(repr); symbol_repr->addChild(repr,NULL); } @@ -3207,7 +3181,6 @@ void sp_selection_symbol(SPDesktop *desktop, bool /*apply*/ ) // Clean up Inkscape::GC::release(symbol_repr); - g_slist_free(items); DocumentUndo::done(doc, SP_VERB_EDIT_SYMBOL, _("Group to symbol")); } @@ -3248,26 +3221,25 @@ void sp_selection_unsymbol(SPDesktop *desktop) desktop->currentLayer()->getRepr()->appendChild(group); // Move all children of symbol to group - GSList* children = symbol->childList(false); + SelContainer children = symbol->childList(false); // Converting a group to a symbol inserts a group for non-translational transform. // In converting a symbol back to a group we strip out the inserted group (or any other // group that only adds a transform to the symbol content). - if( g_slist_length( children ) == 1 ) { - SPObject *object = reinterpret_cast<SPObject *>( children->data ); + if( children.size() == 1 ) { + SPObject *object = reinterpret_cast<SPObject *>( children.front() ); if ( dynamic_cast<SPGroup *>( object ) ) { if( object->getAttribute("style") == NULL || object->getAttribute("class") == NULL ) { group->setAttribute("transform", object->getAttribute("transform")); - g_slist_free(children); children = object->childList(false); } } } - for (GSList* i = children; i != NULL; i = i->next ) { - Inkscape::XML::Node *repr = SP_OBJECT(i->data)->getRepr(); + for (SelContainer::const_iterator i=children.begin();i!=children.end();i++){ + Inkscape::XML::Node *repr = SP_OBJECT(*i)->getRepr(); repr->parent()->removeChild(repr); group->addChild(repr,NULL); } @@ -3293,7 +3265,6 @@ void sp_selection_unsymbol(SPDesktop *desktop) // Clean up Inkscape::GC::release(group); - g_slist_free(children); DocumentUndo::done(doc, SP_VERB_EDIT_UNSYMBOL, _("Group from symbol")); } @@ -3328,12 +3299,12 @@ sp_selection_tile(SPDesktop *desktop, bool apply) move_p[Geom::Y] = -move_p[Geom::Y]; Geom::Affine move = Geom::Affine(Geom::Translate(move_p)); - GSList *items = g_slist_copy(const_cast<GSList *>(selection->itemList())); + SelContainer items (selection->itemList()); - items = g_slist_sort(items, (GCompareFunc) sp_object_compare_position); + items.sort(sp_object_compare_position); // bottommost object, after sorting - SPObject *parent = SP_OBJECT(items->data)->parent; + SPObject *parent = SP_OBJECT(items.front())->parent; Geom::Affine parent_transform; @@ -3347,23 +3318,23 @@ sp_selection_tile(SPDesktop *desktop, bool apply) } // remember the position of the first item - gint pos = SP_OBJECT(items->data)->getRepr()->position(); + gint pos = SP_OBJECT(items.front())->getRepr()->position(); // create a list of duplicates - GSList *repr_copies = NULL; - for (GSList *i = items; i != NULL; i = i->next) { - Inkscape::XML::Node *dup = SP_OBJECT(i->data)->getRepr()->duplicate(xml_doc); - repr_copies = g_slist_prepend(repr_copies, dup); + SelContainer repr_copies; + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + Inkscape::XML::Node *dup = SP_OBJECT(*i)->getRepr()->duplicate(xml_doc); + repr_copies.push_front(dynamic_cast<SPObject*>(dup)); } // restore the z-order after prepends - repr_copies = g_slist_reverse(repr_copies); + repr_copies.reverse(); Geom::Rect bbox(desktop->dt2doc(r->min()), desktop->dt2doc(r->max())); if (apply) { // delete objects so that their clones don't get alerted; this object will be restored shortly - for (GSList *i = items; i != NULL; i = i->next) { - SPObject *item = reinterpret_cast<SPObject*>(i->data); + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + SPObject *item = reinterpret_cast<SPObject*>(*i); item->deleteObject(false); } } @@ -3409,7 +3380,6 @@ sp_selection_tile(SPDesktop *desktop, bool apply) selection->set(rectangle); } - g_slist_free(items); DocumentUndo::done(doc, SP_VERB_EDIT_TILE, _("Objects to pattern")); @@ -3432,15 +3402,13 @@ void sp_selection_untile(SPDesktop *desktop) return; } - GSList *new_select = NULL; + SelContainer new_select; bool did = false; - for (GSList *items = g_slist_copy(const_cast<GSList *>(selection->itemList())); - items != NULL; - items = items->next) { - - SPItem *item = static_cast<SPItem *>(items->data); + SelContainer items(selection->itemList()); + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + SPItem *item = static_cast<SPItem *>(*i); SPStyle *style = item->style; @@ -3476,7 +3444,7 @@ void sp_selection_untile(SPDesktop *desktop) Geom::Affine transform( i->transform * pat_transform ); i->doWriteTransform(i->getRepr(), transform); - new_select = g_slist_prepend(new_select, i); + new_select.push_front(i); } else { g_assert_not_reached(); } @@ -3503,18 +3471,14 @@ void sp_selection_get_export_hints(Inkscape::Selection *selection, Glib::ustring return; } - GSList const *reprlst = selection->reprList(); + SelContainer const reprlst = selection->reprList(); bool filename_search = TRUE; bool xdpi_search = TRUE; bool ydpi_search = TRUE; - for (; reprlst != NULL && - filename_search && - xdpi_search && - ydpi_search; - reprlst = reprlst->next) { + for (SelContainer::const_iterator i=reprlst.begin();filename_search&&xdpi_search&&ydpi_search&&i!=reprlst.end();i++){ gchar const *dpi_string; - Inkscape::XML::Node * repr = static_cast<Inkscape::XML::Node *>(reprlst->data); + Inkscape::XML::Node * repr = dynamic_cast<Inkscape::XML::Node *>(*i); if (filename_search) { const gchar* tmp = repr->attribute("inkscape:export-filename"); @@ -3600,10 +3564,10 @@ void sp_selection_create_bitmap_copy(SPDesktop *desktop) } // List of the items to show; all others will be hidden - GSList *items = g_slist_copy(const_cast<GSList *>(selection->itemList())); + SelContainer items(selection->itemList()); // Sort items so that the topmost comes last - items = g_slist_sort(items, (GCompareFunc) sp_item_repr_compare_position); + items.sort(sp_item_repr_compare_position_obj); // Generate a random value from the current time (you may create bitmap from the same object(s) // multiple times, and this is done so that they don't clash) @@ -3614,7 +3578,7 @@ void sp_selection_create_bitmap_copy(SPDesktop *desktop) // Create the filename. gchar *const basename = g_strdup_printf("%s-%s-%u.png", document->getName(), - SP_OBJECT(items->data)->getRepr()->attribute("id"), + SP_OBJECT(items.front())->getRepr()->attribute("id"), current); // Imagemagick is known not to handle spaces in filenames, so we replace anything but letters, // digits, and a few other chars, with "_" @@ -3634,8 +3598,8 @@ void sp_selection_create_bitmap_copy(SPDesktop *desktop) //g_print("%s\n", filepath); // Remember parent and z-order of the topmost one - gint pos = SP_OBJECT(g_slist_last(items)->data)->getRepr()->position(); - SPObject *parent_object = SP_OBJECT(g_slist_last(items)->data)->parent; + gint pos = SP_OBJECT(items.back())->getRepr()->position(); + SPObject *parent_object = SP_OBJECT(items.back())->parent; Inkscape::XML::Node *parent = parent_object->getRepr(); // Calculate resolution @@ -3727,8 +3691,6 @@ void sp_selection_create_bitmap_copy(SPDesktop *desktop) true, /*bool force_overwrite,*/ items); - g_slist_free(items); - // Run filter, if any if (run) { g_print("Running external filter: %s\n", run); @@ -3803,22 +3765,22 @@ void sp_selection_set_clipgroup(SPDesktop *desktop) return; } - GSList const *l = const_cast<GSList *>(selection->reprList()); + SelContainer l=selection->reprList(); - GSList *p = g_slist_copy(const_cast<GSList *>(l)); + SelContainer p(l); - p = g_slist_sort(p, (GCompareFunc) sp_repr_compare_position); + p.sort(sp_repr_compare_position_obj); selection->clear(); - gint topmost = (static_cast<Inkscape::XML::Node *>(g_slist_last(p)->data))->position(); - Inkscape::XML::Node *topmost_parent = (static_cast<Inkscape::XML::Node *>(g_slist_last(p)->data))->parent(); + gint topmost = (dynamic_cast<Inkscape::XML::Node *>(p.back()))->position(); + Inkscape::XML::Node *topmost_parent = (dynamic_cast<Inkscape::XML::Node *>(p.back()))->parent(); Inkscape::XML::Node *inner = xml_doc->createElement("svg:g"); inner->setAttribute("inkscape:label", "Clip"); - while (p) { - Inkscape::XML::Node *current = static_cast<Inkscape::XML::Node *>(p->data); + while (!p.empty()) { + Inkscape::XML::Node *current = dynamic_cast<Inkscape::XML::Node *>(p.front()); if (current->parent() == topmost_parent) { Inkscape::XML::Node *spnew = current->duplicate(xml_doc); @@ -3827,7 +3789,7 @@ void sp_selection_set_clipgroup(SPDesktop *desktop) Inkscape::GC::release(spnew); topmost --; // only reduce count for those items deleted from topmost_parent } else { // move it to topmost_parent first - GSList *temp_clip = NULL; + SelContainer temp_clip; // At this point, current may already have no item, due to its being a clone whose original is already moved away // So we copy it artificially calculating the transform from its repr->attr("transform") and the parent transform @@ -3843,15 +3805,14 @@ void sp_selection_set_clipgroup(SPDesktop *desktop) // then, if this is clone, looking up its original in that array and pre-multiplying // it by the inverse of that original's transform diff. - sp_selection_copy_one(current, item_t, &temp_clip, xml_doc); + sp_selection_copy_one(current, item_t, temp_clip, xml_doc); sp_repr_unparent(current); // paste into topmost_parent (temporarily) - GSList *copied = sp_selection_paste_impl(doc, doc->getObjectByRepr(topmost_parent), &temp_clip); - if (temp_clip) g_slist_free(temp_clip); - if (copied) { // if success, + SelContainer copied = sp_selection_paste_impl(doc, doc->getObjectByRepr(topmost_parent), temp_clip); + if (!copied.empty()) { // if success, // take pasted object (now in topmost_parent) - Inkscape::XML::Node *in_topmost = static_cast<Inkscape::XML::Node *>(copied->data); + Inkscape::XML::Node *in_topmost = dynamic_cast<Inkscape::XML::Node *>(copied.front()); // make a copy Inkscape::XML::Node *spnew = in_topmost->duplicate(xml_doc); // remove pasted @@ -3859,10 +3820,9 @@ void sp_selection_set_clipgroup(SPDesktop *desktop) // put its copy into group inner->appendChild(spnew); Inkscape::GC::release(spnew); - g_slist_free(copied); } } - p = g_slist_remove(p, current); + p.pop_front(); } Inkscape::XML::Node *outer = xml_doc->createElement("svg:g"); @@ -3920,7 +3880,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ if ( apply_to_layer && is_empty) { desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to create clippath or mask from.")); return; - } else if (!apply_to_layer && ( is_empty || NULL == selection->itemList()->next )) { + } else if (!apply_to_layer && ( is_empty || selection->itemList().size()==1 )) { desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select mask object and <b>object(s)</b> to apply clippath or mask to.")); return; } @@ -3935,9 +3895,9 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ doc->ensureUpToDate(); - GSList *items = g_slist_copy(const_cast<GSList *>(selection->itemList())); + SelContainer items(selection->itemList()); - items = g_slist_sort(items, (GCompareFunc) sp_object_compare_position); + items.sort(sp_object_compare_position); // See lp bug #542004 selection->clear(); @@ -3946,7 +3906,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ GSList *mask_items = NULL; GSList *apply_to_items = NULL; GSList *items_to_delete = NULL; - GSList *items_to_select = NULL; + SelContainer items_to_select; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); bool topmost = prefs->getBool("/options/maskobject/topmost", true); @@ -3957,38 +3917,38 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ // all selected items are used for mask, which is applied to a layer apply_to_items = g_slist_prepend(apply_to_items, desktop->currentLayer()); - for (GSList *i = items; i != NULL; i = i->next) { - Inkscape::XML::Node *dup = SP_OBJECT(i->data)->getRepr()->duplicate(xml_doc); + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++) { + Inkscape::XML::Node *dup = SP_OBJECT(*i)->getRepr()->duplicate(xml_doc); mask_items = g_slist_prepend(mask_items, dup); - SPObject *item = reinterpret_cast<SPObject*>(i->data); + SPObject *item = reinterpret_cast<SPObject*>(*i); if (remove_original) { items_to_delete = g_slist_prepend(items_to_delete, item); } else { - items_to_select = g_slist_prepend(items_to_select, item); + items_to_select.push_front(item); } } } else if (!topmost) { // topmost item is used as a mask, which is applied to other items in a selection - GSList *i = items; - Inkscape::XML::Node *dup = SP_OBJECT(i->data)->getRepr()->duplicate(xml_doc); + Inkscape::XML::Node *dup = SP_OBJECT(items.front())->getRepr()->duplicate(xml_doc); mask_items = g_slist_prepend(mask_items, dup); if (remove_original) { - SPObject *item = reinterpret_cast<SPObject*>(i->data); + SPObject *item = reinterpret_cast<SPObject*>(items.front()); items_to_delete = g_slist_prepend(items_to_delete, item); } - for (i = i->next; i != NULL; i = i->next) { - apply_to_items = g_slist_prepend(apply_to_items, i->data); - items_to_select = g_slist_prepend(items_to_select, i->data); + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++) { + if(i==items.begin())continue; + apply_to_items = g_slist_prepend(apply_to_items, *i); + items_to_select.push_front(*i); } } else { GSList *i = NULL; - for (i = items; NULL != i->next; i = i->next) { - apply_to_items = g_slist_prepend(apply_to_items, i->data); - items_to_select = g_slist_prepend(items_to_select, i->data); + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++) { + apply_to_items = g_slist_prepend(apply_to_items, *i); + items_to_select.push_front(*i); } Inkscape::XML::Node *dup = SP_OBJECT(i->data)->getRepr()->duplicate(xml_doc); @@ -3999,9 +3959,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ items_to_delete = g_slist_prepend(items_to_delete, item); } } - - g_slist_free(items); - items = NULL; + items.clear(); if (apply_to_items && grouping == PREFS_MASKOBJECT_GROUPING_ALL) { // group all those objects into one group @@ -4011,24 +3969,22 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ // make a note we should ungroup this when unsetting mask group->setAttribute("inkscape:groupmode", "maskhelper"); - GSList *reprs_to_group = NULL; + SelContainer reprs_to_group; for (GSList *i = apply_to_items ; NULL != i ; i = i->next) { - reprs_to_group = g_slist_prepend(reprs_to_group, SP_OBJECT(i->data)->getRepr()); - items_to_select = g_slist_remove(items_to_select, i->data); + reprs_to_group.push_front(dynamic_cast<SPObject*>(SP_OBJECT(i->data)->getRepr())); + items_to_select.remove(static_cast<SPObject*>(i->data)); } - reprs_to_group = g_slist_reverse(reprs_to_group); + reprs_to_group.reverse(); sp_selection_group_impl(reprs_to_group, group, xml_doc, doc); - reprs_to_group = NULL; - // apply clip/mask only to newly created group g_slist_free(apply_to_items); apply_to_items = NULL; apply_to_items = g_slist_prepend(apply_to_items, doc->getObjectByRepr(group)); - items_to_select = g_slist_prepend(items_to_select, doc->getObjectByRepr(group)); + items_to_select.push_front(doc->getObjectByRepr(group)); Inkscape::GC::release(group); } @@ -4068,7 +4024,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ Inkscape::XML::Node *spnew = current->duplicate(xml_doc); gint position = current->position(); - items_to_select = g_slist_remove(items_to_select, item); + items_to_select.remove(item); current->parent()->appendChild(group); sp_repr_unparent(current); group->appendChild(spnew); @@ -4077,7 +4033,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ // Apply clip/mask to group instead apply_mask_to = group; - items_to_select = g_slist_prepend(items_to_select, doc->getObjectByRepr(group)); + items_to_select.push_front(doc->getObjectByRepr(group)); Inkscape::GC::release(spnew); Inkscape::GC::release(group); } @@ -4092,14 +4048,13 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ for (GSList *i = items_to_delete; NULL != i; i = i->next) { SPObject *item = reinterpret_cast<SPObject*>(i->data); item->deleteObject(false); - items_to_select = g_slist_remove(items_to_select, item); + items_to_select.remove(item); } g_slist_free(items_to_delete); - items_to_select = g_slist_reverse(items_to_select); + items_to_select.reverse(); selection->addList(items_to_select); - g_slist_free(items_to_select); if (apply_clip_path) { DocumentUndo::done(doc, SP_VERB_OBJECT_SET_CLIPPATH, _("Set clipping path")); @@ -4131,20 +4086,20 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) { gchar const *attributeName = apply_clip_path ? "clip-path" : "mask"; std::map<SPObject*,SPItem*> referenced_objects; - GSList *items = g_slist_copy(const_cast<GSList *>(selection->itemList())); + SelContainer items(selection->itemList()); selection->clear(); GSList *items_to_ungroup = NULL; - GSList *items_to_select = g_slist_copy(items); - items_to_select = g_slist_reverse(items_to_select); + SelContainer items_to_select(items); + items_to_select.reverse(); // SPObject* refers to a group containing the clipped path or mask itself, // whereas SPItem* refers to the item being clipped or masked - for (GSList const *i = items; NULL != i; i = i->next) { + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ if (remove_original) { // remember referenced mask/clippath, so orphaned masks can be moved back to document - SPItem *item = reinterpret_cast<SPItem *>(i->data); + SPItem *item = reinterpret_cast<SPItem *>(*i); Inkscape::URIReference *uri_ref = NULL; if (apply_clip_path) { @@ -4159,9 +4114,9 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) { } } - SP_OBJECT(i->data)->getRepr()->setAttribute(attributeName, "none"); + SP_OBJECT(*i)->getRepr()->setAttribute(attributeName, "none"); - SPGroup *group = dynamic_cast<SPGroup *>(static_cast<SPObject *>(i->data)); + SPGroup *group = dynamic_cast<SPGroup *>(static_cast<SPObject *>(*i)); if (ungroup_masked && group) { // if we had previously enclosed masked object in group, // add it to list so we can ungroup it later @@ -4173,7 +4128,6 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) { } } - g_slist_free(items); // restore mask objects into a document for ( std::map<SPObject*,SPItem*>::iterator it = referenced_objects.begin() ; it != referenced_objects.end() ; ++it) { @@ -4207,7 +4161,7 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) { repr->setPosition((pos + 1) > 0 ? (pos + 1) : 0); SPItem *mask_item = static_cast<SPItem *>(desktop->getDocument()->getObjectByRepr(repr)); - items_to_select = g_slist_prepend(items_to_select, mask_item); + items_to_select.push_front(mask_item); // transform mask, so it is moved the same spot where mask was applied Geom::Affine transform(mask_item->transform); @@ -4222,10 +4176,10 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) { for (GSList *i = items_to_ungroup ; NULL != i ; i = i->next) { SPGroup *group = dynamic_cast<SPGroup *>(static_cast<SPObject *>(i->data)); if (group) { - items_to_select = g_slist_remove(items_to_select, group); - GSList *children = NULL; - sp_item_group_ungroup(group, &children, false); - items_to_select = g_slist_concat(children, items_to_select); + items_to_select.remove(group); + SelContainer children; + sp_item_group_ungroup(group, children, false); + items_to_select.splice(items_to_select.begin(),children); } else { g_assert_not_reached(); } @@ -4234,9 +4188,8 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) { g_slist_free(items_to_ungroup); // rebuild selection - items_to_select = g_slist_reverse(items_to_select); + items_to_select.reverse(); selection->addList(items_to_select); - g_slist_free(items_to_select); if (apply_clip_path) { DocumentUndo::done(doc, SP_VERB_OBJECT_UNSET_CLIPPATH, _("Release clipping path")); |
