summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/conn-avoid-ref.cpp5
-rw-r--r--src/desktop-style.cpp120
-rw-r--r--src/desktop-style.h25
-rw-r--r--src/extension/execution-env.cpp8
-rw-r--r--src/extension/implementation/implementation.cpp7
-rw-r--r--src/extension/implementation/script.cpp7
-rw-r--r--src/extension/internal/bitmap/imagemagick.cpp16
-rw-r--r--src/extension/internal/bluredge.cpp7
-rw-r--r--src/extension/internal/cairo-renderer.cpp8
-rw-r--r--src/extension/internal/filter/filter.cpp8
-rw-r--r--src/extension/internal/grid.cpp7
-rw-r--r--src/extension/internal/latex-text-renderer.cpp8
-rw-r--r--src/file.cpp6
-rw-r--r--src/filter-chemistry.cpp2
-rw-r--r--src/gradient-chemistry.cpp12
-rw-r--r--src/gradient-drag.cpp17
-rw-r--r--src/graphlayout.cpp10
-rw-r--r--src/graphlayout.h4
-rw-r--r--src/helper/png-write.cpp12
-rw-r--r--src/helper/png-write.h9
-rw-r--r--src/live_effects/lpe-knot.cpp6
-rw-r--r--src/main.cpp23
-rw-r--r--src/object-snapper.cpp5
-rw-r--r--src/path-chemistry.cpp125
-rw-r--r--src/path-chemistry.h2
-rw-r--r--src/removeoverlap.cpp12
-rw-r--r--src/removeoverlap.h2
-rw-r--r--src/selcue.cpp19
-rw-r--r--src/selection-chemistry.cpp779
-rw-r--r--src/selection-chemistry.h11
-rw-r--r--src/selection-describer.cpp34
-rw-r--r--src/selection.cpp159
-rw-r--r--src/selection.h38
-rw-r--r--src/seltrans.cpp54
-rw-r--r--src/seltrans.h2
-rw-r--r--src/snap.cpp14
-rw-r--r--src/snap.h8
-rw-r--r--src/sp-conn-end.cpp5
-rw-r--r--src/sp-defs.cpp9
-rw-r--r--src/sp-filter.cpp9
-rw-r--r--src/sp-item-group.cpp91
-rw-r--r--src/sp-item-group.h5
-rw-r--r--src/sp-lpe-item.cpp30
-rw-r--r--src/sp-marker.cpp6
-rw-r--r--src/sp-marker.h2
-rw-r--r--src/sp-object.cpp6
-rw-r--r--src/sp-object.h10
-rw-r--r--src/sp-pattern.cpp6
-rw-r--r--src/sp-pattern.h2
-rw-r--r--src/sp-switch.cpp24
-rw-r--r--src/sp-switch.h2
-rw-r--r--src/splivarot.cpp102
-rw-r--r--src/text-chemistry.cpp83
-rw-r--r--src/text-editing.cpp7
-rw-r--r--src/trace/trace.cpp8
-rw-r--r--src/ui/clipboard.cpp33
-rw-r--r--src/ui/dialog/align-and-distribute.cpp87
-rw-r--r--src/ui/dialog/clonetiler.cpp14
-rw-r--r--src/ui/dialog/export.cpp28
-rw-r--r--src/ui/dialog/filter-effects-dialog.cpp27
-rw-r--r--src/ui/dialog/find.cpp92
-rw-r--r--src/ui/dialog/find.h11
-rw-r--r--src/ui/dialog/glyphs.cpp12
-rw-r--r--src/ui/interface.cpp17
-rw-r--r--src/unclump.cpp57
-rw-r--r--src/unclump.h3
-rw-r--r--src/vanishing-point.cpp26
-rw-r--r--src/widgets/arc-toolbar.cpp33
-rw-r--r--src/widgets/connector-toolbar.cpp16
-rw-r--r--src/widgets/fill-style.cpp32
-rw-r--r--src/widgets/gradient-toolbar.cpp15
-rw-r--r--src/widgets/mesh-toolbar.cpp10
-rw-r--r--src/widgets/rect-toolbar.cpp18
-rw-r--r--src/widgets/spiral-toolbar.cpp16
-rw-r--r--src/widgets/star-toolbar.cpp38
-rw-r--r--src/widgets/stroke-style.cpp29
-rw-r--r--src/widgets/stroke-style.h2
-rw-r--r--src/widgets/text-toolbar.cpp34
78 files changed, 1283 insertions, 1365 deletions
diff --git a/src/conn-avoid-ref.cpp b/src/conn-avoid-ref.cpp
index c13b9a5d3..f2cde352c 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);
+ SelContainer itemlist = sp_item_group_item_list(group);
+ for (SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++) {
+ SPItem* child_item = SP_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 ee9fa39ec..39dfad44b 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) {
+ SelContainer const itemlist = desktop->selection->itemList();
+ for (SelContainer::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 = reinterpret_cast<SPObject *>(*i); // TODO unsafe until Selection is refactored.
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);
+ SelContainer const itemlist = desktop->selection->itemList();
+ for (SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++) {
+ SPItem *item = reinterpret_cast<SPItem *>(*i);
// If not text, don't apply text attributes (can a group have text attributes? Yes! FIXME)
if (isTextualItem(item)) {
@@ -438,17 +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 SelContainer &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);
+ for (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) {
+ SPObject *obj = reinterpret_cast<SPObject *>(*i);
SPItem *item = dynamic_cast<SPItem *>(obj);
if (!item) {
continue;
@@ -471,7 +471,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 +492,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 SelContainer &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 +514,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 (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) {
+ SPObject *obj = reinterpret_cast<SPObject *>(*i);
if (!obj) {
continue;
}
@@ -674,7 +674,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 +685,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 SelContainer &objects, SPStyle *style_res)
{
- if (g_slist_length(objects) == 0) {
+ if (objects.empty()) {
/* No objects, set empty */
return QUERY_STYLE_NOTHING;
}
@@ -698,8 +698,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 (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) {
+ SPObject *obj = reinterpret_cast<SPObject *>(*i);
if (!obj) {
continue;
}
@@ -739,9 +739,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 SelContainer &objects, SPStyle *style_res)
{
- if (g_slist_length(objects) == 0) {
+ if (objects.empty()) {
/* No objects, set empty */
return QUERY_STYLE_NOTHING;
}
@@ -754,8 +754,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 (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) {
+ SPObject *obj = reinterpret_cast<SPObject *>(*i);
if (!obj) {
continue;
}
@@ -815,9 +815,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 SelContainer &objects, SPStyle *style_res)
{
- if (g_slist_length(objects) == 0) {
+ if (objects.empty()) {
/* No objects, set empty */
return QUERY_STYLE_NOTHING;
}
@@ -828,8 +828,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 (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) {
+ SPObject *obj = reinterpret_cast<SPObject *>(*i);
if (!dynamic_cast<SPItem *>(obj)) {
continue;
}
@@ -875,9 +875,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 SelContainer &objects, SPStyle *style_res)
{
- if (g_slist_length(objects) == 0) {
+ if (objects.empty()) {
/* No objects, set empty */
return QUERY_STYLE_NOTHING;
}
@@ -887,8 +887,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 (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) {
+ SPObject *obj = reinterpret_cast<SPObject *>(*i);
if (!dynamic_cast<SPItem *>(obj)) {
continue;
}
@@ -929,9 +929,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 SelContainer &objects, SPStyle *style_res)
{
- if (g_slist_length(objects) == 0) {
+ if (objects.empty()) {
/* No objects, set empty */
return QUERY_STYLE_NOTHING;
}
@@ -941,8 +941,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 (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) {
+ SPObject *obj = reinterpret_cast<SPObject *>(*i);
if (!dynamic_cast<SPItem *>(obj)) {
continue;
}
@@ -984,7 +984,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 SelContainer &objects, SPStyle *style_res)
{
bool different = false;
@@ -1004,8 +1004,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 (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) {
+ SPObject *obj = reinterpret_cast<SPObject *>(*i);
if (!isTextualItem(obj)) {
continue;
@@ -1116,15 +1116,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 SelContainer &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 (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) {
+ SPObject *obj = reinterpret_cast<SPObject *>(*i);
if (!isTextualItem(obj)) {
continue;
@@ -1173,7 +1173,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 SelContainer &objects, SPStyle *style_res)
{
bool different = false;
@@ -1192,8 +1192,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 (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) {
+ SPObject *obj = reinterpret_cast<SPObject *>(*i);
if (!isTextualItem(obj)) {
continue;
@@ -1269,7 +1269,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 SelContainer &objects, SPStyle *style_res)
{
bool different = false;
int texts = 0;
@@ -1280,8 +1280,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 (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) {
+ SPObject *obj = reinterpret_cast<SPObject *>(*i);
// std::cout << " " << reinterpret_cast<SPObject*>(i->data)->getId() << std::endl;
if (!isTextualItem(obj)) {
@@ -1325,7 +1325,7 @@ objects_query_fontfamily (GSList *objects, SPStyle *style_res)
}
static int
-objects_query_fontspecification (GSList *objects, SPStyle *style_res)
+objects_query_fontspecification (const SelContainer &objects, SPStyle *style_res)
{
bool different = false;
int texts = 0;
@@ -1336,8 +1336,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 (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) {
+ SPObject *obj = reinterpret_cast<SPObject *>(*i);
// std::cout << " " << reinterpret_cast<SPObject*>(i->data)->getId() << std::endl;
if (!isTextualItem(obj)) {
@@ -1385,7 +1385,7 @@ objects_query_fontspecification (GSList *objects, SPStyle *style_res)
}
static int
-objects_query_blend (GSList *objects, SPStyle *style_res)
+objects_query_blend (const SelContainer &objects, SPStyle *style_res)
{
const int empty_prev = -2;
const int complex_filter = 5;
@@ -1394,8 +1394,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 (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) {
+ SPObject *obj = reinterpret_cast<SPObject *>(*i);
if (!obj) {
continue;
}
@@ -1471,9 +1471,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 SelContainer &objects, SPStyle *style_res)
{
- if (g_slist_length(objects) == 0) {
+ if (objects.empty()) {
/* No objects, set empty */
return QUERY_STYLE_NOTHING;
}
@@ -1484,8 +1484,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 (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) {
+ SPObject *obj = reinterpret_cast<SPObject *>(*i);
if (!obj) {
continue;
}
@@ -1553,7 +1553,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 SelContainer &list, SPStyle *style, int property)
{
if (property == QUERY_STYLE_PROPERTY_FILL) {
return objects_query_fillstroke (list, style, true);
@@ -1606,7 +1606,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..0e40a2652 100644
--- a/src/desktop-style.h
+++ b/src/desktop-style.h
@@ -13,6 +13,7 @@
* Released under GNU GPL, read the file 'COPYING' for more information
*/
+#include "selection.h" // SelContainer
class ColorRGBA;
class SPCSSAttr;
class SPDesktop;
@@ -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 SelContainer &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 SelContainer &objects, SPStyle *style_res, bool const isfill);
+int objects_query_fontnumbers (const SelContainer &objects, SPStyle *style_res);
+int objects_query_fontstyle (const SelContainer &objects, SPStyle *style_res);
+int objects_query_fontfamily (const SelContainer &objects, SPStyle *style_res);
+int objects_query_opacity (const SelContainer &objects, SPStyle *style_res);
+int objects_query_strokewidth (const SelContainer &objects, SPStyle *style_res);
+int objects_query_miterlimit (const SelContainer &objects, SPStyle *style_res);
+int objects_query_strokecap (const SelContainer &objects, SPStyle *style_res);
+int objects_query_strokejoin (const SelContainer &objects, SPStyle *style_res);
-int objects_query_blur (GSList *objects, SPStyle *style_res);
+int objects_query_blur (const SelContainer &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 SelContainer &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/extension/execution-env.cpp b/src/extension/execution-env.cpp
index 13b8d60c4..66a8c4358 100644
--- a/src/extension/execution-env.cpp
+++ b/src/extension/execution-env.cpp
@@ -64,14 +64,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 ) {
+ SelContainer selected = desktop->getSelection()->itemList();
+ for(SelContainer::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..6eff3ede3 100644
--- a/src/extension/implementation/implementation.cpp
+++ b/src/extension/implementation/implementation.cpp
@@ -48,11 +48,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();
+ SelContainer 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 = SP_ITEM(selected.front());
first_select = item->getRepr();
}
diff --git a/src/extension/implementation/script.cpp b/src/extension/implementation/script.cpp
index bbc567f75..f396e9848 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 =
+ SelContainer selected =
desktop->getSelection()->itemList(); //desktop should not be NULL since doc was checked and desktop is a casted pointer
- while ( selected != NULL ) {
+ for(SelContainer::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 76f35415e..87ef30887 100644
--- a/src/extension/internal/bitmap/imagemagick.cpp
+++ b/src/extension/internal/bitmap/imagemagick.cpp
@@ -70,8 +70,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 SelContainer selectedItemList = desktop->selection->itemList();
+ int selectCount = selectedItemList.size();
// Init the data-holders
_nodes = new Inkscape::XML::Node*[selectCount];
@@ -83,9 +83,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 (SelContainer::const_iterator i=selectedItemList.begin();i!=selectedItemList.end();i++) {
+ SPItem *item = static_cast<SPItem *>(*i);
Inkscape::XML::Node *node = reinterpret_cast<Inkscape::XML::Node *>(item->getRepr());
if (!strcmp(node->name(), "image") || !strcmp(node->name(), "svg:image"))
{
@@ -243,11 +242,10 @@ ImageMagick::prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::Vie
using Inkscape::Util::GSListConstIterator;
- // FIXME very unsafe cast
- GSListConstIterator<SPItem *> selected = ((SPDesktop *)view)->getSelection()->itemList();
+ SelContainer 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..138172715 100644
--- a/src/extension/internal/bluredge.cpp
+++ b/src/extension/internal/bluredge.cpp
@@ -65,13 +65,12 @@ BlurEdge::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View
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);
+ SelContainer items(selection->itemList());
selection->clear();
- for(std::list<SPItem *>::iterator item = items.begin();
+ for(SelContainer::iterator item = items.begin();
item != items.end(); ++item) {
- SPItem * spitem = *item;
+ SPItem * spitem = static_cast<SPItem*>(*item);
std::vector<Inkscape::XML::Node *> new_items(steps);
Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc();
diff --git a/src/extension/internal/cairo-renderer.cpp b/src/extension/internal/cairo-renderer.cpp
index 1f48d2097..7ce5cdf8a 100644
--- a/src/extension/internal/cairo-renderer.cpp
+++ b/src/extension/internal/cairo-renderer.cpp
@@ -294,14 +294,14 @@ 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);
+ SelContainer l(group->childList(false));
+ l.reverse();
+ for(SelContainer::const_iterator x=l.begin();x!=l.end();x++){
+ SPObject *o = reinterpret_cast<SPObject *>(*x);
SPItem *item = dynamic_cast<SPItem *>(o);
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..821c023ac 100644
--- a/src/extension/internal/filter/filter.cpp
+++ b/src/extension/internal/filter/filter.cpp
@@ -125,17 +125,15 @@ 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);
+ SelContainer 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(SelContainer::iterator item = items.begin();
item != items.end(); ++item) {
- SPItem * spitem = *item;
+ SPItem * spitem = static_cast<SPItem*>(*item);
Inkscape::XML::Node * node = spitem->getRepr();
SPCSSAttr * css = sp_repr_css_attr(node, "style");
diff --git a/src/extension/internal/grid.cpp b/src/extension/internal/grid.cpp
index 270edfe44..4c12f629c 100644
--- a/src/extension/internal/grid.cpp
+++ b/src/extension/internal/grid.cpp
@@ -192,11 +192,10 @@ Grid::prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View
using Inkscape::Util::GSListConstIterator;
- // FIXME very unsafe cast
- GSListConstIterator<SPItem *> selected = ((SPDesktop *)view)->getSelection()->itemList();
+ SelContainer 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/latex-text-renderer.cpp b/src/extension/internal/latex-text-renderer.cpp
index ab0733848..dab27a0e1 100644
--- a/src/extension/internal/latex-text-renderer.cpp
+++ b/src/extension/internal/latex-text-renderer.cpp
@@ -228,14 +228,14 @@ 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);
+ SelContainer l = (group->childList(false));
+ l.reverse();
+ for(SelContainer::const_iterator x=l.begin();x!=l.end();x++){
+ SPObject *o = reinterpret_cast<SPObject *>(*x);
SPItem *item = dynamic_cast<SPItem *>(o);
if (item) {
renderItem(item);
}
- l = g_slist_remove (l, o);
}
}
diff --git a/src/file.cpp b/src/file.cpp
index 72516d776..4325c838b 100644
--- a/src/file.cpp
+++ b/src/file.cpp
@@ -1063,7 +1063,7 @@ void sp_import_document(SPDesktop *desktop, SPDocument *clipdoc, bool in_place)
desktop->doc()->importDefs(clipdoc);
// copy objects
- GSList *pasted_objects = NULL;
+ std::list<SPObject*> 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")) {
@@ -1082,7 +1082,7 @@ 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_front(dynamic_cast<SPObject*>(obj_copy));
}
// Change the selection to the freshly pasted objects
@@ -1123,8 +1123,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/filter-chemistry.cpp b/src/filter-chemistry.cpp
index 9298a1ffc..c89cf6220 100644
--- a/src/filter-chemistry.cpp
+++ b/src/filter-chemistry.cpp
@@ -23,9 +23,9 @@
#include "filter-chemistry.h"
#include "filter-enums.h"
-
#include "filters/blend.h"
#include "filters/gaussian-blur.h"
+#include "selection.h"
#include "sp-filter.h"
#include "sp-filter-reference.h"
#include "svg/css-ostringstream.h"
diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp
index cf75f6cf0..5f1da6cf1 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 SelContainer list=selection->itemList();
+ for (SelContainer::const_iterator i=list.begin();i!=list.end();i++) {
+ sp_item_gradient_invert_vector_color(SP_ITEM(*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 SelContainer list=selection->itemList();
+ for (SelContainer::const_iterator i=list.begin();i!=list.end();i++) {
+ sp_item_gradient_reverse_vector(SP_ITEM(*i), Inkscape::FOR_FILL);
+ sp_item_gradient_reverse_vector(SP_ITEM(*i), Inkscape::FOR_STROKE);
}
}
diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp
index 154b7339b..649928060 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);
+ SelContainer list = this->selection->itemList();
+ for (SelContainer::const_iterator i=list.begin();i!=list.end();i++) {
+ SPItem *item = SP_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);
+ SelContainer list = this->selection->itemList();
+ for (SelContainer::const_iterator i=list.begin();i!=list.end();i++) {
+ SPItem *item = SP_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);
+ SelContainer list = this->selection->itemList();
+ for (SelContainer::const_iterator i=list.begin();i!=list.end();i++) {
+ SPItem *item = SP_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..613440269 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(SelContainer const &items, list<SPItem *> &filtered) {
+ for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){
+ SPItem *item = SP_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(SelContainer const &items) {
+ if(items.empty()) {
return;
}
diff --git a/src/graphlayout.h b/src/graphlayout.h
index 0ffb645b6..c38f9471c 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(SelContainer const &items);
bool isConnector(SPItem const *const item);
-void filterConnectors(GSList const *const items, std::list<SPItem *> &filtered);
+void filterConnectors(SelContainer 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..55fef5a4c 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 SelContainer &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 SelContainer &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 SelContainer &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..47fad1b41 100644
--- a/src/helper/png-write.h
+++ b/src/helper/png-write.h
@@ -16,6 +16,11 @@
#include <glib.h>
#include <2geom/forward.h>
+
+//should be in selection.h
+typedef std::list<SPObject*> SelContainer;
+
+
class SPDocument;
enum ExportResult {
@@ -33,12 +38,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 SelContainer &items_only = SelContainer());
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 SelContainer &items_only = SelContainer());
#endif // SEEN_SP_PNG_WRITE_H
diff --git a/src/live_effects/lpe-knot.cpp b/src/live_effects/lpe-knot.cpp
index 3876aa24b..95a6b16dd 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);
+ SelContainer item_list = sp_item_group_item_list(SP_GROUP(lpeitem));
+ for ( SelContainer::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) {
+ SPObject *subitem = static_cast<SPObject *>(*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 15576109d..25dc91f14 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;
+ SelContainer items;
SPRoot *root = doc->getRoot();
doc->ensureUpToDate();
for ( SPObject *iter = root->firstChild(); iter ; iter = iter->getNext()) {
@@ -1166,17 +1166,17 @@ 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;
+ SelContainer selected;
+ SelContainer 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);
+ items.clear();
+ selected.clear();
+ to_select.clear();
}
if(sp_export_id) {
doc->ensureUpToDate();
@@ -1435,7 +1435,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;
+ SelContainer items;
Geom::Rect area;
if (sp_export_id || sp_export_area_drawing) {
@@ -1459,7 +1459,7 @@ static int sp_do_export_png(SPDocument *doc)
return 1;
}
- items = g_slist_prepend (items, SP_ITEM(o));
+ items.push_front(SP_ITEM(o));
if (sp_export_id_only) {
g_print("Exporting only object with id=\"%s\"; all other objects hidden\n", sp_export_id);
@@ -1647,7 +1647,7 @@ static int sp_do_export_png(SPDocument *doc)
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 : SelContainer()) == 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 +1657,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..960b5087b 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)) {
+ SelContainer rotationSource=_snapmanager->getRotationCenterSource();
+ for ( SelContainer::const_iterator itemlist=rotationSource.begin();itemlist!=rotationSource.end();itemlist++) {
+ if ((*i).item == reinterpret_cast<SPItem*>(*itemlist)) {
// don't snap to this item's rotation center
_snapmanager->snapprefs.setTargetSnappable(SNAPTARGET_ROTATION_CENTER, false);
break;
diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp
index 5f6e1495b..a5e71b720 100644
--- a/src/path-chemistry.cpp
+++ b/src/path-chemistry.cpp
@@ -44,13 +44,22 @@
using Inkscape::DocumentUndo;
+
+inline bool less_than_objects(SPObject const *first, SPObject 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();
+
+ SelContainer 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,26 @@ 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;
+ SelContainer to_paths;
+ for (SelContainer::const_iterator i=items.begin();i!=items.end();i++) {
+ SPItem *item = (SPItem *) (*i);
if (!dynamic_cast<SPPath *>(item) && !dynamic_cast<SPGroup *>(item)) {
- to_paths = g_slist_prepend(to_paths, item);
+ to_paths.push_front(item);
}
}
- 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)));
+ SelContainer converted;
+ bool did = sp_item_list_to_curves(to_paths, items, converted);
+ to_paths.clear();
+ for (SelContainer::const_iterator i=converted.begin();i!=converted.end();i++)
+ items.push_front(doc->getObjectByRepr((Inkscape::XML::Node*)(*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
+ items.sort(less_than_objects);
+ items.reverse();
+ 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 +104,9 @@ sp_selected_path_combine(SPDesktop *desktop)
selection->clear();
}
- for (GSList *i = items; i != NULL; i = i->next) { // going from top to bottom
+ for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){
- SPItem *item = (SPItem *) i->data;
+ SPItem *item = (SPItem *) (*i);
SPPath *path = dynamic_cast<SPPath *>(item);
if (!path) {
continue;
@@ -136,7 +143,6 @@ sp_selected_path_combine(SPDesktop *desktop)
}
}
- g_slist_free(items);
if (did) {
first->deleteObject(false);
@@ -200,11 +206,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) {
+ SelContainer itemlist(selection->itemList());
+ for (SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
- SPItem *item = (SPItem *) items->data;
+ SPItem *item = (SPItem *) (*i);
SPPath *path = dynamic_cast<SPPath *>(item);
if (!path) {
@@ -241,7 +246,7 @@ sp_selected_path_break_apart(SPDesktop *desktop)
curve->unref();
- GSList *reprs = NULL;
+ SelContainer reprs;
for (GSList *l = list; l != NULL; l = l->next) {
curve = (SPCurve *) l->data;
@@ -267,14 +272,14 @@ sp_selected_path_break_apart(SPDesktop *desktop)
if (l == list)
repr->setAttribute("id", id);
- reprs = g_slist_prepend (reprs, repr);
+ reprs.push_front(dynamic_cast<SPObject*>(repr));
Inkscape::GC::release(repr);
}
selection->setReprList(reprs);
- g_slist_free(reprs);
+ reprs.clear();
g_slist_free(list);
g_free(style);
g_free(path_effect);
@@ -307,18 +312,18 @@ 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;
+ SelContainer selected(selection->itemList());
+ SelContainer to_select;
selection->clear();
- GSList *items = g_slist_copy(selected);
+ SelContainer 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);
+ items.clear();
selection->setReprList(to_select);
selection->addList(selected);
- g_slist_free (to_select);
- g_slist_free (selected);
+ to_select.clear();
+ selected.clear();
if (interactive && desktop) {
desktop->clearWaitingCursor();
@@ -341,33 +346,29 @@ void sp_selected_to_lpeitems(SPDesktop *desktop)
return;
}
- GSList *selected = g_slist_copy((GSList *) selection->itemList());
- GSList *to_select = NULL;
+ SelContainer selected(selection->itemList());
+ SelContainer to_select;
selection->clear();
- GSList *items = g_slist_copy(selected);
+ SelContainer 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;
+ items.clear();
selection->setReprList(to_select);
selection->addList(selected);
- g_slist_free(to_select);
- to_select = 0;
- g_slist_free(selected);
- selected = 0;
+ to_select.clear();
+ selected.clear();
}
bool
-sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_select, bool skip_all_lpeitems)
+sp_item_list_to_curves(const SelContainer &items, SelContainer& selected, SelContainer &to_select, bool skip_all_lpeitems)
{
bool did = false;
- for (;
- items != NULL;
- items = items->next) {
+ for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){
- SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(items->data));
+ SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(*i));
g_assert(item != NULL);
SPDocument *document = item->document;
@@ -398,9 +399,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.push_front(dynamic_cast<SPObject *>(repr));
did = true;
- *selected = g_slist_remove (*selected, item);
+ selected.remove(item);
}
continue;
@@ -408,17 +409,17 @@ 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);
+ SelContainer item_list = sp_item_group_item_list(group);
- GSList *item_to_select = NULL;
- GSList *item_selected = NULL;
+ SelContainer item_to_select;
+ SelContainer 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);
+ item_list.clear();
+ item_to_select.clear();
+ item_selected.clear();
continue;
}
@@ -428,7 +429,7 @@ sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_selec
continue;
did = true;
- *selected = g_slist_remove (*selected, item);
+ selected.remove(item);
// remember the position of the item
gint pos = item->getRepr()->position();
@@ -470,7 +471,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.push_front(dynamic_cast<SPObject *>(repr));
Inkscape::GC::release(repr);
}
@@ -612,9 +613,9 @@ void
sp_selected_path_reverse(SPDesktop *desktop)
{
Inkscape::Selection *selection = desktop->getSelection();
- GSList *items = (GSList *) selection->itemList();
+ SelContainer items = selection->itemList();
- if (!items) {
+ if (items.empty()) {
desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>path(s)</b> to reverse."));
return;
}
@@ -626,9 +627,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 (SelContainer::const_iterator i=items.begin();i!=items.end();i++){
- SPPath *path = dynamic_cast<SPPath *>(static_cast<SPObject *>(i->data));
+ SPPath *path = dynamic_cast<SPPath *>(static_cast<SPObject *>(*i));
if (!path) {
continue;
}
diff --git a/src/path-chemistry.h b/src/path-chemistry.h
index a2150440c..388268af4 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 SelContainer &items, SelContainer &selected, SelContainer &to_select, bool skip_all_lpeitems = false);
#endif // SEEN_PATH_CHEMISTRY_H
diff --git a/src/removeoverlap.cpp b/src/removeoverlap.cpp
index ba5740e55..9009de5e9 100644
--- a/src/removeoverlap.cpp
+++ b/src/removeoverlap.cpp
@@ -38,20 +38,20 @@ 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) {
+void removeoverlap(SelContainer const &items, double const xGap, double const yGap) {
using Inkscape::Util::GSListConstIterator;
- std::list<SPItem *> selected;
- selected.insert<GSListConstIterator<SPItem *> >(selected.end(), items, NULL);
+ SelContainer 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 (SelContainer::iterator it(selected.begin());
it != selected.end();
++it)
{
+ SPItem* item=static_cast<SPItem*>(*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 +67,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..d050ca9ef 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(SelContainer const &items, double xGap, double yGap);
#endif // SEEN_REMOVEOVERLAP_H
diff --git a/src/selcue.cpp b/src/selcue.cpp
index d2fa0970a..0fab6e5a8 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 SelContainer 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);
+ SelContainer ll=_selection->itemList();
+ for (SelContainer::const_iterator l=ll.begin();l!=ll.end();l++) {
+ SPItem *item = static_cast<SPItem *>(*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);
+ SelContainer ll=_selection->itemList();
+ for (SelContainer::const_iterator l=ll.begin();l!=ll.end();l++) {
+ SPItem *item = static_cast<SPItem *>(*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);
+ SelContainer ll=_selection->itemList();
+ for (SelContainer::const_iterator l=ll.begin();l!=ll.end();l++) {
+ SPItem *item = static_cast<SPItem *>(*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 c9837aabe..f20df1594 100644
--- a/src/selection-chemistry.cpp
+++ b/src/selection-chemistry.cpp
@@ -279,25 +279,23 @@ void SelectionHelper::fixSelection(SPDesktop *dt)
Inkscape::Selection *selection = dt->getSelection();
- GSList *items = NULL;
+ SelContainer items ;
- GSList const *selList = selection->itemList();
+ SelContainer const selList = selection->itemList();
- for( GSList const *i = selList; i; i = i->next ) {
- SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(i->data));
+ for( SelContainer::const_iterator i=selList.begin();i!=selList.end();i++ ) {
+ SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(*i));
if( item &&
!dt->isLayer(item) &&
(!item->isLocked()))
{
- items = g_slist_prepend(items, item);
+ items.push_front(item);
}
}
selection->setList(items);
- if(items) {
- g_slist_free(items);
- }
+ items.clear();
}
} // namespace Inkscape
@@ -307,7 +305,7 @@ void SelectionHelper::fixSelection(SPDesktop *dt)
* Copies repr and its inherited css style elements, along with the accumulated transform 'full_t',
* then prepends the copy to 'clip'.
*/
-static void sp_selection_copy_one(Inkscape::XML::Node *repr, Geom::Affine full_t, GSList **clip, Inkscape::XML::Document* xml_doc)
+static void sp_selection_copy_one(Inkscape::XML::Node *repr, Geom::Affine full_t, SelContainer &clip, Inkscape::XML::Document* xml_doc)
{
Inkscape::XML::Node *copy = repr->duplicate(xml_doc);
@@ -323,18 +321,18 @@ static void sp_selection_copy_one(Inkscape::XML::Node *repr, Geom::Affine full_t
copy->setAttribute("transform", affinestr);
g_free(affinestr);
- *clip = g_slist_prepend(*clip, copy);
+ clip.push_front(dynamic_cast<SPObject*>(copy));
}
-static void sp_selection_copy_impl(GSList const *items, GSList **clip, Inkscape::XML::Document* xml_doc)
+static void sp_selection_copy_impl(SelContainer const &items, SelContainer &clip, Inkscape::XML::Document* xml_doc)
{
// Sort items:
- GSList *sorted_items = g_slist_copy(const_cast<GSList *>(items));
- sorted_items = g_slist_sort(static_cast<GSList *>(sorted_items), (GCompareFunc) sp_object_compare_position);
+ SelContainer sorted_items(items);
+ sorted_items.sort(sp_object_compare_position);
// Copy item reprs:
- for (GSList *i = sorted_items; i != NULL; i = i->next) {
- SPItem *item = dynamic_cast<SPItem *>(SP_OBJECT(i->data));
+ for (SelContainer::const_iterator i = sorted_items.begin();i!=sorted_items.end();i++) {
+ SPItem *item = dynamic_cast<SPItem *>(SP_OBJECT(*i));
if (item) {
sp_selection_copy_one(item->getRepr(), item->i2doc_affine(), clip, xml_doc);
} else {
@@ -342,22 +340,22 @@ static void sp_selection_copy_impl(GSList const *items, GSList **clip, Inkscape:
}
}
- *clip = g_slist_reverse(*clip);
- g_slist_free(static_cast<GSList *>(sorted_items));
+ clip.reverse();
+ sorted_items.clear();
}
// TODO check if parent parameter should be changed to SPItem, of if the code should handle non-items.
-static GSList *sp_selection_paste_impl(SPDocument *doc, SPObject *parent, GSList **clip)
+static SelContainer sp_selection_paste_impl(SPDocument *doc, SPObject *parent, SelContainer &clip)
{
Inkscape::XML::Document *xml_doc = doc->getReprDoc();
SPItem *parentItem = dynamic_cast<SPItem *>(parent);
g_assert(parentItem != NULL);
- GSList *copied = NULL;
+ SelContainer copied;
// add objects to document
- for (GSList *l = *clip; l != NULL; l = l->next) {
- Inkscape::XML::Node *repr = static_cast<Inkscape::XML::Node *>(l->data);
+ for (SelContainer::const_iterator l=clip.begin();l!=clip.end();l++) {
+ Inkscape::XML::Node *repr = dynamic_cast<Inkscape::XML::Node *>(*l);
Inkscape::XML::Node *copy = repr->duplicate(xml_doc);
// premultiply the item transform by the accumulated parent transform in the paste layer
@@ -375,19 +373,19 @@ static GSList *sp_selection_paste_impl(SPDocument *doc, SPObject *parent, GSList
}
parent->appendChildRepr(copy);
- copied = g_slist_prepend(copied, copy);
+ copied.push_front(dynamic_cast<SPObject*>(copy));
Inkscape::GC::release(copy);
}
return copied;
}
-static void sp_selection_delete_impl(GSList const *items, bool propagate = true, bool propagate_descendants = true)
+static void sp_selection_delete_impl(SelContainer const &items, bool propagate = true, bool propagate_descendants = true)
{
- for (GSList const *i = items ; i ; i = i->next ) {
- sp_object_ref(static_cast<SPItem *>(i->data), NULL);
+ for (SelContainer::const_iterator i=items.begin();i!=items.end();i++) {
+ sp_object_ref(static_cast<SPItem *>(*i), NULL);
}
- for (GSList const *i = items; i != NULL; i = i->next) {
- SPItem *item = static_cast<SPItem *>(i->data);
+ for (SelContainer::const_iterator i=items.begin();i!=items.end();i++) {
+ SPItem *item = static_cast<SPItem *>(*i);
item->deleteObject(propagate, propagate_descendants);
sp_object_unref(item, NULL);
}
@@ -414,11 +412,10 @@ void sp_selection_delete(SPDesktop *desktop)
desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("<b>Nothing</b> was deleted."));
return;
}
-
- GSList *selected = g_slist_copy(const_cast<GSList *>(selection->itemList()));
+ SelContainer selected(selection->itemList());
selection->clear();
sp_selection_delete_impl(selected);
- g_slist_free(selected);
+ selected.clear();
desktop->currentLayer()->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
/* a tool may have set up private information in it's selection context
@@ -446,6 +443,10 @@ static void add_ids_recursive(std::vector<const gchar *> &ids, SPObject *obj)
}
}
+bool sp_repr_compare_position_obj(SPObject* &a,SPObject* &b){
+ return sp_repr_compare_position(dynamic_cast<Inkscape::XML::Node*>(a),dynamic_cast<Inkscape::XML::Node*>(b));
+}
+
void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone)
{
if (desktop == NULL) {
@@ -461,16 +462,15 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone)
desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to duplicate."));
return;
}
-
- GSList *reprs = g_slist_copy(const_cast<GSList *>(selection->reprList()));
+ SelContainer reprs(selection->reprList());
selection->clear();
// sorting items from different parents sorts each parent's subset without possibly mixing
// them, just what we need
- reprs = g_slist_sort(reprs, (GCompareFunc) sp_repr_compare_position);
+ reprs.sort(sp_repr_compare_position_obj);
- GSList *newsel = NULL;
+ SelContainer newsel;
std::vector<const gchar *> old_ids;
std::vector<const gchar *> new_ids;
@@ -478,8 +478,8 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone)
bool relink_clones = prefs->getBool("/options/relinkclonesonduplicate/value");
const bool fork_livepatheffects = prefs->getBool("/options/forklpeonduplicate/value", true);
- while (reprs) {
- Inkscape::XML::Node *old_repr = static_cast<Inkscape::XML::Node *>(reprs->data);
+ while (!reprs.empty()) {
+ Inkscape::XML::Node *old_repr = dynamic_cast<Inkscape::XML::Node *>(reprs.front());
Inkscape::XML::Node *parent = old_repr->parent();
Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc);
@@ -500,8 +500,8 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone)
}
}
- newsel = g_slist_prepend(newsel, copy);
- reprs = g_slist_remove(reprs, reprs->data);
+ newsel.push_front(dynamic_cast<SPObject*>(copy));
+ reprs.pop_front();
Inkscape::GC::release(copy);
}
@@ -548,7 +548,7 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone)
selection->setReprList(newsel);
- g_slist_free(newsel);
+ newsel.clear();
}
void sp_edit_clear_all(Inkscape::Selection *selection)
@@ -561,11 +561,11 @@ void sp_edit_clear_all(Inkscape::Selection *selection)
SPGroup *group = dynamic_cast<SPGroup *>(selection->layers()->currentLayer());
g_return_if_fail(group != NULL);
- GSList *items = sp_item_group_item_list(group);
+ SelContainer items = sp_item_group_item_list(group);
- while (items) {
- reinterpret_cast<SPObject*>(items->data)->deleteObject();
- items = g_slist_remove(items, items->data);
+ while (!items.empty()) {
+ reinterpret_cast<SPObject*>(items.front())->deleteObject();
+ items.pop_front();
}
DocumentUndo::done(doc, SP_VERB_EDIT_CLEAR_ALL,
@@ -582,7 +582,7 @@ void sp_edit_clear_all(Inkscape::Selection *selection)
* onlysensitive - TRUE includes only non-locked items
* ingroups - TRUE to recursively get grouped items children
*/
-GSList *get_all_items(GSList *list, SPObject *from, SPDesktop *desktop, bool onlyvisible, bool onlysensitive, bool ingroups, GSList const *exclude)
+SelContainer &get_all_items(SelContainer &list, SPObject *from, SPDesktop *desktop, bool onlyvisible, bool onlysensitive, bool ingroups, SelContainer const &exclude)
{
for ( SPObject *child = from->firstChild() ; child; child = child->getNext() ) {
SPItem *item = dynamic_cast<SPItem *>(child);
@@ -590,10 +590,10 @@ GSList *get_all_items(GSList *list, SPObject *from, SPDesktop *desktop, bool onl
!desktop->isLayer(item) &&
(!onlysensitive || !item->isLocked()) &&
(!onlyvisible || !desktop->itemIsHidden(item)) &&
- (!exclude || !g_slist_find(const_cast<GSList *>(exclude), child))
+ (exclude.empty() || exclude.end() == std::find(exclude.begin(),exclude.end(),child))
)
{
- list = g_slist_prepend(list, item);
+ list.push_front(item);
}
if (ingroups || (item && desktop->isLayer(item))) {
@@ -618,9 +618,9 @@ static void sp_edit_select_all_full(SPDesktop *dt, bool force_all_layers, bool i
bool onlyvisible = prefs->getBool("/options/kbselection/onlyvisible", true);
bool onlysensitive = prefs->getBool("/options/kbselection/onlysensitive", true);
- GSList *items = NULL;
+ SelContainer items ;
- GSList const *exclude = NULL;
+ SelContainer exclude;
if (invert) {
exclude = selection->itemList();
}
@@ -634,39 +634,41 @@ static void sp_edit_select_all_full(SPDesktop *dt, bool force_all_layers, bool i
(onlyvisible && dt->itemIsHidden(dynamic_cast<SPItem *>(dt->currentLayer()))) )
return;
- GSList *all_items = sp_item_group_item_list(dynamic_cast<SPGroup *>(dt->currentLayer()));
+ SelContainer all_items = sp_item_group_item_list(dynamic_cast<SPGroup *>(dt->currentLayer()));
- for (GSList *i = all_items; i; i = i->next) {
- SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(i->data));
+ for (SelContainer::const_iterator i=all_items.begin();i!=all_items.end();i++) {
+ SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(*i));
if (item && (!onlysensitive || !item->isLocked())) {
if (!onlyvisible || !dt->itemIsHidden(item)) {
if (!dt->isLayer(item)) {
- if (!invert || !g_slist_find(const_cast<GSList *>(exclude), item)) {
- items = g_slist_prepend(items, item); // leave it in the list
+ if (!invert || exclude.end() == std::find(exclude.begin(),exclude.end(),item)) {
+ items.push_front(item); // leave it in the list
}
}
}
}
}
- g_slist_free(all_items);
+ all_items.clear();
break;
}
case PREFS_SELECTION_LAYER_RECURSIVE: {
- items = get_all_items(NULL, dt->currentLayer(), dt, onlyvisible, onlysensitive, FALSE, exclude);
+ SelContainer x;
+ items = get_all_items(x, dt->currentLayer(), dt, onlyvisible, onlysensitive, FALSE, exclude);
break;
}
default: {
- items = get_all_items(NULL, dt->currentRoot(), dt, onlyvisible, onlysensitive, FALSE, exclude);
+ SelContainer x;
+ items = get_all_items(x, dt->currentRoot(), dt, onlyvisible, onlysensitive, FALSE, exclude);
break;
}
}
selection->setList(items);
- if (items) {
- g_slist_free(items);
+ if (!items.empty()) {
+ items.clear();
}
}
@@ -690,16 +692,16 @@ void sp_edit_invert_in_all_layers(SPDesktop *desktop)
sp_edit_select_all_full(desktop, true, true);
}
-static void sp_selection_group_impl(GSList *p, Inkscape::XML::Node *group, Inkscape::XML::Document *xml_doc, SPDocument *doc) {
+static void sp_selection_group_impl(SelContainer p, Inkscape::XML::Node *group, Inkscape::XML::Document *xml_doc, SPDocument *doc) {
- p = g_slist_sort(p, (GCompareFunc) sp_repr_compare_position);
+ p.sort(sp_repr_compare_position_obj);
// Remember the position and parent of the topmost object.
- gint topmost = (static_cast<Inkscape::XML::Node *>(g_slist_last(p)->data))->position();
- Inkscape::XML::Node *topmost_parent = (static_cast<Inkscape::XML::Node *>(g_slist_last(p)->data))->parent();
+ gint topmost = (dynamic_cast<Inkscape::XML::Node *>(p.back()))->position();
+ Inkscape::XML::Node *topmost_parent = (dynamic_cast<Inkscape::XML::Node *>(p.back()))->parent();
- while (p) {
- Inkscape::XML::Node *current = static_cast<Inkscape::XML::Node *>(p->data);
+ while (!p.empty()) {
+ Inkscape::XML::Node *current = dynamic_cast<Inkscape::XML::Node *>(p.front());
if (current->parent() == topmost_parent) {
Inkscape::XML::Node *spnew = current->duplicate(xml_doc);
@@ -708,7 +710,7 @@ static void sp_selection_group_impl(GSList *p, Inkscape::XML::Node *group, Inksc
Inkscape::GC::release(spnew);
topmost --; // only reduce count for those items deleted from topmost_parent
} else { // move it to topmost_parent first
- GSList *temp_clip = NULL;
+ SelContainer temp_clip;
// At this point, current may already have no item, due to its being a clone whose original is already moved away
// So we copy it artificially calculating the transform from its repr->attr("transform") and the parent transform
@@ -724,15 +726,15 @@ static void sp_selection_group_impl(GSList *p, Inkscape::XML::Node *group, Inksc
// then, if this is clone, looking up its original in that array and pre-multiplying
// it by the inverse of that original's transform diff.
- sp_selection_copy_one(current, item_t, &temp_clip, xml_doc);
+ sp_selection_copy_one(current, item_t, temp_clip, xml_doc);
sp_repr_unparent(current);
// paste into topmost_parent (temporarily)
- GSList *copied = sp_selection_paste_impl(doc, doc->getObjectByRepr(topmost_parent), &temp_clip);
- if (temp_clip) g_slist_free(temp_clip);
- if (copied) { // if success,
+ SelContainer copied = sp_selection_paste_impl(doc, doc->getObjectByRepr(topmost_parent), temp_clip);
+ if (!temp_clip.empty())temp_clip.clear() ;
+ if (!copied.empty()) { // if success,
// take pasted object (now in topmost_parent)
- Inkscape::XML::Node *in_topmost = static_cast<Inkscape::XML::Node *>(copied->data);
+ Inkscape::XML::Node *in_topmost = dynamic_cast<Inkscape::XML::Node *>(copied.front());
// make a copy
Inkscape::XML::Node *spnew = in_topmost->duplicate(xml_doc);
// remove pasted
@@ -740,10 +742,10 @@ static void sp_selection_group_impl(GSList *p, Inkscape::XML::Node *group, Inksc
// put its copy into group
group->appendChild(spnew);
Inkscape::GC::release(spnew);
- g_slist_free(copied);
+ copied.clear();
}
}
- p = g_slist_remove(p, current);
+ p.pop_front();
}
// Add the new group to the topmost members' parent
@@ -764,9 +766,7 @@ void sp_selection_group(Inkscape::Selection *selection, SPDesktop *desktop)
return;
}
- GSList const *l = const_cast<GSList *>(selection->reprList());
-
- GSList *p = g_slist_copy(const_cast<GSList *>(l));
+ SelContainer p (selection->reprList());
selection->clear();
@@ -802,11 +802,11 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop)
}
// first check whether there is anything to ungroup
- GSList *old_select = const_cast<GSList *>(selection->itemList());
- GSList *new_select = NULL;
+ SelContainer old_select = selection->itemList();
+ SelContainer new_select;
GSList *groups = NULL;
- for (GSList *item = old_select; item; item = item->next) {
- SPItem *obj = static_cast<SPItem*>(item->data);
+ for (SelContainer::const_iterator item = old_select.begin(); item!=old_select.end(); item++) {
+ SPItem *obj = static_cast<SPItem*>(*item);
if (dynamic_cast<SPGroup *>(obj)) {
groups = g_slist_prepend(groups, obj);
}
@@ -818,14 +818,14 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop)
return;
}
- GSList *items = g_slist_copy(old_select);
+ SelContainer items(old_select);
selection->clear();
// If any of the clones refer to the groups, unlink them and replace them with successors
// in the items list.
GSList *clones_to_unlink = NULL;
- for (GSList *item = items; item; item = item->next) {
- SPUse *use = dynamic_cast<SPUse *>(static_cast<SPItem *>(item->data));
+ for (SelContainer::const_iterator item = items.begin(); item!=items.end(); item++) {
+ SPUse *use = dynamic_cast<SPUse *>(static_cast<SPItem *>(*item));
SPItem *original = use;
while (dynamic_cast<SPUse *>(original)) {
@@ -833,7 +833,7 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop)
}
if (g_slist_find(groups, original) != NULL) {
- clones_to_unlink = g_slist_prepend(clones_to_unlink, item->data);
+ clones_to_unlink = g_slist_prepend(clones_to_unlink, *item);
}
}
@@ -844,57 +844,57 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop)
for (GSList *item = clones_to_unlink; item; item = item->next) {
SPUse *use = static_cast<SPUse *>(item->data);
- GSList *items_node = g_slist_find(items, item->data);
- items_node->data = use->unlink();
+ SelContainer::iterator items_node = std::find(items.begin(),items.end(), item->data);
+ (*items_node) = use->unlink();
}
g_slist_free(clones_to_unlink);
// do the actual work
- for (GSList *item = items; item; item = item->next) {
- SPItem *obj = static_cast<SPItem *>(item->data);
+ for (SelContainer::iterator item = items.begin(); item!=items.end(); item++) {
+ SPItem *obj = static_cast<SPItem *>(*item);
// ungroup only the groups marked earlier
- if (g_slist_find(groups, item->data) != NULL) {
- GSList *children = NULL;
- sp_item_group_ungroup(dynamic_cast<SPGroup *>(obj), &children, false);
+ if (g_slist_find(groups, *item) != NULL) {
+ SelContainer children;
+ sp_item_group_ungroup(dynamic_cast<SPGroup *>(obj), children, false);
// add the items resulting from ungrouping to the selection
- new_select = g_slist_concat(new_select, children);
- item->data = NULL; // zero out the original pointer, which is no longer valid
+ new_select.splice(new_select.end(),children);
+ (*item) = NULL; // zero out the original pointer, which is no longer valid
} else {
// if not a group, keep in the selection
- new_select = g_slist_append(new_select, item->data);
+ new_select.push_back(*item);
}
}
selection->addList(new_select);
- g_slist_free(new_select);
- g_slist_free(items);
+ new_select.clear();
+ items.clear();
DocumentUndo::done(selection->layers()->getDocument(), SP_VERB_SELECTION_UNGROUP,
_("Ungroup"));
}
/** Replace all groups in the list with their member objects, recursively; returns a new list, frees old */
-GSList *
-sp_degroup_list(GSList *items)
+SelContainer
+sp_degroup_list(SelContainer &items)
{
- GSList *out = NULL;
+ SelContainer out;
bool has_groups = false;
- for (GSList *item = items; item; item = item->next) {
- SPGroup *group = dynamic_cast<SPGroup *>(static_cast<SPObject *>(item->data));
+ for (SelContainer::const_iterator item=items.begin();item!=items.end();item++) {
+ SPGroup *group = dynamic_cast<SPGroup *>(static_cast<SPObject *>(*item));
if (!group) {
- out = g_slist_prepend(out, item->data);
+ out.push_front(*item);
} else {
has_groups = true;
- GSList *members = sp_item_group_item_list(group);
- for (GSList *member = members; member; member = member->next) {
- out = g_slist_prepend(out, member->data);
+ SelContainer members = sp_item_group_item_list(group);
+ for (SelContainer::const_iterator member=members.begin();member!=members.end();member++) {
+ out.push_front(*member);
}
- g_slist_free(members);
+ members.clear();
}
}
- out = g_slist_reverse(out);
- g_slist_free(items);
+ out.reverse();
+ items.clear();
if (has_groups) { // recurse if we unwrapped a group - it may have contained others
out = sp_degroup_list(out);
@@ -906,18 +906,19 @@ sp_degroup_list(GSList *items)
/** If items in the list have a common parent, return it, otherwise return NULL */
static SPGroup *
-sp_item_list_common_parent_group(GSList const *items)
+sp_item_list_common_parent_group(SelContainer const items)
{
- if (!items) {
+ if (items.empty()) {
return NULL;
}
- SPObject *parent = SP_OBJECT(items->data)->parent;
+ SPObject *parent = SP_OBJECT(items.front())->parent;
// Strictly speaking this CAN happen, if user selects <svg> from Inkscape::XML editor
if (!dynamic_cast<SPGroup *>(parent)) {
return NULL;
}
- for (items = items->next; items; items = items->next) {
- if (SP_OBJECT(items->data)->parent != parent) {
+ for (SelContainer::const_iterator item=items.begin();item!=items.end();item++) {
+ if((*item)==items.front())continue;
+ if (SP_OBJECT(*item)->parent != parent) {
return NULL;
}
}
@@ -927,13 +928,13 @@ sp_item_list_common_parent_group(GSList const *items)
/** Finds out the minimum common bbox of the selected items. */
static Geom::OptRect
-enclose_items(GSList const *items)
+enclose_items(SelContainer const &items)
{
- g_assert(items != NULL);
+ g_assert(!items.empty());
Geom::OptRect r;
- for (GSList const *i = items; i; i = i->next) {
- r.unionWith(static_cast<SPItem *>(i->data)->desktopVisualBounds());
+ for (SelContainer::const_iterator i = items.begin();i!=items.end();i++) {
+ r.unionWith(static_cast<SPItem *>(*i)->desktopVisualBounds());
}
return r;
}
@@ -948,11 +949,17 @@ static SPObject *prev_sibling(SPObject *child)
return prev;
}
+int sp_item_repr_compare_position_obj(SPObject const *first, SPObject const *second)
+{
+ return sp_repr_compare_position(((SPItem*)first)->getRepr(),
+ ((SPItem*)second)->getRepr())<0;
+}
+
void
sp_selection_raise(Inkscape::Selection *selection, SPDesktop *desktop)
{
- GSList const *items = const_cast<GSList *>(selection->itemList());
- if (!items) {
+ SelContainer items= selection->itemList();
+ if (items.empty()) {
selection_display_message(desktop, Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to raise."));
return;
}
@@ -966,16 +973,16 @@ sp_selection_raise(Inkscape::Selection *selection, SPDesktop *desktop)
Inkscape::XML::Node *grepr = const_cast<Inkscape::XML::Node *>(group->getRepr());
/* Construct reverse-ordered list of selected children. */
- GSList *rev = g_slist_copy(const_cast<GSList *>(items));
- rev = g_slist_sort(rev, (GCompareFunc) sp_item_repr_compare_position);
+ SelContainer rev(items);
+ rev.sort(sp_item_repr_compare_position_obj);
// Determine the common bbox of the selected items.
Geom::OptRect selected = enclose_items(items);
// Iterate over all objects in the selection (starting from top).
if (selected) {
- while (rev) {
- SPObject *child = reinterpret_cast<SPObject*>(rev->data);
+ while (!rev.empty()) {
+ SPObject *child = reinterpret_cast<SPObject*>(rev.front());
// for each selected object, find the next sibling
for (SPObject *newref = child->next; newref; newref = newref->next) {
// if the sibling is an item AND overlaps our selection,
@@ -984,7 +991,7 @@ sp_selection_raise(Inkscape::Selection *selection, SPDesktop *desktop)
Geom::OptRect newref_bbox = newItem->desktopVisualBounds();
if ( newref_bbox && selected->intersects(*newref_bbox) ) {
// AND if it's not one of our selected objects,
- if (!g_slist_find(const_cast<GSList *>(items), newref)) {
+ if ( std::find(items.begin(),items.end(),newref)==items.end()) {
// move the selected object after that sibling
grepr->changeOrder(child->getRepr(), newref->getRepr());
}
@@ -992,10 +999,10 @@ sp_selection_raise(Inkscape::Selection *selection, SPDesktop *desktop)
}
}
}
- rev = g_slist_remove(rev, child);
+ rev.pop_front();
}
} else {
- g_slist_free(rev);
+ rev.clear();
}
DocumentUndo::done(selection->layers()->getDocument(), SP_VERB_SELECTION_RAISE,
@@ -1012,7 +1019,7 @@ void sp_selection_raise_to_top(Inkscape::Selection *selection, SPDesktop *deskto
return;
}
- GSList const *items = const_cast<GSList *>(selection->itemList());
+ SelContainer items = selection->itemList();
SPGroup const *group = sp_item_list_common_parent_group(items);
if (!group) {
@@ -1020,15 +1027,15 @@ void sp_selection_raise_to_top(Inkscape::Selection *selection, SPDesktop *deskto
return;
}
- GSList *rl = g_slist_copy(const_cast<GSList *>(selection->reprList()));
- rl = g_slist_sort(rl, (GCompareFunc) sp_repr_compare_position);
+ SelContainer rl(selection->reprList());
+ rl.sort(sp_repr_compare_position_obj);
- for (GSList *l = rl; l != NULL; l = l->next) {
- Inkscape::XML::Node *repr = static_cast<Inkscape::XML::Node *>(l->data);
+ for (SelContainer::iterator l=rl.begin(); l!=rl.end();l++) {
+ Inkscape::XML::Node *repr = dynamic_cast<Inkscape::XML::Node *>(*l);
repr->setPosition(-1);
}
- g_slist_free(rl);
+ rl.clear();
DocumentUndo::done(document, SP_VERB_SELECTION_TO_FRONT,
_("Raise to top"));
@@ -1036,8 +1043,8 @@ void sp_selection_raise_to_top(Inkscape::Selection *selection, SPDesktop *deskto
void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop)
{
- GSList const *items = const_cast<GSList *>(selection->itemList());
- if (!items) {
+ SelContainer items = selection->itemList();
+ if (items.empty()) {
selection_display_message(desktop, Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to lower."));
return;
}
@@ -1054,14 +1061,14 @@ void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop)
Geom::OptRect selected = enclose_items(items);
/* Construct direct-ordered list of selected children. */
- GSList *rev = g_slist_copy(const_cast<GSList *>(items));
- rev = g_slist_sort(rev, (GCompareFunc) sp_item_repr_compare_position);
- rev = g_slist_reverse(rev);
+ SelContainer rev(items);
+ rev.sort(sp_item_repr_compare_position_obj);
+ rev.reverse();
// Iterate over all objects in the selection (starting from top).
if (selected) {
- while (rev) {
- SPObject *child = reinterpret_cast<SPObject*>(rev->data);
+ while (!rev.empty()) {
+ SPObject *child = reinterpret_cast<SPObject*>(rev.front());
// for each selected object, find the prev sibling
for (SPObject *newref = prev_sibling(child); newref; newref = prev_sibling(newref)) {
// if the sibling is an item AND overlaps our selection,
@@ -1070,7 +1077,7 @@ void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop)
Geom::OptRect ref_bbox = newItem->desktopVisualBounds();
if ( ref_bbox && selected->intersects(*ref_bbox) ) {
// AND if it's not one of our selected objects,
- if (!g_slist_find(const_cast<GSList *>(items), newref)) {
+ if (items.end()==std::find(items.begin(),items.end(),newref)) {
// move the selected object before that sibling
SPObject *put_after = prev_sibling(newref);
if (put_after)
@@ -1082,10 +1089,10 @@ void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop)
}
}
}
- rev = g_slist_remove(rev, child);
+ rev.pop_front();
}
} else {
- g_slist_free(rev);
+ rev.clear();
}
DocumentUndo::done(selection->layers()->getDocument(), SP_VERB_SELECTION_LOWER,
@@ -1102,7 +1109,7 @@ void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *des
return;
}
- GSList const *items = const_cast<GSList *>(selection->itemList());
+ SelContainer items =selection->itemList();
SPGroup const *group = sp_item_list_common_parent_group(items);
if (!group) {
@@ -1110,15 +1117,14 @@ void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *des
return;
}
- GSList *rl;
- rl = g_slist_copy(const_cast<GSList *>(selection->reprList()));
- rl = g_slist_sort(rl, (GCompareFunc) sp_repr_compare_position);
- rl = g_slist_reverse(rl);
+ SelContainer rl(selection->reprList());
+ rl.sort(sp_repr_compare_position_obj);
+ rl.reverse();
- for (GSList *l = rl; l != NULL; l = l->next) {
+ for (SelContainer::const_iterator l=rl.begin();l!=rl.end();l++) {
gint minpos;
SPObject *pp, *pc;
- Inkscape::XML::Node *repr = static_cast<Inkscape::XML::Node *>(l->data);
+ Inkscape::XML::Node *repr = dynamic_cast<Inkscape::XML::Node *>(*l);
pp = document->getObjectByRepr(repr->parent());
minpos = 0;
g_assert(dynamic_cast<SPGroup *>(pp));
@@ -1130,7 +1136,7 @@ void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *des
repr->setPosition(minpos);
}
- g_slist_free(rl);
+ rl.clear();
DocumentUndo::done(document, SP_VERB_SELECTION_TO_BACK,
_("Lower to bottom"));
@@ -1269,9 +1275,9 @@ void sp_selection_remove_livepatheffect(SPDesktop *desktop)
desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to remove live path effects from."));
return;
}
-
- for ( GSList const *itemlist = selection->itemList(); itemlist != NULL; itemlist = g_slist_next(itemlist) ) {
- SPItem *item = reinterpret_cast<SPItem*>(itemlist->data);
+ SelContainer list=selection->itemList();
+ for ( SelContainer::const_iterator itemlist=list.begin();itemlist!=list.end();itemlist++) {
+ SPItem *item = reinterpret_cast<SPItem*>(*itemlist);
sp_selection_remove_livepatheffect_impl(item);
@@ -1331,25 +1337,25 @@ void sp_selection_to_next_layer(SPDesktop *dt, bool suppressDone)
return;
}
- GSList const *items = g_slist_copy(const_cast<GSList *>(selection->itemList()));
+ SelContainer items(selection->itemList());
bool no_more = false; // Set to true, if no more layers above
SPObject *next=Inkscape::next_layer(dt->currentRoot(), dt->currentLayer());
if (next) {
- GSList *temp_clip = NULL;
- sp_selection_copy_impl(items, &temp_clip, dt->doc()->getReprDoc());
+ SelContainer temp_clip;
+ sp_selection_copy_impl(items, temp_clip, dt->doc()->getReprDoc());
sp_selection_delete_impl(items, false, false);
next=Inkscape::next_layer(dt->currentRoot(), dt->currentLayer()); // Fixes bug 1482973: crash while moving layers
- GSList *copied;
+ SelContainer copied;
if (next) {
- copied = sp_selection_paste_impl(dt->getDocument(), next, &temp_clip);
+ copied = sp_selection_paste_impl(dt->getDocument(), next, temp_clip);
} else {
- copied = sp_selection_paste_impl(dt->getDocument(), dt->currentLayer(), &temp_clip);
+ copied = sp_selection_paste_impl(dt->getDocument(), dt->currentLayer(), temp_clip);
no_more = true;
}
- selection->setReprList((GSList const *) copied);
- g_slist_free(copied);
- if (temp_clip) g_slist_free(temp_clip);
+ selection->setReprList(copied);
+ copied.clear();
+ if (!temp_clip.empty()) temp_clip.clear();
if (next) dt->setCurrentLayer(next);
if ( !suppressDone ) {
DocumentUndo::done(dt->getDocument(), SP_VERB_LAYER_MOVE_TO_NEXT,
@@ -1363,7 +1369,7 @@ void sp_selection_to_next_layer(SPDesktop *dt, bool suppressDone)
dt->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("No more layers above."));
}
- g_slist_free(const_cast<GSList *>(items));
+ items.clear();
}
void sp_selection_to_prev_layer(SPDesktop *dt, bool suppressDone)
@@ -1376,25 +1382,25 @@ void sp_selection_to_prev_layer(SPDesktop *dt, bool suppressDone)
return;
}
- GSList const *items = g_slist_copy(const_cast<GSList *>(selection->itemList()));
+ const SelContainer items(selection->itemList());
bool no_more = false; // Set to true, if no more layers below
SPObject *next=Inkscape::previous_layer(dt->currentRoot(), dt->currentLayer());
if (next) {
- GSList *temp_clip = NULL;
- sp_selection_copy_impl(items, &temp_clip, dt->doc()->getReprDoc()); // we're in the same doc, so no need to copy defs
+ SelContainer temp_clip;
+ sp_selection_copy_impl(items, temp_clip, dt->doc()->getReprDoc()); // we're in the same doc, so no need to copy defs
sp_selection_delete_impl(items, false, false);
next=Inkscape::previous_layer(dt->currentRoot(), dt->currentLayer()); // Fixes bug 1482973: crash while moving layers
- GSList *copied;
+ SelContainer copied;
if (next) {
- copied = sp_selection_paste_impl(dt->getDocument(), next, &temp_clip);
+ copied = sp_selection_paste_impl(dt->getDocument(), next, temp_clip);
} else {
- copied = sp_selection_paste_impl(dt->getDocument(), dt->currentLayer(), &temp_clip);
+ copied = sp_selection_paste_impl(dt->getDocument(), dt->currentLayer(), temp_clip);
no_more = true;
}
- selection->setReprList((GSList const *) copied);
- g_slist_free(copied);
- if (temp_clip) g_slist_free(temp_clip);
+ selection->setReprList( copied);
+ copied.clear();
+ if (!temp_clip.empty()) temp_clip.clear();
if (next) dt->setCurrentLayer(next);
if ( !suppressDone ) {
DocumentUndo::done(dt->getDocument(), SP_VERB_LAYER_MOVE_TO_PREV,
@@ -1407,8 +1413,6 @@ void sp_selection_to_prev_layer(SPDesktop *dt, bool suppressDone)
if (no_more) {
dt->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("No more layers below."));
}
-
- g_slist_free(const_cast<GSList *>(items));
}
void sp_selection_to_layer(SPDesktop *dt, SPObject *moveto, bool suppressDone)
@@ -1421,24 +1425,22 @@ void sp_selection_to_layer(SPDesktop *dt, SPObject *moveto, bool suppressDone)
return;
}
- GSList const *items = g_slist_copy(const_cast<GSList *>(selection->itemList()));
+ SelContainer items(selection->itemList());
if (moveto) {
- GSList *temp_clip = NULL;
- sp_selection_copy_impl(items, &temp_clip, dt->doc()->getReprDoc()); // we're in the same doc, so no need to copy defs
+ SelContainer temp_clip;
+ sp_selection_copy_impl(items, temp_clip, dt->doc()->getReprDoc()); // we're in the same doc, so no need to copy defs
sp_selection_delete_impl(items, false, false);
- GSList *copied = sp_selection_paste_impl(dt->getDocument(), moveto, &temp_clip);
- selection->setReprList((GSList const *) copied);
- g_slist_free(copied);
- if (temp_clip) g_slist_free(temp_clip);
+ SelContainer copied = sp_selection_paste_impl(dt->getDocument(), moveto, temp_clip);
+ selection->setReprList(copied);
+ copied.clear();
+ if (!temp_clip.empty()) temp_clip.clear();
if (moveto) dt->setCurrentLayer(moveto);
if ( !suppressDone ) {
DocumentUndo::done(dt->getDocument(), SP_VERB_LAYER_MOVE_TO,
_("Move selection to layer"));
}
}
-
- g_slist_free(const_cast<GSList *>(items));
}
static bool
@@ -1473,8 +1475,9 @@ static bool
selection_contains_both_clone_and_original(Inkscape::Selection *selection)
{
bool clone_with_original = false;
- for (GSList const *l = selection->itemList(); l != NULL; l = l->next) {
- SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(l->data));
+ SelContainer items = selection->itemList();
+ for (SelContainer::const_iterator l=items.begin();l!=items.end() ;l++) {
+ SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(*l));
if (item) {
clone_with_original |= selection_contains_original(item, selection);
if (clone_with_original)
@@ -1517,9 +1520,9 @@ void sp_selection_apply_affine(Inkscape::Selection *selection, Geom::Affine cons
persp3d_apply_affine_transformation(transf_persp, affine);
}
-
- for (GSList const *l = selection->itemList(); l != NULL; l = l->next) {
- SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(l->data));
+ SelContainer items = selection->itemList();
+ for (SelContainer::const_iterator l=items.begin();l!=items.end() ;l++) {
+ SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(*l));
if( dynamic_cast<SPRoot *>(item) ) {
// An SVG element cannot have a transform. We could change 'x' and 'y' in response
@@ -1688,10 +1691,9 @@ void sp_selection_remove_transform(SPDesktop *desktop)
Inkscape::Selection *selection = desktop->getSelection();
- GSList const *l = const_cast<GSList *>(selection->reprList());
- while (l != NULL) {
- ((Inkscape::XML::Node*)l->data)->setAttribute("transform", NULL, false);
- l = l->next;
+ SelContainer items = selection->itemList();
+ for (SelContainer::const_iterator l=items.begin();l!=items.end() ;l++) {
+ ((Inkscape::XML::Node*)*l)->setAttribute("transform", NULL, false);
}
DocumentUndo::done(desktop->getDocument(), SP_VERB_OBJECT_FLATTEN,
@@ -1789,10 +1791,10 @@ void sp_selection_rotate_90(SPDesktop *desktop, bool ccw)
if (selection->isEmpty())
return;
- GSList const *l = selection->itemList();
+ SelContainer items = selection->itemList();
Geom::Rotate const rot_90(Geom::Point(0, ccw ? 1 : -1)); // pos. or neg. rotation, depending on the value of ccw
- for (GSList const *l2 = l ; l2 != NULL ; l2 = l2->next) {
- SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(l2->data));
+ for (SelContainer::const_iterator l=items.begin();l!=items.end() ;l++) {
+ SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(*l));
if (item) {
sp_item_rotate_rel(item, rot_90);
} else {
@@ -1848,15 +1850,15 @@ void sp_select_same_fill_stroke_style(SPDesktop *desktop, gboolean fill, gboolea
bool onlyvisible = prefs->getBool("/options/kbselection/onlyvisible", true);
bool onlysensitive = prefs->getBool("/options/kbselection/onlysensitive", true);
bool ingroups = TRUE;
-
- GSList *all_list = get_all_items(NULL, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, NULL);
- GSList *all_matches = NULL;
+ SelContainer x,y;
+ SelContainer all_list = get_all_items(x, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, y);
+ SelContainer all_matches;
Inkscape::Selection *selection = desktop->getSelection();
-
- for (GSList const* sel_iter = selection->itemList(); sel_iter; sel_iter = sel_iter->next) {
- SPItem *sel = dynamic_cast<SPItem *>(static_cast<SPObject *>(sel_iter->data));
- GSList *matches = all_list;
+ SelContainer items = selection->itemList();
+ for (SelContainer::const_iterator sel_iter=items.begin();sel_iter!=items.end();sel_iter++) {
+ SPItem *sel = dynamic_cast<SPItem *>(static_cast<SPObject *>(*sel_iter));
+ SelContainer matches = all_list;
if (fill) {
matches = sp_get_same_fill_or_stroke_color(sel, matches, SP_FILL_COLOR);
}
@@ -1868,19 +1870,12 @@ void sp_select_same_fill_stroke_style(SPDesktop *desktop, gboolean fill, gboolea
matches = sp_get_same_stroke_style(sel, matches, SP_STROKE_STYLE_DASHES);
matches = sp_get_same_stroke_style(sel, matches, SP_STROKE_STYLE_MARKERS);
}
- all_matches = g_slist_concat (all_matches, matches);
+ all_matches.splice(all_matches.end(), matches);
}
selection->clear();
selection->setList(all_matches);
- if (all_matches) {
- g_slist_free(all_matches);
- }
- if (all_list) {
- g_slist_free(all_list);
- }
-
}
@@ -1901,14 +1896,15 @@ void sp_select_same_object_type(SPDesktop *desktop)
bool onlyvisible = prefs->getBool("/options/kbselection/onlyvisible", true);
bool onlysensitive = prefs->getBool("/options/kbselection/onlysensitive", true);
bool ingroups = TRUE;
-
- GSList *all_list = get_all_items(NULL, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, NULL);
- GSList *matches = all_list;
+ SelContainer x,y;
+ SelContainer all_list = get_all_items(x, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, y);
+ SelContainer matches = all_list;
Inkscape::Selection *selection = desktop->getSelection();
- for (GSList const* sel_iter = selection->itemList(); sel_iter; sel_iter = sel_iter->next) {
- SPItem *sel = dynamic_cast<SPItem *>(static_cast<SPObject *>(sel_iter->data));
+ SelContainer items=selection->itemList();
+ for (SelContainer::const_iterator sel_iter=items.begin();sel_iter!=items.end();sel_iter++) {
+ SPItem *sel = dynamic_cast<SPItem *>(static_cast<SPObject *>(*sel_iter));
if (sel) {
matches = sp_get_same_object_type(sel, matches);
} else {
@@ -1919,12 +1915,6 @@ void sp_select_same_object_type(SPDesktop *desktop)
selection->clear();
selection->setList(matches);
- if (matches) {
- g_slist_free(matches);
- }
- if (all_list) {
- g_slist_free(all_list);
- }
}
/*
@@ -1944,13 +1934,14 @@ void sp_select_same_stroke_style(SPDesktop *desktop)
bool onlysensitive = prefs->getBool("/options/kbselection/onlysensitive", true);
bool ingroups = TRUE;
- GSList *all_list = get_all_items(NULL, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, NULL);
- GSList *matches = all_list;
+ SelContainer x,y;
+ SelContainer matches = get_all_items(x, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, y);
Inkscape::Selection *selection = desktop->getSelection();
+ SelContainer items=selection->itemList();
- for (GSList const* sel_iter = selection->itemList(); sel_iter; sel_iter = sel_iter->next) {
- SPItem *sel = dynamic_cast<SPItem *>(static_cast<SPObject *>(sel_iter->data));
+ for (SelContainer::const_iterator sel_iter=items.begin();sel_iter!=items.end();sel_iter++) {
+ SPItem *sel = dynamic_cast<SPItem *>(static_cast<SPObject *>(*sel_iter));
if (sel) {
matches = sp_get_same_stroke_style(sel, matches, SP_STROKE_STYLE_WIDTH);
matches = sp_get_same_stroke_style(sel, matches, SP_STROKE_STYLE_DASHES);
@@ -1963,27 +1954,21 @@ void sp_select_same_stroke_style(SPDesktop *desktop)
selection->clear();
selection->setList(matches);
- if (matches) {
- g_slist_free(matches);
- }
- if (all_list) {
- g_slist_free(all_list);
- }
}
/*
* Find all items in src list that have the same fill or stroke style as sel
* Return the list of matching items
*/
-GSList *sp_get_same_fill_or_stroke_color(SPItem *sel, GSList *src, SPSelectStrokeStyleType type)
+SelContainer sp_get_same_fill_or_stroke_color(SPItem *sel, SelContainer &src, SPSelectStrokeStyleType type)
{
- GSList *matches = NULL;
+ SelContainer matches ;
gboolean match = false;
SPIPaint *sel_paint = (type == SP_FILL_COLOR) ? &(sel->style->fill) : &(sel->style->stroke);
- for (GSList *i = src; i != NULL; i = i->next) {
- SPItem *iter = dynamic_cast<SPItem *>(static_cast<SPObject *>(i->data));
+ for (SelContainer::const_iterator i=src.begin();i!=src.end();i++) {
+ SPItem *iter = dynamic_cast<SPItem *>(static_cast<SPObject *>(*i));
if (iter) {
SPIPaint *iter_paint = (type == SP_FILL_COLOR) ? &(iter->style->fill) : &(iter->style->stroke);
match = false;
@@ -2022,7 +2007,7 @@ GSList *sp_get_same_fill_or_stroke_color(SPItem *sel, GSList *src, SPSelectStrok
}
if (match) {
- matches = g_slist_prepend(matches, iter);
+ matches.push_front(iter);
}
} else {
g_assert_not_reached();
@@ -2073,17 +2058,16 @@ static bool item_type_match (SPItem *i, SPItem *j)
* Find all items in src list that have the same object type as sel by type
* Return the list of matching items
*/
-GSList *sp_get_same_object_type(SPItem *sel, GSList *src)
+SelContainer sp_get_same_object_type(SPItem *sel, SelContainer &src)
{
- GSList *matches = NULL;
+ SelContainer matches;
- for (GSList *i = src; i != NULL; i = i->next) {
- SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(i->data));
+ for (SelContainer::const_iterator i=src.begin();i!=src.end();i++) {
+ SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(*i));
if (item && item_type_match(sel, item)) {
- matches = g_slist_prepend (matches, item);
+ matches.push_front(item);
}
}
-
return matches;
}
@@ -2091,9 +2075,9 @@ GSList *sp_get_same_object_type(SPItem *sel, GSList *src)
* Find all items in src list that have the same stroke style as sel by type
* Return the list of matching items
*/
-GSList *sp_get_same_stroke_style(SPItem *sel, GSList *src, SPSelectStrokeStyleType type)
+SelContainer sp_get_same_stroke_style(SPItem *sel, SelContainer &src, SPSelectStrokeStyleType type)
{
- GSList *matches = NULL;
+ SelContainer matches;
gboolean match = false;
SPStyle *sel_style = sel->style;
@@ -2106,16 +2090,15 @@ GSList *sp_get_same_stroke_style(SPItem *sel, GSList *src, SPSelectStrokeStyleTy
* Stroke width needs to handle transformations, so call this function
* to get the transformed stroke width
*/
- GSList *objects = NULL;
+ SelContainer objects;
SPStyle *sel_style_for_width = NULL;
if (type == SP_STROKE_STYLE_WIDTH) {
- objects = g_slist_prepend(objects, sel);
+ objects.push_front(sel);
sel_style_for_width = new SPStyle(SP_ACTIVE_DOCUMENT);
objects_query_strokewidth (objects, sel_style_for_width);
}
-
- for (GSList *i = src; i != NULL; i = i->next) {
- SPItem *iter = dynamic_cast<SPItem *>(static_cast<SPObject *>(i->data));
+ for (SelContainer::const_iterator i=src.begin();i!=src.end();i++) {
+ SPItem *iter = dynamic_cast<SPItem *>(static_cast<SPObject *>(*i));
if (iter) {
SPStyle *iter_style = iter->style;
match = false;
@@ -2123,15 +2106,15 @@ GSList *sp_get_same_stroke_style(SPItem *sel, GSList *src, SPSelectStrokeStyleTy
if (type == SP_STROKE_STYLE_WIDTH) {
match = (sel_style->stroke_width.set == iter_style->stroke_width.set);
if (sel_style->stroke_width.set && iter_style->stroke_width.set) {
- GSList *objects = NULL;
- objects = g_slist_prepend(objects, iter);
+ SelContainer objects;
+ objects.push_front(iter);
SPStyle tmp_style(SP_ACTIVE_DOCUMENT);
objects_query_strokewidth (objects, &tmp_style);
if (sel_style_for_width) {
match = (sel_style_for_width->stroke_width.computed == tmp_style.stroke_width.computed);
}
- g_slist_free(objects);
+ objects.clear();
}
}
else if (type == SP_STROKE_STYLE_DASHES ) {
@@ -2154,7 +2137,7 @@ GSList *sp_get_same_stroke_style(SPItem *sel, GSList *src, SPSelectStrokeStyleTy
}
if (match) {
- matches = g_slist_prepend(matches, iter);
+ matches.push_front(iter);
}
} else {
g_assert_not_reached();
@@ -2162,8 +2145,6 @@ GSList *sp_get_same_stroke_style(SPItem *sel, GSList *src, SPSelectStrokeStyleTy
}
if( sel_style_for_width != NULL ) delete sel_style_for_width;
- g_slist_free(objects);
-
return matches;
}
@@ -2320,11 +2301,11 @@ sp_selection_move_screen(Inkscape::Selection *selection, gdouble dx, gdouble dy)
namespace {
template <typename D>
-SPItem *next_item(SPDesktop *desktop, GSList *path, SPObject *root,
+SPItem *next_item(SPDesktop *desktop, SelContainer &path, SPObject *root,
bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive);
template <typename D>
-SPItem *next_item_from_list(SPDesktop *desktop, GSList const *items, SPObject *root,
+SPItem *next_item_from_list(SPDesktop *desktop, SelContainer const &items, SPObject *root,
bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive);
struct Forward {
@@ -2618,17 +2599,17 @@ void sp_selection_clone(SPDesktop *desktop)
return;
}
- GSList *reprs = g_slist_copy(const_cast<GSList *>(selection->reprList()));
+ SelContainer reprs (selection->reprList());
selection->clear();
// sorting items from different parents sorts each parent's subset without possibly mixing them, just what we need
- reprs = g_slist_sort(reprs, (GCompareFunc) sp_repr_compare_position);
+ reprs.sort(sp_repr_compare_position_obj);
- GSList *newsel = NULL;
+ SelContainer newsel;
- while (reprs) {
- Inkscape::XML::Node *sel_repr = static_cast<Inkscape::XML::Node *>(reprs->data);
+ while (!reprs.empty()) {
+ Inkscape::XML::Node *sel_repr = dynamic_cast<Inkscape::XML::Node *>(reprs.front());
Inkscape::XML::Node *parent = sel_repr->parent();
Inkscape::XML::Node *clone = xml_doc->createElement("svg:use");
@@ -2644,8 +2625,8 @@ void sp_selection_clone(SPDesktop *desktop)
// add the new clone to the top of the original's parent
parent->appendChild(clone);
- newsel = g_slist_prepend(newsel, clone);
- reprs = g_slist_remove(reprs, sel_repr);
+ newsel.push_front(dynamic_cast<SPObject*>(clone));
+ reprs.pop_front();
Inkscape::GC::release(clone);
}
@@ -2653,8 +2634,6 @@ void sp_selection_clone(SPDesktop *desktop)
C_("Action", "Clone"));
selection->setReprList(newsel);
-
- g_slist_free(newsel);
}
void
@@ -2680,11 +2659,9 @@ sp_selection_relink(SPDesktop *desktop)
// Get a copy of current selection.
bool relinked = false;
- for (GSList *items = const_cast<GSList *>(selection->itemList());
- items != NULL;
- items = items->next)
- {
- SPItem *item = static_cast<SPItem *>(items->data);
+ SelContainer items=selection->itemList();
+ for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){
+ SPItem *item = static_cast<SPItem *>(*i);
if (dynamic_cast<SPUse *>(item)) {
item->getRepr()->setAttribute("xlink:href", newref);
@@ -2718,13 +2695,11 @@ sp_selection_unlink(SPDesktop *desktop)
}
// Get a copy of current selection.
- GSList *new_select = NULL;
+ SelContainer new_select;
bool unlinked = false;
- for (GSList *items = g_slist_copy(const_cast<GSList *>(selection->itemList()));
- items != NULL;
- items = items->next)
- {
- SPItem *item = static_cast<SPItem *>(items->data);
+ SelContainer items=selection->itemList();
+ for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){
+ SPItem *item = static_cast<SPItem *>(*i);
if (dynamic_cast<SPText *>(item)) {
SPObject *tspan = sp_tref_convert_to_tspan(item);
@@ -2740,7 +2715,7 @@ sp_selection_unlink(SPDesktop *desktop)
if (!(dynamic_cast<SPUse *>(item) || dynamic_cast<SPTRef *>(item))) {
// keep the non-use item in the new selection
- new_select = g_slist_prepend(new_select, item);
+ new_select.push_front(item);
continue;
}
@@ -2750,7 +2725,7 @@ sp_selection_unlink(SPDesktop *desktop)
unlink = use->unlink();
// Unable to unlink use (external or invalid href?)
if (!unlink) {
- new_select = g_slist_prepend(new_select, item);
+ new_select.push_front(item);
continue;
}
} else /*if (SP_IS_TREF(use))*/ {
@@ -2760,13 +2735,12 @@ sp_selection_unlink(SPDesktop *desktop)
unlinked = true;
// Add ungrouped items to the new selection.
- new_select = g_slist_prepend(new_select, unlink);
+ new_select.push_front(unlink);
}
- if (new_select) { // set new selection
+ if (!new_select.empty()) { // set new selection
selection->clear();
selection->setList(new_select);
- g_slist_free(new_select);
}
if (!unlinked) {
desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No clones to unlink</b> in the selection."));
@@ -2789,7 +2763,9 @@ sp_select_clone_original(SPDesktop *desktop)
gchar const *error = _("Select a <b>clone</b> to go to its original. Select a <b>linked offset</b> to go to its source. Select a <b>text on path</b> to go to the path. Select a <b>flowed text</b> to go to its frame.");
// Check if other than two objects are selected
- if (g_slist_length(const_cast<GSList *>(selection->itemList())) != 1 || !item) {
+
+ SelContainer items=selection->itemList();
+ if (items.size() != 1 || !item) {
desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, error);
return;
}
@@ -2886,14 +2862,15 @@ void sp_selection_clone_original_path_lpe(SPDesktop *desktop)
Inkscape::SVGOStringStream os;
SPObject * firstItem = NULL;
- for (const GSList * item = selection->itemList(); item != NULL; item = item->next) {
- if (SP_IS_SHAPE(item->data) || SP_IS_TEXT(item->data)) {
+ SelContainer items=selection->itemList();
+ for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){
+ if (SP_IS_SHAPE(*i) || SP_IS_TEXT(*i)) {
if (firstItem) {
os << "|";
} else {
- firstItem = SP_ITEM(item->data);
+ firstItem = SP_ITEM(*i);
}
- os << '#' << SP_ITEM(item->data)->getId() << ",0";
+ os << '#' << SP_ITEM(*i)->getId() << ",0";
}
}
if (firstItem) {
@@ -2970,12 +2947,12 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply)
Geom::Point center( *c - corner ); // As defined by rotation center
center[Geom::Y] = -center[Geom::Y];
- GSList *items = g_slist_copy(const_cast<GSList *>(selection->itemList()));
+ SelContainer items(selection->itemList());
//items = g_slist_sort(items, (GCompareFunc) sp_object_compare_position); // Why needed?
// bottommost object, after sorting
- SPObject *parent = SP_OBJECT(items->data)->parent;
+ SPObject *parent = SP_OBJECT(items.front())->parent;
Geom::Affine parent_transform;
{
@@ -2988,10 +2965,10 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply)
}
// Create a list of duplicates, to be pasted inside marker element.
- GSList *repr_copies = NULL;
- for (GSList *i = items; i != NULL; i = i->next) {
- Inkscape::XML::Node *dup = SP_OBJECT(i->data)->getRepr()->duplicate(xml_doc);
- repr_copies = g_slist_prepend(repr_copies, dup);
+ SelContainer repr_copies;
+ for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){
+ Inkscape::XML::Node *dup = SP_OBJECT(*i)->getRepr()->duplicate(xml_doc);
+ repr_copies.push_front(dynamic_cast<SPObject*>(dup));
}
Geom::Rect bbox(desktop->dt2doc(r->min()), desktop->dt2doc(r->max()));
@@ -2999,8 +2976,8 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply)
if (apply) {
// Delete objects so that their clones don't get alerted;
// the objects will be restored inside the marker element.
- for (GSList *i = items; i != NULL; i = i->next) {
- SPObject *item = reinterpret_cast<SPObject*>(i->data);
+ for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){
+ SPObject *item = reinterpret_cast<SPObject*>(*i);
item->deleteObject(false);
}
}
@@ -3019,7 +2996,6 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply)
prefs->setInt("/options/clonecompensation/value", saved_compensation);
- g_slist_free(items);
DocumentUndo::done(doc, SP_VERB_EDIT_SELECTION_2_MARKER,
_("Objects to marker"));
@@ -3028,8 +3004,9 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply)
static void sp_selection_to_guides_recursive(SPItem *item, bool wholegroups) {
SPGroup *group = dynamic_cast<SPGroup *>(item);
if (group && !dynamic_cast<SPBox3D *>(item) && !wholegroups) {
- for (GSList *i = sp_item_group_item_list(group); i != NULL; i = i->next) {
- sp_selection_to_guides_recursive(static_cast<SPItem*>(i->data), wholegroups);
+ SelContainer items=sp_item_group_item_list(group);
+ for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){
+ sp_selection_to_guides_recursive(static_cast<SPItem*>(*i), wholegroups);
}
} else {
item->convert_to_guides();
@@ -3044,9 +3021,9 @@ void sp_selection_to_guides(SPDesktop *desktop)
SPDocument *doc = desktop->getDocument();
Inkscape::Selection *selection = desktop->getSelection();
// we need to copy the list because it gets reset when objects are deleted
- GSList *items = g_slist_copy(const_cast<GSList *>(selection->itemList()));
+ SelContainer items(selection->itemList());
- if (!items) {
+ if (items.empty()) {
desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to convert to guides."));
return;
}
@@ -3059,8 +3036,8 @@ void sp_selection_to_guides(SPDesktop *desktop)
// and its entry in the selection list is invalid (crash).
// Therefore: first convert all, then delete all.
- for (GSList const *i = items; i != NULL; i = i->next) {
- sp_selection_to_guides_recursive(static_cast<SPItem*>(i->data), wholegroups);
+ for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){
+ sp_selection_to_guides_recursive(static_cast<SPItem*>(*i), wholegroups);
}
if (deleteitems) {
@@ -3068,8 +3045,6 @@ void sp_selection_to_guides(SPDesktop *desktop)
sp_selection_delete_impl(items);
}
- g_slist_free(items);
-
DocumentUndo::done(doc, SP_VERB_EDIT_SELECTION_2_GUIDES, _("Objects to guides"));
}
@@ -3112,18 +3087,18 @@ void sp_selection_symbol(SPDesktop *desktop, bool /*apply*/ )
doc->ensureUpToDate();
- GSList *items = g_slist_copy(const_cast<GSList *>(selection->list()));
+ SelContainer items(selection->list());
// Keep track of parent, this is where <use> will be inserted.
- Inkscape::XML::Node *the_first_repr = reinterpret_cast<SPObject *>( items->data )->getRepr();
+ Inkscape::XML::Node *the_first_repr = reinterpret_cast<SPObject *>( items.front() )->getRepr();
Inkscape::XML::Node *the_parent_repr = the_first_repr->parent();
// Find out if we have a single group
bool single_group = false;
SPGroup *the_group = NULL;
Geom::Affine transform;
- if( g_slist_length( items ) == 1 ) {
- SPObject *object = reinterpret_cast<SPObject *>( items->data );
+ if( items.size() == 1 ) {
+ SPObject *object = reinterpret_cast<SPObject *>( items.front() );
the_group = dynamic_cast<SPGroup *>(object);
if ( the_group ) {
single_group = true;
@@ -3134,7 +3109,6 @@ void sp_selection_symbol(SPDesktop *desktop, bool /*apply*/ )
if( transform.isTranslation() ) {
// Create new list from group children.
- g_slist_free(items);
items = object->childList(false);
// Hack: Temporarily set clone compensation to unmoved, so that we can move clone-originals
@@ -3180,8 +3154,8 @@ void sp_selection_symbol(SPDesktop *desktop, bool /*apply*/ )
}
// Move selected items to new <symbol>
- for (GSList *i = items; i != NULL; i = i->next) {
- Inkscape::XML::Node *repr = SP_OBJECT(i->data)->getRepr();
+ for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){
+ Inkscape::XML::Node *repr = SP_OBJECT(*i)->getRepr();
repr->parent()->removeChild(repr);
symbol_repr->addChild(repr,NULL);
}
@@ -3207,7 +3181,6 @@ void sp_selection_symbol(SPDesktop *desktop, bool /*apply*/ )
// Clean up
Inkscape::GC::release(symbol_repr);
- g_slist_free(items);
DocumentUndo::done(doc, SP_VERB_EDIT_SYMBOL, _("Group to symbol"));
}
@@ -3248,26 +3221,25 @@ void sp_selection_unsymbol(SPDesktop *desktop)
desktop->currentLayer()->getRepr()->appendChild(group);
// Move all children of symbol to group
- GSList* children = symbol->childList(false);
+ SelContainer children = symbol->childList(false);
// Converting a group to a symbol inserts a group for non-translational transform.
// In converting a symbol back to a group we strip out the inserted group (or any other
// group that only adds a transform to the symbol content).
- if( g_slist_length( children ) == 1 ) {
- SPObject *object = reinterpret_cast<SPObject *>( children->data );
+ if( children.size() == 1 ) {
+ SPObject *object = reinterpret_cast<SPObject *>( children.front() );
if ( dynamic_cast<SPGroup *>( object ) ) {
if( object->getAttribute("style") == NULL ||
object->getAttribute("class") == NULL ) {
group->setAttribute("transform", object->getAttribute("transform"));
- g_slist_free(children);
children = object->childList(false);
}
}
}
- for (GSList* i = children; i != NULL; i = i->next ) {
- Inkscape::XML::Node *repr = SP_OBJECT(i->data)->getRepr();
+ for (SelContainer::const_iterator i=children.begin();i!=children.end();i++){
+ Inkscape::XML::Node *repr = SP_OBJECT(*i)->getRepr();
repr->parent()->removeChild(repr);
group->addChild(repr,NULL);
}
@@ -3293,7 +3265,6 @@ void sp_selection_unsymbol(SPDesktop *desktop)
// Clean up
Inkscape::GC::release(group);
- g_slist_free(children);
DocumentUndo::done(doc, SP_VERB_EDIT_UNSYMBOL, _("Group from symbol"));
}
@@ -3328,12 +3299,12 @@ sp_selection_tile(SPDesktop *desktop, bool apply)
move_p[Geom::Y] = -move_p[Geom::Y];
Geom::Affine move = Geom::Affine(Geom::Translate(move_p));
- GSList *items = g_slist_copy(const_cast<GSList *>(selection->itemList()));
+ SelContainer items (selection->itemList());
- items = g_slist_sort(items, (GCompareFunc) sp_object_compare_position);
+ items.sort(sp_object_compare_position);
// bottommost object, after sorting
- SPObject *parent = SP_OBJECT(items->data)->parent;
+ SPObject *parent = SP_OBJECT(items.front())->parent;
Geom::Affine parent_transform;
@@ -3347,23 +3318,23 @@ sp_selection_tile(SPDesktop *desktop, bool apply)
}
// remember the position of the first item
- gint pos = SP_OBJECT(items->data)->getRepr()->position();
+ gint pos = SP_OBJECT(items.front())->getRepr()->position();
// create a list of duplicates
- GSList *repr_copies = NULL;
- for (GSList *i = items; i != NULL; i = i->next) {
- Inkscape::XML::Node *dup = SP_OBJECT(i->data)->getRepr()->duplicate(xml_doc);
- repr_copies = g_slist_prepend(repr_copies, dup);
+ SelContainer repr_copies;
+ for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){
+ Inkscape::XML::Node *dup = SP_OBJECT(*i)->getRepr()->duplicate(xml_doc);
+ repr_copies.push_front(dynamic_cast<SPObject*>(dup));
}
// restore the z-order after prepends
- repr_copies = g_slist_reverse(repr_copies);
+ repr_copies.reverse();
Geom::Rect bbox(desktop->dt2doc(r->min()), desktop->dt2doc(r->max()));
if (apply) {
// delete objects so that their clones don't get alerted; this object will be restored shortly
- for (GSList *i = items; i != NULL; i = i->next) {
- SPObject *item = reinterpret_cast<SPObject*>(i->data);
+ for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){
+ SPObject *item = reinterpret_cast<SPObject*>(*i);
item->deleteObject(false);
}
}
@@ -3409,7 +3380,6 @@ sp_selection_tile(SPDesktop *desktop, bool apply)
selection->set(rectangle);
}
- g_slist_free(items);
DocumentUndo::done(doc, SP_VERB_EDIT_TILE,
_("Objects to pattern"));
@@ -3432,15 +3402,13 @@ void sp_selection_untile(SPDesktop *desktop)
return;
}
- GSList *new_select = NULL;
+ SelContainer new_select;
bool did = false;
- for (GSList *items = g_slist_copy(const_cast<GSList *>(selection->itemList()));
- items != NULL;
- items = items->next) {
-
- SPItem *item = static_cast<SPItem *>(items->data);
+ SelContainer items(selection->itemList());
+ for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){
+ SPItem *item = static_cast<SPItem *>(*i);
SPStyle *style = item->style;
@@ -3476,7 +3444,7 @@ void sp_selection_untile(SPDesktop *desktop)
Geom::Affine transform( i->transform * pat_transform );
i->doWriteTransform(i->getRepr(), transform);
- new_select = g_slist_prepend(new_select, i);
+ new_select.push_front(i);
} else {
g_assert_not_reached();
}
@@ -3503,18 +3471,14 @@ void sp_selection_get_export_hints(Inkscape::Selection *selection, Glib::ustring
return;
}
- GSList const *reprlst = selection->reprList();
+ SelContainer const reprlst = selection->reprList();
bool filename_search = TRUE;
bool xdpi_search = TRUE;
bool ydpi_search = TRUE;
- for (; reprlst != NULL &&
- filename_search &&
- xdpi_search &&
- ydpi_search;
- reprlst = reprlst->next) {
+ for (SelContainer::const_iterator i=reprlst.begin();filename_search&&xdpi_search&&ydpi_search&&i!=reprlst.end();i++){
gchar const *dpi_string;
- Inkscape::XML::Node * repr = static_cast<Inkscape::XML::Node *>(reprlst->data);
+ Inkscape::XML::Node * repr = dynamic_cast<Inkscape::XML::Node *>(*i);
if (filename_search) {
const gchar* tmp = repr->attribute("inkscape:export-filename");
@@ -3600,10 +3564,10 @@ void sp_selection_create_bitmap_copy(SPDesktop *desktop)
}
// List of the items to show; all others will be hidden
- GSList *items = g_slist_copy(const_cast<GSList *>(selection->itemList()));
+ SelContainer items(selection->itemList());
// Sort items so that the topmost comes last
- items = g_slist_sort(items, (GCompareFunc) sp_item_repr_compare_position);
+ items.sort(sp_item_repr_compare_position_obj);
// Generate a random value from the current time (you may create bitmap from the same object(s)
// multiple times, and this is done so that they don't clash)
@@ -3614,7 +3578,7 @@ void sp_selection_create_bitmap_copy(SPDesktop *desktop)
// Create the filename.
gchar *const basename = g_strdup_printf("%s-%s-%u.png",
document->getName(),
- SP_OBJECT(items->data)->getRepr()->attribute("id"),
+ SP_OBJECT(items.front())->getRepr()->attribute("id"),
current);
// Imagemagick is known not to handle spaces in filenames, so we replace anything but letters,
// digits, and a few other chars, with "_"
@@ -3634,8 +3598,8 @@ void sp_selection_create_bitmap_copy(SPDesktop *desktop)
//g_print("%s\n", filepath);
// Remember parent and z-order of the topmost one
- gint pos = SP_OBJECT(g_slist_last(items)->data)->getRepr()->position();
- SPObject *parent_object = SP_OBJECT(g_slist_last(items)->data)->parent;
+ gint pos = SP_OBJECT(items.back())->getRepr()->position();
+ SPObject *parent_object = SP_OBJECT(items.back())->parent;
Inkscape::XML::Node *parent = parent_object->getRepr();
// Calculate resolution
@@ -3727,8 +3691,6 @@ void sp_selection_create_bitmap_copy(SPDesktop *desktop)
true, /*bool force_overwrite,*/
items);
- g_slist_free(items);
-
// Run filter, if any
if (run) {
g_print("Running external filter: %s\n", run);
@@ -3803,22 +3765,22 @@ void sp_selection_set_clipgroup(SPDesktop *desktop)
return;
}
- GSList const *l = const_cast<GSList *>(selection->reprList());
+ SelContainer l=selection->reprList();
- GSList *p = g_slist_copy(const_cast<GSList *>(l));
+ SelContainer p(l);
- p = g_slist_sort(p, (GCompareFunc) sp_repr_compare_position);
+ p.sort(sp_repr_compare_position_obj);
selection->clear();
- gint topmost = (static_cast<Inkscape::XML::Node *>(g_slist_last(p)->data))->position();
- Inkscape::XML::Node *topmost_parent = (static_cast<Inkscape::XML::Node *>(g_slist_last(p)->data))->parent();
+ gint topmost = (dynamic_cast<Inkscape::XML::Node *>(p.back()))->position();
+ Inkscape::XML::Node *topmost_parent = (dynamic_cast<Inkscape::XML::Node *>(p.back()))->parent();
Inkscape::XML::Node *inner = xml_doc->createElement("svg:g");
inner->setAttribute("inkscape:label", "Clip");
- while (p) {
- Inkscape::XML::Node *current = static_cast<Inkscape::XML::Node *>(p->data);
+ while (!p.empty()) {
+ Inkscape::XML::Node *current = dynamic_cast<Inkscape::XML::Node *>(p.front());
if (current->parent() == topmost_parent) {
Inkscape::XML::Node *spnew = current->duplicate(xml_doc);
@@ -3827,7 +3789,7 @@ void sp_selection_set_clipgroup(SPDesktop *desktop)
Inkscape::GC::release(spnew);
topmost --; // only reduce count for those items deleted from topmost_parent
} else { // move it to topmost_parent first
- GSList *temp_clip = NULL;
+ SelContainer temp_clip;
// At this point, current may already have no item, due to its being a clone whose original is already moved away
// So we copy it artificially calculating the transform from its repr->attr("transform") and the parent transform
@@ -3843,15 +3805,14 @@ void sp_selection_set_clipgroup(SPDesktop *desktop)
// then, if this is clone, looking up its original in that array and pre-multiplying
// it by the inverse of that original's transform diff.
- sp_selection_copy_one(current, item_t, &temp_clip, xml_doc);
+ sp_selection_copy_one(current, item_t, temp_clip, xml_doc);
sp_repr_unparent(current);
// paste into topmost_parent (temporarily)
- GSList *copied = sp_selection_paste_impl(doc, doc->getObjectByRepr(topmost_parent), &temp_clip);
- if (temp_clip) g_slist_free(temp_clip);
- if (copied) { // if success,
+ SelContainer copied = sp_selection_paste_impl(doc, doc->getObjectByRepr(topmost_parent), temp_clip);
+ if (!copied.empty()) { // if success,
// take pasted object (now in topmost_parent)
- Inkscape::XML::Node *in_topmost = static_cast<Inkscape::XML::Node *>(copied->data);
+ Inkscape::XML::Node *in_topmost = dynamic_cast<Inkscape::XML::Node *>(copied.front());
// make a copy
Inkscape::XML::Node *spnew = in_topmost->duplicate(xml_doc);
// remove pasted
@@ -3859,10 +3820,9 @@ void sp_selection_set_clipgroup(SPDesktop *desktop)
// put its copy into group
inner->appendChild(spnew);
Inkscape::GC::release(spnew);
- g_slist_free(copied);
}
}
- p = g_slist_remove(p, current);
+ p.pop_front();
}
Inkscape::XML::Node *outer = xml_doc->createElement("svg:g");
@@ -3920,7 +3880,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_
if ( apply_to_layer && is_empty) {
desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to create clippath or mask from."));
return;
- } else if (!apply_to_layer && ( is_empty || NULL == selection->itemList()->next )) {
+ } else if (!apply_to_layer && ( is_empty || selection->itemList().size()==1 )) {
desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select mask object and <b>object(s)</b> to apply clippath or mask to."));
return;
}
@@ -3935,9 +3895,9 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_
doc->ensureUpToDate();
- GSList *items = g_slist_copy(const_cast<GSList *>(selection->itemList()));
+ SelContainer items(selection->itemList());
- items = g_slist_sort(items, (GCompareFunc) sp_object_compare_position);
+ items.sort(sp_object_compare_position);
// See lp bug #542004
selection->clear();
@@ -3946,7 +3906,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_
GSList *mask_items = NULL;
GSList *apply_to_items = NULL;
GSList *items_to_delete = NULL;
- GSList *items_to_select = NULL;
+ SelContainer items_to_select;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
bool topmost = prefs->getBool("/options/maskobject/topmost", true);
@@ -3957,38 +3917,38 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_
// all selected items are used for mask, which is applied to a layer
apply_to_items = g_slist_prepend(apply_to_items, desktop->currentLayer());
- for (GSList *i = items; i != NULL; i = i->next) {
- Inkscape::XML::Node *dup = SP_OBJECT(i->data)->getRepr()->duplicate(xml_doc);
+ for (SelContainer::const_iterator i=items.begin();i!=items.end();i++) {
+ Inkscape::XML::Node *dup = SP_OBJECT(*i)->getRepr()->duplicate(xml_doc);
mask_items = g_slist_prepend(mask_items, dup);
- SPObject *item = reinterpret_cast<SPObject*>(i->data);
+ SPObject *item = reinterpret_cast<SPObject*>(*i);
if (remove_original) {
items_to_delete = g_slist_prepend(items_to_delete, item);
}
else {
- items_to_select = g_slist_prepend(items_to_select, item);
+ items_to_select.push_front(item);
}
}
} else if (!topmost) {
// topmost item is used as a mask, which is applied to other items in a selection
- GSList *i = items;
- Inkscape::XML::Node *dup = SP_OBJECT(i->data)->getRepr()->duplicate(xml_doc);
+ Inkscape::XML::Node *dup = SP_OBJECT(items.front())->getRepr()->duplicate(xml_doc);
mask_items = g_slist_prepend(mask_items, dup);
if (remove_original) {
- SPObject *item = reinterpret_cast<SPObject*>(i->data);
+ SPObject *item = reinterpret_cast<SPObject*>(items.front());
items_to_delete = g_slist_prepend(items_to_delete, item);
}
- for (i = i->next; i != NULL; i = i->next) {
- apply_to_items = g_slist_prepend(apply_to_items, i->data);
- items_to_select = g_slist_prepend(items_to_select, i->data);
+ for (SelContainer::const_iterator i=items.begin();i!=items.end();i++) {
+ if(i==items.begin())continue;
+ apply_to_items = g_slist_prepend(apply_to_items, *i);
+ items_to_select.push_front(*i);
}
} else {
GSList *i = NULL;
- for (i = items; NULL != i->next; i = i->next) {
- apply_to_items = g_slist_prepend(apply_to_items, i->data);
- items_to_select = g_slist_prepend(items_to_select, i->data);
+ for (SelContainer::const_iterator i=items.begin();i!=items.end();i++) {
+ apply_to_items = g_slist_prepend(apply_to_items, *i);
+ items_to_select.push_front(*i);
}
Inkscape::XML::Node *dup = SP_OBJECT(i->data)->getRepr()->duplicate(xml_doc);
@@ -3999,9 +3959,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_
items_to_delete = g_slist_prepend(items_to_delete, item);
}
}
-
- g_slist_free(items);
- items = NULL;
+ items.clear();
if (apply_to_items && grouping == PREFS_MASKOBJECT_GROUPING_ALL) {
// group all those objects into one group
@@ -4011,24 +3969,22 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_
// make a note we should ungroup this when unsetting mask
group->setAttribute("inkscape:groupmode", "maskhelper");
- GSList *reprs_to_group = NULL;
+ SelContainer reprs_to_group;
for (GSList *i = apply_to_items ; NULL != i ; i = i->next) {
- reprs_to_group = g_slist_prepend(reprs_to_group, SP_OBJECT(i->data)->getRepr());
- items_to_select = g_slist_remove(items_to_select, i->data);
+ reprs_to_group.push_front(dynamic_cast<SPObject*>(SP_OBJECT(i->data)->getRepr()));
+ items_to_select.remove(static_cast<SPObject*>(i->data));
}
- reprs_to_group = g_slist_reverse(reprs_to_group);
+ reprs_to_group.reverse();
sp_selection_group_impl(reprs_to_group, group, xml_doc, doc);
- reprs_to_group = NULL;
-
// apply clip/mask only to newly created group
g_slist_free(apply_to_items);
apply_to_items = NULL;
apply_to_items = g_slist_prepend(apply_to_items, doc->getObjectByRepr(group));
- items_to_select = g_slist_prepend(items_to_select, doc->getObjectByRepr(group));
+ items_to_select.push_front(doc->getObjectByRepr(group));
Inkscape::GC::release(group);
}
@@ -4068,7 +4024,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_
Inkscape::XML::Node *spnew = current->duplicate(xml_doc);
gint position = current->position();
- items_to_select = g_slist_remove(items_to_select, item);
+ items_to_select.remove(item);
current->parent()->appendChild(group);
sp_repr_unparent(current);
group->appendChild(spnew);
@@ -4077,7 +4033,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_
// Apply clip/mask to group instead
apply_mask_to = group;
- items_to_select = g_slist_prepend(items_to_select, doc->getObjectByRepr(group));
+ items_to_select.push_front(doc->getObjectByRepr(group));
Inkscape::GC::release(spnew);
Inkscape::GC::release(group);
}
@@ -4092,14 +4048,13 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_
for (GSList *i = items_to_delete; NULL != i; i = i->next) {
SPObject *item = reinterpret_cast<SPObject*>(i->data);
item->deleteObject(false);
- items_to_select = g_slist_remove(items_to_select, item);
+ items_to_select.remove(item);
}
g_slist_free(items_to_delete);
- items_to_select = g_slist_reverse(items_to_select);
+ items_to_select.reverse();
selection->addList(items_to_select);
- g_slist_free(items_to_select);
if (apply_clip_path) {
DocumentUndo::done(doc, SP_VERB_OBJECT_SET_CLIPPATH, _("Set clipping path"));
@@ -4131,20 +4086,20 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) {
gchar const *attributeName = apply_clip_path ? "clip-path" : "mask";
std::map<SPObject*,SPItem*> referenced_objects;
- GSList *items = g_slist_copy(const_cast<GSList *>(selection->itemList()));
+ SelContainer items(selection->itemList());
selection->clear();
GSList *items_to_ungroup = NULL;
- GSList *items_to_select = g_slist_copy(items);
- items_to_select = g_slist_reverse(items_to_select);
+ SelContainer items_to_select(items);
+ items_to_select.reverse();
// SPObject* refers to a group containing the clipped path or mask itself,
// whereas SPItem* refers to the item being clipped or masked
- for (GSList const *i = items; NULL != i; i = i->next) {
+ for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){
if (remove_original) {
// remember referenced mask/clippath, so orphaned masks can be moved back to document
- SPItem *item = reinterpret_cast<SPItem *>(i->data);
+ SPItem *item = reinterpret_cast<SPItem *>(*i);
Inkscape::URIReference *uri_ref = NULL;
if (apply_clip_path) {
@@ -4159,9 +4114,9 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) {
}
}
- SP_OBJECT(i->data)->getRepr()->setAttribute(attributeName, "none");
+ SP_OBJECT(*i)->getRepr()->setAttribute(attributeName, "none");
- SPGroup *group = dynamic_cast<SPGroup *>(static_cast<SPObject *>(i->data));
+ SPGroup *group = dynamic_cast<SPGroup *>(static_cast<SPObject *>(*i));
if (ungroup_masked && group) {
// if we had previously enclosed masked object in group,
// add it to list so we can ungroup it later
@@ -4173,7 +4128,6 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) {
}
}
- g_slist_free(items);
// restore mask objects into a document
for ( std::map<SPObject*,SPItem*>::iterator it = referenced_objects.begin() ; it != referenced_objects.end() ; ++it) {
@@ -4207,7 +4161,7 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) {
repr->setPosition((pos + 1) > 0 ? (pos + 1) : 0);
SPItem *mask_item = static_cast<SPItem *>(desktop->getDocument()->getObjectByRepr(repr));
- items_to_select = g_slist_prepend(items_to_select, mask_item);
+ items_to_select.push_front(mask_item);
// transform mask, so it is moved the same spot where mask was applied
Geom::Affine transform(mask_item->transform);
@@ -4222,10 +4176,10 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) {
for (GSList *i = items_to_ungroup ; NULL != i ; i = i->next) {
SPGroup *group = dynamic_cast<SPGroup *>(static_cast<SPObject *>(i->data));
if (group) {
- items_to_select = g_slist_remove(items_to_select, group);
- GSList *children = NULL;
- sp_item_group_ungroup(group, &children, false);
- items_to_select = g_slist_concat(children, items_to_select);
+ items_to_select.remove(group);
+ SelContainer children;
+ sp_item_group_ungroup(group, children, false);
+ items_to_select.splice(items_to_select.begin(),children);
} else {
g_assert_not_reached();
}
@@ -4234,9 +4188,8 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) {
g_slist_free(items_to_ungroup);
// rebuild selection
- items_to_select = g_slist_reverse(items_to_select);
+ items_to_select.reverse();
selection->addList(items_to_select);
- g_slist_free(items_to_select);
if (apply_clip_path) {
DocumentUndo::done(doc, SP_VERB_OBJECT_UNSET_CLIPPATH, _("Release clipping path"));
diff --git a/src/selection-chemistry.h b/src/selection-chemistry.h
index d86906548..bc317d556 100644
--- a/src/selection-chemistry.h
+++ b/src/selection-chemistry.h
@@ -19,6 +19,7 @@
#include <2geom/forward.h>
#include "sp-item.h"
+#include "selection.h"
class SPCSSAttr;
class SPDesktop;
@@ -142,9 +143,9 @@ enum SPSelectStrokeStyleType {
void sp_select_same_fill_stroke_style(SPDesktop *desktop, gboolean fill, gboolean strok, gboolean style);
void sp_select_same_stroke_style(SPDesktop *desktop);
void sp_select_same_object_type(SPDesktop *desktop);
-GSList *sp_get_same_fill_or_stroke_color(SPItem *sel, GSList *src, SPSelectStrokeStyleType type);
-GSList *sp_get_same_stroke_style(SPItem *sel, GSList *src, SPSelectStrokeStyleType type);
-GSList *sp_get_same_object_type(SPItem *sel, GSList *src);
+SelContainer sp_get_same_fill_or_stroke_color(SPItem *sel, SelContainer &src, SPSelectStrokeStyleType type);
+SelContainer sp_get_same_stroke_style(SPItem *sel, SelContainer &src, SPSelectStrokeStyleType type);
+SelContainer sp_get_same_object_type(SPItem *sel, SelContainer &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);
+SelContainer &get_all_items(SelContainer &list, SPObject *from, SPDesktop *desktop, bool onlyvisible, bool onlysensitive, bool ingroups, SelContainer const &exclude);
-GSList *sp_degroup_list (GSList *items);
+SelContainer sp_degroup_list (SelContainer &items);
/* selection cycling */
typedef enum
diff --git a/src/selection-describer.cpp b/src/selection-describer.cpp
index f7814fd57..0625c4002 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 SelContainer &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 ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) {
+ SPItem *item = dynamic_cast<SPItem *>(reinterpret_cast<SPObject *>(*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 SelContainer &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 ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) {
+ SPItem *item = dynamic_cast<SPItem *>(reinterpret_cast<SPObject *>(*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 SelContainer &items)
{
int count=0;
- for (GSList *i = items; i != NULL; i = i->next) {
- SPItem *item = dynamic_cast<SPItem *>(reinterpret_cast<SPObject *>((i->data)));
+ for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) {
+ SPItem *item = dynamic_cast<SPItem *>(reinterpret_cast<SPObject *>((*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();
+ SelContainer 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 = dynamic_cast<SPItem *>(reinterpret_cast<SPObject *>(items.front()));
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>%i</b> objects selected of type %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..b509f4272 100644
--- a/src/selection.cpp
+++ b/src/selection.cpp
@@ -42,9 +42,9 @@
namespace Inkscape {
Selection::Selection(LayerModel *layers, SPDesktop *desktop) :
- _objs(NULL),
- _reprs(NULL),
- _items(NULL),
+ _objs(SelContainer()),
+ _reprs(SelContainer()),
+ _items(SelContainer()),
_layers(layers),
_desktop(desktop),
_selection_context(NULL),
@@ -121,17 +121,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=reinterpret_cast<SPObject *>(_objs.front());
_remove(obj);
}
}
@@ -148,7 +145,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 ( find(_objs.begin(),_objs.end(),obj)!=_objs.end() );
}
void Selection::add(SPObject *obj, bool persist_selection_context/* = false */) {
@@ -180,7 +177,7 @@ void Selection::_add(SPObject *obj) {
_removeObjectDescendants(obj);
_removeObjectAncestors(obj);
- _objs = g_slist_prepend(_objs, obj);
+ _objs.push_front(obj);
add_3D_boxes_recursively(obj);
@@ -234,26 +231,26 @@ void Selection::_remove(SPObject *obj) {
remove_3D_boxes_recursively(obj);
- _objs = g_slist_remove(_objs, obj);
+ _objs.remove(obj);
}
-void Selection::setList(GSList const *list) {
+void Selection::setList(SelContainer 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(SelContainer 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 ( SelContainer::const_iterator iter=list.begin();iter!=list.end();iter++ ) {
+ SPObject *obj = reinterpret_cast<SPObject *>(*iter);
if (includes(obj)) continue;
_add (obj);
}
@@ -261,11 +258,11 @@ void Selection::addList(GSList const *list) {
_emitChanged();
}
-void Selection::setReprList(GSList const *list) {
+void Selection::setReprList(SelContainer const &list) {
_clear();
- for ( GSList const *iter = list ; iter != NULL ; iter = iter->next ) {
- SPObject *obj=_objectForXMLNode(reinterpret_cast<Inkscape::XML::Node *>(iter->data));
+ for ( SelContainer::const_iterator iter=list.begin();iter!=list.end();iter++ ) {
+ SPObject *obj=_objectForXMLNode(reinterpret_cast<Inkscape::XML::Node *>(*iter));
if (obj) {
_add(obj);
}
@@ -279,34 +276,34 @@ void Selection::clear() {
_emitChanged();
}
-GSList const *Selection::list() {
+SelContainer const &Selection::list() {
return _objs;
}
-GSList const *Selection::itemList() {
- if (_items) {
+SelContainer 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 ( SelContainer::const_iterator iter=_objs.begin();iter!=_objs.end();iter++ ) {
+ SPObject *obj=reinterpret_cast<SPObject *>(*iter);
if (SP_IS_ITEM(obj)) {
- _items = g_slist_prepend(_items, SP_ITEM(obj));
+ _items.push_front(SP_ITEM(obj));
}
}
- _items = g_slist_reverse(_items);
+ _items.reverse();
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());
+SelContainer const &Selection::reprList() {
+ if (!_reprs.empty()) { return _reprs; }
+ SelContainer list = itemList();
+ for ( SelContainer::const_iterator iter=list.begin();iter!=list.end();iter++ ) {
+ SPObject *obj=reinterpret_cast<SPObject *>(*iter);
+ _reprs.push_front(dynamic_cast<SPObject*>(obj->getRepr()));
}
- _reprs = g_slist_reverse(_reprs);
+ _reprs.reverse();
return _reprs;
}
@@ -337,17 +334,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 reinterpret_cast<SPObject *>(_objs.front());
} else {
return NULL;
}
}
SPItem *Selection::singleItem() {
- GSList const *items=itemList();
- if ( items != NULL && items->next == NULL ) {
- return reinterpret_cast<SPItem *>(items->data);
+ SelContainer const items=itemList();
+ if ( !items.size()==1) {
+ return reinterpret_cast<SPItem *>(items.front());
} else {
return NULL;
}
@@ -362,12 +359,12 @@ SPItem *Selection::largestItem(Selection::CompareSize compare) {
}
SPItem *Selection::_sizeistItem(bool sml, Selection::CompareSize compare) {
- GSList const *items = const_cast<Selection *>(this)->itemList();
+ SelContainer 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 ( SelContainer::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 +373,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 +392,22 @@ Geom::OptRect Selection::bounds(SPItem::BBoxType type) const
Geom::OptRect Selection::geometricBounds() const
{
- GSList const *items = const_cast<Selection *>(this)->itemList();
+ SelContainer 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 ( SelContainer::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();
+ SelContainer 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 ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) {
+ bbox.unionWith(SP_ITEM(*iter)->desktopVisualBounds());
}
return bbox;
}
@@ -427,11 +424,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;
+ SelContainer 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 ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) {
+ SPItem *item = SP_ITEM(*iter);
bbox |= item->documentBounds(type);
}
@@ -441,9 +438,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
+ SelContainer const items = const_cast<Selection *>(this)->itemList();
+ if (!items.empty()) {
+ SPItem *first = reinterpret_cast<SPItem*>(items.back()); // from the first item in selection
if (first->isCenterSet()) { // only if set explicitly
return first->getCenter();
}
@@ -457,13 +454,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();
+ SelContainer 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 ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) {
+ SPItem *this_item = SP_ITEM(*iter);
this_item->getSnappoints(p, &snapprefs_dummy);
//Include the transformation origin for snapping
@@ -477,10 +474,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 ( SelContainer::const_iterator iter=_objs.begin();iter!=_objs.end();iter++ ) {
+ SPObject *sel_obj=reinterpret_cast<SPObject *>(*iter);
SPObject *parent = sel_obj->parent;
while (parent) {
if ( parent == obj ) {
@@ -511,32 +506,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() {
+ SelContainer const items = const_cast<Selection *>(this)->itemList();
+ std::set<SPObject*> layers;
+ for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) {
+ SPObject *layer = _layers->layerForObject(SP_OBJECT(*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);
- }
+ SelContainer const items = const_cast<Selection *>(this)->itemList();
+ std::set<SPObject*> parents;
+ for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) {
+ SPObject *parent = SP_OBJECT(*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 5964b20e8..7171b8742 100644
--- a/src/selection.h
+++ b/src/selection.h
@@ -19,6 +19,11 @@
#include <stddef.h>
#include <sigc++/sigc++.h>
+#include <boost/multi_index_container.hpp>
+#include <boost/multi_index/ordered_index.hpp>
+#include <boost/multi_index/identity.hpp>
+#include <boost/multi_index/member.hpp>
+
#include "gc-managed.h"
#include "gc-finalized.h"
#include "gc-anchored.h"
@@ -26,11 +31,13 @@
#include "sp-item.h"
+
class SPDesktop;
class SPItem;
class SPBox3D;
class Persp3D;
-typedef struct _GSList GSList;
+
+typedef std::list<SPObject*> SelContainer;
namespace Inkscape {
class LayerModel;
@@ -39,6 +46,15 @@ class Node;
}
}
+/*template<typename T>
+const GSList* std_list_to_GS_list(const std::list<T *> list) const
+{
+ gpointer l=NULL;
+ for(auto x:list){
+
+ }
+}*/
+
namespace Inkscape {
/**
@@ -154,21 +170,21 @@ public:
*
* @param objs the objects to select
*/
- void setList(GSList const *objs);
+ void setList(SelContainer const &objs);
/**
* Adds the specified objects to selection, without deselecting first.
*
* @param objs the objects to select
*/
- void addList(GSList const *objs);
+ void addList(SelContainer 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::list<SPObject*> const &reprs);
/** Add items from an STL iterator range to the selection.
* \param from the begin iterator
@@ -192,7 +208,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 +254,13 @@ public:
XML::Node *singleRepr();
/** Returns the list of selected objects. */
- GSList const *list();
+ std::list<SPObject*> const &list();
/** Returns the list of selected SPItems. */
- GSList const *itemList();
+ std::list<SPObject*> 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::list<SPObject*> 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 +376,9 @@ 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;
+ mutable std::list<SPObject*> _reprs;
+ mutable std::list<SPObject*> _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..8c06356db 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(SelContainer()),
_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);
+ SelContainer items=_desktop->selection->itemList();
+ for ( SelContainer::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));
+ SelContainer items=_desktop->selection->itemList();
+ for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) {
+ SPItem *it = reinterpret_cast<SPItem*>(sp_object_ref(SP_ITEM(*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)
@@ -433,9 +435,8 @@ void Inkscape::SelTrans::ungrab()
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 +492,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);
+ SelContainer items=_desktop->selection->itemList();
+ for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) {
+ SPItem *it = SP_ITEM(*iter);
it->updateRepr();
}
DocumentUndo::done(_desktop->getDocument(), SP_VERB_CONTEXT_SELECT,
@@ -515,26 +517,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) {
+ SelContainer 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();
+ l.sort(sp_object_compare_position);
_stamp_cache = l;
}
- while (l) {
- SPItem *original_item = SP_ITEM(l->data);
+ for(SelContainer::const_iterator x=l.begin();x!=l.end();x++) {
+ SPItem *original_item = SP_ITEM(*x);
Inkscape::XML::Node *original_repr = original_item->getRepr();
// remember the position of the item
@@ -568,16 +569,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 +711,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);
+ SelContainer items=_desktop->selection->itemList();
+ for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) {
+ SPItem *it = SP_ITEM(*iter);
it->unsetCenter();
it->updateRepr();
_center_is_set = false; // center has changed
@@ -1283,7 +1283,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();
+ SelContainer 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..8f9c329ed 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;
+ SelContainer _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 8138e4546..a7145b834 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(SelContainer()),
_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));
+ SelContainer const items = sel->itemList();
+ for (SelContainer::const_iterator i=items.begin();i!=items.end();i++) {
+ _items_to_ignore.push_back(static_cast<SPItem const *>(*i));
}
}
diff --git a/src/snap.h b/src/snap.h
index 20b2b246f..012eb072b 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 SelContainer &items) {_rotation_center_source_items = items;}
+ SelContainer 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
+ SelContainer _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..bd139277d 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);
+ SelContainer g = sp_item_group_item_list(group);
+ for (SelContainer::const_iterator i = g.begin();i!=g.end();i++) {
+ SPItem* child_item = SP_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 334570076..d52fa038a 100644
--- a/src/sp-defs.cpp
+++ b/src/sp-defs.cpp
@@ -46,11 +46,10 @@ 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);
+ SelContainer l(this->childList(true));
+ l.reverse();
+ for(SelContainer::const_iterator i=l.begin();i!=l.end();i++){
+ SPObject *child = SP_OBJECT(*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 9cb33a6f3..bf8f7a5a4 100644
--- a/src/sp-filter.cpp
+++ b/src/sp-filter.cpp
@@ -244,11 +244,10 @@ 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);
+ SelContainer l(this->childList(true, SPObject::ActionUpdate));
+ l.reverse();
+ for(SelContainer::const_iterator i=l.begin();i!=l.end();i++){
+ SPObject *child = SP_OBJECT (*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 b1ba37de2..e6531c6be 100644
--- a/src/sp-item-group.cpp
+++ b/src/sp-item-group.cpp
@@ -171,11 +171,10 @@ 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);
+ SelContainer l=this->childList(true, SPObject::ActionUpdate);
+ l.reverse();
+ for(SelContainer::const_iterator i=l.begin();i!=l.end();i++){
+ SPObject *child = SP_OBJECT (*i);
if (childflags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
SPItem *item = dynamic_cast<SPItem *>(child);
@@ -211,20 +210,16 @@ 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);
+ SelContainer l=this->childList(true);
+ l.reverse();
+ for(SelContainer::const_iterator i=l.begin();i!=l.end();i++){
+ SPObject *child = SP_OBJECT (*i);
if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
child->emitModified(flags);
@@ -296,35 +291,28 @@ 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);
-
+ SelContainer l=const_cast<SPGroup*>(this)->childList(false, SPObject::ActionBBox);
+ for(SelContainer::const_iterator i=l.begin();i!=l.end();i++){
+ SPObject *o = SP_OBJECT (*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);
-
+ SelContainer l=this->childList(false);
+ l.reverse();
+ for(SelContainer::const_iterator i=l.begin();i!=l.end();i++){
+ SPObject *o = SP_OBJECT (*i);
SPItem *item = dynamic_cast<SPItem *>(o);
if (item) {
item->invoke_print(ctx);
}
-
- l = g_slist_remove (l, o);
}
}
@@ -372,17 +360,15 @@ 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);
+ SelContainer l=this->childList(false, SPObject::ActionShow);
+ l.reverse();
+ for(SelContainer::const_iterator i=l.begin();i!=l.end();i++){
+ SPObject *o = SP_OBJECT (*i);
SPItem *item = dynamic_cast<SPItem *>(o);
if (item) {
item->invoke_hide(key);
}
-
- l = g_slist_remove (l, o);
}
// SPLPEItem::onHide(key);
@@ -401,7 +387,7 @@ void SPGroup::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape:
void
-sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done)
+sp_item_group_ungroup (SPGroup *group, SelContainer &children, bool do_done)
{
g_return_if_fail (group != NULL);
@@ -560,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.push_front(dynamic_cast<SPObject*>(item));
}
items = g_slist_remove (items, items->data);
@@ -576,19 +562,18 @@ 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)
+SelContainer sp_item_group_item_list(SPGroup * group)
{
- g_return_val_if_fail(group != NULL, NULL);
-
- GSList *s = NULL;
+ SelContainer 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_front(o);
}
}
-
- return g_slist_reverse (s);
+ s.reverse();
+ return s;
}
SPObject *sp_item_group_get_child_by_name(SPGroup *group, SPObject *ref, const gchar *name)
@@ -809,9 +794,10 @@ 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);
+ SelContainer l=this->childList(false, SPObject::ActionShow);
+ l.reverse();
+ for(SelContainer::const_iterator i=l.begin();i!=l.end();i++){
+ SPObject *o = SP_OBJECT (*i);
SPItem * child = dynamic_cast<SPItem *>(o);
if (child) {
ac = child->invoke_show (drawing, key, flags);
@@ -819,7 +805,6 @@ void SPGroup::_showChildren (Inkscape::Drawing &drawing, Inkscape::DrawingItem *
ai->appendChild(ac);
}
}
- l = g_slist_remove (l, o);
}
}
@@ -828,10 +813,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);
+ SelContainer 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 ( SelContainer::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) {
+ SPObject *subitem = static_cast<SPObject *>(*iter);
SPLPEItem *lpeItem = dynamic_cast<SPLPEItem *>(subitem);
if (lpeItem) {
@@ -856,10 +841,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);
+ SelContainer 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 ( SelContainer::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) {
+ SPObject *subitem = static_cast<SPObject *>(*iter);
SPGroup *subGroup = dynamic_cast<SPGroup *>(subitem);
if (subGroup) {
diff --git a/src/sp-item-group.h b/src/sp-item-group.h
index 15bb58f22..9a5ee0161 100644
--- a/src/sp-item-group.h
+++ b/src/sp-item-group.h
@@ -15,6 +15,7 @@
#include <map>
#include "sp-lpe-item.h"
+#include "selection.h"//SelContainer
#define SP_GROUP(obj) (dynamic_cast<SPGroup*>((SPObject*)obj))
#define SP_IS_GROUP(obj) (dynamic_cast<const SPGroup*>((SPObject*)obj) != NULL)
@@ -95,10 +96,10 @@ public:
virtual void update_patheffect(bool write);
};
-void sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done = true);
+void sp_item_group_ungroup (SPGroup *group, SelContainer &children, bool do_done = true);
-GSList *sp_item_group_item_list (SPGroup *group);
+SelContainer 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 f059ab531..1305efd83 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);
+ SelContainer item_list = sp_item_group_item_list(SP_GROUP(lpeitem));
+ for ( SelContainer::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) {
+ SPObject *subitem = static_cast<SPObject *>(*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);
+ SelContainer item_list = sp_item_group_item_list(SP_GROUP(lpeitem));
+ for ( SelContainer::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) {
+ SPObject *subitem = static_cast<SPObject *>(*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);
+ SelContainer item_list = sp_item_group_item_list(SP_GROUP(item));
+ for ( SelContainer::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) {
+ SPObject *subitem = static_cast<SPObject *>(*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);
+ SelContainer item_list = sp_item_group_item_list(SP_GROUP(item));
+ for ( SelContainer::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) {
+ SPObject *subitem = static_cast<SPObject *>(*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);
+ SelContainer item_list = sp_item_group_item_list(SP_GROUP(group));
+ for ( SelContainer::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) {
+ SPObject *subitem = static_cast<SPObject *>(*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 371a6c35c..66b445265 100644
--- a/src/sp-marker.cpp
+++ b/src/sp-marker.cpp
@@ -429,7 +429,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(SelContainer &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();
@@ -452,8 +452,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 (SelContainer::const_iterator i=reprs.begin();i!=reprs.end();i++){
+ Inkscape::XML::Node *node = (Inkscape::XML::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..594c164c5 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 (SelContainer &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 7d24a978e..3ea480f66 100644
--- a/src/sp-object.cpp
+++ b/src/sp-object.cpp
@@ -382,14 +382,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;
+SelContainer SPObject::childList(bool add_ref, Action) {
+ SelContainer l;
for ( SPObject *child = firstChild() ; child; child = child->getNext() ) {
if (add_ref) {
sp_object_ref (child);
}
- l = g_slist_prepend (l, child);
+ l.push_front(child);
}
return l;
diff --git a/src/sp-object.h b/src/sp-object.h
index ff80eaefc..858587611 100644
--- a/src/sp-object.h
+++ b/src/sp-object.h
@@ -47,11 +47,14 @@ class SPObject;
#define SP_OBJECT_WRITE_ALL (1 << 2)
#define SP_OBJECT_WRITE_NO_CHILDREN (1 << 3)
+
+
#include <cassert>
#include <stddef.h>
#include <sigc++/connection.h>
#include <sigc++/functors/slot.h>
#include <sigc++/signal.h>
+#include <list>
#include "version.h"
#include "util/forward-pointer-iterator.h"
@@ -60,6 +63,11 @@ class SPCSSAttr;
class SPStyle;
typedef struct _GSList GSList;
+//should be in selection.h
+typedef std::list<SPObject*> SelContainer;
+
+
+
namespace Inkscape {
namespace XML {
class Node;
@@ -330,7 +338,7 @@ public:
* Retrieves the children as a GSList object, optionally ref'ing the children
* in the process, if add_ref is specified.
*/
- GSList *childList(bool add_ref, Action action = ActionGeneral);
+ SelContainer 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 961ab0f84..d5eff9796 100644
--- a/src/sp-pattern.cpp
+++ b/src/sp-pattern.cpp
@@ -408,7 +408,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 SelContainer &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();
@@ -426,8 +426,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 (SelContainer::const_iterator i=reprs.begin();i!=reprs.end();i++){
+ Inkscape::XML::Node *node = (Inkscape::XML::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..0e2b058b5 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 SelContainer &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 db6db9909..0090f1855 100644
--- a/src/sp-switch.cpp
+++ b/src/sp-switch.cpp
@@ -55,21 +55,22 @@ SPObject *SPSwitch::_evaluateFirst() {
return first;
}
-GSList *SPSwitch::_childList(bool add_ref, SPObject::Action action) {
+SelContainer SPSwitch::_childList(bool add_ref, SPObject::Action action) {
if ( action != SPObject::ActionGeneral ) {
return this->childList(add_ref, action);
}
SPObject *child = _evaluateFirst();
+ SelContainer 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_front(child);
+ return x;
}
const char *SPSwitch::displayName() const {
@@ -109,10 +110,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);
+ SelContainer item_list = _childList(false, SPObject::ActionShow);
+ for ( SelContainer::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) {
+ SPObject *o = SP_OBJECT (*iter);
if ( !SP_IS_ITEM (o) ) {
continue;
}
@@ -144,10 +144,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);
+ SelContainer l = this->_childList(false, SPObject::ActionShow);
- while (l) {
- SPObject *o = SP_OBJECT (l->data);
+ for ( SelContainer::const_iterator iter=l.begin();iter!=l.end();iter++) {
+ SPObject *o = SP_OBJECT (*iter);
if (SP_IS_ITEM (o)) {
SPItem * child = SP_ITEM(o);
@@ -158,8 +158,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..6a83072e7 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);
+ SelContainer _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 8bb3e9897..aec7051e0 100644
--- a/src/splivarot.cpp
+++ b/src/splivarot.cpp
@@ -60,6 +60,11 @@ using Inkscape::DocumentUndo;
bool Ancetre(Inkscape::XML::Node *a, Inkscape::XML::Node *who);
+//SHOULD DISAPPEAR
+bool sp_repr_compare_position_obj(SPObject* &a,SPObject* &b){
+ return sp_repr_compare_position(dynamic_cast<Inkscape::XML::Node*>(a),dynamic_cast<Inkscape::XML::Node*>(b));
+}
+
void sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool_op bop, const unsigned int verb=SP_VERB_NONE, const Glib::ustring description="");
void sp_selected_path_do_offset(SPDesktop *desktop, bool expand, double prefOffset);
void sp_selected_path_create_offset_object(SPDesktop *desktop, int expand, bool updating);
@@ -326,21 +331,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();
+ SelContainer 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 +359,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 = SP_OBJECT(il.front())->getRepr();
+ Inkscape::XML::Node *b = SP_OBJECT(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 +399,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 (SelContainer::const_iterator l = il.begin(); l != il.end(); l++)
{
- SPItem *item = SP_ITEM(l->data);
+ SPItem *item = SP_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 (SelContainer::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.front())->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 +438,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((SPItem *) (*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 +474,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 (SelContainer::const_iterator l = il.begin(); l != il.end(); l++){
+ if(*l==il.front())continue;
originaux[curOrig]->ConvertWithBackData(0.1);
originaux[curOrig]->Fill(theShape, curOrig);
@@ -668,15 +671,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 (SelContainer::const_iterator l = il.begin(); l != il.end(); l++){
+ SP_OBJECT(*l)->deleteObject();
}
DocumentUndo::done(doc, SP_VERB_NONE, description);
selection->clear();
delete res;
- g_slist_free(il);
return;
}
@@ -684,19 +685,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 = SP_OBJECT(il.front());
} else {
- source = SP_OBJECT(il->next->data);
+ source = SP_OBJECT(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);
+ SelContainer sorted(selection->reprList());
- source = doc->getObjectByRepr((Inkscape::XML::Node *)sorted->data);
+ sorted.sort(sp_repr_compare_position_obj);
- g_slist_free(sorted);
+ source = doc->getObjectByRepr((Inkscape::XML::Node *)sorted.front());
}
// adjust style properties that depend on a possible transform in the source object in order
@@ -721,17 +720,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 (SelContainer::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);
+ SP_OBJECT(*l)->deleteObject(false);
} else {
// delete the object for real, so that its clones can take appropriate action
- SP_OBJECT(l->data)->deleteObject();
+ SP_OBJECT(*l)->deleteObject();
}
}
- g_slist_free(il);
// premultiply by the inverse of parent's repr
SPItem *parent_item = SP_ITEM(doc->getObjectByRepr(parent));
@@ -1159,12 +1157,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);
+ SelContainer il(selection->itemList());
+ for (SelContainer::const_iterator l = il.begin(); l != il.end(); l++){
+ SPItem *item = SP_ITEM(*l);
if (!SP_IS_SHAPE(item) && !SP_IS_TEXT(item))
continue;
@@ -1774,12 +1769,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);
+ SelContainer il(selection->itemList());
+ for (SelContainer::const_iterator l = il.begin(); l != il.end(); l++){
+ SPItem *item = SP_ITEM(*l);
SPCurve *curve = NULL;
if (!SP_IS_SHAPE(item) && !SP_IS_TEXT(item))
@@ -1975,7 +1967,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, SelContainer &items,
float threshold, bool justCoalesce,
float angleLimit, bool breakableAngles,
bool modifySelection);
@@ -1994,7 +1986,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));
+ SelContainer items = sp_item_group_item_list(SP_GROUP(item));
return sp_selected_path_simplify_items(desktop, selection, items,
threshold, justCoalesce,
@@ -2119,7 +2111,7 @@ sp_selected_path_simplify_item(SPDesktop *desktop,
bool
sp_selected_path_simplify_items(SPDesktop *desktop,
- Inkscape::Selection *selection, GSList *items,
+ Inkscape::Selection *selection, SelContainer &items,
float threshold, bool justCoalesce,
float angleLimit, bool breakableAngles,
bool modifySelection)
@@ -2145,13 +2137,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 (SelContainer::const_iterator l = items.begin(); l != items.end(); l++){
+ SPItem *item = SP_ITEM(*l);
if (!(SP_IS_GROUP(item) || SP_IS_SHAPE(item) || SP_IS_TEXT(item)))
continue;
@@ -2199,7 +2191,7 @@ sp_selected_path_simplify_selection(SPDesktop *desktop, float threshold, bool ju
return;
}
- GSList *items = g_slist_copy((GSList *) selection->itemList());
+ SelContainer 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..391e255a5 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);
+ SelContainer items = selection->itemList();
+ for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){
+ if (SP_IS_FLOWTEXT(*i))
+ return ((SPItem *) *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);
+ SelContainer items = selection->itemList();
+ for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){
+ if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i))
+ return ((SPItem *) *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);
+ SelContainer items = selection->itemList();
+ for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){
+ if (SP_IS_SHAPE(*i))
+ return ((SPItem *) *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);
+ SelContainer items(selection->itemList());
+ for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){
+ SPObject *obj = SP_OBJECT(*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);
+ SelContainer items = selection->itemList();
+ for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){
+ SPObject *obj = SP_OBJECT(*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);
+ SelContainer items = selection->itemList();
+ for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){
+ SPItem *item = SP_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;
+ SelContainer new_objs;
GSList *old_objs = NULL;
- for (GSList *items = g_slist_copy((GSList *) selection->itemList());
- items != NULL;
- items = items->next) {
+ SelContainer items = selection->itemList();
+ for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){
- if (!SP_IS_FLOWTEXT(SP_OBJECT(items->data))) {
+ if (!SP_IS_FLOWTEXT(SP_OBJECT(*i))) {
continue;
}
- SPItem *flowtext = SP_ITEM(items->data);
+ SPItem *flowtext = SP_ITEM(*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_front(text_object);
old_objs = g_slist_prepend (old_objs, flowtext);
Inkscape::GC::release(rtext);
@@ -466,7 +458,6 @@ text_unflow ()
}
g_slist_free (old_objs);
- g_slist_free (new_objs);
DocumentUndo::done(doc, SP_VERB_CONTEXT_TEXT,
_("Unflow flowed text"));
@@ -487,11 +478,11 @@ flowtext_to_text()
bool did = false;
- GSList *reprs = NULL;
- GSList *items = g_slist_copy((GSList *) selection->itemList());
- for (; items != NULL; items = items->next) {
+ SelContainer reprs;
+ SelContainer items(selection->itemList());
+ for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){
- SPItem *item = (SPItem *) items->data;
+ SPItem *item = (SPItem *) *i;
if (!SP_IS_FLOWTEXT(item))
continue;
@@ -519,10 +510,9 @@ flowtext_to_text()
Inkscape::GC::release(repr);
item->deleteObject();
- reprs = g_slist_prepend(reprs, repr);
+ reprs.push_front(dynamic_cast<SPObject*>(repr));
}
- g_slist_free(items);
if (did) {
DocumentUndo::done(desktop->getDocument(),
@@ -535,7 +525,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..44d90b4ae 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);
+ SelContainer item_list = sp_item_group_item_list(SP_GROUP(item));
+ for(SelContainer::const_iterator i=item_list.begin();i!=item_list.end();i++){
+ SPItem* list_item = static_cast<SPItem*>(*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..892ecdb87 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();
+ SelContainer 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(SelContainer::const_iterator x=list.begin();x!=list.end();x++){
{
- if (!SP_IS_ITEM(list->data))
+ if (!SP_IS_ITEM(*x))
{
continue;
}
- SPItem *item = SP_ITEM(list->data);
+ SPItem *item = SP_ITEM(*x);
items.insert(items.begin(), item);
}
std::vector<SPItem *>::iterator iter;
diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp
index 94a1eb2dc..20b43af3b 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));
+ SelContainer itemlist=selection->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *item = SP_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);
+ SelContainer itemlist=selection->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *item = SP_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));
+ SelContainer itemlist=selection->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *item = SP_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);
+ SelContainer sorted_items(itemlist);
+ sorted_items.sort(sp_object_compare_position);
- for (GSList *i = sorted_items ; i ; i = i->next) {
- SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(i->data));
+ for(SelContainer::const_iterator i=sorted_items.begin();i!=sorted_items.end();i++){
+ SPItem *item = SP_ITEM(*i);
if (item) {
Inkscape::XML::Node *obj = item->getRepr();
Inkscape::XML::Node *obj_copy = _copyNode(obj, _doc, _root);
@@ -695,8 +697,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 = static_cast<SPObject *>(sorted_items.front());
SPItem *item = dynamic_cast<SPItem *>(object);
if (item) {
SPCSSAttr *style = take_style_from_item(item);
@@ -719,7 +721,6 @@ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection)
sp_repr_set_point(_clipnode, "max", size->max());
}
- g_slist_free(sorted_items);
}
@@ -1156,8 +1157,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);
+ SelContainer 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..562bc28b7 100644
--- a/src/ui/dialog/align-and-distribute.cpp
+++ b/src/ui/dialog/align-and-distribute.cpp
@@ -98,8 +98,7 @@ void ActionAlign::do_action(SPDesktop *desktop, int index)
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);
+ SelContainer selected(selection->itemList());
if (selected.empty()) return;
const Coeffs &a = _allCoeffs[index];
@@ -149,18 +148,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 (SelContainer::iterator it(selected.begin());
it != selected.end(); ++it)
{
+ SPItem* item=static_cast<SPItem*> (*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;
}
}
@@ -251,25 +251,24 @@ private :
if (!selection) return;
using Inkscape::Util::GSListConstIterator;
- std::list<SPItem *> selected;
- selected.insert<GSListConstIterator<SPItem *> >(selected.end(), selection->itemList(), NULL);
+ SelContainer selected(selection->itemList());
if (selected.empty()) return;
//Check 2 or more selected objects
- std::list<SPItem *>::iterator second(selected.begin());
+ SelContainer::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 (SelContainer::iterator it(selected.begin());
it != selected.end();
++it)
- {
- Geom::OptRect bbox = !prefs_bbox ? (*it)->desktopVisualBounds() : (*it)->desktopGeometricBounds();
+ {SPItem *item=static_cast<SPItem*>(*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
@@ -541,6 +540,10 @@ private :
return (a->isSiblingOf(b));
}
+ static bool local_obj_compare(SPObject* a,SPObject* b){
+ return ActionExchangePositions::sort_compare(static_cast<SPItem*>(a),static_cast<SPItem*>(b));
+ }
+
virtual void on_button_click()
{
SPDesktop *desktop = _dialog.getDesktop();
@@ -550,8 +553,7 @@ private :
if (!selection) return;
using Inkscape::Util::GSListConstIterator;
- std::list<SPItem *> selected;
- selected.insert<GSListConstIterator<SPItem *> >(selected.end(), selection->itemList(), NULL);
+ SelContainer selected(selection->itemList());
if (selected.empty()) return;
//Check 2 or more selected objects
@@ -569,20 +571,22 @@ private :
} else { // sorting by ZOrder is outomatically done by not setting the center
center.reset();
}
- selected.sort(ActionExchangePositions::sort_compare);
+ selected.sort(local_obj_compare);
}
- std::list<SPItem *>::iterator it(selected.begin());
- Geom::Point p1 = (*it)->getCenter();
+ SelContainer::iterator it(selected.begin());
+ SPItem* item=static_cast<SPItem*>(*it);
+ Geom::Point p1 = (item)->getCenter();
for (++it ;it != selected.end(); ++it)
{
- Geom::Point p2 = (*it)->getCenter();
+ item=static_cast<SPItem*>(*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();
+ Geom::Point p2 = static_cast<SPItem*>(selected.front())->getCenter();
Geom::Point delta = p1 - p2;
- sp_item_move_rel(selected.front(),Geom::Translate(delta[Geom::X],delta[Geom::Y] ));
+ sp_item_move_rel(static_cast<SPItem*>(selected.front()),Geom::Translate(delta[Geom::X],delta[Geom::Y] ));
// restore compensation setting
prefs->setInt("/options/clonecompensation/value", saved_compensation);
@@ -615,8 +619,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());
+ SelContainer x(_dialog.getDesktop()->getSelection()->itemList());
+ unclump (x);
// restore compensation setting
prefs->setInt("/options/clonecompensation/value", saved_compensation);
@@ -647,8 +651,7 @@ private :
if (!selection) return;
using Inkscape::Util::GSListConstIterator;
- std::list<SPItem *> selected;
- selected.insert<GSListConstIterator<SPItem *> >(selected.end(), selection->itemList(), NULL);
+ SelContainer selected(selection->itemList());
if (selected.empty()) return;
//Check 2 or more selected objects
@@ -672,12 +675,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 (SelContainer::iterator it(selected.begin());
it != selected.end();
++it)
{
+ SPItem* item=static_cast<SPItem*>(*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 +690,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));
}
}
@@ -746,8 +750,7 @@ private :
if (!selection) return;
using Inkscape::Util::GSListConstIterator;
- std::list<SPItem *> selected;
- selected.insert<GSListConstIterator<SPItem *> >(selected.end(), selection->itemList(), NULL);
+ SelContainer selected(selection->itemList());
if (selected.empty()) return;
//Check 2 or more selected objects
@@ -758,20 +761,21 @@ private :
std::vector<Baselines> sorted;
- for (std::list<SPItem *>::iterator it(selected.begin());
+ for (SelContainer::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=static_cast<SPItem*>(*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 +805,19 @@ private :
}
} else {
- for (std::list<SPItem *>::iterator it(selected.begin());
+ for (SelContainer::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=static_cast<SPItem*>(*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 fede30b26..abfab8b19 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,11 +2104,11 @@ void CloneTiler::clonetiler_unclump(GtkWidget */*widget*/, void *)
SPObject *obj = selection->singleItem();
SPObject *parent = obj->parent;
- GSList *to_unclump = NULL; // not including the original
+ SelContainer 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_front(child);
}
}
@@ -2116,8 +2116,6 @@ void CloneTiler::clonetiler_unclump(GtkWidget */*widget*/, void *)
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 6d90c792e..fc6094c9f 100644
--- a/src/ui/dialog/export.cpp
+++ b/src/ui/dialog/export.cpp
@@ -605,7 +605,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));
@@ -817,9 +817,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 SelContainer reprlst = SP_ACTIVE_DESKTOP->getSelection()->reprList();
+ for(SelContainer::const_iterator i=reprlst.begin(); reprlst.end() != i; i++) {
+ Inkscape::XML::Node * repr = (Inkscape::XML::Node *)(*i);
if (repr->attribute("id")) {
id = repr->attribute("id");
break;
@@ -1010,7 +1010,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) {
@@ -1024,8 +1024,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);
+ SelContainer itemlist=desktop->getSelection()->itemList();
+ for(SelContainer::const_iterator i = itemlist.begin();i!=itemlist.end() && !interrupted ;i++){
+ SPItem *item = reinterpret_cast<SPItem *>(*i);
prog_dlg->set_data("current", GINT_TO_POINTER(n));
prog_dlg->set_data("total", GINT_TO_POINTER(num));
@@ -1063,13 +1064,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);
-
+ SelContainer 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);
@@ -1153,12 +1154,13 @@ void Export::onExport ()
prog_dlg->set_data("total", GINT_TO_POINTER(0));
/* Do export */
+ SelContainer 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());
@@ -1224,7 +1226,7 @@ void Export::onExport ()
break;
}
case SELECTION_SELECTION: {
- const GSList * reprlst;
+ SelContainer reprlst;
SPDocument * doc = SP_ACTIVE_DOCUMENT;
bool modified = false;
@@ -1232,8 +1234,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(SelContainer::const_iterator i=reprlst.begin(); reprlst.end() != i; i++) {
+ Inkscape::XML::Node * repr = dynamic_cast<Inkscape::XML::Node *>(*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 3da0e0043..657d6771b 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 = (Inkscape::XML::Node*) sel->reprList().front();
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);
+ SelContainer itemlist=sel->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) {
+ SPObject *obj = SP_OBJECT (*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);
+ SelContainer itemlist=sel->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) {
+ SPItem * item = SP_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)) {
+ SelContainer x,y;
+ SelContainer all = get_all_items(x, _desktop->currentRoot(), _desktop, false, false, true, y);
+ for(SelContainer::const_iterator i=all.begin(); all.end() != i; i++) {
+ if (!SP_IS_ITEM(*i)) {
continue;
}
- SPItem *item = SP_ITEM(i->data);
+ SPItem *item = SP_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..43ecb60ac 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)
+SelContainer Find::filter_fields (SelContainer &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;
+ SelContainer in = l;
+ SelContainer out;
if (check_searchin_text.get_active()) {
- for (GSList *i = in; i != NULL; i = i->next) {
- SPObject *obj = reinterpret_cast<SPObject *>(i->data);
+ for(SelContainer::const_iterator i=in.begin(); in.end() != i; i++) {
+ SPObject *obj = SP_OBJECT (*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_front(*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(SelContainer::const_iterator i=in.begin(); in.end() != i; i++) {
+ SPObject *obj = SP_OBJECT (*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_front(*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(SelContainer::const_iterator i=in.begin(); in.end() != i; i++) {
+ SPObject *obj = SP_OBJECT (*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_front(*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(SelContainer::const_iterator i=in.begin(); in.end() != i; i++) {
+ SPObject *obj = SP_OBJECT (*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_front(*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(SelContainer::const_iterator i=in.begin(); in.end() != i; i++) {
+ SPObject *obj = SP_OBJECT (*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_front(*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(SelContainer::const_iterator i=in.begin(); in.end() != i; i++) {
+ SPObject *obj = SP_OBJECT (*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_front(*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)
+SelContainer Find::filter_types (SelContainer &l)
{
- GSList *n = NULL;
- for (GSList *i = l; i != NULL; i = i->next) {
- SPObject *obj = reinterpret_cast<SPObject *>(i->data);
+ SelContainer n;
+ for(SelContainer::const_iterator i=l.begin(); l.end() != i; i++) {
+ SPObject *obj = SP_OBJECT (*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_front(*i);
}
}
return n;
}
-GSList *Find::filter_list (GSList *l, bool exact, bool casematch)
+SelContainer &Find::filter_list (SelContainer &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)
+SelContainer &Find::all_items (SPObject *r, SelContainer &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.push_front(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)
+SelContainer &Find::all_selection_items (Inkscape::Selection *s, SelContainer &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);
+ SelContainer itemlist=s->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) {
+ SPObject *obj = SP_OBJECT (*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;
+ SelContainer 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);
+ SelContainer 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 = reinterpret_cast<SPObject *>(n.front());
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..1aded96f2 100644
--- a/src/ui/dialog/find.h
+++ b/src/ui/dialog/find.h
@@ -16,6 +16,7 @@
# include <config.h>
#endif
+#include "selection.h"
#include "ui/widget/panel.h"
#include "ui/widget/button.h"
#include "ui/widget/entry.h"
@@ -148,10 +149,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);
+ SelContainer filter_fields (SelContainer &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);
+ SelContainer filter_types (SelContainer &l);
+ SelContainer & filter_list (SelContainer &l, bool exact, bool casematch);
/**
* Find a string within a string and returns true if found with options for exact and casematching
@@ -172,12 +173,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);
+ SelContainer & all_items (SPObject *r, SelContainer &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);
+ SelContainer & all_selection_items (Inkscape::Selection *s, SelContainer &l, SPObject *ancestor, bool hidden, bool locked);
/**
* Shrink the dialog size when the expander widget is closed
diff --git a/src/ui/dialog/glyphs.cpp b/src/ui/dialog/glyphs.cpp
index 2b9053da9..1ef97b996 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);
+ SelContainer itemlist=targetDesktop->selection->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) {
+ if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) {
+ textItem = SP_ITEM(*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)) {
+ SelContainer itemlist=targetDesktop->selection->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) {
+ if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) {
++items;
}
}
diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp
index 28a65e0b4..86cf629c1 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;
+ SelContainer 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);
+ SelContainer 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();
+ SelContainer itemlist=_desktop->selection->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ Inkscape::XML::Node *ir = SP_ITEM(*i)->getRepr();
const gchar *href = ir->attribute("xlink:href");
if (strncmp (href,"file:",5) == 0) {
diff --git a/src/unclump.cpp b/src/unclump.cpp
index 940369d7a..d1cfc6628 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, SelContainer &others)
{
int n = 0;
double sum = 0;
-
- for (GSList *i = others; i != NULL; i = i->next) {
- SPItem *other = SP_ITEM (i->data);
+ for (SelContainer::const_iterator i = others.begin(); i != others.end();i++) {
+ SPItem *other = SP_ITEM (*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, SelContainer &others)
{
double min = HUGE_VAL;
SPItem *closest = NULL;
- for (GSList *i = others; i != NULL; i = i->next) {
- SPItem *other = SP_ITEM (i->data);
+ for (SelContainer::const_iterator i = others.begin(); i != others.end();i++) {
+ SPItem *other = SP_ITEM (*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, SelContainer &others)
{
double max = -HUGE_VAL;
SPItem *farest = NULL;
-
- for (GSList *i = others; i != NULL; i = i->next) {
- SPItem *other = SP_ITEM (i->data);
+ for (SelContainer::const_iterator i = others.begin(); i != others.end();i++) {
+ SPItem *other = SP_ITEM (*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 SelContainer
+unclump_remove_behind (SPItem *item, SPItem *closest, SelContainer &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);
+ SelContainer out;
+ for (SelContainer::const_iterator i = rest.begin(); i != rest.end();i++) {
+ SPItem *other = SP_ITEM (*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_front(other);
}
}
@@ -334,34 +331,32 @@ 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 (SelContainer &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 (SelContainer::const_iterator i = items.begin(); i != items.end();i++) { // for each original/clone x:
+ SPItem *item = SP_ITEM (*i);
- GSList *nei = NULL;
+ SelContainer nei;
- GSList *rest = g_slist_copy (items);
- rest = g_slist_remove (rest, item);
+ SelContainer rest(items);
+ 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);
+ nei.push_front(closest);
+ rest.remove(closest);
+ SelContainer new_rest = unclump_remove_behind (item, closest, rest);
rest = new_rest;
} 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..54f43ffde 100644
--- a/src/unclump.h
+++ b/src/unclump.h
@@ -12,8 +12,9 @@
#define SEEN_DIALOGS_UNCLUMP_H
typedef struct _GSList GSList;
+#include "selection.h"
-void unclump(GSList *items);
+void unclump(SelContainer &items);
#endif /* !UNCLUMP_H_SEEN */
diff --git a/src/vanishing-point.cpp b/src/vanishing-point.cpp
index b62aacbc5..98a3eaa67 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);
+ SelContainer itemlist=sel->itemList();
+ for (SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++) {
+ SPItem *item = static_cast<SPItem *>(*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);
+ SelContainer itemlist=sel->itemList();
+ for (SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++) {
+ SPItem *item = static_cast<SPItem *>(*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);
+ SelContainer itemlist=this->selection->itemList();
+ for (SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++) {
+ SPItem *item = static_cast<SPItem *>(*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);
+ SelContainer itemlist=this->selection->itemList();
+ for (SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++) {
+ SPItem *item = static_cast<SPItem *>(*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)
+ SelContainer 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..23c248129 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);
-
+ SelContainer itemlist=desktop->getSelection()->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *item = SP_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);
+ SelContainer itemlist=desktop->getSelection()->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *item = SP_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);
+ SelContainer itemlist=desktop->getSelection()->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *item = SP_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);
+ SelContainer itemlist=selection->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *item = SP_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..401ce932a 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);
+ SelContainer itemlist=desktop->getSelection()->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *item = SP_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);
+ SelContainer itemlist=desktop->getSelection()->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *item = SP_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 d60a92b8b..2c298b04d 100644
--- a/src/widgets/fill-style.cpp
+++ b/src/widgets/fill-style.cpp
@@ -481,7 +481,7 @@ void FillNStroke::updateFromPaint()
SPDocument *document = desktop->getDocument();
Inkscape::Selection *selection = desktop->getSelection();
- GSList const *items = selection->itemList();
+ SelContainer const items = selection->itemList();
switch (psel->mode) {
case SPPaintSelector::MODE_EMPTY:
@@ -543,7 +543,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 );
@@ -561,7 +561,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;
@@ -576,39 +576,39 @@ void FillNStroke::updateFromPaint()
}
}
- for (GSList const *i = items; i != NULL; i = i->next) {
+ for(SelContainer::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(reinterpret_cast<SPObject*>(*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(SP_ITEM(*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(SP_ITEM(*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(SelContainer::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(reinterpret_cast<SPObject*>(*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(SP_ITEM(*i), vector, gradient_type, (kind == FILL) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE);
psel->pushAttrsToGradient( gr );
}
}
@@ -625,7 +625,7 @@ void FillNStroke::updateFromPaint()
case SPPaintSelector::MODE_PATTERN:
- if (items) {
+ if (!items.empty()) {
SPPattern *pattern = psel->getPattern();
if (!pattern) {
@@ -648,12 +648,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(SelContainer::const_iterator i=items.begin();i!=items.end();i++){
+ Inkscape::XML::Node *selrepr = reinterpret_cast<SPObject*>(*i)->getRepr();
if ( (kind == STROKE) && !selrepr) {
continue;
}
- SPObject *selobj = reinterpret_cast<SPObject*>(i->data);
+ SPObject *selobj = reinterpret_cast<SPObject*>(*i);
SPStyle *style = selobj->style;
if (style && ((kind == FILL) ? style->fill : style->stroke).isPaintserver()) {
@@ -686,7 +686,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..b9608130b 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);
+ SelContainer itemlist=selection->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ gr_apply_gradient_to_item(SP_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
+ SelContainer itemlist=selection->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *item = SP_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);
+ SelContainer itemlist=selection->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *item = SP_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 3d549047a..b4176db6f 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_smooth = SP_MESH_SMOOTH_NONE;
- for (GSList const* i = selection->itemList(); i; i = i->next) {
- SPItem *item = SP_ITEM(i->data);
+ SelContainer itemlist=selection->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *item = SP_ITEM(*i);
SPStyle *style = item->style;
if (style && (style->fill.isPaintserver())) {
@@ -213,8 +214,9 @@ void ms_get_dt_selected_gradient(Inkscape::Selection *selection, SPMeshGradient
{
SPMeshGradient *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
+ SelContainer itemlist=selection->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *item = SP_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 016aa4987..1f19867ee 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)) {
+ SelContainer itemlist=selection->itemList();
+ for(SelContainer::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, desktop->getNamedView()->svg_units));
+ (SP_RECT(*i)->*setter)(Quantity::convert(gtk_adjustment_get_value(adj), unit, desktop->getNamedView()->svg_units));
} else {
- SP_OBJECT(items->data)->getRepr()->setAttribute(value_name, NULL);
+ SP_OBJECT(*i)->getRepr()->setAttribute(value_name, NULL);
}
modmade = true;
}
@@ -243,12 +244,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))) {
+ SelContainer itemlist=selection->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ if (SP_IS_RECT(reinterpret_cast<SPItem *>(*i))) {
n_selected++;
- item = reinterpret_cast<SPItem *>(items->data);
+ item = reinterpret_cast<SPItem *>(*i);
repr = item->getRepr();
}
}
diff --git a/src/widgets/spiral-toolbar.cpp b/src/widgets/spiral-toolbar.cpp
index 3fb0015c1..2f4ad481d 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);
+ SelContainer itemlist=desktop->getSelection()->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *item = SP_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);
+ SelContainer itemlist=selection->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *item = SP_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..37daf69d0 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);
+ SelContainer itemlist=selection->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *item = SP_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);
+ SelContainer itemlist=selection->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *item = SP_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);
+ SelContainer itemlist=selection->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *item = SP_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);
+ SelContainer itemlist=selection->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *item = SP_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);
+ SelContainer itemlist=selection->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *item = SP_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);
+ SelContainer itemlist=selection->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *item = SP_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..2599fe537 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);
+ SelContainer itemlist=selection->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *item = SP_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);
+ SelContainer const objects = sel->itemList();
+ SPObject * const object = SP_OBJECT(objects.front());
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();
+ SelContainer 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(SelContainer::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 = SP_OBJECT(*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 (SP_OBJECT(*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(SelContainer const &objects)
{
struct { MarkerComboBox *key; int loc; } const keyloc[] = {
{ startMarkerCombo, SP_MARKER_LOC_START },
@@ -1153,8 +1152,8 @@ 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(SelContainer::const_iterator i=objects.begin();i!=objects.end();i++){
+ if (!SP_IS_TEXT (*i)) {
all_texts = false;
}
}
@@ -1167,7 +1166,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 = SP_OBJECT(objects.front());
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..286305ec3 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(SelContainer 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 3d2e6eef8..ba7dfc1fd 100644
--- a/src/widgets/text-toolbar.cpp
+++ b/src/widgets/text-toolbar.cpp
@@ -366,9 +366,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);
+ SelContainer itemlist=selection->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ if (SP_IS_TEXT(SP_ITEM(*i))) {
+ SPItem *item = SP_ITEM(*i);
unsigned writing_mode = item->style->writing_mode.value;
// below, variable names suggest horizontal move, but we check the writing direction
@@ -517,11 +518,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));
+ SelContainer itemlist=selection->itemList();
+ for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ if (SP_IS_TEXT (*i)) {
+ SP_OBJECT(*i)->getRepr()->setAttribute("sodipodi:linespacing", sp_repr_css_property (css, "line-height", NULL));
modmade = true;
}
}
@@ -863,12 +864,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) {
+ SelContainer itemlist=SP_ACTIVE_DESKTOP->getSelection()->itemList();
+ for(SelContainer::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(SP_ITEM(*i))) {
isFlow = true;
// std::cout << " Found flowed text" << std::endl;
break;
@@ -1153,14 +1153,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;
+ SelContainer 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);
+ SelContainer x,y;
+ SelContainer allList = get_all_items(x, document->getRoot(), desktop, false, false, true, y);
+ for(SelContainer::const_iterator i=allList.begin();i!=allList.end();i++){
+ SPItem *item = SP_ITEM(*i);
SPStyle *style = item->style;
if (style) {
@@ -1177,7 +1177,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_front(static_cast<SPObject*>(item));
}
}
}