cprinter_121.c 17.8 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
#include "cpicture_121.h"
#include "util_121.h"
#include "cprinter_121.h"
Peter Achten's avatar
Peter Achten committed
16

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

extern HWND   ghMainWindow;
extern HINSTANCE ghInst;

25 26 27 28 29 30 31 32 33 34 35 36 37
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;

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

49
static void mwMemcpy(char* dest, char *src, int count)
Peter Achten's avatar
Peter Achten committed
50
{
51 52 53
	int i;
	for(i=0; i<count; i++)
		dest[i]	= src[i];
Peter Achten's avatar
Peter Achten committed
54 55
}

56
static int CStringLength(char* string)
57 58 59 60 61 62 63 64 65
// returns length of C string INCLUDING the '\0'
{
	int i=0;
	while(string[i]!='\0')
		i++;
	i++;
	return i;
}

66
static CleanString PassCleanString(PassObject *pPassObj, char* data,unsigned int size)
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
{
	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,',',' ');
103 104 105
	*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);
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
	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);
}

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

130 131 132 133 134 135
	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;
}
136

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

139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
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;
	

154 155
	icPrint	= myCreateIC(	CleanStringCharacters(driver),CleanStringCharacters(device),
							(DEVMODE*) CleanStringCharacters(devmode));
156
	
157 158
	xResolution = GetDeviceCapsWithDefault(icPrint, LOGPIXELSX, 300);
	yResolution = GetDeviceCapsWithDefault(icPrint, LOGPIXELSY, 300);
159 160 161 162 163 164 165 166 167
	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;	};
	
168 169
	horPaperPixels	= (GetDeviceCapsWithDefault(icPrint, PHYSICALWIDTH, 2246)*scNX)/scDX;
	verPaperPixels	= (GetDeviceCapsWithDefault(icPrint, PHYSICALHEIGHT, 3250)*scNY)/scDY;
170

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

174 175
    *leftPaper		= (-GetDeviceCapsWithDefault(icPrint, PHYSICALOFFSETX, 116)*scNX)/scDX;
	*topPaper		= (-GetDeviceCapsWithDefault(icPrint, PHYSICALOFFSETY, 129)*scNY)/scDY;
176 177 178 179 180 181 182 183 184 185
	*rightPaper		= horPaperPixels - *leftPaper;
	*bottomPaper	= verPaperPixels - *topPaper;
	
	if (emulateScreenRes)
		{	*xRes = scNX;	*yRes = scNY; }
	  else
		{	*xRes = xResolution ;	*yRes = yResolution; };
	DeleteDC(icPrint);
}

186 187
static HANDLE setupDevnames(int deviceLength,int driverLength,int outputLength,
							char *device,char *driver,char *output)	
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
{
	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;
}

204
static HANDLE setupDevmode(int size, char *pData)
205 206 207 208 209 210 211 212 213 214 215
{
	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
216
void get_printSetup_with_PRINTDLG(PRINTDLG *pd, CleanString *o_devmode,
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
						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);
}

237
/*	PA: called in Clean. */
Martin Wierich's avatar
Martin Wierich committed
238
int release_memory_handles(PRINTDLG *pd, int os) {
Martin Wierich's avatar
bugfix  
Martin Wierich committed
239 240 241 242
	if (pd) {
		LocalFree(pd->hDevNames);
		LocalFree(pd->hDevMode);
		};
Martin Wierich's avatar
Martin Wierich committed
243 244
	return os;
	}
245

246
static UINT APIENTRY DialogToFrontHook(HWND hdl, UINT msg, WPARAM wParam, LPARAM lParam)
247 248 249 250 251 252 253 254 255 256 257 258
// 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
259
{
260 261 262
  	int			deviceLength, driverLength, outputLength;
	HANDLE		hDevnames,hDevmode;
	static PRINTDLG	pd;
Peter Achten's avatar
Peter Achten committed
263

264
	// Set up DEVNAMES structure
Peter Achten's avatar
Peter Achten committed
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
	//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;
295
	pd.lpfnSetupHook =  DialogToFrontHook;
296 297 298 299 300 301 302 303
	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
304 305 306 307

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

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


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
329 330
	bUserAbort = FALSE ;
    
331
	return StartDoc((HDC) hdc, &docInfo);
Peter Achten's avatar
Peter Achten committed
332 333
}

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

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

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

386 387 388 389 390 391 392 393
// 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
394 395 396 397
					// err code: -1:no error, others: non fatal error
{
	static PRINTDLG pd;
	HDC hdcPrint;
Martin Wierich's avatar
bugfix  
Martin Wierich committed
398
	int ok;
Peter Achten's avatar
Peter Achten committed
399 400 401 402 403
	
	*err = -1;

	if (doDialog)
	  {	// Set up print dialog record
404 405 406 407 408 409 410 411 412 413
		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
414 415 416 417 418 419

		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.
420 421
		pd.hDevMode = hDevmode;
		pd.hDevNames = hDevnames;
Peter Achten's avatar
Peter Achten committed
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441
		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
442 443 444 445 446 447 448 449 450 451 452
		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
453
	
Martin Wierich's avatar
bugfix  
Martin Wierich committed
454

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

Martin Wierich's avatar
bugfix  
Martin Wierich committed
468
	else
Peter Achten's avatar
Peter Achten committed
469
	  
470 471 472
		{ 	
		hdcPrint = CreateDC(driver, device, output, NULL);
		if (hdcPrint==NULL)
Peter Achten's avatar
Peter Achten committed
473 474 475 476 477 478
		  { *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
479
		*ppPrintDlg		= NULL;
480
		};
Peter Achten's avatar
Peter Achten committed
481 482 483 484 485 486 487 488 489 490 491 492 493

	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;
494
	//rMessageBox(NULL, MB_APPLMODAL, "leaving getDC","");
Peter Achten's avatar
Peter Achten committed
495

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



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

538
HWND CreateCancelDialog(void)
Peter Achten's avatar
Peter Achten committed
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
{
	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; 
594
	hwndText = CreateWindow ("static", "",WS_VISIBLE | WS_CHILD | SS_CENTER, 
Peter Achten's avatar
Peter Achten committed
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617
									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; 
}

618
/*	PA: Called in Clean. */
Peter Achten's avatar
Peter Achten committed
619 620 621 622 623
int addSemaphor(int add)
{
	int old=semaphor;
	semaphor+=add;
	return old;
624 625 626 627 628 629 630 631
}

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

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