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

Last change on this file since 22010 was 10598, checked in by sandervl, 21 years ago

Update the hDevNames member of the printer dialog structure whenever the user chooses another printer

File size: 116.9 KB
Line 
1/*
2 * COMMDLG - Print Dialog
3 *
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
6 * Copyright 1999 Klaas van Gend
7 * Copyright 2000 Huw D M Davies
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23#include <ctype.h>
24#include <stdlib.h>
25#include <stdio.h>
26#include <string.h>
27#include "windef.h"
28#include "winbase.h"
29#include "wingdi.h"
30#include "wine/wingdi16.h"
31#include "winuser.h"
32#include "wine/winuser16.h"
33#include "commdlg.h"
34#include "dlgs.h"
35#include "wine/debug.h"
36#include "cderr.h"
37#include "winspool.h"
38#include "winerror.h"
39
40WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
41
42#include "cdlg.h"
43
44/* This PRINTDLGA internal structure stores
45 * pointers to several throughout useful structures.
46 *
47 */
48typedef struct
49{
50 LPDEVMODEA lpDevMode;
51 struct {
52 LPPRINTDLGA lpPrintDlg;
53 LPPRINTDLG16 lpPrintDlg16;
54 } dlg;
55 LPPRINTER_INFO_2A lpPrinterInfo;
56 LPDRIVER_INFO_3A lpDriverInfo;
57 UINT HelpMessageID;
58 HICON hCollateIcon; /* PrintDlg only */
59 HICON hNoCollateIcon; /* PrintDlg only */
60 HICON hPortraitIcon; /* PrintSetupDlg only */
61 HICON hLandscapeIcon; /* PrintSetupDlg only */
62 HWND hwndUpDown;
63} PRINT_PTRA;
64
65typedef struct
66{
67 LPDEVMODEW lpDevMode;
68 struct {
69 LPPRINTDLGW lpPrintDlg;
70 } dlg;
71 LPPRINTER_INFO_2W lpPrinterInfo;
72 LPDRIVER_INFO_3W lpDriverInfo;
73 UINT HelpMessageID;
74 HICON hCollateIcon; /* PrintDlg only */
75 HICON hNoCollateIcon; /* PrintDlg only */
76 HICON hPortraitIcon; /* PrintSetupDlg only */
77 HICON hLandscapeIcon; /* PrintSetupDlg only */
78 HWND hwndUpDown;
79} PRINT_PTRW;
80
81/* Debugging info */
82static struct pd_flags {
83 DWORD flag;
84 LPSTR name;
85} pd_flags[] = {
86 {PD_SELECTION, "PD_SELECTION "},
87 {PD_PAGENUMS, "PD_PAGENUMS "},
88 {PD_NOSELECTION, "PD_NOSELECTION "},
89 {PD_NOPAGENUMS, "PD_NOPAGENUMS "},
90 {PD_COLLATE, "PD_COLLATE "},
91 {PD_PRINTTOFILE, "PD_PRINTTOFILE "},
92 {PD_PRINTSETUP, "PD_PRINTSETUP "},
93 {PD_NOWARNING, "PD_NOWARNING "},
94 {PD_RETURNDC, "PD_RETURNDC "},
95 {PD_RETURNIC, "PD_RETURNIC "},
96 {PD_RETURNDEFAULT, "PD_RETURNDEFAULT "},
97 {PD_SHOWHELP, "PD_SHOWHELP "},
98 {PD_ENABLEPRINTHOOK, "PD_ENABLEPRINTHOOK "},
99 {PD_ENABLESETUPHOOK, "PD_ENABLESETUPHOOK "},
100 {PD_ENABLEPRINTTEMPLATE, "PD_ENABLEPRINTTEMPLATE "},
101 {PD_ENABLESETUPTEMPLATE, "PD_ENABLESETUPTEMPLATE "},
102 {PD_ENABLEPRINTTEMPLATEHANDLE, "PD_ENABLEPRINTTEMPLATEHANDLE "},
103 {PD_ENABLESETUPTEMPLATEHANDLE, "PD_ENABLESETUPTEMPLATEHANDLE "},
104 {PD_USEDEVMODECOPIES, "PD_USEDEVMODECOPIES[ANDCOLLATE] "},
105 {PD_DISABLEPRINTTOFILE, "PD_DISABLEPRINTTOFILE "},
106 {PD_HIDEPRINTTOFILE, "PD_HIDEPRINTTOFILE "},
107 {PD_NONETWORKBUTTON, "PD_NONETWORKBUTTON "},
108 {-1, NULL}
109};
110
111/* Debugging info */
112static struct pd_flags psd_flags[] = {
113 {PSD_MINMARGINS,"PSD_MINMARGINS"},
114 {PSD_MARGINS,"PSD_MARGINS"},
115 {PSD_INTHOUSANDTHSOFINCHES,"PSD_INTHOUSANDTHSOFINCHES"},
116 {PSD_INHUNDREDTHSOFMILLIMETERS,"PSD_INHUNDREDTHSOFMILLIMETERS"},
117 {PSD_DISABLEMARGINS,"PSD_DISABLEMARGINS"},
118 {PSD_DISABLEPRINTER,"PSD_DISABLEPRINTER"},
119 {PSD_NOWARNING,"PSD_NOWARNING"},
120 {PSD_DISABLEORIENTATION,"PSD_DISABLEORIENTATION"},
121 {PSD_RETURNDEFAULT,"PSD_RETURNDEFAULT"},
122 {PSD_DISABLEPAPER,"PSD_DISABLEPAPER"},
123 {PSD_SHOWHELP,"PSD_SHOWHELP"},
124 {PSD_ENABLEPAGESETUPHOOK,"PSD_ENABLEPAGESETUPHOOK"},
125 {PSD_ENABLEPAGESETUPTEMPLATE,"PSD_ENABLEPAGESETUPTEMPLATE"},
126 {PSD_ENABLEPAGESETUPTEMPLATEHANDLE,"PSD_ENABLEPAGESETUPTEMPLATEHANDLE"},
127 {PSD_ENABLEPAGEPAINTHOOK,"PSD_ENABLEPAGEPAINTHOOK"},
128 {PSD_DISABLEPAGEPAINTING,"PSD_DISABLEPAGEPAINTING"},
129 {-1, NULL}
130};
131
132/* Yes these constants are the same, but we're just copying win98 */
133#define UPDOWN_ID 0x270f
134#define MAX_COPIES 9999
135
136
137/***********************************************************************
138 * PRINTDLG_GetDefaultPrinterName
139 *
140 * Returns the default printer name in buf.
141 * Even under WinNT/2000 default printer is retrieved via GetProfileString -
142 * these entries are mapped somewhere in the registry rather than win.ini.
143 *
144 * Returns TRUE on success else FALSE
145 */
146static BOOL PRINTDLG_GetDefaultPrinterNameA(LPSTR buf, DWORD len)
147{
148 char *ptr;
149
150 if(!GetProfileStringA("windows", "device", "", buf, len)) {
151 TRACE("No profile entry for default printer found.\n");
152 return FALSE;
153 }
154 if((ptr = strchr(buf, ',')) == NULL) {
155 FIXME("bad format for default printer (%s)!\n",buf);
156 return FALSE;
157 }
158 *ptr = '\0';
159 return TRUE;
160}
161
162static BOOL PRINTDLG_GetDefaultPrinterNameW(LPWSTR buf, DWORD len)
163{
164 LPSTR ptr, bufA = (LPSTR)HeapAlloc(GetProcessHeap(),0,len+1);
165
166
167 if(!GetProfileStringA("windows", "device", "", bufA, len)) {
168 TRACE("No profile entry for default printer found.\n");
169 HeapFree(GetProcessHeap(),0,bufA);
170 return FALSE;
171 }
172 if((ptr = strchr(bufA, ',')) == NULL) {
173 FIXME("bad format for default printer (%s)!\n",bufA);
174 HeapFree(GetProcessHeap(),0,bufA);
175 return FALSE;
176 }
177 *ptr = '\0';
178 MultiByteToWideChar( CP_ACP, 0, bufA, -1, buf, len );
179 HeapFree(GetProcessHeap(),0,bufA);
180 return TRUE;
181}
182
183/***********************************************************************
184 * PRINTDLG_OpenDefaultPrinter
185 *
186 * Returns a winspool printer handle to the default printer in *hprn
187 * Caller must call ClosePrinter on the handle
188 *
189 * Returns TRUE on success else FALSE
190 */
191static BOOL PRINTDLG_OpenDefaultPrinter(HANDLE *hprn)
192{
193 char buf[260];
194 BOOL res;
195 if(!PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf)))
196 return FALSE;
197 res = OpenPrinterA(buf, hprn, NULL);
198 if (!res)
199 FIXME("Could not open printer %s?!\n",buf);
200 return res;
201}
202
203/***********************************************************************
204 * PRINTDLG_SetUpPrinterListCombo
205 *
206 * Initializes printer list combox.
207 * hDlg: HWND of dialog
208 * id: Control id of combo
209 * name: Name of printer to select
210 *
211 * Initializes combo with list of available printers. Selects printer 'name'
212 * If name is NULL or does not exist select the default printer.
213 *
214 * Returns number of printers added to list.
215 */
216static INT PRINTDLG_SetUpPrinterListComboA(HWND hDlg, UINT id, LPCSTR name)
217{
218 DWORD needed, num;
219 INT i;
220 LPPRINTER_INFO_2A pi;
221
222 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
223 pi = HeapAlloc(GetProcessHeap(), 0, needed);
224 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
225 &num);
226
227 for(i = 0; i < num; i++) {
228 SendDlgItemMessageA(hDlg, id, CB_ADDSTRING, 0,
229 (LPARAM)pi[i].pPrinterName );
230 }
231 HeapFree(GetProcessHeap(), 0, pi);
232
233 if(!name ||
234 (i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1,
235 (LPARAM)name)) == CB_ERR) {
236 char buf[260];
237 FIXME("Can't find '%s' in printer list so trying to find default\n",
238 name);
239 if(!PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf)))
240 return num;
241 i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
242
243 if(i == CB_ERR)
244 FIXME("Can't find default printer in printer list\n");
245 }
246 SendDlgItemMessageA(hDlg, id, CB_SETCURSEL, i, 0);
247 return num;
248}
249
250static INT PRINTDLG_SetUpPrinterListComboW(HWND hDlg, UINT id, LPCWSTR name)
251{
252 DWORD needed, num;
253 INT i;
254 LPPRINTER_INFO_2W pi;
255 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
256 pi = HeapAlloc(GetProcessHeap(), 0, needed);
257 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
258 &num);
259
260 for(i = 0; i < num; i++) {
261 SendDlgItemMessageW(hDlg, id, CB_ADDSTRING, 0,
262 (LPARAM)pi[i].pPrinterName );
263 }
264 HeapFree(GetProcessHeap(), 0, pi);
265 if(!name ||
266 (i = SendDlgItemMessageW(hDlg, id, CB_FINDSTRINGEXACT, -1,
267 (LPARAM)name)) == CB_ERR) {
268
269 /* ansi is ok */
270 char buf[260];
271 FIXME("Can't find '%s' in printer list so trying to find default\n",
272 debugstr_w(name));
273 if(!PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf)))
274 return num;
275 i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
276 if(i == CB_ERR)
277 FIXME("Can't find default printer in printer list\n");
278 }
279 SendDlgItemMessageW(hDlg, id, CB_SETCURSEL, i, 0);
280 return num;
281}
282
283/***********************************************************************
284 * PRINTDLG_CreateDevNames [internal]
285 *
286 *
287 * creates a DevNames structure.
288 *
289 * (NB. when we handle unicode the offsets will be in wchars).
290 */
291static BOOL PRINTDLG_CreateDevNames(HGLOBAL *hmem, char* DeviceDriverName,
292 char* DeviceName, char* OutputPort)
293{
294 long size;
295 char* pDevNamesSpace;
296 char* pTempPtr;
297 LPDEVNAMES lpDevNames;
298 char buf[260];
299
300 size = strlen(DeviceDriverName) + 1
301 + strlen(DeviceName) + 1
302 + strlen(OutputPort) + 1
303 + sizeof(DEVNAMES);
304
305 if(*hmem)
306 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
307 else
308 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
309 if (*hmem == 0)
310 return FALSE;
311
312 pDevNamesSpace = GlobalLock(*hmem);
313 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
314
315 pTempPtr = pDevNamesSpace + sizeof(DEVNAMES);
316 strcpy(pTempPtr, DeviceDriverName);
317 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
318
319 pTempPtr += strlen(DeviceDriverName) + 1;
320 strcpy(pTempPtr, DeviceName);
321 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
322
323 pTempPtr += strlen(DeviceName) + 1;
324 strcpy(pTempPtr, OutputPort);
325 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
326
327 PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf));
328 lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
329 GlobalUnlock(*hmem);
330 return TRUE;
331}
332
333static BOOL PRINTDLG_CreateDevNamesW(HGLOBAL *hmem, LPCWSTR DeviceDriverName,
334 LPCWSTR DeviceName, LPCWSTR OutputPort)
335{
336 long size;
337 LPWSTR pDevNamesSpace;
338 LPWSTR pTempPtr;
339 LPDEVNAMES lpDevNames;
340 WCHAR bufW[260];
341 char buf[260];
342
343 size = sizeof(WCHAR)*lstrlenW(DeviceDriverName) + 2
344 + sizeof(WCHAR)*lstrlenW(DeviceName) + 2
345 + sizeof(WCHAR)*lstrlenW(OutputPort) + 2
346 + sizeof(DEVNAMES);
347
348 if(*hmem)
349 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
350 else
351 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
352 if (*hmem == 0)
353 return FALSE;
354
355 pDevNamesSpace = GlobalLock(*hmem);
356 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
357
358 pTempPtr = (LPWSTR)((LPDEVNAMES)pDevNamesSpace + 1);
359 lstrcpyW(pTempPtr, DeviceDriverName);
360 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
361
362 pTempPtr += lstrlenW(DeviceDriverName) + 1;
363 lstrcpyW(pTempPtr, DeviceName);
364 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
365
366 pTempPtr += lstrlenW(DeviceName) + 1;
367 lstrcpyW(pTempPtr, OutputPort);
368 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
369
370 PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf));
371 MultiByteToWideChar(CP_ACP, 0, buf, -1, bufW, -1);
372 lpDevNames->wDefault = (lstrcmpW(bufW, DeviceName) == 0) ? 1 : 0;
373 GlobalUnlock(*hmem);
374 return TRUE;
375}
376
377
378#ifndef __WIN32OS2__
379static BOOL PRINTDLG_CreateDevNames16(HGLOBAL16 *hmem, char* DeviceDriverName,
380 char* DeviceName, char* OutputPort)
381{
382 long size;
383 char* pDevNamesSpace;
384 char* pTempPtr;
385 LPDEVNAMES lpDevNames;
386 char buf[260];
387
388 size = strlen(DeviceDriverName) + 1
389 + strlen(DeviceName) + 1
390 + strlen(OutputPort) + 1
391 + sizeof(DEVNAMES);
392
393 if(*hmem)
394 *hmem = GlobalReAlloc16(*hmem, size, GMEM_MOVEABLE);
395 else
396 *hmem = GlobalAlloc16(GMEM_MOVEABLE, size);
397 if (*hmem == 0)
398 return FALSE;
399
400 pDevNamesSpace = GlobalLock16(*hmem);
401 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
402
403 pTempPtr = pDevNamesSpace + sizeof(DEVNAMES);
404 strcpy(pTempPtr, DeviceDriverName);
405 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
406
407 pTempPtr += strlen(DeviceDriverName) + 1;
408 strcpy(pTempPtr, DeviceName);
409 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
410
411 pTempPtr += strlen(DeviceName) + 1;
412 strcpy(pTempPtr, OutputPort);
413 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
414
415 PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf));
416 lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
417 GlobalUnlock16(*hmem);
418 return TRUE;
419}
420#endif
421
422/***********************************************************************
423 * PRINTDLG_UpdatePrintDlg [internal]
424 *
425 *
426 * updates the PrintDlg structure for returnvalues.
427 *
428 * RETURNS
429 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
430 * TRUE if succesful.
431 */
432static BOOL PRINTDLG_UpdatePrintDlgA(HWND hDlg,
433 PRINT_PTRA* PrintStructures)
434{
435 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
436 PDEVMODEA lpdm = PrintStructures->lpDevMode;
437 LPPRINTER_INFO_2A pi = PrintStructures->lpPrinterInfo;
438
439
440 if(!lpdm) {
441 FIXME("No lpdm ptr?\n");
442 return FALSE;
443 }
444
445
446 if(!(lppd->Flags & PD_PRINTSETUP)) {
447 /* check whether nFromPage and nToPage are within range defined by
448 * nMinPage and nMaxPage
449 */
450 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
451 WORD nToPage;
452 WORD nFromPage;
453 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
454 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
455 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
456 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
457 char resourcestr[256];
458 char resultstr[256];
459 LoadStringA(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
460 resourcestr, 255);
461 sprintf(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
462 LoadStringA(COMDLG32_hInstance, PD32_PRINT_TITLE,
463 resourcestr, 255);
464 MessageBoxA(hDlg, resultstr, resourcestr,
465 MB_OK | MB_ICONWARNING);
466 return FALSE;
467 }
468 lppd->nFromPage = nFromPage;
469 lppd->nToPage = nToPage;
470 lppd->Flags |= PD_PAGENUMS;
471 }
472 else
473 lppd->Flags &= ~PD_PAGENUMS;
474
475 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
476 lppd->Flags |= PD_PRINTTOFILE;
477 pi->pPortName = "FILE:";
478 }
479
480 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
481 FIXME("Collate lppd not yet implemented as output\n");
482 }
483
484 /* set PD_Collate and nCopies */
485 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
486 /* The application doesn't support multiple copies or collate...
487 */
488 lppd->Flags &= ~PD_COLLATE;
489 lppd->nCopies = 1;
490 /* if the printer driver supports it... store info there
491 * otherwise no collate & multiple copies !
492 */
493 if (lpdm->dmFields & DM_COLLATE)
494 lpdm->dmCollate =
495 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
496 if (lpdm->dmFields & DM_COPIES)
497 lpdm->dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
498 } else {
499 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
500 lppd->Flags |= PD_COLLATE;
501 else
502 lppd->Flags &= ~PD_COLLATE;
503 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
504 }
505 }
506 return TRUE;
507}
508
509static BOOL PRINTDLG_UpdatePrintDlgW(HWND hDlg,
510 PRINT_PTRW* PrintStructures)
511{
512 LPPRINTDLGW lppd = PrintStructures->dlg.lpPrintDlg;
513 PDEVMODEW lpdm = PrintStructures->lpDevMode;
514 LPPRINTER_INFO_2W pi = PrintStructures->lpPrinterInfo;
515
516
517 if(!lpdm) {
518 FIXME("No lpdm ptr?\n");
519 return FALSE;
520 }
521
522
523 if(!(lppd->Flags & PD_PRINTSETUP)) {
524 /* check whether nFromPage and nToPage are within range defined by
525 * nMinPage and nMaxPage
526 */
527 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
528 WORD nToPage;
529 WORD nFromPage;
530 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
531 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
532 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
533 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
534 char resourcestr[256];
535 char resultstr[256];
536 LoadStringA(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
537 resourcestr, 255);
538 sprintf(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
539 LoadStringA(COMDLG32_hInstance, PD32_PRINT_TITLE,
540 resourcestr, 255);
541 MessageBoxA(hDlg, resultstr, resourcestr,
542 MB_OK | MB_ICONWARNING);
543 return FALSE;
544 }
545 lppd->nFromPage = nFromPage;
546 lppd->nToPage = nToPage;
547 }
548
549 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
550 static WCHAR file[] = {'F','I','L','E',':',0};
551 lppd->Flags |= PD_PRINTTOFILE;
552 pi->pPortName = file;
553 }
554
555 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
556 FIXME("Collate lppd not yet implemented as output\n");
557 }
558
559 /* set PD_Collate and nCopies */
560 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
561 /* The application doesn't support multiple copies or collate...
562 */
563 lppd->Flags &= ~PD_COLLATE;
564 lppd->nCopies = 1;
565 /* if the printer driver supports it... store info there
566 * otherwise no collate & multiple copies !
567 */
568 if (lpdm->dmFields & DM_COLLATE)
569 lpdm->dmCollate =
570 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
571 if (lpdm->dmFields & DM_COPIES)
572 lpdm->dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
573 } else {
574 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
575 lppd->Flags |= PD_COLLATE;
576 else
577 lppd->Flags &= ~PD_COLLATE;
578 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
579 }
580 }
581 return TRUE;
582}
583
584static BOOL PRINTDLG_PaperSizeA(
585 PRINTDLGA *pdlga,const char *PaperSize,LPPOINT size
586) {
587 DEVNAMES *dn;
588 DEVMODEA *dm;
589 LPSTR devname,portname;
590 int i;
591 INT NrOfEntries,ret;
592 char *Names = NULL;
593 POINT *points = NULL;
594 BOOL retval = FALSE;
595
596 dn = GlobalLock(pdlga->hDevNames);
597 dm = GlobalLock(pdlga->hDevMode);
598 devname = ((char*)dn)+dn->wDeviceOffset;
599 portname = ((char*)dn)+dn->wOutputOffset;
600
601
602 NrOfEntries = DeviceCapabilitiesA(devname,portname,DC_PAPERNAMES,NULL,dm);
603 if (!NrOfEntries) {
604 FIXME("No papernames found for %s/%s\n",devname,portname);
605 goto out;
606 }
607 if (NrOfEntries == -1) {
608 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
609 goto out;
610 }
611
612 Names = (char*)HeapAlloc(GetProcessHeap(),0,NrOfEntries*64);
613 if (NrOfEntries != (ret=DeviceCapabilitiesA(devname,portname,DC_PAPERNAMES,Names,dm))) {
614 FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
615 goto out;
616 }
617 for (i=0;i<NrOfEntries;i++)
618 if (!strcmp(PaperSize,Names+(64*i)))
619 break;
620 HeapFree(GetProcessHeap(),0,Names);
621 if (i==NrOfEntries) {
622 FIXME("Papersize %s not found in list?\n",PaperSize);
623 goto out;
624 }
625 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
626 if (NrOfEntries!=(ret=DeviceCapabilitiesA(devname,portname,DC_PAPERSIZE,(LPBYTE)points,dm))) {
627 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
628 goto out;
629 }
630 /* this is _10ths_ of a millimeter */
631 size->x=points[i].x;
632 size->y=points[i].y;
633 retval = TRUE;
634out:
635 GlobalUnlock(pdlga->hDevNames);
636 GlobalUnlock(pdlga->hDevMode);
637 if (Names) HeapFree(GetProcessHeap(),0,Names);
638 if (points) HeapFree(GetProcessHeap(),0,points);
639 return retval;
640}
641
642static BOOL PRINTDLG_PaperSizeW(
643 PRINTDLGW *pdlga,const WCHAR *PaperSize,LPPOINT size
644) {
645 DEVNAMES *dn;
646 DEVMODEW *dm;
647 LPWSTR devname,portname;
648 int i;
649 INT NrOfEntries,ret;
650 WCHAR *Names = NULL;
651 POINT *points = NULL;
652 BOOL retval = FALSE;
653
654 dn = GlobalLock(pdlga->hDevNames);
655 dm = GlobalLock(pdlga->hDevMode);
656 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
657 portname = ((WCHAR*)dn)+dn->wOutputOffset;
658
659
660 NrOfEntries = DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,NULL,dm);
661 if (!NrOfEntries) {
662 FIXME("No papernames found for %s/%s\n",debugstr_w(devname),debugstr_w(portname));
663 goto out;
664 }
665 if (NrOfEntries == -1) {
666 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
667 goto out;
668 }
669
670 Names = (WCHAR*)HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*NrOfEntries*64);
671 if (NrOfEntries != (ret=DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,Names,dm))) {
672 FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
673 goto out;
674 }
675 for (i=0;i<NrOfEntries;i++)
676 if (!lstrcmpW(PaperSize,Names+(64*i)))
677 break;
678 HeapFree(GetProcessHeap(),0,Names);
679 if (i==NrOfEntries) {
680 FIXME("Papersize %s not found in list?\n",debugstr_w(PaperSize));
681 goto out;
682 }
683 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
684 if (NrOfEntries!=(ret=DeviceCapabilitiesW(devname,portname,DC_PAPERSIZE,(LPWSTR)points,dm))) {
685 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
686 goto out;
687 }
688 /* this is _10ths_ of a millimeter */
689 size->x=points[i].x;
690 size->y=points[i].y;
691 retval = TRUE;
692out:
693 GlobalUnlock(pdlga->hDevNames);
694 GlobalUnlock(pdlga->hDevMode);
695 if (Names) HeapFree(GetProcessHeap(),0,Names);
696 if (points) HeapFree(GetProcessHeap(),0,points);
697 return retval;
698}
699
700
701/************************************************************************
702 * PRINTDLG_SetUpPaperComboBox
703 *
704 * Initialize either the papersize or inputslot combos of the Printer Setup
705 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
706 * We also try to re-select the old selection.
707 */
708static BOOL PRINTDLG_SetUpPaperComboBoxA(HWND hDlg,
709 int nIDComboBox,
710 char* PrinterName,
711 char* PortName,
712 LPDEVMODEA dm)
713{
714 int i;
715 int NrOfEntries;
716 char* Names;
717 WORD* Words;
718 DWORD Sel;
719 WORD oldWord = 0;
720 int NamesSize;
721 int fwCapability_Names;
722 int fwCapability_Words;
723
724 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName,PortName,nIDComboBox);
725
726 /* query the dialog box for the current selected value */
727 Sel = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
728 if(Sel != CB_ERR) {
729 /* we enter here only if a different printer is selected after
730 * the Print Setup dialog is opened. The current settings are
731 * stored into the newly selected printer.
732 */
733 oldWord = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA,
734 Sel, 0);
735 if (dm) {
736 if (nIDComboBox == cmb2)
737 dm->u1.s1.dmPaperSize = oldWord;
738 else
739 dm->dmDefaultSource = oldWord;
740 }
741 }
742 else {
743 /* we enter here only when the Print setup dialog is initially
744 * opened. In this case the settings are restored from when
745 * the dialog was last closed.
746 */
747 if (dm) {
748 if (nIDComboBox == cmb2)
749 oldWord = dm->u1.s1.dmPaperSize;
750 else
751 oldWord = dm->dmDefaultSource;
752 }
753 }
754
755 if (nIDComboBox == cmb2) {
756 NamesSize = 64;
757 fwCapability_Names = DC_PAPERNAMES;
758 fwCapability_Words = DC_PAPERS;
759 } else {
760 nIDComboBox = cmb3;
761 NamesSize = 24;
762 fwCapability_Names = DC_BINNAMES;
763 fwCapability_Words = DC_BINS;
764 }
765
766 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
767 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
768 */
769 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
770 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
771 fwCapability_Names, NULL, dm);
772 if (NrOfEntries == 0)
773 WARN("no Name Entries found!\n");
774 else if (NrOfEntries < 0)
775 return FALSE;
776
777 if(DeviceCapabilitiesA(PrinterName, PortName, fwCapability_Words, NULL, dm)
778 != NrOfEntries) {
779 ERR("Number of caps is different\n");
780 NrOfEntries = 0;
781 }
782
783 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(char)*NamesSize);
784 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
785 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
786 fwCapability_Names, Names, dm);
787 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
788 fwCapability_Words, (LPSTR)Words, dm);
789
790 /* reset any current content in the combobox */
791 SendDlgItemMessageA(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
792
793 /* store new content */
794 for (i = 0; i < NrOfEntries; i++) {
795 DWORD pos = SendDlgItemMessageA(hDlg, nIDComboBox, CB_ADDSTRING, 0,
796 (LPARAM)(&Names[i*NamesSize]) );
797 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
798 Words[i]);
799 }
800
801 /* Look for old selection - can't do this is previous loop since
802 item order will change as more items are added */
803 Sel = 0;
804 for (i = 0; i < NrOfEntries; i++) {
805 if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
806 oldWord) {
807 Sel = i;
808 break;
809 }
810 }
811 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
812
813 HeapFree(GetProcessHeap(),0,Words);
814 HeapFree(GetProcessHeap(),0,Names);
815 return TRUE;
816}
817
818static BOOL PRINTDLG_SetUpPaperComboBoxW(HWND hDlg,
819 int nIDComboBox,
820 WCHAR* PrinterName,
821 WCHAR* PortName,
822 LPDEVMODEW dm)
823{
824 int i;
825 int NrOfEntries;
826 WCHAR* Names;
827 WORD* Words;
828 DWORD Sel;
829 WORD oldWord = 0;
830 int NamesSize;
831 int fwCapability_Names;
832 int fwCapability_Words;
833
834 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName),debugstr_w(PortName),nIDComboBox);
835
836 /* query the dialog box for the current selected value */
837 Sel = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
838 if(Sel != CB_ERR) {
839 /* we enter here only if a different printer is selected after
840 * the Print Setup dialog is opened. The current settings are
841 * stored into the newly selected printer.
842 */
843 oldWord = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA,
844 Sel, 0);
845 if (dm) {
846 if (nIDComboBox == cmb2)
847 dm->u1.s1.dmPaperSize = oldWord;
848 else
849 dm->dmDefaultSource = oldWord;
850 }
851 }
852 else {
853 /* we enter here only when the Print setup dialog is initially
854 * opened. In this case the settings are restored from when
855 * the dialog was last closed.
856 */
857 if (dm) {
858 if (nIDComboBox == cmb2)
859 oldWord = dm->u1.s1.dmPaperSize;
860 else
861 oldWord = dm->dmDefaultSource;
862 }
863 }
864
865 if (nIDComboBox == cmb2) {
866 NamesSize = 64;
867 fwCapability_Names = DC_PAPERNAMES;
868 fwCapability_Words = DC_PAPERS;
869 } else {
870 nIDComboBox = cmb3;
871 NamesSize = 24;
872 fwCapability_Names = DC_BINNAMES;
873 fwCapability_Words = DC_BINS;
874 }
875
876 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
877 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
878 */
879 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
880 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
881 fwCapability_Names, NULL, dm);
882 if (NrOfEntries == 0)
883 WARN("no Name Entries found!\n");
884 else if (NrOfEntries < 0)
885 return FALSE;
886
887 if(DeviceCapabilitiesW(PrinterName, PortName, fwCapability_Words, NULL, dm)
888 != NrOfEntries) {
889 ERR("Number of caps is different\n");
890 NrOfEntries = 0;
891 }
892
893 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WCHAR)*NamesSize);
894 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
895 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
896 fwCapability_Names, Names, dm);
897 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
898 fwCapability_Words, (LPWSTR)Words, dm);
899
900 /* reset any current content in the combobox */
901 SendDlgItemMessageA(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
902
903 /* store new content */
904 for (i = 0; i < NrOfEntries; i++) {
905 DWORD pos = SendDlgItemMessageW(hDlg, nIDComboBox, CB_ADDSTRING, 0,
906 (LPARAM)(&Names[i*NamesSize]) );
907 SendDlgItemMessageW(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
908 Words[i]);
909 }
910
911 /* Look for old selection - can't do this is previous loop since
912 item order will change as more items are added */
913 Sel = 0;
914 for (i = 0; i < NrOfEntries; i++) {
915 if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
916 oldWord) {
917 Sel = i;
918 break;
919 }
920 }
921 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
922
923 HeapFree(GetProcessHeap(),0,Words);
924 HeapFree(GetProcessHeap(),0,Names);
925 return TRUE;
926}
927
928
929/***********************************************************************
930 * PRINTDLG_UpdatePrinterInfoTexts [internal]
931 */
932static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg, LPPRINTER_INFO_2A pi)
933{
934 char StatusMsg[256];
935 char ResourceString[256];
936 int i;
937
938 /* Status Message */
939 StatusMsg[0]='\0';
940
941 /* add all status messages */
942 for (i = 0; i < 25; i++) {
943 if (pi->Status & (1<<i)) {
944 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
945 ResourceString, 255);
946 strcat(StatusMsg,ResourceString);
947 }
948 }
949 /* append "ready" */
950 /* FIXME: status==ready must only be appended if really so.
951 but how to detect? */
952 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
953 ResourceString, 255);
954 strcat(StatusMsg,ResourceString);
955
956 SendDlgItemMessageA(hDlg, stc12, WM_SETTEXT, 0, (LPARAM)StatusMsg);
957
958 /* set all other printer info texts */
959 SendDlgItemMessageA(hDlg, stc11, WM_SETTEXT, 0, (LPARAM)pi->pDriverName);
960 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
961 SendDlgItemMessageA(hDlg, stc14, WM_SETTEXT, 0,(LPARAM)pi->pLocation);
962 else
963 SendDlgItemMessageA(hDlg, stc14, WM_SETTEXT, 0,(LPARAM)pi->pPortName);
964 SendDlgItemMessageA(hDlg, stc13, WM_SETTEXT, 0, (LPARAM)(pi->pComment ?
965 pi->pComment : ""));
966 return;
967}
968
969static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg, LPPRINTER_INFO_2W pi)
970{
971 WCHAR StatusMsg[256];
972 WCHAR ResourceString[256];
973 int i;
974
975 /* Status Message */
976 StatusMsg[0]='\0';
977
978 /* add all status messages */
979 for (i = 0; i < 25; i++) {
980 if (pi->Status & (1<<i)) {
981 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
982 ResourceString, 255);
983 lstrcatW(StatusMsg,ResourceString);
984 }
985 }
986 /* append "ready" */
987 /* FIXME: status==ready must only be appended if really so.
988 but how to detect? */
989 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
990 ResourceString, 255);
991 lstrcatW(StatusMsg,ResourceString);
992
993 SendDlgItemMessageW(hDlg, stc12, WM_SETTEXT, 0, (LPARAM)StatusMsg);
994
995 /* set all other printer info texts */
996 SendDlgItemMessageW(hDlg, stc11, WM_SETTEXT, 0, (LPARAM)pi->pDriverName);
997 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
998 SendDlgItemMessageW(hDlg, stc14, WM_SETTEXT, 0,(LPARAM)pi->pLocation);
999 else
1000 SendDlgItemMessageW(hDlg, stc14, WM_SETTEXT, 0,(LPARAM)pi->pPortName);
1001 SendDlgItemMessageW(hDlg, stc13, WM_SETTEXT, 0, (LPARAM)(pi->pComment ?
1002 pi->pComment : (LPCWSTR)"\0\0"));
1003 return;
1004}
1005
1006
1007/*******************************************************************
1008 *
1009 * PRINTDLG_ChangePrinter
1010 *
1011 */
1012static BOOL PRINTDLG_ChangePrinterA(HWND hDlg, char *name,
1013 PRINT_PTRA *PrintStructures)
1014{
1015 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
1016 LPDEVMODEA lpdm = NULL;
1017 LONG dmSize;
1018 DWORD needed;
1019 HANDLE hprn;
1020
1021 if(PrintStructures->lpPrinterInfo)
1022 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
1023 if(PrintStructures->lpDriverInfo)
1024 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
1025 if(!OpenPrinterA(name, &hprn, NULL)) {
1026 ERR("Can't open printer %s\n", name);
1027 return FALSE;
1028 }
1029 GetPrinterA(hprn, 2, NULL, 0, &needed);
1030 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,needed);
1031 GetPrinterA(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
1032 &needed);
1033 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
1034 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,needed);
1035 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
1036 needed, &needed)) {
1037 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures->lpPrinterInfo->pPrinterName);
1038 return FALSE;
1039 }
1040#ifndef __WIN32OS2__
1041 ClosePrinter(hprn);
1042#endif
1043
1044 PRINTDLG_UpdatePrinterInfoTextsA(hDlg, PrintStructures->lpPrinterInfo);
1045
1046 if(PrintStructures->lpDevMode) {
1047 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
1048 PrintStructures->lpDevMode = NULL;
1049 }
1050
1051#ifdef __WIN32OS2__
1052 dmSize = DocumentPropertiesA(0, hprn, name, NULL, NULL, 0);
1053#else
1054 dmSize = DocumentPropertiesA(0, 0, name, NULL, NULL, 0);
1055#endif
1056 if(dmSize == -1) {
1057 ERR("DocumentProperties fails on %s\n", debugstr_a(name));
1058 return FALSE;
1059 }
1060 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
1061
1062#ifdef __WIN32OS2__
1063 dmSize = DocumentPropertiesA(0, hprn, name, PrintStructures->lpDevMode, NULL,
1064#else
1065 dmSize = DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, NULL,
1066#endif
1067 DM_OUT_BUFFER);
1068
1069 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
1070 !strcmp(lpdm->dmDeviceName,
1071 PrintStructures->lpDevMode->dmDeviceName)) {
1072 /* Supplied devicemode matches current printer so try to use it */
1073#ifdef __WIN32OS2__
1074 DocumentPropertiesA(0, hprn, name, PrintStructures->lpDevMode, lpdm,
1075#else
1076 DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, lpdm,
1077#endif
1078 DM_OUT_BUFFER | DM_IN_BUFFER);
1079 }
1080#ifdef __WIN32OS2__
1081 ClosePrinter(hprn);
1082#endif
1083 if(lpdm)
1084 GlobalUnlock(lppd->hDevMode);
1085
1086#ifdef __WIN32OS2__
1087 //Yes, we need to update the device names in the printer dialog structure
1088 //Some applications actually rely on that to change when the user chooses
1089 //another printer
1090 {
1091 DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
1092 PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
1093 DRIVER_INFO_3A *di = PrintStructures->lpDriverInfo;
1094
1095 if (lppd->hDevNames != 0) {
1096 WORD locks;
1097 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
1098 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
1099 while(locks--)
1100 GlobalUnlock(lppd->hDevNames);
1101 }
1102 }
1103 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
1104 di->pDriverPath,
1105 pi->pPrinterName,
1106 pi->pPortName
1107 );
1108 }
1109#endif
1110
1111 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
1112
1113 if(!(lppd->Flags & PD_PRINTSETUP)) {
1114 /* Print range (All/Range/Selection) */
1115 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
1116 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
1117 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
1118 if (lppd->Flags & PD_NOSELECTION)
1119 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
1120 else
1121 if (lppd->Flags & PD_SELECTION)
1122 CheckRadioButton(hDlg, rad1, rad3, rad2);
1123 if (lppd->Flags & PD_NOPAGENUMS) {
1124 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
1125 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
1126 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
1127 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
1128 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
1129 } else {
1130 if (lppd->Flags & PD_PAGENUMS)
1131 CheckRadioButton(hDlg, rad1, rad3, rad3);
1132 }
1133 /* "All xxx pages"... */
1134 {
1135 char resourcestr[64];
1136 char result[64];
1137 LoadStringA(COMDLG32_hInstance, PD32_PRINT_ALL_X_PAGES,
1138 resourcestr, 49);
1139 sprintf(result,resourcestr,lppd->nMaxPage - lppd->nMinPage + 1);
1140 SendDlgItemMessageA(hDlg, rad1, WM_SETTEXT, 0, (LPARAM) result);
1141 }
1142
1143 /* Collate pages
1144 *
1145 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1146 */
1147 if (lppd->Flags & PD_COLLATE) {
1148 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1149 (LPARAM)PrintStructures->hCollateIcon);
1150 CheckDlgButton(hDlg, chx2, 1);
1151 } else {
1152 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1153 (LPARAM)PrintStructures->hNoCollateIcon);
1154 CheckDlgButton(hDlg, chx2, 0);
1155 }
1156
1157 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1158#ifdef __WIN32OS2__
1159 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1160 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
1161 ShowWindow(GetDlgItem(hDlg, chx2), SW_HIDE);
1162#else
1163 /* if printer doesn't support it: no Collate */
1164 if (!(lpdm->dmFields & DM_COLLATE)) {
1165 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1166 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
1167 }
1168#endif
1169 }
1170
1171 /* nCopies */
1172 {
1173 INT copies;
1174 if (lppd->hDevMode == 0)
1175 copies = lppd->nCopies;
1176 else
1177 copies = lpdm->dmCopies;
1178 if(copies == 0) copies = 1;
1179 else if(copies < 0) copies = MAX_COPIES;
1180 SetDlgItemInt(hDlg, edt3, copies, FALSE);
1181 }
1182
1183 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1184 /* if printer doesn't support it: no nCopies */
1185 if (!(lpdm->dmFields & DM_COPIES)) {
1186 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
1187 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
1188 }
1189 }
1190
1191 /* print to file */
1192 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
1193 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
1194 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
1195 if (lppd->Flags & PD_HIDEPRINTTOFILE)
1196 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
1197
1198 } else { /* PD_PRINTSETUP */
1199 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
1200
1201 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb2,
1202 PrintStructures->lpPrinterInfo->pPrinterName,
1203 PrintStructures->lpPrinterInfo->pPortName,
1204 lpdm);
1205 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb3,
1206 PrintStructures->lpPrinterInfo->pPrinterName,
1207 PrintStructures->lpPrinterInfo->pPortName,
1208 lpdm);
1209 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1210 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1211 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1212 PrintStructures->hLandscapeIcon));
1213
1214 }
1215
1216 /* help button */
1217 if ((lppd->Flags & PD_SHOWHELP)==0) {
1218 /* hide if PD_SHOWHELP not specified */
1219 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1220 }
1221 return TRUE;
1222}
1223
1224static BOOL PRINTDLG_ChangePrinterW(HWND hDlg, WCHAR *name,
1225 PRINT_PTRW *PrintStructures)
1226{
1227 LPPRINTDLGW lppd = PrintStructures->dlg.lpPrintDlg;
1228 LPDEVMODEW lpdm = NULL;
1229 LONG dmSize;
1230 DWORD needed;
1231 HANDLE hprn;
1232
1233 if(PrintStructures->lpPrinterInfo)
1234 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
1235 if(PrintStructures->lpDriverInfo)
1236 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
1237 if(!OpenPrinterW(name, &hprn, NULL)) {
1238 ERR("Can't open printer %s\n", debugstr_w(name));
1239 return FALSE;
1240 }
1241 GetPrinterW(hprn, 2, NULL, 0, &needed);
1242 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
1243 GetPrinterW(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
1244 &needed);
1245 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
1246 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
1247 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
1248 needed, &needed)) {
1249 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures->lpPrinterInfo->pPrinterName));
1250 return FALSE;
1251 }
1252 ClosePrinter(hprn);
1253
1254 PRINTDLG_UpdatePrinterInfoTextsW(hDlg, PrintStructures->lpPrinterInfo);
1255
1256 if(PrintStructures->lpDevMode) {
1257 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
1258 PrintStructures->lpDevMode = NULL;
1259 }
1260
1261 dmSize = DocumentPropertiesW(0, 0, name, NULL, NULL, 0);
1262 if(dmSize == -1) {
1263 ERR("DocumentProperties fails on %s\n", debugstr_w(name));
1264 return FALSE;
1265 }
1266 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
1267 dmSize = DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, NULL,
1268 DM_OUT_BUFFER);
1269 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
1270 !lstrcmpW(lpdm->dmDeviceName,
1271 PrintStructures->lpDevMode->dmDeviceName)) {
1272 /* Supplied devicemode matches current printer so try to use it */
1273 DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, lpdm,
1274 DM_OUT_BUFFER | DM_IN_BUFFER);
1275 }
1276 if(lpdm)
1277 GlobalUnlock(lppd->hDevMode);
1278
1279 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
1280
1281 if(!(lppd->Flags & PD_PRINTSETUP)) {
1282 /* Print range (All/Range/Selection) */
1283 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
1284 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
1285 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
1286 if (lppd->Flags & PD_NOSELECTION)
1287 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
1288 else
1289 if (lppd->Flags & PD_SELECTION)
1290 CheckRadioButton(hDlg, rad1, rad3, rad2);
1291 if (lppd->Flags & PD_NOPAGENUMS) {
1292 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
1293 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
1294 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
1295 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
1296 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
1297 } else {
1298 if (lppd->Flags & PD_PAGENUMS)
1299 CheckRadioButton(hDlg, rad1, rad3, rad3);
1300 }
1301 /* "All xxx pages"... */
1302 {
1303 /* ansi is ok */
1304 char resourcestr[64];
1305 char result[64];
1306 LoadStringA(COMDLG32_hInstance, PD32_PRINT_ALL_X_PAGES,
1307 resourcestr, 49);
1308 sprintf(result,resourcestr,lppd->nMaxPage - lppd->nMinPage + 1);
1309 SendDlgItemMessageA(hDlg, rad1, WM_SETTEXT, 0, (LPARAM) result);
1310 }
1311
1312 /* Collate pages
1313 *
1314 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1315 */
1316 if (lppd->Flags & PD_COLLATE) {
1317 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1318 (LPARAM)PrintStructures->hCollateIcon);
1319 CheckDlgButton(hDlg, chx2, 1);
1320 } else {
1321 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1322 (LPARAM)PrintStructures->hNoCollateIcon);
1323 CheckDlgButton(hDlg, chx2, 0);
1324 }
1325
1326 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1327#ifdef __WIN32OS2__
1328 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1329 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
1330 ShowWindow(GetDlgItem(hDlg, chx2), SW_HIDE);
1331#else
1332 /* if printer doesn't support it: no Collate */
1333 if (!(lpdm->dmFields & DM_COLLATE)) {
1334 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1335 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
1336 }
1337#endif
1338 }
1339
1340 /* nCopies */
1341 {
1342 INT copies;
1343 if (lppd->hDevMode == 0)
1344 copies = lppd->nCopies;
1345 else
1346 copies = lpdm->dmCopies;
1347 if(copies == 0) copies = 1;
1348 else if(copies < 0) copies = MAX_COPIES;
1349 SetDlgItemInt(hDlg, edt3, copies, FALSE);
1350 }
1351
1352 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1353 /* if printer doesn't support it: no nCopies */
1354 if (!(lpdm->dmFields & DM_COPIES)) {
1355 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
1356 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
1357 }
1358 }
1359
1360 /* print to file */
1361 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
1362 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
1363 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
1364 if (lppd->Flags & PD_HIDEPRINTTOFILE)
1365 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
1366
1367 } else { /* PD_PRINTSETUP */
1368 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
1369
1370 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb2,
1371 PrintStructures->lpPrinterInfo->pPrinterName,
1372 PrintStructures->lpPrinterInfo->pPortName,
1373 lpdm);
1374 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb3,
1375 PrintStructures->lpPrinterInfo->pPrinterName,
1376 PrintStructures->lpPrinterInfo->pPortName,
1377 lpdm);
1378 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1379 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1380 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1381 PrintStructures->hLandscapeIcon));
1382
1383 }
1384
1385 /* help button */
1386 if ((lppd->Flags & PD_SHOWHELP)==0) {
1387 /* hide if PD_SHOWHELP not specified */
1388 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1389 }
1390 return TRUE;
1391}
1392
1393/***********************************************************************
1394 * PRINTDLG_WMInitDialog [internal]
1395 */
1396static LRESULT PRINTDLG_WMInitDialog(HWND hDlg, WPARAM wParam,
1397 PRINT_PTRA* PrintStructures)
1398{
1399 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
1400 DEVNAMES *pdn;
1401 DEVMODEA *pdm;
1402 char *name = NULL;
1403 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1404
1405 /* load Collate ICONs */
1406 /* We load these with LoadImage because they are not a standard
1407 size and we don't want them rescaled */
1408 PrintStructures->hCollateIcon =
1409 LoadImageA(COMDLG32_hInstance, "PD32_COLLATE", IMAGE_ICON, 0, 0, 0);
1410 PrintStructures->hNoCollateIcon =
1411 LoadImageA(COMDLG32_hInstance, "PD32_NOCOLLATE", IMAGE_ICON, 0, 0, 0);
1412
1413 /* These can be done with LoadIcon */
1414 PrintStructures->hPortraitIcon =
1415 LoadIconA(COMDLG32_hInstance, "PD32_PORTRAIT");
1416 PrintStructures->hLandscapeIcon =
1417 LoadIconA(COMDLG32_hInstance, "PD32_LANDSCAPE");
1418
1419 if(PrintStructures->hCollateIcon == 0 ||
1420 PrintStructures->hNoCollateIcon == 0 ||
1421 PrintStructures->hPortraitIcon == 0 ||
1422 PrintStructures->hLandscapeIcon == 0) {
1423 ERR("no icon in resourcefile\n");
1424 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1425 EndDialog(hDlg, FALSE);
1426 }
1427
1428 /*
1429 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1430 * must be registered and the Help button must be shown.
1431 */
1432 if (lppd->Flags & PD_SHOWHELP) {
1433 if((PrintStructures->HelpMessageID =
1434 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
1435 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1436 return FALSE;
1437 }
1438 } else
1439 PrintStructures->HelpMessageID = 0;
1440
1441 if(!(lppd->Flags &PD_PRINTSETUP)) {
1442 PrintStructures->hwndUpDown =
1443 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1444 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1445 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1446 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1447 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1448 }
1449
1450 /* FIXME: I allow more freedom than either Win95 or WinNT,
1451 * which do not agree to what errors should be thrown or not
1452 * in case nToPage or nFromPage is out-of-range.
1453 */
1454 if (lppd->nMaxPage < lppd->nMinPage)
1455 lppd->nMaxPage = lppd->nMinPage;
1456 if (lppd->nMinPage == lppd->nMaxPage)
1457 lppd->Flags |= PD_NOPAGENUMS;
1458 if (lppd->nToPage < lppd->nMinPage)
1459 lppd->nToPage = lppd->nMinPage;
1460 if (lppd->nToPage > lppd->nMaxPage)
1461 lppd->nToPage = lppd->nMaxPage;
1462 if (lppd->nFromPage < lppd->nMinPage)
1463 lppd->nFromPage = lppd->nMinPage;
1464 if (lppd->nFromPage > lppd->nMaxPage)
1465 lppd->nFromPage = lppd->nMaxPage;
1466
1467 /* if we have the combo box, fill it */
1468 if (GetDlgItem(hDlg,comboID)) {
1469 /* Fill Combobox
1470 */
1471 pdn = GlobalLock(lppd->hDevNames);
1472 pdm = GlobalLock(lppd->hDevMode);
1473 if(pdn)
1474 name = (char*)pdn + pdn->wDeviceOffset;
1475 else if(pdm)
1476 name = pdm->dmDeviceName;
1477 PRINTDLG_SetUpPrinterListComboA(hDlg, comboID, name);
1478 if(pdm) GlobalUnlock(lppd->hDevMode);
1479 if(pdn) GlobalUnlock(lppd->hDevNames);
1480
1481 /* Now find selected printer and update rest of dlg */
1482 name = HeapAlloc(GetProcessHeap(),0,256);
1483 if (GetDlgItemTextA(hDlg, comboID, name, 255))
1484 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1485 HeapFree(GetProcessHeap(),0,name);
1486 } else {
1487 /* else use default printer */
1488 char name[200];
1489 BOOL ret = PRINTDLG_GetDefaultPrinterNameA(name, sizeof(name));
1490 if (ret)
1491 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1492 else
1493 FIXME("No default printer found, expect problems!\n");
1494 }
1495 return TRUE;
1496}
1497
1498static LRESULT PRINTDLG_WMInitDialogW(HWND hDlg, WPARAM wParam,
1499 PRINT_PTRW* PrintStructures)
1500{
1501 LPPRINTDLGW lppd = PrintStructures->dlg.lpPrintDlg;
1502 DEVNAMES *pdn;
1503 DEVMODEW *pdm;
1504 WCHAR *name = NULL;
1505 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1506
1507 /* load Collate ICONs */
1508 /* We load these with LoadImage because they are not a standard
1509 size and we don't want them rescaled */
1510 PrintStructures->hCollateIcon =
1511 LoadImageA(COMDLG32_hInstance, "PD32_COLLATE", IMAGE_ICON, 0, 0, 0);
1512 PrintStructures->hNoCollateIcon =
1513 LoadImageA(COMDLG32_hInstance, "PD32_NOCOLLATE", IMAGE_ICON, 0, 0, 0);
1514
1515 /* These can be done with LoadIcon */
1516 PrintStructures->hPortraitIcon =
1517 LoadIconA(COMDLG32_hInstance, "PD32_PORTRAIT");
1518 PrintStructures->hLandscapeIcon =
1519 LoadIconA(COMDLG32_hInstance, "PD32_LANDSCAPE");
1520
1521 if(PrintStructures->hCollateIcon == 0 ||
1522 PrintStructures->hNoCollateIcon == 0 ||
1523 PrintStructures->hPortraitIcon == 0 ||
1524 PrintStructures->hLandscapeIcon == 0) {
1525 ERR("no icon in resourcefile\n");
1526 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1527 EndDialog(hDlg, FALSE);
1528 }
1529
1530 /*
1531 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1532 * must be registered and the Help button must be shown.
1533 */
1534 if (lppd->Flags & PD_SHOWHELP) {
1535 if((PrintStructures->HelpMessageID =
1536 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
1537 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1538 return FALSE;
1539 }
1540 } else
1541 PrintStructures->HelpMessageID = 0;
1542
1543 if(!(lppd->Flags &PD_PRINTSETUP)) {
1544 PrintStructures->hwndUpDown =
1545 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1546 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1547 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1548 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1549 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1550 }
1551
1552 /* FIXME: I allow more freedom than either Win95 or WinNT,
1553 * which do not agree to what errors should be thrown or not
1554 * in case nToPage or nFromPage is out-of-range.
1555 */
1556 if (lppd->nMaxPage < lppd->nMinPage)
1557 lppd->nMaxPage = lppd->nMinPage;
1558 if (lppd->nMinPage == lppd->nMaxPage)
1559 lppd->Flags |= PD_NOPAGENUMS;
1560 if (lppd->nToPage < lppd->nMinPage)
1561 lppd->nToPage = lppd->nMinPage;
1562 if (lppd->nToPage > lppd->nMaxPage)
1563 lppd->nToPage = lppd->nMaxPage;
1564 if (lppd->nFromPage < lppd->nMinPage)
1565 lppd->nFromPage = lppd->nMinPage;
1566 if (lppd->nFromPage > lppd->nMaxPage)
1567 lppd->nFromPage = lppd->nMaxPage;
1568
1569 /* if we have the combo box, fill it */
1570 if (GetDlgItem(hDlg,comboID)) {
1571 /* Fill Combobox
1572 */
1573 pdn = GlobalLock(lppd->hDevNames);
1574 pdm = GlobalLock(lppd->hDevMode);
1575 if(pdn)
1576 name = (WCHAR*)pdn + pdn->wDeviceOffset;
1577 else if(pdm)
1578 name = pdm->dmDeviceName;
1579 PRINTDLG_SetUpPrinterListComboW(hDlg, comboID, name);
1580 if(pdm) GlobalUnlock(lppd->hDevMode);
1581 if(pdn) GlobalUnlock(lppd->hDevNames);
1582
1583 /* Now find selected printer and update rest of dlg */
1584 /* ansi is ok here */
1585 name = HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR));
1586 if (GetDlgItemTextW(hDlg, comboID, name, 255))
1587 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1588 HeapFree(GetProcessHeap(),0,name);
1589 } else {
1590 /* else use default printer */
1591 WCHAR name[200];
1592 BOOL ret = PRINTDLG_GetDefaultPrinterNameW(name, sizeof(name));
1593
1594 if (ret)
1595 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1596 else
1597 FIXME("No default printer found, expect problems!\n");
1598 }
1599 return TRUE;
1600}
1601
1602#ifndef __WIN32OS2__
1603/***********************************************************************
1604 * PRINTDLG_WMInitDialog [internal]
1605 */
1606static LRESULT PRINTDLG_WMInitDialog16(HWND hDlg, WPARAM wParam,
1607 PRINT_PTRA* PrintStructures)
1608{
1609 LPPRINTDLG16 lppd = PrintStructures->dlg.lpPrintDlg16;
1610 DEVNAMES *pdn;
1611 DEVMODEA *pdm;
1612 char *name = NULL;
1613 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1614
1615 /* load Collate ICONs */
1616 PrintStructures->hCollateIcon =
1617 LoadIconA(COMDLG32_hInstance, "PD32_COLLATE");
1618 PrintStructures->hNoCollateIcon =
1619 LoadIconA(COMDLG32_hInstance, "PD32_NOCOLLATE");
1620 if(PrintStructures->hCollateIcon == 0 ||
1621 PrintStructures->hNoCollateIcon == 0) {
1622 ERR("no icon in resourcefile\n");
1623 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1624 EndDialog(hDlg, FALSE);
1625 }
1626
1627 /* load Paper Orientation ICON */
1628 /* FIXME: not implemented yet */
1629
1630 /*
1631 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1632 * must be registered and the Help button must be shown.
1633 */
1634 if (lppd->Flags & PD_SHOWHELP) {
1635 if((PrintStructures->HelpMessageID =
1636 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
1637 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1638 return FALSE;
1639 }
1640 } else
1641 PrintStructures->HelpMessageID = 0;
1642
1643 if (!(lppd->Flags & PD_PRINTSETUP)) {
1644 /* We have a print quality combo box. What shall we do? */
1645 if (GetDlgItem(hDlg,cmb1)) {
1646 char buf [20];
1647
1648 FIXME("Print quality only displaying currently.\n");
1649
1650 pdm = GlobalLock16(lppd->hDevMode);
1651 if(pdm) {
1652 switch (pdm->dmPrintQuality) {
1653 case DMRES_HIGH : strcpy(buf,"High");break;
1654 case DMRES_MEDIUM : strcpy(buf,"Medium");break;
1655 case DMRES_LOW : strcpy(buf,"Low");break;
1656 case DMRES_DRAFT : strcpy(buf,"Draft");break;
1657 case 0 : strcpy(buf,"Default");break;
1658 default : sprintf(buf,"%ddpi",pdm->dmPrintQuality);break;
1659 }
1660 GlobalUnlock16(lppd->hDevMode);
1661 } else
1662 strcpy(buf,"Default");
1663 SendDlgItemMessageA(hDlg,cmb1,CB_ADDSTRING,0,(LPARAM)buf);
1664 SendDlgItemMessageA(hDlg,cmb1,CB_SETCURSEL,0,0);
1665 EnableWindow(GetDlgItem(hDlg,cmb1),FALSE);
1666 }
1667 }
1668
1669 /* FIXME: I allow more freedom than either Win95 or WinNT,
1670 * which do not agree to what errors should be thrown or not
1671 * in case nToPage or nFromPage is out-of-range.
1672 */
1673 if (lppd->nMaxPage < lppd->nMinPage)
1674 lppd->nMaxPage = lppd->nMinPage;
1675 if (lppd->nMinPage == lppd->nMaxPage)
1676 lppd->Flags |= PD_NOPAGENUMS;
1677 if (lppd->nToPage < lppd->nMinPage)
1678 lppd->nToPage = lppd->nMinPage;
1679 if (lppd->nToPage > lppd->nMaxPage)
1680 lppd->nToPage = lppd->nMaxPage;
1681 if (lppd->nFromPage < lppd->nMinPage)
1682 lppd->nFromPage = lppd->nMinPage;
1683 if (lppd->nFromPage > lppd->nMaxPage)
1684 lppd->nFromPage = lppd->nMaxPage;
1685
1686 /* If the printer combo box is in the dialog, fill it */
1687 if (GetDlgItem(hDlg,comboID)) {
1688 /* Fill Combobox
1689 */
1690 pdn = GlobalLock16(lppd->hDevNames);
1691 pdm = GlobalLock16(lppd->hDevMode);
1692 if(pdn)
1693 name = (char*)pdn + pdn->wDeviceOffset;
1694 else if(pdm)
1695 name = pdm->dmDeviceName;
1696 PRINTDLG_SetUpPrinterListComboA(hDlg, comboID, name);
1697 if(pdm) GlobalUnlock16(lppd->hDevMode);
1698 if(pdn) GlobalUnlock16(lppd->hDevNames);
1699
1700 /* Now find selected printer and update rest of dlg */
1701 name = HeapAlloc(GetProcessHeap(),0,256);
1702 if (GetDlgItemTextA(hDlg, comboID, name, 255))
1703 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1704 } else {
1705 /* else just use default printer */
1706 char name[200];
1707 BOOL ret = PRINTDLG_GetDefaultPrinterNameA(name, sizeof(name));
1708
1709 if (ret)
1710 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1711 else
1712 FIXME("No default printer found, expect problems!\n");
1713 }
1714 HeapFree(GetProcessHeap(),0,name);
1715
1716 return TRUE;
1717}
1718#endif
1719/***********************************************************************
1720 * PRINTDLG_WMCommand [internal]
1721 */
1722static LRESULT PRINTDLG_WMCommandA(HWND hDlg, WPARAM wParam,
1723 LPARAM lParam, PRINT_PTRA* PrintStructures)
1724{
1725 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
1726 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1727 LPDEVMODEA lpdm = PrintStructures->lpDevMode;
1728
1729 switch (LOWORD(wParam)) {
1730 case IDOK:
1731 TRACE(" OK button was hit\n");
1732 if (PRINTDLG_UpdatePrintDlgA(hDlg, PrintStructures)!=TRUE) {
1733 FIXME("Update printdlg was not successful!\n");
1734 return(FALSE);
1735 }
1736 EndDialog(hDlg, TRUE);
1737 return(TRUE);
1738
1739 case IDCANCEL:
1740 TRACE(" CANCEL button was hit\n");
1741 EndDialog(hDlg, FALSE);
1742 return(FALSE);
1743
1744 case pshHelp:
1745 TRACE(" HELP button was hit\n");
1746 SendMessageA(lppd->hwndOwner, PrintStructures->HelpMessageID,
1747 (WPARAM) hDlg, (LPARAM) lppd);
1748 break;
1749#ifdef __WIN32OS2__
1750 //PF Surely we need to clear/set this flag during runtime as well!
1751 case chx1:
1752 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED)
1753 lppd->Flags |= PD_PRINTTOFILE;
1754 else
1755 lppd->Flags &= ~PD_PRINTTOFILE;
1756 break;
1757#endif
1758 case chx2: /* collate pages checkbox */
1759 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1760 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1761 (LPARAM)PrintStructures->hCollateIcon);
1762 else
1763 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1764 (LPARAM)PrintStructures->hNoCollateIcon);
1765 break;
1766 case edt1: /* from page nr editbox */
1767 case edt2: /* to page nr editbox */
1768 if (HIWORD(wParam)==EN_CHANGE) {
1769 WORD nToPage;
1770 WORD nFromPage;
1771 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1772 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1773 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1774 CheckRadioButton(hDlg, rad1, rad3, rad3);
1775 }
1776 break;
1777
1778 case edt3:
1779#ifndef __WIN32OS2__
1780 if(HIWORD(wParam) == EN_CHANGE) {
1781 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1782 if(copies <= 1)
1783 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1784 else
1785 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1786 }
1787#endif
1788 break;
1789
1790#ifndef __WIN32OS2__
1791 case psh1: /* Print Setup */
1792 {
1793 PRINTDLG16 pdlg;
1794
1795 if (!PrintStructures->dlg.lpPrintDlg16) {
1796 FIXME("The 32bit print dialog does not have this button!?\n");
1797 break;
1798 }
1799
1800 memcpy(&pdlg,PrintStructures->dlg.lpPrintDlg16,sizeof(pdlg));
1801 pdlg.Flags |= PD_PRINTSETUP;
1802 pdlg.hwndOwner = HWND_16(hDlg);
1803 if (!PrintDlg16(&pdlg))
1804 break;
1805 }
1806 break;
1807#endif
1808
1809 case psh2: /* Properties button */
1810 {
1811 HANDLE hPrinter;
1812 char PrinterName[256];
1813
1814 GetDlgItemTextA(hDlg, PrinterComboID, PrinterName, 255);
1815 if (!OpenPrinterA(PrinterName, &hPrinter, NULL)) {
1816 FIXME(" Call to OpenPrinter did not succeed!\n");
1817 break;
1818 }
1819 DocumentPropertiesA(hDlg, hPrinter, PrinterName,
1820 PrintStructures->lpDevMode,
1821 PrintStructures->lpDevMode,
1822 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1823 ClosePrinter(hPrinter);
1824 break;
1825 }
1826
1827 case rad1: /* Paperorientation */
1828 if (lppd->Flags & PD_PRINTSETUP)
1829 {
1830#ifdef __WIN32OS2__
1831 lpdm->dmFields |= DM_ORIENTATION;
1832#endif
1833 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1834 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1835 (LPARAM)(PrintStructures->hPortraitIcon));
1836 }
1837 break;
1838
1839 case rad2: /* Paperorientation */
1840 if (lppd->Flags & PD_PRINTSETUP)
1841 {
1842#ifdef __WIN32OS2__
1843 lpdm->dmFields |= DM_ORIENTATION;
1844#endif
1845 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1846 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1847 (LPARAM)(PrintStructures->hLandscapeIcon));
1848 }
1849 break;
1850
1851 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1852 if (PrinterComboID != wParam) {
1853 FIXME("No handling for print quality combo box yet.\n");
1854 break;
1855 }
1856 /* FALLTHROUGH */
1857 case cmb4: /* Printer combobox */
1858 if (HIWORD(wParam)==CBN_SELCHANGE) {
1859 char PrinterName[256];
1860 GetDlgItemTextA(hDlg, LOWORD(wParam), PrinterName, 255);
1861 PRINTDLG_ChangePrinterA(hDlg, PrinterName, PrintStructures);
1862 }
1863 break;
1864
1865 case cmb2: /* Papersize */
1866 {
1867 DWORD Sel = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1868 if(Sel != CB_ERR)
1869 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
1870 CB_GETITEMDATA,
1871 Sel, 0);
1872 }
1873 break;
1874
1875 case cmb3: /* Bin */
1876 {
1877 DWORD Sel = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1878 if(Sel != CB_ERR)
1879 lpdm->dmDefaultSource = SendDlgItemMessageA(hDlg, cmb3,
1880 CB_GETITEMDATA, Sel,
1881 0);
1882 }
1883 break;
1884 }
1885 if(lppd->Flags & PD_PRINTSETUP) {
1886 switch (LOWORD(wParam)) {
1887 case rad1: /* orientation */
1888 case rad2:
1889 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1890 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1891 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1892 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1893 (WPARAM)IMAGE_ICON,
1894 (LPARAM)PrintStructures->hPortraitIcon);
1895 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1896 (WPARAM)IMAGE_ICON,
1897 (LPARAM)PrintStructures->hPortraitIcon);
1898 }
1899 } else {
1900 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1901 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1902 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1903 (WPARAM)IMAGE_ICON,
1904 (LPARAM)PrintStructures->hLandscapeIcon);
1905 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1906 (WPARAM)IMAGE_ICON,
1907 (LPARAM)PrintStructures->hLandscapeIcon);
1908 }
1909 }
1910 break;
1911 }
1912 }
1913 return FALSE;
1914}
1915
1916static LRESULT PRINTDLG_WMCommandW(HWND hDlg, WPARAM wParam,
1917 LPARAM lParam, PRINT_PTRW* PrintStructures)
1918{
1919 LPPRINTDLGW lppd = PrintStructures->dlg.lpPrintDlg;
1920 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1921 LPDEVMODEW lpdm = PrintStructures->lpDevMode;
1922
1923 switch (LOWORD(wParam)) {
1924 case IDOK:
1925 TRACE(" OK button was hit\n");
1926 if (PRINTDLG_UpdatePrintDlgW(hDlg, PrintStructures)!=TRUE) {
1927 FIXME("Update printdlg was not successful!\n");
1928 return(FALSE);
1929 }
1930 EndDialog(hDlg, TRUE);
1931 return(TRUE);
1932
1933 case IDCANCEL:
1934 TRACE(" CANCEL button was hit\n");
1935 EndDialog(hDlg, FALSE);
1936 return(FALSE);
1937
1938 case pshHelp:
1939 TRACE(" HELP button was hit\n");
1940 SendMessageW(lppd->hwndOwner, PrintStructures->HelpMessageID,
1941 (WPARAM) hDlg, (LPARAM) lppd);
1942 break;
1943
1944 case chx2: /* collate pages checkbox */
1945 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1946 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1947 (LPARAM)PrintStructures->hCollateIcon);
1948 else
1949 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1950 (LPARAM)PrintStructures->hNoCollateIcon);
1951 break;
1952 case edt1: /* from page nr editbox */
1953 case edt2: /* to page nr editbox */
1954 if (HIWORD(wParam)==EN_CHANGE) {
1955 WORD nToPage;
1956 WORD nFromPage;
1957 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1958 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1959 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1960 CheckRadioButton(hDlg, rad1, rad3, rad3);
1961 }
1962 break;
1963
1964 case edt3:
1965#ifndef __WIN32OS2__
1966 if(HIWORD(wParam) == EN_CHANGE) {
1967 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1968 if(copies <= 1)
1969 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1970 else
1971 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1972 }
1973#endif
1974 break;
1975
1976 case psh1: /* Print Setup */
1977 {
1978 ERR("psh1 is called from 16bit code only, we should not get here.\n");
1979 }
1980 break;
1981 case psh2: /* Properties button */
1982 {
1983 HANDLE hPrinter;
1984 WCHAR PrinterName[256];
1985
1986 GetDlgItemTextW(hDlg, PrinterComboID, PrinterName, 255);
1987 if (!OpenPrinterW(PrinterName, &hPrinter, NULL)) {
1988 FIXME(" Call to OpenPrinter did not succeed!\n");
1989 break;
1990 }
1991 DocumentPropertiesW(hDlg, hPrinter, PrinterName,
1992 PrintStructures->lpDevMode,
1993 PrintStructures->lpDevMode,
1994 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1995 ClosePrinter(hPrinter);
1996 break;
1997 }
1998
1999 case rad1: /* Paperorientation */
2000 if (lppd->Flags & PD_PRINTSETUP)
2001 {
2002#ifdef __WIN32OS2__
2003 lpdm->dmFields |= DM_ORIENTATION;
2004#endif
2005 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
2006 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
2007 (LPARAM)(PrintStructures->hPortraitIcon));
2008 }
2009 break;
2010
2011 case rad2: /* Paperorientation */
2012 if (lppd->Flags & PD_PRINTSETUP)
2013 {
2014#ifdef __WIN32OS2__
2015 lpdm->dmFields |= DM_ORIENTATION;
2016#endif
2017 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
2018 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
2019 (LPARAM)(PrintStructures->hLandscapeIcon));
2020 }
2021 break;
2022
2023 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
2024 if (PrinterComboID != wParam) {
2025 FIXME("No handling for print quality combo box yet.\n");
2026 break;
2027 }
2028 /* FALLTHROUGH */
2029 case cmb4: /* Printer combobox */
2030 if (HIWORD(wParam)==CBN_SELCHANGE) {
2031 WCHAR PrinterName[256];
2032 GetDlgItemTextW(hDlg, LOWORD(wParam), PrinterName, 255);
2033 PRINTDLG_ChangePrinterW(hDlg, PrinterName, PrintStructures);
2034 }
2035 break;
2036
2037 case cmb2: /* Papersize */
2038 {
2039 DWORD Sel = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
2040 if(Sel != CB_ERR)
2041 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
2042 CB_GETITEMDATA,
2043 Sel, 0);
2044 }
2045 break;
2046
2047 case cmb3: /* Bin */
2048 {
2049 DWORD Sel = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
2050 if(Sel != CB_ERR)
2051 lpdm->dmDefaultSource = SendDlgItemMessageW(hDlg, cmb3,
2052 CB_GETITEMDATA, Sel,
2053 0);
2054 }
2055 break;
2056 }
2057 if(lppd->Flags & PD_PRINTSETUP) {
2058 switch (LOWORD(wParam)) {
2059 case rad1: /* orientation */
2060 case rad2:
2061 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
2062 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
2063 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
2064 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
2065 (WPARAM)IMAGE_ICON,
2066 (LPARAM)PrintStructures->hPortraitIcon);
2067 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
2068 (WPARAM)IMAGE_ICON,
2069 (LPARAM)PrintStructures->hPortraitIcon);
2070 }
2071 } else {
2072 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
2073 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
2074 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
2075 (WPARAM)IMAGE_ICON,
2076 (LPARAM)PrintStructures->hLandscapeIcon);
2077 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
2078 (WPARAM)IMAGE_ICON,
2079 (LPARAM)PrintStructures->hLandscapeIcon);
2080 }
2081 }
2082 break;
2083 }
2084 }
2085 return FALSE;
2086}
2087
2088/***********************************************************************
2089 * PrintDlgProcA [internal]
2090 */
2091BOOL WINAPI PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
2092 LPARAM lParam)
2093{
2094 PRINT_PTRA* PrintStructures;
2095 LRESULT res=FALSE;
2096
2097 if (uMsg!=WM_INITDIALOG) {
2098 PrintStructures = (PRINT_PTRA*)GetPropA(hDlg,"__WINE_PRINTDLGDATA");
2099 if (!PrintStructures)
2100 return FALSE;
2101 } else {
2102 PrintStructures = (PRINT_PTRA*) lParam;
2103 SetPropA(hDlg,"__WINE_PRINTDLGDATA",lParam);
2104 res = PRINTDLG_WMInitDialog(hDlg, wParam, PrintStructures);
2105
2106 if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
2107 res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(
2108 hDlg, uMsg, wParam, (LPARAM)PrintStructures->dlg.lpPrintDlg
2109 );
2110#ifdef __WIN32OS2__
2111 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
2112 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
2113 ShowWindow(GetDlgItem(hDlg, chx2), SW_HIDE);
2114#endif
2115 }
2116 return res;
2117 }
2118
2119 if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
2120 res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam,
2121 lParam);
2122 if(res) return res;
2123 }
2124
2125 switch (uMsg) {
2126 case WM_COMMAND:
2127 return PRINTDLG_WMCommandA(hDlg, wParam, lParam, PrintStructures);
2128
2129 case WM_DESTROY:
2130 DestroyIcon(PrintStructures->hCollateIcon);
2131 DestroyIcon(PrintStructures->hNoCollateIcon);
2132 DestroyIcon(PrintStructures->hPortraitIcon);
2133 DestroyIcon(PrintStructures->hLandscapeIcon);
2134 if(PrintStructures->hwndUpDown)
2135 DestroyWindow(PrintStructures->hwndUpDown);
2136 return FALSE;
2137 }
2138 return res;
2139}
2140
2141BOOL WINAPI PrintDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
2142 LPARAM lParam)
2143{
2144 PRINT_PTRW* PrintStructures;
2145 LRESULT res=FALSE;
2146
2147 if (uMsg!=WM_INITDIALOG) {
2148 PrintStructures = (PRINT_PTRW*) GetWindowLongA(hDlg, DWL_USER);
2149 if (!PrintStructures)
2150 return FALSE;
2151 } else {
2152 PrintStructures = (PRINT_PTRW*) lParam;
2153 SetWindowLongA(hDlg, DWL_USER, lParam);
2154 res = PRINTDLG_WMInitDialogW(hDlg, wParam, PrintStructures);
2155
2156 if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
2157 {
2158 res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(
2159 hDlg, uMsg, wParam, (LPARAM)PrintStructures->dlg.lpPrintDlg
2160 );
2161#ifdef __WIN32OS2__
2162 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
2163 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
2164 ShowWindow(GetDlgItem(hDlg, chx2), SW_HIDE);
2165#endif
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#ifdef __WIN32OS2__
3130 dm->dmFields |= DM_ORIENTATION;
3131 dm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
3132#endif
3133
3134 }
3135 GlobalUnlock(pda->pdlg.hDevNames);
3136 GlobalUnlock(pda->pdlg.hDevMode);
3137 return TRUE;
3138}
3139
3140static BOOL
3141PRINTDLG_PS_UpdateDlgStructW(HWND hDlg, PageSetupDataW *pda) {
3142 DEVNAMES *dn;
3143 DEVMODEW *dm;
3144 LPWSTR devname,portname;
3145 WCHAR papername[64];
3146
3147 char buf[200];
3148
3149 dn = GlobalLock(pda->pdlg.hDevNames);
3150 dm = GlobalLock(pda->pdlg.hDevMode);
3151 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
3152 portname = ((WCHAR*)dn)+dn->wOutputOffset;
3153 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
3154 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
3155
3156 if (GetDlgItemTextW(hDlg,cmb2,papername,sizeof(papername))>0) {
3157 PRINTDLG_PaperSizeW(&(pda->pdlg),papername,&(pda->dlga->ptPaperSize));
3158 pda->dlga->ptPaperSize.x = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga,pda->dlga->ptPaperSize.x);
3159 pda->dlga->ptPaperSize.y = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga,pda->dlga->ptPaperSize.y);
3160 } else
3161 FIXME("could not get dialog text for papersize cmbbox?\n");
3162#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); }
3163 GETVAL(edt4,pda->dlga->rtMargin.left);
3164 GETVAL(edt5,pda->dlga->rtMargin.top);
3165 GETVAL(edt6,pda->dlga->rtMargin.right);
3166 GETVAL(edt7,pda->dlga->rtMargin.bottom);
3167#undef GETVAL
3168
3169 /* If we are in landscape, swap x and y of page size */
3170 if (IsDlgButtonChecked(hDlg, rad2)) {
3171 DWORD tmp;
3172 tmp = pda->dlga->ptPaperSize.x;
3173 pda->dlga->ptPaperSize.x = pda->dlga->ptPaperSize.y;
3174 pda->dlga->ptPaperSize.y = tmp;
3175
3176#ifdef __WIN32OS2__
3177 dm->dmFields |= DM_ORIENTATION;
3178 dm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
3179#endif
3180
3181 }
3182 GlobalUnlock(pda->pdlg.hDevNames);
3183 GlobalUnlock(pda->pdlg.hDevMode);
3184 return TRUE;
3185}
3186
3187/*
3188 * This is called after returning from PrintDlg().
3189 */
3190static BOOL
3191PRINTDLG_PS_ChangePrinterA(HWND hDlg, PageSetupDataA *pda) {
3192 DEVNAMES *dn;
3193 DEVMODEA *dm;
3194 LPSTR devname,portname;
3195
3196 dn = GlobalLock(pda->pdlg.hDevNames);
3197 dm = GlobalLock(pda->pdlg.hDevMode);
3198 devname = ((char*)dn)+dn->wDeviceOffset;
3199 portname = ((char*)dn)+dn->wOutputOffset;
3200 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb2,devname,portname,dm);
3201 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb3,devname,portname,dm);
3202 GlobalUnlock(pda->pdlg.hDevNames);
3203 GlobalUnlock(pda->pdlg.hDevMode);
3204 return TRUE;
3205}
3206
3207static BOOL
3208PRINTDLG_PS_ChangePrinterW(HWND hDlg, PageSetupDataW *pda) {
3209 DEVNAMES *dn;
3210 DEVMODEW *dm;
3211 LPWSTR devname,portname;
3212
3213 dn = GlobalLock(pda->pdlg.hDevNames);
3214 dm = GlobalLock(pda->pdlg.hDevMode);
3215 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
3216 portname = ((WCHAR*)dn)+dn->wOutputOffset;
3217 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
3218 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
3219 GlobalUnlock(pda->pdlg.hDevNames);
3220 GlobalUnlock(pda->pdlg.hDevMode);
3221 return TRUE;
3222}
3223
3224static BOOL
3225PRINTDLG_PS_WMCommandA(
3226 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataA *pda
3227) {
3228 switch (LOWORD(wParam)) {
3229 case IDOK:
3230 if (!PRINTDLG_PS_UpdateDlgStructA(hDlg, pda))
3231 return(FALSE);
3232 EndDialog(hDlg, TRUE);
3233 return TRUE ;
3234
3235 case IDCANCEL:
3236 EndDialog(hDlg, FALSE);
3237 return FALSE ;
3238
3239 case psh3: {
3240 pda->pdlg.Flags = 0;
3241 pda->pdlg.hwndOwner = hDlg;
3242 if (PrintDlgA(&(pda->pdlg)))
3243 PRINTDLG_PS_ChangePrinterA(hDlg,pda);
3244 return TRUE;
3245 }
3246 }
3247 FIXME("loword (lparam) %d, wparam 0x%x, lparam %08lx, STUB mostly.\n",
3248 LOWORD(lParam),wParam,lParam
3249 );
3250 return FALSE;
3251}
3252
3253static BOOL
3254PRINTDLG_PS_WMCommandW(
3255 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataW *pda
3256) {
3257 switch (LOWORD(wParam)) {
3258 case IDOK:
3259 if (!PRINTDLG_PS_UpdateDlgStructW(hDlg, pda))
3260 return(FALSE);
3261 EndDialog(hDlg, TRUE);
3262 return TRUE ;
3263
3264 case IDCANCEL:
3265 EndDialog(hDlg, FALSE);
3266 return FALSE ;
3267
3268 case psh3: {
3269 pda->pdlg.Flags = 0;
3270 pda->pdlg.hwndOwner = hDlg;
3271 if (PrintDlgW(&(pda->pdlg)))
3272 PRINTDLG_PS_ChangePrinterW(hDlg,pda);
3273 return TRUE;
3274 }
3275 }
3276 FIXME("loword (lparam) %d, wparam 0x%x, lparam %08lx, STUB mostly.\n",
3277 LOWORD(lParam),wParam,lParam
3278 );
3279 return FALSE;
3280}
3281
3282
3283static BOOL WINAPI
3284PageDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
3285{
3286 PageSetupDataA *pda;
3287 BOOL res = FALSE;
3288
3289 if (uMsg==WM_INITDIALOG) {
3290 res = TRUE;
3291 pda = (PageSetupDataA*)lParam;
3292 SetPropA(hDlg,"__WINE_PAGESETUPDLGDATA",lParam);
3293 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3294 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3295 if (!res) {
3296 FIXME("Setup page hook failed?\n");
3297 res = TRUE;
3298 }
3299 }
3300 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK) {
3301 FIXME("PagePaintHook not yet implemented!\n");
3302 }
3303 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
3304 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
3305 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
3306 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
3307 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
3308 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
3309 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
3310 }
3311 /* width larger as height -> landscape */
3312 if (pda->dlga->ptPaperSize.x > pda->dlga->ptPaperSize.y)
3313 CheckRadioButton(hDlg, rad1, rad2, rad2);
3314 else /* this is default if papersize is not set */
3315 CheckRadioButton(hDlg, rad1, rad2, rad1);
3316 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
3317 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
3318 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
3319 }
3320 /* We fill them out enabled or not */
3321 if (pda->dlga->Flags & PSD_MARGINS) {
3322 char str[100];
3323 _c_size2strA(pda,pda->dlga->rtMargin.left,str);
3324 SetDlgItemTextA(hDlg,edt4,str);
3325 _c_size2strA(pda,pda->dlga->rtMargin.top,str);
3326 SetDlgItemTextA(hDlg,edt5,str);
3327 _c_size2strA(pda,pda->dlga->rtMargin.right,str);
3328 SetDlgItemTextA(hDlg,edt6,str);
3329 _c_size2strA(pda,pda->dlga->rtMargin.bottom,str);
3330 SetDlgItemTextA(hDlg,edt7,str);
3331 } else {
3332 /* default is 1 inch */
3333 DWORD size = _c_inch2size(pda->dlga,1000);
3334 char str[20];
3335 _c_size2strA(pda,size,str);
3336 SetDlgItemTextA(hDlg,edt4,str);
3337 SetDlgItemTextA(hDlg,edt5,str);
3338 SetDlgItemTextA(hDlg,edt6,str);
3339 SetDlgItemTextA(hDlg,edt7,str);
3340 }
3341 PRINTDLG_PS_ChangePrinterA(hDlg,pda);
3342 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
3343 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
3344 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
3345 }
3346 return TRUE;
3347 } else {
3348 pda = (PageSetupDataA*)GetPropA(hDlg,"__WINE_PAGESETUPDLGDATA");
3349 if (!pda) {
3350 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3351 return FALSE;
3352 }
3353 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3354 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3355 if (res) return res;
3356 }
3357 }
3358 switch (uMsg) {
3359 case WM_COMMAND:
3360 return PRINTDLG_PS_WMCommandA(hDlg, wParam, lParam, pda);
3361 }
3362 return FALSE;
3363}
3364
3365static BOOL WINAPI
3366PageDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
3367{
3368 PageSetupDataW *pda;
3369 BOOL res = FALSE;
3370
3371 if (uMsg==WM_INITDIALOG) {
3372 res = TRUE;
3373 pda = (PageSetupDataW*)lParam;
3374 SetPropA(hDlg,"__WINE_PAGESETUPDLGDATA",lParam);
3375 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3376 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3377 if (!res) {
3378 FIXME("Setup page hook failed?\n");
3379 res = TRUE;
3380 }
3381 }
3382 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK) {
3383 FIXME("PagePaintHook not yet implemented!\n");
3384 }
3385 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
3386 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
3387 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
3388 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
3389 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
3390 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
3391 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
3392 }
3393 /* width larger as height -> landscape */
3394 if (pda->dlga->ptPaperSize.x > pda->dlga->ptPaperSize.y)
3395 CheckRadioButton(hDlg, rad1, rad2, rad2);
3396 else /* this is default if papersize is not set */
3397 CheckRadioButton(hDlg, rad1, rad2, rad1);
3398 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
3399 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
3400 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
3401 }
3402 /* We fill them out enabled or not */
3403 if (pda->dlga->Flags & PSD_MARGINS) {
3404 char str[100];
3405 _c_size2strW(pda,pda->dlga->rtMargin.left,str);
3406 SetDlgItemTextA(hDlg,edt4,str);
3407 _c_size2strW(pda,pda->dlga->rtMargin.top,str);
3408 SetDlgItemTextA(hDlg,edt5,str);
3409 _c_size2strW(pda,pda->dlga->rtMargin.right,str);
3410 SetDlgItemTextA(hDlg,edt6,str);
3411 _c_size2strW(pda,pda->dlga->rtMargin.bottom,str);
3412 SetDlgItemTextA(hDlg,edt7,str);
3413 } else {
3414 /* default is 1 inch */
3415 DWORD size = _c_inch2size((LPPAGESETUPDLGA)pda->dlga,1000);
3416 char str[20];
3417 _c_size2strW(pda,size,str);
3418 SetDlgItemTextA(hDlg,edt4,str);
3419 SetDlgItemTextA(hDlg,edt5,str);
3420 SetDlgItemTextA(hDlg,edt6,str);
3421 SetDlgItemTextA(hDlg,edt7,str);
3422 }
3423 PRINTDLG_PS_ChangePrinterW(hDlg,pda);
3424 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
3425 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
3426 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
3427 }
3428 return TRUE;
3429 } else {
3430 pda = (PageSetupDataW*)GetPropA(hDlg,"__WINE_PAGESETUPDLGDATA");
3431 if (!pda) {
3432 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3433 return FALSE;
3434 }
3435 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3436 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3437 if (res) return res;
3438 }
3439 }
3440 switch (uMsg) {
3441 case WM_COMMAND:
3442 return PRINTDLG_PS_WMCommandW(hDlg, wParam, lParam, pda);
3443 }
3444 return FALSE;
3445}
3446
3447/***********************************************************************
3448 * PageSetupDlgA (COMDLG32.@)
3449 */
3450BOOL WINAPI PageSetupDlgA(LPPAGESETUPDLGA setupdlg) {
3451 HGLOBAL hDlgTmpl;
3452 LPVOID ptr;
3453 BOOL bRet;
3454 PageSetupDataA *pda;
3455 PRINTDLGA pdlg;
3456
3457 if(TRACE_ON(commdlg)) {
3458 char flagstr[1000] = "";
3459 struct pd_flags *pflag = psd_flags;
3460 for( ; pflag->name; pflag++) {
3461 if(setupdlg->Flags & pflag->flag) {
3462 strcat(flagstr, pflag->name);
3463 strcat(flagstr, "|");
3464 }
3465 }
3466 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
3467 "hinst %08x, flags %08lx (%s)\n",
3468 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
3469 setupdlg->hDevNames,
3470 setupdlg->hInstance, setupdlg->Flags, flagstr);
3471 }
3472
3473 /* First get default printer data, we need it right after that. */
3474 memset(&pdlg,0,sizeof(pdlg));
3475 pdlg.lStructSize = sizeof(pdlg);
3476 pdlg.Flags = PD_RETURNDEFAULT;
3477 bRet = PrintDlgA(&pdlg);
3478 if (!bRet) return FALSE;
3479
3480 /* short cut exit, just return default values */
3481 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
3482 setupdlg->hDevMode = pdlg.hDevMode;
3483 setupdlg->hDevNames = pdlg.hDevNames;
3484 /* FIXME: Just return "A4" for now. */
3485 PRINTDLG_PaperSizeA(&pdlg,"A4",&setupdlg->ptPaperSize);
3486 setupdlg->ptPaperSize.x=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.x);
3487 setupdlg->ptPaperSize.y=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.y);
3488 return TRUE;
3489 }
3490 hDlgTmpl = PRINTDLG_GetPGSTemplateA(setupdlg);
3491 if (!hDlgTmpl) {
3492 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3493 return FALSE;
3494 }
3495 ptr = LockResource( hDlgTmpl );
3496 if (!ptr) {
3497 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3498 return FALSE;
3499 }
3500 pda = HeapAlloc(GetProcessHeap(),0,sizeof(*pda));
3501 pda->dlga = setupdlg;
3502 memcpy(&pda->pdlg,&pdlg,sizeof(pdlg));
3503
3504 bRet = (0<DialogBoxIndirectParamA(
3505 setupdlg->hInstance,
3506 ptr,
3507 setupdlg->hwndOwner,
3508 PageDlgProcA,
3509 (LPARAM)pda)
3510 );
3511#ifdef __WIN32OS2__
3512 //On return we should overwrite the input devmode & devnames with the one
3513 //set up by the dialog
3514 setupdlg->hDevMode = pdlg.hDevMode;
3515 setupdlg->hDevNames = pdlg.hDevNames;
3516#endif
3517 return bRet;
3518}
3519/***********************************************************************
3520 * PageSetupDlgW (COMDLG32.@)
3521 */
3522BOOL WINAPI PageSetupDlgW(LPPAGESETUPDLGW setupdlg) {
3523 HGLOBAL hDlgTmpl;
3524 LPVOID ptr;
3525 BOOL bRet;
3526 PageSetupDataW *pdw;
3527 PRINTDLGW pdlg;
3528
3529 if(TRACE_ON(commdlg)) {
3530 char flagstr[1000] = "";
3531 struct pd_flags *pflag = psd_flags;
3532 for( ; pflag->name; pflag++) {
3533 if(setupdlg->Flags & pflag->flag) {
3534 strcat(flagstr, pflag->name);
3535 strcat(flagstr, "|");
3536 }
3537 }
3538 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
3539 "hinst %08x, flags %08lx (%s)\n",
3540 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
3541 setupdlg->hDevNames,
3542 setupdlg->hInstance, setupdlg->Flags, flagstr);
3543 }
3544
3545 /* First get default printer data, we need it right after that. */
3546 memset(&pdlg,0,sizeof(pdlg));
3547 pdlg.lStructSize = sizeof(pdlg);
3548 pdlg.Flags = PD_RETURNDEFAULT;
3549 bRet = PrintDlgW(&pdlg);
3550 if (!bRet) return FALSE;
3551
3552 /* short cut exit, just return default values */
3553 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
3554 const WCHAR a4[] = {'A','4',0};
3555 setupdlg->hDevMode = pdlg.hDevMode;
3556 setupdlg->hDevNames = pdlg.hDevNames;
3557 /* FIXME: Just return "A4" for now. */
3558 PRINTDLG_PaperSizeW(&pdlg,a4,&setupdlg->ptPaperSize);
3559 setupdlg->ptPaperSize.x=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.x);
3560 setupdlg->ptPaperSize.y=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.y);
3561 return TRUE;
3562 }
3563 hDlgTmpl = PRINTDLG_GetPGSTemplateW(setupdlg);
3564 if (!hDlgTmpl) {
3565 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3566 return FALSE;
3567 }
3568 ptr = LockResource( hDlgTmpl );
3569 if (!ptr) {
3570 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3571 return FALSE;
3572 }
3573 pdw = HeapAlloc(GetProcessHeap(),0,sizeof(*pdw));
3574 pdw->dlga = setupdlg;
3575 memcpy(&pdw->pdlg,&pdlg,sizeof(pdlg));
3576
3577 bRet = (0<DialogBoxIndirectParamW(
3578 setupdlg->hInstance,
3579 ptr,
3580 setupdlg->hwndOwner,
3581 PageDlgProcW,
3582 (LPARAM)pdw)
3583 );
3584#ifdef __WIN32OS2__
3585 //On return we should overwrite the input devmode & devnames with the one
3586 //set up by the dialog
3587 setupdlg->hDevMode = pdlg.hDevMode;
3588 setupdlg->hDevNames = pdlg.hDevNames;
3589#endif
3590 return bRet;
3591}
3592
3593#ifndef __WIN32OS2__
3594/**********************************************************************
3595 *
3596 * 16 bit commdlg
3597 */
3598
3599/***********************************************************************
3600 * PrintDlgProc (COMMDLG.21)
3601 */
3602LRESULT WINAPI PrintDlgProc16(HWND16 hDlg16, UINT16 uMsg, WPARAM16 wParam,
3603 LPARAM lParam)
3604{
3605 HWND hDlg = HWND_32(hDlg16);
3606 PRINT_PTRA* PrintStructures;
3607 LRESULT res=FALSE;
3608
3609 if (uMsg!=WM_INITDIALOG) {
3610 PrintStructures = (PRINT_PTRA*)GetPropA(hDlg,"__WINE_PRINTDLGDATA");
3611 if (!PrintStructures)
3612 return FALSE;
3613 } else {
3614 PrintStructures = (PRINT_PTRA*) lParam;
3615 SetPropA(hDlg,"__WINE_PRINTDLGDATA",lParam);
3616 res = PRINTDLG_WMInitDialog16(hDlg, wParam, PrintStructures);
3617
3618 if(PrintStructures->dlg.lpPrintDlg16->Flags & PD_ENABLEPRINTHOOK) {
3619 res = CallWindowProc16(
3620 (WNDPROC16)PrintStructures->dlg.lpPrintDlg16->lpfnPrintHook,
3621 hDlg16, uMsg, wParam, (LPARAM)PrintStructures->dlg.lpPrintDlg16
3622 );
3623 }
3624 return res;
3625 }
3626
3627 if(PrintStructures->dlg.lpPrintDlg16->Flags & PD_ENABLEPRINTHOOK) {
3628 res = CallWindowProc16(
3629 (WNDPROC16)PrintStructures->dlg.lpPrintDlg16->lpfnPrintHook,
3630 hDlg16,uMsg, wParam, lParam
3631 );
3632 if(LOWORD(res)) return res;
3633 }
3634
3635 switch (uMsg) {
3636 case WM_COMMAND: {
3637 /* We need to map those for the 32bit window procedure, compare
3638 * with 32Ato16 mapper in winproc.c
3639 */
3640 return PRINTDLG_WMCommandA(
3641 hDlg,
3642 MAKEWPARAM(wParam,HIWORD(lParam)),
3643 LOWORD(lParam),
3644 PrintStructures
3645 );
3646 }
3647 case WM_DESTROY:
3648 DestroyIcon(PrintStructures->hCollateIcon);
3649 DestroyIcon(PrintStructures->hNoCollateIcon);
3650 /* FIXME: don't forget to delete the paper orientation icons here! */
3651
3652 return FALSE;
3653 }
3654 return res;
3655}
3656
3657
3658/***********************************************************************
3659 * PrintSetupDlgProc (COMMDLG.22)
3660 */
3661LRESULT WINAPI PrintSetupDlgProc16(HWND16 hWnd16, UINT16 wMsg, WPARAM16 wParam,
3662 LPARAM lParam)
3663{
3664 HWND hWnd = HWND_32(hWnd16);
3665 switch (wMsg)
3666 {
3667 case WM_INITDIALOG:
3668 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
3669 ShowWindow(hWnd, SW_SHOWNORMAL);
3670 return (TRUE);
3671 case WM_COMMAND:
3672 switch (wParam) {
3673 case IDOK:
3674 EndDialog(hWnd, TRUE);
3675 return(TRUE);
3676 case IDCANCEL:
3677 EndDialog(hWnd, FALSE);
3678 return(TRUE);
3679 }
3680 return(FALSE);
3681 }
3682 return FALSE;
3683}
3684#endif
3685
3686/***********************************************************************
3687 * PrintDlgExA (COMDLG32.@)
3688 */
3689HRESULT WINAPI PrintDlgExA(LPVOID lpPrintDlgExA) /* [???] FIXME: LPPRINTDLGEXA */
3690{
3691 FIXME("stub\n");
3692 return E_NOTIMPL;
3693}
3694/***********************************************************************
3695 * PrintDlgExW (COMDLG32.@)
3696 */
3697HRESULT WINAPI PrintDlgExW(LPVOID lpPrintDlgExW) /* [???] FIXME: LPPRINTDLGEXW */
3698{
3699 FIXME("stub\n");
3700 return E_NOTIMPL;
3701}
3702
Note: See TracBrowser for help on using the repository browser.