cprinter_121.c 17.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
/********************************************************************************************
	Clean OS Windows library module version 1.2.1.
	This module is part of the Clean Object I/O library and Clean 0.8 I/O library
	for the Windows platform.
********************************************************************************************/

/********************************************************************************************
	About this module:
	Routines related to printing.
********************************************************************************************/
Peter Achten's avatar
Peter Achten committed
11
12
#include <windows.h>
#include <limits.h>
13
14
15
16
#include "cpicture_121.h"
#include "util_121.h"
#include "cCrossCall_121.h"
#include "cprinter_121.h"
Peter Achten's avatar
Peter Achten committed
17

18
19
BOOL	bUserAbort;
HWND	hDlgPrint;
Peter Achten's avatar
Peter Achten committed
20
21
22
23
24
25
HWND	hwndButton,hwndText;
int		semaphor=0;

extern HWND   ghMainWindow;
extern HINSTANCE ghInst;

26
27
28
29
30
31
32
33
34
35
36
37
38
39
typedef struct pass_object *PassObject;
/*	with a PassObject one can pass strings back to Clean. It's first DWORD
	contains the size of the object -8, the second DWORD contains the length
	of the string, and the rest contains the string itself. In

	PassObject	pObj;
	
	the following expression points to a Clean string:

	((char*)passObj)[4] 
*/
PassObject	passObj1 = NULL, passObj2 = NULL, passObj3 = NULL, passObj4 = NULL;

void mwStrcpy(char* dest, char *src)
Peter Achten's avatar
Peter Achten committed
40
{
41
42
43
44
45
46
47
	int i=0;
	while (src[i]!='\0')
		{
		dest[i]	= src[i];
		i++;
		};
	dest[i]	= '\0';
Peter Achten's avatar
Peter Achten committed
48
49
}

50
void mwMemcpy(char* dest, char *src, int count)
Peter Achten's avatar
Peter Achten committed
51
{
52
53
54
	int i;
	for(i=0; i<count; i++)
		dest[i]	= src[i];
Peter Achten's avatar
Peter Achten committed
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
int CStringLength(char* string)
// returns length of C string INCLUDING the '\0'
{
	int i=0;
	while(string[i]!='\0')
		i++;
	i++;
	return i;
}

CleanString PassCleanString(PassObject *pPassObj, char* data,unsigned int size)
{
	unsigned int	passObjSize,i;
	PassObject		passObj;

	if (*pPassObj==NULL)
		{
		*pPassObj	= (PassObject) LocalAlloc(LMEM_FIXED, size+8);
		((unsigned int*)*pPassObj)[0]	= size;
		};
	passObjSize	= ((unsigned int*)*pPassObj)[0];
	if (passObjSize<size)
		{
		LocalFree(LocalHandle(*pPassObj));
		*pPassObj	= (PassObject) LocalAlloc(LMEM_FIXED, size+8);
		((unsigned int*)*pPassObj)[0]	= size;
		};
	// now the pass object is big enough, so fill it with data
	passObj		= *pPassObj;
	((unsigned int*)passObj)[1]	= size;
	for(i=0; i<size; i++)
		((char*)passObj)[i+8]	= data[i];
	return (CleanString) (((unsigned int*)passObj)+1);
}

#define tachtig 80
void getDevmodeSizeC(int *size, HANDLE *phPrinter,
					 CleanString *device, CleanString *driver,  CleanString *output)
{
	char	szPrinterSpace[80];
	char	*szPrinter = szPrinterSpace;
	char	*szDevice, *szDriver, *szOutput;

	GetProfileString("windows", "device", ",,,", szPrinter, 80);
	szDevice = strtokMW(&szPrinter,',',',');
	szDriver = strtokMW(&szPrinter,',',' ');
	szOutput = strtokMW(&szPrinter,',',' ');
104
105
106
	*device	= PassCleanString(&passObj1,szDevice,CStringLength(szDevice)+1); // add 1 so '\0' will be passed too
	*driver	= PassCleanString(&passObj2,szDriver,CStringLength(szDriver)+1);
	*output	= PassCleanString(&passObj3,szOutput,CStringLength(szOutput)+1);
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
	if (*szDevice=='\0' || szDriver=='\0' || *szOutput=='\0')
		{
		*size	= 0;
		return;
		};
	OpenPrinter(szDevice,phPrinter,NULL);
	*size = DocumentProperties(NULL,*phPrinter,szDevice,NULL,NULL,0);
}

void getDefaultDevmodeC(char *printSetup, LPHANDLE phPrinter,  CleanString *device)
{
	int		size,r1;

	size		= ((int*)printSetup)[0];
	printSetup	+=4;
	r1 = DocumentProperties(NULL,phPrinter,((char*)device)+4,
							(DEVMODE*)printSetup,NULL,DM_OUT_BUFFER);
	ClosePrinter(phPrinter);
}

127
HDC myCreateIC(LPCTSTR driver, LPCTSTR device, DEVMODE *devmode)
128
129
{
	HDC	icPrint;
130

131
132
133
134
135
136
	icPrint	= CreateIC(driver,device,NULL,devmode);
	if (!icPrint)
		icPrint	= CreateIC(driver,device,NULL,devmode);
		// try once again. Adobe printer drivers sometimes need to be told everything twice
	return icPrint;
}
137

138
139
#define GetDeviceCapsWithDefault(icPrint, index, defaullt) (icPrint ? GetDeviceCaps(icPrint, index) : defaullt)

140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
void os_getpagedimensionsC(	CleanString devmode,
							CleanString device, CleanString driver,
							int emulateScreenRes,
							int *maxX, int *maxY,
							int *leftPaper, int *topPaper,
							int *rightPaper, int *bottomPaper,
							int	*xRes, int *yRes
						  )
{
	HDC	icPrint;
	int horPaperPixels, verPaperPixels,
		xResolution,yResolution,
		scNX, scNY, scDX, scDY;
	

155
156
	icPrint	= myCreateIC(	CleanStringCharacters(driver),CleanStringCharacters(device),
							(DEVMODE*) CleanStringCharacters(devmode));
157
	
158
159
	xResolution = GetDeviceCapsWithDefault(icPrint, LOGPIXELSX, 300);
	yResolution = GetDeviceCapsWithDefault(icPrint, LOGPIXELSY, 300);
160
161
162
163
164
165
166
167
168
	if (emulateScreenRes)						// for emulation of the screen resolution
		{	scNX = WinGetHorzResolution();		// all the deviceCaps will be scaled
			scNY = WinGetVertResolution();
			scDX = xResolution;
			scDY = yResolution;
		}
	  else
		{	scNX = 1; scNY = 1; scDX = 1; scDY = 1;	};
	
169
170
	horPaperPixels	= (GetDeviceCapsWithDefault(icPrint, PHYSICALWIDTH, 2246)*scNX)/scDX;
	verPaperPixels	= (GetDeviceCapsWithDefault(icPrint, PHYSICALHEIGHT, 3250)*scNY)/scDY;
171

172
173
	*maxX			= (GetDeviceCapsWithDefault(icPrint, HORZRES, 2241)*scNX)/scDX;
	*maxY			= (GetDeviceCapsWithDefault(icPrint, VERTRES, 3254)*scNY)/scDY;
174

175
176
    *leftPaper		= (-GetDeviceCapsWithDefault(icPrint, PHYSICALOFFSETX, 116)*scNX)/scDX;
	*topPaper		= (-GetDeviceCapsWithDefault(icPrint, PHYSICALOFFSETY, 129)*scNY)/scDY;
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
	*rightPaper		= horPaperPixels - *leftPaper;
	*bottomPaper	= verPaperPixels - *topPaper;
	
	if (emulateScreenRes)
		{	*xRes = scNX;	*yRes = scNY; }
	  else
		{	*xRes = xResolution ;	*yRes = yResolution; };
	DeleteDC(icPrint);
}

HANDLE setupDevnames(int deviceLength,int driverLength,int outputLength,
					 char *device,char *driver,char *output)	
{
	HANDLE		hDevnames;
	DEVNAMES	*pDevnames;
	hDevnames	= (HANDLE) LocalAlloc(LMEM_MOVEABLE, 16+deviceLength+driverLength+outputLength);
	pDevnames	= LocalLock(hDevnames);
	pDevnames->wDriverOffset	= 16;
	pDevnames->wDeviceOffset	= 16+driverLength;
	pDevnames->wOutputOffset	= 16+driverLength+deviceLength;
	pDevnames->wDefault			= 0;
	mwStrcpy(((char*)pDevnames)+pDevnames->wDriverOffset, driver);
	mwStrcpy(((char*)pDevnames)+pDevnames->wDeviceOffset, device);
	mwStrcpy(((char*)pDevnames)+pDevnames->wOutputOffset, output);
	LocalUnlock(hDevnames);
	return hDevnames;
}

HANDLE setupDevmode(int size, char *pData)
{
	HANDLE	hDevmode;
	DEVMODE	*pDevmode;

	hDevmode	= (HANDLE) LocalAlloc(LMEM_MOVEABLE, size);
	pDevmode	= LocalLock(hDevmode);
	mwMemcpy((char*)pDevmode, pData, size);
	LocalUnlock(hDevmode);
	return hDevmode;
}

Martin Wierich's avatar
Martin Wierich committed
217
void get_printSetup_with_PRINTDLG(PRINTDLG *pd, CleanString *o_devmode,
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
						CleanString *o_device, CleanString *o_driver, CleanString *o_output)
{
	char		*newDriver, *newDevice, *newOutput;
	DEVMODE		*pDevmode;
	DEVNAMES	*pDevnames;

	pDevmode	= LocalLock(pd->hDevMode);
	*o_devmode	= PassCleanString(&passObj1,(char*) pDevmode,
								   pDevmode->dmSize+pDevmode->dmDriverExtra);
	LocalUnlock(pd->hDevMode);
	pDevnames	= LocalLock(pd->hDevNames);
	newDriver	= ((char*)pDevnames)+(pDevnames->wDriverOffset);
	newDevice	= ((char*)pDevnames)+(pDevnames->wDeviceOffset);
	newOutput	= ((char*)pDevnames)+(pDevnames->wOutputOffset);
	*o_driver	= PassCleanString(&passObj2,newDriver,CStringLength(newDriver)+1);
	*o_device	= PassCleanString(&passObj3,newDevice,CStringLength(newDevice)+1);
	*o_output	= PassCleanString(&passObj4,newOutput,CStringLength(newOutput)+1);
	LocalUnlock(pd->hDevNames);
}

Martin Wierich's avatar
Martin Wierich committed
238
int release_memory_handles(PRINTDLG *pd, int os) {
239
240
	LocalFree(pd->hDevNames);
	LocalFree(pd->hDevMode);
Martin Wierich's avatar
Martin Wierich committed
241
242
	return os;
	}
243
244
245
246
247
248
249
250
251
252
253
254
255
256

UINT APIENTRY DialogToFrontHook(HWND hdl, UINT msg, WPARAM wParam, LPARAM lParam)
// This function hooks the Print dialog. It's purpose is to set the dialog in the
// foreground.
{
     if (msg==WM_INITDIALOG)
		{ SetForegroundWindow(hdl);
		};
	 return FALSE;
}

void printSetup(int calledFromCleanThread, int devmodeSize,
			   char *devmode, char *device, char *driver, char *output,
			   int *ok, PRINTDLG **pdPtr)
Peter Achten's avatar
Peter Achten committed
257
{
258
259
260
  	int			deviceLength, driverLength, outputLength;
	HANDLE		hDevnames,hDevmode;
	static PRINTDLG	pd;
Peter Achten's avatar
Peter Achten committed
261

262
	// Set up DEVNAMES structure
Peter Achten's avatar
Peter Achten committed
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
	//rMessageBox(NULL, MB_APPLMODAL, "in printSetup", "");
	deviceLength	= CStringLength(device);
	driverLength	= CStringLength(driver);
	outputLength	= CStringLength(output);
	
	hDevnames	= setupDevnames(deviceLength,driverLength,outputLength,device,driver,output);

	// Set up DEVMODE structure
	hDevmode	= setupDevmode(devmodeSize,devmode);

	// Set up print dialog record
	pd.lStructSize = sizeof(PRINTDLG);
	pd.hwndOwner = calledFromCleanThread ? NULL : ghMainWindow;	// (NULL = desktop)
//	pd.hwndOwner = NULL;	// (NULL = desktop)
		// the handle must belong to the active thread, otherwise PrintDlg will crash
		// When this function is called from the Clean thread, ghMainWindow will not
		// belong to the active thread.
	pd.hDevMode = hDevmode;
	pd.hDevNames = hDevnames;
	pd.hDC = NULL;
	pd.Flags =	PD_PRINTSETUP | PD_ENABLESETUPHOOK;
	pd.nFromPage = 1;
	pd.nToPage = 1; 
	pd.nMinPage = 1;
	pd.nMaxPage = USHRT_MAX;
	pd.nCopies = 1;
	pd.hInstance = NULL;
	pd.lCustData = 0L;
	pd.lpfnPrintHook = NULL;
293
	pd.lpfnSetupHook =  DialogToFrontHook;
294
295
296
297
298
299
300
301
	pd.lpPrintTemplateName = NULL;
	pd.lpSetupTemplateName = NULL;
	pd.hPrintTemplate = NULL;
	pd.hSetupTemplate = NULL;

	// Open print dialog
	*ok	= PrintDlg(&pd);
	*pdPtr = &pd;
Martin Wierich's avatar
bugfix  
Martin Wierich committed
302
303
304
305

	if (hDevnames!=pd.hDevNames) LocalFree(hDevnames);
	if (hDevmode!=pd.hDevMode) LocalFree(hDevmode);

306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
}


int startPage(int hdc)
{
	//rMessageBox(NULL, MB_APPLMODAL, "in startPage", "");
	return StartPage((HDC) hdc) > 0;
}

int endPage(int hdc)
{
	//rMessageBox(NULL, MB_APPLMODAL, "in endPage", "");
	return EndPage((HDC) hdc) > 0;
}

int startDoc(int hdc)
			// err code: >0:no error, <=0: user cancelled file dialog
{
	static DOCINFO docInfo = { sizeof (DOCINFO), "Clean", NULL, NULL, 0 } ;

	//rMessageBox(NULL, MB_APPLMODAL, "in startDoc", "");
Peter Achten's avatar
Peter Achten committed
327
328
	bUserAbort = FALSE ;
    
329
	return StartDoc((HDC) hdc, &docInfo);
Peter Achten's avatar
Peter Achten committed
330
331
}

332
void endDoc(int hdc)
Peter Achten's avatar
Peter Achten committed
333
{
334
	//rMessageBox(NULL, MB_APPLMODAL, "in endDoc", "");
Peter Achten's avatar
Peter Achten committed
335
336
337
338
339
340
	if (bUserAbort)
		AbortDoc((HDC) hdc);
	  else
		EndDoc((HDC) hdc);
}

341
void deleteDC(int hdc)
Peter Achten's avatar
Peter Achten committed
342
{
343
	//rMessageBox(NULL, MB_APPLMODAL, "in deleteDC", "");
Peter Achten's avatar
Peter Achten committed
344
345
346
347
348
	DeleteDC((HDC) hdc);
}

int wasCanceled()
{
349
	//rMessageBox(NULL, MB_APPLMODAL, "in wasCanceled", "");
Peter Achten's avatar
Peter Achten committed
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
	return bUserAbort;
}

/* getDC opens the print job dialog and 
 * lets the user change various settings or gets the default printer
 */

char * strtokMW(char **str, const char ch1, const char ch2)
/* 	nearly like the standard strtok function. This function splits a null terminated
	string into two parts. From the beginning of the string it searches for the next
	occurence of ch1 or ch2, replaces that character with '\0' and gives back the
	first part. The first parameter will be altered, so that it points now to the
	string after that '\0' character.
*/   
{
	char *start,*count;
	int terminate=0;
	start=*str;
	count=*str;
	do 
	  {	if (*count==ch1 || *count==ch2 || *count=='\0')
			{ terminate=1; }
		  else 
		  	count = CharNext(count);	// I hope this works well in the far east
	  }									// (multibyte character codes)
	  while (!terminate);
	if (*count!='\0')
	  { *count='\0';
	    count++;
	  };
	*str=count;
	return start;
}

384
385
386
387
388
389
390
391
// c-strings are passed to this function !
void getDC( int doDialog, int emulateScreen, int calledFromCleanThread, int devmodeLength,
			char *devmode,char *device,char *driver,char *output,
			int *err,
			int *first, int *last, int *copies,
			PRINTDLG	**ppPrintDlg,
			int *deviceContext
	 		)
Peter Achten's avatar
Peter Achten committed
392
393
394
395
					// err code: -1:no error, others: non fatal error
{
	static PRINTDLG pd;
	HDC hdcPrint;
Martin Wierich's avatar
bugfix  
Martin Wierich committed
396
	int ok;
Peter Achten's avatar
Peter Achten committed
397
398
399
400
401
	
	*err = -1;

	if (doDialog)
	  {	// Set up print dialog record
402
403
404
405
406
407
408
409
410
411
		HANDLE	hDevnames, hDevmode;
		int deviceLength,driverLength,outputLength;

		deviceLength	= CStringLength(device);
		driverLength	= CStringLength(driver);
		outputLength	= CStringLength(output);
	
		hDevnames	= setupDevnames(deviceLength,driverLength,outputLength,
									device,driver,output);
		hDevmode	= setupDevmode(devmodeLength,devmode);
Peter Achten's avatar
Peter Achten committed
412
413
414
415
416
417

		pd.lStructSize = sizeof(PRINTDLG);
		pd.hwndOwner = calledFromCleanThread ? NULL : ghMainWindow;	// (NULL = desktop)
			// the handle must belong to the active thread, otherwise PrintDlg will crash
			// When this function is called from the Clean thread, ghMainWindow will not
			// belong to the active thread.
418
419
		pd.hDevMode = hDevmode;
		pd.hDevNames = hDevnames;
Peter Achten's avatar
Peter Achten committed
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
		pd.hDC = NULL;
		pd.Flags = PD_ALLPAGES | PD_COLLATE | PD_RETURNDC | PD_NOSELECTION 
				 | PD_ENABLEPRINTHOOK;
		      // hide some options from print dialog
		pd.nFromPage = 1;
		pd.nToPage = 1; 
		pd.nMinPage = 1;
		pd.nMaxPage = USHRT_MAX;
		pd.nCopies = 1;
		pd.hInstance = NULL;
		pd.lCustData = 0L;
		pd.lpfnPrintHook = DialogToFrontHook;
		pd.lpfnSetupHook = NULL;
		pd.lpPrintTemplateName = NULL;
		pd.lpSetupTemplateName = NULL;
		pd.hPrintTemplate = NULL;
		pd.hSetupTemplate = NULL;

		// Open print dialog

Martin Wierich's avatar
bugfix  
Martin Wierich committed
440
441
442
443
444
445
446
447
448
449
450
		ok = PrintDlg(&pd);

		if (hDevnames!=pd.hDevNames) LocalFree(hDevnames);
		if (hDevmode!=pd.hDevMode) LocalFree(hDevmode);
		
		if (!ok)
			{
			*err = CommDlgExtendedError();	// will return 0 iff user canceled, otherwise positive value 
			release_memory_handles(&pd, 0);
			return;
			}
Peter Achten's avatar
Peter Achten committed
451
	
Martin Wierich's avatar
bugfix  
Martin Wierich committed
452

Peter Achten's avatar
Peter Achten committed
453
454
455
456
457
458
459
460
461
		if (pd.Flags & PD_PAGENUMS)
			{ *first	= pd.nFromPage;
			  *last		= pd.nToPage;
			}
		  else
			{ *first	= 1;
			  *last		= 9999;
			};
		*copies			= pd.nCopies;
462
		*ppPrintDlg		= &pd;
Peter Achten's avatar
Peter Achten committed
463
464
465
		hdcPrint		= pd.hDC;
	  }

Martin Wierich's avatar
bugfix  
Martin Wierich committed
466
	else
Peter Achten's avatar
Peter Achten committed
467
	  
468
469
470
		{ 	
		hdcPrint = CreateDC(driver, device, output, NULL);
		if (hdcPrint==NULL)
Peter Achten's avatar
Peter Achten committed
471
472
473
474
475
476
		  { *err = 0;	// non fatal error, iff e.g. no printer driver is installed
	 	    return;
		  };
		*first	= 1;
		*last	= 9999;
		*copies	= 1;
Martin Wierich's avatar
bugfix  
Martin Wierich committed
477
		*ppPrintDlg		= NULL;
478
		};
Peter Achten's avatar
Peter Achten committed
479
480
481
482
483
484
485
486
487
488
489
490
491

	if (emulateScreen)
		{	int pXdpi,pYdpi,sXdpi,sYdpi;
			pXdpi = GetDeviceCaps(hdcPrint, LOGPIXELSX);
			pYdpi = GetDeviceCaps(hdcPrint, LOGPIXELSY);
			sXdpi = WinGetHorzResolution();
			sYdpi = WinGetVertResolution();
			SetMapMode(hdcPrint, MM_ISOTROPIC);
			SetWindowExtEx  (hdcPrint,sXdpi, sYdpi, NULL);
			SetViewportExtEx(hdcPrint,pXdpi, pYdpi, NULL);
		};
	
	*deviceContext	= (int) hdcPrint;
492
	//rMessageBox(NULL, MB_APPLMODAL, "leaving getDC","");
Peter Achten's avatar
Peter Achten committed
493

494
}
Peter Achten's avatar
Peter Achten committed
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



BOOL CALLBACK PrintDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
     {
     switch (msg)
          {
          case WM_INITDIALOG :
               EnableMenuItem (GetSystemMenu (hDlg, FALSE), SC_CLOSE,
                                                            MF_GRAYED) ;
               return TRUE ;
          case WM_COMMAND :
               bUserAbort = TRUE ;
               EnableWindow (ghMainWindow, TRUE) ;
               DestroyWindow (hDlg) ;
               hDlgPrint = 0 ;
               return TRUE ;
          }
     return FALSE;
	 }

BOOL CALLBACK AbortProc (HDC hdcPrn, int iCode)
     {
     MSG   msg ;

     while (!bUserAbort && PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
          {
          if (!hDlgPrint || !IsDialogMessage (hDlgPrint, &msg))
               {
               TranslateMessage (&msg) ;
               DispatchMessage (&msg) ;
               }
          }
     return !bUserAbort ;
     }


#define DIALOG_WIDTH 100
#define DIALOG_HEIGHT 60
	// in dialog units

HWND CreateCancelDialog()
{
	HWND hwndButton,dlgHdl;

	WORD *p, *pdlgtemplate,baseunitX,baseunitY;
	int nchar;
	int scrnWidth,scrnHeight;
	int buttonX, buttonY, buttonWidth, buttonHeight;
	int textX, textY, textWidth, textHeight;
	DWORD lStyle,baseunits;
	HDC screen;
	LOGFONT lf;

	/* allocate some memory to play with  */
	pdlgtemplate = p = (PWORD) rmalloc (1000);

	screen = CreateDC ("DISPLAY", NULL, NULL, NULL);
	scrnWidth  = GetDeviceCaps (screen, HORZRES);
	scrnHeight = GetDeviceCaps (screen, VERTRES);
	DeleteDC (screen);
	baseunits = GetDialogBaseUnits();

	/* start to fill in the dlgtemplate information.  addressing by WORDs */
	lStyle = WS_CAPTION | DS_MODALFRAME | WS_SYSMENU;

	baseunitX=LOWORD(baseunits);
	baseunitY=HIWORD(baseunits);

	*p++ = LOWORD (lStyle);
	*p++ = HIWORD (lStyle);
	*p++ = 0;		/* LOWORD (lExtendedStyle) */
	*p++ = 0;		/* HIWORD (lExtendedStyle) */
	*p++ = 0;		/* NumberOfItems */
	*p++ = ((scrnWidth*4)/3)/baseunitX;		// x 
	*p++ = ((scrnHeight*8)/3)/baseunitY;	// y
	*p++ = DIALOG_WIDTH;	/* cx */
	*p++ = DIALOG_HEIGHT;	/* cy */
	*p++ = 0;		/* Menu */
	*p++ = 0;		/* Class */

	/* copy the title of the dialog */
	nchar = nCopyAnsiToWideChar (p, (char *) "Printing in Progress");
	p += nchar;
	
	dlgHdl = CreateDialogIndirectParam (ghInst, (LPDLGTEMPLATE) pdlgtemplate, ghMainWindow,
										(DLGPROC) PrintDlgProc, (LPARAM) 0);

	LocalFree (LocalHandle (pdlgtemplate));

	// Add a text field
	textWidth = 19*baseunitX;
	textHeight = baseunitY;
	textX =    (((DIALOG_WIDTH*baseunitX)/4) - textWidth)
		       / 2;
	textY =    (((DIALOG_HEIGHT*baseunitY)/8) - textHeight)
			   / 4; 
592
	hwndText = CreateWindow ("static", "",WS_VISIBLE | WS_CHILD | SS_CENTER, 
Peter Achten's avatar
Peter Achten committed
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
									textX, textY, textWidth, textHeight,
									dlgHdl, (HMENU) 0, ghInst, 0);

	
	// Add a Cancel button:
	buttonWidth = 10*baseunitX;
	buttonHeight = (3*baseunitY)/2;
	buttonX =    (((DIALOG_WIDTH*baseunitX)/4) - buttonWidth)
		       / 2;
	buttonY =  (3 *  (((DIALOG_HEIGHT*baseunitY)/8) - buttonHeight))
			   / 5; 
	hwndButton = CreateWindow ("button", "Cancel", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
									buttonX, buttonY, buttonWidth, buttonHeight,
									dlgHdl, (HMENU) 0, ghInst, 0);
	SetLogFontData (&lf,"MS Sans Serif",0,8);
	SendMessage(hwndButton,WM_SETFONT,(WPARAM)CreateFontIndirect (&lf),MAKELPARAM (TRUE,0));
	SendMessage(hwndText,WM_SETFONT,(WPARAM)CreateFontIndirect (&lf),MAKELPARAM (TRUE,0));

	ShowWindow (dlgHdl,SW_SHOWNORMAL);

	return dlgHdl; 
}


int addSemaphor(int add)
{
	int old=semaphor;
	semaphor+=add;
	return old;
622
623
624
625
626
627
628
629
}

int os_printsetupvalidC(	CleanString devmode,
							CleanString device, CleanString driver
					  )
{
	HDC	icPrint;

630
631
	icPrint	= myCreateIC(	CleanStringCharacters(driver),CleanStringCharacters(device),
							(DEVMODE*) CleanStringCharacters(devmode));
632
633
634
635
	if (icPrint)
		DeleteDC(icPrint);
	return icPrint!=NULL;
}