diff options
author | Matthew Barnes <mbarnes@src.gnome.org> | 2007-04-20 14:57:55 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@src.gnome.org> | 2007-04-20 14:57:55 +0800 |
commit | 4a044a636e418f4c95a85819aa92316e21f58b35 (patch) | |
tree | fed737c87045e269aa840b770172fb798682fd10 | |
parent | ba064da784cd29692e0db6d4560c7e7a8c68aeeb (diff) | |
download | gsoc2013-evolution-4a044a636e418f4c95a85819aa92316e21f58b35.tar.gz gsoc2013-evolution-4a044a636e418f4c95a85819aa92316e21f58b35.tar.zst gsoc2013-evolution-4a044a636e418f4c95a85819aa92316e21f58b35.zip |
Clean up printing in Evolution (bug #426816)
svn path=/trunk/; revision=33440
40 files changed, 1417 insertions, 2363 deletions
@@ -1,3 +1,8 @@ +2007-04-20 Matthew Barnes <mbarnes@redhat.com> + + * configure.in: + Evolution no longer depends on libgnomeprint[ui]. (#426816) + 2007-04-11 Matthew Barnes <mbarnes@redhat.com> * configure.in: diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index 1dae147ff8..f357e37235 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,3 +1,27 @@ +2007-04-20 Matthew Barnes <mbarnes@redhat.com> + + ** Fixes part of bug #426816 + + * gui/component/addressbook-view.c: + * gui/widgets/e-addressbook-view.c: + * gui/widgets/e-addressbook-view.h: + * printing/e-contact-print.c: + * printing/e-contact-print.h: + * printing/e-contact-print-types.h: + Refactor the printing infrastructure. + Migrate off of libgnomeprint[ui] once and for all. + + * printing/test-print.c: + Migrate off of libgnomeprint[ui] once and for all. + + * printing/e-contact-print-envelope.c: + * printing/e-contact-print-envelope.h: + This module is unused. Disable it, but keep the logic around for + future reference. + + * printing/Makefile.am: + Remove e-contact-print-envelope.[ch]. + 2007-04-19 Matthew Barnes <mbarnes@redhat.com> ** Fixes part of bug #429422 diff --git a/addressbook/gui/component/addressbook-view.c b/addressbook/gui/component/addressbook-view.c index 7defe5e42b..53a5453e1c 100644 --- a/addressbook/gui/component/addressbook-view.c +++ b/addressbook/gui/component/addressbook-view.c @@ -193,7 +193,7 @@ print_cb (BonoboUIComponent *uih, void *user_data, const char *path) AddressbookView *view = (AddressbookView *) user_data; EABView *v = get_current_view (view); if (v) - eab_view_print (v, 0); + eab_view_print (v, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG); } static void @@ -202,7 +202,7 @@ print_preview_cb (BonoboUIComponent *uih, void *user_data, const char *path) AddressbookView *view = (AddressbookView *) user_data; EABView *v = get_current_view (view); if (v) - eab_view_print_preview (v); + eab_view_print (v, GTK_PRINT_OPERATION_ACTION_PREVIEW); } static void diff --git a/addressbook/gui/widgets/e-addressbook-view.c b/addressbook/gui/widgets/e-addressbook-view.c index 282f142a77..14019d582b 100644 --- a/addressbook/gui/widgets/e-addressbook-view.c +++ b/addressbook/gui/widgets/e-addressbook-view.c @@ -37,11 +37,6 @@ #include <e-util/e-icon-factory.h> #include <libgnomeui/gnome-dialog-util.h> -#include <libgnomeprint/gnome-print.h> -#include <libgnomeprint/gnome-print-job.h> -#include <libgnomeprintui/gnome-print-dialog.h> -#include <libgnomeprintui/gnome-print-job-preview.h> - #include "addressbook/printing/e-contact-print.h" #include "addressbook/printing/e-contact-print-envelope.h" #include "addressbook/gui/widgets/eab-popup.h" @@ -81,7 +76,6 @@ #include <libxml/tree.h> #include <libxml/parser.h> -#include <gtk/gtkprintunixdialog.h> #define SHOW_ALL_SEARCH "(contains \"x-evolution-any-field\" \"\")" @@ -121,7 +115,6 @@ static void query_changed (ESearchBar *esb, EABView *view); static void search_activated (ESearchBar *esb, EABView *view); static void search_menu_activated (ESearchBar *esb, int id, EABView *view); static GList *get_master_list (void); -static void contact_print_button_draw_page (GtkPrintOperation *print, GtkPrintContext *context, gint page_nr,EPrintable *printable); #define PARENT_TYPE GTK_TYPE_VBOX static GtkVBoxClass *parent_class = NULL; @@ -874,17 +867,13 @@ print (EPopup *ep, EPopupItem *pitem, void *data) { /*ContactAndBook *contact_and_book = data;*/ EABPopupTargetSelect *t = (EABPopupTargetSelect *)ep->target; - GtkWidget *dialog; + GList *contact_list; - if (t->cards->len == 1) { - dialog = e_contact_print_contact_dialog_new(t->cards->pdata[0]); - e_contact_print_response (dialog, GTK_RESPONSE_OK, NULL); - } else { - GList *contacts = get_contact_list(t); - dialog = e_contact_print_contact_list_dialog_new (contacts); - e_contact_print_response (dialog, GTK_RESPONSE_OK, NULL); - g_list_free(contacts); - } + contact_list = get_contact_list (t); + e_contact_print ( + NULL, NULL, contact_list, + GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG); + g_list_free (contact_list); } static void @@ -1703,77 +1692,46 @@ get_master_list (void) return category_list; } -typedef struct { - GtkWidget *table; - GObject *printable; -} EContactPrintDialogWeakData; - static void -e_contact_print_destroy(gpointer data, GObject *where_object_was) +contact_print_button_draw_page (GtkPrintOperation *operation, + GtkPrintContext *context, + gint page_nr, + EPrintable *printable) { - EContactPrintDialogWeakData *weak_data = data; - g_object_unref (weak_data->printable); - g_object_unref (weak_data->table); - g_free (weak_data); + GtkPageSetup *setup; + gdouble top_margin; + cairo_t *cr; + + setup = gtk_print_context_get_page_setup (context); + top_margin = gtk_page_setup_get_top_margin (setup, GTK_UNIT_POINTS); + + cr = gtk_print_context_get_cairo_context (context); + + e_printable_reset (printable); + + while (e_printable_data_left (printable)) { + cairo_save (cr); + e_printable_print_page ( + printable, context, 6.5 * 72, top_margin + 10, TRUE); + cairo_restore (cr); + } } static void -e_contact_print_button(GtkDialog *dialog, gint response, gpointer data) -{ -#ifdef G_OS_UNIX /* Just to get it to build on Win32 */ - GtkPrintOperation *print; - GtkPrintSettings *settings; - GtkPageSetup *page_setup; - GtkPaperSize *paper_size; - - EPrintable *printable = g_object_get_data(G_OBJECT(dialog), "printable"); - print = gtk_print_operation_new (); - page_setup = gtk_page_setup_new (); - - /*get & set,the settings of the dialog */ - settings = gtk_print_unix_dialog_get_settings (GTK_PRINT_UNIX_DIALOG (dialog)); - paper_size = gtk_paper_size_new ("iso_a4"); /* FIXME paper size hardcoded */ - gtk_page_setup_set_paper_size (page_setup, paper_size); - gtk_print_operation_set_print_settings (print, settings); - - gtk_print_operation_set_n_pages (print, 1); - gtk_print_operation_set_default_page_setup (print, page_setup); - /* run the dialog */ - g_signal_connect (print,"draw_page",G_CALLBACK(contact_print_button_draw_page), printable); - - if (response == GTK_RESPONSE_APPLY) - gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PREVIEW, NULL, NULL); - else - gtk_print_operation_run (print,GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL,NULL); - - gtk_widget_destroy(dialog); - g_object_unref (print); -#else - g_warning ("Not implemented currently on Windows"); -#endif -} +e_contact_print_button (EPrintable *printable, GtkPrintOperationAction action) +{ + GtkPrintOperation *operation; -static void -contact_print_button_draw_page (GtkPrintOperation *print, GtkPrintContext *context, gint page_nr,EPrintable *printable) + operation = e_print_operation_new (); + gtk_print_operation_set_n_pages (operation, 1); -{ - cairo_t *cr; - GtkPageSetup *page_setup; - gdouble top_margin; - - cr = gtk_print_context_get_cairo_context (context); - page_setup = gtk_print_operation_get_default_page_setup (print); - top_margin = gtk_page_setup_get_top_margin (page_setup, GTK_UNIT_POINTS); - e_printable_reset(printable); - while (e_printable_data_left(printable)) { - cairo_save (cr); - e_printable_print_page (printable, - context, - 6.5 * 72, - top_margin + 10, - TRUE); - cairo_restore (cr); - } + g_signal_connect ( + operation, "draw_page", + G_CALLBACK (contact_print_button_draw_page), printable); + + gtk_print_operation_run (operation, action, NULL, NULL); + + g_object_unref (operation); } void @@ -1838,110 +1796,44 @@ eab_view_discard_menus (EABView *view) } void -eab_view_print(EABView *view, int preview) +eab_view_print (EABView *view, GtkPrintOperationAction action) { if (view->view_type == EAB_VIEW_MINICARD) { - char *query; EBook *book; - GtkWidget *print; - GList *list; - - g_object_get (view->model, - "query", &query, - "book", &book, - NULL); - list = get_selected_contacts (view); - print = e_contact_print_dialog_new (book, query, list); - - if (!preview) - e_contact_print_response (print, GTK_RESPONSE_OK, NULL); - else - e_contact_print_response (print, GTK_RESPONSE_APPLY, NULL); - - g_free (query); - g_list_foreach (list, (GFunc) g_object_unref, NULL); - g_list_free (list); - } - else if (view->view_type == EAB_VIEW_TABLE) { - GtkWidget *dialog; - EPrintable *printable; - ETable *etable; - EContactPrintDialogWeakData *weak_data; - - /* FIXME: Allow range selection in table views, as in minicard view */ - dialog = e_print_get_dialog (_("Print cards"), 0); + EBookQuery *query; + gchar *query_string; + GList *contact_list; - g_object_get(view->widget, "table", &etable, NULL); - printable = e_table_get_printable(etable); - g_object_ref_sink (printable); - g_object_unref(etable); - g_object_ref (view->widget); + g_object_get ( + view->model, "query", &query_string, + "book", &book, NULL); - g_object_set_data (G_OBJECT (dialog), "table", view->widget); - g_object_set_data (G_OBJECT (dialog), "printable", printable); - - weak_data = g_new (EContactPrintDialogWeakData, 1); - weak_data->table = view->widget; - weak_data->printable = G_OBJECT (printable); - g_object_weak_ref (G_OBJECT (dialog), e_contact_print_destroy, weak_data); - if (preview) - e_contact_print_button (dialog, GTK_RESPONSE_APPLY, NULL); + if (query_string != NULL) + query = e_book_query_from_string (query_string); else - e_contact_print_button (dialog, GTK_RESPONSE_OK, NULL); - } -#ifdef WITH_ADDRESSBOOK_VIEW_TREEVIEW - else if (view->view_type == EAB_VIEW_TREEVIEW) { - /* XXX */ - } -#endif -} + query = NULL; + g_free (query_string); -void -eab_view_print_preview(EABView *view) -{ - if (view->view_type == EAB_VIEW_MINICARD) { - char *query; - EBook *book; - GtkWidget *dialog; - GList *list; + contact_list = get_selected_contacts (view); + e_contact_print (book, query, contact_list, action); + g_list_foreach (contact_list, (GFunc) g_object_unref, NULL); + g_list_free (contact_list); - g_object_get (view->model, - "query", &query, - "book", &book, - NULL); + if (query != NULL) + e_book_query_unref (query); - list = get_selected_contacts (view); - if (list != NULL) - dialog = e_contact_print_contact_list_dialog_new (list); - else - dialog = e_contact_print_dialog_new (book, query, list); - e_contact_print_response (dialog, GTK_RESPONSE_APPLY, NULL); - g_list_foreach (list, (GFunc) g_object_unref, NULL); - g_list_free (list); - g_free (query); - }else if (view->view_type == EAB_VIEW_TABLE) { - GtkWidget *dialog; + } else if (view->view_type == EAB_VIEW_TABLE) { EPrintable *printable; - ETable *etable; - EContactPrintDialogWeakData *weak_data; + ETable *table; - /* FIXME: Allow range selection in table views, as in minicard view */ - dialog = e_print_get_dialog (_("Print cards"), 0); - - g_object_get(view->widget, "table", &etable, NULL); - printable = e_table_get_printable(etable); + g_object_get (view->widget, "table", &table, NULL); + printable = e_table_get_printable (table); g_object_ref_sink (printable); - g_object_unref(etable); - g_object_ref (view->widget); + g_object_unref (table); - g_object_set_data (G_OBJECT (dialog), "table", view->widget); - g_object_set_data (G_OBJECT (dialog), "printable", printable); - - weak_data = g_new (EContactPrintDialogWeakData, 1); - weak_data->table = view->widget; - weak_data->printable = G_OBJECT (printable); - g_object_weak_ref (G_OBJECT (dialog), e_contact_print_destroy, weak_data); - e_contact_print_button (dialog, GTK_RESPONSE_APPLY, NULL); + e_contact_print_button (printable, action); + + g_object_unref (printable); } } diff --git a/addressbook/gui/widgets/e-addressbook-view.h b/addressbook/gui/widgets/e-addressbook-view.h index 0f674c9edd..b525e97ed0 100644 --- a/addressbook/gui/widgets/e-addressbook-view.h +++ b/addressbook/gui/widgets/e-addressbook-view.h @@ -130,8 +130,8 @@ void eab_view_save_as (EABView *view, gboolean all); void eab_view_view (EABView *view); void eab_view_send (EABView *view); void eab_view_send_to (EABView *view); -void eab_view_print (EABView *view, int preview); -void eab_view_print_preview (EABView *view); +void eab_view_print (EABView *view, + GtkPrintOperationAction action); void eab_view_delete_selection (EABView *view, gboolean is_delete); void eab_view_cut (EABView *view); void eab_view_copy (EABView *view); diff --git a/addressbook/printing/Makefile.am b/addressbook/printing/Makefile.am index 0f3a3e85f3..6113519b2f 100644 --- a/addressbook/printing/Makefile.am +++ b/addressbook/printing/Makefile.am @@ -22,8 +22,6 @@ noinst_LTLIBRARIES = \ libecontactprint.la libecontactprint_la_SOURCES = \ - e-contact-print-envelope.c \ - e-contact-print-envelope.h \ e-contact-print-style-editor.c \ e-contact-print-style-editor.h \ e-contact-print-types.h \ diff --git a/addressbook/printing/e-contact-print-envelope.c b/addressbook/printing/e-contact-print-envelope.c index 1c9b210a97..eabe41aa48 100644 --- a/addressbook/printing/e-contact-print-envelope.c +++ b/addressbook/printing/e-contact-print-envelope.c @@ -19,16 +19,17 @@ * Boston, MA 02111-1307, USA. */ +/* XXX Keeping the rendering code around for future reference, + * but it needs a lot of work to make it usable again. */ + +#if 0 + #include <config.h> #include "addressbook/printing/e-contact-print-envelope.h" #include <glib.h> #include <glib/gi18n.h> #include <libgnomeui/gnome-dialog.h> #include <time.h> -#include <libgnomeprintui/gnome-print-dialog.h> -#include <libgnomeprint/gnome-print.h> -#include <libgnomeprint/gnome-print-job.h> -#include <libgnomeprintui/gnome-print-job-preview.h> #include <e-util/e-print.h> #define ENVELOPE_HEIGHT (72.0 * 4.0) @@ -123,12 +124,6 @@ ecpe_linelist_print(GnomePrintContext *pc, GnomeFont *font, char *address, EcpeL } } -static gint -e_contact_print_envelope_close(GnomeDialog *dialog, gpointer data) -{ - return FALSE; -} - static void ecpe_print(GnomePrintContext *pc, EContact *contact, gboolean as_return) { @@ -166,78 +161,4 @@ ecpe_print(GnomePrintContext *pc, EContact *contact, gboolean as_return) gnome_print_context_close(pc); } -static void -e_contact_print_envelope_button(GnomeDialog *dialog, gint button, gpointer data) -{ - GnomePrintJob *master; - GnomePrintContext *pc; - GnomePrintConfig *config; - EContact *contact = NULL; - GtkWidget *preview; - - contact = g_object_get_data(G_OBJECT(dialog), "contact"); - - switch( button ) { - case GNOME_PRINT_DIALOG_RESPONSE_PRINT: - config = gnome_print_dialog_get_config (GNOME_PRINT_DIALOG (dialog)); - master = gnome_print_job_new (config); - pc = gnome_print_job_get_context( master ); - - ecpe_print(pc, contact, FALSE); - - gnome_print_job_print(master); - gnome_dialog_close(dialog); - break; - case GNOME_PRINT_DIALOG_RESPONSE_PREVIEW: - config = gnome_print_dialog_get_config (GNOME_PRINT_DIALOG (dialog)); - master = gnome_print_job_new (config); - pc = gnome_print_job_get_context( master ); - - ecpe_print(pc, contact, FALSE); - - preview = GTK_WIDGET(gnome_print_job_preview_new(master, "Print Preview")); - gtk_widget_show_all(preview); - break; - case GNOME_PRINT_DIALOG_RESPONSE_CANCEL: - g_object_unref(contact); - gnome_dialog_close(dialog); - break; - } -} - -GtkWidget * -e_contact_print_envelope_dialog_new(EContact *contact) -{ - GtkWidget *dialog; - - dialog = e_print_get_dialog (_("Print envelope"), GNOME_PRINT_DIALOG_COPIES); - - contact = e_contact_duplicate(contact); - g_object_set_data(G_OBJECT(dialog), "contact", contact); - g_signal_connect(dialog, - "clicked", G_CALLBACK(e_contact_print_envelope_button), NULL); - g_signal_connect(dialog, - "close", G_CALLBACK(e_contact_print_envelope_close), NULL); - return dialog; -} - -/* FIXME: Print all the contacts selected. */ -GtkWidget * -e_contact_print_envelope_list_dialog_new(GList *list) -{ - GtkWidget *dialog; - EContact *contact; - - if (list == NULL) - return NULL; - - dialog = e_print_get_dialog(_("Print envelope"), GNOME_PRINT_DIALOG_COPIES); - - contact = e_contact_duplicate(list->data); - g_object_set_data(G_OBJECT(dialog), "contact", contact); - g_signal_connect(dialog, - "clicked", G_CALLBACK(e_contact_print_envelope_button), NULL); - g_signal_connect(dialog, - "close", G_CALLBACK(e_contact_print_envelope_close), NULL); - return dialog; -} +#endif diff --git a/addressbook/printing/e-contact-print-envelope.h b/addressbook/printing/e-contact-print-envelope.h index a7a8492638..05009b9035 100644 --- a/addressbook/printing/e-contact-print-envelope.h +++ b/addressbook/printing/e-contact-print-envelope.h @@ -22,11 +22,6 @@ #ifndef E_CONTACT_PRINT_ENVELOPE_H #define E_CONTACT_PRINT_ENVELOPE_H -#include <gtk/gtkwidget.h> -#include <libebook/e-contact.h> -#include "e-contact-print-types.h" - -GtkWidget *e_contact_print_envelope_dialog_new(EContact *contact); -GtkWidget *e_contact_print_envelope_list_dialog_new(GList *list); +/* XXX Currently unused */ #endif /* E_CONTACT_PRINT_ENVELOPE_H */ diff --git a/addressbook/printing/e-contact-print-types.h b/addressbook/printing/e-contact-print-types.h index 5aafa96d40..d1fe68e745 100644 --- a/addressbook/printing/e-contact-print-types.h +++ b/addressbook/printing/e-contact-print-types.h @@ -23,8 +23,6 @@ #define E_CONTACT_PRINT_TYPES_H #include <glib.h> -#include <libgnomeprint/gnome-font.h> -#include <libgnomeprint/gnome-print-pango.h> typedef struct _EContactPrintStyle EContactPrintStyle; typedef enum _EContactPrintType EContactPrintType; diff --git a/addressbook/printing/e-contact-print.c b/addressbook/printing/e-contact-print.c index 32098689d9..002e284366 100644 --- a/addressbook/printing/e-contact-print.c +++ b/addressbook/printing/e-contact-print.c @@ -33,19 +33,11 @@ #include <libxml/xmlmemory.h> #include <libgnome/gnome-util.h> #include <glib/gi18n.h> -#include <libgnomeui/gnome-dialog.h> -#include <libgnomeprint/gnome-print.h> -#include <libgnomeprint/gnome-print-unit.h> -#include <libgnomeprint/gnome-print-config.h> -#include <libgnomeprint/gnome-font.h> -#include <libgnomeprint/gnome-print-job.h> -#include <libgnomeprintui/gnome-print-dialog.h> -#include <libgnomeprintui/gnome-print-job-preview.h> #include <libebook/e-book.h> #include <libebook/e-contact.h> #include <gtk/gtk.h> -#include <gtk/gtkprintunixdialog.h> +#include <libedataserver/e-flag.h> #include <libedataserver/e-xml-utils.h> #include "e-util/e-print.h" @@ -53,556 +45,340 @@ #include "e-util/e-util-private.h" #include "e-contact-print.h" - -#define SCALE 5 -#define HYPHEN_PIXELS 20 -#define HYPHEN_PENALTY ( (SCALE) * (SCALE) * (HYPHEN_PIXELS) * (HYPHEN_PIXELS) ) typedef struct _EContactPrintContext EContactPrintContext; typedef struct _ContactPrintItem ContactPrintItem; struct _EContactPrintContext { - GtkPrintContext *pc; - GtkPrintOperation *print; - GnomePrintJob *master; - PangoLayout *pl; + GtkPrintContext *context; gdouble x; gdouble y; gint column; + gdouble column_width; + gdouble column_spacing; EContactPrintStyle *style; gboolean first_section; PangoFontDescription *letter_heading_font; - char *character; + gchar *section; gboolean first_contact; - gboolean uses_book; - int type; - gint response_id; EBook *book; EBookQuery *query; - GList *contacts; -}; - -struct _ContactPrintItem -{ - EContactPrintContext *ctxt; - EContactPrintStyle *style; - EContact *contact; GList *contact_list; - EBook *book; - GtkPrintSettings *settings; - gboolean uses_book, uses_list; }; -static void -contact_draw_page (GtkPrintOperation *print, GtkPrintContext *context, gint page_nr, ContactPrintItem *cpi); - -static void -print_func (EBookView *book_view, const GList *contacts, EContactPrintContext *ctxt); - -static double -get_font_height (PangoFontDescription *font) +static gdouble +get_font_height (PangoFontDescription *desc) { - return (double)pango_font_description_get_size (font)/(double)PANGO_SCALE; + return pango_units_to_double ( + pango_font_description_get_size (desc)); } -static double -get_font_width (EContactPrintContext *context, PangoFontDescription *font, const char *text) +static gdouble +get_font_width (GtkPrintContext *context, + PangoFontDescription *desc, + const gchar *text) { - int width; - int height; + PangoLayout *layout; + gint width, height; - g_return_val_if_fail (font, 0.0); - g_return_val_if_fail (text, 0.0); + g_return_val_if_fail (desc, .0); + g_return_val_if_fail (text, .0); - g_assert (context->pl); - pango_layout_set_font_description (context->pl, font); - pango_layout_set_text (context->pl, text, -1); - pango_layout_set_width (context->pl, -1); - pango_layout_set_indent (context->pl, 0); + layout = gtk_print_context_create_pango_layout (context); - pango_layout_get_size (context->pl, - &width, - &height); + pango_layout_set_font_description (layout, desc); + pango_layout_set_text (layout, text, -1); + pango_layout_set_width (layout, -1); + pango_layout_set_indent (layout, 0); - return (double)width/(double)PANGO_SCALE; -} + pango_layout_get_size (layout, &width, &height); -static PangoFontDescription* -find_font (const char *name, double height) -{ - PangoFontDescription *desc = pango_font_description_new (); - pango_font_description_set_family (desc, name); - pango_font_description_set_size (desc, height * PANGO_SCALE); + g_object_unref (layout); - return desc; + return pango_units_to_double (width); } -static PangoFontDescription* -find_closest_font_from_weight_slant (const guchar *family, GnomeFontWeight weight, gboolean italic, gdouble size) +static void +e_contact_output (GtkPrintContext *context, + PangoFontDescription *font, + gdouble x, gdouble y, gdouble width, + const gchar *text) { - PangoFontDescription *desc = pango_font_description_new (); - pango_font_description_set_family (desc, family); - - /* GnomePrintWeight and PangoWeight values should be interchangeable: */ - pango_font_description_set_weight (desc, (PangoWeight)weight); + PangoLayout *layout; + gdouble indent; + cairo_t *cr; - if (italic) { - pango_font_description_set_style (desc, PANGO_STYLE_ITALIC); - } - pango_font_description_set_size (desc, size * PANGO_SCALE); + layout = gtk_print_context_create_pango_layout (context); - return desc; -} + if (width == -1 || get_font_width (context, font, text) <= width) + indent = .0; + else + indent = get_font_width (context, font, " "); -static void -e_contact_output(EContactPrintContext *ctxt, PangoFontDescription *font, double x, double y, double width, const gchar *text) -{ - double indent; - cairo_t *cr = gtk_print_context_get_cairo_context (ctxt->pc); - cairo_save(cr); + pango_layout_set_font_description (layout, font); + pango_layout_set_text (layout, text, -1); + pango_layout_set_width (layout, pango_units_from_double (width)); + pango_layout_set_indent (layout, pango_units_from_double (indent)); - if ( width == -1 || get_font_width(ctxt, font, text) <= width ) { - indent = 0.0; - } else { - indent = get_font_width (ctxt, font, " "); - } + cr = gtk_print_context_get_cairo_context (context); - g_assert (ctxt->pl); - pango_layout_set_font_description (ctxt->pl, font); - pango_layout_set_text (ctxt->pl, text, -1); - pango_layout_set_width (ctxt->pl, width*PANGO_SCALE); - pango_layout_set_indent (ctxt->pl, indent*PANGO_SCALE); - - cairo_move_to(cr, x, y); - pango_cairo_show_layout (cr, ctxt->pl); + cairo_save (cr); + cairo_move_to (cr, x, y); + pango_cairo_show_layout (cr, layout); cairo_restore (cr); + g_object_unref (layout); } static gdouble -e_contact_text_height(EContactPrintContext *ctxt, PangoFontDescription *font, double width, const gchar *text) +e_contact_text_height (GtkPrintContext *context, + PangoFontDescription *desc, + const gchar *text) { - gint w, h; + PangoLayout *layout; + gint width, height; - g_assert (ctxt->pl); - pango_layout_set_font_description (ctxt->pl, font); - pango_layout_set_text (ctxt->pl, text, -1); - pango_layout_set_width (ctxt->pl, 1); /* fix me width hard coded */ - pango_layout_set_indent (ctxt->pl, 0); - pango_layout_get_size (ctxt->pl, &w, &h); + layout = gtk_print_context_create_pango_layout (context); - return (double)h/(double)PANGO_SCALE; -} + pango_layout_set_font_description (layout, desc); + pango_layout_set_text (layout, text, -1); -#if 0 -static void -e_contact_output_and_advance(EContactPrintContext *ctxt, PangoFontDescription *font, double x, double width, gchar *text) -{ - ctxt->y -= .1 * get_font_height (font); - e_contact_output(ctxt->pc, font, x, ctxt->y, width, text); - ctxt->y -= e_contact_text_height(ctxt->pc, font, width, text); - ctxt->y -= .1 * get_font_height (font); -} -#endif + pango_layout_get_size (layout, &width, &height); -static void -e_contact_rectangle(GtkPrintContext *pc, - gdouble x0, - gdouble y0, - gdouble x1, - gdouble y1, - gdouble r, - gdouble g, - gdouble b) -{ - cairo_t *cr; - cr = gtk_print_context_get_cairo_context (pc); - cairo_save(cr); - cairo_set_source_rgb(cr, r, g, b); - cairo_rectangle (cr,x0, y0, x1, y1); - cairo_fill (cr); - cairo_restore (cr); -} + g_object_unref (layout); -static double -e_contact_get_letter_heading_height (EContactPrintContext *ctxt) -{ - return get_font_height (ctxt->letter_heading_font); + return pango_units_to_double (height); } static void -e_contact_print_letter_heading (EContactPrintContext *ctxt, gchar *character) +e_contact_print_letter_heading (EContactPrintContext *ctxt, gchar *letter) { - gdouble height; - gdouble width; + PangoLayout *layout; + PangoFontDescription *desc; + PangoFontMetrics *metrics; + gint width, height; cairo_t *cr; - width = get_font_width(ctxt, ctxt->letter_heading_font, "m") * 1.7; - height = get_font_height (ctxt->letter_heading_font); - - cr = gtk_print_context_get_cairo_context (ctxt->pc); - cairo_save(cr); + desc = ctxt->letter_heading_font; - e_contact_rectangle( ctxt->pc, ctxt->x, ctxt->y, width, height + 6, 0, 0, 0); - cairo_set_source_rgb(cr, 1, 1, 1); - ctxt->y += 4; - e_contact_output(ctxt, ctxt->letter_heading_font, - ctxt->x + (width - get_font_width(ctxt, ctxt->letter_heading_font, character))/ 2 - 5, - ctxt->y - 5, - -1, - character); - ctxt->y += height; - ctxt->y += 2; - ctxt->y += 3; - - cairo_restore(cr); -} + layout = gtk_print_context_create_pango_layout (ctxt->context); -static void -e_contact_start_new_page(EContactPrintContext *ctxt) -{ - cairo_t *cr; - cr = gtk_print_context_get_cairo_context (ctxt->pc); - ctxt->x = ctxt->style->left_margin; - ctxt->y = ctxt->style->top_margin; - cairo_show_page (cr); - ctxt->column = 0; -} + /* Make the rectangle thrice the average character width. + * XXX Works well for English, what about other locales? */ + metrics = pango_context_get_metrics ( + pango_layout_get_context (layout), + desc, pango_language_get_default ()); + width = pango_font_metrics_get_approximate_char_width (metrics) * 3; + pango_font_metrics_unref (metrics); -static double -e_contact_get_contact_size(EContact *contact, EContactPrintContext *ctxt) -{ - const char *file_as; - gdouble height = 0; - gdouble page_width = 72 * (ctxt->style->page_width - ctxt->style->left_margin - ctxt->style->right_margin); - gdouble column_width; - gint field; - column_width = (page_width + 18) / ctxt->style->num_columns - 18; + pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER); + pango_layout_set_font_description (layout, desc); + pango_layout_set_text (layout, letter, -1); + pango_layout_set_width (layout, width); + pango_layout_get_size (layout, NULL, &height); - height += get_font_height (ctxt->style->headings_font) * .2; + /* Draw white text centered in a black rectangle. */ - height += get_font_height (ctxt->style->headings_font) * .2; + cr = gtk_print_context_get_cairo_context (ctxt->context); - file_as = e_contact_get_const (contact, E_CONTACT_FILE_AS); + cairo_save (cr); + cairo_set_source_rgb (cr, .0, .0, .0); + cairo_rectangle ( + cr, ctxt->x, ctxt->y, + pango_units_to_double (width), + pango_units_to_double (height)); + cairo_fill (cr); + cairo_restore (cr); - height += e_contact_text_height(ctxt, ctxt->style->headings_font, column_width - 4, file_as); + cairo_save (cr); + cairo_move_to (cr, ctxt->x, ctxt->y); + cairo_set_source_rgb (cr, 1., 1., 1.); + pango_cairo_show_layout (cr, layout); + cairo_restore (cr); - height += get_font_height (ctxt->style->headings_font) * .2; + ctxt->y += pango_units_to_double (height); +} - height += get_font_height (ctxt->style->headings_font) * .2; - - for(field = E_CONTACT_FILE_AS; field != E_CONTACT_LAST_SIMPLE_STRING; field++) { - char *string; - string = e_contact_get(contact, field); - if (string && *string) { - double xoff = 0; - xoff += get_font_width(ctxt, ctxt->style->body_font, e_contact_pretty_name (field)); - xoff += get_font_width(ctxt, ctxt->style->body_font, ": "); - height += e_contact_text_height(ctxt, ctxt->style->body_font, column_width - xoff, string); - height += .2 * get_font_height (ctxt->style->body_font); - } - g_free(string); - } - height += get_font_height (ctxt->style->headings_font) * .4; +static void +e_contact_start_new_page (EContactPrintContext *ctxt) +{ + cairo_t *cr; - /* g_message ("%s %g", e_card_simple_get (simple, E_CARD_SIMPLE_FIELD_FILE_AS), height); */ - return height; -} + cr = gtk_print_context_get_cairo_context (ctxt->context); + cairo_show_page (cr); + + ctxt->x = ctxt->y = .0; + ctxt->column = 0; +} static void e_contact_print_contact (EContact *contact, EContactPrintContext *ctxt) { - gdouble page_width = 72 * (ctxt->style->page_width - ctxt->style->left_margin - ctxt->style->right_margin); - gdouble column_width; char *file_as; cairo_t *cr; int field; - column_width = (page_width + 18) / ctxt->style->num_columns - 18; - cr = gtk_print_context_get_cairo_context (ctxt->pc); + cr = gtk_print_context_get_cairo_context (ctxt->context); cairo_save(cr); ctxt->y += get_font_height (ctxt->style->headings_font) * .2; - ctxt->y += get_font_height (ctxt->style->headings_font) * .2; file_as = e_contact_get (contact, E_CONTACT_FILE_AS); - if (ctxt->style->print_using_grey) - e_contact_rectangle(ctxt->pc, - ctxt->x,ctxt->y + get_font_height (ctxt->style->headings_font) * .3, - column_width, - e_contact_text_height(ctxt, - ctxt->style->headings_font, - column_width - 4, file_as) - + get_font_height (ctxt->style->headings_font) * .3, - .85, .85, .85); - - - e_contact_output(ctxt, ctxt->style->headings_font, ctxt->x + 2, ctxt->y + 5, column_width + 4, file_as); - ctxt->y += e_contact_text_height(ctxt, ctxt->style->headings_font, column_width + 4, file_as); + if (ctxt->style->print_using_grey) { + cairo_save (cr); + cairo_set_source_rgb (cr, .85, .85, .85); + cairo_rectangle (cr, ctxt->x, ctxt->y, ctxt->column_width, + e_contact_text_height (ctxt->context, + ctxt->style->headings_font, file_as)); + cairo_fill (cr); + cairo_restore (cr); + } + + e_contact_output ( + ctxt->context, ctxt->style->headings_font, + ctxt->x, ctxt->y, ctxt->column_width + 4, file_as); + ctxt->y += e_contact_text_height ( + ctxt->context, ctxt->style->headings_font, file_as); + g_free (file_as); ctxt->y += get_font_height (ctxt->style->headings_font) * .2; - ctxt->y += get_font_height (ctxt->style->headings_font) * .2; - - for(field = E_CONTACT_FILE_AS; field != E_CONTACT_LAST_SIMPLE_STRING;field++) + + for (field = E_CONTACT_FILE_AS; field != E_CONTACT_LAST_SIMPLE_STRING; field++) { - char *string; - string = e_contact_get(contact, field); - - if (string && *string) { - double xoff = 0; - - e_contact_output(ctxt, - ctxt->style->body_font, - ctxt->x + xoff, - ctxt->y + 5, - -1, - e_contact_pretty_name (field)); - - xoff += get_font_width(ctxt, ctxt->style->body_font, e_contact_pretty_name (field)); - e_contact_output(ctxt, ctxt->style->body_font, ctxt->x + xoff, ctxt->y + 5, -1, ": "); - xoff += get_font_width(ctxt, ctxt->style->body_font, ": "); - - e_contact_output(ctxt, - ctxt->style->body_font, - ctxt->x + xoff, - ctxt->y + 5, - column_width - xoff, - string); - - ctxt->y += e_contact_text_height(ctxt, ctxt->style->body_font, column_width - xoff, string); - ctxt->y += .2 * get_font_height (ctxt->style->body_font); + const gchar *value; + gchar *text; - } - g_free(string); - } - ctxt->y += get_font_height (ctxt->style->headings_font) * .4 + 8; - cairo_restore(cr); -} + value = e_contact_get_const (contact, field); + if (value == NULL || *value == '\0') + continue; -static void -e_contact_start_new_column (EContactPrintContext *ctxt) -{ - gdouble page_width = 72 * (ctxt->style->page_width - ctxt->style->left_margin - ctxt->style->right_margin); - gdouble column_offset; + text = g_strdup_printf ("%s: %s", + e_contact_pretty_name (field), value); - column_offset = (page_width + 18) / ctxt->style->num_columns; - ctxt->column ++; + e_contact_output ( + ctxt->context, ctxt->style->body_font, + ctxt->x, ctxt->y, -1, text); - if (ctxt->column >= ctxt->style->num_columns) { - e_contact_start_new_page(ctxt); - ctxt->column = 0; + ctxt->y += e_contact_text_height ( + ctxt->context, ctxt->style->body_font, text); + + ctxt->y += .2 * get_font_height (ctxt->style->body_font); + + g_free (text); } - ctxt->x = ctxt->style->left_margin + column_offset * ctxt->column; - ctxt->y = ctxt->style->top_margin + 12; + + ctxt->y += get_font_height (ctxt->style->headings_font) * .4 + 8; + + cairo_restore (cr); } static void -complete_sequence (EBookView *book_view, EBookViewStatus status, EContactPrintContext *ctxt) +e_contact_start_new_column (EContactPrintContext *ctxt) { - GList *contacts = ctxt->contacts; - - ctxt->first_contact = TRUE; - ctxt->character = NULL; - ctxt->y = ctxt->style->page_height + ctxt->style->top_margin; - ctxt->x = (ctxt->style->left_margin); - - for(; contacts; contacts = contacts->next) { - EContact *contact = contacts->data; - guchar *file_as; - gchar *letter_str = NULL; - - file_as = e_contact_get (contact, E_CONTACT_FILE_AS); - - if (file_as != NULL) { - letter_str = g_strndup (file_as, g_utf8_next_char (file_as) - (gchar *) file_as); - } - if ( file_as && (!ctxt->character || g_utf8_collate (ctxt->character, letter_str) != 0) ) { - g_free (ctxt->character); - ctxt->character = g_strdup (letter_str); - if (ctxt->style->sections_start_new_page && ! ctxt->first_contact) { - e_contact_start_new_page(ctxt); - } - else if ((!ctxt->first_contact) && (ctxt->y > ctxt->style->page_height * 60 )) - e_contact_start_new_column(ctxt); - if ( ctxt->style->letter_headings ) - e_contact_print_letter_heading(ctxt, ctxt->character); - ctxt->first_section = FALSE; - } - - else if ( (!ctxt->first_contact) && (ctxt->y > ctxt->style->page_height * 60)) { - e_contact_start_new_column(ctxt); - if ( ctxt->style->letter_headings ) - e_contact_print_letter_heading(ctxt, ctxt->character); - } - - g_free (letter_str); - e_contact_print_contact(contact, ctxt); - ctxt->first_contact = FALSE; + if (++ctxt->column >= ctxt->style->num_columns) + e_contact_start_new_page (ctxt); + else { + ctxt->x = ctxt->column * + (ctxt->column_width + ctxt->column_spacing); + ctxt->y = .0; } - - if (book_view) - g_object_unref(book_view); - - g_object_unref(ctxt->pc); - g_object_unref(ctxt->pl); - if (ctxt->book) - g_object_unref(ctxt->book); - - g_free(ctxt->character); - if (ctxt->query) - e_book_query_unref (ctxt->query); - g_list_foreach(ctxt->contacts, (GFunc) g_object_unref, NULL); - g_list_free(ctxt->contacts); - pango_font_description_free(ctxt->style->headings_font); - pango_font_description_free(ctxt->style->body_font); - pango_font_description_free(ctxt->style->header_font); - pango_font_description_free(ctxt->style->footer_font); - pango_font_description_free(ctxt->letter_heading_font); - g_free(ctxt->style); } static int contact_compare (EContact *contact1, EContact *contact2) { - if (contact1 && contact2) { - const char *file_as1, *file_as2; - file_as1 = e_contact_get_const (contact1, E_CONTACT_FILE_AS); - file_as2 = e_contact_get_const (contact2, E_CONTACT_FILE_AS); - - if (file_as1 && file_as2) - return g_utf8_collate(file_as1, file_as2); - if (file_as1) - return -1; - if (file_as2) - return 1; - return strcmp(e_contact_get_const(contact1, E_CONTACT_UID), e_contact_get_const(contact2, E_CONTACT_UID)); - } else { + const gchar *field1, *field2; + + if (contact1 == NULL || contact2 == NULL) return 0; - } -} -static void -create_contact(EBookView *book_view, const GList *contacts, EContactPrintContext *ctxt) -{ - for(; contacts; contacts = contacts->next) { - EContact *contact = contacts->data; - g_object_ref(contact); - ctxt->contacts = g_list_insert_sorted(ctxt->contacts, contact, (GCompareFunc) contact_compare); - } -} + field1 = e_contact_get_const (contact1, E_CONTACT_FILE_AS); + field2 = e_contact_get_const (contact2, E_CONTACT_FILE_AS); -static void -book_view_loaded (EBook *book, EBookStatus status, EBookView *book_view, EContactPrintContext *ctxt) -{ - g_object_ref(book_view); - - g_signal_connect(book_view, - "contacts_added", - G_CALLBACK(create_contact), - ctxt); - g_signal_connect(book_view, - "sequence_complete", - G_CALLBACK(print_func), - ctxt); - e_book_view_start (book_view); -} + if (field1 != NULL && field2 != NULL) + return g_utf8_collate (field1, field2); -static void -print_func (EBookView *book_view, const GList *contacts, EContactPrintContext *ctxt) -{ - GtkPrintSettings *settings; - settings = gtk_print_settings_new (); - /* runs a print dialog, emittings signals */ - if(ctxt->response_id == GTK_RESPONSE_APPLY) - gtk_print_operation_run (ctxt->print, GTK_PRINT_OPERATION_ACTION_PREVIEW, NULL, NULL); - else - gtk_print_operation_run (ctxt->print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL, NULL); - settings = gtk_print_operation_get_print_settings (ctxt->print); - e_print_save_settings (settings); -} + if (field1 != NULL || field2 != NULL) + return (field1 != NULL) ? -1 : 1; -static void -e_contact_do_print_contacts (EBook *book, EBookQuery *query, EContactPrintContext *ctxt) -{ - EBookView *bookview; - gboolean status; + field1 = e_contact_get_const (contact1, E_CONTACT_UID); + field2 = e_contact_get_const (contact2, E_CONTACT_UID); + + g_assert (field1 != NULL && field2 != NULL); - status = e_book_get_book_view (book, query, NULL, -1, &bookview, NULL); - book_view_loaded (book, 1, bookview, ctxt); + return strcmp (field1, field2); } - -static void -e_contact_do_print (EBook *book, EBookQuery *query, EContactPrintContext *ctxt) -{ - switch ( ctxt->style->type ) { - case E_CONTACT_PRINT_TYPE_CARDS: - e_contact_do_print_contacts( book, query, ctxt); - break; - default: - break; + +static void +contacts_added (EBookView *book_view, const GList *contact_list, + EContactPrintContext *ctxt) +{ + while (contact_list != NULL) { + ctxt->contact_list = g_list_insert_sorted( + ctxt->contact_list, + g_object_ref (contact_list->data), + (GCompareFunc) contact_compare); + contact_list = contact_list->next; } } -static void lowify( char *data ) +static void +sequence_complete (EBookView *book_view, const GList *contact_list, + EFlag *book_view_started) { - for ( ; *data; data++ ) - *data = tolower((unsigned char) *data); + e_flag_set (book_view_started); } -static gboolean get_bool( char *data ) +static gboolean +get_bool (gchar *data) { - if ( data ) { - lowify ( data ); - return ! strcmp(data, "true"); - } else + if (data) + return (g_ascii_strcasecmp (data, "true") == 0); + else return FALSE; } -static void get_string( char *data, char **variable ) +static void +get_string (gchar *data, gchar **variable) { - g_free ( *variable ); - if ( data ) - *variable = g_strdup( data ); - else - *variable = g_strdup( "" ); + g_free (*variable); + *variable = g_strdup ((data != NULL) ? data : ""); } -static int get_integer( char *data ) +static gint +get_integer (gchar *data) { - if ( data ) - return atoi(data); - else - return 0; + return (data != NULL) ? atoi (data) : 0; } -static double get_float( char *data ) +static gdouble +get_float (gchar *data) { - if ( data ) - return atof(data); - else - return 0; + return (data != NULL) ? atof (data) : .0; } -static void get_font( char *data, PangoFontDescription **variable ) +static void +get_font (gchar *data, PangoFontDescription **variable) { - if ( data ) { - PangoFontDescription *font = pango_font_description_from_string ( data ); - if ( font ) { - pango_font_description_free(*variable); - *variable = font; - } + PangoFontDescription *desc = NULL; + + if (data != NULL) + desc = pango_font_description_from_string (data); + + if (desc != NULL) { + pango_font_description_free (*variable); + *variable = desc; } } - static void -e_contact_build_style(EContactPrintStyle *style, GtkPrintSettings *config) +e_contact_build_style (EContactPrintStyle *style) { xmlDocPtr styledoc; gchar *filename; @@ -614,8 +390,8 @@ e_contact_build_style(EContactPrintStyle *style, GtkPrintSettings *config) style->blank_forms = 2; style->letter_headings = FALSE; - style->headings_font = find_closest_font_from_weight_slant ("Sans", GNOME_FONT_BOLD, FALSE, 8); - style->body_font = find_closest_font_from_weight_slant ("Sans", GNOME_FONT_BOOK, FALSE, 6); + style->headings_font = pango_font_description_from_string ("Sans Bold 8"); + style->body_font = pango_font_description_from_string ("Sans 6"); style->print_using_grey = TRUE; style->paper_type = 0; @@ -639,21 +415,23 @@ e_contact_build_style(EContactPrintStyle *style, GtkPrintSettings *config) #endif style->orientation_portrait = FALSE; - style->header_font = find_closest_font_from_weight_slant ("Sans", GNOME_FONT_BOOK, FALSE, 6); + style->header_font = pango_font_description_copy (style->body_font); style->left_header = g_strdup(""); style->center_header = g_strdup(""); style->right_header = g_strdup(""); - style->footer_font = find_closest_font_from_weight_slant ("Sans", GNOME_FONT_BOOK, FALSE, 6); + style->footer_font = pango_font_description_copy (style->body_font); - style->left_footer = g_strdup(""); - style->center_footer = g_strdup(""); - style->right_footer = g_strdup(""); + style->left_footer = g_strdup (""); + style->center_footer = g_strdup (""); + style->right_footer = g_strdup (""); style->reverse_on_even_pages = FALSE; - filename = g_build_filename(EVOLUTION_ECPSDIR, "medbook.ecps", NULL); + + filename = g_build_filename (EVOLUTION_ECPSDIR, "medbook.ecps", NULL); styledoc = e_xml_parse_file (filename); - g_free(filename); + g_free (filename); + if (styledoc) { xmlNodePtr stylenode = xmlDocGetRootElement(styledoc); xmlNodePtr node; @@ -662,12 +440,11 @@ e_contact_build_style(EContactPrintStyle *style, GtkPrintSettings *config) if ( !strcmp( node->name, "title" ) ) { get_string(data, &(style->title)); } else if ( !strcmp( node->name, "type" ) ) { - lowify( data ); - if ( !strcmp( data, "cards" ) ) + if (g_ascii_strcasecmp (data, "cards") == 0) style->type = E_CONTACT_PRINT_TYPE_CARDS; - else if ( !strcmp( data, "memo_style" ) ) + else if (g_ascii_strcasecmp (data, "memo_style") == 0) style->type = E_CONTACT_PRINT_TYPE_MEMO_STYLE; - else if ( !strcmp( data, "phone_list" ) ) + else if (g_ascii_strcasecmp (data, "phone_list") == 0) style->type = E_CONTACT_PRINT_TYPE_PHONE_LIST; } else if ( !strcmp( node->name, "sections_start_new_page" ) ) { style->sections_start_new_page = get_bool(data); @@ -701,8 +478,8 @@ e_contact_build_style(EContactPrintStyle *style, GtkPrintSettings *config) style->page_height = get_float(data); } else if ( !strcmp( node->name, "orientation" ) ) { if ( data ) { - lowify(data); - style->orientation_portrait = strcmp(data, "landscape"); + style->orientation_portrait = + (g_ascii_strcasecmp (data, "landscape") != 0); } else { style->orientation_portrait = TRUE; } @@ -733,204 +510,192 @@ e_contact_build_style(EContactPrintStyle *style, GtkPrintSettings *config) } -static gint -e_contact_print_close(GnomeDialog *dialog, gpointer data) +static void +load_contacts (EContactPrintContext *ctxt) { - return FALSE; + /* Load contacts from the EBook. This is an asynchronous operation + * but we force it to be synchronous here. */ + + EBookView *book_view; + EFlag *book_view_started; + + book_view_started = e_flag_new (); + + e_book_get_book_view ( + ctxt->book, ctxt->query, NULL, -1, &book_view, NULL); + + g_signal_connect ( + book_view, "contacts_added", + G_CALLBACK (contacts_added), ctxt); + g_signal_connect ( + book_view, "sequence_complete", + G_CALLBACK (sequence_complete), book_view_started); + + e_book_view_start (book_view); + + while (!e_flag_is_set (book_view_started)) + g_main_context_iteration (NULL, TRUE); + + e_flag_free (book_view_started); } -void -e_contact_print_response(GtkWidget *dialog, gint response_id, gpointer data) +static void +free_contacts (EContactPrintContext *ctxt) { -#ifdef G_OS_UNIX /* Just to get it to build on Win32 */ - GtkPrintSettings *settings; - GtkPaperSize *paper_size; - GtkPageSetup *page_setup; - GList *contact_list = NULL; - EBook *book = NULL; - EBookQuery *query = NULL; - EContact *contact = NULL; - gdouble font_size; - gboolean uses_book = FALSE, uses_list = FALSE, uses_range = FALSE; - - EContactPrintContext *ctxt = g_new0 (EContactPrintContext, 1); - EContactPrintStyle *style = g_new0 (EContactPrintStyle, 1); - ContactPrintItem *cpi = g_new0 (ContactPrintItem, 1); - - settings = gtk_print_unix_dialog_get_settings (GTK_PRINT_UNIX_DIALOG (dialog)); - uses_range = GPOINTER_TO_INT (g_object_get_data(G_OBJECT (dialog),"uses_range")); - - if (uses_range) { - if (gtk_print_settings_get_print_pages (settings) == GTK_PRINT_PAGES_ALL) { - uses_book = TRUE; - } - if (gtk_print_settings_get_print_pages (settings) == GTK_PRINT_PAGES_CURRENT) - uses_list = TRUE; - } - else { - uses_book = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dialog), "uses_book")); - uses_list = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dialog), "uses_list")); - } - if (uses_book) { - book = g_object_get_data(G_OBJECT(dialog), "book"); - query = g_object_get_data(G_OBJECT(dialog), "query"); - e_book_query_ref (query); - } - else if (uses_list) { - contact_list = g_object_get_data(G_OBJECT(dialog), "contact_list"); - } - else { - contact = g_object_get_data(G_OBJECT(dialog), "contact"); - } - - page_setup = gtk_page_setup_new (); - paper_size = gtk_paper_size_new ("iso_a4"); /* FIXME paper size hardcoded */ - gtk_page_setup_set_paper_size (page_setup, paper_size); - ctxt->print = gtk_print_operation_new (); - gtk_print_operation_set_default_page_setup (ctxt->print, page_setup); - gtk_print_operation_set_n_pages (ctxt->print, 1); - gtk_print_settings_set_print_pages (settings, GTK_PRINT_PAGES_ALL); - - /* style information */ - e_contact_build_style(style, settings); - style->page_height = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_INCH); - style->page_width = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_INCH); - ctxt->x = 0; - ctxt->y = 0; + g_list_foreach (ctxt->contact_list, (GFunc) g_object_unref, NULL); + g_list_free (ctxt->contact_list); +} + +static void +contact_begin_print (GtkPrintOperation *operation, + GtkPrintContext *context, + EContactPrintContext *ctxt) +{ + GtkPageSetup *setup; + gdouble page_width; + + e_contact_build_style (ctxt->style); + + setup = gtk_print_context_get_page_setup (context); + page_width = gtk_page_setup_get_page_width (setup, GTK_UNIT_POINTS); + + ctxt->context = context; + ctxt->x = ctxt->y = .0; ctxt->column = 0; - ctxt->style = style; + ctxt->first_contact = TRUE; ctxt->first_section = TRUE; - ctxt->type = GTK_RESPONSE_OK; - font_size = 72 * ctxt->style->page_height / 27.0 / 2.0; - ctxt->letter_heading_font = find_font (pango_font_description_get_family (ctxt->style->headings_font), - get_font_height (ctxt->style->headings_font)*1.5); - ctxt->book = book; - ctxt->query = query; - ctxt->response_id = response_id; - cpi->uses_book = uses_book; - cpi->uses_list = uses_list; - cpi->settings = settings; - cpi->ctxt = ctxt; - cpi->contact= contact; - cpi->ctxt->contacts = NULL; - cpi->contact_list= contact_list; - cpi->book = book; - gtk_print_operation_set_print_settings (ctxt->print, settings); - g_signal_connect (ctxt->print, "draw_page",G_CALLBACK (contact_draw_page), cpi); - - if (!uses_book) { - if(ctxt->response_id == GTK_RESPONSE_APPLY) - gtk_print_operation_run (ctxt->print, GTK_PRINT_OPERATION_ACTION_PREVIEW, NULL, NULL); - else - gtk_print_operation_run (ctxt->print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL, NULL); - settings = gtk_print_operation_get_print_settings (ctxt->print); - e_print_save_settings (settings); - } - else - e_contact_do_print_contacts (book, query, ctxt); - - g_object_unref (cpi); - if (!uses_book) { - g_object_unref (ctxt->print); - g_free (ctxt); - } - gtk_widget_destroy (dialog); -#else - g_warning ("Not implemented currently on Windows"); -#endif -} + ctxt->section = NULL; + ctxt->column_spacing = gtk_print_context_get_dpi_x (context) / 4; + ctxt->column_width = (page_width + ctxt->column_spacing) / + ctxt->style->num_columns - ctxt->column_spacing; + + ctxt->letter_heading_font = pango_font_description_new (); + pango_font_description_set_family ( + ctxt->letter_heading_font, + pango_font_description_get_family ( + ctxt->style->headings_font)); + pango_font_description_set_size ( + ctxt->letter_heading_font, + pango_font_description_get_size ( + ctxt->style->headings_font) * 1.5); + + if (ctxt->book != NULL) + load_contacts (ctxt); +} -GtkWidget * -e_contact_print_dialog_new(EBook *book, char *query, GList *list) +static void +contact_draw (EContact *contact, EContactPrintContext *ctxt) { - GtkWidget *dialog; - GList *copied_list = NULL; - GList *l; - - dialog = e_print_get_dialog(_("Print contacts"), 0); - - if (list != NULL) { - copied_list = g_list_copy (list); - for (l = copied_list; l; l = l->next) - l->data = e_contact_duplicate (E_CONTACT (l->data)); + GtkPageSetup *setup; + gdouble page_height; + gchar *file_as; + gboolean new_section = FALSE; + + setup = gtk_print_context_get_page_setup (ctxt->context); + page_height = gtk_page_setup_get_page_height (setup, GTK_UNIT_POINTS); + + file_as = e_contact_get (contact, E_CONTACT_FILE_AS); + + if (file_as != NULL) { + gchar *section; + gsize width; + + width = g_utf8_next_char (file_as) - file_as; + section = g_utf8_strup (file_as, width); + + new_section = (ctxt->section == NULL || + g_utf8_collate (ctxt->section, section) != 0); + + if (new_section) { + g_free (ctxt->section); + ctxt->section = section; + } else + g_free (section); + } + + if (new_section) { + if (!ctxt->first_contact) { + if (ctxt->style->sections_start_new_page) + e_contact_start_new_page (ctxt); + else if (ctxt->y > page_height) + e_contact_start_new_column (ctxt); + } + if (ctxt->style->letter_headings) + e_contact_print_letter_heading (ctxt, ctxt->section); + ctxt->first_section = FALSE; + } + + else if (!ctxt->first_contact && (ctxt->y > page_height)) { + e_contact_start_new_column (ctxt); + if (ctxt->style->letter_headings) + e_contact_print_letter_heading (ctxt, ctxt->section); } - g_object_ref(book); - g_object_set_data(G_OBJECT(dialog), "contact_list", copied_list); - g_object_set_data(G_OBJECT(dialog), "book", book); - g_object_set_data(G_OBJECT(dialog), "query", e_book_query_from_string (query)); - g_object_set_data(G_OBJECT(dialog), "uses_range", GINT_TO_POINTER (TRUE)); - - g_signal_connect(dialog, - "response", G_CALLBACK(e_contact_print_response), NULL); - g_signal_connect(dialog, - "close", G_CALLBACK(e_contact_print_close), NULL); - return dialog; + e_contact_print_contact (contact, ctxt); + + ctxt->first_contact = FALSE; } -GtkWidget * -e_contact_print_contact_dialog_new(EContact *contact) +static void +contact_draw_page (GtkPrintOperation *operation, + GtkPrintContext *context, + gint page_nr, + EContactPrintContext *ctxt) { - GtkWidget *dialog; - - dialog = e_print_get_dialog(_("Print contact"), 0); - contact = e_contact_duplicate(contact); - g_object_set_data(G_OBJECT(dialog), "contact", contact); - g_object_set_data(G_OBJECT(dialog), "uses_list", GINT_TO_POINTER (FALSE)); - g_object_set_data(G_OBJECT(dialog), "uses_book", GINT_TO_POINTER (FALSE)); - g_object_set_data(G_OBJECT(dialog), "uses_range", GINT_TO_POINTER (FALSE)); - g_signal_connect(dialog, - "response", G_CALLBACK(e_contact_print_response), NULL); - g_signal_connect(dialog, - "close", G_CALLBACK(e_contact_print_close), NULL); - return dialog; + g_list_foreach (ctxt->contact_list, (GFunc) contact_draw, ctxt); } - -GtkWidget * -e_contact_print_contact_list_dialog_new(GList *list) + +static void +contact_end_print (GtkPrintOperation *operation, + GtkPrintContext *context, + EContactPrintContext *ctxt) { - GtkWidget *dialog; - GList *copied_list; - GList *l; - - if (list == NULL) - return NULL; - - copied_list = g_list_copy (list); - for (l = copied_list; l; l = l->next) - l->data = e_contact_duplicate (E_CONTACT (l->data)); - - dialog = e_print_get_dialog(_("Print contact"), 0); - - g_object_set_data(G_OBJECT(dialog), "contact_list", copied_list); - g_object_set_data(G_OBJECT(dialog), "uses_list", GINT_TO_POINTER (TRUE)); - g_object_set_data(G_OBJECT(dialog), "uses_book", GINT_TO_POINTER (FALSE)); - g_object_set_data(G_OBJECT(dialog), "uses_range", GINT_TO_POINTER (FALSE)); - g_signal_connect(dialog, - "response", G_CALLBACK(e_contact_print_response), NULL); - g_signal_connect(dialog, - "close", G_CALLBACK(e_contact_print_close), NULL); - return dialog; + pango_font_description_free (ctxt->style->headings_font); + pango_font_description_free (ctxt->style->body_font); + pango_font_description_free (ctxt->style->header_font); + pango_font_description_free (ctxt->style->footer_font); + pango_font_description_free (ctxt->letter_heading_font); + + g_free (ctxt->section); + + if (ctxt->book != NULL) + free_contacts (ctxt); } -static void -contact_draw_page (GtkPrintOperation *print, GtkPrintContext *context, gint page_nr, ContactPrintItem *cpi) +void +e_contact_print (EBook *book, EBookQuery *query, + GList *contact_list, GtkPrintOperationAction action) { - cpi->ctxt->pc = context; - g_object_ref (cpi->ctxt->pc); - cpi->ctxt->pl =gtk_print_context_create_pango_layout (context); - - if (cpi->uses_book) { - complete_sequence(NULL, E_BOOK_VIEW_STATUS_OK, cpi->ctxt); - } - - else if (cpi->uses_list) { - cpi->ctxt->contacts = cpi->contact_list; - complete_sequence(NULL, E_BOOK_VIEW_STATUS_OK, cpi->ctxt); - } - else { - cpi->ctxt->contacts = g_list_append(NULL,cpi->contact); - complete_sequence(NULL, E_BOOK_VIEW_STATUS_OK, cpi->ctxt); - } + GtkPrintOperation *operation; + EContactPrintContext ctxt; + EContactPrintStyle style; + + if (book != NULL) { + ctxt.book = book; + ctxt.query = query; + ctxt.contact_list = NULL; + } else { + ctxt.book = NULL; + ctxt.query = NULL; + ctxt.contact_list = contact_list; + } + ctxt.style = &style; + + operation = e_print_operation_new (); + gtk_print_operation_set_n_pages (operation, 1); + + g_signal_connect ( + operation, "begin-print", + G_CALLBACK (contact_begin_print), &ctxt); + g_signal_connect ( + operation, "draw_page", + G_CALLBACK (contact_draw_page), &ctxt); + g_signal_connect ( + operation, "end-print", + G_CALLBACK (contact_end_print), &ctxt); + + gtk_print_operation_run (operation, action, NULL, NULL); + + g_object_unref (operation); } diff --git a/addressbook/printing/e-contact-print.h b/addressbook/printing/e-contact-print.h index bc7b36c0da..a43f8b70eb 100644 --- a/addressbook/printing/e-contact-print.h +++ b/addressbook/printing/e-contact-print.h @@ -23,14 +23,13 @@ #define E_CONTACT_PRINT_H #include <glib.h> -#include <gtk/gtkwidget.h> +#include <gtk/gtkprintoperation.h> #include <libebook/e-book.h> -#include <libebook/e-contact.h> #include "e-contact-print-types.h" -GtkWidget *e_contact_print_dialog_new (EBook *book, char *query, GList *list); -GtkWidget *e_contact_print_contact_dialog_new (EContact *card); -GtkWidget *e_contact_print_contact_list_dialog_new(GList *list); -void e_contact_print_response (GtkWidget *dialog, gint response_id, gpointer data); +void e_contact_print (EBook *book, + EBookQuery *query, + GList *contact_list, + GtkPrintOperationAction action); #endif /* E_CONTACT_PRINT_H */ diff --git a/addressbook/printing/test-print.c b/addressbook/printing/test-print.c index 708885a861..1ac88dfa0a 100644 --- a/addressbook/printing/test-print.c +++ b/addressbook/printing/test-print.c @@ -32,12 +32,6 @@ /* This is a horrible thing to do, but it is just a test. */ GtkWidget *print; -static gint test_close(GnomeDialog *dialog, gpointer data) -{ - exit(0); - return 1; -} - #if 0 static void about_callback( GtkWidget *widget, gpointer data ) { @@ -77,9 +71,8 @@ int main( int argc, char *argv[] ) shown_fields = g_list_append(shown_fields, "Third field"); shown_fields = g_list_append(shown_fields, "Fourth field"); - print = e_contact_print_dialog_new(NULL, NULL, NULL); - gtk_widget_show_all(print); - g_signal_connect(print, "close", G_CALLBACK(test_close), NULL); + /* does nothing */ + e_contact_print (NULL, NULL, NULL, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG); bonobo_main(); diff --git a/calendar/ChangeLog b/calendar/ChangeLog index d33eddc09c..f71c901a5b 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,16 @@ +2007-04-20 Matthew Barnes <mbarnes@redhat.com> + + * gui/calendar-commands.c: + * gui/dialogs/comp-editor.c: + * gui/e-calendar-table.c: + * gui/e-calendar-view.c: + * gui/e-memo-table.c: + * gui/memos-control.c: + * gui/print.c: + * gui/print.h: + * gui/tasks-control.c: + Refactor the printing infrastructure. (#426816) + 2007-04-19 Matthew Barnes <mbarnes@redhat.com> ** Fixes part of bug #429422 diff --git a/calendar/gui/calendar-commands.c b/calendar/gui/calendar-commands.c index ef517f7137..bbdee852b8 100644 --- a/calendar/gui/calendar-commands.c +++ b/calendar/gui/calendar-commands.c @@ -88,62 +88,38 @@ file_open_event_cb (BonoboUIComponent *uic, gpointer data, const char *path) /* Prints the calendar at its current view and time range */ static void -print (GnomeCalendar *gcal, gboolean preview) +print (GnomeCalendar *gcal, GtkPrintOperationAction action) { - time_t start; - GnomeCalendarViewType view_type; - PrintView print_view; - ECalListView *list_view; - ETable *etable; - - gnome_calendar_get_current_time_range (gcal, &start, NULL); - view_type = gnome_calendar_get_view (gcal); - - switch (view_type) { - case GNOME_CAL_DAY_VIEW: - print_view = PRINT_VIEW_DAY; - break; - - case GNOME_CAL_WORK_WEEK_VIEW: - case GNOME_CAL_WEEK_VIEW: - print_view = PRINT_VIEW_WEEK; - break; + if (gnome_calendar_get_view (gcal) == GNOME_CAL_LIST_VIEW) { + ECalListView *list_view; + ETable *table; - case GNOME_CAL_MONTH_VIEW: - print_view = PRINT_VIEW_MONTH; - break; - - case GNOME_CAL_LIST_VIEW: list_view = E_CAL_LIST_VIEW (gnome_calendar_get_current_view_widget (gcal)); - etable = e_table_scrolled_get_table (list_view->table_scrolled); - print_table (etable, _("Print"), _("Calendar"), preview); - return; + table = e_table_scrolled_get_table (list_view->table_scrolled); + print_table (table, _("Print"), _("Calendar"), action); + } else { + time_t start; - default: - g_assert_not_reached (); - return; + gnome_calendar_get_current_time_range (gcal, &start, NULL); + print_calendar (gcal, action, start); } - - print_calendar (gcal, preview, start, print_view); } /* File/Print callback */ static void file_print_cb (BonoboUIComponent *uic, gpointer data, const char *path) { - GnomeCalendar *gcal; + GnomeCalendar *gcal = GNOME_CALENDAR (data); - gcal = GNOME_CALENDAR (data); - print (gcal, FALSE); + print (gcal, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG); } static void file_print_preview_cb (BonoboUIComponent *uic, gpointer data, const char *path) { - GnomeCalendar *gcal; + GnomeCalendar *gcal = GNOME_CALENDAR (data); - gcal = GNOME_CALENDAR (data); - print (gcal, TRUE); + print (gcal, GTK_PRINT_OPERATION_ACTION_PREVIEW); } /* Sets a clock cursor for the specified calendar window */ diff --git a/calendar/gui/dialogs/comp-editor.c b/calendar/gui/dialogs/comp-editor.c index 0cd25deef7..fe27aa1e9d 100644 --- a/calendar/gui/dialogs/comp-editor.c +++ b/calendar/gui/dialogs/comp-editor.c @@ -1314,7 +1314,7 @@ menu_file_print_cb (BonoboUIComponent *uic, for (l = priv->pages; l != NULL; l = l->next) comp_editor_page_fill_component (l->data, comp); - print_comp (comp, priv->client, FALSE); + print_comp (comp, priv->client, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG); g_object_unref (comp); } diff --git a/calendar/gui/e-calendar-table.c b/calendar/gui/e-calendar-table.c index fd9d014827..88952f9b7a 100644 --- a/calendar/gui/e-calendar-table.c +++ b/calendar/gui/e-calendar-table.c @@ -1132,7 +1132,7 @@ e_calendar_table_on_print_task (EPopup *ep, EPopupItem *pitem, void *data) comp = e_cal_component_new (); e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (comp_data->icalcomp)); - print_comp (comp, comp_data->client, FALSE); + print_comp (comp, comp_data->client, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG); g_object_unref (comp); } diff --git a/calendar/gui/e-calendar-view.c b/calendar/gui/e-calendar-view.c index 2ee44b29a6..c97dc3df59 100644 --- a/calendar/gui/e-calendar-view.c +++ b/calendar/gui/e-calendar-view.c @@ -1204,32 +1204,13 @@ on_print (EPopup *ep, EPopupItem *pitem, void *data) { ECalendarView *cal_view = data; time_t start, end; - GnomeCalendarViewType view_type; - PrintView print_view; e_calendar_view_get_visible_time_range (cal_view, &start, &end); - view_type = gnome_calendar_get_view (cal_view->priv->calendar); - - switch (view_type) { - case GNOME_CAL_DAY_VIEW : - print_view = PRINT_VIEW_DAY; - break; - - case GNOME_CAL_WORK_WEEK_VIEW : - case GNOME_CAL_WEEK_VIEW: - print_view = PRINT_VIEW_WEEK; - break; - - case GNOME_CAL_MONTH_VIEW: - print_view = PRINT_VIEW_MONTH; - break; - - default: - g_assert_not_reached (); - return; - } - print_calendar (cal_view->priv->calendar, FALSE, start, print_view); + print_calendar ( + cal_view->priv->calendar, + GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, + start); } static void @@ -1278,7 +1259,7 @@ on_print_event (EPopup *ep, EPopupItem *pitem, void *data) comp = e_cal_component_new (); e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp)); - print_comp (comp, event->comp_data->client, FALSE); + print_comp (comp, event->comp_data->client, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG); g_object_unref (comp); g_list_free (selected); diff --git a/calendar/gui/e-memo-table.c b/calendar/gui/e-memo-table.c index 18353f5563..8430a110f6 100644 --- a/calendar/gui/e-memo-table.c +++ b/calendar/gui/e-memo-table.c @@ -823,7 +823,7 @@ e_memo_table_on_print_memo (EPopup *ep, EPopupItem *pitem, void *data) comp = e_cal_component_new (); e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (comp_data->icalcomp)); - print_comp (comp, comp_data->client, FALSE); + print_comp (comp, comp_data->client, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG); g_object_unref (comp); } diff --git a/calendar/gui/memos-control.c b/calendar/gui/memos-control.c index 3d4fc5182c..70a2611469 100644 --- a/calendar/gui/memos-control.c +++ b/calendar/gui/memos-control.c @@ -35,13 +35,6 @@ #include <libgnomeui/gnome-dialog.h> #include <libgnomeui/gnome-dialog-util.h> #include <libgnomeui/gnome-stock-icons.h> -#include <libgnomeprint/gnome-print.h> -#include <libgnomeprint/gnome-print-paper.h> -#include <libgnomeprint/gnome-print-job.h> -#include <libgnomeprintui/gnome-print-job-preview.h> -#include <libgnomeprintui/gnome-print-paper-selector.h> -#include <libgnomeprintui/gnome-print-preview.h> -#include <libgnomeprintui/gnome-print-dialog.h> #include <bonobo/bonobo-control.h> #include <bonobo/bonobo-ui-util.h> #include <e-util/e-dialog-utils.h> @@ -327,30 +320,21 @@ memos_control_delete_cmd (BonoboUIComponent *uic, e_memos_delete_selected (memos); } - -static void -print_memos (EMemos *memos, gboolean preview) -{ - EMemoTable *cal_table; - ETable *etable; - - cal_table = e_memos_get_calendar_table (memos); - etable = e_memo_table_get_table (E_MEMO_TABLE (cal_table)); - - print_table (etable, _("Print Memos"), _("Memos"), preview); -} - /* File/Print callback */ static void memos_control_print_cmd (BonoboUIComponent *uic, gpointer data, const char *path) { - EMemos *memos; + EMemos *memos = E_MEMOS (data); + ETable *table; - memos = E_MEMOS (data); + table = e_memo_table_get_table ( + E_MEMO_TABLE (e_memos_get_calendar_table (memos))); - print_memos (memos, FALSE); + print_table ( + table, _("Print Memos"), _("Memos"), + GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG); } static void @@ -358,10 +342,13 @@ memos_control_print_preview_cmd (BonoboUIComponent *uic, gpointer data, const char *path) { - EMemos *memos; + EMemos *memos = E_MEMOS (data); + ETable *table; - memos = E_MEMOS (data); + table = e_memo_table_get_table ( + E_MEMO_TABLE (e_memos_get_calendar_table (memos))); - print_memos (memos, TRUE); + print_table ( + table, _("Print Memos"), _("Memos"), + GTK_PRINT_OPERATION_ACTION_PREVIEW); } - diff --git a/calendar/gui/print.c b/calendar/gui/print.c index 5dbff11c0a..4e158121cb 100644 --- a/calendar/gui/print.c +++ b/calendar/gui/print.c @@ -32,19 +32,11 @@ #include <string.h> #include <time.h> #include <glib.h> -#include <gtk/gtkradiobutton.h> #include <gtk/gtk.h> #include <glib/gi18n.h> #include <libgnomeui/gnome-dialog.h> #include <libgnomeui/gnome-uidefs.h> #include <libgnomeui/gnome-stock-icons.h> -#include <libgnomeprint/gnome-print.h> -#include <libgnomeprint/gnome-print-paper.h> -#include <libgnomeprint/gnome-print-job.h> -#include <libgnomeprintui/gnome-print-job-preview.h> -#include <libgnomeprintui/gnome-print-paper-selector.h> -#include <libgnomeprintui/gnome-print-preview.h> -#include <libgnomeprintui/gnome-print-dialog.h> #include <libedataserver/e-time-utils.h> #include <libedataserver/e-data-server-util.h> #include <e-util/e-util.h> @@ -62,135 +54,47 @@ #include "gnome-cal.h" #include "print.h" -#include <libgnomeprint/gnome-print-pango.h> #include <glade/glade-xml.h> -#include <gtk/gtkprintunixdialog.h> -#include <gtk/gtkwindow.h> -#include <gtk/gtkdialog.h> -#include <gtk/gtkpagesetupunixdialog.h> -#include <gtk/gtkprinter.h> - -typedef struct EvoCalendarPrintRenderer EvoCalendarPrintRenderer; typedef struct PrintCompItem PrintCompItem; -typedef struct PrintTableItem PrintTableItem; typedef struct PrintCalItem PrintCalItem; -struct EvoCalendarPrintRenderer -{ - GtkPrintContext *pc; - - /* keep one of these around: */ - PangoLayout *pl; -}; - -struct PrintCompItem -{ - EvoCalendarPrintRenderer *pr; - struct ECal *client; - struct ECalComponent *comp; - double r,l,b,t; -}; - -struct PrintCalItem -{ - EvoCalendarPrintRenderer *pr; - struct GnomeCalendar *gcal; - PrintView default_view; - double r,l,b,t; - time_t date; +struct PrintCompItem { + struct ECal *client; + struct ECalComponent *comp; }; -struct PrintTableItem -{ - struct EPrintable *printable; - double left_margin,bottom_margin,paper_width,paper_height; - GtkPrintContext *context; +struct PrintCalItem { + struct GnomeCalendar *gcal; + time_t start; }; -static PrintCompItem * -evo_calendar_print_data_new (GtkPrintContext *pc, PrintCompItem *pci); - -static void -comp_draw_page (GtkPrintOperation *print, - GtkPrintContext *context, - gint page_nr, - PrintCompItem *pci); -static void -cal_draw_page (GtkPrintOperation *print, - GtkPrintContext *context, - gint page_nr, - PrintCalItem *pcali); -static void -table_draw_page (GtkPrintOperation *print, - GtkPrintContext *context, - gint page_nr1, - PrintTableItem *pti); - static double -evo_calendar_print_renderer_get_width (EvoCalendarPrintRenderer *pr, +evo_calendar_print_renderer_get_width (GtkPrintContext *context, PangoFontDescription *font, - const char *text); - -GObject* create_custom_widget (GtkPrintOperation *print, GtkWidget *range); -static void apply_custom_widget (GtkPrintOperation *print, GtkWidget *dialog, PrintCalItem *cpi); -static PrintCalItem * -evo_calendar_print_cal_data_new (GtkPrintContext *pc, PrintCalItem *pcali) -{ - g_return_val_if_fail (pc, NULL); - - pcali->pr = g_new0 (EvoCalendarPrintRenderer, 1); - pcali->pr->pc = pc; - pcali->pr->pl = gtk_print_context_create_pango_layout (pc); - - return pcali; -} -static PrintCompItem * -evo_calendar_print_data_new (GtkPrintContext *pc,PrintCompItem *pci) -{ - g_return_val_if_fail (pc, NULL); - - pci->pr = g_new0 (EvoCalendarPrintRenderer, 1); - pci->pr->pc = pc; - pci->pr->pl = gtk_print_context_create_pango_layout (pc); - - return pci; -} - -static void -evo_calendar_print_data_free (EvoCalendarPrintRenderer *pr) + const char *text) { - g_return_if_fail (pr); - - g_assert (pr->pl); - g_object_unref (G_OBJECT (pr->pl)); - - g_free (pr); -} + PangoLayout *layout; + gint layout_width, layout_height; + layout = gtk_print_context_create_pango_layout (context); -static double -evo_calendar_print_renderer_get_width (EvoCalendarPrintRenderer *pr, - PangoFontDescription *font, - const char *text) -{ - int w, h; + pango_layout_set_font_description (layout, font); + pango_layout_set_text (layout, text, -1); + pango_layout_set_indent (layout, 0); + pango_layout_get_size (layout, &layout_width, &layout_height); - pango_layout_set_font_description (pr->pl, font); - pango_layout_set_text (pr->pl, text, -1); - pango_layout_set_indent (pr->pl, 0); - pango_layout_get_size (pr->pl, &w, &h); + g_object_unref (layout); - return w/(double)PANGO_SCALE; + return pango_units_to_double (layout_width); } - static double get_font_size (PangoFontDescription *font) { g_return_val_if_fail (font, 0.0); - return ((double)pango_font_description_get_size (font)/(double)PANGO_SCALE); + return pango_units_to_double (pango_font_description_get_size (font)); } @@ -208,8 +112,7 @@ get_font_size (PangoFontDescription *font) #define TEMP_MARGIN .05 /* The fonts to use */ -#define REGULAR_FONT "Sans Regular" -#define BOLD_FONT "Sans Bold" +#define FONT_FAMILY "Sans" /* The font size to use for normal text. */ #define DAY_NORMAL_FONT_SIZE 12 @@ -298,19 +201,6 @@ struct psinfo double header_row_height; }; -struct ptinfo -{ - GList *todos; -}; - -struct einfo -{ - char *text; - time_t start; - time_t end; - int count; -}; - /* Convenience function to help the transition to timezone functions. It converts a time_t to a struct tm. */ static struct tm* @@ -386,39 +276,22 @@ build_month (int month, int year, int *days, int *start, int *end) } static PangoFontDescription * -get_font_for_size (EvoCalendarPrintRenderer *pr, double h, GnomeFontWeight weight, gboolean italic) +get_font_for_size (double height, PangoWeight weight) { - PangoFontDescription *font_desc; - gchar *font_name; - - if (weight <= GNOME_FONT_BOOK) - font_name = REGULAR_FONT; - else - font_name = BOLD_FONT; - - if (italic) - font_name = g_strconcat (font_name, " Italic", NULL); - - font_desc = pango_font_description_from_string (font_name); + PangoFontDescription *desc; + gint size; #define MAGIC_SCALE_FACTOR (0.86) - pango_font_description_set_size (font_desc, - h * MAGIC_SCALE_FACTOR * PANGO_SCALE ); + size = pango_units_from_double (height * MAGIC_SCALE_FACTOR); - if (italic) - g_free (font_name); + desc = pango_font_description_new (); + pango_font_description_set_size (desc, size); + pango_font_description_set_weight (desc, weight); + pango_font_description_set_family_static (desc, FONT_FAMILY); - return font_desc; + return desc; } -enum align_box { - ALIGN_LEFT=1, - ALIGN_RIGHT, - ALIGN_CENTER, - ALIGN_BORDER= 1<<8 -}; - - /* Prints a rectangle, with or without a border, filled or outline, and possibly with triangular arrows at one or both horizontal edges. width = width of border, -ve means no border. @@ -427,32 +300,33 @@ enum align_box { point of triangle, or -ve for no triangle. */ static void print_border_with_triangles (GtkPrintContext *pc, - double l, double r, double t, double b, - double width, double red, double green, double blue, - double left_triangle_width, - double right_triangle_width) + gdouble x1, gdouble x2, + gdouble y1, gdouble y2, + gdouble line_width, + gdouble red, gdouble green, gdouble blue, + gdouble left_triangle_width, + gdouble right_triangle_width) { - cairo_t *cr; + cairo_t *cr = gtk_print_context_get_cairo_context (pc); - cr = gtk_print_context_get_cairo_context (pc); cairo_save (cr); /* Fill in the interior of the rectangle, if desired. */ if (red >= -EPSILON && green >= -EPSILON && blue >= -EPSILON) { - cairo_move_to (cr, l, t); + cairo_move_to (cr, x1, y1); if (left_triangle_width > 0.0) - cairo_line_to (cr, l - left_triangle_width, - (t + b) / 2); + cairo_line_to (cr, x1 - left_triangle_width, + (y1 + y2) / 2); - cairo_line_to (cr, l, b); - cairo_line_to (cr, r, b); + cairo_line_to (cr, x1, y2); + cairo_line_to (cr, x2, y2); if (right_triangle_width > 0.0) - cairo_line_to (cr, r + right_triangle_width, (t + b) / 2); + cairo_line_to (cr, x2 + right_triangle_width, (y1 + y2) / 2); - cairo_line_to (cr, r, t); + cairo_line_to (cr, x2, y1); cairo_close_path (cr); cairo_set_source_rgb (cr, red, green, blue); cairo_fill (cr); @@ -461,28 +335,27 @@ print_border_with_triangles (GtkPrintContext *pc, } /* Draw the outline, if desired. */ - if (width >= -EPSILON) { + if (line_width >= -EPSILON) { cr = gtk_print_context_get_cairo_context (pc); - cairo_move_to (cr, l, t); + cairo_move_to (cr, x1, y1); if (left_triangle_width > 0.0) - cairo_line_to (cr, l - left_triangle_width, - (t + b) / 2); + cairo_line_to (cr, x1 - left_triangle_width, + (y1 + y2) / 2); - cairo_line_to (cr, l, b); - cairo_line_to (cr, r, b); + cairo_line_to (cr, x1, y2); + cairo_line_to (cr, x2, y2); if (right_triangle_width > 0.0) - cairo_line_to (cr, r + right_triangle_width, - (t + b) / 2); + cairo_line_to (cr, x2 + right_triangle_width, + (y1 + y2) / 2); - cairo_line_to (cr, r, t); + cairo_line_to (cr, x2, y1); cairo_close_path (cr); cairo_set_source_rgb (cr, 0, 0, 0); - cairo_set_line_width (cr, width); + cairo_set_line_width (cr, line_width); cairo_stroke (cr); - } cairo_restore (cr); @@ -494,35 +367,39 @@ print_border_with_triangles (GtkPrintContext *pc, fillcolor = shade of fill, -ve means no fill. */ static void print_border_rgb (GtkPrintContext *pc, - double l, double r, double t, double b, - double width, double red, double green, double blue) + gdouble x1, gdouble x2, + gdouble y1, gdouble y2, + gdouble line_width, + gdouble red, gdouble green, gdouble blue) { - print_border_with_triangles (pc, l, r, t, b, width, red, green, blue, -1.0, -1.0); + print_border_with_triangles ( + pc, x1, x2, y1, y2, line_width, + red, green, blue, -1.0, -1.0); } static void print_border (GtkPrintContext *pc, - double l, double r, double t, double b, - double width, double fillcolor) + gdouble x1, gdouble x2, + gdouble y1, gdouble y2, + gdouble line_width, + gdouble fillcolor) { - print_border_rgb (pc, l, r, t, b, width, fillcolor, fillcolor, fillcolor); + print_border_rgb ( + pc, x1, x2, y1, y2, line_width, + fillcolor, fillcolor, fillcolor); } static void -print_rectangle (GtkPrintContext *pc, - double l, double r, double t, double b, - double red, double green, double blue) +print_rectangle (GtkPrintContext *context, + gdouble x, gdouble y, + gdouble width, gdouble height, + gdouble red, gdouble green, gdouble blue) { - cairo_t *cr; - - cr = gtk_print_context_get_cairo_context (pc); + cairo_t *cr = gtk_print_context_get_cairo_context (context); + cairo_save (cr); - cairo_move_to (cr, l, t); - cairo_line_to (cr, l, b); - cairo_line_to (cr, r, b); - cairo_line_to (cr, r, t); - cairo_close_path (cr); + cairo_rectangle (cr, x, y, width, height); cairo_set_source_rgb (cr, red, green, blue); cairo_fill (cr); @@ -530,74 +407,62 @@ print_rectangle (GtkPrintContext *pc, } /* Prints 1 line of aligned text in a box. It is centered vertically, and - the horizontal alignment can be either ALIGN_LEFT, ALIGN_RIGHT, or - ALIGN_CENTER. */ + the horizontal alignment can be either PANGO_ALIGN_LEFT, PANGO_ALIGN_RIGHT, + or PANGO_ALIGN_CENTER. */ static double -print_text (EvoCalendarPrintRenderer *pr, PangoFontDescription *font, const char *text, - enum align_box align, double l, double r, double t, double b) +print_text (GtkPrintContext *context, PangoFontDescription *desc, + const char *text, PangoAlignment alignment, + gdouble x1, gdouble x2, gdouble y1, gdouble y2) { - double w, x; - int pw, ph; + PangoLayout *layout; + gint layout_width, layout_height; cairo_t *cr; - cr = gtk_print_context_get_cairo_context (pr->pc); - cairo_save (cr); + cr = gtk_print_context_get_cairo_context (context); + layout = gtk_print_context_create_pango_layout (context); - pango_layout_set_font_description (pr->pl, font); - pango_layout_set_text (pr->pl, text, -1); - pango_layout_set_width (pr->pl, -1); /* ensure no line-wrapping occurs */ - pango_layout_set_indent (pr->pl, 0); - pango_layout_get_size (pr->pl, &pw, &ph); - w = pw/(double)PANGO_SCALE; - - switch (align & 3) { - case ALIGN_LEFT: - default: - x = l; - break; - case ALIGN_RIGHT: - x = r - w; - break; - case ALIGN_CENTER: - x = l + ((r - l) - w) / 2; - break; - } + pango_layout_set_font_description (layout, desc); + pango_layout_set_alignment (layout, alignment); + pango_layout_set_text (layout, text, -1); - /* Make sure we don't go off the left edge. */ - x = MAX (l, x); + /* Grab the width before expanding the layout. */ + pango_layout_get_size (layout, &layout_width, &layout_height); + + pango_layout_set_width (layout, pango_units_from_double (x2 - x1)); + + cairo_save (cr); /* Set a clipping rectangle. */ - cairo_move_to (cr, l, t); - cairo_rectangle (cr, l, t, r, b); + cairo_move_to (cr, x1, y1); + cairo_rectangle (cr, x1, y1, x2, y2); cairo_clip (cr); cairo_new_path (cr); cairo_set_source_rgb (cr, 0, 0, 0); - cairo_move_to (cr, x, t); - pango_cairo_show_layout (cr, pr->pl); + cairo_move_to (cr, x1, y1); + pango_cairo_show_layout (cr, layout); cairo_stroke(cr); + cairo_restore (cr); - return w; + g_object_unref (layout); + + return pango_units_to_double (layout_width); } -/* gets/frees the font for you, as a book font */ +/* gets/frees the font for you, as a normal font */ static double -print_text_size(EvoCalendarPrintRenderer *pr, const char *text, - enum align_box align, double l, double r, double t, double b) +print_text_size (GtkPrintContext *context, const char *text, + PangoAlignment alignment, gdouble x1, gdouble x2, + gdouble y1, gdouble y2) { PangoFontDescription *font; double w; - - if(t > b) - font = get_font_for_size (pr,t - b, GNOME_FONT_BOOK, FALSE); - else - { - font = get_font_for_size (pr, b - t , GNOME_FONT_BOOK, FALSE); - } - w = print_text(pr, font, text, align, l, r, t, b); + + font = get_font_for_size (ABS (y2 - y1), PANGO_WEIGHT_NORMAL); + w = print_text (context, font, text, alignment, x1, x2, y1, y2); pango_font_description_free (font); return w; @@ -605,42 +470,36 @@ print_text_size(EvoCalendarPrintRenderer *pr, const char *text, /* gets/frees the font for you, as a bold font */ static double -print_text_size_bold(EvoCalendarPrintRenderer *pr, const char *text, - enum align_box align, double l, double r, double t, double b) +print_text_size_bold (GtkPrintContext *context, const char *text, + PangoAlignment alignment, gdouble x1, gdouble x2, + gdouble y1, gdouble y2) { PangoFontDescription *font; double w; - if (t > b) - font = get_font_for_size (pr, t - b , GNOME_FONT_BOLD, FALSE); - else - font = get_font_for_size (pr, b - t, GNOME_FONT_BOLD, FALSE); - - w = print_text(pr, font, text, align, l, r, t, b); + font = get_font_for_size (ABS (y2 - y1), PANGO_WEIGHT_BOLD); + w = print_text (context, font, text, alignment, x1, x2, y1, y2); pango_font_description_free (font); return w; } static void -titled_box (EvoCalendarPrintRenderer *pr, const char *text, PangoFontDescription *font, - enum align_box align, double *l, double *r, double *t, double *b, - double linewidth) +titled_box (GtkPrintContext *context, const char *text, + PangoFontDescription *font, PangoAlignment alignment, + gdouble *x1, gdouble *y1, gdouble *x2, gdouble *y2, + gdouble linewidth) { double size; size = get_font_size (font); - if (align & ALIGN_BORDER) { - print_border (pr->pc, *l, *r, *t, *t + size * 1.4, - linewidth, 0.9); - print_border (pr->pc, *l, *r, *t + size * 1.4, *b, - linewidth, -1.0); - *l += 2; - *r -= 2; - *b += 2; - } - print_text (pr, font, text, align, *l, *r, *t, *t + size * 1.4); - *t += size * 1.4; + print_border (context, *x1, *x2, *y1, *y1 + size * 1.4, linewidth, 0.9); + print_border (context, *x1, *x2, *y1 + size * 1.4, *y2, linewidth, -1.0); + *x1 += 2; + *x2 -= 2; + *y2 += 2; + print_text (context, font, text, alignment, *x1, *x2, *y1, *y1 + size * 1.4); + *y1 += size * 1.4; } enum datefmt { @@ -714,8 +573,8 @@ instance_cb (ECalComponent *comp, time_t instance_start, time_t instance_end, gp print out the month small, embolden any days with events. */ static void -print_month_small (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, time_t month, - double left, double right, double top, double bottom, +print_month_small (GtkPrintContext *context, GnomeCalendar *gcal, time_t month, + gdouble x1, gdouble y1, gdouble x2, gdouble y2, int titleflags, time_t greystart, time_t greyend, int bordertitle) { @@ -731,7 +590,7 @@ print_month_small (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, time_t mon double header_size, col_width, row_height, text_xpad, w; double cell_top, cell_bottom, cell_left, cell_right, text_right; - /* Translators: These are workday abbreviations, e.g. Su=Sunday and Th=Thursday */ + /* Translators: These are workday abbreviations, e.g. Su=Sunday and Th=thursday */ char *daynames[] = { N_("Su"), N_("Mo"), N_("Tu"), N_("We"), N_("Th"), N_("Fr"), N_("Sa") }; cairo_t *cr; @@ -739,29 +598,21 @@ print_month_small (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, time_t mon /* Print the title, e.g. 'June 2001', in the top 16% of the area. */ format_date (month, titleflags, buf, 100); - if(top < bottom) - header_size = (bottom - top) * 0.16; - else - header_size = (top - bottom) * 0.16; + header_size = ABS (y2 - y1) * 0.16; - font = get_font_for_size (pr, header_size, GNOME_FONT_BOLD, FALSE); - if (bordertitle) { - print_border (pr->pc, left, right, top, top + header_size, - 1.0, 0.9); - } - print_text (pr, font, buf, ALIGN_CENTER, left, right, - top, top + header_size); + font = get_font_for_size (header_size, PANGO_WEIGHT_BOLD); + if (bordertitle) + print_border (context, x1, x2, y1, y1 + header_size, 1.0, 0.9); + print_text (context, font, buf, PANGO_ALIGN_CENTER, x1, x2, + y1, y1 + header_size); pango_font_description_free (font); - top += header_size; - col_width = (right - left) / 7; + y1 += header_size; + col_width = (x2 - x1) / 7; /* The top row with the day abbreviations gets an extra bit of vertical space around it. */ - if (bottom > top ) - row_height = (bottom - top) / 7.4; - else - row_height = (top - bottom ) / 7.4; + row_height = ABS (y2 - y1) / 7.4; /* First we need to calculate a reasonable font size. We start with a rough guess of just under the height of each row. */ @@ -779,39 +630,41 @@ print_month_small (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, time_t mon tm = *convert_timet_to_struct_tm (month, zone); build_month (tm.tm_mon, tm.tm_year + 1900, days, 0, 0); - font_normal = get_font_for_size (pr, font_size, GNOME_FONT_BOOK, FALSE); - font_bold = get_font_for_size (pr, font_size, GNOME_FONT_BOLD, FALSE); + font_normal = get_font_for_size (font_size, PANGO_WEIGHT_NORMAL); + font_bold = get_font_for_size (font_size, PANGO_WEIGHT_BOLD); /* Get a reasonable estimate of the largest number we will need, and use it to calculate the offset from the right edge of the cell that we should put the numbers. */ - w = evo_calendar_print_renderer_get_width (pr, font_bold, "23"); + w = evo_calendar_print_renderer_get_width (context, font_bold, "23"); text_xpad = (col_width - w) / 2; - cr = gtk_print_context_get_cairo_context (pr->pc); + cr = gtk_print_context_get_cairo_context (context); cairo_set_source_rgb (cr, 0, 0, 0); /* Print the abbreviated day names across the top in bold. */ week_start_day = calendar_config_get_week_start_day (); weekday = week_start_day; for (x = 0; x < 7; x++) { - print_text (pr, font_bold, _(daynames[weekday]), ALIGN_CENTER, - left + x * col_width, left + (x + 1) * col_width, - top, top + row_height * 1.4); + print_text ( + context, font_bold, + _(daynames[weekday]), PANGO_ALIGN_RIGHT, + x1 + x * col_width, x1 + (x + 1) * col_width, + y1, y1 + row_height * 1.4); weekday = (weekday + 1) % 7; } - top += row_height * 1.4; + y1 += row_height * 1.4; now = time_month_begin_with_zone (month, zone); for (y = 0; y < 6; y++) { - cell_top = top + y * row_height; + cell_top = y1 + y * row_height; cell_bottom = cell_top + row_height; for (x = 0; x < 7; x++) { - cell_left = left + x * col_width; + cell_left = x1 + x * col_width; /* We add a 0.05 to make sure the cells meet up with each other. Otherwise you sometimes get lines between them which looks bad. Maybe I'm not using @@ -834,12 +687,12 @@ print_month_small (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, time_t mon next = time_add_day_with_zone (now, 1, zone); if ((now >= greystart && now < greyend) || (greystart >= now && greystart < next)) { - print_border (pr->pc, + print_border (context, cell_left, cell_right, cell_top, cell_bottom, -1.0, 0.75); } - print_text (pr, font, buf, ALIGN_RIGHT, + print_text (context, font, buf, PANGO_ALIGN_RIGHT, cell_left, text_right, cell_top, cell_bottom); @@ -851,43 +704,49 @@ print_month_small (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, time_t mon pango_font_description_free (font_bold); } - /* wraps text into the print context, not taking up more than its allowed space */ static double -bound_text (EvoCalendarPrintRenderer *pr, PangoFontDescription *font, const char *text, - double left, double right, double top, double bottom, double indent) +bound_text (GtkPrintContext *context, + PangoFontDescription *font, + const gchar *text, + gdouble x1, gdouble y1, + gdouble x2, gdouble y2) { - /* Let Pango do all the work: */ - int w=0, h=0; + PangoLayout *layout; + gint layout_width, layout_height; cairo_t *cr; - - cr = gtk_print_context_get_cairo_context (pr->pc); + + cr = gtk_print_context_get_cairo_context (context); + layout = gtk_print_context_create_pango_layout (context); + + pango_layout_set_font_description (layout, font); + pango_layout_set_text (layout, text, -1); + pango_layout_set_width (layout, pango_units_from_double (x2 - x1)); + pango_layout_get_size (layout, &layout_width, &layout_height); + cairo_save (cr); /* Set a clipping rectangle. */ - cairo_move_to (cr, left, top); - cairo_rectangle (cr, left, top, right, bottom); + cairo_move_to (cr, x1, y1); + cairo_rectangle (cr, x1, y1, x2, y2); cairo_clip (cr); cairo_new_path (cr); - pango_layout_set_font_description (pr->pl, font); - pango_layout_set_text (pr->pl, text, -1); - pango_layout_set_indent (pr->pl, indent * PANGO_SCALE); - pango_layout_set_width (pr->pl, (right-left)*PANGO_SCALE); - - cairo_move_to (cr, left, top); - pango_cairo_show_layout (cr, pr->pl); + cairo_move_to (cr, x1, y1); + pango_cairo_show_layout (cr, layout); cairo_stroke (cr); cairo_restore (cr); - pango_layout_get_size (pr->pl, &w, &h); - return top + ((double)h/(double)PANGO_SCALE); + + g_object_unref (layout); + + return y1 + pango_units_to_double (layout_height); } /* Draw the borders, lines, and times down the left of the day view. */ static void -print_day_background (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, +print_day_background (GtkPrintContext *context, GnomeCalendar *gcal, time_t whence, struct pdinfo *pdi, double left, double right, double top, double bottom) { @@ -903,16 +762,16 @@ print_day_background (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, cairo_t *cr; /* Fill the time column in light-gray. */ - print_border (pr->pc, left, left + width, top, bottom, -1.0, 0.9); + print_border (context, left, left + width, top, bottom, -1.0, 0.9); /* Draw the border around the entire view. */ - cr = gtk_print_context_get_cairo_context (pr->pc); + cr = gtk_print_context_get_cairo_context (context); cairo_set_source_rgb (cr, 0, 0, 0); - print_border (pr->pc, left, right, top, bottom, 1.0, -1.0); + print_border (context, left, right, top, bottom, 1.0, -1.0); /* Draw the vertical line on the right of the time column. */ - cr = gtk_print_context_get_cairo_context (pr->pc); + cr = gtk_print_context_get_cairo_context (context); cairo_set_line_width (cr, 0.0); cairo_move_to (cr, left + width, bottom); cairo_line_to (cr, left + width, top); @@ -928,12 +787,12 @@ print_day_background (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, font_size = yinc * 0.6; max_font_size = width * 0.5; hour_font_size = MIN (font_size, max_font_size); - font_hour = get_font_for_size (pr, hour_font_size, GNOME_FONT_BOLD, FALSE); + font_hour = get_font_for_size (hour_font_size, PANGO_WEIGHT_BOLD); font_size = yinc * 0.33; max_font_size = width * 0.25; minute_font_size = MIN (font_size, max_font_size); - font_minute = get_font_for_size (pr, minute_font_size, GNOME_FONT_BOLD, FALSE); + font_minute = get_font_for_size (minute_font_size, PANGO_WEIGHT_BOLD); use_24_hour = calendar_config_get_24_hour_format (); @@ -941,7 +800,7 @@ print_day_background (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, hour_minute_x = left + width * 0.58; for (i = pdi->start_hour; i < pdi->end_hour; i++) { y = top + yinc * (row + 1) ; - cr = gtk_print_context_get_cairo_context (pr->pc); + cr = gtk_print_context_get_cairo_context (context); cairo_set_source_rgb (cr, 0, 0, 0); if (use_24_hour) { @@ -960,16 +819,16 @@ print_day_background (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, /* the hour label/minute */ sprintf (buf, "%d", hour); - print_text (pr, font_hour, buf, ALIGN_RIGHT, + print_text (context, font_hour, buf, PANGO_ALIGN_RIGHT, left, hour_minute_x, y - yinc + yinc / 2, y - yinc + yinc / 2 + hour_font_size); - print_text (pr, font_minute, minute, ALIGN_LEFT, + print_text (context, font_minute, minute, PANGO_ALIGN_LEFT, hour_minute_x, left + width - 3, y - yinc + yinc / 2, y - yinc + yinc / 2 + minute_font_size); /* Draw the horizontal line between hours, across the entire width of the day view. */ - cr = gtk_print_context_get_cairo_context (pr->pc); + cr = gtk_print_context_get_cairo_context (context); cairo_move_to (cr, left, y); cairo_line_to (cr, right, y); cairo_set_line_width (cr, 1); @@ -1096,7 +955,7 @@ free_event_array (GArray *array) static void -print_day_long_event (EvoCalendarPrintRenderer *pr, PangoFontDescription *font, +print_day_long_event (GtkPrintContext *context, PangoFontDescription *font, double left, double right, double top, double bottom, double row_height, EDayViewEvent *event, struct pdinfo *pdi, ECalModel *model) @@ -1126,7 +985,7 @@ print_day_long_event (EvoCalendarPrintRenderer *pr, PangoFontDescription *font, y2 = y1 + row_height-7; red = green = blue = 0.95; e_cal_model_get_rgb_color_for_component (model, event->comp_data, &red, &green, &blue); - print_border_with_triangles (pr->pc, x1, x2, y1, y2, 0.5, red, green, blue, + print_border_with_triangles (context, x1, x2, y1, y2, 0.5, red, green, blue, left_triangle_width, right_triangle_width); @@ -1145,7 +1004,7 @@ print_day_long_event (EvoCalendarPrintRenderer *pr, PangoFontDescription *font, buffer, sizeof (buffer)); x1 += 4; - x1 += print_text (pr, font, buffer, ALIGN_LEFT, x1, x2, y1, y2); + x1 += print_text (context, font, buffer, PANGO_ALIGN_LEFT, x1, x2, y1, y2); } /* If the event ends before the end of the last day being printed, @@ -1163,7 +1022,7 @@ print_day_long_event (EvoCalendarPrintRenderer *pr, PangoFontDescription *font, buffer, sizeof (buffer)); x2 -= 4; - x2 -= print_text (pr, font, buffer, ALIGN_RIGHT, x1, x2, y1, y2); + x2 -= print_text (context, font, buffer, PANGO_ALIGN_RIGHT, x1, x2, y1, y2); } /* Print the text. */ @@ -1172,12 +1031,12 @@ print_day_long_event (EvoCalendarPrintRenderer *pr, PangoFontDescription *font, x1 += 4; x2 -= 4; - print_text (pr, font, text, ALIGN_CENTER, x1, x2, y1, y2); + print_text (context, font, text, PANGO_ALIGN_CENTER, x1, x2, y1, y2); } static void -print_day_event (EvoCalendarPrintRenderer *pr, PangoFontDescription *font, +print_day_event (GtkPrintContext *context, PangoFontDescription *font, double left, double right, double top, double bottom, EDayViewEvent *event, struct pdinfo *pdi, ECalModel *model) { @@ -1219,7 +1078,7 @@ print_day_event (EvoCalendarPrintRenderer *pr, PangoFontDescription *font, red = green = blue = 0.95; e_cal_model_get_rgb_color_for_component (model, event->comp_data, &red, &green, &blue); - print_border_rgb (pr->pc, x1, x2, y1, y2, 1.0, red, green, blue); + print_border_rgb (context, x1, x2, y1, y2, 1.0, red, green, blue); summary = icalcomponent_get_summary (event->comp_data->icalcomp); text = summary ? (char*) summary : ""; @@ -1249,7 +1108,7 @@ print_day_event (EvoCalendarPrintRenderer *pr, PangoFontDescription *font, free_text = TRUE; } - bound_text (pr, font, text, x1 + 2, x2 - 2, y1, y2, 0); + bound_text (context, font, text, x1 + 2, y1, x2 - 2, y2); if (free_text) g_free (text); @@ -1257,7 +1116,7 @@ print_day_event (EvoCalendarPrintRenderer *pr, PangoFontDescription *font, static void -print_day_details (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, time_t whence, +print_day_details (GtkPrintContext *context, GnomeCalendar *gcal, time_t whence, double left, double right, double top, double bottom) { icaltimezone *zone = calendar_config_get_icaltimezone (); @@ -1323,10 +1182,10 @@ print_day_details (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, time_t whe pdi.day_starts, &rows_in_top_display); /*Print the long events. */ - font = get_font_for_size (pr, 12, GNOME_FONT_BOOK, FALSE); + font = get_font_for_size (12, PANGO_WEIGHT_NORMAL); for (i = 0; i < pdi.long_events->len; i++) { event = &g_array_index (pdi.long_events, EDayViewEvent, i); - print_day_long_event (pr, font, left, right, top, bottom, + print_day_long_event (context, font, left, right, top, bottom, DAY_VIEW_ROW_HEIGHT, event, &pdi, model); } @@ -1337,10 +1196,10 @@ print_day_details (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, time_t whe DAY_VIEW_MIN_ROWS_IN_TOP_DISPLAY); /* Draw the border around the long events. */ - cr = gtk_print_context_get_cairo_context (pr->pc); + cr = gtk_print_context_get_cairo_context (context); cairo_set_source_rgb (cr, 0, 0, 0); - print_border (pr->pc, left, right, + print_border (context, left, right, top, top + rows_in_top_display * DAY_VIEW_ROW_HEIGHT - 4, 1.0, -1.0); @@ -1348,7 +1207,7 @@ print_day_details (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, time_t whe top += rows_in_top_display * DAY_VIEW_ROW_HEIGHT - 2; /* Draw the borders, lines, and times down the left. */ - print_day_background (pr, gcal, whence, &pdi, + print_day_background (context, gcal, whence, &pdi, left, right, top, bottom); /* Now adjust to get rid of the time column. */ left += DAY_VIEW_TIME_COLUMN_WIDTH; @@ -1364,11 +1223,11 @@ print_day_details (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, time_t whe else max_font_size = ((bottom - top ) / pdi.rows) - 4; font_size = MIN(DAY_NORMAL_FONT_SIZE, max_font_size); - font = get_font_for_size (pr, font_size, GNOME_FONT_BOOK, FALSE); + font = get_font_for_size (font_size, PANGO_WEIGHT_NORMAL); for (i = 0; i < pdi.events[0]->len; i++) { event = &g_array_index (pdi.events[0], EDayViewEvent, i); - print_day_event (pr, font, left, right, top, bottom, + print_day_event (context, font, left, right, top, bottom, event, &pdi, model); } @@ -1400,7 +1259,7 @@ print_is_one_day_week_event (EWeekViewEvent *event, static void -print_week_long_event (EvoCalendarPrintRenderer *pr, PangoFontDescription *font, +print_week_long_event (GtkPrintContext *context, PangoFontDescription *font, struct psinfo *psi, double x1, double x2, double y1, double y2, EWeekViewEvent *event, EWeekViewEventSpan *span, @@ -1420,7 +1279,7 @@ print_week_long_event (EvoCalendarPrintRenderer *pr, PangoFontDescription *font, if (event->end > psi->day_starts[span->start_day + span->num_days]) right_triangle_width = 4; - print_border_with_triangles (pr->pc, x1, x2, y1, y2 + 4, 0.5, red, green, blue, + print_border_with_triangles (context, x1, x2, y1, y2 + 4, 0.5, red, green, blue, left_triangle_width, right_triangle_width); @@ -1439,7 +1298,7 @@ print_week_long_event (EvoCalendarPrintRenderer *pr, PangoFontDescription *font, buffer, sizeof (buffer)); x1 += 4; - x1 += print_text_size (pr, buffer, ALIGN_LEFT, x1, x2, y1, y2); + x1 += print_text_size (context, buffer, PANGO_ALIGN_LEFT, x1, x2, y1, y2); } /* If the event ends before the end of the last day being printed, @@ -1457,17 +1316,17 @@ print_week_long_event (EvoCalendarPrintRenderer *pr, PangoFontDescription *font, buffer, sizeof (buffer)); x2 -= 4; - x2 -= print_text_size (pr, buffer, ALIGN_RIGHT, x1, x2, y1, y2); + x2 -= print_text_size (context, buffer, PANGO_ALIGN_RIGHT, x1, x2, y1, y2); } x1 += 4; x2 -= 4; - print_text_size (pr, text, ALIGN_CENTER, x1, x2, y1, y2); + print_text_size (context, text, PANGO_ALIGN_CENTER, x1, x2, y1, y2); } static void -print_week_day_event (EvoCalendarPrintRenderer *pr, PangoFontDescription *font, +print_week_day_event (GtkPrintContext *context, PangoFontDescription *font, struct psinfo *psi, double x1, double x2, double y1, double y2, EWeekViewEvent *event, EWeekViewEventSpan *span, @@ -1486,24 +1345,24 @@ print_week_day_event (EvoCalendarPrintRenderer *pr, PangoFontDescription *font, e_time_format_time (&date_tm, psi->use_24_hour_format, FALSE, buffer, sizeof (buffer)); - print_rectangle (pr->pc, x1, x2 + 6, y1, y2 + 4, red, green, blue); - x1 += print_text_size (pr, buffer, ALIGN_LEFT, x1, x2, y1, y2 + 3 ) + 4; - print_text_size (pr, text, ALIGN_LEFT, x1, x2, y1, y2 + 3); - + print_rectangle (context, x1, y1, (x2 + 6) - x1, (y2 + 4) - y1, red, green, blue); + x1 += print_text_size (context, buffer, PANGO_ALIGN_LEFT, x1, x2, y1, y2 + 3 ) + 4; + print_text_size (context, text, PANGO_ALIGN_LEFT, x1, x2, y1, y2 + 3); + date_tm.tm_hour = event->end_minute / 60; date_tm.tm_min = event->end_minute % 60; e_time_format_time (&date_tm, psi->use_24_hour_format, FALSE, buffer, sizeof (buffer)); - print_rectangle (pr->pc, x1, x2 + 6, y1, y2 + 4, red, green, blue); - x1 += print_text_size (pr, buffer, ALIGN_LEFT, x1, x2, y1, y2 + 3) + 4; - print_text_size (pr, text, ALIGN_LEFT, x1, x2, y1, y2 + 3); + print_rectangle (context, x1, y1, (x2 + 6) - x1, (y2 + 4) - y1, red, green, blue); + x1 += print_text_size (context, buffer, PANGO_ALIGN_LEFT, x1, x2, y1, y2 + 3) + 4; + print_text_size (context, text, PANGO_ALIGN_LEFT, x1, x2, y1, y2 + 3); } static void -print_week_event (EvoCalendarPrintRenderer *pr, PangoFontDescription *font, +print_week_event (GtkPrintContext *context, PangoFontDescription *font, struct psinfo *psi, double left, double top, double cell_width, double cell_height, @@ -1570,11 +1429,11 @@ print_week_event (EvoCalendarPrintRenderer *pr, PangoFontDescription *font, e_cal_model_get_rgb_color_for_component (model, event->comp_data, &red, &green, &blue); if (print_is_one_day_week_event (event, span, psi->day_starts)) { - print_week_day_event (pr, font, psi, + print_week_day_event (context, font, psi, x1, x2, y1, y2, event, span, text, red, green, blue); } else { - print_week_long_event (pr, font, psi, + print_week_long_event (context, font, psi, x1, x2, y1, y2, event, span, text, red, green, blue); } @@ -1584,7 +1443,8 @@ print_week_event (EvoCalendarPrintRenderer *pr, PangoFontDescription *font, static void -print_week_view_background (EvoCalendarPrintRenderer *pr, PangoFontDescription *font, +print_week_view_background (GtkPrintContext *context, + PangoFontDescription *font, struct psinfo *psi, double left, double top, double cell_width, double cell_height) @@ -1617,7 +1477,7 @@ print_week_view_background (EvoCalendarPrintRenderer *pr, PangoFontDescription * if (psi->multi_week_view && (tm.tm_mon != psi->month)) fillcolor = 0.9; - print_border (pr->pc, x1, x2, y1, y2, 1.0, fillcolor); + print_border (context, x1, x2, y1, y2, 1.0, fillcolor); if (psi->multi_week_view) { if (tm.tm_mday == 1) @@ -1625,7 +1485,7 @@ print_week_view_background (EvoCalendarPrintRenderer *pr, PangoFontDescription * else format_string = "%d"; } else { - cr = gtk_print_context_get_cairo_context (pr->pc); + cr = gtk_print_context_get_cairo_context (context); cairo_move_to (cr, x1 + 0.1 * cell_width, y1 + psi->header_row_height - 4); @@ -1646,7 +1506,7 @@ print_week_view_background (EvoCalendarPrintRenderer *pr, PangoFontDescription * e_utf8_strftime (buffer, sizeof (buffer), format_string, &tm); - print_text_size (pr, buffer, ALIGN_RIGHT, + print_text_size (context, buffer, PANGO_ALIGN_RIGHT, x1, x2 - 4, y1 + 2, y1 + 2 + font_size); } } @@ -1698,7 +1558,7 @@ print_week_summary_cb (ECalComponent *comp, } static void -print_week_summary (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, +print_week_summary (GtkPrintContext *context, GnomeCalendar *gcal, time_t whence, gboolean multi_week_view, int weeks_shown, int month, double font_size, double left, double right, double top, double bottom) @@ -1776,14 +1636,14 @@ print_week_summary (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, psi.rows_per_compressed_cell = (cell_height - psi.header_row_height) / psi.row_height; - font = get_font_for_size (pr, font_size, GNOME_FONT_BOOK, FALSE); + font = get_font_for_size (font_size, PANGO_WEIGHT_NORMAL); /* Draw the grid and the day names/numbers. */ - print_week_view_background (pr, font, &psi, left, top, + print_week_view_background (context, font, &psi, left, top, cell_width, cell_height); /* Print the events. */ for (event_num = 0; event_num < psi.events->len; event_num++) { event = &g_array_index (psi.events, EWeekViewEvent, event_num); - print_week_event (pr, font, &psi, left, top, + print_week_event (context, font, &psi, left, top, cell_width, cell_height, model, event, spans); } @@ -1799,7 +1659,7 @@ print_week_summary (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, static void -print_year_summary (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, time_t whence, +print_year_summary (GtkPrintContext *context, GnomeCalendar *gcal, time_t whence, double left, double right, double top, double bottom, int morerows) { @@ -1833,8 +1693,8 @@ print_year_summary (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, time_t wh for (col = 0; col < cols; col++) { l = left + col_width * col; r = l + col_width; - print_month_small (pr, gcal, now, - l + 8, r - 8, t - 8, b + 8, + print_month_small (context, gcal, now, + l + 8, t - 8, r - 8, b + 8, DATE_MONTH, 0, 0, TRUE); now = time_add_month_with_zone (now, 1, zone); } @@ -1842,7 +1702,7 @@ print_year_summary (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, time_t wh } static void -print_month_summary (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, time_t whence, +print_month_summary (GtkPrintContext *context, GnomeCalendar *gcal, time_t whence, double left, double right, double top, double bottom) { icaltimezone *zone = calendar_config_get_icaltimezone (); @@ -1880,7 +1740,7 @@ print_month_summary (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, time_t w tm = *convert_timet_to_struct_tm (date, zone); tm.tm_mday = (tm.tm_mday % 7) + 7; - font = get_font_for_size (pr, MONTH_NORMAL_FONT_SIZE, GNOME_FONT_BOLD, FALSE); + font = get_font_for_size (MONTH_NORMAL_FONT_SIZE, PANGO_WEIGHT_BOLD); font_size = get_font_size (font); columns = compress_weekend ? 6 : 7; @@ -1903,8 +1763,8 @@ print_month_summary (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, time_t w x1 = left + cell_width * col; x2 = x1 + cell_width; - print_border (pr->pc, x1, x2, y1, y2, 1.0, -1.0); - print_text_size (pr, buffer, ALIGN_CENTER, x1, x2, y1, y2); + print_border (context, x1, x2, y1, y2, 1.0, -1.0); + print_text_size (context, buffer, PANGO_ALIGN_CENTER, x1, x2, y1, y2); tm.tm_mday++; tm.tm_wday = (tm.tm_wday + 1) % 7; @@ -1912,14 +1772,14 @@ print_month_summary (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, time_t w pango_font_description_free (font); top = y2; - print_week_summary (pr, gcal, date, TRUE, 6, month, + print_week_summary (context, gcal, date, TRUE, 6, month, MONTH_NORMAL_FONT_SIZE, left, right, top, bottom); } static void -print_todo_details (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, +print_todo_details (GtkPrintContext *context, GnomeCalendar *gcal, time_t start, time_t end, double left, double right, double top, double bottom) { @@ -1938,16 +1798,16 @@ print_todo_details (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, table = e_calendar_table_get_table (task_pad); model = e_calendar_table_get_model (task_pad); - font_summary = get_font_for_size (pr, 12, GNOME_FONT_BOOK, FALSE); + font_summary = get_font_for_size (12, PANGO_WEIGHT_NORMAL); - cr = gtk_print_context_get_cairo_context (pr->pc); + cr = gtk_print_context_get_cairo_context (context); cairo_set_source_rgb (cr, 0, 0, 0); cairo_set_line_width (cr, 0.0); top +=2; - titled_box (pr, _("Tasks"), font_summary, ALIGN_CENTER | ALIGN_BORDER, - &left, &right, &top, &bottom, 1.0); + titled_box (context, _("Tasks"), font_summary, PANGO_ALIGN_CENTER, + &left, &top, &right, &bottom, 1.0); y = top; yend = bottom - 2; @@ -1979,14 +1839,14 @@ print_todo_details (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, break; /* Print the box to put the tick in. */ - print_border (pr->pc, x + 2, x + 8, y + 6, y + 15, 0.1, -1.0); + print_border (context, x + 2, x + 8, y + 6, y + 15, 0.1, -1.0); /* If the task is complete, print a tick in the box. */ e_cal_component_get_completed (comp, &tt); if (tt) { e_cal_component_free_icaltimetype (tt); - cr = gtk_print_context_get_cairo_context (pr->pc); + cr = gtk_print_context_get_cairo_context (context); cairo_set_source_rgb (cr, 0, 0, 0); cairo_move_to (cr, x + 3, y + 11); cairo_line_to (cr, x + 5, y + 14); @@ -1995,12 +1855,12 @@ print_todo_details (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, cairo_stroke (cr); } - y = bound_text (pr, font_summary, summary.value, - x + 14, xend, y+4, yend, 0); + y = bound_text (context, font_summary, summary.value, + x + 14, y + 4, xend, yend); y += get_font_size (font_summary)-5; - cr = gtk_print_context_get_cairo_context (pr->pc); + cr = gtk_print_context_get_cairo_context (context); cairo_move_to (cr, x, y); cairo_line_to (cr, xend, y); cairo_set_line_width (cr, 1); @@ -2012,146 +1872,53 @@ print_todo_details (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, pango_font_description_free (font_summary); } - -/* Value for the PrintView enum */ -static const int print_view_map[] = { - PRINT_VIEW_DAY, - PRINT_VIEW_WEEK, - PRINT_VIEW_MONTH, - PRINT_VIEW_YEAR, - -1 -}; - -/* Creates the range selector widget for printing a calendar */ -static GtkWidget * -range_selector_new (GtkWidget *dialog, time_t at, int *view) -{ - icaltimezone *zone = calendar_config_get_icaltimezone (); - GtkWidget *box; - GtkWidget *radio; - GSList *group; - char text[1024]; - char str1[512]; - char str2[512]; - struct tm tm; - time_t week_begin, week_end; - struct tm week_begin_tm, week_end_tm; - gint week_start_day; - - box = gtk_vbox_new (FALSE, GNOME_PAD_SMALL); - - tm = *convert_timet_to_struct_tm (at, zone); - - /* Day */ - - e_utf8_strftime (text, sizeof (text), _("Selected day (%a %b %d %Y)"), &tm); - radio = gtk_radio_button_new_with_label (NULL, text); - group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)); - gtk_box_pack_start (GTK_BOX (box), radio, FALSE, FALSE, 0); - - /* Week */ - - week_start_day = calendar_config_get_week_start_day (); - week_begin = time_week_begin_with_zone (at, week_start_day, zone); - /* If the week starts on a Sunday, we have to show the Saturday first, - since the weekend is compressed. If the original date passed in was - a Saturday, we need to move on to the next Saturday, else we move - back to the last one. */ - if (week_start_day == 0) { - if (tm.tm_wday == 6) - week_begin = time_add_day_with_zone (week_begin, 6, zone); - else - week_begin = time_add_day_with_zone (week_begin, -1, zone); - } - week_end = time_add_day_with_zone (week_begin, 6, zone); - - week_begin_tm = *convert_timet_to_struct_tm (week_begin, zone); - week_end_tm = *convert_timet_to_struct_tm (week_end, zone); - - if (week_begin_tm.tm_mon == week_end_tm.tm_mon) { - e_utf8_strftime (str1, sizeof (str1), _("%a %b %d"), &week_begin_tm); - e_utf8_strftime (str2, sizeof (str2), _("%a %d %Y"), &week_end_tm); - } else { - if (week_begin_tm.tm_year == week_end_tm.tm_year) { - e_utf8_strftime (str1, sizeof (str1), _("%a %b %d"), &week_begin_tm); - e_utf8_strftime (str2, sizeof (str2), _("%a %b %d %Y"), &week_end_tm); - } else { - e_utf8_strftime (str1, sizeof (str1), _("%a %b %d %Y"), &week_begin_tm); - e_utf8_strftime (str2, sizeof (str2), _("%a %b %d %Y"), &week_end_tm); - } - } - - g_snprintf (text, sizeof (text), _("Selected week (%s - %s)"), str1, str2); - - radio = gtk_radio_button_new_with_label (group, text); - group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)); - gtk_box_pack_start (GTK_BOX (box), radio, FALSE, FALSE, 0); - - /* Month */ - - e_utf8_strftime (text, sizeof (text), _("Selected month (%b %Y)"), &tm); - radio = gtk_radio_button_new_with_label (group, text); - group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)); - gtk_box_pack_start (GTK_BOX (box), radio, FALSE, FALSE, 0); - - /* Year */ - - e_utf8_strftime (text, sizeof (text), _("Selected year (%Y)"), &tm); - radio = gtk_radio_button_new_with_label (group, text); - group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio)); - gtk_box_pack_start (GTK_BOX (box), radio, FALSE, FALSE, 0); - - /* Select default */ - - e_dialog_widget_hook_value (dialog, radio, view, (gpointer) print_view_map); - - gtk_widget_show_all (box); - return box; -} - - static void -print_day_view (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, time_t date, - double left, double right, double top, double bottom) +print_day_view (GtkPrintContext *context, GnomeCalendar *gcal, time_t date) { + GtkPageSetup *setup; icaltimezone *zone = calendar_config_get_icaltimezone (); int i, days = 1; - double todo, header, l; + double todo, l; char buf[100]; cairo_t *cr; + gdouble width, height; + + setup = gtk_print_context_get_page_setup (context); + + width = gtk_page_setup_get_page_width (setup, GTK_UNIT_POINTS); + height = gtk_page_setup_get_page_height (setup, GTK_UNIT_POINTS); for (i = 0; i < days; i++) { - todo = (right - left) * 0.75 + left; - /* header = top - HEADER_HEIGHT;*/ - header = HEADER_HEIGHT + top; + todo = width * 0.75; - cr = gtk_print_context_get_cairo_context (pr->pc); + cr = gtk_print_context_get_cairo_context (context); /* Print the main view with all the events in. */ - print_day_details (pr, gcal, date, - left, todo - 2.0, header, bottom); + print_day_details (context, gcal, date, + 0.0, todo - 2.0, HEADER_HEIGHT, + height); /* Print the TaskPad down the right. */ - print_todo_details (pr, gcal, 0, INT_MAX, - todo, right, header, bottom); + print_todo_details (context, gcal, 0, INT_MAX, + todo, width, HEADER_HEIGHT, + height); /* Print the filled border around the header. */ - print_border (pr->pc, left, right, top, header + 2.0, 1.0, 0.9); + print_border (context, 0.0, width, + 0.0, HEADER_HEIGHT + 2.0, 1.0, 0.9); /* Print the 2 mini calendar-months. */ - l = right - SMALL_MONTH_PAD - SMALL_MONTH_WIDTH * 2 - SMALL_MONTH_SPACING; + l = width - SMALL_MONTH_PAD - SMALL_MONTH_WIDTH * 2 - SMALL_MONTH_SPACING; - print_month_small (pr, gcal, date, - l, l + SMALL_MONTH_WIDTH, - top + 4, header + 4, + print_month_small (context, gcal, date, + l, 4, l + SMALL_MONTH_WIDTH, HEADER_HEIGHT + 4, DATE_MONTH | DATE_YEAR, date, date, FALSE); l += SMALL_MONTH_SPACING + SMALL_MONTH_WIDTH; - print_month_small (pr, gcal, + print_month_small (context, gcal, time_add_month_with_zone (date, 1, zone), - l, l + SMALL_MONTH_WIDTH, - top + 4, header + 4, + l, 4, l + SMALL_MONTH_WIDTH, HEADER_HEIGHT + 4, DATE_MONTH | DATE_YEAR, 0, 0, FALSE); @@ -2159,32 +1926,38 @@ print_day_view (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, time_t date, format_date (date, DATE_DAY | DATE_MONTH | DATE_YEAR, buf, 100); - print_text_size_bold (pr, buf, ALIGN_LEFT, - left + 4, todo, top + 4, top + 4 + 24); + print_text_size_bold (context, buf, PANGO_ALIGN_LEFT, + 4, todo, 4, + 4 + 24); /* Print the day, e.g. 'Tuesday'. */ format_date (date, DATE_DAYNAME, buf, 100); - print_text_size_bold (pr, buf, ALIGN_LEFT, - left + 4, todo, top + 32, top + 32 + 18); + print_text_size_bold (context, buf, PANGO_ALIGN_LEFT, + 4, todo, 32, + 32 + 18); date = time_add_day_with_zone (date, 1, zone); } } - static void -print_week_view (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, time_t date, - double left, double right, double top, double bottom) +print_week_view (GtkPrintContext *context, GnomeCalendar *gcal, time_t date) { + GtkPageSetup *setup; icaltimezone *zone = calendar_config_get_icaltimezone (); - double header, l; + double l; char buf[100]; time_t when; gint week_start_day; struct tm tm; + gdouble width, height; + + setup = gtk_print_context_get_page_setup (context); + + width = gtk_page_setup_get_page_width (setup, GTK_UNIT_POINTS); + height = gtk_page_setup_get_page_height (setup, GTK_UNIT_POINTS); - header = HEADER_HEIGHT - top; tm = *convert_timet_to_struct_tm (date, zone); week_start_day = calendar_config_get_week_start_day (); when = time_week_begin_with_zone (date, week_start_day, zone); @@ -2199,101 +1972,115 @@ print_week_view (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, time_t date, } /* Print the main week view. */ - print_week_summary (pr, gcal, when, FALSE, 1, 0, + print_week_summary (context, gcal, when, FALSE, 1, 0, WEEK_NORMAL_FONT_SIZE, - left, right, header + 20, bottom); + 0.0, width, + HEADER_HEIGHT + 20, height); /* Print the border around the main view. */ - print_border (pr->pc, left, right, header , bottom, 1.0, -1.0); + print_border (context, 0.0, width, HEADER_HEIGHT , + height, 1.0, -1.0); /* Print the border around the header area. */ - print_border (pr->pc, left, right, top, header + 2.0 + 20, 1.0, 0.9); + print_border (context, 0.0, width, + 0.0, HEADER_HEIGHT + 2.0 + 20, 1.0, 0.9); /* Print the 2 mini calendar-months. */ - l = right - SMALL_MONTH_PAD - SMALL_MONTH_WIDTH * 2 + l = width - SMALL_MONTH_PAD - SMALL_MONTH_WIDTH * 2 - SMALL_MONTH_SPACING; - print_month_small (pr, gcal, when, - l, l + SMALL_MONTH_WIDTH, - top + 4, header + 30, + print_month_small (context, gcal, when, + l, 4, l + SMALL_MONTH_WIDTH, HEADER_HEIGHT + 30, DATE_MONTH | DATE_YEAR, when, time_add_week_with_zone (when, 1, zone), FALSE); l += SMALL_MONTH_SPACING + SMALL_MONTH_WIDTH; - print_month_small (pr, gcal, + print_month_small (context, gcal, time_add_month_with_zone (when, 1, zone), - l, l + SMALL_MONTH_WIDTH, - top + 4, header + 30, + l, 4, l + SMALL_MONTH_WIDTH, HEADER_HEIGHT + 30, DATE_MONTH | DATE_YEAR, when, time_add_week_with_zone (when, 1, zone), FALSE); /* Print the start day of the week, e.g. '7th May 2001'. */ format_date (when, DATE_DAY | DATE_MONTH | DATE_YEAR, buf, 100); - print_text_size_bold (pr, buf, ALIGN_LEFT, - left + 3, right, top + 4, top + 4 + 24); + print_text_size_bold (context, buf, PANGO_ALIGN_LEFT, + 3, width, + 4, 4 + 24); /* Print the end day of the week, e.g. '13th May 2001'. */ when = time_add_day_with_zone (when, 6, zone); format_date (when, DATE_DAY | DATE_MONTH | DATE_YEAR, buf, 100); - print_text_size_bold (pr, buf, ALIGN_LEFT, - left + 3, right, top + 24 + 3, top + 24 + 3 + 24); + print_text_size_bold (context, buf, PANGO_ALIGN_LEFT, + 3, width, + 24 + 3, 24 + 3 + 24); } static void -print_month_view (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, time_t date, - double left, double right, double top, double bottom) +print_month_view (GtkPrintContext *context, GnomeCalendar *gcal, time_t date) { + GtkPageSetup *setup; icaltimezone *zone = calendar_config_get_icaltimezone (); - double header; char buf[100]; + gdouble width, height; + + setup = gtk_print_context_get_page_setup (context); - header = top + HEADER_HEIGHT; + width = gtk_page_setup_get_page_width (setup, GTK_UNIT_POINTS); + height = gtk_page_setup_get_page_height (setup, GTK_UNIT_POINTS); /* Print the main month view. */ - print_month_summary (pr, gcal, date, left, right, header, bottom); + print_month_summary (context, gcal, date, 0.0, width, HEADER_HEIGHT, height); /* Print the border around the header. */ - print_border (pr->pc, left, right, top, header, 1.0, 0.9); + print_border (context, 0.0, width, 0.0, HEADER_HEIGHT, 1.0, 0.9); /* Print the 2 mini calendar-months. */ - print_month_small (pr, gcal, + print_month_small (context, gcal, time_add_month_with_zone (date, 1, zone), - right - (right - left) / 7 + 2, right - 8, - top + 4, header, + width - width / 7 + 2, 4, + width - 8, HEADER_HEIGHT, DATE_MONTH | DATE_YEAR, 0, 0, FALSE); - print_month_small (pr, gcal, + print_month_small (context, gcal, time_add_month_with_zone (date, -1, zone), - left + 8, left + (right - left) / 7 - 2, - top + 4, header, + 8, 4, width / 7 - 2, HEADER_HEIGHT, DATE_MONTH | DATE_YEAR, 0, 0, FALSE); /* Print the month, e.g. 'May 2001'. */ format_date (date, DATE_MONTH | DATE_YEAR, buf, 100); - print_text_size_bold (pr, buf, ALIGN_CENTER, - left + 3, right - 3, top + 3, top + 3 + 24); + print_text_size_bold (context, buf, PANGO_ALIGN_CENTER, + 3, width - 3, + 3, 3 + 24); } - +/* XXX Evolution doesn't have a "year" view. */ static void -print_year_view (EvoCalendarPrintRenderer *pr, GnomeCalendar *gcal, time_t date, - double left, double right, double top, double bottom) +print_year_view (GtkPrintContext *context, GnomeCalendar *gcal, time_t date) { + GtkPageSetup *setup; char buf[100]; cairo_t *cr; + gdouble width, height; + + setup = gtk_print_context_get_page_setup (context); - cr = gtk_print_context_get_cairo_context (pr->pc); + width = gtk_page_setup_get_page_width (setup, GTK_UNIT_POINTS); + height = gtk_page_setup_get_page_height (setup, GTK_UNIT_POINTS); + + cr = gtk_print_context_get_cairo_context (context); cairo_show_page (cr); - print_year_summary (pr, gcal, date, left, right, top + 50, bottom, - TRUE); + print_year_summary (context, gcal, date, 0.0, + width, 50, + height, TRUE); /* centered title */ format_date (date, DATE_YEAR, buf, 100); - print_text_size_bold (pr, buf, ALIGN_CENTER, - left+3, right, top+3, top + 27); - cr=gtk_print_context_get_cairo_context (pr->pc); + print_text_size_bold (context, buf, PANGO_ALIGN_CENTER, + 3, width, + 3, 27); + cr=gtk_print_context_get_cairo_context (context); cairo_show_page (cr); } @@ -2337,7 +2124,7 @@ get_zone_from_tzid (ECal *client, const char *tzid) } static void -print_date_label (EvoCalendarPrintRenderer *pr, ECalComponent *comp, ECal *client, +print_date_label (GtkPrintContext *context, ECalComponent *comp, ECal *client, double left, double right, double top, double bottom) { icaltimezone *start_zone, *end_zone, *due_zone, *completed_zone; @@ -2405,16 +2192,65 @@ print_date_label (EvoCalendarPrintRenderer *pr, ECalComponent *comp, ECal *clien write_label_piece (due, buffer, 1024, _("Due "), NULL); } - print_text_size_bold (pr, buffer, ALIGN_LEFT, + print_text_size_bold (context, buffer, PANGO_ALIGN_LEFT, left, right, top, top - 15); } static void -print_comp_item (PrintCompItem *pci) - +print_calendar_draw_page (GtkPrintOperation *operation, + GtkPrintContext *context, + gint page_nr, + PrintCalItem *pcali) +{ + switch (gnome_calendar_get_view (pcali->gcal)) { + case GNOME_CAL_DAY_VIEW: + print_day_view (context, pcali->gcal, pcali->start); + break; + case GNOME_CAL_WORK_WEEK_VIEW: + case GNOME_CAL_WEEK_VIEW: + print_week_view (context, pcali->gcal, pcali->start); + break; + case GNOME_CAL_MONTH_VIEW: + print_month_view (context, pcali->gcal, pcali->start); + break; + default: + g_assert_not_reached (); + } +} + +void +print_calendar (GnomeCalendar *gcal, GtkPrintOperationAction action, + time_t start) +{ + GtkPrintOperation *operation; + PrintCalItem pcali; + + g_return_if_fail (gcal != NULL); + g_return_if_fail (GNOME_IS_CALENDAR (gcal)); + + pcali.gcal = gcal; + pcali.start = start; + + operation = e_print_operation_new (); + gtk_print_operation_set_n_pages (operation, 1); + + g_signal_connect ( + operation, "draw_page", + G_CALLBACK (print_calendar_draw_page), &pcali); + + gtk_print_operation_run (operation, action, NULL, NULL); + + g_object_unref (operation); +} + +static void +print_comp_draw_page (GtkPrintOperation *operation, + GtkPrintContext *context, + gint page_nr, + PrintCompItem *pci) { + GtkPageSetup *setup; PangoFontDescription *font; - EvoCalendarPrintRenderer *pr; ECal *client; ECalComponent *comp; ECalComponentVType vtype; @@ -2426,20 +2262,19 @@ print_comp_item (PrintCompItem *pci) char *categories_string, *location_string, *summary_string; double header_size; cairo_t *cr; - double left, right, top, bottom; + gdouble width, height; + double top; + + setup = gtk_print_context_get_page_setup (context); + + width = gtk_page_setup_get_page_width (setup, GTK_UNIT_POINTS); + height = gtk_page_setup_get_page_height (setup, GTK_UNIT_POINTS); /* PrintCompItem structure contains elements to be used * with the Print Context , obtained in comp_draw_page */ - comp = g_new0 (ECalComponent, 1); - client = g_new0 (ECal, 1); - pr = pci->pr; client = pci->client; comp = pci->comp; - left = pci->l; - right = pci->r; - top = pci->t; - bottom = pci->b; vtype = e_cal_component_get_vtype (comp); @@ -2453,25 +2288,25 @@ print_comp_item (PrintCompItem *pci) else return; - cr = gtk_print_context_get_cairo_context (pr->pc); + cr = gtk_print_context_get_cairo_context (context); /* Print the title in a box at the top of the page. */ - font = get_font_for_size (pr, 18, GNOME_FONT_BOLD, FALSE); + font = get_font_for_size (18, PANGO_WEIGHT_BOLD); header_size = 40; - print_border (pr->pc, left, right, top, top+header_size, + print_border (context, 0.0, width, 0.0, header_size, 1.0, 0.9); - print_text (pr, font, title, ALIGN_CENTER, left, right, - top + 0.1, top +header_size - 0.1); + print_text (context, font, title, PANGO_ALIGN_CENTER, 0.0, width, + 0.1, header_size - 0.1); pango_font_description_free (font); - top += header_size + 30; + top = header_size + 30; /* Summary */ - font = get_font_for_size (pr, 18, GNOME_FONT_BOLD, FALSE); + font = get_font_for_size (18, PANGO_WEIGHT_BOLD); e_cal_component_get_summary (comp, &text); summary_string = g_strdup_printf (_("Summary: %s"), text.value); - top = bound_text (pr, font, summary_string, left, right, - top, bottom, 0); + top = bound_text (context, font, summary_string, 0.0, top, width, + height); g_free (summary_string); @@ -2480,16 +2315,16 @@ print_comp_item (PrintCompItem *pci) if (location && location[0]) { location_string = g_strdup_printf (_("Location: %s"), location); - top = bound_text (pr, font, location_string, left, right, - top + 3, bottom, 0); + top = bound_text (context, font, location_string, 0.0, + top + 3, width, height); g_free (location_string); } pango_font_description_free (font); /* Date information */ - print_date_label (pr, comp, client, left, right, top + 3, top + 15); + print_date_label (context, comp, client, 0.0, width, top + 3, top + 15); top += 20; - font = get_font_for_size (pr, 12, GNOME_FONT_BOOK, FALSE); + font = get_font_for_size (12, PANGO_WEIGHT_NORMAL); /* For a VTODO we print the Status, Priority, % Complete and URL. */ if (vtype == E_CAL_COMPONENT_TODO) { @@ -2522,8 +2357,8 @@ print_comp_item (PrintCompItem *pci) if (status_string) { char *status_text = g_strdup_printf (_("Status: %s"), status_string); - top = bound_text (pr, font, status_text, - left, right, top, bottom, 0); + top = bound_text (context, font, status_text, + 0.0, top, width, height); top += get_font_size (font) - 6; g_free (status_text); } @@ -2538,8 +2373,8 @@ print_comp_item (PrintCompItem *pci) e_cal_component_free_priority (priority); pri_text = g_strdup_printf (_("Priority: %s"), priority_string); - top = bound_text (pr, font, pri_text, - left, right, top, bottom, 0); + top = bound_text (context, font, pri_text, + 0.0, top, width, height); top += get_font_size (font) - 6; g_free (pri_text); } @@ -2552,8 +2387,8 @@ print_comp_item (PrintCompItem *pci) percent_string = g_strdup_printf (_("Percent Complete: %i"), *percent); e_cal_component_free_percent (percent); - top = bound_text (pr, font, percent_string, - left, right, top, bottom, 0); + top = bound_text (context, font, percent_string, + 0.0, top, width, height); top += get_font_size (font) - 6; } @@ -2564,8 +2399,8 @@ print_comp_item (PrintCompItem *pci) char *url_string = g_strdup_printf (_("URL: %s"), url); - top = bound_text (pr, font, url_string, - left, right, top, bottom, 0); + top = bound_text (context, font, url_string, + 0.0, top, width, height); top += get_font_size (font) - 6; g_free (url_string); } @@ -2576,8 +2411,8 @@ print_comp_item (PrintCompItem *pci) if (categories && categories[0]) { categories_string = g_strdup_printf (_("Categories: %s"), categories); - top = bound_text (pr, font, categories_string, - left, right, top, bottom, 0); + top = bound_text (context, font, categories_string, + 0.0, top, width, height); top += get_font_size (font) - 6 ; g_free (categories_string); } @@ -2595,8 +2430,8 @@ print_comp_item (PrintCompItem *pci) } e_cal_component_free_text_list (contact_list); - top = bound_text (pr, font, contacts->str, - left, right, top, bottom, 0); + top = bound_text (context, font, contacts->str, + 0.0, top, width, height); top += get_font_size (font) - 6; g_string_free (contacts, TRUE); } @@ -2606,12 +2441,12 @@ print_comp_item (PrintCompItem *pci) e_cal_component_get_description_list (comp, &desc); for (l = desc; l != NULL; l = l->next) { ECalComponentText *text = l->data; - if (top > bottom) { + if (top > height) { top = 10; //FIXME cairo_show_page (cr); } if (text->value != NULL) - top = bound_text (pr, font, text->value, left, right, top + 3, bottom, 0) + 30; + top = bound_text (context, font, text->value, 0.0, top + 3, width, height) + 30; } @@ -2621,311 +2456,99 @@ print_comp_item (PrintCompItem *pci) } void -print_calendar (GnomeCalendar *gcal, gboolean preview, time_t date, - PrintView default_view) +print_comp (ECalComponent *comp, ECal *client, GtkPrintOperationAction action) { - GtkPrintSettings *settings; - GtkPrintOperationResult res; - GtkPrintOperation *print; - GtkPaperSize *paper_size; - GtkPageSetup *page_setup; - GtkWidget *gpd; - GtkWidget *range; - PrintCalItem *pcali; - int view; - double r, t, w, h; + GtkPrintOperation *operation; + PrintCompItem pci; - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - - view = (int) default_view; + g_return_if_fail (E_IS_CAL_COMPONENT (comp)); - pcali = g_new0 (PrintCalItem, 1); - pcali->gcal = g_new0 (GnomeCalendar, 1); + pci.comp = comp; + pci.client = client; - print = gtk_print_operation_new (); - paper_size = gtk_paper_size_new ("iso_a4"); - page_setup = gtk_page_setup_new(); - gtk_page_setup_set_paper_size(page_setup, paper_size); + operation = e_print_operation_new (); - settings = gtk_print_settings_new (); - settings = e_print_load_settings (); - gpd = e_print_get_dialog_with_config (_("Print Item"), 0, settings); - range = range_selector_new (gpd, date, &view); + g_signal_connect ( + operation, "draw-page", + G_CALLBACK (print_comp_draw_page), &pci); - t = gtk_paper_size_get_default_top_margin (paper_size, GTK_UNIT_POINTS); - r = gtk_paper_size_get_default_right_margin (paper_size, GTK_UNIT_POINTS); - w = gtk_paper_size_get_width (paper_size, GTK_UNIT_POINTS); - h = gtk_paper_size_get_height (paper_size, GTK_UNIT_POINTS); - - pcali->b = h * (1.0 - TEMP_MARGIN); - pcali->l = r * TEMP_MARGIN; - pcali->t = t * (1.0 - TEMP_MARGIN); - pcali->r = w * (1.0 - TEMP_MARGIN); - pcali->default_view = default_view; - pcali->gcal = gcal; - pcali->date = date; - - gtk_print_operation_set_default_page_setup (print, page_setup); - gtk_print_operation_set_n_pages (print, 1); - - /* FIX ME ,Allow it to use the default settings for the first time */ - gtk_print_operation_set_print_settings (print, settings); - - g_signal_connect (print, "create-custom-widget", G_CALLBACK (create_custom_widget), range); - g_signal_connect (print, "custom-widget-apply", G_CALLBACK (apply_custom_widget), NULL); - g_signal_connect (print, "draw_page", G_CALLBACK (cal_draw_page), pcali); - - /* Runs the print dialog, recursively, emitting signals */ - if (preview) - gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PREVIEW, NULL, NULL); - else - res = gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL, NULL); - - /* Save the user configured settings back to the gconf */ - settings = gtk_print_operation_get_print_settings (print); - e_print_save_settings (settings); - - if (res == GTK_PRINT_OPERATION_RESULT_APPLY) { - g_object_unref (print); - } - else if (res == GTK_PRINT_OPERATION_RESULT_ERROR) { - /* FIX ME */ - - } + gtk_print_operation_run (operation, action, NULL, NULL); -} - -void -print_comp (ECalComponent *comp, ECal *client, gboolean preview) -{ - GtkPrintOperation *print; - GtkPrintSettings *settings; - GtkPaperSize *paper_size; - PrintCompItem *pci; - GtkPrintOperationResult res; - GtkPageSetup *page_setup; - gdouble t, r, w,h; - GtkWidget *gpd; - - g_return_if_fail (comp != NULL); - g_return_if_fail (E_IS_CAL_COMPONENT (comp)); - - pci = g_new0 (PrintCompItem, 1); - - print = gtk_print_operation_new (); - paper_size = gtk_paper_size_new ("iso_a4"); - page_setup = gtk_page_setup_new(); - gtk_page_setup_set_paper_size(page_setup, paper_size); - - settings = gtk_print_settings_new (); - settings = e_print_load_settings (); - gpd = e_print_get_dialog_with_config (_("Print Item"), 0, settings); - - /* Values using the print context , used in comp_draw_page */ - t = gtk_paper_size_get_default_top_margin (paper_size, GTK_UNIT_POINTS); - r = gtk_paper_size_get_default_right_margin (paper_size, GTK_UNIT_POINTS); - w = gtk_paper_size_get_width (paper_size, GTK_UNIT_POINTS); - h = gtk_paper_size_get_height (paper_size, GTK_UNIT_POINTS); - pci->b = h * (1.0 - TEMP_MARGIN); - pci->l = r * TEMP_MARGIN; - pci->t = t * (1.0 - TEMP_MARGIN); - pci->r = w * (1.0 - TEMP_MARGIN); - pci->comp = comp; - pci->client = client; - - gtk_print_operation_set_default_page_setup (print, page_setup); - gtk_print_operation_set_n_pages (print, 1); - - /* FIX ME ,Allow it to use the default settings for the first time */ - gtk_print_operation_set_print_settings (print, settings); - - g_signal_connect (print, "draw_page", G_CALLBACK (comp_draw_page), pci); - - gtk_print_operation_set_print_settings (print, settings); - - /* Runs a dialog , emitting various signals based on user response */ - if (preview) - gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL, NULL); - else - res = gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG , NULL, NULL); - - /* Saves the user configuration in gconf */ - settings = gtk_print_operation_get_print_settings (print); - e_print_save_settings (settings); - - if (res == GTK_PRINT_OPERATION_RESULT_APPLY) { - g_object_unref (print); - } - else if ( res == GTK_PRINT_OPERATION_RESULT_ERROR) { - /* FIX ME */ - } + g_object_unref (operation); } static void -print_title (GtkPrintContext *context, const char *title, - double page_width, double page_height, double left_margin, double bottom_margin) +print_title (GtkPrintContext *context, const gchar *text, gdouble page_width) { - PangoFontDescription *font; - PangoLayout *pl; - double w, x, y; + PangoFontDescription *desc; + PangoLayout *layout; cairo_t *cr; cr = gtk_print_context_get_cairo_context (context); - cairo_save (cr); - pl = gtk_print_context_create_pango_layout (context); - font = pango_font_description_from_string("Sans Bold 18"); - pango_layout_set_font_description (pl, font); - pango_layout_set_text (pl, title, -1); - - w = pango_layout_get_width (pl)/(double)PANGO_SCALE; - y = page_height ; - x = (page_width - w) / 2; - - cairo_move_to (cr, x, y ); - pango_cairo_show_layout (cr, pl); + desc = pango_font_description_from_string (FONT_FAMILY " Bold 18"); - cairo_restore (cr); - pango_font_description_free (font); + layout = gtk_print_context_create_pango_layout (context); + pango_layout_set_text (layout, text, -1); + pango_layout_set_font_description (layout, desc); + pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER); + pango_layout_set_width (layout, pango_units_from_double (page_width)); -} + cairo_save (cr); -void -print_table (ETable *etable, const char *dialog_title, const char *print_header, gboolean preview) -{ - EPrintable *printable; - GtkPrintOperationResult res; - GtkPrintSettings *settings; - GtkPrintOperation *print; - GtkPageSetup *page_setup; - GtkPaperSize *paper_size; - GtkWidget *gpd; - PrintTableItem *pti; - double w, h, t, r, l, b; - - pti = g_new0 (PrintTableItem, 1); - - print = gtk_print_operation_new (); - paper_size = gtk_paper_size_new ("iso_a4"); - page_setup = gtk_page_setup_new(); - gtk_page_setup_set_paper_size(page_setup, paper_size); - - w = gtk_paper_size_get_width (paper_size, GTK_UNIT_POINTS); - h = gtk_paper_size_get_height (paper_size, GTK_UNIT_POINTS); - t = gtk_paper_size_get_default_top_margin (paper_size, GTK_UNIT_POINTS); - r = gtk_paper_size_get_default_right_margin (paper_size, GTK_UNIT_POINTS); - - b =h * (1.0 - TEMP_MARGIN); - l =r * TEMP_MARGIN; - t =t * (1.0 - TEMP_MARGIN); - r =w * (1.0 - TEMP_MARGIN); - - pti->left_margin = l; - pti->bottom_margin = b; - pti->paper_width = r - l; - pti->paper_height= t + 10; + cairo_move_to (cr, 0.0, 0.0); + pango_cairo_show_layout (cr, layout); - settings = e_print_load_settings (); - gpd = e_print_get_dialog_with_config (dialog_title, 0, settings); - printable = e_table_get_printable (etable); + cairo_restore (cr); - g_object_ref_sink (printable); - e_printable_reset (printable); - pti->printable = printable; + g_object_unref (layout); - gtk_print_operation_set_default_page_setup (print, page_setup); - gtk_print_operation_set_n_pages (print, 1); + pango_font_description_free (desc); +} - /* FIX ME ,Allow it to use the default settings for the first time */ - gtk_print_operation_set_print_settings (print, settings); +static void +print_table_draw_page (GtkPrintOperation *operation, + GtkPrintContext *context, + gint page_nr, + EPrintable *printable) +{ + GtkPageSetup *setup; + gdouble width, height; - /* runs the dialog emitting the signals based on user response */ - g_signal_connect (print, "draw_page", G_CALLBACK (table_draw_page), pti); - if (!preview) - res = gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL, NULL); - else - gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PREVIEW, NULL, NULL); - + setup = gtk_print_context_get_page_setup (context); - /* Saves the user configuration in gconf */ - settings = gtk_print_operation_get_print_settings (print); - e_print_save_settings (settings); + width = gtk_page_setup_get_page_width (setup, GTK_UNIT_POINTS); - if (res == GTK_PRINT_OPERATION_RESULT_APPLY) { - g_object_unref (print); - } - else if ( res == GTK_PRINT_OPERATION_RESULT_ERROR) { - /* FIX ME */ - } -} + do { + /* TODO Allow the user to customize the title. */ + print_title (context, _("Upcoming Appointments"), width); -static void -comp_draw_page (GtkPrintOperation *print, GtkPrintContext *context, gint page_nr, PrintCompItem *pci) -{ - pci = evo_calendar_print_data_new (context, pci); - print_comp_item (pci); -} + if (e_printable_data_left (printable)) + e_printable_print_page ( + printable, context, width, 24, TRUE); -static void -cal_draw_page(GtkPrintOperation *print1, GtkPrintContext *context, gint page_nr1, PrintCalItem *pcali) -{ - pcali = evo_calendar_print_cal_data_new (context, pcali); - - switch (pcali->default_view) { - case PRINT_VIEW_DAY: - print_day_view (pcali->pr, pcali->gcal, pcali->date, pcali->l, pcali->r, pcali->t, pcali->b); - break; - case PRINT_VIEW_WEEK: - print_week_view (pcali->pr, pcali->gcal, pcali->date, pcali->l, pcali->r, pcali->t, pcali->b); - break; - case PRINT_VIEW_MONTH: - print_month_view (pcali->pr, pcali->gcal, pcali->date, pcali->l, pcali->r, pcali->t, pcali->b); - break; - case PRINT_VIEW_YEAR: - print_year_view (pcali->pr, pcali->gcal, pcali->date, pcali->l, pcali->r, pcali->t, pcali->b); - break; - default: - g_assert_not_reached (); - } + } while (e_printable_data_left (printable)); } -static void -table_draw_page (GtkPrintOperation *print, GtkPrintContext *context, gint page_nr, PrintTableItem *pti) +void +print_table (ETable *table, const gchar *dialog_title, + const gchar *print_header, GtkPrintOperationAction action) { - pti->context = context; - - do { - print_title (context,"Table", pti->paper_width, pti->paper_height, pti->left_margin, pti->bottom_margin); - - if (e_printable_data_left (pti->printable)) - e_printable_print_page (pti->printable, pti->context, - pti->paper_width, pti->paper_height + 24, TRUE); + GtkPrintOperation *operation; + EPrintable *printable; - } while (e_printable_data_left (pti->printable)); -} + printable = e_table_get_printable (table); + g_object_ref_sink (printable); + e_printable_reset (printable); -/* - * This callback creates a custom widget that gets inserted into the - * print operation dialog, the custom widget contains the range, - * day, view, month, or year - */ + operation = e_print_operation_new (); + gtk_print_operation_set_n_pages (operation, 1); -GObject* create_custom_widget (GtkPrintOperation *print,GtkWidget *range) -{ - return range; -} + g_signal_connect ( + operation, "draw_page", + G_CALLBACK (print_table_draw_page), printable); -/* - * Read the information from the custom widget and print day, view, or - * month based on user selection - */ + gtk_print_operation_run (operation, action, NULL, NULL); -static void -apply_custom_widget (GtkPrintOperation *print, GtkWidget *dialog, PrintCalItem *cpi) -{ - gchar str; - str = e_dialog_editable_get (dialog); - printf("%sValue of Radio Button \n", str); + g_object_unref (operation); } - diff --git a/calendar/gui/print.h b/calendar/gui/print.h index d706125e6c..b6d2abdd26 100644 --- a/calendar/gui/print.h +++ b/calendar/gui/print.h @@ -34,10 +34,15 @@ typedef enum { PRINT_VIEW_LIST } PrintView; -void print_calendar (GnomeCalendar *gcal, gboolean preview, time_t at, PrintView default_view); -void print_comp (ECalComponent *comp, ECal *client, gboolean preview); -void print_table (ETable *etable, const char *dialog_title, const char *print_header, gboolean preview); - - +void print_calendar (GnomeCalendar *gcal, + GtkPrintOperationAction action, + time_t start); +void print_comp (ECalComponent *comp, + ECal *client, + GtkPrintOperationAction action); +void print_table (ETable *table, + const gchar *dialog_title, + const gchar *print_header, + GtkPrintOperationAction action); #endif diff --git a/calendar/gui/tasks-control.c b/calendar/gui/tasks-control.c index 2393c8fd8b..0a8df90370 100644 --- a/calendar/gui/tasks-control.c +++ b/calendar/gui/tasks-control.c @@ -34,13 +34,6 @@ #include <libgnomeui/gnome-dialog.h> #include <libgnomeui/gnome-dialog-util.h> #include <libgnomeui/gnome-stock-icons.h> -#include <libgnomeprint/gnome-print.h> -#include <libgnomeprint/gnome-print-paper.h> -#include <libgnomeprint/gnome-print-job.h> -#include <libgnomeprintui/gnome-print-job-preview.h> -#include <libgnomeprintui/gnome-print-paper-selector.h> -#include <libgnomeprintui/gnome-print-preview.h> -#include <libgnomeprintui/gnome-print-dialog.h> #include <bonobo/bonobo-control.h> #include <bonobo/bonobo-ui-util.h> #include <e-util/e-dialog-utils.h> @@ -469,30 +462,21 @@ tasks_control_purge_cmd (BonoboUIComponent *uic, e_tasks_delete_completed (tasks); } - -static void -print_tasks (ETasks *tasks, gboolean preview) -{ - ECalendarTable *cal_table; - ETable *etable; - - cal_table = e_tasks_get_calendar_table (tasks); - etable = e_calendar_table_get_table (E_CALENDAR_TABLE (cal_table)); - - print_table (etable, _("Print Tasks"), _("Tasks"), preview); -} - /* File/Print callback */ static void tasks_control_print_cmd (BonoboUIComponent *uic, gpointer data, const char *path) { - ETasks *tasks; + ETasks *tasks = E_TASKS (data); + ETable *table; - tasks = E_TASKS (data); + table = e_calendar_table_get_table ( + E_CALENDAR_TABLE (e_tasks_get_calendar_table (tasks))); - print_tasks (tasks, FALSE); + print_table ( + table, _("Print Tasks"), _("Tasks"), + GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG); } static void @@ -500,11 +484,15 @@ tasks_control_print_preview_cmd (BonoboUIComponent *uic, gpointer data, const char *path) { - ETasks *tasks; + ETasks *tasks = E_TASKS (data); + ETable *table; - tasks = E_TASKS (data); + table = e_calendar_table_get_table ( + E_CALENDAR_TABLE (e_tasks_get_calendar_table (tasks))); - print_tasks (tasks, TRUE); + print_table ( + table, _("Print Tasks"), _("Tasks"), + GTK_PRINT_OPERATION_ACTION_PREVIEW); } static void diff --git a/configure.in b/configure.in index 0f5831f65d..a26a0c03f4 100644 --- a/configure.in +++ b/configure.in @@ -1204,7 +1204,7 @@ AC_CHECK_HEADERS(libgnomeui/gnome-icon-lookup.h) AC_CHECK_HEADERS(libgnomeui/gnome-thumbnail.h) CPPFLAGS="$CPPFLAGS_save" -PKG_CHECK_MODULES(EXTRA_GNOME, libgnomeprint-2.2 >= 2.7.0 libgnomeprintui-2.2 >= 2.2.1 $FULL_GNOME_DEPS) +PKG_CHECK_MODULES(EXTRA_GNOME, $FULL_GNOME_DEPS) AC_SUBST(EXTRA_GNOME_LIBS) AC_SUBST(EXTRA_GNOME_CFLAGS) @@ -1247,7 +1247,7 @@ EVO_SET_COMPILE_FLAGS(E_NAME, libgnomeui-2.0 libbonoboui-2.0 >= $BONOBOUI_REQUIR AC_SUBST(E_NAME_CFLAGS) AC_SUBST(E_NAME_LIBS) -EVO_SET_COMPILE_FLAGS(E_UTIL, gthread-2.0 gconf-2.0 libxml-2.0 gtk+-unix-print-2.0 libbonoboui-2.0 >= $BONOBOUI_REQUIRED libglade-2.0 libgnomeui-2.0 libgnome-2.0 libgnomecanvas-2.0 libgnomeprintui-2.2 libedataserver-$EDS_PACKAGE >= $EDS_REQUIRED libedataserverui-$EDS_PACKAGE >= $EDS_REQUIRED $mozilla_nspr $mono_package, $THREADS_CFLAGS $MANUAL_NSPR_CFLAGS, $THREADS_LIBS $MANUAL_NSPR_LIBS) +EVO_SET_COMPILE_FLAGS(E_UTIL, gthread-2.0 gconf-2.0 libxml-2.0 libbonoboui-2.0 >= $BONOBOUI_REQUIRED libglade-2.0 libgnomeui-2.0 libgnome-2.0 libgnomecanvas-2.0 libedataserver-$EDS_PACKAGE >= $EDS_REQUIRED libedataserverui-$EDS_PACKAGE >= $EDS_REQUIRED $mozilla_nspr $mono_package, $THREADS_CFLAGS $MANUAL_NSPR_CFLAGS, $THREADS_LIBS $MANUAL_NSPR_LIBS) AC_SUBST(E_UTIL_CFLAGS) AC_SUBST(E_UTIL_LIBS) @@ -1297,7 +1297,7 @@ AC_SUBST(SHELL_LIBS) dnl --- evolution-addressbook flags -EVOLUTION_ADDRESSBOOK_DEPS="gconf-2.0 libbonoboui-2.0 >= $BONOBOUI_REQUIRED libglade-2.0 libgnomeui-2.0 libgnome-2.0 libgnomecanvas-2.0 gtk+-unix-print-2.0 gnome-vfs-2.0 libgnomeprintui-2.2 libgtkhtml-$GTKHTML_PACKAGE >= $GTKHTML_REQUIRED libebook-$EDS_PACKAGE >= $EDS_REQUIRED libedataserverui-$EDS_PACKAGE >= $EDS_REQUIRED camel-$EDS_PACKAGE" +EVOLUTION_ADDRESSBOOK_DEPS="gconf-2.0 libbonoboui-2.0 >= $BONOBOUI_REQUIRED libglade-2.0 libgnomeui-2.0 libgnome-2.0 libgnomecanvas-2.0 gnome-vfs-2.0 libgtkhtml-$GTKHTML_PACKAGE >= $GTKHTML_REQUIRED libebook-$EDS_PACKAGE >= $EDS_REQUIRED libedataserverui-$EDS_PACKAGE >= $EDS_REQUIRED camel-$EDS_PACKAGE" EVO_SET_COMPILE_FLAGS(EVOLUTION_ADDRESSBOOK, $EVOLUTION_ADDRESSBOOK_DEPS) AC_SUBST(EVOLUTION_ADDRESSBOOK_CFLAGS) @@ -1335,7 +1335,7 @@ EVO_SET_COMPILE_FLAGS(LIBSOUP, $LIBSOUP >= $LIBSOUP_REQUIRED) AC_SUBST(LIBSOUP_CFLAGS) AC_SUBST(LIBSOUP_LIBS) -EVO_SET_COMPILE_FLAGS(EVOLUTION_CALENDAR, libgnome-2.0 libgnomeui-2.0 libbonoboui-2.0 libglade-2.0 gnome-vfs-2.0 gtk+-unix-print-2.0 libgnomeprint-2.2 libgnomeprintui-2.2 gnome-vfs-module-2.0 libgtkhtml-$GTKHTML_PACKAGE >= $GTKHTML_REQUIRED libebook-$EDS_PACKAGE >= $EDS_REQUIRED libecal-$EDS_PACKAGE >= $EDS_REQUIRED libedataserverui-$EDS_PACKAGE >= $EDS_REQUIRED $HAL_REQUIREMENT $libnotify) +EVO_SET_COMPILE_FLAGS(EVOLUTION_CALENDAR, libgnome-2.0 libgnomeui-2.0 libbonoboui-2.0 libglade-2.0 gnome-vfs-2.0 gnome-vfs-module-2.0 libgtkhtml-$GTKHTML_PACKAGE >= $GTKHTML_REQUIRED libebook-$EDS_PACKAGE >= $EDS_REQUIRED libecal-$EDS_PACKAGE >= $EDS_REQUIRED libedataserverui-$EDS_PACKAGE >= $EDS_REQUIRED $HAL_REQUIREMENT $libnotify) AC_SUBST(EVOLUTION_CALENDAR_CFLAGS) AC_SUBST(EVOLUTION_CALENDAR_LIBS) @@ -1347,7 +1347,7 @@ fi dnl --- evolution-mail flags -EVO_SET_COMPILE_FLAGS(EVOLUTION_MAIL, camel-provider-$EDS_PACKAGE libgnome-2.0 libgnomeui-2.0 libbonoboui-2.0 >= $BONOBOUI_REQUIRED libglade-2.0 gnome-vfs-module-2.0 libgnomeprint-2.2 libgnomeprintui-2.2 libgtkhtml-$GTKHTML_PACKAGE >= $GTKHTML_REQUIRED libxml-2.0 bonobo-activation-2.0 gthread-2.0 gconf-2.0 gtk+-unix-print-2.0 $mozilla_nss libebook-$EDS_PACKAGE >= $EDS_REQUIRED libedataserverui-$EDS_PACKAGE >= $EDS_REQUIRED) +EVO_SET_COMPILE_FLAGS(EVOLUTION_MAIL, camel-provider-$EDS_PACKAGE libgnome-2.0 libgnomeui-2.0 libbonoboui-2.0 >= $BONOBOUI_REQUIRED libglade-2.0 gnome-vfs-module-2.0 libgtkhtml-$GTKHTML_PACKAGE >= $GTKHTML_REQUIRED libxml-2.0 bonobo-activation-2.0 gthread-2.0 gconf-2.0 $mozilla_nss libebook-$EDS_PACKAGE >= $EDS_REQUIRED libedataserverui-$EDS_PACKAGE >= $EDS_REQUIRED) AC_SUBST(EVOLUTION_MAIL_CFLAGS) AC_SUBST(EVOLUTION_MAIL_LIBS) @@ -1589,7 +1589,7 @@ if echo ${plugins_enabled} | grep "exchange-operations" > /dev/null ; then dnl ************************************************** dnl * Exchange Operations plugin dnl ************************************************** - EVO_SET_COMPILE_FLAGS(CAMEL_EXCHANGE, libbonoboui-2.0 >= $BONOBOUI_REQUIRED libglade-2.0 libgnomeprint-2.2 libgnomeprintui-2.2 gthread-2.0 gconf-2.0 camel-provider-$EDS_PACKAGE libebook-$EDS_PACKAGE >= $EDS_REQUIRED libedataserverui-$EDS_PACKAGE libexchange-storage-$EDS_PACKAGE >= $EDS_REQUIRED libecal-$EDS_PACKAGE) + EVO_SET_COMPILE_FLAGS(CAMEL_EXCHANGE, libbonoboui-2.0 >= $BONOBOUI_REQUIRED libglade-2.0 gthread-2.0 gconf-2.0 camel-provider-$EDS_PACKAGE libebook-$EDS_PACKAGE >= $EDS_REQUIRED libedataserverui-$EDS_PACKAGE libexchange-storage-$EDS_PACKAGE >= $EDS_REQUIRED libecal-$EDS_PACKAGE) AC_SUBST(CAMEL_EXCHANGE_CFLAGS) AC_SUBST(CAMEL_EXCHANGE_LIBS) else diff --git a/e-util/ChangeLog b/e-util/ChangeLog index e56b6d878c..49055d64e3 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,3 +1,9 @@ +2007-04-20 Matthew Barnes <mbarnes@redhat.com> + + * e-print.c: + * e-print.h: + Refactor the printing infrastructure. (#426816) + 2007-04-19 Matthew Barnes <mbarnes@redhat.com> ** Fixes part of bug #429422 diff --git a/e-util/e-print.c b/e-util/e-print.c index 107f0d2597..0a3cf7ee43 100644 --- a/e-util/e-print.c +++ b/e-util/e-print.c @@ -24,8 +24,9 @@ #include <stdio.h> #include <string.h> #include <gtk/gtk.h> -#include <gtk/gtkprintunixdialog.h> +#include <glib/gi18n.h> #include <gconf/gconf-client.h> + #define PRINTING "/apps/evolution/shell/printing" static void @@ -35,21 +36,23 @@ pack_settings (const gchar *key, const gchar *value, GSList **p_list) item = g_strdup_printf ("%s=%s", key, value); *p_list = g_slist_prepend (*p_list, item); } + static void unpack_settings (gchar *item, GtkPrintSettings *settings) { gchar *cp, *key, *value; cp = strchr (item, '='); if (cp == NULL) - return; + return; *cp ++ = '\0'; key = g_strstrip (item); value = g_strstrip (cp); gtk_print_settings_set (settings, key, value); g_free (item); } -GtkPrintSettings * -e_print_load_settings (void) + +static GtkPrintSettings * +load_settings (void) { GConfClient *client; GtkPrintSettings *settings; @@ -68,19 +71,22 @@ e_print_load_settings (void) g_warning ("%s: %s", G_STRFUNC, error->message); g_error_free (error); } + g_object_unref (client); + return settings; } -/* Saves the print settings */ - -void -e_print_save_settings (GtkPrintSettings *settings) +static void +save_settings (GtkPrintOperation *operation) { + GtkPrintSettings *settings; GConfClient *client; GSList *list = NULL; GError *error = NULL; + settings = gtk_print_operation_get_print_settings (operation); + client = gconf_client_get_default (); gtk_print_settings_foreach ( @@ -98,38 +104,60 @@ e_print_save_settings (GtkPrintSettings *settings) } static void -print_dialog_response(GtkWidget *widget, int resp, gpointer data) +handle_error (GtkPrintOperation *operation) { -#ifdef G_OS_UNIX /* Just to get it to build on Win32 */ - if (resp == GTK_RESPONSE_OK) { - e_print_save_settings (gtk_print_unix_dialog_get_settings(GTK_PRINT_UNIX_DIALOG (widget))); - } -#endif + GtkWidget *dialog; + GError *error = NULL; + + dialog = gtk_message_dialog_new_with_markup ( + NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, + "<span weight=\"bold\" size=\"larger\">%s</span>", + _("An error occurred while printing")); + + gtk_print_operation_get_error (operation, &error); + + if (error != NULL && error->message != NULL) + gtk_message_dialog_format_secondary_text ( + GTK_MESSAGE_DIALOG (dialog), "%s\n\n%s", + _("The printing system reported the " + "following details about the error:"), + error->message); + else + gtk_message_dialog_format_secondary_text ( + GTK_MESSAGE_DIALOG (dialog), "%s", + _("The printing system did not report " + "any additional details about the error.")); + + if (error != NULL) + g_error_free (error); + + gtk_dialog_run (GTK_DIALOG (dialog)); + + gtk_widget_destroy (dialog); } -/* Creates a dialog with the print settings */ -GtkWidget * -e_print_get_dialog (const char *title, int flags) +static void +print_done_cb (GtkPrintOperation *operation, GtkPrintOperationResult result) { - GtkPrintSettings *settings; - GtkWidget *dialog; - - settings = gtk_print_settings_new (); - settings = e_print_load_settings (); - dialog = e_print_get_dialog_with_config (title, flags, settings); - g_object_unref (settings); - return dialog; + if (result == GTK_PRINT_OPERATION_RESULT_APPLY) + save_settings (operation); + if (result == GTK_PRINT_OPERATION_RESULT_ERROR) + handle_error (operation); } -GtkWidget * -e_print_get_dialog_with_config (const char *title, int flags, GtkPrintSettings *settings) +GtkPrintOperation * +e_print_operation_new (void) { - GtkWidget *dialog = NULL; - -#ifdef G_OS_UNIX /* Just to get it to build on Win32 */ - dialog = gtk_print_unix_dialog_new (title, NULL); - gtk_print_unix_dialog_set_settings (GTK_PRINT_UNIX_DIALOG(dialog), settings); - g_signal_connect(dialog, "response", G_CALLBACK(print_dialog_response), NULL); -#endif - return dialog; + GtkPrintOperation *operation; + GtkPrintSettings *settings; + + operation = gtk_print_operation_new (); + + settings = load_settings (); + gtk_print_operation_set_print_settings (operation, settings); + g_object_unref (settings); + + g_signal_connect (operation, "done", G_CALLBACK (print_done_cb), NULL); + + return operation; } diff --git a/e-util/e-print.h b/e-util/e-print.h index 8ae99a2900..8044506c0c 100644 --- a/e-util/e-print.h +++ b/e-util/e-print.h @@ -26,11 +26,7 @@ G_BEGIN_DECLS -GtkPrintSettings *e_print_load_settings (void); -void e_print_save_settings (GtkPrintSettings *settings); - -GtkWidget *e_print_get_dialog (const char *title, int flags); -GtkWidget *e_print_get_dialog_with_config (const char *title, int flags, GtkPrintSettings *settings); +GtkPrintOperation * e_print_operation_new (void); G_END_DECLS diff --git a/mail/ChangeLog b/mail/ChangeLog index 4d5e57fc59..833daa6384 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,3 +1,13 @@ +2007-04-20 Matthew Barnes <mbarnes@redhat.com> + + ** Fixes part of bug #426812 + + * em-format-html-print.c: + * em-format-html-print.h: + * em-folder-view.c: + * em-folder-view.h: + Refactor the printing infrastructure. + 2007-04-20 Srinivasa Ragavan <sragavan@novell.com> * em-composer-prefs.c: (signature_key_press): Fix for bug #353662 diff --git a/mail/em-folder-view.c b/mail/em-folder-view.c index 78b5d00790..62568c8282 100644 --- a/mail/em-folder-view.c +++ b/mail/em-folder-view.c @@ -110,7 +110,6 @@ #include "mail-vfolder.h" #include "mail-component.h" #include "mail-tools.h" -#include <gtk/gtkprintunixdialog.h> #include "evolution-shell-component-utils.h" /* Pixmap stuff, sigh */ @@ -781,7 +780,7 @@ static void emfv_popup_print(EPopup *ep, EPopupItem *pitem, void *data) { EMFolderView *emfv = data; - em_folder_view_print(emfv, FALSE); + em_folder_view_print(emfv, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG); } static void @@ -1549,7 +1548,7 @@ emfv_print_preview_message(BonoboUIComponent *uic, void *data, const char *path) { EMFolderView *emfv = data; - em_folder_view_print(emfv, TRUE); + em_folder_view_print(emfv, GTK_PRINT_OPERATION_ACTION_PREVIEW); } static void @@ -2114,86 +2113,30 @@ emfv_activate(EMFolderView *emfv, BonoboUIComponent *uic, int act) } } -struct _print_data { - EMFolderView *emfv; - - GtkPrintSettings *settings; - int preview; - CamelFolder *folder; - char *uid; -}; - -static void -emfv_print_response(GtkWidget *w, int resp, struct _print_data *data) -{ - EMFormatHTMLPrint *print; - gboolean preview = FALSE; - - switch (resp) { - case GTK_RESPONSE_APPLY: - preview = TRUE; - case GTK_RESPONSE_OK: - print = em_format_html_print_new (); - print->preview = preview; - em_format_set_session ((EMFormat *)print, ((EMFormat *)data->emfv->preview)->session); - em_format_html_print_message (print, - (EMFormatHTML *)data->emfv->preview, - data->settings, - data->folder, - data->uid, - data->preview); - g_object_unref(print); - break; - } - - if (w) - gtk_widget_destroy (w); - - g_object_unref (data->emfv); - g_object_unref (data->settings); - camel_object_unref (data->folder); - g_free (data->uid); - g_free (data); -} - - - -int em_folder_view_print(EMFolderView *emfv, int preview) +int +em_folder_view_print (EMFolderView *emfv, GtkPrintOperationAction action) { - struct _print_data *data; + EMFormatHTMLPrint *efhp; GPtrArray *uids; if (emfv->folder == NULL) return 0; - uids = message_list_get_selected(emfv->list); - if (uids->len != 1) { - message_list_free_uids(emfv->list, uids); - return 0; - } - - data = g_malloc0(sizeof(*data)); - data->emfv = emfv; - g_object_ref(emfv); - data->settings = e_print_load_settings (); - data->preview = preview; - data->folder = emfv->folder; - camel_object_ref(data->folder); - data->uid = g_strdup(uids->pdata[0]); - message_list_free_uids(emfv->list, uids); - - if (preview) { - GtkDialog *dialog = (GtkDialog *)e_print_get_dialog_with_config (_("Print Message"), - 0, data->settings); - e_dialog_set_transient_for ((GtkWindow *) dialog, (GtkWidget *) emfv); - emfv_print_response(dialog, GTK_RESPONSE_APPLY, data); - } else { - GtkDialog *dialog = (GtkDialog *)e_print_get_dialog_with_config (_("Print Message"), - 0, data->settings); - gtk_dialog_set_default_response (dialog, GTK_RESPONSE_OK); - e_dialog_set_transient_for ((GtkWindow *) dialog, (GtkWidget *) emfv); - emfv_print_response (dialog, GTK_RESPONSE_OK, data); - } + uids = message_list_get_selected (emfv->list); + if (uids->len != 1) + goto exit; + + efhp = em_format_html_print_new ( + (EMFormatHTML *) emfv->preview, action); + em_format_set_session ( + (EMFormat *) efhp, + ((EMFormat *) emfv->preview)->session); + em_format_html_print_message ( + efhp, emfv->folder, uids->pdata[0]); + g_object_unref (efhp); + +exit: + message_list_free_uids (emfv->list, uids); return 0; } diff --git a/mail/em-folder-view.h b/mail/em-folder-view.h index 4c998dcc86..d2afb4d666 100644 --- a/mail/em-folder-view.h +++ b/mail/em-folder-view.h @@ -25,6 +25,7 @@ #define _EM_FOLDER_VIEW_H #include <gtk/gtkvbox.h> +#include <gtk/gtkprintoperation.h> #include "mail/em-popup.h" #ifdef __cplusplus @@ -132,7 +133,7 @@ EMPopupTargetSelect *em_folder_view_get_popup_target(EMFolderView *emfv, EMPopup int em_folder_view_mark_selected(EMFolderView *emfv, guint32 mask, guint32 set); int em_folder_view_open_selected(EMFolderView *emfv); -int em_folder_view_print(EMFolderView *emfv, int preview); +int em_folder_view_print(EMFolderView *emfv, GtkPrintOperationAction action); /* this could be on message-list */ guint32 em_folder_view_disable_mask(EMFolderView *emfv); diff --git a/mail/em-format-html-print.c b/mail/em-format-html-print.c index bc94f8aae5..ebda5aaf2a 100644 --- a/mail/em-format-html-print.c +++ b/mail/em-format-html-print.c @@ -26,274 +26,212 @@ #endif #include <string.h> -#include <libgnomeprint/gnome-print-job.h> -#include <libgnomeprintui/gnome-print-job-preview.h> +#include <gtk/gtk.h> #include <gtkhtml/gtkhtml.h> -#include <gtk/gtkwindow.h> #include <camel/camel-i18n.h> #include "mail-ops.h" #include "mail-mt.h" #include "em-format-html-print.h" -#include <gtk/gtk.h> #include <e-util/e-print.h> -static void efhp_builtin_init(EMFormatHTMLPrintClass *efhc); - -static EMFormatHTMLClass *efhp_parent; +static gpointer parent_class = NULL; static void -efhp_init(GObject *o) +efhp_finalize (GObject *o) { EMFormatHTMLPrint *efhp = (EMFormatHTMLPrint *)o; - GtkWidget *html = (GtkWidget *)efhp->formathtml.html; - /* ?? */ - gtk_widget_set_name(html, "EvolutionMailPrintHTMLWidget"); + gtk_widget_destroy (efhp->window); + if (efhp->source != NULL) + g_object_unref (efhp->source); - /* gtk widgets don't like to be realized outside top level widget - so we put new html widget into gtk window */ - efhp->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_container_add((GtkContainer *)efhp->window, html); - gtk_widget_realize(html); - efhp->formathtml.show_icon = FALSE; + ((GObjectClass *) parent_class)->finalize (o); } static void -efhp_finalise(GObject *o) +efhp_class_init (GObjectClass *class) { - EMFormatHTMLPrint *efhp = (EMFormatHTMLPrint *)o; - - gtk_widget_destroy(efhp->window); - if (efhp->settings) - g_object_unref(efhp->settings); - if (efhp->source) - g_object_unref(efhp->source); - - ((GObjectClass *)efhp_parent)->finalize(o); + parent_class = g_type_class_ref(EM_TYPE_FORMAT_HTML_PRINT); + class->finalize = efhp_finalize; } static void -efhp_base_init(EMFormatHTMLPrintClass *efhpklass) +efhp_init (GObject *o) { - efhp_builtin_init(efhpklass); -} + EMFormatHTMLPrint *efhp = (EMFormatHTMLPrint *)o; + GtkWidget *html = (GtkWidget *)efhp->parent.html; -static void -efhp_class_init(GObjectClass *klass) -{ - klass->finalize = efhp_finalise; + /* ?? */ + gtk_widget_set_name(html, "EvolutionMailPrintHTMLWidget"); + + /* gtk widgets don't like to be realized outside top level widget + so we put new html widget into gtk window */ + efhp->window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_container_add (GTK_CONTAINER (efhp->window), html); + gtk_widget_realize (html); + efhp->parent.show_icon = FALSE; } GType -em_format_html_print_get_type(void) +em_format_html_print_get_type (void) { static GType type = 0; - if (type == 0) { - static const GTypeInfo info = { - sizeof(EMFormatHTMLPrintClass), - (GBaseInitFunc)efhp_base_init, NULL, - (GClassInitFunc)efhp_class_init, - NULL, NULL, - sizeof(EMFormatHTMLPrint), 0, - (GInstanceInitFunc)efhp_init + if (G_UNLIKELY (type == 0)) { + static const GTypeInfo type_info = { + sizeof (EMFormatHTMLPrintClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) efhp_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (EMFormatHTMLPrint), + 0, /* n_preallocs */ + (GInstanceInitFunc) efhp_init }; - efhp_parent = g_type_class_ref(em_format_html_get_type()); - type = g_type_register_static(em_format_html_get_type(), "EMFormatHTMLPrint", &info, 0); + + type = g_type_register_static ( + em_format_html_get_type (), "EMFormatHTMLPrint", + &type_info, 0); } return type; } -EMFormatHTMLPrint *em_format_html_print_new(void) +EMFormatHTMLPrint * +em_format_html_print_new (EMFormatHTML *source, GtkPrintOperationAction action) { EMFormatHTMLPrint *efhp; - efhp = g_object_new(em_format_html_print_get_type(), 0); + efhp = g_object_new (EM_TYPE_FORMAT_HTML_PRINT, NULL); + if (source != NULL) + efhp->source = g_object_ref (source); + efhp->action = action; return efhp; } struct footer_info { - GnomeFont *local_font; + PangoLayout *layout; gint page_num, pages; }; -typedef struct MailDraw MailDraw; - -struct MailDraw { - EMFormatHTMLPrint *efhp; - struct footer_info info; - void *data; - gint res; - gdouble line; -}; -static void mail_draw_page(GtkPrintOperation *print, GtkPrintContext *context, gint page_nr, MailDraw *mdi); static void -efhp_footer_cb(GtkHTML *html, GtkPrintContext *print_context, double x, double y, double width, double height, void *data) +efhp_footer_cb (GtkHTML *html, GtkPrintContext *context, gdouble x, gdouble y, + gdouble width, gdouble height, gpointer data) { struct footer_info *info = data; + gchar *footer_text; cairo_t *cr; - - /* do we want anything nicer here, like who its from, etc? */ - if (info->local_font) { - char *text = g_strdup_printf (_("Page %d of %d"), info->page_num, info->pages); - /*gdouble tw = gnome_font_get_width_string (info->local_font, text);*/ - /* FIXME: work out how to measure this */ - gdouble tw = strlen(text) * 8; - cr = gtk_print_context_get_cairo_context (print_context); - cairo_save (cr); - cairo_set_source_rgb (cr, .0, .0, .0); - cairo_move_to (cr, x + width - tw, y - gnome_font_get_ascender(info->local_font)); - cairo_set_font_face (cr, NULL); - cairo_set_font_size (cr, 6); - cairo_show_text (cr, text); - cairo_restore(cr); - g_free(text); - info->page_num++; - } -} -/* perform preview, or print */ -/* returns GNOME_PRINT_OK on success */ -static void -emfhp_complete(EMFormatHTMLPrint *efhp, void *data) -{ - GtkPaperSize *paper_size; - GtkPrintOperation *print; - GtkPrintSettings *settings; - GtkPageSetup *page_setup; - struct MailDraw *mdi; - struct footer_info info; + footer_text = g_strdup_printf (_("Page %d of %d"), + info->page_num++, info->pages); + + pango_layout_set_text (info->layout, footer_text, -1); + pango_layout_set_width (info->layout, pango_units_from_double (width)); - page_setup = gtk_page_setup_new (); - paper_size = gtk_paper_size_new ("iso_a4");/*FIXME paper size hardcoded */ - print = gtk_print_operation_new (); - gtk_page_setup_set_paper_size (page_setup, paper_size); - - settings = e_print_load_settings (); - gtk_print_operation_set_print_settings (print, settings); - /* running the dialog */ - gtk_print_operation_set_default_page_setup (print, page_setup); - gtk_print_operation_set_n_pages (print, 1); - - /*initialise the struct */ - mdi = g_new0 (MailDraw, 1); - mdi->efhp = efhp; - mdi->line = 0.0; - mdi->res = GNOME_PRINT_OK; - mdi->info = info; - - /* connect */ - g_signal_connect (print,"draw_page", G_CALLBACK (mail_draw_page), mdi); - if (!efhp->preview) - gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL, NULL); - else - gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PREVIEW, NULL, NULL); - settings = gtk_print_operation_get_print_settings (print); - e_print_save_settings (settings); - g_object_unref (print); + cr = gtk_print_context_get_cairo_context (context); + + cairo_save (cr); + cairo_set_source_rgb (cr, .0, .0, .0); + cairo_move_to (cr, x, y); + pango_cairo_show_layout (cr, info->layout); + cairo_restore (cr); + + g_free (footer_text); } static void -mail_draw_page (GtkPrintOperation *print, GtkPrintContext *context, gint page_nr, MailDraw *mdi) +mail_draw_page (GtkPrintOperation *print, GtkPrintContext *context, + gint page_nr, EMFormatHTMLPrint *efhp) { - mdi->info.local_font = gnome_font_find_closest("Sans Regular", 10.0); - if (mdi->info.local_font) { - mdi->line = gnome_font_get_ascender(mdi->info.local_font) - gnome_font_get_descender(mdi->info.local_font); - mdi->info.page_num = 1; - mdi->info.pages = gtk_html_print_page_get_pages_num(mdi->efhp->formathtml.html, context, 0.0, mdi->line ); - gtk_html_print_page_with_header_footer(mdi->efhp->formathtml.html, - context, - 0.0, - mdi->line, - NULL, - efhp_footer_cb, - &(mdi->info)); - } else { - gtk_html_print_page (mdi->efhp->formathtml.html, context); - } -} + GtkHTML *html = efhp->parent.html; + PangoFontDescription *desc; + PangoFontMetrics *metrics; + struct footer_info info; + gdouble footer_height; -int em_format_html_print_print(EMFormatHTMLPrint *efhp, EMFormatHTML *source, struct GtkPrintSettings *settings, int preview) -{ - EMFormat *emfs = (EMFormat *)source; + desc = pango_font_description_from_string ("Sans Regular 10"); - efhp->settings = settings; - if (settings) - g_object_ref(settings); + info.layout = gtk_print_context_create_pango_layout (context); + pango_layout_set_alignment (info.layout, PANGO_ALIGN_CENTER); + pango_layout_set_font_description (info.layout, desc); - efhp->preview = preview; - ((EMFormatHTML *)efhp)->load_http = source->load_http_now; + metrics = pango_context_get_metrics ( + pango_layout_get_context (info.layout), + desc, pango_language_get_default ()); + footer_height = pango_units_to_double ( + pango_font_metrics_get_ascent (metrics) + + pango_font_metrics_get_descent (metrics)); + pango_font_metrics_unref (metrics); - g_signal_connect(efhp, "complete", G_CALLBACK(emfhp_complete), efhp); + pango_font_description_free (desc); - g_object_ref(efhp); - em_format_format_clone((EMFormat *)efhp, emfs->folder, emfs->uid, emfs->message, (EMFormat *)source); + info.page_num = 1; + info.pages = gtk_html_print_page_get_pages_num ( + html, context, 0.0, footer_height); - return 0; /* damn async ... */ + gtk_html_print_page_with_header_footer ( + html, context, 0.0, footer_height, + NULL, efhp_footer_cb, &info); } static void -emfhp_got_message(struct _CamelFolder *folder, const char *uid, struct _CamelMimeMessage *msg, void *data) +emfhp_complete (EMFormatHTMLPrint *efhp) { - EMFormatHTMLPrint *efhp = data; - - if (msg) { - if (efhp->source) - ((EMFormatHTML *)efhp)->load_http = efhp->source->load_http_now; - g_signal_connect(efhp, "complete", G_CALLBACK(emfhp_complete), efhp); - em_format_format_clone((EMFormat *)efhp, folder, uid, msg, (EMFormat *)efhp->source); - } else { - g_object_unref(efhp); - } -} + GtkPrintOperation *operation; -int em_format_html_print_message(EMFormatHTMLPrint *efhp, EMFormatHTML *source, struct GtkPrintSettings *settings, struct _CamelFolder *folder, const char *uid, int preview) -{ - efhp->settings = settings; + operation = e_print_operation_new (); + gtk_print_operation_set_n_pages (operation, 1); - if (settings) - g_object_ref(settings); - efhp->preview = preview; - efhp->source = source; - if (source) - g_object_ref(source); - g_object_ref(efhp); + g_signal_connect ( + operation, "draw-page", + G_CALLBACK (mail_draw_page), efhp); - mail_get_message(folder, uid, emfhp_got_message, efhp, mail_thread_new); + gtk_print_operation_run (operation, efhp->action, NULL, NULL); - return 0; /* damn async ... */ + g_object_unref (operation); } -int em_format_html_print_raw_message(EMFormatHTMLPrint *efhp, GtkPrintSettings *settings, struct _CamelMimeMessage *msg, int preview) +static void +emfhp_got_message (CamelFolder *folder, const char *uid, + CamelMimeMessage *msg, gpointer data) { - efhp->settings = settings; + EMFormatHTMLPrint *efhp = data; - if (settings) - g_object_ref(settings); - efhp->source = NULL; - efhp->preview = preview; - g_object_ref(efhp); + if (msg == NULL) { + g_object_unref (efhp); + return; + } - emfhp_got_message(NULL, NULL, msg, efhp); + if (efhp->source != NULL) + ((EMFormatHTML *)efhp)->load_http = + efhp->source->load_http_now; - return 0; + g_signal_connect ( + efhp, "complete", G_CALLBACK (emfhp_complete), efhp); + em_format_format_clone ( + (EMFormat *) efhp, folder, uid, msg, + (EMFormat *) efhp->source); } -/* ********************************************************************** */ +void +em_format_html_print_message (EMFormatHTMLPrint *efhp, + CamelFolder *folder, + const char *uid) +{ + g_object_ref (efhp); -/* if only ... but i doubt this is possible with gnome print/gtkhtml */ -static EMFormatHandler type_builtin_table[] = { - /*{ "application/postscript", (EMFormatFunc)efhp_application_postscript },*/ -}; + mail_get_message ( + folder, uid, emfhp_got_message, efhp, mail_thread_new); +} -static void -efhp_builtin_init(EMFormatHTMLPrintClass *efhc) +void +em_format_html_print_raw_message (EMFormatHTMLPrint *efhp, + CamelMimeMessage *msg) { - int i; + g_object_ref (efhp); - for (i=0;i<sizeof(type_builtin_table)/sizeof(type_builtin_table[0]);i++) - em_format_class_add_handler((EMFormatClass *)efhc, &type_builtin_table[i]); + emfhp_got_message (NULL, NULL, msg, efhp); } diff --git a/mail/em-format-html-print.h b/mail/em-format-html-print.h index 3cc605ba43..a013d57452 100644 --- a/mail/em-format-html-print.h +++ b/mail/em-format-html-print.h @@ -8,32 +8,32 @@ #include "mail/em-format-html.h" -struct GtkPrintSettings; +#define EM_TYPE_FORMAT_HTML_PRINT \ + (em_format_html_print_get_type ()) + typedef struct _EMFormatHTMLPrint EMFormatHTMLPrint; typedef struct _EMFormatHTMLPrintClass EMFormatHTMLPrintClass; -struct _CamelFolder; - struct _EMFormatHTMLPrint { - EMFormatHTML formathtml; + EMFormatHTML parent; - struct _GtkWidget *window; /* used to realise the gtkhtml in a toplevel, i dont know why */ - struct _GtkPrintSettings *settings; - struct _EMFormatHTML *source; /* used for print_message */ + GtkWidget *window; /* used to realise the gtkhtml in a toplevel, i dont know why */ + EMFormatHTML *source; /* used for print_message */ - guint preview:1; + GtkPrintOperationAction action; }; struct _EMFormatHTMLPrintClass { - EMFormatHTMLClass formathtml_class; + EMFormatHTMLClass parent_class; }; -GType em_format_html_print_get_type(void); - -EMFormatHTMLPrint *em_format_html_print_new(void); - -int em_format_html_print_print(EMFormatHTMLPrint *efhp, EMFormatHTML *source, struct GtkPrintSettings *settings, int preview); -int em_format_html_print_message(EMFormatHTMLPrint *efhp, EMFormatHTML *source, struct GtkPrintSettings *settings, struct _CamelFolder *folder, const char *uid, int preview); -int em_format_html_print_raw_message(EMFormatHTMLPrint *efhp, struct _GtkPrintSettings *settings, struct _CamelMimeMessage *msg, int preview); +GType em_format_html_print_get_type (void); +EMFormatHTMLPrint * em_format_html_print_new (EMFormatHTML *source, + GtkPrintOperationAction action); +void em_format_html_print_message (EMFormatHTMLPrint *efhp, + CamelFolder *folder, + const char *uid); +void em_format_html_print_raw_message (EMFormatHTMLPrint *efhp, + CamelMimeMessage *msg); #endif /* ! _EM_FORMAT_HTML_PRINT_H */ diff --git a/plugins/print-message/ChangeLog b/plugins/print-message/ChangeLog index 22020bc06d..506cffce8b 100644 --- a/plugins/print-message/ChangeLog +++ b/plugins/print-message/ChangeLog @@ -1,3 +1,8 @@ +2007-04-20 Matthew Barnes <mbarnes@redhat.com> + + * print-message.c: + Refactor the printing infrastructure. (#426816) + 2007-02-12 Srinivasa Ragavan <sragavan@novell.com> ** Print migration updates from Ebby Wiselyn diff --git a/plugins/print-message/print-message.c b/plugins/print-message/print-message.c index 087aa82370..14b5e4655f 100644 --- a/plugins/print-message/print-message.c +++ b/plugins/print-message/print-message.c @@ -30,7 +30,6 @@ #include "mail/em-format-html-print.h" #include <glib.h> #include <glib/gi18n.h> -#include <libgnomeprintui/gnome-print-dialog.h> #include "mail/em-menu.h" #include "mail/em-utils.h" #include "e-util/e-print.h" @@ -39,72 +38,34 @@ void org_gnome_compose_print_message (EPlugin *ep, EMMenuTargetWidget *t); -struct _print_data { - GtkPrintSettings *config; - CamelMimeMessage *msg; - int preview; -}; - -static void -print_response (GtkWidget *w, int resp, struct _print_data *data) -{ - EMFormatHTMLPrint *print; - - switch (resp) { - case GTK_RESPONSE_APPLY: - data->preview = TRUE; - case GTK_RESPONSE_OK: - print = em_format_html_print_new(); - em_format_html_print_raw_message(print, data->config, data->msg, data->preview); - g_object_unref(print); - break; - } - - if (w) - gtk_widget_destroy(w); - - e_print_save_settings (data->config); - g_object_unref(data->config); - g_free(data); - -} - -void org_gnome_print_message (EPlugin *ep, EMMenuTargetWidget *t); - void org_gnome_print_message (EPlugin *ep, EMMenuTargetWidget *t) { - EMsgComposer *composer = (EMsgComposer *)t->target.widget; - struct _print_data *data; - GtkDialog *dialog; - - data = g_malloc0(sizeof(*data)); - data->config = e_print_load_settings (); - data->preview = 0; - - data->msg = e_msg_composer_get_message (composer, 1); - dialog = (GtkDialog *)e_print_get_dialog_with_config (_("Print Message"), 0, data->config); - gtk_dialog_set_default_response(dialog, GTK_RESPONSE_OK); - e_dialog_set_transient_for ((GtkWindow *) dialog, (GtkWidget *) composer); - print_response (dialog, GTK_RESPONSE_OK, data); -} + GtkPrintOperationAction action; + CamelMimeMessage *message; + EMFormatHTMLPrint *efhp; -void org_gnome_print_preview (EPlugin *ep, EMMenuTargetWidget *t); + action = GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG; + message = e_msg_composer_get_message (composer, 1); + + efhp = em_format_html_print_new (NULL, action); + em_format_html_print_raw_message (efhp, message); + g_object_unref (efhp); +} void org_gnome_print_preview (EPlugin *ep, EMMenuTargetWidget *t) { EMsgComposer *composer = (EMsgComposer *)t->target.widget; - struct _print_data *data; - - data = g_malloc0(sizeof(*data)); - data->config = e_print_load_settings (); - data->preview = 0; - - data->msg = e_msg_composer_get_message (composer, 1); - - print_response(NULL, GTK_RESPONSE_APPLY, data); -} + GtkPrintOperationAction action; + CamelMimeMessage *message; + EMFormatHTMLPrint *efhp; + action = GTK_PRINT_OPERATION_ACTION_PREVIEW; + message = e_msg_composer_get_message (composer, 1); + efhp = em_format_html_print_new (NULL, action); + em_format_html_print_raw_message (efhp, message); + g_object_unref (efhp); +} diff --git a/widgets/misc/e-printable.h b/widgets/misc/e-printable.h index 2d3140c99f..25e0454a0a 100644 --- a/widgets/misc/e-printable.h +++ b/widgets/misc/e-printable.h @@ -25,7 +25,6 @@ #define _E_PRINTABLE_H_ #include <gtk/gtkobject.h> -#include <libgnomeprint/gnome-print.h> #include <gtk/gtk.h> G_BEGIN_DECLS diff --git a/widgets/table/ChangeLog b/widgets/table/ChangeLog index 43d102a326..670368435d 100644 --- a/widgets/table/ChangeLog +++ b/widgets/table/ChangeLog @@ -1,3 +1,12 @@ +2007-04-20 Matthew Barnes <mbarnes@redhat.com> + + * e-cell.h: + * e-cell-pixbuf.c: + * e-cell-text.c: + * e-printable.h: + * e-table-group-container.c: + Refactor the printing infrastructure. (#426816) + 2007-04-19 Matthew Barnes <mbarnes@redhat.com> ** Fixes part of bug #429422 diff --git a/widgets/table/e-cell-pixbuf.c b/widgets/table/e-cell-pixbuf.c index 22d92bf98a..8b341c48a9 100644 --- a/widgets/table/e-cell-pixbuf.c +++ b/widgets/table/e-cell-pixbuf.c @@ -50,17 +50,6 @@ enum { PROP_UNSELECTED_COLUMN }; -static int -gnome_print_pixbuf (GtkPrintContext *pc, GdkPixbuf *pixbuf) -{ - cairo_t *cr = gtk_print_context_get_cairo_context (pc); - - gdk_cairo_set_source_pixbuf (cr, pixbuf, - (double)gdk_pixbuf_get_width (pixbuf), - (double)gdk_pixbuf_get_height (pixbuf)); - return TRUE; -} - /* * ECellPixbuf functions */ diff --git a/widgets/table/e-cell-text.c b/widgets/table/e-cell-text.c index 47088029a6..c6698182e7 100644 --- a/widgets/table/e-cell-text.c +++ b/widgets/table/e-cell-text.c @@ -45,7 +45,6 @@ #include <gtk/gtk.h> #include <libgnomecanvas/gnome-canvas.h> #include <libgnomecanvas/gnome-canvas-rect-ellipse.h> -#include <libgnomeprint/gnome-print-pango.h> #include "a11y/e-table/gal-a11y-e-cell-registry.h" #include "a11y/e-table/gal-a11y-e-cell-text.h" diff --git a/widgets/table/e-cell-tree.c b/widgets/table/e-cell-tree.c index 8853a7a132..6bb61e03d8 100644 --- a/widgets/table/e-cell-tree.c +++ b/widgets/table/e-cell-tree.c @@ -695,11 +695,14 @@ ect_leave_edit (ECellView *ecell_view, int model_col, int view_col, int row, voi } static void -ect_print (ECellView *ecell_view, GnomePrintContext *context, +ect_print (ECellView *ecell_view, GtkPrintContext *context, int model_col, int view_col, int row, double width, double height) { ECellTreeView *tree_view = (ECellTreeView *) ecell_view; + cairo_t *cr = gtk_print_context_get_cairo_context (context); + + cairo_save (cr); if (/* XXX only if we're the active sort */ TRUE) { ETreeModel *tree_model = e_cell_tree_get_tree_model (ecell_view->e_table_model, row); @@ -716,24 +719,20 @@ ect_print (ECellView *ecell_view, GnomePrintContext *context, if (!e_tree_model_node_is_root (tree_model, node) || e_tree_model_node_get_children (tree_model, node, NULL) > 0) { - gnome_print_moveto (context, - offset - INDENT_AMOUNT / 2, - height / 2); - - gnome_print_lineto (context, - offset, - height / 2); + cairo_move_to (cr, + offset - INDENT_AMOUNT / 2, + height / 2); + cairo_line_to (cr, offset, height / 2); } if (visible_depth_of_node (ecell_view->e_table_model, row) != 0) { - gnome_print_moveto (context, - offset - INDENT_AMOUNT / 2, - height); - gnome_print_lineto (context, - offset - INDENT_AMOUNT / 2, - (e_tree_table_adapter_node_get_next (tree_table_adapter, node) - ? 0 - : height / 2)); + cairo_move_to (cr, + offset - INDENT_AMOUNT / 2, height); + cairo_line_to (cr, + offset - INDENT_AMOUNT / 2, + e_tree_table_adapter_node_get_next + (tree_table_adapter, node) ? 0 : + height / 2); } /* now traverse back up to the root of the tree, checking at @@ -744,12 +743,11 @@ ect_print (ECellView *ecell_view, GnomePrintContext *context, offset -= INDENT_AMOUNT; while (node && depth != 0) { if (e_tree_table_adapter_node_get_next(tree_table_adapter, node)) { - gnome_print_moveto (context, - offset - INDENT_AMOUNT / 2, - height); - gnome_print_lineto (context, - offset - INDENT_AMOUNT / 2, - 0); + cairo_move_to (cr, + offset - INDENT_AMOUNT / 2, + height); + cairo_line_to (cr, + offset - INDENT_AMOUNT / 2, 0); } node = e_tree_model_node_get_parent (tree_model, node); depth --; @@ -759,41 +757,40 @@ ect_print (ECellView *ecell_view, GnomePrintContext *context, /* now draw our icon if we're expandable */ if (expandable) { - double image_matrix [6] = {16, 0, 0, 16, 0, 0}; - GdkPixbuf *image = (expanded - ? E_CELL_TREE(tree_view->cell_view.ecell)->open_pixbuf - : E_CELL_TREE(tree_view->cell_view.ecell)->closed_pixbuf); - int image_width, image_height, image_rowstride; - guchar *image_pixels; - - image_width = gdk_pixbuf_get_width(image); - image_height = gdk_pixbuf_get_height(image); - image_pixels = gdk_pixbuf_get_pixels(image); - image_rowstride = gdk_pixbuf_get_rowstride(image); - - image_matrix [4] = subcell_offset - INDENT_AMOUNT / 2 - image_width / 2; - image_matrix [5] = height / 2 - image_height / 2; - - gnome_print_gsave (context); - gnome_print_concat (context, image_matrix); - - gnome_print_rgbaimage (context, image_pixels, image_width, image_height, image_rowstride); - gnome_print_grestore (context); + ECellTree *tree; + GdkPixbuf *pixbuf; + gint image_width; + gint image_height; + + tree = E_CELL_TREE (tree_view->cell_view.ecell); + + if (expanded) + pixbuf = tree->open_pixbuf; + else + pixbuf = tree->closed_pixbuf; + + image_width = gdk_pixbuf_get_width (pixbuf); + image_height = gdk_pixbuf_get_height (pixbuf); + + gdk_cairo_set_source_pixbuf ( + cr, pixbuf, subcell_offset - + INDENT_AMOUNT / 2 - image_width - 2, + height / 2 - image_height / 2); } - gnome_print_stroke (context); + cairo_stroke (cr); - if (gnome_print_translate(context, subcell_offset, 0) == -1) - /* FIXME */; + cairo_translate (cr, subcell_offset, 0); width -= subcell_offset; } + cairo_restore (cr); e_cell_print (tree_view->subcell_view, context, model_col, view_col, row, width, height); } static gdouble -ect_print_height (ECellView *ecell_view, GnomePrintContext *context, +ect_print_height (ECellView *ecell_view, GtkPrintContext *context, int model_col, int view_col, int row, double width) { diff --git a/widgets/table/e-cell.h b/widgets/table/e-cell.h index 378d32d75e..72ae6a6c79 100644 --- a/widgets/table/e-cell.h +++ b/widgets/table/e-cell.h @@ -27,8 +27,6 @@ #include <gdk/gdktypes.h> #include <gtk/gtk.h> -#include <libgnomeprint/gnome-print.h> -#include <libgnomeprint/gnome-font.h> #include <table/e-table-model.h> #include <table/e-table-tooltip.h> diff --git a/widgets/table/e-table-group-container.c b/widgets/table/e-table-group-container.c index 3a21171d1c..0cccdd6e38 100644 --- a/widgets/table/e-table-group-container.c +++ b/widgets/table/e-table-group-container.c @@ -1152,7 +1152,8 @@ e_table_group_container_print_page (EPrintable *ep, GList *child; EPrintable *child_printable; gchar *string; - GnomeFont *font = gnome_font_find_closest ("Helvetica", TEXT_HEIGHT); + PangoLayout *layout; + PangoFontDescription *desc; child_printable = groupcontext->child_printable; child = groupcontext->child; @@ -1177,22 +1178,30 @@ e_table_group_container_print_page (EPrintable *ep, } } + layout = gtk_print_context_create_pango_layout (context); + + desc = pango_font_description_new (); + pango_font_description_set_family_static (desc, "Helvetica"); + pango_font_description_set_size (desc, TEXT_HEIGHT); + pango_layout_set_font_description (layout, desc); + pango_font_description_free (desc); + while (1) { - child_height = e_printable_height(child_printable, context, width,yd + 2 * TEXT_AREA_HEIGHT, quantize); - cr = gtk_print_context_get_cairo_context (context); - cairo_save (cr); - cairo_rectangle (cr, 0, 0, width,TEXT_AREA_HEIGHT); - cairo_rectangle (cr, 0, 0, 2 * TEXT_AREA_HEIGHT, child_height + TEXT_AREA_HEIGHT); - cairo_set_source_rgb (cr, .7, .7, .7) ; - cairo_fill(cr) ; - cairo_restore (cr); - - cairo_save (cr); - cairo_rectangle (cr, 0, 0, width, TEXT_AREA_HEIGHT); - cairo_clip (cr); - cairo_restore (cr); + child_height = e_printable_height(child_printable, context, width,yd + 2 * TEXT_AREA_HEIGHT, quantize); + cr = gtk_print_context_get_cairo_context (context); + cairo_save (cr); + cairo_rectangle (cr, 0, 0, width,TEXT_AREA_HEIGHT); + cairo_rectangle (cr, 0, 0, 2 * TEXT_AREA_HEIGHT, child_height + TEXT_AREA_HEIGHT); + cairo_set_source_rgb (cr, .7, .7, .7) ; + cairo_fill(cr) ; + cairo_restore (cr); + + cairo_save (cr); + cairo_rectangle (cr, 0, 0, width, TEXT_AREA_HEIGHT); + cairo_clip (cr); + cairo_restore (cr); - cairo_move_to(cr, 0, (gnome_font_get_ascender(font) - gnome_font_get_descender(font)) / 2); + cairo_move_to(cr, 0, 0); if (groupcontext->etgc->ecol->text) string = g_strdup_printf ("%s : %s (%d item%s)", groupcontext->etgc->ecol->text, @@ -1204,16 +1213,17 @@ e_table_group_container_print_page (EPrintable *ep, child_node->string, (gint) child_node->count, child_node->count == 1 ? "" : "s"); - cairo_show_text (cr, string); - g_free(string); - - cairo_translate(cr, 2 * TEXT_AREA_HEIGHT, TEXT_AREA_HEIGHT) ; - cairo_move_to(cr, 0, 0); - cairo_rectangle (cr, 0, 0, width - 2 * TEXT_AREA_HEIGHT,child_height); - cairo_clip(cr); + pango_layout_set_text (layout, string, -1); + pango_cairo_show_layout (cr, layout); + g_free(string); + + cairo_translate(cr, 2 * TEXT_AREA_HEIGHT, TEXT_AREA_HEIGHT) ; + cairo_move_to(cr, 0, 0); + cairo_rectangle (cr, 0, 0, width - 2 * TEXT_AREA_HEIGHT,child_height); + cairo_clip(cr); - e_printable_print_page (child_printable, context, width-2 * TEXT_AREA_HEIGHT, 0, quantize); - yd += child_height + TEXT_AREA_HEIGHT; + e_printable_print_page (child_printable, context, width-2 * TEXT_AREA_HEIGHT, 0, quantize); + yd += child_height + TEXT_AREA_HEIGHT; if (e_printable_data_left(child_printable)) break; @@ -1236,6 +1246,8 @@ e_table_group_container_print_page (EPrintable *ep, g_object_unref (groupcontext->child_printable); groupcontext->child_printable = child_printable; groupcontext->child = child; + + g_object_unref (layout); } static gboolean |