~ubuntu-branches/ubuntu/karmic/grace/karmic

« back to all changes in this revision

Viewing changes to src/printwin.c

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2002-03-19 14:19:58 UTC
  • Revision ID: james.westby@ubuntu.com-20020319141958-5gxna6vo1ek3zjml
Tags: upstream-5.1.7
ImportĀ upstreamĀ versionĀ 5.1.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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-2000 Grace Development Team
 
8
 * 
 
9
 * Maintained by Evgeny Stambulchik <fnevgeny@plasma-gate.weizmann.ac.il>
 
10
 * 
 
11
 * 
 
12
 *                           All Rights Reserved
 
13
 * 
 
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.
 
18
 * 
 
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.
 
23
 * 
 
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.
 
27
 */
 
28
 
 
29
/* 
 
30
 * Page/Device setup
 
31
 */
 
32
 
 
33
#include <config.h>
 
34
 
 
35
#include <stdio.h>
 
36
 
 
37
#include "cmath.h"
 
38
#include "globals.h"
 
39
#include "device.h"
 
40
#include "utils.h"
 
41
#include "graphutils.h"
 
42
#include "plotone.h"
 
43
 
 
44
#include "motifinc.h"
 
45
#include "protos.h"
 
46
 
 
47
 
 
48
extern char print_file[];
 
49
 
 
50
static int current_page_units = 0;
 
51
 
 
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;
 
71
 
 
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);
 
75
 
 
76
static int set_printer_proc(void *data);
 
77
void create_printfiles_popup(void *data);
 
78
void create_devopts_popup(void *data);
 
79
 
 
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);
 
84
 
 
85
static void do_print_cb(void *data);
 
86
 
 
87
void create_printer_setup(void *data)
 
88
{
 
89
    int device;
 
90
    
 
91
    set_wait_cursor();
 
92
    
 
93
    if (data == NULL) {
 
94
        device = hdevice;
 
95
    } else {
 
96
        device = *((int *) data);
 
97
    }
 
98
    
 
99
    if (psetup_frame == NULL) {
 
100
        int i, ndev;
 
101
        Widget rc, rc1, fr, wbut;
 
102
        Widget menubar, menupane;
 
103
        OptionItem *option_items;
 
104
 
 
105
        psetup_frame = CreateDialogForm(app_shell, "Device setup");
 
106
        SetDialogFormResizable(psetup_frame, TRUE);
 
107
 
 
108
        menubar = CreateMenuBar(psetup_frame);
 
109
        AddDialogFormChild(psetup_frame, menubar);
 
110
        
 
111
        menupane = CreateMenu(menubar, "File", 'F', FALSE);
 
112
        CreateMenuButton(menupane, "Print", 'P', do_print_cb, NULL);
 
113
        CreateMenuSeparator(menupane);
 
114
        CreateMenuCloseButton(menupane, psetup_frame);
 
115
 
 
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);
 
123
 
 
124
        menupane = CreateMenu(menubar, "Help", 'H', TRUE);
 
125
        CreateMenuHelpButton(menupane, "On device setup", 'd',
 
126
            psetup_frame, "doc/UsersGuide.html#print-setup");
 
127
 
 
128
        ManageChild(menubar);
 
129
 
 
130
        psetup_rc = CreateVContainer(psetup_frame);
 
131
 
 
132
        fr = CreateFrame(psetup_rc, "Device setup");
 
133
        rc1 = CreateVContainer(fr);
 
134
        pdev_rc = CreateHContainer(rc1);
 
135
 
 
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);
 
141
        }
 
142
        devices_item =
 
143
            CreateOptionChoice(pdev_rc, "Device: ", 1, ndev, option_items);
 
144
        AddOptionChoiceCB(devices_item, do_device_toggle, NULL);
 
145
        xfree(option_items);
 
146
        
 
147
        device_opts_item = CreateButton(pdev_rc, "Device options...");
 
148
        AddButtonCB(device_opts_item, create_devopts_popup, NULL);
 
149
        
 
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);
 
154
 
 
155
        print_string_item = CreateTextItem2(rc1, 25, "Print command:");
 
156
 
 
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);
 
161
 
 
162
        
 
163
        fr = CreateFrame(psetup_rc, "Page");
 
164
        rc1 = CreateVContainer(fr);
 
165
        
 
166
        rc = CreateHContainer(rc1);
 
167
 
 
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";
 
173
        page_orient_item =
 
174
            CreateOptionChoice(rc, "Orientation: ", 1, 2, option_items);
 
175
        AddOptionChoiceCB(page_orient_item, do_orient_toggle, NULL);
 
176
        xfree(option_items);
 
177
 
 
178
 
 
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";
 
186
        page_format_item =
 
187
            CreateOptionChoice(rc, "Size: ", 1, 3, option_items);
 
188
        AddOptionChoiceCB(page_format_item, do_format_toggle, NULL);
 
189
        xfree(option_items);
 
190
 
 
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);
 
204
        xfree(option_items);
 
205
        SetOptionChoice(page_size_unit_item, current_page_units);
 
206
 
 
207
        dev_res_item = CreateTextItem2(rc1, 4, "Resolution (dpi):");
 
208
 
 
209
 
 
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");
 
214
        
 
215
        CreateAACDialog(psetup_frame, psetup_rc, set_printer_proc, NULL);
 
216
    }
 
217
    
 
218
    update_printer_setup(device);
 
219
    
 
220
    RaiseWindow(GetParent(psetup_frame));
 
221
    unset_wait_cursor();
 
222
}
 
223
 
 
224
static void update_printer_setup(int device_id)
 
225
{
 
226
    if (psetup_frame) {
 
227
        SetOptionChoice(devices_item, device_id);
 
228
        update_device_setup(device_id);
 
229
    }
 
230
}
 
231
 
 
232
static void update_device_setup(int device_id)
 
233
{
 
234
    char buf[GR_MAXPATHLEN], *bufptr;
 
235
    int page_units;
 
236
    double page_x, page_y;
 
237
    PageFormat pf;
 
238
    
 
239
    Page_geometry pg;
 
240
    Device_entry dev;
 
241
    
 
242
    if (psetup_frame) {
 
243
        dev = get_device_props(device_id);
 
244
        pg = dev.pg;
 
245
                
 
246
        if (dev.setup == NULL) {
 
247
            SetSensitive(device_opts_item, False);
 
248
        } else {
 
249
            SetSensitive(device_opts_item, True);
 
250
        }
 
251
 
 
252
        if (print_file == NULL || print_file[0] == '\0') {
 
253
            strcpy(print_file, mybasename(get_docname())); 
 
254
        }
 
255
        
 
256
        /* Replace existing filename extension */
 
257
        bufptr = strrchr(print_file, '.');
 
258
        if (bufptr) {
 
259
            *(bufptr + 1) = '\0';
 
260
        } else {
 
261
            strcat(print_file, ".");
 
262
        }
 
263
        strcat(print_file, dev.fext);
 
264
        
 
265
        xv_setstr(printfile_item, print_file);
 
266
                
 
267
        xv_setstr(print_string_item, get_print_cmd());
 
268
        
 
269
        switch (dev.type) {
 
270
        case DEVICE_TERM:
 
271
            UnmanageChild(output_frame);
 
272
            break;
 
273
        case DEVICE_FILE:
 
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);
 
279
            break;
 
280
        case DEVICE_PRINT:
 
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);
 
287
            } else {
 
288
                SetSensitive(rc_filesel, False);
 
289
                SetSensitive(GetParent(print_string_item), True);
 
290
            }
 
291
            break;
 
292
        }
 
293
        
 
294
        SetOptionChoice(page_orient_item, pg.width < pg.height ?
 
295
            PAGE_ORIENT_PORTRAIT : PAGE_ORIENT_LANDSCAPE);
 
296
        
 
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);
 
303
        } else {
 
304
            SetSensitive(page_x_item, False);
 
305
            SetSensitive(page_y_item, False);
 
306
            SetSensitive(page_orient_item->menu, True);
 
307
        }
 
308
        
 
309
        sprintf (buf, "%.0f", pg.dpi); 
 
310
        xv_setstr(dev_res_item, buf);
 
311
        
 
312
        page_units = GetOptionChoice(page_size_unit_item);
 
313
        
 
314
        switch (page_units) {
 
315
        case 0:     /* pixels */
 
316
            page_x = (float) pg.width;
 
317
            page_y = (float) pg.height;
 
318
            break;
 
319
        case 1:      /* inches */
 
320
            page_x = (float) pg.width / pg.dpi;
 
321
            page_y = (float) pg.height / pg.dpi;
 
322
            break;
 
323
        case 2:      /* cm */ 
 
324
            page_x = (float) CM_PER_INCH * pg.width / pg.dpi;
 
325
            page_y = (float) CM_PER_INCH * pg.height / pg.dpi;
 
326
            break;
 
327
        default:
 
328
            errmsg("Internal error");
 
329
            return;
 
330
        }
 
331
        
 
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);
 
336
        
 
337
        SetToggleButtonState(fontaa_item, dev.fontaa);
 
338
        
 
339
        SetToggleButtonState(devfont_item, dev.devfonts);
 
340
    }
 
341
}
 
342
 
 
343
static int set_printer_proc(void *data)
 
344
{
 
345
    int seldevice;
 
346
    double page_x, page_y;
 
347
    double dpi;
 
348
    int page_units;
 
349
    Device_entry dev;
 
350
    Page_geometry pg;
 
351
    int do_redraw = FALSE;
 
352
    
 
353
    seldevice = GetOptionChoice(devices_item);
 
354
 
 
355
    dev = get_device_props(seldevice);
 
356
 
 
357
    if (dev.type != DEVICE_TERM) {
 
358
        hdevice = seldevice;
 
359
        set_ptofile(GetToggleButtonState(printto_item));
 
360
        if (get_ptofile()) {
 
361
            strcpy(print_file, xv_getstr(printfile_item));
 
362
        } else {
 
363
            set_print_cmd(xv_getstr(print_string_item));
 
364
        }
 
365
    }
 
366
    
 
367
    dev.devfonts = GetToggleButtonState(devfont_item);
 
368
    dev.fontaa = GetToggleButtonState(fontaa_item);
 
369
    
 
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;
 
374
    }
 
375
 
 
376
    if (xv_evalexpr(dev_res_item, &dpi) != RETURN_SUCCESS || dpi <= 0.0) {
 
377
        errmsg("Invalid dpi");
 
378
        return RETURN_FAILURE;
 
379
    }
 
380
 
 
381
    page_units = GetOptionChoice(page_size_unit_item);
 
382
 
 
383
    switch (page_units) {
 
384
    case 0: 
 
385
        pg.width =  (long) page_x;
 
386
        pg.height = (long) page_y;
 
387
        break;
 
388
    case 1: 
 
389
        pg.width =  (long) (page_x * dpi);
 
390
        pg.height = (long) (page_y * dpi);
 
391
        break;
 
392
    case 2: 
 
393
        pg.width =  (long) (page_x * dpi / CM_PER_INCH);
 
394
        pg.height = (long) (page_y * dpi / CM_PER_INCH);
 
395
        break;
 
396
    default:
 
397
        errmsg("Internal error");
 
398
        return RETURN_FAILURE;
 
399
    }
 
400
    
 
401
    pg.dpi = dpi;
 
402
    
 
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);
 
407
        do_redraw = TRUE;
 
408
    }
 
409
    
 
410
    dev.pg = pg;
 
411
    if (set_device_props(seldevice, dev) != RETURN_SUCCESS) {
 
412
        errmsg("Invalid page dimensions or DPI");
 
413
        return RETURN_FAILURE;
 
414
    }
 
415
    
 
416
    if (seldevice == tdevice) {
 
417
        do_redraw = TRUE;
 
418
    }
 
419
    
 
420
    if (do_redraw) {
 
421
        drawgraph();
 
422
    }
 
423
    
 
424
    return RETURN_SUCCESS;
 
425
}
 
426
 
 
427
 
 
428
/*
 
429
 * set the print options
 
430
 */
 
431
static void do_device_toggle(int value, void *data)
 
432
 
433
    update_device_setup(value);
 
434
}
 
435
 
 
436
static void do_pr_toggle(int onoff, void *data)
 
437
{
 
438
    if (onoff == TRUE) {
 
439
        SetSensitive(rc_filesel, True);
 
440
        SetSensitive(GetParent(print_string_item), False);
 
441
    } else {
 
442
        SetSensitive(rc_filesel, False);
 
443
        SetSensitive(GetParent(print_string_item), True);
 
444
    }
 
445
}
 
446
 
 
447
static void do_format_toggle(int value, void *data)
 
448
{
 
449
    int orientation;
 
450
    int x, y;
 
451
    double px, py;
 
452
    int page_units;
 
453
    double dpi;
 
454
    char buf[32];
 
455
    
 
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);
 
460
    } else {
 
461
        SetSensitive(page_x_item, False);
 
462
        SetSensitive(page_y_item, False);
 
463
        SetSensitive(page_orient_item->menu, True);
 
464
    }
 
465
    
 
466
    
 
467
    switch (value) {
 
468
    case PAGE_FORMAT_USLETTER:
 
469
        x = 612;
 
470
        y = 792;
 
471
        break;
 
472
    case PAGE_FORMAT_A4:
 
473
        x = 595;
 
474
        y = 842;
 
475
        break;
 
476
    case PAGE_FORMAT_CUSTOM:
 
477
    default:
 
478
        return;
 
479
    }
 
480
 
 
481
    
 
482
    page_units = GetOptionChoice(page_size_unit_item);
 
483
    
 
484
    switch (page_units) {
 
485
    case 0:      /* pixels */
 
486
        if (xv_evalexpr(dev_res_item, &dpi) != RETURN_SUCCESS) {
 
487
            errmsg("Invalid dpi");
 
488
            return;
 
489
        }
 
490
        px = (float) x*dpi/72.0;
 
491
        py = (float) y*dpi/72.0;
 
492
        break;
 
493
    case 1:      /* inches */
 
494
        px = (float) x/72.0;
 
495
        py = (float) y/72.0;
 
496
        break;
 
497
    case 2:      /* cm */ 
 
498
        px = (float) x/72.0*CM_PER_INCH;
 
499
        py = (float) y/72.0*CM_PER_INCH;
 
500
        break;
 
501
    default:
 
502
        errmsg("Internal error");
 
503
        return;
 
504
    }
 
505
    
 
506
    orientation = GetOptionChoice(page_orient_item);
 
507
    
 
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);
 
514
    } else {
 
515
        sprintf (buf, "%.2f", py);
 
516
        xv_setstr(page_x_item, buf);
 
517
        sprintf (buf, "%.2f", px);
 
518
        xv_setstr(page_y_item, buf);
 
519
    }
 
520
}
 
521
 
 
522
static void do_orient_toggle(int value, void *data)
 
523
{
 
524
    int orientation = value;
 
525
    double px, py;
 
526
    char buf[32];
 
527
 
 
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)");
 
531
        return;
 
532
    }
 
533
    
 
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);
 
540
    } else {
 
541
        sprintf (buf, "%.2f", py);
 
542
        xv_setstr(page_x_item, buf);
 
543
        sprintf (buf, "%.2f", px);
 
544
        xv_setstr(page_y_item, buf);
 
545
    }
 
546
}
 
547
 
 
548
static int do_prfilesel_proc(char *filename, void *data)
 
549
{
 
550
    xv_setstr(printfile_item, filename);
 
551
    strcpy(print_file, filename);
 
552
    XtVaSetValues(printfile_item, XmNcursorPosition, strlen(filename), NULL);
 
553
    return TRUE;
 
554
}
 
555
 
 
556
void create_printfiles_popup(void *data)
 
557
{
 
558
    static FSBStructure *fsb = NULL;
 
559
    int device;
 
560
    Device_entry dev;
 
561
    char buf[16];
 
562
 
 
563
    set_wait_cursor();
 
564
 
 
565
    if (fsb == NULL) {
 
566
        fsb = CreateFileSelectionBox(app_shell, "Select print file");
 
567
        AddFileSelectionBoxCB(fsb, do_prfilesel_proc, NULL);
 
568
        ManageChild(fsb->FSB);
 
569
    }
 
570
 
 
571
    device = GetOptionChoice(devices_item);
 
572
    dev = get_device_props(device);
 
573
 
 
574
    sprintf(buf, "*.%s", dev.fext);
 
575
    SetFileSelectionBoxPattern(fsb, buf);
 
576
    
 
577
    RaiseWindow(fsb->dialog);
 
578
 
 
579
    unset_wait_cursor();
 
580
}
 
581
 
 
582
void create_devopts_popup(void *data)
 
583
{
 
584
    int device_id;
 
585
    Device_entry dev;
 
586
    
 
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");
 
592
    } else {
 
593
        (dev.setup)();
 
594
    }
 
595
}
 
596
 
 
597
static void do_units_toggle(int value, void *data)
 
598
{
 
599
    char buf[32];
 
600
    double page_x, page_y;
 
601
    double dev_res;
 
602
    int page_units = value;
 
603
    
 
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)");
 
607
        return;
 
608
    }
 
609
    
 
610
    if (xv_evalexpr(dev_res_item, &dev_res) != RETURN_SUCCESS) {
 
611
        errmsg("Invalid device resolution(s)");
 
612
        return;
 
613
    }
 
614
    
 
615
    if (dev_res <= 0.0) {
 
616
        errmsg("Device resolution(s) <= 0");
 
617
        return;
 
618
    }
 
619
    
 
620
    if (current_page_units == page_units) {
 
621
        ;
 
622
    } else if (current_page_units == 0 && page_units == 1) {
 
623
        page_x /= dev_res;
 
624
        page_y /= dev_res;
 
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) {
 
629
        page_x *= dev_res;
 
630
        page_y *= dev_res;
 
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;
 
640
    } else {
 
641
        errmsg("Internal error");
 
642
        return;
 
643
    }
 
644
        
 
645
    current_page_units = page_units;
 
646
    
 
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);
 
651
}
 
652
 
 
653
static void do_print_cb(void *data)
 
654
{
 
655
    set_wait_cursor();
 
656
    do_hardcopy();
 
657
    unset_wait_cursor();
 
658
}