GnuCash  4.11-243-g1cac132214+
print-session.c
1 /********************************************************************\
2  * print-session.c -- simple printing manager for gnucash *
3  * Copyright (C) 2000 Bill Gribble <grib@billgribble.com> *
4  * *
5  * This program is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU General Public License as *
7  * published by the Free Software Foundation; either version 2 of *
8  * the License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License*
16  * along with this program; if not, contact: *
17  * *
18  * Free Software Foundation Voice: +1-617-542-5942 *
19  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
20  * Boston, MA 02110-1301, USA gnu@gnu.org *
21 \********************************************************************/
22 
23 #include <config.h>
24 
25 #include <gtk/gtk.h>
26 
27 #include "print-session.h"
28 
29 #undef G_LOG_DOMAIN
30 #define G_LOG_DOMAIN "gnc.printing"
31 
32 /* Do not treat -Wstrict-aliasing warnings as errors because of problems of the
33  * G_LOCK* macros as declared by glib. See
34  * https://bugs.gnucash.org/show_bug.cgi?id=316221 for additional information.
35  */
36 #if (__GNUC__ >= 4 && __GNUC_MINOR__ >= 2)
37 # pragma GCC diagnostic warning "-Wstrict-aliasing"
38 #endif
39 
40 static GtkPrintSettings *print_settings = NULL;
41 static GtkPageSetup *page_setup = NULL;
42 G_LOCK_DEFINE_STATIC(print_settings);
43 G_LOCK_DEFINE_STATIC(page_setup);
44 
45 
46 void
48 {
49  g_return_if_fail(op);
50 
51  G_LOCK(print_settings);
52  if (print_settings)
53  g_object_unref(print_settings);
54  print_settings = g_object_ref(gtk_print_operation_get_print_settings(op));
55  G_UNLOCK(print_settings);
56 }
57 
58 void
59 gnc_print_operation_init(GtkPrintOperation *op, const gchar* jobname)
60 {
61  g_return_if_fail(op);
62 
63  /* Restore print settings */
64  G_LOCK(print_settings);
65  if (print_settings)
66  gtk_print_operation_set_print_settings(op, print_settings);
67  G_UNLOCK(print_settings);
68 
69  /* Restore page setup */
70  G_LOCK(page_setup);
71  if (page_setup)
72  gtk_print_operation_set_default_page_setup(op, page_setup);
73  G_UNLOCK(page_setup);
74 
75  gtk_print_operation_set_job_name ( op, jobname);
76 }
77 
78 void
79 gnc_ui_page_setup(GtkWindow *parent)
80 {
81  GtkPrintSettings *settings = NULL;
82  GtkPageSetup *old_page_setup, *new_page_setup;
83 
84  /* Get a reference to the current print settings */
85  G_LOCK(print_settings);
86  settings = print_settings;
87  if (settings)
88  g_object_ref(settings);
89  G_UNLOCK(print_settings);
90 
91  /* Get a reference to the current page setup */
92  G_LOCK(page_setup);
93  old_page_setup = page_setup;
94  if (old_page_setup)
95  g_object_ref(old_page_setup);
96  G_UNLOCK(page_setup);
97 
98  /* Run dialog */
99  new_page_setup = gtk_print_run_page_setup_dialog(parent, old_page_setup,
100  settings);
101 
102  /* Save new page setup */
103  G_LOCK(page_setup);
104  if (page_setup)
105  g_object_unref(page_setup);
106  page_setup = new_page_setup;
107  G_UNLOCK(page_setup);
108 
109  /* Release references */
110  if (settings)
111  g_object_unref(settings);
112  if (old_page_setup)
113  g_object_unref(old_page_setup);
114 }
115 
116 GtkPrintSettings *gnc_print_get_settings()
117 {
118  return print_settings;
119 }
void gnc_print_operation_save_print_settings(GtkPrintOperation *op)
Retrieve the print settings from the GtkPrintOperation op and save them in a static variable...
Definition: print-session.c:47
void gnc_ui_page_setup(GtkWindow *parent)
Run a page setup dialog and save the resulting GtkPageSetup in a static variable. ...
Definition: print-session.c:79
void gnc_print_operation_init(GtkPrintOperation *op, const gchar *jobname)
If print settings have been saved by gnc_print_operation_save_print_settings(), then set them on the ...
Definition: print-session.c:59
GtkPrintSettings * gnc_print_get_settings()
Returns the pointer to our static GtkPrintSettings object.