Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

590 lines
17 KiB

  1. /*===========================================================================*/
  2. /* Copyright (c) 1987 - 1988, Future Soft Engineering, Inc. */
  3. /* Houston, Texas */
  4. /*===========================================================================*/
  5. #define NOGDICAPMASKS TRUE
  6. #define NOVIRTUALKEYCODES TRUE
  7. #define NOICONS TRUE
  8. #define NOKEYSTATES TRUE
  9. #define NOSYSCOMMANDS TRUE
  10. #define NOATOM TRUE
  11. #define NOCLIPBOARD TRUE
  12. #define NODRAWTEXT TRUE
  13. #define NOMB TRUE
  14. #define NOOPENFILE TRUE
  15. #define NOSCROLL TRUE
  16. #define NOHELP TRUE
  17. #define NOPROFILER TRUE
  18. #define NODEFERWINDOWPOS TRUE
  19. #define NOPEN TRUE
  20. #define NO_TASK_DEFINES TRUE
  21. #define NOLSTRING TRUE
  22. #define WIN31
  23. #include <windows.h>
  24. #include "port1632.h"
  25. #include "dcrc.h"
  26. #include "dynacomm.h"
  27. #include "task.h"
  28. #include "printfil.h"
  29. #include <commdlg.h>
  30. /*BUG BUG Get this file from 31 folks .... -sdj #include <drivinit.h> */
  31. BOOL PrintFileOn(HANDLE,HWND,LPSTR,LPSTR,LPSTR,LPSTR,BOOL);
  32. BOOL PrintFileOff();
  33. /*---------------------------------------------------------------------------*/
  34. BOOL PrintFileInit()
  35. {
  36. hPrintFile = NULL;
  37. return(TRUE);
  38. }
  39. /*---------------------------------------------------------------------------*/
  40. INT_PTR APIENTRY dbAbortDlg (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  41. {
  42. switch(msg)
  43. {
  44. case WM_INITDIALOG:
  45. lpPrintFile = (LPPRINTREC) GlobalLock(hPrintFile);
  46. SetDlgItemText(hDlg, 99, lpPrintFile->title);
  47. SetFocus (hDlg);
  48. GlobalUnlock(hPrintFile);
  49. return TRUE;
  50. break;
  51. case WM_COMMAND:
  52. lpPrintFile = (LPPRINTREC) GlobalLock(hPrintFile);
  53. lpPrintFile->cancelAbort = TRUE;
  54. GlobalUnlock(hPrintFile);
  55. return TRUE;
  56. break;
  57. }
  58. return FALSE;
  59. }
  60. /*---------------------------------------------------------------------------*/
  61. BOOL APIENTRY abortDlgProc(HDC hPrintDC, INT iReserved)
  62. {
  63. return(TRUE); /* jtfnew */
  64. }
  65. /*---------------------------------------------------------------------------*/
  66. BOOL APIENTRY PrintFileComm(BOOL bPrint) /* rjs bugs 013 */
  67. {
  68. /* Added 02/22/91 for common print dialog by w-dougw */
  69. LPDEVNAMES lpDevNames = NULL;
  70. if(hDevNames)
  71. lpDevNames = (LPDEVNAMES)GlobalLock(hDevNames);
  72. if(bPrint != prtFlag)
  73. {
  74. prtFlag = bPrint;
  75. CheckMenuItem(hMenu, FMPRINTER, prtFlag ? MF_CHECKED : MF_UNCHECKED);
  76. if(prtFlag)
  77. {
  78. if(lpDevNames)
  79. {
  80. if(!(PrintFileOn((HANDLE) hInst, (HWND) hItWnd,
  81. (LPSTR)szAppName,
  82. (LPSTR)lpDevNames+lpDevNames->wDeviceOffset,
  83. (LPSTR)lpDevNames+lpDevNames->wDriverOffset,
  84. (LPSTR)lpDevNames+lpDevNames->wOutputOffset, FALSE)))
  85. {
  86. GlobalUnlock(hDevNames);
  87. return(FALSE);
  88. }
  89. }
  90. else
  91. {
  92. if(!(PrintFileOn((HANDLE) hInst, (HWND) hItWnd,
  93. (LPSTR)szAppName,
  94. NULL_STR,
  95. NULL_STR,
  96. NULL_STR, FALSE)))
  97. {
  98. GlobalUnlock(hDevNames);
  99. return(FALSE);
  100. }
  101. }
  102. PrintFileControl( PRINTFILECRTOLF, TRUE, 0L);
  103. }
  104. else
  105. PrintFileOff();
  106. }
  107. if(hDevNames)
  108. GlobalUnlock(hDevNames);
  109. return TRUE;
  110. }
  111. BOOL PrintFileOn(HANDLE theInstance, HWND theWnd, LPSTR thePrintName,
  112. LPSTR thePrintType, LPSTR thePrintDriver, LPSTR thePrintPort,
  113. BOOL showDialog)
  114. {
  115. CHAR pPrintInfo[80];
  116. LPSTR lpTemp;
  117. LPSTR lpPrintType;
  118. LPSTR lpPrintDriver;
  119. LPSTR lpPrintPort;
  120. TEXTMETRIC tmMetric;
  121. BYTE spool[255];
  122. BYTE szWindows[MINRESSTR];
  123. BYTE szDevice[MINRESSTR];
  124. LPDEVMODE lpDevMode;
  125. if(hPrintFile)
  126. {
  127. lpPrintFile = (LPPRINTREC) GlobalLock(hPrintFile);
  128. lpPrintFile->openCount++;
  129. GlobalUnlock(hPrintFile);
  130. return(TRUE); /* Assume print channel open */
  131. }
  132. hPrintFile = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) sizeof(PRINTREC));
  133. if(hPrintFile == NULL)
  134. return(FALSE); /* not enough memory */
  135. lpPrintFile = (LPPRINTREC) GlobalLock(hPrintFile);
  136. lpPrintFile->active = FALSE;
  137. lpPrintFile->openCount = 1;
  138. LoadString(hInst, STR_INI_WINDOWS, szWindows, MINRESSTR);
  139. LoadString(hInst, STR_INI_DEVICE, szDevice, MINRESSTR);
  140. if(!GetProfileString(szWindows, (LPSTR) szDevice, (LPSTR) NULL_STR, (LPSTR) pPrintInfo, 80))
  141. {
  142. GlobalUnlock(hPrintFile);
  143. hPrintFile = GlobalFree(hPrintFile);
  144. return(FALSE);
  145. }
  146. lpTemp = lpPrintType = pPrintInfo;
  147. lpPrintDriver = lpPrintPort = 0;
  148. while(*lpTemp)
  149. {
  150. if(*lpTemp == ',')
  151. {
  152. *lpTemp++ = 0;
  153. while (*lpTemp == ' ')
  154. lpTemp = AnsiNext(lpTemp);
  155. if(!lpPrintDriver)
  156. lpPrintDriver = lpTemp;
  157. else
  158. {
  159. lpPrintPort = lpTemp;
  160. break;
  161. }
  162. }
  163. else
  164. lpTemp = AnsiNext(lpTemp);
  165. }
  166. lpDevMode = (LPDEVMODE)GlobalLock(hDevMode);
  167. /* Overide win.ini with script referenced driver */
  168. if (lstrlen(thePrintDriver) > 0) lpPrintDriver = thePrintDriver;
  169. if (lstrlen(thePrintType) > 0) lpPrintType = thePrintType;
  170. if (lstrlen(thePrintPort) > 0) lpPrintPort = thePrintPort;
  171. lpPrintFile->hPrintDC = CreateDC((LPSTR)lpPrintDriver ,(LPSTR)lpPrintType,
  172. (LPSTR)lpPrintPort, (LPDEVMODE)lpDevMode);
  173. GlobalUnlock(hDevMode);
  174. if (!lpPrintFile->hPrintDC) /* could not get DC */
  175. {
  176. GlobalUnlock(hPrintFile);
  177. hPrintFile = GlobalFree(hPrintFile);
  178. return(FALSE);
  179. }
  180. GetTextMetrics(lpPrintFile->hPrintDC,&tmMetric);
  181. lpPrintFile->nLineHeight = (SHORT)(tmMetric.tmHeight + tmMetric.tmExternalLeading);
  182. lpPrintFile->font.lfHeight = 0;
  183. lpPrintFile->font.lfWidth = 0;
  184. lpPrintFile->font.lfEscapement = 0;
  185. lpPrintFile->font.lfOrientation = 0;
  186. lpPrintFile->font.lfWeight = 400;
  187. lpPrintFile->font.lfItalic = tmMetric.tmItalic;
  188. lpPrintFile->font.lfUnderline = tmMetric.tmUnderlined;
  189. lpPrintFile->font.lfStrikeOut = tmMetric.tmStruckOut;
  190. lpPrintFile->font.lfCharSet = tmMetric.tmCharSet;
  191. lpPrintFile->font.lfOutPrecision = OUT_DEFAULT_PRECIS;
  192. lpPrintFile->font.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  193. lpPrintFile->font.lfQuality = DEFAULT_QUALITY;
  194. lpPrintFile->font.lfPitchAndFamily = (DEFAULT_PITCH | FF_DONTCARE);
  195. GetTextFace(lpPrintFile->hPrintDC,LF_FACESIZE,
  196. lpPrintFile->font.lfFaceName);
  197. lpPrintFile->tab = 8; /* Default tab */
  198. lpPrintFile->prtLine = 0; /* Current line being printed */
  199. lpPrintFile->charCount = 0; /* Current position in line */
  200. lpPrintFile->pixColCount = 0; /* Keep col for pix count */
  201. lpPrintFile->pixCount = 0; /* Keep track of x position */
  202. lpPrintFile->cancelAbort = FALSE; /* Cancel printing flag */
  203. lpPrintFile->CRtoLF = FALSE; /* Do not translate CR's */
  204. lpPrintFile->fileio = 0; /* No print file open */
  205. /* Get size of a page */
  206. lpPrintFile->pageHeight = GetDeviceCaps(lpPrintFile->hPrintDC, VERTRES);
  207. lpPrintFile->pageWidth = GetDeviceCaps(lpPrintFile->hPrintDC, HORZRES);
  208. /* Create font based on default font */
  209. lpPrintFile->hFont = 0;
  210. lpPrintFile->active = TRUE;
  211. PrintFileControl( PRINTFILESETFONT, 0,0l);
  212. lpPrintFile->active = FALSE;
  213. spool[0] = 0;
  214. lstrcpy( spool, (LPSTR) lpPrintPort);
  215. lstrcpy( spool+lstrlen( (LPSTR)spool),(LPSTR) SPACE_STR+1);
  216. lstrcpy( spool+lstrlen( (LPSTR)spool),(LPSTR) thePrintName);
  217. lstrcpy( spool+lstrlen( (LPSTR)spool),(LPSTR) SPACE_STR+1);
  218. lstrcpy( spool+lstrlen( (LPSTR)spool),(LPSTR) lpPrintType);
  219. lstrcpy( lpPrintFile->title, (LPSTR) thePrintName);
  220. SetAbortProc(lpPrintFile->hPrintDC, abortDlgProc);
  221. if(Escape(lpPrintFile->hPrintDC, STARTDOC, lstrlen ((LPSTR)spool ), spool , (LPSTR) 0) <= 0)
  222. {
  223. DeleteDC(lpPrintFile->hPrintDC);
  224. GlobalUnlock(hPrintFile);
  225. hPrintFile = GlobalFree(hPrintFile);
  226. return FALSE;
  227. }
  228. if(showDialog)
  229. {
  230. lpPrintFile->hAbortDlg = CreateDialog (theInstance, MAKEINTRESOURCE (IDABORTDLG), theWnd, dbAbortDlg);
  231. }
  232. lpPrintFile->active = TRUE;
  233. GlobalUnlock(hPrintFile);
  234. return(TRUE);
  235. }
  236. BOOL PrintFileOff()
  237. {
  238. BYTE tmp[STR255]; /* jtfnew */
  239. if(!hPrintFile)
  240. return(FALSE);
  241. lpPrintFile = (LPPRINTREC) GlobalLock(hPrintFile);
  242. lpPrintFile->openCount--;
  243. if(lpPrintFile->fileio)
  244. {
  245. _close(lpPrintFile->fileio);
  246. lpPrintFile->fileio = 0;
  247. if ( lstrlen( lpPrintFile->tmpFile ) > 0 ) /* jtfnew */
  248. {
  249. lstrcpy ( tmp, (LPSTR) lpPrintFile->tmpFile);
  250. MDeleteFile(tmp);
  251. lpPrintFile->tmpFile[0] = 0;
  252. }
  253. }
  254. if(lpPrintFile->charCount > 0)
  255. PrintFileLineFeed(TRUE);
  256. if(lpPrintFile->openCount > 0)
  257. {
  258. lpPrintFile->cancelAbort = FALSE;
  259. GlobalUnlock(hPrintFile);
  260. return(TRUE); /* Assume leave print channel open */
  261. }
  262. if((lpPrintFile->prtLine > 0) || (lpPrintFile->charCount > 0) || (lpPrintFile->cancelAbort))
  263. PrintFilePageFeed();
  264. if(lpPrintFile->hFont)
  265. DeleteObject(lpPrintFile->hFont);
  266. Escape(lpPrintFile->hPrintDC, ENDDOC, 0, 0, (LPSTR) 0);
  267. if(lpPrintFile->hAbortDlg)
  268. {
  269. DestroyWindow (lpPrintFile->hAbortDlg);
  270. }
  271. DeleteDC(lpPrintFile->hPrintDC);
  272. while(GlobalUnlock(hPrintFile));
  273. hPrintFile = GlobalFree(hPrintFile);
  274. return(FALSE);
  275. }
  276. void PrintFilePageFeed ()
  277. {
  278. if (!hPrintFile) return;
  279. else
  280. lpPrintFile = (LPPRINTREC) GlobalLock(hPrintFile);
  281. lpPrintFile->prtLine = 0;
  282. switch (Escape (lpPrintFile->hPrintDC, NEWFRAME, 0, NULL, (LPSTR) NULL))
  283. {
  284. case SP_ERROR: /* General Error */
  285. break;
  286. case SP_OUTOFDISK: /* Out of disk space */
  287. break;
  288. case SP_OUTOFMEMORY: /* Out of memory */
  289. break;
  290. default:
  291. break;
  292. }
  293. GlobalUnlock(hPrintFile);
  294. }
  295. void PrintFileShutDown ()
  296. {
  297. if (!hPrintFile) return;
  298. else
  299. while (PrintFileOff());
  300. }
  301. void PrintFileLineFeed (BOOL nextLine)
  302. {
  303. BYTE temp[255];
  304. HFONT hOldFont;
  305. INT i;
  306. INT pix,cy;
  307. pix = 0;
  308. if (!hPrintFile) return;
  309. else
  310. lpPrintFile = (LPPRINTREC) GlobalLock(hPrintFile);
  311. if (lpPrintFile->hFont)
  312. hOldFont = SelectObject( lpPrintFile->hPrintDC, lpPrintFile->hFont);
  313. if (lpPrintFile->charCount > 0)
  314. {
  315. lpPrintFile->lineBuffer[lpPrintFile->charCount] = 0;
  316. i = lpPrintFile->charCount;
  317. /* purge blanks from end of line */
  318. if ( (nextLine) && (i > 1) ) /* jtfnew */
  319. while ( (lpPrintFile->lineBuffer[lpPrintFile->charCount-1] == ' ') && (lpPrintFile->charCount > 0) )
  320. lpPrintFile->charCount--;
  321. if ( (lpPrintFile->charCount-lpPrintFile->pixColCount) > 0) /* jtfnew */
  322. { /* jtfnew */
  323. TextOut (lpPrintFile->hPrintDC, lpPrintFile->pixCount, lpPrintFile->prtLine * lpPrintFile->nLineHeight,
  324. (lpPrintFile->lineBuffer + lpPrintFile->pixColCount), lpPrintFile->charCount-lpPrintFile->pixColCount);
  325. /* JAP had said...BUG BUG, port macro screwed this up, so this is best guess
  326. pix = LOWORD( GetTextExtent(lpPrintFile->hPrintDC,
  327. (lpPrintFile->lineBuffer +
  328. lpPrintFile->pixColCount),
  329. lpPrintFile->charCount-lpPrintFile->pixColCount) ); */
  330. /* getextextent was giving DWORD back with high=ht low=width -sdj
  331. MGetTextExtent gives bool back, and takes PINT pcx and PINT pcy as args -sdj
  332. as the code was doing LOWORD, it was interested in width, in pix -sdj
  333. so giving address of pix as pcx and added cy and giving &cy as pcy -sdj */
  334. MGetTextExtent(lpPrintFile->hPrintDC,
  335. (lpPrintFile->lineBuffer +
  336. lpPrintFile->pixColCount) ,
  337. lpPrintFile->charCount-lpPrintFile->pixColCount,
  338. &pix,
  339. &cy);
  340. lpPrintFile->pixColCount = lpPrintFile->charCount;
  341. lpPrintFile->pixCount = pix +lpPrintFile->pixCount;
  342. } /* jtfnew */
  343. }
  344. if(nextLine)
  345. {
  346. lpPrintFile->charCount = 0;
  347. lpPrintFile->pixCount = 0;
  348. lpPrintFile->pixColCount = 0;
  349. lpPrintFile->prtLine++;
  350. }
  351. if (lpPrintFile->hFont)
  352. SelectObject( lpPrintFile->hPrintDC, hOldFont);
  353. GlobalUnlock(hPrintFile);
  354. }
  355. /*---------------------------------------------------------------------------*/
  356. /* PrintFileString() - [jtf] [mbb] */
  357. /*---------------------------------------------------------------------------*/
  358. VOID PrintFileString(LPSTR lpchr, LONG count, BOOL bCRtoLF)
  359. {
  360. INT icount, i;
  361. BYTE chr;
  362. if ( (!hPrintFile) || (count == 0) ) /* jtfnew */ /* no print channel open */
  363. return;
  364. if((lpPrintFile = (LPPRINTREC) GlobalLock(hPrintFile)) != NULL)
  365. {
  366. if(!lpPrintFile->fileio) /* disabled while file printing */
  367. {
  368. for(icount = 0; icount < count; icount += 1)
  369. {
  370. switch((BYTE) lpchr[icount]) /* mbbx 2.01.06 ... jtf 3.18 */
  371. {
  372. case TAB:
  373. for(i = lpPrintFile->tab - ((lpPrintFile->charCount) % lpPrintFile->tab); i > 0; i--)
  374. lpPrintFile->lineBuffer[lpPrintFile->charCount++] = ' ';
  375. break;
  376. case CR:
  377. if(!bCRtoLF)
  378. break;
  379. /* else fall thru... */
  380. case LF:
  381. PrintFileLineFeed(TRUE);
  382. break;
  383. case FF:
  384. PrintFilePageFeed();
  385. break;
  386. default:
  387. if(lpPrintFile->charCount >= lpPrintFile->lineLength)
  388. PrintFileLineFeed(TRUE);
  389. if(lpPrintFile->prtLine >= lpPrintFile->pageLength-1) /* jtf 3.20 */
  390. PrintFilePageFeed();
  391. lpPrintFile->lineBuffer[lpPrintFile->charCount++] = lpchr[icount]; /* mbbx 2.01.06 ... jtf 3.18 */
  392. break;
  393. }
  394. if(lpPrintFile->cancelAbort)
  395. break;
  396. }
  397. }
  398. GlobalUnlock(hPrintFile);
  399. }
  400. }
  401. /*---------------------------------------------------------------------------*/
  402. /*---------------------------------------------------------------------------*/
  403. BOOL PrintFileControl(UINT msg, WPARAM wParam, LPARAM lParam)
  404. {
  405. RECT pageRect;
  406. TEXTMETRIC tmMetric;
  407. HFONT hOldFont;
  408. if (!hPrintFile) return(FALSE);
  409. else
  410. lpPrintFile = (LPPRINTREC) GlobalLock(hPrintFile);
  411. if (msg & PRINTFILEBOLD)
  412. if (wParam) lpPrintFile->font.lfWeight = 700;
  413. else lpPrintFile->font.lfWeight = 400;
  414. if (msg & PRINTFILEUNDERLINE)
  415. lpPrintFile->font.lfUnderline = (BYTE)wParam;
  416. if (msg & PRINTFILEITALIC)
  417. lpPrintFile->font.lfItalic = (BYTE)wParam;
  418. if (msg & PRINTFILESTRIKEOUT)
  419. lpPrintFile->font.lfStrikeOut = (BYTE)wParam;
  420. if (msg & PRINTFILEQUALITY)
  421. if (wParam) lpPrintFile->font.lfQuality = DEFAULT_QUALITY;
  422. else lpPrintFile->font.lfQuality = DRAFT_QUALITY;
  423. if (msg & PRINTFILECRTOLF)
  424. lpPrintFile->CRtoLF = (BOOL)wParam;
  425. if (msg & PRINTFILENORMAL)
  426. {
  427. lpPrintFile->font.lfItalic = FALSE;
  428. lpPrintFile->font.lfUnderline = FALSE;
  429. lpPrintFile->font.lfStrikeOut = FALSE;
  430. lpPrintFile->font.lfQuality = DEFAULT_QUALITY;
  431. lpPrintFile->font.lfWeight = 400;
  432. }
  433. if (msg & PRINTFILETAB)
  434. if (wParam <= TABMAX) lpPrintFile->tab = (INT)wParam;
  435. if (msg & PRINTFILEFONTFACE)
  436. {
  437. if(*(LPSTR)(lParam) != '?')
  438. lstrcpy(lpPrintFile->font.lfFaceName,(LPSTR)lParam);
  439. lpPrintFile->font.lfHeight = (LONG)wParam*
  440. GetDeviceCaps(lpPrintFile->hPrintDC,LOGPIXELSY)/72;
  441. }
  442. if (msg & PRINTFILESETFONT)
  443. {
  444. PrintFileLineFeed(FALSE);
  445. if (lpPrintFile->font.lfHeight > 0)
  446. lpPrintFile->font.lfHeight= lpPrintFile->font.lfHeight+5;
  447. lpPrintFile->font.lfWidth = 0;
  448. if (lpPrintFile->hFont)
  449. DeleteObject( lpPrintFile->hFont );
  450. lpPrintFile->hFont = CreateFontIndirect( &lpPrintFile->font);
  451. hOldFont = SelectObject( lpPrintFile->hPrintDC, lpPrintFile->hFont);
  452. GetTextFace(lpPrintFile->hPrintDC,LF_FACESIZE,
  453. lpPrintFile->font.lfFaceName);
  454. GetTextMetrics(lpPrintFile->hPrintDC,&tmMetric);
  455. lpPrintFile->font.lfHeight = tmMetric.tmHeight;
  456. lpPrintFile->font.lfWidth = tmMetric.tmAveCharWidth;
  457. if ( (GetDeviceCaps(lpPrintFile->hPrintDC,LOGPIXELSY)/72) >= 1)
  458. lpPrintFile->point = lpPrintFile->font.lfHeight / (GetDeviceCaps(lpPrintFile->hPrintDC,LOGPIXELSY)/72);
  459. else
  460. lpPrintFile->point = 0;
  461. if( (lpPrintFile->prtLine == 0) && (lpPrintFile->charCount == 0) )
  462. {
  463. lpPrintFile->nLineHeight = (SHORT)(tmMetric.tmHeight + tmMetric.tmExternalLeading);
  464. /* Calculate size of page */
  465. lpPrintFile->pageLength = max (lpPrintFile->pageHeight / lpPrintFile->nLineHeight , 0);
  466. lpPrintFile->lineLength = max (lpPrintFile->pageWidth / lpPrintFile->font.lfWidth , 0);
  467. }
  468. SelectObject( lpPrintFile->hPrintDC, hOldFont);
  469. }
  470. GlobalUnlock(hPrintFile);
  471. return TRUE;
  472. }