source: trunk/src/comdlg32/printdlg.c@ 9364

Last change on this file since 9364 was 9364, checked in by sandervl, 23 years ago

Use Wine printer dialog

File size: 113.6 KB
Line 
1/*
2 * COMMDLG - Print Dialog
3 *
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
6 * Copyright 1999 Klaas van Gend
7 * Copyright 2000 Huw D M Davies
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23#include <ctype.h>
24#include <stdlib.h>
25#include <stdio.h>
26#include <string.h>
27#include "windef.h"
28#include "winbase.h"
29#include "wingdi.h"
30#include "wine/wingdi16.h"
31#include "winuser.h"
32#include "wine/winuser16.h"
33#include "commdlg.h"
34#include "dlgs.h"
35#include "wine/debug.h"
36#include "cderr.h"
37#include "winspool.h"
38#include "winerror.h"
39
40WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
41
42#include "cdlg.h"
43
44/* This PRINTDLGA internal structure stores
45 * pointers to several throughout useful structures.
46 *
47 */
48typedef struct
49{
50 LPDEVMODEA lpDevMode;
51 struct {
52 LPPRINTDLGA lpPrintDlg;
53 LPPRINTDLG16 lpPrintDlg16;
54 } dlg;
55 LPPRINTER_INFO_2A lpPrinterInfo;
56 LPDRIVER_INFO_3A lpDriverInfo;
57 UINT HelpMessageID;
58 HICON hCollateIcon; /* PrintDlg only */
59 HICON hNoCollateIcon; /* PrintDlg only */
60 HICON hPortraitIcon; /* PrintSetupDlg only */
61 HICON hLandscapeIcon; /* PrintSetupDlg only */
62 HWND hwndUpDown;
63} PRINT_PTRA;
64
65typedef struct
66{
67 LPDEVMODEW lpDevMode;
68 struct {
69 LPPRINTDLGW lpPrintDlg;
70 } dlg;
71 LPPRINTER_INFO_2W lpPrinterInfo;
72 LPDRIVER_INFO_3W lpDriverInfo;
73 UINT HelpMessageID;
74 HICON hCollateIcon; /* PrintDlg only */
75 HICON hNoCollateIcon; /* PrintDlg only */
76 HICON hPortraitIcon; /* PrintSetupDlg only */
77 HICON hLandscapeIcon; /* PrintSetupDlg only */
78 HWND hwndUpDown;
79} PRINT_PTRW;
80
81/* Debugging info */
82static struct pd_flags {
83 DWORD flag;
84 LPSTR name;
85} pd_flags[] = {
86 {PD_SELECTION, "PD_SELECTION "},
87 {PD_PAGENUMS, "PD_PAGENUMS "},
88 {PD_NOSELECTION, "PD_NOSELECTION "},
89 {PD_NOPAGENUMS, "PD_NOPAGENUMS "},
90 {PD_COLLATE, "PD_COLLATE "},
91 {PD_PRINTTOFILE, "PD_PRINTTOFILE "},
92 {PD_PRINTSETUP, "PD_PRINTSETUP "},
93 {PD_NOWARNING, "PD_NOWARNING "},
94 {PD_RETURNDC, "PD_RETURNDC "},
95 {PD_RETURNIC, "PD_RETURNIC "},
96 {PD_RETURNDEFAULT, "PD_RETURNDEFAULT "},
97 {PD_SHOWHELP, "PD_SHOWHELP "},
98 {PD_ENABLEPRINTHOOK, "PD_ENABLEPRINTHOOK "},
99 {PD_ENABLESETUPHOOK, "PD_ENABLESETUPHOOK "},
100 {PD_ENABLEPRINTTEMPLATE, "PD_ENABLEPRINTTEMPLATE "},
101 {PD_ENABLESETUPTEMPLATE, "PD_ENABLESETUPTEMPLATE "},
102 {PD_ENABLEPRINTTEMPLATEHANDLE, "PD_ENABLEPRINTTEMPLATEHANDLE "},
103 {PD_ENABLESETUPTEMPLATEHANDLE, "PD_ENABLESETUPTEMPLATEHANDLE "},
104 {PD_USEDEVMODECOPIES, "PD_USEDEVMODECOPIES[ANDCOLLATE] "},
105 {PD_DISABLEPRINTTOFILE, "PD_DISABLEPRINTTOFILE "},
106 {PD_HIDEPRINTTOFILE, "PD_HIDEPRINTTOFILE "},
107 {PD_NONETWORKBUTTON, "PD_NONETWORKBUTTON "},
108 {-1, NULL}
109};
110
111/* Debugging info */
112static struct pd_flags psd_flags[] = {
113 {PSD_MINMARGINS,"PSD_MINMARGINS"},
114 {PSD_MARGINS,"PSD_MARGINS"},
115 {PSD_INTHOUSANDTHSOFINCHES,"PSD_INTHOUSANDTHSOFINCHES"},
116 {PSD_INHUNDREDTHSOFMILLIMETERS,"PSD_INHUNDREDTHSOFMILLIMETERS"},
117 {PSD_DISABLEMARGINS,"PSD_DISABLEMARGINS"},
118 {PSD_DISABLEPRINTER,"PSD_DISABLEPRINTER"},
119 {PSD_NOWARNING,"PSD_NOWARNING"},
120 {PSD_DISABLEORIENTATION,"PSD_DISABLEORIENTATION"},
121 {PSD_RETURNDEFAULT,"PSD_RETURNDEFAULT"},
122 {PSD_DISABLEPAPER,"PSD_DISABLEPAPER"},
123 {PSD_SHOWHELP,"PSD_SHOWHELP"},
124 {PSD_ENABLEPAGESETUPHOOK,"PSD_ENABLEPAGESETUPHOOK"},
125 {PSD_ENABLEPAGESETUPTEMPLATE,"PSD_ENABLEPAGESETUPTEMPLATE"},
126 {PSD_ENABLEPAGESETUPTEMPLATEHANDLE,"PSD_ENABLEPAGESETUPTEMPLATEHANDLE"},
127 {PSD_ENABLEPAGEPAINTHOOK,"PSD_ENABLEPAGEPAINTHOOK"},
128 {PSD_DISABLEPAGEPAINTING,"PSD_DISABLEPAGEPAINTING"},
129 {-1, NULL}
130};
131
132/* Yes these constants are the same, but we're just copying win98 */
133#define UPDOWN_ID 0x270f
134#define MAX_COPIES 9999
135
136/***********************************************************************
137 * PRINTDLG_GetDefaultPrinterName
138 *
139 * Returns the default printer name in buf.
140 * Even under WinNT/2000 default printer is retrieved via GetProfileString -
141 * these entries are mapped somewhere in the registry rather than win.ini.
142 *
143 * Returns TRUE on success else FALSE
144 */
145static BOOL PRINTDLG_GetDefaultPrinterNameA(LPSTR buf, DWORD len)
146{
147 char *ptr;
148
149 if(!GetProfileStringA("windows", "device", "", buf, len)) {
150 TRACE("No profile entry for default printer found.\n");
151 return FALSE;
152 }
153 if((ptr = strchr(buf, ',')) == NULL) {
154 FIXME("bad format for default printer (%s)!\n",buf);
155 return FALSE;
156 }
157 *ptr = '\0';
158 return TRUE;
159}
160
161static BOOL PRINTDLG_GetDefaultPrinterNameW(LPWSTR buf, DWORD len)
162{
163 LPSTR ptr, bufA = (LPSTR)HeapAlloc(GetProcessHeap(),0,len+1);
164
165
166 if(!GetProfileStringA("windows", "device", "", bufA, len)) {
167 TRACE("No profile entry for default printer found.\n");
168 HeapFree(GetProcessHeap(),0,bufA);
169 return FALSE;
170 }
171 if((ptr = strchr(bufA, ',')) == NULL) {
172 FIXME("bad format for default printer (%s)!\n",bufA);
173 HeapFree(GetProcessHeap(),0,bufA);
174 return FALSE;
175 }
176 *ptr = '\0';
177 MultiByteToWideChar( CP_ACP, 0, bufA, -1, buf, len );
178 HeapFree(GetProcessHeap(),0,bufA);
179 return TRUE;
180}
181
182/***********************************************************************
183 * PRINTDLG_OpenDefaultPrinter
184 *
185 * Returns a winspool printer handle to the default printer in *hprn
186 * Caller must call ClosePrinter on the handle
187 *
188 * Returns TRUE on success else FALSE
189 */
190static BOOL PRINTDLG_OpenDefaultPrinter(HANDLE *hprn)
191{
192 char buf[260];
193 BOOL res;
194 if(!PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf)))
195 return FALSE;
196 res = OpenPrinterA(buf, hprn, NULL);
197 if (!res)
198 FIXME("Could not open printer %s?!\n",buf);
199 return res;
200}
201
202/***********************************************************************
203 * PRINTDLG_SetUpPrinterListCombo
204 *
205 * Initializes printer list combox.
206 * hDlg: HWND of dialog
207 * id: Control id of combo
208 * name: Name of printer to select
209 *
210 * Initializes combo with list of available printers. Selects printer 'name'
211 * If name is NULL or does not exist select the default printer.
212 *
213 * Returns number of printers added to list.
214 */
215static INT PRINTDLG_SetUpPrinterListComboA(HWND hDlg, UINT id, LPCSTR name)
216{
217 DWORD needed, num;
218 INT i;
219 LPPRINTER_INFO_2A pi;
220 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
221 pi = HeapAlloc(GetProcessHeap(), 0, needed);
222 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
223 &num);
224
225 for(i = 0; i < num; i++) {
226 SendDlgItemMessageA(hDlg, id, CB_ADDSTRING, 0,
227 (LPARAM)pi[i].pPrinterName );
228 }
229 HeapFree(GetProcessHeap(), 0, pi);
230 if(!name ||
231 (i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1,
232 (LPARAM)name)) == CB_ERR) {
233
234 char buf[260];
235 FIXME("Can't find '%s' in printer list so trying to find default\n",
236 name);
237 if(!PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf)))
238 return num;
239 i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
240 if(i == CB_ERR)
241 FIXME("Can't find default printer in printer list\n");
242 }
243 SendDlgItemMessageA(hDlg, id, CB_SETCURSEL, i, 0);
244 return num;
245}
246
247static INT PRINTDLG_SetUpPrinterListComboW(HWND hDlg, UINT id, LPCWSTR name)
248{
249 DWORD needed, num;
250 INT i;
251 LPPRINTER_INFO_2W pi;
252 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
253 pi = HeapAlloc(GetProcessHeap(), 0, needed);
254 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
255 &num);
256
257 for(i = 0; i < num; i++) {
258 SendDlgItemMessageW(hDlg, id, CB_ADDSTRING, 0,
259 (LPARAM)pi[i].pPrinterName );
260 }
261 HeapFree(GetProcessHeap(), 0, pi);
262 if(!name ||
263 (i = SendDlgItemMessageW(hDlg, id, CB_FINDSTRINGEXACT, -1,
264 (LPARAM)name)) == CB_ERR) {
265
266 /* ansi is ok */
267 char buf[260];
268 FIXME("Can't find '%s' in printer list so trying to find default\n",
269 debugstr_w(name));
270 if(!PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf)))
271 return num;
272 i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
273 if(i == CB_ERR)
274 FIXME("Can't find default printer in printer list\n");
275 }
276 SendDlgItemMessageW(hDlg, id, CB_SETCURSEL, i, 0);
277 return num;
278}
279
280/***********************************************************************
281 * PRINTDLG_CreateDevNames [internal]
282 *
283 *
284 * creates a DevNames structure.
285 *
286 * (NB. when we handle unicode the offsets will be in wchars).
287 */
288static BOOL PRINTDLG_CreateDevNames(HGLOBAL *hmem, char* DeviceDriverName,
289 char* DeviceName, char* OutputPort)
290{
291 long size;
292 char* pDevNamesSpace;
293 char* pTempPtr;
294 LPDEVNAMES lpDevNames;
295 char buf[260];
296
297 size = strlen(DeviceDriverName) + 1
298 + strlen(DeviceName) + 1
299 + strlen(OutputPort) + 1
300 + sizeof(DEVNAMES);
301
302 if(*hmem)
303 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
304 else
305 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
306 if (*hmem == 0)
307 return FALSE;
308
309 pDevNamesSpace = GlobalLock(*hmem);
310 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
311
312 pTempPtr = pDevNamesSpace + sizeof(DEVNAMES);
313 strcpy(pTempPtr, DeviceDriverName);
314 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
315
316 pTempPtr += strlen(DeviceDriverName) + 1;
317 strcpy(pTempPtr, DeviceName);
318 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
319
320 pTempPtr += strlen(DeviceName) + 1;
321 strcpy(pTempPtr, OutputPort);
322 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
323
324 PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf));
325 lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
326 GlobalUnlock(*hmem);
327 return TRUE;
328}
329
330static BOOL PRINTDLG_CreateDevNamesW(HGLOBAL *hmem, LPCWSTR DeviceDriverName,
331 LPCWSTR DeviceName, LPCWSTR OutputPort)
332{
333 long size;
334 LPWSTR pDevNamesSpace;
335 LPWSTR pTempPtr;
336 LPDEVNAMES lpDevNames;
337 WCHAR bufW[260];
338 char buf[260];
339
340 size = sizeof(WCHAR)*lstrlenW(DeviceDriverName) + 2
341 + sizeof(WCHAR)*lstrlenW(DeviceName) + 2
342 + sizeof(WCHAR)*lstrlenW(OutputPort) + 2
343 + sizeof(DEVNAMES);
344
345 if(*hmem)
346 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
347 else
348 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
349 if (*hmem == 0)
350 return FALSE;
351
352 pDevNamesSpace = GlobalLock(*hmem);
353 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
354
355 pTempPtr = (LPWSTR)((LPDEVNAMES)pDevNamesSpace + 1);
356 lstrcpyW(pTempPtr, DeviceDriverName);
357 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
358
359 pTempPtr += lstrlenW(DeviceDriverName) + 1;
360 lstrcpyW(pTempPtr, DeviceName);
361 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
362
363 pTempPtr += lstrlenW(DeviceName) + 1;
364 lstrcpyW(pTempPtr, OutputPort);
365 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
366
367 PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf));
368 MultiByteToWideChar(CP_ACP, 0, buf, -1, bufW, -1);
369 lpDevNames->wDefault = (lstrcmpW(bufW, DeviceName) == 0) ? 1 : 0;
370 GlobalUnlock(*hmem);
371 return TRUE;
372}
373
374
375#ifndef __WIN32OS2__
376static BOOL PRINTDLG_CreateDevNames16(HGLOBAL16 *hmem, char* DeviceDriverName,
377 char* DeviceName, char* OutputPort)
378{
379 long size;
380 char* pDevNamesSpace;
381 char* pTempPtr;
382 LPDEVNAMES lpDevNames;
383 char buf[260];
384
385 size = strlen(DeviceDriverName) + 1
386 + strlen(DeviceName) + 1
387 + strlen(OutputPort) + 1
388 + sizeof(DEVNAMES);
389
390 if(*hmem)
391 *hmem = GlobalReAlloc16(*hmem, size, GMEM_MOVEABLE);
392 else
393 *hmem = GlobalAlloc16(GMEM_MOVEABLE, size);
394 if (*hmem == 0)
395 return FALSE;
396
397 pDevNamesSpace = GlobalLock16(*hmem);
398 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
399
400 pTempPtr = pDevNamesSpace + sizeof(DEVNAMES);
401 strcpy(pTempPtr, DeviceDriverName);
402 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
403
404 pTempPtr += strlen(DeviceDriverName) + 1;
405 strcpy(pTempPtr, DeviceName);
406 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
407
408 pTempPtr += strlen(DeviceName) + 1;
409 strcpy(pTempPtr, OutputPort);
410 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
411
412 PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf));
413 lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
414 GlobalUnlock16(*hmem);
415 return TRUE;
416}
417#endif
418
419/***********************************************************************
420 * PRINTDLG_UpdatePrintDlg [internal]
421 *
422 *
423 * updates the PrintDlg structure for returnvalues.
424 *
425 * RETURNS
426 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
427 * TRUE if succesful.
428 */
429static BOOL PRINTDLG_UpdatePrintDlgA(HWND hDlg,
430 PRINT_PTRA* PrintStructures)
431{
432 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
433 PDEVMODEA lpdm = PrintStructures->lpDevMode;
434 LPPRINTER_INFO_2A pi = PrintStructures->lpPrinterInfo;
435
436
437 if(!lpdm) {
438 FIXME("No lpdm ptr?\n");
439 return FALSE;
440 }
441
442
443 if(!(lppd->Flags & PD_PRINTSETUP)) {
444 /* check whether nFromPage and nToPage are within range defined by
445 * nMinPage and nMaxPage
446 */
447 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
448 WORD nToPage;
449 WORD nFromPage;
450 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
451 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
452 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
453 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
454 char resourcestr[256];
455 char resultstr[256];
456 LoadStringA(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
457 resourcestr, 255);
458 sprintf(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
459 LoadStringA(COMDLG32_hInstance, PD32_PRINT_TITLE,
460 resourcestr, 255);
461 MessageBoxA(hDlg, resultstr, resourcestr,
462 MB_OK | MB_ICONWARNING);
463 return FALSE;
464 }
465 lppd->nFromPage = nFromPage;
466 lppd->nToPage = nToPage;
467 lppd->Flags |= PD_PAGENUMS;
468 }
469 else
470 lppd->Flags &= ~PD_PAGENUMS;
471
472 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
473 lppd->Flags |= PD_PRINTTOFILE;
474 pi->pPortName = "FILE:";
475 }
476
477 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
478 FIXME("Collate lppd not yet implemented as output\n");
479 }
480
481 /* set PD_Collate and nCopies */
482 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
483 /* The application doesn't support multiple copies or collate...
484 */
485 lppd->Flags &= ~PD_COLLATE;
486 lppd->nCopies = 1;
487 /* if the printer driver supports it... store info there
488 * otherwise no collate & multiple copies !
489 */
490 if (lpdm->dmFields & DM_COLLATE)
491 lpdm->dmCollate =
492 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
493 if (lpdm->dmFields & DM_COPIES)
494 lpdm->dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
495 } else {
496 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
497 lppd->Flags |= PD_COLLATE;
498 else
499 lppd->Flags &= ~PD_COLLATE;
500 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
501 }
502 }
503 return TRUE;
504}
505
506static BOOL PRINTDLG_UpdatePrintDlgW(HWND hDlg,
507 PRINT_PTRW* PrintStructures)
508{
509 LPPRINTDLGW lppd = PrintStructures->dlg.lpPrintDlg;
510 PDEVMODEW lpdm = PrintStructures->lpDevMode;
511 LPPRINTER_INFO_2W pi = PrintStructures->lpPrinterInfo;
512
513
514 if(!lpdm) {
515 FIXME("No lpdm ptr?\n");
516 return FALSE;
517 }
518
519
520 if(!(lppd->Flags & PD_PRINTSETUP)) {
521 /* check whether nFromPage and nToPage are within range defined by
522 * nMinPage and nMaxPage
523 */
524 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
525 WORD nToPage;
526 WORD nFromPage;
527 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
528 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
529 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
530 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
531 char resourcestr[256];
532 char resultstr[256];
533 LoadStringA(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
534 resourcestr, 255);
535 sprintf(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
536 LoadStringA(COMDLG32_hInstance, PD32_PRINT_TITLE,
537 resourcestr, 255);
538 MessageBoxA(hDlg, resultstr, resourcestr,
539 MB_OK | MB_ICONWARNING);
540 return FALSE;
541 }
542 lppd->nFromPage = nFromPage;
543 lppd->nToPage = nToPage;
544 }
545
546 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
547 static WCHAR file[] = {'F','I','L','E',':',0};
548 lppd->Flags |= PD_PRINTTOFILE;
549 pi->pPortName = file;
550 }
551
552 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
553 FIXME("Collate lppd not yet implemented as output\n");
554 }
555
556 /* set PD_Collate and nCopies */
557 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
558 /* The application doesn't support multiple copies or collate...
559 */
560 lppd->Flags &= ~PD_COLLATE;
561 lppd->nCopies = 1;
562 /* if the printer driver supports it... store info there
563 * otherwise no collate & multiple copies !
564 */
565 if (lpdm->dmFields & DM_COLLATE)
566 lpdm->dmCollate =
567 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
568 if (lpdm->dmFields & DM_COPIES)
569 lpdm->dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
570 } else {
571 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
572 lppd->Flags |= PD_COLLATE;
573 else
574 lppd->Flags &= ~PD_COLLATE;
575 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
576 }
577 }
578 return TRUE;
579}
580
581static BOOL PRINTDLG_PaperSizeA(
582 PRINTDLGA *pdlga,const char *PaperSize,LPPOINT size
583) {
584 DEVNAMES *dn;
585 DEVMODEA *dm;
586 LPSTR devname,portname;
587 int i;
588 INT NrOfEntries,ret;
589 char *Names = NULL;
590 POINT *points = NULL;
591 BOOL retval = FALSE;
592
593 dn = GlobalLock(pdlga->hDevNames);
594 dm = GlobalLock(pdlga->hDevMode);
595 devname = ((char*)dn)+dn->wDeviceOffset;
596 portname = ((char*)dn)+dn->wOutputOffset;
597
598
599 NrOfEntries = DeviceCapabilitiesA(devname,portname,DC_PAPERNAMES,NULL,dm);
600 if (!NrOfEntries) {
601 FIXME("No papernames found for %s/%s\n",devname,portname);
602 goto out;
603 }
604 if (NrOfEntries == -1) {
605 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
606 goto out;
607 }
608
609 Names = (char*)HeapAlloc(GetProcessHeap(),0,NrOfEntries*64);
610 if (NrOfEntries != (ret=DeviceCapabilitiesA(devname,portname,DC_PAPERNAMES,Names,dm))) {
611 FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
612 goto out;
613 }
614 for (i=0;i<NrOfEntries;i++)
615 if (!strcmp(PaperSize,Names+(64*i)))
616 break;
617 HeapFree(GetProcessHeap(),0,Names);
618 if (i==NrOfEntries) {
619 FIXME("Papersize %s not found in list?\n",PaperSize);
620 goto out;
621 }
622 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
623 if (NrOfEntries!=(ret=DeviceCapabilitiesA(devname,portname,DC_PAPERSIZE,(LPBYTE)points,dm))) {
624 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
625 goto out;
626 }
627 /* this is _10ths_ of a millimeter */
628 size->x=points[i].x;
629 size->y=points[i].y;
630 retval = TRUE;
631out:
632 GlobalUnlock(pdlga->hDevNames);
633 GlobalUnlock(pdlga->hDevMode);
634 if (Names) HeapFree(GetProcessHeap(),0,Names);
635 if (points) HeapFree(GetProcessHeap(),0,points);
636 return retval;
637}
638
639static BOOL PRINTDLG_PaperSizeW(
640 PRINTDLGW *pdlga,const WCHAR *PaperSize,LPPOINT size
641) {
642 DEVNAMES *dn;
643 DEVMODEW *dm;
644 LPWSTR devname,portname;
645 int i;
646 INT NrOfEntries,ret;
647 WCHAR *Names = NULL;
648 POINT *points = NULL;
649 BOOL retval = FALSE;
650
651 dn = GlobalLock(pdlga->hDevNames);
652 dm = GlobalLock(pdlga->hDevMode);
653 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
654 portname = ((WCHAR*)dn)+dn->wOutputOffset;
655
656
657 NrOfEntries = DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,NULL,dm);
658 if (!NrOfEntries) {
659 FIXME("No papernames found for %s/%s\n",debugstr_w(devname),debugstr_w(portname));
660 goto out;
661 }
662 if (NrOfEntries == -1) {
663 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
664 goto out;
665 }
666
667 Names = (WCHAR*)HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*NrOfEntries*64);
668 if (NrOfEntries != (ret=DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,Names,dm))) {
669 FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
670 goto out;
671 }
672 for (i=0;i<NrOfEntries;i++)
673 if (!lstrcmpW(PaperSize,Names+(64*i)))
674 break;
675 HeapFree(GetProcessHeap(),0,Names);
676 if (i==NrOfEntries) {
677 FIXME("Papersize %s not found in list?\n",debugstr_w(PaperSize));
678 goto out;
679 }
680 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
681 if (NrOfEntries!=(ret=DeviceCapabilitiesW(devname,portname,DC_PAPERSIZE,(LPWSTR)points,dm))) {
682 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
683 goto out;
684 }
685 /* this is _10ths_ of a millimeter */
686 size->x=points[i].x;
687 size->y=points[i].y;
688 retval = TRUE;
689out:
690 GlobalUnlock(pdlga->hDevNames);
691 GlobalUnlock(pdlga->hDevMode);
692 if (Names) HeapFree(GetProcessHeap(),0,Names);
693 if (points) HeapFree(GetProcessHeap(),0,points);
694 return retval;
695}
696
697
698/************************************************************************
699 * PRINTDLG_SetUpPaperComboBox
700 *
701 * Initialize either the papersize or inputslot combos of the Printer Setup
702 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
703 * We also try to re-select the old selection.
704 */
705static BOOL PRINTDLG_SetUpPaperComboBoxA(HWND hDlg,
706 int nIDComboBox,
707 char* PrinterName,
708 char* PortName,
709 LPDEVMODEA dm)
710{
711 int i;
712 int NrOfEntries;
713 char* Names;
714 WORD* Words;
715 DWORD Sel;
716 WORD oldWord = 0;
717 int NamesSize;
718 int fwCapability_Names;
719 int fwCapability_Words;
720
721 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName,PortName,nIDComboBox);
722
723 /* query the dialog box for the current selected value */
724 Sel = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
725 if(Sel != CB_ERR) {
726 /* we enter here only if a different printer is selected after
727 * the Print Setup dialog is opened. The current settings are
728 * stored into the newly selected printer.
729 */
730 oldWord = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA,
731 Sel, 0);
732 if (dm) {
733 if (nIDComboBox == cmb2)
734 dm->u1.s1.dmPaperSize = oldWord;
735 else
736 dm->dmDefaultSource = oldWord;
737 }
738 }
739 else {
740 /* we enter here only when the Print setup dialog is initially
741 * opened. In this case the settings are restored from when
742 * the dialog was last closed.
743 */
744 if (dm) {
745 if (nIDComboBox == cmb2)
746 oldWord = dm->u1.s1.dmPaperSize;
747 else
748 oldWord = dm->dmDefaultSource;
749 }
750 }
751
752 if (nIDComboBox == cmb2) {
753 NamesSize = 64;
754 fwCapability_Names = DC_PAPERNAMES;
755 fwCapability_Words = DC_PAPERS;
756 } else {
757 nIDComboBox = cmb3;
758 NamesSize = 24;
759 fwCapability_Names = DC_BINNAMES;
760 fwCapability_Words = DC_BINS;
761 }
762
763 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
764 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
765 */
766 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
767 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
768 fwCapability_Names, NULL, dm);
769 if (NrOfEntries == 0)
770 WARN("no Name Entries found!\n");
771 else if (NrOfEntries < 0)
772 return FALSE;
773
774 if(DeviceCapabilitiesA(PrinterName, PortName, fwCapability_Words, NULL, dm)
775 != NrOfEntries) {
776 ERR("Number of caps is different\n");
777 NrOfEntries = 0;
778 }
779
780 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(char)*NamesSize);
781 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
782 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
783 fwCapability_Names, Names, dm);
784 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
785 fwCapability_Words, (LPSTR)Words, dm);
786
787 /* reset any current content in the combobox */
788 SendDlgItemMessageA(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
789
790 /* store new content */
791 for (i = 0; i < NrOfEntries; i++) {
792 DWORD pos = SendDlgItemMessageA(hDlg, nIDComboBox, CB_ADDSTRING, 0,
793 (LPARAM)(&Names[i*NamesSize]) );
794 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
795 Words[i]);
796 }
797
798 /* Look for old selection - can't do this is previous loop since
799 item order will change as more items are added */
800 Sel = 0;
801 for (i = 0; i < NrOfEntries; i++) {
802 if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
803 oldWord) {
804 Sel = i;
805 break;
806 }
807 }
808 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
809
810 HeapFree(GetProcessHeap(),0,Words);
811 HeapFree(GetProcessHeap(),0,Names);
812 return TRUE;
813}
814
815static BOOL PRINTDLG_SetUpPaperComboBoxW(HWND hDlg,
816 int nIDComboBox,
817 WCHAR* PrinterName,
818 WCHAR* PortName,
819 LPDEVMODEW dm)
820{
821 int i;
822 int NrOfEntries;
823 WCHAR* Names;
824 WORD* Words;
825 DWORD Sel;
826 WORD oldWord = 0;
827 int NamesSize;
828 int fwCapability_Names;
829 int fwCapability_Words;
830
831 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName),debugstr_w(PortName),nIDComboBox);
832
833 /* query the dialog box for the current selected value */
834 Sel = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
835 if(Sel != CB_ERR) {
836 /* we enter here only if a different printer is selected after
837 * the Print Setup dialog is opened. The current settings are
838 * stored into the newly selected printer.
839 */
840 oldWord = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA,
841 Sel, 0);
842 if (dm) {
843 if (nIDComboBox == cmb2)
844 dm->u1.s1.dmPaperSize = oldWord;
845 else
846 dm->dmDefaultSource = oldWord;
847 }
848 }
849 else {
850 /* we enter here only when the Print setup dialog is initially
851 * opened. In this case the settings are restored from when
852 * the dialog was last closed.
853 */
854 if (dm) {
855 if (nIDComboBox == cmb2)
856 oldWord = dm->u1.s1.dmPaperSize;
857 else
858 oldWord = dm->dmDefaultSource;
859 }
860 }
861
862 if (nIDComboBox == cmb2) {
863 NamesSize = 64;
864 fwCapability_Names = DC_PAPERNAMES;
865 fwCapability_Words = DC_PAPERS;
866 } else {
867 nIDComboBox = cmb3;
868 NamesSize = 24;
869 fwCapability_Names = DC_BINNAMES;
870 fwCapability_Words = DC_BINS;
871 }
872
873 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
874 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
875 */
876 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
877 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
878 fwCapability_Names, NULL, dm);
879 if (NrOfEntries == 0)
880 WARN("no Name Entries found!\n");
881 else if (NrOfEntries < 0)
882 return FALSE;
883
884 if(DeviceCapabilitiesW(PrinterName, PortName, fwCapability_Words, NULL, dm)
885 != NrOfEntries) {
886 ERR("Number of caps is different\n");
887 NrOfEntries = 0;
888 }
889
890 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WCHAR)*NamesSize);
891 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
892 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
893 fwCapability_Names, Names, dm);
894 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
895 fwCapability_Words, (LPWSTR)Words, dm);
896
897 /* reset any current content in the combobox */
898 SendDlgItemMessageA(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
899
900 /* store new content */
901 for (i = 0; i < NrOfEntries; i++) {
902 DWORD pos = SendDlgItemMessageW(hDlg, nIDComboBox, CB_ADDSTRING, 0,
903 (LPARAM)(&Names[i*NamesSize]) );
904 SendDlgItemMessageW(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
905 Words[i]);
906 }
907
908 /* Look for old selection - can't do this is previous loop since
909 item order will change as more items are added */
910 Sel = 0;
911 for (i = 0; i < NrOfEntries; i++) {
912 if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
913 oldWord) {
914 Sel = i;
915 break;
916 }
917 }
918 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
919
920 HeapFree(GetProcessHeap(),0,Words);
921 HeapFree(GetProcessHeap(),0,Names);
922 return TRUE;
923}
924
925
926/***********************************************************************
927 * PRINTDLG_UpdatePrinterInfoTexts [internal]
928 */
929static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg, LPPRINTER_INFO_2A pi)
930{
931 char StatusMsg[256];
932 char ResourceString[256];
933 int i;
934
935 /* Status Message */
936 StatusMsg[0]='\0';
937
938 /* add all status messages */
939 for (i = 0; i < 25; i++) {
940 if (pi->Status & (1<<i)) {
941 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
942 ResourceString, 255);
943 strcat(StatusMsg,ResourceString);
944 }
945 }
946 /* append "ready" */
947 /* FIXME: status==ready must only be appended if really so.
948 but how to detect? */
949 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
950 ResourceString, 255);
951 strcat(StatusMsg,ResourceString);
952
953 SendDlgItemMessageA(hDlg, stc12, WM_SETTEXT, 0, (LPARAM)StatusMsg);
954
955 /* set all other printer info texts */
956 SendDlgItemMessageA(hDlg, stc11, WM_SETTEXT, 0, (LPARAM)pi->pDriverName);
957 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
958 SendDlgItemMessageA(hDlg, stc14, WM_SETTEXT, 0,(LPARAM)pi->pLocation);
959 else
960 SendDlgItemMessageA(hDlg, stc14, WM_SETTEXT, 0,(LPARAM)pi->pPortName);
961 SendDlgItemMessageA(hDlg, stc13, WM_SETTEXT, 0, (LPARAM)(pi->pComment ?
962 pi->pComment : ""));
963 return;
964}
965
966static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg, LPPRINTER_INFO_2W pi)
967{
968 WCHAR StatusMsg[256];
969 WCHAR ResourceString[256];
970 int i;
971
972 /* Status Message */
973 StatusMsg[0]='\0';
974
975 /* add all status messages */
976 for (i = 0; i < 25; i++) {
977 if (pi->Status & (1<<i)) {
978 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
979 ResourceString, 255);
980 lstrcatW(StatusMsg,ResourceString);
981 }
982 }
983 /* append "ready" */
984 /* FIXME: status==ready must only be appended if really so.
985 but how to detect? */
986 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
987 ResourceString, 255);
988 lstrcatW(StatusMsg,ResourceString);
989
990 SendDlgItemMessageW(hDlg, stc12, WM_SETTEXT, 0, (LPARAM)StatusMsg);
991
992 /* set all other printer info texts */
993 SendDlgItemMessageW(hDlg, stc11, WM_SETTEXT, 0, (LPARAM)pi->pDriverName);
994 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
995 SendDlgItemMessageW(hDlg, stc14, WM_SETTEXT, 0,(LPARAM)pi->pLocation);
996 else
997 SendDlgItemMessageW(hDlg, stc14, WM_SETTEXT, 0,(LPARAM)pi->pPortName);
998 SendDlgItemMessageW(hDlg, stc13, WM_SETTEXT, 0, (LPARAM)(pi->pComment ?
999 pi->pComment : (LPCWSTR)"\0\0"));
1000 return;
1001}
1002
1003
1004/*******************************************************************
1005 *
1006 * PRINTDLG_ChangePrinter
1007 *
1008 */
1009static BOOL PRINTDLG_ChangePrinterA(HWND hDlg, char *name,
1010 PRINT_PTRA *PrintStructures)
1011{
1012 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
1013 LPDEVMODEA lpdm = NULL;
1014 LONG dmSize;
1015 DWORD needed;
1016 HANDLE hprn;
1017
1018 if(PrintStructures->lpPrinterInfo)
1019 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
1020 if(PrintStructures->lpDriverInfo)
1021 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
1022 if(!OpenPrinterA(name, &hprn, NULL)) {
1023 ERR("Can't open printer %s\n", name);
1024 return FALSE;
1025 }
1026 GetPrinterA(hprn, 2, NULL, 0, &needed);
1027 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,needed);
1028 GetPrinterA(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
1029 &needed);
1030 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
1031 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,needed);
1032 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
1033 needed, &needed)) {
1034 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures->lpPrinterInfo->pPrinterName);
1035 return FALSE;
1036 }
1037 ClosePrinter(hprn);
1038
1039 PRINTDLG_UpdatePrinterInfoTextsA(hDlg, PrintStructures->lpPrinterInfo);
1040
1041 if(PrintStructures->lpDevMode) {
1042 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
1043 PrintStructures->lpDevMode = NULL;
1044 }
1045
1046 dmSize = DocumentPropertiesA(0, 0, name, NULL, NULL, 0);
1047 if(dmSize == -1) {
1048 ERR("DocumentProperties fails on %s\n", debugstr_a(name));
1049 return FALSE;
1050 }
1051 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
1052 dmSize = DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, NULL,
1053 DM_OUT_BUFFER);
1054 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
1055 !strcmp(lpdm->dmDeviceName,
1056 PrintStructures->lpDevMode->dmDeviceName)) {
1057 /* Supplied devicemode matches current printer so try to use it */
1058 DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, lpdm,
1059 DM_OUT_BUFFER | DM_IN_BUFFER);
1060 }
1061 if(lpdm)
1062 GlobalUnlock(lppd->hDevMode);
1063
1064 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
1065
1066 if(!(lppd->Flags & PD_PRINTSETUP)) {
1067 /* Print range (All/Range/Selection) */
1068 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
1069 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
1070 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
1071 if (lppd->Flags & PD_NOSELECTION)
1072 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
1073 else
1074 if (lppd->Flags & PD_SELECTION)
1075 CheckRadioButton(hDlg, rad1, rad3, rad2);
1076 if (lppd->Flags & PD_NOPAGENUMS) {
1077 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
1078 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
1079 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
1080 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
1081 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
1082 } else {
1083 if (lppd->Flags & PD_PAGENUMS)
1084 CheckRadioButton(hDlg, rad1, rad3, rad3);
1085 }
1086 /* "All xxx pages"... */
1087 {
1088 char resourcestr[64];
1089 char result[64];
1090 LoadStringA(COMDLG32_hInstance, PD32_PRINT_ALL_X_PAGES,
1091 resourcestr, 49);
1092 sprintf(result,resourcestr,lppd->nMaxPage - lppd->nMinPage + 1);
1093 SendDlgItemMessageA(hDlg, rad1, WM_SETTEXT, 0, (LPARAM) result);
1094 }
1095
1096 /* Collate pages
1097 *
1098 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1099 */
1100 if (lppd->Flags & PD_COLLATE) {
1101 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1102 (LPARAM)PrintStructures->hCollateIcon);
1103 CheckDlgButton(hDlg, chx2, 1);
1104 } else {
1105 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1106 (LPARAM)PrintStructures->hNoCollateIcon);
1107 CheckDlgButton(hDlg, chx2, 0);
1108 }
1109
1110 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1111 /* if printer doesn't support it: no Collate */
1112 if (!(lpdm->dmFields & DM_COLLATE)) {
1113 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1114 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
1115 }
1116 }
1117
1118 /* nCopies */
1119 {
1120 INT copies;
1121 if (lppd->hDevMode == 0)
1122 copies = lppd->nCopies;
1123 else
1124 copies = lpdm->dmCopies;
1125 if(copies == 0) copies = 1;
1126 else if(copies < 0) copies = MAX_COPIES;
1127 SetDlgItemInt(hDlg, edt3, copies, FALSE);
1128 }
1129
1130 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1131 /* if printer doesn't support it: no nCopies */
1132 if (!(lpdm->dmFields & DM_COPIES)) {
1133 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
1134 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
1135 }
1136 }
1137
1138 /* print to file */
1139 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
1140 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
1141 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
1142 if (lppd->Flags & PD_HIDEPRINTTOFILE)
1143 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
1144
1145 } else { /* PD_PRINTSETUP */
1146 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
1147
1148 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb2,
1149 PrintStructures->lpPrinterInfo->pPrinterName,
1150 PrintStructures->lpPrinterInfo->pPortName,
1151 lpdm);
1152 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb3,
1153 PrintStructures->lpPrinterInfo->pPrinterName,
1154 PrintStructures->lpPrinterInfo->pPortName,
1155 lpdm);
1156 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1157 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1158 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1159 PrintStructures->hLandscapeIcon));
1160
1161 }
1162
1163 /* help button */
1164 if ((lppd->Flags & PD_SHOWHELP)==0) {
1165 /* hide if PD_SHOWHELP not specified */
1166 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1167 }
1168 return TRUE;
1169}
1170
1171static BOOL PRINTDLG_ChangePrinterW(HWND hDlg, WCHAR *name,
1172 PRINT_PTRW *PrintStructures)
1173{
1174 LPPRINTDLGW lppd = PrintStructures->dlg.lpPrintDlg;
1175 LPDEVMODEW lpdm = NULL;
1176 LONG dmSize;
1177 DWORD needed;
1178 HANDLE hprn;
1179
1180 if(PrintStructures->lpPrinterInfo)
1181 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
1182 if(PrintStructures->lpDriverInfo)
1183 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
1184 if(!OpenPrinterW(name, &hprn, NULL)) {
1185 ERR("Can't open printer %s\n", debugstr_w(name));
1186 return FALSE;
1187 }
1188 GetPrinterW(hprn, 2, NULL, 0, &needed);
1189 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
1190 GetPrinterW(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
1191 &needed);
1192 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
1193 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
1194 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
1195 needed, &needed)) {
1196 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures->lpPrinterInfo->pPrinterName));
1197 return FALSE;
1198 }
1199 ClosePrinter(hprn);
1200
1201 PRINTDLG_UpdatePrinterInfoTextsW(hDlg, PrintStructures->lpPrinterInfo);
1202
1203 if(PrintStructures->lpDevMode) {
1204 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
1205 PrintStructures->lpDevMode = NULL;
1206 }
1207
1208 dmSize = DocumentPropertiesW(0, 0, name, NULL, NULL, 0);
1209 if(dmSize == -1) {
1210 ERR("DocumentProperties fails on %s\n", debugstr_w(name));
1211 return FALSE;
1212 }
1213 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
1214 dmSize = DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, NULL,
1215 DM_OUT_BUFFER);
1216 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
1217 !lstrcmpW(lpdm->dmDeviceName,
1218 PrintStructures->lpDevMode->dmDeviceName)) {
1219 /* Supplied devicemode matches current printer so try to use it */
1220 DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, lpdm,
1221 DM_OUT_BUFFER | DM_IN_BUFFER);
1222 }
1223 if(lpdm)
1224 GlobalUnlock(lppd->hDevMode);
1225
1226 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
1227
1228 if(!(lppd->Flags & PD_PRINTSETUP)) {
1229 /* Print range (All/Range/Selection) */
1230 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
1231 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
1232 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
1233 if (lppd->Flags & PD_NOSELECTION)
1234 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
1235 else
1236 if (lppd->Flags & PD_SELECTION)
1237 CheckRadioButton(hDlg, rad1, rad3, rad2);
1238 if (lppd->Flags & PD_NOPAGENUMS) {
1239 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
1240 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
1241 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
1242 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
1243 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
1244 } else {
1245 if (lppd->Flags & PD_PAGENUMS)
1246 CheckRadioButton(hDlg, rad1, rad3, rad3);
1247 }
1248 /* "All xxx pages"... */
1249 {
1250 /* ansi is ok */
1251 char resourcestr[64];
1252 char result[64];
1253 LoadStringA(COMDLG32_hInstance, PD32_PRINT_ALL_X_PAGES,
1254 resourcestr, 49);
1255 sprintf(result,resourcestr,lppd->nMaxPage - lppd->nMinPage + 1);
1256 SendDlgItemMessageA(hDlg, rad1, WM_SETTEXT, 0, (LPARAM) result);
1257 }
1258
1259 /* Collate pages
1260 *
1261 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1262 */
1263 if (lppd->Flags & PD_COLLATE) {
1264 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1265 (LPARAM)PrintStructures->hCollateIcon);
1266 CheckDlgButton(hDlg, chx2, 1);
1267 } else {
1268 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1269 (LPARAM)PrintStructures->hNoCollateIcon);
1270 CheckDlgButton(hDlg, chx2, 0);
1271 }
1272
1273 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1274 /* if printer doesn't support it: no Collate */
1275 if (!(lpdm->dmFields & DM_COLLATE)) {
1276 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1277 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
1278 }
1279 }
1280
1281 /* nCopies */
1282 {
1283 INT copies;
1284 if (lppd->hDevMode == 0)
1285 copies = lppd->nCopies;
1286 else
1287 copies = lpdm->dmCopies;
1288 if(copies == 0) copies = 1;
1289 else if(copies < 0) copies = MAX_COPIES;
1290 SetDlgItemInt(hDlg, edt3, copies, FALSE);
1291 }
1292
1293 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1294 /* if printer doesn't support it: no nCopies */
1295 if (!(lpdm->dmFields & DM_COPIES)) {
1296 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
1297 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
1298 }
1299 }
1300
1301 /* print to file */
1302 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
1303 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
1304 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
1305 if (lppd->Flags & PD_HIDEPRINTTOFILE)
1306 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
1307
1308 } else { /* PD_PRINTSETUP */
1309 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
1310
1311 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb2,
1312 PrintStructures->lpPrinterInfo->pPrinterName,
1313 PrintStructures->lpPrinterInfo->pPortName,
1314 lpdm);
1315 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb3,
1316 PrintStructures->lpPrinterInfo->pPrinterName,
1317 PrintStructures->lpPrinterInfo->pPortName,
1318 lpdm);
1319 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1320 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1321 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1322 PrintStructures->hLandscapeIcon));
1323
1324 }
1325
1326 /* help button */
1327 if ((lppd->Flags & PD_SHOWHELP)==0) {
1328 /* hide if PD_SHOWHELP not specified */
1329 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1330 }
1331 return TRUE;
1332}
1333
1334/***********************************************************************
1335 * PRINTDLG_WMInitDialog [internal]
1336 */
1337static LRESULT PRINTDLG_WMInitDialog(HWND hDlg, WPARAM wParam,
1338 PRINT_PTRA* PrintStructures)
1339{
1340 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
1341 DEVNAMES *pdn;
1342 DEVMODEA *pdm;
1343 char *name = NULL;
1344 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1345
1346 /* load Collate ICONs */
1347 /* We load these with LoadImage because they are not a standard
1348 size and we don't want them rescaled */
1349 PrintStructures->hCollateIcon =
1350 LoadImageA(COMDLG32_hInstance, "PD32_COLLATE", IMAGE_ICON, 0, 0, 0);
1351 PrintStructures->hNoCollateIcon =
1352 LoadImageA(COMDLG32_hInstance, "PD32_NOCOLLATE", IMAGE_ICON, 0, 0, 0);
1353
1354 /* These can be done with LoadIcon */
1355 PrintStructures->hPortraitIcon =
1356 LoadIconA(COMDLG32_hInstance, "PD32_PORTRAIT");
1357 PrintStructures->hLandscapeIcon =
1358 LoadIconA(COMDLG32_hInstance, "PD32_LANDSCAPE");
1359
1360 if(PrintStructures->hCollateIcon == 0 ||
1361 PrintStructures->hNoCollateIcon == 0 ||
1362 PrintStructures->hPortraitIcon == 0 ||
1363 PrintStructures->hLandscapeIcon == 0) {
1364 ERR("no icon in resourcefile\n");
1365 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1366 EndDialog(hDlg, FALSE);
1367 }
1368
1369 /*
1370 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1371 * must be registered and the Help button must be shown.
1372 */
1373 if (lppd->Flags & PD_SHOWHELP) {
1374 if((PrintStructures->HelpMessageID =
1375 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
1376 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1377 return FALSE;
1378 }
1379 } else
1380 PrintStructures->HelpMessageID = 0;
1381
1382 if(!(lppd->Flags &PD_PRINTSETUP)) {
1383 PrintStructures->hwndUpDown =
1384 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1385 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1386 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1387 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1388 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1389 }
1390
1391 /* FIXME: I allow more freedom than either Win95 or WinNT,
1392 * which do not agree to what errors should be thrown or not
1393 * in case nToPage or nFromPage is out-of-range.
1394 */
1395 if (lppd->nMaxPage < lppd->nMinPage)
1396 lppd->nMaxPage = lppd->nMinPage;
1397 if (lppd->nMinPage == lppd->nMaxPage)
1398 lppd->Flags |= PD_NOPAGENUMS;
1399 if (lppd->nToPage < lppd->nMinPage)
1400 lppd->nToPage = lppd->nMinPage;
1401 if (lppd->nToPage > lppd->nMaxPage)
1402 lppd->nToPage = lppd->nMaxPage;
1403 if (lppd->nFromPage < lppd->nMinPage)
1404 lppd->nFromPage = lppd->nMinPage;
1405 if (lppd->nFromPage > lppd->nMaxPage)
1406 lppd->nFromPage = lppd->nMaxPage;
1407
1408 /* if we have the combo box, fill it */
1409 if (GetDlgItem(hDlg,comboID)) {
1410 /* Fill Combobox
1411 */
1412 pdn = GlobalLock(lppd->hDevNames);
1413 pdm = GlobalLock(lppd->hDevMode);
1414 if(pdn)
1415 name = (char*)pdn + pdn->wDeviceOffset;
1416 else if(pdm)
1417 name = pdm->dmDeviceName;
1418 PRINTDLG_SetUpPrinterListComboA(hDlg, comboID, name);
1419 if(pdm) GlobalUnlock(lppd->hDevMode);
1420 if(pdn) GlobalUnlock(lppd->hDevNames);
1421
1422 /* Now find selected printer and update rest of dlg */
1423 name = HeapAlloc(GetProcessHeap(),0,256);
1424 if (GetDlgItemTextA(hDlg, comboID, name, 255))
1425 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1426 HeapFree(GetProcessHeap(),0,name);
1427 } else {
1428 /* else use default printer */
1429 char name[200];
1430 BOOL ret = PRINTDLG_GetDefaultPrinterNameA(name, sizeof(name));
1431
1432 if (ret)
1433 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1434 else
1435 FIXME("No default printer found, expect problems!\n");
1436 }
1437 return TRUE;
1438}
1439
1440static LRESULT PRINTDLG_WMInitDialogW(HWND hDlg, WPARAM wParam,
1441 PRINT_PTRW* PrintStructures)
1442{
1443 LPPRINTDLGW lppd = PrintStructures->dlg.lpPrintDlg;
1444 DEVNAMES *pdn;
1445 DEVMODEW *pdm;
1446 WCHAR *name = NULL;
1447 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1448
1449 /* load Collate ICONs */
1450 /* We load these with LoadImage because they are not a standard
1451 size and we don't want them rescaled */
1452 PrintStructures->hCollateIcon =
1453 LoadImageA(COMDLG32_hInstance, "PD32_COLLATE", IMAGE_ICON, 0, 0, 0);
1454 PrintStructures->hNoCollateIcon =
1455 LoadImageA(COMDLG32_hInstance, "PD32_NOCOLLATE", IMAGE_ICON, 0, 0, 0);
1456
1457 /* These can be done with LoadIcon */
1458 PrintStructures->hPortraitIcon =
1459 LoadIconA(COMDLG32_hInstance, "PD32_PORTRAIT");
1460 PrintStructures->hLandscapeIcon =
1461 LoadIconA(COMDLG32_hInstance, "PD32_LANDSCAPE");
1462
1463 if(PrintStructures->hCollateIcon == 0 ||
1464 PrintStructures->hNoCollateIcon == 0 ||
1465 PrintStructures->hPortraitIcon == 0 ||
1466 PrintStructures->hLandscapeIcon == 0) {
1467 ERR("no icon in resourcefile\n");
1468 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1469 EndDialog(hDlg, FALSE);
1470 }
1471
1472 /*
1473 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1474 * must be registered and the Help button must be shown.
1475 */
1476 if (lppd->Flags & PD_SHOWHELP) {
1477 if((PrintStructures->HelpMessageID =
1478 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
1479 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1480 return FALSE;
1481 }
1482 } else
1483 PrintStructures->HelpMessageID = 0;
1484
1485 if(!(lppd->Flags &PD_PRINTSETUP)) {
1486 PrintStructures->hwndUpDown =
1487 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1488 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1489 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1490 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1491 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1492 }
1493
1494 /* FIXME: I allow more freedom than either Win95 or WinNT,
1495 * which do not agree to what errors should be thrown or not
1496 * in case nToPage or nFromPage is out-of-range.
1497 */
1498 if (lppd->nMaxPage < lppd->nMinPage)
1499 lppd->nMaxPage = lppd->nMinPage;
1500 if (lppd->nMinPage == lppd->nMaxPage)
1501 lppd->Flags |= PD_NOPAGENUMS;
1502 if (lppd->nToPage < lppd->nMinPage)
1503 lppd->nToPage = lppd->nMinPage;
1504 if (lppd->nToPage > lppd->nMaxPage)
1505 lppd->nToPage = lppd->nMaxPage;
1506 if (lppd->nFromPage < lppd->nMinPage)
1507 lppd->nFromPage = lppd->nMinPage;
1508 if (lppd->nFromPage > lppd->nMaxPage)
1509 lppd->nFromPage = lppd->nMaxPage;
1510
1511 /* if we have the combo box, fill it */
1512 if (GetDlgItem(hDlg,comboID)) {
1513 /* Fill Combobox
1514 */
1515 pdn = GlobalLock(lppd->hDevNames);
1516 pdm = GlobalLock(lppd->hDevMode);
1517 if(pdn)
1518 name = (WCHAR*)pdn + pdn->wDeviceOffset;
1519 else if(pdm)
1520 name = pdm->dmDeviceName;
1521 PRINTDLG_SetUpPrinterListComboW(hDlg, comboID, name);
1522 if(pdm) GlobalUnlock(lppd->hDevMode);
1523 if(pdn) GlobalUnlock(lppd->hDevNames);
1524
1525 /* Now find selected printer and update rest of dlg */
1526 /* ansi is ok here */
1527 name = HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR));
1528 if (GetDlgItemTextW(hDlg, comboID, name, 255))
1529 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1530 HeapFree(GetProcessHeap(),0,name);
1531 } else {
1532 /* else use default printer */
1533 WCHAR name[200];
1534 BOOL ret = PRINTDLG_GetDefaultPrinterNameW(name, sizeof(name));
1535
1536 if (ret)
1537 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1538 else
1539 FIXME("No default printer found, expect problems!\n");
1540 }
1541 return TRUE;
1542}
1543
1544#ifndef __WIN32OS2__
1545/***********************************************************************
1546 * PRINTDLG_WMInitDialog [internal]
1547 */
1548static LRESULT PRINTDLG_WMInitDialog16(HWND hDlg, WPARAM wParam,
1549 PRINT_PTRA* PrintStructures)
1550{
1551 LPPRINTDLG16 lppd = PrintStructures->dlg.lpPrintDlg16;
1552 DEVNAMES *pdn;
1553 DEVMODEA *pdm;
1554 char *name = NULL;
1555 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1556
1557 /* load Collate ICONs */
1558 PrintStructures->hCollateIcon =
1559 LoadIconA(COMDLG32_hInstance, "PD32_COLLATE");
1560 PrintStructures->hNoCollateIcon =
1561 LoadIconA(COMDLG32_hInstance, "PD32_NOCOLLATE");
1562 if(PrintStructures->hCollateIcon == 0 ||
1563 PrintStructures->hNoCollateIcon == 0) {
1564 ERR("no icon in resourcefile\n");
1565 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1566 EndDialog(hDlg, FALSE);
1567 }
1568
1569 /* load Paper Orientation ICON */
1570 /* FIXME: not implemented yet */
1571
1572 /*
1573 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1574 * must be registered and the Help button must be shown.
1575 */
1576 if (lppd->Flags & PD_SHOWHELP) {
1577 if((PrintStructures->HelpMessageID =
1578 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
1579 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1580 return FALSE;
1581 }
1582 } else
1583 PrintStructures->HelpMessageID = 0;
1584
1585 if (!(lppd->Flags & PD_PRINTSETUP)) {
1586 /* We have a print quality combo box. What shall we do? */
1587 if (GetDlgItem(hDlg,cmb1)) {
1588 char buf [20];
1589
1590 FIXME("Print quality only displaying currently.\n");
1591
1592 pdm = GlobalLock16(lppd->hDevMode);
1593 if(pdm) {
1594 switch (pdm->dmPrintQuality) {
1595 case DMRES_HIGH : strcpy(buf,"High");break;
1596 case DMRES_MEDIUM : strcpy(buf,"Medium");break;
1597 case DMRES_LOW : strcpy(buf,"Low");break;
1598 case DMRES_DRAFT : strcpy(buf,"Draft");break;
1599 case 0 : strcpy(buf,"Default");break;
1600 default : sprintf(buf,"%ddpi",pdm->dmPrintQuality);break;
1601 }
1602 GlobalUnlock16(lppd->hDevMode);
1603 } else
1604 strcpy(buf,"Default");
1605 SendDlgItemMessageA(hDlg,cmb1,CB_ADDSTRING,0,(LPARAM)buf);
1606 SendDlgItemMessageA(hDlg,cmb1,CB_SETCURSEL,0,0);
1607 EnableWindow(GetDlgItem(hDlg,cmb1),FALSE);
1608 }
1609 }
1610
1611 /* FIXME: I allow more freedom than either Win95 or WinNT,
1612 * which do not agree to what errors should be thrown or not
1613 * in case nToPage or nFromPage is out-of-range.
1614 */
1615 if (lppd->nMaxPage < lppd->nMinPage)
1616 lppd->nMaxPage = lppd->nMinPage;
1617 if (lppd->nMinPage == lppd->nMaxPage)
1618 lppd->Flags |= PD_NOPAGENUMS;
1619 if (lppd->nToPage < lppd->nMinPage)
1620 lppd->nToPage = lppd->nMinPage;
1621 if (lppd->nToPage > lppd->nMaxPage)
1622 lppd->nToPage = lppd->nMaxPage;
1623 if (lppd->nFromPage < lppd->nMinPage)
1624 lppd->nFromPage = lppd->nMinPage;
1625 if (lppd->nFromPage > lppd->nMaxPage)
1626 lppd->nFromPage = lppd->nMaxPage;
1627
1628 /* If the printer combo box is in the dialog, fill it */
1629 if (GetDlgItem(hDlg,comboID)) {
1630 /* Fill Combobox
1631 */
1632 pdn = GlobalLock16(lppd->hDevNames);
1633 pdm = GlobalLock16(lppd->hDevMode);
1634 if(pdn)
1635 name = (char*)pdn + pdn->wDeviceOffset;
1636 else if(pdm)
1637 name = pdm->dmDeviceName;
1638 PRINTDLG_SetUpPrinterListComboA(hDlg, comboID, name);
1639 if(pdm) GlobalUnlock16(lppd->hDevMode);
1640 if(pdn) GlobalUnlock16(lppd->hDevNames);
1641
1642 /* Now find selected printer and update rest of dlg */
1643 name = HeapAlloc(GetProcessHeap(),0,256);
1644 if (GetDlgItemTextA(hDlg, comboID, name, 255))
1645 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1646 } else {
1647 /* else just use default printer */
1648 char name[200];
1649 BOOL ret = PRINTDLG_GetDefaultPrinterNameA(name, sizeof(name));
1650
1651 if (ret)
1652 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1653 else
1654 FIXME("No default printer found, expect problems!\n");
1655 }
1656 HeapFree(GetProcessHeap(),0,name);
1657
1658 return TRUE;
1659}
1660#endif
1661/***********************************************************************
1662 * PRINTDLG_WMCommand [internal]
1663 */
1664static LRESULT PRINTDLG_WMCommandA(HWND hDlg, WPARAM wParam,
1665 LPARAM lParam, PRINT_PTRA* PrintStructures)
1666{
1667 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
1668 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1669 LPDEVMODEA lpdm = PrintStructures->lpDevMode;
1670
1671 switch (LOWORD(wParam)) {
1672 case IDOK:
1673 TRACE(" OK button was hit\n");
1674 if (PRINTDLG_UpdatePrintDlgA(hDlg, PrintStructures)!=TRUE) {
1675 FIXME("Update printdlg was not successful!\n");
1676 return(FALSE);
1677 }
1678 EndDialog(hDlg, TRUE);
1679 return(TRUE);
1680
1681 case IDCANCEL:
1682 TRACE(" CANCEL button was hit\n");
1683 EndDialog(hDlg, FALSE);
1684 return(FALSE);
1685
1686 case pshHelp:
1687 TRACE(" HELP button was hit\n");
1688 SendMessageA(lppd->hwndOwner, PrintStructures->HelpMessageID,
1689 (WPARAM) hDlg, (LPARAM) lppd);
1690 break;
1691
1692 case chx2: /* collate pages checkbox */
1693 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1694 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1695 (LPARAM)PrintStructures->hCollateIcon);
1696 else
1697 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1698 (LPARAM)PrintStructures->hNoCollateIcon);
1699 break;
1700 case edt1: /* from page nr editbox */
1701 case edt2: /* to page nr editbox */
1702 if (HIWORD(wParam)==EN_CHANGE) {
1703 WORD nToPage;
1704 WORD nFromPage;
1705 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1706 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1707 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1708 CheckRadioButton(hDlg, rad1, rad3, rad3);
1709 }
1710 break;
1711
1712 case edt3:
1713 if(HIWORD(wParam) == EN_CHANGE) {
1714 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1715 if(copies <= 1)
1716 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1717 else
1718 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1719 }
1720 break;
1721
1722#ifndef __WIN32OS2__
1723 case psh1: /* Print Setup */
1724 {
1725 PRINTDLG16 pdlg;
1726
1727 if (!PrintStructures->dlg.lpPrintDlg16) {
1728 FIXME("The 32bit print dialog does not have this button!?\n");
1729 break;
1730 }
1731
1732 memcpy(&pdlg,PrintStructures->dlg.lpPrintDlg16,sizeof(pdlg));
1733 pdlg.Flags |= PD_PRINTSETUP;
1734 pdlg.hwndOwner = HWND_16(hDlg);
1735 if (!PrintDlg16(&pdlg))
1736 break;
1737 }
1738 break;
1739#endif
1740
1741 case psh2: /* Properties button */
1742 {
1743 HANDLE hPrinter;
1744 char PrinterName[256];
1745
1746 GetDlgItemTextA(hDlg, PrinterComboID, PrinterName, 255);
1747 if (!OpenPrinterA(PrinterName, &hPrinter, NULL)) {
1748 FIXME(" Call to OpenPrinter did not succeed!\n");
1749 break;
1750 }
1751 DocumentPropertiesA(hDlg, hPrinter, PrinterName,
1752 PrintStructures->lpDevMode,
1753 PrintStructures->lpDevMode,
1754 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1755 ClosePrinter(hPrinter);
1756 break;
1757 }
1758
1759 case rad1: /* Paperorientation */
1760 if (lppd->Flags & PD_PRINTSETUP)
1761 {
1762 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1763 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1764 (LPARAM)(PrintStructures->hPortraitIcon));
1765 }
1766 break;
1767
1768 case rad2: /* Paperorientation */
1769 if (lppd->Flags & PD_PRINTSETUP)
1770 {
1771 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1772 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1773 (LPARAM)(PrintStructures->hLandscapeIcon));
1774 }
1775 break;
1776
1777 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1778 if (PrinterComboID != wParam) {
1779 FIXME("No handling for print quality combo box yet.\n");
1780 break;
1781 }
1782 /* FALLTHROUGH */
1783 case cmb4: /* Printer combobox */
1784 if (HIWORD(wParam)==CBN_SELCHANGE) {
1785 char PrinterName[256];
1786 GetDlgItemTextA(hDlg, LOWORD(wParam), PrinterName, 255);
1787 PRINTDLG_ChangePrinterA(hDlg, PrinterName, PrintStructures);
1788 }
1789 break;
1790
1791 case cmb2: /* Papersize */
1792 {
1793 DWORD Sel = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1794 if(Sel != CB_ERR)
1795 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
1796 CB_GETITEMDATA,
1797 Sel, 0);
1798 }
1799 break;
1800
1801 case cmb3: /* Bin */
1802 {
1803 DWORD Sel = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1804 if(Sel != CB_ERR)
1805 lpdm->dmDefaultSource = SendDlgItemMessageA(hDlg, cmb3,
1806 CB_GETITEMDATA, Sel,
1807 0);
1808 }
1809 break;
1810 }
1811 if(lppd->Flags & PD_PRINTSETUP) {
1812 switch (LOWORD(wParam)) {
1813 case rad1: /* orientation */
1814 case rad2:
1815 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1816 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1817 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1818 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1819 (WPARAM)IMAGE_ICON,
1820 (LPARAM)PrintStructures->hPortraitIcon);
1821 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1822 (WPARAM)IMAGE_ICON,
1823 (LPARAM)PrintStructures->hPortraitIcon);
1824 }
1825 } else {
1826 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1827 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1828 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1829 (WPARAM)IMAGE_ICON,
1830 (LPARAM)PrintStructures->hLandscapeIcon);
1831 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1832 (WPARAM)IMAGE_ICON,
1833 (LPARAM)PrintStructures->hLandscapeIcon);
1834 }
1835 }
1836 break;
1837 }
1838 }
1839 return FALSE;
1840}
1841
1842static LRESULT PRINTDLG_WMCommandW(HWND hDlg, WPARAM wParam,
1843 LPARAM lParam, PRINT_PTRW* PrintStructures)
1844{
1845 LPPRINTDLGW lppd = PrintStructures->dlg.lpPrintDlg;
1846 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1847 LPDEVMODEW lpdm = PrintStructures->lpDevMode;
1848
1849 switch (LOWORD(wParam)) {
1850 case IDOK:
1851 TRACE(" OK button was hit\n");
1852 if (PRINTDLG_UpdatePrintDlgW(hDlg, PrintStructures)!=TRUE) {
1853 FIXME("Update printdlg was not successful!\n");
1854 return(FALSE);
1855 }
1856 EndDialog(hDlg, TRUE);
1857 return(TRUE);
1858
1859 case IDCANCEL:
1860 TRACE(" CANCEL button was hit\n");
1861 EndDialog(hDlg, FALSE);
1862 return(FALSE);
1863
1864 case pshHelp:
1865 TRACE(" HELP button was hit\n");
1866 SendMessageW(lppd->hwndOwner, PrintStructures->HelpMessageID,
1867 (WPARAM) hDlg, (LPARAM) lppd);
1868 break;
1869
1870 case chx2: /* collate pages checkbox */
1871 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1872 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1873 (LPARAM)PrintStructures->hCollateIcon);
1874 else
1875 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1876 (LPARAM)PrintStructures->hNoCollateIcon);
1877 break;
1878 case edt1: /* from page nr editbox */
1879 case edt2: /* to page nr editbox */
1880 if (HIWORD(wParam)==EN_CHANGE) {
1881 WORD nToPage;
1882 WORD nFromPage;
1883 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1884 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1885 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1886 CheckRadioButton(hDlg, rad1, rad3, rad3);
1887 }
1888 break;
1889
1890 case edt3:
1891 if(HIWORD(wParam) == EN_CHANGE) {
1892 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1893 if(copies <= 1)
1894 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1895 else
1896 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1897 }
1898 break;
1899
1900 case psh1: /* Print Setup */
1901 {
1902 ERR("psh1 is called from 16bit code only, we should not get here.\n");
1903 }
1904 break;
1905 case psh2: /* Properties button */
1906 {
1907 HANDLE hPrinter;
1908 WCHAR PrinterName[256];
1909
1910 GetDlgItemTextW(hDlg, PrinterComboID, PrinterName, 255);
1911 if (!OpenPrinterW(PrinterName, &hPrinter, NULL)) {
1912 FIXME(" Call to OpenPrinter did not succeed!\n");
1913 break;
1914 }
1915 DocumentPropertiesW(hDlg, hPrinter, PrinterName,
1916 PrintStructures->lpDevMode,
1917 PrintStructures->lpDevMode,
1918 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1919 ClosePrinter(hPrinter);
1920 break;
1921 }
1922
1923 case rad1: /* Paperorientation */
1924 if (lppd->Flags & PD_PRINTSETUP)
1925 {
1926 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1927 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1928 (LPARAM)(PrintStructures->hPortraitIcon));
1929 }
1930 break;
1931
1932 case rad2: /* Paperorientation */
1933 if (lppd->Flags & PD_PRINTSETUP)
1934 {
1935 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1936 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1937 (LPARAM)(PrintStructures->hLandscapeIcon));
1938 }
1939 break;
1940
1941 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1942 if (PrinterComboID != wParam) {
1943 FIXME("No handling for print quality combo box yet.\n");
1944 break;
1945 }
1946 /* FALLTHROUGH */
1947 case cmb4: /* Printer combobox */
1948 if (HIWORD(wParam)==CBN_SELCHANGE) {
1949 WCHAR PrinterName[256];
1950 GetDlgItemTextW(hDlg, LOWORD(wParam), PrinterName, 255);
1951 PRINTDLG_ChangePrinterW(hDlg, PrinterName, PrintStructures);
1952 }
1953 break;
1954
1955 case cmb2: /* Papersize */
1956 {
1957 DWORD Sel = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1958 if(Sel != CB_ERR)
1959 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
1960 CB_GETITEMDATA,
1961 Sel, 0);
1962 }
1963 break;
1964
1965 case cmb3: /* Bin */
1966 {
1967 DWORD Sel = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1968 if(Sel != CB_ERR)
1969 lpdm->dmDefaultSource = SendDlgItemMessageW(hDlg, cmb3,
1970 CB_GETITEMDATA, Sel,
1971 0);
1972 }
1973 break;
1974 }
1975 if(lppd->Flags & PD_PRINTSETUP) {
1976 switch (LOWORD(wParam)) {
1977 case rad1: /* orientation */
1978 case rad2:
1979 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1980 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1981 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1982 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1983 (WPARAM)IMAGE_ICON,
1984 (LPARAM)PrintStructures->hPortraitIcon);
1985 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1986 (WPARAM)IMAGE_ICON,
1987 (LPARAM)PrintStructures->hPortraitIcon);
1988 }
1989 } else {
1990 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1991 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1992 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1993 (WPARAM)IMAGE_ICON,
1994 (LPARAM)PrintStructures->hLandscapeIcon);
1995 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1996 (WPARAM)IMAGE_ICON,
1997 (LPARAM)PrintStructures->hLandscapeIcon);
1998 }
1999 }
2000 break;
2001 }
2002 }
2003 return FALSE;
2004}
2005
2006/***********************************************************************
2007 * PrintDlgProcA [internal]
2008 */
2009BOOL WINAPI PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
2010 LPARAM lParam)
2011{
2012 PRINT_PTRA* PrintStructures;
2013 LRESULT res=FALSE;
2014
2015 if (uMsg!=WM_INITDIALOG) {
2016 PrintStructures = (PRINT_PTRA*)GetPropA(hDlg,"__WINE_PRINTDLGDATA");
2017 if (!PrintStructures)
2018 return FALSE;
2019 } else {
2020 PrintStructures = (PRINT_PTRA*) lParam;
2021 SetPropA(hDlg,"__WINE_PRINTDLGDATA",lParam);
2022 res = PRINTDLG_WMInitDialog(hDlg, wParam, PrintStructures);
2023
2024 if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
2025 res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(
2026 hDlg, uMsg, wParam, (LPARAM)PrintStructures->dlg.lpPrintDlg
2027 );
2028 return res;
2029 }
2030
2031 if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
2032 res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam,
2033 lParam);
2034 if(res) return res;
2035 }
2036
2037 switch (uMsg) {
2038 case WM_COMMAND:
2039 return PRINTDLG_WMCommandA(hDlg, wParam, lParam, PrintStructures);
2040
2041 case WM_DESTROY:
2042 DestroyIcon(PrintStructures->hCollateIcon);
2043 DestroyIcon(PrintStructures->hNoCollateIcon);
2044 DestroyIcon(PrintStructures->hPortraitIcon);
2045 DestroyIcon(PrintStructures->hLandscapeIcon);
2046 if(PrintStructures->hwndUpDown)
2047 DestroyWindow(PrintStructures->hwndUpDown);
2048 return FALSE;
2049 }
2050 return res;
2051}
2052
2053BOOL WINAPI PrintDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
2054 LPARAM lParam)
2055{
2056 PRINT_PTRW* PrintStructures;
2057 LRESULT res=FALSE;
2058
2059 if (uMsg!=WM_INITDIALOG) {
2060 PrintStructures = (PRINT_PTRW*) GetWindowLongA(hDlg, DWL_USER);
2061 if (!PrintStructures)
2062 return FALSE;
2063 } else {
2064 PrintStructures = (PRINT_PTRW*) lParam;
2065 SetWindowLongA(hDlg, DWL_USER, lParam);
2066 res = PRINTDLG_WMInitDialogW(hDlg, wParam, PrintStructures);
2067
2068 if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
2069 res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(
2070 hDlg, uMsg, wParam, (LPARAM)PrintStructures->dlg.lpPrintDlg
2071 );
2072 return res;
2073 }
2074
2075 if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
2076 res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam,
2077 lParam);
2078 if(res) return res;
2079 }
2080
2081 switch (uMsg) {
2082 case WM_COMMAND:
2083 return PRINTDLG_WMCommandW(hDlg, wParam, lParam, PrintStructures);
2084
2085 case WM_DESTROY:
2086 DestroyIcon(PrintStructures->hCollateIcon);
2087 DestroyIcon(PrintStructures->hNoCollateIcon);
2088 DestroyIcon(PrintStructures->hPortraitIcon);
2089 DestroyIcon(PrintStructures->hLandscapeIcon);
2090 if(PrintStructures->hwndUpDown)
2091 DestroyWindow(PrintStructures->hwndUpDown);
2092 return FALSE;
2093 }
2094 return res;
2095}
2096
2097
2098#ifndef __WIN32OS2__
2099/************************************************************
2100 *
2101 * PRINTDLG_Get16TemplateFrom32 [Internal]
2102 * Generates a 16 bits template from the Wine 32 bits resource
2103 *
2104 */
2105static HGLOBAL16 PRINTDLG_Get16TemplateFrom32(char *PrintResourceName)
2106{
2107 HRSRC hResInfo;
2108 HGLOBAL hDlgTmpl32;
2109 LPCVOID template32;
2110 DWORD size;
2111 HGLOBAL16 hGlobal16;
2112 LPVOID template;
2113
2114 if (!(hResInfo = FindResourceA(COMMDLG_hInstance32,
2115 PrintResourceName, RT_DIALOGA)))
2116 {
2117 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
2118 return 0;
2119 }
2120 if (!(hDlgTmpl32 = LoadResource(COMMDLG_hInstance32, hResInfo )) ||
2121 !(template32 = LockResource( hDlgTmpl32 )))
2122 {
2123 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2124 return 0;
2125 }
2126 size = SizeofResource(COMMDLG_hInstance32, hResInfo);
2127 hGlobal16 = GlobalAlloc16(0, size);
2128 if (!hGlobal16)
2129 {
2130 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
2131 ERR("alloc failure for %ld bytes\n", size);
2132 return 0;
2133 }
2134 template = GlobalLock16(hGlobal16);
2135 if (!template)
2136 {
2137 COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE);
2138 ERR("global lock failure for %x handle\n", hGlobal16);
2139 GlobalFree16(hGlobal16);
2140 return 0;
2141 }
2142 ConvertDialog32To16((LPVOID)template32, size, (LPVOID)template);
2143 GlobalUnlock16(hGlobal16);
2144 return hGlobal16;
2145}
2146#endif
2147
2148/************************************************************
2149 *
2150 * PRINTDLG_GetDlgTemplate
2151 *
2152 */
2153static HGLOBAL PRINTDLG_GetDlgTemplateA(PRINTDLGA *lppd)
2154{
2155 HRSRC hResInfo;
2156 HGLOBAL hDlgTmpl;
2157
2158 if (lppd->Flags & PD_PRINTSETUP) {
2159 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
2160 hDlgTmpl = lppd->hSetupTemplate;
2161 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
2162 hResInfo = FindResourceA(lppd->hInstance,
2163 lppd->lpSetupTemplateName, RT_DIALOGA);
2164 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2165 } else {
2166 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32_SETUP",
2167 RT_DIALOGA);
2168 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
2169 }
2170 } else {
2171 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
2172 hDlgTmpl = lppd->hPrintTemplate;
2173 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
2174 hResInfo = FindResourceA(lppd->hInstance,
2175 lppd->lpPrintTemplateName,
2176 RT_DIALOGA);
2177 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2178 } else {
2179 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32",
2180 RT_DIALOGA);
2181 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
2182 }
2183 }
2184 return hDlgTmpl;
2185}
2186
2187static HGLOBAL PRINTDLG_GetDlgTemplateW(PRINTDLGW *lppd)
2188{
2189 HRSRC hResInfo;
2190 HGLOBAL hDlgTmpl;
2191 const WCHAR xpsetup[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
2192 const WCHAR xprint[] = { 'P','R','I','N','T','3','2',0};
2193
2194 if (lppd->Flags & PD_PRINTSETUP) {
2195 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
2196 hDlgTmpl = lppd->hSetupTemplate;
2197 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
2198 hResInfo = FindResourceW(lppd->hInstance,
2199 lppd->lpSetupTemplateName, RT_DIALOGW);
2200 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2201 } else {
2202 hResInfo = FindResourceW(COMDLG32_hInstance, xpsetup, RT_DIALOGW);
2203 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
2204 }
2205 } else {
2206 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
2207 hDlgTmpl = lppd->hPrintTemplate;
2208 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
2209 hResInfo = FindResourceW(lppd->hInstance,
2210 lppd->lpPrintTemplateName,
2211 RT_DIALOGW);
2212 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2213 } else {
2214 hResInfo = FindResourceW(COMDLG32_hInstance, xprint, RT_DIALOGW);
2215 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
2216 }
2217 }
2218 return hDlgTmpl;
2219}
2220
2221
2222#ifndef __WIN32OS2__
2223/************************************************************
2224 *
2225 * PRINTDLG_GetDlgTemplate
2226 *
2227 */
2228static HGLOBAL16 PRINTDLG_GetDlgTemplate16(PRINTDLG16 *lppd)
2229{
2230 HGLOBAL16 hDlgTmpl, hResInfo;
2231
2232 if (lppd->Flags & PD_PRINTSETUP) {
2233 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
2234 hDlgTmpl = lppd->hSetupTemplate;
2235 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
2236 hResInfo = FindResource16(lppd->hInstance,
2237 MapSL(lppd->lpSetupTemplateName), RT_DIALOGA);
2238 hDlgTmpl = LoadResource16(lppd->hInstance, hResInfo);
2239 } else {
2240 hDlgTmpl = PRINTDLG_Get16TemplateFrom32("PRINT32_SETUP");
2241 }
2242 } else {
2243 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
2244 hDlgTmpl = lppd->hPrintTemplate;
2245 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
2246 hResInfo = FindResource16(lppd->hInstance,
2247 MapSL(lppd->lpPrintTemplateName),
2248 RT_DIALOGA);
2249 hDlgTmpl = LoadResource16(lppd->hInstance, hResInfo);
2250 } else {
2251 hDlgTmpl = PRINTDLG_Get16TemplateFrom32("PRINT32");
2252 }
2253 }
2254 return hDlgTmpl;
2255}
2256#endif
2257
2258/***********************************************************************
2259 *
2260 * PRINTDLG_CreateDC
2261 *
2262 */
2263static BOOL PRINTDLG_CreateDCA(LPPRINTDLGA lppd)
2264{
2265 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
2266 DEVMODEA *pdm = GlobalLock(lppd->hDevMode);
2267
2268 if(lppd->Flags & PD_RETURNDC) {
2269 lppd->hDC = CreateDCA((char*)pdn + pdn->wDriverOffset,
2270 (char*)pdn + pdn->wDeviceOffset,
2271 (char*)pdn + pdn->wOutputOffset,
2272 pdm );
2273 } else if(lppd->Flags & PD_RETURNIC) {
2274 lppd->hDC = CreateICA((char*)pdn + pdn->wDriverOffset,
2275 (char*)pdn + pdn->wDeviceOffset,
2276 (char*)pdn + pdn->wOutputOffset,
2277 pdm );
2278 }
2279 GlobalUnlock(lppd->hDevNames);
2280 GlobalUnlock(lppd->hDevMode);
2281 return lppd->hDC ? TRUE : FALSE;
2282}
2283
2284static BOOL PRINTDLG_CreateDCW(LPPRINTDLGW lppd)
2285{
2286 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
2287 DEVMODEW *pdm = GlobalLock(lppd->hDevMode);
2288
2289 if(lppd->Flags & PD_RETURNDC) {
2290 lppd->hDC = CreateDCW((WCHAR*)pdn + pdn->wDriverOffset,
2291 (WCHAR*)pdn + pdn->wDeviceOffset,
2292 (WCHAR*)pdn + pdn->wOutputOffset,
2293 pdm );
2294 } else if(lppd->Flags & PD_RETURNIC) {
2295 lppd->hDC = CreateICW((WCHAR*)pdn + pdn->wDriverOffset,
2296 (WCHAR*)pdn + pdn->wDeviceOffset,
2297 (WCHAR*)pdn + pdn->wOutputOffset,
2298 pdm );
2299 }
2300 GlobalUnlock(lppd->hDevNames);
2301 GlobalUnlock(lppd->hDevMode);
2302 return lppd->hDC ? TRUE : FALSE;
2303}
2304
2305#ifndef __WIN32OS2__
2306static BOOL PRINTDLG_CreateDC16(LPPRINTDLG16 lppd)
2307{
2308 DEVNAMES *pdn = GlobalLock16(lppd->hDevNames);
2309 DEVMODEA *pdm = GlobalLock16(lppd->hDevMode);
2310
2311 if(lppd->Flags & PD_RETURNDC) {
2312 lppd->hDC = CreateDCA((char*)pdn + pdn->wDriverOffset,
2313 (char*)pdn + pdn->wDeviceOffset,
2314 (char*)pdn + pdn->wOutputOffset,
2315 pdm );
2316 } else if(lppd->Flags & PD_RETURNIC) {
2317 lppd->hDC = CreateICA((char*)pdn + pdn->wDriverOffset,
2318 (char*)pdn + pdn->wDeviceOffset,
2319 (char*)pdn + pdn->wOutputOffset,
2320 pdm );
2321 }
2322 GlobalUnlock16(lppd->hDevNames);
2323 GlobalUnlock16(lppd->hDevMode);
2324 return lppd->hDC ? TRUE : FALSE;
2325}
2326#endif
2327
2328/***********************************************************************
2329 * PrintDlgA (COMDLG32.@)
2330 *
2331 * Displays the the PRINT dialog box, which enables the user to specify
2332 * specific properties of the print job.
2333 *
2334 * RETURNS
2335 * nonzero if the user pressed the OK button
2336 * zero if the user cancelled the window or an error occurred
2337 *
2338 * BUGS
2339 * PrintDlg:
2340 * * The Collate Icons do not display, even though they are in the code.
2341 * * The Properties Button(s) should call DocumentPropertiesA().
2342 * PrintSetupDlg:
2343 * * The Paper Orientation Icons are not implemented yet.
2344 * * The Properties Button(s) should call DocumentPropertiesA().
2345 * * Settings are not yet taken from a provided DevMode or
2346 * default printer settings.
2347 */
2348
2349BOOL WINAPI PrintDlgA(
2350 LPPRINTDLGA lppd /* [in/out] ptr to PRINTDLG32 struct */
2351 )
2352{
2353 BOOL bRet = FALSE;
2354 LPVOID ptr;
2355 HINSTANCE hInst = GetWindowLongA( lppd->hwndOwner, GWL_HINSTANCE );
2356
2357 if(TRACE_ON(commdlg)) {
2358 char flagstr[1000] = "";
2359 struct pd_flags *pflag = pd_flags;
2360 for( ; pflag->name; pflag++) {
2361 if(lppd->Flags & pflag->flag)
2362 strcat(flagstr, pflag->name);
2363 }
2364 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
2365 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %08x\n"
2366 "flags %08lx (%s)\n",
2367 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2368 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2369 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2370 }
2371
2372 if(lppd->lStructSize != sizeof(PRINTDLGA)) {
2373 WARN("structure size failure !!!\n");
2374 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2375 return FALSE;
2376 }
2377
2378 if(lppd->Flags & PD_RETURNDEFAULT) {
2379 PRINTER_INFO_2A *pbuf;
2380 DRIVER_INFO_3A *dbuf;
2381 HANDLE hprn;
2382 DWORD needed;
2383
2384 if(lppd->hDevMode || lppd->hDevNames) {
2385 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2386 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2387 return FALSE;
2388 }
2389 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2390 WARN("Can't find default printer\n");
2391 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2392 return FALSE;
2393 }
2394
2395 GetPrinterA(hprn, 2, NULL, 0, &needed);
2396 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
2397 GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2398
2399 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
2400 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
2401 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2402 ERR("GetPrinterDriverA failed, le %ld, fix your config for printer %s!\n",GetLastError(),pbuf->pPrinterName);
2403 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2404 return FALSE;
2405 }
2406 ClosePrinter(hprn);
2407
2408 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2409 dbuf->pDriverPath,
2410 pbuf->pPrinterName,
2411 pbuf->pPortName);
2412 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2413 pbuf->pDevMode->dmDriverExtra);
2414 ptr = GlobalLock(lppd->hDevMode);
2415 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2416 pbuf->pDevMode->dmDriverExtra);
2417 GlobalUnlock(lppd->hDevMode);
2418 HeapFree(GetProcessHeap(), 0, pbuf);
2419 HeapFree(GetProcessHeap(), 0, dbuf);
2420 bRet = TRUE;
2421 } else {
2422 HGLOBAL hDlgTmpl;
2423 PRINT_PTRA *PrintStructures;
2424
2425 /* load Dialog resources,
2426 * depending on Flags indicates Print32 or Print32_setup dialog
2427 */
2428 hDlgTmpl = PRINTDLG_GetDlgTemplateA(lppd);
2429 if (!hDlgTmpl) {
2430 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2431 return FALSE;
2432 }
2433 ptr = LockResource( hDlgTmpl );
2434 if (!ptr) {
2435 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2436 return FALSE;
2437 }
2438
2439 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2440 sizeof(PRINT_PTRA));
2441 PrintStructures->dlg.lpPrintDlg = lppd;
2442
2443 /* and create & process the dialog .
2444 * -1 is failure, 0 is broken hwnd, everything else is ok.
2445 */
2446 bRet = (0<DialogBoxIndirectParamA(hInst, ptr, lppd->hwndOwner,
2447 PrintDlgProcA,
2448 (LPARAM)PrintStructures));
2449
2450 if(bRet) {
2451 DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2452 PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
2453 DRIVER_INFO_3A *di = PrintStructures->lpDriverInfo;
2454
2455 if (lppd->hDevMode == 0) {
2456 TRACE(" No hDevMode yet... Need to create my own\n");
2457 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2458 lpdm->dmSize + lpdm->dmDriverExtra);
2459 } else {
2460 WORD locks;
2461 if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
2462 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2463 while(locks--) {
2464 GlobalUnlock(lppd->hDevMode);
2465 TRACE("Now got %d locks\n", locks);
2466 }
2467 }
2468 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2469 lpdm->dmSize + lpdm->dmDriverExtra,
2470 GMEM_MOVEABLE);
2471 }
2472 lpdmReturn = GlobalLock(lppd->hDevMode);
2473 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2474
2475 if (lppd->hDevNames != 0) {
2476 WORD locks;
2477 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
2478 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2479 while(locks--)
2480 GlobalUnlock(lppd->hDevNames);
2481 }
2482 }
2483 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2484 di->pDriverPath,
2485 pi->pPrinterName,
2486 pi->pPortName
2487 );
2488 GlobalUnlock(lppd->hDevMode);
2489 }
2490 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2491 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2492 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2493 HeapFree(GetProcessHeap(), 0, PrintStructures);
2494 }
2495 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2496 bRet = PRINTDLG_CreateDCA(lppd);
2497
2498 TRACE("exit! (%d)\n", bRet);
2499 return bRet;
2500}
2501
2502/***********************************************************************
2503 * PrintDlgW (COMDLG32.@)
2504 */
2505BOOL WINAPI PrintDlgW(
2506 LPPRINTDLGW lppd /* [in/out] ptr to PRINTDLG32 struct */
2507 )
2508{
2509 BOOL bRet = FALSE;
2510 LPVOID ptr;
2511 HINSTANCE hInst = GetWindowLongA( lppd->hwndOwner, GWL_HINSTANCE );
2512
2513 if(TRACE_ON(commdlg)) {
2514 char flagstr[1000] = "";
2515 struct pd_flags *pflag = pd_flags;
2516 for( ; pflag->name; pflag++) {
2517 if(lppd->Flags & pflag->flag)
2518 strcat(flagstr, pflag->name);
2519 }
2520 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
2521 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %08x\n"
2522 "flags %08lx (%s)\n",
2523 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2524 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2525 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2526 }
2527
2528 if(lppd->lStructSize != sizeof(PRINTDLGW)) {
2529 WARN("structure size failure !!!\n");
2530 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2531 return FALSE;
2532 }
2533
2534 if(lppd->Flags & PD_RETURNDEFAULT) {
2535 PRINTER_INFO_2W *pbuf;
2536 DRIVER_INFO_3W *dbuf;
2537 HANDLE hprn;
2538 DWORD needed;
2539
2540 if(lppd->hDevMode || lppd->hDevNames) {
2541 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2542 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2543 return FALSE;
2544 }
2545 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2546 WARN("Can't find default printer\n");
2547 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2548 return FALSE;
2549 }
2550
2551 GetPrinterW(hprn, 2, NULL, 0, &needed);
2552 pbuf = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*needed);
2553 GetPrinterW(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2554
2555 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
2556 dbuf = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
2557 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2558 ERR("GetPrinterDriverA failed, le %ld, fix your config for printer %s!\n",GetLastError(),debugstr_w(pbuf->pPrinterName));
2559 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2560 return FALSE;
2561 }
2562 ClosePrinter(hprn);
2563
2564 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2565 dbuf->pDriverPath,
2566 pbuf->pPrinterName,
2567 pbuf->pPortName);
2568 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2569 pbuf->pDevMode->dmDriverExtra);
2570 ptr = GlobalLock(lppd->hDevMode);
2571 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2572 pbuf->pDevMode->dmDriverExtra);
2573 GlobalUnlock(lppd->hDevMode);
2574 HeapFree(GetProcessHeap(), 0, pbuf);
2575 HeapFree(GetProcessHeap(), 0, dbuf);
2576 bRet = TRUE;
2577 } else {
2578 HGLOBAL hDlgTmpl;
2579 PRINT_PTRW *PrintStructures;
2580
2581 /* load Dialog resources,
2582 * depending on Flags indicates Print32 or Print32_setup dialog
2583 */
2584 hDlgTmpl = PRINTDLG_GetDlgTemplateW(lppd);
2585 if (!hDlgTmpl) {
2586 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2587 return FALSE;
2588 }
2589 ptr = LockResource( hDlgTmpl );
2590 if (!ptr) {
2591 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2592 return FALSE;
2593 }
2594
2595 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2596 sizeof(PRINT_PTRW));
2597 PrintStructures->dlg.lpPrintDlg = lppd;
2598
2599 /* and create & process the dialog .
2600 * -1 is failure, 0 is broken hwnd, everything else is ok.
2601 */
2602 bRet = (0<DialogBoxIndirectParamW(hInst, ptr, lppd->hwndOwner,
2603 PrintDlgProcW,
2604 (LPARAM)PrintStructures));
2605
2606 if(bRet) {
2607 DEVMODEW *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2608 PRINTER_INFO_2W *pi = PrintStructures->lpPrinterInfo;
2609 DRIVER_INFO_3W *di = PrintStructures->lpDriverInfo;
2610
2611 if (lppd->hDevMode == 0) {
2612 TRACE(" No hDevMode yet... Need to create my own\n");
2613 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2614 lpdm->dmSize + lpdm->dmDriverExtra);
2615 } else {
2616 WORD locks;
2617 if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
2618 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2619 while(locks--) {
2620 GlobalUnlock(lppd->hDevMode);
2621 TRACE("Now got %d locks\n", locks);
2622 }
2623 }
2624 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2625 lpdm->dmSize + lpdm->dmDriverExtra,
2626 GMEM_MOVEABLE);
2627 }
2628 lpdmReturn = GlobalLock(lppd->hDevMode);
2629 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2630
2631 if (lppd->hDevNames != 0) {
2632 WORD locks;
2633 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
2634 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2635 while(locks--)
2636 GlobalUnlock(lppd->hDevNames);
2637 }
2638 }
2639 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2640 di->pDriverPath,
2641 pi->pPrinterName,
2642 pi->pPortName
2643 );
2644 GlobalUnlock(lppd->hDevMode);
2645 }
2646 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2647 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2648 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2649 HeapFree(GetProcessHeap(), 0, PrintStructures);
2650 }
2651 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2652 bRet = PRINTDLG_CreateDCW(lppd);
2653
2654 TRACE("exit! (%d)\n", bRet);
2655 return bRet;
2656}
2657
2658#ifndef __WIN32OS2__
2659/***********************************************************************
2660 * PrintDlg (COMMDLG.20)
2661 *
2662 * Displays the the PRINT dialog box, which enables the user to specify
2663 * specific properties of the print job.
2664 *
2665 * RETURNS
2666 * nonzero if the user pressed the OK button
2667 * zero if the user cancelled the window or an error occurred
2668 *
2669 * BUGS
2670 * * calls up to the 32-bit versions of the Dialogs, which look different
2671 * * Customizing is *not* implemented.
2672 */
2673
2674BOOL16 WINAPI PrintDlg16(
2675 LPPRINTDLG16 lppd /* [in/out] ptr to PRINTDLG struct */
2676) {
2677 BOOL bRet = FALSE;
2678 LPVOID ptr;
2679 HINSTANCE hInst = GetWindowLongA( HWND_32(lppd->hwndOwner), GWL_HINSTANCE );
2680
2681 if(TRACE_ON(commdlg)) {
2682 char flagstr[1000] = "";
2683 struct pd_flags *pflag = pd_flags;
2684 for( ; pflag->name; pflag++) {
2685 if(lppd->Flags & pflag->flag)
2686 strcat(flagstr, pflag->name);
2687 }
2688 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
2689 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %08x\n"
2690 "flags %08lx (%s)\n",
2691 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2692 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2693 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2694 }
2695
2696 if(lppd->lStructSize != sizeof(PRINTDLG16)) {
2697 ERR("structure size (%ld/%d)\n",lppd->lStructSize,sizeof(PRINTDLG16));
2698 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2699 return FALSE;
2700 }
2701
2702 if(lppd->Flags & PD_RETURNDEFAULT) {
2703 PRINTER_INFO_2A *pbuf;
2704 DRIVER_INFO_3A *dbuf;
2705 HANDLE hprn;
2706 DWORD needed;
2707
2708 if(lppd->hDevMode || lppd->hDevNames) {
2709 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2710 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2711 return FALSE;
2712 }
2713 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2714 WARN("Can't find default printer\n");
2715 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2716 return FALSE;
2717 }
2718
2719 GetPrinterA(hprn, 2, NULL, 0, &needed);
2720 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
2721 GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2722 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
2723 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
2724 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2725 ERR("GetPrinterDriverA failed for %s, le %ld, fix your config!\n",
2726 pbuf->pPrinterName,GetLastError());
2727 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2728 return FALSE;
2729 }
2730 ClosePrinter(hprn);
2731 PRINTDLG_CreateDevNames16(&(lppd->hDevNames),
2732 dbuf->pDriverPath,
2733 pbuf->pPrinterName,
2734 pbuf->pPortName);
2735 lppd->hDevMode = GlobalAlloc16(GMEM_MOVEABLE,pbuf->pDevMode->dmSize+
2736 pbuf->pDevMode->dmDriverExtra);
2737 ptr = GlobalLock16(lppd->hDevMode);
2738 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2739 pbuf->pDevMode->dmDriverExtra);
2740 GlobalUnlock16(lppd->hDevMode);
2741 HeapFree(GetProcessHeap(), 0, pbuf);
2742 HeapFree(GetProcessHeap(), 0, dbuf);
2743 bRet = TRUE;
2744 } else {
2745 HGLOBAL hDlgTmpl;
2746 PRINT_PTRA *PrintStructures;
2747
2748 /* load Dialog resources,
2749 * depending on Flags indicates Print32 or Print32_setup dialog
2750 */
2751 hDlgTmpl = PRINTDLG_GetDlgTemplate16(lppd);
2752 if (!hDlgTmpl) {
2753 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2754 return FALSE;
2755 }
2756 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2757 sizeof(PRINT_PTRA));
2758 PrintStructures->dlg.lpPrintDlg16 = lppd;
2759 PrintStructures->dlg.lpPrintDlg = (LPPRINTDLGA)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(PRINTDLGA));
2760#define CVAL(x) PrintStructures->dlg.lpPrintDlg->x = lppd->x;
2761#define MVAL(x) PrintStructures->dlg.lpPrintDlg->x = MapSL(lppd->x);
2762 CVAL(Flags);
2763 PrintStructures->dlg.lpPrintDlg->hwndOwner = HWND_32(lppd->hwndOwner);
2764 CVAL(hDC);
2765 CVAL(nFromPage);CVAL(nToPage);CVAL(nMinPage);CVAL(nMaxPage);
2766 CVAL(nCopies);CVAL(hInstance);CVAL(lCustData);
2767 MVAL(lpPrintTemplateName);MVAL(lpSetupTemplateName);
2768 /* Don't copy rest, it is 16 bit specific */
2769#undef MVAL
2770#undef CVAL
2771
2772 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(),0,sizeof(DEVMODEA));
2773
2774 /* and create & process the dialog .
2775 * -1 is failure, 0 is broken hwnd, everything else is ok.
2776 */
2777 bRet = (0<DialogBoxIndirectParam16(
2778 hInst, hDlgTmpl, lppd->hwndOwner,
2779 (DLGPROC16)GetProcAddress16(GetModuleHandle16("COMMDLG"),(LPCSTR)21),
2780 (LPARAM)PrintStructures
2781 )
2782 );
2783 if (!PrintStructures->lpPrinterInfo) bRet = FALSE;
2784 if(bRet) {
2785 DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2786 PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
2787 DRIVER_INFO_3A *di = PrintStructures->lpDriverInfo;
2788
2789 if (lppd->hDevMode == 0) {
2790 TRACE(" No hDevMode yet... Need to create my own\n");
2791 lppd->hDevMode = GlobalAlloc16(GMEM_MOVEABLE,
2792 lpdm->dmSize + lpdm->dmDriverExtra);
2793 } else {
2794 WORD locks;
2795 if((locks = (GlobalFlags16(lppd->hDevMode)&GMEM_LOCKCOUNT))) {
2796 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2797 while(locks--) {
2798 GlobalUnlock16(lppd->hDevMode);
2799 TRACE("Now got %d locks\n", locks);
2800 }
2801 }
2802 lppd->hDevMode = GlobalReAlloc16(lppd->hDevMode,
2803 lpdm->dmSize + lpdm->dmDriverExtra,
2804 GMEM_MOVEABLE);
2805 }
2806 lpdmReturn = GlobalLock16(lppd->hDevMode);
2807 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2808
2809 if (lppd->hDevNames != 0) {
2810 WORD locks;
2811 if((locks = (GlobalFlags16(lppd->hDevNames)&GMEM_LOCKCOUNT))) {
2812 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2813 while(locks--)
2814 GlobalUnlock16(lppd->hDevNames);
2815 }
2816 }
2817 PRINTDLG_CreateDevNames16(&(lppd->hDevNames),
2818 di->pDriverPath,
2819 pi->pPrinterName,
2820 pi->pPortName
2821 );
2822 GlobalUnlock16(lppd->hDevMode);
2823 }
2824 if (!(lppd->Flags & (PD_ENABLESETUPTEMPLATEHANDLE | PD_ENABLESETUPTEMPLATE)))
2825 GlobalFree16(hDlgTmpl); /* created from the 32 bits resource */
2826 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2827 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2828 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2829 HeapFree(GetProcessHeap(), 0, PrintStructures);
2830 }
2831 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2832 bRet = PRINTDLG_CreateDC16(lppd);
2833
2834 TRACE("exit! (%d)\n", bRet);
2835 return bRet;
2836}
2837#endif
2838
2839/***********************************************************************
2840 *
2841 * PageSetupDlg
2842 * rad1 - portrait
2843 * rad2 - landscape
2844 * cmb2 - paper size
2845 * cmb3 - source (tray?)
2846 * edt4 - border left
2847 * edt5 - border top
2848 * edt6 - border right
2849 * edt7 - border bottom
2850 * psh3 - "Printer..."
2851 */
2852
2853typedef struct {
2854 LPPAGESETUPDLGA dlga;
2855 PRINTDLGA pdlg;
2856} PageSetupDataA;
2857
2858typedef struct {
2859 LPPAGESETUPDLGW dlga;
2860 PRINTDLGW pdlg;
2861} PageSetupDataW;
2862
2863static HGLOBAL PRINTDLG_GetPGSTemplateA(PAGESETUPDLGA *lppd)
2864{
2865 HRSRC hResInfo;
2866 HGLOBAL hDlgTmpl;
2867
2868 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2869 hDlgTmpl = lppd->hPageSetupTemplate;
2870 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2871 hResInfo = FindResourceA(lppd->hInstance,
2872 lppd->lpPageSetupTemplateName, RT_DIALOGA);
2873 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2874 } else {
2875 hResInfo = FindResourceA(COMDLG32_hInstance,(LPCSTR)PAGESETUPDLGORD,RT_DIALOGA);
2876 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2877 }
2878 return hDlgTmpl;
2879}
2880
2881static HGLOBAL PRINTDLG_GetPGSTemplateW(PAGESETUPDLGW *lppd)
2882{
2883 HRSRC hResInfo;
2884 HGLOBAL hDlgTmpl;
2885
2886 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2887 hDlgTmpl = lppd->hPageSetupTemplate;
2888 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2889 hResInfo = FindResourceW(lppd->hInstance,
2890 lppd->lpPageSetupTemplateName, RT_DIALOGW);
2891 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2892 } else {
2893 hResInfo = FindResourceW(COMDLG32_hInstance,(LPCWSTR)PAGESETUPDLGORD,RT_DIALOGW);
2894 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2895 }
2896 return hDlgTmpl;
2897}
2898
2899static DWORD
2900_c_10mm2size(PAGESETUPDLGA *dlga,DWORD size) {
2901 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2902 return 10*size*10/25.4;
2903 /* If we don't have a flag, we can choose one. Use millimeters
2904 * to avoid confusing me
2905 */
2906 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2907 return 10*size;
2908}
2909
2910
2911static DWORD
2912_c_inch2size(PAGESETUPDLGA *dlga,DWORD size) {
2913 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2914 return size;
2915 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
2916 return (size*254)/10;
2917 /* if we don't have a flag, we can choose one. Use millimeters
2918 * to avoid confusing me
2919 */
2920 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2921 return (size*254)/10;
2922}
2923
2924static void
2925_c_size2strA(PageSetupDataA *pda,DWORD size,LPSTR strout) {
2926 strcpy(strout,"<undef>");
2927 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2928 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
2929 return;
2930 }
2931 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2932 sprintf(strout,"%.2fin",(size*1.0)/1000.0);
2933 return;
2934 }
2935 pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2936 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
2937 return;
2938}
2939static void
2940_c_size2strW(PageSetupDataW *pda,DWORD size,LPSTR strout) {
2941 strcpy(strout,"<undef>");
2942 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2943 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
2944 return;
2945 }
2946 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2947 sprintf(strout,"%.2fin",(size*1.0)/1000.0);
2948 return;
2949 }
2950 pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2951 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
2952 return;
2953}
2954
2955static DWORD
2956_c_str2size(PAGESETUPDLGA *dlga,LPCSTR strin) {
2957 float val;
2958 char rest[200];
2959
2960 rest[0]='\0';
2961 if (!sscanf(strin,"%f%s",&val,rest))
2962 return 0;
2963
2964 if (!strcmp(rest,"in") || !strcmp(rest,"inch")) {
2965 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2966 return 1000*val;
2967 else
2968 return val*25.4*100;
2969 }
2970 if (!strcmp(rest,"cm")) { rest[0]='m'; val = val*10.0; }
2971 if (!strcmp(rest,"m")) { strcpy(rest,"mm"); val = val*1000.0; }
2972
2973 if (!strcmp(rest,"mm")) {
2974 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
2975 return 100*val;
2976 else
2977 return 1000.0*val/25.4;
2978 }
2979 if (rest[0]=='\0') {
2980 /* use application supplied default */
2981 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2982 /* 100*mm */
2983 return 100.0*val;
2984 }
2985 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2986 /* 1000*inch */
2987 return 1000.0*val;
2988 }
2989 }
2990 ERR("Did not find a conversion for type '%s'!\n",rest);
2991 return 0;
2992}
2993
2994
2995/*
2996 * This is called on finish and will update the output fields of the
2997 * struct.
2998 */
2999static BOOL
3000PRINTDLG_PS_UpdateDlgStructA(HWND hDlg, PageSetupDataA *pda) {
3001 DEVNAMES *dn;
3002 DEVMODEA *dm;
3003 LPSTR devname,portname;
3004 char papername[64];
3005 char buf[200];
3006
3007 dn = GlobalLock(pda->pdlg.hDevNames);
3008 dm = GlobalLock(pda->pdlg.hDevMode);
3009 devname = ((char*)dn)+dn->wDeviceOffset;
3010 portname = ((char*)dn)+dn->wOutputOffset;
3011 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb2,devname,portname,dm);
3012 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb3,devname,portname,dm);
3013
3014 if (GetDlgItemTextA(hDlg,cmb2,papername,sizeof(papername))>0) {
3015 PRINTDLG_PaperSizeA(&(pda->pdlg),papername,&(pda->dlga->ptPaperSize));
3016 pda->dlga->ptPaperSize.x = _c_10mm2size(pda->dlga,pda->dlga->ptPaperSize.x);
3017 pda->dlga->ptPaperSize.y = _c_10mm2size(pda->dlga,pda->dlga->ptPaperSize.y);
3018 } else
3019 FIXME("could not get dialog text for papersize cmbbox?\n");
3020#define GETVAL(id,val) if (GetDlgItemTextA(hDlg,id,buf,sizeof(buf))>0) { val = _c_str2size(pda->dlga,buf); } else { FIXME("could not get dlgitemtexta for %x\n",id); }
3021 GETVAL(edt4,pda->dlga->rtMargin.left);
3022 GETVAL(edt5,pda->dlga->rtMargin.top);
3023 GETVAL(edt6,pda->dlga->rtMargin.right);
3024 GETVAL(edt7,pda->dlga->rtMargin.bottom);
3025#undef GETVAL
3026
3027 /* If we are in landscape, swap x and y of page size */
3028 if (IsDlgButtonChecked(hDlg, rad2)) {
3029 DWORD tmp;
3030 tmp = pda->dlga->ptPaperSize.x;
3031 pda->dlga->ptPaperSize.x = pda->dlga->ptPaperSize.y;
3032 pda->dlga->ptPaperSize.y = tmp;
3033 }
3034 GlobalUnlock(pda->pdlg.hDevNames);
3035 GlobalUnlock(pda->pdlg.hDevMode);
3036 return TRUE;
3037}
3038
3039static BOOL
3040PRINTDLG_PS_UpdateDlgStructW(HWND hDlg, PageSetupDataW *pda) {
3041 DEVNAMES *dn;
3042 DEVMODEW *dm;
3043 LPWSTR devname,portname;
3044 WCHAR papername[64];
3045
3046 char buf[200];
3047
3048 dn = GlobalLock(pda->pdlg.hDevNames);
3049 dm = GlobalLock(pda->pdlg.hDevMode);
3050 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
3051 portname = ((WCHAR*)dn)+dn->wOutputOffset;
3052 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
3053 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
3054
3055 if (GetDlgItemTextW(hDlg,cmb2,papername,sizeof(papername))>0) {
3056 PRINTDLG_PaperSizeW(&(pda->pdlg),papername,&(pda->dlga->ptPaperSize));
3057 pda->dlga->ptPaperSize.x = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga,pda->dlga->ptPaperSize.x);
3058 pda->dlga->ptPaperSize.y = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga,pda->dlga->ptPaperSize.y);
3059 } else
3060 FIXME("could not get dialog text for papersize cmbbox?\n");
3061#define GETVAL(id,val) if (GetDlgItemTextA(hDlg,id,buf,sizeof(buf))>0) { val = _c_str2size((LPPAGESETUPDLGA)pda->dlga,buf); } else { FIXME("could not get dlgitemtexta for %x\n",id); }
3062 GETVAL(edt4,pda->dlga->rtMargin.left);
3063 GETVAL(edt5,pda->dlga->rtMargin.top);
3064 GETVAL(edt6,pda->dlga->rtMargin.right);
3065 GETVAL(edt7,pda->dlga->rtMargin.bottom);
3066#undef GETVAL
3067
3068 /* If we are in landscape, swap x and y of page size */
3069 if (IsDlgButtonChecked(hDlg, rad2)) {
3070 DWORD tmp;
3071 tmp = pda->dlga->ptPaperSize.x;
3072 pda->dlga->ptPaperSize.x = pda->dlga->ptPaperSize.y;
3073 pda->dlga->ptPaperSize.y = tmp;
3074 }
3075 GlobalUnlock(pda->pdlg.hDevNames);
3076 GlobalUnlock(pda->pdlg.hDevMode);
3077 return TRUE;
3078}
3079
3080/*
3081 * This is called after returning from PrintDlg().
3082 */
3083static BOOL
3084PRINTDLG_PS_ChangePrinterA(HWND hDlg, PageSetupDataA *pda) {
3085 DEVNAMES *dn;
3086 DEVMODEA *dm;
3087 LPSTR devname,portname;
3088
3089 dn = GlobalLock(pda->pdlg.hDevNames);
3090 dm = GlobalLock(pda->pdlg.hDevMode);
3091 devname = ((char*)dn)+dn->wDeviceOffset;
3092 portname = ((char*)dn)+dn->wOutputOffset;
3093 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb2,devname,portname,dm);
3094 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb3,devname,portname,dm);
3095 GlobalUnlock(pda->pdlg.hDevNames);
3096 GlobalUnlock(pda->pdlg.hDevMode);
3097 return TRUE;
3098}
3099
3100static BOOL
3101PRINTDLG_PS_ChangePrinterW(HWND hDlg, PageSetupDataW *pda) {
3102 DEVNAMES *dn;
3103 DEVMODEW *dm;
3104 LPWSTR devname,portname;
3105
3106 dn = GlobalLock(pda->pdlg.hDevNames);
3107 dm = GlobalLock(pda->pdlg.hDevMode);
3108 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
3109 portname = ((WCHAR*)dn)+dn->wOutputOffset;
3110 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
3111 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
3112 GlobalUnlock(pda->pdlg.hDevNames);
3113 GlobalUnlock(pda->pdlg.hDevMode);
3114 return TRUE;
3115}
3116
3117static BOOL
3118PRINTDLG_PS_WMCommandA(
3119 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataA *pda
3120) {
3121 switch (LOWORD(wParam)) {
3122 case IDOK:
3123 if (!PRINTDLG_PS_UpdateDlgStructA(hDlg, pda))
3124 return(FALSE);
3125 EndDialog(hDlg, TRUE);
3126 return TRUE ;
3127
3128 case IDCANCEL:
3129 EndDialog(hDlg, FALSE);
3130 return FALSE ;
3131
3132 case psh3: {
3133 pda->pdlg.Flags = 0;
3134 pda->pdlg.hwndOwner = hDlg;
3135 if (PrintDlgA(&(pda->pdlg)))
3136 PRINTDLG_PS_ChangePrinterA(hDlg,pda);
3137 return TRUE;
3138 }
3139 }
3140 FIXME("loword (lparam) %d, wparam 0x%x, lparam %08lx, STUB mostly.\n",
3141 LOWORD(lParam),wParam,lParam
3142 );
3143 return FALSE;
3144}
3145
3146static BOOL
3147PRINTDLG_PS_WMCommandW(
3148 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataW *pda
3149) {
3150 switch (LOWORD(wParam)) {
3151 case IDOK:
3152 if (!PRINTDLG_PS_UpdateDlgStructW(hDlg, pda))
3153 return(FALSE);
3154 EndDialog(hDlg, TRUE);
3155 return TRUE ;
3156
3157 case IDCANCEL:
3158 EndDialog(hDlg, FALSE);
3159 return FALSE ;
3160
3161 case psh3: {
3162 pda->pdlg.Flags = 0;
3163 pda->pdlg.hwndOwner = hDlg;
3164 if (PrintDlgW(&(pda->pdlg)))
3165 PRINTDLG_PS_ChangePrinterW(hDlg,pda);
3166 return TRUE;
3167 }
3168 }
3169 FIXME("loword (lparam) %d, wparam 0x%x, lparam %08lx, STUB mostly.\n",
3170 LOWORD(lParam),wParam,lParam
3171 );
3172 return FALSE;
3173}
3174
3175
3176static BOOL WINAPI
3177PageDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
3178{
3179 PageSetupDataA *pda;
3180 BOOL res = FALSE;
3181
3182 if (uMsg==WM_INITDIALOG) {
3183 res = TRUE;
3184 pda = (PageSetupDataA*)lParam;
3185 SetPropA(hDlg,"__WINE_PAGESETUPDLGDATA",lParam);
3186 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3187 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3188 if (!res) {
3189 FIXME("Setup page hook failed?\n");
3190 res = TRUE;
3191 }
3192 }
3193 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK) {
3194 FIXME("PagePaintHook not yet implemented!\n");
3195 }
3196 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
3197 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
3198 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
3199 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
3200 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
3201 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
3202 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
3203 }
3204 /* width larger as height -> landscape */
3205 if (pda->dlga->ptPaperSize.x > pda->dlga->ptPaperSize.y)
3206 CheckRadioButton(hDlg, rad1, rad2, rad2);
3207 else /* this is default if papersize is not set */
3208 CheckRadioButton(hDlg, rad1, rad2, rad1);
3209 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
3210 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
3211 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
3212 }
3213 /* We fill them out enabled or not */
3214 if (pda->dlga->Flags & PSD_MARGINS) {
3215 char str[100];
3216 _c_size2strA(pda,pda->dlga->rtMargin.left,str);
3217 SetDlgItemTextA(hDlg,edt4,str);
3218 _c_size2strA(pda,pda->dlga->rtMargin.top,str);
3219 SetDlgItemTextA(hDlg,edt5,str);
3220 _c_size2strA(pda,pda->dlga->rtMargin.right,str);
3221 SetDlgItemTextA(hDlg,edt6,str);
3222 _c_size2strA(pda,pda->dlga->rtMargin.bottom,str);
3223 SetDlgItemTextA(hDlg,edt7,str);
3224 } else {
3225 /* default is 1 inch */
3226 DWORD size = _c_inch2size(pda->dlga,1000);
3227 char str[20];
3228 _c_size2strA(pda,size,str);
3229 SetDlgItemTextA(hDlg,edt4,str);
3230 SetDlgItemTextA(hDlg,edt5,str);
3231 SetDlgItemTextA(hDlg,edt6,str);
3232 SetDlgItemTextA(hDlg,edt7,str);
3233 }
3234 PRINTDLG_PS_ChangePrinterA(hDlg,pda);
3235 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
3236 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
3237 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
3238 }
3239 return TRUE;
3240 } else {
3241 pda = (PageSetupDataA*)GetPropA(hDlg,"__WINE_PAGESETUPDLGDATA");
3242 if (!pda) {
3243 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3244 return FALSE;
3245 }
3246 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3247 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3248 if (res) return res;
3249 }
3250 }
3251 switch (uMsg) {
3252 case WM_COMMAND:
3253 return PRINTDLG_PS_WMCommandA(hDlg, wParam, lParam, pda);
3254 }
3255 return FALSE;
3256}
3257
3258static BOOL WINAPI
3259PageDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
3260{
3261 PageSetupDataW *pda;
3262 BOOL res = FALSE;
3263
3264 if (uMsg==WM_INITDIALOG) {
3265 res = TRUE;
3266 pda = (PageSetupDataW*)lParam;
3267 SetPropA(hDlg,"__WINE_PAGESETUPDLGDATA",lParam);
3268 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3269 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3270 if (!res) {
3271 FIXME("Setup page hook failed?\n");
3272 res = TRUE;
3273 }
3274 }
3275 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK) {
3276 FIXME("PagePaintHook not yet implemented!\n");
3277 }
3278 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
3279 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
3280 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
3281 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
3282 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
3283 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
3284 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
3285 }
3286 /* width larger as height -> landscape */
3287 if (pda->dlga->ptPaperSize.x > pda->dlga->ptPaperSize.y)
3288 CheckRadioButton(hDlg, rad1, rad2, rad2);
3289 else /* this is default if papersize is not set */
3290 CheckRadioButton(hDlg, rad1, rad2, rad1);
3291 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
3292 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
3293 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
3294 }
3295 /* We fill them out enabled or not */
3296 if (pda->dlga->Flags & PSD_MARGINS) {
3297 char str[100];
3298 _c_size2strW(pda,pda->dlga->rtMargin.left,str);
3299 SetDlgItemTextA(hDlg,edt4,str);
3300 _c_size2strW(pda,pda->dlga->rtMargin.top,str);
3301 SetDlgItemTextA(hDlg,edt5,str);
3302 _c_size2strW(pda,pda->dlga->rtMargin.right,str);
3303 SetDlgItemTextA(hDlg,edt6,str);
3304 _c_size2strW(pda,pda->dlga->rtMargin.bottom,str);
3305 SetDlgItemTextA(hDlg,edt7,str);
3306 } else {
3307 /* default is 1 inch */
3308 DWORD size = _c_inch2size((LPPAGESETUPDLGA)pda->dlga,1000);
3309 char str[20];
3310 _c_size2strW(pda,size,str);
3311 SetDlgItemTextA(hDlg,edt4,str);
3312 SetDlgItemTextA(hDlg,edt5,str);
3313 SetDlgItemTextA(hDlg,edt6,str);
3314 SetDlgItemTextA(hDlg,edt7,str);
3315 }
3316 PRINTDLG_PS_ChangePrinterW(hDlg,pda);
3317 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
3318 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
3319 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
3320 }
3321 return TRUE;
3322 } else {
3323 pda = (PageSetupDataW*)GetPropA(hDlg,"__WINE_PAGESETUPDLGDATA");
3324 if (!pda) {
3325 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3326 return FALSE;
3327 }
3328 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3329 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3330 if (res) return res;
3331 }
3332 }
3333 switch (uMsg) {
3334 case WM_COMMAND:
3335 return PRINTDLG_PS_WMCommandW(hDlg, wParam, lParam, pda);
3336 }
3337 return FALSE;
3338}
3339
3340/***********************************************************************
3341 * PageSetupDlgA (COMDLG32.@)
3342 */
3343BOOL WINAPI PageSetupDlgA(LPPAGESETUPDLGA setupdlg) {
3344 HGLOBAL hDlgTmpl;
3345 LPVOID ptr;
3346 BOOL bRet;
3347 PageSetupDataA *pda;
3348 PRINTDLGA pdlg;
3349
3350 if(TRACE_ON(commdlg)) {
3351 char flagstr[1000] = "";
3352 struct pd_flags *pflag = psd_flags;
3353 for( ; pflag->name; pflag++) {
3354 if(setupdlg->Flags & pflag->flag) {
3355 strcat(flagstr, pflag->name);
3356 strcat(flagstr, "|");
3357 }
3358 }
3359 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
3360 "hinst %08x, flags %08lx (%s)\n",
3361 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
3362 setupdlg->hDevNames,
3363 setupdlg->hInstance, setupdlg->Flags, flagstr);
3364 }
3365
3366 /* First get default printer data, we need it right after that. */
3367 memset(&pdlg,0,sizeof(pdlg));
3368 pdlg.lStructSize = sizeof(pdlg);
3369 pdlg.Flags = PD_RETURNDEFAULT;
3370 bRet = PrintDlgA(&pdlg);
3371 if (!bRet) return FALSE;
3372
3373 /* short cut exit, just return default values */
3374 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
3375 setupdlg->hDevMode = pdlg.hDevMode;
3376 setupdlg->hDevNames = pdlg.hDevNames;
3377 /* FIXME: Just return "A4" for now. */
3378 PRINTDLG_PaperSizeA(&pdlg,"A4",&setupdlg->ptPaperSize);
3379 setupdlg->ptPaperSize.x=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.x);
3380 setupdlg->ptPaperSize.y=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.y);
3381 return TRUE;
3382 }
3383 hDlgTmpl = PRINTDLG_GetPGSTemplateA(setupdlg);
3384 if (!hDlgTmpl) {
3385 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3386 return FALSE;
3387 }
3388 ptr = LockResource( hDlgTmpl );
3389 if (!ptr) {
3390 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3391 return FALSE;
3392 }
3393 pda = HeapAlloc(GetProcessHeap(),0,sizeof(*pda));
3394 pda->dlga = setupdlg;
3395 memcpy(&pda->pdlg,&pdlg,sizeof(pdlg));
3396
3397 bRet = (0<DialogBoxIndirectParamA(
3398 setupdlg->hInstance,
3399 ptr,
3400 setupdlg->hwndOwner,
3401 PageDlgProcA,
3402 (LPARAM)pda)
3403 );
3404 return bRet;
3405}
3406/***********************************************************************
3407 * PageSetupDlgW (COMDLG32.@)
3408 */
3409BOOL WINAPI PageSetupDlgW(LPPAGESETUPDLGW setupdlg) {
3410 HGLOBAL hDlgTmpl;
3411 LPVOID ptr;
3412 BOOL bRet;
3413 PageSetupDataW *pdw;
3414 PRINTDLGW pdlg;
3415
3416 if(TRACE_ON(commdlg)) {
3417 char flagstr[1000] = "";
3418 struct pd_flags *pflag = psd_flags;
3419 for( ; pflag->name; pflag++) {
3420 if(setupdlg->Flags & pflag->flag) {
3421 strcat(flagstr, pflag->name);
3422 strcat(flagstr, "|");
3423 }
3424 }
3425 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
3426 "hinst %08x, flags %08lx (%s)\n",
3427 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
3428 setupdlg->hDevNames,
3429 setupdlg->hInstance, setupdlg->Flags, flagstr);
3430 }
3431
3432 /* First get default printer data, we need it right after that. */
3433 memset(&pdlg,0,sizeof(pdlg));
3434 pdlg.lStructSize = sizeof(pdlg);
3435 pdlg.Flags = PD_RETURNDEFAULT;
3436 bRet = PrintDlgW(&pdlg);
3437 if (!bRet) return FALSE;
3438
3439 /* short cut exit, just return default values */
3440 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
3441 const WCHAR a4[] = {'A','4',0};
3442 setupdlg->hDevMode = pdlg.hDevMode;
3443 setupdlg->hDevNames = pdlg.hDevNames;
3444 /* FIXME: Just return "A4" for now. */
3445 PRINTDLG_PaperSizeW(&pdlg,a4,&setupdlg->ptPaperSize);
3446 setupdlg->ptPaperSize.x=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.x);
3447 setupdlg->ptPaperSize.y=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.y);
3448 return TRUE;
3449 }
3450 hDlgTmpl = PRINTDLG_GetPGSTemplateW(setupdlg);
3451 if (!hDlgTmpl) {
3452 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3453 return FALSE;
3454 }
3455 ptr = LockResource( hDlgTmpl );
3456 if (!ptr) {
3457 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3458 return FALSE;
3459 }
3460 pdw = HeapAlloc(GetProcessHeap(),0,sizeof(*pdw));
3461 pdw->dlga = setupdlg;
3462 memcpy(&pdw->pdlg,&pdlg,sizeof(pdlg));
3463
3464 bRet = (0<DialogBoxIndirectParamW(
3465 setupdlg->hInstance,
3466 ptr,
3467 setupdlg->hwndOwner,
3468 PageDlgProcW,
3469 (LPARAM)pdw)
3470 );
3471 return bRet;
3472}
3473
3474#ifndef __WIN32OS2__
3475/**********************************************************************
3476 *
3477 * 16 bit commdlg
3478 */
3479
3480/***********************************************************************
3481 * PrintDlgProc (COMMDLG.21)
3482 */
3483LRESULT WINAPI PrintDlgProc16(HWND16 hDlg16, UINT16 uMsg, WPARAM16 wParam,
3484 LPARAM lParam)
3485{
3486 HWND hDlg = HWND_32(hDlg16);
3487 PRINT_PTRA* PrintStructures;
3488 LRESULT res=FALSE;
3489
3490 if (uMsg!=WM_INITDIALOG) {
3491 PrintStructures = (PRINT_PTRA*)GetPropA(hDlg,"__WINE_PRINTDLGDATA");
3492 if (!PrintStructures)
3493 return FALSE;
3494 } else {
3495 PrintStructures = (PRINT_PTRA*) lParam;
3496 SetPropA(hDlg,"__WINE_PRINTDLGDATA",lParam);
3497 res = PRINTDLG_WMInitDialog16(hDlg, wParam, PrintStructures);
3498
3499 if(PrintStructures->dlg.lpPrintDlg16->Flags & PD_ENABLEPRINTHOOK) {
3500 res = CallWindowProc16(
3501 (WNDPROC16)PrintStructures->dlg.lpPrintDlg16->lpfnPrintHook,
3502 hDlg16, uMsg, wParam, (LPARAM)PrintStructures->dlg.lpPrintDlg16
3503 );
3504 }
3505 return res;
3506 }
3507
3508 if(PrintStructures->dlg.lpPrintDlg16->Flags & PD_ENABLEPRINTHOOK) {
3509 res = CallWindowProc16(
3510 (WNDPROC16)PrintStructures->dlg.lpPrintDlg16->lpfnPrintHook,
3511 hDlg16,uMsg, wParam, lParam
3512 );
3513 if(LOWORD(res)) return res;
3514 }
3515
3516 switch (uMsg) {
3517 case WM_COMMAND: {
3518 /* We need to map those for the 32bit window procedure, compare
3519 * with 32Ato16 mapper in winproc.c
3520 */
3521 return PRINTDLG_WMCommandA(
3522 hDlg,
3523 MAKEWPARAM(wParam,HIWORD(lParam)),
3524 LOWORD(lParam),
3525 PrintStructures
3526 );
3527 }
3528 case WM_DESTROY:
3529 DestroyIcon(PrintStructures->hCollateIcon);
3530 DestroyIcon(PrintStructures->hNoCollateIcon);
3531 /* FIXME: don't forget to delete the paper orientation icons here! */
3532
3533 return FALSE;
3534 }
3535 return res;
3536}
3537
3538
3539/***********************************************************************
3540 * PrintSetupDlgProc (COMMDLG.22)
3541 */
3542LRESULT WINAPI PrintSetupDlgProc16(HWND16 hWnd16, UINT16 wMsg, WPARAM16 wParam,
3543 LPARAM lParam)
3544{
3545 HWND hWnd = HWND_32(hWnd16);
3546 switch (wMsg)
3547 {
3548 case WM_INITDIALOG:
3549 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
3550 ShowWindow(hWnd, SW_SHOWNORMAL);
3551 return (TRUE);
3552 case WM_COMMAND:
3553 switch (wParam) {
3554 case IDOK:
3555 EndDialog(hWnd, TRUE);
3556 return(TRUE);
3557 case IDCANCEL:
3558 EndDialog(hWnd, FALSE);
3559 return(TRUE);
3560 }
3561 return(FALSE);
3562 }
3563 return FALSE;
3564}
3565#endif
3566
3567/***********************************************************************
3568 * PrintDlgExA (COMDLG32.@)
3569 */
3570HRESULT WINAPI PrintDlgExA(LPVOID lpPrintDlgExA) /* [???] FIXME: LPPRINTDLGEXA */
3571{
3572 FIXME("stub\n");
3573 return E_NOTIMPL;
3574}
3575/***********************************************************************
3576 * PrintDlgExW (COMDLG32.@)
3577 */
3578HRESULT WINAPI PrintDlgExW(LPVOID lpPrintDlgExW) /* [???] FIXME: LPPRINTDLGEXW */
3579{
3580 FIXME("stub\n");
3581 return E_NOTIMPL;
3582}
Note: See TracBrowser for help on using the repository browser.