I've updated the FS module to include undo information
and the flow lines should work now. The patch should
apply cleanly to dia-0.82 and the CVS version. If you
have any problems with it please let me know. Thanks
for your patience with my glacially slow progress.

Because the patch is short, I'm including it in the
message. Is there somewhere else I should be sending
it?

                David
diff -N -u -r dia-0.82/objects/FS/flow-ortho.c dia-0.82-patched/objects/FS/flow-ortho.c
--- dia-0.82/objects/FS/flow-ortho.c    Thu Nov 11 18:30:24 1999
+++ dia-0.82-patched/objects/FS/flow-ortho.c    Tue Feb 29 14:45:32 2000
@@ -1,70 +1,10 @@
-/* Dia -- an diagram creation/manipulation program
- * Copyright (C) 1998, 1999 Alexander Larsson
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-#include <assert.h>
-#include <gtk/gtk.h>
-#include <math.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "config.h"
-#include "intl.h"
-#include "object.h"
-#include "connection.h"
-#include "render.h"
-#include "handle.h"
-#include "arrows.h"
-#include "diamenu.h"
-#include "text.h"
-#include "orth_conn.h"
-
+#include "flow-ortho.h"
 #include "pixmaps/orthflow.xpm"
 
 Color orthflow_color_energy   = { 1.0f, 0.0f, 0.0f };
 Color orthflow_color_material = { 0.8f, 0.0f, 0.8f };
 Color orthflow_color_signal   = { 0.0f, 0.0f, 1.0f };
 
-typedef struct _Orthflow Orthflow;
-typedef struct _OrthflowDialog OrthflowDialog;
-
-typedef enum {
-  ORTHFLOW_ENERGY,
-  ORTHFLOW_MATERIAL,
-  ORTHFLOW_SIGNAL
-} OrthflowType;
-
-struct _Orthflow {
-  OrthConn orth ;
-
-  Handle text_handle;
-
-  Text* text;
-  OrthflowType type;
-};
-
-struct _OrthflowDialog {
-  GtkWidget *dialog;
-  
-  GtkWidget *text;
-
-  GtkWidget *m_energy;
-  GtkWidget *m_material;
-  GtkWidget *m_signal;
-};
   
 #define ORTHFLOW_WIDTH 0.1
 #define ORTHFLOW_MATERIAL_WIDTH 0.2
@@ -117,14 +57,15 @@
   (SaveFunc)           orthflow_save,
   (GetDefaultsFunc)    orthflow_get_defaults,
   (ApplyDefaultsFunc)  orthflow_apply_defaults
+  
 } ;
 
 ObjectType orthflow_type =
 {
-  "FS - Orthflow",         /* name */
-  0,                   /* version */
-  (char **) orthflow_xpm,  /* pixmap */
-  &orthflow_type_ops       /* ops */
+  "FS - Orthflow",             /* name */
+  0,                           /* version */
+  (char **) orthflow_xpm,      /* pixmap */
+  &orthflow_type_ops           /* ops */
 };
 
 static ObjectOps orthflow_ops = {
@@ -140,6 +81,54 @@
   (ObjectMenuFunc)      orthflow_get_object_menu,
 };
 
+void orthflow_change_apply_revert( ObjectChange* objchg, Object* obj )
+{
+  struct _OrthflowChange* change = (struct _OrthflowChange*) objchg ;
+  Orthflow* oflow = (Orthflow*) obj ;
+
+  if ( change->change_type == FLOW_TYPE || change->change_type == BOTH ) {
+    OrthflowType type = oflow->type ;
+    oflow->type = change->type ;
+    change->type = type ;
+    orthflow_update_data(oflow) ;
+  }
+
+  if ( change->change_type & TEXT_EDIT  || change->change_type == BOTH ) {
+    char* tmp = text_get_string_copy( oflow->text ) ;
+    text_set_string( oflow->text, change->text ) ;
+    g_free( change->text ) ;
+    change->text = tmp ;
+  }
+}
+
+void orthflow_change_free( ObjectChange* objchg )
+{
+  struct _OrthflowChange* change = (struct _OrthflowChange*) objchg ;
+
+  if (change->change_type & TEXT_EDIT  || change->change_type == BOTH ) {
+    g_free(change->text) ;
+  }
+}
+
+static ObjectChange*
+orthflow_create_change( enum OrthflowChangeType change_type,
+                       OrthflowType type, Text* text )
+{
+  struct _OrthflowChange* change ;
+  change = g_new( struct _OrthflowChange, 1 ) ;
+  change->obj_change.apply = (ObjectChangeApplyFunc) orthflow_change_apply_revert ;
+  change->obj_change.revert =  (ObjectChangeRevertFunc) orthflow_change_apply_revert ;
+  change->obj_change.free =  (ObjectChangeFreeFunc) orthflow_change_free ;
+  change->change_type = change_type ;
+
+  change->type = type ;
+  if ( text ) {
+    change->text = text_get_string_copy( text ) ;
+  }
+
+  return (ObjectChange*) change ;
+}
+
 static real
 orthflow_distance_from(Orthflow *orthflow, Point *point)
 {
@@ -266,7 +255,7 @@
   Object *obj;
   Point p;
 
-  orthflow = g_malloc(sizeof(Orthflow));
+  orthflow = g_new(Orthflow,1);
 
   orth = &orthflow->orth ;
   orthconn_init( orth, startpoint ) ;
@@ -311,12 +300,13 @@
   orthflow->text_handle.type = HANDLE_MINOR_CONTROL;
   orthflow->text_handle.connect_type = HANDLE_NONCONNECTABLE;
   orthflow->text_handle.connected_to = NULL;
-  obj->handles[2] = &orthflow->text_handle;
+  object_add_handle( obj, &orthflow->text_handle ) ;
   
   orthflow_update_data(orthflow);
 
+  /*obj->handles[1] = orth->handles[2] ;*/
   *handle1 = obj->handles[0];
-  *handle2 = obj->handles[1];
+  *handle2 = obj->handles[2];
   return (Object *)orthflow;
 }
 
@@ -451,9 +441,12 @@
 orthflow_apply_properties(Orthflow *orthflow)
 {
   OrthflowDialog *prop_dialog;
+  ObjectChange* change ;
   
   prop_dialog = properties_dialog;
 
+  change = orthflow_create_change( BOTH,
+                                  orthflow->type, orthflow->text ) ;
   text_set_string(orthflow->text,
                   gtk_editable_get_chars( GTK_EDITABLE(prop_dialog->text),
                                          0, -1));
@@ -467,7 +460,7 @@
 
   orthflow_update_data(orthflow);
 
-  return NULL;
+  return change ;
 }
 
 static void
@@ -619,19 +612,33 @@
 static ObjectChange *
 orthflow_set_type_callback (Object* obj, Point* clicked, gpointer data)
 {
+  ObjectChange* change ;
+  change = orthflow_create_change( FLOW_TYPE, ((Orthflow*)obj)->type, 0 ) ;
+
   ((Orthflow*)obj)->type = (int) data ;
   orthflow_update_defaults( (Orthflow*) obj, 1 ) ;
   if ( defaults_dialog )
     fill_in_defaults_dialog() ;
   orthflow_update_data((Orthflow*)obj);
 
-  return NULL;
+  return change;
+}
+
+static ObjectChange *
+orthflow_segment_callback (Object* obj, Point* clicked, gpointer data)
+{
+  if ( (int)data )
+     return orthconn_add_segment( (OrthConn*)obj, clicked ) ;
+
+  return orthconn_delete_segment( (OrthConn*)obj, clicked ) ;
 }
 
 static DiaMenuItem orthflow_menu_items[] = {
   { N_("Energy"), orthflow_set_type_callback, (void*)ORTHFLOW_ENERGY, 1 },
   { N_("Material"), orthflow_set_type_callback, (void*)ORTHFLOW_MATERIAL, 1 },
   { N_("Signal"), orthflow_set_type_callback, (void*)ORTHFLOW_SIGNAL, 1 },
+  { N_("Add segment"), orthflow_segment_callback, (void*)1, 1 },
+  { N_("Delete segment"), orthflow_segment_callback, (void*)0, 1 }
 };
 
 static DiaMenu orthflow_menu = {
diff -N -u -r dia-0.82/objects/FS/flow-ortho.h dia-0.82-patched/objects/FS/flow-ortho.h
--- dia-0.82/objects/FS/flow-ortho.h    Wed Dec 31 18:00:00 1969
+++ dia-0.82-patched/objects/FS/flow-ortho.h    Mon Feb 28 22:33:01 2000
@@ -0,0 +1,85 @@
+/* Dia -- an diagram creation/manipulation program
+ * Copyright (C) 1998, 1999 Alexander Larsson
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/* If you have a problem with the Function Structure (FS) components,
+ * please send e-mail to David Thompson <[EMAIL PROTECTED]>
+ */
+#ifndef flow_ortho_h
+#define flow_ortho_h
+
+#include <assert.h>
+#include <gtk/gtk.h>
+#include <math.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "config.h"
+#include "intl.h"
+#include "object.h"
+#include "objchange.h"
+#include "connection.h"
+#include "render.h"
+#include "handle.h"
+#include "arrows.h"
+#include "diamenu.h"
+#include "text.h"
+#include "orth_conn.h"
+
+typedef struct _Orthflow Orthflow;
+typedef struct _OrthflowDialog OrthflowDialog;
+typedef struct _OrthflowChange OrthflowChange;
+
+typedef enum {
+  ORTHFLOW_ENERGY,
+  ORTHFLOW_MATERIAL,
+  ORTHFLOW_SIGNAL
+} OrthflowType;
+
+struct _Orthflow {
+  OrthConn orth ;
+
+  Handle text_handle;
+
+  Text* text;
+  OrthflowType type;
+};
+
+struct _OrthflowDialog {
+  GtkWidget *dialog;
+  
+  GtkWidget *text;
+
+  GtkWidget *m_energy;
+  GtkWidget *m_material;
+  GtkWidget *m_signal;
+};
+
+enum OrthflowChangeType {
+  TEXT_EDIT=1,
+  FLOW_TYPE=2,
+  BOTH=3
+};
+
+struct _OrthflowChange {
+  ObjectChange                 obj_change ;
+  enum OrthflowChangeType      change_type ;
+  OrthflowType                 type ;
+  char*                                text ;
+};
+
+#endif /* flow_ortho_h */
diff -N -u -r dia-0.82/objects/FS/function.c dia-0.82-patched/objects/FS/function.c
--- dia-0.82/objects/FS/function.c      Thu Nov 11 18:30:24 1999
+++ dia-0.82-patched/objects/FS/function.c      Tue Feb 29 15:18:59 2000
@@ -34,7 +34,7 @@
 
 typedef struct _Function Function;
 typedef struct _FunctionPropertiesDialog FunctionPropertiesDialog;
-
+typedef struct _FunctionChange FunctionChange;
 
 struct _Function {
   Element element;
@@ -56,6 +56,21 @@
   GtkToggleButton *user;
 };
 
+enum FuncChangeType {
+  WISH_FUNC,
+  USER_FUNC,
+  TEXT_EDIT,
+  ALL
+};
+
+struct _FunctionChange {
+  ObjectChange         obj_change ;
+  enum FuncChangeType  change_type ;
+  int                  is_wish ;
+  int                  is_user ;
+  char*                        text ;
+};
+
 #define FUNCTION_BORDERWIDTH 0.1
 #define FUNCTION_LINEWIDTH 0.05
 #define FUNCTION_MARGIN_X 0.5
@@ -116,6 +131,62 @@
   (ObjectMenuFunc)      function_get_object_menu
 };
 
+static void
+function_change_apply_revert( ObjectChange* objchg, Object* obj)
+{
+  int tmp ;
+  char* ttxt ;
+  FunctionChange* change = (FunctionChange*) objchg ;
+  Function* fcn = (Function*) obj ;
+
+  if ( change->change_type == WISH_FUNC || change->change_type == ALL ) {
+     tmp = fcn->is_wish ;
+     fcn->is_wish = change->is_wish ;
+     change->is_wish = tmp ;
+  }
+  if ( change->change_type == USER_FUNC || change->change_type == ALL ) {
+     tmp = fcn->is_user ;
+     fcn->is_user = change->is_user ;
+     change->is_user = tmp ;
+  }
+  if ( change->change_type == TEXT_EDIT || change->change_type == ALL ) {
+     ttxt = text_get_string_copy( fcn->text ) ;
+     text_set_string( fcn->text, change->text ) ;
+     g_free( change->text ) ;
+     change->text = ttxt ;
+  }
+}
+
+static void
+function_change_free( ObjectChange* objchg )
+{
+  FunctionChange* change = (FunctionChange*) objchg ;
+
+  if ( change->change_type == TEXT_EDIT ) {
+     g_free( change->text ) ;
+  }
+}
+
+static ObjectChange*
+function_create_change( Function* fcn, enum FuncChangeType change_type )
+{
+  FunctionChange* change = g_new(FunctionChange,1) ;
+  change->obj_change.apply = (ObjectChangeApplyFunc) function_change_apply_revert ;
+  change->obj_change.revert = (ObjectChangeRevertFunc) function_change_apply_revert ;
+  change->obj_change.free = (ObjectChangeFreeFunc) function_change_free ;
+  change->change_type = change_type ;
+
+  if ( change_type == WISH_FUNC || change_type == ALL )
+     change->is_wish = fcn->is_wish ;
+
+  if ( change_type == USER_FUNC || change_type == ALL )
+     change->is_user = fcn->is_user ;
+
+  if ( change_type == TEXT_EDIT || change_type == ALL )
+     change->text = text_get_string_copy( fcn->text ) ;
+  return (ObjectChange*) change ;
+}
+  
 static real
 function_distance_from(Function *pkg, Point *point)
 {
@@ -430,6 +501,7 @@
 function_apply_properties(Function *dep)
 {
   FunctionPropertiesDialog *prop_dialog;
+  ObjectChange* change = function_create_change( dep, ALL ) ;
 
   prop_dialog = properties_dialog;
 
@@ -452,7 +524,7 @@
   
   function_update_data(dep);
 
-  return NULL;
+  return change;
 }
 
 static void
@@ -530,6 +602,7 @@
 function_insert_word( Object* obj, Point* clicked, gpointer data)
 {
   Function* func = (Function*)obj ;
+  ObjectChange* change = function_create_change( func, TEXT_EDIT ) ;
   char* word = (char*) data ;
   char* old_chars = text_get_string_copy( func->text ) ;
   char* new_chars = malloc( strlen( old_chars) + strlen( word ) + 1 ) ;
@@ -540,7 +613,7 @@
   function_update_data( func ) ;
   text_set_cursor_at_end( func->text ) ;
 
-  return NULL;
+  return change;
 }
 
 struct _IndentedWords {

Reply via email to