[Gnucash-changes] Convert printing over to g2.

David Hampton hampton at cvs.gnucash.org
Sun Jul 3 01:43:57 EDT 2005


Log Message:
-----------
Convert printing over to g2.

Tags:
----
gnucash-gnome2-dev

Modified Files:
--------------
    gnucash:
        ChangeLog
    gnucash/src/gnome:
        dialog-print-check.c
    gnucash/src/gnome-utils:
        gnc-html.c
        gw-gnome-utils-spec.scm
        print-session.c
        print-session.h
    gnucash/src/scm/printing:
        print-check.scm

Revision Data
-------------
Index: ChangeLog
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/ChangeLog,v
retrieving revision 1.1487.2.236
retrieving revision 1.1487.2.237
diff -LChangeLog -LChangeLog -u -r1.1487.2.236 -r1.1487.2.237
--- ChangeLog
+++ ChangeLog
@@ -1,5 +1,40 @@
+2005-07-03  David Hampton  <hampton at employees.org>
+
+	* src/gnome/dialog-print-check.c:
+	* src/gnome-utils/gnc-html.c:
+	* src/gnome-utils/gw-gnome-utils-spec.scm:
+	* src/gnome-utils/print-session.[ch]:
+	* src/scm/printing/print-check.scm: Convert printing over to g2.
+
+	* src/gnome/gnc-plugin-page-register.c:
+	* src/gnome/ui/gnc-plugin-page-register-ui.xml: Move the "Print
+	Check" command to overlay the "Print" placeholder.
+
+	* src/report/report-gnome/gnc-plugin-page-report.c: Replace the
+	gtk1.2 "draw" signal with the gtk2.0 "expose_event" signal.
+
+2005-07-02  David Hampton  <hampton at employees.org>
+
+	* src/report/report-gnome/gnc-plugin-page-report-ui.xml:
+	* src/report/report-gnome/gnc-plugin-page-report.c: Duplicate a
+	couple of the toolbar buttons as menu items.
+
+	* src/gnome-utils/print-session.[ch]:
+	* configure.in: Remove old checks for libgnomeprint2.0.
+
+	* src/gnome-utils/gnc-main-window.c: Print is a placeholder that
+	must be overridden.
+
+	* src/business/business-core/gncEmployee.h: Add #define for
+	deprecated function.
+		
 2005-07-01  David Hampton  <hampton at employees.org>
 
+	* src/business/business-core/gncEmployee.h: Add #define for
+	deprecated function.
+
+	* src/gnome-utils/dialog-query-list.c: Finish g1->g2 widget conversion.
+
 	* src/gnome/gnc-plugin-basic-commands.c: Rename "Find Transactions"
 	back to "Find".
 
Index: print-session.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/gnome-utils/print-session.c,v
retrieving revision 1.2.4.8
retrieving revision 1.2.4.9
diff -Lsrc/gnome-utils/print-session.c -Lsrc/gnome-utils/print-session.c -u -r1.2.4.8 -r1.2.4.9
--- src/gnome-utils/print-session.c
+++ src/gnome-utils/print-session.c
@@ -39,19 +39,36 @@
 {
   PrintSession * ps = g_new0(PrintSession, 1);
   GnomePrintConfig *config;
+  GtkWidget *dialog;
+  gint response;
 
-  /* this is about the most basic we can get */
-  ps->master       = gnome_print_job_new(NULL);
-  config = gnome_print_job_get_config(ps->master);
-  ps->meta         = gnome_print_context_new(config);
-  ps->default_font = gnome_font_find("Courier", 12);
+  /* Ask the user what to do with the output */
+  dialog = gnome_print_dialog_new(ps->job, _("Print GnuCash Document"), 0);
+  response = gtk_dialog_run(GTK_DIALOG(dialog));
+  switch (response) {
+    case GNOME_PRINT_DIALOG_RESPONSE_PRINT: 
+    case GNOME_PRINT_DIALOG_RESPONSE_PREVIEW:
+      config = gnome_print_dialog_get_config (GNOME_PRINT_DIALOG (dialog));
+      gtk_widget_destroy(dialog);
+      ps->job = gnome_print_job_new(config);
+      ps->context = gnome_print_job_get_context(ps->job);
+      break;
+    
+    default:
+      gtk_widget_destroy(dialog);
+      g_free(ps);
+      return NULL;
+  }
+
+  ps->hand_built_pages = hand_built_pages;
+  ps->print_type = response;
+
+  ps->default_font = gnome_font_find_closest("Sans Regular", 12);
 
   if (hand_built_pages) {
-    gnome_print_beginpage(GNOME_PRINT_CONTEXT(ps->meta), "");
-    gnome_print_setrgbcolor(GNOME_PRINT_CONTEXT(ps->meta),
-			    0.0, 0.0, 0.0);
-    gnome_print_setfont(GNOME_PRINT_CONTEXT(ps->meta), 
-			GNOME_FONT(ps->default_font));
+    gnome_print_beginpage(ps->context, "");
+    gnome_print_setrgbcolor(ps->context, 0.0, 0.0, 0.0);
+    gnome_print_setfont(ps->context, ps->default_font);
   }
   return ps;
 }
@@ -59,8 +76,7 @@
 void 
 gnc_print_session_destroy(PrintSession * ps)
 {
-  g_object_unref(ps->meta);
-  g_object_unref(ps->master);
+  g_object_unref(ps->job);
   g_object_unref(ps->default_font);
 
   g_free(ps);
@@ -69,104 +85,62 @@
 void 
 gnc_print_session_moveto(PrintSession * ps, double x, double y)
 {
-  gnome_print_moveto(GNOME_PRINT_CONTEXT(ps->meta), x, y);
+  gnome_print_moveto(ps->context, x, y);
 }
 
 
 void 
 gnc_print_session_text(PrintSession * ps, const char * text)
 {
-  gnome_print_show(GNOME_PRINT_CONTEXT(ps->meta), text);  
+  gnome_print_show(ps->context, text);  
 }
 
 
 void
-gnc_print_session_done(PrintSession * ps, gboolean hand_built_pages)
+gnc_print_session_done(PrintSession * ps)
 {
-  if (hand_built_pages) {
-    gnome_print_showpage(GNOME_PRINT_CONTEXT(ps->meta));
+  GtkWidget *widget;
+
+  if (ps->hand_built_pages) {
+    gnome_print_showpage(ps->context);
   }
-  gnome_print_context_close(GNOME_PRINT_CONTEXT(ps->meta));
+  gnome_print_job_close (ps->job);
 
+  switch (ps->print_type) {
+    case GNOME_PRINT_DIALOG_RESPONSE_PRINT: 
+      gnome_print_job_print(ps->job);
+      break;
+
+    case GNOME_PRINT_DIALOG_RESPONSE_PREVIEW:
+      widget = gnome_print_job_preview_new(ps->job, "Print Preview");
+      gtk_widget_show(widget);
+      break;
+    
+    default:
+      break;
+  }
 }
 
 void
 gnc_print_session_rotate(PrintSession *ps, double theta_in_degrees)
 {
-  gnome_print_rotate(GNOME_PRINT_CONTEXT(ps->meta), theta_in_degrees);
+  gnome_print_rotate(ps->context, theta_in_degrees);
 }
 
 void
 gnc_print_session_translate(PrintSession *ps, double x, double y)
 {
-  gnome_print_translate(GNOME_PRINT_CONTEXT(ps->meta), x, y);
+  gnome_print_translate(ps->context, x, y);
 }
 
 void
 gnc_print_session_gsave(PrintSession *ps)
 {
-  gnome_print_gsave(GNOME_PRINT_CONTEXT(ps->meta));
+  gnome_print_gsave(ps->context);
 }
 
 void
 gnc_print_session_grestore(PrintSession *ps)
 {
-  gnome_print_grestore(GNOME_PRINT_CONTEXT(ps->meta));
-}
-
-void
-gnc_print_session_print(PrintSession * ps)
-{
-  GtkWidget * dialog    =
-    gnome_print_dialog_new(ps->master,_("Print GnuCash Document"), 0);
-  int button            = gnome_dialog_run(GNOME_DIALOG(dialog));
-  GnomePrintConfig *config;
-
-  switch(button) {
-  case 0: 
-    /* print button */
-    if(ps->master) {
-      g_object_unref(ps->master);
-      ps->master = NULL;
-    }
-    config = gnome_print_dialog_get_config (GNOME_PRINT_DIALOG (dialog));
-    ps->master = gnome_print_job_new(config);
-    gnome_dialog_close(GNOME_DIALOG(dialog));
-    gnc_print_session_render(ps);
-    break;
-    
-  case 1:
-    if(ps->master) {
-      g_object_unref(ps->master);
-      ps->master = NULL;
-    }
-    config = gnome_print_dialog_get_config (GNOME_PRINT_DIALOG (dialog));
-    ps->master = gnome_print_job_new(config);
-    gnome_dialog_close(GNOME_DIALOG(dialog));
-    gnc_print_session_preview(ps);    
-    break;
-
-  case 2:
-    gnome_dialog_close(GNOME_DIALOG(dialog));
-    break;
-  }
-}
-
-
-void 
-gnc_print_session_render(PrintSession * ps)
-{
-  gnome_print_job_render (ps->master, ps->meta);
-  gnome_print_job_close (ps->master);
-  gnome_print_job_print(ps->master);
-}
-
-void 
-gnc_print_session_preview(PrintSession * ps)
-{
-  GtkWidget * preview;
-  gnome_print_job_render (ps->master, ps->meta);
-  gnome_print_job_close (ps->master);
-  preview = gnome_print_job_preview_new(ps->master, _("Print Preview"));
-  gtk_widget_show_all(preview);
+  gnome_print_grestore(ps->context);
 }
Index: gw-gnome-utils-spec.scm
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/gnome-utils/gw-gnome-utils-spec.scm,v
retrieving revision 1.19.4.8
retrieving revision 1.19.4.9
diff -Lsrc/gnome-utils/gw-gnome-utils-spec.scm -Lsrc/gnome-utils/gw-gnome-utils-spec.scm -u -r1.19.4.8 -r1.19.4.9
--- src/gnome-utils/gw-gnome-utils-spec.scm
+++ src/gnome-utils/gw-gnome-utils-spec.scm
@@ -169,7 +169,8 @@
    '<gnc:PrintSession*>
    "gnc_print_session_create"
    '((<gw:bool> yes_is_default))
-   "Start a new print session.")
+   "Start a new print session.  This will display a dialog asking for "
+   "number of copies, print vs. preview, etc.")
 
   (gw:wrap-function
    ws
@@ -232,17 +233,8 @@
    'gnc:print-session-done
    '<gw:void>
    "gnc_print_session_done"
-   '((<gnc:PrintSession*> p)
-     (<gw:bool> yes_is_default))
-   "Let the print context know you're finished with it.")
-
-  (gw:wrap-function
-   ws
-   'gnc:print-session-print
-   '<gw:void>
-   "gnc_print_session_print"
    '((<gnc:PrintSession*> p))
-   "Show the GNOME print dialog to start printing.")
+   "Let the print context know you're finished with it.")
 
   (gw:wrap-function
    ws
Index: gnc-html.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/gnome-utils/gnc-html.c,v
retrieving revision 1.23.4.10
retrieving revision 1.23.4.11
diff -Lsrc/gnome-utils/gnc-html.c -Lsrc/gnome-utils/gnc-html.c -u -r1.23.4.10 -r1.23.4.11
--- src/gnome-utils/gnc-html.c
+++ src/gnome-utils/gnc-html.c
@@ -1361,12 +1361,16 @@
 void
 gnc_html_print(gnc_html * html)
 {
-  PrintSession * ps = gnc_print_session_create(FALSE);
-  
-  gtk_html_print(GTK_HTML(html->html),
-                 GNOME_PRINT_CONTEXT(ps->meta));
-  gnc_print_session_done(ps, FALSE);
-  gnc_print_session_print(ps);
+  PrintSession *ps;
+
+  ps = gnc_print_session_create(FALSE);
+  if (ps == NULL) {
+    /* user cancelled */
+    return;
+  }
+
+  gtk_html_print(GTK_HTML(html->html), ps->context);
+  gnc_print_session_done(ps);
 }
 
 gnc_html_history * 
Index: print-session.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/gnome-utils/print-session.h,v
retrieving revision 1.3.4.5
retrieving revision 1.3.4.6
diff -Lsrc/gnome-utils/print-session.h -Lsrc/gnome-utils/print-session.h -u -r1.3.4.5 -r1.3.4.6
--- src/gnome-utils/print-session.h
+++ src/gnome-utils/print-session.h
@@ -24,6 +24,13 @@
 #ifndef PRINT_SESSION_H
 #define PRINT_SESSION_H
 
+/** @addtogroup Printing
+    @{ */
+/** @file print-session.h
+    @brief Functions for printing
+    @author Copyright (C) 2000 Bill Gribble <grib at billgribble.com>
+*/
+
 #include "config.h"
 
 #include <gnome.h>
@@ -35,62 +42,72 @@
 #include <libgnomeprintui/gnome-print-preview.h>
 
 typedef struct {
-  GnomePrintJob      * master;
-  GnomePrintContext  * meta;
+  gboolean             hand_built_pages;
+  gint                 print_type;
+
+  GnomePrintJob      * job;
+  GnomePrintContext  * context;		/* Convenience only. Owned by the job */
   GnomeFont          * default_font;
   GnomePrintPaper    * paper;
 } PrintSession;
 
-typedef struct {
-  GtkWidget         * toplevel;
-  GtkWidget         * canvas;
-  GnomePrintContext * meta;
-  PrintSession      * session;
-} PrintPreviewDialog;
-
-typedef struct {
-  GtkWidget         * toplevel;
-  GtkWidget         * printer_entry;
-  GtkWidget         * paper_entry;
-  PrintSession      * session;
-} PrintDialog;
 
-typedef struct {
-  GtkWidget         * toplevel;
-  GtkWidget         * papersel;
-  GtkWidget         * entry;
-  PrintSession      * session;
-} PaperDialog;
-
-
-/* paper selector dialog */
-PaperDialog * gnc_ui_paper_dialog_create(PrintSession * ps, GtkWidget * entry);
-void gnc_ui_paper_dialog_destroy(PaperDialog * psd);
-
-/* print preview dialog stuff */
-PrintPreviewDialog * gnc_ui_print_preview_create(PrintSession * ps);
-void gnc_ui_print_preview_destroy(PrintPreviewDialog * ppd);
-
-/* print check dialog stuff */
-PrintDialog * gnc_ui_print_dialog_create(PrintSession * ps);
-void gnc_ui_print_dialog_destroy(PrintDialog * pcd);
+/** @addtogroup Basic Session Functions
+    @{ */
 
-/* printsession stuff */
-PrintSession * gnc_print_session_create(gboolean);
+/** Create a new print 'session'.  Once created, a series of commands
+ *  can be issued on the session to create the output page.  The
+ *  output will be printed when the session is done.  This function
+ *  will present the standard print/preview selection box to the user
+ *  and wait for the result.
+ *
+ *  If the hand_built_pages argument is set to TRUE, this function
+ *  will perform a couple of extra setup steps.  Specifically it will
+ *  call the gnome begin page, set color and set font functions.  The
+ *  code will also call close page when the #gnc_print_session_done
+ *  function is called.
+ *
+ *  @param hand_built_pages If TRUE, this funciton will perform extra setup.
+ *
+ *  @return A pointer to the data structure describing this print session.
+ */
+PrintSession * gnc_print_session_create(gboolean hand_built_pages);
+
+
+/** Destroy a print 'session' without producing any output.
+ *
+ *  @ps A pointer to the session to be destroyed.
+ */
 void gnc_print_session_destroy(PrintSession * ps);
 
+
+/** Finish a print 'session'.  The output from this session will be
+ *  printed to the device selected when the session was created.
+ *
+ *  If the hand_built_pages argument was set to TRUE in the call to
+ *  #gnc_print_session_create, this function will perform the
+ *  additional setp of calling the gnome show page function before
+ *  doing anything else.
+ *
+ *  @param hand_built_pages If TRUE, this funciton will perform extra setup.
+ *
+ *  @return A pointer to the data structure describing this print session.
+ */
+void gnc_print_session_done(PrintSession * ps);
+
+/** @} */
+
+/** @addtogroup Adding Output to a Page
+    @{ */
 void gnc_print_session_moveto(PrintSession * ps, double x, double y);
 void gnc_print_session_text(PrintSession * ps, const char * text);
-void gnc_print_session_done(PrintSession * ps, gboolean);
 
 void gnc_print_session_rotate(PrintSession *ps, double theta_in_degrees);
 void gnc_print_session_translate(PrintSession *ps, double x, double y);
 
 void gnc_print_session_gsave(PrintSession *ps);
 void gnc_print_session_grestore(PrintSession *ps);
-
-void gnc_print_session_preview(PrintSession * ps);
-void gnc_print_session_print(PrintSession * ps);
-void gnc_print_session_render(PrintSession * ps);
+/** @} */
+/** @} */
 
 #endif
Index: dialog-print-check.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/gnome/dialog-print-check.c,v
retrieving revision 1.13.4.6
retrieving revision 1.13.4.7
diff -Lsrc/gnome/dialog-print-check.c -Lsrc/gnome/dialog-print-check.c -u -r1.13.4.6 -r1.13.4.7
--- src/gnome/dialog-print-check.c
+++ src/gnome/dialog-print-check.c
@@ -117,7 +117,7 @@
   gnc_option_menu_init(pcd->units_picker);
 
   window = GTK_WINDOW(GNC_PLUGIN_PAGE(plugin_page)->window);
-  gnome_dialog_set_parent(GNOME_DIALOG(pcd->dialog), window);
+  gtk_window_set_transient_for(GTK_WINDOW(pcd->dialog), window);
 
   /* Create and attach the date-format chooser */
   table = glade_xml_get_widget (xml, "options_table");
@@ -139,11 +139,10 @@
 void
 gnc_ui_print_check_dialog_destroy(PrintCheckDialog * pcd)
 {
-  gnome_dialog_close(GNOME_DIALOG(pcd->dialog));
   gtk_widget_destroy(pcd->dialog);
   pcd->dialog = NULL;
 
-  g_object_set_data(G_OBJECT(pcd->plugin_page), PRINT_CHECK_DATA, pcd);
+  g_object_set_data(G_OBJECT(pcd->plugin_page), PRINT_CHECK_DATA, NULL);
   g_free(pcd);
 }
 
Index: print-check.scm
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/scm/printing/print-check.scm,v
retrieving revision 1.11.4.3
retrieving revision 1.11.4.4
diff -Lsrc/scm/printing/print-check.scm -Lsrc/scm/printing/print-check.scm -u -r1.11.4.3 -r1.11.4.4
--- src/scm/printing/print-check.scm
+++ src/scm/printing/print-check.scm
@@ -97,16 +97,19 @@
     ))
 
 (define (gnc:print-check format-info payee amount date memo)
-    (let* ((int-part (inexact->exact (truncate amount)))
-           (frac-part (inexact->exact 
+  (let* ((int-part (inexact->exact (truncate amount)))
+	 (frac-part (inexact->exact 
                      (truncate 
                       (+ (/ .5 100) (* 100 (- amount int-part))))))
-           (ps (gnc:print-session-create #t))
-           (format #f)
-           (offset #f)
-           (date-string "")
-           (payee-stub-text "")
-           (memo-stub-text ""))
+	 (ps (gnc:print-session-create #t))
+	 (format #f)
+	 (offset #f)
+	 (date-string "")
+	 (payee-stub-text "")
+	 (memo-stub-text ""))
+
+    (if (not (null? ps))
+     (begin
       (if (not (eq? (print-check-format:format format-info) 'custom))
           (begin 
             (set! format (assq (print-check-format:format format-info) 
@@ -202,6 +205,5 @@
                                   (+ offset (caddr amountstub-pos)))
              (gnc:print-session-text ps (printable-value amount 100)))))
 
-      (gnc:print-session-done ps #t)
-      (gnc:print-session-print ps)))
+      (gnc:print-session-done ps)))))
 


More information about the gnucash-changes mailing list