1 /************************************************************************/
2 /*									*/
3 /*  Print Dialog.							*/
4 /*									*/
5 /************************************************************************/
6 
7 #   include	"appFrameConfig.h"
8 
9 #   include	<stddef.h>
10 #   include	<stdlib.h>
11 #   include	<stdio.h>
12 #   include	<string.h>
13 
14 #   include	<appDebugon.h>
15 
16 #   include	"appFrame.h"
17 #   include	"appPaperChooser.h"
18 #   include	<psNup.h>
19 #   include	"appPrintJob.h"
20 #   include	"guiToolUtil.h"
21 #   include	"guiWidgetDrawingSurface.h"
22 #   include	"guiDrawingWidget.h"
23 #   include	"guiDrawPage.h"
24 #   include	"drawDrawingSurfacePrivate.h"
25 #   include	"guiTextUtil.h"
26 
27 #   define	DRH_MM		32
28 
29 /************************************************************************/
30 /*									*/
31 /*  Represents a print dialog.						*/
32 /*									*/
33 /************************************************************************/
34 
35 #   define	FILEL	400
36 
37 #   define	PRINTselAll_PAGES	0
38 #   define	PRINTselPAGE_RANGE	1
39 #   define	PRINTselCURRENT_PAGE	2
40 
41 #   define	PRINTselCOUNT		3
42 
43 typedef struct PlacementSpecification
44     {
45     int			psGridRows;
46     int			psGridCols;
47     int			psGridHorizontal;
48     int			psScalePagesToFit;
49     const char *	psOptionText;
50     } PlacementSpecification;
51 
52 typedef enum PlacementSpecificationNumber
53     {
54     PSnum_1x1_ASIS= 0,
55     PSnum_1x1_SCALED,
56     PSnum_2x1_HOR,
57     PSnum_1x2_HOR,
58     PSnum_2x2_HOR,
59     PSnum_2x2_VER,
60 
61     PSnum__COUNT
62     } PlacementSpecificationNumber;
63 
64 static PlacementSpecification	APP_Placements[PSnum__COUNT]=
65     {
66 	/* R  C  H  F  "text"		*/
67 	{  1, 1, 0, 0, "1x1 As Is"	},
68 	{  1, 1, 1, 1, "1x1 Scale"	},
69 	{  2, 1, 1, 1, "2x1 Hor"	},
70 	{  1, 2, 1, 1, "1x2 Hor"	},
71 	{  2, 2, 1, 1, "2x2 Hor"	},
72 	{  2, 2, 0, 1, "2x2 Ver"	},
73     };
74 
75 typedef struct AppPrintDialogResources
76     {
77     char *			apdrPrinterText;
78     char *			apdrNoneText;
79     char *			apdrCancelText;
80     char *			apdrPrintText;
81 
82     char *			apdrPrintToFileText;
83     char *			apdrVisiblePrinterCountText;
84     char *			apdrPrintersUpText;
85     char *			apdrPrintersDownText;
86 
87     char *			apdrPaperSizeText;
88     char *			apdrCustomPaperSizeText;
89     char *			apdrPlacementText;
90     char *			apdrShowPlacementDrawingString;
91     int				apdrShowPlacementDrawingInt;
92     char *			apdrRotate90Text;
93     char *			apdrCenterHText;
94 
95     char *			apdrSelectionText;
96     char *			apdrAllPagesText;
97     char *			apdrPageRangeText;
98     char *			apdrCurrentPageText;
99     char *			apdrFromPageText;
100     char *			apdrToPageText;
101 
102     char *			apdrDefaultPrinter;
103 
104     PlacementSpecification	apdrPlacements[PSnum__COUNT];
105 
106     char *			apdrOddFacesOnly;
107     char *			apdrEvenFacesOnly;
108     char *			apdrFacesForward;
109     char *			apdrFacesBackward;
110     } AppPrintDialogResources;
111 
112 static AppConfigurableResource APP_PrintDialogresourceTable[]=
113 {
114     APP_RESOURCE( "printDialogPrinter",
115 	    offsetof(AppPrintDialogResources,apdrPrinterText),
116 	    "Printer" ),
117     APP_RESOURCE( "printDialogNone",
118 	    offsetof(AppPrintDialogResources,apdrNoneText),
119 	    "None" ),
120     APP_RESOURCE( "printDialogCancel",
121 	    offsetof(AppPrintDialogResources,apdrCancelText),
122 	    "Cancel" ),
123     APP_RESOURCE( "printDialogPrint",
124 	    offsetof(AppPrintDialogResources,apdrPrintText),
125 	    "Print" ),
126     APP_RESOURCE( "printDialogPrintToFile",
127 	    offsetof(AppPrintDialogResources,apdrPrintToFileText),
128 	    "Print to File" ),
129 
130     APP_RESOURCE( "printDialogPaperSize",
131 	    offsetof(AppPrintDialogResources,apdrPaperSizeText),
132 	    "Paper Size" ),
133     APP_RESOURCE( "printDialogCustomPaperSize",
134 	    offsetof(AppPrintDialogResources,apdrCustomPaperSizeText),
135 	    "Custom" ),
136 
137     /***/
138     APP_RESOURCE( "printDialogPlacement",
139 	    offsetof(AppPrintDialogResources,apdrPlacementText),
140 	    "Placement" ),
141 
142     APP_RESOURCE( "printDialogShowPlacementDrawing",
143 	    offsetof(AppPrintDialogResources,apdrShowPlacementDrawingString),
144 	    "1" ),
145 
146     APP_RESOURCE( "printDialog_1_UpText",
147 	    offsetof(AppPrintDialogResources,
148 			apdrPlacements[PSnum_1x1_ASIS].psOptionText),
149 	    "1 Page/Sheet" ),
150     APP_RESOURCE( "printDialog_1_ScaledText",
151 	    offsetof(AppPrintDialogResources,
152 			apdrPlacements[PSnum_1x1_SCALED].psOptionText),
153 	    "1 Page/Sheet Scale to Fit" ),
154     APP_RESOURCE( "printDialog_2Row_UpText",
155 	    offsetof(AppPrintDialogResources,
156 			apdrPlacements[PSnum_2x1_HOR].psOptionText),
157 	    "2 Pages/Sheet Vertical" ),
158     APP_RESOURCE( "printDialog_2Col_UpText",
159 	    offsetof(AppPrintDialogResources,
160 			apdrPlacements[PSnum_1x2_HOR].psOptionText),
161 	    "2 Pages/Sheet Horizontal" ),
162     APP_RESOURCE( "printDialog_4H_UpText",
163 	    offsetof(AppPrintDialogResources,
164 			apdrPlacements[PSnum_2x2_HOR].psOptionText),
165 	    "4 Pages/Sheet Horizontal" ),
166     APP_RESOURCE( "printDialog_4V_UpText",
167 	    offsetof(AppPrintDialogResources,
168 			apdrPlacements[PSnum_2x2_VER].psOptionText),
169 	    "4 Pages/Sheet Vertical" ),
170 
171     APP_RESOURCE( "printDialogRotate90",
172 	    offsetof(AppPrintDialogResources,apdrRotate90Text),
173 	    "Rotate 90\302\260" ), /* \302\260 is the utf8 degree sign 0xb0 */
174     APP_RESOURCE( "printDialogCenterH",
175 	    offsetof(AppPrintDialogResources,apdrCenterHText),
176 	    "Center Horizontally" ),
177 
178     /***/
179     APP_RESOURCE( "printDialogSelection",
180 	    offsetof(AppPrintDialogResources,apdrSelectionText),
181 	    "Selection" ),
182 
183     APP_RESOURCE( "printDialogAllPages",
184 	    offsetof(AppPrintDialogResources,apdrAllPagesText),
185 	    "All Pages" ),
186     APP_RESOURCE( "printDialogPageRange",
187 	    offsetof(AppPrintDialogResources,apdrPageRangeText),
188 	    "Page Range" ),
189     APP_RESOURCE( "printDialogCurrentPage",
190 	    offsetof(AppPrintDialogResources,apdrCurrentPageText),
191 	    "Current Page" ),
192 
193     APP_RESOURCE( "printDialogFromPage",
194 	    offsetof(AppPrintDialogResources,apdrFromPageText),
195 	    "From" ),
196     APP_RESOURCE( "printDialogToPage",
197 	    offsetof(AppPrintDialogResources,apdrToPageText),
198 	    "To" ),
199 
200     APP_RESOURCE( "defaultPrinter",
201 	    offsetof(AppPrintDialogResources,apdrDefaultPrinter),
202 	    "" ),
203 
204     APP_RESOURCE( "printDialogPrinterCount",
205 	    offsetof(AppPrintDialogResources,apdrVisiblePrinterCountText),
206 	    "15" ),
207     APP_RESOURCE( "printDialogPrintersUp",
208 	    offsetof(AppPrintDialogResources,apdrPrintersUpText),
209 	    "%d up" ),
210     APP_RESOURCE( "printDialogPrintersDown",
211 	    offsetof(AppPrintDialogResources,apdrPrintersDownText),
212 	    "%d down" ),
213 
214     APP_RESOURCE( "printDialogOddFacesOnly",
215 	    offsetof(AppPrintDialogResources,apdrOddFacesOnly),
216 	    "Odd Faces Only" ),
217     APP_RESOURCE( "printDialogEvenFacesOnly",
218 	    offsetof(AppPrintDialogResources,apdrEvenFacesOnly),
219 	    "Even Faces Only" ),
220 
221     APP_RESOURCE( "printDialogFacesForward",
222 	    offsetof(AppPrintDialogResources,apdrFacesForward),
223 	    "First to Last" ),
224     APP_RESOURCE( "printDialogFacesBackward",
225 	    offsetof(AppPrintDialogResources,apdrFacesBackward),
226 	    "Last to First" ),
227 };
228 
229 typedef struct AppPrintDialog
230     {
231     const AppPrintDialogResources *	apdResources;
232     AppDialog				apdDialog;
233 
234     APP_WIDGET				apdButtonRow;
235     APP_WIDGET				apdPrintButton;
236     APP_WIDGET				apdCancelButton;
237 
238     APP_WIDGET				apdPrinterFrame;
239     APP_WIDGET				apdSelectionFrame;
240 
241     AppOptionmenu			apdPrinterOptionmenu;
242     AppOptionmenu			apdPlacementOptionmenu;
243     AppOptionmenu			apdSelectionOptionmenu;
244 
245     APP_WIDGET				apdCustomTransformRow;
246     APP_WIDGET				apdRotate90Toggle;
247     APP_WIDGET				apdCenterHToggle;
248 
249     int					apdUnitType;
250     PaperChooser			apdPaperChooser;
251     double				apdPixelsPerTwip;
252     int					apdPageHighMm;
253 
254     APP_WIDGET				apdPageDrawing;
255     DrawingSurface			apdDrawingSurface;
256     RGB8Color				apdBackgroundColor;
257     int					apdScreenFont;
258 
259     APP_WIDGET				apdSelectionOptions[PRINTselCOUNT];
260     APP_WIDGET				apdPageFromTextWidget;
261     APP_WIDGET				apdPageToTextWidget;
262 
263     APP_WIDGET				apdFaceSelectionRow;
264     APP_WIDGET				apdOddFacesOnlyToggle;
265     APP_WIDGET				apdEvenFacesOnlyToggle;
266 
267     APP_WIDGET				apdFaceDirectionRow;
268     APP_WIDGET				apdDirectionForwardToggle;
269     APP_WIDGET				apdDirectionBackwardToggle;
270 
271     int					apdPrinterCount;
272     int					apdPrintOptionCount;
273     int					apdOptionNrChosen;
274     int					apdVisiblePrinterCount;
275 
276     int					apdToFileOptionNr;
277     int					apdUpOptionNr;
278     int					apdFirstPrinterOptionNr;
279     int					apdDownOptionNr;
280     int					apdFirstVisiblePrinter;
281 
282     DocumentGeometry			apdDocumentGeometry;
283     DocumentGeometry			apdPrinterGeometry;
284     APP_WIDGET				apdPlacementOptionWidgets[PSnum__COUNT];
285     int					apdPlacementChosen;
286     int					apdRotate90Chosen;
287     int					apdCenterHChosen;
288 
289     int					apdPageCount;
290     int					apdFirstSelectedPage;
291     int					apdLastSelectedPage;
292     int					apdSelectionChosen;
293     int					apdFirstPageChosen;
294     int					apdLastPageChosen;
295 
296     int					apdPrintOddFacesOnly;
297     int					apdPrintEvenFacesOnly;
298     int					apdPrintSheetsReverse;
299 
300     void *				apdTarget;
301 
302     APP_WIDGET				apdPrinterOptions[1]; 	/* LAST! */
303     } AppPrintDialog;
304 
305 /************************************************************************/
306 /*									*/
307 /*  Adapt the menu with printers to the currently selected range of	*/
308 /*  printers.								*/
309 /*									*/
310 /*  1)  All printers can be shown.. No need to offer browsing options	*/
311 /*  2)  Make the browsing options visible.				*/
312 /*  3)  Hide all printers before the fist visible one.			*/
313 /*  4)  Show the range of visible printers.				*/
314 /*  5)  Hide all printers after the last visible one.			*/
315 /*  6)  Enable/Disable the browsing options depending on whether there	*/
316 /*	are any printers before/after the current range.		*/
317 /*									*/
318 /************************************************************************/
319 
appPrintDialogMenuRange(AppPrintDialog * apd)320 static void appPrintDialogMenuRange(	AppPrintDialog *	apd )
321     {
322     int		i;
323     int		gotBefore= 0;
324     int		gotAfter= 0;
325 
326     /*  1  */
327     if  ( apd->apdPrinterCount <= apd->apdVisiblePrinterCount )
328 	{
329 	if  ( apd->apdUpOptionNr >= 0 )
330 	    {
331 	    appOptionmenuItemSetVisibility(
332 			    apd->apdPrinterOptions[apd->apdUpOptionNr], 0 );
333 	    }
334 
335 	if  ( apd->apdDownOptionNr >= 0 )
336 	    {
337 	    appOptionmenuItemSetVisibility(
338 			    apd->apdPrinterOptions[apd->apdDownOptionNr], 0 );
339 	    }
340 
341 	return;
342 	}
343 
344     /*  2  */
345     appOptionmenuItemSetVisibility(
346 			    apd->apdPrinterOptions[apd->apdUpOptionNr], 1 );
347     appOptionmenuItemSetVisibility(
348 			    apd->apdPrinterOptions[apd->apdDownOptionNr], 1 );
349 
350     /*  3  */
351     for ( i= 0; i < apd->apdFirstVisiblePrinter; i++ )
352 	{
353 	int	opt= apd->apdFirstPrinterOptionNr+ i;
354 
355 	appOptionmenuItemSetVisibility( apd->apdPrinterOptions[opt], 0 );
356 	gotBefore= 1;
357 	}
358 
359     /*  4  */
360     for ( i= apd->apdFirstVisiblePrinter;
361 	  i < apd->apdFirstVisiblePrinter+ apd->apdVisiblePrinterCount &&
362 	  i < apd->apdPrinterCount;
363 	  i++ )
364 	{
365 	int	opt= apd->apdFirstPrinterOptionNr+ i;
366 
367 	appOptionmenuItemSetVisibility( apd->apdPrinterOptions[opt], 1 );
368 	}
369 
370     /*  5  */
371     for ( i= apd->apdFirstVisiblePrinter+ apd->apdVisiblePrinterCount;
372 	  i < apd->apdPrinterCount;
373 	  i++ )
374 	{
375 	int	opt= apd->apdFirstPrinterOptionNr+ i;
376 
377 	appOptionmenuItemSetVisibility( apd->apdPrinterOptions[opt], 0 );
378 	gotAfter= 1;
379 	}
380 
381     /*  6  */
382     guiEnableWidget(
383 		    apd->apdPrinterOptions[apd->apdUpOptionNr], gotBefore );
384     guiEnableWidget(
385 		    apd->apdPrinterOptions[apd->apdDownOptionNr], gotAfter );
386 
387     appOptionmenuRefreshWidth( &(apd->apdPrinterOptionmenu) );
388 
389     return;
390     }
391 
392 /************************************************************************/
393 /*									*/
394 /*  Show a range of pages in the Print Dialog.				*/
395 /*									*/
396 /************************************************************************/
397 
appPrintDialogShowFromTo(AppPrintDialog * apd,int fromPage,int toPage,int enabled)398 static void appPrintDialogShowFromTo(	AppPrintDialog *	apd,
399 					int			fromPage,
400 					int			toPage,
401 					int			enabled )
402     {
403     appIntegerToTextWidget( apd->apdPageFromTextWidget, fromPage );
404     appIntegerToTextWidget( apd->apdPageToTextWidget, toPage );
405 
406     guiEnableText( apd->apdPageFromTextWidget, enabled );
407     guiEnableText( apd->apdPageToTextWidget, enabled );
408 
409     return;
410     }
411 
412 /************************************************************************/
413 /*									*/
414 /*  A printer was chosen.						*/
415 /*									*/
416 /************************************************************************/
417 
appPrinterAdaptToDestination(AppPrintDialog * apd)418 static void appPrinterAdaptToDestination(	AppPrintDialog *	apd )
419     {
420     guiEnableWidget( apd->apdPrintButton, 1 );
421 
422     appGuiSetDefaultButtonForDialog( &(apd->apdDialog), apd->apdPrintButton );
423     }
424 
425 
appPrintersUpChosen(AppPrintDialog * apd)426 static void appPrintersUpChosen( AppPrintDialog *	apd )
427     {
428     int			printerChosen;
429 
430     apd->apdFirstVisiblePrinter -= apd->apdVisiblePrinterCount;
431     if  ( apd->apdFirstVisiblePrinter < 0 )
432 	{ apd->apdFirstVisiblePrinter= 0;	}
433 
434     printerChosen= apd->apdFirstVisiblePrinter;
435     apd->apdOptionNrChosen= apd->apdFirstPrinterOptionNr+ printerChosen;
436 
437     appPrintDialogMenuRange( apd );
438     appSetOptionmenu( &(apd->apdPrinterOptionmenu), apd->apdOptionNrChosen );
439 
440     return;
441     }
442 
appPrintersDownChosen(AppPrintDialog * apd)443 static void appPrintersDownChosen(	AppPrintDialog *	apd )
444     {
445     int			printerChosen;
446 
447     apd->apdFirstVisiblePrinter += apd->apdVisiblePrinterCount;
448     if  ( apd->apdFirstVisiblePrinter+ apd->apdVisiblePrinterCount >
449 						    apd->apdPrinterCount )
450 	{
451 	apd->apdFirstVisiblePrinter=
452 			apd->apdPrinterCount- apd->apdVisiblePrinterCount;
453 	if  ( apd->apdFirstVisiblePrinter < 0 )
454 	    { apd->apdFirstVisiblePrinter= 0;	}
455 	}
456 
457     printerChosen= apd->apdFirstVisiblePrinter;
458     apd->apdOptionNrChosen= apd->apdFirstPrinterOptionNr+ printerChosen;
459 
460     appPrintDialogMenuRange( apd );
461     appSetOptionmenu( &(apd->apdPrinterOptionmenu), apd->apdOptionNrChosen );
462 
463     return;
464     }
465 
appDestinationChosen(int n,void * voidapd)466 static void appDestinationChosen(	int		n,
467 					void *		voidapd )
468     {
469     AppPrintDialog *	apd= (AppPrintDialog *)voidapd;
470 
471     if  ( n < 0 || n >= apd->apdPrintOptionCount )
472 	{ LLDEB(n,apd->apdPrintOptionCount); return;	}
473 
474     if  ( n == apd->apdUpOptionNr )
475 	{
476 	appPrintersUpChosen( apd );
477 	return;
478 	}
479 
480     if  ( n == apd->apdDownOptionNr )
481 	{
482 	appPrintersDownChosen( apd );
483 	return;
484 	}
485 
486     apd->apdOptionNrChosen= n;
487 
488     appPrinterAdaptToDestination( apd );
489 
490     return;
491     }
492 
493 /************************************************************************/
494 /*									*/
495 /*  Refresh placement drawing.						*/
496 /*									*/
497 /************************************************************************/
498 
appPrintDialogRefreshPlacementDrawing(AppPrintDialog * apd)499 static void appPrintDialogRefreshPlacementDrawing(
500 					    AppPrintDialog *	apd )
501     {
502     if  ( ! apd->apdPageDrawing )
503 	{ return;	}
504 
505     guiExposeDrawingWidget( apd->apdPageDrawing );
506     }
507 
508 /************************************************************************/
509 /*									*/
510 /*  Retrieve the print geometry that is currently set.			*/
511 /*									*/
512 /************************************************************************/
513 
appPrintDialogPrintGeometry(int * pCustRelevant,PrintGeometry * pg,AppPrintDialog * apd)514 static int appPrintDialogPrintGeometry(
515 				    int *			pCustRelevant,
516 				    PrintGeometry *		pg,
517 				    AppPrintDialog *		apd )
518     {
519     int					customTransformRelevant= 1;
520 
521     const AppPrintDialogResources *	apdr= apd->apdResources;
522     const PlacementSpecification *	ps;
523 
524     PropertyMask			updMask;
525 
526     if  ( appPaperChooserGetSize( &updMask,
527 				    &(apd->apdPaperChooser),
528 				    &(apd->apdPrinterGeometry) ) )
529 	{ return -1;	}
530 
531     ps= apdr->apdrPlacements+ apd->apdPlacementChosen;
532 
533     pg->pgSheetGeometry= apd->apdPrinterGeometry;
534 
535     pg->pgRotatePage90= apd->apdRotate90Chosen;
536     pg->pgCenterPageHorizontally= apd->apdCenterHChosen;
537 
538     if  ( ps->psGridRows * ps->psGridCols != 1 || ps->psScalePagesToFit )
539 	{
540 	customTransformRelevant= 0;
541 	pg->pgRotatePage90= 0;
542 	pg->pgCenterPageHorizontally= 0;
543 	}
544 
545     pg->pgGridRows= ps->psGridRows;
546     pg->pgGridCols= ps->psGridCols;
547     pg->pgGridHorizontal= ps->psGridHorizontal;
548     pg->pgScalePagesToFit= ps->psScalePagesToFit;
549 
550     pg->pgPrintOddSides= ! apd->apdPrintEvenFacesOnly;
551     pg->pgPrintEvenSides= ! apd->apdPrintOddFacesOnly;
552     pg->pgPrintSheetsReverse= apd->apdPrintSheetsReverse;
553     pg->pgPrintBookletOrder= 0;
554 
555     *pCustRelevant= customTransformRelevant;
556 
557     return 0;
558     }
559 
560 /************************************************************************/
561 /*									*/
562 /*  Adapt Custom Transform Row to other settings.			*/
563 /*									*/
564 /************************************************************************/
565 
appPrintDialogRefreshCustomTransform(AppPrintDialog * apd)566 static void appPrintDialogRefreshCustomTransform(
567 				    AppPrintDialog *	apd )
568     {
569     int			customTransformRelevant= 1;
570     PrintGeometry	pg;
571 
572     int			fitsWithRot= 0;
573     int			fitsWithoutRot= 0;
574 
575     if  ( ! apd->apdCustomTransformRow )
576 	{ XDEB(apd->apdCustomTransformRow); return;	}
577 
578     if  ( appPrintDialogPrintGeometry( &customTransformRelevant, &pg, apd ) )
579 	{ LDEB(1);	}
580 
581     psNupFitPagesToSheet( &fitsWithoutRot, &fitsWithRot,
582 					    &pg, &(apd->apdDocumentGeometry) );
583 
584     if  ( ! customTransformRelevant )
585 	{
586 	guiEnableWidget( apd->apdRotate90Toggle, 0 );
587 	guiEnableWidget( apd->apdCenterHToggle, 0 );
588 
589 	appGuiSetToggleState( apd->apdRotate90Toggle, 0 );
590 	appGuiSetToggleState( apd->apdCenterHToggle, 0 );
591 	}
592     else{
593 	int	fitsCentered;
594 
595 	if  ( apd->apdRotate90Chosen )
596 	    { fitsCentered= fitsWithRot;	}
597 	else{ fitsCentered= fitsWithoutRot;	}
598 
599 	guiEnableWidget( apd->apdRotate90Toggle, fitsWithRot );
600 	guiEnableWidget( apd->apdCenterHToggle, fitsCentered );
601 
602 	appGuiSetToggleState( apd->apdRotate90Toggle,
603 				    fitsWithRot && apd->apdRotate90Chosen );
604 	appGuiSetToggleState( apd->apdCenterHToggle,
605 				    fitsCentered && apd->apdCenterHChosen );
606 	}
607 
608     return;
609     }
610 
611 /************************************************************************/
612 /*									*/
613 /*  A placement was chosen.						*/
614 /*									*/
615 /************************************************************************/
616 
appPrintDialogPlacementChosen(int i,void * voidapd)617 static void appPrintDialogPlacementChosen(	int		i,
618 						void *		voidapd )
619     {
620     AppPrintDialog *	apd= (AppPrintDialog *)voidapd;
621 
622     if  ( i < 0 || i >= PSnum__COUNT )
623 	{ LLDEB(i,PSnum__COUNT); return;	}
624 
625     apd->apdPlacementChosen= i;
626 
627     if  ( apd->apdCustomTransformRow )
628 	{ appPrintDialogRefreshCustomTransform( apd );	}
629 
630     appPrintDialogRefreshPlacementDrawing( apd );
631 
632     return;
633     }
634 
635 /************************************************************************/
636 /*									*/
637 /*  A selection mode was chosen.					*/
638 /*									*/
639 /************************************************************************/
640 
appSelectionChosen(int n,void * voidapd)641 static void appSelectionChosen(		int		n,
642 					void *		voidapd )
643     {
644     AppPrintDialog *	apd= (AppPrintDialog *)voidapd;
645 
646 #   ifdef USE_MOTIF
647     appGuiMotifSetFocusToWindow( apd->apdDialog.adTopWidget );
648 #   endif
649 
650     if  ( n < 0 || n >= PRINTselCOUNT )
651 	{ LLDEB(n,PRINTselCOUNT); return;	}
652 
653     switch( n )
654 	{
655 	case PRINTselAll_PAGES:
656 	    apd->apdFirstPageChosen= 0;
657 	    apd->apdLastPageChosen= apd->apdPageCount- 1;
658 
659 	    appPrintDialogShowFromTo( apd, 1, apd->apdPageCount, 0 );
660 	    apd->apdSelectionChosen= n;
661 	    return;
662 
663 	case PRINTselPAGE_RANGE:
664 	    guiEnableText( apd->apdPageFromTextWidget, 1 );
665 	    guiEnableText( apd->apdPageToTextWidget, 1 );
666 	    apd->apdSelectionChosen= n;
667 
668 	    appGuiFocusToWidget( apd->apdPageFromTextWidget );
669 	    return;
670 
671 	case PRINTselCURRENT_PAGE:
672 	    apd->apdFirstPageChosen= apd->apdFirstSelectedPage;
673 	    apd->apdLastPageChosen= apd->apdLastSelectedPage;
674 
675 	    appPrintDialogShowFromTo( apd, apd->apdFirstSelectedPage+ 1,
676 					    apd->apdLastSelectedPage+ 1, 0 );
677 	    apd->apdSelectionChosen= n;
678 	    return;
679 
680 	default:
681 	    LDEB(n); return;
682 	}
683     }
684 
685 /************************************************************************/
686 /*									*/
687 /*  The buttons have been pushed.					*/
688 /*									*/
689 /************************************************************************/
690 
APP_BUTTON_CALLBACK_H(appPrintDialogCancelPushed,w,voidapd)691 static APP_BUTTON_CALLBACK_H( appPrintDialogCancelPushed, w, voidapd )
692     {
693     AppPrintDialog *	apd= (AppPrintDialog *)voidapd;
694 
695     appGuiBreakDialog( &(apd->apdDialog), AQDrespCANCEL );
696 
697     return;
698     }
699 
APP_BUTTON_CALLBACK_H(appPrintDialogPrintPushed,w,voidapd)700 static APP_BUTTON_CALLBACK_H( appPrintDialogPrintPushed, w, voidapd )
701     {
702     AppPrintDialog *	apd= (AppPrintDialog *)voidapd;
703 
704     if  ( apd->apdOptionNrChosen < 0	)
705 	{ LDEB(apd->apdOptionNrChosen); return;	}
706 
707     if  ( apd->apdSelectionChosen == PRINTselPAGE_RANGE )
708 	{
709 	int		from;
710 	int		to;
711 
712 	if  ( appGetIntegerFromTextWidget( apd->apdPageFromTextWidget,
713 					&from, 1, 0, apd->apdPageCount, 0 ) )
714 	    { return;	}
715 
716 	if  ( appGetIntegerFromTextWidget( apd->apdPageToTextWidget,
717 					&to, from, 0, apd->apdPageCount, 1 ) )
718 	    { return;	}
719 
720 	apd->apdFirstPageChosen= from- 1;
721 	apd->apdLastPageChosen= to- 1;
722 	}
723 
724     appGuiBreakDialog( &(apd->apdDialog), AQDrespOK );
725 
726     return;
727     }
728 
729 /************************************************************************/
730 /*									*/
731 /*  A paper size was chosen.						*/
732 /*									*/
733 /************************************************************************/
734 
appPrintDialogPaperRectChanged(PaperChooser * pc,void * voidapd,const DocumentGeometry * dg)735 static void appPrintDialogPaperRectChanged(
736 				    PaperChooser *		pc,
737 				    void *			voidapd,
738 				    const DocumentGeometry *	dg )
739     {
740     AppPrintDialog *		apd= (AppPrintDialog *)voidapd;
741 
742     apd->apdPrinterGeometry.dgPageWideTwips= dg->dgPageWideTwips;
743     apd->apdPrinterGeometry.dgPageHighTwips= dg->dgPageHighTwips;
744 
745     if  ( apd->apdCustomTransformRow )
746 	{ appPrintDialogRefreshCustomTransform( apd );	}
747 
748     appPrintDialogRefreshPlacementDrawing( apd );
749 
750     return;
751     }
752 
753 /************************************************************************/
754 /*									*/
755 /*  The custom placement toggles were activated.			*/
756 /*									*/
757 /************************************************************************/
758 
APP_TOGGLE_CALLBACK_H(appPrintDialogRotate90Toggled,w,voidapd,e)759 static APP_TOGGLE_CALLBACK_H( appPrintDialogRotate90Toggled, w, voidapd, e )
760     {
761     AppPrintDialog *		apd= (AppPrintDialog *)voidapd;
762     int				set;
763 
764     set= appGuiGetToggleStateFromCallback( w, e );
765 
766     apd->apdRotate90Chosen= ( set != 0 );
767 
768     if  ( apd->apdCustomTransformRow )
769 	{ appPrintDialogRefreshCustomTransform( apd );	}
770 
771     appPrintDialogRefreshPlacementDrawing( apd );
772 
773     return;
774     }
775 
APP_TOGGLE_CALLBACK_H(appPrintDialogCenterHToggled,w,voidapd,e)776 static APP_TOGGLE_CALLBACK_H( appPrintDialogCenterHToggled, w, voidapd, e )
777     {
778     AppPrintDialog *		apd= (AppPrintDialog *)voidapd;
779     int				set;
780 
781     set= appGuiGetToggleStateFromCallback( w, e );
782 
783     apd->apdCenterHChosen= ( set != 0 );
784 
785     if  ( apd->apdCustomTransformRow )
786 	{ appPrintDialogRefreshCustomTransform( apd );	}
787 
788     appPrintDialogRefreshPlacementDrawing( apd );
789 
790     return;
791     }
792 
793 /************************************************************************/
794 /*									*/
795 /*  The Odd/Even pages only toggles have been activated.		*/
796 /*									*/
797 /************************************************************************/
798 
APP_TOGGLE_CALLBACK_H(appPrintDialogOddOnlyToggled,w,voidapd,e)799 static APP_TOGGLE_CALLBACK_H( appPrintDialogOddOnlyToggled, w, voidapd, e )
800     {
801     AppPrintDialog *		apd= (AppPrintDialog *)voidapd;
802     int				set;
803 
804     set= appGuiGetToggleStateFromCallback( w, e );
805 
806     apd->apdPrintOddFacesOnly= ( set != 0 );
807 
808     if  ( set )
809 	{
810 	apd->apdPrintEvenFacesOnly= 0;
811 	appGuiSetToggleState( apd->apdEvenFacesOnlyToggle,
812 						apd->apdPrintEvenFacesOnly );
813 	}
814 
815     return;
816     }
817 
APP_TOGGLE_CALLBACK_H(appPrintDialogEvenOnlyToggled,w,voidapd,e)818 static APP_TOGGLE_CALLBACK_H( appPrintDialogEvenOnlyToggled, w, voidapd, e )
819     {
820     AppPrintDialog *		apd= (AppPrintDialog *)voidapd;
821     int				set;
822 
823     set= appGuiGetToggleStateFromCallback( w, e );
824 
825     apd->apdPrintEvenFacesOnly= ( set != 0 );
826 
827     if  ( set )
828 	{
829 	apd->apdPrintOddFacesOnly= 0;
830 	appGuiSetToggleState( apd->apdOddFacesOnlyToggle,
831 						apd->apdPrintOddFacesOnly );
832 	}
833 
834     return;
835     }
836 
837 /************************************************************************/
838 /*									*/
839 /*  The Forward/Backward pages only toggles have been activated.	*/
840 /*									*/
841 /************************************************************************/
842 
APP_TOGGLE_CALLBACK_H(appPrintDialogForwardToggled,w,voidapd,e)843 static APP_TOGGLE_CALLBACK_H( appPrintDialogForwardToggled, w, voidapd, e )
844     {
845     AppPrintDialog *		apd= (AppPrintDialog *)voidapd;
846     int				set;
847 
848     set= appGuiGetToggleStateFromCallback( w, e );
849 
850     if  ( apd->apdPrintSheetsReverse != ( set == 0 ) )
851 	{
852 	apd->apdPrintSheetsReverse= ( set == 0 );
853 
854 	appGuiSetToggleState( apd->apdDirectionBackwardToggle,
855 						apd->apdPrintSheetsReverse );
856 	}
857 
858     return;
859     }
860 
APP_TOGGLE_CALLBACK_H(appPrintDialogBackwardToggled,w,voidapd,e)861 static APP_TOGGLE_CALLBACK_H( appPrintDialogBackwardToggled, w, voidapd, e )
862     {
863     AppPrintDialog *		apd= (AppPrintDialog *)voidapd;
864     int				set;
865 
866     set= appGuiGetToggleStateFromCallback( w, e );
867 
868     if  ( apd->apdPrintSheetsReverse != ( set != 0 ) )
869 	{
870 	apd->apdPrintSheetsReverse= ( set != 0 );
871 
872 	appGuiSetToggleState( apd->apdDirectionForwardToggle,
873 						! apd->apdPrintSheetsReverse );
874 	}
875 
876     return;
877     }
878 
879 /************************************************************************/
880 /*									*/
881 /*  Draw a schematic view of the page placement.			*/
882 /*									*/
883 /************************************************************************/
884 
APP_EVENT_HANDLER_H(appPrintDialogDrawPage,w,voidapd,exposeEvent)885 static APP_EVENT_HANDLER_H( appPrintDialogDrawPage, w, voidapd, exposeEvent )
886     {
887     AppPrintDialog *		apd= (AppPrintDialog *)voidapd;
888 
889     int				customTransformRelevant= 1;
890     PrintGeometry		pg;
891 
892     if  ( ! apd->apdPageDrawing )
893 	{ XDEB(apd->apdPageDrawing); return;	}
894 
895     if  ( apd->apdPlacementChosen < 0			||
896 	  apd->apdPlacementChosen >= PSnum__COUNT	)
897 	{ LLDEB(apd->apdPlacementChosen,PSnum__COUNT); return;	}
898 
899     if  ( appPrintDialogPrintGeometry( &customTransformRelevant, &pg, apd ) )
900 	{ LDEB(1);	}
901 
902     appDrawNupDiagram( apd->apdPageDrawing, apd->apdDrawingSurface,
903 				&(apd->apdBackgroundColor),
904 				apd->apdScreenFont,
905 				apd->apdPixelsPerTwip,
906 				&(apd->apdDocumentGeometry), &pg );
907     }
908 
909 /************************************************************************/
910 /*									*/
911 /*  Fill the list of printers.						*/
912 /*									*/
913 /*  1)  Empty option menu. It should already be empty.			*/
914 /*  2)  Insert print to file option.					*/
915 /*  4)  Insert printers up option.					*/
916 /*  5)  Insert options for the actual printers.				*/
917 /*  6)  Insert printers down option.					*/
918 /*									*/
919 /************************************************************************/
920 
appPrintDialogFillPrinterMenu(const AppPrintDialogResources * apdr,AppPrintDialog * apd,int printerCount,int defaultPrinter,PrintDestination * pd)921 static int appPrintDialogFillPrinterMenu(
922 				const AppPrintDialogResources *	apdr,
923 				AppPrintDialog *		apd,
924 				int				printerCount,
925 				int				defaultPrinter,
926 				PrintDestination *		pd )
927     {
928     int			opt;
929     int			prt;
930 
931     int			optionChosen= -1;
932     int			firstPrinter= -1;
933 
934     /*  1  */
935     appEmptyOptionmenu( &(apd->apdPrinterOptionmenu) );
936 
937     opt= 0;
938 
939     /*  2  */
940     {
941     apd->apdPrinterOptions[opt]= appAddItemToOptionmenu(
942 					&(apd->apdPrinterOptionmenu),
943 					apdr->apdrPrintToFileText );
944 
945     if  ( optionChosen < 0 )
946 	{ optionChosen= opt;	}
947 
948     apd->apdToFileOptionNr= opt++;
949     }
950 
951     /*  4  */
952     {
953     int		ltxt= strlen( apdr->apdrPrintersUpText );
954     int		lval= strlen( apdr->apdrVisiblePrinterCountText );
955     char *	scratch;
956     int		pos;
957 
958 
959     scratch= malloc( ltxt+ lval+ 1 );
960     if  ( ! scratch )
961 	{ LLXDEB(ltxt,lval,scratch); return -1;	}
962 
963     for ( pos= 0; pos < ltxt; pos++ )
964 	{
965 	if  ( apdr->apdrPrintersUpText[pos+ 0] == '%'	&&
966 	      apdr->apdrPrintersUpText[pos+ 1] == 'd'	)
967 	    { break;	}
968 	}
969 
970     strncpy( (char *)scratch, apdr->apdrPrintersUpText, pos );
971     strncpy( (char *)scratch+ pos, apdr->apdrVisiblePrinterCountText, lval );
972 
973     if  ( pos < ltxt )
974 	{ strcpy( scratch+ pos+ lval, apdr->apdrPrintersUpText+ pos+ 2 ); }
975     else{ strcpy( scratch+ pos+ lval, apdr->apdrPrintersUpText+ pos );    }
976     apd->apdPrinterOptions[opt]= appAddItemToOptionmenu(
977 				    &(apd->apdPrinterOptionmenu), scratch );
978     free( scratch );
979     apd->apdUpOptionNr= opt++;
980     }
981 
982     /*  5  */
983     apd->apdFirstPrinterOptionNr= opt;
984 
985     for ( prt= 0; prt < printerCount; pd++, opt++, prt++ )
986 	{
987 	apd->apdPrinterOptions[opt]= appAddItemToOptionmenu(
988 			    &(apd->apdPrinterOptionmenu), pd->pdPrinterName );
989 
990 	if  ( prt == defaultPrinter )
991 	    {
992 	    optionChosen= opt;
993 	    firstPrinter= prt;
994 	    }
995 	if  ( prt == 0 )
996 	    {
997 	    optionChosen= opt;
998 	    firstPrinter= prt;
999 	    }
1000 	}
1001 
1002     /*  6  */
1003     {
1004     int		ltxt= strlen( apdr->apdrPrintersDownText );
1005     int		lval= strlen( apdr->apdrVisiblePrinterCountText );
1006     char *	scratch;
1007     int		pos;
1008 
1009     scratch= malloc( ltxt+ lval+ 1 );
1010     if  ( ! scratch )
1011 	{ LLXDEB(ltxt,lval,scratch); return -1;	}
1012 
1013     for ( pos= 0; pos < ltxt; pos++ )
1014 	{
1015 	if  ( apdr->apdrPrintersDownText[pos+ 0] == '%'	&&
1016 	      apdr->apdrPrintersDownText[pos+ 1] == 'd'	)
1017 	    { break;	}
1018 	}
1019 
1020     strncpy( scratch, apdr->apdrPrintersDownText, pos );
1021     strncpy( scratch+ pos, apdr->apdrVisiblePrinterCountText, lval );
1022 
1023     if  ( pos < ltxt )
1024 	{ strcpy( scratch+ pos+ lval ,apdr->apdrPrintersDownText+ pos+ 2 ); }
1025     else{ strcpy( scratch+ pos+ lval ,apdr->apdrPrintersDownText+ pos );    }
1026 
1027     apd->apdPrinterOptions[opt]= appAddItemToOptionmenu(
1028 				    &(apd->apdPrinterOptionmenu), scratch );
1029     free( scratch );
1030     apd->apdDownOptionNr= opt++;
1031     }
1032 
1033     apd->apdPrintOptionCount= opt;
1034 
1035     apd->apdPrinterCount= printerCount;
1036     apd->apdOptionNrChosen= optionChosen;
1037     apd->apdFirstVisiblePrinter= firstPrinter;
1038 
1039     appSetOptionmenu( &(apd->apdPrinterOptionmenu), apd->apdOptionNrChosen );
1040     appPrintDialogMenuRange( apd );
1041 
1042     appOptionmenuRefreshWidth( &(apd->apdPrinterOptionmenu) );
1043 
1044     return 0;
1045     }
1046 
1047 /************************************************************************/
1048 /*									*/
1049 /*  Fill the list of possible page placements.				*/
1050 /*									*/
1051 /************************************************************************/
1052 
appPrintDialogFillPlacementMenu(AppPrintDialog * apd)1053 static void appPrintDialogFillPlacementMenu( AppPrintDialog *	apd )
1054     {
1055     const AppPrintDialogResources *	apdr= apd->apdResources;
1056     int					i;
1057 
1058     const PlacementSpecification *	ps;
1059 
1060     appEmptyOptionmenu( &(apd->apdPlacementOptionmenu) );
1061 
1062     ps= apdr->apdrPlacements;
1063     for ( i= 0; i < PSnum__COUNT; ps++, i++ )
1064 	{
1065 	apd->apdPlacementOptionWidgets[i]= appAddItemToOptionmenu(
1066 			&(apd->apdPlacementOptionmenu), ps->psOptionText );
1067 	}
1068 
1069     apd->apdPlacementChosen= 0;
1070     apd->apdRotate90Chosen= 0;
1071     apd->apdCenterHChosen= 0;
1072 
1073     appSetOptionmenu( &(apd->apdPlacementOptionmenu), 0 );
1074 
1075     appOptionmenuRefreshWidth( &(apd->apdPlacementOptionmenu) );
1076     }
1077 
1078 /************************************************************************/
1079 /*									*/
1080 /*  Fill the list of selection options.					*/
1081 /*									*/
1082 /************************************************************************/
1083 
1084 #   define	PRINTselAll_PAGES	0
1085 #   define	PRINTselPAGE_RANGE	1
1086 #   define	PRINTselCURRENT_PAGE	2
1087 
appPrintDialogFillSelectionMenu(AppPrintDialog * apd)1088 static void appPrintDialogFillSelectionMenu( AppPrintDialog *	apd )
1089     {
1090     const AppPrintDialogResources *	apdr= apd->apdResources;
1091 
1092     appEmptyOptionmenu( &(apd->apdSelectionOptionmenu) );
1093 
1094     apd->apdSelectionOptions[PRINTselAll_PAGES]= appAddItemToOptionmenu(
1095 					    &(apd->apdSelectionOptionmenu),
1096 					    apdr->apdrAllPagesText );
1097     apd->apdSelectionOptions[PRINTselPAGE_RANGE]= appAddItemToOptionmenu(
1098 					    &(apd->apdSelectionOptionmenu),
1099 					    apdr->apdrPageRangeText );
1100     apd->apdSelectionOptions[PRINTselCURRENT_PAGE]= appAddItemToOptionmenu(
1101 					    &(apd->apdSelectionOptionmenu),
1102 					    apdr->apdrCurrentPageText );
1103 
1104     apd->apdSelectionChosen= PRINTselAll_PAGES;
1105 
1106     appSetOptionmenu( &(apd->apdSelectionOptionmenu),
1107 						    apd->apdSelectionChosen );
1108 
1109     appOptionmenuRefreshWidth( &(apd->apdSelectionOptionmenu) );
1110     }
1111 
1112 /************************************************************************/
1113 /*									*/
1114 /*  Protocol callback: The print dialog is closed through the window	*/
1115 /*  manager. Interpret this as 'Cancel'					*/
1116 /*									*/
1117 /************************************************************************/
1118 
APP_CLOSE_CALLBACK_H(appClosePrintDialog,w,voidapd)1119 static APP_CLOSE_CALLBACK_H( appClosePrintDialog, w, voidapd )
1120     {
1121     AppPrintDialog *	apd= (AppPrintDialog *)voidapd;
1122 
1123     appGuiBreakDialog( &(apd->apdDialog), AQDrespCLOSED );
1124 
1125     return;
1126     }
1127 
APP_DESTROY_CALLBACK_H(appDestroyPrintDialog,w,voidapd)1128 static APP_DESTROY_CALLBACK_H( appDestroyPrintDialog, w, voidapd )
1129     {
1130     AppPrintDialog *	apd= (AppPrintDialog *)voidapd;
1131 
1132     appCleanPaperChooser( &(apd->apdPaperChooser) );
1133 
1134     return;
1135     }
1136 
1137 /************************************************************************/
1138 /*									*/
1139 /*  Make the frame for selecting a printer.				*/
1140 /*									*/
1141 /************************************************************************/
1142 
appPrintDialogMakePrinterFrame(APP_WIDGET parent,const AppPrintDialogResources * apdr,AppPrintDialog * apd)1143 static APP_WIDGET appPrintDialogMakePrinterFrame(
1144 				APP_WIDGET			parent,
1145 				const AppPrintDialogResources *	apdr,
1146 				AppPrintDialog *		apd )
1147     {
1148     APP_WIDGET	printerFrame;
1149     APP_WIDGET	frameColumn;
1150 
1151     APP_WIDGET	row;
1152 
1153     const int	heightResizable= 0;
1154 
1155     const int	column= 0;
1156     const int	colspan= 2;
1157 
1158     appMakeColumnFrameInColumn( &printerFrame, &frameColumn,
1159 						parent, apdr->apdrPrinterText );
1160 
1161     row= appMakeRowInColumn( frameColumn, 2, heightResizable );
1162 
1163     appMakeOptionmenuInRow( &(apd->apdPrinterOptionmenu), row, column, colspan,
1164 					appDestinationChosen, (void *)apd );
1165 
1166     return printerFrame;
1167     }
1168 
1169 /************************************************************************/
1170 /*									*/
1171 /*  Make the frame for giving page placement.				*/
1172 /*									*/
1173 /************************************************************************/
1174 
appPrintDialogMakePlacementFrame(APP_WIDGET parent,EditApplication * ea,const AppPrintDialogResources * apdr,AppPrintDialog * apd)1175 static APP_WIDGET appPrintDialogMakePlacementFrame(
1176 				APP_WIDGET			parent,
1177 				EditApplication *		ea,
1178 				const AppPrintDialogResources *	apdr,
1179 				AppPrintDialog *		apd )
1180     {
1181     APP_WIDGET		placementFrame;
1182     APP_WIDGET		frameColumn;
1183 
1184     const int		heightResizable= 0;
1185 
1186     appMakeColumnFrameInColumn( &placementFrame, &frameColumn, parent,
1187 						    apdr->apdrPlacementText );
1188 
1189     appMakeOptionmenuInColumn( &(apd->apdPlacementOptionmenu), frameColumn,
1190 				appPrintDialogPlacementChosen, (void *)apd );
1191 
1192     apd->apdCustomTransformRow=
1193 			appMakeRowInColumn( frameColumn, 2, heightResizable );
1194     apd->apdRotate90Toggle= appMakeToggleInRow( apd->apdCustomTransformRow,
1195 			    apdr->apdrRotate90Text,
1196 			    appPrintDialogRotate90Toggled, (void *)apd, 0, 1 );
1197     apd->apdCenterHToggle= appMakeToggleInRow( apd->apdCustomTransformRow,
1198 			    apdr->apdrCenterHText,
1199 			    appPrintDialogCenterHToggled, (void *)apd, 1, 1 );
1200 
1201     apd->apdPageDrawing= (APP_WIDGET)0;
1202 
1203     apd->apdPageHighMm= DRH_MM;
1204     apd->apdPixelsPerTwip= ( apd->apdPageHighMm* ea->eaPixelsPerTwip )/
1205 								A3_MM_HIGH;
1206 
1207     if  ( apdr->apdrShowPlacementDrawingInt >= 0 )
1208 	{
1209 	apd->apdPageDrawing= appMakePageDrawing( parent,
1210 				ea->eaPixelsPerTwip, apd->apdPageHighMm,
1211 				appPrintDialogDrawPage, (void *)apd );
1212 	}
1213 
1214     return placementFrame;
1215     }
1216 
1217 /************************************************************************/
1218 /*									*/
1219 /*  Make the frame to select what pages are to be printed.		*/
1220 /*									*/
1221 /************************************************************************/
1222 
appPrintDialogMakeSelectionFrame(APP_WIDGET parent,const AppPrintDialogResources * apdr,AppPrintDialog * apd)1223 static APP_WIDGET appPrintDialogMakeSelectionFrame(
1224 				APP_WIDGET			parent,
1225 				const AppPrintDialogResources *	apdr,
1226 				AppPrintDialog *		apd )
1227     {
1228     APP_WIDGET		selectionFrame;
1229     APP_WIDGET		frameColumn;
1230 
1231     APP_WIDGET		pageSelectionRow;
1232     APP_WIDGET		row;
1233     APP_WIDGET		leftColumn;
1234     APP_WIDGET		rightColumn;
1235     APP_WIDGET		fromLabel;
1236     APP_WIDGET		toLabel;
1237 
1238     const int		heightResizable= 0;
1239     const int		textEnabled= 0;
1240     const int		colspan= 1;
1241 
1242     const int		makeCollationWidgets= 0;
1243 
1244     appMakeColumnFrameInColumn( &selectionFrame, &frameColumn, parent,
1245 						    apdr->apdrSelectionText );
1246 
1247     appMakeOptionmenuInColumn( &(apd->apdSelectionOptionmenu), frameColumn,
1248 					    appSelectionChosen, (void *)apd );
1249 
1250     /**/
1251     pageSelectionRow= appMakeRowInColumn( frameColumn, 2, heightResizable );
1252 
1253     appMakeColumnInRow( &leftColumn, pageSelectionRow, 0, colspan );
1254     appMakeColumnInRow( &rightColumn, pageSelectionRow, 1, colspan );
1255 
1256     guiToolMakeLabelAndTextRow( &row, &fromLabel, &(apd->apdPageFromTextWidget),
1257 			leftColumn, apdr->apdrFromPageText, 8, textEnabled );
1258 
1259     guiToolMakeLabelAndTextRow( &row, &toLabel, &(apd->apdPageToTextWidget),
1260 			rightColumn, apdr->apdrToPageText, 8, textEnabled );
1261 
1262     /**/
1263     apd->apdFaceSelectionRow= (APP_WIDGET)0;
1264     apd->apdOddFacesOnlyToggle= (APP_WIDGET)0;
1265     apd->apdEvenFacesOnlyToggle= (APP_WIDGET)0;
1266 
1267     if  ( makeCollationWidgets )
1268 	{
1269 	apd->apdFaceSelectionRow=
1270 			appMakeRowInColumn( frameColumn, 2, heightResizable );
1271 	apd->apdOddFacesOnlyToggle= appMakeToggleInRow(
1272 			    apd->apdFaceSelectionRow,
1273 			    apdr->apdrOddFacesOnly,
1274 			    appPrintDialogOddOnlyToggled, (void *)apd, 0, 1 );
1275 	apd->apdEvenFacesOnlyToggle= appMakeToggleInRow(
1276 			    apd->apdFaceSelectionRow,
1277 			    apdr->apdrEvenFacesOnly,
1278 			    appPrintDialogEvenOnlyToggled, (void *)apd, 1, 1 );
1279 	}
1280 
1281     /**/
1282     apd->apdFaceDirectionRow= (APP_WIDGET)0;
1283     apd->apdDirectionForwardToggle= (APP_WIDGET)0;
1284     apd->apdDirectionBackwardToggle= (APP_WIDGET)0;
1285 
1286     if  ( makeCollationWidgets )
1287 	{
1288 	apd->apdFaceDirectionRow=
1289 			appMakeRowInColumn( frameColumn, 2, heightResizable );
1290 	apd->apdDirectionForwardToggle= appMakeToggleInRow(
1291 			    apd->apdFaceDirectionRow,
1292 			    apdr->apdrFacesForward,
1293 			    appPrintDialogForwardToggled, (void *)apd, 0, 1 );
1294 	apd->apdDirectionBackwardToggle= appMakeToggleInRow(
1295 			    apd->apdFaceDirectionRow,
1296 			    apdr->apdrFacesBackward,
1297 			    appPrintDialogBackwardToggled, (void *)apd, 1, 1 );
1298 	}
1299 
1300     return selectionFrame;
1301     }
1302 
1303 /************************************************************************/
1304 /*									*/
1305 /*  Make the form with the two buttons.					*/
1306 /*									*/
1307 /************************************************************************/
1308 
appPrintDialogMakeButtonRow(APP_WIDGET parent,const AppPrintDialogResources * apdr,AppPrintDialog * apd)1309 static APP_WIDGET appPrintDialogMakeButtonRow(
1310 				APP_WIDGET			parent,
1311 				const AppPrintDialogResources *	apdr,
1312 				AppPrintDialog *		apd )
1313     {
1314     APP_WIDGET		row;
1315     const int		heightResizable= 0;
1316     const int		colspan= 1;
1317 
1318     row= appMakeRowInColumn( parent, 2, heightResizable );
1319 
1320     appMakeButtonInRow( &(apd->apdPrintButton), row, apdr->apdrPrintText,
1321 		    appPrintDialogPrintPushed, (void *)apd, 0, colspan, 1 );
1322 
1323     appMakeButtonInRow( &(apd->apdCancelButton), row, apdr->apdrCancelText,
1324 		    appPrintDialogCancelPushed, (void *)apd, 1, colspan, 0 );
1325 
1326     appGuiSetCancelButtonForDialog( &(apd->apdDialog),
1327 						    apd->apdCancelButton );
1328     return row;
1329     }
1330 
1331 /************************************************************************/
1332 /*									*/
1333 /*  make a page tool.							*/
1334 /*									*/
1335 /************************************************************************/
1336 
appMakePrintDialog(EditApplication * ea,EditDocument * ed,APP_WIDGET printOption,const char * pixmapName)1337 static AppPrintDialog * appMakePrintDialog( EditApplication *	ea,
1338 					EditDocument *		ed,
1339 					APP_WIDGET		printOption,
1340 					const char *		pixmapName )
1341     {
1342     AppPrintDialog *		apd;
1343 
1344     APP_WIDGET			paned;
1345 
1346     int				i;
1347 
1348     int				high;
1349     int				wide;
1350 
1351     static int				gotResources;
1352     static AppPrintDialogResources	apdr;
1353 
1354     if  ( ! ea->eaPrintDestinationsCollected	&&
1355 	  appGetPrintDestinations( ea )		)
1356 	{ LDEB(1); return (AppPrintDialog *)0;	}
1357 
1358     apd= (AppPrintDialog *)malloc(
1359 		    sizeof(AppPrintDialog)+
1360 		    ( ea->eaPrintDestinationCount+ 4 )* sizeof(APP_WIDGET) );
1361     if  ( ! apd )
1362 	{
1363 	LXDEB(ea->eaPrintDestinationCount,apd);
1364 	return (AppPrintDialog *)0;
1365 	}
1366 
1367     appInitOptionmenu( &(apd->apdPrinterOptionmenu) );
1368     appInitOptionmenu( &(apd->apdPlacementOptionmenu) );
1369     appInitOptionmenu( &(apd->apdSelectionOptionmenu) );
1370 
1371     apd->apdCustomTransformRow= (APP_WIDGET)0;
1372     apd->apdRotate90Toggle= (APP_WIDGET)0;
1373     apd->apdCenterHToggle= (APP_WIDGET)0;
1374     apd->apdResources= &apdr;
1375 
1376     apd->apdDrawingSurface= (DrawingSurface)0;
1377 
1378     if  ( ! gotResources )
1379 	{
1380 	for ( i= 0; i < PSnum__COUNT; i++ )
1381 	    { apdr.apdrPlacements[i]= APP_Placements[i];	}
1382 
1383 	appGuiGetResourceValues( &gotResources, ea, &apdr,
1384 				    APP_PrintDialogresourceTable,
1385 				    sizeof(APP_PrintDialogresourceTable)/
1386 				    sizeof(AppConfigurableResource) );
1387 
1388 	apdr.apdrShowPlacementDrawingInt= 0;
1389 	if  ( apdr.apdrShowPlacementDrawingString )
1390 	    {
1391 	    if  ( ! strcmp( apdr.apdrShowPlacementDrawingString, "1" ) )
1392 		{ apdr.apdrShowPlacementDrawingInt=  1;	}
1393 	    if  ( ! strcmp( apdr.apdrShowPlacementDrawingString, "0" ) )
1394 		{ apdr.apdrShowPlacementDrawingInt= -1;	}
1395 
1396 	    if  ( apdr.apdrShowPlacementDrawingInt == 0 )
1397 		{ SDEB(apdr.apdrShowPlacementDrawingString);	}
1398 	    }
1399 	}
1400 
1401     apd->apdVisiblePrinterCount= 0;
1402     if  ( apdr.apdrVisiblePrinterCountText )
1403 	{
1404 	char *	past= apdr.apdrVisiblePrinterCountText;
1405 
1406 	apd->apdVisiblePrinterCount=
1407 		strtol( apdr.apdrVisiblePrinterCountText, &past, 0 );
1408 
1409 	while( *past == ' ' )
1410 	    { past++;	}
1411 	if  ( *past )
1412 	    {
1413 	    SDEB(apdr.apdrVisiblePrinterCountText);
1414 	    apd->apdVisiblePrinterCount= 0;
1415 	    }
1416 	}
1417     if  ( apd->apdVisiblePrinterCount < 1 )
1418 	{ apd->apdVisiblePrinterCount= 15;	}
1419 
1420     if  ( apdr.apdrDefaultPrinter && apdr.apdrDefaultPrinter[0] )
1421 	{
1422 	PrintDestination *	pd= ea->eaPrintDestinations;
1423 
1424 	for ( i= 0; i < ea->eaPrintDestinationCount; pd++, i++ )
1425 	    {
1426 	    if  ( ! strcmp( pd->pdPrinterName, apdr.apdrDefaultPrinter ) )
1427 		{ ea->eaDefaultPrintDestination= i; break;	}
1428 	    }
1429 	}
1430 
1431     apd->apdTarget= (void *)ea;
1432     apd->apdPrinterCount= 0;
1433     apd->apdPrintOptionCount= 0;
1434     apd->apdToFileOptionNr= -1;
1435     apd->apdUnitType= ea->eaUnitInt;
1436 
1437     appInitPaperChooser( &(apd->apdPaperChooser) );
1438 
1439     appMakeVerticalDialog( &(apd->apdDialog), &paned, ea,
1440 						appClosePrintDialog,
1441 						appDestroyPrintDialog,
1442 						(void *)apd );
1443 
1444     appSetShellTitle( apd->apdDialog.adTopWidget,
1445 					printOption, ea->eaApplicationName );
1446 
1447     apd->apdPrinterFrame= appPrintDialogMakePrinterFrame( paned, &apdr, apd );
1448 
1449     appMakePaperChooserWidgets( paned, apdr.apdrPaperSizeText,
1450 					    apd->apdUnitType,
1451 					    &(apd->apdPaperChooser),
1452 					    appPrintDialogPaperRectChanged,
1453 					    (void *)apd );
1454 
1455     appPrintDialogMakePlacementFrame( paned, ea, &apdr, apd );
1456     apd->apdSelectionFrame= appPrintDialogMakeSelectionFrame( paned, &apdr, apd );
1457     apd->apdButtonRow= appPrintDialogMakeButtonRow( paned, &apdr, apd );
1458 
1459     appPrintDialogFillPrinterMenu( &apdr, apd,
1460 				    ea->eaPrintDestinationCount,
1461 				    ea->eaDefaultPrintDestination,
1462 				    ea->eaPrintDestinations );
1463 
1464     appPrintDialogFillPlacementMenu( apd );
1465     appPrintDialogFillSelectionMenu( apd );
1466 
1467     appPaperChooserFillMenu( &(apd->apdPaperChooser),
1468 					    apdr.apdrCustomPaperSizeText );
1469 
1470     appGuiShowDialog( ea, &(apd->apdDialog), ed->edToplevel.atTopWidget );
1471 
1472     appPaperChooserRefreshMenuWidth( &(apd->apdPaperChooser) );
1473 
1474     appOptionmenuRefreshWidth( &(apd->apdPrinterOptionmenu) );
1475     appOptionmenuRefreshWidth( &(apd->apdPlacementOptionmenu) );
1476     appOptionmenuRefreshWidth( &(apd->apdSelectionOptionmenu) );
1477 
1478     if  ( apd->apdPageDrawing )
1479 	{
1480 	apd->apdDrawingSurface= guiDrawingSurfaceForNativeWidget(
1481 			    apd->apdPageDrawing,
1482 			    ea->eaPostScriptFontList.psflAvoidFontconfig );
1483 
1484 	guiDrawGetSizeOfWidget( &wide, &high, apd->apdPageDrawing );
1485 
1486 	apd->apdScreenFont= drawOpenDefaultFont( apd->apdDrawingSurface,
1487 					    &(ea->eaPostScriptFontList),
1488 					    apd->apdPageDrawing, high/ 12 );
1489 	if  ( apd->apdScreenFont < 0 )
1490 	    { LLDEB(high/12,apd->apdScreenFont); }
1491 
1492 	guiGetBackgroundColor( &(apd->apdBackgroundColor),
1493 							apd->apdPageDrawing );
1494 	}
1495 
1496     return apd;
1497     }
1498 
1499 /************************************************************************/
1500 /*									*/
1501 /*  Actually execute the print command.					*/
1502 /*									*/
1503 /************************************************************************/
1504 
appPrintDialogPrint(EditDocument * ed,APP_WIDGET printOption,PrintJob * pj,PrintGeometry * pg,AppPrintDialog * apd)1505 static void appPrintDialogPrint(	EditDocument *		ed,
1506 					APP_WIDGET		printOption,
1507 					PrintJob *		pj,
1508 					PrintGeometry *		pg,
1509 					AppPrintDialog *	apd )
1510     {
1511     int					customTransformRelevant= 1;
1512 
1513     if  ( apd->apdPlacementChosen < 0			||
1514 	  apd->apdPlacementChosen >= PSnum__COUNT	)
1515 	{ LLDEB(apd->apdPlacementChosen,PSnum__COUNT); return; }
1516 
1517     if  ( appPrintDialogPrintGeometry( &customTransformRelevant, pg, apd ) )
1518 	{ return; }
1519 
1520     pg->pgFirstPage= apd->apdFirstPageChosen;
1521     pg->pgLastPage= apd->apdLastPageChosen;
1522 
1523     if  ( apd->apdOptionNrChosen == apd->apdToFileOptionNr )
1524 	{
1525 	appDocPrintToFile( printOption, apd->apdDialog.adTopWidget, ed, pg );
1526 	}
1527     else{
1528 	int		printer;
1529 
1530 	printer= apd->apdOptionNrChosen- apd->apdFirstPrinterOptionNr;
1531 
1532 	if  ( appPrintDocument( printer, pj ) )
1533 	    { LDEB(apd->apdOptionNrChosen); }
1534 	}
1535 
1536     return;
1537     }
1538 
1539 /************************************************************************/
1540 /*									*/
1541 /*  Show the 'Print...' dialog.						*/
1542 /*									*/
1543 /*  1)	Make or just show it.						*/
1544 /*  2)	Default destination is set by appMakePrintDialog().		*/
1545 /*									*/
1546 /************************************************************************/
1547 
appRunPrintDialog(EditDocument * ed,const DocumentGeometry * dgDocument,int pageCount,int firstSelected,int lastSelected,APP_WIDGET printOption,const char * pixmapName)1548 void appRunPrintDialog(			EditDocument *		ed,
1549 					const DocumentGeometry * dgDocument,
1550 					int			pageCount,
1551 					int			firstSelected,
1552 					int			lastSelected,
1553 					APP_WIDGET		printOption,
1554 					const char *		pixmapName )
1555     {
1556     EditApplication *			ea= ed->edApplication;
1557     AppPrintDialog *			apd= (AppPrintDialog *)ea->eaPrintDialog;
1558     const AppPrintDialogResources *	apdr;
1559 
1560     PrintJob				pj;
1561     PrintGeometry			pg;
1562 
1563     int					i;
1564 
1565     const int				sheetSize= 0;
1566 
1567     appPrintJobForEditDocument( &pj, ed, &pg );
1568 
1569     /*  1  */
1570     if  ( ! apd )
1571 	{
1572 	apd= appMakePrintDialog( ea, ed, printOption, pixmapName );
1573 
1574 	if  ( ! apd )
1575 	    { XDEB(apd); return;	}
1576 
1577 	ea->eaPrintDialog= (void *)apd;
1578 	}
1579     else{
1580 	appSetShellTitle( apd->apdDialog.adTopWidget, printOption,
1581 						    ea->eaApplicationName );
1582 
1583 	appGuiShowDialog( ea, &(apd->apdDialog), ed->edToplevel.atTopWidget );
1584 	}
1585 
1586     apdr= apd->apdResources;
1587 
1588     apd->apdPrinterGeometry= ea->eaDefaultDocumentGeometry;
1589     apd->apdDocumentGeometry= *dgDocument;
1590 
1591     apd->apdPageCount= pageCount;
1592     apd->apdFirstSelectedPage= firstSelected;
1593     apd->apdLastSelectedPage= lastSelected;
1594     apd->apdFirstPageChosen= 0;
1595     apd->apdLastPageChosen= apd->apdPageCount- 1;
1596     apd->apdPrintOddFacesOnly= 0;
1597     apd->apdPrintEvenFacesOnly= 0;
1598     apd->apdPrintSheetsReverse= 0;
1599 
1600     psInitPrintGeometry( &pg );
1601     appApplicationSettingsToPrintGeometry( &pg, ea );
1602     pg.pgSheetGeometry= apd->apdPrinterGeometry;
1603 
1604     if  ( ea->eaSuggestPageSetup )
1605 	{ (*ea->eaSuggestPageSetup)( &pg, ed->edPrivateData, sheetSize ); }
1606 
1607     for ( i= 0; i < PSnum__COUNT; i++ )
1608 	{
1609 	if  ( apdr->apdrPlacements[i].psGridRows == pg.pgGridRows	&&
1610 	      apdr->apdrPlacements[i].psGridCols == pg.pgGridCols	&&
1611 	      apdr->apdrPlacements[i].psGridHorizontal ==
1612 						pg.pgGridHorizontal	&&
1613 	      apdr->apdrPlacements[i].psScalePagesToFit ==
1614 						pg.pgScalePagesToFit	)
1615 	    { apd->apdPlacementChosen= i; break; }
1616 	}
1617 
1618     appSetOptionmenu( &(apd->apdPlacementOptionmenu),
1619 						apd->apdPlacementChosen );
1620 
1621     apd->apdSelectionChosen= PRINTselAll_PAGES;
1622     appSetOptionmenu( &(apd->apdSelectionOptionmenu),
1623 						apd->apdSelectionChosen );
1624     appPrintDialogShowFromTo( apd, 1, apd->apdPageCount, 0 );
1625 
1626     guiEnableWidget( apd->apdSelectionOptions[PRINTselCURRENT_PAGE],
1627 			    ( apd->apdFirstSelectedPage >= 0	&&
1628 			      apd->apdLastSelectedPage >= 0	)	);
1629 
1630     appSetOptionmenu( &(apd->apdPrinterOptionmenu),
1631 						apd->apdOptionNrChosen );
1632 
1633     if  ( apd->apdOddFacesOnlyToggle )
1634 	{
1635 	appGuiSetToggleState( apd->apdOddFacesOnlyToggle,
1636 				    apd->apdPrintOddFacesOnly );
1637 	}
1638     if  ( apd->apdEvenFacesOnlyToggle )
1639 	{
1640 	appGuiSetToggleState( apd->apdEvenFacesOnlyToggle,
1641 				    apd->apdPrintEvenFacesOnly );
1642 	}
1643 
1644     if  ( apd->apdDirectionBackwardToggle )
1645 	{
1646 	appGuiSetToggleState( apd->apdDirectionBackwardToggle,
1647 						apd->apdPrintSheetsReverse );
1648 	}
1649     if  ( apd->apdDirectionForwardToggle )
1650 	{
1651 	appGuiSetToggleState( apd->apdDirectionForwardToggle,
1652 						! apd->apdPrintSheetsReverse );
1653 	}
1654 
1655     appPrinterAdaptToDestination( apd );
1656 
1657     appPaperChooserAdaptToGeometry( &(apd->apdPaperChooser),
1658 						&(apd->apdPrinterGeometry) );
1659 
1660     if  ( apd->apdCustomTransformRow )
1661 	{ appPrintDialogRefreshCustomTransform( apd );	}
1662 
1663     appGuiRunDialog( &(apd->apdDialog), AQDrespNONE, ea );
1664 
1665     switch( apd->apdDialog.adResponse )
1666 	{
1667 	case AQDrespOK:
1668 	    appPrintDialogPrint( ed, printOption, &pj, &pg, apd );
1669 	    appGuiHideDialog( &(apd->apdDialog) );
1670 	    goto ready;
1671 
1672 	default:
1673 	    LDEB(apd->apdDialog.adResponse);
1674 	    goto error;
1675 
1676 	case AQDrespCLOSED:
1677 	    goto ready;
1678 
1679 	case AQDrespCANCEL:
1680 	error:
1681 	    appGuiHideDialog( &(apd->apdDialog) );
1682 	    goto ready;
1683 	}
1684 
1685   ready:
1686     psCleanPrintGeometry( &pg );
1687     return;
1688     }
1689