Code

Filter effects dialog:
[inkscape.git] / src / conn-avoid-ref.cpp
index d90eca49b1ac20c5e1007517557295736e4bf043..864eadbbab51a52b1036dcca4f2959e5970da4f3 100644 (file)
@@ -74,21 +74,31 @@ void SPAvoidRef::handleSettingChange(void)
     if (desktop == NULL) {
         return;
     }
+    if (sp_desktop_document(desktop) != item->document) {
+        // We don't want to go any further if the active desktop's document
+        // isn't the same as the document that this item is part of.  This
+        // case can happen if a new document is loaded from the file chooser
+        // or via the recent file menu.  In this case, we can end up here
+        // as a rersult of a sp_document_ensure_up_to_date performed on a
+        // document not yet attached to the active desktop.
+        return;
+    }
 
-    Router *router = item->document->router;
-    
     if (new_setting == setting) {
         // Don't need to make any changes
         return;
     }
+    setting = new_setting;
 
+    Router *router = item->document->router;
+    
     _transformed_connection.disconnect();
     if (new_setting) {
-        _transformed_connection = item->connectTransformed(
-                sigc::ptr_fun(&avoid_item_move));
-
         Avoid::Polygn poly = avoid_item_poly(item);
         if (poly.pn > 0) {
+            _transformed_connection = item->connectTransformed(
+                    sigc::ptr_fun(&avoid_item_move));
+
             const char *id = SP_OBJECT_REPR(item)->attribute("id");
             g_assert(id != NULL);
             
@@ -110,7 +120,6 @@ void SPAvoidRef::handleSettingChange(void)
         router->delShape(shapeRef);
         shapeRef = NULL;
     }
-    setting = new_setting;
 }
 
 
@@ -177,18 +186,20 @@ static Avoid::Polygn avoid_item_poly(SPItem const *item)
     //       some convex hull code, though not NR::ConvexHull as this
     //       only keeps the bounding box of the convex hull currently.
 
-    // TODO: SPItem::invokeBbox gives the wrong result for some objects
+    // TODO: SPItem::getBounds gives the wrong result for some objects
     //       that have internal representations that are updated later
     //       by the sp_*_update functions, e.g., text.
     sp_document_ensure_up_to_date(item->document);
     
-    NR::Rect rHull = item->invokeBbox(sp_item_i2doc_affine(item));
-
+    NR::Maybe<NR::Rect> rHull = item->getBounds(sp_item_i2doc_affine(item));
+    if (!rHull) {
+        return Avoid::newPoly(0);
+    }
 
     double spacing = desktop->namedview->connector_spacing;
 
     // Add a little buffer around the edge of each object.
-    NR::Rect rExpandedHull = NR::expand(rHull, -spacing); 
+    NR::Rect rExpandedHull = NR::expand(*rHull, -spacing); 
     poly = Avoid::newPoly(4);
 
     for (unsigned n = 0; n < 4; ++n) {
@@ -264,8 +275,8 @@ void init_avoided_shape_geometry(SPDesktop *desktop)
     // Don't count this as changes to the document,
     // it is basically just llate initialisation.
     SPDocument *document = sp_desktop_document(desktop);
-    gboolean saved = sp_document_get_undo_sensitive(document);
-    sp_document_set_undo_sensitive(document, FALSE);
+    bool saved = sp_document_get_undo_sensitive(document);
+    sp_document_set_undo_sensitive(document, false);
     
     bool initialised = false;
     GSList *items = get_avoided_items(NULL, desktop->currentRoot(), desktop,