2 * (GLABELS) Label and Business Card Creation program for GNOME
4 * print.c: Print module
6 * Copyright (C) 2001 Jim Evins <evins@snaught.com>.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <libgnomeprint/gnome-print-paper.h>
29 #include <libgnomeprintui/gnome-printer-dialog.h>
30 #include <libgnomeprintui/gnome-print-dialog.h>
31 #include <libgnomeprint/gnome-print-master.h>
32 #include <libgnomeprintui/gnome-print-master-preview.h>
34 #include "print-dialog.h"
42 #include "wdgt-print-copies.h"
43 #include "wdgt-print-merge.h"
47 #define RED(x) ( (((x)>>24) & 0xff) / 255.0 )
48 #define GREEN(x) ( (((x)>>16) & 0xff) / 255.0 )
49 #define BLUE(x) ( (((x)>>8) & 0xff) / 255.0 )
50 #define ALPHA(x) ( ( (x) & 0xff) / 255.0 )
52 /*===========================================*/
54 /*===========================================*/
56 /*===========================================*/
57 /* Private globals. */
58 /*===========================================*/
60 /* remember state of dialog. */
61 static gboolean outline_flag = FALSE;
62 static gboolean reverse_flag = FALSE;
63 static gboolean collate_flag = FALSE;
64 static gint first = 1, last = 1, n_sheets = 0, n_copies = 1;
66 /*===========================================*/
67 /* Private function prototypes. */
68 /*===========================================*/
69 static GtkWidget *job_page_new (GtkWidget *dlg, glLabel *label);
70 static GtkWidget *printer_page_new (GtkWidget *dlg, glLabel *label);
72 static void print_response (GtkDialog *dlg,
76 static void print_sheets (GnomePrintConfig *config, glLabel * label,
77 gboolean preview_flag,
78 gint n_sheets, gint first, gint last,
79 gboolean outline_flag, gboolean reverse_flag);
81 static void print_sheets_merge (GnomePrintConfig *config, glLabel * label,
83 gboolean preview_flag,
84 gint n_copies, gint first,
85 gboolean collate_flag,
86 gboolean outline_flag, gboolean reverse_flag);
89 /*****************************************************************************/
91 /*****************************************************************************/
93 gl_print_dialog (glLabel *label, BonoboWindow *win)
96 GtkWidget *pp_button, *notebook, *page;
98 g_return_if_fail (label != NULL);
99 g_return_if_fail (win != NULL);
101 /* ----- Contstruct basic print dialog with notebook ----- */
102 dlg = gtk_dialog_new_with_buttons (_("Print"), GTK_WINDOW(win),
103 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
104 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
105 GTK_STOCK_PRINT, GNOME_PRINT_DIALOG_RESPONSE_PRINT,
108 pp_button = gtk_dialog_add_button (GTK_DIALOG (dlg),
109 GTK_STOCK_PRINT_PREVIEW,
110 GNOME_PRINT_DIALOG_RESPONSE_PREVIEW);
111 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (GTK_DIALOG (dlg)->action_area),
113 gtk_dialog_set_default_response (GTK_DIALOG (dlg),
114 GNOME_PRINT_DIALOG_RESPONSE_PRINT);
115 notebook = gtk_notebook_new ();
116 gtk_container_set_border_width (GTK_CONTAINER (notebook), 4);
117 gtk_widget_show (notebook);
118 gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dlg)->vbox), notebook);
121 /* ----- Create Job notebook page ----- */
122 page = job_page_new (dlg, label);
123 gtk_notebook_append_page (GTK_NOTEBOOK(notebook), page,
124 gtk_label_new_with_mnemonic (_("_Job")));
126 /* ----- Create Printer notebook page ----- */
127 page = printer_page_new (dlg, label);
128 gtk_notebook_append_page (GTK_NOTEBOOK(notebook), page,
129 gtk_label_new_with_mnemonic (_("P_rinter")));
131 g_signal_connect (G_OBJECT(dlg), "response",
132 G_CALLBACK (print_response), label);
134 gtk_widget_show_all (GTK_WIDGET (dlg));
137 /*---------------------------------------------------------------------------*/
138 /* PRIVATE. Create "Job" page. */
139 /*---------------------------------------------------------------------------*/
141 job_page_new (GtkWidget *dlg,
147 GtkWidget *copies = NULL, *prmerge = NULL;
148 GtkWidget *wvbox, *outline_check, *reverse_check;
152 vbox = gtk_vbox_new (FALSE, 0);
154 merge = gl_label_get_merge (label);
155 if (merge->type == GL_MERGE_NONE) {
157 /* ----------- Add simple-copies widget ------------ */
158 wframe = gtk_frame_new (_("Copies"));
159 gtk_box_pack_start (GTK_BOX (vbox), wframe, FALSE, FALSE, 0);
161 copies = gl_wdgt_print_copies_new (label);
162 gtk_container_set_border_width (GTK_CONTAINER (copies),
164 gtk_container_add (GTK_CONTAINER (wframe), copies);
167 gl_wdgt_print_copies_set_range (GL_WDGT_PRINT_COPIES (copies),
168 n_sheets, first, last);
173 /* ------- Otherwise add merge control widget ------------ */
174 wframe = gtk_frame_new (_("Document merge control"));
175 gtk_box_pack_start (GTK_BOX (vbox), wframe, FALSE, FALSE, 0);
177 prmerge = gl_wdgt_print_merge_new (label);
178 gtk_container_set_border_width (GTK_CONTAINER (prmerge),
180 gtk_container_add (GTK_CONTAINER (wframe), prmerge);
182 record_list = gl_merge_read_data (merge->type,
185 n_records = gl_merge_count_records( record_list );
186 gl_wdgt_print_merge_set_copies (GL_WDGT_PRINT_MERGE(prmerge),
187 n_copies, first, n_records,
190 gtk_widget_show_all (wframe);
191 g_object_set_data (G_OBJECT(dlg), "copies", copies);
192 g_object_set_data (G_OBJECT(dlg), "prmerge", prmerge);
194 /* ----------- Add custom print options area ------------ */
195 wframe = gtk_frame_new (_("Options"));
196 gtk_box_pack_start (GTK_BOX (vbox), wframe, FALSE, FALSE, 0);
197 wvbox = gtk_vbox_new (FALSE, GNOME_PAD);
198 gtk_container_set_border_width (GTK_CONTAINER (wvbox),
200 gtk_container_add (GTK_CONTAINER (wframe), wvbox);
202 /* add Outline check button */
204 gtk_check_button_new_with_label (
205 _("print outlines (to test printer alignment)"));
206 gtk_box_pack_start (GTK_BOX (wvbox), outline_check, FALSE, FALSE, 0);
207 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (outline_check),
209 g_object_set_data (G_OBJECT(dlg), "outline_check", outline_check);
211 /* add Reverse check button */
213 gtk_check_button_new_with_label (
214 _("print in reverse (i.e. a mirror image)"));
215 gtk_box_pack_start (GTK_BOX (wvbox), reverse_check, FALSE, FALSE, 0);
216 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (reverse_check),
218 g_object_set_data (G_OBJECT(dlg), "reverse_check", reverse_check);
220 gtk_widget_show_all (wframe);
225 /*---------------------------------------------------------------------------*/
226 /* PRIVATE. Create "Printer" page. */
227 /*---------------------------------------------------------------------------*/
229 printer_page_new (GtkWidget *dlg,
233 GtkWidget *printer_select;
235 vbox = gtk_vbox_new (FALSE, 0);
238 gnome_printer_selection_new (gnome_print_config_default ());
239 gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
240 gtk_widget_show (printer_select);
241 gtk_box_pack_start (GTK_BOX(vbox), printer_select, FALSE, FALSE, 0);
243 g_object_set_data (G_OBJECT(dlg), "printer_select", printer_select);
248 /*---------------------------------------------------------------------------*/
249 /* PRIVATE. Print "response" callback. */
250 /*---------------------------------------------------------------------------*/
252 print_response (GtkDialog *dlg,
256 GtkWidget *copies, *prmerge;
257 GtkWidget *outline_check, *reverse_check;
258 GtkWidget *printer_select;
259 GnomePrintConfig *config;
265 case GNOME_PRINT_DIALOG_RESPONSE_PRINT:
266 case GNOME_PRINT_DIALOG_RESPONSE_PREVIEW:
267 copies = g_object_get_data (G_OBJECT(dlg), "copies");
268 prmerge = g_object_get_data (G_OBJECT(dlg), "prmerge");
269 outline_check = g_object_get_data (G_OBJECT(dlg),
271 reverse_check = g_object_get_data (G_OBJECT(dlg),
273 printer_select = g_object_get_data (G_OBJECT(dlg),
276 config = gnome_printer_selection_get_config (GNOME_PRINTER_SELECTION(printer_select));
279 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
282 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
285 merge = gl_label_get_merge (label);
287 if (merge->type == GL_MERGE_NONE) {
289 gl_wdgt_print_copies_get_range (GL_WDGT_PRINT_COPIES (copies),
290 &n_sheets, &first, &last);
291 print_sheets (config, label,
292 (response == GNOME_PRINT_DIALOG_RESPONSE_PREVIEW),
293 n_sheets, first, last,
294 outline_flag, reverse_flag);
298 record_list = gl_merge_read_data (merge->type,
301 gl_wdgt_print_merge_get_copies (GL_WDGT_PRINT_MERGE (prmerge),
304 print_sheets_merge (config, label, record_list,
305 (response == GNOME_PRINT_DIALOG_RESPONSE_PREVIEW),
312 gl_merge_free (&merge);
320 gtk_widget_destroy (GTK_WIDGET (dlg));
323 /*---------------------------------------------------------------------------*/
324 /* PRIVATE. print the sheets */
325 /*---------------------------------------------------------------------------*/
327 print_sheets (GnomePrintConfig *config,
329 gboolean preview_flag,
333 gboolean outline_flag,
334 gboolean reverse_flag)
336 GnomePrintMaster *master;
338 master = gnome_print_master_new_from_config (config);
339 gl_print_simple (master, label, n_sheets, first, last,
340 outline_flag, reverse_flag);
341 gnome_print_master_close (master);
344 GtkWidget *preview_widget =
345 gnome_print_master_preview_new (master, _("Print preview"));
346 gtk_widget_show (GTK_WIDGET (preview_widget));
348 gnome_print_master_print (master);
351 g_object_unref (G_OBJECT (master));
354 /*---------------------------------------------------------------------------*/
355 /* PRIVATE. print the sheets with merge data */
356 /*---------------------------------------------------------------------------*/
358 print_sheets_merge (GnomePrintConfig *config,
361 gboolean preview_flag,
364 gboolean collate_flag,
365 gboolean outline_flag,
366 gboolean reverse_flag)
368 GnomePrintMaster *master;
370 master = gnome_print_master_new_from_config (config);
371 if ( collate_flag ) {
372 gl_print_merge_collated (master, label, record_list,
374 outline_flag, reverse_flag);
376 gl_print_merge_uncollated (master, label, record_list,
378 outline_flag, reverse_flag);
380 gnome_print_master_close (master);
383 GtkWidget *preview_widget =
384 gnome_print_master_preview_new (master, _("Print preview"));
385 gtk_widget_show (GTK_WIDGET (preview_widget));
387 gnome_print_master_print (master);
390 g_object_unref (G_OBJECT (master));