/
w_print.c
1416 lines (1242 loc) · 43.2 KB
/
w_print.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* FIG : Facility for Interactive Generation of figures
* Copyright (c) 1991 by Paul King
* Parts Copyright (c) 1989-2007 by Brian V. Smith
*
* Any party obtaining a copy of these files is granted, free of charge, a
* full and unrestricted irrevocable, world-wide, paid up, royalty-free,
* nonexclusive right and license to deal in this software and documentation
* files (the "Software"), including without limitation the rights to use,
* copy, modify, merge, publish distribute, sublicense and/or sell copies of
* the Software, and to permit persons who receive copies from any such
* party to do so, with the only requirement being that the above copyright
* and this permission notice remain intact.
*
*/
#include "fig.h"
#include "figx.h"
#include "resources.h"
#include "object.h"
#include "mode.h"
#include "e_edit.h"
#include "u_create.h"
#include "u_print.h"
#include "w_export.h"
#include "w_print.h"
#include "w_icons.h"
#include "w_indpanel.h"
#include "w_msgpanel.h"
#include "w_setup.h"
#include "w_util.h"
#include "f_util.h"
#include "u_bound.h"
#include "u_redraw.h"
#include "w_canvas.h"
#include "w_cmdpanel.h"
#include "w_color.h"
#include "w_cursor.h"
/* EXPORTS */
Widget print_popup; /* the main print popup */
Widget print_panel; /* the form it's in */
Widget print_orient_panel;
Widget print_just_panel;
Widget print_papersize_panel;
Widget print_multiple_panel;
Widget print_overlap_panel;
Widget printer_menu_button;
Widget print_mag_text;
Widget print_background_panel;
void print_update_figure_size(void);
Boolean print_all_layers=True;
Boolean bound_active_layers=False;
Widget print_grid_minor_text, print_grid_major_text;
Widget print_grid_minor_menu_button, print_grid_minor_menu;
Widget print_grid_major_menu_button, print_grid_major_menu;
Widget print_grid_unit_label;
/* LOCAL */
DeclareStaticArgs(15);
static Widget beside;
#define MAX_PRINTERS 1000 /* for those systems using lprng :-) */
static char *printer_names[MAX_PRINTERS];
static int parse_printcap(char **names);
static int numprinters;
static void orient_select(Widget w, XtPointer new_orient, XtPointer garbage);
static void just_select(Widget w, XtPointer new_just, XtPointer garbage);
static Widget just_lab;
static void papersize_select(Widget w, XtPointer new_papersize, XtPointer garbage);
static Widget papersize_menu;
static void background_select(Widget w, XtPointer closure, XtPointer call_data);
static Widget background_menu;
static void multiple_select(Widget w, XtPointer new_multiple, XtPointer garbage);
static void overlap_select(Widget w, XtPointer new_overlap, XtPointer garbage);
static void printer_select(Widget w, XtPointer new_printer, XtPointer garbage);
static Widget dismiss, print,
printer_text, param_text,
clear_batch, print_batch,
num_batch,
printalltoggle, printactivetoggle, boundactivetoggle;
static Widget size_lab;
static void update_figure_size(void);
static void fit_page(void);
static Position xposn, yposn;
static String prn_translations =
"<Message>WM_PROTOCOLS: DismissPrint()\n";
static void print_panel_dismiss(Widget w, XButtonEvent *ev), do_clear_batch(Widget w);
static void get_magnif(void);
static void update_mag(Widget widget, XtPointer item, XtPointer event);
void do_print(Widget w), do_print_batch(Widget w);
static XtCallbackProc switch_print_layers(Widget w, XtPointer closure, XtPointer call_data);
/* callback list to keep track of magnification window */
String print_translations =
"<Key>Return: UpdateMag()\n\
Ctrl<Key>J: UpdateMag()\n\
Ctrl<Key>M: UpdateMag()\n\
Ctrl<Key>X: EmptyTextKey()\n\
Ctrl<Key>U: multiply(4)\n\
<Key>F18: PastePanelKey()\n";
static XtActionsRec prn_actions[] =
{
{"DismissPrint", (XtActionProc) print_panel_dismiss},
{"Dismiss", (XtActionProc) print_panel_dismiss},
{"PrintBatch", (XtActionProc) do_print_batch},
{"ClearBatch", (XtActionProc) do_clear_batch},
{"Print", (XtActionProc) do_print},
{"UpdateMag", (XtActionProc) update_mag},
};
void create_print_panel (Widget w);
void update_batch_count (void);
static void
print_panel_dismiss(Widget w, XButtonEvent *ev)
{
/* first get magnification in case it changed */
/* the other things like paper size, justification, etc. are already
updated because they are from menus */
get_magnif();
XtPopdown(print_popup);
}
static char print_msg[] = "PRINT";
void
do_print(Widget w)
{
char *printer_val;
char *param_val;
char cmd[255],cmd2[255];
char *c1;
char backgrnd[10], grid[80];
/* don't print if in the middle of drawing/editing */
if (check_action_on())
return;
if (emptyfigure_msg(print_msg) && !batch_exists)
return;
/* create popup panel if not already there so we have all the
resources necessary (e.g. printer name etc.) */
if (!print_popup)
create_print_panel(w);
/* get the magnification into appres.magnification */
get_magnif();
/* update the figure size (magnification * bounding_box) */
print_update_figure_size();
printer_val = panel_get_value(printer_text);
param_val = panel_get_value(param_text);
/* get grid params and assemble into fig2dev parm */
get_grid_spec(grid, print_grid_minor_text, print_grid_major_text);
if (batch_exists) {
gen_print_cmd(cmd,batch_file,printer_val,param_val);
if (system(cmd) != 0)
file_msg("Error during PRINT");
/* clear the batch file and the count */
do_clear_batch(w);
} else {
strcpy(cmd, param_val);
/* see if the user wants the filename in the param list (%f) */
if (!strstr(cur_filename,"%f")) { /* don't substitute if the filename has a %f */
while (c1=strstr(cmd,"%f")) {
strcpy(cmd2, c1+2); /* save tail */
strcpy(c1, cur_filename); /* change %f to filename */
strcat(c1, cmd2); /* append tail */
}
}
/* make a #rrggbb string from the background color */
make_rgb_string(export_background_color, backgrnd);
print_to_printer(printer_val, backgrnd, appres.magnification,
print_all_layers, bound_active_layers, grid, cmd);
}
}
/* calculate the magnification needed to fit the figure to the page size */
static void
fit_page(void)
{
int lx,ly,ux,uy;
float wd,ht,pwd,pht;
char buf[60];
/* get current size of figure */
compound_bound(&objects, &lx, &ly, &ux, &uy);
wd = ux-lx;
ht = uy-ly;
/* if there is no figure, return now */
if (wd == 0 || ht == 0)
return;
/* get paper size minus a half inch margin all around */
pwd = paper_sizes[appres.papersize].width - PIX_PER_INCH;
pht = paper_sizes[appres.papersize].height - PIX_PER_INCH;
/* swap height and width if landscape */
if (appres.landscape) {
ux = pwd;
pwd = pht;
pht = ux;
}
/* make magnification lesser of ratio of:
page height / figure height or
page width/figure width
*/
if (pwd/wd < pht/ht)
appres.magnification = 100.0*pwd/wd;
else
appres.magnification = 100.0*pht/ht;
/* adjust for difference in real metric vs "xfig metric" */
if(!appres.INCHES)
appres.magnification *= PIX_PER_CM * 2.54/PIX_PER_INCH;
/* update the magnification widget */
sprintf(buf,"%.1f",appres.magnification);
FirstArg(XtNstring, buf);
SetValues(print_mag_text);
/* and figure size */
update_figure_size();
}
/* get the magnification from the widget and make it reasonable if not */
static void
get_magnif(void)
{
char buf[60];
appres.magnification = (float) atof(panel_get_value(print_mag_text));
if (appres.magnification <= 0.0)
appres.magnification = 100.0;
/* write it back to the widget in case it had a bad value */
sprintf(buf,"%.1f",appres.magnification);
FirstArg(XtNstring, buf);
SetValues(print_mag_text);
}
/* as the user types in a magnification, update the figure size */
static void
update_mag(Widget widget, XtPointer item, XtPointer event)
{
char *buf;
buf = panel_get_value(print_mag_text);
appres.magnification = (float) atof(buf);
update_figure_size();
}
static void
update_figure_size(void)
{
char buf[60];
print_update_figure_size();
/* update the export panel's indicators too */
if (export_popup) {
export_update_figure_size();
sprintf(buf,"%.1f",appres.magnification);
FirstArg(XtNstring, buf);
SetValues(export_mag_text);
}
}
static int num_batch_figures=0;
static Boolean writing_batch=False;
void
do_print_batch(Widget w)
{
FILE *infp,*outfp;
char tmp_exp_file[PATH_MAX];
char str[255];
char backgrnd[10], grid[80];
int fd;
if (writing_batch || emptyfigure_msg(print_msg))
return;
/* set lock so we don't come here while still writing a file */
/* this could happen if the user presses the button too fast */
writing_batch = True;
/* make a temporary name to write this figure to */
snprintf(tmp_exp_file, sizeof(tmp_exp_file), "%s/xfig-exp.XXXXXX",
TMPDIR);
if (batch_exists != True) {
/* make a temporary name to write the batch stuff to */
sprintf(batch_file, "%s/xfig-batch.XXXXXX", TMPDIR);
if ((fd = mkstemp(batch_file)) == -1) {
file_msg("Error creating temporary file");
return;
}
close(fd);
batch_exists = True;
}
if (!print_popup)
create_print_panel(w);
/* get magnification into appres.magnification */
get_magnif();
/* update the figure size (magnification * bounding_box) */
print_update_figure_size();
/* make a #rrggbb string from the background color */
make_rgb_string(export_background_color, backgrnd);
if ((fd = mkstemp(tmp_exp_file)) == -1) {
file_msg("Error creating temporary file");
return;
}
close(fd);
/* get grid params and assemble into fig2dev parm */
get_grid_spec(grid, print_grid_minor_text, print_grid_major_text);
print_to_file(tmp_exp_file, "ps", appres.magnification, 0, 0, backgrnd,
NULL, False, print_all_layers, bound_active_layers, 0, False, grid, appres.overlap);
put_msg("Appending to batch file \"%s\" (%s mode) ... done",
batch_file, appres.landscape ? "LANDSCAPE" : "PORTRAIT");
app_flush(); /* make sure message gets displayed */
/* now append that to the batch file */
if ((infp = fopen(tmp_exp_file, "rb")) == NULL) {
file_msg("Error during PRINT - can't open temporary file to read");
return;
}
if ((outfp = fopen(batch_file, "ab")) == NULL) {
file_msg("Error during PRINT - can't open print file to append");
return;
}
while (fgets(str,255,infp) != NULL)
(void) fputs(str,outfp);
fclose(infp);
fclose(outfp);
unlink(tmp_exp_file);
/* count this batch figure */
num_batch_figures++ ;
/* and update the label widget */
update_batch_count();
/* we're done */
writing_batch = False;
}
static void
do_clear_batch(Widget w)
{
unlink(batch_file);
batch_exists = False;
num_batch_figures = 0;
/* update the label widget */
update_batch_count();
}
/* update the label widget with the current number of figures in the batch file */
void update_batch_count(void)
{
char num[10];
sprintf(num,"%3d",num_batch_figures);
FirstArg(XtNlabel,num);
SetValues(num_batch);
if (num_batch_figures) {
XtSetSensitive(clear_batch, True);
FirstArg(XtNlabel, "Print BATCH \nto Printer");
SetValues(print);
} else {
XtSetSensitive(clear_batch, False);
FirstArg(XtNlabel, "Print FIGURE\nto Printer");
SetValues(print);
}
}
static void
orient_select(Widget w, XtPointer new_orient, XtPointer garbage)
{
if (appres.landscape != (int) new_orient) {
change_orient();
appres.landscape = (int) new_orient;
/* make sure that paper size is appropriate */
papersize_select(print_papersize_panel, (XtPointer) appres.papersize, (XtPointer) 0);
}
}
static void
just_select(Widget w, XtPointer new_just, XtPointer garbage)
{
FirstArg(XtNlabel, XtName(w));
SetValues(print_just_panel);
/* change export justification if it exists */
if (export_just_panel)
SetValues(export_just_panel);
appres.flushleft = (new_just? True: False);
}
static void
papersize_select(Widget w, XtPointer new_papersize, XtPointer garbage)
{
int papersize = (int) new_papersize;
FirstArg(XtNlabel, paper_sizes[papersize].fname);
SetValues(print_papersize_panel);
/* change export papersize if it exists */
if (export_papersize_panel)
SetValues(export_papersize_panel);
appres.papersize = papersize;
/* update the red line showing the new page size */
update_pageborder();
}
static void
multiple_select(Widget w, XtPointer new_multiple, XtPointer garbage)
{
int multiple = (int) new_multiple;
FirstArg(XtNlabel, multiple_pages[multiple]);
SetValues(print_multiple_panel);
/* change export multiple if it exists */
if (export_multiple_panel)
SetValues(export_multiple_panel);
appres.multiple = (multiple? True : False);
/* if multiple pages, disable justification (must be flush left) */
if (appres.multiple) {
XtSetSensitive(just_lab, False);
XtSetSensitive(print_just_panel, False);
XtSetSensitive(print_overlap_panel, True);
if (export_just_panel) {
XtSetSensitive(just_lab, False);
XtSetSensitive(export_just_panel, False);
if (cur_exp_lang == LANG_PS)
XtSetSensitive(export_overlap_panel, True);
}
} else {
XtSetSensitive(just_lab, True);
XtSetSensitive(print_just_panel, True);
XtSetSensitive(print_overlap_panel, False);
if (export_just_panel) {
XtSetSensitive(just_lab, True);
XtSetSensitive(export_just_panel, True);
XtSetSensitive(export_overlap_panel, False);
}
}
}
static void
overlap_select(Widget w, XtPointer new_overlap, XtPointer garbage)
{
int overlap = (int) new_overlap;
FirstArg(XtNlabel, overlap_pages[overlap]);
SetValues(print_overlap_panel);
/* change export overlap if it exists */
if (export_overlap_panel)
SetValues(export_overlap_panel);
appres.overlap = (overlap? True : False);
}
/* user selected a background color from the menu */
static void
background_select(Widget w, XtPointer closure, XtPointer call_data)
{
Pixel bgcolor, fgcolor;
/* get the colors from the color button just pressed */
FirstArg(XtNbackground, &bgcolor);
NextArg(XtNforeground, &fgcolor);
GetValues(w);
/* get the colorname from the color button and put it and the colors
in the menu button */
FirstArg(XtNlabel, XtName(w));
NextArg(XtNbackground, bgcolor);
NextArg(XtNforeground, fgcolor);
SetValues(print_background_panel);
/* update the export panel too if it exists */
if (export_background_panel)
SetValues(export_background_panel);
export_background_color = (int)closure;
XtPopdown(background_menu);
}
/* come here when user chooses minor grid interval from menu */
void
print_grid_minor_select(Widget w, XtPointer new_grid_choice, XtPointer garbage)
{
char *val;
grid_minor = (int) new_grid_choice;
/* put selected grid value in the text area */
/* first get rid of any "mm" following the value */
val = strtok(my_strdup(grid_choices[grid_minor]), " ");
FirstArg(XtNstring, val);
SetValues(print_grid_minor_text);
free(val);
}
/* come here when user chooses major grid interval from menu */
void
print_grid_major_select(Widget w, XtPointer new_grid_choice, XtPointer garbage)
{
char *val;
grid_major = (int) new_grid_choice;
/* put selected grid value in the text area */
/* first get rid of any "mm" following the value */
val = strtok(my_strdup(grid_choices[grid_major]), " ");
FirstArg(XtNstring, val);
SetValues(print_grid_major_text);
free(val);
}
static void
printer_select(Widget w, XtPointer new_printer, XtPointer garbage)
{
int printer = (int) new_printer;
/* put selected printer in the menu button */
FirstArg(XtNlabel, printer_names[printer]);
SetValues(printer_menu_button);
/* and in the printer text widget */
FirstArg(XtNstring, printer_names[printer]);
SetValues(printer_text);
}
/* update the figure size window */
void
print_update_figure_size(void)
{
float mult;
char *unit;
char buf[40];
int ux,uy,lx,ly;
if (!print_popup)
return;
mult = appres.INCHES? PIX_PER_INCH : PIX_PER_CM;
unit = appres.INCHES? "in": "cm";
active_compound_bound(&objects, &lx, &ly, &ux, &uy, bound_active_layers && !print_all_layers);
sprintf(buf, "Fig Size: %.1f%s x %.1f%s",
(float)(ux-lx)/mult*appres.magnification/100.0,unit,
(float)(uy-ly)/mult*appres.magnification/100.0,unit);
FirstArg(XtNlabel, buf);
SetValues(size_lab);
}
void
popup_print_panel(Widget w)
{
char buf[30];
/* turn off Compose key LED */
setCompLED(0);
set_temp_cursor(wait_cursor);
if (print_popup) {
/* the print popup already exists, but the magnification may have been
changed in the export popup */
sprintf(buf,"%.1f",appres.magnification);
FirstArg(XtNstring, buf);
SetValues(print_mag_text);
/* also the figure size (magnification * bounding_box) */
print_update_figure_size();
/* now set the color and name in the background button */
set_but_col(print_background_panel, export_background_color);
/* and the background color menu */
XtDestroyWidget(background_menu);
background_menu = make_color_popup_menu(print_background_panel,
"Background Color", background_select,
NO_TRANSP, INCL_BACKG);
} else {
create_print_panel(w);
}
XtPopup(print_popup, XtGrabNone);
/* now that the popup is realized, put in the name of the first printer */
if (printer_names[0] != NULL) {
FirstArg(XtNlabel, printer_names[0]);
SetValues(printer_menu_button);
}
/* insure that the most recent colormap is installed */
set_cmap(XtWindow(print_popup));
(void) XSetWMProtocols(tool_d, XtWindow(print_popup), &wm_delete_window, 1);
reset_cursor();
}
/* make the popup print panel */
void create_print_panel(Widget w)
{
Widget image;
Widget entry,mag_spinner, below, fitpage;
Pixmap p;
unsigned long fg, bg;
char *printer_val;
char buf[100];
char *unit;
int ux,uy,lx,ly;
int i,len,maxl;
float mult;
XtTranslateCoords(tool, (Position) 0, (Position) 0, &xposn, &yposn);
FirstArg(XtNx, xposn+50);
NextArg(XtNy, yposn+50);
NextArg(XtNtitle, "Xfig: Print menu");
NextArg(XtNcolormap, tool_cm);
print_popup = XtCreatePopupShell("print_popup",
transientShellWidgetClass,
tool, Args, ArgCount);
XtOverrideTranslations(print_popup,
XtParseTranslationTable(prn_translations));
XtAppAddActions(tool_app, prn_actions, XtNumber(prn_actions));
print_panel = XtCreateManagedWidget("print_panel", formWidgetClass,
print_popup, NULL, ZERO);
/* start with the picture of the printer */
FirstArg(XtNlabel, " ");
NextArg(XtNwidth, printer_ic.width);
NextArg(XtNheight, printer_ic.height);
NextArg(XtNborderWidth, 0);
NextArg(XtNinternalWidth, 0);
NextArg(XtNinternalHeight, 0);
NextArg(XtNtop, XtChainTop);
NextArg(XtNbottom, XtChainTop);
NextArg(XtNleft, XtChainLeft);
NextArg(XtNright, XtChainLeft);
image = XtCreateManagedWidget("printer_image", labelWidgetClass,
print_panel, Args, ArgCount);
FirstArg(XtNforeground, &fg);
NextArg(XtNbackground, &bg);
GetValues(image);
p = XCreatePixmapFromBitmapData(tool_d, XtWindow(canvas_sw),
printer_ic.bits, printer_ic.width, printer_ic.height,
fg, bg, tool_dpth);
FirstArg(XtNbitmap, p);
SetValues(image);
FirstArg(XtNlabel, "Print to PostScript Printer");
NextArg(XtNfromHoriz, image);
NextArg(XtNborderWidth, 0);
NextArg(XtNtop, XtChainTop);
NextArg(XtNbottom, XtChainTop);
NextArg(XtNleft, XtChainLeft);
NextArg(XtNright, XtChainLeft);
(void) XtCreateManagedWidget("print_label", labelWidgetClass,
print_panel, Args, ArgCount);
FirstArg(XtNlabel, " Magnification %");
NextArg(XtNfromVert, image);
NextArg(XtNborderWidth, 0);
NextArg(XtNtop, XtChainTop);
NextArg(XtNbottom, XtChainTop);
NextArg(XtNleft, XtChainLeft);
NextArg(XtNright, XtChainLeft);
beside = XtCreateManagedWidget("mag_label", labelWidgetClass,
print_panel, Args, ArgCount);
/* make a spinner entry for the mag */
/* note: this was called "magnification" */
sprintf(buf, "%.1f", appres.magnification);
mag_spinner = MakeFloatSpinnerEntry(print_panel, &print_mag_text, "magnification",
image, beside, update_mag, buf, 0.0, 10000.0, 1.0, 45);
/* we want to track typing here to update figure size label */
XtOverrideTranslations(print_mag_text,
XtParseTranslationTable(print_translations));
/* Fit Page to the right of the magnification window */
FirstArg(XtNlabel, "Fit to Page");
NextArg(XtNfromVert, image);
NextArg(XtNfromHoriz, mag_spinner);
NextArg(XtNborderWidth, INTERNAL_BW);
NextArg(XtNtop, XtChainTop);
NextArg(XtNbottom, XtChainTop);
NextArg(XtNleft, XtChainLeft);
NextArg(XtNright, XtChainLeft);
fitpage = XtCreateManagedWidget("fitpage", commandWidgetClass,
print_panel, Args, ArgCount);
XtAddEventHandler(fitpage, ButtonReleaseMask, False,
(XtEventHandler)fit_page, (XtPointer) NULL);
/* Figure Size to the right of the fit page window */
mult = appres.INCHES? PIX_PER_INCH : PIX_PER_CM;
unit = appres.INCHES? "in": "cm";
/* get the size of the figure */
compound_bound(&objects, &lx, &ly, &ux, &uy);
sprintf(buf, "Fig Size: %.1f%s x %.1f%s ",
(float)(ux-lx)/mult*appres.magnification/100.0,unit,
(float)(uy-ly)/mult*appres.magnification/100.0,unit);
FirstArg(XtNlabel, buf);
NextArg(XtNfromVert, image);
NextArg(XtNfromHoriz, fitpage);
NextArg(XtNhorizDistance, 5);
NextArg(XtNborderWidth, 0);
NextArg(XtNtop, XtChainTop);
NextArg(XtNbottom, XtChainTop);
NextArg(XtNleft, XtChainLeft);
NextArg(XtNright, XtChainLeft);
size_lab = XtCreateManagedWidget("size_label", labelWidgetClass,
print_panel, Args, ArgCount);
/* paper size */
FirstArg(XtNlabel, " Paper Size");
NextArg(XtNborderWidth, 0);
NextArg(XtNfromVert, fitpage);
NextArg(XtNtop, XtChainTop);
NextArg(XtNbottom, XtChainTop);
NextArg(XtNleft, XtChainLeft);
NextArg(XtNright, XtChainLeft);
beside = XtCreateManagedWidget("papersize_label", labelWidgetClass,
print_panel, Args, ArgCount);
FirstArg(XtNlabel, paper_sizes[appres.papersize].fname);
NextArg(XtNfromHoriz, beside);
NextArg(XtNfromVert, fitpage);
NextArg(XtNborderWidth, INTERNAL_BW);
NextArg(XtNresizable, True);
NextArg(XtNrightBitmap, menu_arrow); /* use menu arrow for pull-down */
NextArg(XtNtop, XtChainTop);
NextArg(XtNbottom, XtChainTop);
NextArg(XtNleft, XtChainLeft);
NextArg(XtNright, XtChainLeft);
print_papersize_panel = XtCreateManagedWidget("papersize",
menuButtonWidgetClass,
print_panel, Args, ArgCount);
papersize_menu = XtCreatePopupShell("menu", simpleMenuWidgetClass,
print_papersize_panel, NULL, ZERO);
/* make the menu items */
for (i = 0; i < XtNumber(paper_sizes); i++) {
entry = XtCreateManagedWidget(paper_sizes[i].fname, smeBSBObjectClass,
papersize_menu, NULL, ZERO);
XtAddCallback(entry, XtNcallback, papersize_select, (XtPointer) i);
}
/* Orientation */
FirstArg(XtNlabel, " Orientation");
NextArg(XtNborderWidth, 0);
NextArg(XtNfromVert, print_papersize_panel);
NextArg(XtNtop, XtChainTop);
NextArg(XtNbottom, XtChainTop);
NextArg(XtNleft, XtChainLeft);
NextArg(XtNright, XtChainLeft);
beside = XtCreateManagedWidget("orient_label", labelWidgetClass,
print_panel, Args, ArgCount);
FirstArg(XtNfromHoriz, beside);
NextArg(XtNfromVert, print_papersize_panel);
NextArg(XtNborderWidth, INTERNAL_BW);
NextArg(XtNleftBitmap, menu_arrow); /* use menu arrow for pull-down */
NextArg(XtNtop, XtChainTop);
NextArg(XtNbottom, XtChainTop);
NextArg(XtNleft, XtChainLeft);
NextArg(XtNright, XtChainLeft);
print_orient_panel = XtCreateManagedWidget(orient_items[appres.landscape],
menuButtonWidgetClass,
print_panel, Args, ArgCount);
make_pulldown_menu(orient_items, XtNumber(orient_items), -1, "",
print_orient_panel, orient_select);
FirstArg(XtNlabel, "Justification");
NextArg(XtNborderWidth, 0);
NextArg(XtNfromHoriz, print_orient_panel);
NextArg(XtNfromVert, print_papersize_panel);
NextArg(XtNtop, XtChainTop);
NextArg(XtNbottom, XtChainTop);
NextArg(XtNleft, XtChainLeft);
NextArg(XtNright, XtChainLeft);
just_lab = XtCreateManagedWidget("just_label", labelWidgetClass,
print_panel, Args, ArgCount);
FirstArg(XtNlabel, just_items[appres.flushleft? 1 : 0]);
NextArg(XtNfromHoriz, just_lab);
NextArg(XtNfromVert, print_papersize_panel);
NextArg(XtNborderWidth, INTERNAL_BW);
NextArg(XtNleftBitmap, menu_arrow); /* use menu arrow for pull-down */
NextArg(XtNtop, XtChainTop);
NextArg(XtNbottom, XtChainTop);
NextArg(XtNleft, XtChainLeft);
NextArg(XtNright, XtChainLeft);
print_just_panel = XtCreateManagedWidget("justify",
menuButtonWidgetClass,
print_panel, Args, ArgCount);
make_pulldown_menu(just_items, XtNumber(just_items), -1, "",
print_just_panel, just_select);
/* multiple/single page */
FirstArg(XtNlabel, " Pages");
NextArg(XtNborderWidth, 0);
NextArg(XtNfromVert, print_just_panel);
NextArg(XtNtop, XtChainTop);
NextArg(XtNbottom, XtChainTop);
NextArg(XtNleft, XtChainLeft);
NextArg(XtNright, XtChainLeft);
beside = XtCreateManagedWidget("multiple_label", labelWidgetClass,
print_panel, Args, ArgCount);
FirstArg(XtNlabel, multiple_pages[appres.multiple? 1:0]);
NextArg(XtNfromHoriz, beside);
NextArg(XtNfromVert, print_just_panel);
NextArg(XtNborderWidth, INTERNAL_BW);
NextArg(XtNleftBitmap, menu_arrow); /* use menu arrow for pull-down */
NextArg(XtNtop, XtChainTop);
NextArg(XtNbottom, XtChainTop);
NextArg(XtNleft, XtChainLeft);
NextArg(XtNright, XtChainLeft);
print_multiple_panel = XtCreateManagedWidget("multiple_pages",
menuButtonWidgetClass,
print_panel, Args, ArgCount);
make_pulldown_menu(multiple_pages, XtNumber(multiple_pages), -1, "",
print_multiple_panel, multiple_select);
FirstArg(XtNlabel, overlap_pages[appres.overlap? 1:0]);
NextArg(XtNfromHoriz, print_multiple_panel);
NextArg(XtNfromVert, print_just_panel);
NextArg(XtNborderWidth, INTERNAL_BW);
NextArg(XtNleftBitmap, menu_arrow); /* use menu arrow for pull-down */
NextArg(XtNtop, XtChainTop);
NextArg(XtNbottom, XtChainTop);
NextArg(XtNleft, XtChainLeft);
NextArg(XtNright, XtChainLeft);
print_overlap_panel = XtCreateManagedWidget("overlap_pages",
menuButtonWidgetClass,
print_panel, Args, ArgCount);
make_pulldown_menu(overlap_pages, XtNumber(overlap_pages), -1, "",
print_overlap_panel, overlap_select);
/* background color */
FirstArg(XtNlabel, "Background");
NextArg(XtNfromHoriz, print_overlap_panel);
NextArg(XtNfromVert, print_just_panel);
NextArg(XtNborderWidth, 0);
NextArg(XtNtop, XtChainTop);
NextArg(XtNbottom, XtChainTop);
NextArg(XtNleft, XtChainLeft);
NextArg(XtNright, XtChainLeft);
beside = XtCreateManagedWidget("background_label", labelWidgetClass,
print_panel, Args, ArgCount);
FirstArg(XtNfromHoriz, beside);
NextArg(XtNfromVert, print_just_panel);
NextArg(XtNresize, False);
NextArg(XtNwidth, 80);
NextArg(XtNborderWidth, INTERNAL_BW);
NextArg(XtNtop, XtChainTop);
NextArg(XtNbottom, XtChainTop);
NextArg(XtNleft, XtChainLeft);
NextArg(XtNright, XtChainLeft);
print_background_panel = XtCreateManagedWidget("background",
menuButtonWidgetClass,
print_panel, Args, ArgCount);
/* now set the color and name in the background button */
set_but_col(print_background_panel, export_background_color);
/* make color menu */
background_menu = make_color_popup_menu(print_background_panel,
"Background Color", background_select,
NO_TRANSP, INCL_BACKG);
/* grid options */
FirstArg(XtNlabel, " Grid");
NextArg(XtNfromVert, print_background_panel);
NextArg(XtNborderWidth, 0);
NextArg(XtNtop, XtChainTop);
NextArg(XtNbottom, XtChainTop);
NextArg(XtNleft, XtChainLeft);
NextArg(XtNright, XtChainLeft);
beside = XtCreateManagedWidget("grid_label", labelWidgetClass,
print_panel, Args, ArgCount);
below = make_grid_options(print_panel, print_background_panel, beside, minor_grid, major_grid,
&print_grid_minor_menu_button, &print_grid_major_menu_button,
&print_grid_minor_menu, &print_grid_major_menu,
&print_grid_minor_text, &print_grid_major_text,
&print_grid_unit_label,
print_grid_major_select, print_grid_minor_select);
/* printer name */
FirstArg(XtNlabel, " Printer");
NextArg(XtNfromVert, below);
NextArg(XtNborderWidth, 0);
NextArg(XtNtop, XtChainTop);
NextArg(XtNbottom, XtChainTop);
NextArg(XtNleft, XtChainLeft);
NextArg(XtNright, XtChainLeft);
beside = XtCreateManagedWidget("printer_label", labelWidgetClass,
print_panel, Args, ArgCount);
/*
* don't SetValue the XtNstring so the user may specify the default
* printer in a resource, e.g.: *printer*string: at6
*/
FirstArg(XtNwidth, 200);
NextArg(XtNleftMargin, 4);
NextArg(XtNfromVert, below);
NextArg(XtNfromHoriz, beside);
NextArg(XtNeditType, XawtextEdit);
NextArg(XtNinsertPosition, 0);
NextArg(XtNborderWidth, INTERNAL_BW);
NextArg(XtNtop, XtChainTop);
NextArg(XtNbottom, XtChainTop);
NextArg(XtNleft, XtChainLeft);
NextArg(XtNright, XtChainLeft);
printer_text = XtCreateManagedWidget("printer", asciiTextWidgetClass,
print_panel, Args, ArgCount);
XtOverrideTranslations(printer_text,
XtParseTranslationTable(print_translations));
/* put the printer name in the label if resource isn't set */
FirstArg(XtNstring, &printer_val);
GetValues(printer_text);
/* no printer name specified in resources, get PRINTER environment
var and put it into the widget */
if (emptyname(printer_val)) {
printer_val=getenv("PRINTER");
if ((printer_val!=NULL) && strchr(printer_val,'\\')) {
buf[0]='\0';
len=0;
for (i=0; i<strlen(printer_val); i++) {
buf[len++] = printer_val[i];
if (printer_val[i]=='\\')
buf[len++]='\\';
}
buf[len++]='\0';
printer_val = buf;
}
if (printer_val == NULL) {
printer_val = "";
} else {
FirstArg(XtNstring, printer_val);
SetValues(printer_text);
}
}
/* parse /etc/printcap for printernames for the pull-down menu */
numprinters = parse_printcap(printer_names);
/* find longest name */
maxl = 0;
for (i=0; i<numprinters; i++) {
len=strlen(printer_names[i]);
if (len > maxl) {
maxl = len;
}
}
/* make string of blanks the length of the longest printer name */
buf[0] = '\0';
for (i=0; i<maxl; i++)
strcat(buf," ");
if (numprinters > 0) {
FirstArg(XtNlabel, buf);
NextArg(XtNfromHoriz, printer_text);
NextArg(XtNfromVert, below);
NextArg(XtNborderWidth, INTERNAL_BW);
NextArg(XtNleftBitmap, menu_arrow); /* use menu arrow for pull-down */
NextArg(XtNtop, XtChainTop);
NextArg(XtNbottom, XtChainTop);