GetToggleButtonState -> ToggleButtonGetState
[grace.git] / src / printwin.c
blob4127160db9fb173bf51149c94bf70df2ba0aad7b
1 /*
2 * Grace - GRaphing, Advanced Computation and Exploration of data
3 *
4 * Home page: http://plasma-gate.weizmann.ac.il/Grace/
5 *
6 * Copyright (c) 1991-1995 Paul J Turner, Portland, OR
7 * Copyright (c) 1996-2004 Grace Development Team
8 *
9 * Maintained by Evgeny Stambulchik
12 * All Rights Reserved
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 /*
30 * Page/Device setup
33 #include <config.h>
35 #include <stdio.h>
37 #include "globals.h"
38 #include "utils.h"
39 #ifndef QT_GUI
40 #include <Xm/Xm.h>
41 #else
42 #include <string.h>
43 #endif
44 #include "motifinc.h"
45 #include "xprotos.h"
47 #define canvas grace_get_canvas(gapp->grace)
49 typedef struct {
50 int ndest;
51 Widget top;
52 OptionStructure **opts;
53 } DestSetupUI;
55 typedef struct {
56 Widget top;
58 Widget psetup_rc;
59 Widget device_opts;
60 Widget printto;
61 OptionStructure *destination;
62 TextStructure *print_string;
63 Widget rc_filesel;
64 Widget rc_printsel;
65 Widget dest_opts;
66 TextStructure *printfile;
67 Widget pdev_rc;
68 OptionStructure *devices;
69 Widget output_frame;
70 Widget page_frame;
72 OptionStructure *page_orient;
73 OptionStructure *page_format;
75 TextStructure *page_x;
76 TextStructure *page_y;
77 OptionStructure *page_size_unit;
78 TextStructure *dev_res;
80 Widget autocrop;
82 OptionStructure *fontrast;
83 OptionStructure *color_trans;
85 DestSetupUI *destopts;
87 int current_page_units;
88 } PrintUI;
90 static PrintUI *pui = NULL;
92 static void do_pr_toggle(Widget tbut, int onoff, void *data);
93 static void do_format_toggle(OptionStructure *opt, int value, void *data);
94 static void do_orient_toggle(OptionStructure *opt, int value, void *data);
96 static int set_printer_proc(void *data);
97 void create_printfiles_popup(Widget but, void *data);
98 void create_devopts_popup(Widget but, void *data);
99 void create_destopts_popup(Widget but, void *data);
101 static void do_device_toggle(OptionStructure *opt, int value, void *data);
102 static void do_units_toggle(OptionStructure *opt, int value, void *data);
103 static void update_printer_setup(PrintUI *ui, int device_id);
104 static void update_device_setup(PrintUI *ui, int device_id);
106 static void do_print_cb(Widget but, void *data);
108 void create_printer_setup(Widget but, void *data)
110 int device;
112 set_wait_cursor();
114 if (data == NULL) {
115 device = gapp->rt->hdevice;
116 } else {
117 device = *((int *) data);
120 if (pui == NULL) {
121 int i, j, ndev;
122 Widget rc, rc1, fr, wbut;
123 Widget menubar, menupane;
124 OptionItem *options;
126 pui = xmalloc(sizeof(PrintUI));
127 memset(pui, 0, sizeof(PrintUI));
129 pui->destopts = xcalloc(gapp->rt->num_print_dests, sizeof(DestSetupUI));
131 pui->top = CreateDialog(app_shell, "Device setup");
132 DialogSetResizable(pui->top, TRUE);
134 menubar = CreateMenuBar(pui->top);
135 FormAddVChild(pui->top, menubar);
137 menupane = CreateMenu(menubar, "File", 'F', FALSE);
138 CreateMenuButton(menupane, "Print", 'P', do_print_cb, NULL);
139 CreateMenuSeparator(menupane);
140 CreateMenuButtonA(menupane, "Close", 'C', "<Key>Escape", "Esc", destroy_dialog_cb, pui->top);
142 menupane = CreateMenu(menubar, "Help", 'H', TRUE);
143 CreateMenuHelpButton(menupane, "On device setup", 'd',
144 pui->top, "doc/UsersGuide.html#print-setup");
146 WidgetManage(menubar);
148 pui->psetup_rc = CreateVContainer(pui->top);
150 fr = CreateFrame(pui->psetup_rc, "Device setup");
151 rc1 = CreateVContainer(fr);
152 pui->pdev_rc = CreateHContainer(rc1);
154 ndev = number_of_devices(canvas);
155 options = xmalloc(ndev*sizeof(OptionItem));
156 for (i = 0, j = 0; i < ndev; i++) {
157 if (!device_is_aux(canvas, i)) {
158 options[j].value = i;
159 options[j].label = get_device_name(canvas, i);
160 j++;
163 pui->devices =
164 CreateOptionChoice(pui->pdev_rc, "Device: ", 1, j, options);
165 AddOptionChoiceCB(pui->devices, do_device_toggle, pui);
166 xfree(options);
168 pui->device_opts = CreateButton(pui->pdev_rc, "Device options...");
169 AddButtonCB(pui->device_opts, create_devopts_popup, pui);
171 pui->output_frame = CreateFrame(pui->psetup_rc, "Output");
172 rc1 = CreateVContainer(pui->output_frame);
173 pui->printto = CreateToggleButton(rc1, "Print to file");
174 AddToggleButtonCB(pui->printto, do_pr_toggle, pui);
176 pui->rc_printsel = CreateHContainer(rc1);
177 if (gapp->rt->use_cups) {
178 options = xmalloc(gapp->rt->num_print_dests*sizeof(OptionItem));
180 for (i = 0; i < gapp->rt->num_print_dests; i++) {
181 options[i].value = i;
182 options[i].label = gapp->rt->print_dests[i].printer;
184 pui->destination = CreateOptionChoice(pui->rc_printsel, "Destination:",
185 0, gapp->rt->num_print_dests, options);
187 xfree(options);
189 pui->dest_opts = CreateButton(pui->rc_printsel, "Setup...");
190 AddButtonCB(pui->dest_opts, create_destopts_popup, pui);
192 } else {
193 pui->print_string = CreateText2(pui->rc_printsel,
194 "Print command:", 25);
197 pui->rc_filesel = CreateHContainer(rc1);
198 pui->printfile = CreateText2(pui->rc_filesel, "File name:", 20);
199 wbut = CreateButton(pui->rc_filesel, "Browse...");
200 AddButtonCB(wbut, create_printfiles_popup, pui);
203 pui->page_frame = CreateFrame(pui->psetup_rc, "Page");
204 rc1 = CreateVContainer(pui->page_frame);
206 rc = CreateHContainer(rc1);
208 pui->page_orient = CreatePaperOrientationChoice(rc, "Orientation:");
209 AddOptionChoiceCB(pui->page_orient, do_orient_toggle, pui);
212 pui->page_format = CreatePaperFormatChoice(rc, "Size:");
213 AddOptionChoiceCB(pui->page_format, do_format_toggle, pui);
215 rc = CreateHContainer(rc1);
216 pui->page_x = CreateText2(rc, "Dimensions:", 7);
217 pui->page_y = CreateText2(rc, "x ", 7);
218 options = xmalloc(3*sizeof(OptionItem));
219 options[0].value = 0;
220 options[0].label = "pix";
221 options[1].value = 1;
222 options[1].label = "in";
223 options[2].value = 2;
224 options[2].label = "cm";
225 pui->page_size_unit =
226 CreateOptionChoice(rc, " ", 1, 3, options);
227 AddOptionChoiceCB(pui->page_size_unit, do_units_toggle, pui);
228 xfree(options);
229 SetOptionChoice(pui->page_size_unit, pui->current_page_units);
231 pui->dev_res = CreateText2(rc1, "Resolution (dpi):", 4);
233 pui->autocrop = CreateToggleButton(rc1, "Auto crop");
235 fr = CreateFrame(pui->psetup_rc, "Fonts & Colors");
236 rc1 = CreateVContainer(fr);
238 options = xmalloc(5*sizeof(OptionItem));
239 options[0].value = FONT_RASTER_DEVICE;
240 options[0].label = "Device";
241 options[1].value = FONT_RASTER_MONO;
242 options[1].label = "Mono";
243 options[2].value = FONT_RASTER_AA_LOW;
244 options[2].label = "AA-low";
245 options[3].value = FONT_RASTER_AA_HIGH;
246 options[3].label = "AA-high";
247 options[4].value = FONT_RASTER_AA_SMART;
248 options[4].label = "AA-smart";
249 pui->fontrast = CreateOptionChoice(rc1,
250 "Font rastering:", 1, 5, options);
251 xfree(options);
253 options = xmalloc(6*sizeof(OptionItem));
254 options[0].value = COLOR_TRANS_NONE;
255 options[0].label = "None";
256 options[1].value = COLOR_TRANS_GREYSCALE;
257 options[1].label = "Grayscale";
258 options[2].value = COLOR_TRANS_BW;
259 options[2].label = "B/W";
260 options[3].value = COLOR_TRANS_NEGATIVE;
261 options[3].label = "Negative";
262 options[4].value = COLOR_TRANS_REVERSE;
263 options[4].label = "Reverse";
264 options[5].value = COLOR_TRANS_SRGB;
265 options[5].label = "sRGB";
266 pui->color_trans = CreateOptionChoice(rc1,
267 "Color transform:", 1, 6, options);
268 xfree(options);
270 CreateAACDialog(pui->top, pui->psetup_rc, set_printer_proc, pui);
273 update_printer_setup(pui, device);
275 DialogRaise(pui->top);
276 unset_wait_cursor();
279 static void update_printer_setup(PrintUI *ui, int device_id)
281 if (ui) {
282 SetOptionChoice(ui->devices, device_id);
283 update_device_setup(ui, device_id);
287 static void update_device_setup(PrintUI *ui, int device_id)
289 if (ui) {
290 char buf[GR_MAXPATHLEN], *bufptr;
291 int page_units;
292 double page_x, page_y;
293 PageFormat pf;
295 dev_gui_setup *setup_data;
297 Page_geometry pg;
298 Device_entry *dev;
300 dev = get_device_props(canvas, device_id);
301 pg = dev->pg;
303 setup_data = (dev_gui_setup *) device_get_udata(canvas, device_id);
305 if (setup_data == NULL) {
306 WidgetSetSensitive(ui->device_opts, FALSE);
307 } else {
308 WidgetSetSensitive(ui->device_opts, TRUE);
311 if (string_is_empty(gapp->rt->print_file)) {
312 char *docname = gproject_get_docname(gapp->gp);
313 if (!docname) {
314 docname = NONAME;
316 strcpy(gapp->rt->print_file, mybasename(docname));
319 /* Replace existing filename extension */
320 bufptr = strrchr(gapp->rt->print_file, '.');
321 if (bufptr) {
322 *(bufptr + 1) = '\0';
323 } else {
324 strcat(gapp->rt->print_file, ".");
326 if (dev->fext) {
327 strcat(gapp->rt->print_file, dev->fext);
330 if (gapp->rt->use_cups) {
331 SetOptionChoice(ui->destination, get_print_dest(gapp));
332 } else {
333 TextSetString(ui->print_string, get_print_cmd(gapp));
335 TextSetString(ui->printfile, gapp->rt->print_file);
337 switch (dev->type) {
338 case DEVICE_TERM:
339 WidgetUnmanage(ui->output_frame);
340 WidgetUnmanage(ui->page_frame);
341 break;
342 case DEVICE_FILE:
343 WidgetManage(ui->output_frame);
344 WidgetManage(ui->page_frame);
345 SetToggleButtonState(ui->printto, TRUE);
346 WidgetSetSensitive(ui->printto, FALSE);
347 WidgetSetSensitive(ui->rc_printsel, FALSE);
348 WidgetSetSensitive(ui->rc_filesel, TRUE);
349 break;
350 case DEVICE_PRINT:
351 WidgetManage(ui->output_frame);
352 WidgetManage(ui->page_frame);
353 SetToggleButtonState(ui->printto, get_ptofile(gapp));
354 WidgetSetSensitive(ui->printto, TRUE);
355 if (get_ptofile(gapp) == TRUE) {
356 WidgetSetSensitive(ui->rc_filesel, TRUE);
357 WidgetSetSensitive(ui->rc_printsel, FALSE);
358 } else {
359 WidgetSetSensitive(ui->rc_filesel, FALSE);
360 WidgetSetSensitive(ui->rc_printsel, TRUE);
362 break;
365 SetOptionChoice(ui->page_orient, pg.width < pg.height ?
366 PAGE_ORIENT_PORTRAIT : PAGE_ORIENT_LANDSCAPE);
368 pf = get_page_format(canvas, device_id);
369 SetOptionChoice(ui->page_format, pf);
370 if (pf == PAGE_FORMAT_CUSTOM) {
371 WidgetSetSensitive(ui->page_x->form, TRUE);
372 WidgetSetSensitive(ui->page_y->form, TRUE);
373 WidgetSetSensitive(ui->page_orient->menu, FALSE);
374 } else {
375 WidgetSetSensitive(ui->page_x->form, FALSE);
376 WidgetSetSensitive(ui->page_y->form, FALSE);
377 WidgetSetSensitive(ui->page_orient->menu, TRUE);
380 sprintf (buf, "%.0f", pg.dpi);
381 TextSetString(ui->dev_res, buf);
383 if (dev->type == DEVICE_TERM || dev->type == DEVICE_PRINT) {
384 SetToggleButtonState(ui->autocrop, FALSE);
385 WidgetSetSensitive(ui->autocrop, FALSE);
386 } else {
387 SetToggleButtonState(ui->autocrop, dev->autocrop);
388 WidgetSetSensitive(ui->autocrop, TRUE);
391 page_units = GetOptionChoice(ui->page_size_unit);
393 switch (page_units) {
394 case 0: /* pixels */
395 page_x = (float) pg.width;
396 page_y = (float) pg.height;
397 break;
398 case 1: /* inches */
399 page_x = (float) pg.width / pg.dpi;
400 page_y = (float) pg.height / pg.dpi;
401 break;
402 case 2: /* cm */
403 page_x = (float) CM_PER_INCH * pg.width / pg.dpi;
404 page_y = (float) CM_PER_INCH * pg.height / pg.dpi;
405 break;
406 default:
407 errmsg("Internal error");
408 return;
411 sprintf (buf, "%.2f", page_x);
412 TextSetString(ui->page_x, buf);
413 sprintf (buf, "%.2f", page_y);
414 TextSetString(ui->page_y, buf);
416 SetOptionChoice(ui->fontrast, dev->fontrast);
417 SetOptionChoice(ui->color_trans, dev->color_trans);
421 static int set_printer_proc(void *data)
423 PrintUI *ui = (PrintUI *) data;
424 int seldevice;
425 double page_x, page_y;
426 double dpi;
427 int page_units;
428 Device_entry *dev;
429 Page_geometry pg;
430 int do_redraw = FALSE;
432 seldevice = GetOptionChoice(ui->devices);
434 dev = get_device_props(canvas, seldevice);
436 if (dev->type != DEVICE_TERM) {
437 char *s;
439 gapp->rt->hdevice = seldevice;
440 set_ptofile(gapp, ToggleButtonGetState(ui->printto));
441 if (get_ptofile(gapp)) {
442 s = TextGetString(ui->printfile);
443 strcpy(gapp->rt->print_file, s);
444 xfree(s);
445 } else {
446 if (gapp->rt->use_cups) {
447 set_print_dest(gapp, GetOptionChoice(ui->destination));
448 } else {
449 s = TextGetString(ui->print_string);
450 set_print_cmd(gapp, s);
451 xfree(s);
455 if (xv_evalexpr(ui->page_x, &page_x) != RETURN_SUCCESS ||
456 xv_evalexpr(ui->page_y, &page_y) != RETURN_SUCCESS ||
457 page_x <= 0.0 || page_y <= 0.0) {
458 errmsg("Invalid page dimension(s)");
459 return RETURN_FAILURE;
462 if (xv_evalexpr(ui->dev_res, &dpi) != RETURN_SUCCESS ||
463 dpi <= 0.0) {
464 errmsg("Invalid dpi");
465 return RETURN_FAILURE;
468 dev->autocrop = ToggleButtonGetState(ui->autocrop);
470 page_units = GetOptionChoice(ui->page_size_unit);
472 switch (page_units) {
473 case 0:
474 pg.width = (long) page_x;
475 pg.height = (long) page_y;
476 break;
477 case 1:
478 pg.width = (long) (page_x * dpi);
479 pg.height = (long) (page_y * dpi);
480 break;
481 case 2:
482 pg.width = (long) (page_x * dpi / CM_PER_INCH);
483 pg.height = (long) (page_y * dpi / CM_PER_INCH);
484 break;
485 default:
486 errmsg("Internal error");
487 return RETURN_FAILURE;
490 pg.dpi = dpi;
492 dev->pg = pg;
495 dev->fontrast = GetOptionChoice(ui->fontrast);
496 dev->color_trans = GetOptionChoice(ui->color_trans);
498 if (seldevice == gapp->rt->tdevice) {
499 do_redraw = TRUE;
502 if (do_redraw) {
503 xdrawgraph(gapp->gp);
506 return RETURN_SUCCESS;
511 * set the print options
513 static void do_device_toggle(OptionStructure *opt, int value, void *data)
515 update_device_setup((PrintUI *) data, value);
518 static void do_pr_toggle(Widget tbut, int onoff, void *data)
520 PrintUI *ui = (PrintUI *) data;
522 if (onoff == TRUE) {
523 WidgetSetSensitive(ui->rc_filesel, TRUE);
524 WidgetSetSensitive(ui->rc_printsel, FALSE);
525 } else {
526 WidgetSetSensitive(ui->rc_filesel, FALSE);
527 WidgetSetSensitive(ui->rc_printsel, TRUE);
531 static void do_format_toggle(OptionStructure *opt, int value, void *data)
533 PrintUI *ui = (PrintUI *) data;
534 int orientation;
535 int x, y;
536 double px, py;
537 int page_units;
538 double dpi;
539 char buf[32];
541 if (value == PAGE_FORMAT_CUSTOM) {
542 WidgetSetSensitive(ui->page_x->form, TRUE);
543 WidgetSetSensitive(ui->page_y->form, TRUE);
544 WidgetSetSensitive(ui->page_orient->menu, FALSE);
545 } else {
546 WidgetSetSensitive(ui->page_x->form, FALSE);
547 WidgetSetSensitive(ui->page_y->form, FALSE);
548 WidgetSetSensitive(ui->page_orient->menu, TRUE);
552 switch (value) {
553 case PAGE_FORMAT_USLETTER:
554 x = 612;
555 y = 792;
556 break;
557 case PAGE_FORMAT_A4:
558 x = 595;
559 y = 842;
560 break;
561 case PAGE_FORMAT_CUSTOM:
562 default:
563 return;
567 page_units = GetOptionChoice(ui->page_size_unit);
569 switch (page_units) {
570 case 0: /* pixels */
571 if (xv_evalexpr(ui->dev_res, &dpi) != RETURN_SUCCESS) {
572 errmsg("Invalid dpi");
573 return;
575 px = (float) x*dpi/72.0;
576 py = (float) y*dpi/72.0;
577 break;
578 case 1: /* inches */
579 px = (float) x/72.0;
580 py = (float) y/72.0;
581 break;
582 case 2: /* cm */
583 px = (float) x/72.0*CM_PER_INCH;
584 py = (float) y/72.0*CM_PER_INCH;
585 break;
586 default:
587 errmsg("Internal error");
588 return;
591 orientation = GetOptionChoice(ui->page_orient);
593 if ((orientation == PAGE_ORIENT_LANDSCAPE && px > py) ||
594 (orientation == PAGE_ORIENT_PORTRAIT && px < py) ) {
595 sprintf (buf, "%.2f", px);
596 TextSetString(ui->page_x, buf);
597 sprintf (buf, "%.2f", py);
598 TextSetString(ui->page_y, buf);
599 } else {
600 sprintf (buf, "%.2f", py);
601 TextSetString(ui->page_x, buf);
602 sprintf (buf, "%.2f", px);
603 TextSetString(ui->page_y, buf);
607 static void do_orient_toggle(OptionStructure *opt, int value, void *data)
609 PrintUI *ui = (PrintUI *) data;
610 int orientation = value;
611 double px, py;
612 char buf[32];
614 if (xv_evalexpr(ui->page_x, &px) != RETURN_SUCCESS ||
615 xv_evalexpr(ui->page_y, &py) != RETURN_SUCCESS ) {
616 errmsg("Invalid page dimension(s)");
617 return;
620 if ((orientation == PAGE_ORIENT_LANDSCAPE && px > py) ||
621 (orientation == PAGE_ORIENT_PORTRAIT && px < py) ) {
622 sprintf (buf, "%.2f", px);
623 TextSetString(ui->page_x, buf);
624 sprintf (buf, "%.2f", py);
625 TextSetString(ui->page_y, buf);
626 } else {
627 sprintf (buf, "%.2f", py);
628 TextSetString(ui->page_x, buf);
629 sprintf (buf, "%.2f", px);
630 TextSetString(ui->page_y, buf);
634 static int do_prfilesel_proc(FSBStructure *fsb, char *filename, void *data)
636 PrintUI *ui = (PrintUI *) data;
638 TextSetString(ui->printfile, filename);
639 strcpy(gapp->rt->print_file, filename);
641 return TRUE;
644 void create_printfiles_popup(Widget but, void *data)
646 PrintUI *ui = (PrintUI *) data;
647 static FSBStructure *fsb = NULL;
648 int device;
649 Device_entry *dev;
650 char buf[16];
652 set_wait_cursor();
654 if (fsb == NULL) {
655 fsb = CreateFSBDialog(app_shell, "Select print file");
656 AddFSBDialogCB(fsb, do_prfilesel_proc, ui);
657 WidgetManage(fsb->FSB);
660 device = GetOptionChoice(ui->devices);
661 dev = get_device_props(canvas, device);
663 sprintf(buf, "*.%s", dev->fext);
664 FSBDialogSetPattern(fsb, buf);
666 DialogRaise(fsb->FSB);
668 unset_wait_cursor();
671 void create_devopts_popup(Widget but, void *data)
673 PrintUI *ui = (PrintUI *) data;
674 int device_id;
675 Device_entry *dev;
676 dev_gui_setup *setup_data;
678 device_id = GetOptionChoice(ui->devices);
679 dev = get_device_props(canvas, device_id);
681 setup_data = (dev_gui_setup *) device_get_udata(canvas, device_id);
683 if (setup_data == NULL || setup_data->setup == NULL) {
684 /* Should never come to here */
685 errmsg("No options can be set for this device");
686 } else {
687 (setup_data->setup)(canvas, setup_data->ui);
691 static int set_destopts_proc(void *data)
693 DestSetupUI *dsui = (DestSetupUI *) data;
694 PrintDest *pd = &gapp->rt->print_dests[dsui->ndest];
695 int i, j, nopts = 0;
697 for (i = 0; i < pd->nogroups; i++) {
698 PrintOptGroup *og = &pd->ogroups[i];
700 for (j = 0; j < og->nopts; j++) {
701 PrintOption *po = &og->opts[j];
703 po->selected = GetOptionChoice(dsui->opts[nopts]);
704 nopts++;
708 return RETURN_SUCCESS;
711 void create_destopts_popup(Widget but, void *data)
713 PrintUI *ui = (PrintUI *) data;
714 int ndest = GetOptionChoice(ui->destination);
715 DestSetupUI *dsui = &ui->destopts[ndest];
717 if (dsui->top == NULL) {
718 PrintDest *pd = &gapp->rt->print_dests[ndest];
719 Widget top, tab;
720 int i, j, k, nopts = 0;
721 char buf[128];
723 dsui->ndest = ndest;
724 dsui->opts = xmalloc(pd->nopts*SIZEOF_VOID_P);
726 sprintf(buf, "CUPS setup: %s", pd->printer);
727 top = CreateDialog(app_shell, buf);
729 tab = CreateTab(top);
731 for (i = 0; i < pd->nogroups; i++) {
732 PrintOptGroup *og = &pd->ogroups[i];
733 Widget page = CreateTabPage(tab, og->text);
734 #ifndef QT_GUI
735 XtVaSetValues(page, XmNpacking, XmPACK_COLUMN,
736 XmNnumColumns, og->nopts,
737 XmNorientation, XmHORIZONTAL,
738 XmNentryAlignment, XmALIGNMENT_END,
739 XmNadjustLast, False,
740 XmNisAligned, True,
741 NULL);
742 #endif
744 for (j = 0; j < og->nopts; j++) {
745 PrintOption *po = &og->opts[j];
746 int nchoises = po->choices->size;
747 OptionItem *options;
749 sprintf(buf, "%s:", po->text);
750 CreateLabel(page, buf);
752 options = xmalloc(nchoises*sizeof(OptionItem));
753 for (k = 0; k < nchoises; k++) {
754 options[k].value = po->choices->entries[k].key;
755 options[k].label = po->choices->entries[k].descr;
757 dsui->opts[nopts] = CreateOptionChoice(page, "", 0, nchoises, options);
758 xfree(options);
760 SetOptionChoice(dsui->opts[nopts], po->selected);
761 nopts++;
764 if (strings_are_equal(og->text, "General")) {
765 SelectTabPage(tab, page);
769 CreateAACDialog(top, tab, set_destopts_proc, dsui);
771 dsui->top = top;
774 DialogRaise(dsui->top);
777 static void do_units_toggle(OptionStructure *opt, int value, void *data)
779 PrintUI *ui = (PrintUI *) data;
780 char buf[32];
781 double page_x, page_y;
782 double dev_res;
783 int page_units = value;
785 if (xv_evalexpr(ui->page_x, &page_x) != RETURN_SUCCESS ||
786 xv_evalexpr(ui->page_y, &page_y) != RETURN_SUCCESS ) {
787 errmsg("Invalid page dimension(s)");
788 return;
791 if (xv_evalexpr(ui->dev_res, &dev_res) != RETURN_SUCCESS) {
792 errmsg("Invalid device resolution(s)");
793 return;
796 if (dev_res <= 0.0) {
797 errmsg("Device resolution(s) <= 0");
798 return;
801 if (ui->current_page_units == page_units) {
803 } else if (ui->current_page_units == 0 && page_units == 1) {
804 page_x /= dev_res;
805 page_y /= dev_res;
806 } else if (ui->current_page_units == 0 && page_units == 2) {
807 page_x /= (dev_res/CM_PER_INCH);
808 page_y /= (dev_res/CM_PER_INCH);
809 } else if (ui->current_page_units == 1 && page_units == 0) {
810 page_x *= dev_res;
811 page_y *= dev_res;
812 } else if (ui->current_page_units == 1 && page_units == 2) {
813 page_x *= CM_PER_INCH;
814 page_y *= CM_PER_INCH;
815 } else if (ui->current_page_units == 2 && page_units == 0) {
816 page_x *= (dev_res/CM_PER_INCH);
817 page_y *= (dev_res/CM_PER_INCH);
818 } else if (ui->current_page_units == 2 && page_units == 1) {
819 page_x /= CM_PER_INCH;
820 page_y /= CM_PER_INCH;
821 } else {
822 errmsg("Internal error");
823 return;
826 ui->current_page_units = page_units;
828 sprintf (buf, "%.2f", page_x);
829 TextSetString(ui->page_x, buf);
830 sprintf (buf, "%.2f", page_y);
831 TextSetString(ui->page_y, buf);
834 static void do_print_cb(Widget but, void *data)
836 set_wait_cursor();
837 do_hardcopy(gapp->gp);
838 unset_wait_cursor();