diff options
Diffstat (limited to 'src')
113 files changed, 1543 insertions, 1778 deletions
diff --git a/src/conn-avoid-ref.cpp b/src/conn-avoid-ref.cpp index c13b9a5d3..eb6694233 100644 --- a/src/conn-avoid-ref.cpp +++ b/src/conn-avoid-ref.cpp @@ -252,8 +252,9 @@ static std::vector<Geom::Point> approxItemWithPoints(SPItem const *item, const G { SPGroup* group = SP_GROUP(item); // consider all first-order children - for (GSList const* i = sp_item_group_item_list(group); i != NULL; i = i->next) { - SPItem* child_item = SP_ITEM(i->data); + std::vector<SPItem*> itemlist = sp_item_group_item_list(group); + for (std::vector<SPItem*>::const_iterator i = itemlist.begin(); i != itemlist.end(); i++) { + SPItem* child_item = *i; std::vector<Geom::Point> child_points = approxItemWithPoints(child_item, item_transform * child_item->transform); poly_points.insert(poly_points.end(), child_points.begin(), child_points.end()); } diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp index c713e0d61..afdc3064a 100644 --- a/src/desktop-style.cpp +++ b/src/desktop-style.cpp @@ -194,10 +194,10 @@ sp_desktop_set_style(SPDesktop *desktop, SPCSSAttr *css, bool change, bool write sp_repr_css_merge(css_write, css); sp_css_attr_unset_uris(css_write); prefs->mergeStyle("/desktop/style", css_write); - - for (const GSList *i = desktop->selection->itemList(); i != NULL; i = i->next) { + std::vector<SPItem*> const itemlist = desktop->selection->itemList(); + for (std::vector<SPItem*>::const_iterator i = itemlist.begin(); i!= itemlist.end(); i++) { /* last used styles for 3D box faces are stored separately */ - SPObject *obj = reinterpret_cast<SPObject *>(i->data); // TODO unsafe until Selection is refactored. + SPObject *obj = *i; Box3DSide *side = dynamic_cast<Box3DSide *>(obj); if (side) { const char * descr = box3d_side_axes_string(side); @@ -234,8 +234,9 @@ sp_desktop_set_style(SPDesktop *desktop, SPCSSAttr *css, bool change, bool write sp_repr_css_merge(css_no_text, css); css_no_text = sp_css_attr_unset_text(css_no_text); - for (GSList const *i = desktop->selection->itemList(); i != NULL; i = i->next) { - SPItem *item = reinterpret_cast<SPItem *>(i->data); + std::vector<SPItem*> const itemlist = desktop->selection->itemList(); + for (std::vector<SPItem*>::const_iterator i = itemlist.begin(); i!= itemlist.end(); i++) { + SPItem *item = *i; // If not text, don't apply text attributes (can a group have text attributes? Yes! FIXME) if (isTextualItem(item)) { @@ -438,18 +439,16 @@ sp_desktop_get_font_size_tool(SPDesktop *desktop) /** Determine average stroke width, simple method */ // see TODO in dialogs/stroke-style.cpp on how to get rid of this eventually gdouble -stroke_average_width (GSList const *objects) +stroke_average_width (const std::vector<SPItem*> &objects) { - if (g_slist_length ((GSList *) objects) == 0) + if (objects.empty()) return Geom::infinity(); gdouble avgwidth = 0.0; bool notstroked = true; int n_notstroked = 0; - - for (GSList const *l = objects; l != NULL; l = l->next) { - SPObject *obj = reinterpret_cast<SPObject *>(l->data); - SPItem *item = dynamic_cast<SPItem *>(obj); + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) { + SPItem *item = *i; if (!item) { continue; } @@ -471,7 +470,7 @@ stroke_average_width (GSList const *objects) if (notstroked) return Geom::infinity(); - return avgwidth / (g_slist_length ((GSList *) objects) - n_notstroked); + return avgwidth / (objects.size() - n_notstroked); } static bool vectorsClose( std::vector<double> const &lhs, std::vector<double> const &rhs ) @@ -492,9 +491,9 @@ static bool vectorsClose( std::vector<double> const &lhs, std::vector<double> co * Write to style_res the average fill or stroke of list of objects, if applicable. */ int -objects_query_fillstroke (GSList *objects, SPStyle *style_res, bool const isfill) +objects_query_fillstroke (const std::vector<SPItem*> &objects, SPStyle *style_res, bool const isfill) { - if (g_slist_length(objects) == 0) { + if (objects.empty()) { /* No objects, set empty */ return QUERY_STYLE_NOTHING; } @@ -514,8 +513,8 @@ objects_query_fillstroke (GSList *objects, SPStyle *style_res, bool const isfill prev[0] = prev[1] = prev[2] = 0.0; bool same_color = true; - for (GSList const *i = objects; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast<SPObject *>(i->data); + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i!= objects.end(); i++) { + SPObject *obj = *i; if (!obj) { continue; } @@ -674,7 +673,7 @@ objects_query_fillstroke (GSList *objects, SPStyle *style_res, bool const isfill } // Not color - if (g_slist_length(objects) > 1) { + if (objects.size() > 1) { return QUERY_STYLE_MULTIPLE_SAME; } else { return QUERY_STYLE_SINGLE; @@ -685,9 +684,9 @@ objects_query_fillstroke (GSList *objects, SPStyle *style_res, bool const isfill * Write to style_res the average opacity of a list of objects. */ int -objects_query_opacity (GSList *objects, SPStyle *style_res) +objects_query_opacity (const std::vector<SPItem*> &objects, SPStyle *style_res) { - if (g_slist_length(objects) == 0) { + if (objects.empty()) { /* No objects, set empty */ return QUERY_STYLE_NOTHING; } @@ -698,8 +697,8 @@ objects_query_opacity (GSList *objects, SPStyle *style_res) guint opacity_items = 0; - for (GSList const *i = objects; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast<SPObject *>(i->data); + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) { + SPObject *obj = *i; if (!obj) { continue; } @@ -739,9 +738,9 @@ objects_query_opacity (GSList *objects, SPStyle *style_res) * Write to style_res the average stroke width of a list of objects. */ int -objects_query_strokewidth (GSList *objects, SPStyle *style_res) +objects_query_strokewidth (const std::vector<SPItem*> &objects, SPStyle *style_res) { - if (g_slist_length(objects) == 0) { + if (objects.empty()) { /* No objects, set empty */ return QUERY_STYLE_NOTHING; } @@ -754,8 +753,8 @@ objects_query_strokewidth (GSList *objects, SPStyle *style_res) int n_stroked = 0; - for (GSList const *i = objects; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast<SPObject *>(i->data); + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) { + SPObject *obj = *i; if (!obj) { continue; } @@ -815,9 +814,9 @@ objects_query_strokewidth (GSList *objects, SPStyle *style_res) * Write to style_res the average miter limit of a list of objects. */ int -objects_query_miterlimit (GSList *objects, SPStyle *style_res) +objects_query_miterlimit (const std::vector<SPItem*> &objects, SPStyle *style_res) { - if (g_slist_length(objects) == 0) { + if (objects.empty()) { /* No objects, set empty */ return QUERY_STYLE_NOTHING; } @@ -828,8 +827,8 @@ objects_query_miterlimit (GSList *objects, SPStyle *style_res) gdouble prev_ml = -1; bool same_ml = true; - for (GSList const *i = objects; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast<SPObject *>(i->data); + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) { + SPObject *obj = *i; if (!dynamic_cast<SPItem *>(obj)) { continue; } @@ -875,9 +874,9 @@ objects_query_miterlimit (GSList *objects, SPStyle *style_res) * Write to style_res the stroke cap of a list of objects. */ int -objects_query_strokecap (GSList *objects, SPStyle *style_res) +objects_query_strokecap (const std::vector<SPItem*> &objects, SPStyle *style_res) { - if (g_slist_length(objects) == 0) { + if (objects.empty()) { /* No objects, set empty */ return QUERY_STYLE_NOTHING; } @@ -887,8 +886,8 @@ objects_query_strokecap (GSList *objects, SPStyle *style_res) bool same_cap = true; int n_stroked = 0; - for (GSList const *i = objects; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast<SPObject *>(i->data); + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) { + SPObject *obj = *i; if (!dynamic_cast<SPItem *>(obj)) { continue; } @@ -929,9 +928,9 @@ objects_query_strokecap (GSList *objects, SPStyle *style_res) * Write to style_res the stroke join of a list of objects. */ int -objects_query_strokejoin (GSList *objects, SPStyle *style_res) +objects_query_strokejoin (const std::vector<SPItem*> &objects, SPStyle *style_res) { - if (g_slist_length(objects) == 0) { + if (objects.empty()) { /* No objects, set empty */ return QUERY_STYLE_NOTHING; } @@ -941,8 +940,8 @@ objects_query_strokejoin (GSList *objects, SPStyle *style_res) bool same_join = true; int n_stroked = 0; - for (GSList const *i = objects; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast<SPObject *>(i->data); + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) { + SPObject *obj = *i; if (!dynamic_cast<SPItem *>(obj)) { continue; } @@ -984,7 +983,7 @@ objects_query_strokejoin (GSList *objects, SPStyle *style_res) * Write to style_res the average font size and spacing of objects. */ int -objects_query_fontnumbers (GSList *objects, SPStyle *style_res) +objects_query_fontnumbers (const std::vector<SPItem*> &objects, SPStyle *style_res) { bool different = false; @@ -1004,8 +1003,8 @@ objects_query_fontnumbers (GSList *objects, SPStyle *style_res) int texts = 0; int no_size = 0; - for (GSList const *i = objects; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast<SPObject *>(i->data); + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) { + SPObject *obj = *i; if (!isTextualItem(obj)) { continue; @@ -1116,15 +1115,15 @@ objects_query_fontnumbers (GSList *objects, SPStyle *style_res) * Write to style_res the average font style of objects. */ int -objects_query_fontstyle (GSList *objects, SPStyle *style_res) +objects_query_fontstyle (const std::vector<SPItem*> &objects, SPStyle *style_res) { bool different = false; bool set = false; int texts = 0; - for (GSList const *i = objects; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast<SPObject *>(i->data); + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) { + SPObject *obj = *i; if (!isTextualItem(obj)) { continue; @@ -1173,7 +1172,7 @@ objects_query_fontstyle (GSList *objects, SPStyle *style_res) * Write to style_res the baseline numbers. */ static int -objects_query_baselines (GSList *objects, SPStyle *style_res) +objects_query_baselines (const std::vector<SPItem*> &objects, SPStyle *style_res) { bool different = false; @@ -1192,8 +1191,8 @@ objects_query_baselines (GSList *objects, SPStyle *style_res) int texts = 0; - for (GSList const *i = objects; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast<SPObject *>(i->data); + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) { + SPObject *obj = *i; if (!isTextualItem(obj)) { continue; @@ -1269,7 +1268,7 @@ objects_query_baselines (GSList *objects, SPStyle *style_res) * Write to style_res the average font family of objects. */ int -objects_query_fontfamily (GSList *objects, SPStyle *style_res) +objects_query_fontfamily (const std::vector<SPItem*> &objects, SPStyle *style_res) { bool different = false; int texts = 0; @@ -1280,8 +1279,8 @@ objects_query_fontfamily (GSList *objects, SPStyle *style_res) } style_res->font_family.set = FALSE; - for (GSList const *i = objects; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast<SPObject *>(i->data); + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) { + SPObject *obj = *i; // std::cout << " " << reinterpret_cast<SPObject*>(i->data)->getId() << std::endl; if (!isTextualItem(obj)) { @@ -1325,7 +1324,7 @@ objects_query_fontfamily (GSList *objects, SPStyle *style_res) } static int -objects_query_fontspecification (GSList *objects, SPStyle *style_res) +objects_query_fontspecification (const std::vector<SPItem*> &objects, SPStyle *style_res) { bool different = false; int texts = 0; @@ -1336,8 +1335,8 @@ objects_query_fontspecification (GSList *objects, SPStyle *style_res) } style_res->font_specification.set = FALSE; - for (GSList const *i = objects; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast<SPObject *>(i->data); + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) { + SPObject *obj = *i; // std::cout << " " << reinterpret_cast<SPObject*>(i->data)->getId() << std::endl; if (!isTextualItem(obj)) { @@ -1385,7 +1384,7 @@ objects_query_fontspecification (GSList *objects, SPStyle *style_res) } static int -objects_query_blend (GSList *objects, SPStyle *style_res) +objects_query_blend (const std::vector<SPItem*> &objects, SPStyle *style_res) { const int empty_prev = -2; const int complex_filter = 5; @@ -1394,8 +1393,8 @@ objects_query_blend (GSList *objects, SPStyle *style_res) bool same_blend = true; guint items = 0; - for (GSList const *i = objects; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast<SPObject *>(i->data); + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) { + SPObject *obj = *i; if (!obj) { continue; } @@ -1471,9 +1470,9 @@ objects_query_blend (GSList *objects, SPStyle *style_res) * Write to style_res the average blurring of a list of objects. */ int -objects_query_blur (GSList *objects, SPStyle *style_res) +objects_query_blur (const std::vector<SPItem*> &objects, SPStyle *style_res) { - if (g_slist_length(objects) == 0) { + if (objects.empty()) { /* No objects, set empty */ return QUERY_STYLE_NOTHING; } @@ -1484,8 +1483,8 @@ objects_query_blur (GSList *objects, SPStyle *style_res) guint blur_items = 0; guint items = 0; - for (GSList const *i = objects; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast<SPObject *>(i->data); + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) { + SPObject *obj = *i; if (!obj) { continue; } @@ -1553,7 +1552,7 @@ objects_query_blur (GSList *objects, SPStyle *style_res) * the result to style, return appropriate flag. */ int -sp_desktop_query_style_from_list (GSList *list, SPStyle *style, int property) +sp_desktop_query_style_from_list (const std::vector<SPItem*> &list, SPStyle *style, int property) { if (property == QUERY_STYLE_PROPERTY_FILL) { return objects_query_fillstroke (list, style, true); @@ -1606,7 +1605,7 @@ sp_desktop_query_style(SPDesktop *desktop, SPStyle *style, int property) // otherwise, do querying and averaging over selection if (desktop->selection != NULL) { - return sp_desktop_query_style_from_list ((GSList *) desktop->selection->itemList(), style, property); + return sp_desktop_query_style_from_list (desktop->selection->itemList(), style, property); } return QUERY_STYLE_NOTHING; diff --git a/src/desktop-style.h b/src/desktop-style.h index 40ca27e9e..a72f49776 100644 --- a/src/desktop-style.h +++ b/src/desktop-style.h @@ -17,6 +17,7 @@ class ColorRGBA; class SPCSSAttr; class SPDesktop; class SPObject; +class SPItem; class SPStyle; typedef struct _GSList GSList; namespace Inkscape { @@ -64,21 +65,21 @@ guint32 sp_desktop_get_color_tool(SPDesktop *desktop, Glib::ustring const &tool, double sp_desktop_get_font_size_tool (SPDesktop *desktop); void sp_desktop_apply_style_tool(SPDesktop *desktop, Inkscape::XML::Node *repr, Glib::ustring const &tool, bool with_text); -gdouble stroke_average_width (GSList const *objects); +gdouble stroke_average_width (const std::vector<SPItem*> &objects); -int objects_query_fillstroke (GSList *objects, SPStyle *style_res, bool const isfill); -int objects_query_fontnumbers (GSList *objects, SPStyle *style_res); -int objects_query_fontstyle (GSList *objects, SPStyle *style_res); -int objects_query_fontfamily (GSList *objects, SPStyle *style_res); -int objects_query_opacity (GSList *objects, SPStyle *style_res); -int objects_query_strokewidth (GSList *objects, SPStyle *style_res); -int objects_query_miterlimit (GSList *objects, SPStyle *style_res); -int objects_query_strokecap (GSList *objects, SPStyle *style_res); -int objects_query_strokejoin (GSList *objects, SPStyle *style_res); +int objects_query_fillstroke (const std::vector<SPItem*> &objects, SPStyle *style_res, bool const isfill); +int objects_query_fontnumbers (const std::vector<SPItem*> &objects, SPStyle *style_res); +int objects_query_fontstyle (const std::vector<SPItem*> &objects, SPStyle *style_res); +int objects_query_fontfamily (const std::vector<SPItem*> &objects, SPStyle *style_res); +int objects_query_opacity (const std::vector<SPItem*> &objects, SPStyle *style_res); +int objects_query_strokewidth (const std::vector<SPItem*> &objects, SPStyle *style_res); +int objects_query_miterlimit (const std::vector<SPItem*> &objects, SPStyle *style_res); +int objects_query_strokecap (const std::vector<SPItem*> &objects, SPStyle *style_res); +int objects_query_strokejoin (const std::vector<SPItem*> &objects, SPStyle *style_res); -int objects_query_blur (GSList *objects, SPStyle *style_res); +int objects_query_blur (const std::vector<SPItem*> &objects, SPStyle *style_res); -int sp_desktop_query_style_from_list (GSList *list, SPStyle *style, int property); +int sp_desktop_query_style_from_list (const std::vector<SPItem*> &list, SPStyle *style, int property); int sp_desktop_query_style(SPDesktop *desktop, SPStyle *style, int property); bool sp_desktop_query_style_all (SPDesktop *desktop, SPStyle *query); diff --git a/src/desktop.cpp b/src/desktop.cpp index 1152184c9..5a1558b0f 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -716,7 +716,7 @@ Inkscape::UI::Widget::Dock* SPDesktop::getDock() { /** * \see SPDocument::getItemFromListAtPointBottom() */ -SPItem *SPDesktop::getItemFromListAtPointBottom(const GSList *list, Geom::Point const &p) const +SPItem *SPDesktop::getItemFromListAtPointBottom(const std::vector<SPItem*> &list, Geom::Point const &p) const { g_return_val_if_fail (doc() != NULL, NULL); return SPDocument::getItemFromListAtPointBottom(dkey, doc()->getRoot(), list, p); diff --git a/src/desktop.h b/src/desktop.h index a0b9592d0..754e09766 100644 --- a/src/desktop.h +++ b/src/desktop.h @@ -319,7 +319,7 @@ public: //void push_event_context (GType type, const gchar *config, unsigned int key); void set_coordinate_status (Geom::Point p); - SPItem *getItemFromListAtPointBottom(const GSList *list, Geom::Point const &p) const; + SPItem *getItemFromListAtPointBottom(const std::vector<SPItem*> &list, Geom::Point const &p) const; SPItem *getItemAtPoint(Geom::Point const &p, bool into_groups, SPItem *upto = NULL) const; SPItem *getGroupAtPoint(Geom::Point const &p) const; Geom::Point point() const; diff --git a/src/document.cpp b/src/document.cpp index 1c6bb76de..f06953e34 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -1266,7 +1266,7 @@ static bool overlaps(Geom::Rect const &area, Geom::Rect const &box) return area.intersects(box); } -static GSList *find_items_in_area(GSList *s, SPGroup *group, unsigned int dkey, Geom::Rect const &area, +static std::vector<SPItem*> &find_items_in_area(std::vector<SPItem*> &s, SPGroup *group, unsigned int dkey, Geom::Rect const &area, bool (*test)(Geom::Rect const &, Geom::Rect const &), bool take_insensitive = false) { g_return_val_if_fail(SP_IS_GROUP(group), s); @@ -1279,7 +1279,7 @@ static GSList *find_items_in_area(GSList *s, SPGroup *group, unsigned int dkey, SPItem *child = SP_ITEM(o); Geom::OptRect box = child->desktopVisualBounds(); if ( box && test(area, *box) && (take_insensitive || child->isVisibleAndUnlocked(dkey))) { - s = g_slist_append(s, child); + s.push_back(child); } } } @@ -1306,7 +1306,7 @@ static bool item_is_in_group(SPItem *item, SPGroup *group) return inGroup; } -SPItem *SPDocument::getItemFromListAtPointBottom(unsigned int dkey, SPGroup *group, GSList const *list,Geom::Point const &p, bool take_insensitive) +SPItem *SPDocument::getItemFromListAtPointBottom(unsigned int dkey, SPGroup *group, std::vector<SPItem*> const &list,Geom::Point const &p, bool take_insensitive) { g_return_val_if_fail(group, NULL); SPItem *bottomMost = 0; @@ -1320,7 +1320,7 @@ SPItem *SPDocument::getItemFromListAtPointBottom(unsigned int dkey, SPGroup *gro Inkscape::DrawingItem *arenaitem = item->get_arenaitem(dkey); if (arenaitem && arenaitem->pick(p, delta, 1) != NULL && (take_insensitive || item->isVisibleAndUnlocked(dkey))) { - if (g_slist_find((GSList *) list, item) != NULL) { + if (find(list.begin(),list.end(),item)!=list.end() ) { bottomMost = item; } } @@ -1422,11 +1422,11 @@ static SPItem *find_group_at_point(unsigned int dkey, SPGroup *group, Geom::Poin * Assumes box is normalized (and g_asserts it!) * */ -GSList *SPDocument::getItemsInBox(unsigned int dkey, Geom::Rect const &box) const +std::vector<SPItem*> SPDocument::getItemsInBox(unsigned int dkey, Geom::Rect const &box) const { - g_return_val_if_fail(this->priv != NULL, NULL); - - return find_items_in_area(NULL, SP_GROUP(this->root), dkey, box, is_within); + std::vector<SPItem*> x; + g_return_val_if_fail(this->priv != NULL, x); + return find_items_in_area(x, SP_GROUP(this->root), dkey, box, is_within); } /* @@ -1436,16 +1436,16 @@ GSList *SPDocument::getItemsInBox(unsigned int dkey, Geom::Rect const &box) cons * */ -GSList *SPDocument::getItemsPartiallyInBox(unsigned int dkey, Geom::Rect const &box) const +std::vector<SPItem*> SPDocument::getItemsPartiallyInBox(unsigned int dkey, Geom::Rect const &box) const { - g_return_val_if_fail(this->priv != NULL, NULL); - - return find_items_in_area(NULL, SP_GROUP(this->root), dkey, box, overlaps); + std::vector<SPItem*> x; + g_return_val_if_fail(this->priv != NULL, x); + return find_items_in_area(x, SP_GROUP(this->root), dkey, box, overlaps); } -GSList *SPDocument::getItemsAtPoints(unsigned const key, std::vector<Geom::Point> points) const +std::vector<SPItem*> SPDocument::getItemsAtPoints(unsigned const key, std::vector<Geom::Point> points) const { - GSList *items = NULL; + std::vector<SPItem*> items; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); // When picking along the path, we don't want small objects close together @@ -1454,11 +1454,11 @@ GSList *SPDocument::getItemsAtPoints(unsigned const key, std::vector<Geom::Point gdouble saved_delta = prefs->getDouble("/options/cursortolerance/value", 1.0); prefs->setDouble("/options/cursortolerance/value", 0.25); - for(unsigned int i = 0; i < points.size(); i++) { + for(int i = points.size()-1;i>=0; i--) { SPItem *item = getItemAtPoint(key, points[i], false, NULL); - if (item && !g_slist_find(items, item)) - items = g_slist_prepend (items, item); + if (item && items.end()==find(items.begin(),items.end(), item)) + items.push_back(item); } // and now we restore it back diff --git a/src/document.h b/src/document.h index 74dcfa75e..16b9bb28d 100644 --- a/src/document.h +++ b/src/document.h @@ -232,7 +232,7 @@ public: /** * Returns the bottommost item from the list which is at the point, or NULL if none. */ - static SPItem *getItemFromListAtPointBottom(unsigned int dkey, SPGroup *group, const GSList *list, Geom::Point const &p, bool take_insensitive = false); + static SPItem *getItemFromListAtPointBottom(unsigned int dkey, SPGroup *group, const std::vector<SPItem*> &list, Geom::Point const &p, bool take_insensitive = false); static SPDocument *createDoc(Inkscape::XML::Document *rdoc, char const *uri, char const *base, char const *name, unsigned int keepalive, @@ -259,10 +259,10 @@ public: bool addResource(char const *key, SPObject *object); bool removeResource(char const *key, SPObject *object); const GSList *getResourceList(char const *key) const; - GSList *getItemsInBox(unsigned int dkey, Geom::Rect const &box) const; - GSList *getItemsPartiallyInBox(unsigned int dkey, Geom::Rect const &box) const; + std::vector<SPItem*> getItemsInBox(unsigned int dkey, Geom::Rect const &box) const; + std::vector<SPItem*> getItemsPartiallyInBox(unsigned int dkey, Geom::Rect const &box) const; SPItem *getItemAtPoint(unsigned int key, Geom::Point const &p, bool into_groups, SPItem *upto = NULL) const; - GSList *getItemsAtPoints(unsigned const key, std::vector<Geom::Point> points) const; + std::vector<SPItem*> getItemsAtPoints(unsigned const key, std::vector<Geom::Point> points) const; SPItem *getGroupAtPoint(unsigned int key, Geom::Point const &p) const; void changeUriAndHrefs(char const *uri); diff --git a/src/extension/execution-env.cpp b/src/extension/execution-env.cpp index e7cd43d9d..29c2b5537 100644 --- a/src/extension/execution-env.cpp +++ b/src/extension/execution-env.cpp @@ -60,14 +60,12 @@ ExecutionEnv::ExecutionEnv (Effect * effect, Inkscape::UI::View::View * doc, Imp sp_namedview_document_from_window(desktop); if (desktop != NULL) { - Inkscape::Util::GSListConstIterator<SPItem *> selected = - desktop->getSelection()->itemList(); - while ( selected != NULL ) { + std::vector<SPItem*> selected = desktop->getSelection()->itemList(); + for(std::vector<SPItem*>::const_iterator x = selected.begin(); x != selected.end(); x++){ Glib::ustring selected_id; - selected_id = (*selected)->getId(); + selected_id = (*x)->getId(); _selected.insert(_selected.end(), selected_id); //std::cout << "Selected: " << selected_id << std::endl; - ++selected; } } diff --git a/src/extension/implementation/implementation.cpp b/src/extension/implementation/implementation.cpp index 52f63499a..b0ff3e91c 100644 --- a/src/extension/implementation/implementation.cpp +++ b/src/extension/implementation/implementation.cpp @@ -47,12 +47,10 @@ Gtk::Widget *Implementation::prefs_effect(Inkscape::Extension::Effect *module, I SPDocument * current_document = view->doc(); - using Inkscape::Util::GSListConstIterator; - // FIXME very unsafe cast - GSListConstIterator<SPItem *> selected = ((SPDesktop *)view)->getSelection()->itemList(); + std::vector<SPItem*> selected = ((SPDesktop *)view)->getSelection()->itemList(); Inkscape::XML::Node const* first_select = NULL; - if (selected != NULL) { - const SPItem * item = *selected; + if (!selected.empty()) { + const SPItem * item = selected[0]; first_select = item->getRepr(); } diff --git a/src/extension/implementation/script.cpp b/src/extension/implementation/script.cpp index 52c360fcd..5cab3a2b2 100644 --- a/src/extension/implementation/script.cpp +++ b/src/extension/implementation/script.cpp @@ -689,14 +689,13 @@ void Script::effect(Inkscape::Extension::Effect *module, return; } - Inkscape::Util::GSListConstIterator<SPItem *> selected = + std::vector<SPItem*> selected = desktop->getSelection()->itemList(); //desktop should not be NULL since doc was checked and desktop is a casted pointer - while ( selected != NULL ) { + for(std::vector<SPItem*>::const_iterator x = selected.begin(); x != selected.end(); x++){ Glib::ustring selected_id; selected_id += "--id="; - selected_id += (*selected)->getId(); + selected_id += (*x)->getId(); params.insert(params.begin(), selected_id); - ++selected; } file_listener fileout; diff --git a/src/extension/internal/bitmap/imagemagick.cpp b/src/extension/internal/bitmap/imagemagick.cpp index 7c91bf1ef..bc0dd8e33 100644 --- a/src/extension/internal/bitmap/imagemagick.cpp +++ b/src/extension/internal/bitmap/imagemagick.cpp @@ -66,8 +66,8 @@ ImageMagickDocCache::ImageMagickDocCache(Inkscape::UI::View::View * view) : _imageItems(NULL) { SPDesktop *desktop = (SPDesktop*)view; - const GSList *selectedItemList = desktop->selection->itemList(); - int selectCount = g_slist_length((GSList *)selectedItemList); + const std::vector<SPItem*> selectedItemList = desktop->selection->itemList(); + int selectCount = selectedItemList.size(); // Init the data-holders _nodes = new Inkscape::XML::Node*[selectCount]; @@ -79,9 +79,8 @@ ImageMagickDocCache::ImageMagickDocCache(Inkscape::UI::View::View * view) : _imageItems = new SPItem*[selectCount]; // Loop through selected items - for (; selectedItemList != NULL; selectedItemList = g_slist_next(selectedItemList)) - { - SPItem *item = SP_ITEM(selectedItemList->data); + for (std::vector<SPItem*>::const_iterator i = selectedItemList.begin(); i != selectedItemList.end(); i++) { + SPItem *item = *i; Inkscape::XML::Node *node = reinterpret_cast<Inkscape::XML::Node *>(item->getRepr()); if (!strcmp(node->name(), "image") || !strcmp(node->name(), "svg:image")) { @@ -237,13 +236,10 @@ ImageMagick::prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::Vie { SPDocument * current_document = view->doc(); - using Inkscape::Util::GSListConstIterator; - - // FIXME very unsafe cast - GSListConstIterator<SPItem *> selected = ((SPDesktop *)view)->getSelection()->itemList(); + std::vector<SPItem*> selected = ((SPDesktop *)view)->getSelection()->itemList(); Inkscape::XML::Node * first_select = NULL; - if (selected != NULL) { - first_select = (*selected)->getRepr(); + if (!selected.empty()) { + first_select = (selected.front())->getRepr(); } return module->autogui(current_document, first_select, changeSignal); diff --git a/src/extension/internal/bluredge.cpp b/src/extension/internal/bluredge.cpp index 3ce537d9f..9f19f8b3b 100644 --- a/src/extension/internal/bluredge.cpp +++ b/src/extension/internal/bluredge.cpp @@ -63,13 +63,11 @@ BlurEdge::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View Inkscape::Preferences *prefs = Inkscape::Preferences::get(); double old_offset = prefs->getDouble("/options/defaultoffsetwidth/value", 1.0, "px"); - using Inkscape::Util::GSListConstIterator; // TODO need to properly refcount the items, at least - std::list<SPItem *> items; - items.insert<GSListConstIterator<SPItem *> >(items.end(), selection->itemList(), NULL); + std::vector<SPItem*> items(selection->itemList()); selection->clear(); - for(std::list<SPItem *>::iterator item = items.begin(); + for(std::vector<SPItem*>::iterator item = items.begin(); item != items.end(); ++item) { SPItem * spitem = *item; diff --git a/src/extension/internal/cairo-renderer.cpp b/src/extension/internal/cairo-renderer.cpp index 7fbdc4296..49e145de0 100644 --- a/src/extension/internal/cairo-renderer.cpp +++ b/src/extension/internal/cairo-renderer.cpp @@ -294,14 +294,12 @@ static void sp_group_render(SPGroup *group, CairoRenderContext *ctx) CairoRenderer *renderer = ctx->getRenderer(); TRACE(("sp_group_render opacity: %f\n", SP_SCALE24_TO_FLOAT(item->style->opacity.value))); - GSList *l = g_slist_reverse(group->childList(false)); - while (l) { - SPObject *o = reinterpret_cast<SPObject *>(l->data); - SPItem *item = dynamic_cast<SPItem *>(o); + std::vector<SPObject*> l(group->childList(false)); + for(std::vector<SPObject*>::const_iterator x = l.begin(); x!= l.end(); x++){ + SPItem *item = static_cast<SPItem*>(*x); if (item) { renderer->renderItem(ctx, item); } - l = g_slist_remove (l, o); } } diff --git a/src/extension/internal/filter/filter.cpp b/src/extension/internal/filter/filter.cpp index a2c565699..65162af22 100644 --- a/src/extension/internal/filter/filter.cpp +++ b/src/extension/internal/filter/filter.cpp @@ -125,15 +125,13 @@ void Filter::effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::Vie //printf("Calling filter effect\n"); Inkscape::Selection * selection = ((SPDesktop *)document)->selection; - using Inkscape::Util::GSListConstIterator; // TODO need to properly refcount the items, at least - std::list<SPItem *> items; - items.insert<GSListConstIterator<SPItem *> >(items.end(), selection->itemList(), NULL); + std::vector<SPItem*> items(selection->itemList()); Inkscape::XML::Document * xmldoc = document->doc()->getReprDoc(); Inkscape::XML::Node * defsrepr = document->doc()->getDefs()->getRepr(); - for(std::list<SPItem *>::iterator item = items.begin(); + for(std::vector<SPItem*>::iterator item = items.begin(); item != items.end(); ++item) { SPItem * spitem = *item; Inkscape::XML::Node * node = spitem->getRepr(); diff --git a/src/extension/internal/grid.cpp b/src/extension/internal/grid.cpp index 61f2f70e2..8fd82b675 100644 --- a/src/extension/internal/grid.cpp +++ b/src/extension/internal/grid.cpp @@ -186,13 +186,10 @@ Grid::prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View { SPDocument * current_document = view->doc(); - using Inkscape::Util::GSListConstIterator; - - // FIXME very unsafe cast - GSListConstIterator<SPItem *> selected = ((SPDesktop *)view)->getSelection()->itemList(); + std::vector<SPItem*> selected = ((SPDesktop *)view)->getSelection()->itemList(); Inkscape::XML::Node * first_select = NULL; - if (selected != NULL) { - first_select = (*selected)->getRepr(); + if (!selected.empty()) { + first_select = selected[0]->getRepr(); } return module->autogui(current_document, first_select, changeSignal); diff --git a/src/extension/internal/latex-text-renderer.cpp b/src/extension/internal/latex-text-renderer.cpp index ab0733848..ab863f8b1 100644 --- a/src/extension/internal/latex-text-renderer.cpp +++ b/src/extension/internal/latex-text-renderer.cpp @@ -228,14 +228,12 @@ LaTeXTextRenderer::writePostamble() void LaTeXTextRenderer::sp_group_render(SPGroup *group) { - GSList *l = g_slist_reverse(group->childList(false)); - while (l) { - SPObject *o = reinterpret_cast<SPObject *>(l->data); - SPItem *item = dynamic_cast<SPItem *>(o); + std::vector<SPObject*> l = (group->childList(false)); + for(std::vector<SPObject*>::const_iterator x = l.begin(); x != l.end(); x++){ + SPItem *item = static_cast<SPItem*>(*x); if (item) { renderItem(item); } - l = g_slist_remove (l, o); } } diff --git a/src/file.cpp b/src/file.cpp index f9e259fe2..d1dd2bcd6 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -1069,7 +1069,7 @@ void sp_import_document(SPDesktop *desktop, SPDocument *clipdoc, bool in_place) desktop->doc()->importDefs(clipdoc); // copy objects - GSList *pasted_objects = NULL; + std::vector<Inkscape::XML::Node*> pasted_objects; for (Inkscape::XML::Node *obj = root->firstChild() ; obj ; obj = obj->next()) { // Don't copy metadata, defs, named views and internal clipboard contents to the document if (!strcmp(obj->name(), "svg:defs")) { @@ -1088,9 +1088,8 @@ void sp_import_document(SPDesktop *desktop, SPDocument *clipdoc, bool in_place) target_parent->appendChild(obj_copy); Inkscape::GC::release(obj_copy); - pasted_objects = g_slist_prepend(pasted_objects, (gpointer) obj_copy); + pasted_objects.push_back(obj_copy); } - // Change the selection to the freshly pasted objects Inkscape::Selection *selection = desktop->getSelection(); selection->setReprList(pasted_objects); @@ -1129,8 +1128,6 @@ void sp_import_document(SPDesktop *desktop, SPDocument *clipdoc, bool in_place) sp_selection_move_relative(selection, offset); } - - g_slist_free(pasted_objects); } diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp index aecf1aa35..d90972961 100644 --- a/src/gradient-chemistry.cpp +++ b/src/gradient-chemistry.cpp @@ -1570,8 +1570,9 @@ void sp_gradient_invert_selected_gradients(SPDesktop *desktop, Inkscape::PaintTa { Inkscape::Selection *selection = desktop->getSelection(); - for (GSList const* i = selection->itemList(); i != NULL; i = i->next) { - sp_item_gradient_invert_vector_color(SP_ITEM(i->data), fill_or_stroke); + const std::vector<SPItem*> list=selection->itemList(); + for (std::vector<SPItem*>::const_iterator i = list.begin(); i != list.end(); i++) { + sp_item_gradient_invert_vector_color(*i, fill_or_stroke); } // we did an undoable action @@ -1594,9 +1595,10 @@ void sp_gradient_reverse_selected_gradients(SPDesktop *desktop) if (drag && drag->selected) { drag->selected_reverse_vector(); } else { // If no drag or no dragger selected, act on selection (both fill and stroke gradients) - for (GSList const* i = selection->itemList(); i != NULL; i = i->next) { - sp_item_gradient_reverse_vector(SP_ITEM(i->data), Inkscape::FOR_FILL); - sp_item_gradient_reverse_vector(SP_ITEM(i->data), Inkscape::FOR_STROKE); + const std::vector<SPItem*> list=selection->itemList(); + for (std::vector<SPItem*>::const_iterator i = list.begin(); i != list.end(); i++) { + sp_item_gradient_reverse_vector(*i, Inkscape::FOR_FILL); + sp_item_gradient_reverse_vector(*i, Inkscape::FOR_STROKE); } } diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp index cb2bd737f..169710114 100644 --- a/src/gradient-drag.cpp +++ b/src/gradient-drag.cpp @@ -2082,9 +2082,9 @@ void GrDrag::updateDraggers() this->draggers = NULL; g_return_if_fail(this->selection != NULL); - - for (GSList const* i = this->selection->itemList(); i != NULL; i = i->next) { - SPItem *item = SP_ITEM(i->data); + std::vector<SPItem*> list = this->selection->itemList(); + for (std::vector<SPItem*>::const_iterator i = list.begin(); i != list.end(); i++) { + SPItem *item = *i; SPStyle *style = item->style; if (style && (style->fill.isPaintserver())) { @@ -2151,9 +2151,9 @@ void GrDrag::updateLines() g_return_if_fail(this->selection != NULL); - for (GSList const* i = this->selection->itemList(); i != NULL; i = i->next) { - - SPItem *item = SP_ITEM(i->data); + std::vector<SPItem*> list = this->selection->itemList(); + for (std::vector<SPItem*>::const_iterator i = list.begin(); i != list.end(); i++) { + SPItem *item = *i; SPStyle *style = item->style; @@ -2295,8 +2295,9 @@ void GrDrag::updateLevels() g_return_if_fail (this->selection != NULL); - for (GSList const* i = this->selection->itemList(); i != NULL; i = i->next) { - SPItem *item = SP_ITEM(i->data); + std::vector<SPItem*> list = this->selection->itemList(); + for (std::vector<SPItem*>::const_iterator i = list.begin(); i != list.end(); i++) { + SPItem *item = *i; Geom::OptRect rect = item->desktopVisualBounds(); if (rect) { // Remember the edges of the bbox and the center axis diff --git a/src/graphlayout.cpp b/src/graphlayout.cpp index e5d61ab64..40994347c 100644 --- a/src/graphlayout.cpp +++ b/src/graphlayout.cpp @@ -88,9 +88,9 @@ struct CheckProgress : TestConvergence { * Scans the items list and places those items that are * not connectors in filtered */ -void filterConnectors(GSList const *const items, list<SPItem *> &filtered) { - for(GSList *i=(GSList *)items; i!=NULL; i=i->next) { - SPItem *item=SP_ITEM(i->data); +void filterConnectors(std::vector<SPItem*> const &items, list<SPItem *> &filtered) { + for(std::vector<SPItem*>::const_iterator i = items.begin();i !=items.end(); i++){ + SPItem *item = *i; if(!isConnector(item)) { filtered.push_back(item); } @@ -101,8 +101,8 @@ void filterConnectors(GSList const *const items, list<SPItem *> &filtered) { * connectors between them, and uses graph layout techniques to find * a nice layout */ -void graphlayout(GSList const *const items) { - if(!items) { +void graphlayout(std::vector<SPItem*> const &items) { + if(items.empty()) { return; } diff --git a/src/graphlayout.h b/src/graphlayout.h index 0ffb645b6..9794dd6b5 100644 --- a/src/graphlayout.h +++ b/src/graphlayout.h @@ -19,10 +19,10 @@ typedef struct _GSList GSList; class SPItem; -void graphlayout(GSList const *const items); +void graphlayout(std::vector<SPItem*> const &items); bool isConnector(SPItem const *const item); -void filterConnectors(GSList const *const items, std::list<SPItem *> &filtered); +void filterConnectors(std::vector<SPItem*> const &items, std::list<SPItem *> &filtered); #endif // SEEN_GRAPHLAYOUT_H diff --git a/src/helper/png-write.cpp b/src/helper/png-write.cpp index 32e50b537..fc365c435 100644 --- a/src/helper/png-write.cpp +++ b/src/helper/png-write.cpp @@ -361,19 +361,19 @@ sp_export_get_rows(guchar const **rows, void **to_free, int row, int num_rows, v /** * Hide all items that are not listed in list, recursively, skipping groups and defs. */ -static void hide_other_items_recursively(SPObject *o, GSList *list, unsigned dkey) +static void hide_other_items_recursively(SPObject *o, const std::vector<SPItem*> &list, unsigned dkey) { if ( SP_IS_ITEM(o) && !SP_IS_DEFS(o) && !SP_IS_ROOT(o) && !SP_IS_GROUP(o) - && !g_slist_find(list, o) ) + && list.end()==find(list.begin(),list.end(),o)) { SP_ITEM(o)->invoke_hide(dkey); } // recurse - if (!g_slist_find(list, o)) { + if (list.end()==find(list.begin(),list.end(),o)) { for ( SPObject *child = o->firstChild() ; child; child = child->getNext() ) { hide_other_items_recursively(child, list, dkey); } @@ -387,7 +387,7 @@ ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, unsigned long bgcolor, unsigned int (*status) (float, void *), void *data, bool force_overwrite, - GSList *items_only) + const std::vector<SPItem*> &items_only) { return sp_export_png_file(doc, filename, Geom::Rect(Geom::Point(x0,y0),Geom::Point(x1,y1)), width, height, xdpi, ydpi, bgcolor, status, data, force_overwrite, items_only); @@ -399,7 +399,7 @@ ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, unsigned long bgcolor, unsigned (*status)(float, void *), void *data, bool force_overwrite, - GSList *items_only) + const std::vector<SPItem*> &items_only) { g_return_val_if_fail(doc != NULL, EXPORT_ERROR); g_return_val_if_fail(filename != NULL, EXPORT_ERROR); @@ -457,7 +457,7 @@ ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, // We show all and then hide all items we don't want, instead of showing only requested items, // because that would not work if the shown item references something in defs - if (items_only) { + if (!items_only.empty()) { hide_other_items_recursively(doc->getRoot(), items_only, dkey); } diff --git a/src/helper/png-write.h b/src/helper/png-write.h index 8c04b25dc..2657fb635 100644 --- a/src/helper/png-write.h +++ b/src/helper/png-write.h @@ -14,8 +14,9 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include <glib.h> #include <2geom/forward.h> + + class SPDocument; enum ExportResult { @@ -33,12 +34,12 @@ ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, double x0, double y0, double x1, double y1, unsigned long int width, unsigned long int height, double xdpi, double ydpi, unsigned long bgcolor, - unsigned int (*status) (float, void *), void *data, bool force_overwrite = false, GSList *items_only = NULL); + unsigned int (*status) (float, void *), void *data, bool force_overwrite = false, const std::vector<SPItem*> &items_only = std::vector<SPItem*>()); ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, Geom::Rect const &area, unsigned long int width, unsigned long int height, double xdpi, double ydpi, unsigned long bgcolor, - unsigned int (*status) (float, void *), void *data, bool force_overwrite = false, GSList *items_only = NULL); + unsigned int (*status) (float, void *), void *data, bool force_overwrite = false, const std::vector<SPItem*> &items_only = std::vector<SPItem*>()); #endif // SEEN_SP_PNG_WRITE_H diff --git a/src/live_effects/lpe-knot.cpp b/src/live_effects/lpe-knot.cpp index 820221abf..ec2f9c419 100644 --- a/src/live_effects/lpe-knot.cpp +++ b/src/live_effects/lpe-knot.cpp @@ -505,9 +505,9 @@ LPEKnot::doEffect_path (std::vector<Geom::Path> const &path_in) static void collectPathsAndWidths (SPLPEItem const *lpeitem, std::vector<Geom::Path> &paths, std::vector<double> &stroke_widths){ if (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); + std::vector<SPItem*> item_list = sp_item_group_item_list(SP_GROUP(lpeitem)); + for ( std::vector<SPItem*>::const_iterator iter = item_list.begin(); iter != item_list.end(); iter++) { + SPObject *subitem = *iter; if (SP_IS_LPE_ITEM(subitem)) { collectPathsAndWidths(SP_LPE_ITEM(subitem), paths, stroke_widths); } diff --git a/src/main.cpp b/src/main.cpp index 415118407..d1ebdc3bb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1156,7 +1156,7 @@ static int sp_process_file_list(GSList *fl) } if (sp_export_svg) { if (sp_export_text_to_path) { - GSList *items = NULL; + std::vector<SPItem*> items; SPRoot *root = doc->getRoot(); doc->ensureUpToDate(); for ( SPObject *iter = root->firstChild(); iter ; iter = iter->getNext()) { @@ -1166,17 +1166,14 @@ static int sp_process_file_list(GSList *fl) } te_update_layout_now_recursive(item); - items = g_slist_append(items, item); + items.push_back(item); } - GSList *selected = NULL; - GSList *to_select = NULL; + std::vector<SPItem*> selected; + std::vector<Inkscape::XML::Node*> to_select; - sp_item_list_to_curves(items, &selected, &to_select); + sp_item_list_to_curves(items, selected, to_select); - g_slist_free (items); - g_slist_free (selected); - g_slist_free (to_select); } if(sp_export_id) { doc->ensureUpToDate(); @@ -1435,7 +1432,7 @@ static int sp_do_export_png(SPDocument *doc) g_warning ("--export-use-hints can only be used with --export-id or --export-area-drawing; ignored."); } - GSList *items = NULL; + std::vector<SPItem*> items; Geom::Rect area; if (sp_export_id || sp_export_area_drawing) { @@ -1459,7 +1456,7 @@ static int sp_do_export_png(SPDocument *doc) return 1; } - items = g_slist_prepend (items, SP_ITEM(o)); + items.push_back(SP_ITEM(o)); if (sp_export_id_only) { g_print("Exporting only object with id=\"%s\"; all other objects hidden\n", sp_export_id); @@ -1644,10 +1641,12 @@ static int sp_do_export_png(SPDocument *doc) g_print("Background RRGGBBAA: %08x\n", bgcolor); g_print("Area %g:%g:%g:%g exported to %lu x %lu pixels (%g dpi)\n", area[Geom::X][0], area[Geom::Y][0], area[Geom::X][1], area[Geom::Y][1], width, height, dpi); - + + reverse(items.begin(),items.end()); + if ((width >= 1) && (height >= 1) && (width <= PNG_UINT_31_MAX) && (height <= PNG_UINT_31_MAX)) { if( sp_export_png_file(doc, path.c_str(), area, width, height, dpi, - dpi, bgcolor, NULL, NULL, true, sp_export_id_only ? items : NULL) == 1 ) { + dpi, bgcolor, NULL, NULL, true, sp_export_id_only ? items : std::vector<SPItem*>()) == 1 ) { g_print("Bitmap saved as: %s\n", filename.c_str()); } else { g_warning("Bitmap failed to save to: %s", filename.c_str()); @@ -1657,7 +1656,6 @@ static int sp_do_export_png(SPDocument *doc) } } - g_slist_free (items); return retcode; } diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 338f91463..f9c189c58 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -237,8 +237,9 @@ void Inkscape::ObjectSnapper::_collectNodes(SnapSourceType const &t, // current selection (see the comment in SelTrans::centerRequest()) bool old_pref2 = _snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_ROTATION_CENTER); if (old_pref2) { - for ( GSList const *itemlist = _snapmanager->getRotationCenterSource(); itemlist != NULL; itemlist = g_slist_next(itemlist) ) { - if ((*i).item == reinterpret_cast<SPItem*>(itemlist->data)) { + std::vector<SPItem*> rotationSource=_snapmanager->getRotationCenterSource(); + for ( std::vector<SPItem*>::const_iterator itemlist = rotationSource.begin(); itemlist != rotationSource.end(); itemlist++) { + if ((*i).item == *itemlist) { // don't snap to this item's rotation center _snapmanager->snapprefs.setTargetSnappable(SNAPTARGET_ROTATION_CENTER, false); break; diff --git a/src/object-test.h b/src/object-test.h index 06363c372..4f0be3251 100644 --- a/src/object-test.h +++ b/src/object-test.h @@ -204,7 +204,8 @@ public: assert(n_group != NULL); begin = clock(); - sp_item_group_ungroup(n_group, NULL, false); + std::vector<SPItem*> ch; + sp_item_group_ungroup(n_group, ch, false); end = clock(); std::cout << "Took " << double(end - begin) / double(CLOCKS_PER_SEC) << " seconds to ungroup a <g> with " << num_elements << " elements\n"; diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp index 988559e30..8d2695b85 100644 --- a/src/path-chemistry.cpp +++ b/src/path-chemistry.cpp @@ -44,13 +44,22 @@ using Inkscape::DocumentUndo; + +inline bool less_than_items(SPItem const *first, SPItem const *second) +{ + return sp_repr_compare_position(first->getRepr(), + second->getRepr())<0; +} + void sp_selected_path_combine(SPDesktop *desktop) { Inkscape::Selection *selection = desktop->getSelection(); SPDocument *doc = desktop->getDocument(); + + std::vector<SPItem*> items(selection->itemList()); - if (g_slist_length((GSList *) selection->itemList()) < 1) { + if (items.size() < 1) { desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to combine.")); return; } @@ -59,28 +68,23 @@ sp_selected_path_combine(SPDesktop *desktop) // set "busy" cursor desktop->setWaitingCursor(); - GSList *items = g_slist_copy((GSList *) selection->itemList()); - items = sp_degroup_list (items); // descend into any groups in selection - GSList *to_paths = NULL; - for (GSList *i = items; i != NULL; i = i->next) { - SPItem *item = (SPItem *) i->data; - if (!dynamic_cast<SPPath *>(item) && !dynamic_cast<SPGroup *>(item)) { - to_paths = g_slist_prepend(to_paths, item); + std::vector<SPItem*> to_paths; + for (std::vector<SPItem*>::const_reverse_iterator i = items.rbegin(); i != items.rend(); i++) { + if (!dynamic_cast<SPPath *>(*i) && !dynamic_cast<SPGroup *>(*i)) { + to_paths.push_back(*i); } } - GSList *converted = NULL; - bool did = sp_item_list_to_curves(to_paths, &items, &converted); - g_slist_free(to_paths); - for (GSList *i = converted; i != NULL; i = i->next) - items = g_slist_prepend(items, doc->getObjectByRepr((Inkscape::XML::Node*)(i->data))); + std::vector<Inkscape::XML::Node*> converted; + bool did = sp_item_list_to_curves(to_paths, items, converted); + for (std::vector<Inkscape::XML::Node*>::const_iterator i = converted.begin(); i != converted.end(); i++) + items.push_back((SPItem*)doc->getObjectByRepr(*i)); items = sp_degroup_list (items); // converting to path may have added more groups, descend again - items = g_slist_sort(items, (GCompareFunc) sp_item_repr_compare_position); - items = g_slist_reverse(items); - assert(items); // cannot be NULL because of list length check at top of function + sort(items.begin(),items.end(),less_than_items); + assert(!items.empty()); // cannot be NULL because of list length check at top of function // remember the position, id, transform and style of the topmost path, they will be assigned to the combined one gint position = 0; @@ -97,9 +101,9 @@ sp_selected_path_combine(SPDesktop *desktop) selection->clear(); } - for (GSList *i = items; i != NULL; i = i->next) { // going from top to bottom + for (std::vector<SPItem*>::const_reverse_iterator i = items.rbegin(); i != items.rend(); i++){ - SPItem *item = (SPItem *) i->data; + SPItem *item = *i; SPPath *path = dynamic_cast<SPPath *>(item); if (!path) { continue; @@ -136,7 +140,6 @@ sp_selected_path_combine(SPDesktop *desktop) } } - g_slist_free(items); if (did) { first->deleteObject(false); @@ -200,11 +203,10 @@ sp_selected_path_break_apart(SPDesktop *desktop) bool did = false; - for (GSList *items = g_slist_copy((GSList *) selection->itemList()); - items != NULL; - items = items->next) { + std::vector<SPItem*> itemlist(selection->itemList()); + for (std::vector<SPItem*>::const_iterator i = itemlist.begin(); i != itemlist.end(); i++){ - SPItem *item = (SPItem *) items->data; + SPItem *item = *i; SPPath *path = dynamic_cast<SPPath *>(item); if (!path) { @@ -241,7 +243,7 @@ sp_selected_path_break_apart(SPDesktop *desktop) curve->unref(); - GSList *reprs = NULL; + std::vector<Inkscape::XML::Node*> reprs; for (GSList *l = list; l != NULL; l = l->next) { curve = (SPCurve *) l->data; @@ -267,14 +269,12 @@ sp_selected_path_break_apart(SPDesktop *desktop) if (l == list) repr->setAttribute("id", id); - reprs = g_slist_prepend (reprs, repr); + reprs.push_back(repr); Inkscape::GC::release(repr); } - selection->setReprList(reprs); - g_slist_free(reprs); g_slist_free(list); g_free(style); g_free(path_effect); @@ -307,18 +307,15 @@ sp_selected_path_to_curves(Inkscape::Selection *selection, SPDesktop *desktop, b desktop->setWaitingCursor(); } - GSList *selected = g_slist_copy((GSList *) selection->itemList()); - GSList *to_select = NULL; + std::vector<SPItem*> selected(selection->itemList()); + std::vector<Inkscape::XML::Node*> to_select; selection->clear(); - GSList *items = g_slist_copy(selected); + std::vector<SPItem*> items(selected); - did = sp_item_list_to_curves(items, &selected, &to_select); + did = sp_item_list_to_curves(items, selected, to_select); - g_slist_free (items); selection->setReprList(to_select); selection->addList(selected); - g_slist_free (to_select); - g_slist_free (selected); if (interactive && desktop) { desktop->clearWaitingCursor(); @@ -341,33 +338,24 @@ void sp_selected_to_lpeitems(SPDesktop *desktop) return; } - GSList *selected = g_slist_copy((GSList *) selection->itemList()); - GSList *to_select = NULL; + std::vector<SPItem*> selected(selection->itemList()); + std::vector<Inkscape::XML::Node*> to_select; selection->clear(); - GSList *items = g_slist_copy(selected); + std::vector<SPItem*> items(selected); + - sp_item_list_to_curves(items, &selected, &to_select, true); + sp_item_list_to_curves(items, selected, to_select, true); - g_slist_free(items); - items = 0; selection->setReprList(to_select); selection->addList(selected); - g_slist_free(to_select); - to_select = 0; - g_slist_free(selected); - selected = 0; } bool -sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_select, bool skip_all_lpeitems) +sp_item_list_to_curves(const std::vector<SPItem*> &items, std::vector<SPItem*>& selected, std::vector<Inkscape::XML::Node*> &to_select, bool skip_all_lpeitems) { bool did = false; - - for (; - items != NULL; - items = items->next) { - - SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(items->data)); + for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); i++){ + SPItem *item = *i; g_assert(item != NULL); SPDocument *document = item->document; @@ -398,9 +386,9 @@ sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_selec Inkscape::XML::Node *repr = box3d_convert_to_group(box)->getRepr(); if (repr) { - *to_select = g_slist_prepend (*to_select, repr); + to_select.insert(to_select.begin(),repr); did = true; - *selected = g_slist_remove (*selected, item); + selected.erase(find(selected.begin(),selected.end(),item)); } continue; @@ -408,17 +396,14 @@ sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_selec if (group) { group->removeAllPathEffects(true); - GSList *item_list = sp_item_group_item_list(group); + std::vector<SPItem*> item_list = sp_item_group_item_list(group); - GSList *item_to_select = NULL; - GSList *item_selected = NULL; + std::vector<Inkscape::XML::Node*> item_to_select; + std::vector<SPItem*> item_selected; - if (sp_item_list_to_curves(item_list, &item_selected, &item_to_select)) + if (sp_item_list_to_curves(item_list, item_selected, item_to_select)) did = true; - g_slist_free(item_list); - g_slist_free(item_to_select); - g_slist_free(item_selected); continue; } @@ -428,7 +413,7 @@ sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_selec continue; did = true; - *selected = g_slist_remove (*selected, item); + selected.erase(find(selected.begin(),selected.end(),item)); // remember the position of the item gint pos = item->getRepr()->position(); @@ -470,7 +455,7 @@ sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_selec /* Buglet: We don't re-add the (new version of the) object to the selection of any other * desktops where it was previously selected. */ - *to_select = g_slist_prepend (*to_select, repr); + to_select.insert(to_select.begin(),repr); Inkscape::GC::release(repr); } @@ -622,9 +607,9 @@ void sp_selected_path_reverse(SPDesktop *desktop) { Inkscape::Selection *selection = desktop->getSelection(); - GSList *items = (GSList *) selection->itemList(); + std::vector<SPItem*> items = selection->itemList(); - if (!items) { + if (items.empty()) { desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>path(s)</b> to reverse.")); return; } @@ -636,9 +621,9 @@ sp_selected_path_reverse(SPDesktop *desktop) bool did = false; desktop->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Reversing paths...")); - for (GSList *i = items; i != NULL; i = i->next) { + for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); i++){ - SPPath *path = dynamic_cast<SPPath *>(static_cast<SPObject *>(i->data)); + SPPath *path = dynamic_cast<SPPath *>(*i); if (!path) { continue; } diff --git a/src/path-chemistry.h b/src/path-chemistry.h index a2150440c..f454167a9 100644 --- a/src/path-chemistry.h +++ b/src/path-chemistry.h @@ -33,7 +33,7 @@ void sp_selected_path_to_curves (Inkscape::Selection *selection, SPDesktop *desk void sp_selected_to_lpeitems(SPDesktop *desktop); Inkscape::XML::Node *sp_selected_item_to_curved_repr(SPItem *item, guint32 text_grouping_policy); void sp_selected_path_reverse (SPDesktop *desktop); -bool sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_select, bool skip_all_lpeitems = false); +bool sp_item_list_to_curves(const std::vector<SPItem*> &items, std::vector<SPItem*> &selected, std::vector<Inkscape::XML::Node*> &to_select, bool skip_all_lpeitems = false); #endif // SEEN_PATH_CHEMISTRY_H diff --git a/src/removeoverlap.cpp b/src/removeoverlap.cpp index ba5740e55..9ea75de0d 100644 --- a/src/removeoverlap.cpp +++ b/src/removeoverlap.cpp @@ -38,20 +38,19 @@ namespace { * such that rectangular bounding boxes are separated by at least xGap * horizontally and yGap vertically */ -void removeoverlap(GSList const *const items, double const xGap, double const yGap) { - using Inkscape::Util::GSListConstIterator; - std::list<SPItem *> selected; - selected.insert<GSListConstIterator<SPItem *> >(selected.end(), items, NULL); +void removeoverlap(std::vector<SPItem*> const &items, double const xGap, double const yGap) { + std::vector<SPItem*> selected(items); std::vector<Record> records; std::vector<Rectangle *> rs; Geom::Point const gap(xGap, yGap); - for (std::list<SPItem *>::iterator it(selected.begin()); + for (std::vector<SPItem*>::iterator it(selected.begin()); it != selected.end(); ++it) { + SPItem* item = *it; using Geom::X; using Geom::Y; - Geom::OptRect item_box((*it)->desktopVisualBounds()); + Geom::OptRect item_box((item)->desktopVisualBounds()); if (item_box) { Geom::Point min(item_box->min() - .5*gap); Geom::Point max(item_box->max() + .5*gap); @@ -67,7 +66,7 @@ void removeoverlap(GSList const *const items, double const xGap, double const yG min[Y] = max[Y] = (min[Y] + max[Y])/2; } Rectangle *vspc_rect = new Rectangle(min[X], max[X], min[Y], max[Y]); - records.push_back(Record(*it, item_box->midpoint(), vspc_rect)); + records.push_back(Record(item, item_box->midpoint(), vspc_rect)); rs.push_back(vspc_rect); } } diff --git a/src/removeoverlap.h b/src/removeoverlap.h index 7109c9513..d873663d1 100644 --- a/src/removeoverlap.h +++ b/src/removeoverlap.h @@ -15,6 +15,6 @@ typedef struct _GSList GSList; -void removeoverlap(GSList const *items, double xGap, double yGap); +void removeoverlap(std::vector<SPItem*> const &items, double xGap, double yGap); #endif // SEEN_REMOVEOVERLAP_H diff --git a/src/selcue.cpp b/src/selcue.cpp index d2fa0970a..c73219b7d 100644 --- a/src/selcue.cpp +++ b/src/selcue.cpp @@ -96,15 +96,16 @@ void Inkscape::SelCue::_updateItemBboxes(Inkscape::Preferences *prefs) void Inkscape::SelCue::_updateItemBboxes(gint mode, int prefs_bbox) { - GSList const *items = _selection->itemList(); - if (_item_bboxes.size() != g_slist_length((GSList *) items)) { + const std::vector<SPItem*> items = _selection->itemList(); + if (_item_bboxes.size() != items.size()) { _newItemBboxes(); return; } int bcount = 0; - for (GSList const *l = _selection->itemList(); l != NULL; l = l->next) { - SPItem *item = static_cast<SPItem *>(l->data); + std::vector<SPItem*> ll=_selection->itemList(); + for (std::vector<SPItem*>::const_iterator l = ll.begin(); l != ll.end(); l++) { + SPItem *item = *l; SPCanvasItem* box = _item_bboxes[bcount ++]; if (box) { @@ -145,8 +146,9 @@ void Inkscape::SelCue::_newItemBboxes() int prefs_bbox = prefs->getBool("/tools/bounding_box"); - for (GSList const *l = _selection->itemList(); l != NULL; l = l->next) { - SPItem *item = static_cast<SPItem *>(l->data); + std::vector<SPItem*> ll=_selection->itemList(); + for (std::vector<SPItem*>::const_iterator l = ll.begin(); l != ll.end(); l++) { + SPItem *item = *l; Geom::OptRect const b = (prefs_bbox == 0) ? item->desktopVisualBounds() : item->desktopGeometricBounds(); @@ -199,8 +201,9 @@ void Inkscape::SelCue::_newTextBaselines() } _text_baselines.clear(); - for (GSList const *l = _selection->itemList(); l != NULL; l = l->next) { - SPItem *item = static_cast<SPItem *>(l->data); + std::vector<SPItem*> ll = _selection->itemList(); + for (std::vector<SPItem*>::const_iterator l=ll.begin();l!=ll.end();l++) { + SPItem *item = *l; SPCanvasItem* baseline_point = NULL; if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item)) { // visualize baseline diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 5e8fd5e07..7255e80cb 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -279,25 +279,21 @@ void SelectionHelper::fixSelection(SPDesktop *dt) Inkscape::Selection *selection = dt->getSelection(); - GSList *items = NULL; + std::vector<SPItem*> items ; - GSList const *selList = selection->itemList(); + std::vector<SPItem*> const selList = selection->itemList(); - for( GSList const *i = selList; i; i = i->next ) { - SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(i->data)); + for( std::vector<SPItem*>::const_reverse_iterator i = selList.rbegin(); i != selList.rend(); i++ ) { + SPItem *item = *i; if( item && !dt->isLayer(item) && (!item->isLocked())) { - items = g_slist_prepend(items, item); + items.push_back(item); } } selection->setList(items); - - if(items) { - g_slist_free(items); - } } } // namespace Inkscape @@ -307,7 +303,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, std::vector<Inkscape::XML::Node*> &clip, Inkscape::XML::Document* xml_doc) { Inkscape::XML::Node *copy = repr->duplicate(xml_doc); @@ -323,41 +319,39 @@ 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.insert(clip.begin(),copy); } -static void sp_selection_copy_impl(GSList const *items, GSList **clip, Inkscape::XML::Document* xml_doc) +static void sp_selection_copy_impl(std::vector<SPItem*> const &items, std::vector<Inkscape::XML::Node*> &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); + std::vector<SPItem*> sorted_items(items); + sort(sorted_items.begin(),sorted_items.end(),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 (std::vector<SPItem*>::const_iterator i = sorted_items.begin(); i != sorted_items.end(); i++) { + SPItem *item = *i; if (item) { sp_selection_copy_one(item->getRepr(), item->i2doc_affine(), clip, xml_doc); } else { g_assert_not_reached(); } } - - *clip = g_slist_reverse(*clip); - g_slist_free(static_cast<GSList *>(sorted_items)); + reverse(clip.begin(),clip.end()); } // 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 std::vector<Inkscape::XML::Node*> sp_selection_paste_impl(SPDocument *doc, SPObject *parent, std::vector<Inkscape::XML::Node*> &clip) { Inkscape::XML::Document *xml_doc = doc->getReprDoc(); SPItem *parentItem = dynamic_cast<SPItem *>(parent); g_assert(parentItem != NULL); - GSList *copied = NULL; + std::vector<Inkscape::XML::Node*> 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 (std::vector<Inkscape::XML::Node*>::const_iterator l = clip.begin(); l != clip.end(); l++) { + Inkscape::XML::Node *repr = *l; Inkscape::XML::Node *copy = repr->duplicate(xml_doc); // premultiply the item transform by the accumulated parent transform in the paste layer @@ -375,19 +369,19 @@ static GSList *sp_selection_paste_impl(SPDocument *doc, SPObject *parent, GSList } parent->appendChildRepr(copy); - copied = g_slist_prepend(copied, copy); + copied.push_back(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(std::vector<SPItem*> 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 (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); i++) { + sp_object_ref(*i, NULL); } - for (GSList const *i = items; i != NULL; i = i->next) { - SPItem *item = static_cast<SPItem *>(i->data); + for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); i++) { + SPItem *item = *i; item->deleteObject(propagate, propagate_descendants); sp_object_unref(item, NULL); } @@ -414,11 +408,9 @@ 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())); + std::vector<SPItem*> selected(selection->itemList()); selection->clear(); sp_selection_delete_impl(selected); - g_slist_free(selected); desktop->currentLayer()->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); /* a tool may have set up private information in it's selection context @@ -461,16 +453,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())); + std::vector<Inkscape::XML::Node*> 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); + sort(reprs.begin(),reprs.end(),sp_repr_compare_position); - GSList *newsel = NULL; + std::vector<Inkscape::XML::Node*> newsel; std::vector<const gchar *> old_ids; std::vector<const gchar *> new_ids; @@ -478,8 +469,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); + for(std::vector<Inkscape::XML::Node*>::const_reverse_iterator i=reprs.rbegin();i!=reprs.rend();i++){ + Inkscape::XML::Node *old_repr = *i; Inkscape::XML::Node *parent = old_repr->parent(); Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); @@ -500,8 +491,7 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) } } - newsel = g_slist_prepend(newsel, copy); - reprs = g_slist_remove(reprs, reprs->data); + newsel.push_back(copy); Inkscape::GC::release(copy); } @@ -547,8 +537,6 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) } selection->setReprList(newsel); - - g_slist_free(newsel); } void sp_edit_clear_all(Inkscape::Selection *selection) @@ -561,11 +549,10 @@ 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); + std::vector<SPItem*> items = sp_item_group_item_list(group); - while (items) { - reinterpret_cast<SPObject*>(items->data)->deleteObject(); - items = g_slist_remove(items, items->data); + for(unsigned int i = 0; i < items.size(); i++){ + items[i]->deleteObject(); } DocumentUndo::done(doc, SP_VERB_EDIT_CLEAR_ALL, @@ -582,7 +569,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) +std::vector<SPItem*> &get_all_items(std::vector<SPItem*> &list, SPObject *from, SPDesktop *desktop, bool onlyvisible, bool onlysensitive, bool ingroups, std::vector<SPItem*> const &exclude) { for ( SPObject *child = from->firstChild() ; child; child = child->getNext() ) { SPItem *item = dynamic_cast<SPItem *>(child); @@ -590,10 +577,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.insert(list.begin(),item); } if (ingroups || (item && desktop->isLayer(item))) { @@ -618,9 +605,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; + std::vector<SPItem*> items ; - GSList const *exclude = NULL; + std::vector<SPItem*> exclude; if (invert) { exclude = selection->itemList(); } @@ -634,40 +621,38 @@ 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())); + std::vector<SPItem*> 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 (std::vector<SPItem*>::const_reverse_iterator i=all_items.rbegin();i!=all_items.rend();i++) { + SPItem *item = *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_back(item); // leave it in the list } } } } } - g_slist_free(all_items); break; } case PREFS_SELECTION_LAYER_RECURSIVE: { - items = get_all_items(NULL, dt->currentLayer(), dt, onlyvisible, onlysensitive, FALSE, exclude); + std::vector<SPItem*> 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); + std::vector<SPItem*> x; + items = get_all_items(x, dt->currentRoot(), dt, onlyvisible, onlysensitive, FALSE, exclude); break; } } selection->setList(items); - if (items) { - g_slist_free(items); - } } void sp_edit_select_all(SPDesktop *desktop) @@ -690,16 +675,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(std::vector<Inkscape::XML::Node*> p, Inkscape::XML::Node *group, Inkscape::XML::Document *xml_doc, SPDocument *doc) { - p = g_slist_sort(p, (GCompareFunc) sp_repr_compare_position); + sort(p.begin(),p.end(),sp_repr_compare_position); // 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 = p.back()->position(); + Inkscape::XML::Node *topmost_parent = p.back()->parent(); - while (p) { - Inkscape::XML::Node *current = static_cast<Inkscape::XML::Node *>(p->data); + for(std::vector<Inkscape::XML::Node*>::const_iterator i = p.begin(); i != p.end(); i++){ + Inkscape::XML::Node *current = *i; if (current->parent() == topmost_parent) { Inkscape::XML::Node *spnew = current->duplicate(xml_doc); @@ -708,7 +693,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; + std::vector<Inkscape::XML::Node*> 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 +709,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, + std::vector<Inkscape::XML::Node*> 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 = copied.back(); // make a copy Inkscape::XML::Node *spnew = in_topmost->duplicate(xml_doc); // remove pasted @@ -740,10 +725,9 @@ 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); } // Add the new group to the topmost members' parent @@ -764,9 +748,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)); + std::vector<Inkscape::XML::Node*> p (selection->reprList()); selection->clear(); @@ -802,11 +784,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; + std::vector<SPItem*> old_select = selection->itemList(); + std::vector<SPItem*> new_select; GSList *groups = NULL; - for (GSList *item = old_select; item; item = item->next) { - SPItem *obj = static_cast<SPItem*>(item->data); + for (std::vector<SPItem*>::const_iterator item = old_select.begin(); item!=old_select.end(); item++) { + SPItem *obj = *item; if (dynamic_cast<SPGroup *>(obj)) { groups = g_slist_prepend(groups, obj); } @@ -818,14 +800,14 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop) return; } - GSList *items = g_slist_copy(old_select); + std::vector<SPItem*> 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 (std::vector<SPItem*>::const_iterator item = items.begin(); item != items.end(); item++) { + SPUse *use = dynamic_cast<SPUse *>(*item); SPItem *original = use; while (dynamic_cast<SPUse *>(original)) { @@ -833,7 +815,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 +826,53 @@ 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(); + std::vector<SPItem*>::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 (std::vector<SPItem*>::iterator item = items.begin(); item != items.end(); item++) { + SPItem *obj = *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) { + std::vector<SPItem*> 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.insert(new_select.end(),children.begin(),children.end()); + *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); 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) +std::vector<SPItem*> +sp_degroup_list(std::vector<SPItem*> &items) { - GSList *out = NULL; + std::vector<SPItem*> out; bool has_groups = false; - for (GSList *item = items; item; item = item->next) { - SPGroup *group = dynamic_cast<SPGroup *>(static_cast<SPObject *>(item->data)); + for (std::vector<SPItem*>::const_iterator item=items.begin();item!=items.end();item++) { + SPGroup *group = dynamic_cast<SPGroup *>(*item); if (!group) { - out = g_slist_prepend(out, item->data); + out.push_back(*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); + std::vector<SPItem*> members = sp_item_group_item_list(group); + for (std::vector<SPItem*>::const_iterator member=members.begin();member!=members.end();member++) { + out.push_back(*member); } - g_slist_free(members); + members.clear(); } } - out = g_slist_reverse(out); - g_slist_free(items); if (has_groups) { // recurse if we unwrapped a group - it may have contained others out = sp_degroup_list(out); @@ -906,18 +884,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(std::vector<SPItem*> const items) { - if (!items) { + if (items.empty()) { return NULL; } - SPObject *parent = SP_OBJECT(items->data)->parent; + SPObject *parent = items[0]->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 (std::vector<SPItem*>::const_iterator item=items.begin();item!=items.end();item++) { + if((*item)==items[0])continue; + if ((*item)->parent != parent) { return NULL; } } @@ -927,13 +906,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(std::vector<SPItem*> 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 (std::vector<SPItem*>::const_iterator i = items.begin();i!=items.end();i++) { + r.unionWith((*i)->desktopVisualBounds()); } return r; } @@ -948,11 +927,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) { + std::vector<SPItem*> items= selection->itemList(); + if (items.empty()) { selection_display_message(desktop, Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to raise.")); return; } @@ -966,16 +951,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); + std::vector<SPItem*> rev(items); + sort(rev.begin(),rev.end(),sp_item_repr_compare_position); // 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); + for (std::vector<SPItem*>::const_iterator item=rev.begin();item!=rev.end();item++) { + SPObject *child = *item; // 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 +969,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,12 +977,8 @@ sp_selection_raise(Inkscape::Selection *selection, SPDesktop *desktop) } } } - rev = g_slist_remove(rev, child); } - } else { - g_slist_free(rev); } - DocumentUndo::done(selection->layers()->getDocument(), SP_VERB_SELECTION_RAISE, //TRANSLATORS: "Raise" means "to raise an object" in the undo history C_("Undo action", "Raise")); @@ -1012,7 +993,7 @@ void sp_selection_raise_to_top(Inkscape::Selection *selection, SPDesktop *deskto return; } - GSList const *items = const_cast<GSList *>(selection->itemList()); + std::vector<SPItem*> items = selection->itemList(); SPGroup const *group = sp_item_list_common_parent_group(items); if (!group) { @@ -1020,24 +1001,22 @@ 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); + std::vector<Inkscape::XML::Node*> rl(selection->reprList()); + sort(rl.begin(),rl.end(),sp_repr_compare_position); - for (GSList *l = rl; l != NULL; l = l->next) { - Inkscape::XML::Node *repr = static_cast<Inkscape::XML::Node *>(l->data); + for (std::vector<Inkscape::XML::Node*>::const_iterator l=rl.begin(); l!=rl.end();l++) { + Inkscape::XML::Node *repr =(*l); repr->setPosition(-1); } - g_slist_free(rl); - DocumentUndo::done(document, SP_VERB_SELECTION_TO_FRONT, _("Raise to top")); } void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop) { - GSList const *items = const_cast<GSList *>(selection->itemList()); - if (!items) { + std::vector<SPItem*> items = selection->itemList(); + if (items.empty()) { selection_display_message(desktop, Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to lower.")); return; } @@ -1054,14 +1033,13 @@ 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); + std::vector<SPItem*> rev(items); + sort(rev.begin(),rev.end(),sp_item_repr_compare_position); // Iterate over all objects in the selection (starting from top). if (selected) { - while (rev) { - SPObject *child = reinterpret_cast<SPObject*>(rev->data); + for (std::vector<SPItem*>::const_reverse_iterator item=rev.rbegin();item!=rev.rend();item++) { + SPObject *child = *item; // 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 +1048,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 +1060,7 @@ void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop) } } } - rev = g_slist_remove(rev, child); } - } else { - g_slist_free(rev); } DocumentUndo::done(selection->layers()->getDocument(), SP_VERB_SELECTION_LOWER, @@ -1102,7 +1077,7 @@ void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *des return; } - GSList const *items = const_cast<GSList *>(selection->itemList()); + std::vector<SPItem*> items =selection->itemList(); SPGroup const *group = sp_item_list_common_parent_group(items); if (!group) { @@ -1110,15 +1085,13 @@ 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); + std::vector<Inkscape::XML::Node*> rl(selection->reprList()); + sort(rl.begin(),rl.end(),sp_repr_compare_position); - for (GSList *l = rl; l != NULL; l = l->next) { + for (std::vector<Inkscape::XML::Node*>::const_reverse_iterator l=rl.rbegin();l!=rl.rend();l++) { gint minpos; SPObject *pp, *pc; - Inkscape::XML::Node *repr = static_cast<Inkscape::XML::Node *>(l->data); + Inkscape::XML::Node *repr = (*l); pp = document->getObjectByRepr(repr->parent()); minpos = 0; g_assert(dynamic_cast<SPGroup *>(pp)); @@ -1130,8 +1103,6 @@ void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *des repr->setPosition(minpos); } - g_slist_free(rl); - DocumentUndo::done(document, SP_VERB_SELECTION_TO_BACK, _("Lower to bottom")); } @@ -1269,9 +1240,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); + std::vector<SPItem*> list=selection->itemList(); + for ( std::vector<SPItem*>::const_iterator itemlist=list.begin();itemlist!=list.end();itemlist++) { + SPItem *item = *itemlist; sp_selection_remove_livepatheffect_impl(item); @@ -1325,10 +1296,10 @@ void sp_selection_paste_size_separately(SPDesktop *desktop, bool apply_x, bool a * Ensures that the clones of objects are not modified when moving objects between layers. * Calls the same function as ungroup */ -void sp_selection_change_layer_maintain_clones(GSList const *items,SPObject *where) +void sp_selection_change_layer_maintain_clones(std::vector<SPItem*> const &items,SPObject *where) { - for (const GSList *i = items; i != NULL; i = i->next) { - SPItem *item = dynamic_cast<SPItem *>(SP_OBJECT(i->data)); + for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); i++) { + SPItem *item = *i; if (item) { SPItem *oldparent = dynamic_cast<SPItem *>(item->parent); SPItem *newparent = dynamic_cast<SPItem *>(where); @@ -1350,26 +1321,24 @@ void sp_selection_to_next_layer(SPDesktop *dt, bool suppressDone) return; } - GSList const *items = g_slist_copy(const_cast<GSList *>(selection->itemList())); + std::vector<SPItem*> 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) { sp_selection_change_layer_maintain_clones(items,next); - GSList *temp_clip = NULL; - sp_selection_copy_impl(items, &temp_clip, dt->doc()->getReprDoc()); + std::vector<Inkscape::XML::Node*> 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; + std::vector<Inkscape::XML::Node*> 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); if (next) dt->setCurrentLayer(next); if ( !suppressDone ) { DocumentUndo::done(dt->getDocument(), SP_VERB_LAYER_MOVE_TO_NEXT, @@ -1383,7 +1352,6 @@ 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)); } void sp_selection_to_prev_layer(SPDesktop *dt, bool suppressDone) @@ -1396,26 +1364,24 @@ void sp_selection_to_prev_layer(SPDesktop *dt, bool suppressDone) return; } - GSList const *items = g_slist_copy(const_cast<GSList *>(selection->itemList())); + const std::vector<SPItem*> 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) { sp_selection_change_layer_maintain_clones(items,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 + std::vector<Inkscape::XML::Node*> 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; + std::vector<Inkscape::XML::Node*> 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); if (next) dt->setCurrentLayer(next); if ( !suppressDone ) { DocumentUndo::done(dt->getDocument(), SP_VERB_LAYER_MOVE_TO_PREV, @@ -1428,8 +1394,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) @@ -1442,25 +1406,22 @@ void sp_selection_to_layer(SPDesktop *dt, SPObject *moveto, bool suppressDone) return; } - GSList const *items = g_slist_copy(const_cast<GSList *>(selection->itemList())); + std::vector<SPItem*> items(selection->itemList()); if (moveto) { sp_selection_change_layer_maintain_clones(items,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 + std::vector<Inkscape::XML::Node*> 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); + std::vector<Inkscape::XML::Node*> copied = sp_selection_paste_impl(dt->getDocument(), moveto, temp_clip); + selection->setReprList(copied); + 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 @@ -1495,8 +1456,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)); + std::vector<SPItem*> items = selection->itemList(); + for (std::vector<SPItem*>::const_iterator l=items.begin();l!=items.end() ;l++) { + SPItem *item = *l; if (item) { clone_with_original |= selection_contains_original(item, selection); if (clone_with_original) @@ -1539,9 +1501,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)); + std::vector<SPItem*> items = selection->itemList(); + for (std::vector<SPItem*>::const_iterator l=items.begin();l!=items.end() ;l++) { + SPItem *item = *l; if( dynamic_cast<SPRoot *>(item) ) { // An SVG element cannot have a transform. We could change 'x' and 'y' in response @@ -1710,10 +1672,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; + std::vector<Inkscape::XML::Node*> items = selection->reprList(); + for (std::vector<Inkscape::XML::Node*>::const_iterator l=items.begin();l!=items.end() ;l++) { + (*l)->setAttribute("transform", NULL, false); } DocumentUndo::done(desktop->getDocument(), SP_VERB_OBJECT_FLATTEN, @@ -1811,10 +1772,10 @@ void sp_selection_rotate_90(SPDesktop *desktop, bool ccw) if (selection->isEmpty()) return; - GSList const *l = selection->itemList(); + std::vector<SPItem*> 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 (std::vector<SPItem*>::const_iterator l=items.begin();l!=items.end() ;l++) { + SPItem *item = *l; if (item) { sp_item_rotate_rel(item, rot_90); } else { @@ -1870,15 +1831,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; + std::vector<SPItem*> x,y; + std::vector<SPItem*> all_list = get_all_items(x, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, y); + std::vector<SPItem*> 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; + std::vector<SPItem*> items = selection->itemList(); + for (std::vector<SPItem*>::const_iterator sel_iter=items.begin();sel_iter!=items.end();sel_iter++) { + SPItem *sel = *sel_iter; + std::vector<SPItem*> matches = all_list; if (fill && stroke && style) { matches = sp_get_same_style(sel, matches); } @@ -1891,19 +1852,12 @@ void sp_select_same_fill_stroke_style(SPDesktop *desktop, gboolean fill, gboolea else if (style) { matches = sp_get_same_style(sel, matches,SP_STROKE_STYLE_ALL); } - all_matches = g_slist_concat (all_matches, matches); + all_matches.insert(all_matches.end(), matches.begin(),matches.end()); } selection->clear(); selection->setList(all_matches); - if (all_matches) { - g_slist_free(all_matches); - } - if (all_list) { - g_slist_free(all_list); - } - } @@ -1924,14 +1878,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; + std::vector<SPItem*> x,y; + std::vector<SPItem*> all_list = get_all_items(x, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, y); + std::vector<SPItem*> 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)); + std::vector<SPItem*> items=selection->itemList(); + for (std::vector<SPItem*>::const_iterator sel_iter=items.begin();sel_iter!=items.end();sel_iter++) { + SPItem *sel = *sel_iter; if (sel) { matches = sp_get_same_object_type(sel, matches); } else { @@ -1942,12 +1897,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); - } } @@ -1956,15 +1905,15 @@ void sp_select_same_object_type(SPDesktop *desktop) * 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) +std::vector<SPItem*> sp_get_same_fill_or_stroke_color(SPItem *sel, std::vector<SPItem*> &src, SPSelectStrokeStyleType type) { - GSList *matches = NULL; + std::vector<SPItem*> 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 (std::vector<SPItem*>::const_reverse_iterator i=src.rbegin();i!=src.rend();i++) { + SPItem *iter = *i; if (iter) { SPIPaint *iter_paint = (type == SP_FILL_COLOR) ? &(iter->style->fill) : &(iter->style->stroke); match = false; @@ -2003,7 +1952,7 @@ GSList *sp_get_same_fill_or_stroke_color(SPItem *sel, GSList *src, SPSelectStrok } if (match) { - matches = g_slist_prepend(matches, iter); + matches.push_back(iter); } } else { g_assert_not_reached(); @@ -2054,17 +2003,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) +std::vector<SPItem*> sp_get_same_object_type(SPItem *sel, std::vector<SPItem*> &src) { - GSList *matches = NULL; + std::vector<SPItem*> matches; - for (GSList *i = src; i != NULL; i = i->next) { - SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(i->data)); + for (std::vector<SPItem*>::const_reverse_iterator i=src.rbegin();i!=src.rend();i++) { + SPItem *item = *i; if (item && item_type_match(sel, item) && !item->cloned) { - matches = g_slist_prepend (matches, item); + matches.push_back(item); } } - return matches; } @@ -2074,9 +2022,9 @@ GSList *sp_get_same_fill_or_stroke_color(SPItem *sel, GSList *src, SPSelectStrok * 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_style(SPItem *sel, GSList *src, SPSelectStrokeStyleType type) +std::vector<SPItem*> sp_get_same_style(SPItem *sel, std::vector<SPItem*> &src, SPSelectStrokeStyleType type) { - GSList *matches = NULL; + std::vector<SPItem*> matches; bool match = false; SPStyle *sel_style = sel->style; @@ -2092,16 +2040,16 @@ GSList *sp_get_same_style(SPItem *sel, GSList *src, SPSelectStrokeStyleType type * Stroke width needs to handle transformations, so call this function * to get the transformed stroke width */ - GSList *objects = NULL; + std::vector<SPItem*> objects; SPStyle *sel_style_for_width = NULL; if (type == SP_STROKE_STYLE_WIDTH || type == SP_STROKE_STYLE_ALL || type==SP_STYLE_ALL ) { - objects = g_slist_prepend(objects, sel); + objects.push_back(sel); sel_style_for_width = new SPStyle(SP_ACTIVE_DOCUMENT); objects_query_strokewidth (objects, sel_style_for_width); } bool match_g; - for (GSList *i = src; i != NULL; i = i->next) { - SPItem *iter = dynamic_cast<SPItem *>(static_cast<SPObject *>(i->data)); + for (std::vector<SPItem*>::const_iterator i=src.begin();i!=src.end();i++) { + SPItem *iter = *i; if (iter) { match_g=true; SPStyle *iter_style = iter->style; @@ -2110,15 +2058,14 @@ GSList *sp_get_same_style(SPItem *sel, GSList *src, SPSelectStrokeStyleType type if (type == SP_STROKE_STYLE_WIDTH|| type == SP_STROKE_STYLE_ALL|| type==SP_STYLE_ALL) { 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); + std::vector<SPItem*> objects; + objects.insert(objects.begin(),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); } } match_g = match_g && match; @@ -2141,10 +2088,10 @@ GSList *sp_get_same_style(SPItem *sel, GSList *src, SPSelectStrokeStyleType type } } } - match_g = match_g && match; + match_g = match_g && match; if (match_g) { while (iter->cloned) iter=dynamic_cast<SPItem *>(iter->parent); - matches = g_slist_prepend(matches, iter); + matches.insert(matches.begin(),iter); } } else { g_assert_not_reached(); @@ -2152,8 +2099,6 @@ GSList *sp_get_same_style(SPItem *sel, GSList *src, SPSelectStrokeStyleType type } if( sel_style_for_width != NULL ) delete sel_style_for_width; - g_slist_free(objects); - return matches; } @@ -2307,17 +2252,9 @@ sp_selection_move_screen(Inkscape::Selection *selection, gdouble dx, gdouble dy) } } -namespace { -template <typename D> -SPItem *next_item(SPDesktop *desktop, GSList *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, - bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive); - -struct Forward { +typedef struct Forward { typedef SPObject *Iterator; static Iterator children(SPObject *o) { return o->firstChild(); } @@ -2326,9 +2263,9 @@ struct Forward { static SPObject *object(Iterator i) { return i; } static Iterator next(Iterator i) { return i->getNext(); } -}; +} Forward; -struct ListReverse { +typedef struct ListReverse { typedef GSList *Iterator; static Iterator children(SPObject *o) { @@ -2359,8 +2296,87 @@ private: } return list; } -}; +} ListReverse; + + + +template <typename D> +SPItem *next_item(SPDesktop *desktop, GSList *path, SPObject *root, + bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive) +{ + typename D::Iterator children; + typename D::Iterator iter; + + SPItem *found=NULL; + + if (path) { + SPObject *object=reinterpret_cast<SPObject *>(path->data); + g_assert(object->parent == root); + if (desktop->isLayer(object)) { + found = next_item<D>(desktop, path->next, object, only_in_viewport, inlayer, onlyvisible, onlysensitive); + } + iter = children = D::siblings_after(object); + } else { + iter = children = D::children(root); + } + + while ( iter && !found ) { + SPObject *object=D::object(iter); + if (desktop->isLayer(object)) { + if (PREFS_SELECTION_LAYER != inlayer) { // recurse into sublayers + found = next_item<D>(desktop, NULL, object, only_in_viewport, inlayer, onlyvisible, onlysensitive); + } + } else { + SPItem *item = dynamic_cast<SPItem *>(object); + if ( item && + ( !only_in_viewport || desktop->isWithinViewport(item) ) && + ( !onlyvisible || !desktop->itemIsHidden(item)) && + ( !onlysensitive || !item->isLocked()) && + !desktop->isLayer(item) ) + { + found = item; + } + } + iter = D::next(iter); + } + + D::dispose(children); + return found; +} + + +template <typename D> +SPItem *next_item_from_list(SPDesktop *desktop, std::vector<SPItem*> const items, + SPObject *root, bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive) +{ + SPObject *current=root; + for(std::vector<SPItem*>::const_iterator i = items.begin();i!=items.end();i++) { + SPItem *item = *i; + if ( root->isAncestorOf(item) && + ( !only_in_viewport || desktop->isWithinViewport(item) ) ) + { + current = item; + break; + } + } + + GSList *path=NULL; + while ( current != root ) { + path = g_slist_prepend(path, current); + current = current->parent; + } + + SPItem *next; + // first, try from the current object + next = next_item<D>(desktop, path, root, only_in_viewport, inlayer, onlyvisible, onlysensitive); + g_slist_free(path); + + if (!next) { // if we ran out of objects, start over at the root + next = next_item<D>(desktop, NULL, root, only_in_viewport, inlayer, onlyvisible, onlysensitive); + } + + return next; } void @@ -2487,88 +2503,8 @@ void sp_selection_edit_clip_or_mask(SPDesktop * /*dt*/, bool /*clip*/) } -namespace { - -template <typename D> -SPItem *next_item_from_list(SPDesktop *desktop, GSList const *items, - SPObject *root, bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive) -{ - SPObject *current=root; - while (items) { - SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(items->data)); - if ( root->isAncestorOf(item) && - ( !only_in_viewport || desktop->isWithinViewport(item) ) ) - { - current = item; - break; - } - items = items->next; - } - - GSList *path=NULL; - while ( current != root ) { - path = g_slist_prepend(path, current); - current = current->parent; - } - - SPItem *next; - // first, try from the current object - next = next_item<D>(desktop, path, root, only_in_viewport, inlayer, onlyvisible, onlysensitive); - g_slist_free(path); - - if (!next) { // if we ran out of objects, start over at the root - next = next_item<D>(desktop, NULL, root, only_in_viewport, inlayer, onlyvisible, onlysensitive); - } - - return next; -} -template <typename D> -SPItem *next_item(SPDesktop *desktop, GSList *path, SPObject *root, - bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive) -{ - typename D::Iterator children; - typename D::Iterator iter; - SPItem *found=NULL; - - if (path) { - SPObject *object=reinterpret_cast<SPObject *>(path->data); - g_assert(object->parent == root); - if (desktop->isLayer(object)) { - found = next_item<D>(desktop, path->next, object, only_in_viewport, inlayer, onlyvisible, onlysensitive); - } - iter = children = D::siblings_after(object); - } else { - iter = children = D::children(root); - } - - while ( iter && !found ) { - SPObject *object=D::object(iter); - if (desktop->isLayer(object)) { - if (PREFS_SELECTION_LAYER != inlayer) { // recurse into sublayers - found = next_item<D>(desktop, NULL, object, only_in_viewport, inlayer, onlyvisible, onlysensitive); - } - } else { - SPItem *item = dynamic_cast<SPItem *>(object); - if ( item && - ( !only_in_viewport || desktop->isWithinViewport(item) ) && - ( !onlyvisible || !desktop->itemIsHidden(item)) && - ( !onlysensitive || !item->isLocked()) && - !desktop->isLayer(item) ) - { - found = item; - } - } - iter = D::next(iter); - } - - D::dispose(children); - - return found; -} - -} /** * If \a item is not entirely visible then adjust visible area to centre on the centre on of @@ -2608,17 +2544,17 @@ void sp_selection_clone(SPDesktop *desktop) return; } - GSList *reprs = g_slist_copy(const_cast<GSList *>(selection->reprList())); + std::vector<Inkscape::XML::Node*> 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); + sort(reprs.begin(),reprs.end(),sp_repr_compare_position); - GSList *newsel = NULL; + std::vector<Inkscape::XML::Node*> newsel; - while (reprs) { - Inkscape::XML::Node *sel_repr = static_cast<Inkscape::XML::Node *>(reprs->data); + for(std::vector<Inkscape::XML::Node*>::const_reverse_iterator i=reprs.rbegin();i!=reprs.rend();i++){ + Inkscape::XML::Node *sel_repr = *i; Inkscape::XML::Node *parent = sel_repr->parent(); Inkscape::XML::Node *clone = xml_doc->createElement("svg:use"); @@ -2634,8 +2570,7 @@ 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_back(clone); Inkscape::GC::release(clone); } @@ -2643,8 +2578,6 @@ void sp_selection_clone(SPDesktop *desktop) C_("Action", "Clone")); selection->setReprList(newsel); - - g_slist_free(newsel); } void @@ -2670,11 +2603,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); + std::vector<SPItem*> items=selection->itemList(); + for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + SPItem *item = *i; if (dynamic_cast<SPUse *>(item)) { item->getRepr()->setAttribute("xlink:href", newref); @@ -2708,13 +2639,11 @@ sp_selection_unlink(SPDesktop *desktop) } // Get a copy of current selection. - GSList *new_select = NULL; + std::vector<SPItem*> 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); + std::vector<SPItem*> items=selection->itemList(); + for (std::vector<SPItem*>::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){ + SPItem *item = *i; if (dynamic_cast<SPText *>(item)) { SPObject *tspan = sp_tref_convert_to_tspan(item); @@ -2730,7 +2659,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_back(item); continue; } @@ -2740,7 +2669,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_back(item); continue; } } else /*if (SP_IS_TREF(use))*/ { @@ -2750,13 +2679,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_back(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.")); @@ -2779,7 +2707,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) { + + std::vector<SPItem*> items=selection->itemList(); + if (items.size() != 1 || !item) { desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, error); return; } @@ -2876,14 +2806,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)) { + std::vector<SPItem*> items=selection->itemList(); + for (std::vector<SPItem*>::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) { @@ -2960,12 +2891,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())); + std::vector<SPItem*> 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 = items[0]->parent; Geom::Affine parent_transform; { @@ -2978,10 +2909,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); + std::vector<Inkscape::XML::Node*> repr_copies; + for (std::vector<SPItem*>::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){ + Inkscape::XML::Node *dup = (*i)->getRepr()->duplicate(xml_doc); + repr_copies.push_back(dup); } Geom::Rect bbox(desktop->dt2doc(r->min()), desktop->dt2doc(r->max())); @@ -2989,8 +2920,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 (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + SPObject *item = *i; item->deleteObject(false); } } @@ -3009,7 +2940,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")); @@ -3018,8 +2948,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); + std::vector<SPItem*> items=sp_item_group_item_list(group); + for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + sp_selection_to_guides_recursive(*i, wholegroups); } } else { item->convert_to_guides(); @@ -3034,9 +2965,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())); + std::vector<SPItem*> items(selection->itemList()); - if (!items) { + if (items.empty()) { desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to convert to guides.")); return; } @@ -3049,8 +2980,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 (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + sp_selection_to_guides_recursive(*i, wholegroups); } if (deleteitems) { @@ -3058,8 +2989,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")); } @@ -3102,18 +3031,18 @@ void sp_selection_symbol(SPDesktop *desktop, bool /*apply*/ ) doc->ensureUpToDate(); - GSList *items = g_slist_copy(const_cast<GSList *>(selection->list())); + std::vector<SPObject*> 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 = items[0]->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 = items[0]; the_group = dynamic_cast<SPGroup *>(object); if ( the_group ) { single_group = true; @@ -3124,7 +3053,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 @@ -3170,8 +3098,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 (std::vector<SPObject*>::const_iterator i=items.begin();i!=items.end();i++){ + Inkscape::XML::Node *repr = (*i)->getRepr(); repr->parent()->removeChild(repr); symbol_repr->addChild(repr,NULL); } @@ -3197,7 +3125,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")); } @@ -3238,26 +3165,25 @@ void sp_selection_unsymbol(SPDesktop *desktop) desktop->currentLayer()->getRepr()->appendChild(group); // Move all children of symbol to group - GSList* children = symbol->childList(false); + std::vector<SPObject*> 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 = children[0]; 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 (std::vector<SPObject*>::const_reverse_iterator i=children.rbegin();i!=children.rend();i++){ + Inkscape::XML::Node *repr = (*i)->getRepr(); repr->parent()->removeChild(repr); group->addChild(repr,NULL); } @@ -3283,7 +3209,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")); } @@ -3318,12 +3243,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())); + std::vector<SPItem*> items (selection->itemList()); - items = g_slist_sort(items, (GCompareFunc) sp_object_compare_position); + sort(items.begin(),items.end(),sp_object_compare_position); // bottommost object, after sorting - SPObject *parent = SP_OBJECT(items->data)->parent; + SPObject *parent = items[0]->parent; Geom::Affine parent_transform; @@ -3337,23 +3262,21 @@ sp_selection_tile(SPDesktop *desktop, bool apply) } // remember the position of the first item - gint pos = SP_OBJECT(items->data)->getRepr()->position(); + gint pos = items[0]->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); + std::vector<Inkscape::XML::Node*> repr_copies; + for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + Inkscape::XML::Node *dup = (*i)->getRepr()->duplicate(xml_doc); + repr_copies.push_back(dup); } - // restore the z-order after prepends - repr_copies = g_slist_reverse(repr_copies); 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 (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + SPObject *item = *i; item->deleteObject(false); } } @@ -3399,7 +3322,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")); @@ -3422,15 +3344,13 @@ void sp_selection_untile(SPDesktop *desktop) return; } - GSList *new_select = NULL; + std::vector<SPItem*> 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); + std::vector<SPItem*> items(selection->itemList()); + for (std::vector<SPItem*>::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){ + SPItem *item = *i; SPStyle *style = item->style; @@ -3466,7 +3386,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_back(i); } else { g_assert_not_reached(); } @@ -3493,18 +3413,14 @@ void sp_selection_get_export_hints(Inkscape::Selection *selection, Glib::ustring return; } - GSList const *reprlst = selection->reprList(); + std::vector<Inkscape::XML::Node*> 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 (std::vector<Inkscape::XML::Node*>::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 = *i; if (filename_search) { const gchar* tmp = repr->attribute("inkscape:export-filename"); @@ -3590,10 +3506,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())); + std::vector<SPItem*> items(selection->itemList()); // Sort items so that the topmost comes last - items = g_slist_sort(items, (GCompareFunc) sp_item_repr_compare_position); + sort(items.begin(),items.end(),sp_item_repr_compare_position); // 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) @@ -3604,7 +3520,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"), + items[0]->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 "_" @@ -3624,8 +3540,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 = items.back()->getRepr()->position(); + SPObject *parent_object = items.back()->parent; Inkscape::XML::Node *parent = parent_object->getRepr(); // Calculate resolution @@ -3717,8 +3633,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); @@ -3793,22 +3707,20 @@ void sp_selection_set_clipgroup(SPDesktop *desktop) return; } - GSList const *l = const_cast<GSList *>(selection->reprList()); - - GSList *p = g_slist_copy(const_cast<GSList *>(l)); + std::vector<Inkscape::XML::Node*> p(selection->reprList()); - p = g_slist_sort(p, (GCompareFunc) sp_repr_compare_position); + sort(p.begin(),p.end(),sp_repr_compare_position); 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(); + int topmost = (p.back())->position(); + Inkscape::XML::Node *topmost_parent = (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); + for(std::vector<Inkscape::XML::Node*>::const_iterator i=p.begin();i!=p.end();i++){ + Inkscape::XML::Node *current = *i; if (current->parent() == topmost_parent) { Inkscape::XML::Node *spnew = current->duplicate(xml_doc); @@ -3817,7 +3729,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; + std::vector<Inkscape::XML::Node*> 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 @@ -3833,15 +3745,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, + std::vector<Inkscape::XML::Node*> 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 = copied.back(); // make a copy Inkscape::XML::Node *spnew = in_topmost->duplicate(xml_doc); // remove pasted @@ -3849,10 +3760,8 @@ 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); } Inkscape::XML::Node *outer = xml_doc->createElement("svg:g"); @@ -3910,7 +3819,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; } @@ -3925,9 +3834,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())); + std::vector<SPItem*> items(selection->itemList()); - items = g_slist_sort(items, (GCompareFunc) sp_object_compare_position); + sort(items.begin(),items.end(),sp_object_compare_position); // See lp bug #542004 selection->clear(); @@ -3936,7 +3845,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; + std::vector<SPItem*> items_to_select; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); bool topmost = prefs->getBool("/options/maskobject/topmost", true); @@ -3947,38 +3856,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 (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++) { + Inkscape::XML::Node *dup = (*i)->getRepr()->duplicate(xml_doc); mask_items = g_slist_prepend(mask_items, dup); - SPObject *item = reinterpret_cast<SPObject*>(i->data); + SPObject *item = *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_back((SPItem*)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 = items[0]->getRepr()->duplicate(xml_doc); mask_items = g_slist_prepend(mask_items, dup); if (remove_original) { - SPObject *item = reinterpret_cast<SPObject*>(i->data); + SPObject *item = 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 (std::vector<SPItem*>::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_back(*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 (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++) { + apply_to_items = g_slist_prepend(apply_to_items, *i); + items_to_select.push_back(*i); } Inkscape::XML::Node *dup = SP_OBJECT(i->data)->getRepr()->duplicate(xml_doc); @@ -3989,9 +3898,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 @@ -4001,24 +3908,21 @@ 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; + std::vector<Inkscape::XML::Node*> 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_back(static_cast<SPObject*>(i->data)->getRepr()); + items_to_select.erase(find(items_to_select.begin(),items_to_select.end(),static_cast<SPObject*>(i->data))); } - reprs_to_group = g_slist_reverse(reprs_to_group); 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_back((SPItem*)(doc->getObjectByRepr(group))); Inkscape::GC::release(group); } @@ -4058,7 +3962,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.erase(find(items_to_select.begin(),items_to_select.end(),item)); current->parent()->appendChild(group); sp_repr_unparent(current); group->appendChild(spnew); @@ -4067,7 +3971,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_back((SPItem*)(doc->getObjectByRepr(group))); Inkscape::GC::release(spnew); Inkscape::GC::release(group); } @@ -4082,14 +3986,11 @@ 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.erase(find(items_to_select.begin(),items_to_select.end(),item)); } g_slist_free(items_to_delete); - items_to_select = g_slist_reverse(items_to_select); - 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")); @@ -4121,20 +4022,19 @@ 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())); + std::vector<SPItem*> 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); + std::vector<SPItem*> items_to_select(items); // 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 (std::vector<SPItem*>::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 = *i; Inkscape::URIReference *uri_ref = NULL; if (apply_clip_path) { @@ -4149,9 +4049,9 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) { } } - SP_OBJECT(i->data)->getRepr()->setAttribute(attributeName, "none"); + (*i)->getRepr()->setAttribute(attributeName, "none"); - SPGroup *group = dynamic_cast<SPGroup *>(static_cast<SPObject *>(i->data)); + SPGroup *group = dynamic_cast<SPGroup *>(*i); if (ungroup_masked && group) { // if we had previously enclosed masked object in group, // add it to list so we can ungroup it later @@ -4163,7 +4063,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) { @@ -4171,7 +4070,7 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) { GSList *items_to_move = NULL; for ( SPObject *child = obj->firstChild() ; child; child = child->getNext() ) { // Collect all clipped paths and masks within a single group - Inkscape::XML::Node *copy = SP_OBJECT(child)->getRepr()->duplicate(xml_doc); + Inkscape::XML::Node *copy = child->getRepr()->duplicate(xml_doc); if(copy->attribute("inkscape:original-d") && copy->attribute("inkscape:path-effect")) { copy->setAttribute("d", copy->attribute("inkscape:original-d")); @@ -4197,7 +4096,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_back(mask_item); // transform mask, so it is moved the same spot where mask was applied Geom::Affine transform(mask_item->transform); @@ -4212,10 +4111,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.erase(find(items_to_select.begin(),items_to_select.end(),group)); + std::vector<SPItem*> children; + sp_item_group_ungroup(group, children, false); + items_to_select.insert(items_to_select.end(),children.rbegin(),children.rend()); } else { g_assert_not_reached(); } @@ -4224,9 +4123,7 @@ 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); 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")); diff --git a/src/selection-chemistry.h b/src/selection-chemistry.h index 4ee7a5200..8bcab664b 100644 --- a/src/selection-chemistry.h +++ b/src/selection-chemistry.h @@ -143,8 +143,9 @@ enum SPSelectStrokeStyleType { void sp_select_same_fill_stroke_style(SPDesktop *desktop, gboolean fill, gboolean strok, gboolean style); void sp_select_same_object_type(SPDesktop *desktop); -GSList *sp_get_same_style(SPItem *sel, GSList *src, SPSelectStrokeStyleType type=SP_STYLE_ALL); -GSList *sp_get_same_object_type(SPItem *sel, GSList *src); + +std::vector<SPItem*> sp_get_same_style(SPItem *sel, std::vector<SPItem*> &src, SPSelectStrokeStyleType type=SP_STYLE_ALL); +std::vector<SPItem*> sp_get_same_object_type(SPItem *sel, std::vector<SPItem*> &src); void scroll_to_show_item(SPDesktop *desktop, SPItem *item); @@ -171,9 +172,9 @@ void unlock_all_in_all_layers(SPDesktop *dt); void unhide_all(SPDesktop *dt); void unhide_all_in_all_layers(SPDesktop *dt); -GSList *get_all_items(GSList *list, SPObject *from, SPDesktop *desktop, bool onlyvisible, bool onlysensitive, bool ingroups, GSList const *exclude); +std::vector<SPItem*> &get_all_items(std::vector<SPItem*> &list, SPObject *from, SPDesktop *desktop, bool onlyvisible, bool onlysensitive, bool ingroups, std::vector<SPItem*> const &exclude); -GSList *sp_degroup_list (GSList *items); +std::vector<SPItem*> sp_degroup_list (std::vector<SPItem*> &items); /* selection cycling */ typedef enum diff --git a/src/selection-describer.cpp b/src/selection-describer.cpp index 2386a731e..8304db684 100644 --- a/src/selection-describer.cpp +++ b/src/selection-describer.cpp @@ -40,14 +40,14 @@ #include "sp-spiral.h" // Returns a list of terms for the items to be used in the statusbar -char* collect_terms (GSList *items) +char* collect_terms (const std::vector<SPItem*> &items) { GSList *check = NULL; std::stringstream ss; bool first = true; - for (GSList *i = (GSList *)items; i != NULL; i = i->next) { - SPItem *item = dynamic_cast<SPItem *>(reinterpret_cast<SPObject *>(i->data)); + for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + SPItem *item = *iter; if (item) { const char *term = item->displayName(); if (term != NULL && g_slist_find (check, term) == NULL) { @@ -61,12 +61,12 @@ char* collect_terms (GSList *items) } // Returns the number of terms in the list -static int count_terms (GSList *items) +static int count_terms (const std::vector<SPItem*> &items) { GSList *check = NULL; int count=0; - for (GSList *i = (GSList *)items; i != NULL; i = i->next) { - SPItem *item = dynamic_cast<SPItem *>(reinterpret_cast<SPObject *>(i->data)); + for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + SPItem *item = *iter; if (item) { const char *term = item->displayName(); if (term != NULL && g_slist_find (check, term) == NULL) { @@ -79,11 +79,11 @@ static int count_terms (GSList *items) } // Returns the number of filtered items in the list -static int count_filtered (GSList *items) +static int count_filtered (const std::vector<SPItem*> &items) { int count=0; - for (GSList *i = items; i != NULL; i = i->next) { - SPItem *item = dynamic_cast<SPItem *>(reinterpret_cast<SPObject *>((i->data))); + for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + SPItem *item = *iter; if (item) { count += item->isFiltered(); } @@ -122,12 +122,12 @@ void SelectionDescriber::_selectionModified(Inkscape::Selection *selection, guin } void SelectionDescriber::_updateMessageFromSelection(Inkscape::Selection *selection) { - GSList const *items = selection->itemList(); + std::vector<SPItem*> const items = selection->itemList(); - if (!items) { // no items + if (items.empty()) { // no items _context.set(Inkscape::NORMAL_MESSAGE, _when_nothing); } else { - SPItem *item = dynamic_cast<SPItem *>(reinterpret_cast<SPObject *>(items->data)); + SPItem *item = items[0]; g_assert(item != NULL); SPObject *layer = selection->layers()->layerForObject(item); SPObject *root = selection->layers()->currentRoot(); @@ -188,7 +188,7 @@ void SelectionDescriber::_updateMessageFromSelection(Inkscape::Selection *select g_free (layer_name); g_free (parent_name); - if (!items->next) { // one item + if (items.size()==1) { // one item char *item_desc = item->detailedDescription(); bool isUse = dynamic_cast<SPUse *>(item) != NULL; @@ -228,9 +228,9 @@ void SelectionDescriber::_updateMessageFromSelection(Inkscape::Selection *select g_free(item_desc); } else { // multiple items - int objcount = g_slist_length((GSList *)items); - char *terms = collect_terms ((GSList *)items); - int n_terms = count_terms((GSList *)items); + int objcount = items.size(); + char *terms = collect_terms (items); + int n_terms = count_terms(items); gchar *objects_str = g_strdup_printf(ngettext( "<b>%1$i</b> objects selected of type %2$s", @@ -241,7 +241,7 @@ void SelectionDescriber::_updateMessageFromSelection(Inkscape::Selection *select // indicate all, some, or none filtered gchar *filt_str = NULL; - int n_filt = count_filtered((GSList *)items); //all filtered + int n_filt = count_filtered(items); //all filtered if (n_filt) { filt_str = g_strdup_printf(ngettext("; <i>%d filtered object</i> ", "; <i>%d filtered objects</i> ", n_filt), n_filt); diff --git a/src/selection.cpp b/src/selection.cpp index 81139d044..b2fb6447e 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -42,9 +42,11 @@ namespace Inkscape { Selection::Selection(LayerModel *layers, SPDesktop *desktop) : - _objs(NULL), - _reprs(NULL), - _items(NULL), + _objs(std::list<SPObject*>()), + _objs_vector(std::vector<SPObject*>()), + _objs_set(std::set<SPObject*>()), + _reprs(std::vector<XML::Node*>()), + _items(std::vector<SPItem*>()), _layers(layers), _desktop(desktop), _selection_context(NULL), @@ -121,17 +123,14 @@ Selection::_releaseContext(SPObject *obj) } void Selection::_invalidateCachedLists() { - g_slist_free(_items); - _items = NULL; - - g_slist_free(_reprs); - _reprs = NULL; + _items.clear(); + _reprs.clear(); } void Selection::_clear() { _invalidateCachedLists(); - while (_objs) { - SPObject *obj=reinterpret_cast<SPObject *>(_objs->data); + while (!_objs.empty()) { + SPObject *obj=_objs.front(); _remove(obj); } } @@ -148,7 +147,7 @@ bool Selection::includes(SPObject *obj) const { g_return_val_if_fail(SP_IS_OBJECT(obj), FALSE); - return ( g_slist_find(_objs, obj) != NULL ); + return ( _objs_set.find(obj)!=_objs_set.end() ); } void Selection::add(SPObject *obj, bool persist_selection_context/* = false */) { @@ -180,7 +179,8 @@ void Selection::_add(SPObject *obj) { _removeObjectDescendants(obj); _removeObjectAncestors(obj); - _objs = g_slist_prepend(_objs, obj); + _objs.push_front(obj); + _objs_set.insert(obj); add_3D_boxes_recursively(obj); @@ -234,26 +234,27 @@ void Selection::_remove(SPObject *obj) { remove_3D_boxes_recursively(obj); - _objs = g_slist_remove(_objs, obj); + _objs.remove(obj); + _objs_set.erase(obj); } -void Selection::setList(GSList const *list) { +void Selection::setList(std::vector<SPItem*> const &list) { // Clear and add, or just clear with emit. - if (list != NULL) { + if (!list.empty()) { _clear(); addList(list); } else clear(); } -void Selection::addList(GSList const *list) { +void Selection::addList(std::vector<SPItem*> const &list) { - if (list == NULL) + if (list.empty()) return; _invalidateCachedLists(); - for ( GSList const *iter = list ; iter != NULL ; iter = iter->next ) { - SPObject *obj = reinterpret_cast<SPObject *>(iter->data); + for ( std::vector<SPItem*>::const_iterator iter=list.begin();iter!=list.end();iter++ ) { + SPObject *obj = *iter; if (includes(obj)) continue; _add (obj); } @@ -261,11 +262,11 @@ void Selection::addList(GSList const *list) { _emitChanged(); } -void Selection::setReprList(GSList const *list) { +void Selection::setReprList(std::vector<XML::Node*> const &list) { _clear(); - for ( GSList const *iter = list ; iter != NULL ; iter = iter->next ) { - SPObject *obj=_objectForXMLNode(reinterpret_cast<Inkscape::XML::Node *>(iter->data)); + for ( std::vector<XML::Node*>::const_reverse_iterator iter=list.rbegin();iter!=list.rend();iter++ ) { + SPObject *obj=_objectForXMLNode(*iter); if (obj) { _add(obj); } @@ -279,35 +280,38 @@ void Selection::clear() { _emitChanged(); } -GSList const *Selection::list() { - return _objs; +std::vector<SPObject*> const &Selection::list() { + if(!_objs_vector.empty()) + return _objs_vector; + + for ( std::list<SPObject*>::const_iterator iter=_objs.begin();iter!=_objs.end();iter++ ) { + _objs_vector.push_back(*iter); + } + return _objs_vector; + } -GSList const *Selection::itemList() { - if (_items) { +std::vector<SPItem*> const &Selection::itemList() { + if (!_items.empty()) { return _items; } - for ( GSList const *iter=_objs ; iter != NULL ; iter = iter->next ) { - SPObject *obj=reinterpret_cast<SPObject *>(iter->data); + for ( std::list<SPObject*>::const_iterator iter=_objs.begin();iter!=_objs.end();iter++ ) { + SPObject *obj=*iter; if (SP_IS_ITEM(obj)) { - _items = g_slist_prepend(_items, SP_ITEM(obj)); + _items.push_back(SP_ITEM(obj)); } } - _items = g_slist_reverse(_items); - return _items; } -GSList const *Selection::reprList() { - if (_reprs) { return _reprs; } - - for ( GSList const *iter=itemList() ; iter != NULL ; iter = iter->next ) { - SPObject *obj=reinterpret_cast<SPObject *>(iter->data); - _reprs = g_slist_prepend(_reprs, obj->getRepr()); +std::vector<XML::Node*> const &Selection::reprList() { + if (!_reprs.empty()) { return _reprs; } + std::vector<SPItem*> list = itemList(); + for ( std::vector<SPItem*>::const_iterator iter=list.begin();iter!=list.end();iter++ ) { + SPObject *obj = *iter; + _reprs.push_back(obj->getRepr()); } - _reprs = g_slist_reverse(_reprs); - return _reprs; } @@ -337,17 +341,17 @@ std::list<SPBox3D *> const Selection::box3DList(Persp3D *persp) { } SPObject *Selection::single() { - if ( _objs != NULL && _objs->next == NULL ) { - return reinterpret_cast<SPObject *>(_objs->data); + if ( _objs.size() == 1 ) { + return _objs.front(); } else { return NULL; } } SPItem *Selection::singleItem() { - GSList const *items=itemList(); - if ( items != NULL && items->next == NULL ) { - return reinterpret_cast<SPItem *>(items->data); + std::vector<SPItem*> const items=itemList(); + if ( items.size()==1) { + return items[0]; } else { return NULL; } @@ -362,12 +366,12 @@ SPItem *Selection::largestItem(Selection::CompareSize compare) { } SPItem *Selection::_sizeistItem(bool sml, Selection::CompareSize compare) { - GSList const *items = const_cast<Selection *>(this)->itemList(); + std::vector<SPItem*> const items = const_cast<Selection *>(this)->itemList(); gdouble max = sml ? 1e18 : 0; SPItem *ist = NULL; - for ( GSList const *i = items; i != NULL ; i = i->next ) { - Geom::OptRect obox = SP_ITEM(i->data)->desktopPreferredBounds(); + for ( std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++ ) { + Geom::OptRect obox = SP_ITEM(*i)->desktopPreferredBounds(); if (!obox || obox.isEmpty()) continue; Geom::Rect bbox = *obox; @@ -376,7 +380,7 @@ SPItem *Selection::_sizeistItem(bool sml, Selection::CompareSize compare) { size = sml ? size : size * -1; if (size < max) { max = size; - ist = SP_ITEM(i->data); + ist = SP_ITEM(*i); } } return ist; @@ -395,22 +399,22 @@ Geom::OptRect Selection::bounds(SPItem::BBoxType type) const Geom::OptRect Selection::geometricBounds() const { - GSList const *items = const_cast<Selection *>(this)->itemList(); + std::vector<SPItem*> const items = const_cast<Selection *>(this)->itemList(); Geom::OptRect bbox; - for ( GSList const *i = items ; i != NULL ; i = i->next ) { - bbox.unionWith(SP_ITEM(i->data)->desktopGeometricBounds()); + for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + bbox.unionWith(SP_ITEM(*iter)->desktopGeometricBounds()); } return bbox; } Geom::OptRect Selection::visualBounds() const { - GSList const *items = const_cast<Selection *>(this)->itemList(); + std::vector<SPItem*> const items = const_cast<Selection *>(this)->itemList(); Geom::OptRect bbox; - for ( GSList const *i = items ; i != NULL ; i = i->next ) { - bbox.unionWith(SP_ITEM(i->data)->desktopVisualBounds()); + for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + bbox.unionWith(SP_ITEM(*iter)->desktopVisualBounds()); } return bbox; } @@ -427,11 +431,11 @@ Geom::OptRect Selection::preferredBounds() const Geom::OptRect Selection::documentBounds(SPItem::BBoxType type) const { Geom::OptRect bbox; - GSList const *items = const_cast<Selection *>(this)->itemList(); - if (!items) return bbox; + std::vector<SPItem*> const items = const_cast<Selection *>(this)->itemList(); + if (items.empty()) return bbox; - for ( GSList const *iter=items ; iter != NULL ; iter = iter->next ) { - SPItem *item = SP_ITEM(iter->data); + for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + SPItem *item = SP_ITEM(*iter); bbox |= item->documentBounds(type); } @@ -441,9 +445,9 @@ Geom::OptRect Selection::documentBounds(SPItem::BBoxType type) const // If we have a selection of multiple items, then the center of the first item // will be returned; this is also the case in SelTrans::centerRequest() boost::optional<Geom::Point> Selection::center() const { - GSList *items = (GSList *) const_cast<Selection *>(this)->itemList(); - if (items) { - SPItem *first = reinterpret_cast<SPItem*>(g_slist_last(items)->data); // from the first item in selection + std::vector<SPItem*> const items = const_cast<Selection *>(this)->itemList(); + if (!items.empty()) { + SPItem *first = items.back(); // from the first item in selection if (first->isCenterSet()) { // only if set explicitly return first->getCenter(); } @@ -457,13 +461,13 @@ boost::optional<Geom::Point> Selection::center() const { } std::vector<Inkscape::SnapCandidatePoint> Selection::getSnapPoints(SnapPreferences const *snapprefs) const { - GSList const *items = const_cast<Selection *>(this)->itemList(); + std::vector<SPItem*> const items = const_cast<Selection *>(this)->itemList(); SnapPreferences snapprefs_dummy = *snapprefs; // create a local copy of the snapping prefs snapprefs_dummy.setTargetSnappable(Inkscape::SNAPTARGET_ROTATION_CENTER, false); // locally disable snapping to the item center std::vector<Inkscape::SnapCandidatePoint> p; - for (GSList const *iter = items; iter != NULL; iter = iter->next) { - SPItem *this_item = SP_ITEM(iter->data); + for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + SPItem *this_item = *iter; this_item->getSnappoints(p, &snapprefs_dummy); //Include the transformation origin for snapping @@ -477,10 +481,8 @@ std::vector<Inkscape::SnapCandidatePoint> Selection::getSnapPoints(SnapPreferenc } void Selection::_removeObjectDescendants(SPObject *obj) { - GSList *iter, *next; - for ( iter = _objs ; iter ; iter = next ) { - next = iter->next; - SPObject *sel_obj=reinterpret_cast<SPObject *>(iter->data); + for ( std::list<SPObject*>::const_iterator iter=_objs.begin();iter!=_objs.end();iter++ ) { + SPObject *sel_obj= *iter; SPObject *parent = sel_obj->parent; while (parent) { if ( parent == obj ) { @@ -511,32 +513,24 @@ SPObject *Selection::_objectForXMLNode(Inkscape::XML::Node *repr) const { return object; } -guint Selection::numberOfLayers() { - GSList const *items = const_cast<Selection *>(this)->itemList(); - GSList *layers = NULL; - for (GSList const *iter = items; iter != NULL; iter = iter->next) { - SPObject *layer = _layers->layerForObject(SP_OBJECT(iter->data)); - if (g_slist_find (layers, layer) == NULL) { - layers = g_slist_prepend (layers, layer); - } +uint Selection::numberOfLayers() { + std::vector<SPItem*> const items = const_cast<Selection *>(this)->itemList(); + std::set<SPObject*> layers; + for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + SPObject *layer = _layers->layerForObject(*iter); + layers.insert(layer); } - guint ret = g_slist_length (layers); - g_slist_free (layers); - return ret; + return layers.size(); } guint Selection::numberOfParents() { - GSList const *items = const_cast<Selection *>(this)->itemList(); - GSList *parents = NULL; - for (GSList const *iter = items; iter != NULL; iter = iter->next) { - SPObject *parent = SP_OBJECT(iter->data)->parent; - if (g_slist_find (parents, parent) == NULL) { - parents = g_slist_prepend (parents, parent); - } + std::vector<SPItem*> const items = const_cast<Selection *>(this)->itemList(); + std::set<SPObject*> parents; + for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + SPObject *parent = (*iter)->parent; + parents.insert(parent); } - guint ret = g_slist_length (parents); - g_slist_free (parents); - return ret; + return parents.size(); } } diff --git a/src/selection.h b/src/selection.h index 19e2ae1fd..7ac0f40f3 100644 --- a/src/selection.h +++ b/src/selection.h @@ -16,6 +16,7 @@ #include <vector> #include <map> #include <list> +#include <set> #include <stddef.h> #include <sigc++/sigc++.h> @@ -26,11 +27,11 @@ #include "sp-item.h" + class SPDesktop; class SPItem; class SPBox3D; class Persp3D; -typedef struct _GSList GSList; namespace Inkscape { class LayerModel; @@ -39,6 +40,7 @@ class Node; } } + namespace Inkscape { /** @@ -154,21 +156,21 @@ public: * * @param objs the objects to select */ - void setList(GSList const *objs); + void setList(std::vector<SPItem*> const &objs); /** * Adds the specified objects to selection, without deselecting first. * * @param objs the objects to select */ - void addList(GSList const *objs); + void addList(std::vector<SPItem*> const &objs); /** * Clears the selection and selects the specified objects. * * @param repr a list of xml nodes for the items to select */ - void setReprList(GSList const *reprs); + void setReprList(std::vector<XML::Node*> const &reprs); /** Add items from an STL iterator range to the selection. * \param from the begin iterator @@ -192,7 +194,7 @@ public: /** * Returns true if no items are selected. */ - bool isEmpty() const { return _objs == NULL; } + bool isEmpty() const { return _objs.empty(); } /** * Returns true if the given object is selected. @@ -238,13 +240,13 @@ public: XML::Node *singleRepr(); /** Returns the list of selected objects. */ - GSList const *list(); + std::vector<SPObject*> const &list(); /** Returns the list of selected SPItems. */ - GSList const *itemList(); + std::vector<SPItem*> const &itemList(); /** Returns a list of the xml nodes of all selected objects. */ /// \todo only returns reprs of SPItems currently; need a separate /// method for that - GSList const *reprList(); + std::vector<XML::Node*> const &reprList(); /** Returns a list of all perspectives which have a 3D box in the current selection. (these may also be nested in groups) */ @@ -360,9 +362,11 @@ private: /** Releases an active layer object that is being removed. */ void _releaseContext(SPObject *obj); - mutable GSList *_objs; - mutable GSList *_reprs; - mutable GSList *_items; + mutable std::list<SPObject*> _objs; //to more efficiently remove arbitrary elements + mutable std::vector<SPObject*> _objs_vector; // to be returned by list(); + mutable std::set<SPObject*> _objs_set; //to efficiently test if object is selected + mutable std::vector<XML::Node*> _reprs; + mutable std::vector<SPItem*> _items; void add_box_perspective(SPBox3D *box); void add_3D_boxes_recursively(SPObject *obj); diff --git a/src/seltrans.cpp b/src/seltrans.cpp index 5e4c0642e..bfb8d53f1 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -112,7 +112,7 @@ Inkscape::SelTrans::SelTrans(SPDesktop *desktop) : _opposite_for_bboxpoints(Geom::Point(0,0)), _origin_for_specpoints(Geom::Point(0,0)), _origin_for_bboxpoints(Geom::Point(0,0)), - _stamp_cache(NULL), + _stamp_cache(std::vector<SPItem*>()), _message_context(desktop->messageStack()), _bounding_box_prefs_observer(*this) { @@ -239,8 +239,9 @@ void Inkscape::SelTrans::setCenter(Geom::Point const &p) _center_is_set = true; // Write the new center position into all selected items - for (GSList const *l = _desktop->selection->itemList(); l; l = l->next) { - SPItem *it = SP_ITEM(l->data); + std::vector<SPItem*> items=_desktop->selection->itemList(); + for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + SPItem *it = SP_ITEM(*iter); it->setCenter(p); // only set the value; updating repr and document_done will be done once, on ungrab } @@ -268,8 +269,9 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s return; } - for (GSList const *l = selection->itemList(); l; l = l->next) { - SPItem *it = reinterpret_cast<SPItem*>(sp_object_ref(SP_ITEM(l->data), NULL)); + std::vector<SPItem*> items=_desktop->selection->itemList(); + for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + SPItem *it = static_cast<SPItem*>(sp_object_ref(*iter, NULL)); _items.push_back(it); _items_const.push_back(it); _items_affines.push_back(it->i2dt_affine()); @@ -370,7 +372,7 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s } _updateHandles(); - g_return_if_fail(_stamp_cache == NULL); + g_return_if_fail(_stamp_cache.empty()); } void Inkscape::SelTrans::transform(Geom::Affine const &rel_affine, Geom::Point const &norm) @@ -432,10 +434,8 @@ void Inkscape::SelTrans::ungrab() for (int i = 0; i < 4; i++) sp_canvas_item_hide(_l[i]); } - - if (_stamp_cache) { - g_slist_free(_stamp_cache); - _stamp_cache = NULL; + if(!_stamp_cache.empty()){ + _stamp_cache.clear(); } _message_context.clear(); @@ -491,8 +491,9 @@ void Inkscape::SelTrans::ungrab() if (_center_is_set) { // we were dragging center; update reprs and commit undoable action - for (GSList const *l = _desktop->selection->itemList(); l; l = l->next) { - SPItem *it = SP_ITEM(l->data); + std::vector<SPItem*> items=_desktop->selection->itemList(); + for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + SPItem *it = *iter; it->updateRepr(); } DocumentUndo::done(_desktop->getDocument(), SP_VERB_CONTEXT_SELECT, @@ -515,26 +516,25 @@ void Inkscape::SelTrans::stamp() Inkscape::Selection *selection = _desktop->getSelection(); bool fixup = !_grabbed; - if ( fixup && _stamp_cache ) { + if ( fixup && !_stamp_cache.empty() ) { // TODO - give a proper fix. Simple temporary work-around for the grab() issue - g_slist_free(_stamp_cache); - _stamp_cache = NULL; + _stamp_cache.clear(); } /* stamping mode */ if (!_empty) { - GSList *l; - if (_stamp_cache) { + std::vector<SPItem*> l; + if (!_stamp_cache.empty()) { l = _stamp_cache; } else { /* Build cache */ - l = g_slist_copy((GSList *) selection->itemList()); - l = g_slist_sort(l, (GCompareFunc) sp_object_compare_position); + l = selection->itemList(); + sort(l.begin(),l.end(),sp_object_compare_position); _stamp_cache = l; } - while (l) { - SPItem *original_item = SP_ITEM(l->data); + for(std::vector<SPItem*>::const_iterator x=l.begin();x!=l.end();x++) { + SPItem *original_item = *x; Inkscape::XML::Node *original_repr = original_item->getRepr(); // remember the position of the item @@ -568,16 +568,14 @@ void Inkscape::SelTrans::stamp() } Inkscape::GC::release(copy_repr); - l = l->next; } DocumentUndo::done(_desktop->getDocument(), SP_VERB_CONTEXT_SELECT, _("Stamp")); } - if ( fixup && _stamp_cache ) { + if ( fixup && !_stamp_cache.empty() ) { // TODO - give a proper fix. Simple temporary work-around for the grab() issue - g_slist_free(_stamp_cache); - _stamp_cache = NULL; + _stamp_cache.clear(); } } @@ -712,8 +710,9 @@ void Inkscape::SelTrans::handleClick(SPKnot */*knot*/, guint state, SPSelTransHa case HANDLE_CENTER: if (state & GDK_SHIFT_MASK) { // Unset the center position for all selected items - for (GSList const *l = _desktop->selection->itemList(); l; l = l->next) { - SPItem *it = SP_ITEM(l->data); + std::vector<SPItem*> items=_desktop->selection->itemList(); + for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + SPItem *it = *iter; it->unsetCenter(); it->updateRepr(); _center_is_set = false; // center has changed @@ -1283,7 +1282,7 @@ gboolean Inkscape::SelTrans::centerRequest(Geom::Point &pt, guint state) // items will share a single center. While dragging that single center, it should never snap to the // centers of any of the selected objects. Therefore we will have to pass the list of selected items // to the snapper, to avoid self-snapping of the rotation center - GSList *items = (GSList *) const_cast<Selection *>(_selection)->itemList(); + std::vector<SPItem*> items = const_cast<Selection *>(_selection)->itemList(); SnapManager &m = _desktop->namedview->snap_manager; m.setup(_desktop); m.setRotationCenterSource(items); diff --git a/src/seltrans.h b/src/seltrans.h index d5db1542d..26c2e9cd9 100644 --- a/src/seltrans.h +++ b/src/seltrans.h @@ -187,7 +187,7 @@ private: SPCtrlLine *_l[4]; unsigned int _sel_changed_id; unsigned int _sel_modified_id; - GSList *_stamp_cache; + std::vector<SPItem*> _stamp_cache; Geom::Point _origin; ///< position of origin for transforms Geom::Point _point; ///< original position of the knot being used for the current transform diff --git a/src/snap.cpp b/src/snap.cpp index 96b5ab53c..30441ca0b 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -43,7 +43,7 @@ SnapManager::SnapManager(SPNamedView const *v) : object(this, 0), snapprefs(), _named_view(v), - _rotation_center_source_items(NULL), + _rotation_center_source_items(std::vector<SPItem*>()), _guide_to_ignore(NULL), _desktop(NULL), _snapindicator(true), @@ -1013,7 +1013,7 @@ void SnapManager::setup(SPDesktop const *desktop, _snapindicator = snapindicator; _unselected_nodes = unselected_nodes; _guide_to_ignore = guide_to_ignore; - _rotation_center_source_items = NULL; + _rotation_center_source_items.clear(); } void SnapManager::setup(SPDesktop const *desktop, @@ -1031,7 +1031,7 @@ void SnapManager::setup(SPDesktop const *desktop, _snapindicator = snapindicator; _unselected_nodes = unselected_nodes; _guide_to_ignore = guide_to_ignore; - _rotation_center_source_items = NULL; + _rotation_center_source_items.clear(); } /// Setup, taking the list of items to ignore from the desktop's selection. @@ -1049,13 +1049,13 @@ void SnapManager::setupIgnoreSelection(SPDesktop const *desktop, _snapindicator = snapindicator; _unselected_nodes = unselected_nodes; _guide_to_ignore = guide_to_ignore; - _rotation_center_source_items = NULL; + _rotation_center_source_items.clear(); _items_to_ignore.clear(); Inkscape::Selection *sel = _desktop->selection; - GSList const *items = sel->itemList(); - for (GSList *i = const_cast<GSList*>(items); i; i = i->next) { - _items_to_ignore.push_back(static_cast<SPItem const *>(i->data)); + std::vector<SPItem*> const items = sel->itemList(); + for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++) { + _items_to_ignore.push_back(*i); } } diff --git a/src/snap.h b/src/snap.h index 20b2b246f..49bdbfa7c 100644 --- a/src/snap.h +++ b/src/snap.h @@ -136,7 +136,7 @@ public: std::vector<Inkscape::SnapCandidatePoint> *unselected_nodes = NULL, SPGuide *guide_to_ignore = NULL); - void unSetup() {_rotation_center_source_items = NULL; + void unSetup() {_rotation_center_source_items.clear(); _guide_to_ignore = NULL; _desktop = NULL; _unselected_nodes = NULL;} @@ -145,8 +145,8 @@ public: // of this rotation center; this reference is used to make sure that we do not snap a rotation // center to itself // NOTE: Must be called after calling setup(), not before! - void setRotationCenterSource(GSList *items) {_rotation_center_source_items = items;} - GSList const *getRotationCenterSource() {return _rotation_center_source_items;} + void setRotationCenterSource(const std::vector<SPItem*> &items) {_rotation_center_source_items = items;} + const std::vector<SPItem*> &getRotationCenterSource() {return _rotation_center_source_items;} // freeSnapReturnByRef() is preferred over freeSnap(), because it only returns a // point if snapping has occurred (by overwriting p); otherwise p is untouched @@ -490,7 +490,7 @@ protected: private: std::vector<SPItem const *> _items_to_ignore; ///< Items that should not be snapped to, for example the items that are currently being dragged. Set using the setup() method - GSList *_rotation_center_source_items; // to avoid snapping a rotation center to itself + std::vector<SPItem*> _rotation_center_source_items; // to avoid snapping a rotation center to itself SPGuide *_guide_to_ignore; ///< A guide that should not be snapped to, e.g. the guide that is currently being dragged SPDesktop const *_desktop; bool _snapindicator; ///< When true, an indicator will be drawn at the position that was being snapped to diff --git a/src/sp-conn-end.cpp b/src/sp-conn-end.cpp index 3e5398ced..1e478d1c9 100644 --- a/src/sp-conn-end.cpp +++ b/src/sp-conn-end.cpp @@ -50,8 +50,9 @@ static bool try_get_intersect_point_with_item_recursive(Geom::PathVector& conn_p // consider all first-order children double child_pos = 0.0; - for (GSList const* i = sp_item_group_item_list(group); i != NULL; i = i->next) { - SPItem* child_item = SP_ITEM(i->data); + std::vector<SPItem*> g = sp_item_group_item_list(group); + for (std::vector<SPItem*>::const_iterator i = g.begin();i!=g.end();i++) { + SPItem* child_item = *i; try_get_intersect_point_with_item_recursive(conn_pv, child_item, item_transform * child_item->transform, child_pos); if (intersect_pos < child_pos) diff --git a/src/sp-defs.cpp b/src/sp-defs.cpp index 8dd695867..2e341d3c6 100644 --- a/src/sp-defs.cpp +++ b/src/sp-defs.cpp @@ -36,11 +36,9 @@ void SPDefs::update(SPCtx *ctx, guint flags) { } flags &= SP_OBJECT_MODIFIED_CASCADE; - - GSList *l = g_slist_reverse(this->childList(true)); - while (l) { - SPObject *child = SP_OBJECT(l->data); - l = g_slist_remove(l, child); + std::vector<SPObject*> l(this->childList(true)); + for(std::vector<SPObject*>::const_iterator i=l.begin();i!=l.end();i++){ + SPObject *child = *i; if (flags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { child->updateDisplay(ctx, flags); } diff --git a/src/sp-filter.cpp b/src/sp-filter.cpp index a70fbd5bb..2bf1b11a6 100644 --- a/src/sp-filter.cpp +++ b/src/sp-filter.cpp @@ -235,11 +235,9 @@ void SPFilter::update(SPCtx *ctx, guint flags) { childflags |= SP_OBJECT_PARENT_MODIFIED_FLAG; } childflags &= SP_OBJECT_MODIFIED_CASCADE; - - GSList *l = g_slist_reverse(this->childList(true, SPObject::ActionUpdate)); - while (l) { - SPObject *child = SP_OBJECT (l->data); - l = g_slist_remove (l, child); + std::vector<SPObject*> l(this->childList(true, SPObject::ActionUpdate)); + for(std::vector<SPObject*>::const_iterator i=l.begin();i!=l.end();i++){ + SPObject *child = *i; if( SP_IS_FILTER_PRIMITIVE( child ) ) { child->updateDisplay(ctx, childflags); } diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp index 55857dacf..9bd42665d 100644 --- a/src/sp-item-group.cpp +++ b/src/sp-item-group.cpp @@ -161,11 +161,9 @@ void SPGroup::update(SPCtx *ctx, unsigned int flags) { childflags |= SP_OBJECT_PARENT_MODIFIED_FLAG; } childflags &= SP_OBJECT_MODIFIED_CASCADE; - - GSList *l = g_slist_reverse(this->childList(true, SPObject::ActionUpdate)); - while (l) { - SPObject *child = SP_OBJECT (l->data); - l = g_slist_remove (l, child); + std::vector<SPObject*> l=this->childList(true, SPObject::ActionUpdate); + for(std::vector<SPObject*> ::const_iterator i=l.begin();i!=l.end();i++){ + SPObject *child = *i; if (childflags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { SPItem *item = dynamic_cast<SPItem *>(child); @@ -201,20 +199,15 @@ void SPGroup::update(SPCtx *ctx, unsigned int flags) { void SPGroup::modified(guint flags) { // std::cout << "SPGroup::modified(): " << (getId()?getId():"null") << std::endl; SPLPEItem::modified(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(this->childList(true)); - - while (l) { - child = SP_OBJECT (l->data); - l = g_slist_remove (l, child); + std::vector<SPObject*> l=this->childList(true); + for(std::vector<SPObject*>::const_iterator i=l.begin();i!=l.end();i++){ + SPObject *child = *i; if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { child->emitModified(flags); @@ -286,35 +279,27 @@ Geom::OptRect SPGroup::bbox(Geom::Affine const &transform, SPItem::BBoxType bbox Geom::OptRect bbox; // TODO CPPIFY: replace this const_cast later - GSList *l = const_cast<SPGroup*>(this)->childList(false, SPObject::ActionBBox); - - while (l) { - SPObject *o = SP_OBJECT (l->data); - + std::vector<SPObject*> l = const_cast<SPGroup*>(this)->childList(false, SPObject::ActionBBox); + for(std::vector<SPObject*>::const_iterator i=l.begin();i!=l.end();i++){ + SPObject *o = *i; SPItem *item = dynamic_cast<SPItem *>(o); if (item && !item->isHidden()) { Geom::Affine const ct(item->transform * transform); bbox |= item->bounds(bboxtype, ct); } - - l = g_slist_remove (l, o); } return bbox; } void SPGroup::print(SPPrintContext *ctx) { - GSList *l = g_slist_reverse(this->childList(false)); - - while (l) { - SPObject *o = SP_OBJECT (l->data); - + std::vector<SPObject*> l=this->childList(false); + for(std::vector<SPObject*>::const_iterator i=l.begin();i!=l.end();i++){ + SPObject *o = *i; SPItem *item = dynamic_cast<SPItem *>(o); if (item) { item->invoke_print(ctx); } - - l = g_slist_remove (l, o); } } @@ -362,17 +347,14 @@ Inkscape::DrawingItem *SPGroup::show (Inkscape::Drawing &drawing, unsigned int k } void SPGroup::hide (unsigned int key) { - GSList *l = g_slist_reverse(this->childList(false, SPObject::ActionShow)); - - while (l) { - SPObject *o = SP_OBJECT (l->data); + std::vector<SPObject*> l=this->childList(false, SPObject::ActionShow); + for(std::vector<SPObject*>::const_iterator i=l.begin();i!=l.end();i++){ + SPObject *o = *i; SPItem *item = dynamic_cast<SPItem *>(o); if (item) { item->invoke_hide(key); } - - l = g_slist_remove (l, o); } // SPLPEItem::onHide(key); @@ -407,7 +389,7 @@ void sp_item_group_ungroup_handle_clones(SPItem *parent, Geom::Affine const g) } void -sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done) +sp_item_group_ungroup (SPGroup *group, std::vector<SPItem*> &children, bool do_done) { g_return_if_fail (group != NULL); @@ -564,8 +546,8 @@ sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done) } Inkscape::GC::release(repr); - if (children && item) { - *children = g_slist_prepend(*children, item); + if (!children.empty() && item) { + children.insert(children.begin(),item); } items = g_slist_remove (items, items->data); @@ -580,19 +562,17 @@ sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done) * some API for list aspect of SPGroup */ -GSList *sp_item_group_item_list(SPGroup * group) +std::vector<SPItem*> sp_item_group_item_list(SPGroup * group) { - g_return_val_if_fail(group != NULL, NULL); - - GSList *s = NULL; + std::vector<SPItem*> s; + g_return_val_if_fail(group != NULL, s); for (SPObject *o = group->firstChild() ; o ; o = o->getNext() ) { if ( dynamic_cast<SPItem *>(o) ) { - s = g_slist_prepend(s, o); + s.push_back((SPItem*)o); } } - - return g_slist_reverse (s); + return s; } SPObject *sp_item_group_get_child_by_name(SPGroup *group, SPObject *ref, const gchar *name) @@ -807,9 +787,9 @@ gint SPGroup::getItemCount() const { void SPGroup::_showChildren (Inkscape::Drawing &drawing, Inkscape::DrawingItem *ai, unsigned int key, unsigned int flags) { Inkscape::DrawingItem *ac = NULL; - GSList *l = g_slist_reverse(this->childList(false, SPObject::ActionShow)); - while (l) { - SPObject *o = SP_OBJECT (l->data); + std::vector<SPObject*> l=this->childList(false, SPObject::ActionShow); + for(std::vector<SPObject*>::const_iterator i=l.begin();i!=l.end();i++){ + SPObject *o = *i; SPItem * child = dynamic_cast<SPItem *>(o); if (child) { ac = child->invoke_show (drawing, key, flags); @@ -817,7 +797,6 @@ void SPGroup::_showChildren (Inkscape::Drawing &drawing, Inkscape::DrawingItem * ai->appendChild(ac); } } - l = g_slist_remove (l, o); } } @@ -826,10 +805,10 @@ void SPGroup::update_patheffect(bool write) { g_message("sp_group_update_patheffect: %p\n", lpeitem); #endif - GSList const *item_list = sp_item_group_item_list(this); + std::vector<SPItem*> const item_list = sp_item_group_item_list(this); - for ( GSList const *iter = item_list; iter; iter = iter->next ) { - SPObject *subitem = static_cast<SPObject *>(iter->data); + for ( std::vector<SPItem*>::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { + SPObject *subitem = *iter; SPLPEItem *lpeItem = dynamic_cast<SPLPEItem *>(subitem); if (lpeItem) { @@ -854,10 +833,10 @@ void SPGroup::update_patheffect(bool write) { static void sp_group_perform_patheffect(SPGroup *group, SPGroup *topgroup, bool write) { - GSList const *item_list = sp_item_group_item_list(group); + std::vector<SPItem*> const item_list = sp_item_group_item_list(group); - for ( GSList const *iter = item_list; iter; iter = iter->next ) { - SPObject *subitem = static_cast<SPObject *>(iter->data); + for ( std::vector<SPItem*>::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { + SPObject *subitem = *iter; SPGroup *subGroup = dynamic_cast<SPGroup *>(subitem); if (subGroup) { diff --git a/src/sp-item-group.h b/src/sp-item-group.h index f9a8b88f5..fc0b6382f 100644 --- a/src/sp-item-group.h +++ b/src/sp-item-group.h @@ -95,6 +95,7 @@ public: virtual void update_patheffect(bool write); }; + /** * finds clones of a child of the group going out of the group; and inverse the group transform on its clones * Also called when moving objects between different layers @@ -104,10 +105,11 @@ public: */ void sp_item_group_ungroup_handle_clones(SPItem *parent, Geom::Affine const g); -void sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done = true); +void sp_item_group_ungroup (SPGroup *group, std::vector<SPItem*> &children, bool do_done = true); + +std::vector<SPItem*> sp_item_group_item_list (SPGroup *group); -GSList *sp_item_group_item_list (SPGroup *group); SPObject *sp_item_group_get_child_by_name (SPGroup *group, SPObject *ref, const char *name); #endif diff --git a/src/sp-lpe-item.cpp b/src/sp-lpe-item.cpp index 12d85b3ed..9befd2a2b 100644 --- a/src/sp-lpe-item.cpp +++ b/src/sp-lpe-item.cpp @@ -353,9 +353,9 @@ sp_lpe_item_create_original_path_recursive(SPLPEItem *lpeitem) sp_lpe_item_create_original_path_recursive(SP_LPE_ITEM(clipPath->firstChild())); } if (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); + std::vector<SPItem*> item_list = sp_item_group_item_list(SP_GROUP(lpeitem)); + for ( std::vector<SPItem*>::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { + SPObject *subitem = *iter; if (SP_IS_LPE_ITEM(subitem)) { sp_lpe_item_create_original_path_recursive(SP_LPE_ITEM(subitem)); } @@ -387,9 +387,9 @@ sp_lpe_item_cleanup_original_path_recursive(SPLPEItem *lpeitem) sp_lpe_item_cleanup_original_path_recursive(SP_LPE_ITEM(clipPath->firstChild())); } } - 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); + std::vector<SPItem*> item_list = sp_item_group_item_list(SP_GROUP(lpeitem)); + for ( std::vector<SPItem*>::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { + SPObject *subitem = *iter; if (SP_IS_LPE_ITEM(subitem)) { sp_lpe_item_cleanup_original_path_recursive(SP_LPE_ITEM(subitem)); } @@ -680,9 +680,9 @@ SPLPEItem::apply_to_clippath(SPItem *item) } } if(SP_IS_GROUP(item)){ - GSList const *item_list = sp_item_group_item_list(SP_GROUP(item)); - for ( GSList const *iter = item_list; iter; iter = iter->next ) { - SPObject *subitem = static_cast<SPObject *>(iter->data); + std::vector<SPItem*> item_list = sp_item_group_item_list(SP_GROUP(item)); + for ( std::vector<SPItem*>::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { + SPObject *subitem = *iter; apply_to_clippath(SP_ITEM(subitem)); } } @@ -732,9 +732,9 @@ SPLPEItem::apply_to_mask(SPItem *item) } } if(SP_IS_GROUP(item)){ - GSList const *item_list = sp_item_group_item_list(SP_GROUP(item)); - for ( GSList const *iter = item_list; iter; iter = iter->next ) { - SPObject *subitem = static_cast<SPObject *>(iter->data); + std::vector<SPItem*> item_list = sp_item_group_item_list(SP_GROUP(item)); + for ( std::vector<SPItem*>::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { + SPObject *subitem = *iter; apply_to_mask(SP_ITEM(subitem)); } } @@ -746,9 +746,9 @@ SPLPEItem::apply_to_clip_or_mask_group(SPItem *group, SPItem *item) if (!SP_IS_GROUP(group)) { return; } - GSList *item_list = sp_item_group_item_list(SP_GROUP(group)); - for ( GSList *iter = item_list; iter; iter = iter->next ) { - SPObject *subitem = static_cast<SPObject *>(iter->data); + std::vector<SPItem*> item_list = sp_item_group_item_list(SP_GROUP(group)); + for ( std::vector<SPItem*>::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { + SPObject *subitem = *iter; if (SP_IS_GROUP(subitem)) { apply_to_clip_or_mask_group(SP_ITEM(subitem), item); } else if (SP_IS_SHAPE(subitem)) { diff --git a/src/sp-marker.cpp b/src/sp-marker.cpp index d3cf50fa7..9334614dc 100644 --- a/src/sp-marker.cpp +++ b/src/sp-marker.cpp @@ -419,7 +419,7 @@ sp_marker_hide (SPMarker *marker, unsigned int key) } -const gchar *generate_marker(GSList *reprs, Geom::Rect bounds, SPDocument *document, Geom::Point center, Geom::Affine move) +const gchar *generate_marker(std::vector<Inkscape::XML::Node*> &reprs, Geom::Rect bounds, SPDocument *document, Geom::Point center, Geom::Affine move) { Inkscape::XML::Document *xml_doc = document->getReprDoc(); Inkscape::XML::Node *defsrepr = document->getDefs()->getRepr(); @@ -442,8 +442,8 @@ const gchar *generate_marker(GSList *reprs, Geom::Rect bounds, SPDocument *docum const gchar *mark_id = repr->attribute("id"); SPObject *mark_object = document->getObjectById(mark_id); - for (GSList *i = reprs; i != NULL; i = i->next) { - Inkscape::XML::Node *node = (Inkscape::XML::Node *)(i->data); + for (std::vector<Inkscape::XML::Node*>::const_iterator i=reprs.begin();i!=reprs.end();i++){ + Inkscape::XML::Node *node = *i; SPItem *copy = SP_ITEM(mark_object->appendChildRepr(node)); Geom::Affine dup_transform; diff --git a/src/sp-marker.h b/src/sp-marker.h index e804fd7dc..56cbaf94f 100644 --- a/src/sp-marker.h +++ b/src/sp-marker.h @@ -101,7 +101,7 @@ Inkscape::DrawingItem *sp_marker_show_instance (SPMarker *marker, Inkscape::Draw unsigned int key, unsigned int pos, Geom::Affine const &base, float linewidth); void sp_marker_hide (SPMarker *marker, unsigned int key); -const char *generate_marker (GSList *reprs, Geom::Rect bounds, SPDocument *document, Geom::Point center, Geom::Affine move); +const char *generate_marker (std::vector<Inkscape::XML::Node*> &reprs, Geom::Rect bounds, SPDocument *document, Geom::Point center, Geom::Affine move); SPObject *sp_marker_fork_if_necessary(SPObject *marker); #endif diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 343db435e..d4b8a15c0 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -380,14 +380,14 @@ void SPObject::changeCSS(SPCSSAttr *css, gchar const *attr) sp_repr_css_change(this->getRepr(), css, attr); } -GSList *SPObject::childList(bool add_ref, Action) { - GSList *l = NULL; +std::vector<SPObject*> SPObject::childList(bool add_ref, Action) { + std::vector<SPObject*> l; for ( SPObject *child = firstChild() ; child; child = child->getNext() ) { if (add_ref) { sp_object_ref (child); } - l = g_slist_prepend (l, child); + l.push_back(child); } return l; diff --git a/src/sp-object.h b/src/sp-object.h index ab0b444b6..f5d47be05 100644 --- a/src/sp-object.h +++ b/src/sp-object.h @@ -52,6 +52,7 @@ class SPObject; #include <sigc++/connection.h> #include <sigc++/functors/slot.h> #include <sigc++/signal.h> +#include <vector> #include "version.h" #include "util/forward-pointer-iterator.h" @@ -328,10 +329,10 @@ public: enum Action { ActionGeneral, ActionBBox, ActionUpdate, ActionShow }; /** - * Retrieves the children as a GSList object, optionally ref'ing the children + * Retrieves the children as a std vector object, optionally ref'ing the children * in the process, if add_ref is specified. */ - GSList *childList(bool add_ref, Action action = ActionGeneral); + std::vector<SPObject*> childList(bool add_ref, Action action = ActionGeneral); /** * Append repr as child of this object. diff --git a/src/sp-pattern.cpp b/src/sp-pattern.cpp index 987a86fe4..e89ed77ba 100644 --- a/src/sp-pattern.cpp +++ b/src/sp-pattern.cpp @@ -398,7 +398,7 @@ sp_pattern_transform_multiply (SPPattern *pattern, Geom::Affine postmul, bool se g_free(c); } -const gchar *pattern_tile(GSList *reprs, Geom::Rect bounds, SPDocument *document, Geom::Affine transform, Geom::Affine move) +const gchar *pattern_tile(const std::vector<Inkscape::XML::Node*> &reprs, Geom::Rect bounds, SPDocument *document, Geom::Affine transform, Geom::Affine move) { Inkscape::XML::Document *xml_doc = document->getReprDoc(); Inkscape::XML::Node *defsrepr = document->getDefs()->getRepr(); @@ -416,8 +416,8 @@ const gchar *pattern_tile(GSList *reprs, Geom::Rect bounds, SPDocument *document const gchar *pat_id = repr->attribute("id"); SPObject *pat_object = document->getObjectById(pat_id); - for (GSList *i = reprs; i != NULL; i = i->next) { - Inkscape::XML::Node *node = (Inkscape::XML::Node *)(i->data); + for (std::vector<Inkscape::XML::Node*>::const_iterator i=reprs.begin();i!=reprs.end();i++){ + Inkscape::XML::Node *node = *i; SPItem *copy = SP_ITEM(pat_object->appendChildRepr(node)); Geom::Affine dup_transform; diff --git a/src/sp-pattern.h b/src/sp-pattern.h index f021101e2..34dd5a05b 100644 --- a/src/sp-pattern.h +++ b/src/sp-pattern.h @@ -89,7 +89,7 @@ SPPattern *pattern_chain (SPPattern *pattern); SPPattern *sp_pattern_clone_if_necessary (SPItem *item, SPPattern *pattern, const char *property); void sp_pattern_transform_multiply (SPPattern *pattern, Geom::Affine postmul, bool set); -const char *pattern_tile (GSList *reprs, Geom::Rect bounds, SPDocument *document, Geom::Affine transform, Geom::Affine move); +const char *pattern_tile (const std::vector<Inkscape::XML::Node*> &reprs, Geom::Rect bounds, SPDocument *document, Geom::Affine transform, Geom::Affine move); SPPattern *pattern_getroot (SPPattern *pat); diff --git a/src/sp-switch.cpp b/src/sp-switch.cpp index 66cec3637..cfc0e7d8b 100644 --- a/src/sp-switch.cpp +++ b/src/sp-switch.cpp @@ -41,21 +41,22 @@ SPObject *SPSwitch::_evaluateFirst() { return first; } -GSList *SPSwitch::_childList(bool add_ref, SPObject::Action action) { +std::vector<SPObject*> SPSwitch::_childList(bool add_ref, SPObject::Action action) { if ( action != SPObject::ActionGeneral ) { return this->childList(add_ref, action); } SPObject *child = _evaluateFirst(); + std::vector<SPObject*> x; if (NULL == child) - return NULL; + return x; if (add_ref) { //g_object_ref (G_OBJECT (child)); sp_object_ref(child); } - - return g_slist_prepend (NULL, child); + x.push_back(child); + return x; } const char *SPSwitch::displayName() const { @@ -95,10 +96,9 @@ void SPSwitch::_reevaluate(bool /*add_to_drawing*/) { _releaseLastItem(_cached_item); - for ( GSList *l = _childList(false, SPObject::ActionShow); - NULL != l ; l = g_slist_remove (l, l->data)) - { - SPObject *o = SP_OBJECT (l->data); + std::vector<SPObject*> item_list = _childList(false, SPObject::ActionShow); + for ( std::vector<SPObject*>::const_reverse_iterator iter=item_list.rbegin();iter!=item_list.rend();iter++) { + SPObject *o = *iter; if ( !SP_IS_ITEM (o) ) { continue; } @@ -130,10 +130,10 @@ void SPSwitch::_releaseLastItem(SPObject *obj) void SPSwitch::_showChildren (Inkscape::Drawing &drawing, Inkscape::DrawingItem *ai, unsigned int key, unsigned int flags) { SPObject *evaluated_child = this->_evaluateFirst(); - GSList *l = this->_childList(false, SPObject::ActionShow); + std::vector<SPObject*> l = this->_childList(false, SPObject::ActionShow); - while (l) { - SPObject *o = SP_OBJECT (l->data); + for ( std::vector<SPObject*>::const_reverse_iterator iter=l.rbegin();iter!=l.rend();iter++) { + SPObject *o = *iter; if (SP_IS_ITEM (o)) { SPItem * child = SP_ITEM(o); @@ -144,8 +144,6 @@ void SPSwitch::_showChildren (Inkscape::Drawing &drawing, Inkscape::DrawingItem ai->appendChild(ac); } } - - l = g_slist_remove (l, o); } } diff --git a/src/sp-switch.h b/src/sp-switch.h index 4fce1f5a6..7152e1b82 100644 --- a/src/sp-switch.h +++ b/src/sp-switch.h @@ -29,7 +29,7 @@ public: void resetChildEvaluated() { _reevaluate(); } - GSList *_childList(bool add_ref, SPObject::Action action); + std::vector<SPObject*> _childList(bool add_ref, SPObject::Action action); virtual void _showChildren (Inkscape::Drawing &drawing, Inkscape::DrawingItem *ai, unsigned int key, unsigned int flags); SPObject *_evaluateFirst(); diff --git a/src/splivarot.cpp b/src/splivarot.cpp index 46279cbce..f61a30462 100644 --- a/src/splivarot.cpp +++ b/src/splivarot.cpp @@ -326,21 +326,21 @@ void sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool_op bop, const unsigned int verb, const Glib::ustring description) { SPDocument *doc = selection->layers()->getDocument(); - GSList *il = (GSList *) selection->itemList(); + std::vector<SPItem*> il= selection->itemList(); // allow union on a single object for the purpose of removing self overlapse (svn log, revision 13334) - if ( (g_slist_length(il) < 2) && (bop != bool_op_union)) { + if ( (il.size() < 2) && (bop != bool_op_union)) { boolop_display_error_message(desktop, _("Select <b>at least 2 paths</b> to perform a boolean operation.")); return; } - else if ( g_slist_length(il) < 1 ) { + else if ( il.size() < 1 ) { boolop_display_error_message(desktop, _("Select <b>at least 1 path</b> to perform a boolean union.")); return; } - g_assert(il != NULL); + g_assert(!il.empty()); - if (g_slist_length(il) > 2) { + if (il.size() > 2) { if (bop == bool_op_diff || bop == bool_op_cut || bop == bool_op_slice ) { boolop_display_error_message(desktop, _("Select <b>exactly 2 paths</b> to perform difference, division, or path cut.")); return; @@ -354,8 +354,8 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool if (bop == bool_op_diff || bop == bool_op_cut || bop == bool_op_slice) { // check in the tree to find which element of the selection list is topmost (for 2-operand commands only) - Inkscape::XML::Node *a = SP_OBJECT(il->data)->getRepr(); - Inkscape::XML::Node *b = SP_OBJECT(il->next->data)->getRepr(); + Inkscape::XML::Node *a = il.front()->getRepr(); + Inkscape::XML::Node *b = il.back()->getRepr(); if (a == NULL || b == NULL) { boolop_display_error_message(desktop, _("Unable to determine the <b>z-order</b> of the objects selected for difference, XOR, division, or path cut.")); @@ -394,38 +394,36 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool } } - il = g_slist_copy(il); - g_assert(il != NULL); + g_assert(!il.empty()); // first check if all the input objects have shapes // otherwise bail out - for (GSList *l = il; l != NULL; l = l->next) + for (std::vector<SPItem*>::const_iterator l = il.begin(); l != il.end(); l++) { - SPItem *item = SP_ITEM(l->data); + SPItem *item = *l; if (!SP_IS_SHAPE(item) && !SP_IS_TEXT(item) && !SP_IS_FLOWTEXT(item)) { boolop_display_error_message(desktop, _("One of the objects is <b>not a path</b>, cannot perform boolean operation.")); - g_slist_free(il); return; } } // extract the livarot Paths from the source objects // also get the winding rule specified in the style - int nbOriginaux = g_slist_length(il); + int nbOriginaux = il.size(); std::vector<Path *> originaux(nbOriginaux); std::vector<FillRule> origWind(nbOriginaux); int curOrig; { curOrig = 0; - for (GSList *l = il; l != NULL; l = l->next) + for (std::vector<SPItem*>::const_iterator l = il.begin(); l != il.end(); l++) { // apply live path effects prior to performing boolean operation - if (SP_IS_LPE_ITEM(l->data)) { - SP_LPE_ITEM(l->data)->removeAllPathEffects(true); + if (SP_IS_LPE_ITEM(*l)) { + SP_LPE_ITEM(*l)->removeAllPathEffects(true); } - SPCSSAttr *css = sp_repr_css_attr(reinterpret_cast<SPObject *>(il->data)->getRepr(), "style"); + SPCSSAttr *css = sp_repr_css_attr(reinterpret_cast<SPObject *>(il[0])->getRepr(), "style"); gchar const *val = sp_repr_css_property(css, "fill-rule", NULL); if (val && strcmp(val, "nonzero") == 0) { origWind[curOrig]= fill_nonZero; @@ -435,11 +433,10 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool origWind[curOrig]= fill_nonZero; } - originaux[curOrig] = Path_for_item((SPItem *) l->data, true, true); + originaux[curOrig] = Path_for_item(*l, true, true); if (originaux[curOrig] == NULL || originaux[curOrig]->descr_cmd.size() <= 1) { for (int i = curOrig; i >= 0; i--) delete originaux[i]; - g_slist_free(il); return; } curOrig++; @@ -472,7 +469,8 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool theShapeA->ConvertToShape(theShape, origWind[0]); curOrig = 1; - for (GSList *l = il->next; l != NULL; l = l->next) { + for (std::vector<SPItem*>::const_iterator l = il.begin(); l != il.end(); l++){ + if(*l==il[0])continue; originaux[curOrig]->ConvertWithBackData(0.1); originaux[curOrig]->Fill(theShape, curOrig); @@ -668,15 +666,13 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool if (res->descr_cmd.size() <= 1) { // only one command, presumably a moveto: it isn't a path - for (GSList *l = il; l != NULL; l = l->next) - { - SP_OBJECT(l->data)->deleteObject(); + for (std::vector<SPItem*>::const_iterator l = il.begin(); l != il.end(); l++){ + (*l)->deleteObject(); } DocumentUndo::done(doc, SP_VERB_NONE, description); selection->clear(); delete res; - g_slist_free(il); return; } @@ -684,19 +680,17 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool SPObject *source; if ( bop == bool_op_diff || bop == bool_op_cut || bop == bool_op_slice ) { if (reverseOrderForOp) { - source = SP_OBJECT(il->data); + source = il[0]; } else { - source = SP_OBJECT(il->next->data); + source = il.back(); } } else { // find out the bottom object - GSList *sorted = g_slist_copy((GSList *) selection->reprList()); - - sorted = g_slist_sort(sorted, (GCompareFunc) sp_repr_compare_position); + std::vector<Inkscape::XML::Node*> sorted(selection->reprList()); - source = doc->getObjectByRepr((Inkscape::XML::Node *)sorted->data); + sort(sorted.begin(),sorted.end(),sp_repr_compare_position); - g_slist_free(sorted); + source = doc->getObjectByRepr(sorted.front()); } // adjust style properties that depend on a possible transform in the source object in order @@ -721,17 +715,16 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool gchar *desc = source->desc(); // remove source paths selection->clear(); - for (GSList *l = il; l != NULL; l = l->next) { + for (std::vector<SPItem*>::const_iterator l = il.begin(); l != il.end(); l++){ // if this is the bottommost object, - if (!strcmp(reinterpret_cast<SPObject *>(l->data)->getRepr()->attribute("id"), id)) { + if (!strcmp(reinterpret_cast<SPObject *>(*l)->getRepr()->attribute("id"), id)) { // delete it so that its clones don't get alerted; this object will be restored shortly, with the same id - SP_OBJECT(l->data)->deleteObject(false); + (*l)->deleteObject(false); } else { // delete the object for real, so that its clones can take appropriate action - SP_OBJECT(l->data)->deleteObject(); + (*l)->deleteObject(); } } - g_slist_free(il); // premultiply by the inverse of parent's repr SPItem *parent_item = SP_ITEM(doc->getObjectByRepr(parent)); @@ -1159,12 +1152,9 @@ sp_selected_path_outline(SPDesktop *desktop) } bool did = false; - - for (GSList *items = g_slist_copy((GSList *) selection->itemList()); - items != NULL; - items = items->next) { - - SPItem *item = SP_ITEM(items->data); + std::vector<SPItem*> il(selection->itemList()); + for (std::vector<SPItem*>::const_iterator l = il.begin(); l != il.end(); l++){ + SPItem *item = *l; if (!SP_IS_SHAPE(item) && !SP_IS_TEXT(item)) continue; @@ -1776,12 +1766,9 @@ sp_selected_path_do_offset(SPDesktop *desktop, bool expand, double prefOffset) } bool did = false; - - for (GSList *items = g_slist_copy((GSList *) selection->itemList()); - items != NULL; - items = items->next) { - - SPItem *item = SP_ITEM(items->data); + std::vector<SPItem*> il(selection->itemList()); + for (std::vector<SPItem*>::const_iterator l = il.begin(); l != il.end(); l++){ + SPItem *item = *l; SPCurve *curve = NULL; if (!SP_IS_SHAPE(item) && !SP_IS_TEXT(item)) @@ -1977,7 +1964,7 @@ sp_selected_path_do_offset(SPDesktop *desktop, bool expand, double prefOffset) static bool sp_selected_path_simplify_items(SPDesktop *desktop, - Inkscape::Selection *selection, GSList *items, + Inkscape::Selection *selection, std::vector<SPItem*> &items, float threshold, bool justCoalesce, float angleLimit, bool breakableAngles, bool modifySelection); @@ -1996,7 +1983,7 @@ sp_selected_path_simplify_item(SPDesktop *desktop, //If this is a group, do the children instead if (SP_IS_GROUP(item)) { - GSList *items = sp_item_group_item_list(SP_GROUP(item)); + std::vector<SPItem*> items = sp_item_group_item_list(SP_GROUP(item)); return sp_selected_path_simplify_items(desktop, selection, items, threshold, justCoalesce, @@ -2121,7 +2108,7 @@ sp_selected_path_simplify_item(SPDesktop *desktop, bool sp_selected_path_simplify_items(SPDesktop *desktop, - Inkscape::Selection *selection, GSList *items, + Inkscape::Selection *selection, std::vector<SPItem*> &items, float threshold, bool justCoalesce, float angleLimit, bool breakableAngles, bool modifySelection) @@ -2147,13 +2134,13 @@ sp_selected_path_simplify_items(SPDesktop *desktop, gdouble simplifySize = selectionSize; int pathsSimplified = 0; - int totalPathCount = g_slist_length(items); + int totalPathCount = items.size(); // set "busy" cursor desktop->setWaitingCursor(); - for (; items != NULL; items = items->next) { - SPItem *item = (SPItem *) items->data; + for (std::vector<SPItem*>::const_iterator l = items.begin(); l != items.end(); l++){ + SPItem *item = *l; if (!(SP_IS_GROUP(item) || SP_IS_SHAPE(item) || SP_IS_TEXT(item))) continue; @@ -2201,7 +2188,7 @@ sp_selected_path_simplify_selection(SPDesktop *desktop, float threshold, bool ju return; } - GSList *items = g_slist_copy((GSList *) selection->itemList()); + std::vector<SPItem*> items(selection->itemList()); bool didSomething = sp_selected_path_simplify_items(desktop, selection, items, threshold, diff --git a/src/text-chemistry.cpp b/src/text-chemistry.cpp index 65b59f2ad..9fc862ad2 100644 --- a/src/text-chemistry.cpp +++ b/src/text-chemistry.cpp @@ -43,11 +43,10 @@ using Inkscape::DocumentUndo; static SPItem * flowtext_in_selection(Inkscape::Selection *selection) { - for (GSList *items = (GSList *) selection->itemList(); - items != NULL; - items = items->next) { - if (SP_IS_FLOWTEXT(items->data)) - return ((SPItem *) items->data); + std::vector<SPItem*> items = selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + if (SP_IS_FLOWTEXT(*i)) + return *i; } return NULL; } @@ -55,11 +54,10 @@ flowtext_in_selection(Inkscape::Selection *selection) static SPItem * text_or_flowtext_in_selection(Inkscape::Selection *selection) { - for (GSList *items = (GSList *) selection->itemList(); - items != NULL; - items = items->next) { - if (SP_IS_TEXT(items->data) || SP_IS_FLOWTEXT(items->data)) - return ((SPItem *) items->data); + std::vector<SPItem*> items = selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) + return *i; } return NULL; } @@ -67,11 +65,10 @@ text_or_flowtext_in_selection(Inkscape::Selection *selection) static SPItem * shape_in_selection(Inkscape::Selection *selection) { - for (GSList *items = (GSList *) selection->itemList(); - items != NULL; - items = items->next) { - if (SP_IS_SHAPE(items->data)) - return ((SPItem *) items->data); + std::vector<SPItem*> items = selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + if (SP_IS_SHAPE(*i)) + return *i; } return NULL; } @@ -90,7 +87,7 @@ text_put_on_path() Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - if (!text || !shape || g_slist_length((GSList *) selection->itemList()) != 2) { + if (!text || !shape || selection->itemList().size() != 2) { desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>a text and a path</b> to put text on path.")); return; } @@ -199,11 +196,9 @@ text_remove_from_path() } bool did = false; - - for (GSList *items = g_slist_copy((GSList *) selection->itemList()); - items != NULL; - items = items->next) { - SPObject *obj = SP_OBJECT(items->data); + std::vector<SPItem*> items(selection->itemList()); + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + SPObject *obj = *i; if (SP_IS_TEXT_TEXTPATH(obj)) { SPObject *tp = obj->firstChild(); @@ -219,7 +214,7 @@ text_remove_from_path() } else { DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_TEXT, _("Remove text from path")); - selection->setList(g_slist_copy((GSList *) selection->itemList())); // reselect to update statusbar description + selection->setList(selection->itemList()); // reselect to update statusbar description } } @@ -265,10 +260,9 @@ text_remove_all_kerns() bool did = false; - for (GSList *items = g_slist_copy((GSList *) selection->itemList()); - items != NULL; - items = items->next) { - SPObject *obj = SP_OBJECT(items->data); + std::vector<SPItem*> items = selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + SPObject *obj = *i; if (!SP_IS_TEXT(obj) && !SP_IS_TSPAN(obj) && !SP_IS_FLOWTEXT(obj)) { continue; @@ -302,7 +296,7 @@ text_flow_into_shape() SPItem *text = text_or_flowtext_in_selection(selection); SPItem *shape = shape_in_selection(selection); - if (!text || !shape || g_slist_length((GSList *) selection->itemList()) < 2) { + if (!text || !shape || selection->itemList().size() < 2) { desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>a text</b> and one or more <b>paths or shapes</b> to flow text into frame.")); return; } @@ -326,10 +320,9 @@ text_flow_into_shape() g_return_if_fail(SP_IS_FLOWREGION(object)); /* Add clones */ - for (GSList *items = (GSList *) selection->itemList(); - items != NULL; - items = items->next) { - SPItem *item = SP_ITEM(items->data); + std::vector<SPItem*> items = selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + SPItem *item = *i; if (SP_IS_SHAPE(item)){ Inkscape::XML::Node *clone = xml_doc->createElement("svg:use"); clone->setAttribute("x", "0"); @@ -394,23 +387,22 @@ text_unflow () Inkscape::Selection *selection = desktop->getSelection(); - if (!flowtext_in_selection(selection) || g_slist_length((GSList *) selection->itemList()) < 1) { + if (!flowtext_in_selection(selection) || selection->itemList().size() < 1) { desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>a flowed text</b> to unflow it.")); return; } - GSList *new_objs = NULL; + std::vector<SPItem*> new_objs; GSList *old_objs = NULL; - for (GSList *items = g_slist_copy((GSList *) selection->itemList()); - items != NULL; - items = items->next) { + std::vector<SPItem*> items = selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ - if (!SP_IS_FLOWTEXT(SP_OBJECT(items->data))) { + if (!SP_IS_FLOWTEXT(*i)) { continue; } - SPItem *flowtext = SP_ITEM(items->data); + SPItem *flowtext = *i; // we discard transform when unflowing, but we must preserve expansion which is visible as // font size multiplier @@ -451,7 +443,7 @@ text_unflow () SPText *text = SP_TEXT(text_object); text->_adjustFontsizeRecursive(text, ex); - new_objs = g_slist_prepend (new_objs, text_object); + new_objs.push_back((SPItem*)text_object); old_objs = g_slist_prepend (old_objs, flowtext); Inkscape::GC::release(rtext); @@ -460,13 +452,13 @@ text_unflow () } selection->clear(); + reverse(new_objs.begin(),new_objs.end()); selection->setList(new_objs); for (GSList *i = old_objs; i; i = i->next) { SP_OBJECT(i->data)->deleteObject (true); } g_slist_free (old_objs); - g_slist_free (new_objs); DocumentUndo::done(doc, SP_VERB_CONTEXT_TEXT, _("Unflow flowed text")); @@ -487,11 +479,11 @@ flowtext_to_text() bool did = false; - GSList *reprs = NULL; - GSList *items = g_slist_copy((GSList *) selection->itemList()); - for (; items != NULL; items = items->next) { + std::vector<Inkscape::XML::Node*> reprs; + std::vector<SPItem*> items(selection->itemList()); + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ - SPItem *item = (SPItem *) items->data; + SPItem *item = *i; if (!SP_IS_FLOWTEXT(item)) continue; @@ -519,10 +511,9 @@ flowtext_to_text() Inkscape::GC::release(repr); item->deleteObject(); - reprs = g_slist_prepend(reprs, repr); + reprs.push_back(repr); } - g_slist_free(items); if (did) { DocumentUndo::done(desktop->getDocument(), @@ -535,7 +526,6 @@ flowtext_to_text() _("<b>No flowed text(s)</b> to convert in the selection.")); } - g_slist_free(reprs); } diff --git a/src/text-editing.cpp b/src/text-editing.cpp index 4a962ab4c..050e223eb 100644 --- a/src/text-editing.cpp +++ b/src/text-editing.cpp @@ -67,12 +67,11 @@ static void te_update_layout_now (SPItem *item) void te_update_layout_now_recursive(SPItem *item) { if (SP_IS_GROUP(item)) { - GSList *item_list = sp_item_group_item_list(SP_GROUP(item)); - for(GSList* elem = item_list; elem; elem = elem->next) { - SPItem* list_item = static_cast<SPItem*>(elem->data); + std::vector<SPItem*> item_list = sp_item_group_item_list(SP_GROUP(item)); + for(std::vector<SPItem*>::const_iterator i=item_list.begin();i!=item_list.end();i++){ + SPItem* list_item = *i; te_update_layout_now_recursive(list_item); } - g_slist_free(item_list); } else if (SP_IS_TEXT(item)) SP_TEXT(item)->rebuildLayout(); else if (SP_IS_FLOWTEXT (item)) diff --git a/src/trace/trace.cpp b/src/trace/trace.cpp index cc3d000a3..91c230920 100644 --- a/src/trace/trace.cpp +++ b/src/trace/trace.cpp @@ -65,7 +65,7 @@ SPImage *Tracer::getSelectedSPImage() if (sioxEnabled) { SPImage *img = NULL; - GSList const *list = sel->itemList(); + std::vector<SPItem*> const list = sel->itemList(); std::vector<SPItem *> items; sioxShapes.clear(); @@ -74,13 +74,13 @@ SPImage *Tracer::getSelectedSPImage() them as bottom-to-top so that we can discover the image and any SPItems above it */ - for ( ; list ; list=list->next) + for (std::vector<SPItem*>::const_iterator i=list.begin() ; list.end()!=i ; i++) { - if (!SP_IS_ITEM(list->data)) + if (!SP_IS_ITEM(*i)) { continue; } - SPItem *item = SP_ITEM(list->data); + SPItem *item = *i; items.insert(items.begin(), item); } std::vector<SPItem *>::iterator iter; diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index f1d0ff576..a3620b754 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -523,8 +523,9 @@ bool ClipboardManagerImpl::pasteSize(SPDesktop *desktop, bool separately, bool a // resize each object in the selection if (separately) { - for (GSList *i = const_cast<GSList*>(selection->itemList()) ; i ; i = i->next) { - SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(i->data)); + std::vector<SPItem*> itemlist=selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = *i; if (item) { Geom::OptRect obj_size = item->desktopVisualBounds(); if ( obj_size ) { @@ -578,8 +579,9 @@ bool ClipboardManagerImpl::pastePathEffect(SPDesktop *desktop) desktop->doc()->importDefs(tempdoc); // make sure all selected items are converted to paths first (i.e. rectangles) sp_selected_to_lpeitems(desktop); - for (GSList *itemptr = const_cast<GSList *>(selection->itemList()) ; itemptr ; itemptr = itemptr->next) { - SPItem *item = reinterpret_cast<SPItem*>(itemptr->data); + std::vector<SPItem*> itemlist=selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = *i; _applyPathEffect(item, effectstack); } @@ -659,10 +661,10 @@ Glib::ustring ClipboardManagerImpl::getShapeOrTextObjectId(SPDesktop *desktop) */ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) { - GSList const *items = selection->itemList(); // copy the defs used by all items - for (GSList *i = const_cast<GSList *>(items) ; i != NULL ; i = i->next) { - SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(i->data)); + std::vector<SPItem*> itemlist=selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = *i; if (item) { _copyUsedDefs(item); } else { @@ -671,11 +673,11 @@ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) } // copy the representation of the items - GSList *sorted_items = g_slist_copy(const_cast<GSList *>(items)); - sorted_items = g_slist_sort(sorted_items, (GCompareFunc) sp_object_compare_position); + std::vector<SPItem*> sorted_items(itemlist); + sort(sorted_items.begin(),sorted_items.end(),sp_object_compare_position); - for (GSList *i = sorted_items ; i ; i = i->next) { - SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(i->data)); + for(std::vector<SPItem*>::const_iterator i=sorted_items.begin();i!=sorted_items.end();i++){ + SPItem *item = *i; if (item) { Inkscape::XML::Node *obj = item->getRepr(); Inkscape::XML::Node *obj_copy = _copyNode(obj, _doc, _root); @@ -703,8 +705,8 @@ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) } // copy style for Paste Style action - if (sorted_items) { - SPObject *object = static_cast<SPObject *>(sorted_items->data); + if (!sorted_items.empty()) { + SPObject *object = sorted_items[0]; SPItem *item = dynamic_cast<SPItem *>(object); if (item) { SPCSSAttr *style = take_style_from_item(item); @@ -727,7 +729,6 @@ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) sp_repr_set_point(_clipnode, "max", size->max()); } - g_slist_free(sorted_items); } @@ -1164,8 +1165,8 @@ void ClipboardManagerImpl::_onGet(Gtk::SelectionData &sel, guint /*info*/) sp_repr_get_double(nv, "inkscape:pageopacity", &opacity); bgcolor |= SP_COLOR_F_TO_U(opacity); } - - sp_export_png_file(_clipboardSPDoc, filename, area, width, height, dpi, dpi, bgcolor, NULL, NULL, true, NULL); + std::vector<SPItem*> x; + sp_export_png_file(_clipboardSPDoc, filename, area, width, height, dpi, dpi, bgcolor, NULL, NULL, true, x); } else { diff --git a/src/ui/dialog/align-and-distribute.cpp b/src/ui/dialog/align-and-distribute.cpp index 65bc94011..882427912 100644 --- a/src/ui/dialog/align-and-distribute.cpp +++ b/src/ui/dialog/align-and-distribute.cpp @@ -97,9 +97,7 @@ void ActionAlign::do_action(SPDesktop *desktop, int index) Inkscape::Preferences *prefs = Inkscape::Preferences::get(); bool sel_as_group = prefs->getBool("/dialogs/align/sel-as-groups"); - using Inkscape::Util::GSListConstIterator; - std::list<SPItem *> selected; - selected.insert<GSListConstIterator<SPItem *> >(selected.end(), selection->itemList(), NULL); + std::vector<SPItem*> selected(selection->itemList()); if (selected.empty()) return; const Coeffs &a = _allCoeffs[index]; @@ -149,18 +147,19 @@ void ActionAlign::do_action(SPDesktop *desktop, int index) b = selection->preferredBounds(); //Move each item in the selected list separately - for (std::list<SPItem *>::iterator it(selected.begin()); + for (std::vector<SPItem*>::iterator it(selected.begin()); it != selected.end(); ++it) { + SPItem* item= *it; desktop->getDocument()->ensureUpToDate(); if (!sel_as_group) - b = (*it)->desktopPreferredBounds(); - if (b && (!focus || (*it) != focus)) { + b = (item)->desktopPreferredBounds(); + if (b && (!focus || (item) != focus)) { Geom::Point const sp(a.sx0 * b->min()[Geom::X] + a.sx1 * b->max()[Geom::X], a.sy0 * b->min()[Geom::Y] + a.sy1 * b->max()[Geom::Y]); Geom::Point const mp_rel( mp - sp ); if (LInfty(mp_rel) > 1e-9) { - sp_item_move_rel(*it, Geom::Translate(mp_rel)); + sp_item_move_rel(item, Geom::Translate(mp_rel)); changed = true; } } @@ -250,26 +249,24 @@ private : Inkscape::Selection *selection = desktop->getSelection(); if (!selection) return; - using Inkscape::Util::GSListConstIterator; - std::list<SPItem *> selected; - selected.insert<GSListConstIterator<SPItem *> >(selected.end(), selection->itemList(), NULL); + std::vector<SPItem*> selected(selection->itemList()); if (selected.empty()) return; //Check 2 or more selected objects - std::list<SPItem *>::iterator second(selected.begin()); + std::vector<SPItem*>::iterator second(selected.begin()); ++second; if (second == selected.end()) return; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); int prefs_bbox = prefs->getBool("/tools/bounding_box"); std::vector< BBoxSort > sorted; - for (std::list<SPItem *>::iterator it(selected.begin()); + for (std::vector<SPItem*>::iterator it(selected.begin()); it != selected.end(); - ++it) - { - Geom::OptRect bbox = !prefs_bbox ? (*it)->desktopVisualBounds() : (*it)->desktopGeometricBounds(); + ++it){ + SPItem *item = *it; + Geom::OptRect bbox = !prefs_bbox ? (item)->desktopVisualBounds() : (item)->desktopGeometricBounds(); if (bbox) { - sorted.push_back(BBoxSort(*it, *bbox, _orientation, _kBegin, _kEnd)); + sorted.push_back(BBoxSort(item, *bbox, _orientation, _kBegin, _kEnd)); } } //sort bbox by anchors @@ -549,9 +546,7 @@ private : Inkscape::Selection *selection = desktop->getSelection(); if (!selection) return; - using Inkscape::Util::GSListConstIterator; - std::list<SPItem *> selected; - selected.insert<GSListConstIterator<SPItem *> >(selected.end(), selection->itemList(), NULL); + std::vector<SPItem*> selected(selection->itemList()); if (selected.empty()) return; //Check 2 or more selected objects @@ -569,15 +564,17 @@ private : } else { // sorting by ZOrder is outomatically done by not setting the center center.reset(); } - selected.sort(ActionExchangePositions::sort_compare); + sort(selected.begin(),selected.end(),sort_compare); } - std::list<SPItem *>::iterator it(selected.begin()); - Geom::Point p1 = (*it)->getCenter(); + std::vector<SPItem*>::iterator it(selected.begin()); + SPItem* item = *it; + Geom::Point p1 = item->getCenter(); for (++it ;it != selected.end(); ++it) { - Geom::Point p2 = (*it)->getCenter(); + item = *it; + Geom::Point p2 = item->getCenter(); Geom::Point delta = p1 - p2; - sp_item_move_rel((*it),Geom::Translate(delta[Geom::X],delta[Geom::Y] )); + sp_item_move_rel(item,Geom::Translate(delta[Geom::X],delta[Geom::Y] )); p1 = p2; } Geom::Point p2 = selected.front()->getCenter(); @@ -615,8 +612,8 @@ private : Inkscape::Preferences *prefs = Inkscape::Preferences::get(); int saved_compensation = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); prefs->setInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); - - unclump ((GSList *) _dialog.getDesktop()->getSelection()->itemList()); + std::vector<SPItem*> x(_dialog.getDesktop()->getSelection()->itemList()); + unclump (x); // restore compensation setting prefs->setInt("/options/clonecompensation/value", saved_compensation); @@ -646,9 +643,7 @@ private : Inkscape::Selection *selection = desktop->getSelection(); if (!selection) return; - using Inkscape::Util::GSListConstIterator; - std::list<SPItem *> selected; - selected.insert<GSListConstIterator<SPItem *> >(selected.end(), selection->itemList(), NULL); + std::vector<SPItem*> selected(selection->itemList()); if (selected.empty()) return; //Check 2 or more selected objects @@ -672,12 +667,13 @@ private : int saved_compensation = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); prefs->setInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); - for (std::list<SPItem *>::iterator it(selected.begin()); + for (std::vector<SPItem*>::iterator it(selected.begin()); it != selected.end(); ++it) { + SPItem* item = *it; desktop->getDocument()->ensureUpToDate(); - Geom::OptRect item_box = !prefs_bbox ? (*it)->desktopVisualBounds() : (*it)->desktopGeometricBounds(); + Geom::OptRect item_box = !prefs_bbox ? (item)->desktopVisualBounds() : (item)->desktopGeometricBounds(); if (item_box) { // find new center, staying within bbox double x = _dialog.randomize_bbox->min()[Geom::X] + (*item_box)[Geom::X].extent() /2 + @@ -686,7 +682,7 @@ private : g_random_double_range (0, (*_dialog.randomize_bbox)[Geom::Y].extent() - (*item_box)[Geom::Y].extent()); // displacement is the new center minus old: Geom::Point t = Geom::Point (x, y) - 0.5*(item_box->max() + item_box->min()); - sp_item_move_rel(*it, Geom::Translate(t)); + sp_item_move_rel(item, Geom::Translate(t)); } } @@ -745,9 +741,7 @@ private : Inkscape::Selection *selection = desktop->getSelection(); if (!selection) return; - using Inkscape::Util::GSListConstIterator; - std::list<SPItem *> selected; - selected.insert<GSListConstIterator<SPItem *> >(selected.end(), selection->itemList(), NULL); + std::vector<SPItem*> selected(selection->itemList()); if (selected.empty()) return; //Check 2 or more selected objects @@ -758,20 +752,21 @@ private : std::vector<Baselines> sorted; - for (std::list<SPItem *>::iterator it(selected.begin()); + for (std::vector<SPItem*>::iterator it(selected.begin()); it != selected.end(); ++it) { - if (SP_IS_TEXT (*it) || SP_IS_FLOWTEXT (*it)) { - Inkscape::Text::Layout const *layout = te_get_layout(*it); + SPItem* item = *it; + if (SP_IS_TEXT (item) || SP_IS_FLOWTEXT (item)) { + Inkscape::Text::Layout const *layout = te_get_layout(item); boost::optional<Geom::Point> pt = layout->baselineAnchorPoint(); if (pt) { - Geom::Point base = *pt * (*it)->i2dt_affine(); + Geom::Point base = *pt * (item)->i2dt_affine(); if (base[Geom::X] < b_min[Geom::X]) b_min[Geom::X] = base[Geom::X]; if (base[Geom::Y] < b_min[Geom::Y]) b_min[Geom::Y] = base[Geom::Y]; if (base[Geom::X] > b_max[Geom::X]) b_max[Geom::X] = base[Geom::X]; if (base[Geom::Y] > b_max[Geom::Y]) b_max[Geom::Y] = base[Geom::Y]; - Baselines b (*it, base, _orientation); + Baselines b (item, base, _orientation); sorted.push_back(b); } } @@ -801,18 +796,19 @@ private : } } else { - for (std::list<SPItem *>::iterator it(selected.begin()); + for (std::vector<SPItem*>::iterator it(selected.begin()); it != selected.end(); ++it) { - if (SP_IS_TEXT (*it) || SP_IS_FLOWTEXT (*it)) { - Inkscape::Text::Layout const *layout = te_get_layout(*it); + SPItem* item = *it; + if (SP_IS_TEXT (item) || SP_IS_FLOWTEXT (item)) { + Inkscape::Text::Layout const *layout = te_get_layout(item); boost::optional<Geom::Point> pt = layout->baselineAnchorPoint(); if (pt) { - Geom::Point base = *pt * (*it)->i2dt_affine(); + Geom::Point base = *pt * (item)->i2dt_affine(); Geom::Point t(0.0, 0.0); t[_orientation] = b_min[_orientation] - base[_orientation]; - sp_item_move_rel(*it, Geom::Translate(t)); + sp_item_move_rel(item, Geom::Translate(t)); changed = true; } } diff --git a/src/ui/dialog/clonetiler.cpp b/src/ui/dialog/clonetiler.cpp index bd3ad0254..f84a2ffd6 100644 --- a/src/ui/dialog/clonetiler.cpp +++ b/src/ui/dialog/clonetiler.cpp @@ -1359,7 +1359,7 @@ void CloneTiler::clonetiler_change_selection(Inkscape::Selection *selection, Gtk return; } - if (g_slist_length ((GSList *) selection->itemList()) > 1) { + if (selection->itemList().size() > 1) { gtk_widget_set_sensitive (buttons, FALSE); gtk_label_set_markup (GTK_LABEL(status), _("<small>More than one object selected.</small>")); return; @@ -2096,7 +2096,7 @@ void CloneTiler::clonetiler_unclump(GtkWidget */*widget*/, void *) Inkscape::Selection *selection = desktop->getSelection(); // check if something is selected - if (selection->isEmpty() || g_slist_length((GSList *) selection->itemList()) > 1) { + if (selection->isEmpty() || selection->itemList().size() > 1) { desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>one object</b> whose tiled clones to unclump.")); return; } @@ -2104,20 +2104,18 @@ void CloneTiler::clonetiler_unclump(GtkWidget */*widget*/, void *) SPObject *obj = selection->singleItem(); SPObject *parent = obj->parent; - GSList *to_unclump = NULL; // not including the original + std::vector<SPItem*> to_unclump; // not including the original for (SPObject *child = parent->firstChild(); child != NULL; child = child->next) { if (clonetiler_is_a_clone_of (child, obj)) { - to_unclump = g_slist_prepend (to_unclump, child); + to_unclump.push_back((SPItem*)child); } } desktop->getDocument()->ensureUpToDate(); - + reverse(to_unclump.begin(),to_unclump.end()); unclump (to_unclump); - g_slist_free (to_unclump); - DocumentUndo::done(desktop->getDocument(), SP_VERB_DIALOG_CLONETILER, _("Unclump tiled clones")); } @@ -2147,7 +2145,7 @@ void CloneTiler::clonetiler_remove(GtkWidget */*widget*/, GtkWidget *dlg, bool d Inkscape::Selection *selection = desktop->getSelection(); // check if something is selected - if (selection->isEmpty() || g_slist_length((GSList *) selection->itemList()) > 1) { + if (selection->isEmpty() || selection->itemList().size() > 1) { desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>one object</b> whose tiled clones to remove.")); return; } @@ -2225,7 +2223,7 @@ void CloneTiler::clonetiler_apply(GtkWidget */*widget*/, GtkWidget *dlg) } // Check if more than one object is selected. - if (g_slist_length((GSList *) selection->itemList()) > 1) { + if (selection->itemList().size() > 1) { desktop->getMessageStack()->flash(Inkscape::ERROR_MESSAGE, _("If you want to clone several objects, <b>group</b> them and <b>clone the group</b>.")); return; } diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp index 9ac5c24fe..384aec415 100644 --- a/src/ui/dialog/export.cpp +++ b/src/ui/dialog/export.cpp @@ -601,7 +601,7 @@ void Export::onBatchClicked () void Export::updateCheckbuttons () { - gint num = g_slist_length((GSList *) SP_ACTIVE_DESKTOP->getSelection()->itemList()); + gint num = SP_ACTIVE_DESKTOP->getSelection()->itemList().size(); if (num >= 2) { batch_export.set_sensitive(true); batch_export.set_label(g_strdup_printf (ngettext("B_atch export %d selected object","B_atch export %d selected objects",num), num)); @@ -813,9 +813,9 @@ void Export::onAreaToggled () one that's nice */ if (filename.empty()) { const gchar * id = "object"; - const GSList * reprlst = SP_ACTIVE_DESKTOP->getSelection()->reprList(); - for(; reprlst != NULL; reprlst = reprlst->next) { - Inkscape::XML::Node * repr = (Inkscape::XML::Node *)reprlst->data; + const std::vector<XML::Node*> reprlst = SP_ACTIVE_DESKTOP->getSelection()->reprList(); + for(std::vector<XML::Node*>::const_iterator i=reprlst.begin(); reprlst.end() != i; i++) { + Inkscape::XML::Node * repr = *i; if (repr->attribute("id")) { id = repr->attribute("id"); break; @@ -1006,7 +1006,7 @@ void Export::onExport () if (batch_export.get_active ()) { // Batch export of selected objects - gint num = g_slist_length(const_cast<GSList *>(desktop->getSelection()->itemList())); + gint num = (desktop->getSelection()->itemList()).size(); gint n = 0; if (num < 1) { @@ -1020,8 +1020,9 @@ void Export::onExport () gint export_count = 0; - for (GSList *i = const_cast<GSList *>(desktop->getSelection()->itemList()); i && !interrupted; i = i->next) { - SPItem *item = reinterpret_cast<SPItem *>(i->data); + std::vector<SPItem*> itemlist=desktop->getSelection()->itemList(); + for(std::vector<SPItem*>::const_iterator i = itemlist.begin();i!=itemlist.end() && !interrupted ;i++){ + SPItem *item = *i; prog_dlg->set_data("current", GINT_TO_POINTER(n)); prog_dlg->set_data("total", GINT_TO_POINTER(num)); @@ -1059,13 +1060,13 @@ void Export::onExport () _("Exporting file <b>%s</b>..."), safeFile), desktop); MessageCleaner msgFlashCleanup(desktop->messageStack()->flashF(Inkscape::IMMEDIATE_MESSAGE, _("Exporting file <b>%s</b>..."), safeFile), desktop); - + std::vector<SPItem*> x; if (!sp_export_png_file (doc, path.c_str(), *area, width, height, dpi, dpi, nv->pagecolor, onProgressCallback, (void*)prog_dlg, TRUE, // overwrite without asking - hide ? const_cast<GSList *>(desktop->getSelection()->itemList()) : NULL + hide ? (desktop->getSelection()->itemList()) : x )) { gchar * error = g_strdup_printf(_("Could not export to filename %s.\n"), safeFile); @@ -1149,12 +1150,13 @@ void Export::onExport () prog_dlg->set_data("total", GINT_TO_POINTER(0)); /* Do export */ + std::vector<SPItem*> x; ExportResult status = sp_export_png_file(desktop->getDocument(), path.c_str(), Geom::Rect(Geom::Point(x0, y0), Geom::Point(x1, y1)), width, height, xdpi, ydpi, nv->pagecolor, onProgressCallback, (void*)prog_dlg, FALSE, - hide ? const_cast<GSList *>(desktop->getSelection()->itemList()) : NULL + hide ? (desktop->getSelection()->itemList()) : x ); if (status == EXPORT_ERROR) { gchar * safeFile = Inkscape::IO::sanitizeString(path.c_str()); @@ -1220,7 +1222,7 @@ void Export::onExport () break; } case SELECTION_SELECTION: { - const GSList * reprlst; + std::vector<XML::Node*> reprlst; SPDocument * doc = SP_ACTIVE_DOCUMENT; bool modified = false; @@ -1228,8 +1230,8 @@ void Export::onExport () DocumentUndo::setUndoSensitive(doc, false); reprlst = desktop->getSelection()->reprList(); - for(; reprlst != NULL; reprlst = reprlst->next) { - Inkscape::XML::Node * repr = static_cast<Inkscape::XML::Node *>(reprlst->data); + for(std::vector<Inkscape::XML::Node*>::const_iterator i=reprlst.begin(); reprlst.end() != i; i++) { + Inkscape::XML::Node * repr = *i; const gchar * temp_string; Glib::ustring dir = Glib::path_get_dirname(filename.c_str()); const gchar* docURI=SP_ACTIVE_DOCUMENT->getURI(); diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index 077c6f5ca..f81519ed1 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -690,7 +690,7 @@ private: void select_svg_element(){ Inkscape::Selection* sel = _desktop->getSelection(); if (sel->isEmpty()) return; - Inkscape::XML::Node* node = (Inkscape::XML::Node*) g_slist_nth_data((GSList *)sel->reprList(), 0); + Inkscape::XML::Node* node = sel->reprList()[0]; if (!node || !node->matchAttributeName("id")) return; std::ostringstream xlikhref; @@ -1465,9 +1465,9 @@ void FilterEffectsDialog::FilterModifier::update_selection(Selection *sel) } std::set<SPObject*> used; - - for (GSList const *i = sel->itemList(); i != NULL; i = i->next) { - SPObject *obj = SP_OBJECT (i->data); + std::vector<SPItem*> itemlist=sel->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { + SPObject *obj = *i; SPStyle *style = obj->style; if (!style || !SP_IS_ITEM(obj)) { continue; @@ -1545,10 +1545,9 @@ void FilterEffectsDialog::FilterModifier::on_selection_toggled(const Glib::ustri if((*iter)[_columns.sel] == 1) filter = 0; - GSList const *items = sel->itemList(); - - for (GSList const *i = items; i != NULL; i = i->next) { - SPItem * item = SP_ITEM(i->data); + std::vector<SPItem*> itemlist=sel->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { + SPItem * item = *i; SPStyle *style = item->style; g_assert(style != NULL); @@ -1650,12 +1649,13 @@ void FilterEffectsDialog::FilterModifier::remove_filter() SPDocument* doc = filter->document; // Delete all references to this filter - GSList *all = get_all_items(NULL, _desktop->currentRoot(), _desktop, false, false, true, NULL); - for (GSList *i = all; i != NULL; i = i->next) { - if (!SP_IS_ITEM(i->data)) { + std::vector<SPItem*> x,y; + std::vector<SPItem*> all = get_all_items(x, _desktop->currentRoot(), _desktop, false, false, true, y); + for(std::vector<SPItem*>::const_iterator i=all.begin(); all.end() != i; i++) { + if (!SP_IS_ITEM(*i)) { continue; } - SPItem *item = SP_ITEM(i->data); + SPItem *item = *i; if (!item->style) { continue; } @@ -1668,9 +1668,6 @@ void FilterEffectsDialog::FilterModifier::remove_filter() } } } - if (all) { - g_slist_free(all); - } //XML Tree being used directly here while it shouldn't be. sp_repr_unparent(filter->getRepr()); diff --git a/src/ui/dialog/find.cpp b/src/ui/dialog/find.cpp index 951cb01ea..a8ac42a1b 100644 --- a/src/ui/dialog/find.cpp +++ b/src/ui/dialog/find.cpp @@ -549,7 +549,7 @@ bool Find::item_font_match(SPItem *item, const gchar *text, bool exact, bool cas } -GSList *Find::filter_fields (GSList *l, bool exact, bool casematch) +std::vector<SPItem*> Find::filter_fields (std::vector<SPItem*> &l, bool exact, bool casematch) { Glib::ustring tmp = entry_find.getEntry()->get_text(); if (tmp.empty()) { @@ -557,17 +557,17 @@ GSList *Find::filter_fields (GSList *l, bool exact, bool casematch) } gchar* text = g_strdup(tmp.c_str()); - GSList *in = l; - GSList *out = NULL; + std::vector<SPItem*> in = l; + std::vector<SPItem*> out; if (check_searchin_text.get_active()) { - for (GSList *i = in; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast<SPObject *>(i->data); + for(std::vector<SPItem*>::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) { + SPObject *obj = *i; SPItem *item = dynamic_cast<SPItem *>(obj); g_assert(item != NULL); if (item_text_match(item, text, exact, casematch)) { - if (!g_slist_find(out, i->data)) { - out = g_slist_prepend (out, i->data); + if (out.end()==find(out.begin(),out.end(), *i)) { + out.push_back(*i); if (_action_replace) { item_text_match(item, text, exact, casematch, _action_replace); } @@ -584,12 +584,12 @@ GSList *Find::filter_fields (GSList *l, bool exact, bool casematch) bool attrvalue = check_attributevalue.get_active(); if (ids) { - for (GSList *i = in; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast<SPObject *>(i->data); + for(std::vector<SPItem*>::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) { + SPObject *obj = *i; SPItem *item = dynamic_cast<SPItem *>(obj); if (item_id_match(item, text, exact, casematch)) { - if (!g_slist_find(out, i->data)) { - out = g_slist_prepend (out, i->data); + if (out.end()==find(out.begin(),out.end(), *i)) { + out.push_back(*i); if (_action_replace) { item_id_match(item, text, exact, casematch, _action_replace); } @@ -600,14 +600,13 @@ GSList *Find::filter_fields (GSList *l, bool exact, bool casematch) if (style) { - for (GSList *i = in; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast<SPObject *>(i->data); + for(std::vector<SPItem*>::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) { + SPObject *obj = *i; SPItem *item = dynamic_cast<SPItem *>(obj); g_assert(item != NULL); if (item_style_match(item, text, exact, casematch)) { - if (!g_slist_find(out, i->data)) - if (!g_slist_find(out, i->data)) { - out = g_slist_prepend (out, i->data); + if (out.end()==find(out.begin(),out.end(), *i)){ + out.push_back(*i); if (_action_replace) { item_style_match(item, text, exact, casematch, _action_replace); } @@ -618,13 +617,13 @@ GSList *Find::filter_fields (GSList *l, bool exact, bool casematch) if (attrname) { - for (GSList *i = in; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast<SPObject *>(i->data); + for(std::vector<SPItem*>::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) { + SPObject *obj = *i; SPItem *item = dynamic_cast<SPItem *>(obj); g_assert(item != NULL); if (item_attr_match(item, text, exact, casematch)) { - if (!g_slist_find(out, i->data)) { - out = g_slist_prepend (out, i->data); + if (out.end()==find(out.begin(),out.end(), *i)) { + out.push_back(*i); if (_action_replace) { item_attr_match(item, text, exact, casematch, _action_replace); } @@ -635,13 +634,13 @@ GSList *Find::filter_fields (GSList *l, bool exact, bool casematch) if (attrvalue) { - for (GSList *i = in; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast<SPObject *>(i->data); + for(std::vector<SPItem*>::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) { + SPObject *obj = *i; SPItem *item = dynamic_cast<SPItem *>(obj); g_assert(item != NULL); if (item_attrvalue_match(item, text, exact, casematch)) { - if (!g_slist_find(out, i->data)) { - out = g_slist_prepend (out, i->data); + if (out.end()==find(out.begin(),out.end(), *i)) { + out.push_back(*i); if (_action_replace) { item_attrvalue_match(item, text, exact, casematch, _action_replace); } @@ -652,13 +651,13 @@ GSList *Find::filter_fields (GSList *l, bool exact, bool casematch) if (font) { - for (GSList *i = in; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast<SPObject *>(i->data); + for(std::vector<SPItem*>::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) { + SPObject *obj = *i; SPItem *item = dynamic_cast<SPItem *>(obj); g_assert(item != NULL); if (item_font_match(item, text, exact, casematch)) { - if (!g_slist_find(out, i->data)) { - out = g_slist_prepend (out, i->data); + if (out.end()==find(out.begin(),out.end(),*i)) { + out.push_back(*i); if (_action_replace) { item_font_match(item, text, exact, casematch, _action_replace); } @@ -716,29 +715,29 @@ bool Find::item_type_match (SPItem *item) return false; } -GSList *Find::filter_types (GSList *l) +std::vector<SPItem*> Find::filter_types (std::vector<SPItem*> &l) { - GSList *n = NULL; - for (GSList *i = l; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast<SPObject *>(i->data); + std::vector<SPItem*> n; + for(std::vector<SPItem*>::const_reverse_iterator i=l.rbegin(); l.rend() != i; i++) { + SPObject *obj = *i; SPItem *item = dynamic_cast<SPItem *>(obj); g_assert(item != NULL); if (item_type_match(item)) { - n = g_slist_prepend (n, i->data); + n.push_back(*i); } } return n; } -GSList *Find::filter_list (GSList *l, bool exact, bool casematch) +std::vector<SPItem*> &Find::filter_list (std::vector<SPItem*> &l, bool exact, bool casematch) { l = filter_types (l); l = filter_fields (l, exact, casematch); return l; } -GSList *Find::all_items (SPObject *r, GSList *l, bool hidden, bool locked) +std::vector<SPItem*> &Find::all_items (SPObject *r, std::vector<SPItem*> &l, bool hidden, bool locked) { if (dynamic_cast<SPDefs *>(r)) { return l; // we're not interested in items in defs @@ -752,7 +751,7 @@ GSList *Find::all_items (SPObject *r, GSList *l, bool hidden, bool locked) SPItem *item = dynamic_cast<SPItem *>(child); if (item && !child->cloned && !desktop->isLayer(item)) { if ((hidden || !desktop->itemIsHidden(item)) && (locked || !item->isLocked())) { - l = g_slist_prepend (l, child); + l.insert(l.begin(),(SPItem*)child); } } l = all_items (child, l, hidden, locked); @@ -760,16 +759,17 @@ GSList *Find::all_items (SPObject *r, GSList *l, bool hidden, bool locked) return l; } -GSList *Find::all_selection_items (Inkscape::Selection *s, GSList *l, SPObject *ancestor, bool hidden, bool locked) +std::vector<SPItem*> &Find::all_selection_items (Inkscape::Selection *s, std::vector<SPItem*> &l, SPObject *ancestor, bool hidden, bool locked) { - for (GSList *i = (GSList *) s->itemList(); i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast<SPObject *>(i->data); + std::vector<SPItem*> itemlist=s->itemList(); + for(std::vector<SPItem*>::const_reverse_iterator i=itemlist.rbegin(); itemlist.rend() != i; i++) { + SPObject *obj = *i; SPItem *item = dynamic_cast<SPItem *>(obj); g_assert(item != NULL); if (item && !item->cloned && !desktop->isLayer(item)) { if (!ancestor || ancestor->isAncestorOf(item)) { if ((hidden || !desktop->itemIsHidden(item)) && (locked || !item->isLocked())) { - l = g_slist_prepend (l, i->data); + l.push_back(*i); } } } @@ -817,7 +817,7 @@ void Find::onAction() bool casematch = check_case_sensitive.get_active(); blocked = true; - GSList *l = NULL; + std::vector<SPItem*> l; if (check_scope_selection.get_active()) { if (check_scope_layer.get_active()) { l = all_selection_items (desktop->selection, l, desktop->currentLayer(), hidden, locked); @@ -831,12 +831,12 @@ void Find::onAction() l = all_items(desktop->getDocument()->getRoot(), l, hidden, locked); } } - guint all = g_slist_length (l); + guint all = l.size(); - GSList *n = filter_list (l, exact, casematch); + std::vector<SPItem*> n = filter_list (l, exact, casematch); - if (n != NULL) { - int count = g_slist_length (n); + if (!n.empty()) { + int count = n.size(); desktop->messageStack()->flashF(Inkscape::NORMAL_MESSAGE, // TRANSLATORS: "%s" is replaced with "exact" or "partial" when this string is displayed ngettext("<b>%d</b> object found (out of <b>%d</b>), %s match.", @@ -857,7 +857,7 @@ void Find::onAction() Inkscape::Selection *selection = desktop->getSelection(); selection->clear(); selection->setList(n); - SPObject *obj = reinterpret_cast<SPObject *>(n->data); + SPObject *obj = n[0]; SPItem *item = dynamic_cast<SPItem *>(obj); g_assert(item != NULL); scroll_to_show_item(desktop, item); diff --git a/src/ui/dialog/find.h b/src/ui/dialog/find.h index c0c635f94..4bcb900b6 100644 --- a/src/ui/dialog/find.h +++ b/src/ui/dialog/find.h @@ -148,10 +148,10 @@ protected: /** * Function to filter a list of items based on the item type by calling each item_XXX_match function */ - GSList * filter_fields (GSList *l, bool exact, bool casematch); + std::vector<SPItem*> filter_fields (std::vector<SPItem*> &l, bool exact, bool casematch); bool item_type_match (SPItem *item); - GSList * filter_types (GSList *l); - GSList * filter_list (GSList *l, bool exact, bool casematch); + std::vector<SPItem*> filter_types (std::vector<SPItem*> &l); + std::vector<SPItem*> & filter_list (std::vector<SPItem*> &l, bool exact, bool casematch); /** * Find a string within a string and returns true if found with options for exact and casematching @@ -172,12 +172,12 @@ protected: * recursive function to return a list of all the items in the SPObject tree * */ - GSList * all_items (SPObject *r, GSList *l, bool hidden, bool locked); + std::vector<SPItem*> & all_items (SPObject *r, std::vector<SPItem*> &l, bool hidden, bool locked); /** * to return a list of all the selected items * */ - GSList * all_selection_items (Inkscape::Selection *s, GSList *l, SPObject *ancestor, bool hidden, bool locked); + std::vector<SPItem*> & all_selection_items (Inkscape::Selection *s, std::vector<SPItem*> &l, SPObject *ancestor, bool hidden, bool locked); /** * Shrink the dialog size when the expander widget is closed diff --git a/src/ui/dialog/font-substitution.cpp b/src/ui/dialog/font-substitution.cpp index 2ef61978f..19506c6a3 100644 --- a/src/ui/dialog/font-substitution.cpp +++ b/src/ui/dialog/font-substitution.cpp @@ -66,19 +66,15 @@ FontSubstitution::checkFontSubstitutions(SPDocument* doc) int show_dlg = prefs->getInt("/options/font/substitutedlg", 0); if (show_dlg) { Glib::ustring out; - GSList *l = getFontReplacedItems(doc, &out); + std::vector<SPItem*> l = getFontReplacedItems(doc, &out); if (out.length() > 0) { show(out, l); } - if (l) { - g_slist_free(l); - l = NULL; - } } } void -FontSubstitution::show(Glib::ustring out, GSList *l) +FontSubstitution::show(Glib::ustring out, std::vector<SPItem*> &l) { Gtk::MessageDialog warning(_("\nSome fonts are not available and have been substituted."), false, Gtk::MESSAGE_INFO, Gtk::BUTTONS_OK, true); @@ -148,20 +144,18 @@ FontSubstitution::show(Glib::ustring out, GSList *l) * b. Build up a list of the objects rendered fonts - taken for the objects layout/spans * If there are fonts in a. that are not in b. then those fonts have been substituted. */ -GSList * FontSubstitution::getFontReplacedItems(SPDocument* doc, Glib::ustring *out) +std::vector<SPItem*> FontSubstitution::getFontReplacedItems(SPDocument* doc, Glib::ustring *out) { SPDesktop *desktop = SP_ACTIVE_DESKTOP; - GSList *allList = NULL; - GSList *outList = NULL; + std::vector<SPItem*> allList; + std::vector<SPItem*> outList,x,y; std::set<Glib::ustring> setErrors; std::set<Glib::ustring> setFontSpans; std::map<SPItem *, Glib::ustring> mapFontStyles; - allList = get_all_items(NULL, doc->getRoot(), desktop, false, false, true, NULL); - - for (GSList *i = allList; i != NULL; i = i->next) { - - SPItem *item = SP_ITEM(i->data); + allList = get_all_items(x, doc->getRoot(), desktop, false, false, true, y); + for(std::vector<SPItem*>::const_iterator i = allList.begin();i!=allList.end();i++){ + SPItem *item = *i; SPStyle *style = item->style; Glib::ustring family = ""; @@ -216,8 +210,8 @@ GSList * FontSubstitution::getFontReplacedItems(SPDocument* doc, Glib::ustring * } // Check if any document styles are not in the actual layout - std::map<SPItem *, Glib::ustring>::const_iterator mapIter; - for (mapIter = mapFontStyles.begin(); mapIter != mapFontStyles.end(); ++mapIter) { + std::map<SPItem *, Glib::ustring>::const_reverse_iterator mapIter; + for (mapIter = mapFontStyles.rbegin(); mapIter != mapFontStyles.rend(); ++mapIter) { SPItem *item = mapIter->first; Glib::ustring fonts = mapIter->second; @@ -250,7 +244,7 @@ GSList * FontSubstitution::getFontReplacedItems(SPDocument* doc, Glib::ustring * Glib::ustring err = Glib::ustring::compose( _("Font '%1' substituted with '%2'"), fonts.c_str(), subName.c_str()); setErrors.insert(err); - outList = g_slist_prepend (outList, item); + outList.push_back(item); } } diff --git a/src/ui/dialog/font-substitution.h b/src/ui/dialog/font-substitution.h index 1c445081b..0818d778c 100644 --- a/src/ui/dialog/font-substitution.h +++ b/src/ui/dialog/font-substitution.h @@ -14,6 +14,7 @@ #include <glibmm/ustring.h> +class SPItem; class SPDocument; namespace Inkscape { @@ -25,13 +26,13 @@ public: FontSubstitution(); virtual ~FontSubstitution(); void checkFontSubstitutions(SPDocument* doc); - void show(Glib::ustring out, GSList *l); + void show(Glib::ustring out, std::vector<SPItem*> &l); static FontSubstitution &getInstance() { return *new FontSubstitution(); } Glib::ustring getSubstituteFontName (Glib::ustring font); protected: - GSList *getFontReplacedItems(SPDocument* doc, Glib::ustring *out); + std::vector<SPItem*> getFontReplacedItems(SPDocument* doc, Glib::ustring *out); private: FontSubstitution(FontSubstitution const &d); diff --git a/src/ui/dialog/glyphs.cpp b/src/ui/dialog/glyphs.cpp index 2b9053da9..7ca277ea2 100644 --- a/src/ui/dialog/glyphs.cpp +++ b/src/ui/dialog/glyphs.cpp @@ -578,9 +578,10 @@ void GlyphsPanel::setTargetDesktop(SPDesktop *desktop) void GlyphsPanel::insertText() { SPItem *textItem = 0; - for (const GSList *item = targetDesktop->selection->itemList(); item; item = item->next ) { - if (SP_IS_TEXT(item->data) || SP_IS_FLOWTEXT(item->data)) { - textItem = SP_ITEM(item->data); + std::vector<SPItem*> itemlist=targetDesktop->selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { + if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) { + textItem = *i; break; } } @@ -687,8 +688,9 @@ void GlyphsPanel::selectionModifiedCB(guint flags) void GlyphsPanel::calcCanInsert() { int items = 0; - for (const GSList *item = targetDesktop->selection->itemList(); item; item = item->next ) { - if (SP_IS_TEXT(item->data) || SP_IS_FLOWTEXT(item->data)) { + std::vector<SPItem*> itemlist=targetDesktop->selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { + if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) { ++items; } } diff --git a/src/ui/dialog/grid-arrange-tab.cpp b/src/ui/dialog/grid-arrange-tab.cpp index d3ccb9bde..4465d73a9 100644 --- a/src/ui/dialog/grid-arrange-tab.cpp +++ b/src/ui/dialog/grid-arrange-tab.cpp @@ -48,7 +48,7 @@ * 0 *elem1 == *elem2 * >0 *elem1 goes after *elem2 */ -static int sp_compare_x_position(SPItem *first, SPItem *second) +static bool sp_compare_x_position(SPItem *first, SPItem *second) { using Geom::X; using Geom::Y; @@ -58,7 +58,7 @@ static int sp_compare_x_position(SPItem *first, SPItem *second) if ( !a || !b ) { // FIXME? - return 0; + return false; } double const a_height = a->dimensions()[Y]; @@ -76,40 +76,41 @@ static int sp_compare_x_position(SPItem *first, SPItem *second) } if (!a_in_b_vert) { - return -1; + return true; } if (a_in_b_vert && a->min()[X] > b->min()[X]) { - return 1; + return false; } if (a_in_b_vert && a->min()[X] < b->min()[X]) { - return -1; + return true; } - return 0; + return false; } /* * Sort items by their y co-ordinates. */ -static int sp_compare_y_position(SPItem *first, SPItem *second) +static bool sp_compare_y_position(SPItem *first, SPItem *second) { Geom::OptRect a = first->documentVisualBounds(); Geom::OptRect b = second->documentVisualBounds(); if ( !a || !b ) { // FIXME? - return 0; + return false; } if (a->min()[Geom::Y] > b->min()[Geom::Y]) { - return 1; + return false; } if (a->min()[Geom::Y] < b->min()[Geom::Y]) { - return -1; + return true; } - return 0; + return false; } + namespace Inkscape { namespace UI { namespace Dialog { @@ -168,10 +169,10 @@ void GridArrangeTab::arrange() desktop->getDocument()->ensureUpToDate(); Inkscape::Selection *selection = desktop->getSelection(); - const GSList *items = selection ? selection->itemList() : 0; + const std::vector<SPItem*> items = selection ? selection->itemList() : std::vector<SPItem*>(); cnt=0; - for (; items != NULL; items = items->next) { - SPItem *item = SP_ITEM(items->data); + for(std::vector<SPItem*>::const_iterator i = items.begin();i!=items.end();i++){ + SPItem *item = *i; Geom::OptRect b = item->documentVisualBounds(); if (!b) { continue; @@ -198,20 +199,18 @@ void GridArrangeTab::arrange() // require the sorting done before we can calculate row heights etc. g_return_if_fail(selection); - const GSList *items2 = selection->itemList(); - GSList *rev = g_slist_copy(const_cast<GSList *>(items2)); - GSList *sorted = NULL; - rev = g_slist_sort(rev, (GCompareFunc) sp_compare_y_position); - sorted = g_slist_sort(rev, (GCompareFunc) sp_compare_x_position); + std::vector<SPItem*> sorted(selection->itemList()); + sort(sorted.begin(),sorted.end(),sp_compare_y_position); + sort(sorted.begin(),sorted.end(),sp_compare_x_position); // Calculate individual Row and Column sizes if necessary cnt=0; - const GSList *sizes = sorted; - for (; sizes != NULL; sizes = sizes->next) { - SPItem *item = SP_ITEM(sizes->data); + const std::vector<SPItem*> sizes(sorted); + for (std::vector<SPItem*>::const_iterator i = sizes.begin();i!=sizes.end();i++) { + SPItem *item = *i; Geom::OptRect b = item->documentVisualBounds(); if (b) { width = b->dimensions()[Geom::X]; @@ -308,12 +307,14 @@ g_print("\n row = %f col = %f selection x= %f selection y = %f", total_row_h } cnt=0; - for (row_cnt=0; ((sorted != NULL) && (row_cnt<NoOfRows)); row_cnt++) { + std::vector<SPItem*>::iterator it = sorted.begin(); + for (row_cnt=0; ((it != sorted.end()) && (row_cnt<NoOfRows)); row_cnt++) { GSList *current_row = NULL; - for (col_cnt = 0; ((sorted != NULL) && (col_cnt<NoOfCols)); col_cnt++) { - current_row = g_slist_append (current_row, sorted->data); - sorted = sorted->next; + col_cnt = 0; + for(;it!=sorted.end()&&col<NoOfCols;it++) { + current_row = g_slist_append (current_row, *it); + col_cnt++; } for (; current_row != NULL; current_row = current_row->next) { @@ -374,8 +375,8 @@ void GridArrangeTab::on_row_spinbutton_changed() Inkscape::Selection *selection = desktop ? desktop->selection : 0; g_return_if_fail( selection ); - GSList const *items = selection->itemList(); - int selcount = g_slist_length((GSList *)items); + std::vector<SPItem*> const items = selection->itemList(); + int selcount = items.size(); double PerCol = ceil(selcount / NoOfColsSpinner.get_value()); NoOfRowsSpinner.set_value(PerCol); @@ -400,8 +401,7 @@ void GridArrangeTab::on_col_spinbutton_changed() Inkscape::Selection *selection = desktop ? desktop->selection : 0; g_return_if_fail(selection); - GSList const *items = selection->itemList(); - int selcount = g_slist_length((GSList *)items); + int selcount = selection->itemList().size(); double PerRow = ceil(selcount / NoOfRowsSpinner.get_value()); NoOfColsSpinner.set_value(PerRow); @@ -538,10 +538,10 @@ void GridArrangeTab::updateSelection() updating = true; SPDesktop *desktop = Parent->getDesktop(); Inkscape::Selection *selection = desktop ? desktop->selection : 0; - GSList const *items = selection ? selection->itemList() : 0; + std::vector<SPItem*> const items = selection ? selection->itemList() : std::vector<SPItem*>(); - if (items) { - int selcount = g_slist_length((GSList *)items); + if (!items.empty()) { + int selcount = items.size(); if (NoOfColsSpinner.get_value() > 1 && NoOfRowsSpinner.get_value() > 1){ // Update the number of rows assuming number of columns wanted remains same. @@ -609,8 +609,7 @@ GridArrangeTab::GridArrangeTab(ArrangeDialog *parent) g_return_if_fail( selection ); int selcount = 1; if (!selection->isEmpty()) { - GSList const *items = selection->itemList(); - selcount = g_slist_length((GSList *)items); + selcount = selection->itemList().size(); } diff --git a/src/ui/dialog/icon-preview.cpp b/src/ui/dialog/icon-preview.cpp index 069b61cb7..7dc55c95c 100644 --- a/src/ui/dialog/icon-preview.cpp +++ b/src/ui/dialog/icon-preview.cpp @@ -362,16 +362,14 @@ void IconPreviewPanel::refreshPreview() if ( sel ) { //g_message("found a selection to play with"); - GSList const *items = sel->itemList(); - while ( items && !target ) { - SPItem* item = SP_ITEM( items->data ); + std::vector<SPItem*> const items = sel->itemList(); + for(std::vector<SPItem*>::const_iterator i=items.begin();!target && i!=items.end();i++){ + SPItem* item = *i; gchar const *id = item->getId(); if ( id ) { targetId = id; target = item; } - - items = g_slist_next(items); } } } diff --git a/src/ui/dialog/object-attributes.cpp b/src/ui/dialog/object-attributes.cpp index f43a15225..1bc570f43 100644 --- a/src/ui/dialog/object-attributes.cpp +++ b/src/ui/dialog/object-attributes.cpp @@ -127,7 +127,7 @@ void ObjectAttributes::widget_setup (void) blocked = true; // CPPIFY - SPObject *obj = SP_OBJECT(item); //to get the selected item + SPObject *obj = item; //to get the selected item // GObjectClass *klass = G_OBJECT_GET_CLASS(obj); //to deduce the object's type // GType type = G_TYPE_FROM_CLASS(klass); const SPAttrDesc *desc; diff --git a/src/ui/dialog/objects.cpp b/src/ui/dialog/objects.cpp index 9db0285d7..781c6ef93 100644 --- a/src/ui/dialog/objects.cpp +++ b/src/ui/dialog/objects.cpp @@ -477,15 +477,15 @@ void ObjectsPanel::_objectsSelected( Selection *sel ) { _selectedConnection.block(); _tree.get_selection()->unselect_all(); SPItem *item = NULL; - for (const GSList * iter = sel->itemList(); iter != NULL; iter = iter->next) - { - item = reinterpret_cast<SPItem *>(iter->data); + std::vector<SPItem*> const items = sel->itemList(); + for(std::vector<SPItem*>::const_iterator i=items.begin(); i!=items.end();i++){ + item = *i; if (setOpacity) { _setCompositingValues(item); setOpacity = false; } - _store->foreach(sigc::bind<SPItem *, bool>( sigc::mem_fun(*this, &ObjectsPanel::_checkForSelected), item, iter->next == NULL)); + _store->foreach(sigc::bind<SPItem *, bool>( sigc::mem_fun(*this, &ObjectsPanel::_checkForSelected), item, (*i)==items.back())); } if (!item) { if (_desktop->currentLayer() && SP_IS_ITEM(_desktop->currentLayer())) { diff --git a/src/ui/dialog/pixelartdialog.cpp b/src/ui/dialog/pixelartdialog.cpp index 5113f172a..760391df6 100644 --- a/src/ui/dialog/pixelartdialog.cpp +++ b/src/ui/dialog/pixelartdialog.cpp @@ -372,12 +372,12 @@ void PixelArtDialogImpl::vectorize() return; } - for ( GSList const *list = desktop->selection->itemList() ; list - ; list = list->next ) { - if ( !SP_IS_IMAGE(list->data) ) + std::vector<SPItem*> const items = desktop->selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=items.begin(); i!=items.end();i++){ + if ( !SP_IS_IMAGE(*i) ) continue; - SPImage *img = SP_IMAGE(list->data); + SPImage *img = SP_IMAGE(*i); Input input; input.pixbuf = Glib::wrap(img->pixbuf->getPixbufRaw(), true); input.x = img->x; diff --git a/src/ui/dialog/polar-arrange-tab.cpp b/src/ui/dialog/polar-arrange-tab.cpp index 281958998..af1386e27 100644 --- a/src/ui/dialog/polar-arrange-tab.cpp +++ b/src/ui/dialog/polar-arrange-tab.cpp @@ -297,19 +297,18 @@ static void moveToPoint(int anchor, SPItem *item, Geom::Point p) void PolarArrangeTab::arrange() { Inkscape::Selection *selection = parent->getDesktop()->getSelection(); - const GSList *items, *tmp; - tmp = items = selection->itemList(); + const std::vector<SPItem*> tmp(selection->itemList()); SPGenericEllipse *referenceEllipse = NULL; // Last ellipse in selection bool arrangeOnEllipse = !arrangeOnParametersRadio.get_active(); bool arrangeOnFirstEllipse = arrangeOnEllipse && arrangeOnFirstCircleRadio.get_active(); int count = 0; - while(tmp) + for(std::vector<SPItem*>::const_iterator i=tmp.begin();i!=tmp.end();i++) { if(arrangeOnEllipse) { - SPItem *item = SP_ITEM(tmp->data); + SPItem *item = *i; if(arrangeOnFirstEllipse) { @@ -322,7 +321,6 @@ void PolarArrangeTab::arrange() referenceEllipse = SP_GENERICELLIPSE(item); } } - tmp = tmp->next; ++count; } @@ -374,11 +372,10 @@ void PolarArrangeTab::arrange() Geom::Point realCenter = Geom::Point(cx, cy) * transformation; - tmp = items; int i = 0; - while(tmp) + for(std::vector<SPItem*>::const_iterator it=tmp.begin();it!=tmp.end();it++) { - SPItem *item = SP_ITEM(tmp->data); + SPItem *item = *it; // Ignore the reference ellipse if any if(item != referenceEllipse) @@ -396,7 +393,6 @@ void PolarArrangeTab::arrange() ++i; } - tmp = tmp->next; } DocumentUndo::done(parent->getDesktop()->getDocument(), SP_VERB_SELECTION_ARRANGE, diff --git a/src/ui/dialog/print.cpp b/src/ui/dialog/print.cpp index ad979b570..c44d645a5 100644 --- a/src/ui/dialog/print.cpp +++ b/src/ui/dialog/print.cpp @@ -81,7 +81,7 @@ static void draw_page( width, height, (unsigned long)(Inkscape::Util::Quantity::convert(width, "px", "in") * dpi), (unsigned long)(Inkscape::Util::Quantity::convert(height, "px", "in") * dpi), - dpi, dpi, bgcolor, NULL, NULL, true, NULL); + dpi, dpi, bgcolor, NULL, NULL, true, std::vector<SPItem*>()); // This doesn't seem to work: //context->set_cairo_context ( Cairo::Context::create (Cairo::ImageSurface::create_from_png (tmp_png) ), dpi, dpi ); diff --git a/src/ui/dialog/svg-fonts-dialog.cpp b/src/ui/dialog/svg-fonts-dialog.cpp index bc228633d..12b423602 100644 --- a/src/ui/dialog/svg-fonts-dialog.cpp +++ b/src/ui/dialog/svg-fonts-dialog.cpp @@ -524,7 +524,7 @@ void SvgFontsDialog::set_glyph_description_from_selected_path(){ return; } - Inkscape::XML::Node* node = (Inkscape::XML::Node*) g_slist_nth_data((GSList *)sel->reprList(), 0); + Inkscape::XML::Node* node = sel->reprList().front(); if (!node) return;//TODO: should this be an assert? if (!node->matchAttributeName("d") || !node->attribute("d")){ char *msg = _("The selected object does not have a <b>path</b> description."); @@ -566,7 +566,7 @@ void SvgFontsDialog::missing_glyph_description_from_selected_path(){ return; } - Inkscape::XML::Node* node = (Inkscape::XML::Node*) g_slist_nth_data((GSList *)sel->reprList(), 0); + Inkscape::XML::Node* node = sel->reprList().front(); if (!node) return;//TODO: should this be an assert? if (!node->matchAttributeName("d") || !node->attribute("d")){ char *msg = _("The selected object does not have a <b>path</b> description."); diff --git a/src/ui/dialog/swatches.cpp b/src/ui/dialog/swatches.cpp index 8759039c3..72677c07e 100644 --- a/src/ui/dialog/swatches.cpp +++ b/src/ui/dialog/swatches.cpp @@ -123,10 +123,10 @@ static void editGradientImpl( SPDesktop* desktop, SPGradient* gr ) bool shown = false; if ( desktop && desktop->doc() ) { Inkscape::Selection *selection = desktop->getSelection(); - GSList const *items = selection->itemList(); - if (items) { + std::vector<SPItem*> const items = selection->itemList(); + if (!items.empty()) { SPStyle query( desktop->doc() ); - int result = objects_query_fillstroke(const_cast<GSList *>(items), &query, true); + int result = objects_query_fillstroke((items), &query, true); if ( (result == QUERY_STYLE_MULTIPLE_SAME) || (result == QUERY_STYLE_SINGLE) ) { // could be pertinent if (query.fill.isPaintserver()) { diff --git a/src/ui/dialog/tags.cpp b/src/ui/dialog/tags.cpp index 7d3edaffb..ed71c826f 100644 --- a/src/ui/dialog/tags.cpp +++ b/src/ui/dialog/tags.cpp @@ -352,9 +352,10 @@ void TagsPanel::_objectsSelected( Selection *sel ) { _selectedConnection.block(); _tree.get_selection()->unselect_all(); - for (const GSList * iter = sel->list(); iter != NULL; iter = iter->next) + std::vector<SPObject*> tmp=sel->list(); + for(std::vector<SPObject*>::const_iterator i=tmp.begin();i!=tmp.end();i++) { - SPObject *obj = reinterpret_cast<SPObject *>(iter->data); + SPObject *obj = *i; _store->foreach(sigc::bind<SPObject *>( sigc::mem_fun(*this, &TagsPanel::_checkForSelected), obj)); } _selectedConnection.unblock(); @@ -649,9 +650,9 @@ bool TagsPanel::_handleButtonEvent(GdkEventButton* event) if (col == _tree.get_column(COL_ADD - 1) && down_at_add) { if (SP_IS_TAG(obj)) { bool wasadded = false; - for (const GSList * iter = _desktop->selection->itemList(); iter != NULL; iter = iter->next) - { - SPObject *newobj = reinterpret_cast<SPObject *>(iter->data); + std::vector<SPItem*> items=_desktop->selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + SPObject *newobj = *i; bool addchild = true; for ( SPObject *child = obj->children; child != NULL; child = child->next) { if (SP_IS_TAG_USE(child) && SP_TAG_USE(child)->ref->getObject() == newobj) { diff --git a/src/ui/dialog/text-edit.cpp b/src/ui/dialog/text-edit.cpp index a8be8b543..815aa12ef 100644 --- a/src/ui/dialog/text-edit.cpp +++ b/src/ui/dialog/text-edit.cpp @@ -418,12 +418,11 @@ SPItem *TextEdit::getSelectedTextItem (void) if (!SP_ACTIVE_DESKTOP) return NULL; - for (const GSList *item = SP_ACTIVE_DESKTOP->getSelection()->itemList(); - item != NULL; - item = item->next) + std::vector<SPItem*> tmp=SP_ACTIVE_DESKTOP->getSelection()->itemList(); + for(std::vector<SPItem*>::const_iterator i=tmp.begin();i!=tmp.end();i++) { - if (SP_IS_TEXT(item->data) || SP_IS_FLOWTEXT(item->data)) - return SP_ITEM (item->data); + if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) + return *i; } return NULL; @@ -437,11 +436,10 @@ unsigned TextEdit::getSelectedTextCount (void) unsigned int items = 0; - for (const GSList *item = SP_ACTIVE_DESKTOP->getSelection()->itemList(); - item != NULL; - item = item->next) + std::vector<SPItem*> tmp=SP_ACTIVE_DESKTOP->getSelection()->itemList(); + for(std::vector<SPItem*>::const_iterator i=tmp.begin();i!=tmp.end();i++) { - if (SP_IS_TEXT(item->data) || SP_IS_FLOWTEXT(item->data)) + if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) ++items; } @@ -542,20 +540,20 @@ void TextEdit::onApply() SPDesktop *desktop = SP_ACTIVE_DESKTOP; unsigned items = 0; - const GSList *item_list = desktop->getSelection()->itemList(); + const std::vector<SPItem*> item_list = desktop->getSelection()->itemList(); SPCSSAttr *css = fillTextStyle (); sp_desktop_set_style(desktop, css, true); - for (; item_list != NULL; item_list = item_list->next) { + for(std::vector<SPItem*>::const_iterator i=item_list.begin();i!=item_list.end();i++){ // apply style to the reprs of all text objects in the selection - if (SP_IS_TEXT (item_list->data)) { + if (SP_IS_TEXT (*i)) { // backwards compatibility: - reinterpret_cast<SPObject*>(item_list->data)->getRepr()->setAttribute("sodipodi:linespacing", sp_repr_css_property (css, "line-height", NULL)); + (*i)->getRepr()->setAttribute("sodipodi:linespacing", sp_repr_css_property (css, "line-height", NULL)); ++items; } - else if (SP_IS_FLOWTEXT (item_list->data)) + else if (SP_IS_FLOWTEXT (*i)) // no need to set sodipodi:linespacing, because Inkscape never supported it on flowtext ++items; } diff --git a/src/ui/dialog/transformation.cpp b/src/ui/dialog/transformation.cpp index e7ee9529f..498ad7822 100644 --- a/src/ui/dialog/transformation.cpp +++ b/src/ui/dialog/transformation.cpp @@ -651,7 +651,7 @@ void Transformation::updatePageTransform(Inkscape::Selection *selection) { if (selection && !selection->isEmpty()) { if (_check_replace_matrix.get_active()) { - Geom::Affine current (SP_ITEM(selection->itemList()->data)->transform); // take from the first item in selection + Geom::Affine current (selection->itemList()[0]->transform); // take from the first item in selection Geom::Affine new_displayed = current; @@ -736,20 +736,19 @@ void Transformation::applyPageMove(Inkscape::Selection *selection) if (_check_move_relative.get_active()) { // shift each object relatively to the previous one - using Inkscape::Util::GSListConstIterator; - std::list<SPItem *> selected; - selected.insert<GSListConstIterator<SPItem *> >(selected.end(), selection->itemList(), NULL); + std::vector<SPItem*> selected(selection->itemList()); if (selected.empty()) return; if (fabs(x) > 1e-6) { std::vector< BBoxSort > sorted; - for (std::list<SPItem *>::iterator it(selected.begin()); + for (std::vector<SPItem*>::iterator it(selected.begin()); it != selected.end(); ++it) { - Geom::OptRect bbox = (*it)->desktopPreferredBounds(); + SPItem* item = *it; + Geom::OptRect bbox = item->desktopPreferredBounds(); if (bbox) { - sorted.push_back(BBoxSort(*it, *bbox, Geom::X, x > 0? 1. : 0., x > 0? 0. : 1.)); + sorted.push_back(BBoxSort(item, *bbox, Geom::X, x > 0? 1. : 0., x > 0? 0. : 1.)); } } //sort bbox by anchors @@ -767,13 +766,14 @@ void Transformation::applyPageMove(Inkscape::Selection *selection) } if (fabs(y) > 1e-6) { std::vector< BBoxSort > sorted; - for (std::list<SPItem *>::iterator it(selected.begin()); + for (std::vector<SPItem*>::iterator it(selected.begin()); it != selected.end(); ++it) { - Geom::OptRect bbox = (*it)->desktopPreferredBounds(); + SPItem* item = *it; + Geom::OptRect bbox = item->desktopPreferredBounds(); if (bbox) { - sorted.push_back(BBoxSort(*it, *bbox, Geom::Y, y > 0? 1. : 0., y > 0? 0. : 1.)); + sorted.push_back(BBoxSort(item, *bbox, Geom::Y, y > 0? 1. : 0., y > 0? 0. : 1.)); } } //sort bbox by anchors @@ -811,8 +811,9 @@ void Transformation::applyPageScale(Inkscape::Selection *selection) bool transform_stroke = prefs->getBool("/options/transform/stroke", true); bool preserve = prefs->getBool("/options/preservetransform/value", false); if (prefs->getBool("/dialogs/transformation/applyseparately")) { - for (GSList const *l = selection->itemList(); l != NULL; l = l->next) { - SPItem *item = SP_ITEM(l->data); + std::vector<SPItem*> tmp=selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=tmp.begin();i!=tmp.end();i++){ + SPItem *item = *i; Geom::OptRect bbox_pref = item->desktopPreferredBounds(); Geom::OptRect bbox_geom = item->desktopGeometricBounds(); if (bbox_pref && bbox_geom) { @@ -874,8 +875,9 @@ void Transformation::applyPageRotate(Inkscape::Selection *selection) } if (prefs->getBool("/dialogs/transformation/applyseparately")) { - for (GSList const *l = selection->itemList(); l != NULL; l = l->next) { - SPItem *item = SP_ITEM(l->data); + std::vector<SPItem*> tmp=selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=tmp.begin();i!=tmp.end();i++){ + SPItem *item = *i; sp_item_rotate_rel(item, Geom::Rotate (angle*M_PI/180.0)); } } else { @@ -893,8 +895,9 @@ void Transformation::applyPageSkew(Inkscape::Selection *selection) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/dialogs/transformation/applyseparately")) { - for (GSList const *l = selection->itemList(); l != NULL; l = l->next) { - SPItem *item = SP_ITEM(l->data); + std::vector<SPItem*> items=selection->itemList(); + for(std::vector<SPItem*>::const_iterator i = items.begin();i!=items.end();i++){ + SPItem *item = *i; if (!_units_skew.isAbsolute()) { // percentage double skewX = _scalar_skew_horizontal.getValue("%"); @@ -994,10 +997,11 @@ void Transformation::applyPageTransform(Inkscape::Selection *selection) } if (_check_replace_matrix.get_active()) { - for (GSList const *l = selection->itemList(); l != NULL; l = l->next) { - SPItem *item = SP_ITEM(l->data); + std::vector<SPItem*> tmp=selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=tmp.begin();i!=tmp.end();i++){ + SPItem *item = *i; item->set_item_transform(displayed); - SP_OBJECT(item)->updateRepr(); + item->updateRepr(); } } else { sp_selection_apply_affine(selection, displayed); // post-multiply each object's transform @@ -1146,7 +1150,7 @@ void Transformation::onReplaceMatrixToggled() double f = _scalar_transform_f.getValue(); Geom::Affine displayed (a, b, c, d, e, f); - Geom::Affine current = SP_ITEM(selection->itemList()->data)->transform; // take from the first item in selection + Geom::Affine current = selection->itemList()[0]->transform; // take from the first item in selection Geom::Affine new_displayed; if (_check_replace_matrix.get_active()) { diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index 87438ac01..760d19e89 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -1906,11 +1906,10 @@ void ContextMenu::ActivateGroup(void) void ContextMenu::ActivateUngroup(void) { - GSList *children = NULL; + std::vector<SPItem*> children; - sp_item_group_ungroup(static_cast<SPGroup*>(_item), &children); + sp_item_group_ungroup(static_cast<SPGroup*>(_item), children); _desktop->selection->setList(children); - g_slist_free(children); } void ContextMenu::MakeAnchorMenu(void) @@ -1959,10 +1958,9 @@ void ContextMenu::AnchorLinkFollow(void) void ContextMenu::AnchorLinkRemove(void) { - GSList *children = NULL; - sp_item_group_ungroup(static_cast<SPAnchor*>(_item), &children, false); + std::vector<SPItem*> children; + sp_item_group_ungroup(static_cast<SPAnchor*>(_item), children, false); DocumentUndo::done(_desktop->doc(), SP_VERB_NONE, _("Remove link")); - g_slist_free(children); } void ContextMenu::MakeImageMenu (void) @@ -2051,8 +2049,6 @@ void ContextMenu::ImageEdit(void) _desktop->selection->set(_item); } - GSList const *selected = _desktop->selection->itemList(); - GError* errThing = 0; Glib::ustring cmdline = getImageEditorName(); Glib::ustring name; @@ -2079,8 +2075,9 @@ void ContextMenu::ImageEdit(void) } #endif - for (GSList const *iter = selected; iter != NULL; iter = iter->next) { - Inkscape::XML::Node *ir = SP_ITEM(iter->data)->getRepr(); + std::vector<SPItem*> itemlist=_desktop->selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + Inkscape::XML::Node *ir = (*i)->getRepr(); const gchar *href = ir->attribute("xlink:href"); if (strncmp (href,"file:",5) == 0) { diff --git a/src/ui/tools/connector-tool.cpp b/src/ui/tools/connector-tool.cpp index c3ef19507..0a36877ff 100644 --- a/src/ui/tools/connector-tool.cpp +++ b/src/ui/tools/connector-tool.cpp @@ -1303,12 +1303,12 @@ void cc_selection_set_avoid(bool const set_avoid) Inkscape::Selection *selection = desktop->getSelection(); - GSList *l = const_cast<GSList *>(selection->itemList()); int changes = 0; - while (l) { - SPItem *item = SP_ITEM(l->data); + std::vector<SPItem*> l = selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=l.begin();i!=l.end();i++) { + SPItem *item = *i; char const *value = (set_avoid) ? "true" : NULL; @@ -1317,8 +1317,6 @@ void cc_selection_set_avoid(bool const set_avoid) item->avoidRef->handleSettingChange(); changes++; } - - l = l->next; } if (changes == 0) { diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp index af0cbcb78..01b75fdb4 100644 --- a/src/ui/tools/eraser-tool.cpp +++ b/src/ui/tools/eraser-tool.cpp @@ -666,8 +666,7 @@ void EraserTool::set_to_accumulated() { Geom::OptRect eraserBbox = acid->visualBounds(); Geom::Rect bounds = (*eraserBbox) * desktop->doc2dt(); std::vector<SPItem*> remainingItems; - GSList* toWorkOn = 0; - + std::vector<SPItem*> toWorkOn; if (selection->isEmpty()) { if ( eraserMode ) { toWorkOn = desktop->getDocument()->getItemsPartiallyInBox(desktop->dkey, bounds); @@ -675,17 +674,16 @@ void EraserTool::set_to_accumulated() { Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop); toWorkOn = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints()); } - - toWorkOn = g_slist_remove( toWorkOn, acid ); + toWorkOn.erase(find(toWorkOn.begin(),toWorkOn.end(),acid)); } else { - toWorkOn = g_slist_copy(const_cast<GSList*>(selection->itemList())); + toWorkOn= selection->itemList(); wasSelection = true; } - if ( g_slist_length(toWorkOn) > 0 ) { + if ( !toWorkOn.empty() ) { if ( eraserMode ) { - for (GSList *i = toWorkOn ; i ; i = i->next ) { - SPItem *item = SP_ITEM(i->data); + for (std::vector<SPItem*>::const_iterator i = toWorkOn.begin(); i != toWorkOn.end(); i++){ + SPItem *item = *i; if ( eraserMode ) { Geom::OptRect bbox = item->visualBounds(); @@ -702,13 +700,10 @@ void EraserTool::set_to_accumulated() { if ( !selection->isEmpty() ) { // If the item was not completely erased, track the new remainder. - GSList *nowSel = g_slist_copy(const_cast<GSList *>(selection->itemList())); - - for (GSList const *i2 = nowSel ; i2 ; i2 = i2->next ) { - remainingItems.push_back(SP_ITEM(i2->data)); + std::vector<SPItem*> nowSel(selection->itemList()); + for (std::vector<SPItem*>::const_iterator i2 = nowSel.begin();i2!=nowSel.end();i2++) { + remainingItems.push_back(*i2); } - - g_slist_free(nowSel); } } else { remainingItems.push_back(item); @@ -716,20 +711,18 @@ void EraserTool::set_to_accumulated() { } } } else { - for (GSList *i = toWorkOn ; i ; i = i->next ) { - sp_object_ref( SP_ITEM(i->data), 0 ); + for (std::vector<SPItem*> ::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();i++) { + sp_object_ref( *i, 0 ); } - for (GSList *i = toWorkOn ; i ; i = i->next ) { - SPItem *item = SP_ITEM(i->data); + for (std::vector<SPItem*>::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();i++) { + SPItem *item = *i; item->deleteObject(true); sp_object_unref(item); workDone = true; } } - g_slist_free(toWorkOn); - if ( !eraserMode ) { //sp_selection_delete(desktop); remainingItems.clear(); diff --git a/src/ui/tools/gradient-tool.cpp b/src/ui/tools/gradient-tool.cpp index b27859ebb..526671515 100644 --- a/src/ui/tools/gradient-tool.cpp +++ b/src/ui/tools/gradient-tool.cpp @@ -106,7 +106,7 @@ void GradientTool::selection_changed(Inkscape::Selection*) { if (selection == NULL) { return; } - guint n_obj = g_slist_length((GSList *) selection->itemList()); + guint n_obj = selection->itemList().size(); if (!drag->isNonEmpty() || selection->isEmpty()) return; @@ -492,10 +492,11 @@ bool GradientTool::root_handler(GdkEvent* event) { if (over_line) { // we take the first item in selection, because with doubleclick, the first click // always resets selection to the single object under cursor - sp_gradient_context_add_stop_near_point(this, SP_ITEM(selection->itemList()->data), this->mousepoint_doc, event->button.time); + sp_gradient_context_add_stop_near_point(this, SP_ITEM(selection->itemList().front()), this->mousepoint_doc, event->button.time); } else { - for (GSList const* i = selection->itemList(); i != NULL; i = i->next) { - SPItem *item = SP_ITEM(i->data); + std::vector<SPItem*> items=selection->itemList(); + for (std::vector<SPItem*>::const_iterator i = items.begin();i!=items.end();i++) { + SPItem *item = *i; SPGradientType new_type = (SPGradientType) prefs->getInt("/tools/gradient/newgradient", SP_GRADIENT_TYPE_LINEAR); Inkscape::PaintTarget fsmode = (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE; @@ -898,32 +899,32 @@ static void sp_gradient_drag(GradientTool &rc, Geom::Point const pt, guint /*sta } else { // Starting from empty space: // Sort items so that the topmost comes last - GSList *items = g_slist_copy ((GSList *) selection->itemList()); - items = g_slist_sort(items, (GCompareFunc) sp_item_repr_compare_position); + std::vector<SPItem*> items(selection->itemList()); + sort(items.begin(),items.end(),sp_item_repr_compare_position); // take topmost - vector = sp_gradient_vector_for_object(document, desktop, SP_ITEM(g_slist_last(items)->data), fill_or_stroke); - g_slist_free (items); + vector = sp_gradient_vector_for_object(document, desktop, SP_ITEM(items.back()), fill_or_stroke); } // HACK: reset fill-opacity - that 0.75 is annoying; BUT remove this when we have an opacity slider for all tabs SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_set_property(css, "fill-opacity", "1.0"); - for (GSList const *i = selection->itemList(); i != NULL; i = i->next) { + std::vector<SPItem*> itemlist = selection->itemList(); + for (std::vector<SPItem*>::const_iterator i = itemlist.begin();i!=itemlist.end();i++) { //FIXME: see above - sp_repr_css_change_recursive(SP_OBJECT(i->data)->getRepr(), css, "style"); + sp_repr_css_change_recursive((*i)->getRepr(), css, "style"); - sp_item_set_gradient(SP_ITEM(i->data), vector, (SPGradientType) type, fill_or_stroke); + sp_item_set_gradient(*i, vector, (SPGradientType) type, fill_or_stroke); if (type == SP_GRADIENT_TYPE_LINEAR) { - sp_item_gradient_set_coords (SP_ITEM(i->data), POINT_LG_BEGIN, 0, rc.origin, fill_or_stroke, true, false); - sp_item_gradient_set_coords (SP_ITEM(i->data), POINT_LG_END, 0, pt, fill_or_stroke, true, false); + sp_item_gradient_set_coords (*i, POINT_LG_BEGIN, 0, rc.origin, fill_or_stroke, true, false); + sp_item_gradient_set_coords (*i, POINT_LG_END, 0, pt, fill_or_stroke, true, false); } else if (type == SP_GRADIENT_TYPE_RADIAL) { - sp_item_gradient_set_coords (SP_ITEM(i->data), POINT_RG_CENTER, 0, rc.origin, fill_or_stroke, true, false); - sp_item_gradient_set_coords (SP_ITEM(i->data), POINT_RG_R1, 0, pt, fill_or_stroke, true, false); + sp_item_gradient_set_coords (*i, POINT_RG_CENTER, 0, rc.origin, fill_or_stroke, true, false); + sp_item_gradient_set_coords (*i, POINT_RG_R1, 0, pt, fill_or_stroke, true, false); } - SP_OBJECT(i->data)->requestModified(SP_OBJECT_MODIFIED_FLAG); + (*i)->requestModified(SP_OBJECT_MODIFIED_FLAG); } if (ec->_grdrag) { ec->_grdrag->updateDraggers(); @@ -932,7 +933,7 @@ static void sp_gradient_drag(GradientTool &rc, Geom::Point const pt, guint /*sta ec->_grdrag->local_change = true; // give the grab out-of-bounds values of xp/yp because we're already dragging // and therefore are already out of tolerance - ec->_grdrag->grabKnot (SP_ITEM(selection->itemList()->data), + ec->_grdrag->grabKnot (selection->itemList()[0], type == SP_GRADIENT_TYPE_LINEAR? POINT_LG_END : POINT_RG_R1, -1, // ignore number (though it is always 1) fill_or_stroke, 99999, 99999, etime); @@ -941,7 +942,7 @@ static void sp_gradient_drag(GradientTool &rc, Geom::Point const pt, guint /*sta // status text; we do not track coords because this branch is run once, not all the time // during drag - int n_objects = g_slist_length((GSList *) selection->itemList()); + int n_objects = selection->itemList().size(); rc.message_context->setF(Inkscape::NORMAL_MESSAGE, ngettext("<b>Gradient</b> for %d object; with <b>Ctrl</b> to snap angle", "<b>Gradient</b> for %d objects; with <b>Ctrl</b> to snap angle", n_objects), diff --git a/src/ui/tools/lpe-tool.cpp b/src/ui/tools/lpe-tool.cpp index c0517578d..13e47f3a6 100644 --- a/src/ui/tools/lpe-tool.cpp +++ b/src/ui/tools/lpe-tool.cpp @@ -396,10 +396,10 @@ lpetool_create_measuring_items(LpeTool *lc, Inkscape::Selection *selection) SPCanvasGroup *tmpgrp = lc->desktop->getTempGroup(); gchar *arc_length; double lengthval; - - for (GSList const *i = selection->itemList(); i != NULL; i = i->next) { - if (SP_IS_PATH(i->data)) { - path = SP_PATH(i->data); + std::vector<SPItem*> items=selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + if (SP_IS_PATH(*i)) { + path = SP_PATH(*i); curve = path->getCurve(); Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = paths_to_pw(curve->get_pathvector()); canvas_text = (SPCanvasText *) sp_canvastext_new(tmpgrp, lc->desktop, Geom::Point(0,0), ""); diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 0875c29e0..570f3e796 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -431,10 +431,10 @@ bool MeasureTool::root_handler(GdkEvent* event) { // TODO switch to a different variable name. The single letter 'l' is easy to misread. //select elements crossed by line segment: - GSList *items = desktop->getDocument()->getItemsAtPoints(desktop->dkey, points); + std::vector<SPItem*> items = desktop->getDocument()->getItemsAtPoints(desktop->dkey, points); std::vector<double> intersection_times; - for (GSList *l = items; l != NULL; l = l->next) { - SPItem *item = static_cast<SPItem*>(l->data); + for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++) { + SPItem *item = *i; if (SP_IS_SHAPE(item)) { calculate_intersections(desktop, item, lineseg, SP_SHAPE(item)->getCurve(), intersection_times); diff --git a/src/ui/tools/mesh-tool.cpp b/src/ui/tools/mesh-tool.cpp index 67ed7aef1..0e68af601 100644 --- a/src/ui/tools/mesh-tool.cpp +++ b/src/ui/tools/mesh-tool.cpp @@ -103,7 +103,7 @@ void MeshTool::selection_changed(Inkscape::Selection* /*sel*/) { return; } - guint n_obj = g_slist_length((GSList *) selection->itemList()); + guint n_obj = selection->itemList().size(); if (!drag->isNonEmpty() || selection->isEmpty()) { return; @@ -467,11 +467,12 @@ bool MeshTool::root_handler(GdkEvent* event) { if (over_line) { // We take the first item in selection, because with doubleclick, the first click // always resets selection to the single object under cursor - sp_mesh_context_split_near_point(this, SP_ITEM(selection->itemList()->data), this->mousepoint_doc, event->button.time); + sp_mesh_context_split_near_point(this, selection->itemList()[0], this->mousepoint_doc, event->button.time); } else { // Create a new gradient with default coordinates. - for (GSList const* i = selection->itemList(); i != NULL; i = i->next) { - SPItem *item = SP_ITEM(i->data); + std::vector<SPItem*> items=selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + SPItem *item = *i; SPGradientType new_type = SP_GRADIENT_TYPE_MESH; Inkscape::PaintTarget fsmode = (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE; @@ -940,27 +941,27 @@ static void sp_mesh_drag(MeshTool &rc, Geom::Point const /*pt*/, guint /*state*/ } else { // Starting from empty space: // Sort items so that the topmost comes last - GSList *items = g_slist_copy ((GSList *) selection->itemList()); - items = g_slist_sort(items, (GCompareFunc) sp_item_repr_compare_position); + std::vector<SPItem*> items(selection->itemList()); + sort(items.begin(),items.end(),sp_item_repr_compare_position); // take topmost - vector = sp_gradient_vector_for_object(document, desktop, SP_ITEM(g_slist_last(items)->data), fill_or_stroke); - g_slist_free (items); + vector = sp_gradient_vector_for_object(document, desktop, SP_ITEM(items.back()), fill_or_stroke); } // HACK: reset fill-opacity - that 0.75 is annoying; BUT remove this when we have an opacity slider for all tabs SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_set_property(css, "fill-opacity", "1.0"); - for (GSList const *i = selection->itemList(); i != NULL; i = i->next) { + std::vector<SPItem*> items=selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ //FIXME: see above - sp_repr_css_change_recursive(SP_OBJECT(i->data)->getRepr(), css, "style"); + sp_repr_css_change_recursive((*i)->getRepr(), css, "style"); - sp_item_set_gradient(SP_ITEM(i->data), vector, (SPGradientType) type, fill_or_stroke); + sp_item_set_gradient(*i, vector, (SPGradientType) type, fill_or_stroke); // We don't need to do anything. Mesh is already sized appropriately. - SP_OBJECT(i->data)->requestModified(SP_OBJECT_MODIFIED_FLAG); + (*i)->requestModified(SP_OBJECT_MODIFIED_FLAG); } // if (ec->_grdrag) { // ec->_grdrag->updateDraggers(); @@ -978,7 +979,7 @@ static void sp_mesh_drag(MeshTool &rc, Geom::Point const /*pt*/, guint /*state*/ // status text; we do not track coords because this branch is run once, not all the time // during drag - int n_objects = g_slist_length((GSList *) selection->itemList()); + int n_objects = selection->itemList().size(); rc.message_context->setF(Inkscape::NORMAL_MESSAGE, ngettext("<b>Gradient</b> for %d object; with <b>Ctrl</b> to snap angle", "<b>Gradient</b> for %d objects; with <b>Ctrl</b> to snap angle", n_objects), diff --git a/src/ui/tools/node-tool.cpp b/src/ui/tools/node-tool.cpp index a4b903960..ef00eaa40 100644 --- a/src/ui/tools/node-tool.cpp +++ b/src/ui/tools/node-tool.cpp @@ -410,10 +410,9 @@ void NodeTool::selection_changed(Inkscape::Selection *sel) { std::set<ShapeRecord> shapes; - GSList const *ilist = sel->itemList(); - - for (GSList *i = const_cast<GSList*>(ilist); i; i = i->next) { - SPObject *obj = static_cast<SPObject*>(i->data); + std::vector<SPItem*> items=sel->itemList(); + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + SPObject *obj = *i; if (SP_IS_ITEM(obj)) { gather_items(this, NULL, static_cast<SPItem*>(obj), SHAPE_ROLE_NORMAL, shapes); @@ -658,9 +657,8 @@ void NodeTool::select_area(Geom::Rect const &sel, GdkEventButton *event) { if (this->_multipath->empty()) { // if multipath is empty, select rubberbanded items rather than nodes Inkscape::Selection *selection = this->desktop->selection; - GSList *items = this->desktop->getDocument()->getItemsInBox(this->desktop->dkey, sel); + std::vector<SPItem*> items = this->desktop->getDocument()->getItemsInBox(this->desktop->dkey, sel); selection->setList(items); - g_slist_free(items); } else { if (!held_shift(*event)) { this->_selected_nodes->clear(); diff --git a/src/ui/tools/select-tool.cpp b/src/ui/tools/select-tool.cpp index 40b994968..f8375a1bb 100644 --- a/src/ui/tools/select-tool.cpp +++ b/src/ui/tools/select-tool.cpp @@ -472,7 +472,7 @@ bool SelectTool::root_handler(GdkEvent* event) { case GDK_2BUTTON_PRESS: if (event->button.button == 1) { if (!selection->isEmpty()) { - SPItem *clicked_item = static_cast<SPItem *>(selection->itemList()->data); + SPItem *clicked_item = selection->itemList()[0]; if (dynamic_cast<SPGroup *>(clicked_item) && !dynamic_cast<SPBox3D *>(clicked_item)) { // enter group if it's not a 3D box desktop->setCurrentLayer(clicked_item); @@ -709,7 +709,7 @@ bool SelectTool::root_handler(GdkEvent* event) { if (r->is_started() && !within_tolerance) { // this was a rubberband drag - GSList *items = NULL; + std::vector<SPItem*> items; if (r->getMode() == RUBBERBAND_MODE_RECT) { Geom::OptRect const b = r->getRectangle(); @@ -730,7 +730,6 @@ bool SelectTool::root_handler(GdkEvent* event) { selection->setList (items); } - g_slist_free (items); } else { // it was just a click, or a too small rubberband r->stop(); diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 0399b1e55..26d74733a 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -178,7 +178,7 @@ void SprayTool::update_cursor(bool /*with_shift*/) { gchar *sel_message = NULL; if (!desktop->selection->isEmpty()) { - num = g_slist_length(const_cast<GSList *>(desktop->selection->itemList())); + num = desktop->selection->itemList().size(); sel_message = g_strdup_printf(ngettext("<b>%i</b> object selected","<b>%i</b> objects selected",num), num); } else { sel_message = g_strdup_printf("%s", _("<b>Nothing</b> selected")); @@ -426,11 +426,9 @@ static bool sp_spray_recursive(SPDesktop *desktop, SPItem *unionResult = NULL; // Previous union int i=1; - for (GSList *items = g_slist_copy(const_cast<GSList *>(selection->itemList())); - items != NULL; - items = items->next) { - - SPItem *item1 = dynamic_cast<SPItem *>(static_cast<SPObject *>(items->data)); + std::vector<SPItem*> items=selection->itemList(); + for(std::vector<SPItem*>::const_iterator it=items.begin();it!=items.end();it++){ + SPItem *item1 = *it; if (i == 1) { parent_item = item1; } @@ -544,20 +542,16 @@ static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point double move_standard_deviation = get_move_standard_deviation(tc); { - GSList *const original_selection = g_slist_copy(const_cast<GSList *>(selection->itemList())); + std::vector<SPItem*> const items(selection->itemList()); - for (GSList *items = original_selection; - items != NULL; - items = items->next) { - SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(items->data)); + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + SPItem *item = *i; g_assert(item != NULL); sp_object_ref(item); } - for (GSList *items = original_selection; - items != NULL; - items = items->next) { - SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(items->data)); + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + SPItem *item = *i; g_assert(item != NULL); if (is_transform_modes(tc->mode)) { @@ -571,10 +565,8 @@ static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point } } - for (GSList *items = original_selection; - items != NULL; - items = items->next) { - SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(items->data)); + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + SPItem *item = *i; g_assert(item != NULL); sp_object_unref(item); } @@ -650,7 +642,7 @@ bool SprayTool::root_handler(GdkEvent* event) { guint num = 0; if (!desktop->selection->isEmpty()) { - num = g_slist_length(const_cast<GSList *>(desktop->selection->itemList())); + num = desktop->selection->itemList().size(); } if (num == 0) { this->message_context->flash(Inkscape::ERROR_MESSAGE, _("<b>Nothing selected!</b> Select objects to spray.")); diff --git a/src/ui/tools/text-tool.cpp b/src/ui/tools/text-tool.cpp index a2c0c81ae..1888551cf 100644 --- a/src/ui/tools/text-tool.cpp +++ b/src/ui/tools/text-tool.cpp @@ -1461,7 +1461,7 @@ int TextTool::_styleQueried(SPStyle *style, int property) } sp_text_context_validate_cursor_iterators(this); - GSList *styles_list = NULL; + std::vector<SPItem*> styles_list; Inkscape::Text::Layout::iterator begin_it, end_it; if (this->text_sel_start < this->text_sel_end) { @@ -1477,7 +1477,7 @@ int TextTool::_styleQueried(SPStyle *style, int property) } } for (Inkscape::Text::Layout::iterator it = begin_it ; it < end_it ; it.nextStartOfSpan()) { - SPObject const *pos_obj = 0; + SPObject *pos_obj = 0; void *rawptr = 0; layout->getSourceOfCharacter(it, &rawptr); if (!rawptr || !SP_IS_OBJECT(rawptr)) { @@ -1487,12 +1487,11 @@ int TextTool::_styleQueried(SPStyle *style, int property) while (SP_IS_STRING(pos_obj) && pos_obj->parent) { pos_obj = pos_obj->parent; // SPStrings don't have style } - styles_list = g_slist_prepend(styles_list, (gpointer)pos_obj); + styles_list.insert(styles_list.begin(),(SPItem*)pos_obj); } int result = sp_desktop_query_style_from_list (styles_list, style, property); - g_slist_free(styles_list); return result; } diff --git a/src/ui/tools/tool-base.cpp b/src/ui/tools/tool-base.cpp index 2eb6d24d9..0f9b3ee7a 100644 --- a/src/ui/tools/tool-base.cpp +++ b/src/ui/tools/tool-base.cpp @@ -1174,11 +1174,9 @@ SPItem *sp_event_context_find_item(SPDesktop *desktop, Geom::Point const &p, SPItem * sp_event_context_over_item(SPDesktop *desktop, SPItem *item, Geom::Point const &p) { - GSList *temp = NULL; - temp = g_slist_prepend(temp, item); + std::vector<SPItem*> temp; + temp.push_back(item); SPItem *item_at_point = desktop->getItemFromListAtPointBottom(temp, p); - g_slist_free(temp); - return item_at_point; } diff --git a/src/ui/tools/tweak-tool.cpp b/src/ui/tools/tweak-tool.cpp index 80b52fba6..76b52f9be 100644 --- a/src/ui/tools/tweak-tool.cpp +++ b/src/ui/tools/tweak-tool.cpp @@ -153,7 +153,7 @@ void TweakTool::update_cursor (bool with_shift) { gchar *sel_message = NULL; if (!desktop->selection->isEmpty()) { - num = g_slist_length(const_cast<GSList *>(desktop->selection->itemList())); + num = desktop->selection->itemList().size(); sel_message = g_strdup_printf(ngettext("<b>%i</b> object selected","<b>%i</b> objects selected",num), num); } else { sel_message = g_strdup_printf("%s", _("<b>Nothing</b> selected")); @@ -372,14 +372,13 @@ sp_tweak_dilate_recursive (Inkscape::Selection *selection, SPItem *item, Geom::P } if (dynamic_cast<SPText *>(item) || dynamic_cast<SPFlowtext *>(item)) { - GSList *items = g_slist_prepend (NULL, item); - GSList *selected = NULL; - GSList *to_select = NULL; + std::vector<SPItem*> items; + items.push_back(item); + std::vector<SPItem*> selected; + std::vector<Inkscape::XML::Node*> to_select; SPDocument *doc = item->document; - sp_item_list_to_curves (items, &selected, &to_select); - g_slist_free (items); - SPObject* newObj = doc->getObjectByRepr(static_cast<Inkscape::XML::Node *>(to_select->data)); - g_slist_free (to_select); + sp_item_list_to_curves (items, selected, to_select); + SPObject* newObj = doc->getObjectByRepr(to_select[0]); item = dynamic_cast<SPItem *>(newObj); g_assert(item != NULL); selection->add(item); @@ -1078,11 +1077,9 @@ sp_tweak_dilate (TweakTool *tc, Geom::Point event_p, Geom::Point p, Geom::Point double move_force = get_move_force(tc); double color_force = MIN(sqrt(path_force)/20.0, 1); - for (GSList *items = g_slist_copy(const_cast<GSList *>(selection->itemList())); - items != NULL; - items = items->next) { - - SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(items->data)); + std::vector<SPItem*> items=selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + SPItem *item = *i; if (is_color_mode (tc->mode)) { if (do_fill || do_stroke || do_opacity) { @@ -1189,7 +1186,7 @@ bool TweakTool::root_handler(GdkEvent* event) { guint num = 0; if (!desktop->selection->isEmpty()) { - num = g_slist_length(const_cast<GSList *>(desktop->selection->itemList())); + num = desktop->selection->itemList().size(); } if (num == 0) { this->message_context->flash(Inkscape::ERROR_MESSAGE, _("<b>Nothing selected!</b> Select objects to tweak.")); diff --git a/src/ui/widget/object-composite-settings.cpp b/src/ui/widget/object-composite-settings.cpp index 00a74c4fe..598a90e95 100644 --- a/src/ui/widget/object-composite-settings.cpp +++ b/src/ui/widget/object-composite-settings.cpp @@ -125,7 +125,8 @@ ObjectCompositeSettings::_blendBlurValueChanged() const Glib::ustring blendmode = _fe_cb.get_blend_mode(); //apply created filter to every selected item - for (StyleSubject::iterator i = _subject->begin() ; i != _subject->end() ; ++i ) { + std::vector<SPItem*> sel=_subject->getDesktop()->getSelection()->itemList(); + for (std::vector<SPItem*>::const_iterator i = sel.begin() ; i != sel.end() ; ++i ) { if (!SP_IS_ITEM(*i)) { continue; } diff --git a/src/ui/widget/style-subject.cpp b/src/ui/widget/style-subject.cpp index a48370d9b..95b89bf5f 100644 --- a/src/ui/widget/style-subject.cpp +++ b/src/ui/widget/style-subject.cpp @@ -54,7 +54,7 @@ Inkscape::Selection *StyleSubject::Selection::_getSelection() const { return NULL; } } - +/* StyleSubject::iterator StyleSubject::Selection::begin() { Inkscape::Selection *selection = _getSelection(); if (selection) { @@ -62,7 +62,7 @@ StyleSubject::iterator StyleSubject::Selection::begin() { } else { return iterator(NULL); } -} +}*/ Geom::OptRect StyleSubject::Selection::getBounds(SPItem::BBoxType type) { Inkscape::Selection *selection = _getSelection(); @@ -104,8 +104,7 @@ void StyleSubject::Selection::setCSS(SPCSSAttr *css) { } StyleSubject::CurrentLayer::CurrentLayer() { - _element.data = NULL; - _element.next = NULL; + _element = NULL; } StyleSubject::CurrentLayer::~CurrentLayer() { @@ -114,10 +113,10 @@ StyleSubject::CurrentLayer::~CurrentLayer() { void StyleSubject::CurrentLayer::_setLayer(SPObject *layer) { _layer_release.disconnect(); _layer_modified.disconnect(); - if (_element.data) { - sp_object_unref(static_cast<SPObject *>(_element.data), NULL); + if (_element) { + sp_object_unref(_element, NULL); } - _element.data = layer; + _element = layer; if (layer) { sp_object_ref(layer, NULL); _layer_release = layer->connectRelease(sigc::hide(sigc::bind(sigc::mem_fun(*this, &CurrentLayer::_setLayer), (SPObject *)NULL))); @@ -127,20 +126,17 @@ void StyleSubject::CurrentLayer::_setLayer(SPObject *layer) { } SPObject *StyleSubject::CurrentLayer::_getLayer() const { - return static_cast<SPObject *>(_element.data); + return _element; } -GSList *StyleSubject::CurrentLayer::_getLayerSList() const { - if (_element.data) { - return &_element; - } else { - return NULL; - } -} +SPObject *StyleSubject::CurrentLayer::_getLayerSList() const { + return _element; +} +/* StyleSubject::iterator StyleSubject::CurrentLayer::begin() { return iterator(_getLayerSList()); -} +}*/ Geom::OptRect StyleSubject::CurrentLayer::getBounds(SPItem::BBoxType type) { SPObject *layer = _getLayer(); @@ -152,8 +148,10 @@ Geom::OptRect StyleSubject::CurrentLayer::getBounds(SPItem::BBoxType type) { } int StyleSubject::CurrentLayer::queryStyle(SPStyle *query, int property) { - GSList *list = _getLayerSList(); - if (list) { + std::vector<SPItem*> list; + SPObject* i=_getLayerSList(); + if (i) { + list.push_back((SPItem*)i); return sp_desktop_query_style_from_list(list, query, property); } else { return QUERY_STYLE_NOTHING; diff --git a/src/ui/widget/style-subject.h b/src/ui/widget/style-subject.h index 47da91732..60f979eb0 100644 --- a/src/ui/widget/style-subject.h +++ b/src/ui/widget/style-subject.h @@ -35,7 +35,8 @@ public: class Selection; class CurrentLayer; - typedef Util::GSListConstIterator<SPObject *> iterator; + //typedef Util::GSListConstIterator<SPObject *> iterator; + typedef std::list<SPObject*>::iterator iterator; StyleSubject(); virtual ~StyleSubject(); @@ -43,8 +44,8 @@ public: void setDesktop(SPDesktop *desktop); SPDesktop *getDesktop() const { return _desktop; } - virtual iterator begin() = 0; - virtual iterator end() { return iterator(NULL); } +// virtual iterator begin() = 0; +// virtual iterator end() { return iterator(NULL); } virtual Geom::OptRect getBounds(SPItem::BBoxType type) = 0; virtual int queryStyle(SPStyle *query, int property) = 0; virtual void setCSS(SPCSSAttr *css) = 0; @@ -67,7 +68,7 @@ public: Selection(); ~Selection(); - virtual iterator begin(); +// virtual iterator begin(); virtual Geom::OptRect getBounds(SPItem::BBoxType type); virtual int queryStyle(SPStyle *query, int property); virtual void setCSS(SPCSSAttr *css); @@ -88,7 +89,7 @@ public: CurrentLayer(); ~CurrentLayer(); - virtual iterator begin(); +// virtual iterator begin(); virtual Geom::OptRect getBounds(SPItem::BBoxType type); virtual int queryStyle(SPStyle *query, int property); virtual void setCSS(SPCSSAttr *css); @@ -99,12 +100,12 @@ protected: private: SPObject *_getLayer() const; void _setLayer(SPObject *layer); - GSList *_getLayerSList() const; + SPObject *_getLayerSList() const; sigc::connection _layer_switched; sigc::connection _layer_release; sigc::connection _layer_modified; - mutable GSList _element; + mutable SPObject* _element; }; } diff --git a/src/unclump.cpp b/src/unclump.cpp index 940369d7a..81c958937 100644 --- a/src/unclump.cpp +++ b/src/unclump.cpp @@ -168,13 +168,12 @@ unclump_dist (SPItem *item1, SPItem *item2) /** Average unclump_dist from item to others */ -static double unclump_average (SPItem *item, GSList *others) +static double unclump_average (SPItem *item, std::list<SPItem*> &others) { int n = 0; double sum = 0; - - for (GSList *i = others; i != NULL; i = i->next) { - SPItem *other = SP_ITEM (i->data); + for (std::list<SPItem*>::const_iterator i = others.begin(); i != others.end();i++) { + SPItem *other = *i; if (other == item) continue; @@ -192,13 +191,13 @@ static double unclump_average (SPItem *item, GSList *others) /** Closest to item among others */ -static SPItem *unclump_closest (SPItem *item, GSList *others) +static SPItem *unclump_closest (SPItem *item, std::list<SPItem*> &others) { double min = HUGE_VAL; SPItem *closest = NULL; - for (GSList *i = others; i != NULL; i = i->next) { - SPItem *other = SP_ITEM (i->data); + for (std::list<SPItem*>::const_iterator i = others.begin(); i != others.end();i++) { + SPItem *other = *i; if (other == item) continue; @@ -216,13 +215,12 @@ static SPItem *unclump_closest (SPItem *item, GSList *others) /** Most distant from item among others */ -static SPItem *unclump_farest (SPItem *item, GSList *others) +static SPItem *unclump_farest (SPItem *item, std::list<SPItem*> &others) { double max = -HUGE_VAL; SPItem *farest = NULL; - - for (GSList *i = others; i != NULL; i = i->next) { - SPItem *other = SP_ITEM (i->data); + for (std::list<SPItem*>::const_iterator i = others.begin(); i != others.end();i++) { + SPItem *other = *i; if (other == item) continue; @@ -242,8 +240,8 @@ Removes from the \a rest list those items that are "behind" \a closest as seen f i.e. those on the other side of the line through \a closest perpendicular to the direction from \a item to \a closest. Returns a newly created list which must be freed. */ -static GSList * -unclump_remove_behind (SPItem *item, SPItem *closest, GSList *rest) +static std::vector<SPItem*> +unclump_remove_behind (SPItem *item, SPItem *closest, std::list<SPItem*> &rest) { Geom::Point it = unclump_center (item); Geom::Point p1 = unclump_center (closest); @@ -260,10 +258,9 @@ unclump_remove_behind (SPItem *item, SPItem *closest, GSList *rest) // substitute the item into it: double val_item = A * it[Geom::X] + B * it[Geom::Y] + C; - GSList *out = NULL; - - for (GSList *i = rest; i != NULL; i = i->next) { - SPItem *other = SP_ITEM (i->data); + std::vector<SPItem*> out; + for (std::list<SPItem*>::const_reverse_iterator i = rest.rbegin(); i != rest.rend();i++) { + SPItem *other = *i; if (other == item) continue; @@ -274,7 +271,7 @@ unclump_remove_behind (SPItem *item, SPItem *closest, GSList *rest) if (val_item * val_other <= 1e-6) { // different signs, which means item and other are on the different sides of p1-p2 line; skip } else { - out = g_slist_prepend (out, other); + out.push_back(other); } } @@ -334,34 +331,34 @@ similar to "engraver dots". The only distribution which is unchanged by unclumpi grid. May be called repeatedly for stronger effect. */ void -unclump (GSList *items) +unclump (std::vector<SPItem*> &items) { c_cache.clear(); wh_cache.clear(); - for (GSList *i = items; i != NULL; i = i->next) { // for each original/clone x: - SPItem *item = SP_ITEM (i->data); + for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end();i++) { // for each original/clone x: + SPItem *item = *i; - GSList *nei = NULL; + std::list<SPItem*> nei; - GSList *rest = g_slist_copy (items); - rest = g_slist_remove (rest, item); + std::list<SPItem*> rest; + for(int i=0;i<items.size();i++)rest.push_front(items[items.size()-i-1]); + rest.remove(item); - while (rest != NULL) { + while (!rest.empty()) { SPItem *closest = unclump_closest (item, rest); if (closest) { - nei = g_slist_prepend (nei, closest); - rest = g_slist_remove (rest, closest); - GSList *new_rest = unclump_remove_behind (item, closest, rest); - g_slist_free (rest); - rest = new_rest; + nei.push_front(closest); + rest.remove(closest); + std::vector<SPItem*> new_rest = unclump_remove_behind (item, closest, rest); + rest.clear(); + for(int i=0;i<new_rest.size();i++)rest.push_front(new_rest[new_rest.size()-i-1]); } else { - g_slist_free (rest); break; } } - if (g_slist_length (nei) >= 2) { + if ( (nei.size()) >= 2) { double ave = unclump_average (item, nei); SPItem *closest = unclump_closest (item, nei); diff --git a/src/unclump.h b/src/unclump.h index 2411cb713..461e99d0b 100644 --- a/src/unclump.h +++ b/src/unclump.h @@ -13,7 +13,7 @@ typedef struct _GSList GSList; -void unclump(GSList *items); +void unclump(std::vector<SPItem*> &items); #endif /* !UNCLUMP_H_SEEN */ diff --git a/src/vanishing-point.cpp b/src/vanishing-point.cpp index b62aacbc5..46f895c06 100644 --- a/src/vanishing-point.cpp +++ b/src/vanishing-point.cpp @@ -256,8 +256,9 @@ VanishingPoint::set_pos(Proj::Pt2 const &pt) { std::list<SPBox3D *> VanishingPoint::selectedBoxes(Inkscape::Selection *sel) { std::list<SPBox3D *> sel_boxes; - for (GSList const* i = sel->itemList(); i != NULL; i = i->next) { - SPItem *item = static_cast<SPItem *>(i->data); + std::vector<SPItem*> itemlist=sel->itemList(); + for (std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { + SPItem *item = *i; SPBox3D *box = dynamic_cast<SPBox3D *>(item); if (box && this->hasBox(box)) { sel_boxes.push_back(box); @@ -395,8 +396,9 @@ VPDragger::VPsOfSelectedBoxes() { VanishingPoint *vp; // FIXME: Should we take the selection from the parent VPDrag? I guess it shouldn't make a difference. Inkscape::Selection *sel = SP_ACTIVE_DESKTOP->getSelection(); - for (GSList const* i = sel->itemList(); i != NULL; i = i->next) { - SPItem *item = static_cast<SPItem *>(i->data); + std::vector<SPItem*> itemlist=sel->itemList(); + for (std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { + SPItem *item = *i; SPBox3D *box = dynamic_cast<SPBox3D *>(item); if (box) { vp = this->findVPWithBox(box); @@ -577,8 +579,9 @@ VPDrag::updateDraggers () g_return_if_fail (this->selection != NULL); - for (GSList const* i = this->selection->itemList(); i != NULL; i = i->next) { - SPItem *item = static_cast<SPItem *>(i->data); + std::vector<SPItem*> itemlist=this->selection->itemList(); + for (std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { + SPItem *item = *i; SPBox3D *box = dynamic_cast<SPBox3D *>(item); if (box) { VanishingPoint vp; @@ -609,8 +612,9 @@ VPDrag::updateLines () g_return_if_fail (this->selection != NULL); - for (GSList const* i = this->selection->itemList(); i != NULL; i = i->next) { - SPItem *item = static_cast<SPItem *>(i->data); + std::vector<SPItem*> itemlist=this->selection->itemList(); + for (std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { + SPItem *item = *i; SPBox3D *box = dynamic_cast<SPBox3D *>(item); if (box) { this->drawLinesForFace (box, Proj::X); @@ -626,11 +630,11 @@ VPDrag::updateBoxHandles () // FIXME: Is there a way to update the knots without accessing the // (previously) statically linked function KnotHolder::update_knots? - GSList *sel = (GSList *) selection->itemList(); - if (!sel) + std::vector<SPItem*> sel = selection->itemList(); + if (sel.empty()) return; // no selection - if (g_slist_length (sel) > 1) { + if (sel.size() > 1) { // Currently we only show handles if a single box is selected return; } diff --git a/src/widgets/arc-toolbar.cpp b/src/widgets/arc-toolbar.cpp index 8a64854be..71418e238 100644 --- a/src/widgets/arc-toolbar.cpp +++ b/src/widgets/arc-toolbar.cpp @@ -97,12 +97,9 @@ sp_arctb_startend_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *v gchar* namespaced_name = g_strconcat("sodipodi:", value_name, NULL); bool modmade = false; - for (GSList const *items = desktop->getSelection()->itemList(); - items != NULL; - items = items->next) - { - SPItem *item = SP_ITEM(items->data); - + std::vector<SPItem*> itemlist=desktop->getSelection()->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = *i; if (SP_IS_GENERICELLIPSE(item)) { SPGenericEllipse *ge = SP_GENERICELLIPSE(item); @@ -166,11 +163,9 @@ static void sp_arctb_open_state_changed( EgeSelectOneAction *act, GObject *tbl ) bool modmade = false; if ( ege_select_one_action_get_active(act) != 0 ) { - for (GSList const *items = desktop->getSelection()->itemList(); - items != NULL; - items = items->next) - { - SPItem *item = reinterpret_cast<SPItem*>(items->data); + std::vector<SPItem*> itemlist=desktop->getSelection()->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = *i; if (SP_IS_GENERICELLIPSE(item)) { Inkscape::XML::Node *repr = item->getRepr(); repr->setAttribute("sodipodi:open", "true"); @@ -179,11 +174,9 @@ static void sp_arctb_open_state_changed( EgeSelectOneAction *act, GObject *tbl ) } } } else { - for (GSList const *items = desktop->getSelection()->itemList(); - items != NULL; - items = items->next) - { - SPItem *item = reinterpret_cast<SPItem *>(items->data); + std::vector<SPItem*> itemlist=desktop->getSelection()->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = *i; if (SP_IS_GENERICELLIPSE(item)) { Inkscape::XML::Node *repr = item->getRepr(); repr->setAttribute("sodipodi:open", NULL); @@ -271,11 +264,9 @@ static void sp_arc_toolbox_selection_changed(Inkscape::Selection *selection, GOb purge_repr_listener( tbl, tbl ); - for (GSList const *items = selection->itemList(); - items != NULL; - items = items->next) - { - SPItem *item = reinterpret_cast<SPItem *>(items->data); + std::vector<SPItem*> itemlist=selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = *i; if (SP_IS_GENERICELLIPSE(item)) { n_selected++; repr = item->getRepr(); diff --git a/src/widgets/connector-toolbar.cpp b/src/widgets/connector-toolbar.cpp index c906f7de4..1c99f283d 100644 --- a/src/widgets/connector-toolbar.cpp +++ b/src/widgets/connector-toolbar.cpp @@ -76,7 +76,6 @@ static void sp_connector_path_set_ignore(void) static void sp_connector_orthogonal_toggled( GtkToggleAction* act, GObject *tbl ) { SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" )); - Inkscape::Selection * selection = desktop->getSelection(); SPDocument *doc = desktop->getDocument(); if (!DocumentUndo::getUndoSensitive(doc)) { @@ -98,9 +97,9 @@ static void sp_connector_orthogonal_toggled( GtkToggleAction* act, GObject *tbl gchar *value = is_orthog ? orthog_str : polyline_str ; bool modmade = false; - GSList *l = (GSList *) selection->itemList(); - while (l) { - SPItem *item = SP_ITEM(l->data); + std::vector<SPItem*> itemlist=desktop->getSelection()->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = *i; if (Inkscape::UI::Tools::cc_item_is_connector(item)) { item->setAttribute( "inkscape:connector-type", @@ -108,7 +107,6 @@ static void sp_connector_orthogonal_toggled( GtkToggleAction* act, GObject *tbl item->avoidRef->handleSettingChange(); modmade = true; } - l = l->next; } if (!modmade) { @@ -126,7 +124,6 @@ static void sp_connector_orthogonal_toggled( GtkToggleAction* act, GObject *tbl static void connector_curvature_changed(GtkAdjustment *adj, GObject* tbl) { SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" )); - Inkscape::Selection * selection = desktop->getSelection(); SPDocument *doc = desktop->getDocument(); if (!DocumentUndo::getUndoSensitive(doc)) { @@ -147,9 +144,9 @@ static void connector_curvature_changed(GtkAdjustment *adj, GObject* tbl) g_ascii_dtostr(value, G_ASCII_DTOSTR_BUF_SIZE, newValue); bool modmade = false; - GSList *l = (GSList *) selection->itemList(); - while (l) { - SPItem *item = SP_ITEM(l->data); + std::vector<SPItem*> itemlist=desktop->getSelection()->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = *i; if (Inkscape::UI::Tools::cc_item_is_connector(item)) { item->setAttribute( "inkscape:connector-curvature", @@ -157,7 +154,6 @@ static void connector_curvature_changed(GtkAdjustment *adj, GObject* tbl) item->avoidRef->handleSettingChange(); modmade = true; } - l = l->next; } if (!modmade) { diff --git a/src/widgets/fill-style.cpp b/src/widgets/fill-style.cpp index b92b0a474..b1f812338 100644 --- a/src/widgets/fill-style.cpp +++ b/src/widgets/fill-style.cpp @@ -477,7 +477,7 @@ void FillNStroke::updateFromPaint() SPDocument *document = desktop->getDocument(); Inkscape::Selection *selection = desktop->getSelection(); - GSList const *items = selection->itemList(); + std::vector<SPItem*> const items = selection->itemList(); switch (psel->mode) { case SPPaintSelector::MODE_EMPTY: @@ -539,7 +539,7 @@ void FillNStroke::updateFromPaint() case SPPaintSelector::MODE_GRADIENT_LINEAR: case SPPaintSelector::MODE_GRADIENT_RADIAL: case SPPaintSelector::MODE_SWATCH: - if (items) { + if (!items.empty()) { SPGradientType const gradient_type = ( psel->mode != SPPaintSelector::MODE_GRADIENT_RADIAL ? SP_GRADIENT_TYPE_LINEAR : SP_GRADIENT_TYPE_RADIAL ); @@ -557,7 +557,7 @@ void FillNStroke::updateFromPaint() /* No vector in paint selector should mean that we just changed mode */ SPStyle query(desktop->doc()); - int result = objects_query_fillstroke(const_cast<GSList *>(items), &query, kind == FILL); + int result = objects_query_fillstroke(items, &query, kind == FILL); if (result == QUERY_STYLE_MULTIPLE_SAME) { SPIPaint &targPaint = (kind == FILL) ? query.fill : query.stroke; SPColor common; @@ -572,39 +572,39 @@ void FillNStroke::updateFromPaint() } } - for (GSList const *i = items; i != NULL; i = i->next) { + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ //FIXME: see above if (kind == FILL) { - sp_repr_css_change_recursive(reinterpret_cast<SPObject*>(i->data)->getRepr(), css, "style"); + sp_repr_css_change_recursive((*i)->getRepr(), css, "style"); } if (!vector) { SPGradient *gr = sp_gradient_vector_for_object( document, desktop, - reinterpret_cast<SPObject*>(i->data), + reinterpret_cast<SPObject*>(*i), (kind == FILL) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE, createSwatch ); if ( gr && createSwatch ) { gr->setSwatch(); } - sp_item_set_gradient(SP_ITEM(i->data), + sp_item_set_gradient(*i, gr, gradient_type, (kind == FILL) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE); } else { - sp_item_set_gradient(SP_ITEM(i->data), vector, gradient_type, (kind == FILL) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE); + sp_item_set_gradient(*i, vector, gradient_type, (kind == FILL) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE); } } } else { // We have changed from another gradient type, or modified spread/units within // this gradient type. vector = sp_gradient_ensure_vector_normalized(vector); - for (GSList const *i = items; i != NULL; i = i->next) { + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ //FIXME: see above if (kind == FILL) { - sp_repr_css_change_recursive(reinterpret_cast<SPObject*>(i->data)->getRepr(), css, "style"); + sp_repr_css_change_recursive((*i)->getRepr(), css, "style"); } - SPGradient *gr = sp_item_set_gradient(SP_ITEM(i->data), vector, gradient_type, (kind == FILL) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE); + SPGradient *gr = sp_item_set_gradient(*i, vector, gradient_type, (kind == FILL) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE); psel->pushAttrsToGradient( gr ); } } @@ -621,7 +621,7 @@ void FillNStroke::updateFromPaint() case SPPaintSelector::MODE_PATTERN: - if (items) { + if (!items.empty()) { SPPattern *pattern = psel->getPattern(); if (!pattern) { @@ -644,12 +644,12 @@ void FillNStroke::updateFromPaint() // cannot just call sp_desktop_set_style, because we don't want to touch those // objects who already have the same root pattern but through a different href // chain. FIXME: move this to a sp_item_set_pattern - for (GSList const *i = items; i != NULL; i = i->next) { - Inkscape::XML::Node *selrepr = reinterpret_cast<SPObject*>(i->data)->getRepr(); + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + Inkscape::XML::Node *selrepr = (*i)->getRepr(); if ( (kind == STROKE) && !selrepr) { continue; } - SPObject *selobj = reinterpret_cast<SPObject*>(i->data); + SPObject *selobj = *i; SPStyle *style = selobj->style; if (style && ((kind == FILL) ? style->fill : style->stroke).isPaintserver()) { @@ -682,7 +682,7 @@ void FillNStroke::updateFromPaint() break; case SPPaintSelector::MODE_UNSET: - if (items) { + if (!items.empty()) { SPCSSAttr *css = sp_repr_css_attr_new(); if (kind == FILL) { sp_repr_css_unset_property(css, "fill"); diff --git a/src/widgets/gradient-toolbar.cpp b/src/widgets/gradient-toolbar.cpp index 7ce04403b..6743dd23a 100644 --- a/src/widgets/gradient-toolbar.cpp +++ b/src/widgets/gradient-toolbar.cpp @@ -116,8 +116,9 @@ void gr_apply_gradient(Inkscape::Selection *selection, GrDrag *drag, SPGradient } // If no drag or no dragger selected, act on selection - for (GSList const* i = selection->itemList(); i != NULL; i = i->next) { - gr_apply_gradient_to_item(SP_ITEM(i->data), gr, initialType, initialMode, initialMode); + std::vector<SPItem*> itemlist=selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + gr_apply_gradient_to_item(*i, gr, initialType, initialMode, initialMode); } } @@ -217,8 +218,9 @@ void gr_get_dt_selected_gradient(Inkscape::Selection *selection, SPGradient *&gr { SPGradient *gradient = 0; - for (GSList const* i = selection->itemList(); i; i = i->next) { - SPItem *item = SP_ITEM(i->data); // get the items gradient, not the getVector() version + std::vector<SPItem*> itemlist=selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = *i;// get the items gradient, not the getVector() version SPStyle *style = item->style; SPPaintServer *server = 0; @@ -284,8 +286,9 @@ void gr_read_selection( Inkscape::Selection *selection, } // If no selected dragger, read desktop selection - for (GSList const* i = selection->itemList(); i; i = i->next) { - SPItem *item = SP_ITEM(i->data); + std::vector<SPItem*> itemlist=selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = *i; SPStyle *style = item->style; if (style && (style->fill.isPaintserver())) { diff --git a/src/widgets/mesh-toolbar.cpp b/src/widgets/mesh-toolbar.cpp index bf406e632..1af55d9cd 100644 --- a/src/widgets/mesh-toolbar.cpp +++ b/src/widgets/mesh-toolbar.cpp @@ -87,8 +87,9 @@ void ms_read_selection( Inkscape::Selection *selection, bool first = true; ms_type = SP_MESH_TYPE_COONS; - for (GSList const* i = selection->itemList(); i; i = i->next) { - SPItem *item = SP_ITEM(i->data); + std::vector<SPItem*> itemlist=selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = *i; SPStyle *style = item->style; if (style && (style->fill.isPaintserver())) { @@ -213,8 +214,9 @@ void ms_get_dt_selected_gradient(Inkscape::Selection *selection, SPMesh *&ms_sel { SPMesh *gradient = 0; - for (GSList const* i = selection->itemList(); i; i = i->next) { - SPItem *item = SP_ITEM(i->data); // get the items gradient, not the getVector() version + std::vector<SPItem*> itemlist=selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = *i;// get the items gradient, not the getVector() version SPStyle *style = item->style; SPPaintServer *server = 0; diff --git a/src/widgets/rect-toolbar.cpp b/src/widgets/rect-toolbar.cpp index 46f6d1c23..96ba699dc 100644 --- a/src/widgets/rect-toolbar.cpp +++ b/src/widgets/rect-toolbar.cpp @@ -106,12 +106,13 @@ static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const * bool modmade = false; Inkscape::Selection *selection = desktop->getSelection(); - for (GSList const *items = selection->itemList(); items != NULL; items = items->next) { - if (SP_IS_RECT(items->data)) { + std::vector<SPItem*> itemlist=selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + if (SP_IS_RECT(*i)) { if (gtk_adjustment_get_value(adj) != 0) { - (SP_RECT(items->data)->*setter)(Quantity::convert(gtk_adjustment_get_value(adj), unit, "px")); + (SP_RECT(*i)->*setter)(Quantity::convert(gtk_adjustment_get_value(adj), unit, "px")); } else { - SP_OBJECT(items->data)->getRepr()->setAttribute(value_name, NULL); + (*i)->getRepr()->setAttribute(value_name, NULL); } modmade = true; } @@ -242,12 +243,11 @@ static void sp_rect_toolbox_selection_changed(Inkscape::Selection *selection, GO } purge_repr_listener( tbl, tbl ); - for (GSList const *items = selection->itemList(); - items != NULL; - items = items->next) { - if (SP_IS_RECT(reinterpret_cast<SPItem *>(items->data))) { + std::vector<SPItem*> itemlist=selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + if (SP_IS_RECT(*i)) { n_selected++; - item = reinterpret_cast<SPItem *>(items->data); + item = *i; repr = item->getRepr(); } } diff --git a/src/widgets/spiral-toolbar.cpp b/src/widgets/spiral-toolbar.cpp index 3fb0015c1..751a60f06 100644 --- a/src/widgets/spiral-toolbar.cpp +++ b/src/widgets/spiral-toolbar.cpp @@ -79,11 +79,9 @@ static void sp_spl_tb_value_changed(GtkAdjustment *adj, GObject *tbl, Glib::ustr gchar* namespaced_name = g_strconcat("sodipodi:", value_name.data(), NULL); bool modmade = false; - for (GSList const *items = desktop->getSelection()->itemList(); - items != NULL; - items = items->next) - { - SPItem *item = reinterpret_cast<SPItem*>(items->data); + std::vector<SPItem*> itemlist=desktop->getSelection()->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = *i; if (SP_IS_SPIRAL(item)) { Inkscape::XML::Node *repr = item->getRepr(); sp_repr_set_svg_double( repr, namespaced_name, @@ -197,11 +195,9 @@ static void sp_spiral_toolbox_selection_changed(Inkscape::Selection *selection, purge_repr_listener( tbl, tbl ); - for (GSList const *items = selection->itemList(); - items != NULL; - items = items->next) - { - SPItem *item = reinterpret_cast<SPItem*>(items->data); + std::vector<SPItem*> itemlist=selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = *i; if (SP_IS_SPIRAL(item)) { n_selected++; repr = item->getRepr(); diff --git a/src/widgets/star-toolbar.cpp b/src/widgets/star-toolbar.cpp index cf12391c1..96005d7df 100644 --- a/src/widgets/star-toolbar.cpp +++ b/src/widgets/star-toolbar.cpp @@ -83,9 +83,9 @@ static void sp_stb_magnitude_value_changed( GtkAdjustment *adj, GObject *dataKlu bool modmade = false; Inkscape::Selection *selection = desktop->getSelection(); - GSList const *items = selection->itemList(); - for (; items != NULL; items = items->next) { - SPItem *item = reinterpret_cast<SPItem*>(items->data); + std::vector<SPItem*> itemlist=selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = *i; if (SP_IS_STAR(item)) { Inkscape::XML::Node *repr = item->getRepr(); sp_repr_set_int(repr,"sodipodi:sides", @@ -128,9 +128,9 @@ static void sp_stb_proportion_value_changed( GtkAdjustment *adj, GObject *dataKl bool modmade = false; Inkscape::Selection *selection = desktop->getSelection(); - GSList const *items = selection->itemList(); - for (; items != NULL; items = items->next) { - SPItem *item = reinterpret_cast<SPItem *>(items->data); + std::vector<SPItem*> itemlist=selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = *i; if (SP_IS_STAR(item)) { Inkscape::XML::Node *repr = item->getRepr(); @@ -178,7 +178,6 @@ static void sp_stb_sides_flat_state_changed( EgeSelectOneAction *act, GObject *d g_object_set_data( dataKludge, "freeze", GINT_TO_POINTER(TRUE) ); Inkscape::Selection *selection = desktop->getSelection(); - GSList const *items = selection->itemList(); GtkAction* prop_action = GTK_ACTION( g_object_get_data( dataKludge, "prop_action" ) ); bool modmade = false; @@ -186,8 +185,9 @@ static void sp_stb_sides_flat_state_changed( EgeSelectOneAction *act, GObject *d gtk_action_set_sensitive( prop_action, !flat ); } - for (; items != NULL; items = items->next) { - SPItem *item = reinterpret_cast<SPItem *>(items->data); + std::vector<SPItem*> itemlist=selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = *i; if (SP_IS_STAR(item)) { Inkscape::XML::Node *repr = item->getRepr(); repr->setAttribute("inkscape:flatsided", flat ? "true" : "false" ); @@ -224,9 +224,9 @@ static void sp_stb_rounded_value_changed( GtkAdjustment *adj, GObject *dataKludg bool modmade = false; Inkscape::Selection *selection = desktop->getSelection(); - GSList const *items = selection->itemList(); - for (; items != NULL; items = items->next) { - SPItem *item = reinterpret_cast<SPItem*>(items->data); + std::vector<SPItem*> itemlist=selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = *i; if (SP_IS_STAR(item)) { Inkscape::XML::Node *repr = item->getRepr(); sp_repr_set_svg_double(repr, "inkscape:rounded", @@ -264,9 +264,9 @@ static void sp_stb_randomized_value_changed( GtkAdjustment *adj, GObject *dataKl bool modmade = false; Inkscape::Selection *selection = desktop->getSelection(); - GSList const *items = selection->itemList(); - for (; items != NULL; items = items->next) { - SPItem *item = reinterpret_cast<SPItem *>(items->data); + std::vector<SPItem*> itemlist=selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = *i; if (SP_IS_STAR(item)) { Inkscape::XML::Node *repr = item->getRepr(); sp_repr_set_svg_double(repr, "inkscape:randomized", @@ -367,11 +367,9 @@ sp_star_toolbox_selection_changed(Inkscape::Selection *selection, GObject *tbl) purge_repr_listener( tbl, tbl ); - for (GSList const *items = selection->itemList(); - items != NULL; - items = items->next) - { - SPItem* item = reinterpret_cast<SPItem *>(items->data); + std::vector<SPItem*> itemlist=selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = *i; if (SP_IS_STAR(item)) { n_selected++; repr = item->getRepr(); diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index 5ca06a795..482ca7af4 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -475,9 +475,9 @@ void StrokeStyle::markerSelectCB(MarkerComboBox *marker_combo, StrokeStyle *spw, //spw->updateMarkerHist(which); Inkscape::Selection *selection = spw->desktop->getSelection(); - GSList const *items = selection->itemList(); - for (; items != NULL; items = items->next) { - SPItem *item = reinterpret_cast<SPItem *>(items->data); + std::vector<SPItem*> itemlist=selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = *i; if (!SP_IS_SHAPE(item) || SP_IS_RECT(item)) { // can't set marker to rect, until it's converted to using <path> continue; } @@ -901,8 +901,8 @@ StrokeStyle::updateLine() if (!sel || sel->isEmpty()) return; - GSList const *objects = sel->itemList(); - SPObject * const object = SP_OBJECT(objects->data); + std::vector<SPItem*> const objects = sel->itemList(); + SPObject * const object = objects[0]; SPStyle * const style = object->style; /* Markers */ @@ -957,13 +957,12 @@ StrokeStyle::scaleLine() SPDocument *document = desktop->getDocument(); Inkscape::Selection *selection = desktop->getSelection(); - - GSList const *items = selection->itemList(); + std::vector<SPItem*> items=selection->itemList(); /* TODO: Create some standardized method */ SPCSSAttr *css = sp_repr_css_attr_new(); - if (items) { + if (!items.empty()) { #if WITH_GTKMM_3_0 double width_typed = (*widthAdj)->get_value(); double const miterlimit = (*miterLimitAdj)->get_value(); @@ -978,13 +977,13 @@ StrokeStyle::scaleLine() int ndash; dashSelector->get_dash(&ndash, &dash, &offset); - for (GSList const *i = items; i != NULL; i = i->next) { + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ /* Set stroke width */ double width; if (unit->type == Inkscape::Util::UNIT_TYPE_LINEAR) { width = Inkscape::Util::Quantity::convert(width_typed, unit, "px"); } else { // percentage - gdouble old_w = SP_OBJECT(i->data)->style->stroke_width.computed; + gdouble old_w = (*i)->style->stroke_width.computed; width = old_w * width_typed / 100; } @@ -1003,7 +1002,7 @@ StrokeStyle::scaleLine() /* Set dash */ setScaledDash(css, ndash, dash, offset, width); - sp_desktop_apply_css_recursive (SP_OBJECT(i->data), css, true); + sp_desktop_apply_css_recursive ((*i), css, true); } g_free(dash); @@ -1144,7 +1143,7 @@ StrokeStyle::setCapButtons(Gtk::ToggleButton *active) * that marker. */ void -StrokeStyle::updateAllMarkers(GSList const *objects) +StrokeStyle::updateAllMarkers(std::vector<SPItem*> const &objects) { struct { MarkerComboBox *key; int loc; } const keyloc[] = { { startMarkerCombo, SP_MARKER_LOC_START }, @@ -1153,9 +1152,10 @@ StrokeStyle::updateAllMarkers(GSList const *objects) }; bool all_texts = true; - for (GSList *i = (GSList *) objects; i != NULL; i = i->next) { - if (!SP_IS_TEXT (i->data)) { + for(std::vector<SPItem*>::const_iterator i=objects.begin();i!=objects.end();i++){ + if (!SP_IS_TEXT (*i)) { all_texts = false; + break; } } @@ -1167,7 +1167,7 @@ StrokeStyle::updateAllMarkers(GSList const *objects) // We show markers of the first object in the list only // FIXME: use the first in the list that has the marker of each type, if any - SPObject *object = SP_OBJECT(objects->data); + SPObject *object = objects[0]; for (unsigned i = 0; i < G_N_ELEMENTS(keyloc); ++i) { // For all three marker types, diff --git a/src/widgets/stroke-style.h b/src/widgets/stroke-style.h index 83048cb76..2605e1acf 100644 --- a/src/widgets/stroke-style.h +++ b/src/widgets/stroke-style.h @@ -153,7 +153,7 @@ private: }; void updateLine(); - void updateAllMarkers(GSList const *objects); + void updateAllMarkers(std::vector<SPItem*> const &objects); void updateMarkerHist(SPMarkerLoc const which); void setDashSelectorFromStyle(SPDashSelector *dsel, SPStyle *style); void setJoinType (unsigned const jointype); diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index ec011fffd..7b22e4af7 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -372,9 +372,10 @@ static void sp_text_align_mode_changed( EgeSelectOneAction *act, GObject *tbl ) // move the x of all texts to preserve the same bbox Inkscape::Selection *selection = desktop->getSelection(); - for (GSList const *items = selection->itemList(); items != NULL; items = items->next) { - if (SP_IS_TEXT(SP_ITEM(items->data))) { - SPItem *item = SP_ITEM(items->data); + std::vector<SPItem*> itemlist=selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + if (SP_IS_TEXT(*i)) { + SPItem *item = *i; unsigned writing_mode = item->style->writing_mode.value; // below, variable names suggest horizontal move, but we check the writing direction @@ -523,11 +524,11 @@ static void sp_text_lineheight_value_changed( GtkAdjustment *adj, GObject *tbl ) // Until deprecated sodipodi:linespacing purged: Inkscape::Selection *selection = desktop->getSelection(); - GSList const *items = selection->itemList(); bool modmade = false; - for (; items != NULL; items = items->next) { - if (SP_IS_TEXT (items->data)) { - SP_OBJECT(items->data)->getRepr()->setAttribute("sodipodi:linespacing", sp_repr_css_property (css, "line-height", NULL)); + std::vector<SPItem*> itemlist=selection->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + if (SP_IS_TEXT (*i)) { + (*i)->getRepr()->setAttribute("sodipodi:linespacing", sp_repr_css_property (css, "line-height", NULL)); modmade = true; } } @@ -869,12 +870,11 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ // Only flowed text can be justified, only normal text can be kerned... // Find out if we have flowed text now so we can use it several places gboolean isFlow = false; - for (GSList const *items = SP_ACTIVE_DESKTOP->getSelection()->itemList(); - items != NULL; - items = items->next) { + std::vector<SPItem*> itemlist=SP_ACTIVE_DESKTOP->getSelection()->itemList(); + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ // const gchar* id = reinterpret_cast<SPItem *>(items->data)->getId(); // std::cout << " " << id << std::endl; - if( SP_IS_FLOWTEXT(SP_ITEM(items->data))) { + if( SP_IS_FLOWTEXT(*i)) { isFlow = true; // std::cout << " Found flowed text" << std::endl; break; @@ -1159,14 +1159,14 @@ static void sp_text_toolbox_select_cb( GtkEntry* entry, GtkEntryIconPosition /*p //std::cout << "text_toolbox_missing_font_cb: selecting: " << family << std::endl; // Get all items with matching font-family set (not inherited!). - GSList *selectList = NULL; + std::vector<SPItem*> selectList; SPDesktop *desktop = SP_ACTIVE_DESKTOP; SPDocument *document = desktop->getDocument(); - GSList *allList = get_all_items(NULL, document->getRoot(), desktop, false, false, true, NULL); - for (GSList *i = allList; i != NULL; i = i->next) { - - SPItem *item = SP_ITEM(i->data); + std::vector<SPItem*> x,y; + std::vector<SPItem*> allList = get_all_items(x, document->getRoot(), desktop, false, false, true, y); + for(std::vector<SPItem*>::const_reverse_iterator i=allList.rbegin();i!=allList.rend();i++){ + SPItem *item = *i; SPStyle *style = item->style; if (style) { @@ -1183,7 +1183,7 @@ static void sp_text_toolbox_select_cb( GtkEntry* entry, GtkEntryIconPosition /*p if (family_style.compare( family ) == 0 ) { //std::cout << " found: " << item->getId() << std::endl; - selectList = g_slist_prepend (selectList, item); + selectList.push_back(item); } } } diff --git a/src/xml/repr-util.cpp b/src/xml/repr-util.cpp index 7c5d2d6fc..3858f08a7 100644 --- a/src/xml/repr-util.cpp +++ b/src/xml/repr-util.cpp @@ -260,7 +260,7 @@ gchar const *sp_xml_ns_prefix_uri(gchar const *prefix) * -1 first object's position is less than the second * @todo Rewrite this function's description to be understandable */ -int sp_repr_compare_position(Inkscape::XML::Node const *first, Inkscape::XML::Node const *second) +bool sp_repr_compare_position(Inkscape::XML::Node const *first, Inkscape::XML::Node const *second) { int p1, p2; if (first->parent() == second->parent()) { @@ -277,9 +277,9 @@ int sp_repr_compare_position(Inkscape::XML::Node const *first, Inkscape::XML::No g_assert(ancestor != NULL); if (ancestor == first) { - return 1; + return false; } else if (ancestor == second) { - return -1; + return true; } else { Inkscape::XML::Node const *to_first = AncetreFils(first, ancestor); Inkscape::XML::Node const *to_second = AncetreFils(second, ancestor); @@ -289,9 +289,9 @@ int sp_repr_compare_position(Inkscape::XML::Node const *first, Inkscape::XML::No } } - if (p1 > p2) return 1; - if (p1 < p2) return -1; - return 0; + if (p1 > p2) return false; + if (p1 < p2) return true; + return false; /* effic: Assuming that the parent--child relationship is consistent (i.e. that the parent really does contain first and second among diff --git a/src/xml/repr.h b/src/xml/repr.h index c3ba40e45..fbe25ec12 100644 --- a/src/xml/repr.h +++ b/src/xml/repr.h @@ -120,7 +120,8 @@ unsigned sp_repr_set_svg_length(Inkscape::XML::Node *repr, char const *key, SVGL unsigned sp_repr_set_point(Inkscape::XML::Node *repr, char const *key, Geom::Point const & val); unsigned sp_repr_get_point(Inkscape::XML::Node *repr, char const *key, Geom::Point *val); -int sp_repr_compare_position(Inkscape::XML::Node const *first, Inkscape::XML::Node const *second); +//c++-style comparison : returns (bool)(a<b) +bool sp_repr_compare_position(Inkscape::XML::Node const *first, Inkscape::XML::Node const *second); // Searching /** |
