Code

Connector tool: pointers should be nulled after snapping
[inkscape.git] / src / document.cpp
index f137ba60dab668fc43d0dd725db569fb2786a3f7..3c9f7e5edc2a06272324aa8b422cae78914bbad3 100644 (file)
@@ -92,7 +92,7 @@ SPDocument::SPDocument() :
     base(0),
     name(0),
     priv(0), // reset in ctor
-    actionkey(0),
+    actionkey(),
     modified_id(0),
     rerouting_handler_id(0),
     profileManager(0), // deferred until after other initialization
@@ -211,7 +211,6 @@ SPDocument::~SPDocument() {
         inkscape_unref();
         keepalive = FALSE;
     }
-
     //delete this->_whiteboard_session_manager;
 }
 
@@ -288,7 +287,7 @@ void SPDocument::collectOrphans() {
 
 void SPDocument::reset_key (void */*dummy*/)
 {
-    actionkey = NULL;
+    actionkey.clear();
 }
 
 SPDocument *
@@ -662,6 +661,7 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins)
     double const w = rect.width();
     double const h = rect.height();
 
+    double const old_height = sp_document_height(this);
     SPUnit const &px(sp_unit_get_by_id(SP_UNIT_PX));
     
     /* in px */
@@ -681,7 +681,7 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins)
                 margin_units = sp_unit_get_by_abbreviation(units_abbr);
             }
             if (margin_units == NULL) {
-                margin_units = &sp_unit_get_by_id(SP_UNIT_PX);
+                margin_units = &px;
             }
             margin_top = getMarginLength(nv_repr, "fit-margin-top",
                                          margin_units, &px, w, h, false);
@@ -695,14 +695,16 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins)
     }
     
     Geom::Rect const rect_with_margins(
-            rect.min() - Geom::Point(margin_left, margin_top),
-            rect.max() + Geom::Point(margin_right, margin_bottom));
+            rect.min() - Geom::Point(margin_left, margin_bottom),
+            rect.max() + Geom::Point(margin_right, margin_top));
     
     
     sp_document_set_width(this, rect_with_margins.width(), &px);
     sp_document_set_height(this, rect_with_margins.height(), &px);
 
-    Geom::Translate const tr(-to_2geom(rect_with_margins.min()));
+    Geom::Translate const tr(
+            Geom::Point(0, old_height - rect_with_margins.height())
+            - to_2geom(rect_with_margins.min()));
     SP_GROUP(root)->translateChildItems(tr);
 
     if(nv) {
@@ -710,7 +712,7 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins)
         nv->translateGuides(tr2);
 
         // update the viewport so the drawing appears to stay where it was
-        nv->scrollAllDesktops(-tr2[0], -tr2[1], false);
+        nv->scrollAllDesktops(-tr2[0], tr2[1], false);
     }
 }