[123] | 1 |
|
---|
| 2 | /***********************************************************************
|
---|
| 3 |
|
---|
| 4 | $Id: printer.c 907 2008-01-06 07:26:17Z stevenhl $
|
---|
| 5 |
|
---|
[355] | 6 | Print file list
|
---|
| 7 |
|
---|
[123] | 8 | Copyright (c) 1993-98 M. Kimes
|
---|
[907] | 9 | Copyright (c) 2004, 2008 Steven H.Levine
|
---|
[123] | 10 |
|
---|
[355] | 11 | 01 Aug 04 SHL Rework lstrip/rstrip usage
|
---|
| 12 | 17 Jul 06 SHL Use Runtime_Error
|
---|
[533] | 13 | 03 Nov 06 SHL Renames
|
---|
| 14 | 03 Nov 06 SHL Count thread usage
|
---|
[574] | 15 | 22 Mar 07 GKY Use QWL_USER
|
---|
[793] | 16 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
|
---|
[123] | 17 |
|
---|
| 18 | ***********************************************************************/
|
---|
| 19 |
|
---|
[2] | 20 | #include <stdlib.h>
|
---|
| 21 | #include <string.h>
|
---|
| 22 | #include <ctype.h>
|
---|
| 23 | #include <share.h>
|
---|
[843] | 24 |
|
---|
| 25 | #define INCL_DOS
|
---|
| 26 | #define INCL_WIN
|
---|
[907] | 27 | #define INCL_LONGLONG // dircnrs.h
|
---|
[843] | 28 |
|
---|
[2] | 29 | #include "fm3dlg.h"
|
---|
| 30 | #include "fm3str.h"
|
---|
[907] | 31 | #include "makelist.h" // AddToList
|
---|
| 32 | #include "errutil.h" // Dos_Error...
|
---|
| 33 | #include "strutil.h" // GetPString
|
---|
| 34 | #include "fm3dll.h"
|
---|
[2] | 35 |
|
---|
| 36 | #pragma data_seg(DATA1)
|
---|
[355] | 37 |
|
---|
| 38 | static PSZ pszSrcFile = __FILE__;
|
---|
| 39 |
|
---|
[2] | 40 | static HMTX PrintSem = 0;
|
---|
| 41 |
|
---|
[551] | 42 | BOOL PrinterReady(CHAR * printdevname)
|
---|
[355] | 43 | {
|
---|
[551] | 44 | FILE *printhandle;
|
---|
| 45 | CHAR param = 0, data = 0;
|
---|
[766] | 46 | ULONG datalen = 1, parmlen = 1, htype, flagword;
|
---|
[2] | 47 |
|
---|
[551] | 48 | if (!fWorkPlace) /* assume spooler is active */
|
---|
[2] | 49 | return TRUE;
|
---|
| 50 | DosError(FERR_DISABLEHARDERR);
|
---|
[551] | 51 | printhandle = xfopen(printdevname, "a+", pszSrcFile, __LINE__);
|
---|
[355] | 52 | if (printhandle) {
|
---|
[551] | 53 | if (!strnicmp(printdevname, "COM", 3) && isdigit(printdevname[3])) {
|
---|
[2] | 54 | fclose(printhandle);
|
---|
| 55 | return TRUE;
|
---|
| 56 | }
|
---|
[551] | 57 | if (!DosQueryHType(fileno(printhandle), &htype, &flagword) &&
|
---|
| 58 | !(htype & 7)) {
|
---|
[2] | 59 | fclose(printhandle);
|
---|
| 60 | return TRUE;
|
---|
| 61 | }
|
---|
[766] | 62 | if (DosDevIOCtl(fileno(printhandle), 5, 0x00000066, (PVOID) & param,
|
---|
| 63 | 1, &parmlen, (PVOID) & data, 1,
|
---|
[551] | 64 | &datalen) != 0x00000100) {
|
---|
[2] | 65 | fclose(printhandle);
|
---|
| 66 | return FALSE;
|
---|
| 67 | }
|
---|
| 68 | fclose(printhandle);
|
---|
[551] | 69 | if (data & 32) /* bit 5 is out of paper */
|
---|
[2] | 70 | return FALSE;
|
---|
| 71 | return TRUE;
|
---|
| 72 | }
|
---|
| 73 | return FALSE;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[551] | 76 | BOOL SayPrinterReady(HWND hwnd)
|
---|
[355] | 77 | {
|
---|
[551] | 78 | if (!hwnd)
|
---|
[2] | 79 | hwnd = HWND_DESKTOP;
|
---|
[551] | 80 | if (!PrinterReady(printer)) {
|
---|
[2] | 81 | saymsg(MB_ENTER | MB_ICONEXCLAMATION,
|
---|
[551] | 82 | hwnd,
|
---|
| 83 | GetPString(IDS_NOTETEXT), GetPString(IDS_PRINTERNOTREADYTEXT));
|
---|
[2] | 84 | return FALSE;
|
---|
| 85 | }
|
---|
| 86 | return TRUE;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
[533] | 89 | //=== PrintListThread - background-print a list of files ===
|
---|
[2] | 90 |
|
---|
[551] | 91 | VOID PrintListThread(VOID * arg)
|
---|
[355] | 92 | {
|
---|
[551] | 93 | HAB hab2;
|
---|
| 94 | HMQ hmq2;
|
---|
| 95 | LISTINFO *li = (LISTINFO *) arg;
|
---|
[2] | 96 | register INT x;
|
---|
[551] | 97 | FILE *fpi, *fpo;
|
---|
| 98 | CHAR s[CCHMAXPATH + 80];
|
---|
[843] | 99 | FILESTATUS3 fs3;
|
---|
[551] | 100 | LONG cols, lines, pages, z, lmargin, rmargin;
|
---|
| 101 | BOOL endline, endpage, startpage, skipping, firstpass;
|
---|
| 102 | int c;
|
---|
| 103 | APIRET rc = MBID_YES;
|
---|
[2] | 104 |
|
---|
[551] | 105 | if (StopPrinting)
|
---|
[2] | 106 | goto Abort;
|
---|
[551] | 107 | if (!PrintSem) {
|
---|
| 108 | if (DosCreateMutexSem(NULL, &PrintSem, 0, FALSE)) {
|
---|
| 109 | Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
|
---|
| 110 | "DosCreateMutexSem");
|
---|
[2] | 111 | goto Abort;
|
---|
| 112 | }
|
---|
| 113 | }
|
---|
| 114 | priority_normal();
|
---|
| 115 | hab2 = WinInitialize(0);
|
---|
[551] | 116 | if (hab2) {
|
---|
| 117 | hmq2 = WinCreateMsgQueue(hab2, 0);
|
---|
| 118 | if (hmq2) {
|
---|
| 119 | WinCancelShutdown(hmq2, TRUE);
|
---|
[533] | 120 | IncrThreadUsage();
|
---|
[551] | 121 | if (li && li->list && li->list[0]) {
|
---|
| 122 | AddNote(GetPString(IDS_PRINTINGLISTTEXT));
|
---|
| 123 | for (x = 0; li->list[x]; x++) {
|
---|
| 124 | if (rc == MBID_CANCEL)
|
---|
| 125 | break;
|
---|
| 126 | DosError(FERR_DISABLEHARDERR);
|
---|
[843] | 127 | if (DosQueryPathInfo(li->list[x], FIL_STANDARD, &fs3, sizeof(fs3)) ||
|
---|
| 128 | fs3.attrFile & FILE_DIRECTORY ||
|
---|
| 129 | !fs3.cbFile)
|
---|
[551] | 130 | continue;
|
---|
| 131 | if (StopPrinting)
|
---|
| 132 | break;
|
---|
[766] | 133 | DosRequestMutexSem(PrintSem, 240000);
|
---|
[551] | 134 | if (StopPrinting)
|
---|
| 135 | break;
|
---|
| 136 | if (!PrinterReady(li->targetpath))
|
---|
| 137 | Runtime_Error(pszSrcFile, __LINE__, "printer %s error",
|
---|
| 138 | li->targetpath);
|
---|
[355] | 139 | else {
|
---|
[551] | 140 | fpi = _fsopen(li->list[x], "r", SH_DENYWR);
|
---|
| 141 | if (!fpi)
|
---|
| 142 | Runtime_Error(pszSrcFile, __LINE__, "cannot open %s",
|
---|
| 143 | li->list[x]);
|
---|
[355] | 144 | else {
|
---|
[551] | 145 | fpo = _fsopen(li->targetpath, "a+", SH_DENYRW);
|
---|
| 146 | if (!fpo)
|
---|
| 147 | Runtime_Error(pszSrcFile, __LINE__, "cannot open %s",
|
---|
| 148 | li->targetpath);
|
---|
[355] | 149 | else {
|
---|
[551] | 150 | sprintf(s, GetPString(IDS_PRINTINGTEXT), li->list[x]);
|
---|
| 151 | AddNote(s);
|
---|
| 152 | firstpass = TRUE;
|
---|
| 153 | skipping = FALSE;
|
---|
| 154 | lmargin = prnlmargin;
|
---|
| 155 | rmargin = prnrmargin;
|
---|
| 156 | if (prnformfeedbefore) {
|
---|
| 157 | if (!skipping)
|
---|
| 158 | fputc('\x0c', fpo);
|
---|
| 159 | }
|
---|
| 160 | Again:
|
---|
| 161 | cols = lines = pages = 0;
|
---|
| 162 | endline = endpage = FALSE;
|
---|
| 163 | startpage = TRUE;
|
---|
| 164 | while ((c = fgetc(fpi)) != EOF) {
|
---|
| 165 | if (StopPrinting || ferror(fpo))
|
---|
| 166 | break;
|
---|
| 167 | if (prnformat) {
|
---|
| 168 | if (startpage) {
|
---|
| 169 | pages++;
|
---|
| 170 | if (prnpagenums) {
|
---|
| 171 | if (!skipping)
|
---|
| 172 | fprintf(fpo, "%*.*s#%lu",
|
---|
| 173 | lmargin, lmargin, " ", pages);
|
---|
| 174 | }
|
---|
| 175 | for (z = 0; z < prntmargin; z++) {
|
---|
| 176 | if (!skipping)
|
---|
| 177 | fputc('\n', fpo);
|
---|
| 178 | }
|
---|
| 179 | lines = prntmargin;
|
---|
| 180 | endline = endpage = FALSE;
|
---|
| 181 | cols = 0;
|
---|
| 182 | startpage = FALSE;
|
---|
| 183 | }
|
---|
| 184 | if (!cols) {
|
---|
| 185 | for (z = 0; z < lmargin; z++) {
|
---|
| 186 | if (!skipping)
|
---|
| 187 | fputc(' ', fpo);
|
---|
| 188 | }
|
---|
| 189 | cols = lmargin;
|
---|
| 190 | }
|
---|
| 191 | if (!skipping) {
|
---|
| 192 | if (c == '\t') {
|
---|
| 193 | for (z = 0; z < prntabspaces &&
|
---|
| 194 | cols + z < prnwidth - rmargin; z++)
|
---|
| 195 | fputc(' ', fpo);
|
---|
| 196 | }
|
---|
| 197 | else
|
---|
| 198 | fputc(c, fpo);
|
---|
| 199 | }
|
---|
| 200 | if (c == '\x0c')
|
---|
| 201 | endpage = TRUE;
|
---|
| 202 | else if (c == '\n') {
|
---|
| 203 | lines++;
|
---|
| 204 | cols = 0;
|
---|
| 205 | for (z = 1; z < prnspacing; z++) {
|
---|
| 206 | if (prnlength - lines <= prnbmargin)
|
---|
| 207 | break;
|
---|
| 208 | if (!skipping)
|
---|
| 209 | fputc('\n', fpo);
|
---|
| 210 | lines++;
|
---|
| 211 | }
|
---|
| 212 | if (prnlength - lines <= prnbmargin)
|
---|
| 213 | endpage = TRUE;
|
---|
| 214 | }
|
---|
| 215 | else {
|
---|
| 216 | cols++;
|
---|
| 217 | if (c == '\t')
|
---|
| 218 | c += prntabspaces;
|
---|
| 219 | if (prnwidth - cols <= rmargin) {
|
---|
| 220 | endline = TRUE;
|
---|
| 221 | if (!skipping)
|
---|
| 222 | fputc('\n', fpo);
|
---|
| 223 | lines++;
|
---|
| 224 | }
|
---|
| 225 | for (z = 1; z < prnspacing; z++) {
|
---|
| 226 | if (prnlength - lines <= prnbmargin)
|
---|
| 227 | break;
|
---|
| 228 | if (!skipping)
|
---|
| 229 | fputc('\n', fpo);
|
---|
| 230 | lines++;
|
---|
| 231 | }
|
---|
| 232 | }
|
---|
| 233 | if (endline) {
|
---|
| 234 | do {
|
---|
| 235 | c = fgetc(fpi);
|
---|
| 236 | if (c == '\n')
|
---|
| 237 | break;
|
---|
| 238 | } while (isspace(c) && c != EOF);
|
---|
| 239 | if (c == EOF)
|
---|
| 240 | break;
|
---|
| 241 | if (!isspace(c))
|
---|
| 242 | ungetc(c, fpi);
|
---|
| 243 | endline = FALSE;
|
---|
| 244 | cols = 0;
|
---|
| 245 | if (prnlength - lines <= prnbmargin)
|
---|
| 246 | endpage = TRUE;
|
---|
| 247 | }
|
---|
| 248 | if (endpage) {
|
---|
| 249 | if (prnbmargin) {
|
---|
| 250 | if (c != '\x0c') {
|
---|
| 251 | if (!skipping)
|
---|
| 252 | fputc('\r\x0c', fpo);
|
---|
| 253 | }
|
---|
| 254 | }
|
---|
| 255 | lines = cols = 0;
|
---|
| 256 | endpage = FALSE;
|
---|
| 257 | startpage = TRUE;
|
---|
| 258 | do {
|
---|
| 259 | c = fgetc(fpi);
|
---|
| 260 | } while (c == '\n');
|
---|
| 261 | if (c == EOF)
|
---|
| 262 | break;
|
---|
| 263 | ungetc(c, fpi);
|
---|
| 264 | if (prnformat && prnalt)
|
---|
| 265 | skipping = (skipping) ? FALSE : TRUE;
|
---|
[766] | 266 | DosSleep(1);
|
---|
[551] | 267 | }
|
---|
| 268 | }
|
---|
| 269 | else
|
---|
| 270 | fputc(c, fpo);
|
---|
| 271 | }
|
---|
| 272 | if (prnalt && prnformat && firstpass && pages > 1) {
|
---|
| 273 | fclose(fpo);
|
---|
| 274 | fpo = _fsopen(li->targetpath, "a+", SH_DENYRW);
|
---|
| 275 | if (fpo) {
|
---|
| 276 | rewind(fpi);
|
---|
| 277 | firstpass = FALSE;
|
---|
| 278 | skipping = TRUE;
|
---|
| 279 | rc = saymsg(MB_YESNOCANCEL | MB_ICONEXCLAMATION,
|
---|
| 280 | HWND_DESKTOP,
|
---|
| 281 | GetPString(IDS_PRINTTITLETEXT),
|
---|
| 282 | GetPString(IDS_PRINTEVENTEXT), li->list[x]);
|
---|
| 283 | if (rc == MBID_YES) {
|
---|
| 284 | lmargin = prnrmargin;
|
---|
| 285 | rmargin = prnlmargin;
|
---|
| 286 | fputc('\x0c', fpo);
|
---|
| 287 | goto Again;
|
---|
| 288 | }
|
---|
| 289 | }
|
---|
| 290 | else
|
---|
| 291 | saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
|
---|
| 292 | HWND_DESKTOP,
|
---|
| 293 | GetPString(IDS_PRINTTITLETEXT),
|
---|
| 294 | GetPString(IDS_PRINTCANTREOPENTEXT),
|
---|
| 295 | li->targetpath);
|
---|
| 296 | }
|
---|
| 297 | if (prnformfeedafter)
|
---|
| 298 | fputc('\x0c', fpo);
|
---|
| 299 | if (!StopPrinting) {
|
---|
| 300 | sprintf(s, GetPString(IDS_PRINTEDTEXT), li->list[x]);
|
---|
| 301 | AddNote(s);
|
---|
| 302 | }
|
---|
| 303 | fclose(fpo);
|
---|
| 304 | }
|
---|
| 305 | fclose(fpi);
|
---|
| 306 | }
|
---|
| 307 | }
|
---|
| 308 | DosReleaseMutexSem(PrintSem);
|
---|
[766] | 309 | DosSleep(1);
|
---|
[551] | 310 | }
|
---|
| 311 | if (!StopPrinting)
|
---|
| 312 | AddNote(GetPString(IDS_PRINTEDLISTTEXT));
|
---|
[2] | 313 | }
|
---|
| 314 | WinDestroyMsgQueue(hmq2);
|
---|
| 315 | }
|
---|
[533] | 316 | DecrThreadUsage();
|
---|
[2] | 317 | WinTerminate(hab2);
|
---|
| 318 | }
|
---|
| 319 | Abort:
|
---|
[551] | 320 | if (li)
|
---|
[2] | 321 | FreeListInfo(li);
|
---|
| 322 | }
|
---|
| 323 |
|
---|
[551] | 324 | MRESULT EXPENTRY PrintDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
[355] | 325 | {
|
---|
[2] | 326 | LISTINFO *li;
|
---|
| 327 |
|
---|
[551] | 328 | switch (msg) {
|
---|
| 329 | case WM_INITDLG:
|
---|
| 330 | if (!mp2)
|
---|
| 331 | WinDismissDlg(hwnd, 0);
|
---|
| 332 | else {
|
---|
[574] | 333 | WinSetWindowPtr(hwnd, QWL_USER, mp2);
|
---|
[551] | 334 | WinSendDlgItemMsg(hwnd, PRN_WIDTH, EM_SETTEXTLIMIT,
|
---|
| 335 | MPFROM2SHORT(3, 0), MPVOID);
|
---|
| 336 | WinSendDlgItemMsg(hwnd, PRN_LENGTH, EM_SETTEXTLIMIT,
|
---|
| 337 | MPFROM2SHORT(3, 0), MPVOID);
|
---|
| 338 | WinSendDlgItemMsg(hwnd, PRN_LMARGIN, EM_SETTEXTLIMIT,
|
---|
| 339 | MPFROM2SHORT(2, 0), MPVOID);
|
---|
| 340 | WinSendDlgItemMsg(hwnd, PRN_RMARGIN, EM_SETTEXTLIMIT,
|
---|
| 341 | MPFROM2SHORT(2, 0), MPVOID);
|
---|
| 342 | WinSendDlgItemMsg(hwnd, PRN_TMARGIN, EM_SETTEXTLIMIT,
|
---|
| 343 | MPFROM2SHORT(2, 0), MPVOID);
|
---|
| 344 | WinSendDlgItemMsg(hwnd, PRN_BMARGIN, EM_SETTEXTLIMIT,
|
---|
| 345 | MPFROM2SHORT(2, 0), MPVOID);
|
---|
| 346 | WinSendDlgItemMsg(hwnd, PRN_SPACING, EM_SETTEXTLIMIT,
|
---|
| 347 | MPFROM2SHORT(1, 0), MPVOID);
|
---|
| 348 | WinSendDlgItemMsg(hwnd, PRN_TABSPACES, EM_SETTEXTLIMIT,
|
---|
| 349 | MPFROM2SHORT(2, 0), MPVOID);
|
---|
| 350 | WinSendDlgItemMsg(hwnd, PRN_PRINTER, EM_SETTEXTLIMIT,
|
---|
| 351 | MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
|
---|
| 352 | WinSendMsg(hwnd, UM_UNDO, MPVOID, MPVOID);
|
---|
| 353 | PosOverOkay(hwnd);
|
---|
| 354 | }
|
---|
| 355 | break;
|
---|
[2] | 356 |
|
---|
[551] | 357 | case UM_UNDO:
|
---|
| 358 | WinCheckButton(hwnd, PRN_FORMAT, prnformat);
|
---|
| 359 | WinCheckButton(hwnd, PRN_ALT, prnalt);
|
---|
| 360 | WinCheckButton(hwnd, PRN_PAGENUMS, prnpagenums);
|
---|
| 361 | WinCheckButton(hwnd, PRN_FORMBEFORE, prnformfeedbefore);
|
---|
| 362 | WinCheckButton(hwnd, PRN_FORMAFTER, prnformfeedafter);
|
---|
| 363 | {
|
---|
| 364 | CHAR s[33];
|
---|
[2] | 365 |
|
---|
[551] | 366 | sprintf(s, "%lu", prnwidth);
|
---|
| 367 | WinSetDlgItemText(hwnd, PRN_WIDTH, s);
|
---|
| 368 | sprintf(s, "%lu", prnlength);
|
---|
| 369 | WinSetDlgItemText(hwnd, PRN_LENGTH, s);
|
---|
| 370 | sprintf(s, "%lu", prnlmargin);
|
---|
| 371 | WinSetDlgItemText(hwnd, PRN_LMARGIN, s);
|
---|
| 372 | sprintf(s, "%lu", prnrmargin);
|
---|
| 373 | WinSetDlgItemText(hwnd, PRN_RMARGIN, s);
|
---|
| 374 | sprintf(s, "%lu", prntmargin);
|
---|
| 375 | WinSetDlgItemText(hwnd, PRN_TMARGIN, s);
|
---|
| 376 | sprintf(s, "%lu", prnbmargin);
|
---|
| 377 | WinSetDlgItemText(hwnd, PRN_BMARGIN, s);
|
---|
| 378 | sprintf(s, "%lu", prnspacing);
|
---|
| 379 | WinSetDlgItemText(hwnd, PRN_SPACING, s);
|
---|
| 380 | sprintf(s, "%lu", prntabspaces);
|
---|
| 381 | WinSetDlgItemText(hwnd, PRN_TABSPACES, s);
|
---|
| 382 | }
|
---|
| 383 | WinSetDlgItemText(hwnd, PRN_PRINTER, printer);
|
---|
| 384 | WinSendDlgItemMsg(hwnd, PRN_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
|
---|
| 385 | li = WinQueryWindowPtr(hwnd, QWL_USER);
|
---|
| 386 | if (!li)
|
---|
| 387 | Runtime_Error(pszSrcFile, __LINE__, "no data");
|
---|
| 388 | else {
|
---|
| 389 | INT x;
|
---|
[2] | 390 |
|
---|
[551] | 391 | for (x = 0; li->list[x]; x++) {
|
---|
| 392 | if (IsFile(li->list[x]) == 1) {
|
---|
| 393 | WinSendDlgItemMsg(hwnd, PRN_LISTBOX, LM_INSERTITEM,
|
---|
| 394 | MPFROM2SHORT(LIT_END, 0), MPFROMP(li->list[x]));
|
---|
| 395 | WinSendDlgItemMsg(hwnd, PRN_LISTBOX, LM_SELECTITEM,
|
---|
| 396 | MPFROM2SHORT(x, 0), MPFROMSHORT(TRUE));
|
---|
| 397 | }
|
---|
[2] | 398 | }
|
---|
[551] | 399 | if (!(SHORT) WinSendDlgItemMsg(hwnd, PRN_LISTBOX, LM_QUERYITEMCOUNT,
|
---|
| 400 | MPVOID, MPVOID)) {
|
---|
| 401 | saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
|
---|
| 402 | hwnd,
|
---|
| 403 | GetPString(IDS_TWIDDLETEXT), GetPString(IDS_NOPRINTABLETEXT));
|
---|
| 404 | WinDismissDlg(hwnd, 0);
|
---|
| 405 | }
|
---|
| 406 | }
|
---|
| 407 | return 0;
|
---|
[2] | 408 |
|
---|
[551] | 409 | case WM_CONTROL:
|
---|
| 410 | switch (SHORT1FROMMP(mp1)) {
|
---|
| 411 | case PRN_LISTBOX:
|
---|
| 412 | if (SHORT2FROMMP(mp1) == LN_ENTER) {
|
---|
[2] | 413 |
|
---|
[551] | 414 | SHORT x;
|
---|
| 415 | CHAR szBuffer[CCHMAXPATH];
|
---|
[2] | 416 |
|
---|
[551] | 417 | x = (SHORT) WinSendDlgItemMsg(hwnd, PRN_LISTBOX, LM_QUERYSELECTION,
|
---|
| 418 | MPFROMSHORT(LIT_FIRST), MPVOID);
|
---|
| 419 | if (x >= 0) {
|
---|
| 420 | *szBuffer = 0;
|
---|
| 421 | WinSendDlgItemMsg(hwnd, PRN_LISTBOX, LM_QUERYITEMTEXT,
|
---|
| 422 | MPFROM2SHORT(x, CCHMAXPATH), MPFROMP(szBuffer));
|
---|
| 423 | if (*szBuffer)
|
---|
| 424 | QuickView(hwnd, szBuffer);
|
---|
| 425 | }
|
---|
[2] | 426 | }
|
---|
[551] | 427 | }
|
---|
| 428 | return 0;
|
---|
[2] | 429 |
|
---|
[551] | 430 | case WM_COMMAND:
|
---|
| 431 | switch (SHORT1FROMMP(mp1)) {
|
---|
| 432 | case DID_OK:
|
---|
| 433 | li = WinQueryWindowPtr(hwnd, QWL_USER);
|
---|
| 434 | if (!li)
|
---|
| 435 | Runtime_Error(pszSrcFile, __LINE__, "no data");
|
---|
| 436 | else {
|
---|
| 437 | prnformat = WinQueryButtonCheckstate(hwnd, PRN_FORMAT);
|
---|
| 438 | PrfWriteProfileData(fmprof, FM3Str, "Prnformat",
|
---|
| 439 | (PVOID) & prnformat, sizeof(prnformat));
|
---|
| 440 | prnalt = WinQueryButtonCheckstate(hwnd, PRN_ALT);
|
---|
| 441 | PrfWriteProfileData(fmprof, FM3Str, "Prnalt",
|
---|
| 442 | (PVOID) & prnalt, sizeof(prnalt));
|
---|
| 443 | prnpagenums = WinQueryButtonCheckstate(hwnd, PRN_PAGENUMS);
|
---|
| 444 | PrfWriteProfileData(fmprof, FM3Str, "Prnpagenums",
|
---|
| 445 | (PVOID) & prnpagenums, sizeof(prnpagenums));
|
---|
| 446 | prnformfeedbefore = WinQueryButtonCheckstate(hwnd, PRN_FORMBEFORE);
|
---|
| 447 | PrfWriteProfileData(fmprof, FM3Str, "Prnformfeedbefore",
|
---|
| 448 | (PVOID) & prnformfeedbefore,
|
---|
| 449 | sizeof(prnformfeedbefore));
|
---|
| 450 | prnformfeedafter = WinQueryButtonCheckstate(hwnd, PRN_FORMAFTER);
|
---|
| 451 | PrfWriteProfileData(fmprof, FM3Str, "Prnformfeedafter",
|
---|
| 452 | (PVOID) & prnformfeedafter,
|
---|
| 453 | sizeof(prnformfeedafter));
|
---|
| 454 | {
|
---|
| 455 | CHAR s[33];
|
---|
[2] | 456 |
|
---|
[551] | 457 | *s = 0;
|
---|
| 458 | WinQueryDlgItemText(hwnd, PRN_WIDTH, sizeof(s), s);
|
---|
| 459 | if (atol(s) < 24 || atol(s) > 4096) {
|
---|
| 460 | WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, PRN_WIDTH));
|
---|
| 461 | DosBeep(50, 100);
|
---|
| 462 | break;
|
---|
| 463 | }
|
---|
| 464 | prnwidth = atol(s);
|
---|
| 465 | PrfWriteProfileData(fmprof, FM3Str, "Prnwidth",
|
---|
| 466 | (PVOID) & prnwidth, sizeof(prnwidth));
|
---|
| 467 | *s = 0;
|
---|
| 468 | WinQueryDlgItemText(hwnd, PRN_LENGTH, sizeof(s), s);
|
---|
| 469 | if (atol(s) < 24 || atol(s) > 4096) {
|
---|
| 470 | WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, PRN_LENGTH));
|
---|
| 471 | DosBeep(50, 100);
|
---|
| 472 | break;
|
---|
| 473 | }
|
---|
| 474 | prnlength = atol(s);
|
---|
| 475 | PrfWriteProfileData(fmprof, FM3Str, "Prnlength",
|
---|
| 476 | (PVOID) & prnlength, sizeof(prnlength));
|
---|
| 477 | *s = 0;
|
---|
| 478 | WinQueryDlgItemText(hwnd, PRN_LMARGIN, sizeof(s), s);
|
---|
| 479 | if (atol(s) < 0 || atol(s) > prnwidth - 1) {
|
---|
| 480 | WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, PRN_LMARGIN));
|
---|
| 481 | DosBeep(50, 100);
|
---|
| 482 | break;
|
---|
| 483 | }
|
---|
| 484 | prnlmargin = atol(s);
|
---|
| 485 | PrfWriteProfileData(fmprof, FM3Str, "Prnlmargin",
|
---|
| 486 | (PVOID) & prnlmargin, sizeof(prnlmargin));
|
---|
| 487 | *s = 0;
|
---|
| 488 | WinQueryDlgItemText(hwnd, PRN_RMARGIN, sizeof(s), s);
|
---|
| 489 | if (atol(s) < 0 || atol(s) > (prnwidth - prnlmargin) - 1) {
|
---|
| 490 | WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, PRN_RMARGIN));
|
---|
| 491 | DosBeep(50, 100);
|
---|
| 492 | break;
|
---|
| 493 | }
|
---|
| 494 | prnrmargin = atol(s);
|
---|
| 495 | PrfWriteProfileData(fmprof, FM3Str, "Prnrmargin",
|
---|
| 496 | (PVOID) & prnrmargin, sizeof(prnrmargin));
|
---|
| 497 | *s = 0;
|
---|
| 498 | WinQueryDlgItemText(hwnd, PRN_TABSPACES, sizeof(s), s);
|
---|
| 499 | if (atol(s) < 1 ||
|
---|
| 500 | atol(s) > prnwidth - ((prnlmargin + prnrmargin) - 1)) {
|
---|
| 501 | WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, PRN_TABSPACES));
|
---|
| 502 | DosBeep(50, 100);
|
---|
| 503 | break;
|
---|
| 504 | }
|
---|
| 505 | prntabspaces = atol(s);
|
---|
| 506 | PrfWriteProfileData(fmprof, FM3Str, "Prntabspaces",
|
---|
| 507 | (PVOID) & prntabspaces, sizeof(prntabspaces));
|
---|
| 508 | *s = 0;
|
---|
| 509 | WinQueryDlgItemText(hwnd, PRN_TMARGIN, sizeof(s), s);
|
---|
| 510 | if (atol(s) < 0 || atol(s) > prnlength - 1) {
|
---|
| 511 | WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, PRN_TMARGIN));
|
---|
| 512 | DosBeep(50, 100);
|
---|
| 513 | break;
|
---|
| 514 | }
|
---|
| 515 | prntmargin = atol(s);
|
---|
| 516 | PrfWriteProfileData(fmprof, FM3Str, "Prntmargin",
|
---|
| 517 | (PVOID) & prntmargin, sizeof(prntmargin));
|
---|
| 518 | *s = 0;
|
---|
| 519 | WinQueryDlgItemText(hwnd, PRN_BMARGIN, sizeof(s), s);
|
---|
| 520 | if (atol(s) < 0 || atol(s) > (prnlength - prntmargin) - 1) {
|
---|
| 521 | WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, PRN_BMARGIN));
|
---|
| 522 | DosBeep(50, 100);
|
---|
| 523 | break;
|
---|
| 524 | }
|
---|
| 525 | prnbmargin = atol(s);
|
---|
| 526 | PrfWriteProfileData(fmprof, FM3Str, "Prnbmargin",
|
---|
| 527 | (PVOID) & prnbmargin, sizeof(prnbmargin));
|
---|
| 528 | *s = 0;
|
---|
| 529 | WinQueryDlgItemText(hwnd, PRN_SPACING, sizeof(s), s);
|
---|
| 530 | if (atol(s) < 1 ||
|
---|
| 531 | atol(s) > ((prnlength - prntmargin) - prnbmargin) - 1) {
|
---|
| 532 | WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, PRN_SPACING));
|
---|
| 533 | DosBeep(50, 100);
|
---|
| 534 | break;
|
---|
| 535 | }
|
---|
| 536 | prnspacing = atol(s);
|
---|
| 537 | PrfWriteProfileData(fmprof, FM3Str, "Prnspacing",
|
---|
| 538 | (PVOID) & prnspacing, sizeof(prnspacing));
|
---|
| 539 | WinQueryDlgItemText(hwnd, PRN_PRINTER, sizeof(printer), printer);
|
---|
| 540 | bstrip(printer);
|
---|
| 541 | if (!*printer)
|
---|
| 542 | strcpy(printer, "PRN");
|
---|
| 543 | WinSetDlgItemText(hwnd, PRN_PRINTER, printer);
|
---|
| 544 | PrfWriteProfileString(fmprof, appname, "Printer", printer);
|
---|
| 545 | SayPrinterReady(hwnd);
|
---|
| 546 | }
|
---|
| 547 | {
|
---|
| 548 | CHAR szBuffer[CCHMAXPATH + 1];
|
---|
[907] | 549 | UINT numfiles = 0, numalloc = 0;
|
---|
| 550 | INT error;
|
---|
[551] | 551 | SHORT x;
|
---|
[2] | 552 |
|
---|
[551] | 553 | if (li->list)
|
---|
| 554 | FreeList(li->list);
|
---|
| 555 | li->list = NULL;
|
---|
| 556 | x = (SHORT) WinSendDlgItemMsg(hwnd, PRN_LISTBOX, LM_QUERYSELECTION,
|
---|
| 557 | MPFROMSHORT(LIT_FIRST), MPVOID);
|
---|
| 558 | if (x >= 0) {
|
---|
| 559 | do {
|
---|
| 560 | *szBuffer = 0;
|
---|
| 561 | WinSendDlgItemMsg(hwnd, PRN_LISTBOX, LM_QUERYITEMTEXT,
|
---|
| 562 | MPFROM2SHORT(x, CCHMAXPATH),
|
---|
| 563 | MPFROMP(szBuffer));
|
---|
| 564 | error = AddToList(szBuffer, &li->list, &numfiles, &numalloc);
|
---|
| 565 | if (error) {
|
---|
| 566 | Runtime_Error(pszSrcFile, __LINE__, "AddToList");
|
---|
| 567 | break;
|
---|
| 568 | }
|
---|
| 569 | x = (SHORT) WinSendDlgItemMsg(hwnd, PRN_LISTBOX,
|
---|
| 570 | LM_QUERYSELECTION,
|
---|
| 571 | MPFROMSHORT(x), MPVOID);
|
---|
| 572 | } while (x >= 0);
|
---|
| 573 | }
|
---|
| 574 | }
|
---|
| 575 | if (!li->list || !li->list[0])
|
---|
| 576 | WinDismissDlg(hwnd, 0);
|
---|
| 577 | else
|
---|
| 578 | WinDismissDlg(hwnd, 1);
|
---|
[2] | 579 | }
|
---|
[551] | 580 | break;
|
---|
| 581 | case DID_CANCEL:
|
---|
| 582 | WinDismissDlg(hwnd, 0);
|
---|
| 583 | break;
|
---|
| 584 | case IDM_HELP:
|
---|
| 585 | if (hwndHelp)
|
---|
| 586 | WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
|
---|
| 587 | MPFROM2SHORT(HELP_PRINT, 0), MPFROMSHORT(HM_RESOURCEID));
|
---|
| 588 | break;
|
---|
| 589 | case IDM_UNDO:
|
---|
| 590 | PostMsg(hwnd, UM_UNDO, MPVOID, MPVOID);
|
---|
| 591 | break;
|
---|
| 592 | }
|
---|
| 593 | return 0;
|
---|
[2] | 594 | }
|
---|
[551] | 595 | return WinDefDlgProc(hwnd, msg, mp1, mp2);
|
---|
[2] | 596 | }
|
---|
[793] | 597 |
|
---|
| 598 | #pragma alloc_text(PRINTER,PrinterReady,SayPrinterReady)
|
---|
| 599 | #pragma alloc_text(PRINTER2,PrintListThread)
|
---|
| 600 | #pragma alloc_text(PRINTER3,PrintDlgProc)
|
---|