GnuCash fec5643+
Loading...
Searching...
No Matches
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
32static GtkPrintSettings *print_settings = NULL;
33static GtkPageSetup *page_setup = NULL;
34G_LOCK_DEFINE_STATIC(print_settings);
35G_LOCK_DEFINE_STATIC(page_setup);
36
37
38void
40{
41 g_return_if_fail(op);
42
43 G_LOCK(print_settings);
44 if (print_settings)
45 g_object_unref(print_settings);
46 print_settings = g_object_ref(gtk_print_operation_get_print_settings(op));
47 G_UNLOCK(print_settings);
48}
49
50void
51gnc_print_operation_init(GtkPrintOperation *op, const gchar* jobname)
52{
53 g_return_if_fail(op);
54
55 /* Restore print settings */
56 G_LOCK(print_settings);
57 if (print_settings)
58 {
59 // Clear page range to prevent carryover from previous print jobs
60 gtk_print_settings_set(print_settings, GTK_PRINT_SETTINGS_PAGE_RANGES, NULL);
61 gtk_print_settings_set(print_settings, GTK_PRINT_SETTINGS_PAGE_SET, NULL);
62 gtk_print_operation_set_print_settings(op, print_settings);
63 }
64 G_UNLOCK(print_settings);
65
66 /* Restore page setup */
67 G_LOCK(page_setup);
68 if (page_setup)
69 gtk_print_operation_set_default_page_setup(op, page_setup);
70 G_UNLOCK(page_setup);
71
72 gtk_print_operation_set_job_name ( op, jobname);
73}
74
75void
76gnc_ui_page_setup(GtkWindow *parent)
77{
78 GtkPrintSettings *settings = NULL;
79 GtkPageSetup *old_page_setup, *new_page_setup;
80
81 /* Get a reference to the current print settings */
82 G_LOCK(print_settings);
83 settings = print_settings;
84 if (settings)
85 g_object_ref(settings);
86 G_UNLOCK(print_settings);
87
88 /* Get a reference to the current page setup */
89 G_LOCK(page_setup);
90 old_page_setup = page_setup;
91 if (old_page_setup)
92 g_object_ref(old_page_setup);
93 G_UNLOCK(page_setup);
94
95 /* Run dialog */
96 new_page_setup = gtk_print_run_page_setup_dialog(parent, old_page_setup,
97 settings);
98
99 /* Save new page setup */
100 G_LOCK(page_setup);
101 if (page_setup)
102 g_object_unref(page_setup);
103 page_setup = new_page_setup;
104 G_UNLOCK(page_setup);
105
106 /* Release references */
107 if (settings)
108 g_object_unref(settings);
109 if (old_page_setup)
110 g_object_unref(old_page_setup);
111}
112
113GtkPrintSettings *gnc_print_get_settings()
114{
115 return print_settings;
116}
void gnc_ui_page_setup(GtkWindow *parent)
Run a page setup dialog and save the resulting GtkPageSetup in a static variable.
GtkPrintSettings * gnc_print_get_settings()
Returns the pointer to our static GtkPrintSettings object.
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 ...
void gnc_print_operation_save_print_settings(GtkPrintOperation *op)
Retrieve the print settings from the GtkPrintOperation op and save them in a static variable.
Functions for printing.