Hi there,

        I had some idle cycles today so I hacked up some more bonobo
bits; adding a persitfile ( so we can load ) and a print ( so we can print
) interface. Unfortunately Dia ( as with very many embeddables ) is not
well behaved; consequently it is hard to get printing / zooming / scaling
accurate, so I havn't bothered. The simplest way to fix this is to have
dia fit it's extent to the pixel size of the window it is given to render
into; other ways are more correct and far more complex.

        Anyway; for lovers of pictures:

        http://www.gnome.org/~michael/gnumeric-dia.jpeg
        http://www.gnome.org/~michael/gnumeric-dia-print.jpeg

        Here is the patch:

? jamesh
? app/splash.h
? lib/stbtbUbi
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/dia/ChangeLog,v
retrieving revision 1.501
diff -u -r1.501 ChangeLog
--- ChangeLog   2001/01/10 19:42:21     1.501
+++ ChangeLog   2001/01/12 00:13:45
@@ -1,3 +1,29 @@
+2001-01-12  Michael Meeks  <[EMAIL PROTECTED]>
+
+       * app/dia_embedd.c (init_server_factory): do a bonobo_activate
+       so our POA gets setup properly.
+
+       * app/paginate_gnomeprint.c (paginate_gnomeprint): g_free
+       things we g_malloc.
+
+       * configure.in: Use bonobox_print.
+
+       * app/dia_embedd.c (embeddable_factory): add print interface.
+       (object_print): impl.
+
+2001-01-11  Michael Meeks  <[EMAIL PROTECTED]>
+
+       * app/dia_embedd.c (embeddable_factory): aggregate PersistFile.
+       (load_fn, save_fn): impl.
+       (view_factory): hide modified status bar, & use activate fn.
+       (refresh_view): force redraws of the views.
+       (view_show_hide): split from
+       (dia_view_activate): here.
+
+       * app/diagram.c (diagram_load_into): split from diagram_load.
+       (new_diagram): simplify bu splittin stuff into
+       (diagram_init): here.
+
 2001-01-10  Steffen Macke <[EMAIL PROTECTED]>
 
        * shapes/jigsaw/*.shape: replaced #000000 with foreground
Index: configure.in
===================================================================
RCS file: /cvs/gnome/dia/configure.in,v
retrieving revision 1.95
diff -u -r1.95 configure.in
--- configure.in        2001/01/08 22:20:14     1.95
+++ configure.in        2001/01/12 00:13:45
@@ -69,7 +69,7 @@
 
     AC_MSG_CHECKING(for Bonobo >= 0.31)
 
-    if gnome-config --libs bonobox > /dev/null 2>&1; then
+    if gnome-config --libs bonobox_print > /dev/null 2>&1; then
       vers=`gnome-config --modversion bonobo | sed -e "s/bonobo-//" | \
        awk 'BEGIN { FS = "."; } { printf "%d", $1 * 1000 + $2;}'`
       if test "$vers" -ge 31; then
@@ -89,8 +89,8 @@
       AC_MSG_RESULT([not found])
     fi
 
-    hcomponents="$hcomponents bonobox"
-    BONOBO_LIBS=`gnome-config bonobox $components --libs`
+    hcomponents="$hcomponents bonobox_print"
+    BONOBO_LIBS=`gnome-config bonobox_print $components --libs`
   fi
   GNOME_CFLAGS=`gnome-config $hcomponents $components --cflags`
   GNOME_LIBS=`gnome-config $components --libs`
Index: app/dia_embedd.c
===================================================================
RCS file: /cvs/gnome/dia/app/dia_embedd.c,v
retrieving revision 1.7
diff -u -r1.7 dia_embedd.c
--- app/dia_embedd.c    2001/01/08 12:08:52     1.7
+++ app/dia_embedd.c    2001/01/12 00:13:46
@@ -29,7 +29,12 @@
 #include "disp_callbacks.h"
 #include "app_procs.h"
 #include "interface.h"
+#include "load_save.h"
 
+#ifdef GNOME_PRINT
+#  include "render_gnomeprint.h"
+#endif
+
 typedef struct _EmbeddedDia EmbeddedDia;
 typedef struct _EmbeddedView EmbeddedView;
 
@@ -48,12 +53,11 @@
 static BonoboGenericFactory *factory = NULL;
 
 static void
-dia_view_activate(BonoboView *view, gboolean activate,
-                 EmbeddedView *view_data)
+view_show_hide (EmbeddedView *view_data,
+               gboolean      activate)
 {
   DDisplay *ddisp = view_data->display;
 
-  bonobo_view_activate_notify(view, activate);
   if (activate) {
     toolbox_show();
 
@@ -63,6 +67,7 @@
     gtk_widget_show(ddisp->hsb);
     gtk_widget_show(ddisp->vsb);
     gtk_widget_show(ddisp->zoom_status->parent);
+    gtk_widget_show(ddisp->modified_status);
   } else {
     toolbox_hide();
 
@@ -72,10 +77,19 @@
     gtk_widget_hide(ddisp->hsb);
     gtk_widget_hide(ddisp->vsb);
     gtk_widget_hide(ddisp->zoom_status->parent);
+    gtk_widget_hide(ddisp->modified_status);
   }
 }
 
 static void
+dia_view_activate(BonoboView *view, gboolean activate,
+                 EmbeddedView *view_data)
+{
+  bonobo_view_activate_notify(view, activate);
+  view_show_hide(view_data,activate);
+}
+
+static void
 dia_view_display_destroy (GtkWidget *ddisp_shell, EmbeddedView *view_data)
 {
   view_data->display = NULL;
@@ -137,22 +151,16 @@
   
   view_data->display = new_display(embedded_dia->diagram);
 
+  view_show_hide (view_data, FALSE);
+  
   gtk_signal_connect (GTK_OBJECT (view_data->display->shell), "destroy",
                       GTK_SIGNAL_FUNC (dia_view_display_destroy),
                       view_data);
-  
-  gtk_widget_hide(view_data->display->origin);
-  gtk_widget_hide(view_data->display->hrule);
-  gtk_widget_hide(view_data->display->vrule);
-  gtk_widget_hide(view_data->display->hsb);
-  gtk_widget_hide(view_data->display->vsb);
-  gtk_widget_hide(view_data->display->zoom_status->parent);
 
   view = bonobo_view_new (view_data->display->shell);
   view_data->view = view;
   gtk_object_set_data (GTK_OBJECT (view), "view_data", view_data);
   
-  
   gtk_signal_connect(GTK_OBJECT (view), "activate",
                     GTK_SIGNAL_FUNC (dia_view_activate), view_data);
   
@@ -181,12 +189,102 @@
   return view;
 }
 
+static int
+save_fn (BonoboPersistFile *pf,
+        const CORBA_char  *filename,
+        CORBA_Environment *ev,
+        void              *closure)
+{
+  EmbeddedDia *dia = closure;
+
+  if (!diagram_save (dia->diagram, filename))
+    CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
+                        ex_Bonobo_IOError, NULL);
+  return 0;
+}
+
+static void 
+refresh_view (DDisplay *ddisp)
+{
+  Point        middle;
+  Rectangle   *visible;
+
+  visible = &ddisp->visible;
+  middle.x = visible->left*0.5 + visible->right*0.5;
+  middle.y = visible->top*0.5 + visible->bottom*0.5;
+  
+  ddisplay_zoom(ddisp, &middle, 1.0);
+  gtk_widget_queue_draw(ddisp->shell);
+}
+
+static int
+load_fn (BonoboPersistFile *pf,
+        const CORBA_char  *filename,
+        CORBA_Environment *ev,
+        void              *closure)
+{
+  EmbeddedDia *dia = closure;
+
+  if (!diagram_load_into (dia->diagram, filename, NULL)) {
+         g_warning ("Failed to load '%s'", filename);
+         CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
+                              ex_Bonobo_Persist_WrongDataType,
+                              NULL);
+  } else {
+         GSList *l;
+         diagram_update_extents(dia->diagram);
+         for (l=dia->diagram->displays;l;l=l->next)
+                 refresh_view (l->data);
+  }
+  return 0;
+}
+
+#ifdef GNOME_PRINT
+static void
+object_print (GnomePrintContext         *ctx,
+             double                     width,
+             double                     height,
+             const Bonobo_PrintScissor *scissor,
+             gpointer                   user_data)
+{
+  RendererGPrint *rend;
+  EmbeddedDia    *edia = user_data;
+  Diagram        *dia = edia->diagram;
+  Rectangle      *extents;
+  double          scalex, scaley;
+
+  rend = new_gnomeprint_renderer(dia, ctx);
+
+  /*
+   * FIXME: we need to de-complicate all this - this should
+   * probably be done by scaling the view to the extent or
+   * alternatively keeping the visible bounds on the embeddable
+   * not the view; or possibly none of these.
+   */
+  extents = &dia->data->extents;
+
+  scalex = width / (extents->right - extents->left);
+  scaley = -height / (extents->bottom - extents->top);
+
+  gnome_print_translate (ctx, - scalex* extents->left,
+                        height - scaley * extents->top);
+  gnome_print_scale     (ctx, scalex, scaley);
+
+
+  data_render(dia->data, (Renderer *)rend, extents, NULL, NULL);
+
+  g_free (rend);
+}
+#endif
+
 static BonoboObject *
 embeddable_factory (BonoboGenericFactory *this,
                    void *data)
 {
-  BonoboEmbeddable *embeddable;
-  EmbeddedDia *embedded_dia;
+  BonoboPersistFile *pfile;
+  BonoboEmbeddable  *embeddable;
+  BonoboPrint       *print;
+  EmbeddedDia       *embedded_dia;
 
   embedded_dia = g_new0 (EmbeddedDia, 1);
   if (embedded_dia == NULL)
@@ -212,6 +310,24 @@
                     GTK_SIGNAL_FUNC (dia_embeddable_destroy),
                     embedded_dia);
 
+  /* Register the Bonobo::PersistFile interface. */
+  pfile = bonobo_persist_file_new (load_fn, save_fn, embedded_dia);
+  bonobo_object_add_interface (
+         BONOBO_OBJECT (embeddable),
+         BONOBO_OBJECT (pfile));
+
+#ifdef GNOME_PRINT
+  /* Register the Bonobo::Print interface */
+  print = bonobo_print_new (object_print, embedded_dia);
+  if (!print) {
+         bonobo_object_unref (BONOBO_OBJECT (embeddable));
+         return NULL;
+  }
+  
+  bonobo_object_add_interface (BONOBO_OBJECT (embeddable),
+                              BONOBO_OBJECT (print));
+#endif
+
   return BONOBO_OBJECT (embeddable);
 }
 
@@ -234,6 +350,7 @@
 
   if (bonobo_init (orb, NULL, NULL) == FALSE)
     g_error (_("Could not initialize Bonobo!"));
+  bonobo_activate ();
 }
 
 int
Index: app/diagram.c
===================================================================
RCS file: /cvs/gnome/dia/app/diagram.c,v
retrieving revision 1.39
diff -u -r1.39 diagram.c
--- app/diagram.c       2001/01/05 16:36:40     1.39
+++ app/diagram.c       2001/01/12 00:13:46
@@ -38,48 +38,78 @@
 
 GList *open_diagrams = NULL;
 
-Diagram *
-diagram_load(const char *filename, DiaImportFilter *ifilter)
+static void
+diagram_init(Diagram *dia, const char *filename)
 {
-  Diagram *diagram;
+  if(dia->data)
+    diagram_data_destroy(dia->data);
+  
+  dia->data = new_diagram_data();
+  dia->data->grid.width_x = prefs.grid.x;
+  dia->data->grid.width_y = prefs.grid.y;
+
+  g_free(dia->filename);
+  dia->filename = g_strdup(filename);
+  
+  dia->unsaved = TRUE;
+  dia->modified = FALSE;
 
+  if (dia->undo)
+    undo_destroy(dia->undo);
+  dia->undo = new_undo_stack(dia);
+
+  if (!g_list_find(open_diagrams, dia))
+    open_diagrams = g_list_prepend(open_diagrams, dia);
+
+  layer_dialog_update_diagram_list();
+}
+
+int
+diagram_load_into(Diagram         *diagram,
+                 const char      *filename,
+                 DiaImportFilter *ifilter)
+{
   if (!ifilter)
     ifilter = filter_guess_import_filter(filename);
   if (!ifilter)  /* default to native format */
     ifilter = &dia_import_filter;
-  diagram = new_diagram(filename);
+
+  diagram_init(diagram, filename);
+
   if (ifilter->import(filename, diagram->data, ifilter->user_data)) {
     diagram->unsaved = FALSE;
     diagram_set_modified(diagram, FALSE);
     recent_file_history_add(filename, ifilter);
-  } else {
+    return TRUE;
+  } else
+    return FALSE;
+}
+
+Diagram *
+diagram_load(const char *filename, DiaImportFilter *ifilter)
+{
+  Diagram *diagram;
+
+  diagram = new_diagram(filename);
+
+  if (!diagram_load_into (diagram, filename, ifilter)) {
     diagram_destroy(diagram);
     diagram = NULL;
   }
+
   return diagram;
 }
 
 Diagram *
 new_diagram(const char *filename)  /* Note: filename is copied */
 {
-  Diagram *dia = g_new(Diagram, 1);
-  
-  dia->data = new_diagram_data();
-  dia->data->grid.width_x = prefs.grid.x;
-  dia->data->grid.width_y = prefs.grid.y;
+  Diagram *dia = g_new0(Diagram, 1);
 
-  dia->filename = g_strdup(filename);
-  
-  dia->unsaved = TRUE;
-  dia->modified = FALSE;
-
   dia->display_count = 0;
   dia->displays = NULL;
 
-  dia->undo = new_undo_stack(dia);
-  
-  open_diagrams = g_list_prepend(open_diagrams, dia);
-  layer_dialog_update_diagram_list();
+  diagram_init(dia, filename);
+
   return dia;
 }
 
Index: app/diagram.h
===================================================================
RCS file: /cvs/gnome/dia/app/diagram.h,v
retrieving revision 1.17
diff -u -r1.17 diagram.h
--- app/diagram.h       2000/10/12 17:45:07     1.17
+++ app/diagram.h       2001/01/12 00:13:46
@@ -47,6 +47,7 @@
 extern GList *open_diagrams; /* Read only! */
 
 Diagram *diagram_load(const char *filename, DiaImportFilter *ifilter);
+int diagram_load_into (Diagram *dest, const char *filename, DiaImportFilter *ifilter);
 Diagram *new_diagram(const char *filename); /*Note: filename is copied*/
 void diagram_destroy(Diagram *dia);
 void diagram_modified(Diagram *dia);
Index: app/paginate_gnomeprint.c
===================================================================
RCS file: /cvs/gnome/dia/app/paginate_gnomeprint.c,v
retrieving revision 1.6
diff -u -r1.6 paginate_gnomeprint.c
--- app/paginate_gnomeprint.c   2000/10/14 10:18:02     1.6
+++ app/paginate_gnomeprint.c   2001/01/12 00:13:46
@@ -130,7 +130,7 @@
       nobjs += print_page(dia->data, rend, &page_bounds, xpos, ypos);
     }
 
-  free(rend);
+  g_free(rend);
 
   gnome_print_context_close(ctx);
 

-- 
 [EMAIL PROTECTED]  <><, Pseudo Engineer, itinerant idiot

Reply via email to