r17611 - gnucash/trunk/src - Bug #531871: Add a page setup dialog.

Andreas Köhler andi5 at cvs.gnucash.org
Sun Sep 28 11:32:02 EDT 2008


Author: andi5
Date: 2008-09-28 11:32:02 -0400 (Sun, 28 Sep 2008)
New Revision: 17611
Trac: http://svn.gnucash.org/trac/changeset/17611

Modified:
   gnucash/trunk/src/gnome-utils/gnc-html.c
   gnucash/trunk/src/gnome-utils/gnc-main-window.c
   gnucash/trunk/src/gnome-utils/print-session.c
   gnucash/trunk/src/gnome-utils/print-session.h
   gnucash/trunk/src/gnome-utils/ui/gnc-main-window-ui.xml
   gnucash/trunk/src/gnome/dialog-print-check.c
Log:
Bug #531871: Add a page setup dialog.

Save the page setup in a static variable in print-session.c and use it when
initializing a GtkPrintOperation.  Add gnc_ui_page_setup() and offer access to
it from a File > Pa_ge Setup... menu entry.

Modified: gnucash/trunk/src/gnome/dialog-print-check.c
===================================================================
--- gnucash/trunk/src/gnome/dialog-print-check.c	2008-09-28 15:31:50 UTC (rev 17610)
+++ gnucash/trunk/src/gnome/dialog-print-check.c	2008-09-28 15:32:02 UTC (rev 17611)
@@ -1978,7 +1978,7 @@
 
     print = gtk_print_operation_new();
 
-    gnc_print_operation_restore_print_settings(print);
+    gnc_print_operation_init(print);
     gtk_print_operation_set_unit(print, GTK_UNIT_POINTS);
     gtk_print_operation_set_use_full_page(print, TRUE);
     g_signal_connect(print, "begin_print", G_CALLBACK(begin_print), NULL);

Modified: gnucash/trunk/src/gnome-utils/gnc-html.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-html.c	2008-09-28 15:31:50 UTC (rev 17610)
+++ gnucash/trunk/src/gnome-utils/gnc-html.c	2008-09-28 15:32:02 UTC (rev 17611)
@@ -1234,7 +1234,7 @@
 
     print = gtk_print_operation_new();
 
-    gnc_print_operation_restore_print_settings(print);
+    gnc_print_operation_init(print);
     gtk_print_operation_set_use_full_page(print, FALSE);
     gtk_print_operation_set_unit(print, GTK_UNIT_POINTS);
     gtk_print_operation_set_n_pages(print, 1);

Modified: gnucash/trunk/src/gnome-utils/gnc-main-window.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-main-window.c	2008-09-28 15:31:50 UTC (rev 17610)
+++ gnucash/trunk/src/gnome-utils/gnc-main-window.c	2008-09-28 15:32:02 UTC (rev 17611)
@@ -67,6 +67,9 @@
 // +JSLED
 #include "gnc-html.h"
 #include "gnc-autosave.h"
+#ifdef HAVE_GTK_2_10
+#    include "print-session.h"
+#endif
 
 /** Names of signals generated by the main window. */
 enum {
@@ -121,6 +124,9 @@
 static void gnc_main_window_plugin_removed (GncPlugin *manager, GncPlugin *plugin, GncMainWindow *window);
 
 /* Command callbacks */
+#ifdef HAVE_GTK_2_10
+static void gnc_main_window_cmd_page_setup (GtkAction *action, GncMainWindow *window);
+#endif
 static void gnc_main_window_cmd_file_properties (GtkAction *action, GncMainWindow *window);
 static void gnc_main_window_cmd_file_close (GtkAction *action, GncMainWindow *window);
 static void gnc_main_window_cmd_file_quit (GtkAction *action, GncMainWindow *window);
@@ -236,6 +242,14 @@
 	{ "FileExportAction", NULL, N_("_Export"), NULL, NULL, NULL },
 	{ "FilePrintAction", GTK_STOCK_PRINT, N_("_Print..."), "<control>p", 
 	  N_("Print the currently active page"), NULL },
+#ifdef HAVE_GTK_2_10
+#    ifndef GTK_STOCK_PAGE_SETUP
+#        define GTK_STOCK_PAGE_SETUP NULL
+#    endif
+	{ "FilePageSetupAction", GTK_STOCK_PAGE_SETUP, N_("Pa_ge Setup..."), "<control><shift>p",
+	  N_("Specify the page size and orientation for printing"),
+	  G_CALLBACK (gnc_main_window_cmd_page_setup) },
+#endif
 	{ "FilePropertiesAction", GTK_STOCK_PROPERTIES, N_("Proper_ties"), "<Alt>Return",
 	  N_("Edit the properties of the current file"),
 	  G_CALLBACK (gnc_main_window_cmd_file_properties) },
@@ -3142,7 +3156,21 @@
 
 
 /* Command callbacks */
+#ifdef HAVE_GTK_2_10
 static void
+gnc_main_window_cmd_page_setup (GtkAction *action,
+                                         GncMainWindow *window)
+{
+  GtkWindow *gtk_window;
+
+  g_return_if_fail(GNC_IS_MAIN_WINDOW(window));
+
+  gtk_window = gnc_window_get_gtk_window(GNC_WINDOW(window));
+  gnc_ui_page_setup(gtk_window);
+}
+#endif
+
+static void
 gnc_main_window_cmd_file_properties (GtkAction *action, GncMainWindow *window)
 {
   SCM func = scm_c_eval_string("gnc:main-window-properties-cb");

Modified: gnucash/trunk/src/gnome-utils/print-session.c
===================================================================
--- gnucash/trunk/src/gnome-utils/print-session.c	2008-09-28 15:31:50 UTC (rev 17610)
+++ gnucash/trunk/src/gnome-utils/print-session.c	2008-09-28 15:32:02 UTC (rev 17611)
@@ -48,7 +48,9 @@
 #    endif
 
 static GtkPrintSettings *print_settings = NULL;
+static GtkPageSetup *page_setup = NULL;
 G_LOCK_DEFINE_STATIC(print_settings);
+G_LOCK_DEFINE_STATIC(page_setup);
 #endif
 
 
@@ -66,15 +68,60 @@
 }
 
 void
-gnc_print_operation_restore_print_settings(GtkPrintOperation *op)
+gnc_print_operation_init(GtkPrintOperation *op)
 {
   g_return_if_fail(op);
 
+  /* Restore print settings */
   G_LOCK(print_settings);
   if (print_settings)
     gtk_print_operation_set_print_settings(op, print_settings);
   G_UNLOCK(print_settings);
+
+  /* Restore page setup */
+  G_LOCK(page_setup);
+  if (page_setup)
+    gtk_print_operation_set_default_page_setup(op, page_setup);
+  G_UNLOCK(page_setup);
 }
+
+void
+gnc_ui_page_setup(GtkWindow *parent)
+{
+  GtkPrintSettings *settings = NULL;
+  GtkPageSetup *old_page_setup, *new_page_setup;
+
+  /* Get a reference to the current print settings */
+  G_LOCK(print_settings);
+  settings = print_settings;
+  if (settings)
+    g_object_ref(settings);
+  G_UNLOCK(print_settings);
+
+  /* Get a reference to the current page setup */
+  G_LOCK(page_setup);
+  old_page_setup = page_setup;
+  if (old_page_setup)
+    g_object_ref(old_page_setup);
+  G_UNLOCK(page_setup);
+
+  /* Run dialog */
+  new_page_setup = gtk_print_run_page_setup_dialog(parent, old_page_setup,
+                                                   settings);
+
+  /* Save new page setup */
+  G_LOCK(page_setup);
+  if (page_setup)
+    g_object_unref(page_setup);
+  page_setup = new_page_setup;
+  G_UNLOCK(page_setup);
+
+  /* Release references */
+  if (settings)
+    g_object_unref(settings);
+  if (old_page_setup)
+    g_object_unref(old_page_setup);
+}
 #endif  /* HAVE_GTK_2_10 */
 
 

Modified: gnucash/trunk/src/gnome-utils/print-session.h
===================================================================
--- gnucash/trunk/src/gnome-utils/print-session.h	2008-09-28 15:31:50 UTC (rev 17610)
+++ gnucash/trunk/src/gnome-utils/print-session.h	2008-09-28 15:32:02 UTC (rev 17611)
@@ -49,12 +49,20 @@
 /**
  * If print settings have been saved by
  * gnc_print_operation_save_print_settings(), then set them on the given
- * GtkPrintOperation @a op.
+ * GtkPrintOperation @a op.  Set the default page setup as well.
  *
  * @param op non-NULL print operation
  */
-void gnc_print_operation_restore_print_settings(GtkPrintOperation *op);
+void gnc_print_operation_init(GtkPrintOperation *op);
 
+/**
+ * Run a page setup dialog and save the resulting GtkPageSetup in a static
+ * variable.
+ *
+ * @param parent Transient parent, or NULL
+ */
+void gnc_ui_page_setup(GtkWindow *parent);
+
 #endif  /* HAVE_GTK_2_10 */
 
 

Modified: gnucash/trunk/src/gnome-utils/ui/gnc-main-window-ui.xml
===================================================================
--- gnucash/trunk/src/gnome-utils/ui/gnc-main-window-ui.xml	2008-09-28 15:31:50 UTC (rev 17610)
+++ gnucash/trunk/src/gnome-utils/ui/gnc-main-window-ui.xml	2008-09-28 15:32:02 UTC (rev 17611)
@@ -18,6 +18,7 @@
       <placeholder name="FileSavePlaceholder"/>
       <separator name="FileSep2"/>
       <menuitem name="FilePrint" action="FilePrintAction"/>
+      <menuitem name="FilePageSetup" action="FilePageSetupAction"/>
       <placeholder name="FilePrintPlaceholder"/>
       <menu name="FileExport" action="FileExportAction">
         <placeholder name="FileExportPlaceholder"/>



More information about the gnucash-changes mailing list