summaryrefslogtreecommitdiffstats
path: root/src/desktop-style.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/desktop-style.cpp')
-rw-r--r--src/desktop-style.cpp121
1 files changed, 60 insertions, 61 deletions
diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp
index c713e0d61..afdc3064a 100644
--- a/src/desktop-style.cpp
+++ b/src/desktop-style.cpp
@@ -194,10 +194,10 @@ sp_desktop_set_style(SPDesktop *desktop, SPCSSAttr *css, bool change, bool write
sp_repr_css_merge(css_write, css);
sp_css_attr_unset_uris(css_write);
prefs->mergeStyle("/desktop/style", css_write);
-
- for (const GSList *i = desktop->selection->itemList(); i != NULL; i = i->next) {
+ std::vector<SPItem*> const itemlist = desktop->selection->itemList();
+ for (std::vector<SPItem*>::const_iterator i = itemlist.begin(); i!= itemlist.end(); i++) {
/* last used styles for 3D box faces are stored separately */
- SPObject *obj = reinterpret_cast<SPObject *>(i->data); // TODO unsafe until Selection is refactored.
+ SPObject *obj = *i;
Box3DSide *side = dynamic_cast<Box3DSide *>(obj);
if (side) {
const char * descr = box3d_side_axes_string(side);
@@ -234,8 +234,9 @@ sp_desktop_set_style(SPDesktop *desktop, SPCSSAttr *css, bool change, bool write
sp_repr_css_merge(css_no_text, css);
css_no_text = sp_css_attr_unset_text(css_no_text);
- for (GSList const *i = desktop->selection->itemList(); i != NULL; i = i->next) {
- SPItem *item = reinterpret_cast<SPItem *>(i->data);
+ std::vector<SPItem*> const itemlist = desktop->selection->itemList();
+ for (std::vector<SPItem*>::const_iterator i = itemlist.begin(); i!= itemlist.end(); i++) {
+ SPItem *item = *i;
// If not text, don't apply text attributes (can a group have text attributes? Yes! FIXME)
if (isTextualItem(item)) {
@@ -438,18 +439,16 @@ sp_desktop_get_font_size_tool(SPDesktop *desktop)
/** Determine average stroke width, simple method */
// see TODO in dialogs/stroke-style.cpp on how to get rid of this eventually
gdouble
-stroke_average_width (GSList const *objects)
+stroke_average_width (const std::vector<SPItem*> &objects)
{
- if (g_slist_length ((GSList *) objects) == 0)
+ if (objects.empty())
return Geom::infinity();
gdouble avgwidth = 0.0;
bool notstroked = true;
int n_notstroked = 0;
-
- for (GSList const *l = objects; l != NULL; l = l->next) {
- SPObject *obj = reinterpret_cast<SPObject *>(l->data);
- SPItem *item = dynamic_cast<SPItem *>(obj);
+ for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) {
+ SPItem *item = *i;
if (!item) {
continue;
}
@@ -471,7 +470,7 @@ stroke_average_width (GSList const *objects)
if (notstroked)
return Geom::infinity();
- return avgwidth / (g_slist_length ((GSList *) objects) - n_notstroked);
+ return avgwidth / (objects.size() - n_notstroked);
}
static bool vectorsClose( std::vector<double> const &lhs, std::vector<double> const &rhs )
@@ -492,9 +491,9 @@ static bool vectorsClose( std::vector<double> const &lhs, std::vector<double> co
* Write to style_res the average fill or stroke of list of objects, if applicable.
*/
int
-objects_query_fillstroke (GSList *objects, SPStyle *style_res, bool const isfill)
+objects_query_fillstroke (const std::vector<SPItem*> &objects, SPStyle *style_res, bool const isfill)
{
- if (g_slist_length(objects) == 0) {
+ if (objects.empty()) {
/* No objects, set empty */
return QUERY_STYLE_NOTHING;
}
@@ -514,8 +513,8 @@ objects_query_fillstroke (GSList *objects, SPStyle *style_res, bool const isfill
prev[0] = prev[1] = prev[2] = 0.0;
bool same_color = true;
- for (GSList const *i = objects; i != NULL; i = i->next) {
- SPObject *obj = reinterpret_cast<SPObject *>(i->data);
+ for (std::vector<SPItem*>::const_iterator i = objects.begin(); i!= objects.end(); i++) {
+ SPObject *obj = *i;
if (!obj) {
continue;
}
@@ -674,7 +673,7 @@ objects_query_fillstroke (GSList *objects, SPStyle *style_res, bool const isfill
}
// Not color
- if (g_slist_length(objects) > 1) {
+ if (objects.size() > 1) {
return QUERY_STYLE_MULTIPLE_SAME;
} else {
return QUERY_STYLE_SINGLE;
@@ -685,9 +684,9 @@ objects_query_fillstroke (GSList *objects, SPStyle *style_res, bool const isfill
* Write to style_res the average opacity of a list of objects.
*/
int
-objects_query_opacity (GSList *objects, SPStyle *style_res)
+objects_query_opacity (const std::vector<SPItem*> &objects, SPStyle *style_res)
{
- if (g_slist_length(objects) == 0) {
+ if (objects.empty()) {
/* No objects, set empty */
return QUERY_STYLE_NOTHING;
}
@@ -698,8 +697,8 @@ objects_query_opacity (GSList *objects, SPStyle *style_res)
guint opacity_items = 0;
- for (GSList const *i = objects; i != NULL; i = i->next) {
- SPObject *obj = reinterpret_cast<SPObject *>(i->data);
+ for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) {
+ SPObject *obj = *i;
if (!obj) {
continue;
}
@@ -739,9 +738,9 @@ objects_query_opacity (GSList *objects, SPStyle *style_res)
* Write to style_res the average stroke width of a list of objects.
*/
int
-objects_query_strokewidth (GSList *objects, SPStyle *style_res)
+objects_query_strokewidth (const std::vector<SPItem*> &objects, SPStyle *style_res)
{
- if (g_slist_length(objects) == 0) {
+ if (objects.empty()) {
/* No objects, set empty */
return QUERY_STYLE_NOTHING;
}
@@ -754,8 +753,8 @@ objects_query_strokewidth (GSList *objects, SPStyle *style_res)
int n_stroked = 0;
- for (GSList const *i = objects; i != NULL; i = i->next) {
- SPObject *obj = reinterpret_cast<SPObject *>(i->data);
+ for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) {
+ SPObject *obj = *i;
if (!obj) {
continue;
}
@@ -815,9 +814,9 @@ objects_query_strokewidth (GSList *objects, SPStyle *style_res)
* Write to style_res the average miter limit of a list of objects.
*/
int
-objects_query_miterlimit (GSList *objects, SPStyle *style_res)
+objects_query_miterlimit (const std::vector<SPItem*> &objects, SPStyle *style_res)
{
- if (g_slist_length(objects) == 0) {
+ if (objects.empty()) {
/* No objects, set empty */
return QUERY_STYLE_NOTHING;
}
@@ -828,8 +827,8 @@ objects_query_miterlimit (GSList *objects, SPStyle *style_res)
gdouble prev_ml = -1;
bool same_ml = true;
- for (GSList const *i = objects; i != NULL; i = i->next) {
- SPObject *obj = reinterpret_cast<SPObject *>(i->data);
+ for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) {
+ SPObject *obj = *i;
if (!dynamic_cast<SPItem *>(obj)) {
continue;
}
@@ -875,9 +874,9 @@ objects_query_miterlimit (GSList *objects, SPStyle *style_res)
* Write to style_res the stroke cap of a list of objects.
*/
int
-objects_query_strokecap (GSList *objects, SPStyle *style_res)
+objects_query_strokecap (const std::vector<SPItem*> &objects, SPStyle *style_res)
{
- if (g_slist_length(objects) == 0) {
+ if (objects.empty()) {
/* No objects, set empty */
return QUERY_STYLE_NOTHING;
}
@@ -887,8 +886,8 @@ objects_query_strokecap (GSList *objects, SPStyle *style_res)
bool same_cap = true;
int n_stroked = 0;
- for (GSList const *i = objects; i != NULL; i = i->next) {
- SPObject *obj = reinterpret_cast<SPObject *>(i->data);
+ for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) {
+ SPObject *obj = *i;
if (!dynamic_cast<SPItem *>(obj)) {
continue;
}
@@ -929,9 +928,9 @@ objects_query_strokecap (GSList *objects, SPStyle *style_res)
* Write to style_res the stroke join of a list of objects.
*/
int
-objects_query_strokejoin (GSList *objects, SPStyle *style_res)
+objects_query_strokejoin (const std::vector<SPItem*> &objects, SPStyle *style_res)
{
- if (g_slist_length(objects) == 0) {
+ if (objects.empty()) {
/* No objects, set empty */
return QUERY_STYLE_NOTHING;
}
@@ -941,8 +940,8 @@ objects_query_strokejoin (GSList *objects, SPStyle *style_res)
bool same_join = true;
int n_stroked = 0;
- for (GSList const *i = objects; i != NULL; i = i->next) {
- SPObject *obj = reinterpret_cast<SPObject *>(i->data);
+ for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) {
+ SPObject *obj = *i;
if (!dynamic_cast<SPItem *>(obj)) {
continue;
}
@@ -984,7 +983,7 @@ objects_query_strokejoin (GSList *objects, SPStyle *style_res)
* Write to style_res the average font size and spacing of objects.
*/
int
-objects_query_fontnumbers (GSList *objects, SPStyle *style_res)
+objects_query_fontnumbers (const std::vector<SPItem*> &objects, SPStyle *style_res)
{
bool different = false;
@@ -1004,8 +1003,8 @@ objects_query_fontnumbers (GSList *objects, SPStyle *style_res)
int texts = 0;
int no_size = 0;
- for (GSList const *i = objects; i != NULL; i = i->next) {
- SPObject *obj = reinterpret_cast<SPObject *>(i->data);
+ for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) {
+ SPObject *obj = *i;
if (!isTextualItem(obj)) {
continue;
@@ -1116,15 +1115,15 @@ objects_query_fontnumbers (GSList *objects, SPStyle *style_res)
* Write to style_res the average font style of objects.
*/
int
-objects_query_fontstyle (GSList *objects, SPStyle *style_res)
+objects_query_fontstyle (const std::vector<SPItem*> &objects, SPStyle *style_res)
{
bool different = false;
bool set = false;
int texts = 0;
- for (GSList const *i = objects; i != NULL; i = i->next) {
- SPObject *obj = reinterpret_cast<SPObject *>(i->data);
+ for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) {
+ SPObject *obj = *i;
if (!isTextualItem(obj)) {
continue;
@@ -1173,7 +1172,7 @@ objects_query_fontstyle (GSList *objects, SPStyle *style_res)
* Write to style_res the baseline numbers.
*/
static int
-objects_query_baselines (GSList *objects, SPStyle *style_res)
+objects_query_baselines (const std::vector<SPItem*> &objects, SPStyle *style_res)
{
bool different = false;
@@ -1192,8 +1191,8 @@ objects_query_baselines (GSList *objects, SPStyle *style_res)
int texts = 0;
- for (GSList const *i = objects; i != NULL; i = i->next) {
- SPObject *obj = reinterpret_cast<SPObject *>(i->data);
+ for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) {
+ SPObject *obj = *i;
if (!isTextualItem(obj)) {
continue;
@@ -1269,7 +1268,7 @@ objects_query_baselines (GSList *objects, SPStyle *style_res)
* Write to style_res the average font family of objects.
*/
int
-objects_query_fontfamily (GSList *objects, SPStyle *style_res)
+objects_query_fontfamily (const std::vector<SPItem*> &objects, SPStyle *style_res)
{
bool different = false;
int texts = 0;
@@ -1280,8 +1279,8 @@ objects_query_fontfamily (GSList *objects, SPStyle *style_res)
}
style_res->font_family.set = FALSE;
- for (GSList const *i = objects; i != NULL; i = i->next) {
- SPObject *obj = reinterpret_cast<SPObject *>(i->data);
+ for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) {
+ SPObject *obj = *i;
// std::cout << " " << reinterpret_cast<SPObject*>(i->data)->getId() << std::endl;
if (!isTextualItem(obj)) {
@@ -1325,7 +1324,7 @@ objects_query_fontfamily (GSList *objects, SPStyle *style_res)
}
static int
-objects_query_fontspecification (GSList *objects, SPStyle *style_res)
+objects_query_fontspecification (const std::vector<SPItem*> &objects, SPStyle *style_res)
{
bool different = false;
int texts = 0;
@@ -1336,8 +1335,8 @@ objects_query_fontspecification (GSList *objects, SPStyle *style_res)
}
style_res->font_specification.set = FALSE;
- for (GSList const *i = objects; i != NULL; i = i->next) {
- SPObject *obj = reinterpret_cast<SPObject *>(i->data);
+ for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) {
+ SPObject *obj = *i;
// std::cout << " " << reinterpret_cast<SPObject*>(i->data)->getId() << std::endl;
if (!isTextualItem(obj)) {
@@ -1385,7 +1384,7 @@ objects_query_fontspecification (GSList *objects, SPStyle *style_res)
}
static int
-objects_query_blend (GSList *objects, SPStyle *style_res)
+objects_query_blend (const std::vector<SPItem*> &objects, SPStyle *style_res)
{
const int empty_prev = -2;
const int complex_filter = 5;
@@ -1394,8 +1393,8 @@ objects_query_blend (GSList *objects, SPStyle *style_res)
bool same_blend = true;
guint items = 0;
- for (GSList const *i = objects; i != NULL; i = i->next) {
- SPObject *obj = reinterpret_cast<SPObject *>(i->data);
+ for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) {
+ SPObject *obj = *i;
if (!obj) {
continue;
}
@@ -1471,9 +1470,9 @@ objects_query_blend (GSList *objects, SPStyle *style_res)
* Write to style_res the average blurring of a list of objects.
*/
int
-objects_query_blur (GSList *objects, SPStyle *style_res)
+objects_query_blur (const std::vector<SPItem*> &objects, SPStyle *style_res)
{
- if (g_slist_length(objects) == 0) {
+ if (objects.empty()) {
/* No objects, set empty */
return QUERY_STYLE_NOTHING;
}
@@ -1484,8 +1483,8 @@ objects_query_blur (GSList *objects, SPStyle *style_res)
guint blur_items = 0;
guint items = 0;
- for (GSList const *i = objects; i != NULL; i = i->next) {
- SPObject *obj = reinterpret_cast<SPObject *>(i->data);
+ for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) {
+ SPObject *obj = *i;
if (!obj) {
continue;
}
@@ -1553,7 +1552,7 @@ objects_query_blur (GSList *objects, SPStyle *style_res)
* the result to style, return appropriate flag.
*/
int
-sp_desktop_query_style_from_list (GSList *list, SPStyle *style, int property)
+sp_desktop_query_style_from_list (const std::vector<SPItem*> &list, SPStyle *style, int property)
{
if (property == QUERY_STYLE_PROPERTY_FILL) {
return objects_query_fillstroke (list, style, true);
@@ -1606,7 +1605,7 @@ sp_desktop_query_style(SPDesktop *desktop, SPStyle *style, int property)
// otherwise, do querying and averaging over selection
if (desktop->selection != NULL) {
- return sp_desktop_query_style_from_list ((GSList *) desktop->selection->itemList(), style, property);
+ return sp_desktop_query_style_from_list (desktop->selection->itemList(), style, property);
}
return QUERY_STYLE_NOTHING;