2 * COMMDLG - Print Dialog
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
6 * Copyright 1999 Klaas van Gend
7 * Copyright 2000 Huw D M Davies
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #define NONAMELESSUNION
31 #define NONAMELESSSTRUCT
39 #include "wine/unicode.h"
40 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
51 /* Yes these constants are the same, but we're just copying win98 */
52 #define UPDOWN_ID 0x270f
53 #define MAX_COPIES 9999
56 static const struct pd_flags psd_flags[] = {
57 {PSD_MINMARGINS,"PSD_MINMARGINS"},
58 {PSD_MARGINS,"PSD_MARGINS"},
59 {PSD_INTHOUSANDTHSOFINCHES,"PSD_INTHOUSANDTHSOFINCHES"},
60 {PSD_INHUNDREDTHSOFMILLIMETERS,"PSD_INHUNDREDTHSOFMILLIMETERS"},
61 {PSD_DISABLEMARGINS,"PSD_DISABLEMARGINS"},
62 {PSD_DISABLEPRINTER,"PSD_DISABLEPRINTER"},
63 {PSD_NOWARNING,"PSD_NOWARNING"},
64 {PSD_DISABLEORIENTATION,"PSD_DISABLEORIENTATION"},
65 {PSD_RETURNDEFAULT,"PSD_RETURNDEFAULT"},
66 {PSD_DISABLEPAPER,"PSD_DISABLEPAPER"},
67 {PSD_SHOWHELP,"PSD_SHOWHELP"},
68 {PSD_ENABLEPAGESETUPHOOK,"PSD_ENABLEPAGESETUPHOOK"},
69 {PSD_ENABLEPAGESETUPTEMPLATE,"PSD_ENABLEPAGESETUPTEMPLATE"},
70 {PSD_ENABLEPAGESETUPTEMPLATEHANDLE,"PSD_ENABLEPAGESETUPTEMPLATEHANDLE"},
71 {PSD_ENABLEPAGEPAINTHOOK,"PSD_ENABLEPAGEPAINTHOOK"},
72 {PSD_DISABLEPAGEPAINTING,"PSD_DISABLEPAGEPAINTING"},
76 /* address of wndproc for subclassed Static control */
77 static WNDPROC lpfnStaticWndProc;
78 static WNDPROC edit_wndproc;
79 /* the text of the fake document to render for the Page Setup dialog */
80 static WCHAR wszFakeDocumentText[1024];
81 static const WCHAR pd32_collateW[] = { 'P', 'D', '3', '2', '_', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
82 static const WCHAR pd32_nocollateW[] = { 'P', 'D', '3', '2', '_', 'N', 'O', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
83 static const WCHAR pd32_portraitW[] = { 'P', 'D', '3', '2', '_', 'P', 'O', 'R', 'T', 'R', 'A', 'I', 'T', 0 };
84 static const WCHAR pd32_landscapeW[] = { 'P', 'D', '3', '2', '_', 'L', 'A', 'N', 'D', 'S', 'C', 'A', 'P', 'E', 0 };
85 static const WCHAR printdlg_prop[] = {'_','_','W','I','N','E','_','P','R','I','N','T','D','L','G','D','A','T','A',0};
86 static const WCHAR pagesetupdlg_prop[] = { '_', '_', 'W', 'I', 'N', 'E', '_', 'P', 'A', 'G', 'E',
87 'S', 'E', 'T', 'U', 'P', 'D', 'L', 'G', 'D', 'A', 'T', 'A', 0 };
90 /***********************************************************
93 * Creates an ansi copy of supplied devmode
95 static DEVMODEA *convert_to_devmodeA(const DEVMODEW *dmW)
100 if (!dmW) return NULL;
101 size = dmW->dmSize - CCHDEVICENAME -
102 ((dmW->dmSize > FIELD_OFFSET(DEVMODEW, dmFormName)) ? CCHFORMNAME : 0);
104 dmA = HeapAlloc(GetProcessHeap(), 0, size + dmW->dmDriverExtra);
105 if (!dmA) return NULL;
107 WideCharToMultiByte(CP_ACP, 0, dmW->dmDeviceName, -1,
108 (LPSTR)dmA->dmDeviceName, CCHDEVICENAME, NULL, NULL);
110 if (FIELD_OFFSET(DEVMODEW, dmFormName) >= dmW->dmSize)
112 memcpy(&dmA->dmSpecVersion, &dmW->dmSpecVersion,
113 dmW->dmSize - FIELD_OFFSET(DEVMODEW, dmSpecVersion));
117 memcpy(&dmA->dmSpecVersion, &dmW->dmSpecVersion,
118 FIELD_OFFSET(DEVMODEW, dmFormName) - FIELD_OFFSET(DEVMODEW, dmSpecVersion));
119 WideCharToMultiByte(CP_ACP, 0, dmW->dmFormName, -1,
120 (LPSTR)dmA->dmFormName, CCHFORMNAME, NULL, NULL);
122 memcpy(&dmA->dmLogPixels, &dmW->dmLogPixels, dmW->dmSize - FIELD_OFFSET(DEVMODEW, dmLogPixels));
126 memcpy((char *)dmA + dmA->dmSize, (const char *)dmW + dmW->dmSize, dmW->dmDriverExtra);
130 /***********************************************************************
131 * PRINTDLG_OpenDefaultPrinter
133 * Returns a winspool printer handle to the default printer in *hprn
134 * Caller must call ClosePrinter on the handle
136 * Returns TRUE on success else FALSE
138 BOOL PRINTDLG_OpenDefaultPrinter(HANDLE *hprn)
141 DWORD dwBufLen = sizeof(buf) / sizeof(buf[0]);
143 if(!GetDefaultPrinterW(buf, &dwBufLen))
145 res = OpenPrinterW(buf, hprn, NULL);
147 WARN("Could not open printer %s\n", debugstr_w(buf));
151 /***********************************************************************
152 * PRINTDLG_SetUpPrinterListCombo
154 * Initializes printer list combox.
155 * hDlg: HWND of dialog
156 * id: Control id of combo
157 * name: Name of printer to select
159 * Initializes combo with list of available printers. Selects printer 'name'
160 * If name is NULL or does not exist select the default printer.
162 * Returns number of printers added to list.
164 INT PRINTDLG_SetUpPrinterListComboA(HWND hDlg, UINT id, LPCSTR name)
168 LPPRINTER_INFO_2A pi;
169 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
170 pi = HeapAlloc(GetProcessHeap(), 0, needed);
171 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
174 SendDlgItemMessageA(hDlg, id, CB_RESETCONTENT, 0, 0);
176 for(i = 0; i < num; i++) {
177 SendDlgItemMessageA(hDlg, id, CB_ADDSTRING, 0,
178 (LPARAM)pi[i].pPrinterName );
180 HeapFree(GetProcessHeap(), 0, pi);
182 (i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1,
183 (LPARAM)name)) == CB_ERR) {
186 DWORD dwBufLen = sizeof(buf);
188 WARN("Can't find %s in printer list so trying to find default\n",
190 if(!GetDefaultPrinterA(buf, &dwBufLen))
192 i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
194 FIXME("Can't find default printer in printer list\n");
196 SendDlgItemMessageA(hDlg, id, CB_SETCURSEL, i, 0);
200 static INT PRINTDLG_SetUpPrinterListComboW(HWND hDlg, UINT id, LPCWSTR name)
204 LPPRINTER_INFO_2W pi;
205 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
206 pi = HeapAlloc(GetProcessHeap(), 0, needed);
207 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
210 for(i = 0; i < num; i++) {
211 SendDlgItemMessageW(hDlg, id, CB_ADDSTRING, 0,
212 (LPARAM)pi[i].pPrinterName );
214 HeapFree(GetProcessHeap(), 0, pi);
216 (i = SendDlgItemMessageW(hDlg, id, CB_FINDSTRINGEXACT, -1,
217 (LPARAM)name)) == CB_ERR) {
219 DWORD dwBufLen = sizeof(buf)/sizeof(buf[0]);
221 WARN("Can't find %s in printer list so trying to find default\n",
223 if(!GetDefaultPrinterW(buf, &dwBufLen))
225 i = SendDlgItemMessageW(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
227 TRACE("Can't find default printer in printer list\n");
229 SendDlgItemMessageW(hDlg, id, CB_SETCURSEL, i, 0);
233 /***********************************************************************
234 * PRINTDLG_CreateDevNames [internal]
237 * creates a DevNames structure.
239 * (NB. when we handle unicode the offsets will be in wchars).
241 static BOOL PRINTDLG_CreateDevNames(HGLOBAL *hmem, const char* DeviceDriverName,
242 const char* DeviceName, const char* OutputPort)
245 char* pDevNamesSpace;
247 LPDEVNAMES lpDevNames;
249 DWORD dwBufLen = sizeof(buf);
251 size = strlen(DeviceDriverName) + 1
252 + strlen(DeviceName) + 1
253 + strlen(OutputPort) + 1
257 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
259 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
263 pDevNamesSpace = GlobalLock(*hmem);
264 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
266 pTempPtr = pDevNamesSpace + sizeof(DEVNAMES);
267 strcpy(pTempPtr, DeviceDriverName);
268 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
270 pTempPtr += strlen(DeviceDriverName) + 1;
271 strcpy(pTempPtr, DeviceName);
272 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
274 pTempPtr += strlen(DeviceName) + 1;
275 strcpy(pTempPtr, OutputPort);
276 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
278 GetDefaultPrinterA(buf, &dwBufLen);
279 lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
284 static BOOL PRINTDLG_CreateDevNamesW(HGLOBAL *hmem, LPCWSTR DeviceDriverName,
285 LPCWSTR DeviceName, LPCWSTR OutputPort)
288 LPWSTR pDevNamesSpace;
290 LPDEVNAMES lpDevNames;
292 DWORD dwBufLen = sizeof(bufW) / sizeof(WCHAR);
294 size = sizeof(WCHAR)*lstrlenW(DeviceDriverName) + 2
295 + sizeof(WCHAR)*lstrlenW(DeviceName) + 2
296 + sizeof(WCHAR)*lstrlenW(OutputPort) + 2
300 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
302 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
306 pDevNamesSpace = GlobalLock(*hmem);
307 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
309 pTempPtr = (LPWSTR)((LPDEVNAMES)pDevNamesSpace + 1);
310 lstrcpyW(pTempPtr, DeviceDriverName);
311 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
313 pTempPtr += lstrlenW(DeviceDriverName) + 1;
314 lstrcpyW(pTempPtr, DeviceName);
315 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
317 pTempPtr += lstrlenW(DeviceName) + 1;
318 lstrcpyW(pTempPtr, OutputPort);
319 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
321 GetDefaultPrinterW(bufW, &dwBufLen);
322 lpDevNames->wDefault = (lstrcmpW(bufW, DeviceName) == 0) ? 1 : 0;
327 /***********************************************************************
328 * PRINTDLG_UpdatePrintDlg [internal]
331 * updates the PrintDlg structure for return values.
334 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
335 * TRUE if successful.
337 static BOOL PRINTDLG_UpdatePrintDlgA(HWND hDlg,
338 PRINT_PTRA* PrintStructures)
340 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
341 PDEVMODEA lpdm = PrintStructures->lpDevMode;
342 LPPRINTER_INFO_2A pi = PrintStructures->lpPrinterInfo;
346 FIXME("No lpdm ptr?\n");
351 if(!(lppd->Flags & PD_PRINTSETUP)) {
352 /* check whether nFromPage and nToPage are within range defined by
353 * nMinPage and nMaxPage
355 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
359 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
360 nToPage = GetDlgItemInt(hDlg, edt2, &translated, FALSE);
362 /* if no ToPage value is entered, use the FromPage value */
363 if(!translated) nToPage = nFromPage;
365 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
366 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
367 WCHAR resourcestr[256];
368 WCHAR resultstr[256];
369 LoadStringW(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE, resourcestr, 255);
370 wsprintfW(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
371 LoadStringW(COMDLG32_hInstance, PD32_PRINT_TITLE, resourcestr, 255);
372 MessageBoxW(hDlg, resultstr, resourcestr, MB_OK | MB_ICONWARNING);
375 lppd->nFromPage = nFromPage;
376 lppd->nToPage = nToPage;
377 lppd->Flags |= PD_PAGENUMS;
380 lppd->Flags &= ~PD_PAGENUMS;
382 if (IsDlgButtonChecked(hDlg, rad2) == BST_CHECKED) /* Selection */
383 lppd->Flags |= PD_SELECTION;
385 lppd->Flags &= ~PD_SELECTION;
387 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
388 static char file[] = "FILE:";
389 lppd->Flags |= PD_PRINTTOFILE;
390 pi->pPortName = file;
393 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
394 FIXME("Collate lppd not yet implemented as output\n");
397 /* set PD_Collate and nCopies */
398 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
399 /* The application doesn't support multiple copies or collate...
401 lppd->Flags &= ~PD_COLLATE;
403 /* if the printer driver supports it... store info there
404 * otherwise no collate & multiple copies !
406 if (lpdm->dmFields & DM_COLLATE)
408 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
409 if (lpdm->dmFields & DM_COPIES)
410 lpdm->u1.s1.dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
412 /* Application is responsible for multiple copies */
413 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
414 lppd->Flags |= PD_COLLATE;
416 lppd->Flags &= ~PD_COLLATE;
417 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
418 /* multiple copies already included in the document. Driver must print only one copy */
419 lpdm->u1.s1.dmCopies = 1;
422 /* Print quality, PrintDlg16 */
423 if(GetDlgItem(hDlg, cmb1))
425 HWND hQuality = GetDlgItem(hDlg, cmb1);
426 int Sel = SendMessageA(hQuality, CB_GETCURSEL, 0, 0);
430 LONG dpi = SendMessageA(hQuality, CB_GETITEMDATA, Sel, 0);
431 lpdm->dmFields |= DM_PRINTQUALITY | DM_YRESOLUTION;
432 lpdm->u1.s1.dmPrintQuality = LOWORD(dpi);
433 lpdm->dmYResolution = HIWORD(dpi);
440 static BOOL PRINTDLG_UpdatePrintDlgW(HWND hDlg,
441 PRINT_PTRW* PrintStructures)
443 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
444 PDEVMODEW lpdm = PrintStructures->lpDevMode;
445 LPPRINTER_INFO_2W pi = PrintStructures->lpPrinterInfo;
449 FIXME("No lpdm ptr?\n");
454 if(!(lppd->Flags & PD_PRINTSETUP)) {
455 /* check whether nFromPage and nToPage are within range defined by
456 * nMinPage and nMaxPage
458 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
462 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
463 nToPage = GetDlgItemInt(hDlg, edt2, &translated, FALSE);
465 /* if no ToPage value is entered, use the FromPage value */
466 if(!translated) nToPage = nFromPage;
468 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
469 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
470 WCHAR resourcestr[256];
471 WCHAR resultstr[256];
472 LoadStringW(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
474 wsprintfW(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
475 LoadStringW(COMDLG32_hInstance, PD32_PRINT_TITLE,
477 MessageBoxW(hDlg, resultstr, resourcestr,
478 MB_OK | MB_ICONWARNING);
481 lppd->nFromPage = nFromPage;
482 lppd->nToPage = nToPage;
483 lppd->Flags |= PD_PAGENUMS;
486 lppd->Flags &= ~PD_PAGENUMS;
488 if (IsDlgButtonChecked(hDlg, rad2) == BST_CHECKED) /* Selection */
489 lppd->Flags |= PD_SELECTION;
491 lppd->Flags &= ~PD_SELECTION;
493 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
494 static WCHAR file[] = {'F','I','L','E',':',0};
495 lppd->Flags |= PD_PRINTTOFILE;
496 pi->pPortName = file;
499 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
500 FIXME("Collate lppd not yet implemented as output\n");
503 /* set PD_Collate and nCopies */
504 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
505 /* The application doesn't support multiple copies or collate...
507 lppd->Flags &= ~PD_COLLATE;
509 /* if the printer driver supports it... store info there
510 * otherwise no collate & multiple copies !
512 if (lpdm->dmFields & DM_COLLATE)
514 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
515 if (lpdm->dmFields & DM_COPIES)
516 lpdm->u1.s1.dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
518 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
519 lppd->Flags |= PD_COLLATE;
521 lppd->Flags &= ~PD_COLLATE;
522 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
528 static BOOL PRINTDLG_PaperSizeW(
529 PRINTDLGW *pdlga,const WCHAR *PaperSize,LPPOINT size
533 LPWSTR devname,portname;
537 POINT *points = NULL;
540 dn = GlobalLock(pdlga->hDevNames);
541 dm = GlobalLock(pdlga->hDevMode);
542 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
543 portname = ((WCHAR*)dn)+dn->wOutputOffset;
546 NrOfEntries = DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,NULL,dm);
548 FIXME("No papernames found for %s/%s\n",debugstr_w(devname),debugstr_w(portname));
551 if (NrOfEntries == -1) {
552 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
556 Names = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*NrOfEntries*64);
557 if (NrOfEntries != (ret=DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,Names,dm))) {
558 FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
561 for (i=0;i<NrOfEntries;i++)
562 if (!lstrcmpW(PaperSize,Names+(64*i)))
564 if (i==NrOfEntries) {
565 FIXME("Papersize %s not found in list?\n",debugstr_w(PaperSize));
568 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
569 if (NrOfEntries!=(ret=DeviceCapabilitiesW(devname,portname,DC_PAPERSIZE,(LPWSTR)points,dm))) {
570 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
573 /* this is _10ths_ of a millimeter */
578 GlobalUnlock(pdlga->hDevNames);
579 GlobalUnlock(pdlga->hDevMode);
580 HeapFree(GetProcessHeap(),0,Names);
581 HeapFree(GetProcessHeap(),0,points);
586 /************************************************************************
587 * PRINTDLG_SetUpPaperComboBox
589 * Initialize either the papersize or inputslot combos of the Printer Setup
590 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
591 * We also try to re-select the old selection.
593 static BOOL PRINTDLG_SetUpPaperComboBoxA(HWND hDlg,
606 int fwCapability_Names;
607 int fwCapability_Words;
609 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName,PortName,nIDComboBox);
611 /* query the dialog box for the current selected value */
612 Sel = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
614 /* we enter here only if a different printer is selected after
615 * the Print Setup dialog is opened. The current settings are
616 * stored into the newly selected printer.
618 oldWord = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA,
621 if (nIDComboBox == cmb2)
622 dm->u1.s1.dmPaperSize = oldWord;
624 dm->u1.s1.dmDefaultSource = oldWord;
628 /* we enter here only when the Print setup dialog is initially
629 * opened. In this case the settings are restored from when
630 * the dialog was last closed.
633 if (nIDComboBox == cmb2)
634 oldWord = dm->u1.s1.dmPaperSize;
636 oldWord = dm->u1.s1.dmDefaultSource;
640 if (nIDComboBox == cmb2) {
642 fwCapability_Names = DC_PAPERNAMES;
643 fwCapability_Words = DC_PAPERS;
647 fwCapability_Names = DC_BINNAMES;
648 fwCapability_Words = DC_BINS;
651 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
652 fwCapability_Names, NULL, dm);
653 if (NrOfEntries == 0)
654 WARN("no Name Entries found!\n");
655 else if (NrOfEntries < 0)
658 if(DeviceCapabilitiesA(PrinterName, PortName, fwCapability_Words, NULL, dm)
660 ERR("Number of caps is different\n");
664 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(char)*NamesSize);
665 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
666 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
667 fwCapability_Names, Names, dm);
668 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
669 fwCapability_Words, (LPSTR)Words, dm);
671 /* reset any current content in the combobox */
672 SendDlgItemMessageA(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
674 /* store new content */
675 for (i = 0; i < NrOfEntries; i++) {
676 DWORD pos = SendDlgItemMessageA(hDlg, nIDComboBox, CB_ADDSTRING, 0,
677 (LPARAM)(&Names[i*NamesSize]) );
678 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
682 /* Look for old selection - can't do this is previous loop since
683 item order will change as more items are added */
685 for (i = 0; i < NrOfEntries; i++) {
686 if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
692 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
694 HeapFree(GetProcessHeap(),0,Words);
695 HeapFree(GetProcessHeap(),0,Names);
699 static BOOL PRINTDLG_SetUpPaperComboBoxW(HWND hDlg,
701 const WCHAR* PrinterName,
702 const WCHAR* PortName,
712 int fwCapability_Names;
713 int fwCapability_Words;
715 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName),debugstr_w(PortName),nIDComboBox);
717 /* query the dialog box for the current selected value */
718 Sel = SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
720 /* we enter here only if a different printer is selected after
721 * the Print Setup dialog is opened. The current settings are
722 * stored into the newly selected printer.
724 oldWord = SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETITEMDATA,
727 if (nIDComboBox == cmb2)
728 dm->u1.s1.dmPaperSize = oldWord;
730 dm->u1.s1.dmDefaultSource = oldWord;
734 /* we enter here only when the Print setup dialog is initially
735 * opened. In this case the settings are restored from when
736 * the dialog was last closed.
739 if (nIDComboBox == cmb2)
740 oldWord = dm->u1.s1.dmPaperSize;
742 oldWord = dm->u1.s1.dmDefaultSource;
746 if (nIDComboBox == cmb2) {
748 fwCapability_Names = DC_PAPERNAMES;
749 fwCapability_Words = DC_PAPERS;
753 fwCapability_Names = DC_BINNAMES;
754 fwCapability_Words = DC_BINS;
757 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
758 fwCapability_Names, NULL, dm);
759 if (NrOfEntries == 0)
760 WARN("no Name Entries found!\n");
761 else if (NrOfEntries < 0)
764 if(DeviceCapabilitiesW(PrinterName, PortName, fwCapability_Words, NULL, dm)
766 ERR("Number of caps is different\n");
770 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WCHAR)*NamesSize);
771 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
772 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
773 fwCapability_Names, Names, dm);
774 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
775 fwCapability_Words, Words, dm);
777 /* reset any current content in the combobox */
778 SendDlgItemMessageW(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
780 /* store new content */
781 for (i = 0; i < NrOfEntries; i++) {
782 DWORD pos = SendDlgItemMessageW(hDlg, nIDComboBox, CB_ADDSTRING, 0,
783 (LPARAM)(&Names[i*NamesSize]) );
784 SendDlgItemMessageW(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
788 /* Look for old selection - can't do this is previous loop since
789 item order will change as more items are added */
791 for (i = 0; i < NrOfEntries; i++) {
792 if(SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
798 SendDlgItemMessageW(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
800 HeapFree(GetProcessHeap(),0,Words);
801 HeapFree(GetProcessHeap(),0,Names);
806 /***********************************************************************
807 * PRINTDLG_UpdatePrinterInfoTexts [internal]
809 static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg, const PRINTER_INFO_2A *pi)
812 char ResourceString[256];
818 /* add all status messages */
819 for (i = 0; i < 25; i++) {
820 if (pi->Status & (1<<i)) {
821 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
822 ResourceString, 255);
823 strcat(StatusMsg,ResourceString);
827 /* FIXME: status==ready must only be appended if really so.
828 but how to detect? */
829 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
830 ResourceString, 255);
831 strcat(StatusMsg,ResourceString);
832 SetDlgItemTextA(hDlg, stc12, StatusMsg);
834 /* set all other printer info texts */
835 SetDlgItemTextA(hDlg, stc11, pi->pDriverName);
837 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
838 SetDlgItemTextA(hDlg, stc14, pi->pLocation);
840 SetDlgItemTextA(hDlg, stc14, pi->pPortName);
841 SetDlgItemTextA(hDlg, stc13, pi->pComment ? pi->pComment : "");
845 static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg, const PRINTER_INFO_2W *pi)
847 WCHAR StatusMsg[256];
848 WCHAR ResourceString[256];
849 static const WCHAR emptyW[] = {0};
855 /* add all status messages */
856 for (i = 0; i < 25; i++) {
857 if (pi->Status & (1<<i)) {
858 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
859 ResourceString, 255);
860 lstrcatW(StatusMsg,ResourceString);
864 /* FIXME: status==ready must only be appended if really so.
865 but how to detect? */
866 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
867 ResourceString, 255);
868 lstrcatW(StatusMsg,ResourceString);
869 SetDlgItemTextW(hDlg, stc12, StatusMsg);
871 /* set all other printer info texts */
872 SetDlgItemTextW(hDlg, stc11, pi->pDriverName);
873 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
874 SetDlgItemTextW(hDlg, stc14, pi->pLocation);
876 SetDlgItemTextW(hDlg, stc14, pi->pPortName);
877 SetDlgItemTextW(hDlg, stc13, pi->pComment ? pi->pComment : emptyW);
881 /*******************************************************************
883 * PRINTDLG_ChangePrinter
886 BOOL PRINTDLG_ChangePrinterA(HWND hDlg, char *name,
887 PRINT_PTRA *PrintStructures)
889 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
890 LPDEVMODEA lpdm = NULL;
895 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
896 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
897 if(!OpenPrinterA(name, &hprn, NULL)) {
898 ERR("Can't open printer %s\n", name);
901 GetPrinterA(hprn, 2, NULL, 0, &needed);
902 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,needed);
903 GetPrinterA(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
905 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
906 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,needed);
907 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
909 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures->lpPrinterInfo->pPrinterName);
914 PRINTDLG_UpdatePrinterInfoTextsA(hDlg, PrintStructures->lpPrinterInfo);
916 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
917 PrintStructures->lpDevMode = NULL;
919 dmSize = DocumentPropertiesA(0, 0, name, NULL, NULL, 0);
921 ERR("DocumentProperties fails on %s\n", debugstr_a(name));
924 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
925 dmSize = DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, NULL,
927 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
928 !lstrcmpA( (LPSTR) lpdm->dmDeviceName,
929 (LPSTR) PrintStructures->lpDevMode->dmDeviceName)) {
930 /* Supplied devicemode matches current printer so try to use it */
931 DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, lpdm,
932 DM_OUT_BUFFER | DM_IN_BUFFER);
935 GlobalUnlock(lppd->hDevMode);
937 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
939 if(!(lppd->Flags & PD_PRINTSETUP)) {
940 /* Print range (All/Range/Selection) */
941 if(lppd->nFromPage != 0xffff)
942 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
943 if(lppd->nToPage != 0xffff)
944 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
946 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
947 if (lppd->Flags & PD_NOSELECTION)
948 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
950 if (lppd->Flags & PD_SELECTION)
951 CheckRadioButton(hDlg, rad1, rad3, rad2);
952 if (lppd->Flags & PD_NOPAGENUMS) {
953 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
954 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
955 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
956 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
957 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
959 if (lppd->Flags & PD_PAGENUMS)
960 CheckRadioButton(hDlg, rad1, rad3, rad3);
965 * FIXME: The ico3 is not displayed for some reason. I don't know why.
967 if (lppd->Flags & PD_COLLATE) {
968 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
969 (LPARAM)PrintStructures->hCollateIcon);
970 CheckDlgButton(hDlg, chx2, 1);
972 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
973 (LPARAM)PrintStructures->hNoCollateIcon);
974 CheckDlgButton(hDlg, chx2, 0);
977 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
978 /* if printer doesn't support it: no Collate */
979 if (!(lpdm->dmFields & DM_COLLATE)) {
980 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
981 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
988 if (lppd->hDevMode == 0)
989 copies = lppd->nCopies;
991 copies = lpdm->u1.s1.dmCopies;
992 if(copies == 0) copies = 1;
993 else if(copies < 0) copies = MAX_COPIES;
994 SetDlgItemInt(hDlg, edt3, copies, FALSE);
997 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
998 /* if printer doesn't support it: no nCopies */
999 if (!(lpdm->dmFields & DM_COPIES)) {
1000 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
1001 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
1006 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
1007 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
1008 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
1009 if (lppd->Flags & PD_HIDEPRINTTOFILE)
1010 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
1012 /* Fill print quality combo, PrintDlg16 */
1013 if(GetDlgItem(hDlg, cmb1))
1015 DWORD numResolutions = DeviceCapabilitiesA(PrintStructures->lpPrinterInfo->pPrinterName,
1016 PrintStructures->lpPrinterInfo->pPortName,
1017 DC_ENUMRESOLUTIONS, NULL, lpdm);
1019 if(numResolutions != -1)
1021 HWND hQuality = GetDlgItem(hDlg, cmb1);
1026 HDC hPrinterDC = CreateDCA(PrintStructures->lpPrinterInfo->pDriverName,
1027 PrintStructures->lpPrinterInfo->pPrinterName,
1030 Resolutions = HeapAlloc(GetProcessHeap(), 0, numResolutions*sizeof(LONG)*2);
1031 DeviceCapabilitiesA(PrintStructures->lpPrinterInfo->pPrinterName,
1032 PrintStructures->lpPrinterInfo->pPortName,
1033 DC_ENUMRESOLUTIONS, (LPSTR)Resolutions, lpdm);
1035 dpiX = GetDeviceCaps(hPrinterDC, LOGPIXELSX);
1036 dpiY = GetDeviceCaps(hPrinterDC, LOGPIXELSY);
1037 DeleteDC(hPrinterDC);
1039 SendMessageA(hQuality, CB_RESETCONTENT, 0, 0);
1040 for(i = 0; i < (numResolutions * 2); i += 2)
1042 BOOL IsDefault = FALSE;
1045 if(Resolutions[i] == Resolutions[i+1])
1047 if(dpiX == Resolutions[i])
1049 sprintf(buf, "%d dpi", Resolutions[i]);
1052 if(dpiX == Resolutions[i] && dpiY == Resolutions[i+1])
1054 sprintf(buf, "%d dpi x %d dpi", Resolutions[i], Resolutions[i+1]);
1057 Index = SendMessageA(hQuality, CB_ADDSTRING, 0, (LPARAM)buf);
1060 SendMessageA(hQuality, CB_SETCURSEL, Index, 0);
1062 SendMessageA(hQuality, CB_SETITEMDATA, Index, MAKELONG(dpiX,dpiY));
1064 HeapFree(GetProcessHeap(), 0, Resolutions);
1067 } else { /* PD_PRINTSETUP */
1068 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
1070 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb2,
1071 PrintStructures->lpPrinterInfo->pPrinterName,
1072 PrintStructures->lpPrinterInfo->pPortName,
1074 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb3,
1075 PrintStructures->lpPrinterInfo->pPrinterName,
1076 PrintStructures->lpPrinterInfo->pPortName,
1078 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1079 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1080 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1081 PrintStructures->hLandscapeIcon));
1086 if ((lppd->Flags & PD_SHOWHELP)==0) {
1087 /* hide if PD_SHOWHELP not specified */
1088 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1093 static BOOL PRINTDLG_ChangePrinterW(HWND hDlg, WCHAR *name,
1094 PRINT_PTRW *PrintStructures)
1096 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1097 LPDEVMODEW lpdm = NULL;
1102 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
1103 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
1104 if(!OpenPrinterW(name, &hprn, NULL)) {
1105 ERR("Can't open printer %s\n", debugstr_w(name));
1108 GetPrinterW(hprn, 2, NULL, 0, &needed);
1109 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,needed);
1110 GetPrinterW(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
1112 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
1113 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,needed);
1114 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
1116 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures->lpPrinterInfo->pPrinterName));
1121 PRINTDLG_UpdatePrinterInfoTextsW(hDlg, PrintStructures->lpPrinterInfo);
1123 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
1124 PrintStructures->lpDevMode = NULL;
1126 dmSize = DocumentPropertiesW(0, 0, name, NULL, NULL, 0);
1128 ERR("DocumentProperties fails on %s\n", debugstr_w(name));
1131 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
1132 dmSize = DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, NULL,
1134 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
1135 !lstrcmpW(lpdm->dmDeviceName,
1136 PrintStructures->lpDevMode->dmDeviceName)) {
1137 /* Supplied devicemode matches current printer so try to use it */
1138 DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, lpdm,
1139 DM_OUT_BUFFER | DM_IN_BUFFER);
1142 GlobalUnlock(lppd->hDevMode);
1144 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
1146 if(!(lppd->Flags & PD_PRINTSETUP)) {
1147 /* Print range (All/Range/Selection) */
1148 if(lppd->nFromPage != 0xffff)
1149 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
1150 if(lppd->nToPage != 0xffff)
1151 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
1153 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
1154 if (lppd->Flags & PD_NOSELECTION)
1155 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
1157 if (lppd->Flags & PD_SELECTION)
1158 CheckRadioButton(hDlg, rad1, rad3, rad2);
1159 if (lppd->Flags & PD_NOPAGENUMS) {
1160 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
1161 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
1162 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
1163 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
1164 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
1166 if (lppd->Flags & PD_PAGENUMS)
1167 CheckRadioButton(hDlg, rad1, rad3, rad3);
1172 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1174 if (lppd->Flags & PD_COLLATE) {
1175 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1176 (LPARAM)PrintStructures->hCollateIcon);
1177 CheckDlgButton(hDlg, chx2, 1);
1179 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1180 (LPARAM)PrintStructures->hNoCollateIcon);
1181 CheckDlgButton(hDlg, chx2, 0);
1184 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1185 /* if printer doesn't support it: no Collate */
1186 if (!(lpdm->dmFields & DM_COLLATE)) {
1187 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1188 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
1195 if (lppd->hDevMode == 0)
1196 copies = lppd->nCopies;
1198 copies = lpdm->u1.s1.dmCopies;
1199 if(copies == 0) copies = 1;
1200 else if(copies < 0) copies = MAX_COPIES;
1201 SetDlgItemInt(hDlg, edt3, copies, FALSE);
1204 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1205 /* if printer doesn't support it: no nCopies */
1206 if (!(lpdm->dmFields & DM_COPIES)) {
1207 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
1208 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
1213 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
1214 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
1215 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
1216 if (lppd->Flags & PD_HIDEPRINTTOFILE)
1217 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
1219 } else { /* PD_PRINTSETUP */
1220 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
1222 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb2,
1223 PrintStructures->lpPrinterInfo->pPrinterName,
1224 PrintStructures->lpPrinterInfo->pPortName,
1226 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb3,
1227 PrintStructures->lpPrinterInfo->pPrinterName,
1228 PrintStructures->lpPrinterInfo->pPortName,
1230 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1231 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1232 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1233 PrintStructures->hLandscapeIcon));
1238 if ((lppd->Flags & PD_SHOWHELP)==0) {
1239 /* hide if PD_SHOWHELP not specified */
1240 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1245 /***********************************************************************
1246 * check_printer_setup [internal]
1248 static LRESULT check_printer_setup(HWND hDlg)
1251 WCHAR resourcestr[256],resultstr[256];
1253 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
1256 EnumPrintersW(PRINTER_ENUM_CONNECTIONS, NULL, 2, NULL, 0, &needed, &num);
1262 LoadStringW(COMDLG32_hInstance, PD32_NO_DEVICES,resultstr, 255);
1263 LoadStringW(COMDLG32_hInstance, PD32_PRINT_TITLE,resourcestr, 255);
1264 MessageBoxW(hDlg, resultstr, resourcestr,MB_OK | MB_ICONWARNING);
1269 /***********************************************************************
1270 * PRINTDLG_WMInitDialog [internal]
1272 static LRESULT PRINTDLG_WMInitDialog(HWND hDlg, WPARAM wParam,
1273 PRINT_PTRA* PrintStructures)
1275 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
1279 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1281 /* load Collate ICONs */
1282 /* We load these with LoadImage because they are not a standard
1283 size and we don't want them rescaled */
1284 PrintStructures->hCollateIcon =
1285 LoadImageA(COMDLG32_hInstance, "PD32_COLLATE", IMAGE_ICON, 0, 0, 0);
1286 PrintStructures->hNoCollateIcon =
1287 LoadImageA(COMDLG32_hInstance, "PD32_NOCOLLATE", IMAGE_ICON, 0, 0, 0);
1289 /* These can be done with LoadIcon */
1290 PrintStructures->hPortraitIcon =
1291 LoadIconA(COMDLG32_hInstance, "PD32_PORTRAIT");
1292 PrintStructures->hLandscapeIcon =
1293 LoadIconA(COMDLG32_hInstance, "PD32_LANDSCAPE");
1295 /* display the collate/no_collate icon */
1296 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1297 (LPARAM)PrintStructures->hNoCollateIcon);
1299 if(PrintStructures->hCollateIcon == 0 ||
1300 PrintStructures->hNoCollateIcon == 0 ||
1301 PrintStructures->hPortraitIcon == 0 ||
1302 PrintStructures->hLandscapeIcon == 0) {
1303 ERR("no icon in resourcefile\n");
1304 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1305 EndDialog(hDlg, FALSE);
1309 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1310 * must be registered and the Help button must be shown.
1312 if (lppd->Flags & PD_SHOWHELP) {
1313 if((PrintStructures->HelpMessageID =
1314 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
1315 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1319 PrintStructures->HelpMessageID = 0;
1321 if(!(lppd->Flags &PD_PRINTSETUP)) {
1322 PrintStructures->hwndUpDown =
1323 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1324 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1325 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1326 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1327 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1330 /* FIXME: I allow more freedom than either Win95 or WinNT,
1331 * which do not agree to what errors should be thrown or not
1332 * in case nToPage or nFromPage is out-of-range.
1334 if (lppd->nMaxPage < lppd->nMinPage)
1335 lppd->nMaxPage = lppd->nMinPage;
1336 if (lppd->nMinPage == lppd->nMaxPage)
1337 lppd->Flags |= PD_NOPAGENUMS;
1338 if (lppd->nToPage < lppd->nMinPage)
1339 lppd->nToPage = lppd->nMinPage;
1340 if (lppd->nToPage > lppd->nMaxPage)
1341 lppd->nToPage = lppd->nMaxPage;
1342 if (lppd->nFromPage < lppd->nMinPage)
1343 lppd->nFromPage = lppd->nMinPage;
1344 if (lppd->nFromPage > lppd->nMaxPage)
1345 lppd->nFromPage = lppd->nMaxPage;
1347 /* if we have the combo box, fill it */
1348 if (GetDlgItem(hDlg,comboID)) {
1351 pdn = GlobalLock(lppd->hDevNames);
1352 pdm = GlobalLock(lppd->hDevMode);
1354 name = (char*)pdn + pdn->wDeviceOffset;
1356 name = (char*)pdm->dmDeviceName;
1357 PRINTDLG_SetUpPrinterListComboA(hDlg, comboID, name);
1358 if(pdm) GlobalUnlock(lppd->hDevMode);
1359 if(pdn) GlobalUnlock(lppd->hDevNames);
1361 /* Now find selected printer and update rest of dlg */
1362 name = HeapAlloc(GetProcessHeap(),0,256);
1363 if (GetDlgItemTextA(hDlg, comboID, name, 255))
1364 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1365 HeapFree(GetProcessHeap(),0,name);
1367 /* else use default printer */
1369 DWORD dwBufLen = sizeof(name);
1370 BOOL ret = GetDefaultPrinterA(name, &dwBufLen);
1373 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1375 FIXME("No default printer found, expect problems!\n");
1380 static LRESULT PRINTDLG_WMInitDialogW(HWND hDlg, WPARAM wParam,
1381 PRINT_PTRW* PrintStructures)
1383 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1387 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1389 /* load Collate ICONs */
1390 /* We load these with LoadImage because they are not a standard
1391 size and we don't want them rescaled */
1392 PrintStructures->hCollateIcon =
1393 LoadImageW(COMDLG32_hInstance, pd32_collateW, IMAGE_ICON, 0, 0, 0);
1394 PrintStructures->hNoCollateIcon =
1395 LoadImageW(COMDLG32_hInstance, pd32_nocollateW, IMAGE_ICON, 0, 0, 0);
1397 /* These can be done with LoadIcon */
1398 PrintStructures->hPortraitIcon =
1399 LoadIconW(COMDLG32_hInstance, pd32_portraitW);
1400 PrintStructures->hLandscapeIcon =
1401 LoadIconW(COMDLG32_hInstance, pd32_landscapeW);
1403 /* display the collate/no_collate icon */
1404 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1405 (LPARAM)PrintStructures->hNoCollateIcon);
1407 if(PrintStructures->hCollateIcon == 0 ||
1408 PrintStructures->hNoCollateIcon == 0 ||
1409 PrintStructures->hPortraitIcon == 0 ||
1410 PrintStructures->hLandscapeIcon == 0) {
1411 ERR("no icon in resourcefile\n");
1412 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1413 EndDialog(hDlg, FALSE);
1417 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1418 * must be registered and the Help button must be shown.
1420 if (lppd->Flags & PD_SHOWHELP) {
1421 if((PrintStructures->HelpMessageID =
1422 RegisterWindowMessageW(HELPMSGSTRINGW)) == 0) {
1423 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1427 PrintStructures->HelpMessageID = 0;
1429 if(!(lppd->Flags &PD_PRINTSETUP)) {
1430 PrintStructures->hwndUpDown =
1431 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1432 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1433 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1434 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1435 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1438 /* FIXME: I allow more freedom than either Win95 or WinNT,
1439 * which do not agree to what errors should be thrown or not
1440 * in case nToPage or nFromPage is out-of-range.
1442 if (lppd->nMaxPage < lppd->nMinPage)
1443 lppd->nMaxPage = lppd->nMinPage;
1444 if (lppd->nMinPage == lppd->nMaxPage)
1445 lppd->Flags |= PD_NOPAGENUMS;
1446 if (lppd->nToPage < lppd->nMinPage)
1447 lppd->nToPage = lppd->nMinPage;
1448 if (lppd->nToPage > lppd->nMaxPage)
1449 lppd->nToPage = lppd->nMaxPage;
1450 if (lppd->nFromPage < lppd->nMinPage)
1451 lppd->nFromPage = lppd->nMinPage;
1452 if (lppd->nFromPage > lppd->nMaxPage)
1453 lppd->nFromPage = lppd->nMaxPage;
1455 /* if we have the combo box, fill it */
1456 if (GetDlgItem(hDlg,comboID)) {
1459 pdn = GlobalLock(lppd->hDevNames);
1460 pdm = GlobalLock(lppd->hDevMode);
1462 name = (WCHAR*)pdn + pdn->wDeviceOffset;
1464 name = pdm->dmDeviceName;
1465 PRINTDLG_SetUpPrinterListComboW(hDlg, comboID, name);
1466 if(pdm) GlobalUnlock(lppd->hDevMode);
1467 if(pdn) GlobalUnlock(lppd->hDevNames);
1469 /* Now find selected printer and update rest of dlg */
1470 /* ansi is ok here */
1471 name = HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR));
1472 if (GetDlgItemTextW(hDlg, comboID, name, 255))
1473 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1474 HeapFree(GetProcessHeap(),0,name);
1476 /* else use default printer */
1478 DWORD dwBufLen = sizeof(name) / sizeof(WCHAR);
1479 BOOL ret = GetDefaultPrinterW(name, &dwBufLen);
1482 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1484 FIXME("No default printer found, expect problems!\n");
1489 /***********************************************************************
1490 * PRINTDLG_WMCommand [internal]
1492 LRESULT PRINTDLG_WMCommandA(HWND hDlg, WPARAM wParam,
1493 LPARAM lParam, PRINT_PTRA* PrintStructures)
1495 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
1496 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1497 LPDEVMODEA lpdm = PrintStructures->lpDevMode;
1499 switch (LOWORD(wParam)) {
1501 TRACE(" OK button was hit\n");
1502 if (!PRINTDLG_UpdatePrintDlgA(hDlg, PrintStructures)) {
1503 FIXME("Update printdlg was not successful!\n");
1506 EndDialog(hDlg, TRUE);
1510 TRACE(" CANCEL button was hit\n");
1511 EndDialog(hDlg, FALSE);
1515 TRACE(" HELP button was hit\n");
1516 SendMessageA(lppd->hwndOwner, PrintStructures->HelpMessageID,
1517 (WPARAM) hDlg, (LPARAM) lppd);
1520 case chx2: /* collate pages checkbox */
1521 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1522 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1523 (LPARAM)PrintStructures->hCollateIcon);
1525 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1526 (LPARAM)PrintStructures->hNoCollateIcon);
1528 case edt1: /* from page nr editbox */
1529 case edt2: /* to page nr editbox */
1530 if (HIWORD(wParam)==EN_CHANGE) {
1533 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1534 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1535 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1536 CheckRadioButton(hDlg, rad1, rad3, rad3);
1541 if(HIWORD(wParam) == EN_CHANGE) {
1542 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1544 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1546 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1551 case psh1: /* Print Setup */
1555 if (!PrintStructures->dlg.lpPrintDlg16) {
1556 FIXME("The 32bit print dialog does not have this button!?\n");
1560 memcpy(&pdlg,PrintStructures->dlg.lpPrintDlg16,sizeof(pdlg));
1561 pdlg.Flags |= PD_PRINTSETUP;
1562 pdlg.hwndOwner = HWND_16(hDlg);
1563 if (!PrintDlg16(&pdlg))
1568 case psh2: /* Properties button */
1571 char PrinterName[256];
1573 GetDlgItemTextA(hDlg, PrinterComboID, PrinterName, 255);
1574 if (!OpenPrinterA(PrinterName, &hPrinter, NULL)) {
1575 FIXME(" Call to OpenPrinter did not succeed!\n");
1578 DocumentPropertiesA(hDlg, hPrinter, PrinterName,
1579 PrintStructures->lpDevMode,
1580 PrintStructures->lpDevMode,
1581 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1582 ClosePrinter(hPrinter);
1586 case rad1: /* Paperorientation */
1587 if (lppd->Flags & PD_PRINTSETUP)
1589 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1590 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1591 (LPARAM)(PrintStructures->hPortraitIcon));
1595 case rad2: /* Paperorientation */
1596 if (lppd->Flags & PD_PRINTSETUP)
1598 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1599 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1600 (LPARAM)(PrintStructures->hLandscapeIcon));
1604 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT16 */
1605 if (PrinterComboID != LOWORD(wParam)) {
1609 case cmb4: /* Printer combobox */
1610 if (HIWORD(wParam)==CBN_SELCHANGE) {
1611 char PrinterName[256];
1612 GetDlgItemTextA(hDlg, LOWORD(wParam), PrinterName, 255);
1613 PRINTDLG_ChangePrinterA(hDlg, PrinterName, PrintStructures);
1617 case cmb2: /* Papersize */
1619 DWORD Sel = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1621 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
1627 case cmb3: /* Bin */
1629 DWORD Sel = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1631 lpdm->u1.s1.dmDefaultSource = SendDlgItemMessageA(hDlg, cmb3,
1632 CB_GETITEMDATA, Sel,
1637 if(lppd->Flags & PD_PRINTSETUP) {
1638 switch (LOWORD(wParam)) {
1639 case rad1: /* orientation */
1641 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1642 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1643 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1644 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1646 (LPARAM)PrintStructures->hPortraitIcon);
1647 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1649 (LPARAM)PrintStructures->hPortraitIcon);
1652 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1653 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1654 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1656 (LPARAM)PrintStructures->hLandscapeIcon);
1657 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1659 (LPARAM)PrintStructures->hLandscapeIcon);
1668 static LRESULT PRINTDLG_WMCommandW(HWND hDlg, WPARAM wParam,
1669 LPARAM lParam, PRINT_PTRW* PrintStructures)
1671 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1672 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1673 LPDEVMODEW lpdm = PrintStructures->lpDevMode;
1675 switch (LOWORD(wParam)) {
1677 TRACE(" OK button was hit\n");
1678 if (!PRINTDLG_UpdatePrintDlgW(hDlg, PrintStructures)) {
1679 FIXME("Update printdlg was not successful!\n");
1682 EndDialog(hDlg, TRUE);
1686 TRACE(" CANCEL button was hit\n");
1687 EndDialog(hDlg, FALSE);
1691 TRACE(" HELP button was hit\n");
1692 SendMessageW(lppd->hwndOwner, PrintStructures->HelpMessageID,
1693 (WPARAM) hDlg, (LPARAM) lppd);
1696 case chx2: /* collate pages checkbox */
1697 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1698 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1699 (LPARAM)PrintStructures->hCollateIcon);
1701 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1702 (LPARAM)PrintStructures->hNoCollateIcon);
1704 case edt1: /* from page nr editbox */
1705 case edt2: /* to page nr editbox */
1706 if (HIWORD(wParam)==EN_CHANGE) {
1709 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1710 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1711 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1712 CheckRadioButton(hDlg, rad1, rad3, rad3);
1717 if(HIWORD(wParam) == EN_CHANGE) {
1718 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1720 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1722 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1726 case psh1: /* Print Setup */
1728 ERR("psh1 is called from 16bit code only, we should not get here.\n");
1731 case psh2: /* Properties button */
1734 WCHAR PrinterName[256];
1736 if (!GetDlgItemTextW(hDlg, PrinterComboID, PrinterName, 255)) break;
1737 if (!OpenPrinterW(PrinterName, &hPrinter, NULL)) {
1738 FIXME(" Call to OpenPrinter did not succeed!\n");
1741 DocumentPropertiesW(hDlg, hPrinter, PrinterName,
1742 PrintStructures->lpDevMode,
1743 PrintStructures->lpDevMode,
1744 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1745 ClosePrinter(hPrinter);
1749 case rad1: /* Paperorientation */
1750 if (lppd->Flags & PD_PRINTSETUP)
1752 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1753 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1754 (LPARAM)(PrintStructures->hPortraitIcon));
1758 case rad2: /* Paperorientation */
1759 if (lppd->Flags & PD_PRINTSETUP)
1761 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1762 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1763 (LPARAM)(PrintStructures->hLandscapeIcon));
1767 case cmb1: /* Printer Combobox in PRINT SETUP */
1769 case cmb4: /* Printer combobox */
1770 if (HIWORD(wParam)==CBN_SELCHANGE) {
1771 WCHAR PrinterName[256];
1772 GetDlgItemTextW(hDlg, LOWORD(wParam), PrinterName, 255);
1773 PRINTDLG_ChangePrinterW(hDlg, PrinterName, PrintStructures);
1777 case cmb2: /* Papersize */
1779 DWORD Sel = SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1781 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageW(hDlg, cmb2,
1787 case cmb3: /* Bin */
1789 DWORD Sel = SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1791 lpdm->u1.s1.dmDefaultSource = SendDlgItemMessageW(hDlg, cmb3,
1792 CB_GETITEMDATA, Sel,
1797 if(lppd->Flags & PD_PRINTSETUP) {
1798 switch (LOWORD(wParam)) {
1799 case rad1: /* orientation */
1801 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1802 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1803 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1804 SendDlgItemMessageW(hDlg, stc10, STM_SETIMAGE,
1806 (LPARAM)PrintStructures->hPortraitIcon);
1807 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE,
1809 (LPARAM)PrintStructures->hPortraitIcon);
1812 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1813 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1814 SendDlgItemMessageW(hDlg, stc10, STM_SETIMAGE,
1816 (LPARAM)PrintStructures->hLandscapeIcon);
1817 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE,
1819 (LPARAM)PrintStructures->hLandscapeIcon);
1828 /***********************************************************************
1829 * PrintDlgProcA [internal]
1831 static INT_PTR CALLBACK PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
1834 PRINT_PTRA* PrintStructures;
1835 INT_PTR res = FALSE;
1837 if (uMsg!=WM_INITDIALOG) {
1838 PrintStructures = GetPropW(hDlg, printdlg_prop);
1839 if (!PrintStructures)
1842 PrintStructures = (PRINT_PTRA*) lParam;
1843 SetPropW(hDlg, printdlg_prop, PrintStructures);
1844 if(!check_printer_setup(hDlg))
1846 EndDialog(hDlg,FALSE);
1849 res = PRINTDLG_WMInitDialog(hDlg, wParam, PrintStructures);
1851 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
1852 res = PrintStructures->lpPrintDlg->lpfnPrintHook(
1853 hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg
1858 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
1859 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam,
1866 return PRINTDLG_WMCommandA(hDlg, wParam, lParam, PrintStructures);
1869 DestroyIcon(PrintStructures->hCollateIcon);
1870 DestroyIcon(PrintStructures->hNoCollateIcon);
1871 DestroyIcon(PrintStructures->hPortraitIcon);
1872 DestroyIcon(PrintStructures->hLandscapeIcon);
1873 if(PrintStructures->hwndUpDown)
1874 DestroyWindow(PrintStructures->hwndUpDown);
1880 static INT_PTR CALLBACK PrintDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
1883 PRINT_PTRW* PrintStructures;
1884 INT_PTR res = FALSE;
1886 if (uMsg!=WM_INITDIALOG) {
1887 PrintStructures = GetPropW(hDlg, printdlg_prop);
1888 if (!PrintStructures)
1891 PrintStructures = (PRINT_PTRW*) lParam;
1892 SetPropW(hDlg, printdlg_prop, PrintStructures);
1893 if(!check_printer_setup(hDlg))
1895 EndDialog(hDlg,FALSE);
1898 res = PRINTDLG_WMInitDialogW(hDlg, wParam, PrintStructures);
1900 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
1901 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg);
1905 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
1906 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam, lParam);
1912 return PRINTDLG_WMCommandW(hDlg, wParam, lParam, PrintStructures);
1915 DestroyIcon(PrintStructures->hCollateIcon);
1916 DestroyIcon(PrintStructures->hNoCollateIcon);
1917 DestroyIcon(PrintStructures->hPortraitIcon);
1918 DestroyIcon(PrintStructures->hLandscapeIcon);
1919 if(PrintStructures->hwndUpDown)
1920 DestroyWindow(PrintStructures->hwndUpDown);
1926 /************************************************************
1928 * PRINTDLG_GetDlgTemplate
1931 static HGLOBAL PRINTDLG_GetDlgTemplateA(const PRINTDLGA *lppd)
1936 if (lppd->Flags & PD_PRINTSETUP) {
1937 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
1938 hDlgTmpl = lppd->hSetupTemplate;
1939 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
1940 hResInfo = FindResourceA(lppd->hInstance,
1941 lppd->lpSetupTemplateName, (LPSTR)RT_DIALOG);
1942 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1944 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32_SETUP",
1946 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1949 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
1950 hDlgTmpl = lppd->hPrintTemplate;
1951 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
1952 hResInfo = FindResourceA(lppd->hInstance,
1953 lppd->lpPrintTemplateName,
1955 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1957 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32",
1959 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1965 static HGLOBAL PRINTDLG_GetDlgTemplateW(const PRINTDLGW *lppd)
1969 static const WCHAR xpsetup[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
1970 static const WCHAR xprint[] = { 'P','R','I','N','T','3','2',0};
1972 if (lppd->Flags & PD_PRINTSETUP) {
1973 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
1974 hDlgTmpl = lppd->hSetupTemplate;
1975 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
1976 hResInfo = FindResourceW(lppd->hInstance,
1977 lppd->lpSetupTemplateName, (LPWSTR)RT_DIALOG);
1978 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1980 hResInfo = FindResourceW(COMDLG32_hInstance, xpsetup, (LPWSTR)RT_DIALOG);
1981 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1984 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
1985 hDlgTmpl = lppd->hPrintTemplate;
1986 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
1987 hResInfo = FindResourceW(lppd->hInstance,
1988 lppd->lpPrintTemplateName,
1990 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1992 hResInfo = FindResourceW(COMDLG32_hInstance, xprint, (LPWSTR)RT_DIALOG);
1993 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1999 /***********************************************************************
2004 static BOOL PRINTDLG_CreateDCA(LPPRINTDLGA lppd)
2006 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
2007 DEVMODEA *pdm = GlobalLock(lppd->hDevMode);
2009 if(lppd->Flags & PD_RETURNDC) {
2010 lppd->hDC = CreateDCA((char*)pdn + pdn->wDriverOffset,
2011 (char*)pdn + pdn->wDeviceOffset,
2012 (char*)pdn + pdn->wOutputOffset,
2014 } else if(lppd->Flags & PD_RETURNIC) {
2015 lppd->hDC = CreateICA((char*)pdn + pdn->wDriverOffset,
2016 (char*)pdn + pdn->wDeviceOffset,
2017 (char*)pdn + pdn->wOutputOffset,
2020 GlobalUnlock(lppd->hDevNames);
2021 GlobalUnlock(lppd->hDevMode);
2022 return lppd->hDC ? TRUE : FALSE;
2025 static BOOL PRINTDLG_CreateDCW(LPPRINTDLGW lppd)
2027 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
2028 DEVMODEW *pdm = GlobalLock(lppd->hDevMode);
2030 if(lppd->Flags & PD_RETURNDC) {
2031 lppd->hDC = CreateDCW((WCHAR*)pdn + pdn->wDriverOffset,
2032 (WCHAR*)pdn + pdn->wDeviceOffset,
2033 (WCHAR*)pdn + pdn->wOutputOffset,
2035 } else if(lppd->Flags & PD_RETURNIC) {
2036 lppd->hDC = CreateICW((WCHAR*)pdn + pdn->wDriverOffset,
2037 (WCHAR*)pdn + pdn->wDeviceOffset,
2038 (WCHAR*)pdn + pdn->wOutputOffset,
2041 GlobalUnlock(lppd->hDevNames);
2042 GlobalUnlock(lppd->hDevMode);
2043 return lppd->hDC ? TRUE : FALSE;
2046 /***********************************************************************
2047 * PrintDlgA (COMDLG32.@)
2049 * Displays the PRINT dialog box, which enables the user to specify
2050 * specific properties of the print job.
2053 * lppd [IO] ptr to PRINTDLG32 struct
2056 * nonzero if the user pressed the OK button
2057 * zero if the user cancelled the window or an error occurred
2061 * * The Collate Icons do not display, even though they are in the code.
2062 * * The Properties Button(s) should call DocumentPropertiesA().
2065 BOOL WINAPI PrintDlgA(LPPRINTDLGA lppd)
2073 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION);
2077 hInst = (HINSTANCE)GetWindowLongPtrA( lppd->hwndOwner, GWLP_HINSTANCE );
2078 if(TRACE_ON(commdlg)) {
2079 char flagstr[1000] = "";
2080 const struct pd_flags *pflag = pd_flags;
2081 for( ; pflag->name; pflag++) {
2082 if(lppd->Flags & pflag->flag)
2083 strcat(flagstr, pflag->name);
2085 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2086 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2087 "flags %08x (%s)\n",
2088 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2089 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2090 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2093 if(lppd->lStructSize != sizeof(PRINTDLGA)) {
2094 WARN("structure size failure !!!\n");
2095 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2099 if(lppd->Flags & PD_RETURNDEFAULT) {
2100 PRINTER_INFO_2A *pbuf;
2101 DRIVER_INFO_3A *dbuf;
2105 if(lppd->hDevMode || lppd->hDevNames) {
2106 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2107 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2110 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2111 WARN("Can't find default printer\n");
2112 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2116 GetPrinterA(hprn, 2, NULL, 0, &needed);
2117 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
2118 GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2120 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
2121 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
2122 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2123 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2124 GetLastError(),pbuf->pPrinterName);
2125 HeapFree(GetProcessHeap(), 0, dbuf);
2126 HeapFree(GetProcessHeap(), 0, pbuf);
2127 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2132 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2136 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2137 pbuf->pDevMode->dmDriverExtra);
2138 ptr = GlobalLock(lppd->hDevMode);
2139 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2140 pbuf->pDevMode->dmDriverExtra);
2141 GlobalUnlock(lppd->hDevMode);
2142 HeapFree(GetProcessHeap(), 0, pbuf);
2143 HeapFree(GetProcessHeap(), 0, dbuf);
2147 PRINT_PTRA *PrintStructures;
2149 /* load Dialog resources,
2150 * depending on Flags indicates Print32 or Print32_setup dialog
2152 hDlgTmpl = PRINTDLG_GetDlgTemplateA(lppd);
2154 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2157 ptr = LockResource( hDlgTmpl );
2159 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2163 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2164 sizeof(PRINT_PTRA));
2165 PrintStructures->lpPrintDlg = lppd;
2167 /* and create & process the dialog .
2168 * -1 is failure, 0 is broken hwnd, everything else is ok.
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 hInst = (HINSTANCE)GetWindowLongPtrW( lppd->hwndOwner, GWLP_HINSTANCE );
2228 if(TRACE_ON(commdlg)) {
2229 char flagstr[1000] = "";
2230 const struct pd_flags *pflag = pd_flags;
2231 for( ; pflag->name; pflag++) {
2232 if(lppd->Flags & pflag->flag)
2233 strcat(flagstr, pflag->name);
2235 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2236 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2237 "flags %08x (%s)\n",
2238 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2239 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2240 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2243 if(lppd->lStructSize != sizeof(PRINTDLGW)) {
2244 WARN("structure size failure !!!\n");
2245 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2249 if(lppd->Flags & PD_RETURNDEFAULT) {
2250 PRINTER_INFO_2W *pbuf;
2251 DRIVER_INFO_3W *dbuf;
2255 if(lppd->hDevMode || lppd->hDevNames) {
2256 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2257 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2260 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2261 WARN("Can't find default printer\n");
2262 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2266 GetPrinterW(hprn, 2, NULL, 0, &needed);
2267 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
2268 GetPrinterW(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2270 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
2271 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
2272 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2273 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2274 GetLastError(),debugstr_w(pbuf->pPrinterName));
2275 HeapFree(GetProcessHeap(), 0, dbuf);
2276 HeapFree(GetProcessHeap(), 0, pbuf);
2277 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2282 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2286 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2287 pbuf->pDevMode->dmDriverExtra);
2288 ptr = GlobalLock(lppd->hDevMode);
2289 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2290 pbuf->pDevMode->dmDriverExtra);
2291 GlobalUnlock(lppd->hDevMode);
2292 HeapFree(GetProcessHeap(), 0, pbuf);
2293 HeapFree(GetProcessHeap(), 0, dbuf);
2297 PRINT_PTRW *PrintStructures;
2299 /* load Dialog resources,
2300 * depending on Flags indicates Print32 or Print32_setup dialog
2302 hDlgTmpl = PRINTDLG_GetDlgTemplateW(lppd);
2304 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2307 ptr = LockResource( hDlgTmpl );
2309 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2313 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2314 sizeof(PRINT_PTRW));
2315 PrintStructures->lpPrintDlg = lppd;
2317 /* and create & process the dialog .
2318 * -1 is failure, 0 is broken hwnd, everything else is ok.
2320 bRet = (0<DialogBoxIndirectParamW(hInst, ptr, lppd->hwndOwner,
2322 (LPARAM)PrintStructures));
2325 DEVMODEW *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2326 PRINTER_INFO_2W *pi = PrintStructures->lpPrinterInfo;
2327 DRIVER_INFO_3W *di = PrintStructures->lpDriverInfo;
2329 if (lppd->hDevMode == 0) {
2330 TRACE(" No hDevMode yet... Need to create my own\n");
2331 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2332 lpdm->dmSize + lpdm->dmDriverExtra);
2335 if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
2336 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2338 GlobalUnlock(lppd->hDevMode);
2339 TRACE("Now got %d locks\n", locks);
2342 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2343 lpdm->dmSize + lpdm->dmDriverExtra,
2346 lpdmReturn = GlobalLock(lppd->hDevMode);
2347 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2349 if (lppd->hDevNames != 0) {
2351 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
2352 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2354 GlobalUnlock(lppd->hDevNames);
2357 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2362 GlobalUnlock(lppd->hDevMode);
2364 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2365 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2366 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2367 HeapFree(GetProcessHeap(), 0, PrintStructures);
2369 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2370 bRet = PRINTDLG_CreateDCW(lppd);
2372 TRACE("exit! (%d)\n", bRet);
2376 /***********************************************************************
2381 * cmb1 - printer select (not in standard dialog template)
2383 * cmb3 - source (tray?)
2384 * edt4 - border left
2386 * edt6 - border right
2387 * edt7 - border bottom
2388 * psh3 - "Printer..."
2393 LPPAGESETUPDLGA dlga; /* Handler to user defined struct */
2394 HWND hDlg; /* Page Setup dialog handler */
2395 RECT rtDrawRect; /* Drawing rect for page */
2399 LPPAGESETUPDLGW dlgw;
2401 PAGESETUPDLGW curdlg; /* Current dialog state */
2405 static HGLOBAL PRINTDLG_GetPGSTemplateA(const PAGESETUPDLGA *lppd)
2410 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2411 hDlgTmpl = lppd->hPageSetupTemplate;
2412 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2413 hResInfo = FindResourceA(lppd->hInstance,
2414 lppd->lpPageSetupTemplateName, (LPSTR)RT_DIALOG);
2415 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2417 hResInfo = FindResourceA(COMDLG32_hInstance,(LPCSTR)PAGESETUPDLGORD,(LPSTR)RT_DIALOG);
2418 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2423 static HGLOBAL PRINTDLG_GetPGSTemplateW(const PAGESETUPDLGW *lppd)
2428 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2429 hDlgTmpl = lppd->hPageSetupTemplate;
2430 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2431 hResInfo = FindResourceW(lppd->hInstance,
2432 lppd->lpPageSetupTemplateName, (LPWSTR)RT_DIALOG);
2433 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2435 hResInfo = FindResourceW(COMDLG32_hInstance,(LPCWSTR)PAGESETUPDLGORD,(LPWSTR)RT_DIALOG);
2436 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2441 static inline DWORD pagesetup_get_flags(const pagesetup_data *data)
2443 return data->dlga->Flags;
2446 static inline BOOL is_metric(const pagesetup_data *data)
2448 return pagesetup_get_flags(data) & PSD_INHUNDREDTHSOFMILLIMETERS;
2451 static inline LONG tenths_mm_to_size(pagesetup_data *data, LONG size)
2453 if (is_metric(data))
2456 return 10 * size * 100 / 254;
2459 static inline LONG thousandths_inch_to_size(pagesetup_data *data, LONG size)
2461 if (is_metric(data))
2462 return size * 254 / 100;
2468 _c_10mm2size(PAGESETUPDLGW *dlga,DWORD size) {
2469 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2470 return 10*size*100/254;
2476 _c_inch2size(PAGESETUPDLGW *dlga,DWORD size) {
2477 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2480 return (size*254)/100;
2483 static WCHAR get_decimal_sep(void)
2489 WCHAR buf[2] = {'.',0};
2490 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, buf, sizeof(buf) / sizeof(buf[0]));
2496 static void size2str(const pagesetup_data *data, DWORD size, LPWSTR strout)
2498 WCHAR integer_fmt[] = {'%','d',0};
2499 WCHAR hundredths_fmt[] = {'%','d','%','c','%','0','2','d',0};
2500 WCHAR thousandths_fmt[] = {'%','d','%','c','%','0','3','d',0};
2502 /* FIXME use LOCALE_SDECIMAL when the edit parsing code can cope */
2504 if (is_metric(data))
2507 wsprintfW(strout, hundredths_fmt, size / 100, get_decimal_sep(), size % 100);
2509 wsprintfW(strout, integer_fmt, size / 100);
2514 wsprintfW(strout, thousandths_fmt, size / 1000, get_decimal_sep(), size % 1000);
2516 wsprintfW(strout, integer_fmt, size / 1000);
2522 _c_size2strW(PageSetupDataW *pdw,DWORD size,LPWSTR strout) {
2523 static const char mm_fmt[] = "%.2f mm";
2524 static const char in_fmt[] = "%.2f in";
2526 if (pdw->dlgw->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2527 sprintf(buf, mm_fmt, (size * 1.0) / 100.0);
2528 } else if (pdw->dlgw->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2529 sprintf(buf, in_fmt, (size * 1.0) / 1000.0);
2531 pdw->dlgw->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2532 sprintf(buf, mm_fmt, (size * 1.0) / 100.0);
2535 MultiByteToWideChar(CP_ACP, 0, buf, -1, strout, 20);
2539 _c_str2sizeA(const PAGESETUPDLGA *dlga, LPCSTR strin) {
2544 if (!sscanf(strin,"%f%s",&val,rest))
2547 if (!strcmp(rest,"in") || !strcmp(rest,"inch")) {
2548 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2551 return val*25.4*100;
2553 if (!strcmp(rest,"cm")) { rest[0]='m'; val = val*10.0; }
2554 if (!strcmp(rest,"m")) { strcpy(rest,"mm"); val = val*1000.0; }
2556 if (!strcmp(rest,"mm")) {
2557 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
2560 return 1000.0*val/25.4;
2562 if (rest[0]=='\0') {
2563 /* use application supplied default */
2564 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2568 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2573 ERR("Did not find a conversion for type '%s'!\n",rest);
2579 _c_str2sizeW(const PAGESETUPDLGW *dlga, LPCWSTR strin) {
2582 /* this W -> A transition is OK */
2583 /* we need a unicode version of sscanf to avoid it */
2584 WideCharToMultiByte(CP_ACP, 0, strin, -1, buf, sizeof(buf), NULL, NULL);
2585 return _c_str2sizeA((const PAGESETUPDLGA *)dlga, buf);
2588 static inline BOOL is_default_metric(void)
2591 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IMEASURE | LOCALE_RETURN_NUMBER,
2592 (LPWSTR)&system, sizeof(system));
2596 /**********************************************
2598 * Cyclically permute the four members of rc
2599 * If sense is TRUE l -> t -> r -> b
2600 * otherwise l <- t <- r <- b
2602 static inline void rotate_rect(RECT *rc, BOOL sense)
2608 rc->bottom = rc->right;
2609 rc->right = rc->top;
2617 rc->top = rc->right;
2618 rc->right = rc->bottom;
2623 static void pagesetup_set_orientation(pagesetup_data *data, WORD orient)
2625 DEVMODEA *dm = GlobalLock(data->dlga->hDevMode);
2627 assert(orient == DMORIENT_PORTRAIT || orient == DMORIENT_LANDSCAPE);
2629 dm->u1.s1.dmOrientation = orient;
2630 GlobalUnlock(data->dlga->hDevMode);
2633 static WORD pagesetup_get_orientation(const pagesetup_data *data)
2635 DEVMODEA *dm = GlobalLock(data->dlga->hDevMode);
2636 WORD orient = dm->u1.s1.dmOrientation;
2637 GlobalUnlock(data->dlga->hDevMode);
2641 static void pagesetup_set_papersize(pagesetup_data *data, WORD paper)
2643 DEVMODEA *dm = GlobalLock(data->dlga->hDevMode);
2644 dm->u1.s1.dmPaperSize = paper;
2645 GlobalUnlock(data->dlga->hDevMode);
2648 static WORD pagesetup_get_papersize(const pagesetup_data *data)
2650 DEVMODEA *dm = GlobalLock(data->dlga->hDevMode);
2651 WORD paper = dm->u1.s1.dmPaperSize;
2652 GlobalUnlock(data->dlga->hDevMode);
2656 static void pagesetup_set_defaultsource(pagesetup_data *data, WORD source)
2658 DEVMODEA *dm = GlobalLock(data->dlga->hDevMode);
2659 dm->u1.s1.dmDefaultSource = source;
2660 GlobalUnlock(data->dlga->hDevMode);
2663 static WCHAR *pagesetup_get_drvname(const pagesetup_data *data)
2669 dn = GlobalLock(data->dlga->hDevNames);
2670 len = MultiByteToWideChar(CP_ACP, 0, (char*)dn + dn->wDriverOffset, -1, NULL, 0);
2671 name = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
2672 MultiByteToWideChar(CP_ACP, 0, (char*)dn + dn->wDriverOffset, -1, name, len);
2673 GlobalUnlock(data->dlga->hDevNames);
2677 static void pagesetup_release_drvname(const pagesetup_data *data, WCHAR *name)
2679 HeapFree(GetProcessHeap(), 0, name);
2682 static WCHAR *pagesetup_get_devname(const pagesetup_data *data)
2688 dn = GlobalLock(data->dlga->hDevNames);
2689 len = MultiByteToWideChar(CP_ACP, 0, (char*)dn + dn->wDeviceOffset, -1, NULL, 0);
2690 name = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
2691 MultiByteToWideChar(CP_ACP, 0, (char*)dn + dn->wDeviceOffset, -1, name, len);
2692 GlobalUnlock(data->dlga->hDevNames);
2696 static void pagesetup_release_devname(const pagesetup_data *data, WCHAR *name)
2698 HeapFree(GetProcessHeap(), 0, name);
2701 static WCHAR *pagesetup_get_portname(const pagesetup_data *data)
2707 dn = GlobalLock(data->dlga->hDevNames);
2708 len = MultiByteToWideChar(CP_ACP, 0, (char*)dn + dn->wOutputOffset, -1, NULL, 0);
2709 name = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
2710 MultiByteToWideChar(CP_ACP, 0, (char*)dn + dn->wOutputOffset, -1, name, len);
2711 GlobalUnlock(data->dlga->hDevNames);
2715 static void pagesetup_release_portname(const pagesetup_data *data, WCHAR *name)
2717 HeapFree(GetProcessHeap(), 0, name);
2720 static void pagesetup_set_devnames(pagesetup_data *data, LPCWSTR drv, LPCWSTR devname, LPCWSTR port)
2725 DWORD len = sizeof(DEVNAMES), drv_len, dev_len, port_len;
2726 drv_len = WideCharToMultiByte(CP_ACP, 0, drv, -1, NULL, 0, NULL, NULL);
2727 dev_len = WideCharToMultiByte(CP_ACP, 0, devname, -1, NULL, 0, NULL, NULL);
2728 port_len = WideCharToMultiByte(CP_ACP, 0, port, -1, NULL, 0, NULL, NULL);
2730 len += drv_len + dev_len + port_len;
2732 data->dlga->hDevNames = GlobalReAlloc(data->dlga->hDevNames, len, GMEM_MOVEABLE);
2733 dn = GlobalLock(data->dlga->hDevNames);
2735 ptr = (char *)(dn + 1);
2736 len = sizeof(DEVNAMES);
2737 dn->wDriverOffset = len;
2738 WideCharToMultiByte(CP_ACP, 0, drv, -1, ptr, drv_len, NULL, NULL);
2741 dn->wDeviceOffset = len;
2742 WideCharToMultiByte(CP_ACP, 0, devname, -1, ptr, dev_len, NULL, NULL);
2745 dn->wOutputOffset = len;
2746 WideCharToMultiByte(CP_ACP, 0, port, -1, ptr, port_len, NULL, NULL);
2749 len = sizeof(def) / sizeof(def[0]);
2750 GetDefaultPrinterW(def, &len);
2751 if(!lstrcmpW(def, devname))
2754 GlobalUnlock(data->dlga->hDevNames);
2757 static DEVMODEW *pagesetup_get_devmode(const pagesetup_data *data)
2762 dm = GlobalLock(data->dlga->hDevMode);
2763 dmW = GdiConvertToDevmodeW(dm);
2764 GlobalUnlock(data->dlga->hDevMode);
2768 static void pagesetup_release_devmode(const pagesetup_data *data, DEVMODEW *dm)
2770 HeapFree(GetProcessHeap(), 0, dm);
2773 static void pagesetup_set_devmode(pagesetup_data *data, DEVMODEW *dm)
2775 DEVMODEA *dmA, *tmp_dm;
2777 tmp_dm = convert_to_devmodeA(dm);
2778 data->dlga->hDevMode = GlobalReAlloc(data->dlga->hDevMode,
2779 tmp_dm->dmSize + tmp_dm->dmDriverExtra,
2781 dmA = GlobalLock(data->dlga->hDevMode);
2782 memcpy(dmA, tmp_dm, tmp_dm->dmSize + tmp_dm->dmDriverExtra);
2783 GlobalUnlock(data->dlga->hDevMode);
2784 HeapFree(GetProcessHeap(), 0, tmp_dm);
2787 static inline POINT *pagesetup_get_papersize_pt(const pagesetup_data *data)
2789 return &data->dlga->ptPaperSize;
2792 static inline RECT *pagesetup_get_margin_rect(const pagesetup_data *data)
2794 return &data->dlga->rtMargin;
2797 static inline void swap_point(POINT *pt)
2804 static BOOL pagesetup_update_papersize(pagesetup_data *data)
2807 LPWSTR devname, portname;
2809 WORD *words = NULL, paperword;
2810 POINT *points = NULL;
2811 BOOL retval = FALSE;
2813 dm = pagesetup_get_devmode(data);
2814 devname = pagesetup_get_devname(data);
2815 portname = pagesetup_get_portname(data);
2817 num = DeviceCapabilitiesW(devname, portname, DC_PAPERS, NULL, dm);
2820 FIXME("No papernames found for %s/%s\n", debugstr_w(devname), debugstr_w(portname));
2824 words = HeapAlloc(GetProcessHeap(), 0, num * sizeof(WORD));
2825 points = HeapAlloc(GetProcessHeap(), 0, num * sizeof(POINT));
2827 if (num != DeviceCapabilitiesW(devname, portname, DC_PAPERS, (LPWSTR)words, dm))
2829 FIXME("Number of returned words is not %d\n", num);
2833 if (num != DeviceCapabilitiesW(devname, portname, DC_PAPERSIZE, (LPWSTR)points, dm))
2835 FIXME("Number of returned sizes is not %d\n", num);
2839 paperword = pagesetup_get_papersize(data);
2841 for (i = 0; i < num; i++)
2842 if (words[i] == paperword)
2847 FIXME("Papersize %d not found in list?\n", paperword);
2851 /* this is _10ths_ of a millimeter */
2852 pagesetup_get_papersize_pt(data)->x = tenths_mm_to_size(data, points[i].x);
2853 pagesetup_get_papersize_pt(data)->y = tenths_mm_to_size(data, points[i].y);
2855 if(pagesetup_get_orientation(data) == DMORIENT_LANDSCAPE)
2856 swap_point(pagesetup_get_papersize_pt(data));
2861 HeapFree(GetProcessHeap(), 0, words);
2862 HeapFree(GetProcessHeap(), 0, points);
2863 pagesetup_release_portname(data, portname);
2864 pagesetup_release_devname(data, devname);
2865 pagesetup_release_devmode(data, dm);
2871 PRINTDLG_PS_UpdateDlgStructW(HWND hDlg, PageSetupDataW *pdw) {
2874 LPWSTR devname,portname;
2875 WCHAR papername[64];
2878 dn = GlobalLock(pdw->pdlg.hDevNames);
2879 dm = GlobalLock(pdw->pdlg.hDevMode);
2880 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
2881 portname = ((WCHAR*)dn)+dn->wOutputOffset;
2883 /* Save paper size into device context */
2884 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
2885 /* Save paper source into device context */
2886 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
2888 if (GetDlgItemTextW(hDlg,cmb2,papername,sizeof(papername)/sizeof(papername[0]))>0) {
2889 PRINTDLG_PaperSizeW(&(pdw->pdlg),papername,&(pdw->dlgw->ptPaperSize));
2890 pdw->dlgw->ptPaperSize.x = _c_10mm2size(pdw->dlgw,pdw->dlgw->ptPaperSize.x);
2891 pdw->dlgw->ptPaperSize.y = _c_10mm2size(pdw->dlgw,pdw->dlgw->ptPaperSize.y);
2893 FIXME("could not get dialog text for papersize cmbbox?\n");
2894 #define GETVAL(id,val) if (GetDlgItemTextW(hDlg,id,buf,sizeof(buf)/sizeof(buf[0]))>0) { val = _c_str2sizeW(pdw->dlgw,buf); } else { FIXME("could not get dlgitemtextw for %x\n",id); }
2895 GETVAL(edt4,pdw->dlgw->rtMargin.left);
2896 GETVAL(edt5,pdw->dlgw->rtMargin.top);
2897 GETVAL(edt6,pdw->dlgw->rtMargin.right);
2898 GETVAL(edt7,pdw->dlgw->rtMargin.bottom);
2901 /* If we are in landscape, swap x and y of page size */
2902 if (IsDlgButtonChecked(hDlg, rad2)) {
2904 tmp = pdw->dlgw->ptPaperSize.x;
2905 pdw->dlgw->ptPaperSize.x = pdw->dlgw->ptPaperSize.y;
2906 pdw->dlgw->ptPaperSize.y = tmp;
2909 /* Save orientation */
2910 if (pdw->dlgw->ptPaperSize.x > pdw->dlgw->ptPaperSize.y)
2911 dm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
2913 dm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
2915 GlobalUnlock(pdw->pdlg.hDevNames);
2916 GlobalUnlock(pdw->pdlg.hDevMode);
2920 /**********************************************************************************************
2921 * pagesetup_change_printer
2923 * Redefines hDevMode and hDevNames HANDLES and initialises it.
2926 static BOOL pagesetup_change_printer(LPWSTR name, pagesetup_data *data)
2930 PRINTER_INFO_2W *prn_info = NULL;
2931 DRIVER_INFO_3W *drv_info = NULL;
2932 DEVMODEW *dm = NULL;
2933 BOOL retval = FALSE;
2935 if(!OpenPrinterW(name, &hprn, NULL))
2937 ERR("Can't open printer %s\n", debugstr_w(name));
2941 GetPrinterW(hprn, 2, NULL, 0, &needed);
2942 prn_info = HeapAlloc(GetProcessHeap(), 0, needed);
2943 GetPrinterW(hprn, 2, (LPBYTE)prn_info, needed, &needed);
2944 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
2945 drv_info = HeapAlloc(GetProcessHeap(), 0, needed);
2946 if(!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)drv_info, needed, &needed))
2948 ERR("GetPrinterDriverA failed for %s, fix your config!\n", debugstr_w(prn_info->pPrinterName));
2953 needed = DocumentPropertiesW(0, 0, name, NULL, NULL, 0);
2956 ERR("DocumentProperties fails on %s\n", debugstr_w(name));
2960 dm = HeapAlloc(GetProcessHeap(), 0, needed);
2961 DocumentPropertiesW(0, 0, name, dm, NULL, DM_OUT_BUFFER);
2963 pagesetup_set_devmode(data, dm);
2964 pagesetup_set_devnames(data, drv_info->pDriverPath, prn_info->pPrinterName,
2965 prn_info->pPortName);
2969 HeapFree(GetProcessHeap(), 0, dm);
2970 HeapFree(GetProcessHeap(), 0, prn_info);
2971 HeapFree(GetProcessHeap(), 0, drv_info);
2975 /****************************************************************************************
2976 * pagesetup_init_combos
2978 * Fills Printers, Paper and Source combos
2981 static void pagesetup_init_combos(HWND hDlg, pagesetup_data *data)
2984 LPWSTR devname, portname;
2986 dm = pagesetup_get_devmode(data);
2987 devname = pagesetup_get_devname(data);
2988 portname = pagesetup_get_portname(data);
2990 PRINTDLG_SetUpPrinterListComboW(hDlg, cmb1, devname);
2991 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb2, devname, portname, dm);
2992 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb3, devname, portname, dm);
2994 pagesetup_release_portname(data, portname);
2995 pagesetup_release_devname(data, devname);
2996 pagesetup_release_devmode(data, dm);
3000 /****************************************************************************************
3001 * pagesetup_change_printer_dialog
3003 * Pops up another dialog that lets the user pick another printer.
3005 * For now we display the PrintDlg, this should display a striped down version of it.
3007 static void pagesetup_change_printer_dialog(HWND hDlg, pagesetup_data *data)
3010 LPWSTR drvname, devname, portname;
3011 DEVMODEW *tmp_dm, *dm;
3013 memset(&prnt, 0, sizeof(prnt));
3014 prnt.lStructSize = sizeof(prnt);
3016 prnt.hwndOwner = hDlg;
3018 drvname = pagesetup_get_drvname(data);
3019 devname = pagesetup_get_devname(data);
3020 portname = pagesetup_get_portname(data);
3022 PRINTDLG_CreateDevNamesW(&prnt.hDevNames, drvname, devname, portname);
3023 pagesetup_release_portname(data, portname);
3024 pagesetup_release_devname(data, devname);
3025 pagesetup_release_drvname(data, drvname);
3027 tmp_dm = pagesetup_get_devmode(data);
3028 prnt.hDevMode = GlobalAlloc(GMEM_MOVEABLE, tmp_dm->dmSize + tmp_dm->dmDriverExtra);
3029 dm = GlobalLock(prnt.hDevMode);
3030 memcpy(dm, tmp_dm, tmp_dm->dmSize + tmp_dm->dmDriverExtra);
3031 GlobalUnlock(prnt.hDevMode);
3032 pagesetup_release_devmode(data, tmp_dm);
3034 if (PrintDlgW(&prnt))
3036 DEVMODEW *dm = GlobalLock(prnt.hDevMode);
3037 DEVNAMES *dn = GlobalLock(prnt.hDevNames);
3039 pagesetup_set_devnames(data, (WCHAR*)dn + dn->wDriverOffset,
3040 (WCHAR*)dn + dn->wDeviceOffset, (WCHAR *)dn + dn->wOutputOffset);
3041 pagesetup_set_devmode(data, dm);
3042 GlobalUnlock(prnt.hDevNames);
3043 GlobalUnlock(prnt.hDevMode);
3044 pagesetup_init_combos(hDlg, data);
3047 GlobalFree(prnt.hDevMode);
3048 GlobalFree(prnt.hDevNames);
3052 static void PRINTDLG_PS_SetOrientationW(HWND hDlg, PageSetupDataW* pdw)
3054 WCHAR PaperName[64];
3056 GetDlgItemTextW(hDlg, cmb2, PaperName, sizeof(PaperName)/sizeof(WCHAR));
3057 PRINTDLG_PaperSizeW(&pdw->pdlg, PaperName, &pdw->curdlg.ptPaperSize);
3058 pdw->curdlg.ptPaperSize.x = _c_10mm2size(pdw->dlgw, pdw->curdlg.ptPaperSize.x);
3059 pdw->curdlg.ptPaperSize.y = _c_10mm2size(pdw->dlgw, pdw->curdlg.ptPaperSize.y);
3061 if(IsDlgButtonChecked(hDlg, rad2))
3063 DWORD tmp = pdw->curdlg.ptPaperSize.x;
3064 pdw->curdlg.ptPaperSize.x = pdw->curdlg.ptPaperSize.y;
3065 pdw->curdlg.ptPaperSize.y = tmp;
3069 static void PRINTDLG_PS_UpdatePrintDlgW(PageSetupDataW* pdw, HWND hDlg)
3074 dm = GlobalLock(pdw->pdlg.hDevMode);
3079 if(pdw->curdlg.ptPaperSize.y > pdw->curdlg.ptPaperSize.x)
3080 dm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
3082 dm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
3084 sel = SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0);
3087 dm->u1.s1.dmPaperSize = SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, sel, 0);
3089 GlobalUnlock(pdw->pdlg.hDevMode);
3093 PRINTDLG_PS_ChangePrinterW(HWND hDlg, PageSetupDataW *pdw) {
3096 LPWSTR devname,portname;
3098 dn = GlobalLock(pdw->pdlg.hDevNames);
3099 dm = GlobalLock(pdw->pdlg.hDevMode);
3100 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
3101 portname = ((WCHAR*)dn)+dn->wOutputOffset;
3102 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
3103 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
3105 /* Landscape orientation */
3106 if (dm->u1.s1.dmOrientation == DMORIENT_LANDSCAPE)
3107 CheckRadioButton(hDlg, rad1, rad2, rad2);
3108 else /* this is default if papersize is not set */
3109 CheckRadioButton(hDlg, rad1, rad2, rad1);
3111 GlobalUnlock(pdw->pdlg.hDevNames);
3112 GlobalUnlock(pdw->pdlg.hDevMode);
3114 PRINTDLG_PS_SetOrientationW(hDlg, pdw);
3119 /******************************************************************************************
3120 * pagesetup_change_preview
3122 * Changes paper preview size / position
3125 static void pagesetup_change_preview(const pagesetup_data *data)
3127 LONG width, height, x, y;
3129 const int shadow = 4;
3131 if(pagesetup_get_orientation(data) == DMORIENT_LANDSCAPE)
3133 width = data->rtDrawRect.right - data->rtDrawRect.left;
3134 height = pagesetup_get_papersize_pt(data)->y * width / pagesetup_get_papersize_pt(data)->x;
3138 height = data->rtDrawRect.bottom - data->rtDrawRect.top;
3139 width = pagesetup_get_papersize_pt(data)->x * height / pagesetup_get_papersize_pt(data)->y;
3141 x = (data->rtDrawRect.right + data->rtDrawRect.left - width) / 2;
3142 y = (data->rtDrawRect.bottom + data->rtDrawRect.top - height) / 2;
3143 TRACE("draw rect %s x=%d, y=%d, w=%d, h=%d\n",
3144 wine_dbgstr_rect(&data->rtDrawRect), x, y, width, height);
3146 MoveWindow(GetDlgItem(data->hDlg, rct2), x + width, y + shadow, shadow, height, FALSE);
3147 MoveWindow(GetDlgItem(data->hDlg, rct3), x + shadow, y + height, width, shadow, FALSE);
3148 MoveWindow(GetDlgItem(data->hDlg, rct1), x, y, width, height, FALSE);
3150 tmp = data->rtDrawRect;
3151 tmp.right += shadow;
3152 tmp.bottom += shadow;
3153 InvalidateRect(data->hDlg, &tmp, TRUE);
3156 static inline LONG *element_from_margin_id(RECT *rc, WORD id)
3160 case edt4: return &rc->left;
3161 case edt5: return &rc->top;
3162 case edt6: return &rc->right;
3163 case edt7: return &rc->bottom;
3168 static void update_margin_edits(HWND hDlg, const pagesetup_data *data, WORD id)
3173 for(idx = edt4; idx <= edt7; idx++)
3175 if(id == 0 || id == idx)
3177 size2str(data, *element_from_margin_id(pagesetup_get_margin_rect(data), idx), str);
3178 SetDlgItemTextW(hDlg, idx, str);
3183 static void margin_edit_notification(HWND hDlg, pagesetup_data *data, WORD msg, WORD id)
3191 LONG *value = element_from_margin_id(pagesetup_get_margin_rect(data), id);
3193 if (GetDlgItemTextW(hDlg, id, buf, sizeof(buf) / sizeof(buf[0])) != 0)
3196 WCHAR decimal = get_decimal_sep();
3198 val = strtolW(buf, &end, 10);
3199 if(end != buf || *end == decimal)
3201 int mult = is_metric(data) ? 100 : 1000;
3210 val += (*end - '0') * mult;
3222 update_margin_edits(hDlg, data, id);
3227 static void set_margin_groupbox_title(HWND hDlg, const pagesetup_data *data)
3231 if(LoadStringW(COMDLG32_hInstance, is_metric(data) ? PD32_MARGINS_IN_MILLIMETERS : PD32_MARGINS_IN_INCHES,
3232 title, sizeof(title)/sizeof(title[0])))
3233 SetDlgItemTextW(hDlg, grp4, title);
3236 static void pagesetup_update_orientation_buttons(HWND hDlg, const pagesetup_data *data)
3238 if (pagesetup_get_orientation(data) == DMORIENT_LANDSCAPE)
3239 CheckRadioButton(hDlg, rad1, rad2, rad2);
3241 CheckRadioButton(hDlg, rad1, rad2, rad1);
3244 /****************************************************************************************
3245 * pagesetup_printer_properties
3247 * Handle invocation of the 'Properties' button (not present in the default template).
3249 static void pagesetup_printer_properties(HWND hDlg, pagesetup_data *data)
3257 devname = pagesetup_get_devname(data);
3259 if (!OpenPrinterW(devname, &hprn, NULL))
3261 FIXME("Call to OpenPrinter did not succeed!\n");
3262 pagesetup_release_devname(data, devname);
3266 dm = pagesetup_get_devmode(data);
3267 DocumentPropertiesW(hDlg, hprn, devname, dm, dm, DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
3268 pagesetup_set_devmode(data, dm);
3269 pagesetup_release_devmode(data, dm);
3270 pagesetup_release_devname(data, devname);
3273 /* Changing paper */
3274 pagesetup_update_papersize(data);
3275 pagesetup_update_orientation_buttons(hDlg, data);
3277 /* Changing paper preview */
3278 pagesetup_change_preview(data);
3280 /* Selecting paper in combo */
3281 count = SendDlgItemMessageW(hDlg, cmb2, CB_GETCOUNT, 0, 0);
3284 WORD paperword = pagesetup_get_papersize(data);
3285 for(i = 0; i < count; i++)
3287 if(SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, i, 0) == paperword) {
3288 SendDlgItemMessageW(hDlg, cmb2, CB_SETCURSEL, i, 0);
3295 /********************************************************************************
3296 * PRINTDLG_PS_WMCommandA
3297 * process WM_COMMAND message for PageSetupDlgA
3300 * hDlg [in] Main dialog HANDLE
3301 * wParam [in] WM_COMMAND wParam
3302 * lParam [in] WM_COMMAND lParam
3303 * pda [in/out] ptr to PageSetupDataA
3306 static BOOL PRINTDLG_PS_WMCommandA(HWND hDlg, WPARAM wParam, LPARAM lParam, pagesetup_data *data)
3308 WORD msg = HIWORD(wParam);
3309 WORD id = LOWORD(wParam);
3311 TRACE("loword (lparam) %d, wparam 0x%lx, lparam %08lx\n",
3312 LOWORD(lParam),wParam,lParam);
3315 EndDialog(hDlg, TRUE);
3319 EndDialog(hDlg, FALSE);
3322 case psh3: /* Printer... */
3323 pagesetup_change_printer_dialog(hDlg, data);
3326 case rad1: /* Portrait */
3327 case rad2: /* Landscape */
3328 if((id == rad1 && pagesetup_get_orientation(data) == DMORIENT_LANDSCAPE) ||
3329 (id == rad2 && pagesetup_get_orientation(data) == DMORIENT_PORTRAIT))
3331 pagesetup_set_orientation(data, (id == rad1) ? DMORIENT_PORTRAIT : DMORIENT_LANDSCAPE);
3332 pagesetup_update_papersize(data);
3333 rotate_rect(pagesetup_get_margin_rect(data), (id == rad2));
3334 update_margin_edits(hDlg, data, 0);
3335 pagesetup_change_preview(data);
3338 case cmb1: /* Printer combo */
3339 if(msg == CBN_SELCHANGE)
3342 GetDlgItemTextW(hDlg, id, name, sizeof(name) / sizeof(name[0]));
3343 pagesetup_change_printer(name, data);
3344 pagesetup_init_combos(hDlg, data);
3347 case cmb2: /* Paper combo */
3348 if(msg == CBN_SELCHANGE)
3350 DWORD paperword = SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA,
3351 SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0), 0);
3352 if (paperword != CB_ERR)
3354 pagesetup_set_papersize(data, paperword);
3355 pagesetup_update_papersize(data);
3356 pagesetup_change_preview(data);
3358 FIXME("could not get dialog text for papersize cmbbox?\n");
3361 case cmb3: /* Paper Source */
3362 if(msg == CBN_SELCHANGE)
3364 WORD source = SendDlgItemMessageW(hDlg, cmb3, CB_GETITEMDATA,
3365 SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0), 0);
3366 pagesetup_set_defaultsource(data, source);
3369 case psh2: /* Printer Properties button */
3370 pagesetup_printer_properties(hDlg, data);
3376 margin_edit_notification(hDlg, data, msg, id);
3379 InvalidateRect(GetDlgItem(hDlg, rct1), NULL, TRUE);
3384 PRINTDLG_PS_WMCommandW(
3385 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataW *pdw
3387 TRACE("loword (lparam) %d, wparam 0x%lx, lparam %08lx\n",
3388 LOWORD(lParam),wParam,lParam);
3389 switch (LOWORD(wParam)) {
3391 if (!PRINTDLG_PS_UpdateDlgStructW(hDlg, pdw))
3393 EndDialog(hDlg, TRUE);
3397 EndDialog(hDlg, FALSE);
3402 if((LOWORD(wParam) == rad1 && pdw->curdlg.ptPaperSize.x > pdw->curdlg.ptPaperSize.y) ||
3403 (LOWORD(wParam) == rad2 && pdw->curdlg.ptPaperSize.y > pdw->curdlg.ptPaperSize.x))
3407 DWORD tmp = pdw->curdlg.ptPaperSize.y;
3409 pdw->curdlg.ptPaperSize.y = pdw->curdlg.ptPaperSize.x;
3410 pdw->curdlg.ptPaperSize.x = tmp;
3412 GetDlgItemTextW(hDlg, edt4, tmpText, sizeof(tmpText)/sizeof(WCHAR));
3413 GetDlgItemTextW(hDlg, edt5, tmpText2, sizeof(tmpText2)/sizeof(WCHAR));
3414 SetDlgItemTextW(hDlg, edt5, tmpText);
3415 SetDlgItemTextW(hDlg, edt4, tmpText2);
3417 GetDlgItemTextW(hDlg, edt6, tmpText, sizeof(tmpText)/sizeof(WCHAR));
3418 GetDlgItemTextW(hDlg, edt7, tmpText2, sizeof(tmpText2)/sizeof(WCHAR));
3419 SetDlgItemTextW(hDlg, edt7, tmpText);
3420 SetDlgItemTextW(hDlg, edt6, tmpText2);
3425 pdw->pdlg.Flags = 0;
3426 pdw->pdlg.hwndOwner = hDlg;
3427 PRINTDLG_PS_UpdatePrintDlgW(pdw, hDlg);
3428 if (PrintDlgW(&(pdw->pdlg)))
3429 PRINTDLG_PS_ChangePrinterW(hDlg,pdw);
3437 /***********************************************************************
3438 * DefaultPagePaintHook
3439 * Default hook paint procedure that receives WM_PSD_* messages from the dialog box
3440 * whenever the sample page is redrawn.
3444 PRINTDLG_DefaultPagePaintHook(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam,
3445 const pagesetup_data *data)
3447 LPRECT lprc = (LPRECT) lParam;
3448 HDC hdc = (HDC) wParam;
3451 HFONT hfont, holdfont;
3453 TRACE("uMsg: WM_USER+%d\n",uMsg-WM_USER);
3454 /* Call user paint hook if enable */
3455 if (pagesetup_get_flags(data) & PSD_ENABLEPAGEPAINTHOOK)
3456 if (data->dlga->lpfnPagePaintHook(hwndDlg, uMsg, wParam, lParam))
3460 /* LPPAGESETUPDLG in lParam */
3461 case WM_PSD_PAGESETUPDLG:
3462 /* Inform about the sample page rectangle */
3463 case WM_PSD_FULLPAGERECT:
3464 /* Inform about the margin rectangle */
3465 case WM_PSD_MINMARGINRECT:
3468 /* Draw dashed rectangle showing margins */
3469 case WM_PSD_MARGINRECT:
3470 hpen = CreatePen(PS_DASH, 1, GetSysColor(COLOR_3DSHADOW));
3471 holdpen = SelectObject(hdc, hpen);
3472 Rectangle(hdc, lprc->left, lprc->top, lprc->right, lprc->bottom);
3473 DeleteObject(SelectObject(hdc, holdpen));
3475 /* Draw the fake document */
3476 case WM_PSD_GREEKTEXTRECT:
3477 /* select a nice scalable font, because we want the text really small */
3478 SystemParametersInfoW(SPI_GETICONTITLELOGFONT, sizeof(lf), &lf, 0);
3479 lf.lfHeight = 6; /* value chosen based on visual effect */
3480 hfont = CreateFontIndirectW(&lf);
3481 holdfont = SelectObject(hdc, hfont);
3483 /* if text not loaded, then do so now */
3484 if (wszFakeDocumentText[0] == '\0')
3485 LoadStringW(COMDLG32_hInstance,
3487 wszFakeDocumentText,
3488 sizeof(wszFakeDocumentText)/sizeof(wszFakeDocumentText[0]));
3490 oldbkmode = SetBkMode(hdc, TRANSPARENT);
3491 DrawTextW(hdc, wszFakeDocumentText, -1, lprc, DT_TOP|DT_LEFT|DT_NOPREFIX|DT_WORDBREAK);
3492 SetBkMode(hdc, oldbkmode);
3494 DeleteObject(SelectObject(hdc, holdfont));
3497 /* Envelope stamp */
3498 case WM_PSD_ENVSTAMPRECT:
3499 /* Return address */
3500 case WM_PSD_YAFULLPAGERECT:
3501 FIXME("envelope/stamp is not implemented\n");
3504 FIXME("Unknown message %x\n",uMsg);
3510 /***********************************************************************
3512 * The main paint procedure for the PageSetupDlg function.
3513 * The Page Setup dialog box includes an image of a sample page that shows how
3514 * the user's selections affect the appearance of the printed output.
3515 * The image consists of a rectangle that represents the selected paper
3516 * or envelope type, with a dotted-line rectangle representing
3517 * the current margins, and partial (Greek text) characters
3518 * to show how text looks on the printed page.
3520 * The following messages in the order sends to user hook procedure:
3521 * WM_PSD_PAGESETUPDLG Draw the contents of the sample page
3522 * WM_PSD_FULLPAGERECT Inform about the bounding rectangle
3523 * WM_PSD_MINMARGINRECT Inform about the margin rectangle (min margin?)
3524 * WM_PSD_MARGINRECT Draw the margin rectangle
3525 * WM_PSD_GREEKTEXTRECT Draw the Greek text inside the margin rectangle
3526 * If any of first three messages returns TRUE, painting done.
3529 * hWnd [in] Handle to the Page Setup dialog box
3530 * uMsg [in] Received message
3533 * WM_PSD_ENVSTAMPRECT Draw in the envelope-stamp rectangle (for envelopes only)
3534 * WM_PSD_YAFULLPAGERECT Draw the return address portion (for envelopes and other paper sizes)
3537 * FALSE if all done correctly
3542 static LRESULT CALLBACK
3543 PRINTDLG_PagePaintProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3546 RECT rcClient, rcMargin;
3549 HBRUSH hbrush, holdbrush;
3550 pagesetup_data *data;
3551 int papersize=0, orientation=0; /* FIXME: set this values for user paint hook */
3552 double scalx, scaly;
3553 #define CALLPAINTHOOK(msg,lprc) PRINTDLG_DefaultPagePaintHook( hWnd, msg, (WPARAM)hdc, (LPARAM)lprc, data)
3555 if (uMsg != WM_PAINT)
3556 return CallWindowProcA(lpfnStaticWndProc, hWnd, uMsg, wParam, lParam);
3558 /* Processing WM_PAINT message */
3559 data = GetPropW(hWnd, pagesetupdlg_prop);
3561 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3564 if (PRINTDLG_DefaultPagePaintHook(hWnd, WM_PSD_PAGESETUPDLG, MAKELONG(papersize, orientation), (LPARAM)data->dlga, data))
3567 hdc = BeginPaint(hWnd, &ps);
3568 GetClientRect(hWnd, &rcClient);
3570 scalx = rcClient.right / (double)pagesetup_get_papersize_pt(data)->x;
3571 scaly = rcClient.bottom / (double)pagesetup_get_papersize_pt(data)->y;
3572 rcMargin = rcClient;
3574 rcMargin.left += pagesetup_get_margin_rect(data)->left * scalx;
3575 rcMargin.top += pagesetup_get_margin_rect(data)->top * scaly;
3576 rcMargin.right -= pagesetup_get_margin_rect(data)->right * scalx;
3577 rcMargin.bottom -= pagesetup_get_margin_rect(data)->bottom * scaly;
3579 /* if the space is too small then we make sure to not draw anything */
3580 rcMargin.left = min(rcMargin.left, rcMargin.right);
3581 rcMargin.top = min(rcMargin.top, rcMargin.bottom);
3583 if (!CALLPAINTHOOK(WM_PSD_FULLPAGERECT, &rcClient) &&
3584 !CALLPAINTHOOK(WM_PSD_MINMARGINRECT, &rcMargin) )
3586 /* fill background */
3587 hbrush = GetSysColorBrush(COLOR_3DHIGHLIGHT);
3588 FillRect(hdc, &rcClient, hbrush);
3589 holdbrush = SelectObject(hdc, hbrush);
3591 hpen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW));
3592 holdpen = SelectObject(hdc, hpen);
3594 /* paint left edge */
3595 MoveToEx(hdc, rcClient.left, rcClient.top, NULL);
3596 LineTo(hdc, rcClient.left, rcClient.bottom-1);
3598 /* paint top edge */
3599 MoveToEx(hdc, rcClient.left, rcClient.top, NULL);
3600 LineTo(hdc, rcClient.right, rcClient.top);
3602 hpen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DDKSHADOW));
3603 DeleteObject(SelectObject(hdc, hpen));
3605 /* paint right edge */
3606 MoveToEx(hdc, rcClient.right-1, rcClient.top, NULL);
3607 LineTo(hdc, rcClient.right-1, rcClient.bottom);
3609 /* paint bottom edge */
3610 MoveToEx(hdc, rcClient.left, rcClient.bottom-1, NULL);
3611 LineTo(hdc, rcClient.right, rcClient.bottom-1);
3613 DeleteObject(SelectObject(hdc, holdpen));
3614 DeleteObject(SelectObject(hdc, holdbrush));
3616 CALLPAINTHOOK(WM_PSD_MARGINRECT, &rcMargin);
3618 /* give text a bit of a space from the frame */
3621 rcMargin.right -= 2;
3622 rcMargin.bottom -= 2;
3624 /* if the space is too small then we make sure to not draw anything */
3625 rcMargin.left = min(rcMargin.left, rcMargin.right);
3626 rcMargin.top = min(rcMargin.top, rcMargin.bottom);
3628 CALLPAINTHOOK(WM_PSD_GREEKTEXTRECT, &rcMargin);
3631 EndPaint(hWnd, &ps);
3633 #undef CALLPAINTHOOK
3636 /*******************************************************
3637 * The margin edit controls are subclassed to filter
3638 * anything other than numbers and the decimal separator.
3640 static LRESULT CALLBACK pagesetup_margin_editproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3645 WCHAR decimal = get_decimal_sep();
3646 WCHAR wc = (WCHAR)wparam;
3647 if(!isdigitW(wc) && wc != decimal && wc != VK_BACK) return 0;
3649 return CallWindowProcW(edit_wndproc, hwnd, msg, wparam, lparam);
3652 static void subclass_margin_edits(HWND hDlg)
3657 for(id = edt4; id <= edt7; id++)
3659 old_proc = (WNDPROC)SetWindowLongPtrW(GetDlgItem(hDlg, id),
3661 (ULONG_PTR)pagesetup_margin_editproc);
3662 InterlockedCompareExchangePointer((void**)&edit_wndproc, old_proc, NULL);
3666 /***********************************************************************
3667 * PRINTDLG_PageDlgProcA
3668 * Message handler for PageSetupDlgA
3670 static INT_PTR CALLBACK
3671 PRINTDLG_PageDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
3673 pagesetup_data *data;
3674 INT_PTR res = FALSE;
3677 if (uMsg == WM_INITDIALOG) { /*Init dialog*/
3678 data = (pagesetup_data *)lParam;
3681 hDrawWnd = GetDlgItem(hDlg, rct1);
3682 TRACE("set property to %p\n", data);
3683 SetPropW(hDlg, pagesetupdlg_prop, data);
3684 SetPropW(hDrawWnd, pagesetupdlg_prop, data);
3685 GetWindowRect(hDrawWnd, &data->rtDrawRect); /* Calculating rect in client coordinates where paper draws */
3686 ScreenToClient(hDlg, (LPPOINT)&data->rtDrawRect);
3687 ScreenToClient(hDlg, (LPPOINT)(&data->rtDrawRect.right));
3688 lpfnStaticWndProc = (WNDPROC)SetWindowLongPtrW(
3691 (ULONG_PTR)PRINTDLG_PagePaintProc);
3693 /* FIXME: Paint hook. Must it be at begin of initialization or at end? */
3695 if (pagesetup_get_flags(data) & PSD_ENABLEPAGESETUPHOOK)
3697 if (!data->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,(LPARAM)data->dlga))
3698 FIXME("Setup page hook failed?\n");
3701 /* if printer button disabled */
3702 if (pagesetup_get_flags(data) & PSD_DISABLEPRINTER)
3703 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
3704 /* if margin edit boxes disabled */
3705 if (pagesetup_get_flags(data) & PSD_DISABLEMARGINS)
3707 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
3708 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
3709 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
3710 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
3713 /* Set orientation radiobuttons properly */
3714 pagesetup_update_orientation_buttons(hDlg, data);
3716 /* if orientation disabled */
3717 if (pagesetup_get_flags(data) & PSD_DISABLEORIENTATION)
3719 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
3720 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
3723 /* We fill them out enabled or not */
3724 if (!(pagesetup_get_flags(data) & PSD_MARGINS))
3726 /* default is 1 inch */
3727 LONG size = thousandths_inch_to_size(data, 1000);
3728 SetRect(pagesetup_get_margin_rect(data), size, size, size, size);
3730 update_margin_edits(hDlg, data, 0);
3731 subclass_margin_edits(hDlg);
3732 set_margin_groupbox_title(hDlg, data);
3734 /* if paper disabled */
3735 if (pagesetup_get_flags(data) & PSD_DISABLEPAPER)
3737 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
3738 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
3741 /* filling combos: printer, paper, source. selecting current printer (from DEVMODEA) */
3742 pagesetup_init_combos(hDlg, data);
3743 pagesetup_update_papersize(data);
3744 pagesetup_set_defaultsource(data, DMBIN_FORMSOURCE); /* FIXME: This is the auto select bin. Is this correct? */
3746 /* Drawing paper prev */
3747 pagesetup_change_preview(data);
3750 data = GetPropW(hDlg, pagesetupdlg_prop);
3753 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3756 if (pagesetup_get_flags(data) & PSD_ENABLEPAGESETUPHOOK)
3758 res = data->dlga->lpfnPageSetupHook(hDlg, uMsg, wParam, lParam);
3759 if (res) return res;
3764 return PRINTDLG_PS_WMCommandA(hDlg, wParam, lParam, data);
3769 static INT_PTR CALLBACK
3770 PageDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
3772 PageSetupDataW *pdw;
3775 if (uMsg==WM_INITDIALOG) {
3777 pdw = (PageSetupDataW*)lParam;
3778 pdw->curdlg = *pdw->dlgw;
3779 SetPropW(hDlg, pagesetupdlg_prop, pdw);
3780 if (pdw->dlgw->Flags & PSD_ENABLEPAGESETUPHOOK) {
3781 res = pdw->dlgw->lpfnPageSetupHook(hDlg,uMsg,wParam,(LPARAM)pdw->dlgw);
3783 FIXME("Setup page hook failed?\n");
3788 if (pdw->dlgw->Flags & PSD_ENABLEPAGEPAINTHOOK) {
3789 FIXME("PagePaintHook not yet implemented!\n");
3791 if (pdw->dlgw->Flags & PSD_DISABLEPRINTER)
3792 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
3793 if (pdw->dlgw->Flags & PSD_DISABLEMARGINS) {
3794 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
3795 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
3796 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
3797 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
3800 PRINTDLG_PS_ChangePrinterW(hDlg,pdw);
3802 if (pdw->dlgw->Flags & PSD_DISABLEORIENTATION) {
3803 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
3804 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
3806 /* We fill them out enabled or not */
3807 if (pdw->dlgw->Flags & PSD_MARGINS) {
3809 _c_size2strW(pdw,pdw->dlgw->rtMargin.left,str);
3810 SetDlgItemTextW(hDlg,edt4,str);
3811 _c_size2strW(pdw,pdw->dlgw->rtMargin.top,str);
3812 SetDlgItemTextW(hDlg,edt5,str);
3813 _c_size2strW(pdw,pdw->dlgw->rtMargin.right,str);
3814 SetDlgItemTextW(hDlg,edt6,str);
3815 _c_size2strW(pdw,pdw->dlgw->rtMargin.bottom,str);
3816 SetDlgItemTextW(hDlg,edt7,str);
3818 /* default is 1 inch */
3819 DWORD size = _c_inch2size(pdw->dlgw,1000);
3821 _c_size2strW(pdw,size,str);
3822 SetDlgItemTextW(hDlg,edt4,str);
3823 SetDlgItemTextW(hDlg,edt5,str);
3824 SetDlgItemTextW(hDlg,edt6,str);
3825 SetDlgItemTextW(hDlg,edt7,str);
3828 if (pdw->dlgw->Flags & PSD_DISABLEPAPER) {
3829 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
3830 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
3835 pdw = GetPropW(hDlg, pagesetupdlg_prop);
3837 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3840 if (pdw->dlgw->Flags & PSD_ENABLEPAGESETUPHOOK) {
3841 res = pdw->dlgw->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3842 if (res) return res;
3847 return PRINTDLG_PS_WMCommandW(hDlg, wParam, lParam, pdw);
3852 /***********************************************************************
3853 * PageSetupDlgA (COMDLG32.@)
3855 * Displays the PAGE SETUP dialog box, which enables the user to specify
3856 * specific properties of a printed page such as
3857 * size, source, orientation and the width of the page margins.
3860 * setupdlg [IO] PAGESETUPDLGA struct
3863 * TRUE if the user pressed the OK button
3864 * FALSE if the user cancelled the window or an error occurred
3867 * The values of hDevMode and hDevNames are filled on output and can be
3868 * changed in PAGESETUPDLG when they are passed in PageSetupDlg.
3872 BOOL WINAPI PageSetupDlgA(LPPAGESETUPDLGA setupdlg) {
3876 pagesetup_data *data;
3878 if (setupdlg == NULL) {
3879 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION);
3884 if(TRACE_ON(commdlg)) {
3885 char flagstr[1000] = "";
3886 const struct pd_flags *pflag = psd_flags;
3887 for( ; pflag->name; pflag++) {
3888 if(setupdlg->Flags & pflag->flag) {
3889 strcat(flagstr, pflag->name);
3890 strcat(flagstr, "|");
3893 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3894 "hinst %p, flags %08x (%s)\n",
3895 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
3896 setupdlg->hDevNames,
3897 setupdlg->hInstance, setupdlg->Flags, flagstr);
3900 /* Checking setupdlg structure */
3901 if(setupdlg->lStructSize != sizeof(PAGESETUPDLGA)) {
3902 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
3905 if ((setupdlg->Flags & PSD_ENABLEPAGEPAINTHOOK) &&
3906 (setupdlg->lpfnPagePaintHook == NULL)) {
3907 COMDLG32_SetCommDlgExtendedError(CDERR_NOHOOK);
3911 if(!(setupdlg->Flags & (PSD_INTHOUSANDTHSOFINCHES | PSD_INHUNDREDTHSOFMILLIMETERS)))
3912 setupdlg->Flags |= is_default_metric() ?
3913 PSD_INHUNDREDTHSOFMILLIMETERS : PSD_INTHOUSANDTHSOFINCHES;
3915 /* Initialize default printer struct. If no printer device info is specified
3916 retrieve the default printer data. */
3917 if (!setupdlg->hDevMode || !setupdlg->hDevNames)
3920 memset(&pdlg, 0, sizeof(pdlg));
3921 pdlg.lStructSize = sizeof(pdlg);
3922 pdlg.Flags = PD_RETURNDEFAULT;
3923 bRet = PrintDlgA(&pdlg);
3926 if (!(setupdlg->Flags & PSD_NOWARNING)) {
3928 LoadStringW(COMDLG32_hInstance, PD32_NO_DEFAULT_PRINTER, errstr, 255);
3929 MessageBoxW(setupdlg->hwndOwner, errstr, 0, MB_OK | MB_ICONERROR);
3933 setupdlg->hDevMode = pdlg.hDevMode;
3934 setupdlg->hDevNames = pdlg.hDevNames;
3937 data = HeapAlloc(GetProcessHeap(), 0, sizeof(*data));
3938 data->dlga = setupdlg;
3940 /* short cut exit, just return default values */
3941 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
3942 pagesetup_update_papersize(data);
3943 HeapFree(GetProcessHeap(), 0, data);
3947 /* get dialog template */
3948 hDlgTmpl = PRINTDLG_GetPGSTemplateA(setupdlg);
3950 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3953 ptr = LockResource( hDlgTmpl );
3955 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3959 bRet = (0<DialogBoxIndirectParamW(
3960 setupdlg->hInstance,
3962 setupdlg->hwndOwner,
3963 PRINTDLG_PageDlgProcA,
3967 HeapFree(GetProcessHeap(), 0, data);
3970 /***********************************************************************
3971 * PageSetupDlgW (COMDLG32.@)
3973 * See PageSetupDlgA.
3975 BOOL WINAPI PageSetupDlgW(LPPAGESETUPDLGW setupdlg) {
3979 PageSetupDataW *pdw;
3982 FIXME("Unicode implementation is not done yet\n");
3984 if (setupdlg == NULL) {
3985 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION);
3989 if(TRACE_ON(commdlg)) {
3990 char flagstr[1000] = "";
3991 const struct pd_flags *pflag = psd_flags;
3992 for( ; pflag->name; pflag++) {
3993 if(setupdlg->Flags & pflag->flag) {
3994 strcat(flagstr, pflag->name);
3995 strcat(flagstr, "|");
3998 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3999 "hinst %p, flags %08x (%s)\n",
4000 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
4001 setupdlg->hDevNames,
4002 setupdlg->hInstance, setupdlg->Flags, flagstr);
4005 /* Initialize default printer struct. If no printer device info is specified
4006 retrieve the default printer data. */
4007 memset(&pdlg,0,sizeof(pdlg));
4008 pdlg.lStructSize = sizeof(pdlg);
4009 if (setupdlg->hDevMode && setupdlg->hDevNames) {
4010 pdlg.hDevMode = setupdlg->hDevMode;
4011 pdlg.hDevNames = setupdlg->hDevNames;
4013 pdlg.Flags = PD_RETURNDEFAULT;
4014 bRet = PrintDlgW(&pdlg);
4016 if (!(setupdlg->Flags & PSD_NOWARNING)) {
4018 LoadStringW(COMDLG32_hInstance, PD32_NO_DEFAULT_PRINTER, errstr, 255);
4019 MessageBoxW(setupdlg->hwndOwner, errstr, 0, MB_OK | MB_ICONERROR);
4025 /* short cut exit, just return default values */
4026 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
4027 static const WCHAR a4[] = {'A','4',0};
4028 setupdlg->hDevMode = pdlg.hDevMode;
4029 setupdlg->hDevNames = pdlg.hDevNames;
4030 /* FIXME: Just return "A4" for now. */
4031 PRINTDLG_PaperSizeW(&pdlg,a4,&setupdlg->ptPaperSize);
4032 setupdlg->ptPaperSize.x=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.x);
4033 setupdlg->ptPaperSize.y=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.y);
4036 hDlgTmpl = PRINTDLG_GetPGSTemplateW(setupdlg);
4038 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
4041 ptr = LockResource( hDlgTmpl );
4043 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
4046 pdw = HeapAlloc(GetProcessHeap(),0,sizeof(*pdw));
4047 pdw->dlgw = setupdlg;
4050 bRet = (0<DialogBoxIndirectParamW(
4051 setupdlg->hInstance,
4053 setupdlg->hwndOwner,
4060 /***********************************************************************
4061 * PrintDlgExA (COMDLG32.@)
4069 HRESULT WINAPI PrintDlgExA(LPPRINTDLGEXA lppd)
4072 FIXME("(%p) stub\n", lppd);
4073 if ((lppd == NULL) || (lppd->lStructSize != sizeof(PRINTDLGEXA))) {
4074 return E_INVALIDARG;
4077 if (!IsWindow(lppd->hwndOwner)) {
4084 /***********************************************************************
4085 * PrintDlgExW (COMDLG32.@)
4087 * Display the property sheet style PRINT dialog box
4090 * lppd [IO] ptr to PRINTDLGEX struct
4094 * Failure: One of the following COM error codes:
4095 * E_OUTOFMEMORY Insufficient memory.
4096 * E_INVALIDARG One or more arguments are invalid.
4097 * E_POINTER Invalid pointer.
4098 * E_HANDLE Invalid handle.
4099 * E_FAIL Unspecified error.
4102 * This Dialog enables the user to specify specific properties of the print job.
4103 * The property sheet can also have additional application-specific and
4104 * driver-specific property pages.
4107 * Not fully implemented
4110 HRESULT WINAPI PrintDlgExW(LPPRINTDLGEXW lppd)
4115 FIXME("(%p) not fully implemented\n", lppd);
4117 if ((lppd == NULL) || (lppd->lStructSize != sizeof(PRINTDLGEXW))) {
4118 return E_INVALIDARG;
4121 if (!IsWindow(lppd->hwndOwner)) {
4125 if (lppd->Flags & PD_RETURNDEFAULT) {
4126 PRINTER_INFO_2W *pbuf;
4127 DRIVER_INFO_2W *dbuf;
4129 DWORD needed = 1024;
4132 if (lppd->hDevMode || lppd->hDevNames) {
4133 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
4134 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
4135 return E_INVALIDARG;
4137 if (!PRINTDLG_OpenDefaultPrinter(&hprn)) {
4138 WARN("Can't find default printer\n");
4139 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
4143 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
4144 bRet = GetPrinterW(hprn, 2, (LPBYTE)pbuf, needed, &needed);
4145 if (!bRet && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
4146 HeapFree(GetProcessHeap(), 0, pbuf);
4147 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
4148 bRet = GetPrinterW(hprn, 2, (LPBYTE)pbuf, needed, &needed);
4151 HeapFree(GetProcessHeap(), 0, pbuf);
4157 dbuf = HeapAlloc(GetProcessHeap(), 0, needed);
4158 bRet = GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed);
4159 if (!bRet && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
4160 HeapFree(GetProcessHeap(), 0, dbuf);
4161 dbuf = HeapAlloc(GetProcessHeap(), 0, needed);
4162 bRet = GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed);
4165 ERR("GetPrinterDriverW failed, last error %d, fix your config for printer %s!\n",
4166 GetLastError(), debugstr_w(pbuf->pPrinterName));
4167 HeapFree(GetProcessHeap(), 0, dbuf);
4168 HeapFree(GetProcessHeap(), 0, pbuf);
4169 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
4175 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
4179 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
4180 pbuf->pDevMode->dmDriverExtra);
4181 if (lppd->hDevMode) {
4182 ptr = GlobalLock(lppd->hDevMode);
4184 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
4185 pbuf->pDevMode->dmDriverExtra);
4186 GlobalUnlock(lppd->hDevMode);
4190 HeapFree(GetProcessHeap(), 0, pbuf);
4191 HeapFree(GetProcessHeap(), 0, dbuf);