2
* Grace - GRaphing, Advanced Computation and Exploration of data
4
* Home page: http://plasma-gate.weizmann.ac.il/Grace/
6
* Copyright (c) 1991-1995 Paul J Turner, Portland, OR
7
* Copyright (c) 1996-2000 Grace Development Team
9
* Maintained by Evgeny Stambulchik <fnevgeny@plasma-gate.weizmann.ac.il>
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.
41
#include "graphutils.h"
48
extern char print_file[];
50
static int current_page_units = 0;
52
static Widget psetup_frame;
53
static Widget psetup_rc;
54
static Widget device_opts_item;
55
static Widget printto_item;
56
static Widget print_string_item;
57
static Widget rc_filesel;
58
static Widget printfile_item;
59
static Widget pdev_rc;
60
static OptionStructure *devices_item;
61
static Widget output_frame;
62
static OptionStructure *page_orient_item;
63
static OptionStructure *page_format_item;
64
static Widget page_x_item;
65
static Widget page_y_item;
66
static OptionStructure *page_size_unit_item;
67
static Widget dev_res_item;
68
static Widget fontaa_item;
69
static Widget devfont_item;
70
static Widget dsync_item, psync_item;
72
static void do_pr_toggle(int onoff, void *data);
73
static void do_format_toggle(int value, void *data);
74
static void do_orient_toggle(int value, void *data);
76
static int set_printer_proc(void *data);
77
void create_printfiles_popup(void *data);
78
void create_devopts_popup(void *data);
80
static void do_device_toggle(int value, void *data);
81
static void do_units_toggle(int value, void *data);
82
static void update_printer_setup(int device_id);
83
static void update_device_setup(int device_id);
85
static void do_print_cb(void *data);
87
void create_printer_setup(void *data)
96
device = *((int *) data);
99
if (psetup_frame == NULL) {
101
Widget rc, rc1, fr, wbut;
102
Widget menubar, menupane;
103
OptionItem *option_items;
105
psetup_frame = CreateDialogForm(app_shell, "Device setup");
106
SetDialogFormResizable(psetup_frame, TRUE);
108
menubar = CreateMenuBar(psetup_frame);
109
AddDialogFormChild(psetup_frame, menubar);
111
menupane = CreateMenu(menubar, "File", 'F', FALSE);
112
CreateMenuButton(menupane, "Print", 'P', do_print_cb, NULL);
113
CreateMenuSeparator(menupane);
114
CreateMenuCloseButton(menupane, psetup_frame);
116
menupane = CreateMenu(menubar, "Options", 'O', FALSE);
117
dsync_item = CreateMenuToggle(menupane,
118
"Sync page size of all devices", 'S', NULL, NULL);
119
SetToggleButtonState(dsync_item, TRUE);
120
psync_item = CreateMenuToggle(menupane,
121
"Rescale plot on page size change", 'R', NULL, NULL);
122
SetToggleButtonState(psync_item, FALSE);
124
menupane = CreateMenu(menubar, "Help", 'H', TRUE);
125
CreateMenuHelpButton(menupane, "On device setup", 'd',
126
psetup_frame, "doc/UsersGuide.html#print-setup");
128
ManageChild(menubar);
130
psetup_rc = CreateVContainer(psetup_frame);
132
fr = CreateFrame(psetup_rc, "Device setup");
133
rc1 = CreateVContainer(fr);
134
pdev_rc = CreateHContainer(rc1);
136
ndev = number_of_devices();
137
option_items = xmalloc(ndev*sizeof(OptionItem));
138
for (i = 0; i < ndev; i++) {
139
option_items[i].value = i;
140
option_items[i].label = get_device_name(i);
143
CreateOptionChoice(pdev_rc, "Device: ", 1, ndev, option_items);
144
AddOptionChoiceCB(devices_item, do_device_toggle, NULL);
147
device_opts_item = CreateButton(pdev_rc, "Device options...");
148
AddButtonCB(device_opts_item, create_devopts_popup, NULL);
150
output_frame = CreateFrame(psetup_rc, "Output");
151
rc1 = CreateVContainer(output_frame);
152
printto_item = CreateToggleButton(rc1, "Print to file");
153
AddToggleButtonCB(printto_item, do_pr_toggle, NULL);
155
print_string_item = CreateTextItem2(rc1, 25, "Print command:");
157
rc_filesel = CreateHContainer(rc1);
158
printfile_item = CreateTextItem2(rc_filesel, 20, "File name:");
159
wbut = CreateButton(rc_filesel, "Browse...");
160
AddButtonCB(wbut, create_printfiles_popup, NULL);
163
fr = CreateFrame(psetup_rc, "Page");
164
rc1 = CreateVContainer(fr);
166
rc = CreateHContainer(rc1);
168
option_items = xmalloc(2*sizeof(OptionItem));
169
option_items[0].value = PAGE_ORIENT_LANDSCAPE;
170
option_items[0].label = "Landscape";
171
option_items[1].value = PAGE_ORIENT_PORTRAIT;
172
option_items[1].label = "Portrait";
174
CreateOptionChoice(rc, "Orientation: ", 1, 2, option_items);
175
AddOptionChoiceCB(page_orient_item, do_orient_toggle, NULL);
179
option_items = xmalloc(3*sizeof(OptionItem));
180
option_items[0].value = PAGE_FORMAT_CUSTOM;
181
option_items[0].label = "Custom";
182
option_items[1].value = PAGE_FORMAT_USLETTER;
183
option_items[1].label = "Letter";
184
option_items[2].value = PAGE_FORMAT_A4;
185
option_items[2].label = "A4";
187
CreateOptionChoice(rc, "Size: ", 1, 3, option_items);
188
AddOptionChoiceCB(page_format_item, do_format_toggle, NULL);
191
rc = CreateHContainer(rc1);
192
page_x_item = CreateTextItem2(rc, 7, "Dimensions:");
193
page_y_item = CreateTextItem2(rc, 7, "x ");
194
option_items = xmalloc(3*sizeof(OptionItem));
195
option_items[0].value = 0;
196
option_items[0].label = "pix";
197
option_items[1].value = 1;
198
option_items[1].label = "in";
199
option_items[2].value = 2;
200
option_items[2].label = "cm";
201
page_size_unit_item =
202
CreateOptionChoice(rc, " ", 1, 3, option_items);
203
AddOptionChoiceCB(page_size_unit_item, do_units_toggle, NULL);
205
SetOptionChoice(page_size_unit_item, current_page_units);
207
dev_res_item = CreateTextItem2(rc1, 4, "Resolution (dpi):");
210
fr = CreateFrame(psetup_rc, "Fonts");
211
rc1 = CreateVContainer(fr);
212
fontaa_item = CreateToggleButton(rc1, "Enable font antialiasing");
213
devfont_item = CreateToggleButton(rc1, "Use device fonts");
215
CreateAACDialog(psetup_frame, psetup_rc, set_printer_proc, NULL);
218
update_printer_setup(device);
220
RaiseWindow(GetParent(psetup_frame));
224
static void update_printer_setup(int device_id)
227
SetOptionChoice(devices_item, device_id);
228
update_device_setup(device_id);
232
static void update_device_setup(int device_id)
234
char buf[GR_MAXPATHLEN], *bufptr;
236
double page_x, page_y;
243
dev = get_device_props(device_id);
246
if (dev.setup == NULL) {
247
SetSensitive(device_opts_item, False);
249
SetSensitive(device_opts_item, True);
252
if (print_file == NULL || print_file[0] == '\0') {
253
strcpy(print_file, mybasename(get_docname()));
256
/* Replace existing filename extension */
257
bufptr = strrchr(print_file, '.');
259
*(bufptr + 1) = '\0';
261
strcat(print_file, ".");
263
strcat(print_file, dev.fext);
265
xv_setstr(printfile_item, print_file);
267
xv_setstr(print_string_item, get_print_cmd());
271
UnmanageChild(output_frame);
274
ManageChild(output_frame);
275
SetToggleButtonState(printto_item, TRUE);
276
SetSensitive(printto_item, False);
277
SetSensitive(GetParent(print_string_item), False);
278
SetSensitive(rc_filesel, True);
281
ManageChild(output_frame);
282
SetToggleButtonState(printto_item, get_ptofile());
283
SetSensitive(printto_item, True);
284
if (get_ptofile() == TRUE) {
285
SetSensitive(rc_filesel, True);
286
SetSensitive(GetParent(print_string_item), False);
288
SetSensitive(rc_filesel, False);
289
SetSensitive(GetParent(print_string_item), True);
294
SetOptionChoice(page_orient_item, pg.width < pg.height ?
295
PAGE_ORIENT_PORTRAIT : PAGE_ORIENT_LANDSCAPE);
297
pf = get_page_format(device_id);
298
SetOptionChoice(page_format_item, pf);
299
if (pf == PAGE_FORMAT_CUSTOM) {
300
SetSensitive(page_x_item, True);
301
SetSensitive(page_y_item, True);
302
SetSensitive(page_orient_item->menu, False);
304
SetSensitive(page_x_item, False);
305
SetSensitive(page_y_item, False);
306
SetSensitive(page_orient_item->menu, True);
309
sprintf (buf, "%.0f", pg.dpi);
310
xv_setstr(dev_res_item, buf);
312
page_units = GetOptionChoice(page_size_unit_item);
314
switch (page_units) {
316
page_x = (float) pg.width;
317
page_y = (float) pg.height;
320
page_x = (float) pg.width / pg.dpi;
321
page_y = (float) pg.height / pg.dpi;
324
page_x = (float) CM_PER_INCH * pg.width / pg.dpi;
325
page_y = (float) CM_PER_INCH * pg.height / pg.dpi;
328
errmsg("Internal error");
332
sprintf (buf, "%.2f", page_x);
333
xv_setstr(page_x_item, buf);
334
sprintf (buf, "%.2f", page_y);
335
xv_setstr(page_y_item, buf);
337
SetToggleButtonState(fontaa_item, dev.fontaa);
339
SetToggleButtonState(devfont_item, dev.devfonts);
343
static int set_printer_proc(void *data)
346
double page_x, page_y;
351
int do_redraw = FALSE;
353
seldevice = GetOptionChoice(devices_item);
355
dev = get_device_props(seldevice);
357
if (dev.type != DEVICE_TERM) {
359
set_ptofile(GetToggleButtonState(printto_item));
361
strcpy(print_file, xv_getstr(printfile_item));
363
set_print_cmd(xv_getstr(print_string_item));
367
dev.devfonts = GetToggleButtonState(devfont_item);
368
dev.fontaa = GetToggleButtonState(fontaa_item);
370
if (xv_evalexpr(page_x_item, &page_x) != RETURN_SUCCESS ||
371
xv_evalexpr(page_y_item, &page_y) != RETURN_SUCCESS ) {
372
errmsg("Invalid page dimension(s)");
373
return RETURN_FAILURE;
376
if (xv_evalexpr(dev_res_item, &dpi) != RETURN_SUCCESS || dpi <= 0.0) {
377
errmsg("Invalid dpi");
378
return RETURN_FAILURE;
381
page_units = GetOptionChoice(page_size_unit_item);
383
switch (page_units) {
385
pg.width = (long) page_x;
386
pg.height = (long) page_y;
389
pg.width = (long) (page_x * dpi);
390
pg.height = (long) (page_y * dpi);
393
pg.width = (long) (page_x * dpi / CM_PER_INCH);
394
pg.height = (long) (page_y * dpi / CM_PER_INCH);
397
errmsg("Internal error");
398
return RETURN_FAILURE;
403
if (GetToggleButtonState(dsync_item) == TRUE) {
404
set_page_dimensions((int) rint(72.0*pg.width/pg.dpi),
405
(int) rint(72.0*pg.height/pg.dpi),
406
GetToggleButtonState(psync_item) == TRUE);
411
if (set_device_props(seldevice, dev) != RETURN_SUCCESS) {
412
errmsg("Invalid page dimensions or DPI");
413
return RETURN_FAILURE;
416
if (seldevice == tdevice) {
424
return RETURN_SUCCESS;
429
* set the print options
431
static void do_device_toggle(int value, void *data)
433
update_device_setup(value);
436
static void do_pr_toggle(int onoff, void *data)
439
SetSensitive(rc_filesel, True);
440
SetSensitive(GetParent(print_string_item), False);
442
SetSensitive(rc_filesel, False);
443
SetSensitive(GetParent(print_string_item), True);
447
static void do_format_toggle(int value, void *data)
456
if (value == PAGE_FORMAT_CUSTOM) {
457
SetSensitive(page_x_item, True);
458
SetSensitive(page_y_item, True);
459
SetSensitive(page_orient_item->menu, False);
461
SetSensitive(page_x_item, False);
462
SetSensitive(page_y_item, False);
463
SetSensitive(page_orient_item->menu, True);
468
case PAGE_FORMAT_USLETTER:
476
case PAGE_FORMAT_CUSTOM:
482
page_units = GetOptionChoice(page_size_unit_item);
484
switch (page_units) {
486
if (xv_evalexpr(dev_res_item, &dpi) != RETURN_SUCCESS) {
487
errmsg("Invalid dpi");
490
px = (float) x*dpi/72.0;
491
py = (float) y*dpi/72.0;
498
px = (float) x/72.0*CM_PER_INCH;
499
py = (float) y/72.0*CM_PER_INCH;
502
errmsg("Internal error");
506
orientation = GetOptionChoice(page_orient_item);
508
if ((orientation == PAGE_ORIENT_LANDSCAPE && px > py) ||
509
(orientation == PAGE_ORIENT_PORTRAIT && px < py) ) {
510
sprintf (buf, "%.2f", px);
511
xv_setstr(page_x_item, buf);
512
sprintf (buf, "%.2f", py);
513
xv_setstr(page_y_item, buf);
515
sprintf (buf, "%.2f", py);
516
xv_setstr(page_x_item, buf);
517
sprintf (buf, "%.2f", px);
518
xv_setstr(page_y_item, buf);
522
static void do_orient_toggle(int value, void *data)
524
int orientation = value;
528
if (xv_evalexpr(page_x_item, &px) != RETURN_SUCCESS ||
529
xv_evalexpr(page_y_item, &py) != RETURN_SUCCESS ) {
530
errmsg("Invalid page dimension(s)");
534
if ((orientation == PAGE_ORIENT_LANDSCAPE && px > py) ||
535
(orientation == PAGE_ORIENT_PORTRAIT && px < py) ) {
536
sprintf (buf, "%.2f", px);
537
xv_setstr(page_x_item, buf);
538
sprintf (buf, "%.2f", py);
539
xv_setstr(page_y_item, buf);
541
sprintf (buf, "%.2f", py);
542
xv_setstr(page_x_item, buf);
543
sprintf (buf, "%.2f", px);
544
xv_setstr(page_y_item, buf);
548
static int do_prfilesel_proc(char *filename, void *data)
550
xv_setstr(printfile_item, filename);
551
strcpy(print_file, filename);
552
XtVaSetValues(printfile_item, XmNcursorPosition, strlen(filename), NULL);
556
void create_printfiles_popup(void *data)
558
static FSBStructure *fsb = NULL;
566
fsb = CreateFileSelectionBox(app_shell, "Select print file");
567
AddFileSelectionBoxCB(fsb, do_prfilesel_proc, NULL);
568
ManageChild(fsb->FSB);
571
device = GetOptionChoice(devices_item);
572
dev = get_device_props(device);
574
sprintf(buf, "*.%s", dev.fext);
575
SetFileSelectionBoxPattern(fsb, buf);
577
RaiseWindow(fsb->dialog);
582
void create_devopts_popup(void *data)
587
device_id = GetOptionChoice(devices_item);
588
dev = get_device_props(device_id);
589
if (dev.setup == NULL) {
590
/* Should never come to here */
591
errmsg("No options can be set for this device");
597
static void do_units_toggle(int value, void *data)
600
double page_x, page_y;
602
int page_units = value;
604
if (xv_evalexpr(page_x_item, &page_x) != RETURN_SUCCESS ||
605
xv_evalexpr(page_y_item, &page_y) != RETURN_SUCCESS ) {
606
errmsg("Invalid page dimension(s)");
610
if (xv_evalexpr(dev_res_item, &dev_res) != RETURN_SUCCESS) {
611
errmsg("Invalid device resolution(s)");
615
if (dev_res <= 0.0) {
616
errmsg("Device resolution(s) <= 0");
620
if (current_page_units == page_units) {
622
} else if (current_page_units == 0 && page_units == 1) {
625
} else if (current_page_units == 0 && page_units == 2) {
626
page_x /= (dev_res/CM_PER_INCH);
627
page_y /= (dev_res/CM_PER_INCH);
628
} else if (current_page_units == 1 && page_units == 0) {
631
} else if (current_page_units == 1 && page_units == 2) {
632
page_x *= CM_PER_INCH;
633
page_y *= CM_PER_INCH;
634
} else if (current_page_units == 2 && page_units == 0) {
635
page_x *= (dev_res/CM_PER_INCH);
636
page_y *= (dev_res/CM_PER_INCH);
637
} else if (current_page_units == 2 && page_units == 1) {
638
page_x /= CM_PER_INCH;
639
page_y /= CM_PER_INCH;
641
errmsg("Internal error");
645
current_page_units = page_units;
647
sprintf (buf, "%.2f", page_x);
648
xv_setstr(page_x_item, buf);
649
sprintf (buf, "%.2f", page_y);
650
xv_setstr(page_y_item, buf);
653
static void do_print_cb(void *data)