File: appPrintDialog.c

package info (click to toggle)
ted 2.11-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 11,064 kB
  • ctags: 13,935
  • sloc: ansic: 120,446; makefile: 7,469; sh: 253
file content (1207 lines) | stat: -rw-r--r-- 33,388 bytes parent folder | download
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
/************************************************************************/
/*									*/
/*  Print Dialog.							*/
/*									*/
/************************************************************************/

#   include	"appFrameConfig.h"

#   include	<stddef.h>
#   include	<stdlib.h>
#   include	<stdio.h>
#   include	<string.h>

#   include	<appDebugon.h>

#   include	<appFrame.h>
#   include	"appUnit.h"
#   include	"appGeoString.h"
#   include	"appPaperChooser.h"
#   include	"appPaper.h"

#   define	DRH_MM	45

/************************************************************************/
/*									*/
/*  Represents a print dialog.						*/
/*									*/
/************************************************************************/

#   define	FILEL	400

#   define	PRINTselAll_PAGES	0
#   define	PRINTselPAGE_RANGE	1
#   define	PRINTselCURRENT_PAGE	2

#   define	PRINTselCOUNT		3

typedef struct PlacementSpecification
    {
    int		psNup;
    int		psHorizontal;
    char *	psOptionText;
    APP_WIDGET	psOptionWidget;
    } PlacementSpecification;

#   define	PRINTps_1_UP	0
#   define	PRINTps_2_UP	1
#   define	PRINTps_4H_UP	2
#   define	PRINTps_4V_UP	3

#   define	PRINTpsCOUNT	4

static PlacementSpecification	APP_Placements[]=
    {
	{ 1, 0, "1 Up"		},
	{ 2, 1, "2 Up"		},
	{ 4, 1, "4 Up Hor"	},
	{ 4, 0, "4 Up Ver"	},
    };

typedef struct AppPrintDialog
    {
    AppDialog			apdDialog;

    APP_WIDGET			apdPrintButton;
    APP_WIDGET			apdCancelButton;

    AppOptionmenu		apdPrinterOptionmenu;
    AppOptionmenu		apdPlacementOptionmenu;
    AppOptionmenu		apdSelectionOptionmenu;

    APP_WIDGET			apdCustomTransformRow;
    APP_WIDGET			apdRotate90Toggle;
    APP_WIDGET			apdCenterHToggle;

    int				apdUnitType;
    PaperChooser		apdPaperChooser;

    APP_WIDGET			apdFaxNumberText;
    APP_WIDGET			apdPrintToFileOption;

    APP_WIDGET			apdPageDrawing;
    AppDrawingData		apdDrawingData;
    int				apdDrawingDataAllocated;
    APP_FONT *			apdFontStruct;

    APP_WIDGET			apdSelectionOptions[PRINTselCOUNT];
    APP_WIDGET			apdPageFromTextWidget;
    APP_WIDGET			apdPageToTextWidget;

    int				apdPrinterCount;
    int				apdPrintOptionCount;
    int				apdDestinationChosen;

    int				apdActivateFaxOptions;
    int				apdFileDestination;
    int				apdFaxDestination;

    DocumentGeometry		apdDocumentGeometry;
    DocumentGeometry		apdPrinterGeometry;
    PlacementSpecification	apdPlacements[PRINTpsCOUNT];
    int				apdPlacementChosen;
    int				apdRotate90Chosen;
    int				apdCenterHChosen;

    int				apdPageCount;
    int				apdFirstSelectedPage;
    int				apdLastSelectedPage;
    int				apdSelectionChosen;
    int				apdFirstPageChosen;
    int				apdLastPageChosen;

    void *			apdTarget;

    char *			apdPrinterText;
    char *			apdNoneText;
    char *			apdCancelText;
    char *			apdPrintText;

    char *			apdFaxText;
    char *			apdPrintToFileText;

    char *			apdPaperSizeText;
    char *			apdCustomPaperSizeText;
    char *			apdPlacementText;
    char *			apdRotate90Text;
    char *			apdCenterHText;

    char *			apdSelectionText;
    char *			apdAllPagesText;
    char *			apdPageRangeText;
    char *			apdCurrentPageText;
    char *			apdFromPageText;
    char *			apdToPageText;

    char *			apdDefaultPrinter;

    APP_WIDGET			apdPrinterOptions[1]; /* LAST! */

    } AppPrintDialog;

static AppConfigurableResource APP_PrintDialogresourceTable[]=
    {
	APP_RESOURCE( "printDialogPrinter",
		    offsetof(AppPrintDialog,apdPrinterText),
		    "Printer" ),
	APP_RESOURCE( "printDialogNone",
		    offsetof(AppPrintDialog,apdNoneText),
		    "None" ),
	APP_RESOURCE( "printDialogCancel",
		    offsetof(AppPrintDialog,apdCancelText),
		    "Cancel" ),
	APP_RESOURCE( "printDialogPrint",
		    offsetof(AppPrintDialog,apdPrintText),
		    "Print" ),
	APP_RESOURCE( "printDialogPrintToFile",
		    offsetof(AppPrintDialog,apdPrintToFileText),
		    "Print to File" ),

	APP_RESOURCE( "printDialogFax",
		    offsetof(AppPrintDialog,apdFaxText),
		    "Fax" ),
	APP_RESOURCE( "printDialogPaperSize",
		    offsetof(AppPrintDialog,apdPaperSizeText),
		    "Paper Size" ),
	APP_RESOURCE( "printDialogCustomPaperSize",
		    offsetof(AppPrintDialog,apdCustomPaperSizeText),
		    "Custom" ),

	/***/
	APP_RESOURCE( "printDialogPlacement",
		    offsetof(AppPrintDialog,apdPlacementText),
		    "Placement" ),

	APP_RESOURCE( "printDialog_1_UpText",
		    offsetof(AppPrintDialog,
				apdPlacements[PRINTps_1_UP].psOptionText),
		    "1 Page/Sheet" ),
	APP_RESOURCE( "printDialog_2_UpText",
		    offsetof(AppPrintDialog,
				apdPlacements[PRINTps_2_UP].psOptionText),
		    "2 Pages/Sheet" ),
	APP_RESOURCE( "printDialog_4H_UpText",
		    offsetof(AppPrintDialog,
				apdPlacements[PRINTps_4H_UP].psOptionText),
		    "4 Pages/Sheet Horizontal" ),
	APP_RESOURCE( "printDialog_4V_UpText",
		    offsetof(AppPrintDialog,
				apdPlacements[PRINTps_4V_UP].psOptionText),
		    "4 Pages/Sheet Vertical" ),

	APP_RESOURCE( "printDialogRotate90",
		    offsetof(AppPrintDialog,apdRotate90Text),
		    "Rotate 90\260" ),
	APP_RESOURCE( "printDialogCenterH",
		    offsetof(AppPrintDialog,apdCenterHText),
		    "Center Horizontally" ),

	/***/
	APP_RESOURCE( "printDialogSelection",
		    offsetof(AppPrintDialog,apdSelectionText),
		    "Selection" ),

	APP_RESOURCE( "printDialogAllPages",
		    offsetof(AppPrintDialog,apdAllPagesText),
		    "All Pages" ),
	APP_RESOURCE( "printDialogPageRange",
		    offsetof(AppPrintDialog,apdPageRangeText),
		    "Page Range" ),
	APP_RESOURCE( "printDialogCurrentPage",
		    offsetof(AppPrintDialog,apdCurrentPageText),
		    "Current Page" ),

	APP_RESOURCE( "printDialogFromPage",
		    offsetof(AppPrintDialog,apdFromPageText),
		    "From" ),
	APP_RESOURCE( "printDialogToPage",
		    offsetof(AppPrintDialog,apdToPageText),
		    "To" ),

	APP_RESOURCE( "defaultPrinter",
		    offsetof(AppPrintDialog,apdDefaultPrinter),
		    "" ),
    };

/************************************************************************/
/*									*/
/*  Show a range of pages in the Print Dialog.				*/
/*									*/
/************************************************************************/

static void appPrintDialogShowFromTo(	AppPrintDialog *	apd,
					int			fromPage,
					int			toPage,
					int			enabled )
    {
    appIntegerToTextWidget( apd->apdPageFromTextWidget, fromPage );
    appIntegerToTextWidget( apd->apdPageToTextWidget, toPage );

    appEnableText( apd->apdPageFromTextWidget, enabled );
    appEnableText( apd->apdPageToTextWidget, enabled );

    return;
    }

/************************************************************************/
/*									*/
/*  Fax number changed.							*/
/*									*/
/************************************************************************/

static void appPrintCheckFaxNumber(	AppPrintDialog *	apd )
    {
    char *	faxNumber;
    char *	s;

    s= faxNumber= appGetStringFromTextWidget( apd->apdFaxNumberText );

    while( *s == ' ' )
	{ s++;	}

    appGuiEnableWidget( apd->apdPrintButton, *s != '\0' );

    appFreeStringFromTextWidget( faxNumber );

    return;
    }

static void appPrintFaxChanged(	APP_WIDGET	w,
				void *		voidapd,
				void *		call_data )
    {
    AppPrintDialog *	apd= (AppPrintDialog *)voidapd;

    appPrintCheckFaxNumber( apd );

    return;
    }

/************************************************************************/
/*									*/
/*  A printer was chosen.						*/
/*									*/
/************************************************************************/

static void appPrinterAdaptToDestination(	AppPrintDialog *	apd )
    {
    if  ( apd->apdDestinationChosen == apd->apdFaxDestination )
	{
	if  ( apd->apdFaxNumberText )
	    {
	    appEnableText( apd->apdFaxNumberText, 1 );

	    appPrintCheckFaxNumber( apd );
	    }
	}
    else{
	if  ( apd->apdFaxNumberText )
	    {
	    appEnableText( apd->apdFaxNumberText, 0 );
	    }

	appGuiEnableWidget( apd->apdPrintButton, 1 );

	appGuiSetDefaultButtonForDialog( &(apd->apdDialog),
						    apd->apdPrintButton );
	}
    }

static void appDestinationChosen(	APP_WIDGET	w,
					void *		voidapd,
					void *		voidpbcs )
    {
    AppPrintDialog *	apd= (AppPrintDialog *)voidapd;
    short		n= -1;

    for ( n= 0; n < apd->apdPrintOptionCount; n++ )
	{
	if  ( apd->apdPrinterOptions[n] == w )
	    { break;	}
	}

    if  ( n < 0 || n >= apd->apdPrintOptionCount )
	{ LLDEB(n,apd->apdPrintOptionCount); return;	}

    apd->apdDestinationChosen= n;

    appPrinterAdaptToDestination( apd );

    return;
    }

/************************************************************************/
/*									*/
/*  A placement was chosen.						*/
/*									*/
/************************************************************************/

static void appPrintDialogPlacementChosen(	APP_WIDGET	w,
						void *		voidapd,
						void *		voidpbcs )
    {
    AppPrintDialog *	apd= (AppPrintDialog *)voidapd;
    AppDrawingData *	add= &(apd->apdDrawingData);
    int			i;

    for ( i= 0; i < PRINTpsCOUNT; i++ )
	{
	if  ( apd->apdPlacements[i].psOptionWidget == w )
	    { break;	}
	}

    if  ( i < 0 || i >= PRINTpsCOUNT )
	{ LLDEB(i,PRINTpsCOUNT); return;	}

    apd->apdPlacementChosen= i;

    if  ( apd->apdCustomTransformRow )
	{
	int	rotate90= apd->apdRotate90Chosen;
	int	centerHorizontally= apd->apdCenterHChosen;

	if  ( apd->apdPlacementChosen != 0 )
	    { rotate90= centerHorizontally= 0;	}

	appGuiEnableWidget( apd->apdRotate90Toggle,
				    apd->apdPlacementChosen == 0 );
	appGuiEnableWidget( apd->apdCenterHToggle,
				    apd->apdPlacementChosen == 0 );

	appGuiSetToggleState( apd->apdRotate90Toggle, rotate90 );
	appGuiSetToggleState( apd->apdCenterHToggle, centerHorizontally );
	}

    appExposeRectangle( add, 0, 0, 0, 0 );

    return;
    }

/************************************************************************/
/*									*/
/*  A selection mode was chosen.					*/
/*									*/
/************************************************************************/

static void appSelectionChosen(		APP_WIDGET	w,
					void *		voidapd,
					void *		voidpbcs )
    {
    AppPrintDialog *	apd= (AppPrintDialog *)voidapd;
    int			n;

#   ifdef USE_MOTIF
    XSetInputFocus( XtDisplay( apd->apdDialog.adTopWidget ),
				    XtWindow( apd->apdDialog.adTopWidget ),
				    RevertToNone, CurrentTime );
#   endif

    for ( n= 0; n < PRINTselCOUNT; n++ )
	{
	if  ( apd->apdSelectionOptions[n] == w )
	    { break;	}
	}

    if  ( n < 0 || n >= PRINTselCOUNT )
	{ LLDEB(n,PRINTselCOUNT); return;	}

    switch( n )
	{
	case PRINTselAll_PAGES:
	    apd->apdFirstPageChosen= 0;
	    apd->apdLastPageChosen= apd->apdPageCount- 1;

	    appPrintDialogShowFromTo( apd, 1, apd->apdPageCount, 0 );
	    apd->apdSelectionChosen= n;
	    return;

	case PRINTselPAGE_RANGE:
	    appEnableText( apd->apdPageFromTextWidget, 1 );
	    appEnableText( apd->apdPageToTextWidget, 1 );
	    apd->apdSelectionChosen= n;

#	    ifdef USE_MOTIF
	    XmProcessTraversal( apd->apdPageFromTextWidget,
							XmTRAVERSE_CURRENT );
#	    endif
	    return;

	case PRINTselCURRENT_PAGE:
	    apd->apdFirstPageChosen= apd->apdFirstSelectedPage;
	    apd->apdLastPageChosen= apd->apdLastSelectedPage;

	    appPrintDialogShowFromTo( apd, apd->apdFirstSelectedPage+ 1,
					    apd->apdLastSelectedPage+ 1, 0 );
	    apd->apdSelectionChosen= n;
	    return;

	default:
	    LDEB(n); return;
	}
    }

/************************************************************************/
/*									*/
/*  The buttons have been pushed.					*/
/*									*/
/************************************************************************/

static void appPrintDialogCancelPushed(	APP_WIDGET	w,
					void *		voidapd,
					void *		voidpbcs )
    {
    AppPrintDialog *	apd= (AppPrintDialog *)voidapd;

    appGuiBreakDialog( &(apd->apdDialog), AQDrespCANCEL );

    return;
    }

static void appPrintDialogPrintPushed(	APP_WIDGET	w,
					void *		voidapd,
					void *		voidpbcs )
    {
    AppPrintDialog *	apd= (AppPrintDialog *)voidapd;

    if  ( apd->apdDestinationChosen < 0	)
	{ LDEB(apd->apdDestinationChosen); return;	}

    if  ( apd->apdSelectionChosen == PRINTselPAGE_RANGE )
	{
	int		from;
	int		to;

	if  ( appGetIntegerFromTextWidget( apd->apdPageFromTextWidget,
					&from, 1, 0, apd->apdPageCount, 0 ) )
	    { return;	}

	if  ( appGetIntegerFromTextWidget( apd->apdPageToTextWidget,
					&to, from, 0, apd->apdPageCount, 1 ) )
	    { return;	}

	apd->apdFirstPageChosen= from- 1;
	apd->apdLastPageChosen= to- 1;
	}

    appGuiBreakDialog( &(apd->apdDialog), AQDrespOK );

    return;
    }

/************************************************************************/
/*									*/
/*  A paper size was chosen.						*/
/*									*/
/************************************************************************/

static void appPrintDialogSizeChosen(	APP_WIDGET	w,
					void *		voidapd,
					void *		voidpbcs )
    {
    AppPrintDialog *		apd= (AppPrintDialog *)voidapd;
    AppDrawingData *		add= &(apd->apdDrawingData);

    appPaperSizeChosen( w, &(apd->apdPaperChooser),
						&(apd->apdPrinterGeometry),
						apd->apdUnitType );

    appExposeRectangle( add, 0, 0, 0, 0 );

    return;
    }

static void appPrintDialogPaperSizeChanged(	APP_WIDGET	w,
						void *		voidapd,
						void *		voidcbs	 )
    {
    AppPrintDialog *		apd= (AppPrintDialog *)voidapd;
    AppDrawingData *		add= &(apd->apdDrawingData);
    const int			set= 0;

    appPaperSizeChanged( &(apd->apdPaperChooser),
						&(apd->apdPrinterGeometry),
						apd->apdUnitType );

    appPaperChooserAdaptToGeometry( &(apd->apdPaperChooser),
			apd->apdUnitType, &(apd->apdPrinterGeometry), set );

    appExposeRectangle( add, 0, 0, 0, 0 );

    return;
    }

/************************************************************************/
/*									*/
/*  The custom placement toggles were activated.			*/
/*									*/
/************************************************************************/

static void appPrintDialogRotate90Toggled(	APP_WIDGET	w,
						void *		voidapd,
						void *		voidtbcs )
    {
    AppPrintDialog *		apd= (AppPrintDialog *)voidapd;
    AppDrawingData *		add= &(apd->apdDrawingData);
    int				set;

    set= appGuiGetToggleStateFromCallback( w, voidtbcs );

    apd->apdRotate90Chosen= ( set != 0 );

    appExposeRectangle( add, 0, 0, 0, 0 );

    return;
    }

static void appPrintDialogCenterHToggled(	APP_WIDGET	w,
						void *		voidapd,
						void *		voidtbcs )
    {
    AppPrintDialog *		apd= (AppPrintDialog *)voidapd;
    AppDrawingData *		add= &(apd->apdDrawingData);
    int				set;

    set= appGuiGetToggleStateFromCallback( w, voidtbcs );

    apd->apdCenterHChosen= ( set != 0 );

    appExposeRectangle( add, 0, 0, 0, 0 );

    return;
    }

/************************************************************************/
/*									*/
/*  Draw a schematic view of the page placement.			*/
/*									*/
/************************************************************************/

static void appPrintDialogPrintGeometry(
				    PrintGeometry *		pg,
				    const AppPrintDialog *	apd )
    {
    const PlacementSpecification *	ps;

    ps= apd->apdPlacements+ apd->apdPlacementChosen;

    pg->pgSheetGeometry= apd->apdPrinterGeometry;

    pg->pgRotate90= apd->apdRotate90Chosen;
    pg->pgCenterHorizontally= apd->apdCenterHChosen;

    if  ( apd->apdPlacementChosen != 0 )
	{ pg->pgRotate90= pg->pgCenterHorizontally= 0; }

    pg->pgNup= ps->psNup;
    pg->pgHorizontal= ps->psHorizontal;

    return;
    }

static APP_EVENT_HANDLER( appPrintDialogDrawPage, w, voidapd, exposeEvent )
    {
    AppPrintDialog *		apd= (AppPrintDialog *)voidapd;
    AppDrawingData *		add= &(apd->apdDrawingData);

    PrintGeometry		pg;

    if  ( apd->apdPlacementChosen < 0			||
	  apd->apdPlacementChosen >= PRINTpsCOUNT	)
	{ LLDEB(apd->apdPlacementChosen,PRINTpsCOUNT); return;	}

    appPrintDialogPrintGeometry( &pg, apd );

    appDrawNupDiagram( apd->apdPageDrawing, add, apd->apdFontStruct, DRH_MM,
					    &(apd->apdDocumentGeometry), &pg );
    }

/************************************************************************/
/*									*/
/*  Fill the list of printers.						*/
/*									*/
/************************************************************************/

static void appPrintDialogFillPrinterMenu( AppPrintDialog *	apd,
					int			printerCount,
					int			defaultPrinter,
					PrintDestination *	pd )
    {
    int			i;
    int			destinationChosen= -1;

    appEmptyOptionmenu( &(apd->apdPrinterOptionmenu) );

    for ( i= 0; i < printerCount; pd++, i++ )
	{
	apd->apdPrinterOptions[i]=
			appAddItemToOptionmenu( &(apd->apdPrinterOptionmenu),
			pd->pdPrinterName, appDestinationChosen,
			(void *)apd );

	if  ( i == defaultPrinter )
	    { destinationChosen= i;	}
	if  ( i == 0 )
	    { destinationChosen= i;	}
	}

    apd->apdPrinterOptions[i]= appAddItemToOptionmenu(
		    &(apd->apdPrinterOptionmenu),
		    apd->apdFaxText, appDestinationChosen, (void *)apd );

    if  ( ! apd->apdActivateFaxOptions )
	{ appGuiEnableWidget( apd->apdPrinterOptions[i], 0 ); }

    apd->apdFaxDestination= i++;
    
    apd->apdPrinterOptions[i]= apd->apdPrintToFileOption=
	appAddItemToOptionmenu( &(apd->apdPrinterOptionmenu),
	    apd->apdPrintToFileText, appDestinationChosen, (void *)apd );

    if  ( destinationChosen < 0 )
	{ destinationChosen= printerCount+ 1;	}

    apd->apdFileDestination= i++;
    apd->apdPrintOptionCount= i;
    
    appSetOptionmenu( &(apd->apdPrinterOptionmenu), destinationChosen );

    apd->apdPrinterCount= printerCount;

    if  ( defaultPrinter >= 0 )
	{ apd->apdDestinationChosen= defaultPrinter;	}
    else{ apd->apdDestinationChosen= destinationChosen; }

    appOptionmenuRefreshWidth( &(apd->apdPrinterOptionmenu) );
    }

/************************************************************************/
/*									*/
/*  Fill the list of possible page placements.				*/
/*									*/
/************************************************************************/

static void appPrintDialogFillPlacementMenu( AppPrintDialog *	apd )
    {
    int				i;

    PlacementSpecification *	ps;

    appEmptyOptionmenu( &(apd->apdPlacementOptionmenu) );

    ps= apd->apdPlacements;
    for ( i= 0; i < PRINTpsCOUNT; ps++, i++ )
	{
	ps->psOptionWidget= appAddItemToOptionmenu(
				&(apd->apdPlacementOptionmenu),
				ps->psOptionText,
				appPrintDialogPlacementChosen, (void *)apd );
	}

    apd->apdPlacementChosen= 0;
    apd->apdRotate90Chosen= 0;
    apd->apdCenterHChosen= 0;

    appSetOptionmenu( &(apd->apdPlacementOptionmenu), 0 );

    appOptionmenuRefreshWidth( &(apd->apdPlacementOptionmenu) );
    }

/************************************************************************/
/*									*/
/*  Fill the list of selection options.					*/
/*									*/
/************************************************************************/

#   define	PRINTselAll_PAGES	0
#   define	PRINTselPAGE_RANGE	1
#   define	PRINTselCURRENT_PAGE	2

static void appPrintDialogFillSelectionMenu( AppPrintDialog *	apd )
    {
    appEmptyOptionmenu( &(apd->apdSelectionOptionmenu) );

    apd->apdSelectionOptions[PRINTselAll_PAGES]= appAddItemToOptionmenu(
					    &(apd->apdSelectionOptionmenu),
					    apd->apdAllPagesText,
					    appSelectionChosen, (void *)apd );
    apd->apdSelectionOptions[PRINTselPAGE_RANGE]= appAddItemToOptionmenu(
					    &(apd->apdSelectionOptionmenu),
					    apd->apdPageRangeText,
					    appSelectionChosen, (void *)apd );
    apd->apdSelectionOptions[PRINTselCURRENT_PAGE]= appAddItemToOptionmenu(
					    &(apd->apdSelectionOptionmenu),
					    apd->apdCurrentPageText,
					    appSelectionChosen, (void *)apd );

    apd->apdSelectionChosen= PRINTselAll_PAGES;

    appSetOptionmenu( &(apd->apdSelectionOptionmenu),
						    apd->apdSelectionChosen );

    appOptionmenuRefreshWidth( &(apd->apdSelectionOptionmenu) );
    }

/************************************************************************/
/*									*/
/*  Protocol callback: The print dialog is closed through the window	*/
/*  manager. Interpret this as 'Cancel'					*/
/*									*/
/************************************************************************/

static APP_CLOSE_CALLBACK( appClosePrintDialog, w, voidapd )
    {
    AppPrintDialog *	apd= (AppPrintDialog *)voidapd;

    appGuiBreakDialog( &(apd->apdDialog), AQDrespCANCEL );

    return;
    }

static APP_DESTROY_CALLBACK( appDestroyPrintDialog, w, voidapd )
    {
    AppPrintDialog *	apd= (AppPrintDialog *)voidapd;

    appCleanPaperChooser( &(apd->apdPaperChooser) );

    return;
    }

/************************************************************************/
/*									*/
/*  Make the frame for selecting a printer.				*/
/*									*/
/************************************************************************/

static APP_WIDGET appPrintDialogMakePrinterFrame( APP_WIDGET	parent,
					AppPrintDialog *	apd )
    {
    APP_WIDGET	printerFrame;
    APP_WIDGET	frameColumn;

    APP_WIDGET	row;

    const int	heightResizable= 0;
    const int	textEnabled= 0;
    const int	textColumn= 1;
    const int	textColspan= 1;

    appMakeColumnFrameInColumn( &printerFrame, &frameColumn,
						parent, apd->apdPrinterText );

    row= appMakeRowInColumn( frameColumn, 2, heightResizable );

    appMakeOptionmenuInRow( &(apd->apdPrinterOptionmenu), row, 0, 1 );

    appMakeTextInRow( &(apd->apdFaxNumberText), row, textColumn,
					    textColspan, 15, textEnabled );

    appGuiSetTypingCallbackForText( apd->apdFaxNumberText,
					    appPrintFaxChanged, (void *)apd );

    return printerFrame;
    }

/************************************************************************/
/*									*/
/*  Make the frame for giving page placement.				*/
/*									*/
/************************************************************************/

static APP_WIDGET appPrintDialogMakePlacementFrame( APP_WIDGET	parent,
					EditApplication *	ea,
					AppPrintDialog *	apd )
    {
    APP_WIDGET		placementFrame;
    APP_WIDGET		frameColumn;

    const int		heightResizable= 0;

    appMakeColumnFrameInColumn( &placementFrame, &frameColumn, parent,
						    apd->apdPlacementText );

    appMakeOptionmenuInColumn( &(apd->apdPlacementOptionmenu), frameColumn );

    apd->apdCustomTransformRow=
			appMakeRowInColumn( frameColumn, 2, heightResizable );
    apd->apdRotate90Toggle= appMakeToggleInRow( apd->apdCustomTransformRow,
				apd->apdRotate90Text,
				appPrintDialogRotate90Toggled, (void *)apd, 0 );
    apd->apdCenterHToggle= appMakeToggleInRow( apd->apdCustomTransformRow,
				apd->apdCenterHText,
				appPrintDialogCenterHToggled, (void *)apd, 1 );

    apd->apdPageDrawing= appMakePageDrawing( parent, ea, DRH_MM,
					appPrintDialogDrawPage, (void *)apd );

    return placementFrame;
    }

/************************************************************************/
/*									*/
/*  Make the frame to select what pages are to be printed.		*/
/*									*/
/************************************************************************/

static APP_WIDGET appPrintDialogMakeSelectionFrame( APP_WIDGET	parent,
					AppPrintDialog *	apd )
    {
    APP_WIDGET		selectionFrame;
    APP_WIDGET		frameColumn;

    APP_WIDGET		pageSelectionRow;
    APP_WIDGET		row;
    APP_WIDGET		leftColumn;
    APP_WIDGET		rightColumn;
    APP_WIDGET		fromLabel;
    APP_WIDGET		toLabel;

    const int		heightResizable= 0;
    const int		textEnabled= 0;

    appMakeColumnFrameInColumn( &selectionFrame, &frameColumn, parent,
						    apd->apdSelectionText );

    appMakeOptionmenuInColumn( &(apd->apdSelectionOptionmenu), frameColumn );

    pageSelectionRow= appMakeRowInColumn( frameColumn, 2, heightResizable );

    appMakeColumnInRow( &leftColumn, pageSelectionRow, 0 );
    appMakeColumnInRow( &rightColumn, pageSelectionRow, 1 );

    appMakeLabelAndTextRow( &row, &fromLabel, &(apd->apdPageFromTextWidget),
			    leftColumn, apd->apdFromPageText, 8, textEnabled );

    appMakeLabelAndTextRow( &row, &toLabel, &(apd->apdPageToTextWidget),
			    rightColumn, apd->apdToPageText, 8, textEnabled );

    return selectionFrame;
    }

/************************************************************************/
/*									*/
/*  Make the form with the two buttons.					*/
/*									*/
/************************************************************************/

static APP_WIDGET appPrintDialogMakeButtonRow(	APP_WIDGET		parent,
						AppPrintDialog *	apd )
    {
    APP_WIDGET		row;
    const int		heightResizable= 0;

    row= appMakeRowInColumn( parent, 2, heightResizable );

    appMakeButtonInRow( &(apd->apdPrintButton), row, apd->apdPrintText,
			appPrintDialogPrintPushed, (void *)apd, 0, 1 );

    appMakeButtonInRow( &(apd->apdCancelButton), row, apd->apdCancelText,
			appPrintDialogCancelPushed, (void *)apd, 1, 0 );

    appGuiSetCancelButtonForDialog( &(apd->apdDialog),
						    apd->apdCancelButton );
    return row;
    }

/************************************************************************/
/*									*/
/*  make a page tool.							*/
/*									*/
/************************************************************************/

static AppPrintDialog * appMakePrintDialog( EditApplication *	ea,
					EditDocument *		ed,
					APP_WIDGET		printOption,
					const char *		pixmapName )
    {
    AppPrintDialog *	apd;
    AppDrawingData *	add;
    
    APP_WIDGET		printerFrame;
    APP_WIDGET		selectionFrame;
    APP_WIDGET		paned;
    APP_WIDGET		buttonRow;

    int			i;

    int			high;
    int			wide;

    APP_BITMAP_IMAGE	iconPixmap= (APP_BITMAP_IMAGE)0;
    APP_BITMAP_MASK	iconMask= (APP_BITMAP_MASK)0;
    
    char		name[128];

    const double	magnification= 1.0;

    if  ( appGetImagePixmap( ea, pixmapName, &iconPixmap, &iconMask )  )
	{ SDEB(pixmapName); return (AppPrintDialog *)0;	}

    if  ( ea->eaPrintDestinationCount == 0				&&
	  utilPrinterGetPrinters( &(ea->eaPrintDestinationCount),
				    &(ea->eaDefaultPrintDestination),
				    &(ea->eaPrintDestinations),
				    ea->eaCustomPrintCommand,
				    ea->eaCustomPrinterName )		)
	{ LDEB(1); return (AppPrintDialog *)0;	}

    apd= (AppPrintDialog *)malloc(
		    sizeof(AppPrintDialog)+
		    ( ea->eaPrintDestinationCount+ 2 )* sizeof(APP_WIDGET) );
    if  ( ! apd )
	{
	LXDEB(ea->eaPrintDestinationCount,apd);
	return (AppPrintDialog *)0;
	}

    apd->apdCustomTransformRow= (APP_WIDGET)0;
    apd->apdRotate90Toggle= (APP_WIDGET)0;
    apd->apdCenterHToggle= (APP_WIDGET)0;

    add= &(apd->apdDrawingData);

    appInitDrawingData( add );

    for ( i= 0; i < PRINTpsCOUNT; i++ )
	{ apd->apdPlacements[i]= APP_Placements[i];	}

    appGuiGetResourceValues( ea, apd,
				    APP_PrintDialogresourceTable,
				    sizeof(APP_PrintDialogresourceTable)/
				    sizeof(AppConfigurableResource) );

    if  ( ea->eaFaxCommand )
	{ apd->apdActivateFaxOptions= 1;	}
    else{ apd->apdActivateFaxOptions= 0;	}

    if  ( apd->apdDefaultPrinter && apd->apdDefaultPrinter[0] )
	{
	PrintDestination *	pd= ea->eaPrintDestinations;

	for ( i= 0; i < ea->eaPrintDestinationCount; pd++, i++ )
	    {
	    if  ( ! strcmp( pd->pdPrinterName, apd->apdDefaultPrinter ) )
		{ ea->eaDefaultPrintDestination= i; break;	}
	    }
	}

    apd->apdTarget= (void *)ea;
    apd->apdPrinterCount= 0;
    apd->apdPrintOptionCount= 0;
    apd->apdFileDestination= -1;
    apd->apdFaxDestination= -1;
    apd->apdUnitType= ea->eaUnitInt;

    appInitPaperChooser( &(apd->apdPaperChooser) );

    appMakeVerticalDialog( &(apd->apdDialog), &paned, ea,
						appClosePrintDialog,
						appDestroyPrintDialog,
						(void *)apd,
						ea->eaPrintDialogName );

    appSetShellTitle( apd->apdDialog.adTopWidget,
					printOption, ea->eaApplicationName );

    printerFrame= appPrintDialogMakePrinterFrame( paned, apd );

    appMakePaperChooserWidgets( paned, apd->apdPaperSizeText,
					    &(apd->apdPaperChooser),
					    appPrintDialogPaperSizeChanged,
					    (void *)apd );

    appPrintDialogMakePlacementFrame( paned, ea, apd );
    selectionFrame= appPrintDialogMakeSelectionFrame( paned, apd );
    buttonRow= appPrintDialogMakeButtonRow( paned, apd );

    appPrintDialogFillPrinterMenu( apd,
				    ea->eaPrintDestinationCount,
				    ea->eaDefaultPrintDestination,
				    ea->eaPrintDestinations );

    appPrintDialogFillPlacementMenu( apd );
    appPrintDialogFillSelectionMenu( apd );

    appPaperChooserFillMenu( &(apd->apdPaperChooser),
				apd->apdCustomPaperSizeText,
				appPrintDialogSizeChosen, (void *)apd );

    appGuiShowDialog( &(apd->apdDialog), ed->edToplevel.atTopWidget );

    appPaperChooserRetreshMenuWidth( &(apd->apdPaperChooser) );

    appOptionmenuRefreshWidth( &(apd->apdPrinterOptionmenu) );
    appOptionmenuRefreshWidth( &(apd->apdPlacementOptionmenu) );
    appOptionmenuRefreshWidth( &(apd->apdSelectionOptionmenu) );

    if  ( appSetDrawingDataForWidget( apd->apdPageDrawing,
						    magnification, add ) )
	{ LDEB(1);	}

    appDrawGetSizeOfWidget( &wide, &high, apd->apdPageDrawing );

    sprintf( name, ea->eaPrintDialogFont, high/ 12 );
    apd->apdFontStruct= appDrawOpenFont( add, name );

    if  ( ! apd->apdFontStruct )
	{ SXDEB(ea->eaPrintDialogFont,apd->apdFontStruct);	}
    else{
	appDrawSetFont( add, apd->apdFontStruct );
	}

    return apd;
    }

/************************************************************************/
/*									*/
/*  Show the 'Print...' dialog.						*/
/*									*/
/*  1)	Make or just show it.						*/
/*  2)	Set the default destination.					*/
/*  3)	Make Fax View by Martin Vermeer happy.				*/
/*									*/
/************************************************************************/

void appRunPrintDialog(			EditDocument *		ed,
					const DocumentGeometry * dgDocument,
					int			pageCount,
					int			firstSelected,
					int			lastSelected,
					APP_WIDGET		printOption,
					const char *		pixmapName )
    {
    EditApplication *		ea= ed->edApplication;
    AppPrintDialog *		apd= (AppPrintDialog *)ea->eaPrintDialog;

    PrintJob			pj;
    PrintGeometry		pg;

    appPrintJobForEditDocument( &pj, ed );

    /*  1  */
    if  ( ! apd )
	{
	apd= appMakePrintDialog( ea, ed, printOption, pixmapName );

	if  ( ! apd )
	    { XDEB(apd); return;	}

	ea->eaPrintDialog= (void *)apd;

	/*  2  */
	if  ( ea->eaDefaultPrintDestination >= 0			  &&
	      ea->eaDefaultPrintDestination < ea->eaPrintDestinationCount )
	    { apd->apdDestinationChosen= ea->eaDefaultPrintDestination; }
	else{
	    if  ( apd->apdPrinterCount > 0 )
		{ apd->apdDestinationChosen= 0;	}
	    else{ apd->apdDestinationChosen= 1; }
	    }

	/*  1  */
	if  ( apd->apdActivateFaxOptions )
	    {
	    const char *	faxNumber= getenv( "APP_FAX_TO" );

	    if  ( faxNumber )
		{
		appStringToTextWidget( apd->apdFaxNumberText, faxNumber );
		apd->apdDestinationChosen= apd->apdFaxDestination;
		}
	    }
	}
    else{
	appSetShellTitle( apd->apdDialog.adTopWidget, printOption,
						    ea->eaApplicationName );

	appGuiShowDialog( &(apd->apdDialog), ed->edToplevel.atTopWidget );
	}

    apd->apdPrinterGeometry= ea->eaDefaultDocumentGeometry;
    apd->apdDocumentGeometry= *dgDocument;

    apd->apdPageCount= pageCount;
    apd->apdFirstSelectedPage= firstSelected;
    apd->apdLastSelectedPage= lastSelected;
    apd->apdFirstPageChosen= 0;
    apd->apdLastPageChosen= apd->apdPageCount- 1;

    apd->apdSelectionChosen= PRINTselAll_PAGES;
    appSetOptionmenu( &(apd->apdSelectionOptionmenu),
						apd->apdSelectionChosen );
    appPrintDialogShowFromTo( apd, 1, apd->apdPageCount, 0 );

    appGuiEnableWidget( apd->apdSelectionOptions[PRINTselCURRENT_PAGE],
			    ( apd->apdFirstSelectedPage >= 0	&&
			      apd->apdLastSelectedPage >= 0	)	);

    appSetOptionmenu( &(apd->apdPrinterOptionmenu),
						apd->apdDestinationChosen );
    appPrinterAdaptToDestination( apd );

    appPaperChooserAdaptToGeometry( &(apd->apdPaperChooser),
			apd->apdUnitType, &(apd->apdPrinterGeometry), 1 );

    appGuiRunDialog( &(apd->apdDialog), AQDrespNONE, ea );

    if  ( apd->apdPlacementChosen < 0			||
	  apd->apdPlacementChosen >= PRINTpsCOUNT	)
	{
	LLDEB(apd->apdPlacementChosen,PRINTpsCOUNT);
	appGuiHideDialog( &(apd->apdDialog) );
	return;
	}

    appPrintDialogPrintGeometry( &pg, apd );

    switch( apd->apdDialog.adResponse )
	{
	case AQDrespOK:
	    if  ( apd->apdDestinationChosen == apd->apdFileDestination )
		{
		appDocPrintToFile( printOption, apd->apdDialog.adTopWidget,
						ed, &pg,
						apd->apdFirstPageChosen,
						apd->apdLastPageChosen );
		}
	    else{
		if  ( apd->apdDestinationChosen == apd->apdFaxDestination )
		    {
		    char *	faxNumber;
		    char *	s;

		    s= faxNumber=
			appGetStringFromTextWidget( apd->apdFaxNumberText );

		    while( *s == ' ' )
			{ s++;	}

		    if  ( ! *s )
			{ SDEB(faxNumber);	}
		    else{
			if  ( appFaxDocument( ed, s, &pg,
						apd->apdFirstPageChosen,
						apd->apdLastPageChosen ) )
			    { SDEB(faxNumber);	}
			}

		    appFreeStringFromTextWidget( faxNumber );
		    }
		else{
		    if  ( appPrintDocument( apd->apdDestinationChosen, &pj, &pg,
			    apd->apdFirstPageChosen, apd->apdLastPageChosen ) )
			{ LDEB(apd->apdDestinationChosen); }
		    }
		}

	    appGuiHideDialog( &(apd->apdDialog) );
	    return;

	default:
	    LDEB(apd->apdDialog.adResponse);
	    /*FALLTHROUGH*/
	case AQDrespCANCEL:
	    appGuiHideDialog( &(apd->apdDialog) );
	    return;
	}

    }