1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
---|
2 | /* |
---|
3 | * gnome-print-dialog.c: A system print dialog |
---|
4 | * |
---|
5 | * This program is free software; you can redistribute it and/or |
---|
6 | * modify it under the terms of the GNU Library General Public License |
---|
7 | * as 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 Library General Public License for more details. |
---|
14 | * |
---|
15 | * You should have received a copy of the GNU Library General Public |
---|
16 | * License along with this program; if not, write to the Free Software |
---|
17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
18 | * |
---|
19 | * Authors: |
---|
20 | * Michael Zucchi <notzed@helixcode.com> |
---|
21 | * Chema Celorio <chema@celorio.com> |
---|
22 | * Lauris Kaplinski <lauris@ximian.com> |
---|
23 | * Andreas J. Guelzow <aguelzow@taliesin.ca> |
---|
24 | * |
---|
25 | * Copyright (C) 2000-2002 Ximian Inc. |
---|
26 | * Copyright (C) 2004 Andreas J. Guelzow |
---|
27 | * |
---|
28 | */ |
---|
29 | |
---|
30 | #define GNOME_PRINT_UNSTABLE_API |
---|
31 | |
---|
32 | #include <config.h> |
---|
33 | |
---|
34 | #include <time.h> |
---|
35 | #include <atk/atk.h> |
---|
36 | #include <gdk/gdkkeysyms.h> |
---|
37 | #include <gtk/gtk.h> |
---|
38 | |
---|
39 | #include <libgnomeprint/gnome-print-config.h> |
---|
40 | |
---|
41 | #include "gnome-print-i18n.h" |
---|
42 | #include "gnome-printer-selector.h" |
---|
43 | #include "gnome-print-paper-selector.h" |
---|
44 | #include "gnome-print-copies.h" |
---|
45 | #include "gnome-print-dialog.h" |
---|
46 | #include "gnome-print-dialog-private.h" |
---|
47 | |
---|
48 | #define PAD 6 |
---|
49 | |
---|
50 | enum { |
---|
51 | PROP_0, |
---|
52 | PROP_PRINT_CONFIG |
---|
53 | }; |
---|
54 | |
---|
55 | static void gnome_print_dialog_class_init (GnomePrintDialogClass *class); |
---|
56 | static void gnome_print_dialog_init (GnomePrintDialog *dialog); |
---|
57 | |
---|
58 | static GtkWidget *gpd_create_job_page (GnomePrintDialog *gpd); |
---|
59 | |
---|
60 | static GtkDialogClass *parent_class; |
---|
61 | |
---|
62 | GType |
---|
63 | gnome_print_dialog_get_type (void) |
---|
64 | { static GType type = 0; |
---|
65 | if (!type) { |
---|
66 | static const GTypeInfo info = { |
---|
67 | sizeof (GnomePrintDialogClass), |
---|
68 | NULL, NULL, |
---|
69 | (GClassInitFunc) gnome_print_dialog_class_init, |
---|
70 | NULL, NULL, |
---|
71 | sizeof (GnomePrintDialog), |
---|
72 | 0, |
---|
73 | (GInstanceInitFunc) gnome_print_dialog_init, |
---|
74 | NULL, |
---|
75 | }; |
---|
76 | type = g_type_register_static (GTK_TYPE_DIALOG, "GnomePrintDialog", &info, 0); |
---|
77 | } |
---|
78 | return type; |
---|
79 | } |
---|
80 | |
---|
81 | static void |
---|
82 | gnome_print_dialog_destroy (GtkObject *object) |
---|
83 | { |
---|
84 | GnomePrintDialog *gpd; |
---|
85 | |
---|
86 | gpd = GNOME_PRINT_DIALOG (object); |
---|
87 | |
---|
88 | if (gpd->config) { |
---|
89 | gpd->config = gnome_print_config_unref (gpd->config); |
---|
90 | } |
---|
91 | |
---|
92 | if (GTK_OBJECT_CLASS (parent_class)->destroy) |
---|
93 | (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); |
---|
94 | } |
---|
95 | |
---|
96 | static void |
---|
97 | gnome_print_dialog_set_property (GObject *object, |
---|
98 | guint prop_id, |
---|
99 | GValue const *value, |
---|
100 | GParamSpec *pspec) |
---|
101 | { |
---|
102 | gpointer new_config; |
---|
103 | GnomePrintDialog *gpd = GNOME_PRINT_DIALOG (object); |
---|
104 | |
---|
105 | switch (prop_id) { |
---|
106 | case PROP_PRINT_CONFIG: |
---|
107 | new_config = g_value_get_pointer (value); |
---|
108 | if (new_config) { |
---|
109 | if (gpd->config) |
---|
110 | gnome_print_config_unref (gpd->config); |
---|
111 | gpd->config = g_value_get_pointer (value); |
---|
112 | gnome_print_config_ref (gpd->config); |
---|
113 | } |
---|
114 | break; |
---|
115 | default: |
---|
116 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | static void |
---|
121 | gnome_print_dialog_class_init (GnomePrintDialogClass *class) |
---|
122 | { |
---|
123 | GtkObjectClass *object_class; |
---|
124 | |
---|
125 | object_class = (GtkObjectClass *) class; |
---|
126 | |
---|
127 | parent_class = gtk_type_class (GTK_TYPE_DIALOG); |
---|
128 | |
---|
129 | object_class->destroy = gnome_print_dialog_destroy; |
---|
130 | |
---|
131 | G_OBJECT_CLASS (class)->set_property = gnome_print_dialog_set_property; |
---|
132 | g_object_class_install_property (G_OBJECT_CLASS (class), |
---|
133 | PROP_PRINT_CONFIG, |
---|
134 | g_param_spec_pointer ("print_config", |
---|
135 | "Print Config", |
---|
136 | "Printing Configuration to be used", |
---|
137 | G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE)); |
---|
138 | } |
---|
139 | |
---|
140 | static void |
---|
141 | gnome_print_dialog_init (GnomePrintDialog *gpd) |
---|
142 | { |
---|
143 | /* Empty */ |
---|
144 | } |
---|
145 | |
---|
146 | static void |
---|
147 | gnome_print_dialog_response_cb (GtkDialog *dialog, |
---|
148 | gint response_id, |
---|
149 | GnomePrintDialog *gpd) |
---|
150 | { |
---|
151 | if (response_id != GNOME_PRINT_DIALOG_RESPONSE_PRINT) |
---|
152 | return; |
---|
153 | |
---|
154 | if (!gnome_printer_selector_check_consistency |
---|
155 | (GNOME_PRINTER_SELECTOR (gpd->printer))) |
---|
156 | g_signal_stop_emission_by_name (dialog, "response"); |
---|
157 | } |
---|
158 | |
---|
159 | |
---|
160 | |
---|
161 | static void |
---|
162 | gpd_copies_set (GnomePrintCopiesSelector *gpc, |
---|
163 | gint copies, |
---|
164 | GnomePrintDialog *gpd) |
---|
165 | { |
---|
166 | if (gpd->config) |
---|
167 | gnome_print_config_set_int (gpd->config, |
---|
168 | GNOME_PRINT_KEY_NUM_COPIES, |
---|
169 | copies); |
---|
170 | } |
---|
171 | |
---|
172 | static void |
---|
173 | gpd_collate_set (GnomePrintCopiesSelector *gpc, |
---|
174 | gboolean collate, |
---|
175 | GnomePrintDialog *gpd) |
---|
176 | { |
---|
177 | if (gpd->config) |
---|
178 | gnome_print_config_set_boolean (gpd->config, |
---|
179 | GNOME_PRINT_KEY_COLLATE, |
---|
180 | collate); |
---|
181 | } |
---|
182 | |
---|
183 | static GtkWidget * |
---|
184 | gpd_create_job_page (GnomePrintDialog *gpd) |
---|
185 | { |
---|
186 | GtkWidget *hb, *vb, *f, *c, *l; |
---|
187 | gchar *text; |
---|
188 | |
---|
189 | hb = gtk_hbox_new (FALSE, 0); |
---|
190 | |
---|
191 | vb = gtk_vbox_new (FALSE, PAD); |
---|
192 | gtk_widget_show (vb); |
---|
193 | |
---|
194 | gtk_box_pack_start (GTK_BOX (hb), vb, FALSE, FALSE, 0); |
---|
195 | |
---|
196 | f = gtk_frame_new (""); |
---|
197 | gtk_frame_set_shadow_type (GTK_FRAME (f), GTK_SHADOW_NONE); |
---|
198 | l = gtk_label_new (""); |
---|
199 | text = g_strdup_printf ("<b>%s</b>", _("Print Range")); |
---|
200 | gtk_label_set_markup (GTK_LABEL (l), text); |
---|
201 | g_free (text); |
---|
202 | gtk_frame_set_label_widget (GTK_FRAME (f), l); |
---|
203 | gtk_widget_show (l); |
---|
204 | gtk_widget_hide (f); |
---|
205 | gtk_box_pack_start (GTK_BOX (vb), f, FALSE, FALSE, 0); |
---|
206 | g_object_set_data (G_OBJECT (hb), "range", f); |
---|
207 | |
---|
208 | c = gnome_print_copies_selector_new (); |
---|
209 | if (gpd) { |
---|
210 | g_signal_connect (G_OBJECT (c), "copies_set", |
---|
211 | (GCallback) gpd_copies_set, gpd); |
---|
212 | g_signal_connect (G_OBJECT (c), "collate_set", |
---|
213 | (GCallback) gpd_collate_set, gpd); |
---|
214 | } |
---|
215 | gtk_widget_hide (c); |
---|
216 | gtk_box_pack_start (GTK_BOX (vb), c, FALSE, FALSE, 0); |
---|
217 | g_object_set_data (G_OBJECT (hb), "copies", c); |
---|
218 | |
---|
219 | return hb; |
---|
220 | } |
---|
221 | |
---|
222 | static GtkWidget * |
---|
223 | gpd_create_range (gint flags, GtkWidget *range, const guchar *clabel, const guchar *rlabel) |
---|
224 | { |
---|
225 | GtkWidget *t, *rb; |
---|
226 | GSList *group; |
---|
227 | gint row; |
---|
228 | |
---|
229 | t = gtk_table_new (4, 2, FALSE); |
---|
230 | gtk_container_set_border_width (GTK_CONTAINER (t), 6); |
---|
231 | |
---|
232 | group = NULL; |
---|
233 | row = 0; |
---|
234 | |
---|
235 | if (flags & GNOME_PRINT_RANGE_CURRENT) { |
---|
236 | rb = gtk_radio_button_new_with_mnemonic (group, clabel); |
---|
237 | g_object_set_data (G_OBJECT (t), "current", rb); |
---|
238 | gtk_widget_show (rb); |
---|
239 | gtk_table_attach (GTK_TABLE (t), rb, 0, 1, row, row + 1, GTK_FILL | GTK_EXPAND, |
---|
240 | GTK_FILL, 0, 0); |
---|
241 | group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (rb)); |
---|
242 | row += 1; |
---|
243 | } |
---|
244 | |
---|
245 | if (flags & GNOME_PRINT_RANGE_ALL) { |
---|
246 | rb = gtk_radio_button_new_with_mnemonic(group, _("_All")); |
---|
247 | g_object_set_data (G_OBJECT (t), "all", rb); |
---|
248 | gtk_widget_show (rb); |
---|
249 | gtk_table_attach (GTK_TABLE (t), rb, 0, 1, row, row + 1, GTK_FILL | GTK_EXPAND, |
---|
250 | GTK_FILL, 0, 0); |
---|
251 | group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (rb)); |
---|
252 | row += 1; |
---|
253 | } |
---|
254 | |
---|
255 | if (flags & GNOME_PRINT_RANGE_RANGE) { |
---|
256 | rb = gtk_radio_button_new_with_mnemonic (group, rlabel); |
---|
257 | g_object_set_data (G_OBJECT (t), "range", rb); |
---|
258 | gtk_widget_show (rb); |
---|
259 | gtk_table_attach (GTK_TABLE (t), rb, 0, 1, row, row + 1, GTK_FILL | GTK_EXPAND, |
---|
260 | GTK_FILL, 0, 0); |
---|
261 | g_object_set_data (G_OBJECT (t), "range-widget", range); |
---|
262 | gtk_table_attach (GTK_TABLE (t), range, 1, 2, row, row + 1, GTK_FILL, 0, 0, 0); |
---|
263 | group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (rb)); |
---|
264 | row += 1; |
---|
265 | } |
---|
266 | |
---|
267 | if ((flags & GNOME_PRINT_RANGE_SELECTION) || (flags & GNOME_PRINT_RANGE_SELECTION_UNSENSITIVE)) { |
---|
268 | rb = gtk_radio_button_new_with_mnemonic (group, _("_Selection")); |
---|
269 | g_object_set_data (G_OBJECT (t), "selection", rb); |
---|
270 | gtk_widget_show (rb); |
---|
271 | gtk_widget_set_sensitive (rb, !(flags & GNOME_PRINT_RANGE_SELECTION_UNSENSITIVE)); |
---|
272 | gtk_table_attach (GTK_TABLE (t), rb, 0, 1, row, row + 1, GTK_FILL | GTK_EXPAND, |
---|
273 | GTK_FILL, 0, 0); |
---|
274 | group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (rb)); |
---|
275 | row += 1; |
---|
276 | } |
---|
277 | |
---|
278 | return t; |
---|
279 | } |
---|
280 | |
---|
281 | /** |
---|
282 | * gnome_print_dialog_new: |
---|
283 | * @gpj: GnomePrintJob |
---|
284 | * @title: Title of window. |
---|
285 | * @flags: Options for created widget. |
---|
286 | * |
---|
287 | * Create a new gnome-print-dialog window. |
---|
288 | * |
---|
289 | * The following options flags are available: |
---|
290 | * GNOME_PRINT_DIALOG_RANGE: A range widget container will be created. |
---|
291 | * A range widget must be created separately, using one of the |
---|
292 | * gnome_print_dialog_construct_* functions. |
---|
293 | * GNOME_PRINT_DIALOG_COPIES: A copies widget will be created. |
---|
294 | * |
---|
295 | * Return value: A newly created and initialised widget. |
---|
296 | **/ |
---|
297 | GtkWidget * |
---|
298 | gnome_print_dialog_new (GnomePrintJob *gpj, const guchar *title, gint flags) |
---|
299 | { |
---|
300 | GnomePrintConfig *gpc = NULL; |
---|
301 | GnomePrintDialog *gpd; |
---|
302 | |
---|
303 | gpd = GNOME_PRINT_DIALOG (g_object_new (GNOME_TYPE_PRINT_DIALOG, NULL)); |
---|
304 | |
---|
305 | if (gpd) { |
---|
306 | if (gpj) |
---|
307 | gpc = gnome_print_job_get_config (gpj); |
---|
308 | if (gpc == NULL) |
---|
309 | gpc = gnome_print_config_default (); |
---|
310 | gpd->config = gpc; |
---|
311 | gnome_print_dialog_construct (gpd, title, flags); |
---|
312 | } |
---|
313 | |
---|
314 | return GTK_WIDGET (gpd); |
---|
315 | } |
---|
316 | |
---|
317 | /** |
---|
318 | * gnome_print_dialog_construct: |
---|
319 | * @gpd: A created GnomePrintDialog. |
---|
320 | * @title: Title of the window. |
---|
321 | * @flags: Initialisation options, see gnome_print_dialog_new(). |
---|
322 | * |
---|
323 | * Used for language bindings to post-initialise an object instantiation. |
---|
324 | * |
---|
325 | */ |
---|
326 | void |
---|
327 | gnome_print_dialog_construct (GnomePrintDialog *gpd, const guchar *title, gint flags) |
---|
328 | { |
---|
329 | GtkWidget *pp_button; |
---|
330 | |
---|
331 | g_return_if_fail (gpd != NULL); |
---|
332 | g_return_if_fail (GNOME_IS_PRINT_DIALOG (gpd)); |
---|
333 | |
---|
334 | if (gpd->config) { |
---|
335 | GtkWidget *hb, *p, *l; |
---|
336 | gpd->notebook = gtk_notebook_new (); |
---|
337 | gtk_container_set_border_width (GTK_CONTAINER (gpd->notebook), 4); |
---|
338 | gtk_widget_show (gpd->notebook); |
---|
339 | |
---|
340 | gtk_container_add (GTK_CONTAINER (GTK_DIALOG (gpd)->vbox), gpd->notebook); |
---|
341 | |
---|
342 | /* Add the job page, if it has any content */ |
---|
343 | gpd->job = gpd_create_job_page (gpd); |
---|
344 | gtk_container_set_border_width (GTK_CONTAINER (gpd->job), 4); |
---|
345 | l = gtk_label_new_with_mnemonic (_("Job")); |
---|
346 | gtk_widget_show (l); |
---|
347 | gtk_notebook_append_page (GTK_NOTEBOOK (gpd->notebook), gpd->job, l); |
---|
348 | |
---|
349 | { |
---|
350 | int copies; |
---|
351 | gboolean collate; |
---|
352 | |
---|
353 | if (!gnome_print_config_get_int (gpd->config, |
---|
354 | GNOME_PRINT_KEY_NUM_COPIES, &copies)) |
---|
355 | copies = 1; |
---|
356 | if (!gnome_print_config_get_boolean (gpd->config, |
---|
357 | GNOME_PRINT_KEY_COLLATE, &collate)) |
---|
358 | collate = FALSE; |
---|
359 | gnome_print_dialog_set_copies (gpd, copies, collate); |
---|
360 | } |
---|
361 | |
---|
362 | /* Add the printers page */ |
---|
363 | hb = gtk_hbox_new (FALSE, 0); |
---|
364 | gtk_widget_show (hb); |
---|
365 | |
---|
366 | gpd->printer = gnome_printer_selector_new (gpd->config); |
---|
367 | gtk_container_set_border_width (GTK_CONTAINER (hb), 4); |
---|
368 | gtk_widget_show (gpd->printer); |
---|
369 | |
---|
370 | gtk_box_pack_start (GTK_BOX (hb), gpd->printer, TRUE, TRUE, 0); |
---|
371 | |
---|
372 | l = gtk_label_new_with_mnemonic (_("Printer")); |
---|
373 | gtk_widget_show (l); |
---|
374 | |
---|
375 | gtk_notebook_append_page (GTK_NOTEBOOK (gpd->notebook), hb, l); |
---|
376 | |
---|
377 | /* Add a paper page */ |
---|
378 | p = gnome_paper_selector_new (gpd->config); |
---|
379 | gtk_container_set_border_width (GTK_CONTAINER (p), 4); |
---|
380 | gtk_widget_show (p); |
---|
381 | |
---|
382 | l = gtk_label_new_with_mnemonic (_("Paper")); |
---|
383 | gtk_widget_show (l); |
---|
384 | |
---|
385 | gtk_notebook_append_page (GTK_NOTEBOOK (gpd->notebook), p, l); |
---|
386 | } |
---|
387 | else { |
---|
388 | GtkWidget *label; |
---|
389 | label = gtk_label_new (_("Error while loading printer configuration")); |
---|
390 | gtk_widget_show (label); |
---|
391 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (gpd)->vbox), label, TRUE, TRUE, 0); |
---|
392 | } |
---|
393 | |
---|
394 | gtk_window_set_title (GTK_WINDOW (gpd), |
---|
395 | (title) ? title : |
---|
396 | (const guchar *) _("Gnome Print Dialog")); |
---|
397 | |
---|
398 | gtk_dialog_set_has_separator (GTK_DIALOG (gpd), FALSE); |
---|
399 | |
---|
400 | gtk_dialog_add_buttons (GTK_DIALOG (gpd), |
---|
401 | GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
---|
402 | GTK_STOCK_PRINT, GNOME_PRINT_DIALOG_RESPONSE_PRINT, |
---|
403 | NULL); |
---|
404 | |
---|
405 | pp_button = gtk_dialog_add_button (GTK_DIALOG (gpd), |
---|
406 | GTK_STOCK_PRINT_PREVIEW, |
---|
407 | GNOME_PRINT_DIALOG_RESPONSE_PREVIEW); |
---|
408 | |
---|
409 | gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (GTK_DIALOG (gpd)->action_area), |
---|
410 | pp_button, |
---|
411 | TRUE); |
---|
412 | |
---|
413 | gtk_dialog_set_default_response (GTK_DIALOG (gpd), |
---|
414 | GNOME_PRINT_DIALOG_RESPONSE_PRINT); |
---|
415 | |
---|
416 | g_signal_connect (gpd, "response", |
---|
417 | G_CALLBACK (gnome_print_dialog_response_cb), |
---|
418 | (gpointer) gpd); |
---|
419 | |
---|
420 | |
---|
421 | /* Construct job options, if needed */ |
---|
422 | if (flags & GNOME_PRINT_DIALOG_RANGE) { |
---|
423 | GtkWidget *r; |
---|
424 | r = g_object_get_data (G_OBJECT (gpd->job), "range"); |
---|
425 | if (r) { |
---|
426 | gtk_widget_show (r); |
---|
427 | gtk_widget_show (gpd->job); |
---|
428 | } |
---|
429 | } |
---|
430 | |
---|
431 | if (flags & GNOME_PRINT_DIALOG_COPIES) { |
---|
432 | GtkWidget *c; |
---|
433 | c = g_object_get_data (G_OBJECT (gpd->job), "copies"); |
---|
434 | if (c) { |
---|
435 | gtk_widget_show (c); |
---|
436 | gtk_widget_show (gpd->job); |
---|
437 | } |
---|
438 | } |
---|
439 | } |
---|
440 | |
---|
441 | /** |
---|
442 | * gnome_print_dialog_construct_range_custom: |
---|
443 | * @gpd: A GnomePrintDialog for which a range was requested. |
---|
444 | * @custom: A widget which will be placed in a "Range" frame in the |
---|
445 | * main display. |
---|
446 | * |
---|
447 | * Install a custom range specification widget. |
---|
448 | **/ |
---|
449 | void |
---|
450 | gnome_print_dialog_construct_range_custom (GnomePrintDialog *gpd, GtkWidget *custom) |
---|
451 | { |
---|
452 | GtkWidget *f, *r; |
---|
453 | |
---|
454 | g_return_if_fail (gpd != NULL); |
---|
455 | g_return_if_fail (GNOME_IS_PRINT_DIALOG (gpd)); |
---|
456 | g_return_if_fail (custom != NULL); |
---|
457 | g_return_if_fail (GTK_IS_WIDGET (custom)); |
---|
458 | |
---|
459 | f = g_object_get_data (G_OBJECT (gpd->job), "range"); |
---|
460 | g_return_if_fail (f != NULL); |
---|
461 | r = g_object_get_data (G_OBJECT (f), "range"); |
---|
462 | if (r) |
---|
463 | gtk_container_remove (GTK_CONTAINER (f), r); |
---|
464 | |
---|
465 | gtk_widget_show (custom); |
---|
466 | gtk_widget_show (gpd->job); |
---|
467 | gtk_container_add (GTK_CONTAINER (f), custom); |
---|
468 | g_object_set_data (G_OBJECT (f), "range", custom); |
---|
469 | } |
---|
470 | |
---|
471 | /** |
---|
472 | * gnome_print_dialog_construct_range_any: |
---|
473 | * @gpd: An initialise GnomePrintDialog, which can contain a range. |
---|
474 | * @flags: Options flags, which ranges are displayed. |
---|
475 | * @range_widget: Widget to display for the range option. |
---|
476 | * @currentlabel: Label to display next to the 'current page' button. |
---|
477 | * @rangelabel: Label to display next to the 'range' button. |
---|
478 | * |
---|
479 | * Create a generic range area within the print range dialogue. The flags |
---|
480 | * field contains a mask of which options you wish displayed: |
---|
481 | * |
---|
482 | * GNOME_PRINT_RANGE_CURRENT: A label @currentlabel will be displayed. |
---|
483 | * GNOME_PRINT_RANGE_ALL: A label "All" will be displayed. |
---|
484 | * GNOME_PRINT_RANGE_RANGE: A label @rangelabel will be displayed, next |
---|
485 | * to the range specification widget @range_widget. |
---|
486 | * GNOME_PRINT_RANGE_SELECTION: A label "Selection" will be displayed. |
---|
487 | * |
---|
488 | **/ |
---|
489 | void |
---|
490 | gnome_print_dialog_construct_range_any (GnomePrintDialog *gpd, gint flags, GtkWidget *range_widget, |
---|
491 | const guchar *currentlabel, const guchar *rangelabel) |
---|
492 | { |
---|
493 | GtkWidget *f, *r; |
---|
494 | |
---|
495 | g_return_if_fail (gpd != NULL); |
---|
496 | g_return_if_fail (GNOME_IS_PRINT_DIALOG (gpd)); |
---|
497 | g_return_if_fail (!range_widget || GTK_IS_WIDGET (range_widget)); |
---|
498 | g_return_if_fail (!(range_widget && !(flags & GNOME_PRINT_RANGE_RANGE))); |
---|
499 | g_return_if_fail (!(!range_widget && (flags & GNOME_PRINT_RANGE_RANGE))); |
---|
500 | g_return_if_fail (!((flags & GNOME_PRINT_RANGE_SELECTION) && (flags & GNOME_PRINT_RANGE_SELECTION_UNSENSITIVE))); |
---|
501 | |
---|
502 | f = g_object_get_data (G_OBJECT (gpd->job), "range"); |
---|
503 | g_return_if_fail (f != NULL); |
---|
504 | r = g_object_get_data (G_OBJECT (f), "range"); |
---|
505 | if (r) |
---|
506 | gtk_container_remove (GTK_CONTAINER (f), r); |
---|
507 | |
---|
508 | r = gpd_create_range (flags, range_widget, currentlabel, rangelabel); |
---|
509 | |
---|
510 | if (r) { |
---|
511 | gtk_widget_show (r); |
---|
512 | gtk_widget_show (gpd->job); |
---|
513 | gtk_container_add (GTK_CONTAINER (f), r); |
---|
514 | } |
---|
515 | |
---|
516 | g_object_set_data (G_OBJECT (f), "range", r); |
---|
517 | } |
---|
518 | |
---|
519 | /** |
---|
520 | * gnome_print_dialog_construct_range_page: |
---|
521 | * @gpd: An initialise GnomePrintDialog, which can contain a range. |
---|
522 | * @flags: Option flags. See gnome_print_dialog_construct_any(). |
---|
523 | * @start: First page which may be printed. |
---|
524 | * @end: Last page which may be printed. |
---|
525 | * @currentlabel: Label text for current option. |
---|
526 | * @rangelabel: Label text for range option. |
---|
527 | * |
---|
528 | * Construct a generic page/sheet range area. |
---|
529 | **/ |
---|
530 | void |
---|
531 | gnome_print_dialog_construct_range_page (GnomePrintDialog *gpd, gint flags, gint start, gint end, |
---|
532 | const guchar *currentlabel, const guchar *rangelabel) |
---|
533 | { |
---|
534 | GtkWidget *hbox; |
---|
535 | |
---|
536 | hbox = NULL; |
---|
537 | |
---|
538 | if (flags & GNOME_PRINT_RANGE_RANGE) { |
---|
539 | GtkWidget *l, *sb; |
---|
540 | GtkObject *a; |
---|
541 | AtkObject *atko; |
---|
542 | |
---|
543 | hbox = gtk_hbox_new (FALSE, 3); |
---|
544 | gtk_widget_show (hbox); |
---|
545 | |
---|
546 | l = gtk_label_new_with_mnemonic (_("_From:")); |
---|
547 | gtk_widget_show (l); |
---|
548 | gtk_box_pack_start (GTK_BOX (hbox), l, FALSE, FALSE, 0); |
---|
549 | |
---|
550 | a = gtk_adjustment_new (start, start, end, 1, 10, 10); |
---|
551 | g_object_set_data (G_OBJECT (hbox), "from", a); |
---|
552 | sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1, 0.0); |
---|
553 | gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (sb), TRUE); |
---|
554 | gtk_widget_show (sb); |
---|
555 | gtk_box_pack_start (GTK_BOX (hbox), sb, FALSE, FALSE, 0); |
---|
556 | gtk_label_set_mnemonic_widget ((GtkLabel *) l, sb); |
---|
557 | |
---|
558 | atko = gtk_widget_get_accessible (sb); |
---|
559 | atk_object_set_description (atko, _("Sets the start of the range of pages to be printed")); |
---|
560 | |
---|
561 | l = gtk_label_new_with_mnemonic (_("_To:")); |
---|
562 | gtk_widget_show (l); |
---|
563 | gtk_box_pack_start (GTK_BOX (hbox), l, FALSE, FALSE, 0); |
---|
564 | |
---|
565 | a = gtk_adjustment_new (end, start, end, 1, 10, 10); |
---|
566 | g_object_set_data (G_OBJECT (hbox), "to", a); |
---|
567 | sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1, 0.0); |
---|
568 | gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (sb), TRUE); |
---|
569 | gtk_widget_show (sb); |
---|
570 | gtk_box_pack_start (GTK_BOX (hbox), sb, FALSE, FALSE, 0); |
---|
571 | gtk_label_set_mnemonic_widget ((GtkLabel *) l, sb); |
---|
572 | |
---|
573 | atko = gtk_widget_get_accessible (sb); |
---|
574 | atk_object_set_description (atko, _("Sets the end of the range of pages to be printed")); |
---|
575 | } |
---|
576 | |
---|
577 | gnome_print_dialog_construct_range_any (gpd, flags, hbox, currentlabel, rangelabel); |
---|
578 | } |
---|
579 | |
---|
580 | /** |
---|
581 | * gnome_print_dialog_get_range: |
---|
582 | * @gpd: A GnomePrintDialog with a range display. |
---|
583 | * |
---|
584 | * Return the range option selected by the user. This is a bitmask |
---|
585 | * with only 1 bit set, out of: |
---|
586 | * |
---|
587 | * GNOME_PRINT_RANGE_CURRENT: The current option selected. |
---|
588 | * GNOME_PRINT_RANGE_ALL: The all option selected. |
---|
589 | * GNOME_PRINT_RANGE_RANGE The range option selected. |
---|
590 | * GNOME_PRINT_RANGE_SELECTION: The selection option selected. |
---|
591 | * |
---|
592 | * Return value: A bitmask with one option set. |
---|
593 | **/ |
---|
594 | GnomePrintRangeType |
---|
595 | gnome_print_dialog_get_range (GnomePrintDialog *gpd) |
---|
596 | { |
---|
597 | GtkWidget *f, *r, *b; |
---|
598 | |
---|
599 | g_return_val_if_fail (gpd != NULL, 0); |
---|
600 | g_return_val_if_fail (GNOME_IS_PRINT_DIALOG (gpd), 0); |
---|
601 | |
---|
602 | f = g_object_get_data (G_OBJECT (gpd->job), "range"); |
---|
603 | g_return_val_if_fail (f != NULL, 0); |
---|
604 | r = g_object_get_data (G_OBJECT (f), "range"); |
---|
605 | g_return_val_if_fail (r != NULL, 0); |
---|
606 | |
---|
607 | b = g_object_get_data (G_OBJECT (r), "current"); |
---|
608 | if (b && GTK_IS_TOGGLE_BUTTON (b) && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (b))) |
---|
609 | return GNOME_PRINT_RANGE_CURRENT; |
---|
610 | |
---|
611 | b = g_object_get_data (G_OBJECT (r), "all"); |
---|
612 | if (b && GTK_IS_TOGGLE_BUTTON (b) && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (b))) |
---|
613 | return GNOME_PRINT_RANGE_ALL; |
---|
614 | |
---|
615 | b = g_object_get_data (G_OBJECT (r), "range"); |
---|
616 | if (b && GTK_IS_TOGGLE_BUTTON (b) && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (b))) |
---|
617 | return GNOME_PRINT_RANGE_RANGE; |
---|
618 | |
---|
619 | b = g_object_get_data (G_OBJECT (r), "selection"); |
---|
620 | if (b && GTK_IS_TOGGLE_BUTTON (b) && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (b))) |
---|
621 | return GNOME_PRINT_RANGE_SELECTION; |
---|
622 | |
---|
623 | return 0; |
---|
624 | } |
---|
625 | |
---|
626 | /** |
---|
627 | * gnome_print_dialog_get_range_page: |
---|
628 | * @gpd: A GnomePrintDialog with a page range display. |
---|
629 | * @start: Return for the user-specified start page. |
---|
630 | * @end: Return for the user-specified end page. |
---|
631 | * |
---|
632 | * Retrieves the user choice for range type and range, if the user |
---|
633 | * has requested a range of pages to print. |
---|
634 | * |
---|
635 | * Return value: A bitmask with the user-selection set. See |
---|
636 | * gnome_print_dialog_get_range(). |
---|
637 | **/ |
---|
638 | gint |
---|
639 | gnome_print_dialog_get_range_page (GnomePrintDialog *gpd, gint *start, gint *end) |
---|
640 | { |
---|
641 | gint mask; |
---|
642 | |
---|
643 | g_return_val_if_fail (gpd != NULL, 0); |
---|
644 | g_return_val_if_fail (GNOME_IS_PRINT_DIALOG(gpd), 0); |
---|
645 | |
---|
646 | mask = gnome_print_dialog_get_range (gpd); |
---|
647 | |
---|
648 | if (mask & GNOME_PRINT_RANGE_RANGE) { |
---|
649 | GtkObject *f, *r, *w, *a; |
---|
650 | f = g_object_get_data (G_OBJECT (gpd->job), "range"); |
---|
651 | g_return_val_if_fail (f != NULL, 0); |
---|
652 | r = g_object_get_data (G_OBJECT (f), "range"); |
---|
653 | g_return_val_if_fail (r != NULL, 0); |
---|
654 | w = g_object_get_data (G_OBJECT (r), "range-widget"); |
---|
655 | g_return_val_if_fail (w != NULL, 0); |
---|
656 | a = g_object_get_data (G_OBJECT (w), "from"); |
---|
657 | g_return_val_if_fail (a && GTK_IS_ADJUSTMENT (a), 0); |
---|
658 | if (start) |
---|
659 | *start = (gint) gtk_adjustment_get_value (GTK_ADJUSTMENT (a)); |
---|
660 | a = g_object_get_data (G_OBJECT (w), "to"); |
---|
661 | g_return_val_if_fail (a && GTK_IS_ADJUSTMENT (a), 0); |
---|
662 | if (end) |
---|
663 | *end = (gint) gtk_adjustment_get_value (GTK_ADJUSTMENT (a)); |
---|
664 | } |
---|
665 | |
---|
666 | return mask; |
---|
667 | } |
---|
668 | |
---|
669 | /** |
---|
670 | * gnome_print_dialog_get_copies: |
---|
671 | * @gpd: A GnomePrintDialog with a copies display. |
---|
672 | * @copies: Return for the number of copies. |
---|
673 | * @collate: Return for collation flag. |
---|
674 | * |
---|
675 | * Retrieves the number of copies and collation indicator from |
---|
676 | * the print dialogue. If the print dialogue does not have a |
---|
677 | * copies indicator, then a default of 1 copy is returned. |
---|
678 | **/ |
---|
679 | void |
---|
680 | gnome_print_dialog_get_copies (GnomePrintDialog *gpd, gint *copies, gboolean *collate) |
---|
681 | { |
---|
682 | g_return_if_fail (gpd != NULL); |
---|
683 | g_return_if_fail (GNOME_IS_PRINT_DIALOG (gpd)); |
---|
684 | |
---|
685 | if (copies) *copies = 1; |
---|
686 | if (collate) *collate = FALSE; |
---|
687 | |
---|
688 | if (gpd->job) { |
---|
689 | GnomePrintCopiesSelector *c; |
---|
690 | |
---|
691 | c = g_object_get_data (G_OBJECT (gpd->job), "copies"); |
---|
692 | if (c && GNOME_IS_PRINT_COPIES_SELECTOR (c)) { |
---|
693 | if (copies) |
---|
694 | *copies = gnome_print_copies_selector_get_copies (c); |
---|
695 | if (collate) |
---|
696 | *collate = gnome_print_copies_selector_get_collate (c); |
---|
697 | } |
---|
698 | } |
---|
699 | } |
---|
700 | |
---|
701 | /** |
---|
702 | * gnome_print_dialog_set_copies: |
---|
703 | * @gpd: A GnomePrintDialog with a copies display. |
---|
704 | * @copies: New number of copies. |
---|
705 | * @collate: New collation status. |
---|
706 | * |
---|
707 | * Sets the print copies and collation status in the print dialogue. |
---|
708 | **/ |
---|
709 | void |
---|
710 | gnome_print_dialog_set_copies (GnomePrintDialog *gpd, gint copies, gboolean collate) |
---|
711 | { |
---|
712 | GnomePrintCopiesSelector *c; |
---|
713 | |
---|
714 | g_return_if_fail (gpd != NULL); |
---|
715 | g_return_if_fail (GNOME_IS_PRINT_DIALOG (gpd)); |
---|
716 | g_return_if_fail (gpd->job != NULL); |
---|
717 | c = g_object_get_data (G_OBJECT (gpd->job), "copies"); |
---|
718 | g_return_if_fail (c && GNOME_IS_PRINT_COPIES_SELECTOR (c)); |
---|
719 | |
---|
720 | gnome_print_copies_selector_set_copies (c, copies, collate); |
---|
721 | } |
---|
722 | |
---|
723 | /** |
---|
724 | * gnome_print_dialog_get_printer: |
---|
725 | * @gpd: An initialised GnomePrintDialog. |
---|
726 | * |
---|
727 | * Retrieve the user-requested printer from the printer area of |
---|
728 | * the print dialogue. |
---|
729 | * |
---|
730 | * Return value: The user-selected printer. |
---|
731 | **/ |
---|
732 | GnomePrintConfig * |
---|
733 | gnome_print_dialog_get_config (GnomePrintDialog *gpd) |
---|
734 | { |
---|
735 | g_return_val_if_fail (gpd != NULL, NULL); |
---|
736 | g_return_val_if_fail (GNOME_IS_PRINT_DIALOG (gpd), NULL); |
---|
737 | |
---|
738 | return gnome_print_config_ref (gpd->config); |
---|
739 | } |
---|
740 | |
---|
741 | |
---|
742 | /** |
---|
743 | * gnome_print_dialog_run: |
---|
744 | * @gpd: |
---|
745 | * |
---|
746 | * Runs a gnome-print dialog. Use it instead of gtk_dialog_run |
---|
747 | * in the future this function will handle more stuff like opening |
---|
748 | * a file selector when printing to a file. |
---|
749 | * |
---|
750 | * Note: this routine does not destroy the dialog! |
---|
751 | * |
---|
752 | * Return Value: the user response |
---|
753 | **/ |
---|
754 | gint |
---|
755 | gnome_print_dialog_run (GnomePrintDialog const *gpd) |
---|
756 | { |
---|
757 | gint response; |
---|
758 | |
---|
759 | response = gtk_dialog_run (GTK_DIALOG (gpd)); |
---|
760 | |
---|
761 | return response; |
---|
762 | } |
---|
763 | |
---|