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
8 * Copyright 2010 Vitaly Perov
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #define NONAMELESSUNION
32 #define NONAMELESSSTRUCT
40 #include "wine/unicode.h"
41 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
50 /* Yes these constants are the same, but we're just copying win98 */
51 #define UPDOWN_ID 0x270f
52 #define MAX_COPIES 9999
54 /* This PRINTDLGA internal structure stores
55 * pointers to several throughout useful structures.
61 LPPRINTDLGA lpPrintDlg;
62 LPPRINTER_INFO_2A lpPrinterInfo;
63 LPDRIVER_INFO_3A lpDriverInfo;
65 HICON hCollateIcon; /* PrintDlg only */
66 HICON hNoCollateIcon; /* PrintDlg only */
67 HICON hPortraitIcon; /* PrintSetupDlg only */
68 HICON hLandscapeIcon; /* PrintSetupDlg only */
75 LPPRINTDLGW lpPrintDlg;
76 LPPRINTER_INFO_2W lpPrinterInfo;
77 LPDRIVER_INFO_3W lpDriverInfo;
79 HICON hCollateIcon; /* PrintDlg only */
80 HICON hNoCollateIcon; /* PrintDlg only */
81 HICON hPortraitIcon; /* PrintSetupDlg only */
82 HICON hLandscapeIcon; /* PrintSetupDlg only */
93 static const struct pd_flags psd_flags[] = {
94 {PSD_MINMARGINS,"PSD_MINMARGINS"},
95 {PSD_MARGINS,"PSD_MARGINS"},
96 {PSD_INTHOUSANDTHSOFINCHES,"PSD_INTHOUSANDTHSOFINCHES"},
97 {PSD_INHUNDREDTHSOFMILLIMETERS,"PSD_INHUNDREDTHSOFMILLIMETERS"},
98 {PSD_DISABLEMARGINS,"PSD_DISABLEMARGINS"},
99 {PSD_DISABLEPRINTER,"PSD_DISABLEPRINTER"},
100 {PSD_NOWARNING,"PSD_NOWARNING"},
101 {PSD_DISABLEORIENTATION,"PSD_DISABLEORIENTATION"},
102 {PSD_RETURNDEFAULT,"PSD_RETURNDEFAULT"},
103 {PSD_DISABLEPAPER,"PSD_DISABLEPAPER"},
104 {PSD_SHOWHELP,"PSD_SHOWHELP"},
105 {PSD_ENABLEPAGESETUPHOOK,"PSD_ENABLEPAGESETUPHOOK"},
106 {PSD_ENABLEPAGESETUPTEMPLATE,"PSD_ENABLEPAGESETUPTEMPLATE"},
107 {PSD_ENABLEPAGESETUPTEMPLATEHANDLE,"PSD_ENABLEPAGESETUPTEMPLATEHANDLE"},
108 {PSD_ENABLEPAGEPAINTHOOK,"PSD_ENABLEPAGEPAINTHOOK"},
109 {PSD_DISABLEPAGEPAINTING,"PSD_DISABLEPAGEPAINTING"},
113 static const struct pd_flags pd_flags[] = {
114 {PD_SELECTION, "PD_SELECTION "},
115 {PD_PAGENUMS, "PD_PAGENUMS "},
116 {PD_NOSELECTION, "PD_NOSELECTION "},
117 {PD_NOPAGENUMS, "PD_NOPAGENUMS "},
118 {PD_COLLATE, "PD_COLLATE "},
119 {PD_PRINTTOFILE, "PD_PRINTTOFILE "},
120 {PD_PRINTSETUP, "PD_PRINTSETUP "},
121 {PD_NOWARNING, "PD_NOWARNING "},
122 {PD_RETURNDC, "PD_RETURNDC "},
123 {PD_RETURNIC, "PD_RETURNIC "},
124 {PD_RETURNDEFAULT, "PD_RETURNDEFAULT "},
125 {PD_SHOWHELP, "PD_SHOWHELP "},
126 {PD_ENABLEPRINTHOOK, "PD_ENABLEPRINTHOOK "},
127 {PD_ENABLESETUPHOOK, "PD_ENABLESETUPHOOK "},
128 {PD_ENABLEPRINTTEMPLATE, "PD_ENABLEPRINTTEMPLATE "},
129 {PD_ENABLESETUPTEMPLATE, "PD_ENABLESETUPTEMPLATE "},
130 {PD_ENABLEPRINTTEMPLATEHANDLE, "PD_ENABLEPRINTTEMPLATEHANDLE "},
131 {PD_ENABLESETUPTEMPLATEHANDLE, "PD_ENABLESETUPTEMPLATEHANDLE "},
132 {PD_USEDEVMODECOPIES, "PD_USEDEVMODECOPIES[ANDCOLLATE] "},
133 {PD_DISABLEPRINTTOFILE, "PD_DISABLEPRINTTOFILE "},
134 {PD_HIDEPRINTTOFILE, "PD_HIDEPRINTTOFILE "},
135 {PD_NONETWORKBUTTON, "PD_NONETWORKBUTTON "},
138 /* address of wndproc for subclassed Static control */
139 static WNDPROC lpfnStaticWndProc;
140 static WNDPROC edit_wndproc;
141 /* the text of the fake document to render for the Page Setup dialog */
142 static WCHAR wszFakeDocumentText[1024];
143 static const WCHAR pd32_collateW[] = { 'P', 'D', '3', '2', '_', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
144 static const WCHAR pd32_nocollateW[] = { 'P', 'D', '3', '2', '_', 'N', 'O', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
145 static const WCHAR pd32_portraitW[] = { 'P', 'D', '3', '2', '_', 'P', 'O', 'R', 'T', 'R', 'A', 'I', 'T', 0 };
146 static const WCHAR pd32_landscapeW[] = { 'P', 'D', '3', '2', '_', 'L', 'A', 'N', 'D', 'S', 'C', 'A', 'P', 'E', 0 };
147 static const WCHAR printdlg_prop[] = {'_','_','W','I','N','E','_','P','R','I','N','T','D','L','G','D','A','T','A',0};
148 static const WCHAR pagesetupdlg_prop[] = { '_', '_', 'W', 'I', 'N', 'E', '_', 'P', 'A', 'G', 'E',
149 'S', 'E', 'T', 'U', 'P', 'D', 'L', 'G', 'D', 'A', 'T', 'A', 0 };
152 static LPWSTR strdupW(LPCWSTR p)
158 len = (strlenW(p) + 1) * sizeof(WCHAR);
159 ret = HeapAlloc(GetProcessHeap(), 0, len);
164 /***********************************************************
165 * convert_to_devmodeA
167 * Creates an ansi copy of supplied devmode
169 static DEVMODEA *convert_to_devmodeA(const DEVMODEW *dmW)
174 if (!dmW) return NULL;
175 size = dmW->dmSize - CCHDEVICENAME -
176 ((dmW->dmSize > FIELD_OFFSET(DEVMODEW, dmFormName)) ? CCHFORMNAME : 0);
178 dmA = HeapAlloc(GetProcessHeap(), 0, size + dmW->dmDriverExtra);
179 if (!dmA) return NULL;
181 WideCharToMultiByte(CP_ACP, 0, dmW->dmDeviceName, -1,
182 (LPSTR)dmA->dmDeviceName, CCHDEVICENAME, NULL, NULL);
184 if (FIELD_OFFSET(DEVMODEW, dmFormName) >= dmW->dmSize)
186 memcpy(&dmA->dmSpecVersion, &dmW->dmSpecVersion,
187 dmW->dmSize - FIELD_OFFSET(DEVMODEW, dmSpecVersion));
191 memcpy(&dmA->dmSpecVersion, &dmW->dmSpecVersion,
192 FIELD_OFFSET(DEVMODEW, dmFormName) - FIELD_OFFSET(DEVMODEW, dmSpecVersion));
193 WideCharToMultiByte(CP_ACP, 0, dmW->dmFormName, -1,
194 (LPSTR)dmA->dmFormName, CCHFORMNAME, NULL, NULL);
196 memcpy(&dmA->dmLogPixels, &dmW->dmLogPixels, dmW->dmSize - FIELD_OFFSET(DEVMODEW, dmLogPixels));
200 memcpy((char *)dmA + dmA->dmSize, (const char *)dmW + dmW->dmSize, dmW->dmDriverExtra);
204 /***********************************************************************
205 * PRINTDLG_OpenDefaultPrinter
207 * Returns a winspool printer handle to the default printer in *hprn
208 * Caller must call ClosePrinter on the handle
210 * Returns TRUE on success else FALSE
212 static BOOL PRINTDLG_OpenDefaultPrinter(HANDLE *hprn)
215 DWORD dwBufLen = sizeof(buf) / sizeof(buf[0]);
217 if(!GetDefaultPrinterW(buf, &dwBufLen))
219 res = OpenPrinterW(buf, hprn, NULL);
221 WARN("Could not open printer %s\n", debugstr_w(buf));
225 /***********************************************************************
226 * PRINTDLG_SetUpPrinterListCombo
228 * Initializes printer list combox.
229 * hDlg: HWND of dialog
230 * id: Control id of combo
231 * name: Name of printer to select
233 * Initializes combo with list of available printers. Selects printer 'name'
234 * If name is NULL or does not exist select the default printer.
236 * Returns number of printers added to list.
238 static INT PRINTDLG_SetUpPrinterListComboA(HWND hDlg, UINT id, LPCSTR name)
242 LPPRINTER_INFO_2A pi;
243 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
244 pi = HeapAlloc(GetProcessHeap(), 0, needed);
245 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
248 SendDlgItemMessageA(hDlg, id, CB_RESETCONTENT, 0, 0);
250 for(i = 0; i < num; i++) {
251 SendDlgItemMessageA(hDlg, id, CB_ADDSTRING, 0,
252 (LPARAM)pi[i].pPrinterName );
254 HeapFree(GetProcessHeap(), 0, pi);
256 (i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1,
257 (LPARAM)name)) == CB_ERR) {
260 DWORD dwBufLen = sizeof(buf);
262 WARN("Can't find %s in printer list so trying to find default\n",
264 if(!GetDefaultPrinterA(buf, &dwBufLen))
266 i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
268 FIXME("Can't find default printer in printer list\n");
270 SendDlgItemMessageA(hDlg, id, CB_SETCURSEL, i, 0);
274 static INT PRINTDLG_SetUpPrinterListComboW(HWND hDlg, UINT id, LPCWSTR name)
278 LPPRINTER_INFO_2W pi;
279 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
280 pi = HeapAlloc(GetProcessHeap(), 0, needed);
281 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
284 for(i = 0; i < num; i++) {
285 SendDlgItemMessageW(hDlg, id, CB_ADDSTRING, 0,
286 (LPARAM)pi[i].pPrinterName );
288 HeapFree(GetProcessHeap(), 0, pi);
290 (i = SendDlgItemMessageW(hDlg, id, CB_FINDSTRINGEXACT, -1,
291 (LPARAM)name)) == CB_ERR) {
293 DWORD dwBufLen = sizeof(buf)/sizeof(buf[0]);
295 WARN("Can't find %s in printer list so trying to find default\n",
297 if(!GetDefaultPrinterW(buf, &dwBufLen))
299 i = SendDlgItemMessageW(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
301 TRACE("Can't find default printer in printer list\n");
303 SendDlgItemMessageW(hDlg, id, CB_SETCURSEL, i, 0);
307 /***********************************************************************
308 * PRINTDLG_CreateDevNames [internal]
311 * creates a DevNames structure.
313 * (NB. when we handle unicode the offsets will be in wchars).
315 static BOOL PRINTDLG_CreateDevNames(HGLOBAL *hmem, const char* DeviceDriverName,
316 const char* DeviceName, const char* OutputPort)
319 char* pDevNamesSpace;
321 LPDEVNAMES lpDevNames;
323 DWORD dwBufLen = sizeof(buf);
325 size = strlen(DeviceDriverName) + 1
326 + strlen(DeviceName) + 1
327 + strlen(OutputPort) + 1
331 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
333 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
337 pDevNamesSpace = GlobalLock(*hmem);
338 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
340 pTempPtr = pDevNamesSpace + sizeof(DEVNAMES);
341 strcpy(pTempPtr, DeviceDriverName);
342 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
344 pTempPtr += strlen(DeviceDriverName) + 1;
345 strcpy(pTempPtr, DeviceName);
346 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
348 pTempPtr += strlen(DeviceName) + 1;
349 strcpy(pTempPtr, OutputPort);
350 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
352 GetDefaultPrinterA(buf, &dwBufLen);
353 lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
358 static BOOL PRINTDLG_CreateDevNamesW(HGLOBAL *hmem, LPCWSTR DeviceDriverName,
359 LPCWSTR DeviceName, LPCWSTR OutputPort)
362 LPWSTR pDevNamesSpace;
364 LPDEVNAMES lpDevNames;
366 DWORD dwBufLen = sizeof(bufW) / sizeof(WCHAR);
368 size = sizeof(WCHAR)*lstrlenW(DeviceDriverName) + 2
369 + sizeof(WCHAR)*lstrlenW(DeviceName) + 2
370 + sizeof(WCHAR)*lstrlenW(OutputPort) + 2
374 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
376 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
380 pDevNamesSpace = GlobalLock(*hmem);
381 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
383 pTempPtr = (LPWSTR)((LPDEVNAMES)pDevNamesSpace + 1);
384 lstrcpyW(pTempPtr, DeviceDriverName);
385 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
387 pTempPtr += lstrlenW(DeviceDriverName) + 1;
388 lstrcpyW(pTempPtr, DeviceName);
389 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
391 pTempPtr += lstrlenW(DeviceName) + 1;
392 lstrcpyW(pTempPtr, OutputPort);
393 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
395 GetDefaultPrinterW(bufW, &dwBufLen);
396 lpDevNames->wDefault = (lstrcmpW(bufW, DeviceName) == 0) ? 1 : 0;
401 /***********************************************************************
402 * PRINTDLG_UpdatePrintDlg [internal]
405 * updates the PrintDlg structure for return values.
408 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
409 * TRUE if successful.
411 static BOOL PRINTDLG_UpdatePrintDlgA(HWND hDlg,
412 PRINT_PTRA* PrintStructures)
414 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
415 PDEVMODEA lpdm = PrintStructures->lpDevMode;
416 LPPRINTER_INFO_2A pi = PrintStructures->lpPrinterInfo;
420 FIXME("No lpdm ptr?\n");
425 if(!(lppd->Flags & PD_PRINTSETUP)) {
426 /* check whether nFromPage and nToPage are within range defined by
427 * nMinPage and nMaxPage
429 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
433 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
434 nToPage = GetDlgItemInt(hDlg, edt2, &translated, FALSE);
436 /* if no ToPage value is entered, use the FromPage value */
437 if(!translated) nToPage = nFromPage;
439 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
440 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
441 WCHAR resourcestr[256];
442 WCHAR resultstr[256];
443 LoadStringW(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE, resourcestr, 255);
444 wsprintfW(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
445 LoadStringW(COMDLG32_hInstance, PD32_PRINT_TITLE, resourcestr, 255);
446 MessageBoxW(hDlg, resultstr, resourcestr, MB_OK | MB_ICONWARNING);
449 lppd->nFromPage = nFromPage;
450 lppd->nToPage = nToPage;
451 lppd->Flags |= PD_PAGENUMS;
454 lppd->Flags &= ~PD_PAGENUMS;
456 if (IsDlgButtonChecked(hDlg, rad2) == BST_CHECKED) /* Selection */
457 lppd->Flags |= PD_SELECTION;
459 lppd->Flags &= ~PD_SELECTION;
461 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
462 static char file[] = "FILE:";
463 lppd->Flags |= PD_PRINTTOFILE;
464 pi->pPortName = file;
467 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
468 FIXME("Collate lppd not yet implemented as output\n");
471 /* set PD_Collate and nCopies */
472 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
473 /* The application doesn't support multiple copies or collate...
475 lppd->Flags &= ~PD_COLLATE;
477 /* if the printer driver supports it... store info there
478 * otherwise no collate & multiple copies !
480 if (lpdm->dmFields & DM_COLLATE)
482 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
483 if (lpdm->dmFields & DM_COPIES)
484 lpdm->u1.s1.dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
486 /* Application is responsible for multiple copies */
487 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
488 lppd->Flags |= PD_COLLATE;
490 lppd->Flags &= ~PD_COLLATE;
491 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
492 /* multiple copies already included in the document. Driver must print only one copy */
493 lpdm->u1.s1.dmCopies = 1;
496 /* Print quality, PrintDlg16 */
497 if(GetDlgItem(hDlg, cmb1))
499 HWND hQuality = GetDlgItem(hDlg, cmb1);
500 int Sel = SendMessageA(hQuality, CB_GETCURSEL, 0, 0);
504 LONG dpi = SendMessageA(hQuality, CB_GETITEMDATA, Sel, 0);
505 lpdm->dmFields |= DM_PRINTQUALITY | DM_YRESOLUTION;
506 lpdm->u1.s1.dmPrintQuality = LOWORD(dpi);
507 lpdm->dmYResolution = HIWORD(dpi);
514 static BOOL PRINTDLG_UpdatePrintDlgW(HWND hDlg,
515 PRINT_PTRW* PrintStructures)
517 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
518 PDEVMODEW lpdm = PrintStructures->lpDevMode;
519 LPPRINTER_INFO_2W pi = PrintStructures->lpPrinterInfo;
523 FIXME("No lpdm ptr?\n");
528 if(!(lppd->Flags & PD_PRINTSETUP)) {
529 /* check whether nFromPage and nToPage are within range defined by
530 * nMinPage and nMaxPage
532 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
536 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
537 nToPage = GetDlgItemInt(hDlg, edt2, &translated, FALSE);
539 /* if no ToPage value is entered, use the FromPage value */
540 if(!translated) nToPage = nFromPage;
542 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
543 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
544 WCHAR resourcestr[256];
545 WCHAR resultstr[256];
547 LoadStringW(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
549 args[0] = lppd->nMinPage;
550 args[1] = lppd->nMaxPage;
551 FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
552 resourcestr, 0, 0, resultstr,
553 sizeof(resultstr)/sizeof(*resultstr),
554 (__ms_va_list*)args);
555 LoadStringW(COMDLG32_hInstance, PD32_PRINT_TITLE,
557 MessageBoxW(hDlg, resultstr, resourcestr,
558 MB_OK | MB_ICONWARNING);
561 lppd->nFromPage = nFromPage;
562 lppd->nToPage = nToPage;
563 lppd->Flags |= PD_PAGENUMS;
566 lppd->Flags &= ~PD_PAGENUMS;
568 if (IsDlgButtonChecked(hDlg, rad2) == BST_CHECKED) /* Selection */
569 lppd->Flags |= PD_SELECTION;
571 lppd->Flags &= ~PD_SELECTION;
573 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
574 static WCHAR file[] = {'F','I','L','E',':',0};
575 lppd->Flags |= PD_PRINTTOFILE;
576 pi->pPortName = file;
579 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
580 FIXME("Collate lppd not yet implemented as output\n");
583 /* set PD_Collate and nCopies */
584 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
585 /* The application doesn't support multiple copies or collate...
587 lppd->Flags &= ~PD_COLLATE;
589 /* if the printer driver supports it... store info there
590 * otherwise no collate & multiple copies !
592 if (lpdm->dmFields & DM_COLLATE)
594 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
595 if (lpdm->dmFields & DM_COPIES)
596 lpdm->u1.s1.dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
598 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
599 lppd->Flags |= PD_COLLATE;
601 lppd->Flags &= ~PD_COLLATE;
602 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
608 /************************************************************************
609 * PRINTDLG_SetUpPaperComboBox
611 * Initialize either the papersize or inputslot combos of the Printer Setup
612 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
613 * We also try to re-select the old selection.
615 static BOOL PRINTDLG_SetUpPaperComboBoxA(HWND hDlg,
626 WORD oldWord = 0, newWord = 0; /* DMPAPER_ and DMBIN_ start at 1 */
628 int fwCapability_Names;
629 int fwCapability_Words;
631 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName,PortName,nIDComboBox);
633 /* query the dialog box for the current selected value */
634 Sel = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
636 /* we enter here only if a different printer is selected after
637 * the Print Setup dialog is opened. The current settings are
638 * stored into the newly selected printer.
640 oldWord = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA,
642 if(oldWord >= DMPAPER_USER) /* DMPAPER_USER == DMBIN_USER */
643 oldWord = 0; /* There's no point in trying to keep custom
644 paper / bin sizes across printers */
648 newWord = (nIDComboBox == cmb2) ? dm->u1.s1.dmPaperSize : dm->u1.s1.dmDefaultSource;
650 if (nIDComboBox == cmb2) {
652 fwCapability_Names = DC_PAPERNAMES;
653 fwCapability_Words = DC_PAPERS;
657 fwCapability_Names = DC_BINNAMES;
658 fwCapability_Words = DC_BINS;
661 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
662 fwCapability_Names, NULL, dm);
663 if (NrOfEntries == 0)
664 WARN("no Name Entries found!\n");
665 else if (NrOfEntries < 0)
668 if(DeviceCapabilitiesA(PrinterName, PortName, fwCapability_Words, NULL, dm)
670 ERR("Number of caps is different\n");
674 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(char)*NamesSize);
675 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
676 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
677 fwCapability_Names, Names, dm);
678 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
679 fwCapability_Words, (LPSTR)Words, dm);
681 /* reset any current content in the combobox */
682 SendDlgItemMessageA(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
684 /* store new content */
685 for (i = 0; i < NrOfEntries; i++) {
686 DWORD pos = SendDlgItemMessageA(hDlg, nIDComboBox, CB_ADDSTRING, 0,
687 (LPARAM)(&Names[i*NamesSize]) );
688 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
692 /* Look for old selection or the new default.
693 Can't do this is previous loop since item order will change as more items are added */
695 old_Sel = NrOfEntries;
696 for (i = 0; i < NrOfEntries; i++) {
697 if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
702 if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) == newWord)
706 if(old_Sel < NrOfEntries)
710 if(nIDComboBox == cmb2)
711 dm->u1.s1.dmPaperSize = oldWord;
713 dm->u1.s1.dmDefaultSource = oldWord;
718 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
720 HeapFree(GetProcessHeap(),0,Words);
721 HeapFree(GetProcessHeap(),0,Names);
725 static BOOL PRINTDLG_SetUpPaperComboBoxW(HWND hDlg,
727 const WCHAR* PrinterName,
728 const WCHAR* PortName,
736 WORD oldWord = 0, newWord = 0; /* DMPAPER_ and DMBIN_ start at 1 */
738 int fwCapability_Names;
739 int fwCapability_Words;
741 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName),debugstr_w(PortName),nIDComboBox);
743 /* query the dialog box for the current selected value */
744 Sel = SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
746 /* we enter here only if a different printer is selected after
747 * the Print Setup dialog is opened. The current settings are
748 * stored into the newly selected printer.
750 oldWord = SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETITEMDATA,
753 if(oldWord >= DMPAPER_USER) /* DMPAPER_USER == DMBIN_USER */
754 oldWord = 0; /* There's no point in trying to keep custom
755 paper / bin sizes across printers */
759 newWord = (nIDComboBox == cmb2) ? dm->u1.s1.dmPaperSize : dm->u1.s1.dmDefaultSource;
761 if (nIDComboBox == cmb2) {
763 fwCapability_Names = DC_PAPERNAMES;
764 fwCapability_Words = DC_PAPERS;
768 fwCapability_Names = DC_BINNAMES;
769 fwCapability_Words = DC_BINS;
772 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
773 fwCapability_Names, NULL, dm);
774 if (NrOfEntries == 0)
775 WARN("no Name Entries found!\n");
776 else if (NrOfEntries < 0)
779 if(DeviceCapabilitiesW(PrinterName, PortName, fwCapability_Words, NULL, dm)
781 ERR("Number of caps is different\n");
785 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WCHAR)*NamesSize);
786 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
787 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
788 fwCapability_Names, Names, dm);
789 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
790 fwCapability_Words, Words, dm);
792 /* reset any current content in the combobox */
793 SendDlgItemMessageW(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
795 /* store new content */
796 for (i = 0; i < NrOfEntries; i++) {
797 DWORD pos = SendDlgItemMessageW(hDlg, nIDComboBox, CB_ADDSTRING, 0,
798 (LPARAM)(&Names[i*NamesSize]) );
799 SendDlgItemMessageW(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
803 /* Look for old selection or the new default.
804 Can't do this is previous loop since item order will change as more items are added */
806 old_Sel = NrOfEntries;
807 for (i = 0; i < NrOfEntries; i++) {
808 if(SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
813 if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) == newWord)
817 if(old_Sel < NrOfEntries)
821 if(nIDComboBox == cmb2)
822 dm->u1.s1.dmPaperSize = oldWord;
824 dm->u1.s1.dmDefaultSource = oldWord;
829 SendDlgItemMessageW(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
831 HeapFree(GetProcessHeap(),0,Words);
832 HeapFree(GetProcessHeap(),0,Names);
837 /***********************************************************************
838 * PRINTDLG_UpdatePrinterInfoTexts [internal]
840 static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg, const PRINTER_INFO_2A *pi)
843 char ResourceString[256];
849 /* add all status messages */
850 for (i = 0; i < 25; i++) {
851 if (pi->Status & (1<<i)) {
852 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
853 ResourceString, 255);
854 strcat(StatusMsg,ResourceString);
858 /* FIXME: status==ready must only be appended if really so.
859 but how to detect? */
860 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
861 ResourceString, 255);
862 strcat(StatusMsg,ResourceString);
863 SetDlgItemTextA(hDlg, stc12, StatusMsg);
865 /* set all other printer info texts */
866 SetDlgItemTextA(hDlg, stc11, pi->pDriverName);
868 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
869 SetDlgItemTextA(hDlg, stc14, pi->pLocation);
871 SetDlgItemTextA(hDlg, stc14, pi->pPortName);
872 SetDlgItemTextA(hDlg, stc13, pi->pComment ? pi->pComment : "");
876 static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg, const PRINTER_INFO_2W *pi)
878 WCHAR StatusMsg[256];
879 WCHAR ResourceString[256];
880 static const WCHAR emptyW[] = {0};
886 /* add all status messages */
887 for (i = 0; i < 25; i++) {
888 if (pi->Status & (1<<i)) {
889 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
890 ResourceString, 255);
891 lstrcatW(StatusMsg,ResourceString);
895 /* FIXME: status==ready must only be appended if really so.
896 but how to detect? */
897 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
898 ResourceString, 255);
899 lstrcatW(StatusMsg,ResourceString);
900 SetDlgItemTextW(hDlg, stc12, StatusMsg);
902 /* set all other printer info texts */
903 SetDlgItemTextW(hDlg, stc11, pi->pDriverName);
904 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
905 SetDlgItemTextW(hDlg, stc14, pi->pLocation);
907 SetDlgItemTextW(hDlg, stc14, pi->pPortName);
908 SetDlgItemTextW(hDlg, stc13, pi->pComment ? pi->pComment : emptyW);
912 /*******************************************************************
914 * PRINTDLG_ChangePrinter
917 static BOOL PRINTDLG_ChangePrinterA(HWND hDlg, char *name, PRINT_PTRA *PrintStructures)
919 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
920 LPDEVMODEA lpdm = NULL;
925 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
926 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
927 if(!OpenPrinterA(name, &hprn, NULL)) {
928 ERR("Can't open printer %s\n", name);
931 GetPrinterA(hprn, 2, NULL, 0, &needed);
932 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,needed);
933 GetPrinterA(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
935 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
936 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,needed);
937 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
939 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures->lpPrinterInfo->pPrinterName);
944 PRINTDLG_UpdatePrinterInfoTextsA(hDlg, PrintStructures->lpPrinterInfo);
946 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
947 PrintStructures->lpDevMode = NULL;
949 dmSize = DocumentPropertiesA(0, 0, name, NULL, NULL, 0);
951 ERR("DocumentProperties fails on %s\n", debugstr_a(name));
954 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
955 dmSize = DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, NULL,
957 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
958 !lstrcmpA( (LPSTR) lpdm->dmDeviceName,
959 (LPSTR) PrintStructures->lpDevMode->dmDeviceName)) {
960 /* Supplied devicemode matches current printer so try to use it */
961 DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, lpdm,
962 DM_OUT_BUFFER | DM_IN_BUFFER);
965 GlobalUnlock(lppd->hDevMode);
967 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
969 if(!(lppd->Flags & PD_PRINTSETUP)) {
970 /* Print range (All/Range/Selection) */
971 if(lppd->nFromPage != 0xffff)
972 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
973 if(lppd->nToPage != 0xffff)
974 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
976 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
977 if (lppd->Flags & PD_NOSELECTION)
978 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
980 if (lppd->Flags & PD_SELECTION)
981 CheckRadioButton(hDlg, rad1, rad3, rad2);
982 if (lppd->Flags & PD_NOPAGENUMS) {
983 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
984 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
985 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
986 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
987 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
989 if (lppd->Flags & PD_PAGENUMS)
990 CheckRadioButton(hDlg, rad1, rad3, rad3);
995 * FIXME: The ico3 is not displayed for some reason. I don't know why.
997 if (lppd->Flags & PD_COLLATE) {
998 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, IMAGE_ICON,
999 (LPARAM)PrintStructures->hCollateIcon);
1000 CheckDlgButton(hDlg, chx2, 1);
1002 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, IMAGE_ICON,
1003 (LPARAM)PrintStructures->hNoCollateIcon);
1004 CheckDlgButton(hDlg, chx2, 0);
1007 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1008 /* if printer doesn't support it: no Collate */
1009 if (!(lpdm->dmFields & DM_COLLATE)) {
1010 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1011 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
1018 if (lppd->hDevMode == 0)
1019 copies = lppd->nCopies;
1021 copies = lpdm->u1.s1.dmCopies;
1022 if(copies == 0) copies = 1;
1023 else if(copies < 0) copies = MAX_COPIES;
1024 SetDlgItemInt(hDlg, edt3, copies, FALSE);
1027 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1028 /* if printer doesn't support it: no nCopies */
1029 if (!(lpdm->dmFields & DM_COPIES)) {
1030 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
1031 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
1036 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
1037 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
1038 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
1039 if (lppd->Flags & PD_HIDEPRINTTOFILE)
1040 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
1042 /* Fill print quality combo, PrintDlg16 */
1043 if(GetDlgItem(hDlg, cmb1))
1045 DWORD numResolutions = DeviceCapabilitiesA(PrintStructures->lpPrinterInfo->pPrinterName,
1046 PrintStructures->lpPrinterInfo->pPortName,
1047 DC_ENUMRESOLUTIONS, NULL, lpdm);
1049 if(numResolutions != -1)
1051 HWND hQuality = GetDlgItem(hDlg, cmb1);
1056 HDC hPrinterDC = CreateDCA(PrintStructures->lpPrinterInfo->pDriverName,
1057 PrintStructures->lpPrinterInfo->pPrinterName,
1060 Resolutions = HeapAlloc(GetProcessHeap(), 0, numResolutions*sizeof(LONG)*2);
1061 DeviceCapabilitiesA(PrintStructures->lpPrinterInfo->pPrinterName,
1062 PrintStructures->lpPrinterInfo->pPortName,
1063 DC_ENUMRESOLUTIONS, (LPSTR)Resolutions, lpdm);
1065 dpiX = GetDeviceCaps(hPrinterDC, LOGPIXELSX);
1066 dpiY = GetDeviceCaps(hPrinterDC, LOGPIXELSY);
1067 DeleteDC(hPrinterDC);
1069 SendMessageA(hQuality, CB_RESETCONTENT, 0, 0);
1070 for(i = 0; i < (numResolutions * 2); i += 2)
1072 BOOL IsDefault = FALSE;
1075 if(Resolutions[i] == Resolutions[i+1])
1077 if(dpiX == Resolutions[i])
1079 sprintf(buf, "%d dpi", Resolutions[i]);
1082 if(dpiX == Resolutions[i] && dpiY == Resolutions[i+1])
1084 sprintf(buf, "%d dpi x %d dpi", Resolutions[i], Resolutions[i+1]);
1087 Index = SendMessageA(hQuality, CB_ADDSTRING, 0, (LPARAM)buf);
1090 SendMessageA(hQuality, CB_SETCURSEL, Index, 0);
1092 SendMessageA(hQuality, CB_SETITEMDATA, Index, MAKELONG(dpiX,dpiY));
1094 HeapFree(GetProcessHeap(), 0, Resolutions);
1097 } else { /* PD_PRINTSETUP */
1098 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
1100 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb2,
1101 PrintStructures->lpPrinterInfo->pPrinterName,
1102 PrintStructures->lpPrinterInfo->pPortName,
1104 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb3,
1105 PrintStructures->lpPrinterInfo->pPrinterName,
1106 PrintStructures->lpPrinterInfo->pPortName,
1108 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1109 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, IMAGE_ICON,
1110 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1111 PrintStructures->hLandscapeIcon));
1116 if ((lppd->Flags & PD_SHOWHELP)==0) {
1117 /* hide if PD_SHOWHELP not specified */
1118 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1123 static BOOL PRINTDLG_ChangePrinterW(HWND hDlg, WCHAR *name,
1124 PRINT_PTRW *PrintStructures)
1126 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1127 LPDEVMODEW lpdm = NULL;
1132 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
1133 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
1134 if(!OpenPrinterW(name, &hprn, NULL)) {
1135 ERR("Can't open printer %s\n", debugstr_w(name));
1138 GetPrinterW(hprn, 2, NULL, 0, &needed);
1139 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,needed);
1140 GetPrinterW(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
1142 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
1143 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,needed);
1144 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
1146 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures->lpPrinterInfo->pPrinterName));
1151 PRINTDLG_UpdatePrinterInfoTextsW(hDlg, PrintStructures->lpPrinterInfo);
1153 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
1154 PrintStructures->lpDevMode = NULL;
1156 dmSize = DocumentPropertiesW(0, 0, name, NULL, NULL, 0);
1158 ERR("DocumentProperties fails on %s\n", debugstr_w(name));
1161 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
1162 dmSize = DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, NULL,
1164 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
1165 !lstrcmpW(lpdm->dmDeviceName,
1166 PrintStructures->lpDevMode->dmDeviceName)) {
1167 /* Supplied devicemode matches current printer so try to use it */
1168 DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, lpdm,
1169 DM_OUT_BUFFER | DM_IN_BUFFER);
1172 GlobalUnlock(lppd->hDevMode);
1174 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
1176 if(!(lppd->Flags & PD_PRINTSETUP)) {
1177 /* Print range (All/Range/Selection) */
1178 if(lppd->nFromPage != 0xffff)
1179 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
1180 if(lppd->nToPage != 0xffff)
1181 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
1183 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
1184 if (lppd->Flags & PD_NOSELECTION)
1185 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
1187 if (lppd->Flags & PD_SELECTION)
1188 CheckRadioButton(hDlg, rad1, rad3, rad2);
1189 if (lppd->Flags & PD_NOPAGENUMS) {
1190 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
1191 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
1192 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
1193 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
1194 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
1196 if (lppd->Flags & PD_PAGENUMS)
1197 CheckRadioButton(hDlg, rad1, rad3, rad3);
1202 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1204 if (lppd->Flags & PD_COLLATE) {
1205 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, IMAGE_ICON,
1206 (LPARAM)PrintStructures->hCollateIcon);
1207 CheckDlgButton(hDlg, chx2, 1);
1209 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, IMAGE_ICON,
1210 (LPARAM)PrintStructures->hNoCollateIcon);
1211 CheckDlgButton(hDlg, chx2, 0);
1214 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1215 /* if printer doesn't support it: no Collate */
1216 if (!(lpdm->dmFields & DM_COLLATE)) {
1217 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1218 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
1225 if (lppd->hDevMode == 0)
1226 copies = lppd->nCopies;
1228 copies = lpdm->u1.s1.dmCopies;
1229 if(copies == 0) copies = 1;
1230 else if(copies < 0) copies = MAX_COPIES;
1231 SetDlgItemInt(hDlg, edt3, copies, FALSE);
1234 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1235 /* if printer doesn't support it: no nCopies */
1236 if (!(lpdm->dmFields & DM_COPIES)) {
1237 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
1238 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
1243 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
1244 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
1245 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
1246 if (lppd->Flags & PD_HIDEPRINTTOFILE)
1247 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
1249 } else { /* PD_PRINTSETUP */
1250 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
1252 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb2,
1253 PrintStructures->lpPrinterInfo->pPrinterName,
1254 PrintStructures->lpPrinterInfo->pPortName,
1256 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb3,
1257 PrintStructures->lpPrinterInfo->pPrinterName,
1258 PrintStructures->lpPrinterInfo->pPortName,
1260 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1261 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, IMAGE_ICON,
1262 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1263 PrintStructures->hLandscapeIcon));
1268 if ((lppd->Flags & PD_SHOWHELP)==0) {
1269 /* hide if PD_SHOWHELP not specified */
1270 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1275 /***********************************************************************
1276 * check_printer_setup [internal]
1278 static LRESULT check_printer_setup(HWND hDlg)
1281 WCHAR resourcestr[256],resultstr[256];
1283 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
1286 EnumPrintersW(PRINTER_ENUM_CONNECTIONS, NULL, 2, NULL, 0, &needed, &num);
1292 LoadStringW(COMDLG32_hInstance, PD32_NO_DEVICES,resultstr, 255);
1293 LoadStringW(COMDLG32_hInstance, PD32_PRINT_TITLE,resourcestr, 255);
1294 MessageBoxW(hDlg, resultstr, resourcestr,MB_OK | MB_ICONWARNING);
1299 /***********************************************************************
1300 * PRINTDLG_WMInitDialog [internal]
1302 static LRESULT PRINTDLG_WMInitDialog(HWND hDlg,
1303 PRINT_PTRA* PrintStructures)
1305 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
1309 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1311 /* load Collate ICONs */
1312 /* We load these with LoadImage because they are not a standard
1313 size and we don't want them rescaled */
1314 PrintStructures->hCollateIcon =
1315 LoadImageA(COMDLG32_hInstance, "PD32_COLLATE", IMAGE_ICON, 0, 0, 0);
1316 PrintStructures->hNoCollateIcon =
1317 LoadImageA(COMDLG32_hInstance, "PD32_NOCOLLATE", IMAGE_ICON, 0, 0, 0);
1319 /* These can be done with LoadIcon */
1320 PrintStructures->hPortraitIcon =
1321 LoadIconA(COMDLG32_hInstance, "PD32_PORTRAIT");
1322 PrintStructures->hLandscapeIcon =
1323 LoadIconA(COMDLG32_hInstance, "PD32_LANDSCAPE");
1325 /* display the collate/no_collate icon */
1326 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, IMAGE_ICON,
1327 (LPARAM)PrintStructures->hNoCollateIcon);
1329 if(PrintStructures->hCollateIcon == 0 ||
1330 PrintStructures->hNoCollateIcon == 0 ||
1331 PrintStructures->hPortraitIcon == 0 ||
1332 PrintStructures->hLandscapeIcon == 0) {
1333 ERR("no icon in resourcefile\n");
1334 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1335 EndDialog(hDlg, FALSE);
1339 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1340 * must be registered and the Help button must be shown.
1342 if (lppd->Flags & PD_SHOWHELP) {
1343 if((PrintStructures->HelpMessageID =
1344 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
1345 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1349 PrintStructures->HelpMessageID = 0;
1351 if(!(lppd->Flags &PD_PRINTSETUP)) {
1352 PrintStructures->hwndUpDown =
1353 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1354 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1355 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1356 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1357 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1360 /* FIXME: I allow more freedom than either Win95 or WinNT,
1361 * which do not agree to what errors should be thrown or not
1362 * in case nToPage or nFromPage is out-of-range.
1364 if (lppd->nMaxPage < lppd->nMinPage)
1365 lppd->nMaxPage = lppd->nMinPage;
1366 if (lppd->nMinPage == lppd->nMaxPage)
1367 lppd->Flags |= PD_NOPAGENUMS;
1368 if (lppd->nToPage < lppd->nMinPage)
1369 lppd->nToPage = lppd->nMinPage;
1370 if (lppd->nToPage > lppd->nMaxPage)
1371 lppd->nToPage = lppd->nMaxPage;
1372 if (lppd->nFromPage < lppd->nMinPage)
1373 lppd->nFromPage = lppd->nMinPage;
1374 if (lppd->nFromPage > lppd->nMaxPage)
1375 lppd->nFromPage = lppd->nMaxPage;
1377 /* if we have the combo box, fill it */
1378 if (GetDlgItem(hDlg,comboID)) {
1381 pdn = GlobalLock(lppd->hDevNames);
1382 pdm = GlobalLock(lppd->hDevMode);
1384 name = (char*)pdn + pdn->wDeviceOffset;
1386 name = (char*)pdm->dmDeviceName;
1387 PRINTDLG_SetUpPrinterListComboA(hDlg, comboID, name);
1388 if(pdm) GlobalUnlock(lppd->hDevMode);
1389 if(pdn) GlobalUnlock(lppd->hDevNames);
1391 /* Now find selected printer and update rest of dlg */
1392 name = HeapAlloc(GetProcessHeap(),0,256);
1393 if (GetDlgItemTextA(hDlg, comboID, name, 255))
1394 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1395 HeapFree(GetProcessHeap(),0,name);
1397 /* else use default printer */
1399 DWORD dwBufLen = sizeof(name);
1400 BOOL ret = GetDefaultPrinterA(name, &dwBufLen);
1403 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1405 FIXME("No default printer found, expect problems!\n");
1410 static LRESULT PRINTDLG_WMInitDialogW(HWND hDlg,
1411 PRINT_PTRW* PrintStructures)
1413 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1417 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1419 /* load Collate ICONs */
1420 /* We load these with LoadImage because they are not a standard
1421 size and we don't want them rescaled */
1422 PrintStructures->hCollateIcon =
1423 LoadImageW(COMDLG32_hInstance, pd32_collateW, IMAGE_ICON, 0, 0, 0);
1424 PrintStructures->hNoCollateIcon =
1425 LoadImageW(COMDLG32_hInstance, pd32_nocollateW, IMAGE_ICON, 0, 0, 0);
1427 /* These can be done with LoadIcon */
1428 PrintStructures->hPortraitIcon =
1429 LoadIconW(COMDLG32_hInstance, pd32_portraitW);
1430 PrintStructures->hLandscapeIcon =
1431 LoadIconW(COMDLG32_hInstance, pd32_landscapeW);
1433 /* display the collate/no_collate icon */
1434 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, IMAGE_ICON,
1435 (LPARAM)PrintStructures->hNoCollateIcon);
1437 if(PrintStructures->hCollateIcon == 0 ||
1438 PrintStructures->hNoCollateIcon == 0 ||
1439 PrintStructures->hPortraitIcon == 0 ||
1440 PrintStructures->hLandscapeIcon == 0) {
1441 ERR("no icon in resourcefile\n");
1442 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1443 EndDialog(hDlg, FALSE);
1447 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1448 * must be registered and the Help button must be shown.
1450 if (lppd->Flags & PD_SHOWHELP) {
1451 if((PrintStructures->HelpMessageID =
1452 RegisterWindowMessageW(HELPMSGSTRINGW)) == 0) {
1453 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1457 PrintStructures->HelpMessageID = 0;
1459 if(!(lppd->Flags &PD_PRINTSETUP)) {
1460 PrintStructures->hwndUpDown =
1461 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1462 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1463 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1464 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1465 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1468 /* FIXME: I allow more freedom than either Win95 or WinNT,
1469 * which do not agree to what errors should be thrown or not
1470 * in case nToPage or nFromPage is out-of-range.
1472 if (lppd->nMaxPage < lppd->nMinPage)
1473 lppd->nMaxPage = lppd->nMinPage;
1474 if (lppd->nMinPage == lppd->nMaxPage)
1475 lppd->Flags |= PD_NOPAGENUMS;
1476 if (lppd->nToPage < lppd->nMinPage)
1477 lppd->nToPage = lppd->nMinPage;
1478 if (lppd->nToPage > lppd->nMaxPage)
1479 lppd->nToPage = lppd->nMaxPage;
1480 if (lppd->nFromPage < lppd->nMinPage)
1481 lppd->nFromPage = lppd->nMinPage;
1482 if (lppd->nFromPage > lppd->nMaxPage)
1483 lppd->nFromPage = lppd->nMaxPage;
1485 /* if we have the combo box, fill it */
1486 if (GetDlgItem(hDlg,comboID)) {
1489 pdn = GlobalLock(lppd->hDevNames);
1490 pdm = GlobalLock(lppd->hDevMode);
1492 name = (WCHAR*)pdn + pdn->wDeviceOffset;
1494 name = pdm->dmDeviceName;
1495 PRINTDLG_SetUpPrinterListComboW(hDlg, comboID, name);
1496 if(pdm) GlobalUnlock(lppd->hDevMode);
1497 if(pdn) GlobalUnlock(lppd->hDevNames);
1499 /* Now find selected printer and update rest of dlg */
1500 /* ansi is ok here */
1501 name = HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR));
1502 if (GetDlgItemTextW(hDlg, comboID, name, 255))
1503 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1504 HeapFree(GetProcessHeap(),0,name);
1506 /* else use default printer */
1508 DWORD dwBufLen = sizeof(name) / sizeof(WCHAR);
1509 BOOL ret = GetDefaultPrinterW(name, &dwBufLen);
1512 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1514 FIXME("No default printer found, expect problems!\n");
1519 /***********************************************************************
1520 * PRINTDLG_WMCommand [internal]
1522 static LRESULT PRINTDLG_WMCommandA(HWND hDlg, WPARAM wParam,
1523 PRINT_PTRA* PrintStructures)
1525 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
1526 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1527 LPDEVMODEA lpdm = PrintStructures->lpDevMode;
1529 switch (LOWORD(wParam)) {
1531 TRACE(" OK button was hit\n");
1532 if (!PRINTDLG_UpdatePrintDlgA(hDlg, PrintStructures)) {
1533 FIXME("Update printdlg was not successful!\n");
1536 EndDialog(hDlg, TRUE);
1540 TRACE(" CANCEL button was hit\n");
1541 EndDialog(hDlg, FALSE);
1545 TRACE(" HELP button was hit\n");
1546 SendMessageA(lppd->hwndOwner, PrintStructures->HelpMessageID,
1547 (WPARAM) hDlg, (LPARAM) lppd);
1550 case chx2: /* collate pages checkbox */
1551 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1552 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, IMAGE_ICON,
1553 (LPARAM)PrintStructures->hCollateIcon);
1555 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, IMAGE_ICON,
1556 (LPARAM)PrintStructures->hNoCollateIcon);
1558 case edt1: /* from page nr editbox */
1559 case edt2: /* to page nr editbox */
1560 if (HIWORD(wParam)==EN_CHANGE) {
1563 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1564 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1565 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1566 CheckRadioButton(hDlg, rad1, rad3, rad3);
1571 if(HIWORD(wParam) == EN_CHANGE) {
1572 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1574 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1576 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1580 case psh2: /* Properties button */
1583 char PrinterName[256];
1585 GetDlgItemTextA(hDlg, PrinterComboID, PrinterName, 255);
1586 if (!OpenPrinterA(PrinterName, &hPrinter, NULL)) {
1587 FIXME(" Call to OpenPrinter did not succeed!\n");
1590 DocumentPropertiesA(hDlg, hPrinter, PrinterName,
1591 PrintStructures->lpDevMode,
1592 PrintStructures->lpDevMode,
1593 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1594 ClosePrinter(hPrinter);
1598 case rad1: /* Paperorientation */
1599 if (lppd->Flags & PD_PRINTSETUP)
1601 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1602 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, IMAGE_ICON,
1603 (LPARAM)(PrintStructures->hPortraitIcon));
1607 case rad2: /* Paperorientation */
1608 if (lppd->Flags & PD_PRINTSETUP)
1610 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1611 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, IMAGE_ICON,
1612 (LPARAM)(PrintStructures->hLandscapeIcon));
1616 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT16 */
1617 if (PrinterComboID != LOWORD(wParam)) {
1621 case cmb4: /* Printer combobox */
1622 if (HIWORD(wParam)==CBN_SELCHANGE) {
1623 char PrinterName[256];
1624 GetDlgItemTextA(hDlg, LOWORD(wParam), PrinterName, 255);
1625 PRINTDLG_ChangePrinterA(hDlg, PrinterName, PrintStructures);
1629 case cmb2: /* Papersize */
1631 DWORD Sel = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1633 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
1639 case cmb3: /* Bin */
1641 DWORD Sel = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1643 lpdm->u1.s1.dmDefaultSource = SendDlgItemMessageA(hDlg, cmb3,
1644 CB_GETITEMDATA, Sel,
1649 if(lppd->Flags & PD_PRINTSETUP) {
1650 switch (LOWORD(wParam)) {
1651 case rad1: /* orientation */
1653 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1654 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1655 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1656 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE, IMAGE_ICON,
1657 (LPARAM)PrintStructures->hPortraitIcon);
1658 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, IMAGE_ICON,
1659 (LPARAM)PrintStructures->hPortraitIcon);
1662 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1663 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1664 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE, IMAGE_ICON,
1665 (LPARAM)PrintStructures->hLandscapeIcon);
1666 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, IMAGE_ICON,
1667 (LPARAM)PrintStructures->hLandscapeIcon);
1676 static LRESULT PRINTDLG_WMCommandW(HWND hDlg, WPARAM wParam,
1677 PRINT_PTRW* PrintStructures)
1679 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1680 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1681 LPDEVMODEW lpdm = PrintStructures->lpDevMode;
1683 switch (LOWORD(wParam)) {
1685 TRACE(" OK button was hit\n");
1686 if (!PRINTDLG_UpdatePrintDlgW(hDlg, PrintStructures)) {
1687 FIXME("Update printdlg was not successful!\n");
1690 EndDialog(hDlg, TRUE);
1694 TRACE(" CANCEL button was hit\n");
1695 EndDialog(hDlg, FALSE);
1699 TRACE(" HELP button was hit\n");
1700 SendMessageW(lppd->hwndOwner, PrintStructures->HelpMessageID,
1701 (WPARAM) hDlg, (LPARAM) lppd);
1704 case chx2: /* collate pages checkbox */
1705 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1706 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, IMAGE_ICON,
1707 (LPARAM)PrintStructures->hCollateIcon);
1709 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, IMAGE_ICON,
1710 (LPARAM)PrintStructures->hNoCollateIcon);
1712 case edt1: /* from page nr editbox */
1713 case edt2: /* to page nr editbox */
1714 if (HIWORD(wParam)==EN_CHANGE) {
1717 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1718 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1719 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1720 CheckRadioButton(hDlg, rad1, rad3, rad3);
1725 if(HIWORD(wParam) == EN_CHANGE) {
1726 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1728 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1730 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1734 case psh2: /* Properties button */
1737 WCHAR PrinterName[256];
1739 if (!GetDlgItemTextW(hDlg, PrinterComboID, PrinterName, 255)) break;
1740 if (!OpenPrinterW(PrinterName, &hPrinter, NULL)) {
1741 FIXME(" Call to OpenPrinter did not succeed!\n");
1744 DocumentPropertiesW(hDlg, hPrinter, PrinterName,
1745 PrintStructures->lpDevMode,
1746 PrintStructures->lpDevMode,
1747 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1748 ClosePrinter(hPrinter);
1752 case rad1: /* Paperorientation */
1753 if (lppd->Flags & PD_PRINTSETUP)
1755 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1756 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, IMAGE_ICON,
1757 (LPARAM)(PrintStructures->hPortraitIcon));
1761 case rad2: /* Paperorientation */
1762 if (lppd->Flags & PD_PRINTSETUP)
1764 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1765 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, IMAGE_ICON,
1766 (LPARAM)(PrintStructures->hLandscapeIcon));
1770 case cmb1: /* Printer Combobox in PRINT SETUP */
1772 case cmb4: /* Printer combobox */
1773 if (HIWORD(wParam)==CBN_SELCHANGE) {
1774 WCHAR PrinterName[256];
1775 GetDlgItemTextW(hDlg, LOWORD(wParam), PrinterName, 255);
1776 PRINTDLG_ChangePrinterW(hDlg, PrinterName, PrintStructures);
1780 case cmb2: /* Papersize */
1782 DWORD Sel = SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1784 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageW(hDlg, cmb2,
1790 case cmb3: /* Bin */
1792 DWORD Sel = SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1794 lpdm->u1.s1.dmDefaultSource = SendDlgItemMessageW(hDlg, cmb3,
1795 CB_GETITEMDATA, Sel,
1800 if(lppd->Flags & PD_PRINTSETUP) {
1801 switch (LOWORD(wParam)) {
1802 case rad1: /* orientation */
1804 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1805 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1806 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1807 SendDlgItemMessageW(hDlg, stc10, STM_SETIMAGE, IMAGE_ICON,
1808 (LPARAM)PrintStructures->hPortraitIcon);
1809 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, IMAGE_ICON,
1810 (LPARAM)PrintStructures->hPortraitIcon);
1813 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1814 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1815 SendDlgItemMessageW(hDlg, stc10, STM_SETIMAGE, IMAGE_ICON,
1816 (LPARAM)PrintStructures->hLandscapeIcon);
1817 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, IMAGE_ICON,
1818 (LPARAM)PrintStructures->hLandscapeIcon);
1827 /***********************************************************************
1828 * PrintDlgProcA [internal]
1830 static INT_PTR CALLBACK PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
1833 PRINT_PTRA* PrintStructures;
1834 INT_PTR res = FALSE;
1836 if (uMsg!=WM_INITDIALOG) {
1837 PrintStructures = GetPropW(hDlg, printdlg_prop);
1838 if (!PrintStructures)
1841 PrintStructures = (PRINT_PTRA*) lParam;
1842 SetPropW(hDlg, printdlg_prop, PrintStructures);
1843 if(!check_printer_setup(hDlg))
1845 EndDialog(hDlg,FALSE);
1848 res = PRINTDLG_WMInitDialog(hDlg, PrintStructures);
1850 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
1851 res = PrintStructures->lpPrintDlg->lpfnPrintHook(
1852 hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg
1857 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
1858 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam,
1865 return PRINTDLG_WMCommandA(hDlg, wParam, PrintStructures);
1868 DestroyIcon(PrintStructures->hCollateIcon);
1869 DestroyIcon(PrintStructures->hNoCollateIcon);
1870 DestroyIcon(PrintStructures->hPortraitIcon);
1871 DestroyIcon(PrintStructures->hLandscapeIcon);
1872 if(PrintStructures->hwndUpDown)
1873 DestroyWindow(PrintStructures->hwndUpDown);
1879 static INT_PTR CALLBACK PrintDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
1882 PRINT_PTRW* PrintStructures;
1883 INT_PTR res = FALSE;
1885 if (uMsg!=WM_INITDIALOG) {
1886 PrintStructures = GetPropW(hDlg, printdlg_prop);
1887 if (!PrintStructures)
1890 PrintStructures = (PRINT_PTRW*) lParam;
1891 SetPropW(hDlg, printdlg_prop, PrintStructures);
1892 if(!check_printer_setup(hDlg))
1894 EndDialog(hDlg,FALSE);
1897 res = PRINTDLG_WMInitDialogW(hDlg, PrintStructures);
1899 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
1900 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg);
1904 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
1905 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam, lParam);
1911 return PRINTDLG_WMCommandW(hDlg, wParam, PrintStructures);
1914 DestroyIcon(PrintStructures->hCollateIcon);
1915 DestroyIcon(PrintStructures->hNoCollateIcon);
1916 DestroyIcon(PrintStructures->hPortraitIcon);
1917 DestroyIcon(PrintStructures->hLandscapeIcon);
1918 if(PrintStructures->hwndUpDown)
1919 DestroyWindow(PrintStructures->hwndUpDown);
1925 /************************************************************
1927 * PRINTDLG_GetDlgTemplate
1930 static HGLOBAL PRINTDLG_GetDlgTemplateA(const PRINTDLGA *lppd)
1935 if (lppd->Flags & PD_PRINTSETUP) {
1936 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
1937 hDlgTmpl = lppd->hSetupTemplate;
1938 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
1939 hResInfo = FindResourceA(lppd->hInstance,
1940 lppd->lpSetupTemplateName, (LPSTR)RT_DIALOG);
1941 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1943 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32_SETUP",
1945 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1948 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
1949 hDlgTmpl = lppd->hPrintTemplate;
1950 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
1951 hResInfo = FindResourceA(lppd->hInstance,
1952 lppd->lpPrintTemplateName,
1954 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1956 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32",
1958 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1964 static HGLOBAL PRINTDLG_GetDlgTemplateW(const PRINTDLGW *lppd)
1968 static const WCHAR xpsetup[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
1969 static const WCHAR xprint[] = { 'P','R','I','N','T','3','2',0};
1971 if (lppd->Flags & PD_PRINTSETUP) {
1972 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
1973 hDlgTmpl = lppd->hSetupTemplate;
1974 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
1975 hResInfo = FindResourceW(lppd->hInstance,
1976 lppd->lpSetupTemplateName, (LPWSTR)RT_DIALOG);
1977 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1979 hResInfo = FindResourceW(COMDLG32_hInstance, xpsetup, (LPWSTR)RT_DIALOG);
1980 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1983 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
1984 hDlgTmpl = lppd->hPrintTemplate;
1985 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
1986 hResInfo = FindResourceW(lppd->hInstance,
1987 lppd->lpPrintTemplateName,
1989 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1991 hResInfo = FindResourceW(COMDLG32_hInstance, xprint, (LPWSTR)RT_DIALOG);
1992 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1998 /***********************************************************************
2003 static BOOL PRINTDLG_CreateDCA(LPPRINTDLGA lppd)
2005 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
2006 DEVMODEA *pdm = GlobalLock(lppd->hDevMode);
2008 if(lppd->Flags & PD_RETURNDC) {
2009 lppd->hDC = CreateDCA((char*)pdn + pdn->wDriverOffset,
2010 (char*)pdn + pdn->wDeviceOffset,
2011 (char*)pdn + pdn->wOutputOffset,
2013 } else if(lppd->Flags & PD_RETURNIC) {
2014 lppd->hDC = CreateICA((char*)pdn + pdn->wDriverOffset,
2015 (char*)pdn + pdn->wDeviceOffset,
2016 (char*)pdn + pdn->wOutputOffset,
2019 GlobalUnlock(lppd->hDevNames);
2020 GlobalUnlock(lppd->hDevMode);
2021 return lppd->hDC ? TRUE : FALSE;
2024 static BOOL PRINTDLG_CreateDCW(LPPRINTDLGW lppd)
2026 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
2027 DEVMODEW *pdm = GlobalLock(lppd->hDevMode);
2029 if(lppd->Flags & PD_RETURNDC) {
2030 lppd->hDC = CreateDCW((WCHAR*)pdn + pdn->wDriverOffset,
2031 (WCHAR*)pdn + pdn->wDeviceOffset,
2032 (WCHAR*)pdn + pdn->wOutputOffset,
2034 } else if(lppd->Flags & PD_RETURNIC) {
2035 lppd->hDC = CreateICW((WCHAR*)pdn + pdn->wDriverOffset,
2036 (WCHAR*)pdn + pdn->wDeviceOffset,
2037 (WCHAR*)pdn + pdn->wOutputOffset,
2040 GlobalUnlock(lppd->hDevNames);
2041 GlobalUnlock(lppd->hDevMode);
2042 return lppd->hDC ? TRUE : FALSE;
2045 /***********************************************************************
2046 * PrintDlgA (COMDLG32.@)
2048 * Displays the PRINT dialog box, which enables the user to specify
2049 * specific properties of the print job.
2052 * lppd [IO] ptr to PRINTDLG32 struct
2055 * nonzero if the user pressed the OK button
2056 * zero if the user cancelled the window or an error occurred
2060 * * The Collate Icons do not display, even though they are in the code.
2061 * * The Properties Button(s) should call DocumentPropertiesA().
2064 BOOL WINAPI PrintDlgA(LPPRINTDLGA lppd)
2072 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION);
2076 if(TRACE_ON(commdlg)) {
2077 char flagstr[1000] = "";
2078 const struct pd_flags *pflag = pd_flags;
2079 for( ; pflag->name; pflag++) {
2080 if(lppd->Flags & pflag->flag)
2081 strcat(flagstr, pflag->name);
2083 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2084 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2085 "flags %08x (%s)\n",
2086 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2087 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2088 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2091 if(lppd->lStructSize != sizeof(PRINTDLGA)) {
2092 WARN("structure size failure !!!\n");
2093 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2097 if(lppd->Flags & PD_RETURNDEFAULT) {
2098 PRINTER_INFO_2A *pbuf;
2099 DRIVER_INFO_3A *dbuf;
2103 if(lppd->hDevMode || lppd->hDevNames) {
2104 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2105 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2108 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2109 WARN("Can't find default printer\n");
2110 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2114 GetPrinterA(hprn, 2, NULL, 0, &needed);
2115 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
2116 GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2118 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
2119 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
2120 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2121 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2122 GetLastError(),pbuf->pPrinterName);
2123 HeapFree(GetProcessHeap(), 0, dbuf);
2124 HeapFree(GetProcessHeap(), 0, pbuf);
2125 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2130 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2134 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2135 pbuf->pDevMode->dmDriverExtra);
2136 ptr = GlobalLock(lppd->hDevMode);
2137 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2138 pbuf->pDevMode->dmDriverExtra);
2139 GlobalUnlock(lppd->hDevMode);
2140 HeapFree(GetProcessHeap(), 0, pbuf);
2141 HeapFree(GetProcessHeap(), 0, dbuf);
2145 PRINT_PTRA *PrintStructures;
2147 /* load Dialog resources,
2148 * depending on Flags indicates Print32 or Print32_setup dialog
2150 hDlgTmpl = PRINTDLG_GetDlgTemplateA(lppd);
2152 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2155 ptr = LockResource( hDlgTmpl );
2157 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2161 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2162 sizeof(PRINT_PTRA));
2163 PrintStructures->lpPrintDlg = lppd;
2165 /* and create & process the dialog .
2166 * -1 is failure, 0 is broken hwnd, everything else is ok.
2168 hInst = COMDLG32_hInstance;
2169 if (lppd->Flags & (PD_ENABLESETUPTEMPLATE | PD_ENABLEPRINTTEMPLATE)) hInst = lppd->hInstance;
2170 bRet = (0<DialogBoxIndirectParamA(hInst, ptr, lppd->hwndOwner,
2172 (LPARAM)PrintStructures));
2175 DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2176 PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
2177 DRIVER_INFO_3A *di = PrintStructures->lpDriverInfo;
2179 if (lppd->hDevMode == 0) {
2180 TRACE(" No hDevMode yet... Need to create my own\n");
2181 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2182 lpdm->dmSize + lpdm->dmDriverExtra);
2184 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2185 lpdm->dmSize + lpdm->dmDriverExtra,
2188 lpdmReturn = GlobalLock(lppd->hDevMode);
2189 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2191 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2196 GlobalUnlock(lppd->hDevMode);
2198 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2199 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2200 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2201 HeapFree(GetProcessHeap(), 0, PrintStructures);
2203 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2204 bRet = PRINTDLG_CreateDCA(lppd);
2206 TRACE("exit! (%d)\n", bRet);
2210 /***********************************************************************
2211 * PrintDlgW (COMDLG32.@)
2215 BOOL WINAPI PrintDlgW(LPPRINTDLGW lppd)
2223 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION);
2227 if(TRACE_ON(commdlg)) {
2228 char flagstr[1000] = "";
2229 const struct pd_flags *pflag = pd_flags;
2230 for( ; pflag->name; pflag++) {
2231 if(lppd->Flags & pflag->flag)
2232 strcat(flagstr, pflag->name);
2234 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2235 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2236 "flags %08x (%s)\n",
2237 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2238 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2239 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2242 if(lppd->lStructSize != sizeof(PRINTDLGW)) {
2243 WARN("structure size failure !!!\n");
2244 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2248 if(lppd->Flags & PD_RETURNDEFAULT) {
2249 PRINTER_INFO_2W *pbuf;
2250 DRIVER_INFO_3W *dbuf;
2254 if(lppd->hDevMode || lppd->hDevNames) {
2255 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2256 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2259 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2260 WARN("Can't find default printer\n");
2261 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2265 GetPrinterW(hprn, 2, NULL, 0, &needed);
2266 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
2267 GetPrinterW(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2269 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
2270 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
2271 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2272 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2273 GetLastError(),debugstr_w(pbuf->pPrinterName));
2274 HeapFree(GetProcessHeap(), 0, dbuf);
2275 HeapFree(GetProcessHeap(), 0, pbuf);
2276 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2281 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2285 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2286 pbuf->pDevMode->dmDriverExtra);
2287 ptr = GlobalLock(lppd->hDevMode);
2288 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2289 pbuf->pDevMode->dmDriverExtra);
2290 GlobalUnlock(lppd->hDevMode);
2291 HeapFree(GetProcessHeap(), 0, pbuf);
2292 HeapFree(GetProcessHeap(), 0, dbuf);
2296 PRINT_PTRW *PrintStructures;
2298 /* load Dialog resources,
2299 * depending on Flags indicates Print32 or Print32_setup dialog
2301 hDlgTmpl = PRINTDLG_GetDlgTemplateW(lppd);
2303 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2306 ptr = LockResource( hDlgTmpl );
2308 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2312 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2313 sizeof(PRINT_PTRW));
2314 PrintStructures->lpPrintDlg = lppd;
2316 /* and create & process the dialog .
2317 * -1 is failure, 0 is broken hwnd, everything else is ok.
2319 hInst = COMDLG32_hInstance;
2320 if (lppd->Flags & (PD_ENABLESETUPTEMPLATE | PD_ENABLEPRINTTEMPLATE)) hInst = lppd->hInstance;
2321 bRet = (0<DialogBoxIndirectParamW(hInst, ptr, lppd->hwndOwner,
2323 (LPARAM)PrintStructures));
2326 DEVMODEW *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2327 PRINTER_INFO_2W *pi = PrintStructures->lpPrinterInfo;
2328 DRIVER_INFO_3W *di = PrintStructures->lpDriverInfo;
2330 if (lppd->hDevMode == 0) {
2331 TRACE(" No hDevMode yet... Need to create my own\n");
2332 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2333 lpdm->dmSize + lpdm->dmDriverExtra);
2336 if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
2337 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2339 GlobalUnlock(lppd->hDevMode);
2340 TRACE("Now got %d locks\n", locks);
2343 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2344 lpdm->dmSize + lpdm->dmDriverExtra,
2347 lpdmReturn = GlobalLock(lppd->hDevMode);
2348 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2350 if (lppd->hDevNames != 0) {
2352 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
2353 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2355 GlobalUnlock(lppd->hDevNames);
2358 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2363 GlobalUnlock(lppd->hDevMode);
2365 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2366 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2367 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2368 HeapFree(GetProcessHeap(), 0, PrintStructures);
2370 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2371 bRet = PRINTDLG_CreateDCW(lppd);
2373 TRACE("exit! (%d)\n", bRet);
2377 /***********************************************************************
2382 * cmb1 - printer select (not in standard dialog template)
2384 * cmb3 - source (tray?)
2385 * edt4 - border left
2387 * edt6 - border right
2388 * edt7 - border bottom
2389 * psh3 - "Printer..."
2397 LPPAGESETUPDLGA dlga;
2398 LPPAGESETUPDLGW dlgw;
2400 HWND hDlg; /* Page Setup dialog handle */
2401 RECT rtDrawRect; /* Drawing rect for page */
2404 static inline DWORD pagesetup_get_flags(const pagesetup_data *data)
2406 return data->u.dlgw->Flags;
2409 static inline BOOL is_metric(const pagesetup_data *data)
2411 return pagesetup_get_flags(data) & PSD_INHUNDREDTHSOFMILLIMETERS;
2414 static inline LONG tenths_mm_to_size(const pagesetup_data *data, LONG size)
2416 if (is_metric(data))
2419 return 10 * size * 100 / 254;
2422 static inline LONG thousandths_inch_to_size(const pagesetup_data *data, LONG size)
2424 if (is_metric(data))
2425 return size * 254 / 100;
2430 static WCHAR get_decimal_sep(void)
2436 WCHAR buf[] = {'.', 0};
2437 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, buf, sizeof(buf) / sizeof(buf[0]));
2443 static void size2str(const pagesetup_data *data, DWORD size, LPWSTR strout)
2445 WCHAR integer_fmt[] = {'%','d',0};
2446 WCHAR hundredths_fmt[] = {'%','d','%','c','%','0','2','d',0};
2447 WCHAR thousandths_fmt[] = {'%','d','%','c','%','0','3','d',0};
2449 /* FIXME use LOCALE_SDECIMAL when the edit parsing code can cope */
2451 if (is_metric(data))
2454 wsprintfW(strout, hundredths_fmt, size / 100, get_decimal_sep(), size % 100);
2456 wsprintfW(strout, integer_fmt, size / 100);
2461 wsprintfW(strout, thousandths_fmt, size / 1000, get_decimal_sep(), size % 1000);
2463 wsprintfW(strout, integer_fmt, size / 1000);
2468 static inline BOOL is_default_metric(void)
2471 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IMEASURE | LOCALE_RETURN_NUMBER,
2472 (LPWSTR)&system, sizeof(system));
2476 /**********************************************
2478 * Cyclically permute the four members of rc
2479 * If sense is TRUE l -> t -> r -> b
2480 * otherwise l <- t <- r <- b
2482 static inline void rotate_rect(RECT *rc, BOOL sense)
2488 rc->bottom = rc->right;
2489 rc->right = rc->top;
2497 rc->top = rc->right;
2498 rc->right = rc->bottom;
2503 static void pagesetup_set_orientation(pagesetup_data *data, WORD orient)
2505 DEVMODEW *dm = GlobalLock(data->u.dlgw->hDevMode);
2507 assert(orient == DMORIENT_PORTRAIT || orient == DMORIENT_LANDSCAPE);
2510 dm->u1.s1.dmOrientation = orient;
2513 DEVMODEA *dmA = (DEVMODEA *)dm;
2514 dmA->u1.s1.dmOrientation = orient;
2516 GlobalUnlock(data->u.dlgw->hDevMode);
2519 static WORD pagesetup_get_orientation(const pagesetup_data *data)
2521 DEVMODEW *dm = GlobalLock(data->u.dlgw->hDevMode);
2525 orient = dm->u1.s1.dmOrientation;
2528 DEVMODEA *dmA = (DEVMODEA *)dm;
2529 orient = dmA->u1.s1.dmOrientation;
2531 GlobalUnlock(data->u.dlgw->hDevMode);
2535 static void pagesetup_set_papersize(pagesetup_data *data, WORD paper)
2537 DEVMODEW *dm = GlobalLock(data->u.dlgw->hDevMode);
2540 dm->u1.s1.dmPaperSize = paper;
2543 DEVMODEA *dmA = (DEVMODEA *)dm;
2544 dmA->u1.s1.dmPaperSize = paper;
2546 GlobalUnlock(data->u.dlgw->hDevMode);
2549 static WORD pagesetup_get_papersize(const pagesetup_data *data)
2551 DEVMODEW *dm = GlobalLock(data->u.dlgw->hDevMode);
2555 paper = dm->u1.s1.dmPaperSize;
2558 DEVMODEA *dmA = (DEVMODEA *)dm;
2559 paper = dmA->u1.s1.dmPaperSize;
2561 GlobalUnlock(data->u.dlgw->hDevMode);
2565 static void pagesetup_set_defaultsource(pagesetup_data *data, WORD source)
2567 DEVMODEW *dm = GlobalLock(data->u.dlgw->hDevMode);
2570 dm->u1.s1.dmDefaultSource = source;
2573 DEVMODEA *dmA = (DEVMODEA *)dm;
2574 dmA->u1.s1.dmDefaultSource = source;
2576 GlobalUnlock(data->u.dlgw->hDevMode);
2581 devnames_driver_name,
2582 devnames_device_name,
2583 devnames_output_name
2587 static inline WORD get_devname_offset(const DEVNAMES *dn, devnames_name which)
2591 case devnames_driver_name: return dn->wDriverOffset;
2592 case devnames_device_name: return dn->wDeviceOffset;
2593 case devnames_output_name: return dn->wOutputOffset;
2595 ERR("Shouldn't be here\n");
2599 static WCHAR *pagesetup_get_a_devname(const pagesetup_data *data, devnames_name which)
2604 dn = GlobalLock(data->u.dlgw->hDevNames);
2606 name = strdupW((WCHAR *)dn + get_devname_offset(dn, which));
2609 int len = MultiByteToWideChar(CP_ACP, 0, (char*)dn + get_devname_offset(dn, which), -1, NULL, 0);
2610 name = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
2611 MultiByteToWideChar(CP_ACP, 0, (char*)dn + get_devname_offset(dn, which), -1, name, len);
2613 GlobalUnlock(data->u.dlgw->hDevNames);
2617 static WCHAR *pagesetup_get_drvname(const pagesetup_data *data)
2619 return pagesetup_get_a_devname(data, devnames_driver_name);
2622 static WCHAR *pagesetup_get_devname(const pagesetup_data *data)
2624 return pagesetup_get_a_devname(data, devnames_device_name);
2627 static WCHAR *pagesetup_get_portname(const pagesetup_data *data)
2629 return pagesetup_get_a_devname(data, devnames_output_name);
2632 static void pagesetup_release_a_devname(const pagesetup_data *data, WCHAR *name)
2634 HeapFree(GetProcessHeap(), 0, name);
2637 static void pagesetup_set_devnames(pagesetup_data *data, LPCWSTR drv, LPCWSTR devname, LPCWSTR port)
2641 DWORD len = sizeof(DEVNAMES), drv_len, dev_len, port_len;
2645 drv_len = (strlenW(drv) + 1) * sizeof(WCHAR);
2646 dev_len = (strlenW(devname) + 1) * sizeof(WCHAR);
2647 port_len = (strlenW(port) + 1) * sizeof(WCHAR);
2651 drv_len = WideCharToMultiByte(CP_ACP, 0, drv, -1, NULL, 0, NULL, NULL);
2652 dev_len = WideCharToMultiByte(CP_ACP, 0, devname, -1, NULL, 0, NULL, NULL);
2653 port_len = WideCharToMultiByte(CP_ACP, 0, port, -1, NULL, 0, NULL, NULL);
2655 len += drv_len + dev_len + port_len;
2657 if(data->u.dlgw->hDevNames)
2658 data->u.dlgw->hDevNames = GlobalReAlloc(data->u.dlgw->hDevNames, len, GMEM_MOVEABLE);
2660 data->u.dlgw->hDevNames = GlobalAlloc(GMEM_MOVEABLE, len);
2662 dn = GlobalLock(data->u.dlgw->hDevNames);
2666 WCHAR *ptr = (WCHAR *)(dn + 1);
2667 len = sizeof(DEVNAMES) / sizeof(WCHAR);
2668 dn->wDriverOffset = len;
2670 ptr += drv_len / sizeof(WCHAR);
2671 len += drv_len / sizeof(WCHAR);
2672 dn->wDeviceOffset = len;
2673 strcpyW(ptr, devname);
2674 ptr += dev_len / sizeof(WCHAR);
2675 len += dev_len / sizeof(WCHAR);
2676 dn->wOutputOffset = len;
2681 char *ptr = (char *)(dn + 1);
2682 len = sizeof(DEVNAMES);
2683 dn->wDriverOffset = len;
2684 WideCharToMultiByte(CP_ACP, 0, drv, -1, ptr, drv_len, NULL, NULL);
2687 dn->wDeviceOffset = len;
2688 WideCharToMultiByte(CP_ACP, 0, devname, -1, ptr, dev_len, NULL, NULL);
2691 dn->wOutputOffset = len;
2692 WideCharToMultiByte(CP_ACP, 0, port, -1, ptr, port_len, NULL, NULL);
2696 len = sizeof(def) / sizeof(def[0]);
2697 GetDefaultPrinterW(def, &len);
2698 if(!lstrcmpW(def, devname))
2701 GlobalUnlock(data->u.dlgw->hDevNames);
2704 static DEVMODEW *pagesetup_get_devmode(const pagesetup_data *data)
2706 DEVMODEW *dm = GlobalLock(data->u.dlgw->hDevMode);
2711 /* We make a copy even in the unicode case because the ptr
2712 may get passed back to us in pagesetup_set_devmode. */
2713 ret = HeapAlloc(GetProcessHeap(), 0, dm->dmSize + dm->dmDriverExtra);
2714 memcpy(ret, dm, dm->dmSize + dm->dmDriverExtra);
2717 ret = GdiConvertToDevmodeW((DEVMODEA *)dm);
2719 GlobalUnlock(data->u.dlgw->hDevMode);
2723 static void pagesetup_release_devmode(const pagesetup_data *data, DEVMODEW *dm)
2725 HeapFree(GetProcessHeap(), 0, dm);
2728 static void pagesetup_set_devmode(pagesetup_data *data, DEVMODEW *dm)
2730 DEVMODEA *dmA = NULL;
2736 size = dm->dmSize + dm->dmDriverExtra;
2741 dmA = convert_to_devmodeA(dm);
2742 size = dmA->dmSize + dmA->dmDriverExtra;
2746 if(data->u.dlgw->hDevMode)
2747 data->u.dlgw->hDevMode = GlobalReAlloc(data->u.dlgw->hDevMode, size,
2750 data->u.dlgw->hDevMode = GlobalAlloc(GMEM_MOVEABLE, size);
2752 dst = GlobalLock(data->u.dlgw->hDevMode);
2753 memcpy(dst, src, size);
2754 GlobalUnlock(data->u.dlgw->hDevMode);
2755 HeapFree(GetProcessHeap(), 0, dmA);
2758 static inline POINT *pagesetup_get_papersize_pt(const pagesetup_data *data)
2760 return &data->u.dlgw->ptPaperSize;
2763 static inline RECT *pagesetup_get_margin_rect(const pagesetup_data *data)
2765 return &data->u.dlgw->rtMargin;
2774 static inline LPPAGESETUPHOOK pagesetup_get_hook(const pagesetup_data *data, hook_type which)
2778 case page_setup_hook: return data->u.dlgw->lpfnPageSetupHook;
2779 case page_paint_hook: return data->u.dlgw->lpfnPagePaintHook;
2784 /* This should only be used in calls to hook procs so we return the ptr
2785 already cast to LPARAM */
2786 static inline LPARAM pagesetup_get_dlg_struct(const pagesetup_data *data)
2788 return (LPARAM)data->u.dlgw;
2791 static inline void swap_point(POINT *pt)
2798 static BOOL pagesetup_update_papersize(pagesetup_data *data)
2801 LPWSTR devname, portname;
2803 WORD *words = NULL, paperword;
2804 POINT *points = NULL;
2805 BOOL retval = FALSE;
2807 dm = pagesetup_get_devmode(data);
2808 devname = pagesetup_get_devname(data);
2809 portname = pagesetup_get_portname(data);
2811 num = DeviceCapabilitiesW(devname, portname, DC_PAPERS, NULL, dm);
2814 FIXME("No papernames found for %s/%s\n", debugstr_w(devname), debugstr_w(portname));
2818 words = HeapAlloc(GetProcessHeap(), 0, num * sizeof(WORD));
2819 points = HeapAlloc(GetProcessHeap(), 0, num * sizeof(POINT));
2821 if (num != DeviceCapabilitiesW(devname, portname, DC_PAPERS, (LPWSTR)words, dm))
2823 FIXME("Number of returned words is not %d\n", num);
2827 if (num != DeviceCapabilitiesW(devname, portname, DC_PAPERSIZE, (LPWSTR)points, dm))
2829 FIXME("Number of returned sizes is not %d\n", num);
2833 paperword = pagesetup_get_papersize(data);
2835 for (i = 0; i < num; i++)
2836 if (words[i] == paperword)
2841 FIXME("Papersize %d not found in list?\n", paperword);
2845 /* this is _10ths_ of a millimeter */
2846 pagesetup_get_papersize_pt(data)->x = tenths_mm_to_size(data, points[i].x);
2847 pagesetup_get_papersize_pt(data)->y = tenths_mm_to_size(data, points[i].y);
2849 if(pagesetup_get_orientation(data) == DMORIENT_LANDSCAPE)
2850 swap_point(pagesetup_get_papersize_pt(data));
2855 HeapFree(GetProcessHeap(), 0, words);
2856 HeapFree(GetProcessHeap(), 0, points);
2857 pagesetup_release_a_devname(data, portname);
2858 pagesetup_release_a_devname(data, devname);
2859 pagesetup_release_devmode(data, dm);
2864 /**********************************************************************************************
2865 * pagesetup_change_printer
2867 * Redefines hDevMode and hDevNames HANDLES and initialises it.
2870 static BOOL pagesetup_change_printer(LPWSTR name, pagesetup_data *data)
2874 PRINTER_INFO_2W *prn_info = NULL;
2875 DRIVER_INFO_3W *drv_info = NULL;
2876 DEVMODEW *dm = NULL;
2877 BOOL retval = FALSE;
2879 if(!OpenPrinterW(name, &hprn, NULL))
2881 ERR("Can't open printer %s\n", debugstr_w(name));
2885 GetPrinterW(hprn, 2, NULL, 0, &needed);
2886 prn_info = HeapAlloc(GetProcessHeap(), 0, needed);
2887 GetPrinterW(hprn, 2, (LPBYTE)prn_info, needed, &needed);
2888 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
2889 drv_info = HeapAlloc(GetProcessHeap(), 0, needed);
2890 if(!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)drv_info, needed, &needed))
2892 ERR("GetPrinterDriverA failed for %s, fix your config!\n", debugstr_w(prn_info->pPrinterName));
2897 needed = DocumentPropertiesW(0, 0, name, NULL, NULL, 0);
2900 ERR("DocumentProperties fails on %s\n", debugstr_w(name));
2904 dm = HeapAlloc(GetProcessHeap(), 0, needed);
2905 DocumentPropertiesW(0, 0, name, dm, NULL, DM_OUT_BUFFER);
2907 pagesetup_set_devmode(data, dm);
2908 pagesetup_set_devnames(data, drv_info->pDriverPath, prn_info->pPrinterName,
2909 prn_info->pPortName);
2913 HeapFree(GetProcessHeap(), 0, dm);
2914 HeapFree(GetProcessHeap(), 0, prn_info);
2915 HeapFree(GetProcessHeap(), 0, drv_info);
2919 /****************************************************************************************
2920 * pagesetup_init_combos
2922 * Fills Printers, Paper and Source combos
2925 static void pagesetup_init_combos(HWND hDlg, pagesetup_data *data)
2928 LPWSTR devname, portname;
2930 dm = pagesetup_get_devmode(data);
2931 devname = pagesetup_get_devname(data);
2932 portname = pagesetup_get_portname(data);
2934 PRINTDLG_SetUpPrinterListComboW(hDlg, cmb1, devname);
2935 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb2, devname, portname, dm);
2936 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb3, devname, portname, dm);
2938 pagesetup_release_a_devname(data, portname);
2939 pagesetup_release_a_devname(data, devname);
2940 pagesetup_release_devmode(data, dm);
2944 /****************************************************************************************
2945 * pagesetup_change_printer_dialog
2947 * Pops up another dialog that lets the user pick another printer.
2949 * For now we display the PrintDlg, this should display a striped down version of it.
2951 static void pagesetup_change_printer_dialog(HWND hDlg, pagesetup_data *data)
2954 LPWSTR drvname, devname, portname;
2955 DEVMODEW *tmp_dm, *dm;
2957 memset(&prnt, 0, sizeof(prnt));
2958 prnt.lStructSize = sizeof(prnt);
2960 prnt.hwndOwner = hDlg;
2962 drvname = pagesetup_get_drvname(data);
2963 devname = pagesetup_get_devname(data);
2964 portname = pagesetup_get_portname(data);
2966 PRINTDLG_CreateDevNamesW(&prnt.hDevNames, drvname, devname, portname);
2967 pagesetup_release_a_devname(data, portname);
2968 pagesetup_release_a_devname(data, devname);
2969 pagesetup_release_a_devname(data, drvname);
2971 tmp_dm = pagesetup_get_devmode(data);
2972 prnt.hDevMode = GlobalAlloc(GMEM_MOVEABLE, tmp_dm->dmSize + tmp_dm->dmDriverExtra);
2973 dm = GlobalLock(prnt.hDevMode);
2974 memcpy(dm, tmp_dm, tmp_dm->dmSize + tmp_dm->dmDriverExtra);
2975 GlobalUnlock(prnt.hDevMode);
2976 pagesetup_release_devmode(data, tmp_dm);
2978 if (PrintDlgW(&prnt))
2980 DEVMODEW *dm = GlobalLock(prnt.hDevMode);
2981 DEVNAMES *dn = GlobalLock(prnt.hDevNames);
2983 pagesetup_set_devnames(data, (WCHAR*)dn + dn->wDriverOffset,
2984 (WCHAR*)dn + dn->wDeviceOffset, (WCHAR *)dn + dn->wOutputOffset);
2985 pagesetup_set_devmode(data, dm);
2986 GlobalUnlock(prnt.hDevNames);
2987 GlobalUnlock(prnt.hDevMode);
2988 pagesetup_init_combos(hDlg, data);
2991 GlobalFree(prnt.hDevMode);
2992 GlobalFree(prnt.hDevNames);
2996 /******************************************************************************************
2997 * pagesetup_change_preview
2999 * Changes paper preview size / position
3002 static void pagesetup_change_preview(const pagesetup_data *data)
3004 LONG width, height, x, y;
3006 const int shadow = 4;
3008 if(pagesetup_get_orientation(data) == DMORIENT_LANDSCAPE)
3010 width = data->rtDrawRect.right - data->rtDrawRect.left;
3011 height = pagesetup_get_papersize_pt(data)->y * width / pagesetup_get_papersize_pt(data)->x;
3015 height = data->rtDrawRect.bottom - data->rtDrawRect.top;
3016 width = pagesetup_get_papersize_pt(data)->x * height / pagesetup_get_papersize_pt(data)->y;
3018 x = (data->rtDrawRect.right + data->rtDrawRect.left - width) / 2;
3019 y = (data->rtDrawRect.bottom + data->rtDrawRect.top - height) / 2;
3020 TRACE("draw rect %s x=%d, y=%d, w=%d, h=%d\n",
3021 wine_dbgstr_rect(&data->rtDrawRect), x, y, width, height);
3023 MoveWindow(GetDlgItem(data->hDlg, rct2), x + width, y + shadow, shadow, height, FALSE);
3024 MoveWindow(GetDlgItem(data->hDlg, rct3), x + shadow, y + height, width, shadow, FALSE);
3025 MoveWindow(GetDlgItem(data->hDlg, rct1), x, y, width, height, FALSE);
3027 tmp = data->rtDrawRect;
3028 tmp.right += shadow;
3029 tmp.bottom += shadow;
3030 InvalidateRect(data->hDlg, &tmp, TRUE);
3033 static inline LONG *element_from_margin_id(RECT *rc, WORD id)
3037 case edt4: return &rc->left;
3038 case edt5: return &rc->top;
3039 case edt6: return &rc->right;
3040 case edt7: return &rc->bottom;
3045 static void update_margin_edits(HWND hDlg, const pagesetup_data *data, WORD id)
3050 for(idx = edt4; idx <= edt7; idx++)
3052 if(id == 0 || id == idx)
3054 size2str(data, *element_from_margin_id(pagesetup_get_margin_rect(data), idx), str);
3055 SetDlgItemTextW(hDlg, idx, str);
3060 static void margin_edit_notification(HWND hDlg, const pagesetup_data *data, WORD msg, WORD id)
3068 LONG *value = element_from_margin_id(pagesetup_get_margin_rect(data), id);
3070 if (GetDlgItemTextW(hDlg, id, buf, sizeof(buf) / sizeof(buf[0])) != 0)
3073 WCHAR decimal = get_decimal_sep();
3075 val = strtolW(buf, &end, 10);
3076 if(end != buf || *end == decimal)
3078 int mult = is_metric(data) ? 100 : 1000;
3087 val += (*end - '0') * mult;
3099 update_margin_edits(hDlg, data, id);
3104 static void set_margin_groupbox_title(HWND hDlg, const pagesetup_data *data)
3108 if(LoadStringW(COMDLG32_hInstance, is_metric(data) ? PD32_MARGINS_IN_MILLIMETERS : PD32_MARGINS_IN_INCHES,
3109 title, sizeof(title)/sizeof(title[0])))
3110 SetDlgItemTextW(hDlg, grp4, title);
3113 static void pagesetup_update_orientation_buttons(HWND hDlg, const pagesetup_data *data)
3115 if (pagesetup_get_orientation(data) == DMORIENT_LANDSCAPE)
3116 CheckRadioButton(hDlg, rad1, rad2, rad2);
3118 CheckRadioButton(hDlg, rad1, rad2, rad1);
3121 /****************************************************************************************
3122 * pagesetup_printer_properties
3124 * Handle invocation of the 'Properties' button (not present in the default template).
3126 static void pagesetup_printer_properties(HWND hDlg, pagesetup_data *data)
3134 devname = pagesetup_get_devname(data);
3136 if (!OpenPrinterW(devname, &hprn, NULL))
3138 FIXME("Call to OpenPrinter did not succeed!\n");
3139 pagesetup_release_a_devname(data, devname);
3143 dm = pagesetup_get_devmode(data);
3144 DocumentPropertiesW(hDlg, hprn, devname, dm, dm, DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
3145 pagesetup_set_devmode(data, dm);
3146 pagesetup_release_devmode(data, dm);
3147 pagesetup_release_a_devname(data, devname);
3150 /* Changing paper */
3151 pagesetup_update_papersize(data);
3152 pagesetup_update_orientation_buttons(hDlg, data);
3154 /* Changing paper preview */
3155 pagesetup_change_preview(data);
3157 /* Selecting paper in combo */
3158 count = SendDlgItemMessageW(hDlg, cmb2, CB_GETCOUNT, 0, 0);
3161 WORD paperword = pagesetup_get_papersize(data);
3162 for(i = 0; i < count; i++)
3164 if(SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, i, 0) == paperword) {
3165 SendDlgItemMessageW(hDlg, cmb2, CB_SETCURSEL, i, 0);
3172 /********************************************************************************
3173 * pagesetup_wm_command
3174 * process WM_COMMAND message for PageSetupDlg
3177 * hDlg [in] Main dialog HANDLE
3178 * wParam [in] WM_COMMAND wParam
3179 * lParam [in] WM_COMMAND lParam
3180 * pda [in/out] ptr to PageSetupDataA
3183 static BOOL pagesetup_wm_command(HWND hDlg, WPARAM wParam, LPARAM lParam, pagesetup_data *data)
3185 WORD msg = HIWORD(wParam);
3186 WORD id = LOWORD(wParam);
3188 TRACE("loword (lparam) %d, wparam 0x%lx, lparam %08lx\n",
3189 LOWORD(lParam),wParam,lParam);
3192 EndDialog(hDlg, TRUE);
3196 EndDialog(hDlg, FALSE);
3199 case psh3: /* Printer... */
3200 pagesetup_change_printer_dialog(hDlg, data);
3203 case rad1: /* Portrait */
3204 case rad2: /* Landscape */
3205 if((id == rad1 && pagesetup_get_orientation(data) == DMORIENT_LANDSCAPE) ||
3206 (id == rad2 && pagesetup_get_orientation(data) == DMORIENT_PORTRAIT))
3208 pagesetup_set_orientation(data, (id == rad1) ? DMORIENT_PORTRAIT : DMORIENT_LANDSCAPE);
3209 pagesetup_update_papersize(data);
3210 rotate_rect(pagesetup_get_margin_rect(data), (id == rad2));
3211 update_margin_edits(hDlg, data, 0);
3212 pagesetup_change_preview(data);
3215 case cmb1: /* Printer combo */
3216 if(msg == CBN_SELCHANGE)
3219 GetDlgItemTextW(hDlg, id, name, sizeof(name) / sizeof(name[0]));
3220 pagesetup_change_printer(name, data);
3221 pagesetup_init_combos(hDlg, data);
3224 case cmb2: /* Paper combo */
3225 if(msg == CBN_SELCHANGE)
3227 DWORD paperword = SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA,
3228 SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0), 0);
3229 if (paperword != CB_ERR)
3231 pagesetup_set_papersize(data, paperword);
3232 pagesetup_update_papersize(data);
3233 pagesetup_change_preview(data);
3235 FIXME("could not get dialog text for papersize cmbbox?\n");
3238 case cmb3: /* Paper Source */
3239 if(msg == CBN_SELCHANGE)
3241 WORD source = SendDlgItemMessageW(hDlg, cmb3, CB_GETITEMDATA,
3242 SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0), 0);
3243 pagesetup_set_defaultsource(data, source);
3246 case psh2: /* Printer Properties button */
3247 pagesetup_printer_properties(hDlg, data);
3253 margin_edit_notification(hDlg, data, msg, id);
3256 InvalidateRect(GetDlgItem(hDlg, rct1), NULL, TRUE);
3260 /***********************************************************************
3261 * default_page_paint_hook
3262 * Default hook paint procedure that receives WM_PSD_* messages from the dialog box
3263 * whenever the sample page is redrawn.
3265 static UINT_PTR default_page_paint_hook(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam,
3266 const pagesetup_data *data)
3268 LPRECT lprc = (LPRECT) lParam;
3269 HDC hdc = (HDC) wParam;
3272 HFONT hfont, holdfont;
3274 TRACE("uMsg: WM_USER+%d\n",uMsg-WM_USER);
3275 /* Call user paint hook if enable */
3276 if (pagesetup_get_flags(data) & PSD_ENABLEPAGEPAINTHOOK)
3277 if (pagesetup_get_hook(data, page_paint_hook)(hwndDlg, uMsg, wParam, lParam))
3281 /* LPPAGESETUPDLG in lParam */
3282 case WM_PSD_PAGESETUPDLG:
3283 /* Inform about the sample page rectangle */
3284 case WM_PSD_FULLPAGERECT:
3285 /* Inform about the margin rectangle */
3286 case WM_PSD_MINMARGINRECT:
3289 /* Draw dashed rectangle showing margins */
3290 case WM_PSD_MARGINRECT:
3291 hpen = CreatePen(PS_DASH, 1, GetSysColor(COLOR_3DSHADOW));
3292 holdpen = SelectObject(hdc, hpen);
3293 Rectangle(hdc, lprc->left, lprc->top, lprc->right, lprc->bottom);
3294 DeleteObject(SelectObject(hdc, holdpen));
3296 /* Draw the fake document */
3297 case WM_PSD_GREEKTEXTRECT:
3298 /* select a nice scalable font, because we want the text really small */
3299 SystemParametersInfoW(SPI_GETICONTITLELOGFONT, sizeof(lf), &lf, 0);
3300 lf.lfHeight = 6; /* value chosen based on visual effect */
3301 hfont = CreateFontIndirectW(&lf);
3302 holdfont = SelectObject(hdc, hfont);
3304 /* if text not loaded, then do so now */
3305 if (wszFakeDocumentText[0] == '\0')
3306 LoadStringW(COMDLG32_hInstance,
3308 wszFakeDocumentText,
3309 sizeof(wszFakeDocumentText)/sizeof(wszFakeDocumentText[0]));
3311 oldbkmode = SetBkMode(hdc, TRANSPARENT);
3312 DrawTextW(hdc, wszFakeDocumentText, -1, lprc, DT_TOP|DT_LEFT|DT_NOPREFIX|DT_WORDBREAK);
3313 SetBkMode(hdc, oldbkmode);
3315 DeleteObject(SelectObject(hdc, holdfont));
3318 /* Envelope stamp */
3319 case WM_PSD_ENVSTAMPRECT:
3320 /* Return address */
3321 case WM_PSD_YAFULLPAGERECT:
3322 FIXME("envelope/stamp is not implemented\n");
3325 FIXME("Unknown message %x\n",uMsg);
3331 /***********************************************************************
3333 * The main paint procedure for the PageSetupDlg function.
3334 * The Page Setup dialog box includes an image of a sample page that shows how
3335 * the user's selections affect the appearance of the printed output.
3336 * The image consists of a rectangle that represents the selected paper
3337 * or envelope type, with a dotted-line rectangle representing
3338 * the current margins, and partial (Greek text) characters
3339 * to show how text looks on the printed page.
3341 * The following messages in the order sends to user hook procedure:
3342 * WM_PSD_PAGESETUPDLG Draw the contents of the sample page
3343 * WM_PSD_FULLPAGERECT Inform about the bounding rectangle
3344 * WM_PSD_MINMARGINRECT Inform about the margin rectangle (min margin?)
3345 * WM_PSD_MARGINRECT Draw the margin rectangle
3346 * WM_PSD_GREEKTEXTRECT Draw the Greek text inside the margin rectangle
3347 * If any of first three messages returns TRUE, painting done.
3350 * hWnd [in] Handle to the Page Setup dialog box
3351 * uMsg [in] Received message
3354 * WM_PSD_ENVSTAMPRECT Draw in the envelope-stamp rectangle (for envelopes only)
3355 * WM_PSD_YAFULLPAGERECT Draw the return address portion (for envelopes and other paper sizes)
3358 * FALSE if all done correctly
3363 static LRESULT CALLBACK
3364 PRINTDLG_PagePaintProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3367 RECT rcClient, rcMargin;
3370 HBRUSH hbrush, holdbrush;
3371 pagesetup_data *data;
3372 int papersize=0, orientation=0; /* FIXME: set these values for the user paint hook */
3373 double scalx, scaly;
3375 if (uMsg != WM_PAINT)
3376 return CallWindowProcA(lpfnStaticWndProc, hWnd, uMsg, wParam, lParam);
3378 /* Processing WM_PAINT message */
3379 data = GetPropW(hWnd, pagesetupdlg_prop);
3381 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3384 if (default_page_paint_hook(hWnd, WM_PSD_PAGESETUPDLG, MAKELONG(papersize, orientation),
3385 pagesetup_get_dlg_struct(data), data))
3388 hdc = BeginPaint(hWnd, &ps);
3389 GetClientRect(hWnd, &rcClient);
3391 scalx = rcClient.right / (double)pagesetup_get_papersize_pt(data)->x;
3392 scaly = rcClient.bottom / (double)pagesetup_get_papersize_pt(data)->y;
3393 rcMargin = rcClient;
3395 rcMargin.left += pagesetup_get_margin_rect(data)->left * scalx;
3396 rcMargin.top += pagesetup_get_margin_rect(data)->top * scaly;
3397 rcMargin.right -= pagesetup_get_margin_rect(data)->right * scalx;
3398 rcMargin.bottom -= pagesetup_get_margin_rect(data)->bottom * scaly;
3400 /* if the space is too small then we make sure to not draw anything */
3401 rcMargin.left = min(rcMargin.left, rcMargin.right);
3402 rcMargin.top = min(rcMargin.top, rcMargin.bottom);
3404 if (!default_page_paint_hook(hWnd, WM_PSD_FULLPAGERECT, (WPARAM)hdc, (LPARAM)&rcClient, data) &&
3405 !default_page_paint_hook(hWnd, WM_PSD_MINMARGINRECT, (WPARAM)hdc, (LPARAM)&rcMargin, data) )
3407 /* fill background */
3408 hbrush = GetSysColorBrush(COLOR_3DHIGHLIGHT);
3409 FillRect(hdc, &rcClient, hbrush);
3410 holdbrush = SelectObject(hdc, hbrush);
3412 hpen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW));
3413 holdpen = SelectObject(hdc, hpen);
3415 /* paint left edge */
3416 MoveToEx(hdc, rcClient.left, rcClient.top, NULL);
3417 LineTo(hdc, rcClient.left, rcClient.bottom-1);
3419 /* paint top edge */
3420 MoveToEx(hdc, rcClient.left, rcClient.top, NULL);
3421 LineTo(hdc, rcClient.right, rcClient.top);
3423 hpen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DDKSHADOW));
3424 DeleteObject(SelectObject(hdc, hpen));
3426 /* paint right edge */
3427 MoveToEx(hdc, rcClient.right-1, rcClient.top, NULL);
3428 LineTo(hdc, rcClient.right-1, rcClient.bottom);
3430 /* paint bottom edge */
3431 MoveToEx(hdc, rcClient.left, rcClient.bottom-1, NULL);
3432 LineTo(hdc, rcClient.right, rcClient.bottom-1);
3434 DeleteObject(SelectObject(hdc, holdpen));
3435 DeleteObject(SelectObject(hdc, holdbrush));
3437 default_page_paint_hook(hWnd, WM_PSD_MARGINRECT, (WPARAM)hdc, (LPARAM)&rcMargin, data);
3439 /* give text a bit of a space from the frame */
3442 rcMargin.right -= 2;
3443 rcMargin.bottom -= 2;
3445 /* if the space is too small then we make sure to not draw anything */
3446 rcMargin.left = min(rcMargin.left, rcMargin.right);
3447 rcMargin.top = min(rcMargin.top, rcMargin.bottom);
3449 default_page_paint_hook(hWnd, WM_PSD_GREEKTEXTRECT, (WPARAM)hdc, (LPARAM)&rcMargin, data);
3452 EndPaint(hWnd, &ps);
3456 /*******************************************************
3457 * The margin edit controls are subclassed to filter
3458 * anything other than numbers and the decimal separator.
3460 static LRESULT CALLBACK pagesetup_margin_editproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3464 WCHAR decimal = get_decimal_sep();
3465 WCHAR wc = (WCHAR)wparam;
3466 if(!isdigitW(wc) && wc != decimal && wc != VK_BACK) return 0;
3468 return CallWindowProcW(edit_wndproc, hwnd, msg, wparam, lparam);
3471 static void subclass_margin_edits(HWND hDlg)
3476 for(id = edt4; id <= edt7; id++)
3478 old_proc = (WNDPROC)SetWindowLongPtrW(GetDlgItem(hDlg, id),
3480 (ULONG_PTR)pagesetup_margin_editproc);
3481 InterlockedCompareExchangePointer((void**)&edit_wndproc, old_proc, NULL);
3485 /***********************************************************************
3486 * pagesetup_dlg_proc
3488 * Message handler for PageSetupDlg
3490 static INT_PTR CALLBACK pagesetup_dlg_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
3492 pagesetup_data *data;
3493 INT_PTR res = FALSE;
3496 if (uMsg == WM_INITDIALOG) { /*Init dialog*/
3497 data = (pagesetup_data *)lParam;
3500 hDrawWnd = GetDlgItem(hDlg, rct1);
3501 TRACE("set property to %p\n", data);
3502 SetPropW(hDlg, pagesetupdlg_prop, data);
3503 SetPropW(hDrawWnd, pagesetupdlg_prop, data);
3504 GetWindowRect(hDrawWnd, &data->rtDrawRect); /* Calculating rect in client coordinates where paper draws */
3505 MapWindowPoints( 0, hDlg, (LPPOINT)&data->rtDrawRect, 2 );
3506 lpfnStaticWndProc = (WNDPROC)SetWindowLongPtrW(
3509 (ULONG_PTR)PRINTDLG_PagePaintProc);
3511 /* FIXME: Paint hook. Must it be at begin of initialization or at end? */
3513 if (pagesetup_get_flags(data) & PSD_ENABLEPAGESETUPHOOK)
3515 if (!pagesetup_get_hook(data, page_setup_hook)(hDlg, uMsg, wParam,
3516 pagesetup_get_dlg_struct(data)))
3517 FIXME("Setup page hook failed?\n");
3520 /* if printer button disabled */
3521 if (pagesetup_get_flags(data) & PSD_DISABLEPRINTER)
3522 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
3523 /* if margin edit boxes disabled */
3524 if (pagesetup_get_flags(data) & PSD_DISABLEMARGINS)
3526 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
3527 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
3528 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
3529 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
3532 /* Set orientation radiobuttons properly */
3533 pagesetup_update_orientation_buttons(hDlg, data);
3535 /* if orientation disabled */
3536 if (pagesetup_get_flags(data) & PSD_DISABLEORIENTATION)
3538 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
3539 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
3542 /* We fill them out enabled or not */
3543 if (!(pagesetup_get_flags(data) & PSD_MARGINS))
3545 /* default is 1 inch */
3546 LONG size = thousandths_inch_to_size(data, 1000);
3547 SetRect(pagesetup_get_margin_rect(data), size, size, size, size);
3549 update_margin_edits(hDlg, data, 0);
3550 subclass_margin_edits(hDlg);
3551 set_margin_groupbox_title(hDlg, data);
3553 /* if paper disabled */
3554 if (pagesetup_get_flags(data) & PSD_DISABLEPAPER)
3556 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
3557 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
3560 /* filling combos: printer, paper, source. selecting current printer (from DEVMODEA) */
3561 pagesetup_init_combos(hDlg, data);
3562 pagesetup_update_papersize(data);
3563 pagesetup_set_defaultsource(data, DMBIN_FORMSOURCE); /* FIXME: This is the auto select bin. Is this correct? */
3565 /* Drawing paper prev */
3566 pagesetup_change_preview(data);
3569 data = GetPropW(hDlg, pagesetupdlg_prop);
3572 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3575 if (pagesetup_get_flags(data) & PSD_ENABLEPAGESETUPHOOK)
3577 res = pagesetup_get_hook(data, page_setup_hook)(hDlg, uMsg, wParam, lParam);
3578 if (res) return res;
3583 return pagesetup_wm_command(hDlg, wParam, lParam, data);
3588 static WCHAR *get_default_printer(void)
3593 GetDefaultPrinterW(NULL, &len);
3596 name = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3597 GetDefaultPrinterW(name, &len);
3602 static void pagesetup_dump_dlg_struct(const pagesetup_data *data)
3604 if(TRACE_ON(commdlg))
3606 char flagstr[1000] = "";
3607 const struct pd_flags *pflag = psd_flags;
3608 for( ; pflag->name; pflag++)
3610 if(pagesetup_get_flags(data) & pflag->flag)
3612 strcat(flagstr, pflag->name);
3613 strcat(flagstr, "|");
3616 TRACE("%s: (%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3617 "hinst %p, flags %08x (%s)\n",
3618 data->unicode ? "unicode" : "ansi",
3619 data->u.dlgw, data->u.dlgw->hwndOwner, data->u.dlgw->hDevMode,
3620 data->u.dlgw->hDevNames, data->u.dlgw->hInstance,
3621 pagesetup_get_flags(data), flagstr);
3625 static void *pagesetup_get_template(pagesetup_data *data)
3628 HGLOBAL tmpl_handle;
3630 if(pagesetup_get_flags(data) & PSD_ENABLEPAGESETUPTEMPLATEHANDLE)
3632 tmpl_handle = data->u.dlgw->hPageSetupTemplate;
3634 else if(pagesetup_get_flags(data) & PSD_ENABLEPAGESETUPTEMPLATE)
3637 res = FindResourceW(data->u.dlgw->hInstance,
3638 data->u.dlgw->lpPageSetupTemplateName, MAKEINTRESOURCEW(RT_DIALOG));
3640 res = FindResourceA(data->u.dlga->hInstance,
3641 data->u.dlga->lpPageSetupTemplateName, MAKEINTRESOURCEA(RT_DIALOG));
3642 tmpl_handle = LoadResource(data->u.dlgw->hInstance, res);
3646 res = FindResourceW(COMDLG32_hInstance, MAKEINTRESOURCEW(PAGESETUPDLGORD),
3647 MAKEINTRESOURCEW(RT_DIALOG));
3648 tmpl_handle = LoadResource(COMDLG32_hInstance, res);
3650 return LockResource(tmpl_handle);
3653 static BOOL pagesetup_common(pagesetup_data *data)
3658 if(!pagesetup_get_dlg_struct(data))
3660 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION);
3664 pagesetup_dump_dlg_struct(data);
3666 if(data->u.dlgw->lStructSize != sizeof(PAGESETUPDLGW))
3668 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
3672 if ((pagesetup_get_flags(data) & PSD_ENABLEPAGEPAINTHOOK) &&
3673 (pagesetup_get_hook(data, page_paint_hook) == NULL))
3675 COMDLG32_SetCommDlgExtendedError(CDERR_NOHOOK);
3679 if(!(pagesetup_get_flags(data) & (PSD_INTHOUSANDTHSOFINCHES | PSD_INHUNDREDTHSOFMILLIMETERS)))
3680 data->u.dlgw->Flags |= is_default_metric() ?
3681 PSD_INHUNDREDTHSOFMILLIMETERS : PSD_INTHOUSANDTHSOFINCHES;
3683 if (!data->u.dlgw->hDevMode || !data->u.dlgw->hDevNames)
3685 WCHAR *def = get_default_printer();
3688 if (!(pagesetup_get_flags(data) & PSD_NOWARNING))
3691 LoadStringW(COMDLG32_hInstance, PD32_NO_DEFAULT_PRINTER, errstr, 255);
3692 MessageBoxW(data->u.dlgw->hwndOwner, errstr, 0, MB_OK | MB_ICONERROR);
3694 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
3697 pagesetup_change_printer(def, data);
3698 HeapFree(GetProcessHeap(), 0, def);
3701 if (pagesetup_get_flags(data) & PSD_RETURNDEFAULT)
3703 pagesetup_update_papersize(data);
3707 tmpl = pagesetup_get_template(data);
3709 ret = DialogBoxIndirectParamW(data->u.dlgw->hInstance, tmpl,
3710 data->u.dlgw->hwndOwner,
3711 pagesetup_dlg_proc, (LPARAM)data) > 0;
3715 /***********************************************************************
3716 * PageSetupDlgA (COMDLG32.@)
3718 * Displays the PAGE SETUP dialog box, which enables the user to specify
3719 * specific properties of a printed page such as
3720 * size, source, orientation and the width of the page margins.
3723 * setupdlg [IO] PAGESETUPDLGA struct
3726 * TRUE if the user pressed the OK button
3727 * FALSE if the user cancelled the window or an error occurred
3730 * The values of hDevMode and hDevNames are filled on output and can be
3731 * changed in PAGESETUPDLG when they are passed in PageSetupDlg.
3734 BOOL WINAPI PageSetupDlgA(LPPAGESETUPDLGA setupdlg)
3736 pagesetup_data data;
3738 data.unicode = FALSE;
3739 data.u.dlga = setupdlg;
3741 return pagesetup_common(&data);
3744 /***********************************************************************
3745 * PageSetupDlgW (COMDLG32.@)
3747 * See PageSetupDlgA.
3749 BOOL WINAPI PageSetupDlgW(LPPAGESETUPDLGW setupdlg)
3751 pagesetup_data data;
3753 data.unicode = TRUE;
3754 data.u.dlgw = setupdlg;
3756 return pagesetup_common(&data);
3759 /***********************************************************************
3760 * PrintDlgExA (COMDLG32.@)
3768 HRESULT WINAPI PrintDlgExA(LPPRINTDLGEXA lppd)
3773 FIXME("(%p) not fully implemented\n", lppd);
3774 if ((lppd == NULL) || (lppd->lStructSize != sizeof(PRINTDLGEXA)))
3775 return E_INVALIDARG;
3777 if (!IsWindow(lppd->hwndOwner))
3780 if (lppd->Flags & PD_RETURNDEFAULT)
3782 PRINTER_INFO_2A *pbuf;
3783 DRIVER_INFO_2A *dbuf;
3785 DWORD needed = 1024;
3788 if (lppd->hDevMode || lppd->hDevNames)
3790 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
3791 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
3792 return E_INVALIDARG;
3794 if (!PRINTDLG_OpenDefaultPrinter(&hprn))
3796 WARN("Can't find default printer\n");
3797 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
3801 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
3802 bRet = GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
3803 if (!bRet && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
3805 HeapFree(GetProcessHeap(), 0, pbuf);
3806 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
3807 bRet = GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
3811 HeapFree(GetProcessHeap(), 0, pbuf);
3817 dbuf = HeapAlloc(GetProcessHeap(), 0, needed);
3818 bRet = GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed);
3819 if (!bRet && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
3821 HeapFree(GetProcessHeap(), 0, dbuf);
3822 dbuf = HeapAlloc(GetProcessHeap(), 0, needed);
3823 bRet = GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed);
3827 ERR("GetPrinterDriverŠ failed, last error %d, fix your config for printer %s!\n",
3828 GetLastError(), pbuf->pPrinterName);
3829 HeapFree(GetProcessHeap(), 0, dbuf);
3830 HeapFree(GetProcessHeap(), 0, pbuf);
3831 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
3837 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
3841 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
3842 pbuf->pDevMode->dmDriverExtra);
3845 ptr = GlobalLock(lppd->hDevMode);
3848 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
3849 pbuf->pDevMode->dmDriverExtra);
3850 GlobalUnlock(lppd->hDevMode);
3854 HeapFree(GetProcessHeap(), 0, pbuf);
3855 HeapFree(GetProcessHeap(), 0, dbuf);
3863 /***********************************************************************
3864 * PrintDlgExW (COMDLG32.@)
3866 * Display the property sheet style PRINT dialog box
3869 * lppd [IO] ptr to PRINTDLGEX struct
3873 * Failure: One of the following COM error codes:
3874 * E_OUTOFMEMORY Insufficient memory.
3875 * E_INVALIDARG One or more arguments are invalid.
3876 * E_POINTER Invalid pointer.
3877 * E_HANDLE Invalid handle.
3878 * E_FAIL Unspecified error.
3881 * This Dialog enables the user to specify specific properties of the print job.
3882 * The property sheet can also have additional application-specific and
3883 * driver-specific property pages.
3886 * Not fully implemented
3889 HRESULT WINAPI PrintDlgExW(LPPRINTDLGEXW lppd)
3894 FIXME("(%p) not fully implemented\n", lppd);
3896 if ((lppd == NULL) || (lppd->lStructSize != sizeof(PRINTDLGEXW))) {
3897 return E_INVALIDARG;
3900 if (!IsWindow(lppd->hwndOwner)) {
3904 if (lppd->Flags & PD_RETURNDEFAULT) {
3905 PRINTER_INFO_2W *pbuf;
3906 DRIVER_INFO_2W *dbuf;
3908 DWORD needed = 1024;
3911 if (lppd->hDevMode || lppd->hDevNames) {
3912 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
3913 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
3914 return E_INVALIDARG;
3916 if (!PRINTDLG_OpenDefaultPrinter(&hprn)) {
3917 WARN("Can't find default printer\n");
3918 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
3922 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
3923 bRet = GetPrinterW(hprn, 2, (LPBYTE)pbuf, needed, &needed);
3924 if (!bRet && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
3925 HeapFree(GetProcessHeap(), 0, pbuf);
3926 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
3927 bRet = GetPrinterW(hprn, 2, (LPBYTE)pbuf, needed, &needed);
3930 HeapFree(GetProcessHeap(), 0, pbuf);
3936 dbuf = HeapAlloc(GetProcessHeap(), 0, needed);
3937 bRet = GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed);
3938 if (!bRet && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
3939 HeapFree(GetProcessHeap(), 0, dbuf);
3940 dbuf = HeapAlloc(GetProcessHeap(), 0, needed);
3941 bRet = GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed);
3944 ERR("GetPrinterDriverW failed, last error %d, fix your config for printer %s!\n",
3945 GetLastError(), debugstr_w(pbuf->pPrinterName));
3946 HeapFree(GetProcessHeap(), 0, dbuf);
3947 HeapFree(GetProcessHeap(), 0, pbuf);
3948 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
3954 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
3958 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
3959 pbuf->pDevMode->dmDriverExtra);
3960 if (lppd->hDevMode) {
3961 ptr = GlobalLock(lppd->hDevMode);
3963 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
3964 pbuf->pDevMode->dmDriverExtra);
3965 GlobalUnlock(lppd->hDevMode);
3969 HeapFree(GetProcessHeap(), 0, pbuf);
3970 HeapFree(GetProcessHeap(), 0, dbuf);