summaryrefslogtreecommitdiffstats
path: root/src/sp-namedview.cpp
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2016-03-14 16:37:50 +0000
committerJabiertxof <jtx@jtx.marker.es>2016-03-14 16:37:50 +0000
commitb8d22beef5345210ad27cdc2685083aeae6f8f3b (patch)
treed69b8bfd19d3627a8425a1b265c2abf229b05354 /src/sp-namedview.cpp
parentfixes for update to trunk (diff)
parent"Relative to" option for node alignment. (diff)
downloadinkscape-b8d22beef5345210ad27cdc2685083aeae6f8f3b.tar.gz
inkscape-b8d22beef5345210ad27cdc2685083aeae6f8f3b.zip
update to trunk
(bzr r13708.1.39)
Diffstat (limited to 'src/sp-namedview.cpp')
-rw-r--r--src/sp-namedview.cpp201
1 files changed, 111 insertions, 90 deletions
diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp
index 12c2cdf8e..9598a14ec 100644
--- a/src/sp-namedview.cpp
+++ b/src/sp-namedview.cpp
@@ -51,7 +51,9 @@ using Inkscape::Util::unit_table;
#define DEFAULTPAGECOLOR 0xffffff00
static void sp_namedview_setup_guides(SPNamedView * nv);
+static void sp_namedview_lock_guides(SPNamedView * nv);
static void sp_namedview_show_single_guide(SPGuide* guide, bool show);
+static void sp_namedview_lock_single_guide(SPGuide* guide, bool show);
static gboolean sp_str_to_bool(const gchar *str);
static gboolean sp_nv_read_opacity(const gchar *str, guint32 *color);
@@ -60,7 +62,7 @@ SPNamedView::SPNamedView() : SPObjectGroup(), snap_manager(this) {
this->zoom = 0;
this->guidecolor = 0;
this->guidehicolor = 0;
- this->views = NULL;
+ this->views.clear();
this->borderlayer = 0;
this->page_size_units = NULL;
this->window_x = 0;
@@ -79,13 +81,15 @@ SPNamedView::SPNamedView() : SPObjectGroup(), snap_manager(this) {
this->editable = TRUE;
this->showguides = TRUE;
+ this->lockguides = false;
this->grids_visible = false;
this->showborder = TRUE;
+ this->pagecheckerboard = FALSE;
this->showpageshadow = TRUE;
- this->guides = NULL;
+ this->guides.clear();
this->viewcount = 0;
- this->grids = NULL;
+ this->grids.clear();
this->default_layer_id = 0;
@@ -204,6 +208,7 @@ void SPNamedView::build(SPDocument *document, Inkscape::XML::Node *repr) {
this->readAttr( "bordercolor" );
this->readAttr( "borderopacity" );
this->readAttr( "pagecolor" );
+ this->readAttr( "inkscape:pagecheckerboard" );
this->readAttr( "inkscape:pageopacity" );
this->readAttr( "inkscape:pageshadow" );
this->readAttr( "inkscape:zoom" );
@@ -240,15 +245,17 @@ void SPNamedView::build(SPDocument *document, Inkscape::XML::Node *repr) {
this->readAttr( "inkscape:snap-page" );
this->readAttr( "inkscape:current-layer" );
this->readAttr( "inkscape:connector-spacing" );
+ this->readAttr( "inkscape:lockguides" );
/* Construct guideline list */
for (SPObject *o = this->firstChild() ; o; o = o->getNext() ) {
if (SP_IS_GUIDE(o)) {
SPGuide * g = SP_GUIDE(o);
- this->guides = g_slist_prepend(this->guides, g);
+ this->guides.push_back(g);
//g_object_set(G_OBJECT(g), "color", nv->guidecolor, "hicolor", nv->guidehicolor, NULL);
g->setColor(this->guidecolor);
g->setHiColor(this->guidehicolor);
+ g->readAttr( "inkscape:color" );
}
}
@@ -267,18 +274,12 @@ void SPNamedView::build(SPDocument *document, Inkscape::XML::Node *repr) {
}
void SPNamedView::release() {
- if (this->guides) {
- g_slist_free(this->guides);
- this->guides = NULL;
- }
+ this->guides.clear();
// delete grids:
- while ( this->grids ) {
- Inkscape::CanvasGrid *gr = (Inkscape::CanvasGrid *)this->grids->data; // get first entry
- delete gr;
- this->grids = g_slist_remove_link(this->grids, this->grids); // deletes first entry
- }
-
+ for(std::vector<Inkscape::CanvasGrid *>::const_iterator it=this->grids.begin();it!=this->grids.end();++it )
+ delete *it;
+ this->grids.clear();
SPObjectGroup::release();
}
@@ -324,9 +325,9 @@ void SPNamedView::set(unsigned int key, const gchar* value) {
this->guidecolor = (this->guidecolor & 0xff) | sp_svg_read_color(value, this->guidecolor);
}
- for (GSList *l = this->guides; l != NULL; l = l->next) {
- //g_object_set(G_OBJECT(l->data), "color", nv->guidecolor, NULL);
- SP_GUIDE(l->data)->setColor(this->guidecolor);
+ for(std::vector<SPGuide *>::const_iterator it=this->guides.begin();it!=this->guides.end();++it ) {
+ (*it)->setColor(this->guidecolor);
+ (*it)->readAttr("inkscape:color");
}
this->requestModified(SP_OBJECT_MODIFIED_FLAG);
@@ -335,9 +336,9 @@ void SPNamedView::set(unsigned int key, const gchar* value) {
this->guidecolor = (this->guidecolor & 0xffffff00) | (DEFAULTGUIDECOLOR & 0xff);
sp_nv_read_opacity(value, &this->guidecolor);
- for (GSList *l = this->guides; l != NULL; l = l->next) {
- //g_object_set(G_OBJECT(l->data), "color", nv->guidecolor, NULL);
- SP_GUIDE(l->data)->setColor(this->guidecolor);
+ for(std::vector<SPGuide *>::const_iterator it=this->guides.begin();it!=this->guides.end();++it ) {
+ (*it)->setColor(this->guidecolor);
+ (*it)->readAttr("inkscape:color");
}
this->requestModified(SP_OBJECT_MODIFIED_FLAG);
@@ -348,10 +349,8 @@ void SPNamedView::set(unsigned int key, const gchar* value) {
if (value) {
this->guidehicolor = (this->guidehicolor & 0xff) | sp_svg_read_color(value, this->guidehicolor);
}
-
- for (GSList *l = this->guides; l != NULL; l = l->next) {
- //g_object_set(G_OBJECT(l->data), "hicolor", nv->guidehicolor, NULL);
- SP_GUIDE(l->data)->setHiColor(this->guidehicolor);
+ for(std::vector<SPGuide *>::const_iterator it=this->guides.begin();it!=this->guides.end();++it ) {
+ (*it)->setHiColor(this->guidehicolor);
}
this->requestModified(SP_OBJECT_MODIFIED_FLAG);
@@ -359,10 +358,8 @@ void SPNamedView::set(unsigned int key, const gchar* value) {
case SP_ATTR_GUIDEHIOPACITY:
this->guidehicolor = (this->guidehicolor & 0xffffff00) | (DEFAULTGUIDEHICOLOR & 0xff);
sp_nv_read_opacity(value, &this->guidehicolor);
-
- for (GSList *l = this->guides; l != NULL; l = l->next) {
- //g_object_set(G_OBJECT(l->data), "hicolor", nv->guidehicolor, NULL);
- SP_GUIDE(l->data)->setHiColor(this->guidehicolor);
+ for(std::vector<SPGuide *>::const_iterator it=this->guides.begin();it!=this->guides.end();++it ) {
+ (*it)->setHiColor(this->guidehicolor);
}
this->requestModified(SP_OBJECT_MODIFIED_FLAG);
@@ -395,6 +392,10 @@ void SPNamedView::set(unsigned int key, const gchar* value) {
}
this->requestModified(SP_OBJECT_MODIFIED_FLAG);
break;
+ case SP_ATTR_INKSCAPE_PAGECHECKERBOARD:
+ this->pagecheckerboard = (value) ? sp_str_to_bool (value) : false;
+ this->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ break;
case SP_ATTR_INKSCAPE_PAGEOPACITY:
this->pagecolor = (this->pagecolor & 0xffffff00) | (DEFAULTPAGECOLOR & 0xff);
sp_nv_read_opacity(value, &this->pagecolor);
@@ -597,6 +598,11 @@ void SPNamedView::set(unsigned int key, const gchar* value) {
this->requestModified(SP_OBJECT_MODIFIED_FLAG);
break;
}
+ case SP_ATTR_INKSCAPE_LOCKGUIDES:
+ this->lockguides = value ? sp_str_to_bool(value) : FALSE;
+ sp_namedview_lock_guides(this);
+ this->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ break;
default:
SPObjectGroup::set(key, value);
break;
@@ -611,10 +617,9 @@ static Inkscape::CanvasGrid*
sp_namedview_add_grid(SPNamedView *nv, Inkscape::XML::Node *repr, SPDesktop *desktop) {
Inkscape::CanvasGrid* grid = NULL;
//check if namedview already has an object for this grid
- for (GSList *l = nv->grids; l != NULL; l = l->next) {
- Inkscape::CanvasGrid* g = (Inkscape::CanvasGrid*) l->data;
- if (repr == g->repr) {
- grid = g;
+ for(std::vector<Inkscape::CanvasGrid *>::const_iterator it=nv->grids.begin();it!=nv->grids.end();++it ) {
+ if (repr == (*it)->repr) {
+ grid = (*it);
break;
}
}
@@ -627,14 +632,13 @@ sp_namedview_add_grid(SPNamedView *nv, Inkscape::XML::Node *repr, SPDesktop *des
return NULL;
}
grid = Inkscape::CanvasGrid::NewGrid(nv, repr, nv->document, gridtype);
- nv->grids = g_slist_append(nv->grids, grid);
+ nv->grids.push_back(grid);
}
if (!desktop) {
//add canvasitem to all desktops
- for (GSList *l = nv->views; l != NULL; l = l->next) {
- SPDesktop *dt = static_cast<SPDesktop*>(l->data);
- grid->createCanvasItem(dt);
+ for(std::vector<SPDesktop *>::const_iterator it=nv->views.begin();it!=nv->views.end();++it ) {
+ grid->createCanvasItem(*it);
}
} else {
//add canvasitem only for specified desktop
@@ -657,21 +661,23 @@ void SPNamedView::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *r
if (SP_IS_GUIDE(no)) {
SPGuide *g = (SPGuide *) no;
- this->guides = g_slist_prepend(this->guides, g);
+ this->guides.push_back(g);
//g_object_set(G_OBJECT(g), "color", this->guidecolor, "hicolor", this->guidehicolor, NULL);
g->setColor(this->guidecolor);
g->setHiColor(this->guidehicolor);
+ g->readAttr("inkscape:color");
if (this->editable) {
- for (GSList *l = this->views; l != NULL; l = l->next) {
- g->SPGuide::showSPGuide(static_cast<SPDesktop*>(l->data)->guides, (GCallback) sp_dt_guide_event);
+ for(std::vector<SPDesktop *>::const_iterator it=this->views.begin();it!=this->views.end();++it ) {
+ g->SPGuide::showSPGuide((*it)->guides, (GCallback) sp_dt_guide_event);
- if (static_cast<SPDesktop*>(l->data)->guides_active) {
- g->sensitize((static_cast<SPDesktop*> (l->data))->getCanvas(), TRUE);
+ if ((*it)->guides_active) {
+ g->sensitize((*it)->getCanvas(), TRUE);
}
sp_namedview_show_single_guide(SP_GUIDE(g), this->showguides);
+ sp_namedview_lock_single_guide(SP_GUIDE(g), this->lockguides);
}
}
}
@@ -680,27 +686,19 @@ void SPNamedView::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *r
void SPNamedView::remove_child(Inkscape::XML::Node *child) {
if (!strcmp(child->name(), "inkscape:grid")) {
- for ( GSList *iter = this->grids ; iter ; iter = iter->next ) {
- Inkscape::CanvasGrid *gr = (Inkscape::CanvasGrid *)iter->data;
-
- if ( gr->repr == child ) {
- delete gr;
- this->grids = g_slist_remove_link(this->grids, iter);
+ for(std::vector<Inkscape::CanvasGrid *>::iterator it=this->grids.begin();it!=this->grids.end();++it ) {
+ if ( (*it)->repr == child ) {
+ delete (*it);
+ this->grids.erase(it);
break;
}
}
} else {
- GSList **ref = &this->guides;
- for ( GSList *iter = this->guides ; iter ; iter = iter->next ) {
-
- if ( reinterpret_cast<SPObject *>(iter->data)->getRepr() == child ) {
- *ref = iter->next;
- iter->next = NULL;
- g_slist_free_1(iter);
+ for(std::vector<SPGuide *>::iterator it=this->guides.begin();it!=this->guides.end();++it ) {
+ if ( (*it)->getRepr() == child ) {
+ this->guides.erase(it);
break;
- }
-
- ref = &iter->next;
+ }
}
}
@@ -723,15 +721,16 @@ Inkscape::XML::Node* SPNamedView::write(Inkscape::XML::Document *xml_doc, Inksca
void SPNamedView::show(SPDesktop *desktop)
{
- for (GSList *l = guides; l != NULL; l = l->next) {
- SP_GUIDE(l->data)->showSPGuide( desktop->guides, (GCallback) sp_dt_guide_event);
+ for(std::vector<SPGuide *>::const_iterator it=this->guides.begin();it!=this->guides.end();++it ) {
+ (*it)->showSPGuide( desktop->guides, (GCallback) sp_dt_guide_event);
if (desktop->guides_active) {
- SP_GUIDE(l->data)->sensitize(desktop->getCanvas(), TRUE);
+ (*it)->sensitize(desktop->getCanvas(), TRUE);
}
- sp_namedview_show_single_guide(SP_GUIDE(l->data), showguides);
+ sp_namedview_show_single_guide((*it), showguides);
+ sp_namedview_lock_single_guide((*it), lockguides);
}
- views = g_slist_prepend(views, desktop);
+ views.push_back(desktop);
// generate grids specified in SVG:
Inkscape::XML::Node *repr = this->getRepr();
@@ -920,31 +919,35 @@ void sp_namedview_document_from_window(SPDesktop *desktop)
void SPNamedView::hide(SPDesktop const *desktop)
{
g_assert(desktop != NULL);
- g_assert(g_slist_find(views, desktop));
-
- for (GSList *l = guides; l != NULL; l = l->next) {
- SP_GUIDE(l->data)->hideSPGuide(desktop->getCanvas());
+ g_assert(std::find(views.begin(),views.end(),desktop)!=views.end());
+ for(std::vector<SPGuide *>::iterator it=this->guides.begin();it!=this->guides.end();++it ) {
+ (*it)->hideSPGuide(desktop->getCanvas());
}
-
- views = g_slist_remove(views, desktop);
+ views.erase(std::remove(views.begin(),views.end(),desktop),views.end());
}
void SPNamedView::activateGuides(void* desktop, bool active)
{
g_assert(desktop != NULL);
- g_assert(g_slist_find(views, desktop));
+ g_assert(std::find(views.begin(),views.end(),desktop)!=views.end());
SPDesktop *dt = static_cast<SPDesktop*>(desktop);
-
- for (GSList *l = guides; l != NULL; l = l->next) {
- SP_GUIDE(l->data)->sensitize(dt->getCanvas(), active);
+ for(std::vector<SPGuide *>::iterator it=this->guides.begin();it!=this->guides.end();++it ) {
+ (*it)->sensitize(dt->getCanvas(), active);
}
}
static void sp_namedview_setup_guides(SPNamedView *nv)
{
- for (GSList *l = nv->guides; l != NULL; l = l->next) {
- sp_namedview_show_single_guide(SP_GUIDE(l->data), nv->showguides);
+ for(std::vector<SPGuide *>::iterator it=nv->guides.begin();it!=nv->guides.end();++it ) {
+ sp_namedview_show_single_guide(*it, nv->showguides);
+ }
+}
+
+static void sp_namedview_lock_guides(SPNamedView *nv)
+{
+ for(std::vector<SPGuide *>::iterator it=nv->guides.begin();it!=nv->guides.end();++it ) {
+ sp_namedview_lock_single_guide(*it, nv->lockguides);
}
}
@@ -957,6 +960,11 @@ static void sp_namedview_show_single_guide(SPGuide* guide, bool show)
}
}
+static void sp_namedview_lock_single_guide(SPGuide* guide, bool locked)
+{
+ guide->set_locked(locked, true);
+}
+
void sp_namedview_toggle_guides(SPDocument *doc, Inkscape::XML::Node *repr)
{
unsigned int v;
@@ -975,6 +983,23 @@ void sp_namedview_toggle_guides(SPDocument *doc, Inkscape::XML::Node *repr)
doc->setModifiedSinceSave();
}
+void sp_namedview_guides_toggle_lock(SPDocument *doc, Inkscape::XML::Node *repr)
+{
+ unsigned int v;
+ unsigned int set = sp_repr_get_boolean(repr, "inkscape:lockguides", &v);
+ if (!set) { // hide guides if not specified, for backwards compatibility
+ v = true;
+ } else {
+ v = !v;
+ }
+
+ bool saved = DocumentUndo::getUndoSensitive(doc);
+ DocumentUndo::setUndoSensitive(doc, false);
+ sp_repr_set_boolean(repr, "inkscape:lockguides", v);
+ DocumentUndo::setUndoSensitive(doc, saved);
+ doc->setModifiedSinceSave();
+}
+
void sp_namedview_show_grids(SPNamedView * namedview, bool show, bool dirty_document)
{
namedview->grids_visible = show;
@@ -1006,7 +1031,7 @@ guint SPNamedView::getViewCount()
return ++viewcount;
}
-GSList const *SPNamedView::getViewList() const
+std::vector<SPDesktop *> const SPNamedView::getViewList() const
{
return views;
}
@@ -1073,6 +1098,7 @@ void SPNamedView::setGuides(bool v)
g_assert(this->getRepr() != NULL);
sp_repr_set_boolean(this->getRepr(), "showguides", v);
sp_repr_set_boolean(this->getRepr(), "inkscape:guide-bbox", v);
+ sp_repr_set_boolean(this->getRepr(), "inkscape:locked", false);
}
bool SPNamedView::getGuides()
@@ -1140,18 +1166,17 @@ Inkscape::Util::Unit const & SPNamedView::getSVGUnit() const
*/
Inkscape::CanvasGrid * sp_namedview_get_first_enabled_grid(SPNamedView *namedview)
{
- for (GSList const * l = namedview->grids; l != NULL; l = l->next) {
- Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
- if (grid->isEnabled())
- return grid;
+ for(std::vector<Inkscape::CanvasGrid *>::const_iterator it=namedview->grids.begin();it!=namedview->grids.end();++it ) {
+ if ((*it)->isEnabled())
+ return (*it);
}
return NULL;
}
void SPNamedView::translateGuides(Geom::Translate const &tr) {
- for (GSList *l = guides; l != NULL; l = l->next) {
- SPGuide &guide = *SP_GUIDE(l->data);
+ for(std::vector<SPGuide *>::iterator it=this->guides.begin();it!=this->guides.end();++it ) {
+ SPGuide &guide = *(*it);
Geom::Point point_on_line = guide.getPoint();
point_on_line *= tr;
guide.moveto(point_on_line, true);
@@ -1159,19 +1184,15 @@ void SPNamedView::translateGuides(Geom::Translate const &tr) {
}
void SPNamedView::translateGrids(Geom::Translate const &tr) {
- for (GSList *l = grids; l != NULL; l = l->next) {
- Inkscape::CanvasGrid* g = reinterpret_cast<Inkscape::CanvasGrid*>(l->data);
- if (g) {
- g->setOrigin(g->origin * tr);
- }
+ for(std::vector<Inkscape::CanvasGrid *>::iterator it=this->grids.begin();it!=this->grids.end();++it ) {
+ (*it)->setOrigin((*it)->origin * tr);
}
}
void SPNamedView::scrollAllDesktops(double dx, double dy, bool is_scrolling) {
- for(GSList *l = views; l; l = l->next) {
- SPDesktop *desktop = static_cast<SPDesktop *>(l->data);
- desktop->scroll_world_in_svg_coords(dx, dy, is_scrolling);
- }
+ for(std::vector<SPDesktop *>::iterator it=this->views.begin();it!=this->views.end();++it ) {
+ (*it)->scroll_world_in_svg_coords(dx, dy, is_scrolling);
+ }
}