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

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

AH: Added string check to PRINTDLG_SetUpPrinterListComboA

File size: 115.7 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
1781 case chx2: /* collate pages checkbox */
1782 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1783 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1784 (LPARAM)PrintStructures->hCollateIcon);
1785 else
1786 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1787 (LPARAM)PrintStructures->hNoCollateIcon);
1788 break;
1789 case edt1: /* from page nr editbox */
1790 case edt2: /* to page nr editbox */
1791 if (HIWORD(wParam)==EN_CHANGE) {
1792 WORD nToPage;
1793 WORD nFromPage;
1794 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1795 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1796 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1797 CheckRadioButton(hDlg, rad1, rad3, rad3);
1798 }
1799 break;
1800
1801 case edt3:
1802 if(HIWORD(wParam) == EN_CHANGE) {
1803 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1804 if(copies <= 1)
1805 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1806 else
1807 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1808 }
1809 break;
1810
1811#ifndef __WIN32OS2__
1812 case psh1: /* Print Setup */
1813 {
1814 PRINTDLG16 pdlg;
1815
1816 if (!PrintStructures->dlg.lpPrintDlg16) {
1817 FIXME("The 32bit print dialog does not have this button!?\n");
1818 break;
1819 }
1820
1821 memcpy(&pdlg,PrintStructures->dlg.lpPrintDlg16,sizeof(pdlg));
1822 pdlg.Flags |= PD_PRINTSETUP;
1823 pdlg.hwndOwner = HWND_16(hDlg);
1824 if (!PrintDlg16(&pdlg))
1825 break;
1826 }
1827 break;
1828#endif
1829
1830 case psh2: /* Properties button */
1831 {
1832 HANDLE hPrinter;
1833 char PrinterName[256];
1834
1835 GetDlgItemTextA(hDlg, PrinterComboID, PrinterName, 255);
1836#ifdef __WIN32OS2__
1837 PrnNameToQueue(PrinterName, PrinterName);
1838#endif
1839 if (!OpenPrinterA(PrinterName, &hPrinter, NULL)) {
1840 FIXME(" Call to OpenPrinter did not succeed!\n");
1841 break;
1842 }
1843 DocumentPropertiesA(hDlg, hPrinter, PrinterName,
1844 PrintStructures->lpDevMode,
1845 PrintStructures->lpDevMode,
1846 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1847 ClosePrinter(hPrinter);
1848 break;
1849 }
1850
1851 case rad1: /* Paperorientation */
1852 if (lppd->Flags & PD_PRINTSETUP)
1853 {
1854 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1855 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1856 (LPARAM)(PrintStructures->hPortraitIcon));
1857 }
1858 break;
1859
1860 case rad2: /* Paperorientation */
1861 if (lppd->Flags & PD_PRINTSETUP)
1862 {
1863 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1864 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1865 (LPARAM)(PrintStructures->hLandscapeIcon));
1866 }
1867 break;
1868
1869 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1870 if (PrinterComboID != wParam) {
1871 FIXME("No handling for print quality combo box yet.\n");
1872 break;
1873 }
1874 /* FALLTHROUGH */
1875 case cmb4: /* Printer combobox */
1876 if (HIWORD(wParam)==CBN_SELCHANGE) {
1877 char PrinterName[256];
1878 GetDlgItemTextA(hDlg, LOWORD(wParam), PrinterName, 255);
1879#ifdef __WIN32OS2__
1880 PrnNameToQueue(PrinterName, PrinterName);
1881#endif
1882 PRINTDLG_ChangePrinterA(hDlg, PrinterName, PrintStructures);
1883 }
1884 break;
1885
1886 case cmb2: /* Papersize */
1887 {
1888 DWORD Sel = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1889 if(Sel != CB_ERR)
1890 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
1891 CB_GETITEMDATA,
1892 Sel, 0);
1893 }
1894 break;
1895
1896 case cmb3: /* Bin */
1897 {
1898 DWORD Sel = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1899 if(Sel != CB_ERR)
1900 lpdm->dmDefaultSource = SendDlgItemMessageA(hDlg, cmb3,
1901 CB_GETITEMDATA, Sel,
1902 0);
1903 }
1904 break;
1905 }
1906 if(lppd->Flags & PD_PRINTSETUP) {
1907 switch (LOWORD(wParam)) {
1908 case rad1: /* orientation */
1909 case rad2:
1910 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1911 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1912 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1913 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1914 (WPARAM)IMAGE_ICON,
1915 (LPARAM)PrintStructures->hPortraitIcon);
1916 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1917 (WPARAM)IMAGE_ICON,
1918 (LPARAM)PrintStructures->hPortraitIcon);
1919 }
1920 } else {
1921 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1922 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1923 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1924 (WPARAM)IMAGE_ICON,
1925 (LPARAM)PrintStructures->hLandscapeIcon);
1926 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1927 (WPARAM)IMAGE_ICON,
1928 (LPARAM)PrintStructures->hLandscapeIcon);
1929 }
1930 }
1931 break;
1932 }
1933 }
1934 return FALSE;
1935}
1936
1937static LRESULT PRINTDLG_WMCommandW(HWND hDlg, WPARAM wParam,
1938 LPARAM lParam, PRINT_PTRW* PrintStructures)
1939{
1940 LPPRINTDLGW lppd = PrintStructures->dlg.lpPrintDlg;
1941 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1942 LPDEVMODEW lpdm = PrintStructures->lpDevMode;
1943
1944 switch (LOWORD(wParam)) {
1945 case IDOK:
1946 TRACE(" OK button was hit\n");
1947 if (PRINTDLG_UpdatePrintDlgW(hDlg, PrintStructures)!=TRUE) {
1948 FIXME("Update printdlg was not successful!\n");
1949 return(FALSE);
1950 }
1951 EndDialog(hDlg, TRUE);
1952 return(TRUE);
1953
1954 case IDCANCEL:
1955 TRACE(" CANCEL button was hit\n");
1956 EndDialog(hDlg, FALSE);
1957 return(FALSE);
1958
1959 case pshHelp:
1960 TRACE(" HELP button was hit\n");
1961 SendMessageW(lppd->hwndOwner, PrintStructures->HelpMessageID,
1962 (WPARAM) hDlg, (LPARAM) lppd);
1963 break;
1964
1965 case chx2: /* collate pages checkbox */
1966 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1967 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1968 (LPARAM)PrintStructures->hCollateIcon);
1969 else
1970 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1971 (LPARAM)PrintStructures->hNoCollateIcon);
1972 break;
1973 case edt1: /* from page nr editbox */
1974 case edt2: /* to page nr editbox */
1975 if (HIWORD(wParam)==EN_CHANGE) {
1976 WORD nToPage;
1977 WORD nFromPage;
1978 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1979 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1980 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1981 CheckRadioButton(hDlg, rad1, rad3, rad3);
1982 }
1983 break;
1984
1985 case edt3:
1986 if(HIWORD(wParam) == EN_CHANGE) {
1987 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1988 if(copies <= 1)
1989 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1990 else
1991 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1992 }
1993 break;
1994
1995 case psh1: /* Print Setup */
1996 {
1997 ERR("psh1 is called from 16bit code only, we should not get here.\n");
1998 }
1999 break;
2000 case psh2: /* Properties button */
2001 {
2002 HANDLE hPrinter;
2003 WCHAR PrinterName[256];
2004
2005 GetDlgItemTextW(hDlg, PrinterComboID, PrinterName, 255);
2006 if (!OpenPrinterW(PrinterName, &hPrinter, NULL)) {
2007 FIXME(" Call to OpenPrinter did not succeed!\n");
2008 break;
2009 }
2010 DocumentPropertiesW(hDlg, hPrinter, PrinterName,
2011 PrintStructures->lpDevMode,
2012 PrintStructures->lpDevMode,
2013 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
2014 ClosePrinter(hPrinter);
2015 break;
2016 }
2017
2018 case rad1: /* Paperorientation */
2019 if (lppd->Flags & PD_PRINTSETUP)
2020 {
2021 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
2022 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
2023 (LPARAM)(PrintStructures->hPortraitIcon));
2024 }
2025 break;
2026
2027 case rad2: /* Paperorientation */
2028 if (lppd->Flags & PD_PRINTSETUP)
2029 {
2030 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
2031 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
2032 (LPARAM)(PrintStructures->hLandscapeIcon));
2033 }
2034 break;
2035
2036 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
2037 if (PrinterComboID != wParam) {
2038 FIXME("No handling for print quality combo box yet.\n");
2039 break;
2040 }
2041 /* FALLTHROUGH */
2042 case cmb4: /* Printer combobox */
2043 if (HIWORD(wParam)==CBN_SELCHANGE) {
2044 WCHAR PrinterName[256];
2045 GetDlgItemTextW(hDlg, LOWORD(wParam), PrinterName, 255);
2046 PRINTDLG_ChangePrinterW(hDlg, PrinterName, PrintStructures);
2047 }
2048 break;
2049
2050 case cmb2: /* Papersize */
2051 {
2052 DWORD Sel = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
2053 if(Sel != CB_ERR)
2054 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
2055 CB_GETITEMDATA,
2056 Sel, 0);
2057 }
2058 break;
2059
2060 case cmb3: /* Bin */
2061 {
2062 DWORD Sel = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
2063 if(Sel != CB_ERR)
2064 lpdm->dmDefaultSource = SendDlgItemMessageW(hDlg, cmb3,
2065 CB_GETITEMDATA, Sel,
2066 0);
2067 }
2068 break;
2069 }
2070 if(lppd->Flags & PD_PRINTSETUP) {
2071 switch (LOWORD(wParam)) {
2072 case rad1: /* orientation */
2073 case rad2:
2074 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
2075 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
2076 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
2077 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
2078 (WPARAM)IMAGE_ICON,
2079 (LPARAM)PrintStructures->hPortraitIcon);
2080 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
2081 (WPARAM)IMAGE_ICON,
2082 (LPARAM)PrintStructures->hPortraitIcon);
2083 }
2084 } else {
2085 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
2086 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
2087 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
2088 (WPARAM)IMAGE_ICON,
2089 (LPARAM)PrintStructures->hLandscapeIcon);
2090 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
2091 (WPARAM)IMAGE_ICON,
2092 (LPARAM)PrintStructures->hLandscapeIcon);
2093 }
2094 }
2095 break;
2096 }
2097 }
2098 return FALSE;
2099}
2100
2101/***********************************************************************
2102 * PrintDlgProcA [internal]
2103 */
2104BOOL WINAPI PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
2105 LPARAM lParam)
2106{
2107 PRINT_PTRA* PrintStructures;
2108 LRESULT res=FALSE;
2109
2110 if (uMsg!=WM_INITDIALOG) {
2111 PrintStructures = (PRINT_PTRA*)GetPropA(hDlg,"__WINE_PRINTDLGDATA");
2112 if (!PrintStructures)
2113 return FALSE;
2114 } else {
2115 PrintStructures = (PRINT_PTRA*) lParam;
2116 SetPropA(hDlg,"__WINE_PRINTDLGDATA",lParam);
2117 res = PRINTDLG_WMInitDialog(hDlg, wParam, PrintStructures);
2118
2119 if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
2120 res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(
2121 hDlg, uMsg, wParam, (LPARAM)PrintStructures->dlg.lpPrintDlg
2122 );
2123 return res;
2124 }
2125
2126 if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
2127 res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam,
2128 lParam);
2129 if(res) return res;
2130 }
2131
2132 switch (uMsg) {
2133 case WM_COMMAND:
2134 return PRINTDLG_WMCommandA(hDlg, wParam, lParam, PrintStructures);
2135
2136 case WM_DESTROY:
2137 DestroyIcon(PrintStructures->hCollateIcon);
2138 DestroyIcon(PrintStructures->hNoCollateIcon);
2139 DestroyIcon(PrintStructures->hPortraitIcon);
2140 DestroyIcon(PrintStructures->hLandscapeIcon);
2141 if(PrintStructures->hwndUpDown)
2142 DestroyWindow(PrintStructures->hwndUpDown);
2143 return FALSE;
2144 }
2145 return res;
2146}
2147
2148BOOL WINAPI PrintDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
2149 LPARAM lParam)
2150{
2151 PRINT_PTRW* PrintStructures;
2152 LRESULT res=FALSE;
2153
2154 if (uMsg!=WM_INITDIALOG) {
2155 PrintStructures = (PRINT_PTRW*) GetWindowLongA(hDlg, DWL_USER);
2156 if (!PrintStructures)
2157 return FALSE;
2158 } else {
2159 PrintStructures = (PRINT_PTRW*) lParam;
2160 SetWindowLongA(hDlg, DWL_USER, lParam);
2161 res = PRINTDLG_WMInitDialogW(hDlg, wParam, PrintStructures);
2162
2163 if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
2164 res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(
2165 hDlg, uMsg, wParam, (LPARAM)PrintStructures->dlg.lpPrintDlg
2166 );
2167 return res;
2168 }
2169
2170 if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
2171 res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam,
2172 lParam);
2173 if(res) return res;
2174 }
2175
2176 switch (uMsg) {
2177 case WM_COMMAND:
2178 return PRINTDLG_WMCommandW(hDlg, wParam, lParam, PrintStructures);
2179
2180 case WM_DESTROY:
2181 DestroyIcon(PrintStructures->hCollateIcon);
2182 DestroyIcon(PrintStructures->hNoCollateIcon);
2183 DestroyIcon(PrintStructures->hPortraitIcon);
2184 DestroyIcon(PrintStructures->hLandscapeIcon);
2185 if(PrintStructures->hwndUpDown)
2186 DestroyWindow(PrintStructures->hwndUpDown);
2187 return FALSE;
2188 }
2189 return res;
2190}
2191
2192
2193#ifndef __WIN32OS2__
2194/************************************************************
2195 *
2196 * PRINTDLG_Get16TemplateFrom32 [Internal]
2197 * Generates a 16 bits template from the Wine 32 bits resource
2198 *
2199 */
2200static HGLOBAL16 PRINTDLG_Get16TemplateFrom32(char *PrintResourceName)
2201{
2202 HRSRC hResInfo;
2203 HGLOBAL hDlgTmpl32;
2204 LPCVOID template32;
2205 DWORD size;
2206 HGLOBAL16 hGlobal16;
2207 LPVOID template;
2208
2209 if (!(hResInfo = FindResourceA(COMMDLG_hInstance32,
2210 PrintResourceName, RT_DIALOGA)))
2211 {
2212 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
2213 return 0;
2214 }
2215 if (!(hDlgTmpl32 = LoadResource(COMMDLG_hInstance32, hResInfo )) ||
2216 !(template32 = LockResource( hDlgTmpl32 )))
2217 {
2218 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2219 return 0;
2220 }
2221 size = SizeofResource(COMMDLG_hInstance32, hResInfo);
2222 hGlobal16 = GlobalAlloc16(0, size);
2223 if (!hGlobal16)
2224 {
2225 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
2226 ERR("alloc failure for %ld bytes\n", size);
2227 return 0;
2228 }
2229 template = GlobalLock16(hGlobal16);
2230 if (!template)
2231 {
2232 COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE);
2233 ERR("global lock failure for %x handle\n", hGlobal16);
2234 GlobalFree16(hGlobal16);
2235 return 0;
2236 }
2237 ConvertDialog32To16((LPVOID)template32, size, (LPVOID)template);
2238 GlobalUnlock16(hGlobal16);
2239 return hGlobal16;
2240}
2241#endif
2242
2243/************************************************************
2244 *
2245 * PRINTDLG_GetDlgTemplate
2246 *
2247 */
2248static HGLOBAL PRINTDLG_GetDlgTemplateA(PRINTDLGA *lppd)
2249{
2250 HRSRC hResInfo;
2251 HGLOBAL hDlgTmpl;
2252
2253 if (lppd->Flags & PD_PRINTSETUP) {
2254 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
2255 hDlgTmpl = lppd->hSetupTemplate;
2256 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
2257 hResInfo = FindResourceA(lppd->hInstance,
2258 lppd->lpSetupTemplateName, RT_DIALOGA);
2259 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2260 } else {
2261 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32_SETUP",
2262 RT_DIALOGA);
2263 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
2264 }
2265 } else {
2266 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
2267 hDlgTmpl = lppd->hPrintTemplate;
2268 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
2269 hResInfo = FindResourceA(lppd->hInstance,
2270 lppd->lpPrintTemplateName,
2271 RT_DIALOGA);
2272 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2273 } else {
2274 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32",
2275 RT_DIALOGA);
2276 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
2277 }
2278 }
2279 return hDlgTmpl;
2280}
2281
2282static HGLOBAL PRINTDLG_GetDlgTemplateW(PRINTDLGW *lppd)
2283{
2284 HRSRC hResInfo;
2285 HGLOBAL hDlgTmpl;
2286 const WCHAR xpsetup[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
2287 const WCHAR xprint[] = { 'P','R','I','N','T','3','2',0};
2288
2289 if (lppd->Flags & PD_PRINTSETUP) {
2290 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
2291 hDlgTmpl = lppd->hSetupTemplate;
2292 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
2293 hResInfo = FindResourceW(lppd->hInstance,
2294 lppd->lpSetupTemplateName, RT_DIALOGW);
2295 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2296 } else {
2297 hResInfo = FindResourceW(COMDLG32_hInstance, xpsetup, RT_DIALOGW);
2298 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
2299 }
2300 } else {
2301 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
2302 hDlgTmpl = lppd->hPrintTemplate;
2303 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
2304 hResInfo = FindResourceW(lppd->hInstance,
2305 lppd->lpPrintTemplateName,
2306 RT_DIALOGW);
2307 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2308 } else {
2309 hResInfo = FindResourceW(COMDLG32_hInstance, xprint, RT_DIALOGW);
2310 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
2311 }
2312 }
2313 return hDlgTmpl;
2314}
2315
2316
2317#ifndef __WIN32OS2__
2318/************************************************************
2319 *
2320 * PRINTDLG_GetDlgTemplate
2321 *
2322 */
2323static HGLOBAL16 PRINTDLG_GetDlgTemplate16(PRINTDLG16 *lppd)
2324{
2325 HGLOBAL16 hDlgTmpl, hResInfo;
2326
2327 if (lppd->Flags & PD_PRINTSETUP) {
2328 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
2329 hDlgTmpl = lppd->hSetupTemplate;
2330 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
2331 hResInfo = FindResource16(lppd->hInstance,
2332 MapSL(lppd->lpSetupTemplateName), RT_DIALOGA);
2333 hDlgTmpl = LoadResource16(lppd->hInstance, hResInfo);
2334 } else {
2335 hDlgTmpl = PRINTDLG_Get16TemplateFrom32("PRINT32_SETUP");
2336 }
2337 } else {
2338 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
2339 hDlgTmpl = lppd->hPrintTemplate;
2340 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
2341 hResInfo = FindResource16(lppd->hInstance,
2342 MapSL(lppd->lpPrintTemplateName),
2343 RT_DIALOGA);
2344 hDlgTmpl = LoadResource16(lppd->hInstance, hResInfo);
2345 } else {
2346 hDlgTmpl = PRINTDLG_Get16TemplateFrom32("PRINT32");
2347 }
2348 }
2349 return hDlgTmpl;
2350}
2351#endif
2352
2353/***********************************************************************
2354 *
2355 * PRINTDLG_CreateDC
2356 *
2357 */
2358static BOOL PRINTDLG_CreateDCA(LPPRINTDLGA lppd)
2359{
2360 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
2361 DEVMODEA *pdm = GlobalLock(lppd->hDevMode);
2362
2363 if(lppd->Flags & PD_RETURNDC) {
2364 lppd->hDC = CreateDCA((char*)pdn + pdn->wDriverOffset,
2365 (char*)pdn + pdn->wDeviceOffset,
2366 (char*)pdn + pdn->wOutputOffset,
2367 pdm );
2368 } else if(lppd->Flags & PD_RETURNIC) {
2369 lppd->hDC = CreateICA((char*)pdn + pdn->wDriverOffset,
2370 (char*)pdn + pdn->wDeviceOffset,
2371 (char*)pdn + pdn->wOutputOffset,
2372 pdm );
2373 }
2374 GlobalUnlock(lppd->hDevNames);
2375 GlobalUnlock(lppd->hDevMode);
2376 return lppd->hDC ? TRUE : FALSE;
2377}
2378
2379static BOOL PRINTDLG_CreateDCW(LPPRINTDLGW lppd)
2380{
2381 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
2382 DEVMODEW *pdm = GlobalLock(lppd->hDevMode);
2383
2384 if(lppd->Flags & PD_RETURNDC) {
2385 lppd->hDC = CreateDCW((WCHAR*)pdn + pdn->wDriverOffset,
2386 (WCHAR*)pdn + pdn->wDeviceOffset,
2387 (WCHAR*)pdn + pdn->wOutputOffset,
2388 pdm );
2389 } else if(lppd->Flags & PD_RETURNIC) {
2390 lppd->hDC = CreateICW((WCHAR*)pdn + pdn->wDriverOffset,
2391 (WCHAR*)pdn + pdn->wDeviceOffset,
2392 (WCHAR*)pdn + pdn->wOutputOffset,
2393 pdm );
2394 }
2395 GlobalUnlock(lppd->hDevNames);
2396 GlobalUnlock(lppd->hDevMode);
2397 return lppd->hDC ? TRUE : FALSE;
2398}
2399
2400#ifndef __WIN32OS2__
2401static BOOL PRINTDLG_CreateDC16(LPPRINTDLG16 lppd)
2402{
2403 DEVNAMES *pdn = GlobalLock16(lppd->hDevNames);
2404 DEVMODEA *pdm = GlobalLock16(lppd->hDevMode);
2405
2406 if(lppd->Flags & PD_RETURNDC) {
2407 lppd->hDC = CreateDCA((char*)pdn + pdn->wDriverOffset,
2408 (char*)pdn + pdn->wDeviceOffset,
2409 (char*)pdn + pdn->wOutputOffset,
2410 pdm );
2411 } else if(lppd->Flags & PD_RETURNIC) {
2412 lppd->hDC = CreateICA((char*)pdn + pdn->wDriverOffset,
2413 (char*)pdn + pdn->wDeviceOffset,
2414 (char*)pdn + pdn->wOutputOffset,
2415 pdm );
2416 }
2417 GlobalUnlock16(lppd->hDevNames);
2418 GlobalUnlock16(lppd->hDevMode);
2419 return lppd->hDC ? TRUE : FALSE;
2420}
2421#endif
2422
2423/***********************************************************************
2424 * PrintDlgA (COMDLG32.@)
2425 *
2426 * Displays the the PRINT dialog box, which enables the user to specify
2427 * specific properties of the print job.
2428 *
2429 * RETURNS
2430 * nonzero if the user pressed the OK button
2431 * zero if the user cancelled the window or an error occurred
2432 *
2433 * BUGS
2434 * PrintDlg:
2435 * * The Collate Icons do not display, even though they are in the code.
2436 * * The Properties Button(s) should call DocumentPropertiesA().
2437 * PrintSetupDlg:
2438 * * The Paper Orientation Icons are not implemented yet.
2439 * * The Properties Button(s) should call DocumentPropertiesA().
2440 * * Settings are not yet taken from a provided DevMode or
2441 * default printer settings.
2442 */
2443
2444BOOL WINAPI PrintDlgA(
2445 LPPRINTDLGA lppd /* [in/out] ptr to PRINTDLG32 struct */
2446 )
2447{
2448 BOOL bRet = FALSE;
2449 LPVOID ptr;
2450 HINSTANCE hInst = GetWindowLongA( lppd->hwndOwner, GWL_HINSTANCE );
2451
2452 if(TRACE_ON(commdlg)) {
2453 char flagstr[1000] = "";
2454 struct pd_flags *pflag = pd_flags;
2455 for( ; pflag->name; pflag++) {
2456 if(lppd->Flags & pflag->flag)
2457 strcat(flagstr, pflag->name);
2458 }
2459 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
2460 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %08x\n"
2461 "flags %08lx (%s)\n",
2462 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2463 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2464 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2465 }
2466
2467 if(lppd->lStructSize != sizeof(PRINTDLGA)) {
2468 WARN("structure size failure !!!\n");
2469 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2470 return FALSE;
2471 }
2472
2473 if(lppd->Flags & PD_RETURNDEFAULT) {
2474 PRINTER_INFO_2A *pbuf;
2475 DRIVER_INFO_3A *dbuf;
2476 HANDLE hprn;
2477 DWORD needed;
2478
2479 if(lppd->hDevMode || lppd->hDevNames) {
2480 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2481 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2482 return FALSE;
2483 }
2484 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2485 WARN("Can't find default printer\n");
2486 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2487 return FALSE;
2488 }
2489
2490 GetPrinterA(hprn, 2, NULL, 0, &needed);
2491 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
2492 GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2493
2494 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
2495 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
2496 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2497 ERR("GetPrinterDriverA failed, le %ld, fix your config for printer %s!\n",GetLastError(),pbuf->pPrinterName);
2498 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2499 return FALSE;
2500 }
2501 ClosePrinter(hprn);
2502
2503 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2504 dbuf->pDriverPath,
2505 pbuf->pPrinterName,
2506 pbuf->pPortName);
2507 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2508 pbuf->pDevMode->dmDriverExtra);
2509 ptr = GlobalLock(lppd->hDevMode);
2510 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2511 pbuf->pDevMode->dmDriverExtra);
2512 GlobalUnlock(lppd->hDevMode);
2513 HeapFree(GetProcessHeap(), 0, pbuf);
2514 HeapFree(GetProcessHeap(), 0, dbuf);
2515 bRet = TRUE;
2516 } else {
2517 HGLOBAL hDlgTmpl;
2518 PRINT_PTRA *PrintStructures;
2519
2520 /* load Dialog resources,
2521 * depending on Flags indicates Print32 or Print32_setup dialog
2522 */
2523 hDlgTmpl = PRINTDLG_GetDlgTemplateA(lppd);
2524 if (!hDlgTmpl) {
2525 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2526 return FALSE;
2527 }
2528 ptr = LockResource( hDlgTmpl );
2529 if (!ptr) {
2530 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2531 return FALSE;
2532 }
2533
2534 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2535 sizeof(PRINT_PTRA));
2536 PrintStructures->dlg.lpPrintDlg = lppd;
2537
2538 /* and create & process the dialog .
2539 * -1 is failure, 0 is broken hwnd, everything else is ok.
2540 */
2541 bRet = (0<DialogBoxIndirectParamA(hInst, ptr, lppd->hwndOwner,
2542 PrintDlgProcA,
2543 (LPARAM)PrintStructures));
2544
2545 if(bRet) {
2546 DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2547 PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
2548 DRIVER_INFO_3A *di = PrintStructures->lpDriverInfo;
2549
2550 if (lppd->hDevMode == 0) {
2551 TRACE(" No hDevMode yet... Need to create my own\n");
2552 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2553 lpdm->dmSize + lpdm->dmDriverExtra);
2554 } else {
2555 WORD locks;
2556 if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
2557 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2558 while(locks--) {
2559 GlobalUnlock(lppd->hDevMode);
2560 TRACE("Now got %d locks\n", locks);
2561 }
2562 }
2563 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2564 lpdm->dmSize + lpdm->dmDriverExtra,
2565 GMEM_MOVEABLE);
2566 }
2567 lpdmReturn = GlobalLock(lppd->hDevMode);
2568 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2569
2570 if (lppd->hDevNames != 0) {
2571 WORD locks;
2572 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
2573 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2574 while(locks--)
2575 GlobalUnlock(lppd->hDevNames);
2576 }
2577 }
2578 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2579 di->pDriverPath,
2580 pi->pPrinterName,
2581 pi->pPortName
2582 );
2583 GlobalUnlock(lppd->hDevMode);
2584 }
2585 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2586 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2587 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2588 HeapFree(GetProcessHeap(), 0, PrintStructures);
2589 }
2590 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2591 bRet = PRINTDLG_CreateDCA(lppd);
2592
2593 TRACE("exit! (%d)\n", bRet);
2594 return bRet;
2595}
2596
2597/***********************************************************************
2598 * PrintDlgW (COMDLG32.@)
2599 */
2600BOOL WINAPI PrintDlgW(
2601 LPPRINTDLGW lppd /* [in/out] ptr to PRINTDLG32 struct */
2602 )
2603{
2604 BOOL bRet = FALSE;
2605 LPVOID ptr;
2606 HINSTANCE hInst = GetWindowLongA( lppd->hwndOwner, GWL_HINSTANCE );
2607
2608 if(TRACE_ON(commdlg)) {
2609 char flagstr[1000] = "";
2610 struct pd_flags *pflag = pd_flags;
2611 for( ; pflag->name; pflag++) {
2612 if(lppd->Flags & pflag->flag)
2613 strcat(flagstr, pflag->name);
2614 }
2615 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
2616 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %08x\n"
2617 "flags %08lx (%s)\n",
2618 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2619 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2620 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2621 }
2622
2623 if(lppd->lStructSize != sizeof(PRINTDLGW)) {
2624 WARN("structure size failure !!!\n");
2625 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2626 return FALSE;
2627 }
2628
2629 if(lppd->Flags & PD_RETURNDEFAULT) {
2630 PRINTER_INFO_2W *pbuf;
2631 DRIVER_INFO_3W *dbuf;
2632 HANDLE hprn;
2633 DWORD needed;
2634
2635 if(lppd->hDevMode || lppd->hDevNames) {
2636 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2637 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2638 return FALSE;
2639 }
2640 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2641 WARN("Can't find default printer\n");
2642 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2643 return FALSE;
2644 }
2645
2646 GetPrinterW(hprn, 2, NULL, 0, &needed);
2647 pbuf = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*needed);
2648 GetPrinterW(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2649
2650 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
2651 dbuf = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
2652 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2653 ERR("GetPrinterDriverA failed, le %ld, fix your config for printer %s!\n",GetLastError(),debugstr_w(pbuf->pPrinterName));
2654 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2655 return FALSE;
2656 }
2657 ClosePrinter(hprn);
2658
2659 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2660 dbuf->pDriverPath,
2661 pbuf->pPrinterName,
2662 pbuf->pPortName);
2663 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2664 pbuf->pDevMode->dmDriverExtra);
2665 ptr = GlobalLock(lppd->hDevMode);
2666 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2667 pbuf->pDevMode->dmDriverExtra);
2668 GlobalUnlock(lppd->hDevMode);
2669 HeapFree(GetProcessHeap(), 0, pbuf);
2670 HeapFree(GetProcessHeap(), 0, dbuf);
2671 bRet = TRUE;
2672 } else {
2673 HGLOBAL hDlgTmpl;
2674 PRINT_PTRW *PrintStructures;
2675
2676 /* load Dialog resources,
2677 * depending on Flags indicates Print32 or Print32_setup dialog
2678 */
2679 hDlgTmpl = PRINTDLG_GetDlgTemplateW(lppd);
2680 if (!hDlgTmpl) {
2681 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2682 return FALSE;
2683 }
2684 ptr = LockResource( hDlgTmpl );
2685 if (!ptr) {
2686 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2687 return FALSE;
2688 }
2689
2690 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2691 sizeof(PRINT_PTRW));
2692 PrintStructures->dlg.lpPrintDlg = lppd;
2693
2694 /* and create & process the dialog .
2695 * -1 is failure, 0 is broken hwnd, everything else is ok.
2696 */
2697 bRet = (0<DialogBoxIndirectParamW(hInst, ptr, lppd->hwndOwner,
2698 PrintDlgProcW,
2699 (LPARAM)PrintStructures));
2700
2701 if(bRet) {
2702 DEVMODEW *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2703 PRINTER_INFO_2W *pi = PrintStructures->lpPrinterInfo;
2704 DRIVER_INFO_3W *di = PrintStructures->lpDriverInfo;
2705
2706 if (lppd->hDevMode == 0) {
2707 TRACE(" No hDevMode yet... Need to create my own\n");
2708 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2709 lpdm->dmSize + lpdm->dmDriverExtra);
2710 } else {
2711 WORD locks;
2712 if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
2713 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2714 while(locks--) {
2715 GlobalUnlock(lppd->hDevMode);
2716 TRACE("Now got %d locks\n", locks);
2717 }
2718 }
2719 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2720 lpdm->dmSize + lpdm->dmDriverExtra,
2721 GMEM_MOVEABLE);
2722 }
2723 lpdmReturn = GlobalLock(lppd->hDevMode);
2724 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2725
2726 if (lppd->hDevNames != 0) {
2727 WORD locks;
2728 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
2729 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2730 while(locks--)
2731 GlobalUnlock(lppd->hDevNames);
2732 }
2733 }
2734 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2735 di->pDriverPath,
2736 pi->pPrinterName,
2737 pi->pPortName
2738 );
2739 GlobalUnlock(lppd->hDevMode);
2740 }
2741 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2742 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2743 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2744 HeapFree(GetProcessHeap(), 0, PrintStructures);
2745 }
2746 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2747 bRet = PRINTDLG_CreateDCW(lppd);
2748
2749 TRACE("exit! (%d)\n", bRet);
2750 return bRet;
2751}
2752
2753#ifndef __WIN32OS2__
2754/***********************************************************************
2755 * PrintDlg (COMMDLG.20)
2756 *
2757 * Displays the the PRINT dialog box, which enables the user to specify
2758 * specific properties of the print job.
2759 *
2760 * RETURNS
2761 * nonzero if the user pressed the OK button
2762 * zero if the user cancelled the window or an error occurred
2763 *
2764 * BUGS
2765 * * calls up to the 32-bit versions of the Dialogs, which look different
2766 * * Customizing is *not* implemented.
2767 */
2768
2769BOOL16 WINAPI PrintDlg16(
2770 LPPRINTDLG16 lppd /* [in/out] ptr to PRINTDLG struct */
2771) {
2772 BOOL bRet = FALSE;
2773 LPVOID ptr;
2774 HINSTANCE hInst = GetWindowLongA( HWND_32(lppd->hwndOwner), GWL_HINSTANCE );
2775
2776 if(TRACE_ON(commdlg)) {
2777 char flagstr[1000] = "";
2778 struct pd_flags *pflag = pd_flags;
2779 for( ; pflag->name; pflag++) {
2780 if(lppd->Flags & pflag->flag)
2781 strcat(flagstr, pflag->name);
2782 }
2783 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
2784 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %08x\n"
2785 "flags %08lx (%s)\n",
2786 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2787 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2788 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2789 }
2790
2791 if(lppd->lStructSize != sizeof(PRINTDLG16)) {
2792 ERR("structure size (%ld/%d)\n",lppd->lStructSize,sizeof(PRINTDLG16));
2793 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2794 return FALSE;
2795 }
2796
2797 if(lppd->Flags & PD_RETURNDEFAULT) {
2798 PRINTER_INFO_2A *pbuf;
2799 DRIVER_INFO_3A *dbuf;
2800 HANDLE hprn;
2801 DWORD needed;
2802
2803 if(lppd->hDevMode || lppd->hDevNames) {
2804 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2805 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2806 return FALSE;
2807 }
2808 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2809 WARN("Can't find default printer\n");
2810 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2811 return FALSE;
2812 }
2813
2814 GetPrinterA(hprn, 2, NULL, 0, &needed);
2815 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
2816 GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2817 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
2818 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
2819 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2820 ERR("GetPrinterDriverA failed for %s, le %ld, fix your config!\n",
2821 pbuf->pPrinterName,GetLastError());
2822 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2823 return FALSE;
2824 }
2825 ClosePrinter(hprn);
2826 PRINTDLG_CreateDevNames16(&(lppd->hDevNames),
2827 dbuf->pDriverPath,
2828 pbuf->pPrinterName,
2829 pbuf->pPortName);
2830 lppd->hDevMode = GlobalAlloc16(GMEM_MOVEABLE,pbuf->pDevMode->dmSize+
2831 pbuf->pDevMode->dmDriverExtra);
2832 ptr = GlobalLock16(lppd->hDevMode);
2833 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2834 pbuf->pDevMode->dmDriverExtra);
2835 GlobalUnlock16(lppd->hDevMode);
2836 HeapFree(GetProcessHeap(), 0, pbuf);
2837 HeapFree(GetProcessHeap(), 0, dbuf);
2838 bRet = TRUE;
2839 } else {
2840 HGLOBAL hDlgTmpl;
2841 PRINT_PTRA *PrintStructures;
2842
2843 /* load Dialog resources,
2844 * depending on Flags indicates Print32 or Print32_setup dialog
2845 */
2846 hDlgTmpl = PRINTDLG_GetDlgTemplate16(lppd);
2847 if (!hDlgTmpl) {
2848 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2849 return FALSE;
2850 }
2851 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2852 sizeof(PRINT_PTRA));
2853 PrintStructures->dlg.lpPrintDlg16 = lppd;
2854 PrintStructures->dlg.lpPrintDlg = (LPPRINTDLGA)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(PRINTDLGA));
2855#define CVAL(x) PrintStructures->dlg.lpPrintDlg->x = lppd->x;
2856#define MVAL(x) PrintStructures->dlg.lpPrintDlg->x = MapSL(lppd->x);
2857 CVAL(Flags);
2858 PrintStructures->dlg.lpPrintDlg->hwndOwner = HWND_32(lppd->hwndOwner);
2859 CVAL(hDC);
2860 CVAL(nFromPage);CVAL(nToPage);CVAL(nMinPage);CVAL(nMaxPage);
2861 CVAL(nCopies);CVAL(hInstance);CVAL(lCustData);
2862 MVAL(lpPrintTemplateName);MVAL(lpSetupTemplateName);
2863 /* Don't copy rest, it is 16 bit specific */
2864#undef MVAL
2865#undef CVAL
2866
2867 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(),0,sizeof(DEVMODEA));
2868
2869 /* and create & process the dialog .
2870 * -1 is failure, 0 is broken hwnd, everything else is ok.
2871 */
2872 bRet = (0<DialogBoxIndirectParam16(
2873 hInst, hDlgTmpl, lppd->hwndOwner,
2874 (DLGPROC16)GetProcAddress16(GetModuleHandle16("COMMDLG"),(LPCSTR)21),
2875 (LPARAM)PrintStructures
2876 )
2877 );
2878 if (!PrintStructures->lpPrinterInfo) bRet = FALSE;
2879 if(bRet) {
2880 DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2881 PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
2882 DRIVER_INFO_3A *di = PrintStructures->lpDriverInfo;
2883
2884 if (lppd->hDevMode == 0) {
2885 TRACE(" No hDevMode yet... Need to create my own\n");
2886 lppd->hDevMode = GlobalAlloc16(GMEM_MOVEABLE,
2887 lpdm->dmSize + lpdm->dmDriverExtra);
2888 } else {
2889 WORD locks;
2890 if((locks = (GlobalFlags16(lppd->hDevMode)&GMEM_LOCKCOUNT))) {
2891 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2892 while(locks--) {
2893 GlobalUnlock16(lppd->hDevMode);
2894 TRACE("Now got %d locks\n", locks);
2895 }
2896 }
2897 lppd->hDevMode = GlobalReAlloc16(lppd->hDevMode,
2898 lpdm->dmSize + lpdm->dmDriverExtra,
2899 GMEM_MOVEABLE);
2900 }
2901 lpdmReturn = GlobalLock16(lppd->hDevMode);
2902 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2903
2904 if (lppd->hDevNames != 0) {
2905 WORD locks;
2906 if((locks = (GlobalFlags16(lppd->hDevNames)&GMEM_LOCKCOUNT))) {
2907 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2908 while(locks--)
2909 GlobalUnlock16(lppd->hDevNames);
2910 }
2911 }
2912 PRINTDLG_CreateDevNames16(&(lppd->hDevNames),
2913 di->pDriverPath,
2914 pi->pPrinterName,
2915 pi->pPortName
2916 );
2917 GlobalUnlock16(lppd->hDevMode);
2918 }
2919 if (!(lppd->Flags & (PD_ENABLESETUPTEMPLATEHANDLE | PD_ENABLESETUPTEMPLATE)))
2920 GlobalFree16(hDlgTmpl); /* created from the 32 bits resource */
2921 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2922 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2923 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2924 HeapFree(GetProcessHeap(), 0, PrintStructures);
2925 }
2926 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2927 bRet = PRINTDLG_CreateDC16(lppd);
2928
2929 TRACE("exit! (%d)\n", bRet);
2930 return bRet;
2931}
2932#endif
2933
2934/***********************************************************************
2935 *
2936 * PageSetupDlg
2937 * rad1 - portrait
2938 * rad2 - landscape
2939 * cmb2 - paper size
2940 * cmb3 - source (tray?)
2941 * edt4 - border left
2942 * edt5 - border top
2943 * edt6 - border right
2944 * edt7 - border bottom
2945 * psh3 - "Printer..."
2946 */
2947
2948typedef struct {
2949 LPPAGESETUPDLGA dlga;
2950 PRINTDLGA pdlg;
2951} PageSetupDataA;
2952
2953typedef struct {
2954 LPPAGESETUPDLGW dlga;
2955 PRINTDLGW pdlg;
2956} PageSetupDataW;
2957
2958static HGLOBAL PRINTDLG_GetPGSTemplateA(PAGESETUPDLGA *lppd)
2959{
2960 HRSRC hResInfo;
2961 HGLOBAL hDlgTmpl;
2962
2963 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2964 hDlgTmpl = lppd->hPageSetupTemplate;
2965 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2966 hResInfo = FindResourceA(lppd->hInstance,
2967 lppd->lpPageSetupTemplateName, RT_DIALOGA);
2968 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2969 } else {
2970 hResInfo = FindResourceA(COMDLG32_hInstance,(LPCSTR)PAGESETUPDLGORD,RT_DIALOGA);
2971 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2972 }
2973 return hDlgTmpl;
2974}
2975
2976static HGLOBAL PRINTDLG_GetPGSTemplateW(PAGESETUPDLGW *lppd)
2977{
2978 HRSRC hResInfo;
2979 HGLOBAL hDlgTmpl;
2980
2981 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2982 hDlgTmpl = lppd->hPageSetupTemplate;
2983 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2984 hResInfo = FindResourceW(lppd->hInstance,
2985 lppd->lpPageSetupTemplateName, RT_DIALOGW);
2986 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2987 } else {
2988 hResInfo = FindResourceW(COMDLG32_hInstance,(LPCWSTR)PAGESETUPDLGORD,RT_DIALOGW);
2989 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2990 }
2991 return hDlgTmpl;
2992}
2993
2994static DWORD
2995_c_10mm2size(PAGESETUPDLGA *dlga,DWORD size) {
2996 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2997 return 10*size*10/25.4;
2998 /* If we don't have a flag, we can choose one. Use millimeters
2999 * to avoid confusing me
3000 */
3001 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
3002 return 10*size;
3003}
3004
3005
3006static DWORD
3007_c_inch2size(PAGESETUPDLGA *dlga,DWORD size) {
3008 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
3009 return size;
3010 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
3011 return (size*254)/10;
3012 /* if we don't have a flag, we can choose one. Use millimeters
3013 * to avoid confusing me
3014 */
3015 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
3016 return (size*254)/10;
3017}
3018
3019static void
3020_c_size2strA(PageSetupDataA *pda,DWORD size,LPSTR strout) {
3021 strcpy(strout,"<undef>");
3022 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
3023 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
3024 return;
3025 }
3026 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
3027 sprintf(strout,"%.2fin",(size*1.0)/1000.0);
3028 return;
3029 }
3030 pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
3031 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
3032 return;
3033}
3034static void
3035_c_size2strW(PageSetupDataW *pda,DWORD size,LPSTR strout) {
3036 strcpy(strout,"<undef>");
3037 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
3038 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
3039 return;
3040 }
3041 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
3042 sprintf(strout,"%.2fin",(size*1.0)/1000.0);
3043 return;
3044 }
3045 pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
3046 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
3047 return;
3048}
3049
3050static DWORD
3051_c_str2size(PAGESETUPDLGA *dlga,LPCSTR strin) {
3052 float val;
3053 char rest[200];
3054
3055 rest[0]='\0';
3056 if (!sscanf(strin,"%f%s",&val,rest))
3057 return 0;
3058
3059 if (!strcmp(rest,"in") || !strcmp(rest,"inch")) {
3060 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
3061 return 1000*val;
3062 else
3063 return val*25.4*100;
3064 }
3065 if (!strcmp(rest,"cm")) { rest[0]='m'; val = val*10.0; }
3066 if (!strcmp(rest,"m")) { strcpy(rest,"mm"); val = val*1000.0; }
3067
3068 if (!strcmp(rest,"mm")) {
3069 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
3070 return 100*val;
3071 else
3072 return 1000.0*val/25.4;
3073 }
3074 if (rest[0]=='\0') {
3075 /* use application supplied default */
3076 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
3077 /* 100*mm */
3078 return 100.0*val;
3079 }
3080 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
3081 /* 1000*inch */
3082 return 1000.0*val;
3083 }
3084 }
3085 ERR("Did not find a conversion for type '%s'!\n",rest);
3086 return 0;
3087}
3088
3089
3090/*
3091 * This is called on finish and will update the output fields of the
3092 * struct.
3093 */
3094static BOOL
3095PRINTDLG_PS_UpdateDlgStructA(HWND hDlg, PageSetupDataA *pda) {
3096 DEVNAMES *dn;
3097 DEVMODEA *dm;
3098 LPSTR devname,portname;
3099 char papername[64];
3100 char buf[200];
3101
3102 dn = GlobalLock(pda->pdlg.hDevNames);
3103 dm = GlobalLock(pda->pdlg.hDevMode);
3104 devname = ((char*)dn)+dn->wDeviceOffset;
3105 portname = ((char*)dn)+dn->wOutputOffset;
3106 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb2,devname,portname,dm);
3107 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb3,devname,portname,dm);
3108
3109 if (GetDlgItemTextA(hDlg,cmb2,papername,sizeof(papername))>0) {
3110 PRINTDLG_PaperSizeA(&(pda->pdlg),papername,&(pda->dlga->ptPaperSize));
3111 pda->dlga->ptPaperSize.x = _c_10mm2size(pda->dlga,pda->dlga->ptPaperSize.x);
3112 pda->dlga->ptPaperSize.y = _c_10mm2size(pda->dlga,pda->dlga->ptPaperSize.y);
3113 } else
3114 FIXME("could not get dialog text for papersize cmbbox?\n");
3115#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); }
3116 GETVAL(edt4,pda->dlga->rtMargin.left);
3117 GETVAL(edt5,pda->dlga->rtMargin.top);
3118 GETVAL(edt6,pda->dlga->rtMargin.right);
3119 GETVAL(edt7,pda->dlga->rtMargin.bottom);
3120#undef GETVAL
3121
3122 /* If we are in landscape, swap x and y of page size */
3123 if (IsDlgButtonChecked(hDlg, rad2)) {
3124 DWORD tmp;
3125 tmp = pda->dlga->ptPaperSize.x;
3126 pda->dlga->ptPaperSize.x = pda->dlga->ptPaperSize.y;
3127 pda->dlga->ptPaperSize.y = tmp;
3128 }
3129 GlobalUnlock(pda->pdlg.hDevNames);
3130 GlobalUnlock(pda->pdlg.hDevMode);
3131 return TRUE;
3132}
3133
3134static BOOL
3135PRINTDLG_PS_UpdateDlgStructW(HWND hDlg, PageSetupDataW *pda) {
3136 DEVNAMES *dn;
3137 DEVMODEW *dm;
3138 LPWSTR devname,portname;
3139 WCHAR papername[64];
3140
3141 char buf[200];
3142
3143 dn = GlobalLock(pda->pdlg.hDevNames);
3144 dm = GlobalLock(pda->pdlg.hDevMode);
3145 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
3146 portname = ((WCHAR*)dn)+dn->wOutputOffset;
3147 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
3148 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
3149
3150 if (GetDlgItemTextW(hDlg,cmb2,papername,sizeof(papername))>0) {
3151 PRINTDLG_PaperSizeW(&(pda->pdlg),papername,&(pda->dlga->ptPaperSize));
3152 pda->dlga->ptPaperSize.x = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga,pda->dlga->ptPaperSize.x);
3153 pda->dlga->ptPaperSize.y = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga,pda->dlga->ptPaperSize.y);
3154 } else
3155 FIXME("could not get dialog text for papersize cmbbox?\n");
3156#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); }
3157 GETVAL(edt4,pda->dlga->rtMargin.left);
3158 GETVAL(edt5,pda->dlga->rtMargin.top);
3159 GETVAL(edt6,pda->dlga->rtMargin.right);
3160 GETVAL(edt7,pda->dlga->rtMargin.bottom);
3161#undef GETVAL
3162
3163 /* If we are in landscape, swap x and y of page size */
3164 if (IsDlgButtonChecked(hDlg, rad2)) {
3165 DWORD tmp;
3166 tmp = pda->dlga->ptPaperSize.x;
3167 pda->dlga->ptPaperSize.x = pda->dlga->ptPaperSize.y;
3168 pda->dlga->ptPaperSize.y = tmp;
3169 }
3170 GlobalUnlock(pda->pdlg.hDevNames);
3171 GlobalUnlock(pda->pdlg.hDevMode);
3172 return TRUE;
3173}
3174
3175/*
3176 * This is called after returning from PrintDlg().
3177 */
3178static BOOL
3179PRINTDLG_PS_ChangePrinterA(HWND hDlg, PageSetupDataA *pda) {
3180 DEVNAMES *dn;
3181 DEVMODEA *dm;
3182 LPSTR devname,portname;
3183
3184 dn = GlobalLock(pda->pdlg.hDevNames);
3185 dm = GlobalLock(pda->pdlg.hDevMode);
3186 devname = ((char*)dn)+dn->wDeviceOffset;
3187 portname = ((char*)dn)+dn->wOutputOffset;
3188 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb2,devname,portname,dm);
3189 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb3,devname,portname,dm);
3190 GlobalUnlock(pda->pdlg.hDevNames);
3191 GlobalUnlock(pda->pdlg.hDevMode);
3192 return TRUE;
3193}
3194
3195static BOOL
3196PRINTDLG_PS_ChangePrinterW(HWND hDlg, PageSetupDataW *pda) {
3197 DEVNAMES *dn;
3198 DEVMODEW *dm;
3199 LPWSTR devname,portname;
3200
3201 dn = GlobalLock(pda->pdlg.hDevNames);
3202 dm = GlobalLock(pda->pdlg.hDevMode);
3203 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
3204 portname = ((WCHAR*)dn)+dn->wOutputOffset;
3205 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
3206 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
3207 GlobalUnlock(pda->pdlg.hDevNames);
3208 GlobalUnlock(pda->pdlg.hDevMode);
3209 return TRUE;
3210}
3211
3212static BOOL
3213PRINTDLG_PS_WMCommandA(
3214 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataA *pda
3215) {
3216 switch (LOWORD(wParam)) {
3217 case IDOK:
3218 if (!PRINTDLG_PS_UpdateDlgStructA(hDlg, pda))
3219 return(FALSE);
3220 EndDialog(hDlg, TRUE);
3221 return TRUE ;
3222
3223 case IDCANCEL:
3224 EndDialog(hDlg, FALSE);
3225 return FALSE ;
3226
3227 case psh3: {
3228 pda->pdlg.Flags = 0;
3229 pda->pdlg.hwndOwner = hDlg;
3230 if (PrintDlgA(&(pda->pdlg)))
3231 PRINTDLG_PS_ChangePrinterA(hDlg,pda);
3232 return TRUE;
3233 }
3234 }
3235 FIXME("loword (lparam) %d, wparam 0x%x, lparam %08lx, STUB mostly.\n",
3236 LOWORD(lParam),wParam,lParam
3237 );
3238 return FALSE;
3239}
3240
3241static BOOL
3242PRINTDLG_PS_WMCommandW(
3243 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataW *pda
3244) {
3245 switch (LOWORD(wParam)) {
3246 case IDOK:
3247 if (!PRINTDLG_PS_UpdateDlgStructW(hDlg, pda))
3248 return(FALSE);
3249 EndDialog(hDlg, TRUE);
3250 return TRUE ;
3251
3252 case IDCANCEL:
3253 EndDialog(hDlg, FALSE);
3254 return FALSE ;
3255
3256 case psh3: {
3257 pda->pdlg.Flags = 0;
3258 pda->pdlg.hwndOwner = hDlg;
3259 if (PrintDlgW(&(pda->pdlg)))
3260 PRINTDLG_PS_ChangePrinterW(hDlg,pda);
3261 return TRUE;
3262 }
3263 }
3264 FIXME("loword (lparam) %d, wparam 0x%x, lparam %08lx, STUB mostly.\n",
3265 LOWORD(lParam),wParam,lParam
3266 );
3267 return FALSE;
3268}
3269
3270
3271static BOOL WINAPI
3272PageDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
3273{
3274 PageSetupDataA *pda;
3275 BOOL res = FALSE;
3276
3277 if (uMsg==WM_INITDIALOG) {
3278 res = TRUE;
3279 pda = (PageSetupDataA*)lParam;
3280 SetPropA(hDlg,"__WINE_PAGESETUPDLGDATA",lParam);
3281 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3282 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3283 if (!res) {
3284 FIXME("Setup page hook failed?\n");
3285 res = TRUE;
3286 }
3287 }
3288 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK) {
3289 FIXME("PagePaintHook not yet implemented!\n");
3290 }
3291 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
3292 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
3293 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
3294 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
3295 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
3296 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
3297 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
3298 }
3299 /* width larger as height -> landscape */
3300 if (pda->dlga->ptPaperSize.x > pda->dlga->ptPaperSize.y)
3301 CheckRadioButton(hDlg, rad1, rad2, rad2);
3302 else /* this is default if papersize is not set */
3303 CheckRadioButton(hDlg, rad1, rad2, rad1);
3304 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
3305 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
3306 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
3307 }
3308 /* We fill them out enabled or not */
3309 if (pda->dlga->Flags & PSD_MARGINS) {
3310 char str[100];
3311 _c_size2strA(pda,pda->dlga->rtMargin.left,str);
3312 SetDlgItemTextA(hDlg,edt4,str);
3313 _c_size2strA(pda,pda->dlga->rtMargin.top,str);
3314 SetDlgItemTextA(hDlg,edt5,str);
3315 _c_size2strA(pda,pda->dlga->rtMargin.right,str);
3316 SetDlgItemTextA(hDlg,edt6,str);
3317 _c_size2strA(pda,pda->dlga->rtMargin.bottom,str);
3318 SetDlgItemTextA(hDlg,edt7,str);
3319 } else {
3320 /* default is 1 inch */
3321 DWORD size = _c_inch2size(pda->dlga,1000);
3322 char str[20];
3323 _c_size2strA(pda,size,str);
3324 SetDlgItemTextA(hDlg,edt4,str);
3325 SetDlgItemTextA(hDlg,edt5,str);
3326 SetDlgItemTextA(hDlg,edt6,str);
3327 SetDlgItemTextA(hDlg,edt7,str);
3328 }
3329 PRINTDLG_PS_ChangePrinterA(hDlg,pda);
3330 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
3331 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
3332 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
3333 }
3334 return TRUE;
3335 } else {
3336 pda = (PageSetupDataA*)GetPropA(hDlg,"__WINE_PAGESETUPDLGDATA");
3337 if (!pda) {
3338 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3339 return FALSE;
3340 }
3341 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3342 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3343 if (res) return res;
3344 }
3345 }
3346 switch (uMsg) {
3347 case WM_COMMAND:
3348 return PRINTDLG_PS_WMCommandA(hDlg, wParam, lParam, pda);
3349 }
3350 return FALSE;
3351}
3352
3353static BOOL WINAPI
3354PageDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
3355{
3356 PageSetupDataW *pda;
3357 BOOL res = FALSE;
3358
3359 if (uMsg==WM_INITDIALOG) {
3360 res = TRUE;
3361 pda = (PageSetupDataW*)lParam;
3362 SetPropA(hDlg,"__WINE_PAGESETUPDLGDATA",lParam);
3363 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3364 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3365 if (!res) {
3366 FIXME("Setup page hook failed?\n");
3367 res = TRUE;
3368 }
3369 }
3370 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK) {
3371 FIXME("PagePaintHook not yet implemented!\n");
3372 }
3373 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
3374 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
3375 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
3376 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
3377 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
3378 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
3379 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
3380 }
3381 /* width larger as height -> landscape */
3382 if (pda->dlga->ptPaperSize.x > pda->dlga->ptPaperSize.y)
3383 CheckRadioButton(hDlg, rad1, rad2, rad2);
3384 else /* this is default if papersize is not set */
3385 CheckRadioButton(hDlg, rad1, rad2, rad1);
3386 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
3387 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
3388 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
3389 }
3390 /* We fill them out enabled or not */
3391 if (pda->dlga->Flags & PSD_MARGINS) {
3392 char str[100];
3393 _c_size2strW(pda,pda->dlga->rtMargin.left,str);
3394 SetDlgItemTextA(hDlg,edt4,str);
3395 _c_size2strW(pda,pda->dlga->rtMargin.top,str);
3396 SetDlgItemTextA(hDlg,edt5,str);
3397 _c_size2strW(pda,pda->dlga->rtMargin.right,str);
3398 SetDlgItemTextA(hDlg,edt6,str);
3399 _c_size2strW(pda,pda->dlga->rtMargin.bottom,str);
3400 SetDlgItemTextA(hDlg,edt7,str);
3401 } else {
3402 /* default is 1 inch */
3403 DWORD size = _c_inch2size((LPPAGESETUPDLGA)pda->dlga,1000);
3404 char str[20];
3405 _c_size2strW(pda,size,str);
3406 SetDlgItemTextA(hDlg,edt4,str);
3407 SetDlgItemTextA(hDlg,edt5,str);
3408 SetDlgItemTextA(hDlg,edt6,str);
3409 SetDlgItemTextA(hDlg,edt7,str);
3410 }
3411 PRINTDLG_PS_ChangePrinterW(hDlg,pda);
3412 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
3413 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
3414 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
3415 }
3416 return TRUE;
3417 } else {
3418 pda = (PageSetupDataW*)GetPropA(hDlg,"__WINE_PAGESETUPDLGDATA");
3419 if (!pda) {
3420 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3421 return FALSE;
3422 }
3423 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3424 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3425 if (res) return res;
3426 }
3427 }
3428 switch (uMsg) {
3429 case WM_COMMAND:
3430 return PRINTDLG_PS_WMCommandW(hDlg, wParam, lParam, pda);
3431 }
3432 return FALSE;
3433}
3434
3435/***********************************************************************
3436 * PageSetupDlgA (COMDLG32.@)
3437 */
3438BOOL WINAPI PageSetupDlgA(LPPAGESETUPDLGA setupdlg) {
3439 HGLOBAL hDlgTmpl;
3440 LPVOID ptr;
3441 BOOL bRet;
3442 PageSetupDataA *pda;
3443 PRINTDLGA pdlg;
3444
3445 if(TRACE_ON(commdlg)) {
3446 char flagstr[1000] = "";
3447 struct pd_flags *pflag = psd_flags;
3448 for( ; pflag->name; pflag++) {
3449 if(setupdlg->Flags & pflag->flag) {
3450 strcat(flagstr, pflag->name);
3451 strcat(flagstr, "|");
3452 }
3453 }
3454 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
3455 "hinst %08x, flags %08lx (%s)\n",
3456 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
3457 setupdlg->hDevNames,
3458 setupdlg->hInstance, setupdlg->Flags, flagstr);
3459 }
3460
3461 /* First get default printer data, we need it right after that. */
3462 memset(&pdlg,0,sizeof(pdlg));
3463 pdlg.lStructSize = sizeof(pdlg);
3464 pdlg.Flags = PD_RETURNDEFAULT;
3465 bRet = PrintDlgA(&pdlg);
3466 if (!bRet) return FALSE;
3467
3468 /* short cut exit, just return default values */
3469 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
3470 setupdlg->hDevMode = pdlg.hDevMode;
3471 setupdlg->hDevNames = pdlg.hDevNames;
3472 /* FIXME: Just return "A4" for now. */
3473 PRINTDLG_PaperSizeA(&pdlg,"A4",&setupdlg->ptPaperSize);
3474 setupdlg->ptPaperSize.x=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.x);
3475 setupdlg->ptPaperSize.y=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.y);
3476 return TRUE;
3477 }
3478 hDlgTmpl = PRINTDLG_GetPGSTemplateA(setupdlg);
3479 if (!hDlgTmpl) {
3480 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3481 return FALSE;
3482 }
3483 ptr = LockResource( hDlgTmpl );
3484 if (!ptr) {
3485 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3486 return FALSE;
3487 }
3488 pda = HeapAlloc(GetProcessHeap(),0,sizeof(*pda));
3489 pda->dlga = setupdlg;
3490 memcpy(&pda->pdlg,&pdlg,sizeof(pdlg));
3491
3492 bRet = (0<DialogBoxIndirectParamA(
3493 setupdlg->hInstance,
3494 ptr,
3495 setupdlg->hwndOwner,
3496 PageDlgProcA,
3497 (LPARAM)pda)
3498 );
3499 return bRet;
3500}
3501/***********************************************************************
3502 * PageSetupDlgW (COMDLG32.@)
3503 */
3504BOOL WINAPI PageSetupDlgW(LPPAGESETUPDLGW setupdlg) {
3505 HGLOBAL hDlgTmpl;
3506 LPVOID ptr;
3507 BOOL bRet;
3508 PageSetupDataW *pdw;
3509 PRINTDLGW pdlg;
3510
3511 if(TRACE_ON(commdlg)) {
3512 char flagstr[1000] = "";
3513 struct pd_flags *pflag = psd_flags;
3514 for( ; pflag->name; pflag++) {
3515 if(setupdlg->Flags & pflag->flag) {
3516 strcat(flagstr, pflag->name);
3517 strcat(flagstr, "|");
3518 }
3519 }
3520 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
3521 "hinst %08x, flags %08lx (%s)\n",
3522 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
3523 setupdlg->hDevNames,
3524 setupdlg->hInstance, setupdlg->Flags, flagstr);
3525 }
3526
3527 /* First get default printer data, we need it right after that. */
3528 memset(&pdlg,0,sizeof(pdlg));
3529 pdlg.lStructSize = sizeof(pdlg);
3530 pdlg.Flags = PD_RETURNDEFAULT;
3531 bRet = PrintDlgW(&pdlg);
3532 if (!bRet) return FALSE;
3533
3534 /* short cut exit, just return default values */
3535 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
3536 const WCHAR a4[] = {'A','4',0};
3537 setupdlg->hDevMode = pdlg.hDevMode;
3538 setupdlg->hDevNames = pdlg.hDevNames;
3539 /* FIXME: Just return "A4" for now. */
3540 PRINTDLG_PaperSizeW(&pdlg,a4,&setupdlg->ptPaperSize);
3541 setupdlg->ptPaperSize.x=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.x);
3542 setupdlg->ptPaperSize.y=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.y);
3543 return TRUE;
3544 }
3545 hDlgTmpl = PRINTDLG_GetPGSTemplateW(setupdlg);
3546 if (!hDlgTmpl) {
3547 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3548 return FALSE;
3549 }
3550 ptr = LockResource( hDlgTmpl );
3551 if (!ptr) {
3552 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3553 return FALSE;
3554 }
3555 pdw = HeapAlloc(GetProcessHeap(),0,sizeof(*pdw));
3556 pdw->dlga = setupdlg;
3557 memcpy(&pdw->pdlg,&pdlg,sizeof(pdlg));
3558
3559 bRet = (0<DialogBoxIndirectParamW(
3560 setupdlg->hInstance,
3561 ptr,
3562 setupdlg->hwndOwner,
3563 PageDlgProcW,
3564 (LPARAM)pdw)
3565 );
3566 return bRet;
3567}
3568
3569#ifndef __WIN32OS2__
3570/**********************************************************************
3571 *
3572 * 16 bit commdlg
3573 */
3574
3575/***********************************************************************
3576 * PrintDlgProc (COMMDLG.21)
3577 */
3578LRESULT WINAPI PrintDlgProc16(HWND16 hDlg16, UINT16 uMsg, WPARAM16 wParam,
3579 LPARAM lParam)
3580{
3581 HWND hDlg = HWND_32(hDlg16);
3582 PRINT_PTRA* PrintStructures;
3583 LRESULT res=FALSE;
3584
3585 if (uMsg!=WM_INITDIALOG) {
3586 PrintStructures = (PRINT_PTRA*)GetPropA(hDlg,"__WINE_PRINTDLGDATA");
3587 if (!PrintStructures)
3588 return FALSE;
3589 } else {
3590 PrintStructures = (PRINT_PTRA*) lParam;
3591 SetPropA(hDlg,"__WINE_PRINTDLGDATA",lParam);
3592 res = PRINTDLG_WMInitDialog16(hDlg, wParam, PrintStructures);
3593
3594 if(PrintStructures->dlg.lpPrintDlg16->Flags & PD_ENABLEPRINTHOOK) {
3595 res = CallWindowProc16(
3596 (WNDPROC16)PrintStructures->dlg.lpPrintDlg16->lpfnPrintHook,
3597 hDlg16, uMsg, wParam, (LPARAM)PrintStructures->dlg.lpPrintDlg16
3598 );
3599 }
3600 return res;
3601 }
3602
3603 if(PrintStructures->dlg.lpPrintDlg16->Flags & PD_ENABLEPRINTHOOK) {
3604 res = CallWindowProc16(
3605 (WNDPROC16)PrintStructures->dlg.lpPrintDlg16->lpfnPrintHook,
3606 hDlg16,uMsg, wParam, lParam
3607 );
3608 if(LOWORD(res)) return res;
3609 }
3610
3611 switch (uMsg) {
3612 case WM_COMMAND: {
3613 /* We need to map those for the 32bit window procedure, compare
3614 * with 32Ato16 mapper in winproc.c
3615 */
3616 return PRINTDLG_WMCommandA(
3617 hDlg,
3618 MAKEWPARAM(wParam,HIWORD(lParam)),
3619 LOWORD(lParam),
3620 PrintStructures
3621 );
3622 }
3623 case WM_DESTROY:
3624 DestroyIcon(PrintStructures->hCollateIcon);
3625 DestroyIcon(PrintStructures->hNoCollateIcon);
3626 /* FIXME: don't forget to delete the paper orientation icons here! */
3627
3628 return FALSE;
3629 }
3630 return res;
3631}
3632
3633
3634/***********************************************************************
3635 * PrintSetupDlgProc (COMMDLG.22)
3636 */
3637LRESULT WINAPI PrintSetupDlgProc16(HWND16 hWnd16, UINT16 wMsg, WPARAM16 wParam,
3638 LPARAM lParam)
3639{
3640 HWND hWnd = HWND_32(hWnd16);
3641 switch (wMsg)
3642 {
3643 case WM_INITDIALOG:
3644 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
3645 ShowWindow(hWnd, SW_SHOWNORMAL);
3646 return (TRUE);
3647 case WM_COMMAND:
3648 switch (wParam) {
3649 case IDOK:
3650 EndDialog(hWnd, TRUE);
3651 return(TRUE);
3652 case IDCANCEL:
3653 EndDialog(hWnd, FALSE);
3654 return(TRUE);
3655 }
3656 return(FALSE);
3657 }
3658 return FALSE;
3659}
3660#endif
3661
3662/***********************************************************************
3663 * PrintDlgExA (COMDLG32.@)
3664 */
3665HRESULT WINAPI PrintDlgExA(LPVOID lpPrintDlgExA) /* [???] FIXME: LPPRINTDLGEXA */
3666{
3667 FIXME("stub\n");
3668 return E_NOTIMPL;
3669}
3670/***********************************************************************
3671 * PrintDlgExW (COMDLG32.@)
3672 */
3673HRESULT WINAPI PrintDlgExW(LPVOID lpPrintDlgExW) /* [???] FIXME: LPPRINTDLGEXW */
3674{
3675 FIXME("stub\n");
3676 return E_NOTIMPL;
3677}
3678
Note: See TracBrowser for help on using the repository browser.