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

Last change on this file since 10367 was 10267, checked in by sandervl, 22 years ago

Printer dialog fixes

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