diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp
index 793dff561580d3e01480c455bfa32ca0ffa2872a..47720c5d64f12fb9409e1f74aa7a537b457d0fe8 100644 (file)
--- a/src/sp-namedview.cpp
+++ b/src/sp-namedview.cpp
#include <string>
#include "display/canvas-grid.h"
+#include "display/guideline.h"
#include "helper/units.h"
#include "svg/svg-color.h"
#include "xml/repr.h"
static Inkscape::XML::Node *sp_namedview_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
static void sp_namedview_setup_guides(SPNamedView * nv);
+static void sp_namedview_show_single_guide(SPGuide* guide, bool show);
static gboolean sp_str_to_bool(const gchar *str);
-static gboolean sp_nv_read_length(const gchar *str, guint base, gdouble *val, const SPUnit **unit);
static gboolean sp_nv_read_opacity(const gchar *str, guint32 *color);
static SPObjectGroupClass * parent_class;
@@ -242,6 +243,7 @@ static void sp_namedview_build(SPObject *object, SPDocument *document, Inkscape:
sp_object_read_attr(object, "inkscape:window-height");
sp_object_read_attr(object, "inkscape:window-x");
sp_object_read_attr(object, "inkscape:window-y");
+ sp_object_read_attr(object, "inkscape:window-maximized");
sp_object_read_attr(object, "inkscape:snap-global");
sp_object_read_attr(object, "inkscape:snap-bbox");
sp_object_read_attr(object, "inkscape:snap-nodes");
@@ -252,7 +254,6 @@ static void sp_namedview_build(SPObject *object, SPDocument *document, Inkscape:
sp_object_read_attr(object, "inkscape:snap-object-midpoints");
sp_object_read_attr(object, "inkscape:snap-bbox-edge-midpoints");
sp_object_read_attr(object, "inkscape:snap-bbox-midpoints");
- //sp_object_read_attr(object, "inkscape:snap-intersection-grid-guide");
sp_object_read_attr(object, "inkscape:snap-to-guides");
sp_object_read_attr(object, "inkscape:snap-grids");
sp_object_read_attr(object, "inkscape:snap-intersection-paths");
@@ -437,14 +438,18 @@ static void sp_namedview_set(SPObject *object, unsigned int key, const gchar *va
object->requestModified(SP_OBJECT_MODIFIED_FLAG);
break;
case SP_ATTR_INKSCAPE_WINDOW_X:
- nv->window_x = value ? atoi(value) : -1; // -1 means not set
+ nv->window_x = value ? atoi(value) : 0;
object->requestModified(SP_OBJECT_MODIFIED_FLAG);
break;
case SP_ATTR_INKSCAPE_WINDOW_Y:
- nv->window_y = value ? atoi(value) : -1; // -1 means not set
+ nv->window_y = value ? atoi(value) : 0;
object->requestModified(SP_OBJECT_MODIFIED_FLAG);
break;
- case SP_ATTR_INKSCAPE_SNAP_GLOBAL:
+ case SP_ATTR_INKSCAPE_WINDOW_MAXIMIZED:
+ nv->window_maximized = value ? atoi(value) : 0;
+ object->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ break;
+ case SP_ATTR_INKSCAPE_SNAP_GLOBAL:
nv->snap_manager.snapprefs.setSnapEnabledGlobally(value ? sp_str_to_bool(value) : TRUE);
object->requestModified(SP_OBJECT_MODIFIED_FLAG);
break;
@@ -489,13 +494,9 @@ static void sp_namedview_set(SPObject *object, unsigned int key, const gchar *va
object->requestModified(SP_OBJECT_MODIFIED_FLAG);
break;
case SP_ATTR_INKSCAPE_SNAP_FROM_GUIDE:
- nv->snap_manager.snapprefs.setSnapModeGuide(value ? sp_str_to_bool(value) : FALSE);
+ nv->snap_manager.snapprefs.setSnapModeGuide(value ? sp_str_to_bool(value) : TRUE);
object->requestModified(SP_OBJECT_MODIFIED_FLAG);
break;
- /*case SP_ATTR_INKSCAPE_SNAP_INTERS_GRIDGUIDE:
- nv->snap_manager.snapprefs.setSnapIntersectionGG(value ? sp_str_to_bool(value) : TRUE);
- object->requestModified(SP_OBJECT_MODIFIED_FLAG);
- break;*/
case SP_ATTR_INKSCAPE_SNAP_INTERS_PATHS:
nv->snap_manager.snapprefs.setSnapIntersectionCS(value ? sp_str_to_bool(value) : FALSE);
object->requestModified(SP_OBJECT_MODIFIED_FLAG);
@@ -645,15 +646,7 @@ static void sp_namedview_child_added(SPObject *object, Inkscape::XML::Node *chil
sp_guide_sensitize(g,
sp_desktop_canvas(static_cast<SPDesktop*> (l->data)),
TRUE);
- if (nv->showguides) {
- for (GSList *v = SP_GUIDE(g)->views; v != NULL; v = v->next) {
- sp_canvas_item_show(SP_CANVAS_ITEM(v->data));
- }
- } else {
- for (GSList *v = SP_GUIDE(g)->views; v != NULL; v = v->next) {
- sp_canvas_item_hide(SP_CANVAS_ITEM(v->data));
- }
- }
+ sp_namedview_show_single_guide(SP_GUIDE(g), nv->showguides);
}
}
}
if (desktop->guides_active) {
sp_guide_sensitize(SP_GUIDE(l->data), sp_desktop_canvas(desktop), TRUE);
}
- if (showguides) {
- for (GSList *v = SP_GUIDE(l->data)->views; v != NULL; v = v->next) {
- sp_canvas_item_show(SP_CANVAS_ITEM(v->data));
- }
- } else {
- for (GSList *v = SP_GUIDE(l->data)->views; v != NULL; v = v->next) {
- sp_canvas_item_hide(SP_CANVAS_ITEM(v->data));
- }
- }
+ sp_namedview_show_single_guide(SP_GUIDE(l->data), showguides);
}
views = g_slist_prepend(views, desktop);
// restore window size and position stored with the document
if (geometry_from_file) {
- gint w = MIN(gdk_screen_width(), nv->window_width);
- gint h = MIN(gdk_screen_height(), nv->window_height);
- gint x = MIN(gdk_screen_width() - MIN_ONSCREEN_DISTANCE, nv->window_x);
- gint y = MIN(gdk_screen_height() - MIN_ONSCREEN_DISTANCE, nv->window_y);
- if (w>0 && h>0 && x>0 && y>0) {
- x = MIN(gdk_screen_width() - w, x);
- y = MIN(gdk_screen_height() - h, y);
- }
- if (w>0 && h>0) {
- desktop->setWindowSize(w, h);
- }
- if (x>0 && y>0) {
- desktop->setWindowPosition(Geom::Point(x, y));
- }
+ if (nv->window_maximized) {
+ Gtk::Window *win = desktop->getToplevel();
+ if (win){
+ win->maximize();
+ }
+ } else {
+ gint w = MIN(gdk_screen_width(), nv->window_width);
+ gint h = MIN(gdk_screen_height(), nv->window_height);
+ // prevent the window from moving off the screen to the right or to the bottom
+ gint x = MIN(gdk_screen_width() - MIN_ONSCREEN_DISTANCE, nv->window_x);
+ gint y = MIN(gdk_screen_height() - MIN_ONSCREEN_DISTANCE, nv->window_y);
+ // prevent the window from moving off the screen to the left or to the top
+ x = MAX(MIN_ONSCREEN_DISTANCE - nv->window_width, x);
+ y = MAX(MIN_ONSCREEN_DISTANCE - nv->window_height, y);
+ if (w>0 && h>0) {
+ desktop->setWindowSize(w, h);
+ desktop->setWindowPosition(Geom::Point(x, y));
+ }
+ }
}
// restore zoom and view
sp_repr_set_svg_double(view, "inkscape:cy", r.midpoint()[Geom::Y]);
if (save_geometry_in_file) {
- gint w, h, x, y;
+ gint w, h, x, y;
desktop->getWindowGeometry(x, y, w, h);
sp_repr_set_int(view, "inkscape:window-width", w);
sp_repr_set_int(view, "inkscape:window-height", h);
sp_repr_set_int(view, "inkscape:window-x", x);
sp_repr_set_int(view, "inkscape:window-y", y);
+ sp_repr_set_int(view, "inkscape:window-maximized", desktop->is_maximized());
}
view->setAttribute("inkscape:current-layer", SP_OBJECT_ID(desktop->currentLayer()));
static void sp_namedview_setup_guides(SPNamedView *nv)
{
for (GSList *l = nv->guides; l != NULL; l = l->next) {
- if (nv->showguides) {
- for (GSList *v = SP_GUIDE(l->data)->views; v != NULL; v = v->next) {
- sp_canvas_item_show(SP_CANVAS_ITEM(v->data));
- }
- } else {
- for (GSList *v = SP_GUIDE(l->data)->views; v != NULL; v = v->next) {
- sp_canvas_item_hide(SP_CANVAS_ITEM(v->data));
- }
- }
+ sp_namedview_show_single_guide(SP_GUIDE(l->data), nv->showguides);
}
}
+static void sp_namedview_show_single_guide(SPGuide* guide, bool show)
+{
+ for (GSList *v = guide->views; v != NULL; v = v->next) {
+ if (show) {
+ sp_canvas_item_show(SP_CANVAS_ITEM(v->data));
+ sp_canvas_item_show(SP_CANVAS_ITEM(SP_GUIDELINE(v->data)->origin));
+ } else {
+ sp_canvas_item_hide(SP_CANVAS_ITEM(v->data));
+ sp_canvas_item_hide(SP_CANVAS_ITEM(SP_GUIDELINE(v->data)->origin));
+ }
+ }
+}
+
void sp_namedview_toggle_guides(SPDocument *doc, Inkscape::XML::Node *repr)
{
unsigned int v;
return FALSE;
}
-/* fixme: Collect all these length parsing methods and think common sane API */
-
-static gboolean sp_nv_read_length(const gchar *str, guint base, gdouble *val, const SPUnit **unit)
-{
- if (!str) {
- return FALSE;
- }
-
- gchar *u;
- gdouble v = g_ascii_strtod(str, &u);
- if (!u) {
- return FALSE;
- }
- while (isspace(*u)) {
- u += 1;
- }
-
- if (!*u) {
- /* No unit specified - keep default */
- *val = v;
- return TRUE;
- }
-
- if (base & SP_UNIT_DEVICE) {
- if (u[0] && u[1] && !isalnum(u[2]) && !strncmp(u, "px", 2)) {
- *unit = &sp_unit_get_by_id(SP_UNIT_PX);
- *val = v;
- return TRUE;
- }
- }
-
- if (base & SP_UNIT_ABSOLUTE) {
- if (!strncmp(u, "pt", 2)) {
- *unit = &sp_unit_get_by_id(SP_UNIT_PT);
- } else if (!strncmp(u, "mm", 2)) {
- *unit = &sp_unit_get_by_id(SP_UNIT_MM);
- } else if (!strncmp(u, "cm", 2)) {
- *unit = &sp_unit_get_by_id(SP_UNIT_CM);
- } else if (!strncmp(u, "m", 1)) {
- *unit = &sp_unit_get_by_id(SP_UNIT_M);
- } else if (!strncmp(u, "in", 2)) {
- *unit = &sp_unit_get_by_id(SP_UNIT_IN);
- } else {
- return FALSE;
- }
- *val = v;
- return TRUE;
- }
-
- return FALSE;
-}
-
static gboolean sp_nv_read_opacity(const gchar *str, guint32 *color)
{
if (!str) {