From 0a8d048b97b2efcb3faff5da534359cbcf6f2270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20K=C3=B6hler?= Date: Mon, 6 Mar 2006 21:52:33 +0000 Subject: [PATCH] Add printing support to graphs (depends on #332884). Remove paper from PrintSession. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13504 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 13 ++++++ src/gnome-utils/gnc-html-graph-gog.c | 65 ++++++++++++++++++---------- src/gnome-utils/gnc-html.c | 2 +- src/gnome-utils/gnc-html.h | 5 +-- src/gnome-utils/print-session.c | 8 ++-- src/gnome-utils/print-session.h | 2 - 6 files changed, 62 insertions(+), 33 deletions(-) diff --git a/ChangeLog b/ChangeLog index cd1953c80a..0a8308e70c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2006-03-06 Andreas Köhler + + * src/gnome-utils/gnc-html-graph-gog.c: Save the go graph in the + GtkHTMLEmbedded object. Add printing support for the graphs + (depends on #332884). A bit of formatting. + + * src/gnome-utils/gnc-html.[ch]: Correct prototype of + GncHTMLObjectCB to return gboolean. + + * src/gnome-utils/print-session.[ch]: Create a new job with a + default config for the print dialog. Remove GnomePrintPaper + *paper from the PrintSession. + 2006-03-06 Christian Stimming * src/import-export/ofx/gnc-ofx-import.c: Fix OFX import problem diff --git a/src/gnome-utils/gnc-html-graph-gog.c b/src/gnome-utils/gnc-html-graph-gog.c index 336659a8bf..66270812ca 100644 --- a/src/gnome-utils/gnc-html-graph-gog.c +++ b/src/gnome-utils/gnc-html-graph-gog.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -52,10 +53,9 @@ /** * TODO: * - scatter-plot marker selection - * - series-color, all plots (or drop feature) + * - series-color, piecharts (hard, not really supported by GOG) + * and scatters (or drop feature) * - title-string freeing (fixmes) - * - string rotation on y-axis-label and x-axis-element lables. - * (not supported by GOG?) * - general graph cleanup **/ @@ -65,6 +65,8 @@ static int handle_piechart(gnc_html * html, GtkHTMLEmbedded * eb, gpointer d); static int handle_barchart(gnc_html * html, GtkHTMLEmbedded * eb, gpointer d); static int handle_scatter(gnc_html * html, GtkHTMLEmbedded * eb, gpointer d); +static void draw_print_cb(GtkHTMLEmbedded *eb, GnomePrintContext *context, gpointer graph); + static gboolean create_basic_plot_elements(const char *plot_type, GogObject **out_graph, GogObject **out_chart, GogPlot **out_plot); static double * read_doubles(const char * string, int nvalues); @@ -155,18 +157,18 @@ read_strings(const char * string, int nvalues) } static void -addPixbufGraphWidget( GtkHTMLEmbedded *eb, GogObject *graph ) +add_pixbuf_graph_widget( GtkHTMLEmbedded *eb, GogObject *graph ) { GtkWidget *widget; - GogRenderer *pixbufRend; + GogRendererPixbuf *pixbuf_renderer; GdkPixbuf *buf; - gboolean updateStatus; + gboolean update_status; // Note that this shouldn't be necessary as per discussion with Jody... // ... but it is because we don't embed in a control which passes the // update requests back to the graph widget, a-la the foo-canvas that // gnumeric uses. We probably _should_ do something like that, though. - gog_object_update( GOG_OBJECT(graph) ); + gog_object_update (GOG_OBJECT (graph)); #if 0 // example SVG use. Also, nice for debugging. @@ -180,18 +182,23 @@ addPixbufGraphWidget( GtkHTMLEmbedded *eb, GogObject *graph ) } #endif // 0 - pixbufRend = g_object_new( GOG_RENDERER_PIXBUF_TYPE, - "model", graph, - NULL ); - updateStatus = gog_renderer_pixbuf_update( GOG_RENDERER_PIXBUF(pixbufRend), eb->width, eb->height, 1. ); - buf = gog_renderer_pixbuf_get(GOG_RENDERER_PIXBUF(pixbufRend)); - widget = gtk_image_new_from_pixbuf( buf ); - gtk_widget_set_size_request( widget, eb->width, eb->height ); - gtk_widget_show_all( widget ); - gtk_container_add( GTK_CONTAINER(eb), widget ); + pixbuf_renderer = GOG_RENDERER_PIXBUF (g_object_new (GOG_RENDERER_PIXBUF_TYPE, + "model", graph, + NULL)); + update_status = gog_renderer_pixbuf_update (pixbuf_renderer, + eb->width, eb->height, 1.0); + buf = gog_renderer_pixbuf_get (pixbuf_renderer); + widget = gtk_image_new_from_pixbuf (buf); + gtk_widget_set_size_request (widget, eb->width, eb->height); + gtk_widget_show_all (widget); + gtk_container_add (GTK_CONTAINER (eb), widget); // blindly copied from gnc-html-guppi.c.. - gtk_widget_set_size_request(GTK_WIDGET(eb), eb->width, eb->height); + gtk_widget_set_size_request (GTK_WIDGET (eb), eb->width, eb->height); + + g_object_set_data_full (G_OBJECT (eb), "graph", graph, g_object_unref); + g_signal_connect (G_OBJECT (eb), "draw_print", + G_CALLBACK (draw_print_cb), NULL); } static gboolean @@ -297,7 +304,7 @@ gtkhtml_3_3_2_bug_workaround(GtkHTMLEmbedded *eb) * slice_urls_[123]: ? * legend_urls_[123]: ? */ -static int +static gboolean handle_piechart(gnc_html * html, GtkHTMLEmbedded * eb, gpointer d) { GogObject *graph, *chart; @@ -348,7 +355,7 @@ handle_piechart(gnc_html * html, GtkHTMLEmbedded * eb, gpointer d) // fixme: colors set_chart_titles_from_hash(chart, eb); - addPixbufGraphWidget(eb, graph); + add_pixbuf_graph_widget (eb, graph); return TRUE; } @@ -365,7 +372,7 @@ handle_piechart(gnc_html * html, GtkHTMLEmbedded * eb, gpointer d) * rotate_row_labels:boolean * stacked:boolean **/ -static int +static gboolean handle_barchart(gnc_html * html, GtkHTMLEmbedded * eb, gpointer d) { GogObject *graph, *chart; @@ -482,13 +489,13 @@ handle_barchart(gnc_html * html, GtkHTMLEmbedded * eb, gpointer d) // we need to do this twice for the barchart... :p gog_object_update (GOG_OBJECT (graph)); - addPixbufGraphWidget (eb, graph); + add_pixbuf_graph_widget (eb, graph); PINFO("barchart rendered."); return TRUE; } -static int +static gboolean handle_scatter(gnc_html * html, GtkHTMLEmbedded * eb, gpointer d) { GogObject *graph, *chart; @@ -534,7 +541,19 @@ handle_scatter(gnc_html * html, GtkHTMLEmbedded * eb, gpointer d) // And twice for the scatter, too... :p gog_object_update(GOG_OBJECT(graph)); - addPixbufGraphWidget(eb, graph); + add_pixbuf_graph_widget (eb, graph); return TRUE; } + +static void +draw_print_cb (GtkHTMLEmbedded *eb, GnomePrintContext *context, gpointer d) +{ + GogGraph *graph = GOG_GRAPH (g_object_get_data (G_OBJECT (eb), "graph")); + + /* assuming pixel size is 0.5, cf. gtkhtml/src/htmlprinter.c */ + gnome_print_scale (context, 0.5, 0.5); + + gnome_print_translate (context, 0, eb->height); + gog_graph_print_to_gnome_print (graph, context, eb->width, eb->height); +} diff --git a/src/gnome-utils/gnc-html.c b/src/gnome-utils/gnc-html.c index abdb53b124..1416ffe2f0 100644 --- a/src/gnome-utils/gnc-html.c +++ b/src/gnome-utils/gnc-html.c @@ -686,7 +686,7 @@ gnc_html_url_requested_cb(GtkHTML * html, char * url, * loaded. ********************************************************************/ -static int +static gboolean gnc_html_object_requested_cb(GtkHTML * html, GtkHTMLEmbedded * eb, gpointer data) { diff --git a/src/gnome-utils/gnc-html.h b/src/gnome-utils/gnc-html.h index 384024ad77..f8a1227594 100644 --- a/src/gnome-utils/gnc-html.h +++ b/src/gnome-utils/gnc-html.h @@ -78,10 +78,9 @@ typedef void (* GncHTMLLoadCB)(gnc_html * html, URLType type, gpointer data); typedef int (* GncHTMLButtonCB)(gnc_html * html, GdkEventButton * event, gpointer data); -//#if 0 -typedef int (* GncHTMLObjectCB)(gnc_html * html, GtkHTMLEmbedded * eb, + +typedef gboolean (* GncHTMLObjectCB)(gnc_html * html, GtkHTMLEmbedded * eb, gpointer data); -//#endif typedef int (* GncHTMLActionCB)(gnc_html * html, const char * method, const char * action, GHashTable * form_data); typedef gboolean (* GncHTMLStreamCB)(const char *location, char **data, int *datalen); diff --git a/src/gnome-utils/print-session.c b/src/gnome-utils/print-session.c index 1c81665464..6764a0b991 100644 --- a/src/gnome-utils/print-session.c +++ b/src/gnome-utils/print-session.c @@ -28,9 +28,7 @@ #include #include #include -#include -#include "gnc-ui.h" #include "print-session.h" @@ -43,19 +41,21 @@ gnc_print_session_create(gboolean hand_built_pages) gint response; /* Ask the user what to do with the output */ + config = gnome_print_config_default(); + ps->job = gnome_print_job_new(config); + g_object_unref(config); dialog = gnome_print_dialog_new(ps->job, (guchar *) _("Print GnuCash Document"), 0); response = gtk_dialog_run(GTK_DIALOG(dialog)); switch (response) { case GNOME_PRINT_DIALOG_RESPONSE_PRINT: case GNOME_PRINT_DIALOG_RESPONSE_PREVIEW: - config = gnome_print_dialog_get_config (GNOME_PRINT_DIALOG (dialog)); gtk_widget_destroy(dialog); - ps->job = gnome_print_job_new(config); ps->context = gnome_print_job_get_context(ps->job); break; default: gtk_widget_destroy(dialog); + g_object_unref(ps->job); g_free(ps); return NULL; } diff --git a/src/gnome-utils/print-session.h b/src/gnome-utils/print-session.h index 1caf3fc978..52060ff4b3 100644 --- a/src/gnome-utils/print-session.h +++ b/src/gnome-utils/print-session.h @@ -33,7 +33,6 @@ #include #include -#include #include #include @@ -44,7 +43,6 @@ typedef struct { GnomePrintJob * job; GnomePrintContext * context; /* Convenience only. Owned by the job */ GnomeFont * default_font; - GnomePrintPaper * paper; } PrintSession;