1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
---|
2 | /* |
---|
3 | * gnome-print-paper-selector.c: A paper selector widget |
---|
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 | * James Henstridge <james@daa.com.au> |
---|
21 | * |
---|
22 | * Copyright (C) 1998 James Henstridge <james@daa.com.au> |
---|
23 | * |
---|
24 | */ |
---|
25 | |
---|
26 | #include <config.h> |
---|
27 | |
---|
28 | #include <string.h> |
---|
29 | #include <math.h> |
---|
30 | #include <atk/atk.h> |
---|
31 | #include <gtk/gtk.h> |
---|
32 | #include <libgnomeprint/gnome-print-paper.h> |
---|
33 | #include <libgnomeprint/gnome-print-config.h> |
---|
34 | #include <libgnomeprint/private/gpa-node.h> |
---|
35 | #include <libgnomeprint/private/gpa-utils.h> |
---|
36 | #include <libgnomeprint/private/gnome-print-private.h> |
---|
37 | #include <libgnomeprint/private/gnome-print-config-private.h> |
---|
38 | |
---|
39 | #include "gnome-print-i18n.h" |
---|
40 | #include "gnome-print-paper-selector.h" |
---|
41 | #include "gnome-print-unit-selector.h" |
---|
42 | |
---|
43 | /* This two have to go away */ |
---|
44 | #include "gnome-print-paper-preview.h" |
---|
45 | #include "gpaui/gpa-paper-preview-item.h" |
---|
46 | |
---|
47 | #include "gpaui/gpa-option-menu.h" |
---|
48 | #include "gpaui/gpa-spinbutton.h" |
---|
49 | |
---|
50 | #define MM(v) ((v) * 72.0 / 25.4) |
---|
51 | #define CM(v) ((v) * 72.0 / 2.54) |
---|
52 | #define M(v) ((v) * 72.0 / 0.0254) |
---|
53 | |
---|
54 | #define PAD 6 |
---|
55 | |
---|
56 | /* |
---|
57 | * GnomePaperSelector widget |
---|
58 | */ |
---|
59 | |
---|
60 | struct _GnomePaperSelector { |
---|
61 | GtkHBox box; |
---|
62 | |
---|
63 | GnomePrintConfig *config; |
---|
64 | gint flags; |
---|
65 | |
---|
66 | GtkWidget *preview; |
---|
67 | |
---|
68 | GtkWidget *pmenu, *pomenu, *lomenu, *lymenu, *trmenu; |
---|
69 | GnomePrintUnitSelector *us; |
---|
70 | |
---|
71 | gdouble mt, mb, ml, mr; /* Values for margins */ |
---|
72 | gdouble pw, ph; /* Values for page size */ |
---|
73 | |
---|
74 | struct {GPASpinbutton *t, *b, *l, *r;} m; /* Spins for margins */ |
---|
75 | struct {GPASpinbutton *w, *h;} p; /* Spins for page size */ |
---|
76 | |
---|
77 | GPANode *paper_size_node; |
---|
78 | GPANode *printer; |
---|
79 | |
---|
80 | guint handler_unit, handler_preview, handler_paper_size, handler_printer; |
---|
81 | }; |
---|
82 | |
---|
83 | struct _GnomePaperSelectorClass { |
---|
84 | GtkHBoxClass parent_class; |
---|
85 | }; |
---|
86 | |
---|
87 | static void gnome_paper_selector_class_init (GnomePaperSelectorClass *klass); |
---|
88 | static void gnome_paper_selector_init (GnomePaperSelector *selector); |
---|
89 | static void gnome_paper_selector_finalize (GObject *object); |
---|
90 | |
---|
91 | static GtkHBoxClass *selector_parent_class; |
---|
92 | |
---|
93 | GType |
---|
94 | gnome_paper_selector_get_type (void) |
---|
95 | { |
---|
96 | static GType type = 0; |
---|
97 | |
---|
98 | if (!type) { |
---|
99 | static const GTypeInfo info = { |
---|
100 | sizeof (GnomePaperSelectorClass), |
---|
101 | NULL, NULL, |
---|
102 | (GClassInitFunc) gnome_paper_selector_class_init, |
---|
103 | NULL, NULL, |
---|
104 | sizeof (GnomePaperSelector), |
---|
105 | 0, |
---|
106 | (GInstanceInitFunc) gnome_paper_selector_init |
---|
107 | }; |
---|
108 | type = g_type_register_static (GTK_TYPE_HBOX, "GnomePaperSelector", &info, 0); |
---|
109 | } |
---|
110 | |
---|
111 | return type; |
---|
112 | } |
---|
113 | |
---|
114 | static void |
---|
115 | gnome_paper_selector_class_init (GnomePaperSelectorClass *klass) |
---|
116 | { |
---|
117 | GObjectClass *object_class; |
---|
118 | GtkWidgetClass *widget_class; |
---|
119 | |
---|
120 | object_class = G_OBJECT_CLASS (klass); |
---|
121 | widget_class = GTK_WIDGET_CLASS (klass); |
---|
122 | |
---|
123 | selector_parent_class = g_type_class_peek_parent (klass); |
---|
124 | |
---|
125 | object_class->finalize = gnome_paper_selector_finalize; |
---|
126 | } |
---|
127 | |
---|
128 | static void |
---|
129 | gnome_paper_selector_update_spin_limits (GnomePaperSelector *ps) |
---|
130 | { |
---|
131 | g_return_if_fail (GNOME_IS_PAPER_SELECTOR (ps)); |
---|
132 | |
---|
133 | /* |
---|
134 | * Margins cannot be larger than the page size minus the |
---|
135 | * opposite margin |
---|
136 | */ |
---|
137 | ps->m.t->upper = ps->ph - ps->mb; gpa_spinbutton_update (ps->m.t); |
---|
138 | ps->m.b->upper = ps->ph - ps->mt; gpa_spinbutton_update (ps->m.b); |
---|
139 | ps->m.r->upper = ps->pw - ps->ml; gpa_spinbutton_update (ps->m.r); |
---|
140 | ps->m.l->upper = ps->pw - ps->mr; gpa_spinbutton_update (ps->m.l); |
---|
141 | } |
---|
142 | |
---|
143 | static void |
---|
144 | gps_psize_value_changed (GtkAdjustment *adj, GnomePaperSelector *ps) |
---|
145 | { |
---|
146 | g_return_if_fail (GNOME_IS_PAPER_SELECTOR (ps)); |
---|
147 | |
---|
148 | /* Did the value really change? */ |
---|
149 | if ((fabs (ps->pw - ps->p.w->value) < 0.1) && |
---|
150 | (fabs (ps->ph - ps->p.h->value) < 0.1)) |
---|
151 | return; |
---|
152 | ps->pw = ps->p.w->value; |
---|
153 | ps->ph = ps->p.h->value; |
---|
154 | |
---|
155 | gnome_paper_selector_update_spin_limits (ps); |
---|
156 | } |
---|
157 | |
---|
158 | static void |
---|
159 | gps_m_size_value_changed (GtkAdjustment *adj, GnomePaperSelector *ps) |
---|
160 | { |
---|
161 | g_return_if_fail (GNOME_IS_PAPER_SELECTOR (ps)); |
---|
162 | |
---|
163 | /* Did the value really change? */ |
---|
164 | if ((fabs (ps->mt - ps->m.t->value) < 0.1) && |
---|
165 | (fabs (ps->mb - ps->m.b->value) < 0.1) && |
---|
166 | (fabs (ps->ml - ps->m.l->value) < 0.1) && |
---|
167 | (fabs (ps->mr - ps->m.r->value) < 0.1)) |
---|
168 | return; |
---|
169 | ps->ml = ps->m.l->value; |
---|
170 | ps->mr = ps->m.r->value; |
---|
171 | ps->mt = ps->m.t->value; |
---|
172 | ps->mb = ps->m.b->value; |
---|
173 | |
---|
174 | gpa_paper_preview_item_set_logical_margins |
---|
175 | (GPA_PAPER_PREVIEW_ITEM (GNOME_PAPER_PREVIEW |
---|
176 | (ps->preview)->item), |
---|
177 | ps->ml, ps->mr, ps->mt, ps->mb); |
---|
178 | gnome_paper_selector_update_spin_limits (ps); |
---|
179 | } |
---|
180 | |
---|
181 | static void |
---|
182 | gnome_paper_selector_init (GnomePaperSelector *ps) |
---|
183 | { |
---|
184 | ps->config = NULL; |
---|
185 | ps->flags = 0; |
---|
186 | } |
---|
187 | |
---|
188 | static void |
---|
189 | gnome_paper_selector_finalize (GObject *object) |
---|
190 | { |
---|
191 | GnomePaperSelector *ps; |
---|
192 | |
---|
193 | ps = GNOME_PAPER_SELECTOR (object); |
---|
194 | |
---|
195 | ps->preview = NULL; |
---|
196 | |
---|
197 | if (ps->config) { |
---|
198 | GObject *node; |
---|
199 | |
---|
200 | node = G_OBJECT (gnome_print_config_get_node (ps->config)); |
---|
201 | |
---|
202 | if (ps->handler_preview) { |
---|
203 | g_signal_handler_disconnect (node, ps->handler_preview); |
---|
204 | ps->handler_preview = 0; |
---|
205 | } |
---|
206 | |
---|
207 | if (ps->handler_unit) { |
---|
208 | g_signal_handler_disconnect (node, ps->handler_unit); |
---|
209 | ps->handler_unit = 0; |
---|
210 | } |
---|
211 | |
---|
212 | if (ps->handler_printer) { |
---|
213 | g_signal_handler_disconnect (ps->printer, ps->handler_printer); |
---|
214 | ps->handler_printer = 0; |
---|
215 | } |
---|
216 | |
---|
217 | if (ps->handler_paper_size) { |
---|
218 | g_signal_handler_disconnect (ps->paper_size_node, ps->handler_paper_size); |
---|
219 | ps->handler_paper_size = 0; |
---|
220 | |
---|
221 | gpa_node_unref (ps->paper_size_node); |
---|
222 | ps->paper_size_node = NULL; |
---|
223 | } |
---|
224 | |
---|
225 | gnome_print_config_unref (ps->config); |
---|
226 | ps->config = NULL; |
---|
227 | } |
---|
228 | |
---|
229 | G_OBJECT_CLASS (selector_parent_class)->finalize (object); |
---|
230 | } |
---|
231 | |
---|
232 | static gboolean |
---|
233 | lmargin_top_unit_activated (GtkSpinButton *spin_button, |
---|
234 | GdkEventFocus *event, |
---|
235 | GnomePaperSelector *ps) |
---|
236 | { |
---|
237 | gpa_paper_preview_item_set_lm_highlights |
---|
238 | (GPA_PAPER_PREVIEW_ITEM (GNOME_PAPER_PREVIEW (ps->preview)->item), |
---|
239 | TRUE, FALSE, FALSE, FALSE); |
---|
240 | return FALSE; |
---|
241 | } |
---|
242 | |
---|
243 | static gboolean |
---|
244 | lmargin_bottom_unit_activated (GtkSpinButton *spin_button, |
---|
245 | GdkEventFocus *event, |
---|
246 | GnomePaperSelector *ps) |
---|
247 | { |
---|
248 | gpa_paper_preview_item_set_lm_highlights |
---|
249 | (GPA_PAPER_PREVIEW_ITEM (GNOME_PAPER_PREVIEW (ps->preview)->item), |
---|
250 | FALSE, TRUE, FALSE, FALSE); |
---|
251 | return FALSE; |
---|
252 | } |
---|
253 | |
---|
254 | static gboolean |
---|
255 | lmargin_left_unit_activated (GtkSpinButton *spin_button, |
---|
256 | GdkEventFocus *event, |
---|
257 | GnomePaperSelector *ps) |
---|
258 | { |
---|
259 | gpa_paper_preview_item_set_lm_highlights |
---|
260 | (GPA_PAPER_PREVIEW_ITEM (GNOME_PAPER_PREVIEW (ps->preview)->item), |
---|
261 | FALSE, FALSE, TRUE, FALSE); |
---|
262 | return FALSE; |
---|
263 | } |
---|
264 | |
---|
265 | static gboolean |
---|
266 | lmargin_right_unit_activated (GtkSpinButton *spin_button, |
---|
267 | GdkEventFocus *event, |
---|
268 | GnomePaperSelector *ps) |
---|
269 | { |
---|
270 | gpa_paper_preview_item_set_lm_highlights |
---|
271 | (GPA_PAPER_PREVIEW_ITEM (GNOME_PAPER_PREVIEW (ps->preview)->item), |
---|
272 | FALSE, FALSE, FALSE, TRUE); |
---|
273 | return FALSE; |
---|
274 | } |
---|
275 | |
---|
276 | static gboolean |
---|
277 | lmargin_unit_deactivated (GtkSpinButton *spin_button, |
---|
278 | GdkEventFocus *event, |
---|
279 | GnomePaperSelector *ps) |
---|
280 | { |
---|
281 | gpa_paper_preview_item_set_lm_highlights |
---|
282 | (GPA_PAPER_PREVIEW_ITEM (GNOME_PAPER_PREVIEW (ps->preview)->item), |
---|
283 | FALSE, FALSE, FALSE, FALSE); |
---|
284 | return FALSE; |
---|
285 | } |
---|
286 | |
---|
287 | static void |
---|
288 | gnome_print_paper_selector_update_spin_units (GnomePaperSelector *ps) |
---|
289 | { |
---|
290 | const GnomePrintUnit *unit; |
---|
291 | |
---|
292 | g_return_if_fail (GNOME_IS_PAPER_SELECTOR (ps)); |
---|
293 | |
---|
294 | unit = gnome_print_unit_selector_get_unit (ps->us); |
---|
295 | if (!unit) return; |
---|
296 | |
---|
297 | gpa_spinbutton_set_unit (ps->m.t, unit->abbr); |
---|
298 | gpa_spinbutton_set_unit (ps->m.b, unit->abbr); |
---|
299 | gpa_spinbutton_set_unit (ps->m.r, unit->abbr); |
---|
300 | gpa_spinbutton_set_unit (ps->m.l, unit->abbr); |
---|
301 | gpa_spinbutton_set_unit (ps->p.h, unit->abbr); |
---|
302 | gpa_spinbutton_set_unit (ps->p.w, unit->abbr); |
---|
303 | } |
---|
304 | |
---|
305 | static void |
---|
306 | gnome_paper_selector_unit_changed_cb (GnomePrintUnitSelector *sel, GnomePaperSelector *ps) |
---|
307 | { |
---|
308 | const GnomePrintUnit *unit = gnome_print_unit_selector_get_unit (sel); |
---|
309 | if (NULL != unit) |
---|
310 | gnome_print_config_set (ps->config, GNOME_PRINT_KEY_PREFERED_UNIT, unit->abbr); |
---|
311 | gnome_print_paper_selector_update_spin_units (ps); |
---|
312 | } |
---|
313 | |
---|
314 | static void |
---|
315 | gnome_paper_unit_selector_request_update_cb (GPANode *node, guint flags, |
---|
316 | GnomePaperSelector *ps) |
---|
317 | { |
---|
318 | guchar *unit_txt; |
---|
319 | |
---|
320 | unit_txt = gnome_print_config_get (ps->config, GNOME_PRINT_KEY_PREFERED_UNIT); |
---|
321 | if (!unit_txt) { |
---|
322 | g_warning ("Could not get GNOME_PRINT_KEY_PREFERED_UNIT"); |
---|
323 | return; |
---|
324 | } |
---|
325 | |
---|
326 | gnome_print_unit_selector_set_unit (ps->us, |
---|
327 | gnome_print_unit_get_by_abbreviation (unit_txt)); |
---|
328 | g_free (unit_txt); |
---|
329 | gnome_print_paper_selector_update_spin_units (ps); |
---|
330 | } |
---|
331 | |
---|
332 | /** |
---|
333 | * gnome_paper_selector_paper_size_modified_cb |
---|
334 | * @node: |
---|
335 | * @flags: |
---|
336 | * @ps: |
---|
337 | * |
---|
338 | * Handle paper sizes changes |
---|
339 | **/ |
---|
340 | static void |
---|
341 | gnome_paper_selector_paper_size_modified_cb (GPANode *node, guint flags, GnomePaperSelector *ps) |
---|
342 | { |
---|
343 | guchar *id; |
---|
344 | gboolean sensitivity = FALSE; |
---|
345 | |
---|
346 | id = gnome_print_config_get (ps->config, GNOME_PRINT_KEY_PAPER_SIZE); |
---|
347 | if (id) { |
---|
348 | if (*id && !strcmp (id, "Custom")) sensitivity = TRUE; |
---|
349 | g_free (id); |
---|
350 | } |
---|
351 | |
---|
352 | gtk_widget_set_sensitive (GTK_WIDGET (ps->p.w), sensitivity); |
---|
353 | gtk_widget_set_sensitive (GTK_WIDGET (ps->p.h), sensitivity); |
---|
354 | |
---|
355 | gnome_paper_selector_update_spin_limits (ps); |
---|
356 | } |
---|
357 | |
---|
358 | static void |
---|
359 | gnome_paper_selector_hook_paper_size (GnomePaperSelector *ps) |
---|
360 | { |
---|
361 | if (ps->handler_paper_size) { |
---|
362 | g_signal_handler_disconnect (G_OBJECT (ps->paper_size_node), ps->handler_paper_size); |
---|
363 | ps->handler_paper_size = 0; |
---|
364 | } |
---|
365 | |
---|
366 | if (ps->paper_size_node) { |
---|
367 | gpa_node_unref (ps->paper_size_node); |
---|
368 | ps->paper_size_node = NULL; |
---|
369 | } |
---|
370 | |
---|
371 | ps->paper_size_node = gpa_node_get_child_from_path (GNOME_PRINT_CONFIG_NODE (ps->config), |
---|
372 | GNOME_PRINT_KEY_PAPER_SIZE); |
---|
373 | |
---|
374 | if (ps->paper_size_node) { |
---|
375 | ps->handler_paper_size = g_signal_connect ( |
---|
376 | G_OBJECT (ps->paper_size_node), "modified", |
---|
377 | (GCallback) gnome_paper_selector_paper_size_modified_cb, ps); |
---|
378 | } else { |
---|
379 | g_print ("No paper size node\n"); |
---|
380 | } |
---|
381 | |
---|
382 | gnome_paper_selector_paper_size_modified_cb (NULL, 0, ps); |
---|
383 | } |
---|
384 | |
---|
385 | static void |
---|
386 | gnome_paper_selector_printer_changed_cb (GPANode *node, guint flags, GnomePaperSelector *ps) |
---|
387 | { |
---|
388 | gnome_paper_selector_hook_paper_size (ps); |
---|
389 | } |
---|
390 | |
---|
391 | static void |
---|
392 | gnome_paper_selector_construct (GnomePaperSelector *ps) |
---|
393 | { |
---|
394 | GtkWidget *vb, *f, *t, *l, *s; |
---|
395 | GtkWidget *margin_table, *margin_label; |
---|
396 | gdouble ml, mr, mt, mb, pw = 1., ph = 1.; |
---|
397 | AtkObject *atko; |
---|
398 | GPANode *printer; |
---|
399 | gchar *text; |
---|
400 | |
---|
401 | g_return_if_fail (ps != NULL); |
---|
402 | g_return_if_fail (ps->config != NULL); |
---|
403 | |
---|
404 | printer = gpa_node_get_child_from_path (GNOME_PRINT_CONFIG_NODE (ps->config), "Printer"); |
---|
405 | g_return_if_fail (printer != NULL); |
---|
406 | ps->printer = printer; |
---|
407 | |
---|
408 | /* Fetch the current settings. */ |
---|
409 | ml = MM(10); |
---|
410 | mr = MM(10); |
---|
411 | mt = MM(10); |
---|
412 | mb = MM(10); |
---|
413 | gnome_print_config_get_length (ps->config, |
---|
414 | GNOME_PRINT_KEY_PAGE_MARGIN_LEFT, &ml, NULL); |
---|
415 | gnome_print_config_get_length (ps->config, |
---|
416 | GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT, &mr, NULL); |
---|
417 | gnome_print_config_get_length (ps->config, |
---|
418 | GNOME_PRINT_KEY_PAGE_MARGIN_TOP, &mt, NULL); |
---|
419 | gnome_print_config_get_length (ps->config, |
---|
420 | GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM, &mb, NULL); |
---|
421 | ps->ml = ml; |
---|
422 | ps->mr = mr; |
---|
423 | ps->mt = mt; |
---|
424 | ps->mb = mb; |
---|
425 | gnome_print_config_get_length (ps->config, |
---|
426 | GNOME_PRINT_KEY_PAPER_WIDTH, &pw, NULL); |
---|
427 | gnome_print_config_get_length (ps->config, |
---|
428 | GNOME_PRINT_KEY_PAPER_HEIGHT, &ph, NULL); |
---|
429 | ps->ph = ph; |
---|
430 | ps->pw = pw; |
---|
431 | |
---|
432 | gtk_box_set_spacing (GTK_BOX (ps), PAD); |
---|
433 | |
---|
434 | /* VBox for controls */ |
---|
435 | vb = gtk_vbox_new (FALSE, PAD); |
---|
436 | gtk_widget_show (vb); |
---|
437 | gtk_box_pack_start (GTK_BOX (ps), vb, FALSE, FALSE, 0); |
---|
438 | |
---|
439 | /* Create frame for selection menus */ |
---|
440 | f = gtk_frame_new (""); |
---|
441 | gtk_frame_set_shadow_type (GTK_FRAME (f), GTK_SHADOW_NONE); |
---|
442 | l = gtk_label_new (""); |
---|
443 | text = g_strdup_printf ("<b>%s</b>", _("Paper and Layout")); |
---|
444 | gtk_label_set_markup (GTK_LABEL (l), text); |
---|
445 | g_free (text); |
---|
446 | gtk_frame_set_label_widget (GTK_FRAME (f), l); |
---|
447 | gtk_widget_show (l); |
---|
448 | gtk_widget_show (f); |
---|
449 | gtk_box_pack_start (GTK_BOX (vb), f, FALSE, FALSE, 0); |
---|
450 | |
---|
451 | /* Create table for packing menus */ |
---|
452 | t = gtk_table_new (4, 6, FALSE); |
---|
453 | gtk_widget_show (t); |
---|
454 | gtk_container_set_border_width (GTK_CONTAINER (t), PAD); |
---|
455 | gtk_table_set_row_spacings (GTK_TABLE (t), 2); |
---|
456 | gtk_table_set_col_spacings (GTK_TABLE (t), 4); |
---|
457 | gtk_container_add (GTK_CONTAINER (f), t); |
---|
458 | |
---|
459 | /* Paper size selector */ |
---|
460 | l = gtk_label_new_with_mnemonic (_("Paper _size:")); |
---|
461 | gtk_widget_show (l); |
---|
462 | gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0.5); |
---|
463 | gtk_table_attach_defaults (GTK_TABLE (t), l, 0, 1, 0, 1); |
---|
464 | |
---|
465 | ps->pmenu = gpa_option_menu_new (ps->config, GNOME_PRINT_KEY_PAPER_SIZE); |
---|
466 | gtk_widget_show (ps->pmenu); |
---|
467 | gtk_table_attach_defaults (GTK_TABLE (t), ps->pmenu, 1, 4, 0, 1); |
---|
468 | gtk_label_set_mnemonic_widget ((GtkLabel *) l, GPA_OPTION_MENU (ps->pmenu)->menu); |
---|
469 | |
---|
470 | /* Custom paper Width */ |
---|
471 | l = gtk_label_new_with_mnemonic (_("_Width:")); |
---|
472 | gtk_widget_show (l); |
---|
473 | gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0.5); |
---|
474 | gtk_table_attach_defaults (GTK_TABLE (t), l, 1, 2, 1, 2); |
---|
475 | s = gpa_spinbutton_new (ps->config, GNOME_PRINT_KEY_PAPER_WIDTH, |
---|
476 | 0.0001, 10000, 1, 10, 10, 1, 2); |
---|
477 | ps->p.w = GPA_SPINBUTTON (s); |
---|
478 | gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (ps->p.w->spinbutton), |
---|
479 | TRUE); |
---|
480 | gtk_widget_show (s); |
---|
481 | gtk_table_attach_defaults (GTK_TABLE (t), s, 2, 3, 1, 2); |
---|
482 | gtk_label_set_mnemonic_widget ((GtkLabel *) l, ps->p.w->spinbutton); |
---|
483 | |
---|
484 | /* Custom paper Height */ |
---|
485 | l = gtk_label_new_with_mnemonic (_("_Height:")); |
---|
486 | gtk_widget_show (l); |
---|
487 | gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0.5); |
---|
488 | gtk_table_attach_defaults (GTK_TABLE (t), l, 1, 2, 2, 3); |
---|
489 | s = gpa_spinbutton_new (ps->config, GNOME_PRINT_KEY_PAPER_HEIGHT, |
---|
490 | 0.0001, 10000, 1, 10, 10, 1, 2); |
---|
491 | ps->p.h = GPA_SPINBUTTON (s); |
---|
492 | gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (ps->p.h->spinbutton), |
---|
493 | TRUE); |
---|
494 | gtk_widget_show (s); |
---|
495 | gtk_table_attach_defaults (GTK_TABLE (t), s, 2, 3, 2, 3); |
---|
496 | gtk_label_set_mnemonic_widget ((GtkLabel *) l, ps->p.h->spinbutton); |
---|
497 | |
---|
498 | /* Custom paper Unit selector */ |
---|
499 | s = gnome_print_unit_selector_new (GNOME_PRINT_UNIT_ABSOLUTE); |
---|
500 | ps->us = GNOME_PRINT_UNIT_SELECTOR (s); |
---|
501 | gtk_table_attach_defaults (GTK_TABLE (t), s, 3, 4, 1, 2); |
---|
502 | atko = gtk_widget_get_accessible (s); |
---|
503 | atk_object_set_name (atko, _("Metric selector")); |
---|
504 | atk_object_set_description (atko, _("Specifies the metric to use when setting the width and height of the paper")); |
---|
505 | |
---|
506 | /* Feed orientation */ |
---|
507 | l = gtk_label_new_with_mnemonic (_("_Feed orientation:")); |
---|
508 | gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0.5); |
---|
509 | gtk_table_attach_defaults (GTK_TABLE (t), l, 0, 1, 3, 4); |
---|
510 | |
---|
511 | ps->pomenu = gpa_option_menu_new (ps->config, GNOME_PRINT_KEY_PAPER_ORIENTATION); |
---|
512 | gtk_table_attach_defaults (GTK_TABLE (t), ps->pomenu, 1, 4, 3, 4); |
---|
513 | gtk_label_set_mnemonic_widget ((GtkLabel *) l, GPA_OPTION_MENU (ps->pomenu)->menu); |
---|
514 | |
---|
515 | if (ps->flags & GNOME_PAPER_SELECTOR_FEED_ORIENTATION || TRUE) { |
---|
516 | gtk_widget_show_all (ps->pomenu); |
---|
517 | gtk_widget_show_all (l); |
---|
518 | } |
---|
519 | |
---|
520 | /* Page orientation */ |
---|
521 | l = gtk_label_new_with_mnemonic (_("Page _orientation:")); |
---|
522 | gtk_widget_show (l); |
---|
523 | gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0.5); |
---|
524 | gtk_table_attach_defaults (GTK_TABLE (t), l, 0, 1, 4, 5); |
---|
525 | |
---|
526 | ps->lomenu = gpa_option_menu_new (ps->config, GNOME_PRINT_KEY_PAGE_ORIENTATION); |
---|
527 | gtk_widget_show (ps->lomenu); |
---|
528 | gtk_table_attach_defaults (GTK_TABLE (t), ps->lomenu, 1, 4, 4, 5); |
---|
529 | gtk_label_set_mnemonic_widget ((GtkLabel *) l, GPA_OPTION_MENU (ps->lomenu)->menu); |
---|
530 | |
---|
531 | /* Layout */ |
---|
532 | l = gtk_label_new_with_mnemonic (_("_Layout:")); |
---|
533 | gtk_widget_show (l); |
---|
534 | gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0.5); |
---|
535 | gtk_table_attach_defaults (GTK_TABLE (t), l, 0, 1, 5, 6); |
---|
536 | |
---|
537 | ps->lymenu = gpa_option_menu_new (ps->config, GNOME_PRINT_KEY_LAYOUT); |
---|
538 | gtk_widget_show (ps->lymenu); |
---|
539 | gtk_table_attach_defaults (GTK_TABLE (t), ps->lymenu, 1, 4, 5, 6); |
---|
540 | gtk_label_set_mnemonic_widget ((GtkLabel *) l, GPA_OPTION_MENU (ps->lymenu)->menu); |
---|
541 | |
---|
542 | /* Paper source */ |
---|
543 | l = gtk_label_new_with_mnemonic (_("Paper _tray:")); |
---|
544 | gtk_widget_show(l); |
---|
545 | gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0.5); |
---|
546 | gtk_table_attach_defaults (GTK_TABLE (t), l, 0, 1, 6, 7); |
---|
547 | |
---|
548 | ps->trmenu = gpa_option_menu_new (ps->config, GNOME_PRINT_KEY_PAPER_SOURCE); |
---|
549 | gtk_widget_show(ps->trmenu); |
---|
550 | gtk_table_attach_defaults (GTK_TABLE (t), ps->trmenu, 1, 4, 6, 7); |
---|
551 | gtk_label_set_mnemonic_widget ((GtkLabel *) l, GPA_OPTION_MENU (ps->trmenu)->menu); |
---|
552 | |
---|
553 | /* Preview frame */ |
---|
554 | f = gtk_frame_new (""); |
---|
555 | gtk_frame_set_shadow_type (GTK_FRAME (f), GTK_SHADOW_NONE); |
---|
556 | l = gtk_label_new (""); |
---|
557 | text = g_strdup_printf ("<b>%s</b>", _("Preview")); |
---|
558 | gtk_label_set_markup (GTK_LABEL (l), text); |
---|
559 | g_free (text); |
---|
560 | gtk_frame_set_label_widget (GTK_FRAME (f), l); |
---|
561 | gtk_widget_show (l); |
---|
562 | gtk_widget_show (f); |
---|
563 | gtk_box_pack_start (GTK_BOX (ps), f, TRUE, TRUE, 0); |
---|
564 | |
---|
565 | ps->preview = gnome_paper_preview_new (ps->config); |
---|
566 | gtk_widget_set_size_request (ps->preview, 160, 160); |
---|
567 | gtk_widget_show (ps->preview); |
---|
568 | gtk_container_add (GTK_CONTAINER (f), ps->preview); |
---|
569 | |
---|
570 | atko = gtk_widget_get_accessible (ps->preview); |
---|
571 | atk_object_set_name (atko, _("Preview")); |
---|
572 | atk_object_set_description (atko, _("Preview of the page size, orientation and layout")); |
---|
573 | |
---|
574 | /* Margins */ |
---|
575 | f = gtk_frame_new (""); |
---|
576 | gtk_frame_set_shadow_type (GTK_FRAME (f), GTK_SHADOW_NONE); |
---|
577 | l = gtk_label_new (""); |
---|
578 | text = g_strdup_printf ("<b>%s</b>", _("Margins")); |
---|
579 | gtk_label_set_markup (GTK_LABEL (l), text); |
---|
580 | g_free (text); |
---|
581 | gtk_frame_set_label_widget (GTK_FRAME (f), l); |
---|
582 | gtk_widget_show (l); |
---|
583 | |
---|
584 | gtk_box_pack_start (GTK_BOX (ps), f, FALSE, FALSE, 0); |
---|
585 | margin_table = gtk_table_new ( 8, 1, TRUE); |
---|
586 | gtk_container_set_border_width (GTK_CONTAINER (margin_table), 4); |
---|
587 | |
---|
588 | s = gpa_spinbutton_new (ps->config, |
---|
589 | GNOME_PRINT_KEY_PAGE_MARGIN_TOP, 0., ps->ph, |
---|
590 | 1., 10., 10., 1., 2.); |
---|
591 | ps->m.t = GPA_SPINBUTTON (s); |
---|
592 | gtk_table_attach (GTK_TABLE (margin_table), s, |
---|
593 | 0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 0); |
---|
594 | s = gpa_spinbutton_new (ps->config, |
---|
595 | GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM, 0., ps->ph, |
---|
596 | 1, 10, 10, 1., 2.); |
---|
597 | ps->m.b = GPA_SPINBUTTON (s); |
---|
598 | gtk_table_attach (GTK_TABLE (margin_table), s, |
---|
599 | 0, 1, 7, 8, GTK_FILL, GTK_FILL, 0, 0); |
---|
600 | s = gpa_spinbutton_new (ps->config, |
---|
601 | GNOME_PRINT_KEY_PAGE_MARGIN_LEFT, 0., ps->pw, |
---|
602 | 1, 10, 10, 1., 2.); |
---|
603 | ps->m.l = GPA_SPINBUTTON (s); |
---|
604 | gtk_table_attach (GTK_TABLE (margin_table), s, |
---|
605 | 0, 1, 3, 4, GTK_FILL, GTK_FILL, 0, 0); |
---|
606 | s = gpa_spinbutton_new (ps->config, |
---|
607 | GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT, 0., ps->pw, |
---|
608 | 1, 10, 10, 1., 2.); |
---|
609 | ps->m.r = GPA_SPINBUTTON (s); |
---|
610 | gtk_table_attach (GTK_TABLE (margin_table), s, |
---|
611 | 0, 1, 5, 6, GTK_FILL, GTK_FILL, 0, 0); |
---|
612 | margin_label = gtk_label_new (_("Top")); |
---|
613 | gtk_table_attach (GTK_TABLE (margin_table), margin_label, |
---|
614 | 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0); |
---|
615 | margin_label = gtk_label_new (_("Bottom")); |
---|
616 | gtk_table_attach (GTK_TABLE (margin_table), margin_label, |
---|
617 | 0, 1, 6, 7, GTK_FILL, GTK_FILL, 0, 0); |
---|
618 | margin_label = gtk_label_new (_("Left")); |
---|
619 | gtk_table_attach (GTK_TABLE (margin_table), margin_label, |
---|
620 | 0, 1, 2, 3, GTK_FILL, GTK_FILL, 0, 0); |
---|
621 | margin_label = gtk_label_new (_("Right")); |
---|
622 | gtk_table_attach (GTK_TABLE (margin_table), margin_label, |
---|
623 | 0, 1, 4, 5, GTK_FILL, GTK_FILL, 0, 0); |
---|
624 | gtk_container_add (GTK_CONTAINER (f), margin_table); |
---|
625 | if (ps->flags & GNOME_PAPER_SELECTOR_MARGINS) |
---|
626 | gtk_widget_show_all (f); |
---|
627 | |
---|
628 | /* Hook up the Custom size widgets */ |
---|
629 | gnome_paper_selector_hook_paper_size (ps); |
---|
630 | ps->handler_printer = g_signal_connect (G_OBJECT (ps->printer), |
---|
631 | "modified", (GCallback) gnome_paper_selector_printer_changed_cb, ps); |
---|
632 | |
---|
633 | /* Setup the unit selector */ |
---|
634 | gnome_paper_unit_selector_request_update_cb (NULL, 0, ps); |
---|
635 | g_signal_connect (G_OBJECT (ps->us), "modified", |
---|
636 | G_CALLBACK (gnome_paper_selector_unit_changed_cb), ps); |
---|
637 | ps->handler_unit = g_signal_connect ( |
---|
638 | G_OBJECT (gnome_print_config_get_node (ps->config)), "modified", |
---|
639 | G_CALLBACK (gnome_paper_unit_selector_request_update_cb), ps); |
---|
640 | |
---|
641 | /* Connect signals */ |
---|
642 | g_signal_connect ( |
---|
643 | G_OBJECT (GTK_SPIN_BUTTON (ps->p.w->spinbutton)->adjustment), |
---|
644 | "value_changed", G_CALLBACK (gps_psize_value_changed), ps); |
---|
645 | g_signal_connect ( |
---|
646 | G_OBJECT (GTK_SPIN_BUTTON (ps->p.h->spinbutton)->adjustment), |
---|
647 | "value_changed", G_CALLBACK (gps_psize_value_changed), ps); |
---|
648 | g_signal_connect ( |
---|
649 | G_OBJECT (GTK_SPIN_BUTTON (ps->m.t->spinbutton)->adjustment), |
---|
650 | "value_changed", G_CALLBACK (gps_m_size_value_changed), ps); |
---|
651 | g_signal_connect ( |
---|
652 | G_OBJECT (GTK_SPIN_BUTTON (ps->m.b->spinbutton)->adjustment), |
---|
653 | "value_changed", G_CALLBACK (gps_m_size_value_changed), ps); |
---|
654 | g_signal_connect ( |
---|
655 | G_OBJECT (GTK_SPIN_BUTTON (ps->m.l->spinbutton)->adjustment), |
---|
656 | "value_changed", G_CALLBACK (gps_m_size_value_changed), ps); |
---|
657 | g_signal_connect ( |
---|
658 | G_OBJECT (GTK_SPIN_BUTTON (ps->m.r->spinbutton)->adjustment), |
---|
659 | "value_changed", G_CALLBACK (gps_m_size_value_changed), ps); |
---|
660 | g_signal_connect (G_OBJECT (ps->m.t), "focus_in_event", |
---|
661 | G_CALLBACK (lmargin_top_unit_activated), ps); |
---|
662 | g_signal_connect (G_OBJECT (ps->m.t->spinbutton), "focus_out_event", |
---|
663 | G_CALLBACK (lmargin_unit_deactivated), ps); |
---|
664 | g_signal_connect (G_OBJECT (ps->m.l->spinbutton), "focus_in_event", |
---|
665 | G_CALLBACK (lmargin_left_unit_activated), ps); |
---|
666 | g_signal_connect (G_OBJECT (ps->m.l->spinbutton), "focus_out_event", |
---|
667 | G_CALLBACK (lmargin_unit_deactivated), ps); |
---|
668 | g_signal_connect (G_OBJECT (ps->m.r->spinbutton), "focus_in_event", |
---|
669 | G_CALLBACK (lmargin_right_unit_activated), ps); |
---|
670 | g_signal_connect (G_OBJECT (ps->m.r->spinbutton), "focus_out_event", |
---|
671 | G_CALLBACK (lmargin_unit_deactivated), ps); |
---|
672 | g_signal_connect (G_OBJECT (ps->m.b->spinbutton), "focus_in_event", |
---|
673 | G_CALLBACK (lmargin_bottom_unit_activated), ps); |
---|
674 | g_signal_connect (G_OBJECT (ps->m.b->spinbutton), "focus_out_event", |
---|
675 | G_CALLBACK (lmargin_unit_deactivated), ps); |
---|
676 | |
---|
677 | gtk_widget_show (GTK_WIDGET (ps->us)); |
---|
678 | } |
---|
679 | |
---|
680 | GtkWidget * |
---|
681 | gnome_paper_selector_new_with_flags (GnomePrintConfig *config, gint flags) |
---|
682 | { |
---|
683 | GnomePaperSelector *selector; |
---|
684 | |
---|
685 | selector = g_object_new (GNOME_TYPE_PAPER_SELECTOR, NULL); |
---|
686 | |
---|
687 | if (config) { |
---|
688 | selector->config = gnome_print_config_ref (config); |
---|
689 | } else { |
---|
690 | selector->config = gnome_print_config_default (); |
---|
691 | } |
---|
692 | selector->flags = flags; |
---|
693 | |
---|
694 | gnome_paper_selector_construct (selector); |
---|
695 | |
---|
696 | return (GtkWidget *) selector; |
---|
697 | } |
---|
698 | |
---|
699 | GtkWidget * |
---|
700 | gnome_paper_selector_new (GnomePrintConfig *config) |
---|
701 | { |
---|
702 | return gnome_paper_selector_new_with_flags (config, 0); |
---|
703 | } |
---|
704 | |
---|