2 * COMMDLG - Print Dialog
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
6 * Copyright 1999 Klaas van Gend
7 * Copyright 2000 Huw D M Davies
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #define NONAMELESSUNION
30 #define NONAMELESSSTRUCT
38 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
49 /* Yes these constants are the same, but we're just copying win98 */
50 #define UPDOWN_ID 0x270f
51 #define MAX_COPIES 9999
54 static struct pd_flags psd_flags[] = {
55 {PSD_MINMARGINS,"PSD_MINMARGINS"},
56 {PSD_MARGINS,"PSD_MARGINS"},
57 {PSD_INTHOUSANDTHSOFINCHES,"PSD_INTHOUSANDTHSOFINCHES"},
58 {PSD_INHUNDREDTHSOFMILLIMETERS,"PSD_INHUNDREDTHSOFMILLIMETERS"},
59 {PSD_DISABLEMARGINS,"PSD_DISABLEMARGINS"},
60 {PSD_DISABLEPRINTER,"PSD_DISABLEPRINTER"},
61 {PSD_NOWARNING,"PSD_NOWARNING"},
62 {PSD_DISABLEORIENTATION,"PSD_DISABLEORIENTATION"},
63 {PSD_RETURNDEFAULT,"PSD_RETURNDEFAULT"},
64 {PSD_DISABLEPAPER,"PSD_DISABLEPAPER"},
65 {PSD_SHOWHELP,"PSD_SHOWHELP"},
66 {PSD_ENABLEPAGESETUPHOOK,"PSD_ENABLEPAGESETUPHOOK"},
67 {PSD_ENABLEPAGESETUPTEMPLATE,"PSD_ENABLEPAGESETUPTEMPLATE"},
68 {PSD_ENABLEPAGESETUPTEMPLATEHANDLE,"PSD_ENABLEPAGESETUPTEMPLATEHANDLE"},
69 {PSD_ENABLEPAGEPAINTHOOK,"PSD_ENABLEPAGEPAINTHOOK"},
70 {PSD_DISABLEPAGEPAINTING,"PSD_DISABLEPAGEPAINTING"},
74 /* address of wndproc for subclassed Static control */
75 static WNDPROC lpfnStaticWndProc;
76 /* the text of the fake document to render for the Page Setup dialog */
77 static WCHAR wszFakeDocumentText[1024];
79 /***********************************************************************
80 * PRINTDLG_OpenDefaultPrinter
82 * Returns a winspool printer handle to the default printer in *hprn
83 * Caller must call ClosePrinter on the handle
85 * Returns TRUE on success else FALSE
87 BOOL PRINTDLG_OpenDefaultPrinter(HANDLE *hprn)
90 DWORD dwBufLen = sizeof(buf) / sizeof(buf[0]);
92 if(!GetDefaultPrinterW(buf, &dwBufLen))
94 res = OpenPrinterW(buf, hprn, NULL);
96 WARN("Could not open printer %s\n", debugstr_w(buf));
100 /***********************************************************************
101 * PRINTDLG_SetUpPrinterListCombo
103 * Initializes printer list combox.
104 * hDlg: HWND of dialog
105 * id: Control id of combo
106 * name: Name of printer to select
108 * Initializes combo with list of available printers. Selects printer 'name'
109 * If name is NULL or does not exist select the default printer.
111 * Returns number of printers added to list.
113 INT PRINTDLG_SetUpPrinterListComboA(HWND hDlg, UINT id, LPCSTR name)
117 LPPRINTER_INFO_2A pi;
118 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
119 pi = HeapAlloc(GetProcessHeap(), 0, needed);
120 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
123 for(i = 0; i < num; i++) {
124 SendDlgItemMessageA(hDlg, id, CB_ADDSTRING, 0,
125 (LPARAM)pi[i].pPrinterName );
127 HeapFree(GetProcessHeap(), 0, pi);
129 (i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1,
130 (LPARAM)name)) == CB_ERR) {
133 DWORD dwBufLen = sizeof(buf);
134 FIXME("Can't find '%s' in printer list so trying to find default\n",
136 if(!GetDefaultPrinterA(buf, &dwBufLen))
138 i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
140 FIXME("Can't find default printer in printer list\n");
142 SendDlgItemMessageA(hDlg, id, CB_SETCURSEL, i, 0);
146 static INT PRINTDLG_SetUpPrinterListComboW(HWND hDlg, UINT id, LPCWSTR name)
150 LPPRINTER_INFO_2W pi;
151 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
152 pi = HeapAlloc(GetProcessHeap(), 0, needed);
153 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
156 for(i = 0; i < num; i++) {
157 SendDlgItemMessageW(hDlg, id, CB_ADDSTRING, 0,
158 (LPARAM)pi[i].pPrinterName );
160 HeapFree(GetProcessHeap(), 0, pi);
162 (i = SendDlgItemMessageW(hDlg, id, CB_FINDSTRINGEXACT, -1,
163 (LPARAM)name)) == CB_ERR) {
165 DWORD dwBufLen = sizeof(buf)/sizeof(buf[0]);
166 TRACE("Can't find '%s' in printer list so trying to find default\n",
168 if(!GetDefaultPrinterW(buf, &dwBufLen))
170 i = SendDlgItemMessageW(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
172 TRACE("Can't find default printer in printer list\n");
174 SendDlgItemMessageW(hDlg, id, CB_SETCURSEL, i, 0);
178 /***********************************************************************
179 * PRINTDLG_CreateDevNames [internal]
182 * creates a DevNames structure.
184 * (NB. when we handle unicode the offsets will be in wchars).
186 static BOOL PRINTDLG_CreateDevNames(HGLOBAL *hmem, char* DeviceDriverName,
187 char* DeviceName, char* OutputPort)
190 char* pDevNamesSpace;
192 LPDEVNAMES lpDevNames;
194 DWORD dwBufLen = sizeof(buf);
196 size = strlen(DeviceDriverName) + 1
197 + strlen(DeviceName) + 1
198 + strlen(OutputPort) + 1
202 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
204 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
208 pDevNamesSpace = GlobalLock(*hmem);
209 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
211 pTempPtr = pDevNamesSpace + sizeof(DEVNAMES);
212 strcpy(pTempPtr, DeviceDriverName);
213 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
215 pTempPtr += strlen(DeviceDriverName) + 1;
216 strcpy(pTempPtr, DeviceName);
217 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
219 pTempPtr += strlen(DeviceName) + 1;
220 strcpy(pTempPtr, OutputPort);
221 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
223 GetDefaultPrinterA(buf, &dwBufLen);
224 lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
229 static BOOL PRINTDLG_CreateDevNamesW(HGLOBAL *hmem, LPCWSTR DeviceDriverName,
230 LPCWSTR DeviceName, LPCWSTR OutputPort)
233 LPWSTR pDevNamesSpace;
235 LPDEVNAMES lpDevNames;
237 DWORD dwBufLen = sizeof(bufW) / sizeof(WCHAR);
239 size = sizeof(WCHAR)*lstrlenW(DeviceDriverName) + 2
240 + sizeof(WCHAR)*lstrlenW(DeviceName) + 2
241 + sizeof(WCHAR)*lstrlenW(OutputPort) + 2
245 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
247 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
251 pDevNamesSpace = GlobalLock(*hmem);
252 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
254 pTempPtr = (LPWSTR)((LPDEVNAMES)pDevNamesSpace + 1);
255 lstrcpyW(pTempPtr, DeviceDriverName);
256 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
258 pTempPtr += lstrlenW(DeviceDriverName) + 1;
259 lstrcpyW(pTempPtr, DeviceName);
260 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
262 pTempPtr += lstrlenW(DeviceName) + 1;
263 lstrcpyW(pTempPtr, OutputPort);
264 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
266 GetDefaultPrinterW(bufW, &dwBufLen);
267 lpDevNames->wDefault = (lstrcmpW(bufW, DeviceName) == 0) ? 1 : 0;
272 /***********************************************************************
273 * PRINTDLG_UpdatePrintDlg [internal]
276 * updates the PrintDlg structure for return values.
279 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
280 * TRUE if successful.
282 static BOOL PRINTDLG_UpdatePrintDlgA(HWND hDlg,
283 PRINT_PTRA* PrintStructures)
285 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
286 PDEVMODEA lpdm = PrintStructures->lpDevMode;
287 LPPRINTER_INFO_2A pi = PrintStructures->lpPrinterInfo;
291 FIXME("No lpdm ptr?\n");
296 if(!(lppd->Flags & PD_PRINTSETUP)) {
297 /* check whether nFromPage and nToPage are within range defined by
298 * nMinPage and nMaxPage
300 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
303 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
304 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
305 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
306 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
307 char resourcestr[256];
309 LoadStringA(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
311 sprintf(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
312 LoadStringA(COMDLG32_hInstance, PD32_PRINT_TITLE,
314 MessageBoxA(hDlg, resultstr, resourcestr,
315 MB_OK | MB_ICONWARNING);
318 lppd->nFromPage = nFromPage;
319 lppd->nToPage = nToPage;
320 lppd->Flags |= PD_PAGENUMS;
323 lppd->Flags &= ~PD_PAGENUMS;
325 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
326 lppd->Flags |= PD_PRINTTOFILE;
327 pi->pPortName = "FILE:";
330 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
331 FIXME("Collate lppd not yet implemented as output\n");
334 /* set PD_Collate and nCopies */
335 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
336 /* The application doesn't support multiple copies or collate...
338 lppd->Flags &= ~PD_COLLATE;
340 /* if the printer driver supports it... store info there
341 * otherwise no collate & multiple copies !
343 if (lpdm->dmFields & DM_COLLATE)
345 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
346 if (lpdm->dmFields & DM_COPIES)
347 lpdm->dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
349 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
350 lppd->Flags |= PD_COLLATE;
352 lppd->Flags &= ~PD_COLLATE;
353 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
359 static BOOL PRINTDLG_UpdatePrintDlgW(HWND hDlg,
360 PRINT_PTRW* PrintStructures)
362 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
363 PDEVMODEW lpdm = PrintStructures->lpDevMode;
364 LPPRINTER_INFO_2W pi = PrintStructures->lpPrinterInfo;
368 FIXME("No lpdm ptr?\n");
373 if(!(lppd->Flags & PD_PRINTSETUP)) {
374 /* check whether nFromPage and nToPage are within range defined by
375 * nMinPage and nMaxPage
377 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
380 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
381 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
382 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
383 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
384 WCHAR resourcestr[256];
385 WCHAR resultstr[256];
386 LoadStringW(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
388 wsprintfW(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
389 LoadStringW(COMDLG32_hInstance, PD32_PRINT_TITLE,
391 MessageBoxW(hDlg, resultstr, resourcestr,
392 MB_OK | MB_ICONWARNING);
395 lppd->nFromPage = nFromPage;
396 lppd->nToPage = nToPage;
399 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
400 static WCHAR file[] = {'F','I','L','E',':',0};
401 lppd->Flags |= PD_PRINTTOFILE;
402 pi->pPortName = file;
405 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
406 FIXME("Collate lppd not yet implemented as output\n");
409 /* set PD_Collate and nCopies */
410 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
411 /* The application doesn't support multiple copies or collate...
413 lppd->Flags &= ~PD_COLLATE;
415 /* if the printer driver supports it... store info there
416 * otherwise no collate & multiple copies !
418 if (lpdm->dmFields & DM_COLLATE)
420 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
421 if (lpdm->dmFields & DM_COPIES)
422 lpdm->dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
424 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
425 lppd->Flags |= PD_COLLATE;
427 lppd->Flags &= ~PD_COLLATE;
428 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
434 static BOOL PRINTDLG_PaperSizeA(
435 PRINTDLGA *pdlga,const char *PaperSize,LPPOINT size
439 LPSTR devname,portname;
443 POINT *points = NULL;
446 dn = GlobalLock(pdlga->hDevNames);
447 dm = GlobalLock(pdlga->hDevMode);
448 devname = ((char*)dn)+dn->wDeviceOffset;
449 portname = ((char*)dn)+dn->wOutputOffset;
452 NrOfEntries = DeviceCapabilitiesA(devname,portname,DC_PAPERNAMES,NULL,dm);
454 FIXME("No papernames found for %s/%s\n",devname,portname);
457 if (NrOfEntries == -1) {
458 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
462 Names = HeapAlloc(GetProcessHeap(),0,NrOfEntries*64);
463 if (NrOfEntries != (ret=DeviceCapabilitiesA(devname,portname,DC_PAPERNAMES,Names,dm))) {
464 FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
467 for (i=0;i<NrOfEntries;i++)
468 if (!strcmp(PaperSize,Names+(64*i)))
470 HeapFree(GetProcessHeap(),0,Names);
471 if (i==NrOfEntries) {
472 FIXME("Papersize %s not found in list?\n",PaperSize);
475 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
476 if (NrOfEntries!=(ret=DeviceCapabilitiesA(devname,portname,DC_PAPERSIZE,(LPBYTE)points,dm))) {
477 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
480 /* this is _10ths_ of a millimeter */
485 GlobalUnlock(pdlga->hDevNames);
486 GlobalUnlock(pdlga->hDevMode);
487 HeapFree(GetProcessHeap(),0,Names);
488 HeapFree(GetProcessHeap(),0,points);
492 static BOOL PRINTDLG_PaperSizeW(
493 PRINTDLGW *pdlga,const WCHAR *PaperSize,LPPOINT size
497 LPWSTR devname,portname;
501 POINT *points = NULL;
504 dn = GlobalLock(pdlga->hDevNames);
505 dm = GlobalLock(pdlga->hDevMode);
506 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
507 portname = ((WCHAR*)dn)+dn->wOutputOffset;
510 NrOfEntries = DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,NULL,dm);
512 FIXME("No papernames found for %s/%s\n",debugstr_w(devname),debugstr_w(portname));
515 if (NrOfEntries == -1) {
516 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
520 Names = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*NrOfEntries*64);
521 if (NrOfEntries != (ret=DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,Names,dm))) {
522 FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
525 for (i=0;i<NrOfEntries;i++)
526 if (!lstrcmpW(PaperSize,Names+(64*i)))
528 HeapFree(GetProcessHeap(),0,Names);
529 if (i==NrOfEntries) {
530 FIXME("Papersize %s not found in list?\n",debugstr_w(PaperSize));
533 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
534 if (NrOfEntries!=(ret=DeviceCapabilitiesW(devname,portname,DC_PAPERSIZE,(LPWSTR)points,dm))) {
535 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
538 /* this is _10ths_ of a millimeter */
543 GlobalUnlock(pdlga->hDevNames);
544 GlobalUnlock(pdlga->hDevMode);
545 HeapFree(GetProcessHeap(),0,Names);
546 HeapFree(GetProcessHeap(),0,points);
551 /************************************************************************
552 * PRINTDLG_SetUpPaperComboBox
554 * Initialize either the papersize or inputslot combos of the Printer Setup
555 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
556 * We also try to re-select the old selection.
558 static BOOL PRINTDLG_SetUpPaperComboBoxA(HWND hDlg,
571 int fwCapability_Names;
572 int fwCapability_Words;
574 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName,PortName,nIDComboBox);
576 /* query the dialog box for the current selected value */
577 Sel = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
579 /* we enter here only if a different printer is selected after
580 * the Print Setup dialog is opened. The current settings are
581 * stored into the newly selected printer.
583 oldWord = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA,
586 if (nIDComboBox == cmb2)
587 dm->u1.s1.dmPaperSize = oldWord;
589 dm->dmDefaultSource = oldWord;
593 /* we enter here only when the Print setup dialog is initially
594 * opened. In this case the settings are restored from when
595 * the dialog was last closed.
598 if (nIDComboBox == cmb2)
599 oldWord = dm->u1.s1.dmPaperSize;
601 oldWord = dm->dmDefaultSource;
605 if (nIDComboBox == cmb2) {
607 fwCapability_Names = DC_PAPERNAMES;
608 fwCapability_Words = DC_PAPERS;
612 fwCapability_Names = DC_BINNAMES;
613 fwCapability_Words = DC_BINS;
616 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
617 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
619 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
620 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
621 fwCapability_Names, NULL, dm);
622 if (NrOfEntries == 0)
623 WARN("no Name Entries found!\n");
624 else if (NrOfEntries < 0)
627 if(DeviceCapabilitiesA(PrinterName, PortName, fwCapability_Words, NULL, dm)
629 ERR("Number of caps is different\n");
633 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(char)*NamesSize);
634 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
635 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
636 fwCapability_Names, Names, dm);
637 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
638 fwCapability_Words, (LPSTR)Words, dm);
640 /* reset any current content in the combobox */
641 SendDlgItemMessageA(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
643 /* store new content */
644 for (i = 0; i < NrOfEntries; i++) {
645 DWORD pos = SendDlgItemMessageA(hDlg, nIDComboBox, CB_ADDSTRING, 0,
646 (LPARAM)(&Names[i*NamesSize]) );
647 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
651 /* Look for old selection - can't do this is previous loop since
652 item order will change as more items are added */
654 for (i = 0; i < NrOfEntries; i++) {
655 if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
661 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
663 HeapFree(GetProcessHeap(),0,Words);
664 HeapFree(GetProcessHeap(),0,Names);
668 static BOOL PRINTDLG_SetUpPaperComboBoxW(HWND hDlg,
681 int fwCapability_Names;
682 int fwCapability_Words;
684 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName),debugstr_w(PortName),nIDComboBox);
686 /* query the dialog box for the current selected value */
687 Sel = SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
689 /* we enter here only if a different printer is selected after
690 * the Print Setup dialog is opened. The current settings are
691 * stored into the newly selected printer.
693 oldWord = SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETITEMDATA,
696 if (nIDComboBox == cmb2)
697 dm->u1.s1.dmPaperSize = oldWord;
699 dm->dmDefaultSource = oldWord;
703 /* we enter here only when the Print setup dialog is initially
704 * opened. In this case the settings are restored from when
705 * the dialog was last closed.
708 if (nIDComboBox == cmb2)
709 oldWord = dm->u1.s1.dmPaperSize;
711 oldWord = dm->dmDefaultSource;
715 if (nIDComboBox == cmb2) {
717 fwCapability_Names = DC_PAPERNAMES;
718 fwCapability_Words = DC_PAPERS;
722 fwCapability_Names = DC_BINNAMES;
723 fwCapability_Words = DC_BINS;
726 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
727 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
729 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
730 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
731 fwCapability_Names, NULL, dm);
732 if (NrOfEntries == 0)
733 WARN("no Name Entries found!\n");
734 else if (NrOfEntries < 0)
737 if(DeviceCapabilitiesW(PrinterName, PortName, fwCapability_Words, NULL, dm)
739 ERR("Number of caps is different\n");
743 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WCHAR)*NamesSize);
744 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
745 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
746 fwCapability_Names, Names, dm);
747 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
748 fwCapability_Words, (LPWSTR)Words, dm);
750 /* reset any current content in the combobox */
751 SendDlgItemMessageW(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
753 /* store new content */
754 for (i = 0; i < NrOfEntries; i++) {
755 DWORD pos = SendDlgItemMessageW(hDlg, nIDComboBox, CB_ADDSTRING, 0,
756 (LPARAM)(&Names[i*NamesSize]) );
757 SendDlgItemMessageW(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
761 /* Look for old selection - can't do this is previous loop since
762 item order will change as more items are added */
764 for (i = 0; i < NrOfEntries; i++) {
765 if(SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
771 SendDlgItemMessageW(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
773 HeapFree(GetProcessHeap(),0,Words);
774 HeapFree(GetProcessHeap(),0,Names);
779 /***********************************************************************
780 * PRINTDLG_UpdatePrinterInfoTexts [internal]
782 static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg, LPPRINTER_INFO_2A pi)
785 char ResourceString[256];
791 /* add all status messages */
792 for (i = 0; i < 25; i++) {
793 if (pi->Status & (1<<i)) {
794 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
795 ResourceString, 255);
796 strcat(StatusMsg,ResourceString);
800 /* FIXME: status==ready must only be appended if really so.
801 but how to detect? */
802 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
803 ResourceString, 255);
804 strcat(StatusMsg,ResourceString);
805 SetDlgItemTextA(hDlg, stc12, StatusMsg);
807 /* set all other printer info texts */
808 SetDlgItemTextA(hDlg, stc11, pi->pDriverName);
810 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
811 SetDlgItemTextA(hDlg, stc14, pi->pLocation);
813 SetDlgItemTextA(hDlg, stc14, pi->pPortName);
814 SetDlgItemTextA(hDlg, stc13, pi->pComment ? pi->pComment : "");
818 static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg, LPPRINTER_INFO_2W pi)
820 WCHAR StatusMsg[256];
821 WCHAR ResourceString[256];
822 static const WCHAR emptyW[] = {0};
828 /* add all status messages */
829 for (i = 0; i < 25; i++) {
830 if (pi->Status & (1<<i)) {
831 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
832 ResourceString, 255);
833 lstrcatW(StatusMsg,ResourceString);
837 /* FIXME: status==ready must only be appended if really so.
838 but how to detect? */
839 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
840 ResourceString, 255);
841 lstrcatW(StatusMsg,ResourceString);
842 SetDlgItemTextW(hDlg, stc12, StatusMsg);
844 /* set all other printer info texts */
845 SetDlgItemTextW(hDlg, stc11, pi->pDriverName);
846 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
847 SetDlgItemTextW(hDlg, stc14, pi->pLocation);
849 SetDlgItemTextW(hDlg, stc14, pi->pPortName);
850 SetDlgItemTextW(hDlg, stc13, pi->pComment ? pi->pComment : emptyW);
854 /*******************************************************************
856 * PRINTDLG_ChangePrinter
859 BOOL PRINTDLG_ChangePrinterA(HWND hDlg, char *name,
860 PRINT_PTRA *PrintStructures)
862 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
863 LPDEVMODEA lpdm = NULL;
868 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
869 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
870 if(!OpenPrinterA(name, &hprn, NULL)) {
871 ERR("Can't open printer %s\n", name);
874 GetPrinterA(hprn, 2, NULL, 0, &needed);
875 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,needed);
876 GetPrinterA(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
878 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
879 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,needed);
880 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
882 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures->lpPrinterInfo->pPrinterName);
887 PRINTDLG_UpdatePrinterInfoTextsA(hDlg, PrintStructures->lpPrinterInfo);
889 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
890 PrintStructures->lpDevMode = NULL;
892 dmSize = DocumentPropertiesA(0, 0, name, NULL, NULL, 0);
894 ERR("DocumentProperties fails on %s\n", debugstr_a(name));
897 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
898 dmSize = DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, NULL,
900 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
901 !strcmp(lpdm->dmDeviceName,
902 PrintStructures->lpDevMode->dmDeviceName)) {
903 /* Supplied devicemode matches current printer so try to use it */
904 DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, lpdm,
905 DM_OUT_BUFFER | DM_IN_BUFFER);
908 GlobalUnlock(lppd->hDevMode);
910 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
912 if(!(lppd->Flags & PD_PRINTSETUP)) {
913 /* Print range (All/Range/Selection) */
914 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
915 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
916 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
917 if (lppd->Flags & PD_NOSELECTION)
918 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
920 if (lppd->Flags & PD_SELECTION)
921 CheckRadioButton(hDlg, rad1, rad3, rad2);
922 if (lppd->Flags & PD_NOPAGENUMS) {
923 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
924 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
925 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
926 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
927 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
929 if (lppd->Flags & PD_PAGENUMS)
930 CheckRadioButton(hDlg, rad1, rad3, rad3);
935 * FIXME: The ico3 is not displayed for some reason. I don't know why.
937 if (lppd->Flags & PD_COLLATE) {
938 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
939 (LPARAM)PrintStructures->hCollateIcon);
940 CheckDlgButton(hDlg, chx2, 1);
942 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
943 (LPARAM)PrintStructures->hNoCollateIcon);
944 CheckDlgButton(hDlg, chx2, 0);
947 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
948 /* if printer doesn't support it: no Collate */
949 if (!(lpdm->dmFields & DM_COLLATE)) {
950 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
951 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
958 if (lppd->hDevMode == 0)
959 copies = lppd->nCopies;
961 copies = lpdm->dmCopies;
962 if(copies == 0) copies = 1;
963 else if(copies < 0) copies = MAX_COPIES;
964 SetDlgItemInt(hDlg, edt3, copies, FALSE);
967 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
968 /* if printer doesn't support it: no nCopies */
969 if (!(lpdm->dmFields & DM_COPIES)) {
970 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
971 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
976 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
977 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
978 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
979 if (lppd->Flags & PD_HIDEPRINTTOFILE)
980 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
982 } else { /* PD_PRINTSETUP */
983 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
985 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb2,
986 PrintStructures->lpPrinterInfo->pPrinterName,
987 PrintStructures->lpPrinterInfo->pPortName,
989 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb3,
990 PrintStructures->lpPrinterInfo->pPrinterName,
991 PrintStructures->lpPrinterInfo->pPortName,
993 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
994 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
995 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
996 PrintStructures->hLandscapeIcon));
1001 if ((lppd->Flags & PD_SHOWHELP)==0) {
1002 /* hide if PD_SHOWHELP not specified */
1003 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1008 static BOOL PRINTDLG_ChangePrinterW(HWND hDlg, WCHAR *name,
1009 PRINT_PTRW *PrintStructures)
1011 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1012 LPDEVMODEW lpdm = NULL;
1017 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
1018 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
1019 if(!OpenPrinterW(name, &hprn, NULL)) {
1020 ERR("Can't open printer %s\n", debugstr_w(name));
1023 GetPrinterW(hprn, 2, NULL, 0, &needed);
1024 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
1025 GetPrinterW(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
1027 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
1028 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
1029 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
1031 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures->lpPrinterInfo->pPrinterName));
1036 PRINTDLG_UpdatePrinterInfoTextsW(hDlg, PrintStructures->lpPrinterInfo);
1038 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
1039 PrintStructures->lpDevMode = NULL;
1041 dmSize = DocumentPropertiesW(0, 0, name, NULL, NULL, 0);
1043 ERR("DocumentProperties fails on %s\n", debugstr_w(name));
1046 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
1047 dmSize = DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, NULL,
1049 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
1050 !lstrcmpW(lpdm->dmDeviceName,
1051 PrintStructures->lpDevMode->dmDeviceName)) {
1052 /* Supplied devicemode matches current printer so try to use it */
1053 DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, lpdm,
1054 DM_OUT_BUFFER | DM_IN_BUFFER);
1057 GlobalUnlock(lppd->hDevMode);
1059 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
1061 if(!(lppd->Flags & PD_PRINTSETUP)) {
1062 /* Print range (All/Range/Selection) */
1063 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
1064 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
1065 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
1066 if (lppd->Flags & PD_NOSELECTION)
1067 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
1069 if (lppd->Flags & PD_SELECTION)
1070 CheckRadioButton(hDlg, rad1, rad3, rad2);
1071 if (lppd->Flags & PD_NOPAGENUMS) {
1072 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
1073 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
1074 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
1075 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
1076 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
1078 if (lppd->Flags & PD_PAGENUMS)
1079 CheckRadioButton(hDlg, rad1, rad3, rad3);
1084 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1086 if (lppd->Flags & PD_COLLATE) {
1087 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1088 (LPARAM)PrintStructures->hCollateIcon);
1089 CheckDlgButton(hDlg, chx2, 1);
1091 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1092 (LPARAM)PrintStructures->hNoCollateIcon);
1093 CheckDlgButton(hDlg, chx2, 0);
1096 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1097 /* if printer doesn't support it: no Collate */
1098 if (!(lpdm->dmFields & DM_COLLATE)) {
1099 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1100 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
1107 if (lppd->hDevMode == 0)
1108 copies = lppd->nCopies;
1110 copies = lpdm->dmCopies;
1111 if(copies == 0) copies = 1;
1112 else if(copies < 0) copies = MAX_COPIES;
1113 SetDlgItemInt(hDlg, edt3, copies, FALSE);
1116 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1117 /* if printer doesn't support it: no nCopies */
1118 if (!(lpdm->dmFields & DM_COPIES)) {
1119 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
1120 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
1125 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
1126 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
1127 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
1128 if (lppd->Flags & PD_HIDEPRINTTOFILE)
1129 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
1131 } else { /* PD_PRINTSETUP */
1132 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
1134 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb2,
1135 PrintStructures->lpPrinterInfo->pPrinterName,
1136 PrintStructures->lpPrinterInfo->pPortName,
1138 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb3,
1139 PrintStructures->lpPrinterInfo->pPrinterName,
1140 PrintStructures->lpPrinterInfo->pPortName,
1142 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1143 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1144 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1145 PrintStructures->hLandscapeIcon));
1150 if ((lppd->Flags & PD_SHOWHELP)==0) {
1151 /* hide if PD_SHOWHELP not specified */
1152 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1157 /***********************************************************************
1158 * PRINTDLG_WMInitDialog [internal]
1160 static LRESULT PRINTDLG_WMInitDialog(HWND hDlg, WPARAM wParam,
1161 PRINT_PTRA* PrintStructures)
1163 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
1167 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1169 /* load Collate ICONs */
1170 /* We load these with LoadImage because they are not a standard
1171 size and we don't want them rescaled */
1172 PrintStructures->hCollateIcon =
1173 LoadImageA(COMDLG32_hInstance, "PD32_COLLATE", IMAGE_ICON, 0, 0, 0);
1174 PrintStructures->hNoCollateIcon =
1175 LoadImageA(COMDLG32_hInstance, "PD32_NOCOLLATE", IMAGE_ICON, 0, 0, 0);
1177 /* These can be done with LoadIcon */
1178 PrintStructures->hPortraitIcon =
1179 LoadIconA(COMDLG32_hInstance, "PD32_PORTRAIT");
1180 PrintStructures->hLandscapeIcon =
1181 LoadIconA(COMDLG32_hInstance, "PD32_LANDSCAPE");
1183 /* display the collate/no_collate icon */
1184 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1185 (LPARAM)PrintStructures->hNoCollateIcon);
1187 if(PrintStructures->hCollateIcon == 0 ||
1188 PrintStructures->hNoCollateIcon == 0 ||
1189 PrintStructures->hPortraitIcon == 0 ||
1190 PrintStructures->hLandscapeIcon == 0) {
1191 ERR("no icon in resourcefile\n");
1192 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1193 EndDialog(hDlg, FALSE);
1197 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1198 * must be registered and the Help button must be shown.
1200 if (lppd->Flags & PD_SHOWHELP) {
1201 if((PrintStructures->HelpMessageID =
1202 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
1203 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1207 PrintStructures->HelpMessageID = 0;
1209 if(!(lppd->Flags &PD_PRINTSETUP)) {
1210 PrintStructures->hwndUpDown =
1211 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1212 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1213 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1214 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1215 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1218 /* FIXME: I allow more freedom than either Win95 or WinNT,
1219 * which do not agree to what errors should be thrown or not
1220 * in case nToPage or nFromPage is out-of-range.
1222 if (lppd->nMaxPage < lppd->nMinPage)
1223 lppd->nMaxPage = lppd->nMinPage;
1224 if (lppd->nMinPage == lppd->nMaxPage)
1225 lppd->Flags |= PD_NOPAGENUMS;
1226 if (lppd->nToPage < lppd->nMinPage)
1227 lppd->nToPage = lppd->nMinPage;
1228 if (lppd->nToPage > lppd->nMaxPage)
1229 lppd->nToPage = lppd->nMaxPage;
1230 if (lppd->nFromPage < lppd->nMinPage)
1231 lppd->nFromPage = lppd->nMinPage;
1232 if (lppd->nFromPage > lppd->nMaxPage)
1233 lppd->nFromPage = lppd->nMaxPage;
1235 /* if we have the combo box, fill it */
1236 if (GetDlgItem(hDlg,comboID)) {
1239 pdn = GlobalLock(lppd->hDevNames);
1240 pdm = GlobalLock(lppd->hDevMode);
1242 name = (char*)pdn + pdn->wDeviceOffset;
1244 name = pdm->dmDeviceName;
1245 PRINTDLG_SetUpPrinterListComboA(hDlg, comboID, name);
1246 if(pdm) GlobalUnlock(lppd->hDevMode);
1247 if(pdn) GlobalUnlock(lppd->hDevNames);
1249 /* Now find selected printer and update rest of dlg */
1250 name = HeapAlloc(GetProcessHeap(),0,256);
1251 if (GetDlgItemTextA(hDlg, comboID, name, 255))
1252 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1253 HeapFree(GetProcessHeap(),0,name);
1255 /* else use default printer */
1257 DWORD dwBufLen = sizeof(name);
1258 BOOL ret = GetDefaultPrinterA(name, &dwBufLen);
1261 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1263 FIXME("No default printer found, expect problems!\n");
1268 static LRESULT PRINTDLG_WMInitDialogW(HWND hDlg, WPARAM wParam,
1269 PRINT_PTRW* PrintStructures)
1271 const static WCHAR PD32_COLLATE[] = { 'P', 'D', '3', '2', '_', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
1272 const static WCHAR PD32_NOCOLLATE[] = { 'P', 'D', '3', '2', '_', 'N', 'O', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
1273 const static WCHAR PD32_PORTRAIT[] = { 'P', 'D', '3', '2', '_', 'P', 'O', 'R', 'T', 'R', 'A', 'I', 'T', 0 };
1274 const static WCHAR PD32_LANDSCAPE[] = { 'P', 'D', '3', '2', '_', 'L', 'A', 'N', 'D', 'S', 'C', 'A', 'P', 'E', 0 };
1275 LPPRINTDLGW 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 LoadImageW(COMDLG32_hInstance, PD32_COLLATE, IMAGE_ICON, 0, 0, 0);
1286 PrintStructures->hNoCollateIcon =
1287 LoadImageW(COMDLG32_hInstance, PD32_NOCOLLATE, IMAGE_ICON, 0, 0, 0);
1289 /* These can be done with LoadIcon */
1290 PrintStructures->hPortraitIcon =
1291 LoadIconW(COMDLG32_hInstance, PD32_PORTRAIT);
1292 PrintStructures->hLandscapeIcon =
1293 LoadIconW(COMDLG32_hInstance, PD32_LANDSCAPE);
1295 /* display the collate/no_collate icon */
1296 SendDlgItemMessageW(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 RegisterWindowMessageW(HELPMSGSTRINGW)) == 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 = (WCHAR*)pdn + pdn->wDeviceOffset;
1356 name = pdm->dmDeviceName;
1357 PRINTDLG_SetUpPrinterListComboW(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 /* ansi is ok here */
1363 name = HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR));
1364 if (GetDlgItemTextW(hDlg, comboID, name, 255))
1365 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1366 HeapFree(GetProcessHeap(),0,name);
1368 /* else use default printer */
1370 DWORD dwBufLen = sizeof(name) / sizeof(WCHAR);
1371 BOOL ret = GetDefaultPrinterW(name, &dwBufLen);
1374 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1376 FIXME("No default printer found, expect problems!\n");
1381 /***********************************************************************
1382 * PRINTDLG_WMCommand [internal]
1384 LRESULT PRINTDLG_WMCommandA(HWND hDlg, WPARAM wParam,
1385 LPARAM lParam, PRINT_PTRA* PrintStructures)
1387 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
1388 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1389 LPDEVMODEA lpdm = PrintStructures->lpDevMode;
1391 switch (LOWORD(wParam)) {
1393 TRACE(" OK button was hit\n");
1394 if (!PRINTDLG_UpdatePrintDlgA(hDlg, PrintStructures)) {
1395 FIXME("Update printdlg was not successful!\n");
1398 EndDialog(hDlg, TRUE);
1402 TRACE(" CANCEL button was hit\n");
1403 EndDialog(hDlg, FALSE);
1407 TRACE(" HELP button was hit\n");
1408 SendMessageA(lppd->hwndOwner, PrintStructures->HelpMessageID,
1409 (WPARAM) hDlg, (LPARAM) lppd);
1412 case chx2: /* collate pages checkbox */
1413 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1414 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1415 (LPARAM)PrintStructures->hCollateIcon);
1417 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1418 (LPARAM)PrintStructures->hNoCollateIcon);
1420 case edt1: /* from page nr editbox */
1421 case edt2: /* to page nr editbox */
1422 if (HIWORD(wParam)==EN_CHANGE) {
1425 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1426 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1427 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1428 CheckRadioButton(hDlg, rad1, rad3, rad3);
1433 if(HIWORD(wParam) == EN_CHANGE) {
1434 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1436 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1438 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1443 case psh1: /* Print Setup */
1447 if (!PrintStructures->dlg.lpPrintDlg16) {
1448 FIXME("The 32bit print dialog does not have this button!?\n");
1452 memcpy(&pdlg,PrintStructures->dlg.lpPrintDlg16,sizeof(pdlg));
1453 pdlg.Flags |= PD_PRINTSETUP;
1454 pdlg.hwndOwner = HWND_16(hDlg);
1455 if (!PrintDlg16(&pdlg))
1460 case psh2: /* Properties button */
1463 char PrinterName[256];
1465 GetDlgItemTextA(hDlg, PrinterComboID, PrinterName, 255);
1466 if (!OpenPrinterA(PrinterName, &hPrinter, NULL)) {
1467 FIXME(" Call to OpenPrinter did not succeed!\n");
1470 DocumentPropertiesA(hDlg, hPrinter, PrinterName,
1471 PrintStructures->lpDevMode,
1472 PrintStructures->lpDevMode,
1473 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1474 ClosePrinter(hPrinter);
1478 case rad1: /* Paperorientation */
1479 if (lppd->Flags & PD_PRINTSETUP)
1481 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1482 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1483 (LPARAM)(PrintStructures->hPortraitIcon));
1487 case rad2: /* Paperorientation */
1488 if (lppd->Flags & PD_PRINTSETUP)
1490 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1491 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1492 (LPARAM)(PrintStructures->hLandscapeIcon));
1496 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1497 if (PrinterComboID != LOWORD(wParam)) {
1498 FIXME("No handling for print quality combo box yet.\n");
1502 case cmb4: /* Printer combobox */
1503 if (HIWORD(wParam)==CBN_SELCHANGE) {
1504 char PrinterName[256];
1505 GetDlgItemTextA(hDlg, LOWORD(wParam), PrinterName, 255);
1506 PRINTDLG_ChangePrinterA(hDlg, PrinterName, PrintStructures);
1510 case cmb2: /* Papersize */
1512 DWORD Sel = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1514 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
1520 case cmb3: /* Bin */
1522 DWORD Sel = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1524 lpdm->dmDefaultSource = SendDlgItemMessageA(hDlg, cmb3,
1525 CB_GETITEMDATA, Sel,
1530 if(lppd->Flags & PD_PRINTSETUP) {
1531 switch (LOWORD(wParam)) {
1532 case rad1: /* orientation */
1534 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1535 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1536 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1537 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1539 (LPARAM)PrintStructures->hPortraitIcon);
1540 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1542 (LPARAM)PrintStructures->hPortraitIcon);
1545 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1546 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1547 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1549 (LPARAM)PrintStructures->hLandscapeIcon);
1550 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1552 (LPARAM)PrintStructures->hLandscapeIcon);
1561 static LRESULT PRINTDLG_WMCommandW(HWND hDlg, WPARAM wParam,
1562 LPARAM lParam, PRINT_PTRW* PrintStructures)
1564 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1565 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1566 LPDEVMODEW lpdm = PrintStructures->lpDevMode;
1568 switch (LOWORD(wParam)) {
1570 TRACE(" OK button was hit\n");
1571 if (!PRINTDLG_UpdatePrintDlgW(hDlg, PrintStructures)) {
1572 FIXME("Update printdlg was not successful!\n");
1575 EndDialog(hDlg, TRUE);
1579 TRACE(" CANCEL button was hit\n");
1580 EndDialog(hDlg, FALSE);
1584 TRACE(" HELP button was hit\n");
1585 SendMessageW(lppd->hwndOwner, PrintStructures->HelpMessageID,
1586 (WPARAM) hDlg, (LPARAM) lppd);
1589 case chx2: /* collate pages checkbox */
1590 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1591 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1592 (LPARAM)PrintStructures->hCollateIcon);
1594 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1595 (LPARAM)PrintStructures->hNoCollateIcon);
1597 case edt1: /* from page nr editbox */
1598 case edt2: /* to page nr editbox */
1599 if (HIWORD(wParam)==EN_CHANGE) {
1602 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1603 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1604 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1605 CheckRadioButton(hDlg, rad1, rad3, rad3);
1610 if(HIWORD(wParam) == EN_CHANGE) {
1611 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1613 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1615 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1619 case psh1: /* Print Setup */
1621 ERR("psh1 is called from 16bit code only, we should not get here.\n");
1624 case psh2: /* Properties button */
1627 WCHAR PrinterName[256];
1629 if (!GetDlgItemTextW(hDlg, PrinterComboID, PrinterName, 255)) break;
1630 if (!OpenPrinterW(PrinterName, &hPrinter, NULL)) {
1631 FIXME(" Call to OpenPrinter did not succeed!\n");
1634 DocumentPropertiesW(hDlg, hPrinter, PrinterName,
1635 PrintStructures->lpDevMode,
1636 PrintStructures->lpDevMode,
1637 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1638 ClosePrinter(hPrinter);
1642 case rad1: /* Paperorientation */
1643 if (lppd->Flags & PD_PRINTSETUP)
1645 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1646 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1647 (LPARAM)(PrintStructures->hPortraitIcon));
1651 case rad2: /* Paperorientation */
1652 if (lppd->Flags & PD_PRINTSETUP)
1654 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1655 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1656 (LPARAM)(PrintStructures->hLandscapeIcon));
1660 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1661 if (PrinterComboID != LOWORD(wParam)) {
1662 FIXME("No handling for print quality combo box yet.\n");
1666 case cmb4: /* Printer combobox */
1667 if (HIWORD(wParam)==CBN_SELCHANGE) {
1668 WCHAR PrinterName[256];
1669 GetDlgItemTextW(hDlg, LOWORD(wParam), PrinterName, 255);
1670 PRINTDLG_ChangePrinterW(hDlg, PrinterName, PrintStructures);
1674 case cmb2: /* Papersize */
1676 DWORD Sel = SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1678 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageW(hDlg, cmb2,
1684 case cmb3: /* Bin */
1686 DWORD Sel = SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1688 lpdm->dmDefaultSource = SendDlgItemMessageW(hDlg, cmb3,
1689 CB_GETITEMDATA, Sel,
1694 if(lppd->Flags & PD_PRINTSETUP) {
1695 switch (LOWORD(wParam)) {
1696 case rad1: /* orientation */
1698 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1699 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1700 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1701 SendDlgItemMessageW(hDlg, stc10, STM_SETIMAGE,
1703 (LPARAM)PrintStructures->hPortraitIcon);
1704 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE,
1706 (LPARAM)PrintStructures->hPortraitIcon);
1709 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1710 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1711 SendDlgItemMessageW(hDlg, stc10, STM_SETIMAGE,
1713 (LPARAM)PrintStructures->hLandscapeIcon);
1714 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE,
1716 (LPARAM)PrintStructures->hLandscapeIcon);
1725 /***********************************************************************
1726 * PrintDlgProcA [internal]
1728 static INT_PTR CALLBACK PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
1731 PRINT_PTRA* PrintStructures;
1732 INT_PTR res = FALSE;
1734 if (uMsg!=WM_INITDIALOG) {
1735 PrintStructures = (PRINT_PTRA*)GetPropA(hDlg,"__WINE_PRINTDLGDATA");
1736 if (!PrintStructures)
1739 PrintStructures = (PRINT_PTRA*) lParam;
1740 SetPropA(hDlg,"__WINE_PRINTDLGDATA",PrintStructures);
1741 res = PRINTDLG_WMInitDialog(hDlg, wParam, PrintStructures);
1743 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
1744 res = PrintStructures->lpPrintDlg->lpfnPrintHook(
1745 hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg
1750 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
1751 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam,
1758 return PRINTDLG_WMCommandA(hDlg, wParam, lParam, PrintStructures);
1761 DestroyIcon(PrintStructures->hCollateIcon);
1762 DestroyIcon(PrintStructures->hNoCollateIcon);
1763 DestroyIcon(PrintStructures->hPortraitIcon);
1764 DestroyIcon(PrintStructures->hLandscapeIcon);
1765 if(PrintStructures->hwndUpDown)
1766 DestroyWindow(PrintStructures->hwndUpDown);
1772 static INT_PTR CALLBACK PrintDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
1775 static const WCHAR propW[] = {'_','_','W','I','N','E','_','P','R','I','N','T','D','L','G','D','A','T','A',0};
1776 PRINT_PTRW* PrintStructures;
1777 INT_PTR res = FALSE;
1779 if (uMsg!=WM_INITDIALOG) {
1780 PrintStructures = (PRINT_PTRW*) GetPropW(hDlg, propW);
1781 if (!PrintStructures)
1784 PrintStructures = (PRINT_PTRW*) lParam;
1785 SetPropW(hDlg, propW, PrintStructures);
1786 res = PRINTDLG_WMInitDialogW(hDlg, wParam, PrintStructures);
1788 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
1789 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg);
1793 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
1794 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam, lParam);
1800 return PRINTDLG_WMCommandW(hDlg, wParam, lParam, PrintStructures);
1803 DestroyIcon(PrintStructures->hCollateIcon);
1804 DestroyIcon(PrintStructures->hNoCollateIcon);
1805 DestroyIcon(PrintStructures->hPortraitIcon);
1806 DestroyIcon(PrintStructures->hLandscapeIcon);
1807 if(PrintStructures->hwndUpDown)
1808 DestroyWindow(PrintStructures->hwndUpDown);
1814 /************************************************************
1816 * PRINTDLG_GetDlgTemplate
1819 static HGLOBAL PRINTDLG_GetDlgTemplateA(PRINTDLGA *lppd)
1824 if (lppd->Flags & PD_PRINTSETUP) {
1825 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
1826 hDlgTmpl = lppd->hSetupTemplate;
1827 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
1828 hResInfo = FindResourceA(lppd->hInstance,
1829 lppd->lpSetupTemplateName, (LPSTR)RT_DIALOG);
1830 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1832 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32_SETUP",
1834 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1837 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
1838 hDlgTmpl = lppd->hPrintTemplate;
1839 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
1840 hResInfo = FindResourceA(lppd->hInstance,
1841 lppd->lpPrintTemplateName,
1843 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1845 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32",
1847 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1853 static HGLOBAL PRINTDLG_GetDlgTemplateW(PRINTDLGW *lppd)
1857 static const WCHAR xpsetup[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
1858 static const WCHAR xprint[] = { 'P','R','I','N','T','3','2',0};
1860 if (lppd->Flags & PD_PRINTSETUP) {
1861 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
1862 hDlgTmpl = lppd->hSetupTemplate;
1863 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
1864 hResInfo = FindResourceW(lppd->hInstance,
1865 lppd->lpSetupTemplateName, (LPWSTR)RT_DIALOG);
1866 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1868 hResInfo = FindResourceW(COMDLG32_hInstance, xpsetup, (LPWSTR)RT_DIALOG);
1869 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1872 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
1873 hDlgTmpl = lppd->hPrintTemplate;
1874 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
1875 hResInfo = FindResourceW(lppd->hInstance,
1876 lppd->lpPrintTemplateName,
1878 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1880 hResInfo = FindResourceW(COMDLG32_hInstance, xprint, (LPWSTR)RT_DIALOG);
1881 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1887 /***********************************************************************
1892 static BOOL PRINTDLG_CreateDCA(LPPRINTDLGA lppd)
1894 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
1895 DEVMODEA *pdm = GlobalLock(lppd->hDevMode);
1897 if(lppd->Flags & PD_RETURNDC) {
1898 lppd->hDC = CreateDCA((char*)pdn + pdn->wDriverOffset,
1899 (char*)pdn + pdn->wDeviceOffset,
1900 (char*)pdn + pdn->wOutputOffset,
1902 } else if(lppd->Flags & PD_RETURNIC) {
1903 lppd->hDC = CreateICA((char*)pdn + pdn->wDriverOffset,
1904 (char*)pdn + pdn->wDeviceOffset,
1905 (char*)pdn + pdn->wOutputOffset,
1908 GlobalUnlock(lppd->hDevNames);
1909 GlobalUnlock(lppd->hDevMode);
1910 return lppd->hDC ? TRUE : FALSE;
1913 static BOOL PRINTDLG_CreateDCW(LPPRINTDLGW lppd)
1915 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
1916 DEVMODEW *pdm = GlobalLock(lppd->hDevMode);
1918 if(lppd->Flags & PD_RETURNDC) {
1919 lppd->hDC = CreateDCW((WCHAR*)pdn + pdn->wDriverOffset,
1920 (WCHAR*)pdn + pdn->wDeviceOffset,
1921 (WCHAR*)pdn + pdn->wOutputOffset,
1923 } else if(lppd->Flags & PD_RETURNIC) {
1924 lppd->hDC = CreateICW((WCHAR*)pdn + pdn->wDriverOffset,
1925 (WCHAR*)pdn + pdn->wDeviceOffset,
1926 (WCHAR*)pdn + pdn->wOutputOffset,
1929 GlobalUnlock(lppd->hDevNames);
1930 GlobalUnlock(lppd->hDevMode);
1931 return lppd->hDC ? TRUE : FALSE;
1934 /***********************************************************************
1935 * PrintDlgA (COMDLG32.@)
1937 * Displays the the PRINT dialog box, which enables the user to specify
1938 * specific properties of the print job.
1941 * nonzero if the user pressed the OK button
1942 * zero if the user cancelled the window or an error occurred
1946 * * The Collate Icons do not display, even though they are in the code.
1947 * * The Properties Button(s) should call DocumentPropertiesA().
1950 BOOL WINAPI PrintDlgA(
1951 LPPRINTDLGA lppd /* [in/out] ptr to PRINTDLG32 struct */
1956 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrA( lppd->hwndOwner, GWLP_HINSTANCE );
1958 if(TRACE_ON(commdlg)) {
1959 char flagstr[1000] = "";
1960 struct pd_flags *pflag = pd_flags;
1961 for( ; pflag->name; pflag++) {
1962 if(lppd->Flags & pflag->flag)
1963 strcat(flagstr, pflag->name);
1965 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
1966 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
1967 "flags %08lx (%s)\n",
1968 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
1969 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
1970 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
1973 if(lppd->lStructSize != sizeof(PRINTDLGA)) {
1974 WARN("structure size failure !!!\n");
1975 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
1979 if(lppd->Flags & PD_RETURNDEFAULT) {
1980 PRINTER_INFO_2A *pbuf;
1981 DRIVER_INFO_3A *dbuf;
1985 if(lppd->hDevMode || lppd->hDevNames) {
1986 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
1987 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
1990 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
1991 WARN("Can't find default printer\n");
1992 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
1996 GetPrinterA(hprn, 2, NULL, 0, &needed);
1997 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
1998 GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2000 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
2001 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
2002 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2003 ERR("GetPrinterDriverA failed, le %ld, fix your config for printer %s!\n",GetLastError(),pbuf->pPrinterName);
2004 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2009 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2013 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2014 pbuf->pDevMode->dmDriverExtra);
2015 ptr = GlobalLock(lppd->hDevMode);
2016 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2017 pbuf->pDevMode->dmDriverExtra);
2018 GlobalUnlock(lppd->hDevMode);
2019 HeapFree(GetProcessHeap(), 0, pbuf);
2020 HeapFree(GetProcessHeap(), 0, dbuf);
2024 PRINT_PTRA *PrintStructures;
2026 /* load Dialog resources,
2027 * depending on Flags indicates Print32 or Print32_setup dialog
2029 hDlgTmpl = PRINTDLG_GetDlgTemplateA(lppd);
2031 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2034 ptr = LockResource( hDlgTmpl );
2036 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2040 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2041 sizeof(PRINT_PTRA));
2042 PrintStructures->lpPrintDlg = lppd;
2044 /* and create & process the dialog .
2045 * -1 is failure, 0 is broken hwnd, everything else is ok.
2047 bRet = (0<DialogBoxIndirectParamA(hInst, ptr, lppd->hwndOwner,
2049 (LPARAM)PrintStructures));
2052 DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2053 PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
2054 DRIVER_INFO_3A *di = PrintStructures->lpDriverInfo;
2056 if (lppd->hDevMode == 0) {
2057 TRACE(" No hDevMode yet... Need to create my own\n");
2058 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2059 lpdm->dmSize + lpdm->dmDriverExtra);
2062 if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
2063 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2065 GlobalUnlock(lppd->hDevMode);
2066 TRACE("Now got %d locks\n", locks);
2069 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2070 lpdm->dmSize + lpdm->dmDriverExtra,
2073 lpdmReturn = GlobalLock(lppd->hDevMode);
2074 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2076 if (lppd->hDevNames != 0) {
2078 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
2079 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2081 GlobalUnlock(lppd->hDevNames);
2084 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2089 GlobalUnlock(lppd->hDevMode);
2091 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2092 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2093 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2094 HeapFree(GetProcessHeap(), 0, PrintStructures);
2096 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2097 bRet = PRINTDLG_CreateDCA(lppd);
2099 TRACE("exit! (%d)\n", bRet);
2103 /***********************************************************************
2104 * PrintDlgW (COMDLG32.@)
2106 BOOL WINAPI PrintDlgW(
2107 LPPRINTDLGW lppd /* [in/out] ptr to PRINTDLG32 struct */
2112 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW( lppd->hwndOwner, GWLP_HINSTANCE );
2114 if(TRACE_ON(commdlg)) {
2115 char flagstr[1000] = "";
2116 struct pd_flags *pflag = pd_flags;
2117 for( ; pflag->name; pflag++) {
2118 if(lppd->Flags & pflag->flag)
2119 strcat(flagstr, pflag->name);
2121 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2122 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2123 "flags %08lx (%s)\n",
2124 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2125 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2126 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2129 if(lppd->lStructSize != sizeof(PRINTDLGW)) {
2130 WARN("structure size failure !!!\n");
2131 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2135 if(lppd->Flags & PD_RETURNDEFAULT) {
2136 PRINTER_INFO_2W *pbuf;
2137 DRIVER_INFO_3W *dbuf;
2141 if(lppd->hDevMode || lppd->hDevNames) {
2142 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2143 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2146 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2147 WARN("Can't find default printer\n");
2148 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2152 GetPrinterW(hprn, 2, NULL, 0, &needed);
2153 pbuf = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*needed);
2154 GetPrinterW(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2156 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
2157 dbuf = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
2158 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2159 ERR("GetPrinterDriverA failed, le %ld, fix your config for printer %s!\n",GetLastError(),debugstr_w(pbuf->pPrinterName));
2160 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2165 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2169 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2170 pbuf->pDevMode->dmDriverExtra);
2171 ptr = GlobalLock(lppd->hDevMode);
2172 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2173 pbuf->pDevMode->dmDriverExtra);
2174 GlobalUnlock(lppd->hDevMode);
2175 HeapFree(GetProcessHeap(), 0, pbuf);
2176 HeapFree(GetProcessHeap(), 0, dbuf);
2180 PRINT_PTRW *PrintStructures;
2182 /* load Dialog resources,
2183 * depending on Flags indicates Print32 or Print32_setup dialog
2185 hDlgTmpl = PRINTDLG_GetDlgTemplateW(lppd);
2187 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2190 ptr = LockResource( hDlgTmpl );
2192 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2196 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2197 sizeof(PRINT_PTRW));
2198 PrintStructures->lpPrintDlg = lppd;
2200 /* and create & process the dialog .
2201 * -1 is failure, 0 is broken hwnd, everything else is ok.
2203 bRet = (0<DialogBoxIndirectParamW(hInst, ptr, lppd->hwndOwner,
2205 (LPARAM)PrintStructures));
2208 DEVMODEW *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2209 PRINTER_INFO_2W *pi = PrintStructures->lpPrinterInfo;
2210 DRIVER_INFO_3W *di = PrintStructures->lpDriverInfo;
2212 if (lppd->hDevMode == 0) {
2213 TRACE(" No hDevMode yet... Need to create my own\n");
2214 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2215 lpdm->dmSize + lpdm->dmDriverExtra);
2218 if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
2219 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2221 GlobalUnlock(lppd->hDevMode);
2222 TRACE("Now got %d locks\n", locks);
2225 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2226 lpdm->dmSize + lpdm->dmDriverExtra,
2229 lpdmReturn = GlobalLock(lppd->hDevMode);
2230 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2232 if (lppd->hDevNames != 0) {
2234 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
2235 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2237 GlobalUnlock(lppd->hDevNames);
2240 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2245 GlobalUnlock(lppd->hDevMode);
2247 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2248 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2249 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2250 HeapFree(GetProcessHeap(), 0, PrintStructures);
2252 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2253 bRet = PRINTDLG_CreateDCW(lppd);
2255 TRACE("exit! (%d)\n", bRet);
2259 /***********************************************************************
2264 * cmb1 - printer select (not in standart dialog template)
2266 * cmb3 - source (tray?)
2267 * edt4 - border left
2269 * edt6 - border right
2270 * edt7 - border bottom
2271 * psh3 - "Printer..."
2275 LPPAGESETUPDLGA dlga;
2280 LPPAGESETUPDLGW dlga;
2284 static HGLOBAL PRINTDLG_GetPGSTemplateA(PAGESETUPDLGA *lppd)
2289 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2290 hDlgTmpl = lppd->hPageSetupTemplate;
2291 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2292 hResInfo = FindResourceA(lppd->hInstance,
2293 lppd->lpPageSetupTemplateName, (LPSTR)RT_DIALOG);
2294 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2296 hResInfo = FindResourceA(COMDLG32_hInstance,(LPCSTR)PAGESETUPDLGORD,(LPSTR)RT_DIALOG);
2297 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2302 static HGLOBAL PRINTDLG_GetPGSTemplateW(PAGESETUPDLGW *lppd)
2307 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2308 hDlgTmpl = lppd->hPageSetupTemplate;
2309 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2310 hResInfo = FindResourceW(lppd->hInstance,
2311 lppd->lpPageSetupTemplateName, (LPWSTR)RT_DIALOG);
2312 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2314 hResInfo = FindResourceW(COMDLG32_hInstance,(LPCWSTR)PAGESETUPDLGORD,(LPWSTR)RT_DIALOG);
2315 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2321 _c_10mm2size(PAGESETUPDLGA *dlga,DWORD size) {
2322 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2323 return 10*size*10/25.4;
2324 /* If we don't have a flag, we can choose one. Use millimeters
2325 * to avoid confusing me
2327 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2333 _c_inch2size(PAGESETUPDLGA *dlga,DWORD size) {
2334 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2336 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
2337 return (size*254)/10;
2338 /* if we don't have a flag, we can choose one. Use millimeters
2339 * to avoid confusing me
2341 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2342 return (size*254)/10;
2346 _c_size2strA(PageSetupDataA *pda,DWORD size,LPSTR strout) {
2347 strcpy(strout,"<undef>");
2348 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2349 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
2352 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2353 sprintf(strout,"%.2fin",(size*1.0)/1000.0);
2356 pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2357 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
2361 _c_size2strW(PageSetupDataW *pda,DWORD size,LPWSTR strout) {
2362 const static WCHAR UNDEF[] = { '<', 'u', 'n', 'd', 'e', 'f', '>', 0 };
2363 const static WCHAR mm_fmt[] = { '%', '.', '2', 'f', 'm', 'm', 0 };
2364 const static WCHAR in_fmt[] = { '%', '.', '2', 'f', 'i', 'n', 0 };
2365 lstrcpyW(strout, UNDEF);
2366 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2367 wsprintfW(strout,mm_fmt,(size*1.0)/100.0);
2370 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2371 wsprintfW(strout,in_fmt,(size*1.0)/1000.0);
2374 pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2375 wsprintfW(strout,mm_fmt,(size*1.0)/100.0);
2380 _c_str2sizeA(PAGESETUPDLGA *dlga,LPCSTR strin) {
2385 if (!sscanf(strin,"%f%s",&val,rest))
2388 if (!strcmp(rest,"in") || !strcmp(rest,"inch")) {
2389 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2392 return val*25.4*100;
2394 if (!strcmp(rest,"cm")) { rest[0]='m'; val = val*10.0; }
2395 if (!strcmp(rest,"m")) { strcpy(rest,"mm"); val = val*1000.0; }
2397 if (!strcmp(rest,"mm")) {
2398 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
2401 return 1000.0*val/25.4;
2403 if (rest[0]=='\0') {
2404 /* use application supplied default */
2405 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2409 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2414 ERR("Did not find a conversion for type '%s'!\n",rest);
2420 _c_str2sizeW(PAGESETUPDLGW *dlga, LPCWSTR strin) {
2423 /* this W -> A transition is OK */
2424 /* we need a unicode version of sscanf to avoid it */
2425 WideCharToMultiByte(CP_ACP, 0, strin, -1, buf, sizeof(buf), NULL, NULL);
2426 return _c_str2sizeA((PAGESETUPDLGA *)dlga, buf);
2431 * This is called on finish and will update the output fields of the
2435 PRINTDLG_PS_UpdateDlgStructA(HWND hDlg, PageSetupDataA *pda) {
2438 LPSTR devname,portname;
2442 dn = GlobalLock(pda->pdlg.hDevNames);
2443 dm = GlobalLock(pda->pdlg.hDevMode);
2444 devname = ((char*)dn)+dn->wDeviceOffset;
2445 portname = ((char*)dn)+dn->wOutputOffset;
2446 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb2,devname,portname,dm);
2447 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb3,devname,portname,dm);
2449 if (GetDlgItemTextA(hDlg,cmb2,papername,sizeof(papername))>0) {
2450 PRINTDLG_PaperSizeA(&(pda->pdlg),papername,&(pda->dlga->ptPaperSize));
2451 pda->dlga->ptPaperSize.x = _c_10mm2size(pda->dlga,pda->dlga->ptPaperSize.x);
2452 pda->dlga->ptPaperSize.y = _c_10mm2size(pda->dlga,pda->dlga->ptPaperSize.y);
2454 FIXME("could not get dialog text for papersize cmbbox?\n");
2455 #define GETVAL(id,val) if (GetDlgItemTextA(hDlg,id,buf,sizeof(buf))>0) { val = _c_str2sizeA(pda->dlga,buf); } else { FIXME("could not get dlgitemtexta for %x\n",id); }
2456 GETVAL(edt4,pda->dlga->rtMargin.left);
2457 GETVAL(edt5,pda->dlga->rtMargin.top);
2458 GETVAL(edt6,pda->dlga->rtMargin.right);
2459 GETVAL(edt7,pda->dlga->rtMargin.bottom);
2462 /* If we are in landscape, swap x and y of page size */
2463 if (IsDlgButtonChecked(hDlg, rad2)) {
2465 tmp = pda->dlga->ptPaperSize.x;
2466 pda->dlga->ptPaperSize.x = pda->dlga->ptPaperSize.y;
2467 pda->dlga->ptPaperSize.y = tmp;
2469 GlobalUnlock(pda->pdlg.hDevNames);
2470 GlobalUnlock(pda->pdlg.hDevMode);
2475 PRINTDLG_PS_UpdateDlgStructW(HWND hDlg, PageSetupDataW *pda) {
2478 LPWSTR devname,portname;
2479 WCHAR papername[64];
2482 dn = GlobalLock(pda->pdlg.hDevNames);
2483 dm = GlobalLock(pda->pdlg.hDevMode);
2484 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
2485 portname = ((WCHAR*)dn)+dn->wOutputOffset;
2486 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
2487 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
2489 if (GetDlgItemTextW(hDlg,cmb2,papername,sizeof(papername))>0) {
2490 PRINTDLG_PaperSizeW(&(pda->pdlg),papername,&(pda->dlga->ptPaperSize));
2491 pda->dlga->ptPaperSize.x = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga,pda->dlga->ptPaperSize.x);
2492 pda->dlga->ptPaperSize.y = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga,pda->dlga->ptPaperSize.y);
2494 FIXME("could not get dialog text for papersize cmbbox?\n");
2495 #define GETVAL(id,val) if (GetDlgItemTextW(hDlg,id,buf,sizeof(buf)/sizeof(buf[0]))>0) { val = _c_str2sizeW(pda->dlga,buf); } else { FIXME("could not get dlgitemtextw for %x\n",id); }
2496 GETVAL(edt4,pda->dlga->rtMargin.left);
2497 GETVAL(edt5,pda->dlga->rtMargin.top);
2498 GETVAL(edt6,pda->dlga->rtMargin.right);
2499 GETVAL(edt7,pda->dlga->rtMargin.bottom);
2502 /* If we are in landscape, swap x and y of page size */
2503 if (IsDlgButtonChecked(hDlg, rad2)) {
2505 tmp = pda->dlga->ptPaperSize.x;
2506 pda->dlga->ptPaperSize.x = pda->dlga->ptPaperSize.y;
2507 pda->dlga->ptPaperSize.y = tmp;
2509 GlobalUnlock(pda->pdlg.hDevNames);
2510 GlobalUnlock(pda->pdlg.hDevMode);
2515 * This is called after returning from PrintDlg().
2518 PRINTDLG_PS_ChangePrinterA(HWND hDlg, PageSetupDataA *pda) {
2521 LPSTR devname,portname;
2523 dn = GlobalLock(pda->pdlg.hDevNames);
2524 dm = GlobalLock(pda->pdlg.hDevMode);
2525 devname = ((char*)dn)+dn->wDeviceOffset;
2526 portname = ((char*)dn)+dn->wOutputOffset;
2527 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb2,devname,portname,dm);
2528 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb3,devname,portname,dm);
2529 GlobalUnlock(pda->pdlg.hDevNames);
2530 GlobalUnlock(pda->pdlg.hDevMode);
2535 PRINTDLG_PS_ChangePrinterW(HWND hDlg, PageSetupDataW *pda) {
2538 LPWSTR devname,portname;
2540 dn = GlobalLock(pda->pdlg.hDevNames);
2541 dm = GlobalLock(pda->pdlg.hDevMode);
2542 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
2543 portname = ((WCHAR*)dn)+dn->wOutputOffset;
2544 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
2545 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
2546 GlobalUnlock(pda->pdlg.hDevNames);
2547 GlobalUnlock(pda->pdlg.hDevMode);
2552 PRINTDLG_PS_WMCommandA(
2553 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataA *pda
2555 TRACE("loword (lparam) %d, wparam 0x%x, lparam %08lx\n",
2556 LOWORD(lParam),wParam,lParam);
2557 switch (LOWORD(wParam)) {
2559 if (!PRINTDLG_PS_UpdateDlgStructA(hDlg, pda))
2561 EndDialog(hDlg, TRUE);
2565 EndDialog(hDlg, FALSE);
2569 pda->pdlg.Flags = 0;
2570 pda->pdlg.hwndOwner = hDlg;
2571 if (PrintDlgA(&(pda->pdlg)))
2572 PRINTDLG_PS_ChangePrinterA(hDlg,pda);
2580 PRINTDLG_PS_WMCommandW(
2581 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataW *pda
2583 TRACE("loword (lparam) %d, wparam 0x%x, lparam %08lx\n",
2584 LOWORD(lParam),wParam,lParam);
2585 switch (LOWORD(wParam)) {
2587 if (!PRINTDLG_PS_UpdateDlgStructW(hDlg, pda))
2589 EndDialog(hDlg, TRUE);
2593 EndDialog(hDlg, FALSE);
2597 pda->pdlg.Flags = 0;
2598 pda->pdlg.hwndOwner = hDlg;
2599 if (PrintDlgW(&(pda->pdlg)))
2600 PRINTDLG_PS_ChangePrinterW(hDlg,pda);
2608 /***********************************************************************
2609 * DefaultPagePaintHook
2610 * Default hook paint procedure that receives WM_PSD_* messages from the dialog box
2611 * whenever the sample page is redrawn.
2615 PRINTDLG_DefaultPagePaintHook(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam, PageSetupDataA *pda)
2617 LPRECT lprc = (LPRECT) lParam;
2618 HDC hdc = (HDC) wParam;
2621 HFONT hfont, holdfont;
2623 TRACE("uMsg: WM_USER+%d\n",uMsg-WM_USER);
2625 /* Call user paint hook if enable */
2626 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK)
2627 if (pda->dlga->lpfnPagePaintHook(hwndDlg, uMsg, wParam, lParam))
2631 /* LPPAGESETUPDLG in lParam */
2632 case WM_PSD_PAGESETUPDLG:
2633 /* Inform about the sample page rectangle */
2634 case WM_PSD_FULLPAGERECT:
2635 /* Inform about the margin rectangle */
2636 case WM_PSD_MINMARGINRECT:
2639 /* Draw dashed rectangle showing margins */
2640 case WM_PSD_MARGINRECT:
2641 hpen = CreatePen(PS_DASH, 1, GetSysColor(COLOR_3DSHADOW));
2642 holdpen = SelectObject(hdc, hpen);
2643 Rectangle(hdc, lprc->left, lprc->top, lprc->right, lprc->bottom);
2644 DeleteObject(SelectObject(hdc, holdpen));
2648 /* Draw the fake document */
2649 case WM_PSD_GREEKTEXTRECT:
2650 /* select a nice scalable font, because we want the text really small */
2651 SystemParametersInfoW(SPI_GETICONTITLELOGFONT, sizeof(lf), &lf, 0);
2652 lf.lfHeight = 6; /* value chosen based on visual effect */
2653 hfont = CreateFontIndirectW(&lf);
2654 holdfont = SelectObject(hdc, hfont);
2656 /* if text not loaded, then do so now */
2657 if (wszFakeDocumentText[0] == '\0')
2658 LoadStringW(COMDLG32_hInstance,
2660 wszFakeDocumentText,
2661 sizeof(wszFakeDocumentText)/sizeof(wszFakeDocumentText[0]));
2663 oldbkmode = SetBkMode(hdc, TRANSPARENT);
2664 DrawTextW(hdc, wszFakeDocumentText, -1, lprc, DT_TOP|DT_LEFT|DT_NOPREFIX|DT_WORDBREAK);
2665 SetBkMode(hdc, oldbkmode);
2667 DeleteObject(SelectObject(hdc, holdfont));
2670 /* Envelope stamp */
2671 case WM_PSD_ENVSTAMPRECT:
2672 /* Return address */
2673 case WM_PSD_YAFULLPAGERECT:
2674 FIXME("envelope/stamp is not implemented\n");
2677 FIXME("Unknown message %x\n",uMsg);
2683 /***********************************************************************
2685 * The main paint procedure for the PageSetupDlg function.
2686 * The Page Setup dialog box includes an image of a sample page that shows how
2687 * the user's selections affect the appearance of the printed output.
2688 * The image consists of a rectangle that represents the selected paper
2689 * or envelope type, with a dotted-line rectangle representing
2690 * the current margins, and partial (Greek text) characters
2691 * to show how text looks on the printed page.
2693 * The following messages in the order sends to user hook procedure:
2694 * WM_PSD_PAGESETUPDLG Draw the contents of the sample page
2695 * WM_PSD_FULLPAGERECT Inform about the bounding rectangle
2696 * WM_PSD_MINMARGINRECT Inform about the margin rectangle (min margin?)
2697 * WM_PSD_MARGINRECT Draw the margin rectangle
2698 * WM_PSD_GREEKTEXTRECT Draw the Greek text inside the margin rectangle
2699 * If any of first three messages returns TRUE, painting done.
2702 * hWnd [in] Handle to the Page Setup dialog box
2703 * uMsg [in] Received message
2706 * WM_PSD_ENVSTAMPRECT Draw in the envelope-stamp rectangle (for envelopes only)
2707 * WM_PSD_YAFULLPAGERECT Draw the return address portion (for envelopes and other paper sizes)
2710 * FALSE if all done correctly
2713 static LRESULT CALLBACK
2714 PRINTDLG_PagePaintProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2717 RECT rcClient, rcMargin;
2720 HBRUSH hbrush, holdbrush;
2721 PageSetupDataA *pda;
2722 int papersize=0, orientation=0; /* FIXME: set this values */
2724 #define CALLPAINTHOOK(msg,lprc) PRINTDLG_DefaultPagePaintHook( hWnd, msg, (WPARAM)hdc, (LPARAM)lprc, pda)
2726 if (uMsg != WM_PAINT)
2727 return CallWindowProcA(lpfnStaticWndProc, hWnd, uMsg, wParam, lParam);
2729 /* Processing WM_PAINT message */
2730 pda = (PageSetupDataA*)GetPropA(hWnd, "__WINE_PAGESETUPDLGDATA");
2732 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
2735 if (PRINTDLG_DefaultPagePaintHook(hWnd, WM_PSD_PAGESETUPDLG, MAKELONG(papersize, orientation), (LPARAM)pda->dlga, pda))
2738 hdc = BeginPaint(hWnd, &ps);
2739 GetClientRect(hWnd, &rcClient);
2741 /* FIXME: use real margin values */
2742 rcMargin = rcClient;
2745 rcMargin.right -= 5;
2746 rcMargin.bottom -= 5;
2748 /* if the space is too small then we make sure to not draw anything */
2749 rcMargin.left = min(rcMargin.left, rcMargin.right);
2750 rcMargin.top = min(rcMargin.top, rcMargin.bottom);
2752 if (!CALLPAINTHOOK(WM_PSD_FULLPAGERECT, &rcClient) &&
2753 !CALLPAINTHOOK(WM_PSD_MINMARGINRECT, &rcMargin) )
2755 /* fill background */
2756 hbrush = GetSysColorBrush(COLOR_3DHIGHLIGHT);
2757 FillRect(hdc, &rcClient, hbrush);
2758 holdbrush = SelectObject(hdc, hbrush);
2760 hpen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW));
2761 holdpen = SelectObject(hdc, hpen);
2764 /* paint left edge */
2765 MoveToEx(hdc, rcClient.left, rcClient.top, NULL);
2766 LineTo(hdc, rcClient.left, rcClient.bottom-1);
2768 /* paint top edge */
2769 MoveToEx(hdc, rcClient.left, rcClient.top, NULL);
2770 LineTo(hdc, rcClient.right, rcClient.top);
2772 hpen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DDKSHADOW));
2773 DeleteObject(SelectObject(hdc, hpen));
2775 /* paint right edge */
2776 MoveToEx(hdc, rcClient.right-1, rcClient.top, NULL);
2777 LineTo(hdc, rcClient.right-1, rcClient.bottom);
2779 /* paint bottom edge */
2780 MoveToEx(hdc, rcClient.left, rcClient.bottom-1, NULL);
2781 LineTo(hdc, rcClient.right, rcClient.bottom-1);
2783 DeleteObject(SelectObject(hdc, holdpen));
2784 DeleteObject(SelectObject(hdc, holdbrush));
2787 CALLPAINTHOOK(WM_PSD_MARGINRECT, &rcMargin);
2790 /* give text a bit of a space from the frame */
2793 rcMargin.right -= 2;
2794 rcMargin.bottom -= 2;
2796 /* if the space is too small then we make sure to not draw anything */
2797 rcMargin.left = min(rcMargin.left, rcMargin.right);
2798 rcMargin.top = min(rcMargin.top, rcMargin.bottom);
2800 CALLPAINTHOOK(WM_PSD_GREEKTEXTRECT, &rcMargin);
2803 EndPaint(hWnd, &ps);
2805 #undef CALLPAINTHOOK
2808 /***********************************************************************
2809 * PRINTDLG_PageDlgProcA
2812 static INT_PTR CALLBACK
2813 PRINTDLG_PageDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
2815 PageSetupDataA *pda;
2816 INT_PTR res = FALSE;
2818 if (uMsg == WM_INITDIALOG) {
2819 pda = (PageSetupDataA*)lParam;
2820 TRACE("set property to %p", pda);
2821 SetPropA(hDlg, "__WINE_PAGESETUPDLGDATA", pda);
2822 SetPropA(GetDlgItem(hDlg, rct1), "__WINE_PAGESETUPDLGDATA", pda);
2823 lpfnStaticWndProc = (WNDPROC)SetWindowLongPtrW(
2824 GetDlgItem(hDlg, rct1),
2826 (ULONG_PTR)PRINTDLG_PagePaintProc);
2828 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
2829 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,(LPARAM)pda->dlga);
2831 FIXME("Setup page hook failed?\n");
2836 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
2837 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
2838 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
2839 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
2840 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
2841 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
2842 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
2844 /* width larger as height -> landscape */
2845 if (pda->dlga->ptPaperSize.x > pda->dlga->ptPaperSize.y)
2846 CheckRadioButton(hDlg, rad1, rad2, rad2);
2847 else /* this is default if papersize is not set */
2848 CheckRadioButton(hDlg, rad1, rad2, rad1);
2849 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
2850 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
2851 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
2853 /* We fill them out enabled or not */
2854 if (pda->dlga->Flags & PSD_MARGINS) {
2856 _c_size2strA(pda,pda->dlga->rtMargin.left,str);
2857 SetDlgItemTextA(hDlg,edt4,str);
2858 _c_size2strA(pda,pda->dlga->rtMargin.top,str);
2859 SetDlgItemTextA(hDlg,edt5,str);
2860 _c_size2strA(pda,pda->dlga->rtMargin.right,str);
2861 SetDlgItemTextA(hDlg,edt6,str);
2862 _c_size2strA(pda,pda->dlga->rtMargin.bottom,str);
2863 SetDlgItemTextA(hDlg,edt7,str);
2865 /* default is 1 inch */
2866 DWORD size = _c_inch2size(pda->dlga,1000);
2868 _c_size2strA(pda,size,str);
2869 SetDlgItemTextA(hDlg,edt4,str);
2870 SetDlgItemTextA(hDlg,edt5,str);
2871 SetDlgItemTextA(hDlg,edt6,str);
2872 SetDlgItemTextA(hDlg,edt7,str);
2874 PRINTDLG_PS_ChangePrinterA(hDlg,pda);
2875 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
2876 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
2877 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
2881 pda = (PageSetupDataA*)GetPropA(hDlg,"__WINE_PAGESETUPDLGDATA");
2883 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
2886 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
2887 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
2888 if (res) return res;
2893 return PRINTDLG_PS_WMCommandA(hDlg, wParam, lParam, pda);
2898 static INT_PTR CALLBACK
2899 PageDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
2901 const static WCHAR __WINE_PAGESETUPDLGDATA[] =
2902 { '_', '_', 'W', 'I', 'N', 'E', '_', 'P', 'A', 'G', 'E',
2903 'S', 'E', 'T', 'U', 'P', 'D', 'L', 'G', 'D', 'A', 'T', 'A', 0 };
2904 PageSetupDataW *pda;
2907 if (uMsg==WM_INITDIALOG) {
2909 pda = (PageSetupDataW*)lParam;
2910 SetPropW(hDlg, __WINE_PAGESETUPDLGDATA, pda);
2911 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
2912 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,(LPARAM)pda->dlga);
2914 FIXME("Setup page hook failed?\n");
2918 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK) {
2919 FIXME("PagePaintHook not yet implemented!\n");
2921 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
2922 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
2923 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
2924 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
2925 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
2926 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
2927 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
2929 /* width larger as height -> landscape */
2930 if (pda->dlga->ptPaperSize.x > pda->dlga->ptPaperSize.y)
2931 CheckRadioButton(hDlg, rad1, rad2, rad2);
2932 else /* this is default if papersize is not set */
2933 CheckRadioButton(hDlg, rad1, rad2, rad1);
2934 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
2935 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
2936 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
2938 /* We fill them out enabled or not */
2939 if (pda->dlga->Flags & PSD_MARGINS) {
2941 _c_size2strW(pda,pda->dlga->rtMargin.left,str);
2942 SetDlgItemTextW(hDlg,edt4,str);
2943 _c_size2strW(pda,pda->dlga->rtMargin.top,str);
2944 SetDlgItemTextW(hDlg,edt5,str);
2945 _c_size2strW(pda,pda->dlga->rtMargin.right,str);
2946 SetDlgItemTextW(hDlg,edt6,str);
2947 _c_size2strW(pda,pda->dlga->rtMargin.bottom,str);
2948 SetDlgItemTextW(hDlg,edt7,str);
2950 /* default is 1 inch */
2951 DWORD size = _c_inch2size((LPPAGESETUPDLGA)pda->dlga,1000);
2953 _c_size2strW(pda,size,str);
2954 SetDlgItemTextW(hDlg,edt4,str);
2955 SetDlgItemTextW(hDlg,edt5,str);
2956 SetDlgItemTextW(hDlg,edt6,str);
2957 SetDlgItemTextW(hDlg,edt7,str);
2959 PRINTDLG_PS_ChangePrinterW(hDlg,pda);
2960 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
2961 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
2962 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
2966 pda = (PageSetupDataW*)GetPropW(hDlg, __WINE_PAGESETUPDLGDATA);
2968 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
2971 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
2972 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
2973 if (res) return res;
2978 return PRINTDLG_PS_WMCommandW(hDlg, wParam, lParam, pda);
2983 /***********************************************************************
2984 * PageSetupDlgA (COMDLG32.@)
2986 * Displays the the PAGE SETUP dialog box, which enables the user to specify
2987 * specific properties of a printed page such as
2988 * size, source, orientation and the width of the page margins.
2991 * setupdlg [in] PAGESETUPDLGA struct
2994 * TRUE if the user pressed the OK button
2995 * FALSE if the user cancelled the window or an error occurred
2998 * The values of hDevMode and hDevNames are filled on output and can be
2999 * changed in PAGESETUPDLG when they are passed in PageSetupDlg.
3002 * * The Paper Orientation Icons are not implemented yet.
3003 * * The Properties Button(s) should call DocumentPropertiesA().
3004 * * Settings are not yet taken from a provided DevMode or
3005 * default printer settings.
3008 BOOL WINAPI PageSetupDlgA(LPPAGESETUPDLGA setupdlg) {
3012 PageSetupDataA *pda;
3015 if(TRACE_ON(commdlg)) {
3016 char flagstr[1000] = "";
3017 struct pd_flags *pflag = psd_flags;
3018 for( ; pflag->name; pflag++) {
3019 if(setupdlg->Flags & pflag->flag) {
3020 strcat(flagstr, pflag->name);
3021 strcat(flagstr, "|");
3024 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3025 "hinst %p, flags %08lx (%s)\n",
3026 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
3027 setupdlg->hDevNames,
3028 setupdlg->hInstance, setupdlg->Flags, flagstr);
3030 if (setupdlg->Flags & PSD_ENABLEPAGEPAINTHOOK)
3031 if (setupdlg->lpfnPagePaintHook == NULL) {
3032 COMDLG32_SetCommDlgExtendedError(CDERR_NOHOOK);
3036 /* First get default printer data, we need it right after that. */
3037 memset(&pdlg,0,sizeof(pdlg));
3038 pdlg.lStructSize = sizeof(pdlg);
3039 pdlg.Flags = PD_RETURNDEFAULT;
3040 bRet = PrintDlgA(&pdlg);
3041 if (!bRet) return FALSE;
3043 /* short cut exit, just return default values */
3044 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
3045 setupdlg->hDevMode = pdlg.hDevMode;
3046 setupdlg->hDevNames = pdlg.hDevNames;
3047 /* FIXME: Just return "A4" for now. */
3048 PRINTDLG_PaperSizeA(&pdlg,"A4",&setupdlg->ptPaperSize);
3049 setupdlg->ptPaperSize.x=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.x);
3050 setupdlg->ptPaperSize.y=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.y);
3053 hDlgTmpl = PRINTDLG_GetPGSTemplateA(setupdlg);
3055 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3058 ptr = LockResource( hDlgTmpl );
3060 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3063 pda = HeapAlloc(GetProcessHeap(),0,sizeof(*pda));
3064 pda->dlga = setupdlg;
3065 memcpy(&pda->pdlg,&pdlg,sizeof(pdlg));
3067 bRet = (0<DialogBoxIndirectParamA(
3068 setupdlg->hInstance,
3070 setupdlg->hwndOwner,
3071 PRINTDLG_PageDlgProcA,
3076 /***********************************************************************
3077 * PageSetupDlgW (COMDLG32.@)
3079 BOOL WINAPI PageSetupDlgW(LPPAGESETUPDLGW setupdlg) {
3083 PageSetupDataW *pdw;
3085 FIXME("Unicode implementation is not done yet\n");
3086 if(TRACE_ON(commdlg)) {
3087 char flagstr[1000] = "";
3088 struct pd_flags *pflag = psd_flags;
3089 for( ; pflag->name; pflag++) {
3090 if(setupdlg->Flags & pflag->flag) {
3091 strcat(flagstr, pflag->name);
3092 strcat(flagstr, "|");
3095 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3096 "hinst %p, flags %08lx (%s)\n",
3097 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
3098 setupdlg->hDevNames,
3099 setupdlg->hInstance, setupdlg->Flags, flagstr);
3102 /* First get default printer data, we need it right after that. */
3103 memset(&pdlg,0,sizeof(pdlg));
3104 pdlg.lStructSize = sizeof(pdlg);
3105 pdlg.Flags = PD_RETURNDEFAULT;
3106 bRet = PrintDlgW(&pdlg);
3107 if (!bRet) return FALSE;
3109 /* short cut exit, just return default values */
3110 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
3111 static const WCHAR a4[] = {'A','4',0};
3112 setupdlg->hDevMode = pdlg.hDevMode;
3113 setupdlg->hDevNames = pdlg.hDevNames;
3114 /* FIXME: Just return "A4" for now. */
3115 PRINTDLG_PaperSizeW(&pdlg,a4,&setupdlg->ptPaperSize);
3116 setupdlg->ptPaperSize.x=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.x);
3117 setupdlg->ptPaperSize.y=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.y);
3120 hDlgTmpl = PRINTDLG_GetPGSTemplateW(setupdlg);
3122 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3125 ptr = LockResource( hDlgTmpl );
3127 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3130 pdw = HeapAlloc(GetProcessHeap(),0,sizeof(*pdw));
3131 pdw->dlga = setupdlg;
3132 memcpy(&pdw->pdlg,&pdlg,sizeof(pdlg));
3134 bRet = (0<DialogBoxIndirectParamW(
3135 setupdlg->hInstance,
3137 setupdlg->hwndOwner,
3144 /***********************************************************************
3145 * PrintDlgExA (COMDLG32.@)
3147 HRESULT WINAPI PrintDlgExA(LPPRINTDLGEXA lpPrintDlgExA)
3153 /***********************************************************************
3154 * PrintDlgExW (COMDLG32.@)
3156 HRESULT WINAPI PrintDlgExW(LPPRINTDLGEXW lpPrintDlgExW)