Implemented localeconv() with libc function.
[wine.git] / dlls / commdlg / printdlg.c
blob3e39d1ee4490e4566dfa039d172b0f4eb279eccf
1 /*
2 * COMMDLG - Print Dialog
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
6 * Copyright 1999 Klaas van Gend
7 * Copyright 2000 Huw D M Davies
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.
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.
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
23 #include <ctype.h>
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <string.h>
28 #define NONAMELESSUNION
29 #define NONAMELESSSTRUCT
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wingdi.h"
33 #include "wine/wingdi16.h"
34 #include "winuser.h"
35 #include "wine/winuser16.h"
36 #include "commdlg.h"
37 #include "dlgs.h"
38 #include "wine/debug.h"
39 #include "cderr.h"
40 #include "winspool.h"
41 #include "winerror.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
45 #include "cdlg.h"
47 /* This PRINTDLGA internal structure stores
48 * pointers to several throughout useful structures.
51 typedef struct
53 LPDEVMODEA lpDevMode;
54 struct {
55 LPPRINTDLGA lpPrintDlg;
56 LPPRINTDLG16 lpPrintDlg16;
57 } dlg;
58 LPPRINTER_INFO_2A lpPrinterInfo;
59 LPDRIVER_INFO_3A lpDriverInfo;
60 UINT HelpMessageID;
61 HICON hCollateIcon; /* PrintDlg only */
62 HICON hNoCollateIcon; /* PrintDlg only */
63 HICON hPortraitIcon; /* PrintSetupDlg only */
64 HICON hLandscapeIcon; /* PrintSetupDlg only */
65 HWND hwndUpDown;
66 } PRINT_PTRA;
68 typedef struct
70 LPDEVMODEW lpDevMode;
71 struct {
72 LPPRINTDLGW lpPrintDlg;
73 } dlg;
74 LPPRINTER_INFO_2W lpPrinterInfo;
75 LPDRIVER_INFO_3W lpDriverInfo;
76 UINT HelpMessageID;
77 HICON hCollateIcon; /* PrintDlg only */
78 HICON hNoCollateIcon; /* PrintDlg only */
79 HICON hPortraitIcon; /* PrintSetupDlg only */
80 HICON hLandscapeIcon; /* PrintSetupDlg only */
81 HWND hwndUpDown;
82 } PRINT_PTRW;
84 /* Debugging info */
85 static struct pd_flags {
86 DWORD flag;
87 LPSTR name;
88 } pd_flags[] = {
89 {PD_SELECTION, "PD_SELECTION "},
90 {PD_PAGENUMS, "PD_PAGENUMS "},
91 {PD_NOSELECTION, "PD_NOSELECTION "},
92 {PD_NOPAGENUMS, "PD_NOPAGENUMS "},
93 {PD_COLLATE, "PD_COLLATE "},
94 {PD_PRINTTOFILE, "PD_PRINTTOFILE "},
95 {PD_PRINTSETUP, "PD_PRINTSETUP "},
96 {PD_NOWARNING, "PD_NOWARNING "},
97 {PD_RETURNDC, "PD_RETURNDC "},
98 {PD_RETURNIC, "PD_RETURNIC "},
99 {PD_RETURNDEFAULT, "PD_RETURNDEFAULT "},
100 {PD_SHOWHELP, "PD_SHOWHELP "},
101 {PD_ENABLEPRINTHOOK, "PD_ENABLEPRINTHOOK "},
102 {PD_ENABLESETUPHOOK, "PD_ENABLESETUPHOOK "},
103 {PD_ENABLEPRINTTEMPLATE, "PD_ENABLEPRINTTEMPLATE "},
104 {PD_ENABLESETUPTEMPLATE, "PD_ENABLESETUPTEMPLATE "},
105 {PD_ENABLEPRINTTEMPLATEHANDLE, "PD_ENABLEPRINTTEMPLATEHANDLE "},
106 {PD_ENABLESETUPTEMPLATEHANDLE, "PD_ENABLESETUPTEMPLATEHANDLE "},
107 {PD_USEDEVMODECOPIES, "PD_USEDEVMODECOPIES[ANDCOLLATE] "},
108 {PD_DISABLEPRINTTOFILE, "PD_DISABLEPRINTTOFILE "},
109 {PD_HIDEPRINTTOFILE, "PD_HIDEPRINTTOFILE "},
110 {PD_NONETWORKBUTTON, "PD_NONETWORKBUTTON "},
111 {-1, NULL}
114 /* Debugging info */
115 static struct pd_flags psd_flags[] = {
116 {PSD_MINMARGINS,"PSD_MINMARGINS"},
117 {PSD_MARGINS,"PSD_MARGINS"},
118 {PSD_INTHOUSANDTHSOFINCHES,"PSD_INTHOUSANDTHSOFINCHES"},
119 {PSD_INHUNDREDTHSOFMILLIMETERS,"PSD_INHUNDREDTHSOFMILLIMETERS"},
120 {PSD_DISABLEMARGINS,"PSD_DISABLEMARGINS"},
121 {PSD_DISABLEPRINTER,"PSD_DISABLEPRINTER"},
122 {PSD_NOWARNING,"PSD_NOWARNING"},
123 {PSD_DISABLEORIENTATION,"PSD_DISABLEORIENTATION"},
124 {PSD_RETURNDEFAULT,"PSD_RETURNDEFAULT"},
125 {PSD_DISABLEPAPER,"PSD_DISABLEPAPER"},
126 {PSD_SHOWHELP,"PSD_SHOWHELP"},
127 {PSD_ENABLEPAGESETUPHOOK,"PSD_ENABLEPAGESETUPHOOK"},
128 {PSD_ENABLEPAGESETUPTEMPLATE,"PSD_ENABLEPAGESETUPTEMPLATE"},
129 {PSD_ENABLEPAGESETUPTEMPLATEHANDLE,"PSD_ENABLEPAGESETUPTEMPLATEHANDLE"},
130 {PSD_ENABLEPAGEPAINTHOOK,"PSD_ENABLEPAGEPAINTHOOK"},
131 {PSD_DISABLEPAGEPAINTING,"PSD_DISABLEPAGEPAINTING"},
132 {-1, NULL}
135 /* Yes these constants are the same, but we're just copying win98 */
136 #define UPDOWN_ID 0x270f
137 #define MAX_COPIES 9999
139 /***********************************************************************
140 * PRINTDLG_GetDefaultPrinterName
142 * Returns the default printer name in buf.
143 * Even under WinNT/2000 default printer is retrieved via GetProfileString -
144 * these entries are mapped somewhere in the registry rather than win.ini.
146 * Returns TRUE on success else FALSE
148 static BOOL PRINTDLG_GetDefaultPrinterNameA(LPSTR buf, DWORD len)
150 char *ptr;
152 if(!GetProfileStringA("windows", "device", "", buf, len)) {
153 TRACE("No profile entry for default printer found.\n");
154 return FALSE;
156 if((ptr = strchr(buf, ',')) == NULL) {
157 FIXME("bad format for default printer (%s)!\n",buf);
158 return FALSE;
160 *ptr = '\0';
161 return TRUE;
164 static BOOL PRINTDLG_GetDefaultPrinterNameW(LPWSTR buf, DWORD len)
166 LPSTR ptr, bufA = (LPSTR)HeapAlloc(GetProcessHeap(),0,len+1);
169 if(!GetProfileStringA("windows", "device", "", bufA, len)) {
170 TRACE("No profile entry for default printer found.\n");
171 HeapFree(GetProcessHeap(),0,bufA);
172 return FALSE;
174 if((ptr = strchr(bufA, ',')) == NULL) {
175 FIXME("bad format for default printer (%s)!\n",bufA);
176 HeapFree(GetProcessHeap(),0,bufA);
177 return FALSE;
179 *ptr = '\0';
180 MultiByteToWideChar( CP_ACP, 0, bufA, -1, buf, len );
181 HeapFree(GetProcessHeap(),0,bufA);
182 return TRUE;
185 /***********************************************************************
186 * PRINTDLG_OpenDefaultPrinter
188 * Returns a winspool printer handle to the default printer in *hprn
189 * Caller must call ClosePrinter on the handle
191 * Returns TRUE on success else FALSE
193 static BOOL PRINTDLG_OpenDefaultPrinter(HANDLE *hprn)
195 char buf[260];
196 BOOL res;
197 if(!PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf)))
198 return FALSE;
199 res = OpenPrinterA(buf, hprn, NULL);
200 if (!res)
201 FIXME("Could not open printer %s?!\n",buf);
202 return res;
205 /***********************************************************************
206 * PRINTDLG_SetUpPrinterListCombo
208 * Initializes printer list combox.
209 * hDlg: HWND of dialog
210 * id: Control id of combo
211 * name: Name of printer to select
213 * Initializes combo with list of available printers. Selects printer 'name'
214 * If name is NULL or does not exist select the default printer.
216 * Returns number of printers added to list.
218 static INT PRINTDLG_SetUpPrinterListComboA(HWND hDlg, UINT id, LPCSTR name)
220 DWORD needed, num;
221 INT i;
222 LPPRINTER_INFO_2A pi;
223 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
224 pi = HeapAlloc(GetProcessHeap(), 0, needed);
225 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
226 &num);
228 for(i = 0; i < num; i++) {
229 SendDlgItemMessageA(hDlg, id, CB_ADDSTRING, 0,
230 (LPARAM)pi[i].pPrinterName );
232 HeapFree(GetProcessHeap(), 0, pi);
233 if(!name ||
234 (i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1,
235 (LPARAM)name)) == CB_ERR) {
237 char buf[260];
238 FIXME("Can't find '%s' in printer list so trying to find default\n",
239 name);
240 if(!PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf)))
241 return num;
242 i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
243 if(i == CB_ERR)
244 FIXME("Can't find default printer in printer list\n");
246 SendDlgItemMessageA(hDlg, id, CB_SETCURSEL, i, 0);
247 return num;
250 static INT PRINTDLG_SetUpPrinterListComboW(HWND hDlg, UINT id, LPCWSTR name)
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);
260 for(i = 0; i < num; i++) {
261 SendDlgItemMessageW(hDlg, id, CB_ADDSTRING, 0,
262 (LPARAM)pi[i].pPrinterName );
264 HeapFree(GetProcessHeap(), 0, pi);
265 if(!name ||
266 (i = SendDlgItemMessageW(hDlg, id, CB_FINDSTRINGEXACT, -1,
267 (LPARAM)name)) == CB_ERR) {
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");
279 SendDlgItemMessageW(hDlg, id, CB_SETCURSEL, i, 0);
280 return num;
283 /***********************************************************************
284 * PRINTDLG_CreateDevNames [internal]
287 * creates a DevNames structure.
289 * (NB. when we handle unicode the offsets will be in wchars).
291 static BOOL PRINTDLG_CreateDevNames(HGLOBAL *hmem, char* DeviceDriverName,
292 char* DeviceName, char* OutputPort)
294 long size;
295 char* pDevNamesSpace;
296 char* pTempPtr;
297 LPDEVNAMES lpDevNames;
298 char buf[260];
300 size = strlen(DeviceDriverName) + 1
301 + strlen(DeviceName) + 1
302 + strlen(OutputPort) + 1
303 + sizeof(DEVNAMES);
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;
312 pDevNamesSpace = GlobalLock(*hmem);
313 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
315 pTempPtr = pDevNamesSpace + sizeof(DEVNAMES);
316 strcpy(pTempPtr, DeviceDriverName);
317 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
319 pTempPtr += strlen(DeviceDriverName) + 1;
320 strcpy(pTempPtr, DeviceName);
321 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
323 pTempPtr += strlen(DeviceName) + 1;
324 strcpy(pTempPtr, OutputPort);
325 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
327 PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf));
328 lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
329 GlobalUnlock(*hmem);
330 return TRUE;
333 static BOOL PRINTDLG_CreateDevNamesW(HGLOBAL *hmem, LPCWSTR DeviceDriverName,
334 LPCWSTR DeviceName, LPCWSTR OutputPort)
336 long size;
337 LPWSTR pDevNamesSpace;
338 LPWSTR pTempPtr;
339 LPDEVNAMES lpDevNames;
340 WCHAR bufW[260];
341 char buf[260];
343 size = sizeof(WCHAR)*lstrlenW(DeviceDriverName) + 2
344 + sizeof(WCHAR)*lstrlenW(DeviceName) + 2
345 + sizeof(WCHAR)*lstrlenW(OutputPort) + 2
346 + sizeof(DEVNAMES);
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;
355 pDevNamesSpace = GlobalLock(*hmem);
356 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
358 pTempPtr = (LPWSTR)((LPDEVNAMES)pDevNamesSpace + 1);
359 lstrcpyW(pTempPtr, DeviceDriverName);
360 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
362 pTempPtr += lstrlenW(DeviceDriverName) + 1;
363 lstrcpyW(pTempPtr, DeviceName);
364 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
366 pTempPtr += lstrlenW(DeviceName) + 1;
367 lstrcpyW(pTempPtr, OutputPort);
368 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
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;
378 static BOOL PRINTDLG_CreateDevNames16(HGLOBAL16 *hmem, char* DeviceDriverName,
379 char* DeviceName, char* OutputPort)
381 long size;
382 char* pDevNamesSpace;
383 char* pTempPtr;
384 LPDEVNAMES lpDevNames;
385 char buf[260];
387 size = strlen(DeviceDriverName) + 1
388 + strlen(DeviceName) + 1
389 + strlen(OutputPort) + 1
390 + sizeof(DEVNAMES);
392 if(*hmem)
393 *hmem = GlobalReAlloc16(*hmem, size, GMEM_MOVEABLE);
394 else
395 *hmem = GlobalAlloc16(GMEM_MOVEABLE, size);
396 if (*hmem == 0)
397 return FALSE;
399 pDevNamesSpace = GlobalLock16(*hmem);
400 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
402 pTempPtr = pDevNamesSpace + sizeof(DEVNAMES);
403 strcpy(pTempPtr, DeviceDriverName);
404 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
406 pTempPtr += strlen(DeviceDriverName) + 1;
407 strcpy(pTempPtr, DeviceName);
408 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
410 pTempPtr += strlen(DeviceName) + 1;
411 strcpy(pTempPtr, OutputPort);
412 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
414 PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf));
415 lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
416 GlobalUnlock16(*hmem);
417 return TRUE;
421 /***********************************************************************
422 * PRINTDLG_UpdatePrintDlg [internal]
425 * updates the PrintDlg structure for returnvalues.
427 * RETURNS
428 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
429 * TRUE if succesful.
431 static BOOL PRINTDLG_UpdatePrintDlgA(HWND hDlg,
432 PRINT_PTRA* PrintStructures)
434 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
435 PDEVMODEA lpdm = PrintStructures->lpDevMode;
436 LPPRINTER_INFO_2A pi = PrintStructures->lpPrinterInfo;
439 if(!lpdm) {
440 FIXME("No lpdm ptr?\n");
441 return FALSE;
445 if(!(lppd->Flags & PD_PRINTSETUP)) {
446 /* check whether nFromPage and nToPage are within range defined by
447 * nMinPage and nMaxPage
449 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
450 WORD nToPage;
451 WORD nFromPage;
452 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
453 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
454 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
455 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
456 char resourcestr[256];
457 char resultstr[256];
458 LoadStringA(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
459 resourcestr, 255);
460 sprintf(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
461 LoadStringA(COMDLG32_hInstance, PD32_PRINT_TITLE,
462 resourcestr, 255);
463 MessageBoxA(hDlg, resultstr, resourcestr,
464 MB_OK | MB_ICONWARNING);
465 return FALSE;
467 lppd->nFromPage = nFromPage;
468 lppd->nToPage = nToPage;
469 lppd->Flags |= PD_PAGENUMS;
471 else
472 lppd->Flags &= ~PD_PAGENUMS;
474 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
475 lppd->Flags |= PD_PRINTTOFILE;
476 pi->pPortName = "FILE:";
479 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
480 FIXME("Collate lppd not yet implemented as output\n");
483 /* set PD_Collate and nCopies */
484 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
485 /* The application doesn't support multiple copies or collate...
487 lppd->Flags &= ~PD_COLLATE;
488 lppd->nCopies = 1;
489 /* if the printer driver supports it... store info there
490 * otherwise no collate & multiple copies !
492 if (lpdm->dmFields & DM_COLLATE)
493 lpdm->dmCollate =
494 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
495 if (lpdm->dmFields & DM_COPIES)
496 lpdm->dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
497 } else {
498 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
499 lppd->Flags |= PD_COLLATE;
500 else
501 lppd->Flags &= ~PD_COLLATE;
502 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
505 return TRUE;
508 static BOOL PRINTDLG_UpdatePrintDlgW(HWND hDlg,
509 PRINT_PTRW* PrintStructures)
511 LPPRINTDLGW lppd = PrintStructures->dlg.lpPrintDlg;
512 PDEVMODEW lpdm = PrintStructures->lpDevMode;
513 LPPRINTER_INFO_2W pi = PrintStructures->lpPrinterInfo;
516 if(!lpdm) {
517 FIXME("No lpdm ptr?\n");
518 return FALSE;
522 if(!(lppd->Flags & PD_PRINTSETUP)) {
523 /* check whether nFromPage and nToPage are within range defined by
524 * nMinPage and nMaxPage
526 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
527 WORD nToPage;
528 WORD nFromPage;
529 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
530 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
531 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
532 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
533 char resourcestr[256];
534 char resultstr[256];
535 LoadStringA(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
536 resourcestr, 255);
537 sprintf(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
538 LoadStringA(COMDLG32_hInstance, PD32_PRINT_TITLE,
539 resourcestr, 255);
540 MessageBoxA(hDlg, resultstr, resourcestr,
541 MB_OK | MB_ICONWARNING);
542 return FALSE;
544 lppd->nFromPage = nFromPage;
545 lppd->nToPage = nToPage;
548 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
549 static WCHAR file[] = {'F','I','L','E',':',0};
550 lppd->Flags |= PD_PRINTTOFILE;
551 pi->pPortName = file;
554 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
555 FIXME("Collate lppd not yet implemented as output\n");
558 /* set PD_Collate and nCopies */
559 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
560 /* The application doesn't support multiple copies or collate...
562 lppd->Flags &= ~PD_COLLATE;
563 lppd->nCopies = 1;
564 /* if the printer driver supports it... store info there
565 * otherwise no collate & multiple copies !
567 if (lpdm->dmFields & DM_COLLATE)
568 lpdm->dmCollate =
569 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
570 if (lpdm->dmFields & DM_COPIES)
571 lpdm->dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
572 } else {
573 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
574 lppd->Flags |= PD_COLLATE;
575 else
576 lppd->Flags &= ~PD_COLLATE;
577 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
580 return TRUE;
583 static BOOL PRINTDLG_PaperSizeA(
584 PRINTDLGA *pdlga,const char *PaperSize,LPPOINT size
586 DEVNAMES *dn;
587 DEVMODEA *dm;
588 LPSTR devname,portname;
589 int i;
590 INT NrOfEntries,ret;
591 char *Names = NULL;
592 POINT *points = NULL;
593 BOOL retval = FALSE;
595 dn = GlobalLock(pdlga->hDevNames);
596 dm = GlobalLock(pdlga->hDevMode);
597 devname = ((char*)dn)+dn->wDeviceOffset;
598 portname = ((char*)dn)+dn->wOutputOffset;
601 NrOfEntries = DeviceCapabilitiesA(devname,portname,DC_PAPERNAMES,NULL,dm);
602 if (!NrOfEntries) {
603 FIXME("No papernames found for %s/%s\n",devname,portname);
604 goto out;
606 if (NrOfEntries == -1) {
607 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
608 goto out;
611 Names = (char*)HeapAlloc(GetProcessHeap(),0,NrOfEntries*64);
612 if (NrOfEntries != (ret=DeviceCapabilitiesA(devname,portname,DC_PAPERNAMES,Names,dm))) {
613 FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
614 goto out;
616 for (i=0;i<NrOfEntries;i++)
617 if (!strcmp(PaperSize,Names+(64*i)))
618 break;
619 HeapFree(GetProcessHeap(),0,Names);
620 if (i==NrOfEntries) {
621 FIXME("Papersize %s not found in list?\n",PaperSize);
622 goto out;
624 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
625 if (NrOfEntries!=(ret=DeviceCapabilitiesA(devname,portname,DC_PAPERSIZE,(LPBYTE)points,dm))) {
626 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
627 goto out;
629 /* this is _10ths_ of a millimeter */
630 size->x=points[i].x;
631 size->y=points[i].y;
632 retval = TRUE;
633 out:
634 GlobalUnlock(pdlga->hDevNames);
635 GlobalUnlock(pdlga->hDevMode);
636 if (Names) HeapFree(GetProcessHeap(),0,Names);
637 if (points) HeapFree(GetProcessHeap(),0,points);
638 return retval;
641 static BOOL PRINTDLG_PaperSizeW(
642 PRINTDLGW *pdlga,const WCHAR *PaperSize,LPPOINT size
644 DEVNAMES *dn;
645 DEVMODEW *dm;
646 LPWSTR devname,portname;
647 int i;
648 INT NrOfEntries,ret;
649 WCHAR *Names = NULL;
650 POINT *points = NULL;
651 BOOL retval = FALSE;
653 dn = GlobalLock(pdlga->hDevNames);
654 dm = GlobalLock(pdlga->hDevMode);
655 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
656 portname = ((WCHAR*)dn)+dn->wOutputOffset;
659 NrOfEntries = DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,NULL,dm);
660 if (!NrOfEntries) {
661 FIXME("No papernames found for %s/%s\n",debugstr_w(devname),debugstr_w(portname));
662 goto out;
664 if (NrOfEntries == -1) {
665 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
666 goto out;
669 Names = (WCHAR*)HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*NrOfEntries*64);
670 if (NrOfEntries != (ret=DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,Names,dm))) {
671 FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
672 goto out;
674 for (i=0;i<NrOfEntries;i++)
675 if (!lstrcmpW(PaperSize,Names+(64*i)))
676 break;
677 HeapFree(GetProcessHeap(),0,Names);
678 if (i==NrOfEntries) {
679 FIXME("Papersize %s not found in list?\n",debugstr_w(PaperSize));
680 goto out;
682 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
683 if (NrOfEntries!=(ret=DeviceCapabilitiesW(devname,portname,DC_PAPERSIZE,(LPWSTR)points,dm))) {
684 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
685 goto out;
687 /* this is _10ths_ of a millimeter */
688 size->x=points[i].x;
689 size->y=points[i].y;
690 retval = TRUE;
691 out:
692 GlobalUnlock(pdlga->hDevNames);
693 GlobalUnlock(pdlga->hDevMode);
694 if (Names) HeapFree(GetProcessHeap(),0,Names);
695 if (points) HeapFree(GetProcessHeap(),0,points);
696 return retval;
700 /************************************************************************
701 * PRINTDLG_SetUpPaperComboBox
703 * Initialize either the papersize or inputslot combos of the Printer Setup
704 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
705 * We also try to re-select the old selection.
707 static BOOL PRINTDLG_SetUpPaperComboBoxA(HWND hDlg,
708 int nIDComboBox,
709 char* PrinterName,
710 char* PortName,
711 LPDEVMODEA dm)
713 int i;
714 int NrOfEntries;
715 char* Names;
716 WORD* Words;
717 DWORD Sel;
718 WORD oldWord = 0;
719 int NamesSize;
720 int fwCapability_Names;
721 int fwCapability_Words;
723 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName,PortName,nIDComboBox);
725 /* query the dialog box for the current selected value */
726 Sel = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
727 if(Sel != CB_ERR) {
728 /* we enter here only if a different printer is selected after
729 * the Print Setup dialog is opened. The current settings are
730 * stored into the newly selected printer.
732 oldWord = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA,
733 Sel, 0);
734 if (dm) {
735 if (nIDComboBox == cmb2)
736 dm->u1.s1.dmPaperSize = oldWord;
737 else
738 dm->dmDefaultSource = oldWord;
741 else {
742 /* we enter here only when the Print setup dialog is initially
743 * opened. In this case the settings are restored from when
744 * the dialog was last closed.
746 if (dm) {
747 if (nIDComboBox == cmb2)
748 oldWord = dm->u1.s1.dmPaperSize;
749 else
750 oldWord = dm->dmDefaultSource;
754 if (nIDComboBox == cmb2) {
755 NamesSize = 64;
756 fwCapability_Names = DC_PAPERNAMES;
757 fwCapability_Words = DC_PAPERS;
758 } else {
759 nIDComboBox = cmb3;
760 NamesSize = 24;
761 fwCapability_Names = DC_BINNAMES;
762 fwCapability_Words = DC_BINS;
765 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
766 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
768 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
769 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
770 fwCapability_Names, NULL, dm);
771 if (NrOfEntries == 0)
772 WARN("no Name Entries found!\n");
773 else if (NrOfEntries < 0)
774 return FALSE;
776 if(DeviceCapabilitiesA(PrinterName, PortName, fwCapability_Words, NULL, dm)
777 != NrOfEntries) {
778 ERR("Number of caps is different\n");
779 NrOfEntries = 0;
782 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(char)*NamesSize);
783 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
784 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
785 fwCapability_Names, Names, dm);
786 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
787 fwCapability_Words, (LPSTR)Words, dm);
789 /* reset any current content in the combobox */
790 SendDlgItemMessageA(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
792 /* store new content */
793 for (i = 0; i < NrOfEntries; i++) {
794 DWORD pos = SendDlgItemMessageA(hDlg, nIDComboBox, CB_ADDSTRING, 0,
795 (LPARAM)(&Names[i*NamesSize]) );
796 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
797 Words[i]);
800 /* Look for old selection - can't do this is previous loop since
801 item order will change as more items are added */
802 Sel = 0;
803 for (i = 0; i < NrOfEntries; i++) {
804 if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
805 oldWord) {
806 Sel = i;
807 break;
810 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
812 HeapFree(GetProcessHeap(),0,Words);
813 HeapFree(GetProcessHeap(),0,Names);
814 return TRUE;
817 static BOOL PRINTDLG_SetUpPaperComboBoxW(HWND hDlg,
818 int nIDComboBox,
819 WCHAR* PrinterName,
820 WCHAR* PortName,
821 LPDEVMODEW dm)
823 int i;
824 int NrOfEntries;
825 WCHAR* Names;
826 WORD* Words;
827 DWORD Sel;
828 WORD oldWord = 0;
829 int NamesSize;
830 int fwCapability_Names;
831 int fwCapability_Words;
833 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName),debugstr_w(PortName),nIDComboBox);
835 /* query the dialog box for the current selected value */
836 Sel = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
837 if(Sel != CB_ERR) {
838 /* we enter here only if a different printer is selected after
839 * the Print Setup dialog is opened. The current settings are
840 * stored into the newly selected printer.
842 oldWord = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA,
843 Sel, 0);
844 if (dm) {
845 if (nIDComboBox == cmb2)
846 dm->u1.s1.dmPaperSize = oldWord;
847 else
848 dm->dmDefaultSource = oldWord;
851 else {
852 /* we enter here only when the Print setup dialog is initially
853 * opened. In this case the settings are restored from when
854 * the dialog was last closed.
856 if (dm) {
857 if (nIDComboBox == cmb2)
858 oldWord = dm->u1.s1.dmPaperSize;
859 else
860 oldWord = dm->dmDefaultSource;
864 if (nIDComboBox == cmb2) {
865 NamesSize = 64;
866 fwCapability_Names = DC_PAPERNAMES;
867 fwCapability_Words = DC_PAPERS;
868 } else {
869 nIDComboBox = cmb3;
870 NamesSize = 24;
871 fwCapability_Names = DC_BINNAMES;
872 fwCapability_Words = DC_BINS;
875 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
876 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
878 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
879 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
880 fwCapability_Names, NULL, dm);
881 if (NrOfEntries == 0)
882 WARN("no Name Entries found!\n");
883 else if (NrOfEntries < 0)
884 return FALSE;
886 if(DeviceCapabilitiesW(PrinterName, PortName, fwCapability_Words, NULL, dm)
887 != NrOfEntries) {
888 ERR("Number of caps is different\n");
889 NrOfEntries = 0;
892 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WCHAR)*NamesSize);
893 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
894 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
895 fwCapability_Names, Names, dm);
896 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
897 fwCapability_Words, (LPWSTR)Words, dm);
899 /* reset any current content in the combobox */
900 SendDlgItemMessageA(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
902 /* store new content */
903 for (i = 0; i < NrOfEntries; i++) {
904 DWORD pos = SendDlgItemMessageW(hDlg, nIDComboBox, CB_ADDSTRING, 0,
905 (LPARAM)(&Names[i*NamesSize]) );
906 SendDlgItemMessageW(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
907 Words[i]);
910 /* Look for old selection - can't do this is previous loop since
911 item order will change as more items are added */
912 Sel = 0;
913 for (i = 0; i < NrOfEntries; i++) {
914 if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
915 oldWord) {
916 Sel = i;
917 break;
920 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
922 HeapFree(GetProcessHeap(),0,Words);
923 HeapFree(GetProcessHeap(),0,Names);
924 return TRUE;
928 /***********************************************************************
929 * PRINTDLG_UpdatePrinterInfoTexts [internal]
931 static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg, LPPRINTER_INFO_2A pi)
933 char StatusMsg[256];
934 char ResourceString[256];
935 int i;
937 /* Status Message */
938 StatusMsg[0]='\0';
940 /* add all status messages */
941 for (i = 0; i < 25; i++) {
942 if (pi->Status & (1<<i)) {
943 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
944 ResourceString, 255);
945 strcat(StatusMsg,ResourceString);
948 /* append "ready" */
949 /* FIXME: status==ready must only be appended if really so.
950 but how to detect? */
951 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
952 ResourceString, 255);
953 strcat(StatusMsg,ResourceString);
954 SetDlgItemTextA(hDlg, stc12, StatusMsg);
956 /* set all other printer info texts */
957 SetDlgItemTextA(hDlg, stc11, pi->pDriverName);
959 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
960 SetDlgItemTextA(hDlg, stc14, pi->pLocation);
961 else
962 SetDlgItemTextA(hDlg, stc14, pi->pPortName);
963 SetDlgItemTextA(hDlg, stc13, pi->pComment ? pi->pComment : "");
964 return;
967 static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg, LPPRINTER_INFO_2W pi)
969 WCHAR StatusMsg[256];
970 WCHAR ResourceString[256];
971 static const WCHAR emptyW[] = {0};
972 int i;
974 /* Status Message */
975 StatusMsg[0]='\0';
977 /* add all status messages */
978 for (i = 0; i < 25; i++) {
979 if (pi->Status & (1<<i)) {
980 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
981 ResourceString, 255);
982 lstrcatW(StatusMsg,ResourceString);
985 /* append "ready" */
986 /* FIXME: status==ready must only be appended if really so.
987 but how to detect? */
988 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
989 ResourceString, 255);
990 lstrcatW(StatusMsg,ResourceString);
991 SetDlgItemTextW(hDlg, stc12, StatusMsg);
993 /* set all other printer info texts */
994 SetDlgItemTextW(hDlg, stc11, pi->pDriverName);
995 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
996 SetDlgItemTextW(hDlg, stc14, pi->pLocation);
997 else
998 SetDlgItemTextW(hDlg, stc14, pi->pPortName);
999 SetDlgItemTextW(hDlg, stc13, pi->pComment ? pi->pComment : emptyW);
1003 /*******************************************************************
1005 * PRINTDLG_ChangePrinter
1008 static BOOL PRINTDLG_ChangePrinterA(HWND hDlg, char *name,
1009 PRINT_PTRA *PrintStructures)
1011 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
1012 LPDEVMODEA lpdm = NULL;
1013 LONG dmSize;
1014 DWORD needed;
1015 HANDLE hprn;
1017 if(PrintStructures->lpPrinterInfo)
1018 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
1019 if(PrintStructures->lpDriverInfo)
1020 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
1021 if(!OpenPrinterA(name, &hprn, NULL)) {
1022 ERR("Can't open printer %s\n", name);
1023 return FALSE;
1025 GetPrinterA(hprn, 2, NULL, 0, &needed);
1026 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,needed);
1027 GetPrinterA(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
1028 &needed);
1029 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
1030 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,needed);
1031 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
1032 needed, &needed)) {
1033 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures->lpPrinterInfo->pPrinterName);
1034 return FALSE;
1036 ClosePrinter(hprn);
1038 PRINTDLG_UpdatePrinterInfoTextsA(hDlg, PrintStructures->lpPrinterInfo);
1040 if(PrintStructures->lpDevMode) {
1041 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
1042 PrintStructures->lpDevMode = NULL;
1045 dmSize = DocumentPropertiesA(0, 0, name, NULL, NULL, 0);
1046 if(dmSize == -1) {
1047 ERR("DocumentProperties fails on %s\n", debugstr_a(name));
1048 return FALSE;
1050 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
1051 dmSize = DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, NULL,
1052 DM_OUT_BUFFER);
1053 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
1054 !strcmp(lpdm->dmDeviceName,
1055 PrintStructures->lpDevMode->dmDeviceName)) {
1056 /* Supplied devicemode matches current printer so try to use it */
1057 DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, lpdm,
1058 DM_OUT_BUFFER | DM_IN_BUFFER);
1060 if(lpdm)
1061 GlobalUnlock(lppd->hDevMode);
1063 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
1065 if(!(lppd->Flags & PD_PRINTSETUP)) {
1066 /* Print range (All/Range/Selection) */
1067 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
1068 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
1069 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
1070 if (lppd->Flags & PD_NOSELECTION)
1071 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
1072 else
1073 if (lppd->Flags & PD_SELECTION)
1074 CheckRadioButton(hDlg, rad1, rad3, rad2);
1075 if (lppd->Flags & PD_NOPAGENUMS) {
1076 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
1077 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
1078 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
1079 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
1080 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
1081 } else {
1082 if (lppd->Flags & PD_PAGENUMS)
1083 CheckRadioButton(hDlg, rad1, rad3, rad3);
1085 /* "All xxx pages"... */
1087 char resourcestr[64];
1088 char result[64];
1089 LoadStringA(COMDLG32_hInstance, PD32_PRINT_ALL_X_PAGES,
1090 resourcestr, 49);
1091 sprintf(result,resourcestr,lppd->nMaxPage - lppd->nMinPage + 1);
1092 SendDlgItemMessageA(hDlg, rad1, WM_SETTEXT, 0, (LPARAM) result);
1095 /* Collate pages
1097 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1099 if (lppd->Flags & PD_COLLATE) {
1100 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1101 (LPARAM)PrintStructures->hCollateIcon);
1102 CheckDlgButton(hDlg, chx2, 1);
1103 } else {
1104 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1105 (LPARAM)PrintStructures->hNoCollateIcon);
1106 CheckDlgButton(hDlg, chx2, 0);
1109 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1110 /* if printer doesn't support it: no Collate */
1111 if (!(lpdm->dmFields & DM_COLLATE)) {
1112 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1113 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
1117 /* nCopies */
1119 INT copies;
1120 if (lppd->hDevMode == 0)
1121 copies = lppd->nCopies;
1122 else
1123 copies = lpdm->dmCopies;
1124 if(copies == 0) copies = 1;
1125 else if(copies < 0) copies = MAX_COPIES;
1126 SetDlgItemInt(hDlg, edt3, copies, FALSE);
1129 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1130 /* if printer doesn't support it: no nCopies */
1131 if (!(lpdm->dmFields & DM_COPIES)) {
1132 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
1133 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
1137 /* print to file */
1138 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
1139 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
1140 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
1141 if (lppd->Flags & PD_HIDEPRINTTOFILE)
1142 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
1144 } else { /* PD_PRINTSETUP */
1145 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
1147 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb2,
1148 PrintStructures->lpPrinterInfo->pPrinterName,
1149 PrintStructures->lpPrinterInfo->pPortName,
1150 lpdm);
1151 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb3,
1152 PrintStructures->lpPrinterInfo->pPrinterName,
1153 PrintStructures->lpPrinterInfo->pPortName,
1154 lpdm);
1155 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1156 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1157 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1158 PrintStructures->hLandscapeIcon));
1162 /* help button */
1163 if ((lppd->Flags & PD_SHOWHELP)==0) {
1164 /* hide if PD_SHOWHELP not specified */
1165 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1167 return TRUE;
1170 static BOOL PRINTDLG_ChangePrinterW(HWND hDlg, WCHAR *name,
1171 PRINT_PTRW *PrintStructures)
1173 LPPRINTDLGW lppd = PrintStructures->dlg.lpPrintDlg;
1174 LPDEVMODEW lpdm = NULL;
1175 LONG dmSize;
1176 DWORD needed;
1177 HANDLE hprn;
1179 if(PrintStructures->lpPrinterInfo)
1180 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
1181 if(PrintStructures->lpDriverInfo)
1182 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
1183 if(!OpenPrinterW(name, &hprn, NULL)) {
1184 ERR("Can't open printer %s\n", debugstr_w(name));
1185 return FALSE;
1187 GetPrinterW(hprn, 2, NULL, 0, &needed);
1188 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
1189 GetPrinterW(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
1190 &needed);
1191 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
1192 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
1193 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
1194 needed, &needed)) {
1195 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures->lpPrinterInfo->pPrinterName));
1196 return FALSE;
1198 ClosePrinter(hprn);
1200 PRINTDLG_UpdatePrinterInfoTextsW(hDlg, PrintStructures->lpPrinterInfo);
1202 if(PrintStructures->lpDevMode) {
1203 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
1204 PrintStructures->lpDevMode = NULL;
1207 dmSize = DocumentPropertiesW(0, 0, name, NULL, NULL, 0);
1208 if(dmSize == -1) {
1209 ERR("DocumentProperties fails on %s\n", debugstr_w(name));
1210 return FALSE;
1212 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
1213 dmSize = DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, NULL,
1214 DM_OUT_BUFFER);
1215 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
1216 !lstrcmpW(lpdm->dmDeviceName,
1217 PrintStructures->lpDevMode->dmDeviceName)) {
1218 /* Supplied devicemode matches current printer so try to use it */
1219 DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, lpdm,
1220 DM_OUT_BUFFER | DM_IN_BUFFER);
1222 if(lpdm)
1223 GlobalUnlock(lppd->hDevMode);
1225 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
1227 if(!(lppd->Flags & PD_PRINTSETUP)) {
1228 /* Print range (All/Range/Selection) */
1229 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
1230 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
1231 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
1232 if (lppd->Flags & PD_NOSELECTION)
1233 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
1234 else
1235 if (lppd->Flags & PD_SELECTION)
1236 CheckRadioButton(hDlg, rad1, rad3, rad2);
1237 if (lppd->Flags & PD_NOPAGENUMS) {
1238 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
1239 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
1240 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
1241 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
1242 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
1243 } else {
1244 if (lppd->Flags & PD_PAGENUMS)
1245 CheckRadioButton(hDlg, rad1, rad3, rad3);
1247 /* "All xxx pages"... */
1249 /* ansi is ok */
1250 char resourcestr[64];
1251 char result[64];
1252 LoadStringA(COMDLG32_hInstance, PD32_PRINT_ALL_X_PAGES,
1253 resourcestr, 49);
1254 sprintf(result,resourcestr,lppd->nMaxPage - lppd->nMinPage + 1);
1255 SendDlgItemMessageA(hDlg, rad1, WM_SETTEXT, 0, (LPARAM) result);
1258 /* Collate pages
1260 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1262 if (lppd->Flags & PD_COLLATE) {
1263 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1264 (LPARAM)PrintStructures->hCollateIcon);
1265 CheckDlgButton(hDlg, chx2, 1);
1266 } else {
1267 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1268 (LPARAM)PrintStructures->hNoCollateIcon);
1269 CheckDlgButton(hDlg, chx2, 0);
1272 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1273 /* if printer doesn't support it: no Collate */
1274 if (!(lpdm->dmFields & DM_COLLATE)) {
1275 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1276 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
1280 /* nCopies */
1282 INT copies;
1283 if (lppd->hDevMode == 0)
1284 copies = lppd->nCopies;
1285 else
1286 copies = lpdm->dmCopies;
1287 if(copies == 0) copies = 1;
1288 else if(copies < 0) copies = MAX_COPIES;
1289 SetDlgItemInt(hDlg, edt3, copies, FALSE);
1292 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1293 /* if printer doesn't support it: no nCopies */
1294 if (!(lpdm->dmFields & DM_COPIES)) {
1295 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
1296 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
1300 /* print to file */
1301 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
1302 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
1303 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
1304 if (lppd->Flags & PD_HIDEPRINTTOFILE)
1305 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
1307 } else { /* PD_PRINTSETUP */
1308 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
1310 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb2,
1311 PrintStructures->lpPrinterInfo->pPrinterName,
1312 PrintStructures->lpPrinterInfo->pPortName,
1313 lpdm);
1314 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb3,
1315 PrintStructures->lpPrinterInfo->pPrinterName,
1316 PrintStructures->lpPrinterInfo->pPortName,
1317 lpdm);
1318 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1319 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1320 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1321 PrintStructures->hLandscapeIcon));
1325 /* help button */
1326 if ((lppd->Flags & PD_SHOWHELP)==0) {
1327 /* hide if PD_SHOWHELP not specified */
1328 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1330 return TRUE;
1333 /***********************************************************************
1334 * PRINTDLG_WMInitDialog [internal]
1336 static LRESULT PRINTDLG_WMInitDialog(HWND hDlg, WPARAM wParam,
1337 PRINT_PTRA* PrintStructures)
1339 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
1340 DEVNAMES *pdn;
1341 DEVMODEA *pdm;
1342 char *name = NULL;
1343 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1345 /* load Collate ICONs */
1346 /* We load these with LoadImage because they are not a standard
1347 size and we don't want them rescaled */
1348 PrintStructures->hCollateIcon =
1349 LoadImageA(COMDLG32_hInstance, "PD32_COLLATE", IMAGE_ICON, 0, 0, 0);
1350 PrintStructures->hNoCollateIcon =
1351 LoadImageA(COMDLG32_hInstance, "PD32_NOCOLLATE", IMAGE_ICON, 0, 0, 0);
1353 /* These can be done with LoadIcon */
1354 PrintStructures->hPortraitIcon =
1355 LoadIconA(COMDLG32_hInstance, "PD32_PORTRAIT");
1356 PrintStructures->hLandscapeIcon =
1357 LoadIconA(COMDLG32_hInstance, "PD32_LANDSCAPE");
1359 if(PrintStructures->hCollateIcon == 0 ||
1360 PrintStructures->hNoCollateIcon == 0 ||
1361 PrintStructures->hPortraitIcon == 0 ||
1362 PrintStructures->hLandscapeIcon == 0) {
1363 ERR("no icon in resourcefile\n");
1364 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1365 EndDialog(hDlg, FALSE);
1369 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1370 * must be registered and the Help button must be shown.
1372 if (lppd->Flags & PD_SHOWHELP) {
1373 if((PrintStructures->HelpMessageID =
1374 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
1375 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1376 return FALSE;
1378 } else
1379 PrintStructures->HelpMessageID = 0;
1381 if(!(lppd->Flags &PD_PRINTSETUP)) {
1382 PrintStructures->hwndUpDown =
1383 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1384 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1385 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1386 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1387 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1390 /* FIXME: I allow more freedom than either Win95 or WinNT,
1391 * which do not agree to what errors should be thrown or not
1392 * in case nToPage or nFromPage is out-of-range.
1394 if (lppd->nMaxPage < lppd->nMinPage)
1395 lppd->nMaxPage = lppd->nMinPage;
1396 if (lppd->nMinPage == lppd->nMaxPage)
1397 lppd->Flags |= PD_NOPAGENUMS;
1398 if (lppd->nToPage < lppd->nMinPage)
1399 lppd->nToPage = lppd->nMinPage;
1400 if (lppd->nToPage > lppd->nMaxPage)
1401 lppd->nToPage = lppd->nMaxPage;
1402 if (lppd->nFromPage < lppd->nMinPage)
1403 lppd->nFromPage = lppd->nMinPage;
1404 if (lppd->nFromPage > lppd->nMaxPage)
1405 lppd->nFromPage = lppd->nMaxPage;
1407 /* if we have the combo box, fill it */
1408 if (GetDlgItem(hDlg,comboID)) {
1409 /* Fill Combobox
1411 pdn = GlobalLock(lppd->hDevNames);
1412 pdm = GlobalLock(lppd->hDevMode);
1413 if(pdn)
1414 name = (char*)pdn + pdn->wDeviceOffset;
1415 else if(pdm)
1416 name = pdm->dmDeviceName;
1417 PRINTDLG_SetUpPrinterListComboA(hDlg, comboID, name);
1418 if(pdm) GlobalUnlock(lppd->hDevMode);
1419 if(pdn) GlobalUnlock(lppd->hDevNames);
1421 /* Now find selected printer and update rest of dlg */
1422 name = HeapAlloc(GetProcessHeap(),0,256);
1423 if (GetDlgItemTextA(hDlg, comboID, name, 255))
1424 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1425 HeapFree(GetProcessHeap(),0,name);
1426 } else {
1427 /* else use default printer */
1428 char name[200];
1429 BOOL ret = PRINTDLG_GetDefaultPrinterNameA(name, sizeof(name));
1431 if (ret)
1432 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1433 else
1434 FIXME("No default printer found, expect problems!\n");
1436 return TRUE;
1439 static LRESULT PRINTDLG_WMInitDialogW(HWND hDlg, WPARAM wParam,
1440 PRINT_PTRW* PrintStructures)
1442 LPPRINTDLGW lppd = PrintStructures->dlg.lpPrintDlg;
1443 DEVNAMES *pdn;
1444 DEVMODEW *pdm;
1445 WCHAR *name = NULL;
1446 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1448 /* load Collate ICONs */
1449 /* We load these with LoadImage because they are not a standard
1450 size and we don't want them rescaled */
1451 PrintStructures->hCollateIcon =
1452 LoadImageA(COMDLG32_hInstance, "PD32_COLLATE", IMAGE_ICON, 0, 0, 0);
1453 PrintStructures->hNoCollateIcon =
1454 LoadImageA(COMDLG32_hInstance, "PD32_NOCOLLATE", IMAGE_ICON, 0, 0, 0);
1456 /* These can be done with LoadIcon */
1457 PrintStructures->hPortraitIcon =
1458 LoadIconA(COMDLG32_hInstance, "PD32_PORTRAIT");
1459 PrintStructures->hLandscapeIcon =
1460 LoadIconA(COMDLG32_hInstance, "PD32_LANDSCAPE");
1462 if(PrintStructures->hCollateIcon == 0 ||
1463 PrintStructures->hNoCollateIcon == 0 ||
1464 PrintStructures->hPortraitIcon == 0 ||
1465 PrintStructures->hLandscapeIcon == 0) {
1466 ERR("no icon in resourcefile\n");
1467 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1468 EndDialog(hDlg, FALSE);
1472 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1473 * must be registered and the Help button must be shown.
1475 if (lppd->Flags & PD_SHOWHELP) {
1476 if((PrintStructures->HelpMessageID =
1477 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
1478 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1479 return FALSE;
1481 } else
1482 PrintStructures->HelpMessageID = 0;
1484 if(!(lppd->Flags &PD_PRINTSETUP)) {
1485 PrintStructures->hwndUpDown =
1486 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1487 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1488 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1489 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1490 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1493 /* FIXME: I allow more freedom than either Win95 or WinNT,
1494 * which do not agree to what errors should be thrown or not
1495 * in case nToPage or nFromPage is out-of-range.
1497 if (lppd->nMaxPage < lppd->nMinPage)
1498 lppd->nMaxPage = lppd->nMinPage;
1499 if (lppd->nMinPage == lppd->nMaxPage)
1500 lppd->Flags |= PD_NOPAGENUMS;
1501 if (lppd->nToPage < lppd->nMinPage)
1502 lppd->nToPage = lppd->nMinPage;
1503 if (lppd->nToPage > lppd->nMaxPage)
1504 lppd->nToPage = lppd->nMaxPage;
1505 if (lppd->nFromPage < lppd->nMinPage)
1506 lppd->nFromPage = lppd->nMinPage;
1507 if (lppd->nFromPage > lppd->nMaxPage)
1508 lppd->nFromPage = lppd->nMaxPage;
1510 /* if we have the combo box, fill it */
1511 if (GetDlgItem(hDlg,comboID)) {
1512 /* Fill Combobox
1514 pdn = GlobalLock(lppd->hDevNames);
1515 pdm = GlobalLock(lppd->hDevMode);
1516 if(pdn)
1517 name = (WCHAR*)pdn + pdn->wDeviceOffset;
1518 else if(pdm)
1519 name = pdm->dmDeviceName;
1520 PRINTDLG_SetUpPrinterListComboW(hDlg, comboID, name);
1521 if(pdm) GlobalUnlock(lppd->hDevMode);
1522 if(pdn) GlobalUnlock(lppd->hDevNames);
1524 /* Now find selected printer and update rest of dlg */
1525 /* ansi is ok here */
1526 name = HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR));
1527 if (GetDlgItemTextW(hDlg, comboID, name, 255))
1528 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1529 HeapFree(GetProcessHeap(),0,name);
1530 } else {
1531 /* else use default printer */
1532 WCHAR name[200];
1533 BOOL ret = PRINTDLG_GetDefaultPrinterNameW(name, sizeof(name));
1535 if (ret)
1536 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1537 else
1538 FIXME("No default printer found, expect problems!\n");
1540 return TRUE;
1544 /***********************************************************************
1545 * PRINTDLG_WMInitDialog [internal]
1547 static LRESULT PRINTDLG_WMInitDialog16(HWND hDlg, WPARAM wParam,
1548 PRINT_PTRA* PrintStructures)
1550 LPPRINTDLG16 lppd = PrintStructures->dlg.lpPrintDlg16;
1551 DEVNAMES *pdn;
1552 DEVMODEA *pdm;
1553 char *name = NULL;
1554 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1556 /* load Collate ICONs */
1557 PrintStructures->hCollateIcon =
1558 LoadIconA(COMDLG32_hInstance, "PD32_COLLATE");
1559 PrintStructures->hNoCollateIcon =
1560 LoadIconA(COMDLG32_hInstance, "PD32_NOCOLLATE");
1561 if(PrintStructures->hCollateIcon == 0 ||
1562 PrintStructures->hNoCollateIcon == 0) {
1563 ERR("no icon in resourcefile\n");
1564 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1565 EndDialog(hDlg, FALSE);
1568 /* load Paper Orientation ICON */
1569 /* FIXME: not implemented yet */
1572 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1573 * must be registered and the Help button must be shown.
1575 if (lppd->Flags & PD_SHOWHELP) {
1576 if((PrintStructures->HelpMessageID =
1577 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
1578 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1579 return FALSE;
1581 } else
1582 PrintStructures->HelpMessageID = 0;
1584 if (!(lppd->Flags & PD_PRINTSETUP)) {
1585 /* We have a print quality combo box. What shall we do? */
1586 if (GetDlgItem(hDlg,cmb1)) {
1587 char buf [20];
1589 FIXME("Print quality only displaying currently.\n");
1591 pdm = GlobalLock16(lppd->hDevMode);
1592 if(pdm) {
1593 switch (pdm->dmPrintQuality) {
1594 case DMRES_HIGH : strcpy(buf,"High");break;
1595 case DMRES_MEDIUM : strcpy(buf,"Medium");break;
1596 case DMRES_LOW : strcpy(buf,"Low");break;
1597 case DMRES_DRAFT : strcpy(buf,"Draft");break;
1598 case 0 : strcpy(buf,"Default");break;
1599 default : sprintf(buf,"%ddpi",pdm->dmPrintQuality);break;
1601 GlobalUnlock16(lppd->hDevMode);
1602 } else
1603 strcpy(buf,"Default");
1604 SendDlgItemMessageA(hDlg,cmb1,CB_ADDSTRING,0,(LPARAM)buf);
1605 SendDlgItemMessageA(hDlg,cmb1,CB_SETCURSEL,0,0);
1606 EnableWindow(GetDlgItem(hDlg,cmb1),FALSE);
1610 /* FIXME: I allow more freedom than either Win95 or WinNT,
1611 * which do not agree to what errors should be thrown or not
1612 * in case nToPage or nFromPage is out-of-range.
1614 if (lppd->nMaxPage < lppd->nMinPage)
1615 lppd->nMaxPage = lppd->nMinPage;
1616 if (lppd->nMinPage == lppd->nMaxPage)
1617 lppd->Flags |= PD_NOPAGENUMS;
1618 if (lppd->nToPage < lppd->nMinPage)
1619 lppd->nToPage = lppd->nMinPage;
1620 if (lppd->nToPage > lppd->nMaxPage)
1621 lppd->nToPage = lppd->nMaxPage;
1622 if (lppd->nFromPage < lppd->nMinPage)
1623 lppd->nFromPage = lppd->nMinPage;
1624 if (lppd->nFromPage > lppd->nMaxPage)
1625 lppd->nFromPage = lppd->nMaxPage;
1627 /* If the printer combo box is in the dialog, fill it */
1628 if (GetDlgItem(hDlg,comboID)) {
1629 /* Fill Combobox
1631 pdn = GlobalLock16(lppd->hDevNames);
1632 pdm = GlobalLock16(lppd->hDevMode);
1633 if(pdn)
1634 name = (char*)pdn + pdn->wDeviceOffset;
1635 else if(pdm)
1636 name = pdm->dmDeviceName;
1637 PRINTDLG_SetUpPrinterListComboA(hDlg, comboID, name);
1638 if(pdm) GlobalUnlock16(lppd->hDevMode);
1639 if(pdn) GlobalUnlock16(lppd->hDevNames);
1641 /* Now find selected printer and update rest of dlg */
1642 name = HeapAlloc(GetProcessHeap(),0,256);
1643 if (GetDlgItemTextA(hDlg, comboID, name, 255))
1644 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1645 } else {
1646 /* else just use default printer */
1647 char name[200];
1648 BOOL ret = PRINTDLG_GetDefaultPrinterNameA(name, sizeof(name));
1650 if (ret)
1651 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1652 else
1653 FIXME("No default printer found, expect problems!\n");
1655 HeapFree(GetProcessHeap(),0,name);
1657 return TRUE;
1660 /***********************************************************************
1661 * PRINTDLG_WMCommand [internal]
1663 static LRESULT PRINTDLG_WMCommandA(HWND hDlg, WPARAM wParam,
1664 LPARAM lParam, PRINT_PTRA* PrintStructures)
1666 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
1667 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1668 LPDEVMODEA lpdm = PrintStructures->lpDevMode;
1670 switch (LOWORD(wParam)) {
1671 case IDOK:
1672 TRACE(" OK button was hit\n");
1673 if (PRINTDLG_UpdatePrintDlgA(hDlg, PrintStructures)!=TRUE) {
1674 FIXME("Update printdlg was not successful!\n");
1675 return(FALSE);
1677 EndDialog(hDlg, TRUE);
1678 return(TRUE);
1680 case IDCANCEL:
1681 TRACE(" CANCEL button was hit\n");
1682 EndDialog(hDlg, FALSE);
1683 return(FALSE);
1685 case pshHelp:
1686 TRACE(" HELP button was hit\n");
1687 SendMessageA(lppd->hwndOwner, PrintStructures->HelpMessageID,
1688 (WPARAM) hDlg, (LPARAM) lppd);
1689 break;
1691 case chx2: /* collate pages checkbox */
1692 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1693 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1694 (LPARAM)PrintStructures->hCollateIcon);
1695 else
1696 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1697 (LPARAM)PrintStructures->hNoCollateIcon);
1698 break;
1699 case edt1: /* from page nr editbox */
1700 case edt2: /* to page nr editbox */
1701 if (HIWORD(wParam)==EN_CHANGE) {
1702 WORD nToPage;
1703 WORD nFromPage;
1704 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1705 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1706 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1707 CheckRadioButton(hDlg, rad1, rad3, rad3);
1709 break;
1711 case edt3:
1712 if(HIWORD(wParam) == EN_CHANGE) {
1713 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1714 if(copies <= 1)
1715 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1716 else
1717 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1719 break;
1721 case psh1: /* Print Setup */
1723 PRINTDLG16 pdlg;
1725 if (!PrintStructures->dlg.lpPrintDlg16) {
1726 FIXME("The 32bit print dialog does not have this button!?\n");
1727 break;
1730 memcpy(&pdlg,PrintStructures->dlg.lpPrintDlg16,sizeof(pdlg));
1731 pdlg.Flags |= PD_PRINTSETUP;
1732 pdlg.hwndOwner = HWND_16(hDlg);
1733 if (!PrintDlg16(&pdlg))
1734 break;
1736 break;
1737 case psh2: /* Properties button */
1739 HANDLE hPrinter;
1740 char PrinterName[256];
1742 GetDlgItemTextA(hDlg, PrinterComboID, PrinterName, 255);
1743 if (!OpenPrinterA(PrinterName, &hPrinter, NULL)) {
1744 FIXME(" Call to OpenPrinter did not succeed!\n");
1745 break;
1747 DocumentPropertiesA(hDlg, hPrinter, PrinterName,
1748 PrintStructures->lpDevMode,
1749 PrintStructures->lpDevMode,
1750 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1751 ClosePrinter(hPrinter);
1752 break;
1755 case rad1: /* Paperorientation */
1756 if (lppd->Flags & PD_PRINTSETUP)
1758 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1759 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1760 (LPARAM)(PrintStructures->hPortraitIcon));
1762 break;
1764 case rad2: /* Paperorientation */
1765 if (lppd->Flags & PD_PRINTSETUP)
1767 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1768 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1769 (LPARAM)(PrintStructures->hLandscapeIcon));
1771 break;
1773 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1774 if (PrinterComboID != wParam) {
1775 FIXME("No handling for print quality combo box yet.\n");
1776 break;
1778 /* FALLTHROUGH */
1779 case cmb4: /* Printer combobox */
1780 if (HIWORD(wParam)==CBN_SELCHANGE) {
1781 char PrinterName[256];
1782 GetDlgItemTextA(hDlg, LOWORD(wParam), PrinterName, 255);
1783 PRINTDLG_ChangePrinterA(hDlg, PrinterName, PrintStructures);
1785 break;
1787 case cmb2: /* Papersize */
1789 DWORD Sel = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1790 if(Sel != CB_ERR)
1791 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
1792 CB_GETITEMDATA,
1793 Sel, 0);
1795 break;
1797 case cmb3: /* Bin */
1799 DWORD Sel = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1800 if(Sel != CB_ERR)
1801 lpdm->dmDefaultSource = SendDlgItemMessageA(hDlg, cmb3,
1802 CB_GETITEMDATA, Sel,
1805 break;
1807 if(lppd->Flags & PD_PRINTSETUP) {
1808 switch (LOWORD(wParam)) {
1809 case rad1: /* orientation */
1810 case rad2:
1811 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1812 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1813 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1814 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1815 (WPARAM)IMAGE_ICON,
1816 (LPARAM)PrintStructures->hPortraitIcon);
1817 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1818 (WPARAM)IMAGE_ICON,
1819 (LPARAM)PrintStructures->hPortraitIcon);
1821 } else {
1822 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1823 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1824 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1825 (WPARAM)IMAGE_ICON,
1826 (LPARAM)PrintStructures->hLandscapeIcon);
1827 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1828 (WPARAM)IMAGE_ICON,
1829 (LPARAM)PrintStructures->hLandscapeIcon);
1832 break;
1835 return FALSE;
1838 static LRESULT PRINTDLG_WMCommandW(HWND hDlg, WPARAM wParam,
1839 LPARAM lParam, PRINT_PTRW* PrintStructures)
1841 LPPRINTDLGW lppd = PrintStructures->dlg.lpPrintDlg;
1842 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1843 LPDEVMODEW lpdm = PrintStructures->lpDevMode;
1845 switch (LOWORD(wParam)) {
1846 case IDOK:
1847 TRACE(" OK button was hit\n");
1848 if (PRINTDLG_UpdatePrintDlgW(hDlg, PrintStructures)!=TRUE) {
1849 FIXME("Update printdlg was not successful!\n");
1850 return(FALSE);
1852 EndDialog(hDlg, TRUE);
1853 return(TRUE);
1855 case IDCANCEL:
1856 TRACE(" CANCEL button was hit\n");
1857 EndDialog(hDlg, FALSE);
1858 return(FALSE);
1860 case pshHelp:
1861 TRACE(" HELP button was hit\n");
1862 SendMessageW(lppd->hwndOwner, PrintStructures->HelpMessageID,
1863 (WPARAM) hDlg, (LPARAM) lppd);
1864 break;
1866 case chx2: /* collate pages checkbox */
1867 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1868 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1869 (LPARAM)PrintStructures->hCollateIcon);
1870 else
1871 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1872 (LPARAM)PrintStructures->hNoCollateIcon);
1873 break;
1874 case edt1: /* from page nr editbox */
1875 case edt2: /* to page nr editbox */
1876 if (HIWORD(wParam)==EN_CHANGE) {
1877 WORD nToPage;
1878 WORD nFromPage;
1879 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1880 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1881 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1882 CheckRadioButton(hDlg, rad1, rad3, rad3);
1884 break;
1886 case edt3:
1887 if(HIWORD(wParam) == EN_CHANGE) {
1888 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1889 if(copies <= 1)
1890 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1891 else
1892 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1894 break;
1896 case psh1: /* Print Setup */
1898 ERR("psh1 is called from 16bit code only, we should not get here.\n");
1900 break;
1901 case psh2: /* Properties button */
1903 HANDLE hPrinter;
1904 WCHAR PrinterName[256];
1906 GetDlgItemTextW(hDlg, PrinterComboID, PrinterName, 255);
1907 if (!OpenPrinterW(PrinterName, &hPrinter, NULL)) {
1908 FIXME(" Call to OpenPrinter did not succeed!\n");
1909 break;
1911 DocumentPropertiesW(hDlg, hPrinter, PrinterName,
1912 PrintStructures->lpDevMode,
1913 PrintStructures->lpDevMode,
1914 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1915 ClosePrinter(hPrinter);
1916 break;
1919 case rad1: /* Paperorientation */
1920 if (lppd->Flags & PD_PRINTSETUP)
1922 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1923 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1924 (LPARAM)(PrintStructures->hPortraitIcon));
1926 break;
1928 case rad2: /* Paperorientation */
1929 if (lppd->Flags & PD_PRINTSETUP)
1931 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1932 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1933 (LPARAM)(PrintStructures->hLandscapeIcon));
1935 break;
1937 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1938 if (PrinterComboID != wParam) {
1939 FIXME("No handling for print quality combo box yet.\n");
1940 break;
1942 /* FALLTHROUGH */
1943 case cmb4: /* Printer combobox */
1944 if (HIWORD(wParam)==CBN_SELCHANGE) {
1945 WCHAR PrinterName[256];
1946 GetDlgItemTextW(hDlg, LOWORD(wParam), PrinterName, 255);
1947 PRINTDLG_ChangePrinterW(hDlg, PrinterName, PrintStructures);
1949 break;
1951 case cmb2: /* Papersize */
1953 DWORD Sel = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1954 if(Sel != CB_ERR)
1955 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
1956 CB_GETITEMDATA,
1957 Sel, 0);
1959 break;
1961 case cmb3: /* Bin */
1963 DWORD Sel = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1964 if(Sel != CB_ERR)
1965 lpdm->dmDefaultSource = SendDlgItemMessageW(hDlg, cmb3,
1966 CB_GETITEMDATA, Sel,
1969 break;
1971 if(lppd->Flags & PD_PRINTSETUP) {
1972 switch (LOWORD(wParam)) {
1973 case rad1: /* orientation */
1974 case rad2:
1975 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1976 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1977 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1978 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1979 (WPARAM)IMAGE_ICON,
1980 (LPARAM)PrintStructures->hPortraitIcon);
1981 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1982 (WPARAM)IMAGE_ICON,
1983 (LPARAM)PrintStructures->hPortraitIcon);
1985 } else {
1986 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1987 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1988 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1989 (WPARAM)IMAGE_ICON,
1990 (LPARAM)PrintStructures->hLandscapeIcon);
1991 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1992 (WPARAM)IMAGE_ICON,
1993 (LPARAM)PrintStructures->hLandscapeIcon);
1996 break;
1999 return FALSE;
2002 /***********************************************************************
2003 * PrintDlgProcA [internal]
2005 INT_PTR CALLBACK PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
2006 LPARAM lParam)
2008 PRINT_PTRA* PrintStructures;
2009 INT_PTR res = FALSE;
2011 if (uMsg!=WM_INITDIALOG) {
2012 PrintStructures = (PRINT_PTRA*)GetPropA(hDlg,"__WINE_PRINTDLGDATA");
2013 if (!PrintStructures)
2014 return FALSE;
2015 } else {
2016 PrintStructures = (PRINT_PTRA*) lParam;
2017 SetPropA(hDlg,"__WINE_PRINTDLGDATA",PrintStructures);
2018 res = PRINTDLG_WMInitDialog(hDlg, wParam, PrintStructures);
2020 if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
2021 res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(
2022 hDlg, uMsg, wParam, (LPARAM)PrintStructures->dlg.lpPrintDlg
2024 return res;
2027 if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
2028 res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam,
2029 lParam);
2030 if(res) return res;
2033 switch (uMsg) {
2034 case WM_COMMAND:
2035 return PRINTDLG_WMCommandA(hDlg, wParam, lParam, PrintStructures);
2037 case WM_DESTROY:
2038 DestroyIcon(PrintStructures->hCollateIcon);
2039 DestroyIcon(PrintStructures->hNoCollateIcon);
2040 DestroyIcon(PrintStructures->hPortraitIcon);
2041 DestroyIcon(PrintStructures->hLandscapeIcon);
2042 if(PrintStructures->hwndUpDown)
2043 DestroyWindow(PrintStructures->hwndUpDown);
2044 return FALSE;
2046 return res;
2049 INT_PTR CALLBACK PrintDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
2050 LPARAM lParam)
2052 PRINT_PTRW* PrintStructures;
2053 INT_PTR res = FALSE;
2055 if (uMsg!=WM_INITDIALOG) {
2056 PrintStructures = (PRINT_PTRW*) GetWindowLongW(hDlg, DWL_USER);
2057 if (!PrintStructures)
2058 return FALSE;
2059 } else {
2060 PrintStructures = (PRINT_PTRW*) lParam;
2061 SetWindowLongA(hDlg, DWL_USER, lParam);
2062 res = PRINTDLG_WMInitDialogW(hDlg, wParam, PrintStructures);
2064 if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
2065 res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(
2066 hDlg, uMsg, wParam, (LPARAM)PrintStructures->dlg.lpPrintDlg
2068 return res;
2071 if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
2072 res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam,
2073 lParam);
2074 if(res) return res;
2077 switch (uMsg) {
2078 case WM_COMMAND:
2079 return PRINTDLG_WMCommandW(hDlg, wParam, lParam, PrintStructures);
2081 case WM_DESTROY:
2082 DestroyIcon(PrintStructures->hCollateIcon);
2083 DestroyIcon(PrintStructures->hNoCollateIcon);
2084 DestroyIcon(PrintStructures->hPortraitIcon);
2085 DestroyIcon(PrintStructures->hLandscapeIcon);
2086 if(PrintStructures->hwndUpDown)
2087 DestroyWindow(PrintStructures->hwndUpDown);
2088 return FALSE;
2090 return res;
2094 /************************************************************
2096 * PRINTDLG_Get16TemplateFrom32 [Internal]
2097 * Generates a 16 bits template from the Wine 32 bits resource
2100 static HGLOBAL16 PRINTDLG_Get16TemplateFrom32(char *PrintResourceName)
2102 HRSRC hResInfo;
2103 HGLOBAL hDlgTmpl32;
2104 LPCVOID template32;
2105 DWORD size;
2106 HGLOBAL16 hGlobal16;
2107 LPVOID template;
2109 if (!(hResInfo = FindResourceA(COMDLG32_hInstance,
2110 PrintResourceName, RT_DIALOGA)))
2112 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
2113 return 0;
2115 if (!(hDlgTmpl32 = LoadResource(COMDLG32_hInstance, hResInfo )) ||
2116 !(template32 = LockResource( hDlgTmpl32 )))
2118 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2119 return 0;
2121 size = SizeofResource(COMDLG32_hInstance, hResInfo);
2122 hGlobal16 = GlobalAlloc16(0, size);
2123 if (!hGlobal16)
2125 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
2126 ERR("alloc failure for %ld bytes\n", size);
2127 return 0;
2129 template = GlobalLock16(hGlobal16);
2130 if (!template)
2132 COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE);
2133 ERR("global lock failure for %x handle\n", hGlobal16);
2134 GlobalFree16(hGlobal16);
2135 return 0;
2137 ConvertDialog32To16((LPVOID)template32, size, (LPVOID)template);
2138 GlobalUnlock16(hGlobal16);
2139 return hGlobal16;
2142 /************************************************************
2144 * PRINTDLG_GetDlgTemplate
2147 static HGLOBAL PRINTDLG_GetDlgTemplateA(PRINTDLGA *lppd)
2149 HRSRC hResInfo;
2150 HGLOBAL hDlgTmpl;
2152 if (lppd->Flags & PD_PRINTSETUP) {
2153 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
2154 hDlgTmpl = lppd->hSetupTemplate;
2155 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
2156 hResInfo = FindResourceA(lppd->hInstance,
2157 lppd->lpSetupTemplateName, RT_DIALOGA);
2158 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2159 } else {
2160 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32_SETUP",
2161 RT_DIALOGA);
2162 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
2164 } else {
2165 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
2166 hDlgTmpl = lppd->hPrintTemplate;
2167 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
2168 hResInfo = FindResourceA(lppd->hInstance,
2169 lppd->lpPrintTemplateName,
2170 RT_DIALOGA);
2171 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2172 } else {
2173 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32",
2174 RT_DIALOGA);
2175 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
2178 return hDlgTmpl;
2181 static HGLOBAL PRINTDLG_GetDlgTemplateW(PRINTDLGW *lppd)
2183 HRSRC hResInfo;
2184 HGLOBAL hDlgTmpl;
2185 const WCHAR xpsetup[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
2186 const WCHAR xprint[] = { 'P','R','I','N','T','3','2',0};
2188 if (lppd->Flags & PD_PRINTSETUP) {
2189 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
2190 hDlgTmpl = lppd->hSetupTemplate;
2191 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
2192 hResInfo = FindResourceW(lppd->hInstance,
2193 lppd->lpSetupTemplateName, RT_DIALOGW);
2194 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2195 } else {
2196 hResInfo = FindResourceW(COMDLG32_hInstance, xpsetup, RT_DIALOGW);
2197 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
2199 } else {
2200 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
2201 hDlgTmpl = lppd->hPrintTemplate;
2202 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
2203 hResInfo = FindResourceW(lppd->hInstance,
2204 lppd->lpPrintTemplateName,
2205 RT_DIALOGW);
2206 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2207 } else {
2208 hResInfo = FindResourceW(COMDLG32_hInstance, xprint, RT_DIALOGW);
2209 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
2212 return hDlgTmpl;
2217 /************************************************************
2219 * PRINTDLG_GetDlgTemplate
2222 static HGLOBAL16 PRINTDLG_GetDlgTemplate16(PRINTDLG16 *lppd)
2224 HGLOBAL16 hDlgTmpl, hResInfo;
2226 if (lppd->Flags & PD_PRINTSETUP) {
2227 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
2228 hDlgTmpl = lppd->hSetupTemplate;
2229 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
2230 hResInfo = FindResource16(lppd->hInstance,
2231 MapSL(lppd->lpSetupTemplateName), RT_DIALOGA);
2232 hDlgTmpl = LoadResource16(lppd->hInstance, hResInfo);
2233 } else {
2234 hDlgTmpl = PRINTDLG_Get16TemplateFrom32("PRINT32_SETUP");
2236 } else {
2237 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
2238 hDlgTmpl = lppd->hPrintTemplate;
2239 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
2240 hResInfo = FindResource16(lppd->hInstance,
2241 MapSL(lppd->lpPrintTemplateName),
2242 RT_DIALOGA);
2243 hDlgTmpl = LoadResource16(lppd->hInstance, hResInfo);
2244 } else {
2245 hDlgTmpl = PRINTDLG_Get16TemplateFrom32("PRINT32");
2248 return hDlgTmpl;
2251 /***********************************************************************
2253 * PRINTDLG_CreateDC
2256 static BOOL PRINTDLG_CreateDCA(LPPRINTDLGA lppd)
2258 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
2259 DEVMODEA *pdm = GlobalLock(lppd->hDevMode);
2261 if(lppd->Flags & PD_RETURNDC) {
2262 lppd->hDC = CreateDCA((char*)pdn + pdn->wDriverOffset,
2263 (char*)pdn + pdn->wDeviceOffset,
2264 (char*)pdn + pdn->wOutputOffset,
2265 pdm );
2266 } else if(lppd->Flags & PD_RETURNIC) {
2267 lppd->hDC = CreateICA((char*)pdn + pdn->wDriverOffset,
2268 (char*)pdn + pdn->wDeviceOffset,
2269 (char*)pdn + pdn->wOutputOffset,
2270 pdm );
2272 GlobalUnlock(lppd->hDevNames);
2273 GlobalUnlock(lppd->hDevMode);
2274 return lppd->hDC ? TRUE : FALSE;
2277 static BOOL PRINTDLG_CreateDCW(LPPRINTDLGW lppd)
2279 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
2280 DEVMODEW *pdm = GlobalLock(lppd->hDevMode);
2282 if(lppd->Flags & PD_RETURNDC) {
2283 lppd->hDC = CreateDCW((WCHAR*)pdn + pdn->wDriverOffset,
2284 (WCHAR*)pdn + pdn->wDeviceOffset,
2285 (WCHAR*)pdn + pdn->wOutputOffset,
2286 pdm );
2287 } else if(lppd->Flags & PD_RETURNIC) {
2288 lppd->hDC = CreateICW((WCHAR*)pdn + pdn->wDriverOffset,
2289 (WCHAR*)pdn + pdn->wDeviceOffset,
2290 (WCHAR*)pdn + pdn->wOutputOffset,
2291 pdm );
2293 GlobalUnlock(lppd->hDevNames);
2294 GlobalUnlock(lppd->hDevMode);
2295 return lppd->hDC ? TRUE : FALSE;
2298 static BOOL PRINTDLG_CreateDC16(LPPRINTDLG16 lppd)
2300 DEVNAMES *pdn = GlobalLock16(lppd->hDevNames);
2301 DEVMODEA *pdm = GlobalLock16(lppd->hDevMode);
2303 if(lppd->Flags & PD_RETURNDC) {
2304 lppd->hDC = HDC_16(CreateDCA((char*)pdn + pdn->wDriverOffset,
2305 (char*)pdn + pdn->wDeviceOffset,
2306 (char*)pdn + pdn->wOutputOffset,
2307 pdm ));
2308 } else if(lppd->Flags & PD_RETURNIC) {
2309 lppd->hDC = HDC_16(CreateICA((char*)pdn + pdn->wDriverOffset,
2310 (char*)pdn + pdn->wDeviceOffset,
2311 (char*)pdn + pdn->wOutputOffset,
2312 pdm ));
2314 GlobalUnlock16(lppd->hDevNames);
2315 GlobalUnlock16(lppd->hDevMode);
2316 return lppd->hDC ? TRUE : FALSE;
2319 /***********************************************************************
2320 * PrintDlgA (COMDLG32.@)
2322 * Displays the the PRINT dialog box, which enables the user to specify
2323 * specific properties of the print job.
2325 * RETURNS
2326 * nonzero if the user pressed the OK button
2327 * zero if the user cancelled the window or an error occurred
2329 * BUGS
2330 * PrintDlg:
2331 * * The Collate Icons do not display, even though they are in the code.
2332 * * The Properties Button(s) should call DocumentPropertiesA().
2333 * PrintSetupDlg:
2334 * * The Paper Orientation Icons are not implemented yet.
2335 * * The Properties Button(s) should call DocumentPropertiesA().
2336 * * Settings are not yet taken from a provided DevMode or
2337 * default printer settings.
2340 BOOL WINAPI PrintDlgA(
2341 LPPRINTDLGA lppd /* [in/out] ptr to PRINTDLG32 struct */
2344 BOOL bRet = FALSE;
2345 LPVOID ptr;
2346 HINSTANCE hInst = (HINSTANCE)GetWindowLongA( lppd->hwndOwner, GWL_HINSTANCE );
2348 if(TRACE_ON(commdlg)) {
2349 char flagstr[1000] = "";
2350 struct pd_flags *pflag = pd_flags;
2351 for( ; pflag->name; pflag++) {
2352 if(lppd->Flags & pflag->flag)
2353 strcat(flagstr, pflag->name);
2355 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2356 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2357 "flags %08lx (%s)\n",
2358 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2359 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2360 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2363 if(lppd->lStructSize != sizeof(PRINTDLGA)) {
2364 WARN("structure size failure !!!\n");
2365 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2366 return FALSE;
2369 if(lppd->Flags & PD_RETURNDEFAULT) {
2370 PRINTER_INFO_2A *pbuf;
2371 DRIVER_INFO_3A *dbuf;
2372 HANDLE hprn;
2373 DWORD needed;
2375 if(lppd->hDevMode || lppd->hDevNames) {
2376 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2377 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2378 return FALSE;
2380 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2381 WARN("Can't find default printer\n");
2382 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2383 return FALSE;
2386 GetPrinterA(hprn, 2, NULL, 0, &needed);
2387 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
2388 GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2390 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
2391 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
2392 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2393 ERR("GetPrinterDriverA failed, le %ld, fix your config for printer %s!\n",GetLastError(),pbuf->pPrinterName);
2394 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2395 return FALSE;
2397 ClosePrinter(hprn);
2399 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2400 dbuf->pDriverPath,
2401 pbuf->pPrinterName,
2402 pbuf->pPortName);
2403 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2404 pbuf->pDevMode->dmDriverExtra);
2405 ptr = GlobalLock(lppd->hDevMode);
2406 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2407 pbuf->pDevMode->dmDriverExtra);
2408 GlobalUnlock(lppd->hDevMode);
2409 HeapFree(GetProcessHeap(), 0, pbuf);
2410 HeapFree(GetProcessHeap(), 0, dbuf);
2411 bRet = TRUE;
2412 } else {
2413 HGLOBAL hDlgTmpl;
2414 PRINT_PTRA *PrintStructures;
2416 /* load Dialog resources,
2417 * depending on Flags indicates Print32 or Print32_setup dialog
2419 hDlgTmpl = PRINTDLG_GetDlgTemplateA(lppd);
2420 if (!hDlgTmpl) {
2421 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2422 return FALSE;
2424 ptr = LockResource( hDlgTmpl );
2425 if (!ptr) {
2426 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2427 return FALSE;
2430 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2431 sizeof(PRINT_PTRA));
2432 PrintStructures->dlg.lpPrintDlg = lppd;
2434 /* and create & process the dialog .
2435 * -1 is failure, 0 is broken hwnd, everything else is ok.
2437 bRet = (0<DialogBoxIndirectParamA(hInst, ptr, lppd->hwndOwner,
2438 PrintDlgProcA,
2439 (LPARAM)PrintStructures));
2441 if(bRet) {
2442 DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2443 PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
2444 DRIVER_INFO_3A *di = PrintStructures->lpDriverInfo;
2446 if (lppd->hDevMode == 0) {
2447 TRACE(" No hDevMode yet... Need to create my own\n");
2448 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2449 lpdm->dmSize + lpdm->dmDriverExtra);
2450 } else {
2451 WORD locks;
2452 if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
2453 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2454 while(locks--) {
2455 GlobalUnlock(lppd->hDevMode);
2456 TRACE("Now got %d locks\n", locks);
2459 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2460 lpdm->dmSize + lpdm->dmDriverExtra,
2461 GMEM_MOVEABLE);
2463 lpdmReturn = GlobalLock(lppd->hDevMode);
2464 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2466 if (lppd->hDevNames != 0) {
2467 WORD locks;
2468 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
2469 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2470 while(locks--)
2471 GlobalUnlock(lppd->hDevNames);
2474 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2475 di->pDriverPath,
2476 pi->pPrinterName,
2477 pi->pPortName
2479 GlobalUnlock(lppd->hDevMode);
2481 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2482 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2483 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2484 HeapFree(GetProcessHeap(), 0, PrintStructures);
2486 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2487 bRet = PRINTDLG_CreateDCA(lppd);
2489 TRACE("exit! (%d)\n", bRet);
2490 return bRet;
2493 /***********************************************************************
2494 * PrintDlgW (COMDLG32.@)
2496 BOOL WINAPI PrintDlgW(
2497 LPPRINTDLGW lppd /* [in/out] ptr to PRINTDLG32 struct */
2500 BOOL bRet = FALSE;
2501 LPVOID ptr;
2502 HINSTANCE hInst = (HINSTANCE)GetWindowLongW( lppd->hwndOwner, GWL_HINSTANCE );
2504 if(TRACE_ON(commdlg)) {
2505 char flagstr[1000] = "";
2506 struct pd_flags *pflag = pd_flags;
2507 for( ; pflag->name; pflag++) {
2508 if(lppd->Flags & pflag->flag)
2509 strcat(flagstr, pflag->name);
2511 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2512 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2513 "flags %08lx (%s)\n",
2514 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2515 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2516 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2519 if(lppd->lStructSize != sizeof(PRINTDLGW)) {
2520 WARN("structure size failure !!!\n");
2521 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2522 return FALSE;
2525 if(lppd->Flags & PD_RETURNDEFAULT) {
2526 PRINTER_INFO_2W *pbuf;
2527 DRIVER_INFO_3W *dbuf;
2528 HANDLE hprn;
2529 DWORD needed;
2531 if(lppd->hDevMode || lppd->hDevNames) {
2532 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2533 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2534 return FALSE;
2536 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2537 WARN("Can't find default printer\n");
2538 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2539 return FALSE;
2542 GetPrinterW(hprn, 2, NULL, 0, &needed);
2543 pbuf = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*needed);
2544 GetPrinterW(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2546 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
2547 dbuf = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
2548 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2549 ERR("GetPrinterDriverA failed, le %ld, fix your config for printer %s!\n",GetLastError(),debugstr_w(pbuf->pPrinterName));
2550 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2551 return FALSE;
2553 ClosePrinter(hprn);
2555 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2556 dbuf->pDriverPath,
2557 pbuf->pPrinterName,
2558 pbuf->pPortName);
2559 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2560 pbuf->pDevMode->dmDriverExtra);
2561 ptr = GlobalLock(lppd->hDevMode);
2562 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2563 pbuf->pDevMode->dmDriverExtra);
2564 GlobalUnlock(lppd->hDevMode);
2565 HeapFree(GetProcessHeap(), 0, pbuf);
2566 HeapFree(GetProcessHeap(), 0, dbuf);
2567 bRet = TRUE;
2568 } else {
2569 HGLOBAL hDlgTmpl;
2570 PRINT_PTRW *PrintStructures;
2572 /* load Dialog resources,
2573 * depending on Flags indicates Print32 or Print32_setup dialog
2575 hDlgTmpl = PRINTDLG_GetDlgTemplateW(lppd);
2576 if (!hDlgTmpl) {
2577 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2578 return FALSE;
2580 ptr = LockResource( hDlgTmpl );
2581 if (!ptr) {
2582 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2583 return FALSE;
2586 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2587 sizeof(PRINT_PTRW));
2588 PrintStructures->dlg.lpPrintDlg = lppd;
2590 /* and create & process the dialog .
2591 * -1 is failure, 0 is broken hwnd, everything else is ok.
2593 bRet = (0<DialogBoxIndirectParamW(hInst, ptr, lppd->hwndOwner,
2594 PrintDlgProcW,
2595 (LPARAM)PrintStructures));
2597 if(bRet) {
2598 DEVMODEW *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2599 PRINTER_INFO_2W *pi = PrintStructures->lpPrinterInfo;
2600 DRIVER_INFO_3W *di = PrintStructures->lpDriverInfo;
2602 if (lppd->hDevMode == 0) {
2603 TRACE(" No hDevMode yet... Need to create my own\n");
2604 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2605 lpdm->dmSize + lpdm->dmDriverExtra);
2606 } else {
2607 WORD locks;
2608 if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
2609 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2610 while(locks--) {
2611 GlobalUnlock(lppd->hDevMode);
2612 TRACE("Now got %d locks\n", locks);
2615 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2616 lpdm->dmSize + lpdm->dmDriverExtra,
2617 GMEM_MOVEABLE);
2619 lpdmReturn = GlobalLock(lppd->hDevMode);
2620 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2622 if (lppd->hDevNames != 0) {
2623 WORD locks;
2624 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
2625 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2626 while(locks--)
2627 GlobalUnlock(lppd->hDevNames);
2630 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2631 di->pDriverPath,
2632 pi->pPrinterName,
2633 pi->pPortName
2635 GlobalUnlock(lppd->hDevMode);
2637 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2638 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2639 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2640 HeapFree(GetProcessHeap(), 0, PrintStructures);
2642 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2643 bRet = PRINTDLG_CreateDCW(lppd);
2645 TRACE("exit! (%d)\n", bRet);
2646 return bRet;
2649 /***********************************************************************
2650 * PrintDlg (COMMDLG.20)
2652 * Displays the the PRINT dialog box, which enables the user to specify
2653 * specific properties of the print job.
2655 * RETURNS
2656 * nonzero if the user pressed the OK button
2657 * zero if the user cancelled the window or an error occurred
2659 * BUGS
2660 * * calls up to the 32-bit versions of the Dialogs, which look different
2661 * * Customizing is *not* implemented.
2664 BOOL16 WINAPI PrintDlg16(
2665 LPPRINTDLG16 lppd /* [in/out] ptr to PRINTDLG struct */
2667 BOOL bRet = FALSE;
2668 LPVOID ptr;
2669 HINSTANCE16 hInst = GetWindowWord( HWND_32(lppd->hwndOwner), GWL_HINSTANCE );
2671 if(TRACE_ON(commdlg)) {
2672 char flagstr[1000] = "";
2673 struct pd_flags *pflag = pd_flags;
2674 for( ; pflag->name; pflag++) {
2675 if(lppd->Flags & pflag->flag)
2676 strcat(flagstr, pflag->name);
2678 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
2679 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %08x\n"
2680 "flags %08lx (%s)\n",
2681 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2682 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2683 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2686 if(lppd->lStructSize != sizeof(PRINTDLG16)) {
2687 ERR("structure size (%ld/%d)\n",lppd->lStructSize,sizeof(PRINTDLG16));
2688 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2689 return FALSE;
2692 if(lppd->Flags & PD_RETURNDEFAULT) {
2693 PRINTER_INFO_2A *pbuf;
2694 DRIVER_INFO_3A *dbuf;
2695 HANDLE hprn;
2696 DWORD needed;
2698 if(lppd->hDevMode || lppd->hDevNames) {
2699 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2700 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2701 return FALSE;
2703 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2704 WARN("Can't find default printer\n");
2705 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2706 return FALSE;
2709 GetPrinterA(hprn, 2, NULL, 0, &needed);
2710 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
2711 GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2712 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
2713 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
2714 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2715 ERR("GetPrinterDriverA failed for %s, le %ld, fix your config!\n",
2716 pbuf->pPrinterName,GetLastError());
2717 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2718 return FALSE;
2720 ClosePrinter(hprn);
2721 PRINTDLG_CreateDevNames16(&(lppd->hDevNames),
2722 dbuf->pDriverPath,
2723 pbuf->pPrinterName,
2724 pbuf->pPortName);
2725 lppd->hDevMode = GlobalAlloc16(GMEM_MOVEABLE,pbuf->pDevMode->dmSize+
2726 pbuf->pDevMode->dmDriverExtra);
2727 ptr = GlobalLock16(lppd->hDevMode);
2728 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2729 pbuf->pDevMode->dmDriverExtra);
2730 GlobalUnlock16(lppd->hDevMode);
2731 HeapFree(GetProcessHeap(), 0, pbuf);
2732 HeapFree(GetProcessHeap(), 0, dbuf);
2733 bRet = TRUE;
2734 } else {
2735 HGLOBAL16 hDlgTmpl;
2736 PRINT_PTRA *PrintStructures;
2738 /* load Dialog resources,
2739 * depending on Flags indicates Print32 or Print32_setup dialog
2741 hDlgTmpl = PRINTDLG_GetDlgTemplate16(lppd);
2742 if (!hDlgTmpl) {
2743 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2744 return FALSE;
2746 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2747 sizeof(PRINT_PTRA));
2748 PrintStructures->dlg.lpPrintDlg16 = lppd;
2749 PrintStructures->dlg.lpPrintDlg = (LPPRINTDLGA)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(PRINTDLGA));
2750 #define CVAL(x) PrintStructures->dlg.lpPrintDlg->x = lppd->x;
2751 #define MVAL(x) PrintStructures->dlg.lpPrintDlg->x = MapSL(lppd->x);
2752 CVAL(Flags);
2753 PrintStructures->dlg.lpPrintDlg->hwndOwner = HWND_32(lppd->hwndOwner);
2754 PrintStructures->dlg.lpPrintDlg->hDC = HDC_32(lppd->hDC);
2755 CVAL(nFromPage);CVAL(nToPage);CVAL(nMinPage);CVAL(nMaxPage);
2756 CVAL(nCopies);
2757 PrintStructures->dlg.lpPrintDlg->hInstance = HINSTANCE_32(lppd->hInstance);
2758 CVAL(lCustData);
2759 MVAL(lpPrintTemplateName);MVAL(lpSetupTemplateName);
2760 /* Don't copy rest, it is 16 bit specific */
2761 #undef MVAL
2762 #undef CVAL
2764 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(),0,sizeof(DEVMODEA));
2766 /* and create & process the dialog .
2767 * -1 is failure, 0 is broken hwnd, everything else is ok.
2769 bRet = (0<DialogBoxIndirectParam16(
2770 hInst, hDlgTmpl, lppd->hwndOwner,
2771 (DLGPROC16)GetProcAddress16(GetModuleHandle16("COMMDLG"),(LPCSTR)21),
2772 (LPARAM)PrintStructures
2775 if (!PrintStructures->lpPrinterInfo) bRet = FALSE;
2776 if(bRet) {
2777 DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2778 PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
2779 DRIVER_INFO_3A *di = PrintStructures->lpDriverInfo;
2781 if (lppd->hDevMode == 0) {
2782 TRACE(" No hDevMode yet... Need to create my own\n");
2783 lppd->hDevMode = GlobalAlloc16(GMEM_MOVEABLE,
2784 lpdm->dmSize + lpdm->dmDriverExtra);
2785 } else {
2786 WORD locks;
2787 if((locks = (GlobalFlags16(lppd->hDevMode)&GMEM_LOCKCOUNT))) {
2788 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2789 while(locks--) {
2790 GlobalUnlock16(lppd->hDevMode);
2791 TRACE("Now got %d locks\n", locks);
2794 lppd->hDevMode = GlobalReAlloc16(lppd->hDevMode,
2795 lpdm->dmSize + lpdm->dmDriverExtra,
2796 GMEM_MOVEABLE);
2798 lpdmReturn = GlobalLock16(lppd->hDevMode);
2799 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2801 if (lppd->hDevNames != 0) {
2802 WORD locks;
2803 if((locks = (GlobalFlags16(lppd->hDevNames)&GMEM_LOCKCOUNT))) {
2804 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2805 while(locks--)
2806 GlobalUnlock16(lppd->hDevNames);
2809 PRINTDLG_CreateDevNames16(&(lppd->hDevNames),
2810 di->pDriverPath,
2811 pi->pPrinterName,
2812 pi->pPortName
2814 GlobalUnlock16(lppd->hDevMode);
2816 if (!(lppd->Flags & (PD_ENABLESETUPTEMPLATEHANDLE | PD_ENABLESETUPTEMPLATE)))
2817 GlobalFree16(hDlgTmpl); /* created from the 32 bits resource */
2818 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2819 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2820 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2821 HeapFree(GetProcessHeap(), 0, PrintStructures);
2823 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2824 bRet = PRINTDLG_CreateDC16(lppd);
2826 TRACE("exit! (%d)\n", bRet);
2827 return bRet;
2831 /***********************************************************************
2833 * PageSetupDlg
2834 * rad1 - portrait
2835 * rad2 - landscape
2836 * cmb2 - paper size
2837 * cmb3 - source (tray?)
2838 * edt4 - border left
2839 * edt5 - border top
2840 * edt6 - border right
2841 * edt7 - border bottom
2842 * psh3 - "Printer..."
2845 typedef struct {
2846 LPPAGESETUPDLGA dlga;
2847 PRINTDLGA pdlg;
2848 } PageSetupDataA;
2850 typedef struct {
2851 LPPAGESETUPDLGW dlga;
2852 PRINTDLGW pdlg;
2853 } PageSetupDataW;
2855 static HGLOBAL PRINTDLG_GetPGSTemplateA(PAGESETUPDLGA *lppd)
2857 HRSRC hResInfo;
2858 HGLOBAL hDlgTmpl;
2860 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2861 hDlgTmpl = lppd->hPageSetupTemplate;
2862 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2863 hResInfo = FindResourceA(lppd->hInstance,
2864 lppd->lpPageSetupTemplateName, RT_DIALOGA);
2865 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2866 } else {
2867 hResInfo = FindResourceA(COMDLG32_hInstance,(LPCSTR)PAGESETUPDLGORD,RT_DIALOGA);
2868 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2870 return hDlgTmpl;
2873 static HGLOBAL PRINTDLG_GetPGSTemplateW(PAGESETUPDLGW *lppd)
2875 HRSRC hResInfo;
2876 HGLOBAL hDlgTmpl;
2878 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2879 hDlgTmpl = lppd->hPageSetupTemplate;
2880 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2881 hResInfo = FindResourceW(lppd->hInstance,
2882 lppd->lpPageSetupTemplateName, RT_DIALOGW);
2883 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2884 } else {
2885 hResInfo = FindResourceW(COMDLG32_hInstance,(LPCWSTR)PAGESETUPDLGORD,RT_DIALOGW);
2886 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2888 return hDlgTmpl;
2891 static DWORD
2892 _c_10mm2size(PAGESETUPDLGA *dlga,DWORD size) {
2893 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2894 return 10*size*10/25.4;
2895 /* If we don't have a flag, we can choose one. Use millimeters
2896 * to avoid confusing me
2898 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2899 return 10*size;
2903 static DWORD
2904 _c_inch2size(PAGESETUPDLGA *dlga,DWORD size) {
2905 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2906 return size;
2907 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
2908 return (size*254)/10;
2909 /* if we don't have a flag, we can choose one. Use millimeters
2910 * to avoid confusing me
2912 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2913 return (size*254)/10;
2916 static void
2917 _c_size2strA(PageSetupDataA *pda,DWORD size,LPSTR strout) {
2918 strcpy(strout,"<undef>");
2919 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2920 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
2921 return;
2923 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2924 sprintf(strout,"%.2fin",(size*1.0)/1000.0);
2925 return;
2927 pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2928 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
2929 return;
2931 static void
2932 _c_size2strW(PageSetupDataW *pda,DWORD size,LPSTR strout) {
2933 strcpy(strout,"<undef>");
2934 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2935 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
2936 return;
2938 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2939 sprintf(strout,"%.2fin",(size*1.0)/1000.0);
2940 return;
2942 pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2943 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
2944 return;
2947 static DWORD
2948 _c_str2size(PAGESETUPDLGA *dlga,LPCSTR strin) {
2949 float val;
2950 char rest[200];
2952 rest[0]='\0';
2953 if (!sscanf(strin,"%f%s",&val,rest))
2954 return 0;
2956 if (!strcmp(rest,"in") || !strcmp(rest,"inch")) {
2957 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2958 return 1000*val;
2959 else
2960 return val*25.4*100;
2962 if (!strcmp(rest,"cm")) { rest[0]='m'; val = val*10.0; }
2963 if (!strcmp(rest,"m")) { strcpy(rest,"mm"); val = val*1000.0; }
2965 if (!strcmp(rest,"mm")) {
2966 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
2967 return 100*val;
2968 else
2969 return 1000.0*val/25.4;
2971 if (rest[0]=='\0') {
2972 /* use application supplied default */
2973 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2974 /* 100*mm */
2975 return 100.0*val;
2977 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2978 /* 1000*inch */
2979 return 1000.0*val;
2982 ERR("Did not find a conversion for type '%s'!\n",rest);
2983 return 0;
2988 * This is called on finish and will update the output fields of the
2989 * struct.
2991 static BOOL
2992 PRINTDLG_PS_UpdateDlgStructA(HWND hDlg, PageSetupDataA *pda) {
2993 DEVNAMES *dn;
2994 DEVMODEA *dm;
2995 LPSTR devname,portname;
2996 char papername[64];
2997 char buf[200];
2999 dn = GlobalLock(pda->pdlg.hDevNames);
3000 dm = GlobalLock(pda->pdlg.hDevMode);
3001 devname = ((char*)dn)+dn->wDeviceOffset;
3002 portname = ((char*)dn)+dn->wOutputOffset;
3003 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb2,devname,portname,dm);
3004 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb3,devname,portname,dm);
3006 if (GetDlgItemTextA(hDlg,cmb2,papername,sizeof(papername))>0) {
3007 PRINTDLG_PaperSizeA(&(pda->pdlg),papername,&(pda->dlga->ptPaperSize));
3008 pda->dlga->ptPaperSize.x = _c_10mm2size(pda->dlga,pda->dlga->ptPaperSize.x);
3009 pda->dlga->ptPaperSize.y = _c_10mm2size(pda->dlga,pda->dlga->ptPaperSize.y);
3010 } else
3011 FIXME("could not get dialog text for papersize cmbbox?\n");
3012 #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); }
3013 GETVAL(edt4,pda->dlga->rtMargin.left);
3014 GETVAL(edt5,pda->dlga->rtMargin.top);
3015 GETVAL(edt6,pda->dlga->rtMargin.right);
3016 GETVAL(edt7,pda->dlga->rtMargin.bottom);
3017 #undef GETVAL
3019 /* If we are in landscape, swap x and y of page size */
3020 if (IsDlgButtonChecked(hDlg, rad2)) {
3021 DWORD tmp;
3022 tmp = pda->dlga->ptPaperSize.x;
3023 pda->dlga->ptPaperSize.x = pda->dlga->ptPaperSize.y;
3024 pda->dlga->ptPaperSize.y = tmp;
3026 GlobalUnlock(pda->pdlg.hDevNames);
3027 GlobalUnlock(pda->pdlg.hDevMode);
3028 return TRUE;
3031 static BOOL
3032 PRINTDLG_PS_UpdateDlgStructW(HWND hDlg, PageSetupDataW *pda) {
3033 DEVNAMES *dn;
3034 DEVMODEW *dm;
3035 LPWSTR devname,portname;
3036 WCHAR papername[64];
3038 char buf[200];
3040 dn = GlobalLock(pda->pdlg.hDevNames);
3041 dm = GlobalLock(pda->pdlg.hDevMode);
3042 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
3043 portname = ((WCHAR*)dn)+dn->wOutputOffset;
3044 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
3045 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
3047 if (GetDlgItemTextW(hDlg,cmb2,papername,sizeof(papername))>0) {
3048 PRINTDLG_PaperSizeW(&(pda->pdlg),papername,&(pda->dlga->ptPaperSize));
3049 pda->dlga->ptPaperSize.x = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga,pda->dlga->ptPaperSize.x);
3050 pda->dlga->ptPaperSize.y = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga,pda->dlga->ptPaperSize.y);
3051 } else
3052 FIXME("could not get dialog text for papersize cmbbox?\n");
3053 #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); }
3054 GETVAL(edt4,pda->dlga->rtMargin.left);
3055 GETVAL(edt5,pda->dlga->rtMargin.top);
3056 GETVAL(edt6,pda->dlga->rtMargin.right);
3057 GETVAL(edt7,pda->dlga->rtMargin.bottom);
3058 #undef GETVAL
3060 /* If we are in landscape, swap x and y of page size */
3061 if (IsDlgButtonChecked(hDlg, rad2)) {
3062 DWORD tmp;
3063 tmp = pda->dlga->ptPaperSize.x;
3064 pda->dlga->ptPaperSize.x = pda->dlga->ptPaperSize.y;
3065 pda->dlga->ptPaperSize.y = tmp;
3067 GlobalUnlock(pda->pdlg.hDevNames);
3068 GlobalUnlock(pda->pdlg.hDevMode);
3069 return TRUE;
3073 * This is called after returning from PrintDlg().
3075 static BOOL
3076 PRINTDLG_PS_ChangePrinterA(HWND hDlg, PageSetupDataA *pda) {
3077 DEVNAMES *dn;
3078 DEVMODEA *dm;
3079 LPSTR devname,portname;
3081 dn = GlobalLock(pda->pdlg.hDevNames);
3082 dm = GlobalLock(pda->pdlg.hDevMode);
3083 devname = ((char*)dn)+dn->wDeviceOffset;
3084 portname = ((char*)dn)+dn->wOutputOffset;
3085 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb2,devname,portname,dm);
3086 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb3,devname,portname,dm);
3087 GlobalUnlock(pda->pdlg.hDevNames);
3088 GlobalUnlock(pda->pdlg.hDevMode);
3089 return TRUE;
3092 static BOOL
3093 PRINTDLG_PS_ChangePrinterW(HWND hDlg, PageSetupDataW *pda) {
3094 DEVNAMES *dn;
3095 DEVMODEW *dm;
3096 LPWSTR devname,portname;
3098 dn = GlobalLock(pda->pdlg.hDevNames);
3099 dm = GlobalLock(pda->pdlg.hDevMode);
3100 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
3101 portname = ((WCHAR*)dn)+dn->wOutputOffset;
3102 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
3103 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
3104 GlobalUnlock(pda->pdlg.hDevNames);
3105 GlobalUnlock(pda->pdlg.hDevMode);
3106 return TRUE;
3109 static BOOL
3110 PRINTDLG_PS_WMCommandA(
3111 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataA *pda
3113 switch (LOWORD(wParam)) {
3114 case IDOK:
3115 if (!PRINTDLG_PS_UpdateDlgStructA(hDlg, pda))
3116 return(FALSE);
3117 EndDialog(hDlg, TRUE);
3118 return TRUE ;
3120 case IDCANCEL:
3121 EndDialog(hDlg, FALSE);
3122 return FALSE ;
3124 case psh3: {
3125 pda->pdlg.Flags = 0;
3126 pda->pdlg.hwndOwner = hDlg;
3127 if (PrintDlgA(&(pda->pdlg)))
3128 PRINTDLG_PS_ChangePrinterA(hDlg,pda);
3129 return TRUE;
3132 FIXME("loword (lparam) %d, wparam 0x%x, lparam %08lx, STUB mostly.\n",
3133 LOWORD(lParam),wParam,lParam
3135 return FALSE;
3138 static BOOL
3139 PRINTDLG_PS_WMCommandW(
3140 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataW *pda
3142 switch (LOWORD(wParam)) {
3143 case IDOK:
3144 if (!PRINTDLG_PS_UpdateDlgStructW(hDlg, pda))
3145 return(FALSE);
3146 EndDialog(hDlg, TRUE);
3147 return TRUE ;
3149 case IDCANCEL:
3150 EndDialog(hDlg, FALSE);
3151 return FALSE ;
3153 case psh3: {
3154 pda->pdlg.Flags = 0;
3155 pda->pdlg.hwndOwner = hDlg;
3156 if (PrintDlgW(&(pda->pdlg)))
3157 PRINTDLG_PS_ChangePrinterW(hDlg,pda);
3158 return TRUE;
3161 FIXME("loword (lparam) %d, wparam 0x%x, lparam %08lx, STUB mostly.\n",
3162 LOWORD(lParam),wParam,lParam
3164 return FALSE;
3168 static INT_PTR CALLBACK
3169 PageDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
3171 PageSetupDataA *pda;
3172 INT_PTR res = FALSE;
3174 if (uMsg==WM_INITDIALOG) {
3175 res = TRUE;
3176 pda = (PageSetupDataA*)lParam;
3177 SetPropA(hDlg,"__WINE_PAGESETUPDLGDATA",pda);
3178 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3179 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3180 if (!res) {
3181 FIXME("Setup page hook failed?\n");
3182 res = TRUE;
3185 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK) {
3186 FIXME("PagePaintHook not yet implemented!\n");
3188 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
3189 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
3190 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
3191 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
3192 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
3193 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
3194 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
3196 /* width larger as height -> landscape */
3197 if (pda->dlga->ptPaperSize.x > pda->dlga->ptPaperSize.y)
3198 CheckRadioButton(hDlg, rad1, rad2, rad2);
3199 else /* this is default if papersize is not set */
3200 CheckRadioButton(hDlg, rad1, rad2, rad1);
3201 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
3202 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
3203 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
3205 /* We fill them out enabled or not */
3206 if (pda->dlga->Flags & PSD_MARGINS) {
3207 char str[100];
3208 _c_size2strA(pda,pda->dlga->rtMargin.left,str);
3209 SetDlgItemTextA(hDlg,edt4,str);
3210 _c_size2strA(pda,pda->dlga->rtMargin.top,str);
3211 SetDlgItemTextA(hDlg,edt5,str);
3212 _c_size2strA(pda,pda->dlga->rtMargin.right,str);
3213 SetDlgItemTextA(hDlg,edt6,str);
3214 _c_size2strA(pda,pda->dlga->rtMargin.bottom,str);
3215 SetDlgItemTextA(hDlg,edt7,str);
3216 } else {
3217 /* default is 1 inch */
3218 DWORD size = _c_inch2size(pda->dlga,1000);
3219 char str[20];
3220 _c_size2strA(pda,size,str);
3221 SetDlgItemTextA(hDlg,edt4,str);
3222 SetDlgItemTextA(hDlg,edt5,str);
3223 SetDlgItemTextA(hDlg,edt6,str);
3224 SetDlgItemTextA(hDlg,edt7,str);
3226 PRINTDLG_PS_ChangePrinterA(hDlg,pda);
3227 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
3228 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
3229 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
3231 return TRUE;
3232 } else {
3233 pda = (PageSetupDataA*)GetPropA(hDlg,"__WINE_PAGESETUPDLGDATA");
3234 if (!pda) {
3235 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3236 return FALSE;
3238 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3239 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3240 if (res) return res;
3243 switch (uMsg) {
3244 case WM_COMMAND:
3245 return PRINTDLG_PS_WMCommandA(hDlg, wParam, lParam, pda);
3247 return FALSE;
3250 static INT_PTR CALLBACK
3251 PageDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
3253 PageSetupDataW *pda;
3254 BOOL res = FALSE;
3256 if (uMsg==WM_INITDIALOG) {
3257 res = TRUE;
3258 pda = (PageSetupDataW*)lParam;
3259 SetPropA(hDlg,"__WINE_PAGESETUPDLGDATA",pda);
3260 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3261 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3262 if (!res) {
3263 FIXME("Setup page hook failed?\n");
3264 res = TRUE;
3267 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK) {
3268 FIXME("PagePaintHook not yet implemented!\n");
3270 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
3271 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
3272 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
3273 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
3274 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
3275 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
3276 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
3278 /* width larger as height -> landscape */
3279 if (pda->dlga->ptPaperSize.x > pda->dlga->ptPaperSize.y)
3280 CheckRadioButton(hDlg, rad1, rad2, rad2);
3281 else /* this is default if papersize is not set */
3282 CheckRadioButton(hDlg, rad1, rad2, rad1);
3283 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
3284 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
3285 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
3287 /* We fill them out enabled or not */
3288 if (pda->dlga->Flags & PSD_MARGINS) {
3289 char str[100];
3290 _c_size2strW(pda,pda->dlga->rtMargin.left,str);
3291 SetDlgItemTextA(hDlg,edt4,str);
3292 _c_size2strW(pda,pda->dlga->rtMargin.top,str);
3293 SetDlgItemTextA(hDlg,edt5,str);
3294 _c_size2strW(pda,pda->dlga->rtMargin.right,str);
3295 SetDlgItemTextA(hDlg,edt6,str);
3296 _c_size2strW(pda,pda->dlga->rtMargin.bottom,str);
3297 SetDlgItemTextA(hDlg,edt7,str);
3298 } else {
3299 /* default is 1 inch */
3300 DWORD size = _c_inch2size((LPPAGESETUPDLGA)pda->dlga,1000);
3301 char str[20];
3302 _c_size2strW(pda,size,str);
3303 SetDlgItemTextA(hDlg,edt4,str);
3304 SetDlgItemTextA(hDlg,edt5,str);
3305 SetDlgItemTextA(hDlg,edt6,str);
3306 SetDlgItemTextA(hDlg,edt7,str);
3308 PRINTDLG_PS_ChangePrinterW(hDlg,pda);
3309 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
3310 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
3311 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
3313 return TRUE;
3314 } else {
3315 pda = (PageSetupDataW*)GetPropA(hDlg,"__WINE_PAGESETUPDLGDATA");
3316 if (!pda) {
3317 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3318 return FALSE;
3320 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3321 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3322 if (res) return res;
3325 switch (uMsg) {
3326 case WM_COMMAND:
3327 return PRINTDLG_PS_WMCommandW(hDlg, wParam, lParam, pda);
3329 return FALSE;
3332 /***********************************************************************
3333 * PageSetupDlgA (COMDLG32.@)
3335 BOOL WINAPI PageSetupDlgA(LPPAGESETUPDLGA setupdlg) {
3336 HGLOBAL hDlgTmpl;
3337 LPVOID ptr;
3338 BOOL bRet;
3339 PageSetupDataA *pda;
3340 PRINTDLGA pdlg;
3342 if(TRACE_ON(commdlg)) {
3343 char flagstr[1000] = "";
3344 struct pd_flags *pflag = psd_flags;
3345 for( ; pflag->name; pflag++) {
3346 if(setupdlg->Flags & pflag->flag) {
3347 strcat(flagstr, pflag->name);
3348 strcat(flagstr, "|");
3351 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3352 "hinst %p, flags %08lx (%s)\n",
3353 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
3354 setupdlg->hDevNames,
3355 setupdlg->hInstance, setupdlg->Flags, flagstr);
3358 /* First get default printer data, we need it right after that. */
3359 memset(&pdlg,0,sizeof(pdlg));
3360 pdlg.lStructSize = sizeof(pdlg);
3361 pdlg.Flags = PD_RETURNDEFAULT;
3362 bRet = PrintDlgA(&pdlg);
3363 if (!bRet) return FALSE;
3365 /* short cut exit, just return default values */
3366 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
3367 setupdlg->hDevMode = pdlg.hDevMode;
3368 setupdlg->hDevNames = pdlg.hDevNames;
3369 /* FIXME: Just return "A4" for now. */
3370 PRINTDLG_PaperSizeA(&pdlg,"A4",&setupdlg->ptPaperSize);
3371 setupdlg->ptPaperSize.x=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.x);
3372 setupdlg->ptPaperSize.y=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.y);
3373 return TRUE;
3375 hDlgTmpl = PRINTDLG_GetPGSTemplateA(setupdlg);
3376 if (!hDlgTmpl) {
3377 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3378 return FALSE;
3380 ptr = LockResource( hDlgTmpl );
3381 if (!ptr) {
3382 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3383 return FALSE;
3385 pda = HeapAlloc(GetProcessHeap(),0,sizeof(*pda));
3386 pda->dlga = setupdlg;
3387 memcpy(&pda->pdlg,&pdlg,sizeof(pdlg));
3389 bRet = (0<DialogBoxIndirectParamA(
3390 setupdlg->hInstance,
3391 ptr,
3392 setupdlg->hwndOwner,
3393 PageDlgProcA,
3394 (LPARAM)pda)
3396 return bRet;
3398 /***********************************************************************
3399 * PageSetupDlgW (COMDLG32.@)
3401 BOOL WINAPI PageSetupDlgW(LPPAGESETUPDLGW setupdlg) {
3402 HGLOBAL hDlgTmpl;
3403 LPVOID ptr;
3404 BOOL bRet;
3405 PageSetupDataW *pdw;
3406 PRINTDLGW pdlg;
3408 if(TRACE_ON(commdlg)) {
3409 char flagstr[1000] = "";
3410 struct pd_flags *pflag = psd_flags;
3411 for( ; pflag->name; pflag++) {
3412 if(setupdlg->Flags & pflag->flag) {
3413 strcat(flagstr, pflag->name);
3414 strcat(flagstr, "|");
3417 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3418 "hinst %p, flags %08lx (%s)\n",
3419 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
3420 setupdlg->hDevNames,
3421 setupdlg->hInstance, setupdlg->Flags, flagstr);
3424 /* First get default printer data, we need it right after that. */
3425 memset(&pdlg,0,sizeof(pdlg));
3426 pdlg.lStructSize = sizeof(pdlg);
3427 pdlg.Flags = PD_RETURNDEFAULT;
3428 bRet = PrintDlgW(&pdlg);
3429 if (!bRet) return FALSE;
3431 /* short cut exit, just return default values */
3432 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
3433 const WCHAR a4[] = {'A','4',0};
3434 setupdlg->hDevMode = pdlg.hDevMode;
3435 setupdlg->hDevNames = pdlg.hDevNames;
3436 /* FIXME: Just return "A4" for now. */
3437 PRINTDLG_PaperSizeW(&pdlg,a4,&setupdlg->ptPaperSize);
3438 setupdlg->ptPaperSize.x=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.x);
3439 setupdlg->ptPaperSize.y=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.y);
3440 return TRUE;
3442 hDlgTmpl = PRINTDLG_GetPGSTemplateW(setupdlg);
3443 if (!hDlgTmpl) {
3444 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3445 return FALSE;
3447 ptr = LockResource( hDlgTmpl );
3448 if (!ptr) {
3449 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3450 return FALSE;
3452 pdw = HeapAlloc(GetProcessHeap(),0,sizeof(*pdw));
3453 pdw->dlga = setupdlg;
3454 memcpy(&pdw->pdlg,&pdlg,sizeof(pdlg));
3456 bRet = (0<DialogBoxIndirectParamW(
3457 setupdlg->hInstance,
3458 ptr,
3459 setupdlg->hwndOwner,
3460 PageDlgProcW,
3461 (LPARAM)pdw)
3463 return bRet;
3466 /**********************************************************************
3468 * 16 bit commdlg
3471 /***********************************************************************
3472 * PrintDlgProc (COMMDLG.21)
3474 BOOL16 CALLBACK PrintDlgProc16(HWND16 hDlg16, UINT16 uMsg, WPARAM16 wParam,
3475 LPARAM lParam)
3477 HWND hDlg = HWND_32(hDlg16);
3478 PRINT_PTRA* PrintStructures;
3479 BOOL16 res = FALSE;
3481 if (uMsg!=WM_INITDIALOG) {
3482 PrintStructures = (PRINT_PTRA*)GetPropA(hDlg,"__WINE_PRINTDLGDATA");
3483 if (!PrintStructures)
3484 return FALSE;
3485 } else {
3486 PrintStructures = (PRINT_PTRA*) lParam;
3487 SetPropA(hDlg,"__WINE_PRINTDLGDATA",PrintStructures);
3488 res = PRINTDLG_WMInitDialog16(hDlg, wParam, PrintStructures);
3490 if(PrintStructures->dlg.lpPrintDlg16->Flags & PD_ENABLEPRINTHOOK) {
3491 res = CallWindowProc16(
3492 (WNDPROC16)PrintStructures->dlg.lpPrintDlg16->lpfnPrintHook,
3493 hDlg16, uMsg, wParam, (LPARAM)PrintStructures->dlg.lpPrintDlg16
3496 return res;
3499 if(PrintStructures->dlg.lpPrintDlg16->Flags & PD_ENABLEPRINTHOOK) {
3500 res = CallWindowProc16(
3501 (WNDPROC16)PrintStructures->dlg.lpPrintDlg16->lpfnPrintHook,
3502 hDlg16,uMsg, wParam, lParam
3504 if(LOWORD(res)) return res;
3507 switch (uMsg) {
3508 case WM_COMMAND: {
3509 /* We need to map those for the 32bit window procedure, compare
3510 * with 32Ato16 mapper in winproc.c
3512 return PRINTDLG_WMCommandA(
3513 hDlg,
3514 MAKEWPARAM(wParam,HIWORD(lParam)),
3515 LOWORD(lParam),
3516 PrintStructures
3519 case WM_DESTROY:
3520 DestroyIcon(PrintStructures->hCollateIcon);
3521 DestroyIcon(PrintStructures->hNoCollateIcon);
3522 /* FIXME: don't forget to delete the paper orientation icons here! */
3524 return FALSE;
3526 return res;
3530 /***********************************************************************
3531 * PrintSetupDlgProc (COMMDLG.22)
3533 BOOL16 CALLBACK PrintSetupDlgProc16(HWND16 hWnd16, UINT16 wMsg, WPARAM16 wParam,
3534 LPARAM lParam)
3536 HWND hWnd = HWND_32(hWnd16);
3537 switch (wMsg)
3539 case WM_INITDIALOG:
3540 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
3541 ShowWindow(hWnd, SW_SHOWNORMAL);
3542 return (TRUE);
3543 case WM_COMMAND:
3544 switch (wParam) {
3545 case IDOK:
3546 EndDialog(hWnd, TRUE);
3547 return(TRUE);
3548 case IDCANCEL:
3549 EndDialog(hWnd, FALSE);
3550 return(TRUE);
3552 return(FALSE);
3554 return FALSE;
3558 /***********************************************************************
3559 * PrintDlgExA (COMDLG32.@)
3561 HRESULT WINAPI PrintDlgExA(LPVOID lpPrintDlgExA) /* [???] FIXME: LPPRINTDLGEXA */
3563 FIXME("stub\n");
3564 return E_NOTIMPL;
3566 /***********************************************************************
3567 * PrintDlgExW (COMDLG32.@)
3569 HRESULT WINAPI PrintDlgExW(LPVOID lpPrintDlgExW) /* [???] FIXME: LPPRINTDLGEXW */
3571 FIXME("stub\n");
3572 return E_NOTIMPL;