[dia] Give DiaContext* to more save functions



commit 058ee6e00b5513380a139f4a27f92c5317548d5f
Author: Hans Breuer <hans breuer org>
Date:   Sun Jan 5 21:46:06 2014 +0100

    Give DiaContext* to more save functions
    
    Should introduce no functional change. For object functions the previous
    filename parameter is replaced by DiaContext *ctx. The few functions
    using the filename got ported to use dia_context_get_filename()

 app/app_procs.c                           |   40 +++++++++------
 app/display.c                             |    9 ++-
 app/filedlg.c                             |   18 +++++--
 app/load_save.c                           |   59 +++++++++++++---------
 app/load_save.h                           |    2 +-
 lib/bezier_conn.c                         |    5 +-
 lib/bezier_conn.h                         |    2 +-
 lib/beziershape.c                         |    5 +-
 lib/beziershape.h                         |    2 +-
 lib/connection.c                          |    4 +-
 lib/connection.h                          |    2 +-
 lib/diacontext.c                          |   16 ++++++
 lib/diacontext.h                          |    1 +
 lib/diarenderer.c                         |   75 ++++++++++++++++++++++++++++-
 lib/element.c                             |    4 +-
 lib/element.h                             |    2 +-
 lib/libdia.def                            |    1 +
 lib/object-alias.c                        |    6 +-
 lib/object.c                              |    6 +-
 lib/object.h                              |   10 ++--
 lib/object_defaults.c                     |    8 ++-
 lib/orth_conn.c                           |    4 +-
 lib/orth_conn.h                           |    2 +-
 lib/poly_conn.c                           |    4 +-
 lib/poly_conn.h                           |    2 +-
 lib/polyshape.c                           |    4 +-
 lib/polyshape.h                           |    2 +-
 lib/propobject.c                          |    2 +-
 objects/AADL/aadl.h                       |    2 +-
 objects/AADL/aadlbox.c                    |    6 +-
 objects/Database/compound.c               |    6 +-
 objects/Database/table.c                  |    6 +-
 objects/ER/attribute.c                    |    6 +-
 objects/ER/entity.c                       |    6 +-
 objects/ER/participation.c                |    6 +-
 objects/ER/relationship.c                 |    6 +-
 objects/FS/flow-ortho.c                   |    6 +-
 objects/FS/flow.c                         |    6 +-
 objects/FS/function.c                     |    6 +-
 objects/Misc/diagram_as_object.c          |    8 ++--
 objects/Misc/tree.c                       |    6 +-
 objects/UML/class.c                       |    6 +-
 objects/custom_lines/custom_linetypes.c   |    8 ++--
 objects/flowchart/box.c                   |    6 +-
 objects/flowchart/diamond.c               |    6 +-
 objects/flowchart/ellipse.c               |    6 +-
 objects/flowchart/parallelogram.c         |    6 +-
 objects/network/bus.c                     |    6 +-
 objects/network/wanlink.c                 |    8 ++--
 objects/standard/arc.c                    |    6 +-
 objects/standard/bezier.c                 |    6 +-
 objects/standard/beziergon.c              |    6 +-
 objects/standard/box.c                    |    6 +-
 objects/standard/ellipse.c                |    6 +-
 objects/standard/image.c                  |   13 ++---
 objects/standard/line.c                   |    6 +-
 objects/standard/polygon.c                |    6 +-
 objects/standard/polyline.c               |    6 +-
 objects/standard/textobj.c                |    6 +-
 objects/standard/zigzagline.c             |    6 +-
 plug-ins/drs/dia-render-script-renderer.c |    6 ++-
 plug-ins/drs/dia-render-script-renderer.h |    2 +
 plug-ins/drs/dia-render-script.c          |    2 +
 plug-ins/python/pydia-diagram.c           |   10 ++++-
 64 files changed, 326 insertions(+), 192 deletions(-)
---
diff --git a/app/app_procs.c b/app/app_procs.c
index 7fb5d97..d481b8c 100644
--- a/app/app_procs.c
+++ b/app/app_procs.c
@@ -1067,21 +1067,26 @@ app_exit(void)
       }
       else if (result == EXIT_DIALOG_EXIT_SAVE_SELECTED)
       {
+           DiaContext *ctx = dia_context_new(_("Save"));
         int i;
-        for (i = 0 ; i < items->array_size ; i++)
-        {
-          gchar *filename;
-
-          diagram  = items->array[i].data;
-          filename = g_filename_from_utf8 (diagram->filename, -1, NULL, NULL, NULL);
-          diagram_update_extents (diagram);
-          if (!diagram_save (diagram, filename)) {
-            exit_dialog_free_items (items);
-            return FALSE;
-             }
-          g_free (filename);
-        }
-        exit_dialog_free_items (items);
+        for (i = 0 ; i < items->array_size ; i++) {
+         gchar *filename;
+
+         diagram  = items->array[i].data;
+         filename = g_filename_from_utf8 (diagram->filename, -1, NULL, NULL, NULL);
+         diagram_update_extents (diagram);
+         dia_context_set_filename (ctx, filename);
+         if (!diagram_save (diagram, filename, ctx)) {
+           exit_dialog_free_items (items);
+           dia_context_release (ctx);
+           return FALSE;
+         } else {
+           dia_context_reset (ctx);
+         }
+         g_free (filename);
+       }
+       dia_context_release (ctx);
+       exit_dialog_free_items (items);
       } 
       else if (result == EXIT_DIALOG_EXIT_NO_SAVE) 
       {
@@ -1138,9 +1143,12 @@ app_exit(void)
   persistence_save();
 
   dynobj_refresh_finish();
-    
-  dia_object_defaults_save (NULL);
 
+  {
+    DiaContext *ctx = dia_context_new (_("Exit"));
+    dia_object_defaults_save (NULL, ctx);
+    dia_context_release (ctx);
+  }
   /* Free loads of stuff (toolbox) */
 
   list = dia_open_diagrams();
diff --git a/app/display.c b/app/display.c
index 9aec368..9d60d96 100644
--- a/app/display.c
+++ b/app/display.c
@@ -1285,9 +1285,12 @@ are_you_sure_close_dialog_respond(GtkWidget *widget, /* the dialog */
         ddisp_destroy (ddisp);
       /* no way back */
       return;
-    } else if (!diagram_save(ddisp->diagram, ddisp->diagram->filename))
-      close_ddisp = FALSE;
-
+    } else {
+      DiaContext *ctx = dia_context_new (_("Save"));
+      if (!diagram_save(ddisp->diagram, ddisp->diagram->filename, ctx))
+        close_ddisp = FALSE;
+      dia_context_release (ctx);
+    }
     if (close_ddisp) /* saving succeeded */
       recent_file_history_add(ddisp->diagram->filename);
 
diff --git a/app/filedlg.c b/app/filedlg.c
index 6df3a96..e421941 100644
--- a/app/filedlg.c
+++ b/app/filedlg.c
@@ -421,10 +421,14 @@ file_save_as_response_callback(GtkWidget *fs,
 
     diagram_update_extents(dia);
 
-    diagram_set_filename(dia, filename);
-    if (diagram_save(dia, filename))
-      recent_file_history_add(filename);
-
+    {
+      DiaContext *ctx = dia_context_new (_("Save as"));
+      diagram_set_filename(dia, filename);
+      dia_context_set_filename (ctx, filename);
+      if (diagram_save(dia, filename, ctx))
+       recent_file_history_add(filename);
+      dia_context_release (ctx);
+    }
     g_free (filename);
   }
   /* if we have our own reference, drop it before destroy */
@@ -575,10 +579,12 @@ file_save_callback(GtkAction *action)
     file_save_as_callback(action);
   } else {
     gchar *filename = g_filename_from_utf8(diagram->filename, -1, NULL, NULL, NULL);
+    DiaContext *ctx = dia_context_new (_("Save"));
     diagram_update_extents(diagram);
-    if (diagram_save(diagram, filename))
+    if (diagram_save(diagram, filename, ctx))
       recent_file_history_add(filename);
     g_free (filename);
+    dia_context_release (ctx);
   }
 }
 
@@ -735,7 +741,7 @@ file_export_response_callback(GtkWidget *fs,
     if (!ef)
       ef = filter_guess_export_filter(filename);
     if (ef) {
-      DiaContext *ctx = dia_context_new ("file-export");
+      DiaContext *ctx = dia_context_new (_("Export"));
 
       g_object_ref(dia->data);
       dia_context_set_filename (ctx, filename);
diff --git a/app/load_save.c b/app/load_save.c
index e3a6a2f..d105afe 100644
--- a/app/load_save.c
+++ b/app/load_save.c
@@ -77,11 +77,11 @@ static gboolean diagram_data_load(const gchar *filename, DiagramData *data,
                                  DiaContext *ctx, void* user_data);
 static gboolean write_objects(GList *objects, xmlNodePtr objects_node,
                              GHashTable *objects_hash, int *obj_nr, 
-                             const char *filename);
+                             const char *filename, DiaContext *ctx);
 static gboolean write_connections(GList *objects, xmlNodePtr layer_node,
                                  GHashTable *objects_hash);
-static xmlDocPtr diagram_data_write_doc(DiagramData *data, const char *filename);
-static int diagram_data_raw_save(DiagramData *data, const char *filename);
+static xmlDocPtr diagram_data_write_doc(DiagramData *data, const char *filename, DiaContext *ctx);
+static int diagram_data_raw_save(DiagramData *data, const char *filename, DiaContext *ctx);
 static gboolean diagram_data_save(DiagramData *data, DiaContext *ctx, const char *filename);
 
 
@@ -695,7 +695,8 @@ diagram_data_load(const gchar *filename, DiagramData *data, DiaContext *ctx, voi
 
 static gboolean
 write_objects(GList *objects, xmlNodePtr objects_node,
-             GHashTable *objects_hash, int *obj_nr, const char *filename)
+             GHashTable *objects_hash, int *obj_nr,
+             const char *filename, DiaContext *ctx)
 {
   char buffer[31];
   ObjectNode obj_node;
@@ -714,9 +715,9 @@ write_objects(GList *objects, xmlNodePtr objects_node,
 
     if (IS_GROUP(obj) && group_objects(obj) != NULL) {
       group_node = xmlNewChild(objects_node, NULL, (const xmlChar *)"group", NULL);
-      object_save_props (obj, group_node);
+      object_save_props (obj, group_node, ctx);
       write_objects(group_objects(obj), group_node,
-                   objects_hash, obj_nr, filename);
+                   objects_hash, obj_nr, filename, ctx);
     } else {
       obj_node = xmlNewChild(objects_node, NULL, (const xmlChar *)"object", NULL);
     
@@ -727,7 +728,7 @@ write_objects(GList *objects, xmlNodePtr objects_node,
       g_snprintf(buffer, 30, "O%d", *obj_nr);
       xmlSetProp(obj_node, (const xmlChar *)"id", (xmlChar *)buffer);
 
-      (*obj->type->ops->save)(obj, obj_node, filename);
+      (*obj->type->ops->save)(obj, obj_node, ctx);
 
       /* Add object -> obj_nr to hash table */
       g_hash_table_insert(objects_hash, obj, GINT_TO_POINTER(*obj_nr));
@@ -837,7 +838,7 @@ write_connections(GList *objects, xmlNodePtr layer_node,
 
 /* Filename seems to be junk, but is passed on to objects */
 static xmlDocPtr
-diagram_data_write_doc(DiagramData *data, const char *filename)
+diagram_data_write_doc(DiagramData *data, const char *filename, DiaContext *ctx)
 {
   xmlDocPtr doc;
   xmlNodePtr tree;
@@ -961,7 +962,7 @@ diagram_data_write_doc(DiagramData *data, const char *filename)
       xmlSetProp(layer_node, (const xmlChar *)"active", (const xmlChar *)"true");
       
     write_objects(layer->objects, layer_node,
-                 objects_hash, &obj_nr, filename);
+                 objects_hash, &obj_nr, filename, ctx);
   
     res = write_connections(layer->objects, layer_node, objects_hash);
     /* Why do we bail out like this?  It leaks! */
@@ -982,12 +983,12 @@ diagram_data_write_doc(DiagramData *data, const char *filename)
  * Returns >= 0 on success.
  * Only for internal use. */
 static int
-diagram_data_raw_save(DiagramData *data, const char *filename)
+diagram_data_raw_save(DiagramData *data, const char *filename, DiaContext *ctx)
 {
   xmlDocPtr doc;
   int ret;
 
-  doc = diagram_data_write_doc(data, filename);
+  doc = diagram_data_write_doc(data, filename, ctx);
 
   ret = xmlDiaSaveFile (filename, doc);
   xmlFreeDoc(doc);
@@ -1078,7 +1079,7 @@ diagram_data_save(DiagramData *data, DiaContext *ctx, const char *user_filename)
   }
   fclose(file);
 
-  ret = diagram_data_raw_save(data, tmpname);
+  ret = diagram_data_raw_save(data, tmpname, ctx);
 
   if (ret < 0) {
     /* Save failed; we clean our stuff up, without touching the file named
@@ -1108,9 +1109,8 @@ CLEANUP:
 }
 
 int
-diagram_save(Diagram *dia, const char *filename)
+diagram_save(Diagram *dia, const char *filename, DiaContext *ctx)
 {
-  DiaContext *ctx = dia_context_new (_("Diagram Save"));
   gboolean res = FALSE;
 
   if (diagram_data_save(dia->data, ctx, filename)) {
@@ -1122,7 +1122,6 @@ diagram_save(Diagram *dia, const char *filename)
 
     res = TRUE;
   }
-  dia_context_release (ctx);
 
   return res;
 }
@@ -1151,6 +1150,7 @@ diagram_cleanup_autosave(Diagram *dia)
 typedef struct {
   DiagramData *clone;
   gchar       *filename;
+  DiaContext  *ctx;
 } AutoSaveInfo;
 /*!
  * Efficient and easy to implement autosave in a thread:
@@ -1170,9 +1170,13 @@ _autosave_in_thread (gpointer data)
 {
   AutoSaveInfo *asi = (AutoSaveInfo *)data;
 
-  diagram_data_raw_save(asi->clone, asi->filename);
+  diagram_data_raw_save(asi->clone, asi->filename, asi->ctx);
   g_object_unref (asi->clone);
   g_free (asi->filename);
+  /* FIXME: this is throwing away potential messages ... */
+  dia_context_reset (asi->ctx);
+  /* ... to avoid creating a message_box within this thread */
+  dia_context_release (asi->ctx);
   g_free (asi);
 
   return NULL;
@@ -1202,26 +1206,33 @@ diagram_autosave(Diagram *dia)
       dia->autosavefilename = save_filename;
 #ifdef G_THREADS_ENABLED
       if (g_thread_supported ()) {
-        AutoSaveInfo *asi = g_new (AutoSaveInfo, 1);
-        GError *error = NULL;
+       AutoSaveInfo *asi = g_new (AutoSaveInfo, 1);
+       GError *error = NULL;
 
        asi->clone = diagram_data_clone (dia->data);
        asi->filename = g_strdup (save_filename);
+       asi->ctx = dia_context_new (_("Auto save"));
 
-        if (!g_thread_create (_autosave_in_thread, asi, FALSE, &error)) {
+       if (!g_thread_create (_autosave_in_thread, asi, FALSE, &error)) {
          message_error (error->message);
          g_error_free (error);
        }
        /* FIXME: need better synchronization */
         dia->autosaved = TRUE;
       } else {
-       /* no extra threads supporte, stay in this one */
-        diagram_data_raw_save(dia->data, save_filename);
-        dia->autosaved = TRUE;
+       /* no extra threads supported, stay in this one */
+       DiaContext *ctx = dia_context_new (_("Auto save"));
+       diagram_data_raw_save(dia->data, save_filename, ctx);
+       dia->autosaved = TRUE;
+       dia_context_release (ctx);
       }
 #else
-      diagram_data_raw_save(dia->data, save_filename);
-      dia->autosaved = TRUE;
+      {
+       DiaContext *ctx = dia_context_new (_("Auto save"));
+       diagram_data_raw_save(dia->data, save_filename, ctx);
+       dia->autosaved = TRUE;
+       dia_context_release (ctx);
+      }
 #endif
       return;
     }
diff --git a/app/load_save.h b/app/load_save.h
index 570f1f2..ad5adb9 100644
--- a/app/load_save.h
+++ b/app/load_save.h
@@ -21,7 +21,7 @@
 #include "diagram.h"
 #include "filter.h"
 
-int diagram_save(Diagram *dia, const char *filename);
+int diagram_save(Diagram *dia, const char *filename, DiaContext *ctx);
 void diagram_autosave(Diagram *dia);
 void diagram_cleanup_autosave(Diagram *dia);
 
diff --git a/lib/bezier_conn.c b/lib/bezier_conn.c
index c8c4c57..cf94c66 100644
--- a/lib/bezier_conn.c
+++ b/lib/bezier_conn.c
@@ -852,12 +852,13 @@ bezierconn_destroy (BezierConn *bezier)
  */
 void
 bezierconn_save (BezierConn *bezier,
-                ObjectNode obj_node)
+                ObjectNode obj_node,
+                DiaContext *ctx)
 {
   int i;
   AttributeNode attr;
 
-  object_save(&bezier->object, obj_node);
+  object_save(&bezier->object, obj_node, ctx);
 
   attr = new_attribute(obj_node, "bez_points");
 
diff --git a/lib/bezier_conn.h b/lib/bezier_conn.h
index 5d0b9c5..628e9d9 100644
--- a/lib/bezier_conn.h
+++ b/lib/bezier_conn.h
@@ -48,7 +48,7 @@ void bezierconn_update_boundingbox(BezierConn *bez);
 void bezierconn_init(BezierConn *bez, int num_points);
 void bezierconn_destroy(BezierConn *bez);
 void bezierconn_copy(BezierConn *from, BezierConn *to);
-void bezierconn_save(BezierConn *bez, ObjectNode obj_node);
+void bezierconn_save(BezierConn *bez, ObjectNode obj_node, DiaContext *ctx);
 void bezierconn_load(BezierConn *bez, ObjectNode obj_node, DiaContext *ctx);  /* NOTE: Does object_init() */
 ObjectChange *bezierconn_add_segment(BezierConn *bez, int segment, Point *point);
 ObjectChange *bezierconn_remove_segment(BezierConn *bez, int point);
diff --git a/lib/beziershape.c b/lib/beziershape.c
index 1c5a97e..d1f0577 100644
--- a/lib/beziershape.c
+++ b/lib/beziershape.c
@@ -931,12 +931,13 @@ beziershape_destroy (BezierShape *bezier)
  */
 void
 beziershape_save (BezierShape *bezier,
-                 ObjectNode obj_node)
+                 ObjectNode obj_node,
+                 DiaContext *ctx)
 {
   int i;
   AttributeNode attr;
 
-  object_save(&bezier->object, obj_node);
+  object_save(&bezier->object, obj_node, ctx);
 
   attr = new_attribute(obj_node, "bez_points");
 
diff --git a/lib/beziershape.h b/lib/beziershape.h
index 189a960..e651d37 100644
--- a/lib/beziershape.h
+++ b/lib/beziershape.h
@@ -53,7 +53,7 @@ void beziershape_update_boundingbox(BezierShape *bezier);
 void beziershape_init(BezierShape *bezier, int num_points);
 void beziershape_destroy(BezierShape *bezier);
 void beziershape_copy(BezierShape *from, BezierShape *to);
-void beziershape_save(BezierShape *bezier, ObjectNode obj_node);
+void beziershape_save(BezierShape *bezier, ObjectNode obj_node, DiaContext *ctx);
 /* NOTE: Does object_init() */
 void beziershape_load(BezierShape *bezier, ObjectNode obj_node, DiaContext *ctx);
 ObjectChange *beziershape_add_segment(BezierShape *bezier, int segment,
diff --git a/lib/connection.c b/lib/connection.c
index 9b965ca..e3aec02 100644
--- a/lib/connection.c
+++ b/lib/connection.c
@@ -202,11 +202,11 @@ connection_destroy(Connection *conn)
  * @param obj_node The XML node to save it to.
  */
 void
-connection_save(Connection *conn, ObjectNode obj_node)
+connection_save(Connection *conn, ObjectNode obj_node, DiaContext *ctx)
 {
   AttributeNode attr;
   
-  object_save(&conn->object, obj_node);
+  object_save(&conn->object, obj_node, ctx);
 
   attr = new_attribute(obj_node, "conn_endpoints");
   data_add_point(attr, &conn->endpoints[0]);
diff --git a/lib/connection.h b/lib/connection.h
index bd8dc32..470dab4 100644
--- a/lib/connection.h
+++ b/lib/connection.h
@@ -45,7 +45,7 @@ void connection_init(Connection *conn,
                     int num_handles, int num_connections);
 void connection_destroy(Connection *conn);
 void connection_copy(Connection *from, Connection *to);
-void connection_save(Connection *conn, ObjectNode obj_node);
+void connection_save(Connection *conn, ObjectNode obj_node, DiaContext *ctx);
 void connection_load(Connection *conn, ObjectNode obj_node, DiaContext *ctx);
 ObjectChange* connection_move_handle(Connection *conn, HandleId id,
                                     Point *to, ConnectionPoint* cp,
diff --git a/lib/diacontext.c b/lib/diacontext.c
index 75d477e..60f1168 100644
--- a/lib/diacontext.c
+++ b/lib/diacontext.c
@@ -63,6 +63,7 @@ _dia_context_finalize(GObject *object)
   DiaContext *context = (DiaContext *)object;
 
   g_list_foreach (context->messages, (GFunc) g_free, NULL);
+  g_list_free (context->messages);
   g_free (context->desc);
   g_free (context->filename);
 
@@ -102,6 +103,21 @@ dia_context_release (DiaContext *context)
   g_object_unref (G_OBJECT (context));
 }
 
+/*!
+ * \brief Clean out the context for further use
+ */
+void
+dia_context_reset (DiaContext *context)
+{
+  g_list_foreach (context->messages, (GFunc) g_free, NULL);
+  g_list_free (context->messages);
+  context->messages = NULL;
+  g_free (context->desc);
+  context->desc = NULL;
+  g_free (context->filename);
+  context->filename = NULL;
+}
+
 void 
 dia_context_set_filename (DiaContext *context, 
                          const char *filename)
diff --git a/lib/diacontext.h b/lib/diacontext.h
index 50da3f9..54fc446 100644
--- a/lib/diacontext.h
+++ b/lib/diacontext.h
@@ -7,6 +7,7 @@
 G_BEGIN_DECLS
 
 DiaContext *dia_context_new (const char *desc);
+void dia_context_reset (DiaContext *context);
 void dia_context_release (DiaContext *context);
 
 void dia_context_set_filename (DiaContext *context, const char *filename);
diff --git a/lib/diarenderer.c b/lib/diarenderer.c
index 5c31c33..3428216 100644
--- a/lib/diarenderer.c
+++ b/lib/diarenderer.c
@@ -1560,12 +1560,85 @@ dia_renderer_get_height_pixels (DiaRenderer *renderer)
   return DIA_RENDERER_GET_CLASS(renderer)->get_height_pixels (renderer);
 }
 
+static Point
+_find_close_point (const BezPoint *pts, int n, const Point *p1)
+{
+  int i;
+  Point p;
+  real d = G_MAXDOUBLE;
+
+  for (i = 0; i < n; ++i) {
+    Point p2 = (pts[i].type == BEZ_CURVE_TO ? pts[i].p3 : pts[i].p1);
+    real dist = distance_point_point_manhattan (&p2, p1);
+    if (dist < d) {
+      p = p2;
+      d = dist;
+    }
+  }
+  return p;
+}
+
+void
+bezier_render_fill (DiaRenderer *renderer, BezPoint *pts, int total, Color *color)
+{
+  int i, n = 0;
+  gboolean needs_split = FALSE;
+
+  for (i = 1; i < total; ++i) {
+    if (BEZ_MOVE_TO == pts[i].type) {
+      needs_split = TRUE;
+      break;
+    }
+  }
+  if (!needs_split) {
+    DIA_RENDERER_GET_CLASS (renderer)->fill_bezier (renderer, pts, total, color);
+  } else {
+    GArray *points = g_array_new (FALSE, FALSE, sizeof(BezPoint));
+    Point close_to;
+    gboolean needs_close = FALSE;
+    /* start with move-to */
+    g_array_append_val(points, pts[0]);
+    for (i = 1; i < total; ++i) {
+      if (BEZ_MOVE_TO == pts[i].type) {
+       /* check whether the start point of the second outline is within the first outline. */
+       real dist = distance_bez_shape_point (&g_array_index (points, BezPoint, 0), points->len, 0, 
&pts[i].p1);
+       if (dist > 0) { /* outside, just create a new one? */
+         /* flush what we have */
+         if (needs_close) {
+           BezPoint bp;
+           bp.type = BEZ_LINE_TO;
+           bp.p1 = close_to;
+           g_array_append_val(points, bp);
+         }
+         DIA_RENDERER_GET_CLASS (renderer)->fill_bezier (renderer, &g_array_index(points, BezPoint, 0), 
points->len, color);
+         g_array_set_size (points, 0);
+         g_array_append_val(points, pts[i]); /* new needs move-to */
+         needs_close = FALSE;
+       } else {
+         BezPoint bp = pts[i];
+         bp.type = BEZ_LINE_TO;
+         /* just turn the move- to a line-to */
+         g_array_append_val(points, bp);
+         /* and remember the point we lined from */
+         close_to = (pts[i-1].type == BEZ_CURVE_TO ? pts[i-1].p3 : pts[i-1].p1);
+         needs_close = TRUE;
+       }
+      } else {
+        g_array_append_val(points, pts[i]);
+      }
+    }
+    if (points->len)
+      DIA_RENDERER_GET_CLASS (renderer)->fill_bezier (renderer, &g_array_index(points, BezPoint, 0), 
points->len, color);
+    g_array_free (points, TRUE);
+  }
+}
+
 /*!
  * \brief Helper function to fill bezier with multiple BEZ_MOVE_TO
  * \memberof DiaRenderer
  */
 void
-bezier_render_fill (DiaRenderer *renderer, BezPoint *pts, int total, Color *color)
+bezier_render_fill_old (DiaRenderer *renderer, BezPoint *pts, int total, Color *color)
 {
   int i, n = 0;
   /* first draw the fills */
diff --git a/lib/element.c b/lib/element.c
index 887b262..b3c4e50 100644
--- a/lib/element.c
+++ b/lib/element.c
@@ -433,9 +433,9 @@ element_destroy(Element *elem)
  * @param obj_node
  */
 void 
-element_save(Element *elem, ObjectNode obj_node)
+element_save(Element *elem, ObjectNode obj_node, DiaContext *ctx)
 {
-  object_save(&elem->object, obj_node);
+  object_save(&elem->object, obj_node, ctx);
 
   data_add_point(new_attribute(obj_node, "elem_corner"),
                 &elem->corner);
diff --git a/lib/element.h b/lib/element.h
index b527272..ac72ebe 100644
--- a/lib/element.h
+++ b/lib/element.h
@@ -64,7 +64,7 @@ ObjectChange* element_move_handle(Element *elem, HandleId id,
 void element_move_handle_aspect(Element *elem, HandleId id,
                                Point *to, real aspect_ratio);
 
-void element_save(Element *elem, ObjectNode obj_node);
+void element_save(Element *elem, ObjectNode obj_node, DiaContext *ctx);
 void element_load(Element *elem, ObjectNode obj_node, DiaContext *ctx);
 
 ObjectChange *element_change_new (const Point *corner, 
diff --git a/lib/libdia.def b/lib/libdia.def
index 1578535..60e8dc4 100644
--- a/lib/libdia.def
+++ b/lib/libdia.def
@@ -210,6 +210,7 @@ EXPORTS
  dia_context_get_filename
  dia_context_new
  dia_context_release
+ dia_context_reset
  dia_context_set_filename
 
  dia_dynamic_menu_get_type
diff --git a/lib/object-alias.c b/lib/object-alias.c
index ca05c9f..3192cf8 100644
--- a/lib/object-alias.c
+++ b/lib/object-alias.c
@@ -84,7 +84,7 @@ _alias_create (Point *startpoint,
 static DiaObject *
 _alias_load (ObjectNode obj_node, int version, const char *filename, DiaContext *ctx);
 static void
-_alias_save (DiaObject *obj, ObjectNode obj_node, const char *filename);
+_alias_save (DiaObject *obj, ObjectNode obj_node, DiaContext *ctx);
 
 static ObjectTypeOps _alias_type_ops =
 {
@@ -151,9 +151,9 @@ _alias_load (ObjectNode obj_node, int version, const char *filename, DiaContext
 }
 
 static void
-_alias_save (DiaObject *obj, ObjectNode obj_node, const char *filename)
+_alias_save (DiaObject *obj, ObjectNode obj_node, DiaContext *ctx)
 {
-  object_save_using_properties (obj, obj_node, filename);
+  object_save_using_properties (obj, obj_node, ctx);
 }
 
 void
diff --git a/lib/object.c b/lib/object.c
index f3c783c..3b623eb 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -767,7 +767,7 @@ object_unconnect_all(DiaObject *obj)
  * @param obj_node An XML node to save the data to.
  */
 void 
-object_save(DiaObject *obj, ObjectNode obj_node)
+object_save(DiaObject *obj, ObjectNode obj_node, DiaContext *ctx)
 {
   data_add_point(new_attribute(obj_node, "obj_pos"),
                 &obj->position);
@@ -1008,9 +1008,9 @@ object_load_using_properties(const DiaObjectType *type,
  */
 void 
 object_save_using_properties(DiaObject *obj, ObjectNode obj_node, 
-                             const char *filename)
+                             DiaContext *ctx)
 {
-  object_save_props(obj,obj_node);
+  object_save_props (obj, obj_node, ctx);
 }
 
 /** Copy an object based solely on its properties.
diff --git a/lib/object.h b/lib/object.h
index 01c2fbf..968305a 100644
--- a/lib/object.h
+++ b/lib/object.h
@@ -124,7 +124,7 @@ typedef DiaObject* (*LoadFunc) (ObjectNode obj_node, int version,
  * \public \memberof _DiaObjectType
  */
 typedef void (*SaveFunc) (DiaObject* obj, ObjectNode obj_node,
-                         const char *filename);
+                         DiaContext *ctx);
 
 /** Function called when the user has double clicked on an Tool. 
  *  When this function is called and the dialog already is created,
@@ -369,7 +369,7 @@ void object_destroy(DiaObject *obj); /* Unconnects handles, so don't
                                            free handles before calling. */
 void object_copy(DiaObject *from, DiaObject *to);
 
-void object_save(DiaObject *obj, ObjectNode obj_node);
+void object_save(DiaObject *obj, ObjectNode obj_node, DiaContext *ctx);
 void object_load(DiaObject *obj, ObjectNode obj_node, DiaContext *ctx);
 
 GList *object_copy_list(GList *list);
@@ -406,7 +406,7 @@ DiaObject *object_load_using_properties(const DiaObjectType *type,
                                        ObjectNode obj_node, int version,
                                        DiaContext *ctx);
 void object_save_using_properties(DiaObject *obj, ObjectNode obj_node, 
-                                  const char *filename);
+                                  DiaContext *ctx);
 DiaObject *object_copy_using_properties(DiaObject *obj);
 
 /*****************************************
@@ -576,7 +576,7 @@ DiaObject  *dia_object_default_create (const DiaObjectType *type,
                                     void *user_data,
                                     Handle **handle1,
                                     Handle **handle2);
-gboolean         dia_object_defaults_save (const gchar *filename);
+gboolean         dia_object_defaults_save (const gchar *filename, DiaContext *ctx);
 Layer           *dia_object_get_parent_layer(DiaObject *obj);
 gboolean         dia_object_is_selected (const DiaObject *obj);
 const Rectangle *dia_object_get_bounding_box(const DiaObject *obj);
@@ -594,7 +594,7 @@ int dia_object_get_num_connections (DiaObject *obj);
 
 /* standard way to load/save properties of an object */
 void          object_load_props(DiaObject *obj, ObjectNode obj_node, DiaContext *ctx);
-void          object_save_props(DiaObject *obj, ObjectNode obj_node);
+void          object_save_props(DiaObject *obj, ObjectNode obj_node, DiaContext *ctx);
 
 /* standard way to copy the properties of an object into another (of the
    same type) */
diff --git a/lib/object_defaults.c b/lib/object_defaults.c
index cd0c7c1..fd151a8 100644
--- a/lib/object_defaults.c
+++ b/lib/object_defaults.c
@@ -312,6 +312,7 @@ struct _MyRootInfo
   GHashTable *layer_hash;
   xmlNs      *name_space;
   gint        obj_nr;
+  DiaContext *ctx;
 };
 
 static void
@@ -373,7 +374,7 @@ _obj_store (gpointer key,
 
   obj->ops->move (obj,&(li->pos));
   /* saving every property of the object */
-  obj->type->ops->save (obj, obj_node, ri->filename);
+  obj->type->ops->save (obj, obj_node, ri->ctx);
 
   /* arrange following objects below */
   li->pos.y += (obj->bounding_box.bottom - obj->bounding_box.top + 1.0); 
@@ -387,7 +388,7 @@ _obj_store (gpointer key,
  * separate invisible layers.
  */
 gboolean
-dia_object_defaults_save (const gchar *filename)
+dia_object_defaults_save (const gchar *filename, DiaContext *ctx)
 {
   MyRootInfo ni;
   xmlDocPtr doc;
@@ -410,7 +411,8 @@ dia_object_defaults_save (const gchar *filename)
 
   ni.obj_nr = 0;
   ni.node = doc->xmlRootNode;
-  ni.filename = real_filename;  
+  ni.filename = real_filename;
+  ni.ctx = ctx;
   ni.layer_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
                                          g_free, g_free);
 
diff --git a/lib/orth_conn.c b/lib/orth_conn.c
index 69df550..7239964 100644
--- a/lib/orth_conn.c
+++ b/lib/orth_conn.c
@@ -608,7 +608,7 @@ place_handle_by_swapping(OrthConn *orth, int index, Handle *handle)
 }
 
 void
-orthconn_save(OrthConn *orth, ObjectNode obj_node)
+orthconn_save(OrthConn *orth, ObjectNode obj_node, DiaContext *ctx)
 {
   int i;
   AttributeNode attr;
@@ -617,7 +617,7 @@ orthconn_save(OrthConn *orth, ObjectNode obj_node)
   place_handle_by_swapping(orth, 0, orth->handles[0]);
   place_handle_by_swapping(orth, 1, orth->handles[orth->numpoints-2]);
   
-  object_save(&orth->object, obj_node);
+  object_save(&orth->object, obj_node, ctx);
 
   attr = new_attribute(obj_node, "orth_points");
   
diff --git a/lib/orth_conn.h b/lib/orth_conn.h
index 50b1657..b901197 100644
--- a/lib/orth_conn.h
+++ b/lib/orth_conn.h
@@ -69,7 +69,7 @@ void orthconn_init(OrthConn *orth, Point *startpoint);
 void orthconn_destroy(OrthConn *orth);
 void orthconn_set_points(OrthConn *orth, int num_points, Point *points);
 void orthconn_copy(OrthConn *from, OrthConn *to);
-void orthconn_save(OrthConn *orth, ObjectNode obj_node);
+void orthconn_save(OrthConn *orth, ObjectNode obj_node, DiaContext *ctx);
 void orthconn_load(OrthConn *orth, ObjectNode obj_node, DiaContext *ctx);  /* NOTE: Does object_init() */
 ObjectChange* orthconn_move_handle(OrthConn *orth, Handle *id,
                                   Point *to, ConnectionPoint *cp,
diff --git a/lib/poly_conn.c b/lib/poly_conn.c
index 35f0962..a895985 100644
--- a/lib/poly_conn.c
+++ b/lib/poly_conn.c
@@ -419,12 +419,12 @@ polyconn_destroy(PolyConn *poly)
 
 
 void
-polyconn_save(PolyConn *poly, ObjectNode obj_node)
+polyconn_save(PolyConn *poly, ObjectNode obj_node, DiaContext *ctx)
 {
   int i;
   AttributeNode attr;
 
-  object_save(&poly->object, obj_node);
+  object_save(&poly->object, obj_node, ctx);
 
   attr = new_attribute(obj_node, "poly_points");
   
diff --git a/lib/poly_conn.h b/lib/poly_conn.h
index f470021..86c7981 100644
--- a/lib/poly_conn.h
+++ b/lib/poly_conn.h
@@ -49,7 +49,7 @@ void polyconn_init(PolyConn *poly, int num_points);
 void polyconn_set_points(PolyConn *poly, int num_points, Point *points);
 void polyconn_destroy(PolyConn *poly);
 void polyconn_copy(PolyConn *from, PolyConn *to);
-void polyconn_save(PolyConn *poly, ObjectNode obj_node);
+void polyconn_save(PolyConn *poly, ObjectNode obj_node, DiaContext *ctx);
 void polyconn_load(PolyConn *poly, ObjectNode obj_node, DiaContext *ctx);  /* NOTE: Does object_init() */
 ObjectChange *polyconn_add_point(PolyConn *poly, int segment, Point *point);
 ObjectChange *polyconn_remove_point(PolyConn *poly, int point);
diff --git a/lib/polyshape.c b/lib/polyshape.c
index 5556f3c..9ab9743 100644
--- a/lib/polyshape.c
+++ b/lib/polyshape.c
@@ -491,12 +491,12 @@ polyshape_destroy(PolyShape *poly)
 
 
 void
-polyshape_save(PolyShape *poly, ObjectNode obj_node)
+polyshape_save(PolyShape *poly, ObjectNode obj_node, DiaContext *ctx)
 {
   int i;
   AttributeNode attr;
 
-  object_save(&poly->object, obj_node);
+  object_save(&poly->object, obj_node, ctx);
 
   attr = new_attribute(obj_node, "poly_points");
   
diff --git a/lib/polyshape.h b/lib/polyshape.h
index 9008022..395800c 100644
--- a/lib/polyshape.h
+++ b/lib/polyshape.h
@@ -48,7 +48,7 @@ void polyshape_init(PolyShape *poly, int num_points);
 void polyshape_set_points(PolyShape *poly, int num_points, Point *points);
 void polyshape_destroy(PolyShape *poly);
 void polyshape_copy(PolyShape *from, PolyShape *to);
-void polyshape_save(PolyShape *poly, ObjectNode obj_node);
+void polyshape_save(PolyShape *poly, ObjectNode obj_node, DiaContext *ctx);
 void polyshape_load(PolyShape *poly, ObjectNode obj_node, DiaContext *ctx);  /* NOTE: Does object_init() */
 ObjectChange *polyshape_add_point(PolyShape *poly, int segment, Point *point);
 ObjectChange *polyshape_remove_point(PolyShape *poly, int point);
diff --git a/lib/propobject.c b/lib/propobject.c
index 6b4b9ee..6e0fb7a 100644
--- a/lib/propobject.c
+++ b/lib/propobject.c
@@ -350,7 +350,7 @@ object_load_props(DiaObject *obj, ObjectNode obj_node, DiaContext *ctx)
 }
 
 void
-object_save_props(DiaObject *obj, ObjectNode obj_node)
+object_save_props(DiaObject *obj, ObjectNode obj_node, DiaContext *ctx)
 {
   GPtrArray *props;
 
diff --git a/objects/AADL/aadl.h b/objects/AADL/aadl.h
index a9e9a36..9050599 100755
--- a/objects/AADL/aadl.h
+++ b/objects/AADL/aadl.h
@@ -194,7 +194,7 @@ void aadlbox_get_props(Aadlbox *aadlbox, GPtrArray *props);
 void aadlbox_set_props(Aadlbox *aadlbox, GPtrArray *props);
 DiaObject *aadlbox_copy(DiaObject *obj);
 DiaMenu * aadlbox_get_object_menu(Aadlbox *aadlbox, Point *clickedpoint);
-void aadlbox_save(Aadlbox *aadlbox, ObjectNode obj_node, const char *filename);
+void aadlbox_save(Aadlbox *aadlbox, ObjectNode obj_node, DiaContext *ctx);
 void aadlbox_load(ObjectNode obj_node, int version, DiaContext *ctx,
                        Aadlbox *aadlbox);
 
diff --git a/objects/AADL/aadlbox.c b/objects/AADL/aadlbox.c
index 583ac25..bc6615e 100755
--- a/objects/AADL/aadlbox.c
+++ b/objects/AADL/aadlbox.c
@@ -918,14 +918,14 @@ aadlbox_destroy(Aadlbox *aadlbox)
 }
 
 void
-aadlbox_save(Aadlbox *aadlbox, ObjectNode obj_node, const char *filename)
+aadlbox_save(Aadlbox *aadlbox, ObjectNode obj_node, DiaContext *ctx)
 {
   int i;
   AttributeNode attr;
   DataNode composite;
     
-  element_save(&aadlbox->element, obj_node);
-  object_save_props(&aadlbox->element.object,obj_node);
+  element_save(&aadlbox->element, obj_node, ctx);
+  object_save_props(&aadlbox->element.object, obj_node, ctx);
 
   attr = new_attribute(obj_node, "aadlbox_ports");
   
diff --git a/objects/Database/compound.c b/objects/Database/compound.c
index 82838ab..45312d2 100644
--- a/objects/Database/compound.c
+++ b/objects/Database/compound.c
@@ -114,7 +114,7 @@ mount_point_move_change_free (MountPointMoveChange *);
 
 static DiaObject * compound_create (Point *, void *, Handle **, Handle **);
 static DiaObject * compound_load (ObjectNode obj_node, int version,DiaContext *ctx);
-static void compound_save (Compound *, ObjectNode, const char *);
+static void compound_save (Compound *, ObjectNode, DiaContext *ctx);
 static void compound_destroy (Compound *);
 static void compound_draw (Compound *, DiaRenderer *);
 static real compound_distance_from (Compound *, Point *);
@@ -493,7 +493,7 @@ compound_load (ObjectNode obj_node, int version, DiaContext *ctx)
 }
 
 static void
-compound_save (Compound *comp, ObjectNode obj_node, const char * filename)
+compound_save (Compound *comp, ObjectNode obj_node, DiaContext *ctx)
 {
   gint i;
   AttributeNode attr;
@@ -501,7 +501,7 @@ compound_save (Compound *comp, ObjectNode obj_node, const char * filename)
 
   compound_sanity_check (comp, "Saving");
 
-  object_save (&comp->object, obj_node);
+  object_save (&comp->object, obj_node, ctx);
 
   attr = new_attribute(obj_node, "comp_points");
   for (i = 0; i < obj->num_handles; i++)
diff --git a/objects/Database/table.c b/objects/Database/table.c
index 21e508a..3d19f49 100644
--- a/objects/Database/table.c
+++ b/objects/Database/table.c
@@ -56,7 +56,7 @@ static real         table_calculate_namebox_data (Table *);
 static real         table_init_attributesbox_height (Table *);
 static DiaObject *  table_create (Point *, void *, Handle **, Handle **);
 static DiaObject *  table_load (ObjectNode obj_node, int version, DiaContext *ctx);
-static void         table_save (Table *, ObjectNode, const char *);
+static void         table_save (Table *, ObjectNode, DiaContext *ctx);
 static void         table_destroy (Table *);
 static real         table_distance_from (Table *, Point *);
 static void         table_select (Table *, Point *, DiaRenderer *);
@@ -474,9 +474,9 @@ table_load (ObjectNode obj_node, int version, DiaContext *ctx)
 }
 
 static void
-table_save (Table *table, ObjectNode obj_node, const char *filename)
+table_save (Table *table, ObjectNode obj_node, DiaContext *ctx)
 {
-  object_save_props (&table->element.object, obj_node);
+  object_save_props (&table->element.object, obj_node, ctx);
 }
 
 static void
diff --git a/objects/ER/attribute.c b/objects/ER/attribute.c
index a568106..d043617 100644
--- a/objects/ER/attribute.c
+++ b/objects/ER/attribute.c
@@ -108,7 +108,7 @@ static void
 attribute_set_props(Attribute *attribute, GPtrArray *props);
 
 static void attribute_save(Attribute *attribute, ObjectNode obj_node,
-                          const char *filename);
+                          DiaContext *ctx);
 static DiaObject *attribute_load(ObjectNode obj_node, int version,DiaContext *ctx);
 
 static ObjectTypeOps attribute_type_ops =
@@ -498,9 +498,9 @@ attribute_copy(Attribute *attribute)
 
 static void
 attribute_save(Attribute *attribute, ObjectNode obj_node,
-              const char *filename)
+              DiaContext *ctx)
 {
-  element_save(&attribute->element, obj_node);
+  element_save(&attribute->element, obj_node, ctx);
 
   data_add_real(new_attribute(obj_node, "border_width"),
                attribute->border_width);
diff --git a/objects/ER/entity.c b/objects/ER/entity.c
index 3c664f3..daf67f6 100644
--- a/objects/ER/entity.c
+++ b/objects/ER/entity.c
@@ -90,7 +90,7 @@ static void entity_get_props(Entity *entity, GPtrArray *props);
 static void entity_set_props(Entity *entity, GPtrArray *props);
 
 static void entity_save(Entity *entity, ObjectNode obj_node,
-                       const char *filename);
+                       DiaContext *ctx);
 static DiaObject *entity_load(ObjectNode obj_node, int version,DiaContext *ctx);
 
 static ObjectTypeOps entity_type_ops =
@@ -472,9 +472,9 @@ entity_copy(Entity *entity)
 }
 
 static void
-entity_save(Entity *entity, ObjectNode obj_node, const char *filename)
+entity_save(Entity *entity, ObjectNode obj_node, DiaContext *ctx)
 {
-  element_save(&entity->element, obj_node);
+  element_save(&entity->element, obj_node, ctx);
 
   data_add_real(new_attribute(obj_node, "border_width"),
                entity->border_width);
diff --git a/objects/ER/participation.c b/objects/ER/participation.c
index 39a4e80..b2d99e2 100644
--- a/objects/ER/participation.c
+++ b/objects/ER/participation.c
@@ -64,7 +64,7 @@ static DiaObject *participation_create(Point *startpoint,
                                 Handle **handle2);
 static DiaObject *participation_copy(Participation *dep);
 static void participation_save(Participation *dep, ObjectNode obj_node,
-                              const char *filename);
+                              DiaContext *ctx);
 static DiaObject *participation_load(ObjectNode obj_node, int version,DiaContext *ctx);
 static void participation_update_data(Participation *dep);
 static PropDescription *
@@ -347,9 +347,9 @@ participation_copy(Participation *participation)
 
 static void
 participation_save(Participation *participation, ObjectNode obj_node,
-                  const char *filename)
+                  DiaContext *ctx)
 {
-  orthconn_save(&participation->orth, obj_node);
+  orthconn_save(&participation->orth, obj_node, ctx);
 
   data_add_boolean(new_attribute(obj_node, "total"),
                   participation->total);
diff --git a/objects/ER/relationship.c b/objects/ER/relationship.c
index 2555df4..8901045 100644
--- a/objects/ER/relationship.c
+++ b/objects/ER/relationship.c
@@ -89,7 +89,7 @@ static void relationship_destroy(Relationship *relationship);
 static DiaObject *relationship_copy(Relationship *relationship);
 
 static void relationship_save(Relationship *relationship,
-                             ObjectNode obj_node, const char *filename);
+                             ObjectNode obj_node, DiaContext *ctx);
 static DiaObject *relationship_load(ObjectNode obj_node, int version,DiaContext *ctx);
 static PropDescription *
 relationship_describe_props(Relationship *relationship);
@@ -526,9 +526,9 @@ relationship_copy(Relationship *relationship)
 
 static void
 relationship_save(Relationship *relationship, ObjectNode obj_node,
-                 const char *filename)
+                 DiaContext *ctx)
 {
-  element_save(&relationship->element, obj_node);
+  element_save(&relationship->element, obj_node, ctx);
 
   data_add_real(new_attribute(obj_node, "border_width"),
                relationship->border_width);
diff --git a/objects/FS/flow-ortho.c b/objects/FS/flow-ortho.c
index fbc45f4..c537548 100644
--- a/objects/FS/flow-ortho.c
+++ b/objects/FS/flow-ortho.c
@@ -112,7 +112,7 @@ orthflow_get_props(Orthflow * orthflow, GPtrArray *props);
 static void
 orthflow_set_props(Orthflow * orthflow, GPtrArray *props);
 static void orthflow_save(Orthflow *orthflow, ObjectNode obj_node,
-                         const char *filename);
+                         DiaContext *ctx);
 static DiaObject *orthflow_load(ObjectNode obj_node, int version,DiaContext *ctx);
 static DiaMenu *orthflow_get_object_menu(Orthflow *orthflow, Point *clickedpoint) ;
 
@@ -534,9 +534,9 @@ orthflow_update_data(Orthflow *orthflow)
 
 
 static void
-orthflow_save(Orthflow *orthflow, ObjectNode obj_node, const char *filename)
+orthflow_save(Orthflow *orthflow, ObjectNode obj_node, DiaContext *ctx)
 {
-  orthconn_save(&orthflow->orth, obj_node);
+  orthconn_save(&orthflow->orth, obj_node, ctx);
 
   data_add_text(new_attribute(obj_node, "text"),
                orthflow->text) ;
diff --git a/objects/FS/flow.c b/objects/FS/flow.c
index bdbdb7d..3d5ae92 100644
--- a/objects/FS/flow.c
+++ b/objects/FS/flow.c
@@ -86,7 +86,7 @@ static void flow_update_data(Flow *flow);
 static void flow_destroy(Flow *flow);
 static DiaObject *flow_copy(Flow *flow);
 static void flow_save(Flow *flow, ObjectNode obj_node,
-                     const char *filename);
+                     DiaContext *ctx);
 static DiaObject *flow_load(ObjectNode obj_node, int version,DiaContext *ctx);
 static PropDescription *flow_describe_props(Flow *mes);
 static void
@@ -501,9 +501,9 @@ flow_update_data(Flow *flow)
 
 
 static void
-flow_save(Flow *flow, ObjectNode obj_node, const char *filename)
+flow_save(Flow *flow, ObjectNode obj_node, DiaContext *ctx)
 {
-  connection_save(&flow->connection, obj_node);
+  connection_save(&flow->connection, obj_node, ctx);
 
   data_add_text(new_attribute(obj_node, "text"),
                flow->text) ;
diff --git a/objects/FS/function.c b/objects/FS/function.c
index 00accd8..95155a0 100644
--- a/objects/FS/function.c
+++ b/objects/FS/function.c
@@ -92,7 +92,7 @@ static DiaObject *function_create(Point *startpoint,
 static void function_destroy(Function *pkg);
 static DiaObject *function_copy(Function *pkg);
 static void function_save(Function *pkg, ObjectNode obj_node,
-                         const char *filename);
+                         DiaContext *ctx);
 static DiaObject *function_load(ObjectNode obj_node, int version, DiaContext *ctx);
 static void function_update_data(Function *pkg);
 static DiaMenu *function_get_object_menu(Function *func, Point *clickedpoint) ;
@@ -519,9 +519,9 @@ function_copy(Function *pkg)
 
 
 static void
-function_save(Function *pkg, ObjectNode obj_node, const char *filename)
+function_save(Function *pkg, ObjectNode obj_node, DiaContext *ctx)
 {
-  element_save(&pkg->element, obj_node);
+  element_save(&pkg->element, obj_node, ctx);
 
   data_add_text(new_attribute(obj_node, "text"),
                pkg->text);
diff --git a/objects/Misc/diagram_as_object.c b/objects/Misc/diagram_as_object.c
index 17288b9..7b1911e 100644
--- a/objects/Misc/diagram_as_object.c
+++ b/objects/Misc/diagram_as_object.c
@@ -77,7 +77,7 @@ _dae_create (Point *startpoint,
 static DiaObject *
 _dae_load (ObjectNode obj_node, int version, DiaContext *ctx);
 static void
-_dae_save (DiaObject *obj, ObjectNode obj_node, const char *filename);
+_dae_save (DiaObject *obj, ObjectNode obj_node, DiaContext *ctx);
 
 static ObjectTypeOps _dae_type_ops =
 {
@@ -384,7 +384,7 @@ _dae_load (ObjectNode obj_node, int version, DiaContext *ctx)
 }
 
 static void
-_dae_save (DiaObject *obj, ObjectNode obj_node, const char *filename)
+_dae_save (DiaObject *obj, ObjectNode obj_node, DiaContext *ctx)
 {
   DiagramAsElement *dae;
   /* filename normalization */
@@ -392,14 +392,14 @@ _dae_save (DiaObject *obj, ObjectNode obj_node, const char *filename)
 
   dae = (DiagramAsElement*)obj;
   if (strlen(dae->filename) && g_path_is_absolute (dae->filename)) {
-    gchar *dirname = g_path_get_dirname (filename);
+    gchar *dirname = g_path_get_dirname (dia_context_get_filename (ctx));
     if (strstr (dae->filename, dirname) == dae->filename) {
       saved_path = dae->filename;
       dae->filename += (strlen (dirname) + 1);
     }
     g_free (dirname);
   }
-  object_save_using_properties (obj, obj_node, filename);
+  object_save_using_properties (obj, obj_node, ctx);
 
   if (saved_path) {
     dae->filename = saved_path;
diff --git a/objects/Misc/tree.c b/objects/Misc/tree.c
index 99a6b45..be8205e 100644
--- a/objects/Misc/tree.c
+++ b/objects/Misc/tree.c
@@ -86,7 +86,7 @@ static DiaObject *tree_copy(Tree *tree);
 static PropDescription *tree_describe_props(Tree *tree);
 static void tree_get_props(Tree *tree, GPtrArray *props);
 static void tree_set_props(Tree *tree, GPtrArray *props);
-static void tree_save(Tree *tree, ObjectNode obj_node, const char *filename);
+static void tree_save(Tree *tree, ObjectNode obj_node, DiaContext *ctx);
 static DiaObject *tree_load(ObjectNode obj_node, int version,DiaContext *ctx);
 static DiaMenu *tree_get_object_menu(Tree *tree, Point *clickedpoint);
 
@@ -615,12 +615,12 @@ tree_get_object_menu(Tree *tree, Point *clickedpoint)
 }
 
 static void
-tree_save(Tree *tree, ObjectNode obj_node, const char *filename)
+tree_save(Tree *tree, ObjectNode obj_node, DiaContext *ctx)
 {
   int i;
   AttributeNode attr;
 
-  connection_save(&tree->connection, obj_node);
+  connection_save(&tree->connection, obj_node, ctx);
   
   data_add_color( new_attribute(obj_node, "line_color"), &tree->line_color);
 
diff --git a/objects/UML/class.c b/objects/UML/class.c
index 2278a69..8b56a0a 100644
--- a/objects/UML/class.c
+++ b/objects/UML/class.c
@@ -63,7 +63,7 @@ static void umlclass_destroy(UMLClass *umlclass);
 static DiaObject *umlclass_copy(UMLClass *umlclass);
 
 static void umlclass_save(UMLClass *umlclass, ObjectNode obj_node,
-                         const char *filename);
+                         DiaContext *ctx);
 static DiaObject *umlclass_load(ObjectNode obj_node, int version, DiaContext *ctx);
 
 static DiaMenu * umlclass_object_menu(DiaObject *obj, Point *p);
@@ -2131,7 +2131,7 @@ umlclass_copy(UMLClass *umlclass)
 
 static void
 umlclass_save(UMLClass *umlclass, ObjectNode obj_node,
-             const char *filename)
+             DiaContext *ctx)
 {
   UMLAttribute *attr;
   UMLOperation *op;
@@ -2143,7 +2143,7 @@ umlclass_save(UMLClass *umlclass, ObjectNode obj_node,
   umlclass_sanity_check(umlclass, "Saving");
 #endif
 
-  element_save(&umlclass->element, obj_node);
+  element_save(&umlclass->element, obj_node, ctx);
 
   /* Class info: */
   data_add_string(new_attribute(obj_node, "name"),
diff --git a/objects/custom_lines/custom_linetypes.c b/objects/custom_lines/custom_linetypes.c
index 61f192f..888d8cd 100644
--- a/objects/custom_lines/custom_linetypes.c
+++ b/objects/custom_lines/custom_linetypes.c
@@ -152,7 +152,7 @@ custom_bezierline_load (ObjectNode obj_node, int version, DiaContext *ctx)
 }
 
 static void 
-customline_save (DiaObject *object, ObjectNode obj_node, const char *filename)
+customline_save (DiaObject *object, ObjectNode obj_node, DiaContext *ctx)
 {
   g_assert (object->type &&  object->type->ops && object->type->ops->save);
    
@@ -162,11 +162,11 @@ customline_save (DiaObject *object, ObjectNode obj_node, const char *filename)
   }
 
   if (object->type->ops == &custom_zigzagline_type_ops)
-    zigzag_ot->ops->save (object, obj_node, filename);
+    zigzag_ot->ops->save (object, obj_node, ctx);
   else if (object->type->ops == &custom_polyline_type_ops)
-    polyline_ot->ops->save (object, obj_node, filename);
+    polyline_ot->ops->save (object, obj_node, ctx);
   else if (object->type->ops == &custom_bezierline_type_ops)
-    bezier_ot->ops->save (object, obj_node, filename);
+    bezier_ot->ops->save (object, obj_node, ctx);
   else 
     g_warning ("customline_save() no delegate");
 }
diff --git a/objects/flowchart/box.c b/objects/flowchart/box.c
index f4b25dd..62f3413 100644
--- a/objects/flowchart/box.c
+++ b/objects/flowchart/box.c
@@ -98,7 +98,7 @@ static PropDescription *box_describe_props(Box *box);
 static void box_get_props(Box *box, GPtrArray *props);
 static void box_set_props(Box *box, GPtrArray *props);
 
-static void box_save(Box *box, ObjectNode obj_node, const char *filename);
+static void box_save(Box *box, ObjectNode obj_node, DiaContext *ctx);
 static DiaObject *box_load(ObjectNode obj_node, int version,DiaContext *ctx);
 
 static ObjectTypeOps box_type_ops =
@@ -670,9 +670,9 @@ box_destroy(Box *box)
 }
 
 static void
-box_save(Box *box, ObjectNode obj_node, const char *filename)
+box_save(Box *box, ObjectNode obj_node, DiaContext *ctx)
 {
-  element_save(&box->element, obj_node);
+  element_save(&box->element, obj_node, ctx);
 
   if (box->border_width != 0.1)
     data_add_real(new_attribute(obj_node, "border_width"),
diff --git a/objects/flowchart/diamond.c b/objects/flowchart/diamond.c
index 5b3f342..047843a 100644
--- a/objects/flowchart/diamond.c
+++ b/objects/flowchart/diamond.c
@@ -99,7 +99,7 @@ static PropDescription *diamond_describe_props(Diamond *diamond);
 static void diamond_get_props(Diamond *diamond, GPtrArray *props);
 static void diamond_set_props(Diamond *diamond, GPtrArray *props);
 
-static void diamond_save(Diamond *diamond, ObjectNode obj_node, const char *filename);
+static void diamond_save(Diamond *diamond, ObjectNode obj_node, DiaContext *ctx);
 static DiaObject *diamond_load(ObjectNode obj_node, int version,DiaContext *ctx);
 
 static ObjectTypeOps diamond_type_ops =
@@ -560,9 +560,9 @@ diamond_destroy(Diamond *diamond)
 
 
 static void
-diamond_save(Diamond *diamond, ObjectNode obj_node, const char *filename)
+diamond_save(Diamond *diamond, ObjectNode obj_node, DiaContext *ctx)
 {
-  element_save(&diamond->element, obj_node);
+  element_save(&diamond->element, obj_node, ctx);
 
   if (diamond->border_width != 0.1)
     data_add_real(new_attribute(obj_node, "border_width"),
diff --git a/objects/flowchart/ellipse.c b/objects/flowchart/ellipse.c
index d634741..0561917 100644
--- a/objects/flowchart/ellipse.c
+++ b/objects/flowchart/ellipse.c
@@ -98,7 +98,7 @@ static PropDescription *ellipse_describe_props(Ellipse *ellipse);
 static void ellipse_get_props(Ellipse *ellipse, GPtrArray *props);
 static void ellipse_set_props(Ellipse *ellipse, GPtrArray *props);
 
-static void ellipse_save(Ellipse *ellipse, ObjectNode obj_node, const char *filename);
+static void ellipse_save(Ellipse *ellipse, ObjectNode obj_node, DiaContext *ctx);
 static DiaObject *ellipse_load(ObjectNode obj_node, int version,DiaContext *ctx);
 
 static ObjectTypeOps ellipse_type_ops =
@@ -533,9 +533,9 @@ ellipse_destroy(Ellipse *ellipse)
 }
 
 static void
-ellipse_save(Ellipse *ellipse, ObjectNode obj_node, const char *filename)
+ellipse_save(Ellipse *ellipse, ObjectNode obj_node, DiaContext *ctx)
 {
-  element_save(&ellipse->element, obj_node);
+  element_save(&ellipse->element, obj_node, ctx);
 
   if (ellipse->border_width != 0.1)
     data_add_real(new_attribute(obj_node, "border_width"),
diff --git a/objects/flowchart/parallelogram.c b/objects/flowchart/parallelogram.c
index be7b528..07c264d 100644
--- a/objects/flowchart/parallelogram.c
+++ b/objects/flowchart/parallelogram.c
@@ -100,7 +100,7 @@ static PropDescription *pgram_describe_props(Pgram *pgram);
 static void pgram_get_props(Pgram *pgram, GPtrArray *props);
 static void pgram_set_props(Pgram *pgram, GPtrArray *props);
 
-static void pgram_save(Pgram *pgram, ObjectNode obj_node, const char *filename);
+static void pgram_save(Pgram *pgram, ObjectNode obj_node, DiaContext *ctx);
 static DiaObject *pgram_load(ObjectNode obj_node, int version,DiaContext *ctx);
 
 static ObjectTypeOps pgram_type_ops =
@@ -616,9 +616,9 @@ pgram_destroy(Pgram *pgram)
 }
 
 static void
-pgram_save(Pgram *pgram, ObjectNode obj_node, const char *filename)
+pgram_save(Pgram *pgram, ObjectNode obj_node, DiaContext *ctx)
 {
-  element_save(&pgram->element, obj_node);
+  element_save(&pgram->element, obj_node, ctx);
 
   if (pgram->border_width != 0.1)
     data_add_real(new_attribute(obj_node, "border_width"),
diff --git a/objects/network/bus.c b/objects/network/bus.c
index fc1b42a..6dad761 100644
--- a/objects/network/bus.c
+++ b/objects/network/bus.c
@@ -86,7 +86,7 @@ static DiaObject *bus_copy(Bus *bus);
 static PropDescription *bus_describe_props(Bus *bus);
 static void bus_get_props(Bus *bus, GPtrArray *props);
 static void bus_set_props(Bus *bus, GPtrArray *props);
-static void bus_save(Bus *bus, ObjectNode obj_node, const char *filename);
+static void bus_save(Bus *bus, ObjectNode obj_node, DiaContext *ctx);
 static DiaObject *bus_load(ObjectNode obj_node, int version, DiaContext *ctx);
 static DiaMenu *bus_get_object_menu(Bus *bus, Point *clickedpoint);
 
@@ -623,12 +623,12 @@ bus_get_object_menu(Bus *bus, Point *clickedpoint)
 }
 
 static void
-bus_save(Bus *bus, ObjectNode obj_node, const char *filename)
+bus_save(Bus *bus, ObjectNode obj_node, DiaContext *ctx)
 {
   int i;
   AttributeNode attr;
 
-  connection_save(&bus->connection, obj_node);
+  connection_save(&bus->connection, obj_node, ctx);
   
   data_add_color( new_attribute(obj_node, "line_color"), &bus->line_color);
 
diff --git a/objects/network/wanlink.c b/objects/network/wanlink.c
index 32e46d3..f8c1a1d 100644
--- a/objects/network/wanlink.c
+++ b/objects/network/wanlink.c
@@ -71,8 +71,8 @@ static PropDescription *wanlink_describe_props(WanLink *wanlink);
 static void wanlink_get_props(WanLink *wanlink, GPtrArray *props);
 static void wanlink_set_props(WanLink *wanlink, GPtrArray *props);
 static void wanlink_save(WanLink *wanlink, ObjectNode obj_node,
-                        const char *filename);
-static DiaObject *wanlink_load(ObjectNode obj_node, int version,DiaContext *ctx);
+                        DiaContext *ctx);
+static DiaObject *wanlink_load(ObjectNode obj_node, int version, DiaContext *ctx);
 static void wanlink_update_data(WanLink *wanlink);
 
 static ObjectTypeOps wanlink_type_ops =
@@ -301,11 +301,11 @@ wanlink_move_handle(WanLink *wanlink, Handle *handle,
 
 static void
 wanlink_save(WanLink *wanlink, ObjectNode obj_node,
-            const char *filename)
+            DiaContext *ctx)
 {
     AttributeNode attr;
   
-    connection_save((Connection *)wanlink, obj_node);
+    connection_save((Connection *)wanlink, obj_node, ctx);
     
     attr = new_attribute(obj_node, "width");
     data_add_real(attr, wanlink->width);
diff --git a/objects/standard/arc.c b/objects/standard/arc.c
index 64f6ef1..860cc7c 100644
--- a/objects/standard/arc.c
+++ b/objects/standard/arc.c
@@ -91,7 +91,7 @@ static DiaObject *arc_copy(Arc *arc);
 
 static void arc_set_props(Arc *arc, GPtrArray *props);
 
-static void arc_save(Arc *arc, ObjectNode obj_node, const char *filename);
+static void arc_save(Arc *arc, ObjectNode obj_node, DiaContext *ctx);
 static DiaObject *arc_load(ObjectNode obj_node, int version, DiaContext *ctx);
 static int arc_compute_midpoint(Arc *arc, const Point * ep0, const Point * ep1 , Point * midpoint);
 static void calculate_arc_object_edge(Arc *arc, real ang_start, real ang_end, DiaObject *obj, Point *target, 
gboolean clockwiseness);
@@ -910,9 +910,9 @@ arc_update_data(Arc *arc)
 }
 
 static void
-arc_save(Arc *arc, ObjectNode obj_node, const char *filename)
+arc_save(Arc *arc, ObjectNode obj_node, DiaContext *ctx)
 {
-  connection_save(&arc->connection, obj_node);
+  connection_save(&arc->connection, obj_node, ctx);
 
   if (!color_equals(&arc->arc_color, &color_black))
     data_add_color(new_attribute(obj_node, "arc_color"),
diff --git a/objects/standard/bezier.c b/objects/standard/bezier.c
index 41e85af..1b6d095 100644
--- a/objects/standard/bezier.c
+++ b/objects/standard/bezier.c
@@ -82,7 +82,7 @@ static void bezierline_get_props(Bezierline *bezierline, GPtrArray *props);
 static void bezierline_set_props(Bezierline *bezierline, GPtrArray *props);
 
 static void bezierline_save(Bezierline *bezierline, ObjectNode obj_node,
-                         const char *filename);
+                           DiaContext *ctx);
 static DiaObject *bezierline_load(ObjectNode obj_node, int version, DiaContext *ctx);
 static DiaMenu *bezierline_get_object_menu(Bezierline *bezierline, Point *clickedpoint);
 
@@ -587,7 +587,7 @@ bezierline_update_data(Bezierline *bezierline)
 
 static void
 bezierline_save(Bezierline *bezierline, ObjectNode obj_node,
-             const char *filename)
+               DiaContext *ctx)
 {
   if (connpoint_is_autogap(bezierline->bez.object.handles[0]->connected_to) ||
       
connpoint_is_autogap(bezierline->bez.object.handles[3*(bezierline->bez.bezier.num_points-1)]->connected_to) ||
@@ -598,7 +598,7 @@ bezierline_save(Bezierline *bezierline, ObjectNode obj_node,
     bezierconn_update_boundingbox(&bezierline->bez);
     exchange_bez_gap_points(&bezierline->bez,gap_points);
   } 
-  bezierconn_save(&bezierline->bez, obj_node);
+  bezierconn_save(&bezierline->bez, obj_node, ctx);
 
   if (!color_equals(&bezierline->line_color, &color_black))
     data_add_color(new_attribute(obj_node, "line_color"),
diff --git a/objects/standard/beziergon.c b/objects/standard/beziergon.c
index 4d3ae01..1be8598 100644
--- a/objects/standard/beziergon.c
+++ b/objects/standard/beziergon.c
@@ -84,7 +84,7 @@ static DiaObject *beziergon_copy(Beziergon *beziergon);
 static void beziergon_set_props(Beziergon *beziergon, GPtrArray *props);
 
 static void beziergon_save(Beziergon *beziergon, ObjectNode obj_node,
-                         const char *filename);
+                          DiaContext *ctx);
 static DiaObject *beziergon_load(ObjectNode obj_node, int version, DiaContext *ctx);
 static DiaMenu *beziergon_get_object_menu(Beziergon *beziergon,
                                          Point *clickedpoint);
@@ -373,9 +373,9 @@ beziergon_update_data(Beziergon *beziergon)
 
 static void
 beziergon_save(Beziergon *beziergon, ObjectNode obj_node,
-             const char *filename)
+              DiaContext *ctx)
 {
-  beziershape_save(&beziergon->bezier, obj_node);
+  beziershape_save(&beziergon->bezier, obj_node, ctx);
 
   if (!color_equals(&beziergon->line_color, &color_black))
     data_add_color(new_attribute(obj_node, "line_color"),
diff --git a/objects/standard/box.c b/objects/standard/box.c
index b78cfad..80c55c5 100644
--- a/objects/standard/box.c
+++ b/objects/standard/box.c
@@ -96,7 +96,7 @@ static DiaObject *box_copy(Box *box);
 
 static void box_set_props(Box *box, GPtrArray *props);
 
-static void box_save(Box *box, ObjectNode obj_node, const char *filename);
+static void box_save(Box *box, ObjectNode obj_node, DiaContext *ctx);
 static DiaObject *box_load(ObjectNode obj_node, int version, DiaContext *ctx);
 static DiaMenu *box_get_object_menu(Box *box, Point *clickedpoint);
 
@@ -522,9 +522,9 @@ box_copy(Box *box)
 }
 
 static void
-box_save(Box *box, ObjectNode obj_node, const char *filename)
+box_save(Box *box, ObjectNode obj_node, DiaContext *ctx)
 {
-  element_save(&box->element, obj_node);
+  element_save(&box->element, obj_node, ctx);
 
   if (box->border_width != 0.1)
     data_add_real(new_attribute(obj_node, "border_width"),
diff --git a/objects/standard/ellipse.c b/objects/standard/ellipse.c
index a63e36e..726babe 100644
--- a/objects/standard/ellipse.c
+++ b/objects/standard/ellipse.c
@@ -90,7 +90,7 @@ static DiaObject *ellipse_copy(Ellipse *ellipse);
 
 static void ellipse_set_props(Ellipse *ellipse, GPtrArray *props);
 
-static void ellipse_save(Ellipse *ellipse, ObjectNode obj_node, const char *filename);
+static void ellipse_save(Ellipse *ellipse, ObjectNode obj_node, DiaContext *ctx);
 static DiaObject *ellipse_load(ObjectNode obj_node, int version, DiaContext *ctx);
 static DiaMenu *ellipse_get_object_menu(Ellipse *ellipse, Point *clickedpoint);
 
@@ -500,9 +500,9 @@ ellipse_copy(Ellipse *ellipse)
 
 
 static void
-ellipse_save(Ellipse *ellipse, ObjectNode obj_node, const char *filename)
+ellipse_save(Ellipse *ellipse, ObjectNode obj_node, DiaContext *ctx)
 {
-  element_save(&ellipse->element, obj_node);
+  element_save(&ellipse->element, obj_node, ctx);
 
   if (ellipse->border_width != 0.1)
     data_add_real(new_attribute(obj_node, "border_width"),
diff --git a/objects/standard/image.c b/objects/standard/image.c
index b56072a..eccc3e0 100644
--- a/objects/standard/image.c
+++ b/objects/standard/image.c
@@ -100,7 +100,7 @@ static DiaObject *image_copy(Image *image);
 static void image_get_props(Image *image, GPtrArray *props);
 static void image_set_props(Image *image, GPtrArray *props);
 
-static void image_save(Image *image, ObjectNode obj_node, const char *filename);
+static void image_save(Image *image, ObjectNode obj_node, DiaContext *ctx);
 static DiaObject *image_load(ObjectNode obj_node, int version, DiaContext *ctx);
 
 static ObjectTypeOps image_type_ops =
@@ -625,11 +625,11 @@ get_directory(const char *filename)
 }
 
 static void
-image_save(Image *image, ObjectNode obj_node, const char *filename)
+image_save(Image *image, ObjectNode obj_node, DiaContext *ctx)
 {
   char *diafile_dir;
   
-  element_save(&image->element, obj_node);
+  element_save(&image->element, obj_node, ctx);
 
   if (image->border_width != 0.1)
     data_add_real(new_attribute(obj_node, "border_width"),
@@ -653,7 +653,7 @@ image_save(Image *image, ObjectNode obj_node, const char *filename)
 
   if (image->file != NULL) {
     if (g_path_is_absolute(image->file)) { /* Absolute pathname */
-      diafile_dir = get_directory(filename);
+      diafile_dir = get_directory(dia_context_get_filename (ctx));
 
       if (strncmp(diafile_dir, image->file, strlen(diafile_dir))==0) {
        /* The image pathname has the dia file pathname in the begining */
@@ -663,15 +663,12 @@ image_save(Image *image, ObjectNode obj_node, const char *filename)
        /* Save the absolute path: */
        data_add_filename(new_attribute(obj_node, "file"), image->file);
       }
-      
       g_free(diafile_dir);
-      
     } else {
-      /* Relative path. Must be an erronous filename...
+      /* Relative path. Must be an erronuous filename...
         Just save the filename. */
       data_add_filename(new_attribute(obj_node, "file"), image->file);
     }
-    
   }
   /* only save image_data inline if told to do so */
   if (image->inline_data) {
diff --git a/objects/standard/line.c b/objects/standard/line.c
index 4e0f1ce..2516194 100644
--- a/objects/standard/line.c
+++ b/objects/standard/line.c
@@ -91,7 +91,7 @@ static DiaObject *line_copy(Line *line);
 
 static void line_set_props(Line *line, GPtrArray *props);
 
-static void line_save(Line *line, ObjectNode obj_node, const char *filename);
+static void line_save(Line *line, ObjectNode obj_node, DiaContext *ctx);
 static DiaObject *line_load(ObjectNode obj_node, int version, DiaContext *ctx);
 static DiaMenu *line_get_object_menu(Line *line, Point *clickedpoint);
 
@@ -623,13 +623,13 @@ line_update_data(Line *line)
 
 
 static void
-line_save(Line *line, ObjectNode obj_node, const char *filename)
+line_save(Line *line, ObjectNode obj_node, DiaContext *ctx)
 {
 #ifdef DEBUG
   dia_object_sanity_check((DiaObject*)line, "Saving line");
 #endif
 
-  connection_save(&line->connection, obj_node);
+  connection_save(&line->connection, obj_node, ctx);
 
   connpointline_save(line->cpl,obj_node,"numcp");
 
diff --git a/objects/standard/polygon.c b/objects/standard/polygon.c
index 72c9bb3..38cca6a 100644
--- a/objects/standard/polygon.c
+++ b/objects/standard/polygon.c
@@ -87,7 +87,7 @@ static DiaObject *polygon_copy(Polygon *polygon);
 static void polygon_set_props(Polygon *polygon, GPtrArray *props);
 
 static void polygon_save(Polygon *polygon, ObjectNode obj_node,
-                         const char *filename);
+                        DiaContext *ctx);
 static DiaObject *polygon_load(ObjectNode obj_node, int version, DiaContext *ctx);
 static DiaMenu *polygon_get_object_menu(Polygon *polygon, Point *clickedpoint);
 
@@ -343,9 +343,9 @@ polygon_update_data(Polygon *polygon)
 
 static void
 polygon_save(Polygon *polygon, ObjectNode obj_node,
-             const char *filename)
+            DiaContext *ctx)
 {
-  polyshape_save(&polygon->poly, obj_node);
+  polyshape_save(&polygon->poly, obj_node, ctx);
 
   if (!color_equals(&polygon->line_color, &color_black))
     data_add_color(new_attribute(obj_node, "line_color"),
diff --git a/objects/standard/polyline.c b/objects/standard/polyline.c
index f759366..79b15b4 100644
--- a/objects/standard/polyline.c
+++ b/objects/standard/polyline.c
@@ -76,7 +76,7 @@ static DiaObject *polyline_copy(Polyline *polyline);
 static void polyline_set_props(Polyline *polyline, GPtrArray *props);
 
 static void polyline_save(Polyline *polyline, ObjectNode obj_node,
-                         const char *filename);
+                         DiaContext *ctx);
 static DiaObject *polyline_load(ObjectNode obj_node, int version, DiaContext *ctx);
 static DiaMenu *polyline_get_object_menu(Polyline *polyline, Point *clickedpoint);
 void polyline_calculate_gap_endpoints(Polyline *polyline, Point *gap_endpoints);
@@ -463,9 +463,9 @@ polyline_update_data(Polyline *polyline)
 
 static void
 polyline_save(Polyline *polyline, ObjectNode obj_node,
-             const char *filename)
+             DiaContext *ctx)
 {
-  polyconn_save(&polyline->poly, obj_node);
+  polyconn_save(&polyline->poly, obj_node, ctx);
 
   if (!color_equals(&polyline->line_color, &color_black))
     data_add_color(new_attribute(obj_node, "line_color"),
diff --git a/objects/standard/textobj.c b/objects/standard/textobj.c
index be428ab..067300f 100644
--- a/objects/standard/textobj.c
+++ b/objects/standard/textobj.c
@@ -90,7 +90,7 @@ static void textobj_get_props(Textobj *textobj, GPtrArray *props);
 static void textobj_set_props(Textobj *textobj, GPtrArray *props);
 
 static void textobj_save(Textobj *textobj, ObjectNode obj_node,
-                        const char *filename);
+                        DiaContext *ctx);
 static DiaObject *textobj_load(ObjectNode obj_node, int version, DiaContext *ctx);
 static DiaMenu *textobj_get_object_menu(Textobj *textobj, Point *clickedpoint);
 
@@ -349,9 +349,9 @@ textobj_destroy(Textobj *textobj)
 }
 
 static void
-textobj_save(Textobj *textobj, ObjectNode obj_node, const char *filename)
+textobj_save(Textobj *textobj, ObjectNode obj_node, DiaContext *ctx)
 {
-  object_save(&textobj->object, obj_node);
+  object_save(&textobj->object, obj_node, ctx);
 
   data_add_text(new_attribute(obj_node, "text"),
                textobj->text);
diff --git a/objects/standard/zigzagline.c b/objects/standard/zigzagline.c
index e46866c..486bfa6 100644
--- a/objects/standard/zigzagline.c
+++ b/objects/standard/zigzagline.c
@@ -79,7 +79,7 @@ static DiaMenu *zigzagline_get_object_menu(Zigzagline *zigzagline,
 static void zigzagline_set_props(Zigzagline *zigzagline, GPtrArray *props);
 
 static void zigzagline_save(Zigzagline *zigzagline, ObjectNode obj_node,
-                           const char *filename);
+                           DiaContext *ctx);
 static DiaObject *zigzagline_load(ObjectNode obj_node, int version, DiaContext *ctx);
 
 static ObjectTypeOps zigzagline_type_ops =
@@ -474,9 +474,9 @@ zigzagline_get_object_menu(Zigzagline *zigzagline, Point *clickedpoint)
 
 static void
 zigzagline_save(Zigzagline *zigzagline, ObjectNode obj_node,
-               const char *filename)
+               DiaContext *ctx)
 {
-  orthconn_save(&zigzagline->orth, obj_node);
+  orthconn_save(&zigzagline->orth, obj_node, ctx);
 
   if (!color_equals(&zigzagline->line_color, &color_black))
     data_add_color(new_attribute(obj_node, "line_color"),
diff --git a/plug-ins/drs/dia-render-script-renderer.c b/plug-ins/drs/dia-render-script-renderer.c
index 65645cf..fa90842 100644
--- a/plug-ins/drs/dia-render-script-renderer.c
+++ b/plug-ins/drs/dia-render-script-renderer.c
@@ -61,6 +61,8 @@ drs_renderer_finalize (GObject *object)
 
   g_queue_free (renderer->parents);
   g_queue_free (renderer->matrices);
+  if (renderer->ctx)
+    dia_context_release (renderer->ctx);
 
   G_OBJECT_CLASS (parent_class)->finalize (object);  
 }
@@ -118,9 +120,9 @@ draw_object(DiaRenderer *self,
   }
   if (renderer->save_props) {
     xmlNodePtr props_node;
-    
+
     props_node = xmlNewChild(node, NULL, (const xmlChar *)"properties", NULL);
-    object_save_props (object, props_node);
+    object_save_props (object, props_node, renderer->ctx);
   }
   if (matrix) {
     DiaMatrix *m2 = g_new (DiaMatrix, 1);
diff --git a/plug-ins/drs/dia-render-script-renderer.h b/plug-ins/drs/dia-render-script-renderer.h
index 563208e..4e52080 100644
--- a/plug-ins/drs/dia-render-script-renderer.h
+++ b/plug-ins/drs/dia-render-script-renderer.h
@@ -49,6 +49,8 @@ struct _DrsRenderer
   GQueue *matrices;
   /* to actually render transformed */
   DiaRenderer *transformer;
+  /* initially NULL, only to be used during export_data */
+  DiaContext *ctx;
 };
 
 struct _DrsRendererClass
diff --git a/plug-ins/drs/dia-render-script.c b/plug-ins/drs/dia-render-script.c
index b83c66d..566f4fd 100644
--- a/plug-ins/drs/dia-render-script.c
+++ b/plug-ins/drs/dia-render-script.c
@@ -130,6 +130,8 @@ export_data(DiagramData *data, DiaContext *ctx,
   renderer = DRS_RENDERER (g_object_new(DRS_TYPE_RENDERER, NULL));
   /* store also object properties */
   renderer->save_props = (user_data == NULL);
+  /* remember context for object_save_props */
+  renderer->ctx = g_object_ref (ctx);
 
   /* set up the root node */
   doc = xmlNewDoc((const xmlChar *)"1.0");
diff --git a/plug-ins/python/pydia-diagram.c b/plug-ins/python/pydia-diagram.c
index 93f2bb3..447e6a1 100644
--- a/plug-ins/python/pydia-diagram.c
+++ b/plug-ins/python/pydia-diagram.c
@@ -314,11 +314,19 @@ PyDiaDiagram_UngroupSelected(PyDiaDiagram *self, PyObject *args)
 static PyObject *
 PyDiaDiagram_Save(PyDiaDiagram *self, PyObject *args)
 {
+    DiaContext *ctx;
     gchar *filename = self->dia->filename;
+    int ret;
 
     if (!PyArg_ParseTuple(args, "|s:Diagram.save", &filename))
        return NULL;
-    return PyInt_FromLong(diagram_save(self->dia, filename));
+    ctx = dia_context_new ("PyDia Save");
+    dia_context_set_filename (ctx, filename);
+    ret = diagram_save(self->dia, filename, ctx);
+    /* FIXME: throwing away possible error messages */
+    dia_context_reset (ctx);
+    dia_context_release (ctx);
+    return PyInt_FromLong(ret);
 }
 
 static PyObject *


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]