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
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 SendDlgItemMessageA(hDlg, id, CB_RESETCONTENT, 0, 0);
125 for(i = 0; i < num; i++) {
126 SendDlgItemMessageA(hDlg, id, CB_ADDSTRING, 0,
127 (LPARAM)pi[i].pPrinterName );
129 HeapFree(GetProcessHeap(), 0, pi);
131 (i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1,
132 (LPARAM)name)) == CB_ERR) {
135 DWORD dwBufLen = sizeof(buf);
136 FIXME("Can't find '%s' in printer list so trying to find default\n",
138 if(!GetDefaultPrinterA(buf, &dwBufLen))
140 i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
142 FIXME("Can't find default printer in printer list\n");
144 SendDlgItemMessageA(hDlg, id, CB_SETCURSEL, i, 0);
148 static INT PRINTDLG_SetUpPrinterListComboW(HWND hDlg, UINT id, LPCWSTR name)
152 LPPRINTER_INFO_2W pi;
153 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
154 pi = HeapAlloc(GetProcessHeap(), 0, needed);
155 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
158 for(i = 0; i < num; i++) {
159 SendDlgItemMessageW(hDlg, id, CB_ADDSTRING, 0,
160 (LPARAM)pi[i].pPrinterName );
162 HeapFree(GetProcessHeap(), 0, pi);
164 (i = SendDlgItemMessageW(hDlg, id, CB_FINDSTRINGEXACT, -1,
165 (LPARAM)name)) == CB_ERR) {
167 DWORD dwBufLen = sizeof(buf)/sizeof(buf[0]);
168 TRACE("Can't find '%s' in printer list so trying to find default\n",
170 if(!GetDefaultPrinterW(buf, &dwBufLen))
172 i = SendDlgItemMessageW(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
174 TRACE("Can't find default printer in printer list\n");
176 SendDlgItemMessageW(hDlg, id, CB_SETCURSEL, i, 0);
180 /***********************************************************************
181 * PRINTDLG_CreateDevNames [internal]
184 * creates a DevNames structure.
186 * (NB. when we handle unicode the offsets will be in wchars).
188 static BOOL PRINTDLG_CreateDevNames(HGLOBAL *hmem, char* DeviceDriverName,
189 char* DeviceName, char* OutputPort)
192 char* pDevNamesSpace;
194 LPDEVNAMES lpDevNames;
196 DWORD dwBufLen = sizeof(buf);
198 size = strlen(DeviceDriverName) + 1
199 + strlen(DeviceName) + 1
200 + strlen(OutputPort) + 1
204 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
206 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
210 pDevNamesSpace = GlobalLock(*hmem);
211 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
213 pTempPtr = pDevNamesSpace + sizeof(DEVNAMES);
214 strcpy(pTempPtr, DeviceDriverName);
215 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
217 pTempPtr += strlen(DeviceDriverName) + 1;
218 strcpy(pTempPtr, DeviceName);
219 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
221 pTempPtr += strlen(DeviceName) + 1;
222 strcpy(pTempPtr, OutputPort);
223 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
225 GetDefaultPrinterA(buf, &dwBufLen);
226 lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
231 static BOOL PRINTDLG_CreateDevNamesW(HGLOBAL *hmem, LPCWSTR DeviceDriverName,
232 LPCWSTR DeviceName, LPCWSTR OutputPort)
235 LPWSTR pDevNamesSpace;
237 LPDEVNAMES lpDevNames;
239 DWORD dwBufLen = sizeof(bufW) / sizeof(WCHAR);
241 size = sizeof(WCHAR)*lstrlenW(DeviceDriverName) + 2
242 + sizeof(WCHAR)*lstrlenW(DeviceName) + 2
243 + sizeof(WCHAR)*lstrlenW(OutputPort) + 2
247 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
249 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
253 pDevNamesSpace = GlobalLock(*hmem);
254 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
256 pTempPtr = (LPWSTR)((LPDEVNAMES)pDevNamesSpace + 1);
257 lstrcpyW(pTempPtr, DeviceDriverName);
258 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
260 pTempPtr += lstrlenW(DeviceDriverName) + 1;
261 lstrcpyW(pTempPtr, DeviceName);
262 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
264 pTempPtr += lstrlenW(DeviceName) + 1;
265 lstrcpyW(pTempPtr, OutputPort);
266 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
268 GetDefaultPrinterW(bufW, &dwBufLen);
269 lpDevNames->wDefault = (lstrcmpW(bufW, DeviceName) == 0) ? 1 : 0;
274 /***********************************************************************
275 * PRINTDLG_UpdatePrintDlg [internal]
278 * updates the PrintDlg structure for return values.
281 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
282 * TRUE if successful.
284 static BOOL PRINTDLG_UpdatePrintDlgA(HWND hDlg,
285 PRINT_PTRA* PrintStructures)
287 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
288 PDEVMODEA lpdm = PrintStructures->lpDevMode;
289 LPPRINTER_INFO_2A pi = PrintStructures->lpPrinterInfo;
293 FIXME("No lpdm ptr?\n");
298 if(!(lppd->Flags & PD_PRINTSETUP)) {
299 /* check whether nFromPage and nToPage are within range defined by
300 * nMinPage and nMaxPage
302 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
305 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
306 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
307 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
308 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
309 char resourcestr[256];
311 LoadStringA(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
313 sprintf(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
314 LoadStringA(COMDLG32_hInstance, PD32_PRINT_TITLE,
316 MessageBoxA(hDlg, resultstr, resourcestr,
317 MB_OK | MB_ICONWARNING);
320 lppd->nFromPage = nFromPage;
321 lppd->nToPage = nToPage;
322 lppd->Flags |= PD_PAGENUMS;
325 lppd->Flags &= ~PD_PAGENUMS;
327 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
328 static char file[] = "FILE:";
329 lppd->Flags |= PD_PRINTTOFILE;
330 pi->pPortName = file;
333 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
334 FIXME("Collate lppd not yet implemented as output\n");
337 /* set PD_Collate and nCopies */
338 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
339 /* The application doesn't support multiple copies or collate...
341 lppd->Flags &= ~PD_COLLATE;
343 /* if the printer driver supports it... store info there
344 * otherwise no collate & multiple copies !
346 if (lpdm->dmFields & DM_COLLATE)
348 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
349 if (lpdm->dmFields & DM_COPIES)
350 lpdm->dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
352 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
353 lppd->Flags |= PD_COLLATE;
355 lppd->Flags &= ~PD_COLLATE;
356 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
362 static BOOL PRINTDLG_UpdatePrintDlgW(HWND hDlg,
363 PRINT_PTRW* PrintStructures)
365 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
366 PDEVMODEW lpdm = PrintStructures->lpDevMode;
367 LPPRINTER_INFO_2W pi = PrintStructures->lpPrinterInfo;
371 FIXME("No lpdm ptr?\n");
376 if(!(lppd->Flags & PD_PRINTSETUP)) {
377 /* check whether nFromPage and nToPage are within range defined by
378 * nMinPage and nMaxPage
380 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
383 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
384 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
385 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
386 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
387 WCHAR resourcestr[256];
388 WCHAR resultstr[256];
389 LoadStringW(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
391 wsprintfW(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
392 LoadStringW(COMDLG32_hInstance, PD32_PRINT_TITLE,
394 MessageBoxW(hDlg, resultstr, resourcestr,
395 MB_OK | MB_ICONWARNING);
398 lppd->nFromPage = nFromPage;
399 lppd->nToPage = nToPage;
400 lppd->Flags |= PD_PAGENUMS;
403 lppd->Flags &= ~PD_PAGENUMS;
405 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
406 static WCHAR file[] = {'F','I','L','E',':',0};
407 lppd->Flags |= PD_PRINTTOFILE;
408 pi->pPortName = file;
411 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
412 FIXME("Collate lppd not yet implemented as output\n");
415 /* set PD_Collate and nCopies */
416 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
417 /* The application doesn't support multiple copies or collate...
419 lppd->Flags &= ~PD_COLLATE;
421 /* if the printer driver supports it... store info there
422 * otherwise no collate & multiple copies !
424 if (lpdm->dmFields & DM_COLLATE)
426 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
427 if (lpdm->dmFields & DM_COPIES)
428 lpdm->dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
430 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
431 lppd->Flags |= PD_COLLATE;
433 lppd->Flags &= ~PD_COLLATE;
434 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
440 static BOOL PRINTDLG_PaperSizeA(
441 PRINTDLGA *pdlga,const WORD PaperSize,LPPOINT size
445 LPSTR devname,portname;
449 POINT *points = NULL;
452 dn = GlobalLock(pdlga->hDevNames);
453 dm = GlobalLock(pdlga->hDevMode);
454 devname = ((char*)dn)+dn->wDeviceOffset;
455 portname = ((char*)dn)+dn->wOutputOffset;
458 NrOfEntries = DeviceCapabilitiesA(devname,portname,DC_PAPERNAMES,NULL,dm);
460 FIXME("No papernames found for %s/%s\n",devname,portname);
463 if (NrOfEntries == -1) {
464 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
468 Words = HeapAlloc(GetProcessHeap(),0,NrOfEntries*sizeof(WORD));
469 if (NrOfEntries != (ret=DeviceCapabilitiesA(devname,portname,DC_PAPERS,(LPSTR)Words,dm))) {
470 FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
473 for (i=0;i<NrOfEntries;i++)
474 if (Words[i] == PaperSize)
476 HeapFree(GetProcessHeap(),0,Words);
477 if (i == NrOfEntries) {
478 FIXME("Papersize %d not found in list?\n",PaperSize);
481 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
482 if (NrOfEntries!=(ret=DeviceCapabilitiesA(devname,portname,DC_PAPERSIZE,(LPSTR)points,dm))) {
483 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
486 /* this is _10ths_ of a millimeter */
491 GlobalUnlock(pdlga->hDevNames);
492 GlobalUnlock(pdlga->hDevMode);
493 HeapFree(GetProcessHeap(),0,Words);
494 HeapFree(GetProcessHeap(),0,points);
498 static BOOL PRINTDLG_PaperSizeW(
499 PRINTDLGW *pdlga,const WCHAR *PaperSize,LPPOINT size
503 LPWSTR devname,portname;
507 POINT *points = NULL;
510 dn = GlobalLock(pdlga->hDevNames);
511 dm = GlobalLock(pdlga->hDevMode);
512 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
513 portname = ((WCHAR*)dn)+dn->wOutputOffset;
516 NrOfEntries = DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,NULL,dm);
518 FIXME("No papernames found for %s/%s\n",debugstr_w(devname),debugstr_w(portname));
521 if (NrOfEntries == -1) {
522 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
526 Names = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*NrOfEntries*64);
527 if (NrOfEntries != (ret=DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,Names,dm))) {
528 FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
531 for (i=0;i<NrOfEntries;i++)
532 if (!lstrcmpW(PaperSize,Names+(64*i)))
534 HeapFree(GetProcessHeap(),0,Names);
535 if (i==NrOfEntries) {
536 FIXME("Papersize %s not found in list?\n",debugstr_w(PaperSize));
539 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
540 if (NrOfEntries!=(ret=DeviceCapabilitiesW(devname,portname,DC_PAPERSIZE,(LPWSTR)points,dm))) {
541 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
544 /* this is _10ths_ of a millimeter */
549 GlobalUnlock(pdlga->hDevNames);
550 GlobalUnlock(pdlga->hDevMode);
551 HeapFree(GetProcessHeap(),0,Names);
552 HeapFree(GetProcessHeap(),0,points);
557 /************************************************************************
558 * PRINTDLG_SetUpPaperComboBox
560 * Initialize either the papersize or inputslot combos of the Printer Setup
561 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
562 * We also try to re-select the old selection.
564 static BOOL PRINTDLG_SetUpPaperComboBoxA(HWND hDlg,
577 int fwCapability_Names;
578 int fwCapability_Words;
580 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName,PortName,nIDComboBox);
582 /* query the dialog box for the current selected value */
583 Sel = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
585 /* we enter here only if a different printer is selected after
586 * the Print Setup dialog is opened. The current settings are
587 * stored into the newly selected printer.
589 oldWord = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA,
592 if (nIDComboBox == cmb2)
593 dm->u1.s1.dmPaperSize = oldWord;
595 dm->dmDefaultSource = oldWord;
599 /* we enter here only when the Print setup dialog is initially
600 * opened. In this case the settings are restored from when
601 * the dialog was last closed.
604 if (nIDComboBox == cmb2)
605 oldWord = dm->u1.s1.dmPaperSize;
607 oldWord = dm->dmDefaultSource;
611 if (nIDComboBox == cmb2) {
613 fwCapability_Names = DC_PAPERNAMES;
614 fwCapability_Words = DC_PAPERS;
618 fwCapability_Names = DC_BINNAMES;
619 fwCapability_Words = DC_BINS;
622 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
623 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
625 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
626 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
627 fwCapability_Names, NULL, dm);
628 if (NrOfEntries == 0)
629 WARN("no Name Entries found!\n");
630 else if (NrOfEntries < 0)
633 if(DeviceCapabilitiesA(PrinterName, PortName, fwCapability_Words, NULL, dm)
635 ERR("Number of caps is different\n");
639 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(char)*NamesSize);
640 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
641 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
642 fwCapability_Names, Names, dm);
643 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
644 fwCapability_Words, (LPSTR)Words, dm);
646 /* reset any current content in the combobox */
647 SendDlgItemMessageA(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
649 /* store new content */
650 for (i = 0; i < NrOfEntries; i++) {
651 DWORD pos = SendDlgItemMessageA(hDlg, nIDComboBox, CB_ADDSTRING, 0,
652 (LPARAM)(&Names[i*NamesSize]) );
653 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
657 /* Look for old selection - can't do this is previous loop since
658 item order will change as more items are added */
660 for (i = 0; i < NrOfEntries; i++) {
661 if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
667 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
669 HeapFree(GetProcessHeap(),0,Words);
670 HeapFree(GetProcessHeap(),0,Names);
674 static BOOL PRINTDLG_SetUpPaperComboBoxW(HWND hDlg,
687 int fwCapability_Names;
688 int fwCapability_Words;
690 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName),debugstr_w(PortName),nIDComboBox);
692 /* query the dialog box for the current selected value */
693 Sel = SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
695 /* we enter here only if a different printer is selected after
696 * the Print Setup dialog is opened. The current settings are
697 * stored into the newly selected printer.
699 oldWord = SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETITEMDATA,
702 if (nIDComboBox == cmb2)
703 dm->u1.s1.dmPaperSize = oldWord;
705 dm->dmDefaultSource = oldWord;
709 /* we enter here only when the Print setup dialog is initially
710 * opened. In this case the settings are restored from when
711 * the dialog was last closed.
714 if (nIDComboBox == cmb2)
715 oldWord = dm->u1.s1.dmPaperSize;
717 oldWord = dm->dmDefaultSource;
721 if (nIDComboBox == cmb2) {
723 fwCapability_Names = DC_PAPERNAMES;
724 fwCapability_Words = DC_PAPERS;
728 fwCapability_Names = DC_BINNAMES;
729 fwCapability_Words = DC_BINS;
732 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
733 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
735 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
736 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
737 fwCapability_Names, NULL, dm);
738 if (NrOfEntries == 0)
739 WARN("no Name Entries found!\n");
740 else if (NrOfEntries < 0)
743 if(DeviceCapabilitiesW(PrinterName, PortName, fwCapability_Words, NULL, dm)
745 ERR("Number of caps is different\n");
749 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WCHAR)*NamesSize);
750 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
751 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
752 fwCapability_Names, Names, dm);
753 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
754 fwCapability_Words, (LPWSTR)Words, dm);
756 /* reset any current content in the combobox */
757 SendDlgItemMessageW(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
759 /* store new content */
760 for (i = 0; i < NrOfEntries; i++) {
761 DWORD pos = SendDlgItemMessageW(hDlg, nIDComboBox, CB_ADDSTRING, 0,
762 (LPARAM)(&Names[i*NamesSize]) );
763 SendDlgItemMessageW(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
767 /* Look for old selection - can't do this is previous loop since
768 item order will change as more items are added */
770 for (i = 0; i < NrOfEntries; i++) {
771 if(SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
777 SendDlgItemMessageW(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
779 HeapFree(GetProcessHeap(),0,Words);
780 HeapFree(GetProcessHeap(),0,Names);
785 /***********************************************************************
786 * PRINTDLG_UpdatePrinterInfoTexts [internal]
788 static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg, LPPRINTER_INFO_2A pi)
791 char ResourceString[256];
797 /* add all status messages */
798 for (i = 0; i < 25; i++) {
799 if (pi->Status & (1<<i)) {
800 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
801 ResourceString, 255);
802 strcat(StatusMsg,ResourceString);
806 /* FIXME: status==ready must only be appended if really so.
807 but how to detect? */
808 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
809 ResourceString, 255);
810 strcat(StatusMsg,ResourceString);
811 SetDlgItemTextA(hDlg, stc12, StatusMsg);
813 /* set all other printer info texts */
814 SetDlgItemTextA(hDlg, stc11, pi->pDriverName);
816 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
817 SetDlgItemTextA(hDlg, stc14, pi->pLocation);
819 SetDlgItemTextA(hDlg, stc14, pi->pPortName);
820 SetDlgItemTextA(hDlg, stc13, pi->pComment ? pi->pComment : "");
824 static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg, LPPRINTER_INFO_2W pi)
826 WCHAR StatusMsg[256];
827 WCHAR ResourceString[256];
828 static const WCHAR emptyW[] = {0};
834 /* add all status messages */
835 for (i = 0; i < 25; i++) {
836 if (pi->Status & (1<<i)) {
837 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
838 ResourceString, 255);
839 lstrcatW(StatusMsg,ResourceString);
843 /* FIXME: status==ready must only be appended if really so.
844 but how to detect? */
845 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
846 ResourceString, 255);
847 lstrcatW(StatusMsg,ResourceString);
848 SetDlgItemTextW(hDlg, stc12, StatusMsg);
850 /* set all other printer info texts */
851 SetDlgItemTextW(hDlg, stc11, pi->pDriverName);
852 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
853 SetDlgItemTextW(hDlg, stc14, pi->pLocation);
855 SetDlgItemTextW(hDlg, stc14, pi->pPortName);
856 SetDlgItemTextW(hDlg, stc13, pi->pComment ? pi->pComment : emptyW);
860 /*******************************************************************
862 * PRINTDLG_ChangePrinter
865 BOOL PRINTDLG_ChangePrinterA(HWND hDlg, char *name,
866 PRINT_PTRA *PrintStructures)
868 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
869 LPDEVMODEA lpdm = NULL;
874 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
875 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
876 if(!OpenPrinterA(name, &hprn, NULL)) {
877 ERR("Can't open printer %s\n", name);
880 GetPrinterA(hprn, 2, NULL, 0, &needed);
881 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,needed);
882 GetPrinterA(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
884 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
885 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,needed);
886 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
888 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures->lpPrinterInfo->pPrinterName);
893 PRINTDLG_UpdatePrinterInfoTextsA(hDlg, PrintStructures->lpPrinterInfo);
895 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
896 PrintStructures->lpDevMode = NULL;
898 dmSize = DocumentPropertiesA(0, 0, name, NULL, NULL, 0);
900 ERR("DocumentProperties fails on %s\n", debugstr_a(name));
903 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
904 dmSize = DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, NULL,
906 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
907 !lstrcmpA( (LPSTR) lpdm->dmDeviceName,
908 (LPSTR) PrintStructures->lpDevMode->dmDeviceName)) {
909 /* Supplied devicemode matches current printer so try to use it */
910 DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, lpdm,
911 DM_OUT_BUFFER | DM_IN_BUFFER);
914 GlobalUnlock(lppd->hDevMode);
916 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
918 if(!(lppd->Flags & PD_PRINTSETUP)) {
919 /* Print range (All/Range/Selection) */
920 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
921 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
922 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
923 if (lppd->Flags & PD_NOSELECTION)
924 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
926 if (lppd->Flags & PD_SELECTION)
927 CheckRadioButton(hDlg, rad1, rad3, rad2);
928 if (lppd->Flags & PD_NOPAGENUMS) {
929 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
930 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
931 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
932 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
933 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
935 if (lppd->Flags & PD_PAGENUMS)
936 CheckRadioButton(hDlg, rad1, rad3, rad3);
941 * FIXME: The ico3 is not displayed for some reason. I don't know why.
943 if (lppd->Flags & PD_COLLATE) {
944 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
945 (LPARAM)PrintStructures->hCollateIcon);
946 CheckDlgButton(hDlg, chx2, 1);
948 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
949 (LPARAM)PrintStructures->hNoCollateIcon);
950 CheckDlgButton(hDlg, chx2, 0);
953 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
954 /* if printer doesn't support it: no Collate */
955 if (!(lpdm->dmFields & DM_COLLATE)) {
956 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
957 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
964 if (lppd->hDevMode == 0)
965 copies = lppd->nCopies;
967 copies = lpdm->dmCopies;
968 if(copies == 0) copies = 1;
969 else if(copies < 0) copies = MAX_COPIES;
970 SetDlgItemInt(hDlg, edt3, copies, FALSE);
973 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
974 /* if printer doesn't support it: no nCopies */
975 if (!(lpdm->dmFields & DM_COPIES)) {
976 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
977 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
982 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
983 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
984 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
985 if (lppd->Flags & PD_HIDEPRINTTOFILE)
986 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
988 } else { /* PD_PRINTSETUP */
989 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
991 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb2,
992 PrintStructures->lpPrinterInfo->pPrinterName,
993 PrintStructures->lpPrinterInfo->pPortName,
995 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb3,
996 PrintStructures->lpPrinterInfo->pPrinterName,
997 PrintStructures->lpPrinterInfo->pPortName,
999 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1000 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1001 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1002 PrintStructures->hLandscapeIcon));
1007 if ((lppd->Flags & PD_SHOWHELP)==0) {
1008 /* hide if PD_SHOWHELP not specified */
1009 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1014 static BOOL PRINTDLG_ChangePrinterW(HWND hDlg, WCHAR *name,
1015 PRINT_PTRW *PrintStructures)
1017 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1018 LPDEVMODEW lpdm = NULL;
1023 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
1024 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
1025 if(!OpenPrinterW(name, &hprn, NULL)) {
1026 ERR("Can't open printer %s\n", debugstr_w(name));
1029 GetPrinterW(hprn, 2, NULL, 0, &needed);
1030 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
1031 GetPrinterW(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
1033 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
1034 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
1035 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
1037 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures->lpPrinterInfo->pPrinterName));
1042 PRINTDLG_UpdatePrinterInfoTextsW(hDlg, PrintStructures->lpPrinterInfo);
1044 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
1045 PrintStructures->lpDevMode = NULL;
1047 dmSize = DocumentPropertiesW(0, 0, name, NULL, NULL, 0);
1049 ERR("DocumentProperties fails on %s\n", debugstr_w(name));
1052 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
1053 dmSize = DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, NULL,
1055 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
1056 !lstrcmpW(lpdm->dmDeviceName,
1057 PrintStructures->lpDevMode->dmDeviceName)) {
1058 /* Supplied devicemode matches current printer so try to use it */
1059 DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, lpdm,
1060 DM_OUT_BUFFER | DM_IN_BUFFER);
1063 GlobalUnlock(lppd->hDevMode);
1065 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
1067 if(!(lppd->Flags & PD_PRINTSETUP)) {
1068 /* Print range (All/Range/Selection) */
1069 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
1070 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
1071 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
1072 if (lppd->Flags & PD_NOSELECTION)
1073 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
1075 if (lppd->Flags & PD_SELECTION)
1076 CheckRadioButton(hDlg, rad1, rad3, rad2);
1077 if (lppd->Flags & PD_NOPAGENUMS) {
1078 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
1079 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
1080 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
1081 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
1082 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
1084 if (lppd->Flags & PD_PAGENUMS)
1085 CheckRadioButton(hDlg, rad1, rad3, rad3);
1090 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1092 if (lppd->Flags & PD_COLLATE) {
1093 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1094 (LPARAM)PrintStructures->hCollateIcon);
1095 CheckDlgButton(hDlg, chx2, 1);
1097 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1098 (LPARAM)PrintStructures->hNoCollateIcon);
1099 CheckDlgButton(hDlg, chx2, 0);
1102 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1103 /* if printer doesn't support it: no Collate */
1104 if (!(lpdm->dmFields & DM_COLLATE)) {
1105 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1106 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
1113 if (lppd->hDevMode == 0)
1114 copies = lppd->nCopies;
1116 copies = lpdm->dmCopies;
1117 if(copies == 0) copies = 1;
1118 else if(copies < 0) copies = MAX_COPIES;
1119 SetDlgItemInt(hDlg, edt3, copies, FALSE);
1122 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1123 /* if printer doesn't support it: no nCopies */
1124 if (!(lpdm->dmFields & DM_COPIES)) {
1125 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
1126 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
1131 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
1132 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
1133 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
1134 if (lppd->Flags & PD_HIDEPRINTTOFILE)
1135 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
1137 } else { /* PD_PRINTSETUP */
1138 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
1140 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb2,
1141 PrintStructures->lpPrinterInfo->pPrinterName,
1142 PrintStructures->lpPrinterInfo->pPortName,
1144 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb3,
1145 PrintStructures->lpPrinterInfo->pPrinterName,
1146 PrintStructures->lpPrinterInfo->pPortName,
1148 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1149 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1150 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1151 PrintStructures->hLandscapeIcon));
1156 if ((lppd->Flags & PD_SHOWHELP)==0) {
1157 /* hide if PD_SHOWHELP not specified */
1158 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1163 /***********************************************************************
1164 * check_printer_setup [internal]
1166 static LRESULT check_printer_setup(HWND hDlg)
1169 WCHAR resourcestr[256],resultstr[256];
1172 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
1175 EnumPrintersW(PRINTER_ENUM_CONNECTIONS, NULL, 2, NULL, 0, &needed, &num);
1181 LoadStringW(COMDLG32_hInstance, PD32_NO_DEVICES,resultstr, 255);
1182 LoadStringW(COMDLG32_hInstance, PD32_PRINT_TITLE,resourcestr, 255);
1183 res = MessageBoxW(hDlg, resultstr, resourcestr,MB_OK | MB_ICONWARNING);
1188 /***********************************************************************
1189 * PRINTDLG_WMInitDialog [internal]
1191 static LRESULT PRINTDLG_WMInitDialog(HWND hDlg, WPARAM wParam,
1192 PRINT_PTRA* PrintStructures)
1194 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
1198 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1200 /* load Collate ICONs */
1201 /* We load these with LoadImage because they are not a standard
1202 size and we don't want them rescaled */
1203 PrintStructures->hCollateIcon =
1204 LoadImageA(COMDLG32_hInstance, "PD32_COLLATE", IMAGE_ICON, 0, 0, 0);
1205 PrintStructures->hNoCollateIcon =
1206 LoadImageA(COMDLG32_hInstance, "PD32_NOCOLLATE", IMAGE_ICON, 0, 0, 0);
1208 /* These can be done with LoadIcon */
1209 PrintStructures->hPortraitIcon =
1210 LoadIconA(COMDLG32_hInstance, "PD32_PORTRAIT");
1211 PrintStructures->hLandscapeIcon =
1212 LoadIconA(COMDLG32_hInstance, "PD32_LANDSCAPE");
1214 /* display the collate/no_collate icon */
1215 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1216 (LPARAM)PrintStructures->hNoCollateIcon);
1218 if(PrintStructures->hCollateIcon == 0 ||
1219 PrintStructures->hNoCollateIcon == 0 ||
1220 PrintStructures->hPortraitIcon == 0 ||
1221 PrintStructures->hLandscapeIcon == 0) {
1222 ERR("no icon in resourcefile\n");
1223 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1224 EndDialog(hDlg, FALSE);
1228 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1229 * must be registered and the Help button must be shown.
1231 if (lppd->Flags & PD_SHOWHELP) {
1232 if((PrintStructures->HelpMessageID =
1233 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
1234 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1238 PrintStructures->HelpMessageID = 0;
1240 if(!(lppd->Flags &PD_PRINTSETUP)) {
1241 PrintStructures->hwndUpDown =
1242 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1243 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1244 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1245 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1246 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1249 /* FIXME: I allow more freedom than either Win95 or WinNT,
1250 * which do not agree to what errors should be thrown or not
1251 * in case nToPage or nFromPage is out-of-range.
1253 if (lppd->nMaxPage < lppd->nMinPage)
1254 lppd->nMaxPage = lppd->nMinPage;
1255 if (lppd->nMinPage == lppd->nMaxPage)
1256 lppd->Flags |= PD_NOPAGENUMS;
1257 if (lppd->nToPage < lppd->nMinPage)
1258 lppd->nToPage = lppd->nMinPage;
1259 if (lppd->nToPage > lppd->nMaxPage)
1260 lppd->nToPage = lppd->nMaxPage;
1261 if (lppd->nFromPage < lppd->nMinPage)
1262 lppd->nFromPage = lppd->nMinPage;
1263 if (lppd->nFromPage > lppd->nMaxPage)
1264 lppd->nFromPage = lppd->nMaxPage;
1266 /* if we have the combo box, fill it */
1267 if (GetDlgItem(hDlg,comboID)) {
1270 pdn = GlobalLock(lppd->hDevNames);
1271 pdm = GlobalLock(lppd->hDevMode);
1273 name = (char*)pdn + pdn->wDeviceOffset;
1275 name = (char*)pdm->dmDeviceName;
1276 PRINTDLG_SetUpPrinterListComboA(hDlg, comboID, name);
1277 if(pdm) GlobalUnlock(lppd->hDevMode);
1278 if(pdn) GlobalUnlock(lppd->hDevNames);
1280 /* Now find selected printer and update rest of dlg */
1281 name = HeapAlloc(GetProcessHeap(),0,256);
1282 if (GetDlgItemTextA(hDlg, comboID, name, 255))
1283 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1284 HeapFree(GetProcessHeap(),0,name);
1286 /* else use default printer */
1288 DWORD dwBufLen = sizeof(name);
1289 BOOL ret = GetDefaultPrinterA(name, &dwBufLen);
1292 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1294 FIXME("No default printer found, expect problems!\n");
1299 static LRESULT PRINTDLG_WMInitDialogW(HWND hDlg, WPARAM wParam,
1300 PRINT_PTRW* PrintStructures)
1302 static const WCHAR PD32_COLLATE[] = { 'P', 'D', '3', '2', '_', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
1303 static const WCHAR PD32_NOCOLLATE[] = { 'P', 'D', '3', '2', '_', 'N', 'O', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
1304 static const WCHAR PD32_PORTRAIT[] = { 'P', 'D', '3', '2', '_', 'P', 'O', 'R', 'T', 'R', 'A', 'I', 'T', 0 };
1305 static const WCHAR PD32_LANDSCAPE[] = { 'P', 'D', '3', '2', '_', 'L', 'A', 'N', 'D', 'S', 'C', 'A', 'P', 'E', 0 };
1306 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1310 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1312 /* load Collate ICONs */
1313 /* We load these with LoadImage because they are not a standard
1314 size and we don't want them rescaled */
1315 PrintStructures->hCollateIcon =
1316 LoadImageW(COMDLG32_hInstance, PD32_COLLATE, IMAGE_ICON, 0, 0, 0);
1317 PrintStructures->hNoCollateIcon =
1318 LoadImageW(COMDLG32_hInstance, PD32_NOCOLLATE, IMAGE_ICON, 0, 0, 0);
1320 /* These can be done with LoadIcon */
1321 PrintStructures->hPortraitIcon =
1322 LoadIconW(COMDLG32_hInstance, PD32_PORTRAIT);
1323 PrintStructures->hLandscapeIcon =
1324 LoadIconW(COMDLG32_hInstance, PD32_LANDSCAPE);
1326 /* display the collate/no_collate icon */
1327 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1328 (LPARAM)PrintStructures->hNoCollateIcon);
1330 if(PrintStructures->hCollateIcon == 0 ||
1331 PrintStructures->hNoCollateIcon == 0 ||
1332 PrintStructures->hPortraitIcon == 0 ||
1333 PrintStructures->hLandscapeIcon == 0) {
1334 ERR("no icon in resourcefile\n");
1335 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1336 EndDialog(hDlg, FALSE);
1340 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1341 * must be registered and the Help button must be shown.
1343 if (lppd->Flags & PD_SHOWHELP) {
1344 if((PrintStructures->HelpMessageID =
1345 RegisterWindowMessageW(HELPMSGSTRINGW)) == 0) {
1346 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1350 PrintStructures->HelpMessageID = 0;
1352 if(!(lppd->Flags &PD_PRINTSETUP)) {
1353 PrintStructures->hwndUpDown =
1354 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1355 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1356 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1357 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1358 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1361 /* FIXME: I allow more freedom than either Win95 or WinNT,
1362 * which do not agree to what errors should be thrown or not
1363 * in case nToPage or nFromPage is out-of-range.
1365 if (lppd->nMaxPage < lppd->nMinPage)
1366 lppd->nMaxPage = lppd->nMinPage;
1367 if (lppd->nMinPage == lppd->nMaxPage)
1368 lppd->Flags |= PD_NOPAGENUMS;
1369 if (lppd->nToPage < lppd->nMinPage)
1370 lppd->nToPage = lppd->nMinPage;
1371 if (lppd->nToPage > lppd->nMaxPage)
1372 lppd->nToPage = lppd->nMaxPage;
1373 if (lppd->nFromPage < lppd->nMinPage)
1374 lppd->nFromPage = lppd->nMinPage;
1375 if (lppd->nFromPage > lppd->nMaxPage)
1376 lppd->nFromPage = lppd->nMaxPage;
1378 /* if we have the combo box, fill it */
1379 if (GetDlgItem(hDlg,comboID)) {
1382 pdn = GlobalLock(lppd->hDevNames);
1383 pdm = GlobalLock(lppd->hDevMode);
1385 name = (WCHAR*)pdn + pdn->wDeviceOffset;
1387 name = pdm->dmDeviceName;
1388 PRINTDLG_SetUpPrinterListComboW(hDlg, comboID, name);
1389 if(pdm) GlobalUnlock(lppd->hDevMode);
1390 if(pdn) GlobalUnlock(lppd->hDevNames);
1392 /* Now find selected printer and update rest of dlg */
1393 /* ansi is ok here */
1394 name = HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR));
1395 if (GetDlgItemTextW(hDlg, comboID, name, 255))
1396 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1397 HeapFree(GetProcessHeap(),0,name);
1399 /* else use default printer */
1401 DWORD dwBufLen = sizeof(name) / sizeof(WCHAR);
1402 BOOL ret = GetDefaultPrinterW(name, &dwBufLen);
1405 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1407 FIXME("No default printer found, expect problems!\n");
1412 /***********************************************************************
1413 * PRINTDLG_WMCommand [internal]
1415 LRESULT PRINTDLG_WMCommandA(HWND hDlg, WPARAM wParam,
1416 LPARAM lParam, PRINT_PTRA* PrintStructures)
1418 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
1419 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1420 LPDEVMODEA lpdm = PrintStructures->lpDevMode;
1422 switch (LOWORD(wParam)) {
1424 TRACE(" OK button was hit\n");
1425 if (!PRINTDLG_UpdatePrintDlgA(hDlg, PrintStructures)) {
1426 FIXME("Update printdlg was not successful!\n");
1429 EndDialog(hDlg, TRUE);
1433 TRACE(" CANCEL button was hit\n");
1434 EndDialog(hDlg, FALSE);
1438 TRACE(" HELP button was hit\n");
1439 SendMessageA(lppd->hwndOwner, PrintStructures->HelpMessageID,
1440 (WPARAM) hDlg, (LPARAM) lppd);
1443 case chx2: /* collate pages checkbox */
1444 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1445 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1446 (LPARAM)PrintStructures->hCollateIcon);
1448 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1449 (LPARAM)PrintStructures->hNoCollateIcon);
1451 case edt1: /* from page nr editbox */
1452 case edt2: /* to page nr editbox */
1453 if (HIWORD(wParam)==EN_CHANGE) {
1456 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1457 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1458 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1459 CheckRadioButton(hDlg, rad1, rad3, rad3);
1464 if(HIWORD(wParam) == EN_CHANGE) {
1465 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1467 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1469 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1474 case psh1: /* Print Setup */
1478 if (!PrintStructures->dlg.lpPrintDlg16) {
1479 FIXME("The 32bit print dialog does not have this button!?\n");
1483 memcpy(&pdlg,PrintStructures->dlg.lpPrintDlg16,sizeof(pdlg));
1484 pdlg.Flags |= PD_PRINTSETUP;
1485 pdlg.hwndOwner = HWND_16(hDlg);
1486 if (!PrintDlg16(&pdlg))
1491 case psh2: /* Properties button */
1494 char PrinterName[256];
1496 GetDlgItemTextA(hDlg, PrinterComboID, PrinterName, 255);
1497 if (!OpenPrinterA(PrinterName, &hPrinter, NULL)) {
1498 FIXME(" Call to OpenPrinter did not succeed!\n");
1501 DocumentPropertiesA(hDlg, hPrinter, PrinterName,
1502 PrintStructures->lpDevMode,
1503 PrintStructures->lpDevMode,
1504 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1505 ClosePrinter(hPrinter);
1509 case rad1: /* Paperorientation */
1510 if (lppd->Flags & PD_PRINTSETUP)
1512 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1513 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1514 (LPARAM)(PrintStructures->hPortraitIcon));
1518 case rad2: /* Paperorientation */
1519 if (lppd->Flags & PD_PRINTSETUP)
1521 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1522 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1523 (LPARAM)(PrintStructures->hLandscapeIcon));
1527 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1528 if (PrinterComboID != LOWORD(wParam)) {
1529 FIXME("No handling for print quality combo box yet.\n");
1533 case cmb4: /* Printer combobox */
1534 if (HIWORD(wParam)==CBN_SELCHANGE) {
1535 char PrinterName[256];
1536 GetDlgItemTextA(hDlg, LOWORD(wParam), PrinterName, 255);
1537 PRINTDLG_ChangePrinterA(hDlg, PrinterName, PrintStructures);
1541 case cmb2: /* Papersize */
1543 DWORD Sel = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1545 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
1551 case cmb3: /* Bin */
1553 DWORD Sel = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1555 lpdm->dmDefaultSource = SendDlgItemMessageA(hDlg, cmb3,
1556 CB_GETITEMDATA, Sel,
1561 if(lppd->Flags & PD_PRINTSETUP) {
1562 switch (LOWORD(wParam)) {
1563 case rad1: /* orientation */
1565 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1566 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1567 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1568 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1570 (LPARAM)PrintStructures->hPortraitIcon);
1571 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1573 (LPARAM)PrintStructures->hPortraitIcon);
1576 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1577 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1578 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1580 (LPARAM)PrintStructures->hLandscapeIcon);
1581 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1583 (LPARAM)PrintStructures->hLandscapeIcon);
1592 static LRESULT PRINTDLG_WMCommandW(HWND hDlg, WPARAM wParam,
1593 LPARAM lParam, PRINT_PTRW* PrintStructures)
1595 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1596 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1597 LPDEVMODEW lpdm = PrintStructures->lpDevMode;
1599 switch (LOWORD(wParam)) {
1601 TRACE(" OK button was hit\n");
1602 if (!PRINTDLG_UpdatePrintDlgW(hDlg, PrintStructures)) {
1603 FIXME("Update printdlg was not successful!\n");
1606 EndDialog(hDlg, TRUE);
1610 TRACE(" CANCEL button was hit\n");
1611 EndDialog(hDlg, FALSE);
1615 TRACE(" HELP button was hit\n");
1616 SendMessageW(lppd->hwndOwner, PrintStructures->HelpMessageID,
1617 (WPARAM) hDlg, (LPARAM) lppd);
1620 case chx2: /* collate pages checkbox */
1621 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1622 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1623 (LPARAM)PrintStructures->hCollateIcon);
1625 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1626 (LPARAM)PrintStructures->hNoCollateIcon);
1628 case edt1: /* from page nr editbox */
1629 case edt2: /* to page nr editbox */
1630 if (HIWORD(wParam)==EN_CHANGE) {
1633 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1634 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1635 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1636 CheckRadioButton(hDlg, rad1, rad3, rad3);
1641 if(HIWORD(wParam) == EN_CHANGE) {
1642 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1644 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1646 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1650 case psh1: /* Print Setup */
1652 ERR("psh1 is called from 16bit code only, we should not get here.\n");
1655 case psh2: /* Properties button */
1658 WCHAR PrinterName[256];
1660 if (!GetDlgItemTextW(hDlg, PrinterComboID, PrinterName, 255)) break;
1661 if (!OpenPrinterW(PrinterName, &hPrinter, NULL)) {
1662 FIXME(" Call to OpenPrinter did not succeed!\n");
1665 DocumentPropertiesW(hDlg, hPrinter, PrinterName,
1666 PrintStructures->lpDevMode,
1667 PrintStructures->lpDevMode,
1668 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1669 ClosePrinter(hPrinter);
1673 case rad1: /* Paperorientation */
1674 if (lppd->Flags & PD_PRINTSETUP)
1676 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1677 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1678 (LPARAM)(PrintStructures->hPortraitIcon));
1682 case rad2: /* Paperorientation */
1683 if (lppd->Flags & PD_PRINTSETUP)
1685 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1686 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1687 (LPARAM)(PrintStructures->hLandscapeIcon));
1691 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1692 if (PrinterComboID != LOWORD(wParam)) {
1693 FIXME("No handling for print quality combo box yet.\n");
1697 case cmb4: /* Printer combobox */
1698 if (HIWORD(wParam)==CBN_SELCHANGE) {
1699 WCHAR PrinterName[256];
1700 GetDlgItemTextW(hDlg, LOWORD(wParam), PrinterName, 255);
1701 PRINTDLG_ChangePrinterW(hDlg, PrinterName, PrintStructures);
1705 case cmb2: /* Papersize */
1707 DWORD Sel = SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1709 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageW(hDlg, cmb2,
1715 case cmb3: /* Bin */
1717 DWORD Sel = SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1719 lpdm->dmDefaultSource = SendDlgItemMessageW(hDlg, cmb3,
1720 CB_GETITEMDATA, Sel,
1725 if(lppd->Flags & PD_PRINTSETUP) {
1726 switch (LOWORD(wParam)) {
1727 case rad1: /* orientation */
1729 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1730 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1731 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1732 SendDlgItemMessageW(hDlg, stc10, STM_SETIMAGE,
1734 (LPARAM)PrintStructures->hPortraitIcon);
1735 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE,
1737 (LPARAM)PrintStructures->hPortraitIcon);
1740 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1741 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1742 SendDlgItemMessageW(hDlg, stc10, STM_SETIMAGE,
1744 (LPARAM)PrintStructures->hLandscapeIcon);
1745 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE,
1747 (LPARAM)PrintStructures->hLandscapeIcon);
1756 /***********************************************************************
1757 * PrintDlgProcA [internal]
1759 static INT_PTR CALLBACK PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
1762 PRINT_PTRA* PrintStructures;
1763 INT_PTR res = FALSE;
1765 if (uMsg!=WM_INITDIALOG) {
1766 PrintStructures = (PRINT_PTRA*)GetPropA(hDlg,"__WINE_PRINTDLGDATA");
1767 if (!PrintStructures)
1770 PrintStructures = (PRINT_PTRA*) lParam;
1771 SetPropA(hDlg,"__WINE_PRINTDLGDATA",PrintStructures);
1772 if(!check_printer_setup(hDlg))
1774 EndDialog(hDlg,FALSE);
1777 res = PRINTDLG_WMInitDialog(hDlg, wParam, PrintStructures);
1779 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
1780 res = PrintStructures->lpPrintDlg->lpfnPrintHook(
1781 hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg
1786 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
1787 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam,
1794 return PRINTDLG_WMCommandA(hDlg, wParam, lParam, PrintStructures);
1797 DestroyIcon(PrintStructures->hCollateIcon);
1798 DestroyIcon(PrintStructures->hNoCollateIcon);
1799 DestroyIcon(PrintStructures->hPortraitIcon);
1800 DestroyIcon(PrintStructures->hLandscapeIcon);
1801 if(PrintStructures->hwndUpDown)
1802 DestroyWindow(PrintStructures->hwndUpDown);
1808 static INT_PTR CALLBACK PrintDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
1811 static const WCHAR propW[] = {'_','_','W','I','N','E','_','P','R','I','N','T','D','L','G','D','A','T','A',0};
1812 PRINT_PTRW* PrintStructures;
1813 INT_PTR res = FALSE;
1815 if (uMsg!=WM_INITDIALOG) {
1816 PrintStructures = (PRINT_PTRW*) GetPropW(hDlg, propW);
1817 if (!PrintStructures)
1820 PrintStructures = (PRINT_PTRW*) lParam;
1821 SetPropW(hDlg, propW, PrintStructures);
1822 if(!check_printer_setup(hDlg))
1824 EndDialog(hDlg,FALSE);
1827 res = PRINTDLG_WMInitDialogW(hDlg, wParam, PrintStructures);
1829 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
1830 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg);
1834 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
1835 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam, lParam);
1841 return PRINTDLG_WMCommandW(hDlg, wParam, lParam, PrintStructures);
1844 DestroyIcon(PrintStructures->hCollateIcon);
1845 DestroyIcon(PrintStructures->hNoCollateIcon);
1846 DestroyIcon(PrintStructures->hPortraitIcon);
1847 DestroyIcon(PrintStructures->hLandscapeIcon);
1848 if(PrintStructures->hwndUpDown)
1849 DestroyWindow(PrintStructures->hwndUpDown);
1855 /************************************************************
1857 * PRINTDLG_GetDlgTemplate
1860 static HGLOBAL PRINTDLG_GetDlgTemplateA(PRINTDLGA *lppd)
1865 if (lppd->Flags & PD_PRINTSETUP) {
1866 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
1867 hDlgTmpl = lppd->hSetupTemplate;
1868 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
1869 hResInfo = FindResourceA(lppd->hInstance,
1870 lppd->lpSetupTemplateName, (LPSTR)RT_DIALOG);
1871 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1873 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32_SETUP",
1875 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1878 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
1879 hDlgTmpl = lppd->hPrintTemplate;
1880 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
1881 hResInfo = FindResourceA(lppd->hInstance,
1882 lppd->lpPrintTemplateName,
1884 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1886 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32",
1888 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1894 static HGLOBAL PRINTDLG_GetDlgTemplateW(PRINTDLGW *lppd)
1898 static const WCHAR xpsetup[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
1899 static const WCHAR xprint[] = { 'P','R','I','N','T','3','2',0};
1901 if (lppd->Flags & PD_PRINTSETUP) {
1902 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
1903 hDlgTmpl = lppd->hSetupTemplate;
1904 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
1905 hResInfo = FindResourceW(lppd->hInstance,
1906 lppd->lpSetupTemplateName, (LPWSTR)RT_DIALOG);
1907 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1909 hResInfo = FindResourceW(COMDLG32_hInstance, xpsetup, (LPWSTR)RT_DIALOG);
1910 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1913 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
1914 hDlgTmpl = lppd->hPrintTemplate;
1915 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
1916 hResInfo = FindResourceW(lppd->hInstance,
1917 lppd->lpPrintTemplateName,
1919 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1921 hResInfo = FindResourceW(COMDLG32_hInstance, xprint, (LPWSTR)RT_DIALOG);
1922 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1928 /***********************************************************************
1933 static BOOL PRINTDLG_CreateDCA(LPPRINTDLGA lppd)
1935 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
1936 DEVMODEA *pdm = GlobalLock(lppd->hDevMode);
1938 if(lppd->Flags & PD_RETURNDC) {
1939 lppd->hDC = CreateDCA((char*)pdn + pdn->wDriverOffset,
1940 (char*)pdn + pdn->wDeviceOffset,
1941 (char*)pdn + pdn->wOutputOffset,
1943 } else if(lppd->Flags & PD_RETURNIC) {
1944 lppd->hDC = CreateICA((char*)pdn + pdn->wDriverOffset,
1945 (char*)pdn + pdn->wDeviceOffset,
1946 (char*)pdn + pdn->wOutputOffset,
1949 GlobalUnlock(lppd->hDevNames);
1950 GlobalUnlock(lppd->hDevMode);
1951 return lppd->hDC ? TRUE : FALSE;
1954 static BOOL PRINTDLG_CreateDCW(LPPRINTDLGW lppd)
1956 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
1957 DEVMODEW *pdm = GlobalLock(lppd->hDevMode);
1959 if(lppd->Flags & PD_RETURNDC) {
1960 lppd->hDC = CreateDCW((WCHAR*)pdn + pdn->wDriverOffset,
1961 (WCHAR*)pdn + pdn->wDeviceOffset,
1962 (WCHAR*)pdn + pdn->wOutputOffset,
1964 } else if(lppd->Flags & PD_RETURNIC) {
1965 lppd->hDC = CreateICW((WCHAR*)pdn + pdn->wDriverOffset,
1966 (WCHAR*)pdn + pdn->wDeviceOffset,
1967 (WCHAR*)pdn + pdn->wOutputOffset,
1970 GlobalUnlock(lppd->hDevNames);
1971 GlobalUnlock(lppd->hDevMode);
1972 return lppd->hDC ? TRUE : FALSE;
1975 /***********************************************************************
1976 * PrintDlgA (COMDLG32.@)
1978 * Displays the the PRINT dialog box, which enables the user to specify
1979 * specific properties of the print job.
1982 * lppd [IO] ptr to PRINTDLG32 struct
1985 * nonzero if the user pressed the OK button
1986 * zero if the user cancelled the window or an error occurred
1990 * * The Collate Icons do not display, even though they are in the code.
1991 * * The Properties Button(s) should call DocumentPropertiesA().
1994 BOOL WINAPI PrintDlgA(LPPRINTDLGA lppd)
1998 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrA( lppd->hwndOwner, GWLP_HINSTANCE );
2000 if(TRACE_ON(commdlg)) {
2001 char flagstr[1000] = "";
2002 struct pd_flags *pflag = pd_flags;
2003 for( ; pflag->name; pflag++) {
2004 if(lppd->Flags & pflag->flag)
2005 strcat(flagstr, pflag->name);
2007 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2008 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2009 "flags %08lx (%s)\n",
2010 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2011 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2012 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2015 if(lppd->lStructSize != sizeof(PRINTDLGA)) {
2016 WARN("structure size failure !!!\n");
2017 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2021 if(lppd->Flags & PD_RETURNDEFAULT) {
2022 PRINTER_INFO_2A *pbuf;
2023 DRIVER_INFO_3A *dbuf;
2027 if(lppd->hDevMode || lppd->hDevNames) {
2028 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2029 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2032 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2033 WARN("Can't find default printer\n");
2034 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2038 GetPrinterA(hprn, 2, NULL, 0, &needed);
2039 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
2040 GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2042 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
2043 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
2044 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2045 ERR("GetPrinterDriverA failed, le %ld, fix your config for printer %s!\n",GetLastError(),pbuf->pPrinterName);
2046 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2051 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2055 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2056 pbuf->pDevMode->dmDriverExtra);
2057 ptr = GlobalLock(lppd->hDevMode);
2058 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2059 pbuf->pDevMode->dmDriverExtra);
2060 GlobalUnlock(lppd->hDevMode);
2061 HeapFree(GetProcessHeap(), 0, pbuf);
2062 HeapFree(GetProcessHeap(), 0, dbuf);
2066 PRINT_PTRA *PrintStructures;
2068 /* load Dialog resources,
2069 * depending on Flags indicates Print32 or Print32_setup dialog
2071 hDlgTmpl = PRINTDLG_GetDlgTemplateA(lppd);
2073 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2076 ptr = LockResource( hDlgTmpl );
2078 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2082 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2083 sizeof(PRINT_PTRA));
2084 PrintStructures->lpPrintDlg = lppd;
2086 /* and create & process the dialog .
2087 * -1 is failure, 0 is broken hwnd, everything else is ok.
2089 bRet = (0<DialogBoxIndirectParamA(hInst, ptr, lppd->hwndOwner,
2091 (LPARAM)PrintStructures));
2094 DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2095 PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
2096 DRIVER_INFO_3A *di = PrintStructures->lpDriverInfo;
2098 if (lppd->hDevMode == 0) {
2099 TRACE(" No hDevMode yet... Need to create my own\n");
2100 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2101 lpdm->dmSize + lpdm->dmDriverExtra);
2103 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2104 lpdm->dmSize + lpdm->dmDriverExtra,
2107 lpdmReturn = GlobalLock(lppd->hDevMode);
2108 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2110 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2115 GlobalUnlock(lppd->hDevMode);
2117 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2118 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2119 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2120 HeapFree(GetProcessHeap(), 0, PrintStructures);
2122 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2123 bRet = PRINTDLG_CreateDCA(lppd);
2125 TRACE("exit! (%d)\n", bRet);
2129 /***********************************************************************
2130 * PrintDlgW (COMDLG32.@)
2134 BOOL WINAPI PrintDlgW(
2135 LPPRINTDLGW lppd /* [in/out] ptr to PRINTDLG32 struct */
2140 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW( lppd->hwndOwner, GWLP_HINSTANCE );
2142 if(TRACE_ON(commdlg)) {
2143 char flagstr[1000] = "";
2144 struct pd_flags *pflag = pd_flags;
2145 for( ; pflag->name; pflag++) {
2146 if(lppd->Flags & pflag->flag)
2147 strcat(flagstr, pflag->name);
2149 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2150 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2151 "flags %08lx (%s)\n",
2152 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2153 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2154 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2157 if(lppd->lStructSize != sizeof(PRINTDLGW)) {
2158 WARN("structure size failure !!!\n");
2159 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2163 if(lppd->Flags & PD_RETURNDEFAULT) {
2164 PRINTER_INFO_2W *pbuf;
2165 DRIVER_INFO_3W *dbuf;
2169 if(lppd->hDevMode || lppd->hDevNames) {
2170 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2171 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2174 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2175 WARN("Can't find default printer\n");
2176 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2180 GetPrinterW(hprn, 2, NULL, 0, &needed);
2181 pbuf = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*needed);
2182 GetPrinterW(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2184 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
2185 dbuf = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
2186 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2187 ERR("GetPrinterDriverA failed, le %ld, fix your config for printer %s!\n",GetLastError(),debugstr_w(pbuf->pPrinterName));
2188 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2193 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2197 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2198 pbuf->pDevMode->dmDriverExtra);
2199 ptr = GlobalLock(lppd->hDevMode);
2200 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2201 pbuf->pDevMode->dmDriverExtra);
2202 GlobalUnlock(lppd->hDevMode);
2203 HeapFree(GetProcessHeap(), 0, pbuf);
2204 HeapFree(GetProcessHeap(), 0, dbuf);
2208 PRINT_PTRW *PrintStructures;
2210 /* load Dialog resources,
2211 * depending on Flags indicates Print32 or Print32_setup dialog
2213 hDlgTmpl = PRINTDLG_GetDlgTemplateW(lppd);
2215 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2218 ptr = LockResource( hDlgTmpl );
2220 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2224 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2225 sizeof(PRINT_PTRW));
2226 PrintStructures->lpPrintDlg = lppd;
2228 /* and create & process the dialog .
2229 * -1 is failure, 0 is broken hwnd, everything else is ok.
2231 bRet = (0<DialogBoxIndirectParamW(hInst, ptr, lppd->hwndOwner,
2233 (LPARAM)PrintStructures));
2236 DEVMODEW *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2237 PRINTER_INFO_2W *pi = PrintStructures->lpPrinterInfo;
2238 DRIVER_INFO_3W *di = PrintStructures->lpDriverInfo;
2240 if (lppd->hDevMode == 0) {
2241 TRACE(" No hDevMode yet... Need to create my own\n");
2242 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2243 lpdm->dmSize + lpdm->dmDriverExtra);
2246 if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
2247 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2249 GlobalUnlock(lppd->hDevMode);
2250 TRACE("Now got %d locks\n", locks);
2253 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2254 lpdm->dmSize + lpdm->dmDriverExtra,
2257 lpdmReturn = GlobalLock(lppd->hDevMode);
2258 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2260 if (lppd->hDevNames != 0) {
2262 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
2263 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2265 GlobalUnlock(lppd->hDevNames);
2268 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2273 GlobalUnlock(lppd->hDevMode);
2275 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2276 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2277 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2278 HeapFree(GetProcessHeap(), 0, PrintStructures);
2280 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2281 bRet = PRINTDLG_CreateDCW(lppd);
2283 TRACE("exit! (%d)\n", bRet);
2287 /***********************************************************************
2292 * cmb1 - printer select (not in standart dialog template)
2294 * cmb3 - source (tray?)
2295 * edt4 - border left
2297 * edt6 - border right
2298 * edt7 - border bottom
2299 * psh3 - "Printer..."
2303 LPPAGESETUPDLGA dlga; /* Handler to user defined struct */
2305 HWND hDlg; /* Page Setup dialog handler */
2306 PAGESETUPDLGA curdlg; /* Struct means cerrent dialog state */
2307 RECT rtDrawRect; /* Drawing rect for page */
2311 LPPAGESETUPDLGW dlga;
2316 static HGLOBAL PRINTDLG_GetPGSTemplateA(PAGESETUPDLGA *lppd)
2321 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2322 hDlgTmpl = lppd->hPageSetupTemplate;
2323 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2324 hResInfo = FindResourceA(lppd->hInstance,
2325 lppd->lpPageSetupTemplateName, (LPSTR)RT_DIALOG);
2326 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2328 hResInfo = FindResourceA(COMDLG32_hInstance,(LPCSTR)PAGESETUPDLGORD,(LPSTR)RT_DIALOG);
2329 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2334 static HGLOBAL PRINTDLG_GetPGSTemplateW(PAGESETUPDLGW *lppd)
2339 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2340 hDlgTmpl = lppd->hPageSetupTemplate;
2341 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2342 hResInfo = FindResourceW(lppd->hInstance,
2343 lppd->lpPageSetupTemplateName, (LPWSTR)RT_DIALOG);
2344 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2346 hResInfo = FindResourceW(COMDLG32_hInstance,(LPCWSTR)PAGESETUPDLGORD,(LPWSTR)RT_DIALOG);
2347 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2353 _c_10mm2size(PAGESETUPDLGA *dlga,DWORD size) {
2354 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2355 return 10*size*100/254;
2356 /* If we don't have a flag, we can choose one. Use millimeters
2357 * to avoid confusing me
2359 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2365 _c_inch2size(PAGESETUPDLGA *dlga,DWORD size) {
2366 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2368 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
2369 return (size*254)/100;
2370 /* if we don't have a flag, we can choose one. Use millimeters
2371 * to avoid confusing me
2373 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2374 return (size*254)/100;
2378 _c_size2strA(PageSetupDataA *pda,DWORD size,LPSTR strout) {
2379 strcpy(strout,"<undef>");
2380 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2381 sprintf(strout,"%ld",(size)/100);
2384 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2385 sprintf(strout,"%ldin",(size)/1000);
2388 pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2389 sprintf(strout,"%ld",(size)/100);
2393 _c_size2strW(PageSetupDataW *pda,DWORD size,LPWSTR strout) {
2394 static const WCHAR UNDEF[] = { '<', 'u', 'n', 'd', 'e', 'f', '>', 0 };
2395 static const WCHAR mm_fmt[] = { '%', '.', '2', 'f', 'm', 'm', 0 };
2396 static const WCHAR in_fmt[] = { '%', '.', '2', 'f', 'i', 'n', 0 };
2397 lstrcpyW(strout, UNDEF);
2398 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2399 wsprintfW(strout,mm_fmt,(size*1.0)/100.0);
2402 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2403 wsprintfW(strout,in_fmt,(size*1.0)/1000.0);
2406 pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2407 wsprintfW(strout,mm_fmt,(size*1.0)/100.0);
2412 _c_str2sizeA(PAGESETUPDLGA *dlga,LPCSTR strin) {
2417 if (!sscanf(strin,"%f%s",&val,rest))
2420 if (!strcmp(rest,"in") || !strcmp(rest,"inch")) {
2421 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2424 return val*25.4*100;
2426 if (!strcmp(rest,"cm")) { rest[0]='m'; val = val*10.0; }
2427 if (!strcmp(rest,"m")) { strcpy(rest,"mm"); val = val*1000.0; }
2429 if (!strcmp(rest,"mm")) {
2430 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
2433 return 1000.0*val/25.4;
2435 if (rest[0]=='\0') {
2436 /* use application supplied default */
2437 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2441 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2446 ERR("Did not find a conversion for type '%s'!\n",rest);
2452 _c_str2sizeW(PAGESETUPDLGW *dlga, LPCWSTR strin) {
2455 /* this W -> A transition is OK */
2456 /* we need a unicode version of sscanf to avoid it */
2457 WideCharToMultiByte(CP_ACP, 0, strin, -1, buf, sizeof(buf), NULL, NULL);
2458 return _c_str2sizeA((PAGESETUPDLGA *)dlga, buf);
2462 /****************************************************************************
2463 * PRINTDLG_PS_UpdateDlgStructA
2465 * Updates pda->dlga structure
2466 * Function calls when user presses OK button
2469 * hDlg [in] main window dialog HANDLE
2470 * pda [in/out] ptr to PageSetupDataA structere
2476 PRINTDLG_PS_UpdateDlgStructA(HWND hDlg, PageSetupDataA *pda) {
2481 memcpy(pda->dlga, &pda->curdlg, sizeof(pda->curdlg));
2482 pda->dlga->hDevMode = pda->pdlg.hDevMode;
2483 pda->dlga->hDevNames = pda->pdlg.hDevNames;
2485 dn = GlobalLock(pda->pdlg.hDevNames);
2486 dm = GlobalLock(pda->pdlg.hDevMode);
2488 /* Save paper orientation into device context */
2489 if(pda->curdlg.ptPaperSize.x > pda->curdlg.ptPaperSize.y)
2490 dm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
2492 dm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
2494 /* Save paper size into the device context */
2495 paperword = SendDlgItemMessageA(hDlg,cmb2,CB_GETITEMDATA,
2496 SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0), 0);
2497 if (paperword != CB_ERR)
2498 dm->u1.s1.dmPaperSize = paperword;
2500 FIXME("could not get dialog text for papersize cmbbox?\n");
2502 /* Save paper source into the device context */
2503 paperword = SendDlgItemMessageA(hDlg,cmb1,CB_GETITEMDATA,
2504 SendDlgItemMessageA(hDlg, cmb1, CB_GETCURSEL, 0, 0), 0);
2505 if (paperword != CB_ERR)
2506 dm->dmDefaultSource = paperword;
2508 FIXME("could not get dialog text for papersize cmbbox?\n");
2510 GlobalUnlock(pda->pdlg.hDevNames);
2511 GlobalUnlock(pda->pdlg.hDevMode);
2517 PRINTDLG_PS_UpdateDlgStructW(HWND hDlg, PageSetupDataW *pda) {
2520 LPWSTR devname,portname;
2521 WCHAR papername[64];
2524 dn = GlobalLock(pda->pdlg.hDevNames);
2525 dm = GlobalLock(pda->pdlg.hDevMode);
2526 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
2527 portname = ((WCHAR*)dn)+dn->wOutputOffset;
2529 /* Save paper size into device context */
2530 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
2531 /* Save paper source into device context */
2532 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
2534 if (GetDlgItemTextW(hDlg,cmb2,papername,sizeof(papername))>0) {
2535 PRINTDLG_PaperSizeW(&(pda->pdlg),papername,&(pda->dlga->ptPaperSize));
2536 pda->dlga->ptPaperSize.x = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga,pda->dlga->ptPaperSize.x);
2537 pda->dlga->ptPaperSize.y = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga,pda->dlga->ptPaperSize.y);
2539 FIXME("could not get dialog text for papersize cmbbox?\n");
2540 #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); }
2541 GETVAL(edt4,pda->dlga->rtMargin.left);
2542 GETVAL(edt5,pda->dlga->rtMargin.top);
2543 GETVAL(edt6,pda->dlga->rtMargin.right);
2544 GETVAL(edt7,pda->dlga->rtMargin.bottom);
2547 /* If we are in landscape, swap x and y of page size */
2548 if (IsDlgButtonChecked(hDlg, rad2)) {
2550 tmp = pda->dlga->ptPaperSize.x;
2551 pda->dlga->ptPaperSize.x = pda->dlga->ptPaperSize.y;
2552 pda->dlga->ptPaperSize.y = tmp;
2554 GlobalUnlock(pda->pdlg.hDevNames);
2555 GlobalUnlock(pda->pdlg.hDevMode);
2559 /**********************************************************************************************
2560 * PRINTDLG_PS_ChangeActivePrinerA
2562 * Redefines hDevMode and hDevNames HANDLES and initialises it.
2565 * name [in] Name of a printer for activation
2566 * pda [in/out] ptr to PageSetupDataA structure
2573 PRINTDLG_PS_ChangeActivePrinterA(LPSTR name, PageSetupDataA *pda){
2576 LPPRINTER_INFO_2A lpPrinterInfo;
2577 LPDRIVER_INFO_3A lpDriverInfo;
2578 DEVMODEA *pDevMode, *dm;
2580 if(!OpenPrinterA(name, &hprn, NULL)){
2581 ERR("Can't open printer %s\n", name);
2584 GetPrinterA(hprn, 2, NULL, 0, &needed);
2585 lpPrinterInfo = HeapAlloc(GetProcessHeap(), 0, needed);
2586 GetPrinterA(hprn, 2, (LPBYTE)lpPrinterInfo, needed, &needed);
2587 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
2588 lpDriverInfo = HeapAlloc(GetProcessHeap(), 0, needed);
2589 if(!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)lpDriverInfo, needed, &needed)) {
2590 ERR("GetPrinterDriverA failed for %s, fix your config!\n", lpPrinterInfo->pPrinterName);
2595 needed = DocumentPropertiesA(0, 0, name, NULL, NULL, 0);
2597 ERR("DocumentProperties fails on %s\n", debugstr_a(name));
2600 pDevMode = HeapAlloc(GetProcessHeap(), 0, needed);
2601 DocumentPropertiesA(0, 0, name, pDevMode, NULL, DM_OUT_BUFFER);
2603 pda->pdlg.hDevMode = GlobalReAlloc(pda->pdlg.hDevMode,
2604 pDevMode->dmSize + pDevMode->dmDriverExtra,
2606 dm = GlobalLock(pda->pdlg.hDevMode);
2607 memcpy(dm, pDevMode, pDevMode->dmSize + pDevMode->dmDriverExtra);
2609 PRINTDLG_CreateDevNames(&(pda->pdlg.hDevNames),
2610 lpDriverInfo->pDriverPath,
2611 lpPrinterInfo->pPrinterName,
2612 lpPrinterInfo->pPortName);
2614 GlobalUnlock(pda->pdlg.hDevMode);
2615 HeapFree(GetProcessHeap(), 0, pDevMode);
2616 HeapFree(GetProcessHeap(), 0, lpPrinterInfo);
2617 HeapFree(GetProcessHeap(), 0, lpDriverInfo);
2621 /****************************************************************************************
2622 * PRINTDLG_PS_ChangePrinterA
2624 * Fills Printers, Paper and Source combo
2630 PRINTDLG_PS_ChangePrinterA(HWND hDlg, PageSetupDataA *pda) {
2633 LPSTR devname,portname;
2635 dn = GlobalLock(pda->pdlg.hDevNames);
2636 dm = GlobalLock(pda->pdlg.hDevMode);
2637 devname = ((char*)dn)+dn->wDeviceOffset;
2638 portname = ((char*)dn)+dn->wOutputOffset;
2639 PRINTDLG_SetUpPrinterListComboA(hDlg, cmb1, devname);
2640 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb2,devname,portname,dm);
2641 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb3,devname,portname,dm);
2642 GlobalUnlock(pda->pdlg.hDevNames);
2643 GlobalUnlock(pda->pdlg.hDevMode);
2648 PRINTDLG_PS_ChangePrinterW(HWND hDlg, PageSetupDataW *pda) {
2651 LPWSTR devname,portname;
2653 dn = GlobalLock(pda->pdlg.hDevNames);
2654 dm = GlobalLock(pda->pdlg.hDevMode);
2655 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
2656 portname = ((WCHAR*)dn)+dn->wOutputOffset;
2657 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
2658 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
2659 GlobalUnlock(pda->pdlg.hDevNames);
2660 GlobalUnlock(pda->pdlg.hDevMode);
2664 /******************************************************************************************
2665 * PRINTDLG_PS_ChangePaperPrev
2667 * Changes paper preview size / position
2670 * pda [i] Pointer for current PageSetupDataA structure
2676 PRINTDLG_PS_ChangePaperPrev(PageSetupDataA *pda)
2678 LONG width, height, x, y;
2681 if(pda->curdlg.ptPaperSize.x > pda->curdlg.ptPaperSize.y) {
2682 width = pda->rtDrawRect.right - pda->rtDrawRect.left;
2683 height = pda->curdlg.ptPaperSize.y * width / pda->curdlg.ptPaperSize.x;
2685 height = pda->rtDrawRect.bottom - pda->rtDrawRect.top;
2686 width = pda->curdlg.ptPaperSize.x * height / pda->curdlg.ptPaperSize.y;
2688 x = (pda->rtDrawRect.right + pda->rtDrawRect.left - width) / 2;
2689 y = (pda->rtDrawRect.bottom + pda->rtDrawRect.top - height) / 2;
2690 TRACE("rtDrawRect(%ld, %ld, %ld, %ld) x=%ld, y=%ld, w=%ld, h=%ld",
2691 pda->rtDrawRect.left, pda->rtDrawRect.top, pda->rtDrawRect.right, pda->rtDrawRect.bottom,
2692 x, y, width, height);
2695 MoveWindow(GetDlgItem(pda->hDlg, rct2), x+width, y+SHADOW, SHADOW, height, FALSE);
2696 MoveWindow(GetDlgItem(pda->hDlg, rct3), x+SHADOW, y+height, width, SHADOW, FALSE);
2697 MoveWindow(GetDlgItem(pda->hDlg, rct1), x, y, width, height, FALSE);
2698 memcpy(&rtTmp, &pda->rtDrawRect, sizeof(RECT));
2699 rtTmp.right += SHADOW;
2700 rtTmp.bottom += SHADOW;
2703 InvalidateRect(pda->hDlg, &rtTmp, TRUE);
2707 #define GETVAL(idc,val) \
2708 if(msg == EN_CHANGE){ \
2709 if (GetDlgItemTextA(hDlg,idc,buf,sizeof(buf)) > 0)\
2710 val = _c_str2sizeA(pda->dlga,buf); \
2712 FIXME("could not get dlgitemtexta for %x\n",id); \
2715 /********************************************************************************
2716 * PRINTDLG_PS_WMCommandA
2717 * process WM_COMMAND message for PageSetupDlgA
2720 * hDlg [in] Main dialog HANDLE
2721 * wParam [in] WM_COMMAND wParam
2722 * lParam [in] WM_COMMAND lParam
2723 * pda [in/out] ptr to PageSetupDataA
2727 PRINTDLG_PS_WMCommandA(
2728 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataA *pda
2730 WORD msg = HIWORD(wParam);
2731 WORD id = LOWORD(wParam);
2734 TRACE("loword (lparam) %d, wparam 0x%x, lparam %08lx\n",
2735 LOWORD(lParam),wParam,lParam);
2738 if (!PRINTDLG_PS_UpdateDlgStructA(hDlg, pda))
2740 EndDialog(hDlg, TRUE);
2744 EndDialog(hDlg, FALSE);
2748 pda->pdlg.Flags = 0;
2749 pda->pdlg.hwndOwner = hDlg;
2750 if (PrintDlgA(&(pda->pdlg)))
2751 PRINTDLG_PS_ChangePrinterA(hDlg,pda);
2755 if (pda->curdlg.ptPaperSize.x > pda->curdlg.ptPaperSize.y){
2756 DWORD tmp = pda->curdlg.ptPaperSize.x;
2757 pda->curdlg.ptPaperSize.x = pda->curdlg.ptPaperSize.y;
2758 pda->curdlg.ptPaperSize.y = tmp;
2760 PRINTDLG_PS_ChangePaperPrev(pda);
2763 if (pda->curdlg.ptPaperSize.y > pda->curdlg.ptPaperSize.x){
2764 DWORD tmp = pda->curdlg.ptPaperSize.x;
2765 pda->curdlg.ptPaperSize.x = pda->curdlg.ptPaperSize.y;
2766 pda->curdlg.ptPaperSize.y = tmp;
2768 PRINTDLG_PS_ChangePaperPrev(pda);
2770 case cmb1: /* Printer combo */
2771 if(msg == CBN_SELCHANGE){
2772 char crPrinterName[256];
2773 GetDlgItemTextA(hDlg, id, crPrinterName, 255);
2774 PRINTDLG_PS_ChangeActivePrinterA(crPrinterName, pda);
2775 PRINTDLG_PS_ChangePrinterA(hDlg, pda);
2778 case cmb2: /* Paper combo */
2779 if(msg == CBN_SELCHANGE){
2780 DWORD paperword = SendDlgItemMessageA(hDlg,cmb2,CB_GETITEMDATA,
2781 SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0), 0);
2782 if (paperword != CB_ERR) {
2783 PRINTDLG_PaperSizeA(&(pda->pdlg), paperword,&(pda->curdlg.ptPaperSize));
2784 pda->curdlg.ptPaperSize.x = _c_10mm2size(pda->dlga,pda->curdlg.ptPaperSize.x);
2785 pda->curdlg.ptPaperSize.y = _c_10mm2size(pda->dlga,pda->curdlg.ptPaperSize.y);
2787 if (IsDlgButtonChecked(hDlg, rad2)) {
2788 DWORD tmp = pda->curdlg.ptPaperSize.x;
2789 pda->curdlg.ptPaperSize.x = pda->curdlg.ptPaperSize.y;
2790 pda->curdlg.ptPaperSize.y = tmp;
2792 PRINTDLG_PS_ChangePaperPrev(pda);
2794 FIXME("could not get dialog text for papersize cmbbox?\n");
2798 if(msg == CBN_SELCHANGE){
2799 DEVMODEA *dm = GlobalLock(pda->pdlg.hDevMode);
2800 dm->dmDefaultSource = SendDlgItemMessageA(hDlg, cmb3,CB_GETITEMDATA,
2801 SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0), 0);
2802 GlobalUnlock(pda->pdlg.hDevMode);
2805 case psh2: /* Printer Properties button */
2808 char PrinterName[256];
2813 GetDlgItemTextA(hDlg, cmb1, PrinterName, 255);
2814 if (!OpenPrinterA(PrinterName, &hPrinter, NULL)) {
2815 FIXME("Call to OpenPrinter did not succeed!\n");
2818 dm = GlobalLock(pda->pdlg.hDevMode);
2819 DocumentPropertiesA(hDlg, hPrinter, PrinterName, dm, dm,
2820 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
2821 ClosePrinter(hPrinter);
2822 /* Changing paper */
2823 PRINTDLG_PaperSizeA(&(pda->pdlg), dm->u1.s1.dmPaperSize, &(pda->curdlg.ptPaperSize));
2824 pda->curdlg.ptPaperSize.x = _c_10mm2size(pda->dlga, pda->curdlg.ptPaperSize.x);
2825 pda->curdlg.ptPaperSize.y = _c_10mm2size(pda->dlga, pda->curdlg.ptPaperSize.y);
2826 if (dm->u1.s1.dmOrientation == DMORIENT_LANDSCAPE){
2827 DWORD tmp = pda->curdlg.ptPaperSize.x;
2828 pda->curdlg.ptPaperSize.x = pda->curdlg.ptPaperSize.y;
2829 pda->curdlg.ptPaperSize.y = tmp;
2830 CheckRadioButton(hDlg, rad1, rad2, rad2);
2833 CheckRadioButton(hDlg, rad1, rad2, rad1);
2834 /* Changing paper preview */
2835 PRINTDLG_PS_ChangePaperPrev(pda);
2836 /* Selecting paper in combo */
2837 count = SendDlgItemMessageA(hDlg, cmb2, CB_GETCOUNT, 0, 0);
2838 if(count != CB_ERR){
2839 for(i=0; i<count; ++i){
2840 if(SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, i, 0) == dm->u1.s1.dmPaperSize) {
2841 SendDlgItemMessageA(hDlg, cmb2, CB_SETCURSEL, i, 0);
2847 GlobalUnlock(pda->pdlg.hDevMode);
2851 GETVAL(id, pda->curdlg.rtMargin.left);
2854 GETVAL(id, pda->curdlg.rtMargin.right);
2857 GETVAL(id, pda->curdlg.rtMargin.top);
2860 GETVAL(id, pda->curdlg.rtMargin.bottom);
2863 InvalidateRect(GetDlgItem(hDlg, rct1), NULL, TRUE);
2869 PRINTDLG_PS_WMCommandW(
2870 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataW *pda
2872 TRACE("loword (lparam) %d, wparam 0x%x, lparam %08lx\n",
2873 LOWORD(lParam),wParam,lParam);
2874 switch (LOWORD(wParam)) {
2876 if (!PRINTDLG_PS_UpdateDlgStructW(hDlg, pda))
2878 EndDialog(hDlg, TRUE);
2882 EndDialog(hDlg, FALSE);
2886 pda->pdlg.Flags = 0;
2887 pda->pdlg.hwndOwner = hDlg;
2888 if (PrintDlgW(&(pda->pdlg)))
2889 PRINTDLG_PS_ChangePrinterW(hDlg,pda);
2897 /***********************************************************************
2898 * DefaultPagePaintHook
2899 * Default hook paint procedure that receives WM_PSD_* messages from the dialog box
2900 * whenever the sample page is redrawn.
2904 PRINTDLG_DefaultPagePaintHook(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam, PageSetupDataA *pda)
2906 LPRECT lprc = (LPRECT) lParam;
2907 HDC hdc = (HDC) wParam;
2910 HFONT hfont, holdfont;
2912 TRACE("uMsg: WM_USER+%d\n",uMsg-WM_USER);
2913 /* Call user paint hook if enable */
2914 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK)
2915 if (pda->dlga->lpfnPagePaintHook(hwndDlg, uMsg, wParam, lParam))
2919 /* LPPAGESETUPDLG in lParam */
2920 case WM_PSD_PAGESETUPDLG:
2921 /* Inform about the sample page rectangle */
2922 case WM_PSD_FULLPAGERECT:
2923 /* Inform about the margin rectangle */
2924 case WM_PSD_MINMARGINRECT:
2927 /* Draw dashed rectangle showing margins */
2928 case WM_PSD_MARGINRECT:
2929 hpen = CreatePen(PS_DASH, 1, GetSysColor(COLOR_3DSHADOW));
2930 holdpen = SelectObject(hdc, hpen);
2931 Rectangle(hdc, lprc->left, lprc->top, lprc->right, lprc->bottom);
2932 DeleteObject(SelectObject(hdc, holdpen));
2934 /* Draw the fake document */
2935 case WM_PSD_GREEKTEXTRECT:
2936 /* select a nice scalable font, because we want the text really small */
2937 SystemParametersInfoW(SPI_GETICONTITLELOGFONT, sizeof(lf), &lf, 0);
2938 lf.lfHeight = 6; /* value chosen based on visual effect */
2939 hfont = CreateFontIndirectW(&lf);
2940 holdfont = SelectObject(hdc, hfont);
2942 /* if text not loaded, then do so now */
2943 if (wszFakeDocumentText[0] == '\0')
2944 LoadStringW(COMDLG32_hInstance,
2946 wszFakeDocumentText,
2947 sizeof(wszFakeDocumentText)/sizeof(wszFakeDocumentText[0]));
2949 oldbkmode = SetBkMode(hdc, TRANSPARENT);
2950 DrawTextW(hdc, wszFakeDocumentText, -1, lprc, DT_TOP|DT_LEFT|DT_NOPREFIX|DT_WORDBREAK);
2951 SetBkMode(hdc, oldbkmode);
2953 DeleteObject(SelectObject(hdc, holdfont));
2956 /* Envelope stamp */
2957 case WM_PSD_ENVSTAMPRECT:
2958 /* Return address */
2959 case WM_PSD_YAFULLPAGERECT:
2960 FIXME("envelope/stamp is not implemented\n");
2963 FIXME("Unknown message %x\n",uMsg);
2969 /***********************************************************************
2971 * The main paint procedure for the PageSetupDlg function.
2972 * The Page Setup dialog box includes an image of a sample page that shows how
2973 * the user's selections affect the appearance of the printed output.
2974 * The image consists of a rectangle that represents the selected paper
2975 * or envelope type, with a dotted-line rectangle representing
2976 * the current margins, and partial (Greek text) characters
2977 * to show how text looks on the printed page.
2979 * The following messages in the order sends to user hook procedure:
2980 * WM_PSD_PAGESETUPDLG Draw the contents of the sample page
2981 * WM_PSD_FULLPAGERECT Inform about the bounding rectangle
2982 * WM_PSD_MINMARGINRECT Inform about the margin rectangle (min margin?)
2983 * WM_PSD_MARGINRECT Draw the margin rectangle
2984 * WM_PSD_GREEKTEXTRECT Draw the Greek text inside the margin rectangle
2985 * If any of first three messages returns TRUE, painting done.
2988 * hWnd [in] Handle to the Page Setup dialog box
2989 * uMsg [in] Received message
2992 * WM_PSD_ENVSTAMPRECT Draw in the envelope-stamp rectangle (for envelopes only)
2993 * WM_PSD_YAFULLPAGERECT Draw the return address portion (for envelopes and other paper sizes)
2996 * FALSE if all done correctly
3001 static LRESULT CALLBACK
3002 PRINTDLG_PagePaintProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3005 RECT rcClient, rcMargin;
3008 HBRUSH hbrush, holdbrush;
3009 PageSetupDataA *pda;
3010 int papersize=0, orientation=0; /* FIXME: set this values for user paint hook */
3011 double scalx, scaly;
3012 #define CALLPAINTHOOK(msg,lprc) PRINTDLG_DefaultPagePaintHook( hWnd, msg, (WPARAM)hdc, (LPARAM)lprc, pda)
3014 if (uMsg != WM_PAINT)
3015 return CallWindowProcA(lpfnStaticWndProc, hWnd, uMsg, wParam, lParam);
3017 /* Processing WM_PAINT message */
3018 pda = (PageSetupDataA*)GetPropA(hWnd, "__WINE_PAGESETUPDLGDATA");
3020 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3023 if (PRINTDLG_DefaultPagePaintHook(hWnd, WM_PSD_PAGESETUPDLG, MAKELONG(papersize, orientation), (LPARAM)pda->dlga, pda))
3026 hdc = BeginPaint(hWnd, &ps);
3027 GetClientRect(hWnd, &rcClient);
3029 scalx = rcClient.right / (double)pda->curdlg.ptPaperSize.x;
3030 scaly = rcClient.bottom / (double)pda->curdlg.ptPaperSize.y;
3031 rcMargin = rcClient;
3033 rcMargin.left += (LONG)pda->curdlg.rtMargin.left * scalx;
3034 rcMargin.top += (LONG)pda->curdlg.rtMargin.top * scalx;
3035 rcMargin.right -= (LONG)pda->curdlg.rtMargin.right * scaly;
3036 rcMargin.bottom -= (LONG)pda->curdlg.rtMargin.bottom * scaly;
3038 /* if the space is too small then we make sure to not draw anything */
3039 rcMargin.left = min(rcMargin.left, rcMargin.right);
3040 rcMargin.top = min(rcMargin.top, rcMargin.bottom);
3042 if (!CALLPAINTHOOK(WM_PSD_FULLPAGERECT, &rcClient) &&
3043 !CALLPAINTHOOK(WM_PSD_MINMARGINRECT, &rcMargin) )
3045 /* fill background */
3046 hbrush = GetSysColorBrush(COLOR_3DHIGHLIGHT);
3047 FillRect(hdc, &rcClient, hbrush);
3048 holdbrush = SelectObject(hdc, hbrush);
3050 hpen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW));
3051 holdpen = SelectObject(hdc, hpen);
3053 /* paint left edge */
3054 MoveToEx(hdc, rcClient.left, rcClient.top, NULL);
3055 LineTo(hdc, rcClient.left, rcClient.bottom-1);
3057 /* paint top edge */
3058 MoveToEx(hdc, rcClient.left, rcClient.top, NULL);
3059 LineTo(hdc, rcClient.right, rcClient.top);
3061 hpen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DDKSHADOW));
3062 DeleteObject(SelectObject(hdc, hpen));
3064 /* paint right edge */
3065 MoveToEx(hdc, rcClient.right-1, rcClient.top, NULL);
3066 LineTo(hdc, rcClient.right-1, rcClient.bottom);
3068 /* paint bottom edge */
3069 MoveToEx(hdc, rcClient.left, rcClient.bottom-1, NULL);
3070 LineTo(hdc, rcClient.right, rcClient.bottom-1);
3072 DeleteObject(SelectObject(hdc, holdpen));
3073 DeleteObject(SelectObject(hdc, holdbrush));
3075 CALLPAINTHOOK(WM_PSD_MARGINRECT, &rcMargin);
3077 /* give text a bit of a space from the frame */
3080 rcMargin.right -= 2;
3081 rcMargin.bottom -= 2;
3083 /* if the space is too small then we make sure to not draw anything */
3084 rcMargin.left = min(rcMargin.left, rcMargin.right);
3085 rcMargin.top = min(rcMargin.top, rcMargin.bottom);
3087 CALLPAINTHOOK(WM_PSD_GREEKTEXTRECT, &rcMargin);
3090 EndPaint(hWnd, &ps);
3092 #undef CALLPAINTHOOK
3095 /***********************************************************************
3096 * PRINTDLG_PageDlgProcA
3097 * Message handler for PageSetupDlgA
3099 static INT_PTR CALLBACK
3100 PRINTDLG_PageDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
3103 PageSetupDataA *pda;
3104 INT_PTR res = FALSE;
3107 if (uMsg == WM_INITDIALOG) { /*Init dialog*/
3108 pda = (PageSetupDataA*)lParam;
3109 pda->hDlg = hDlg; /* saving handle to main window to PageSetupDataA structure */
3110 memcpy(&pda->curdlg, pda->dlga, sizeof(pda->curdlg));
3112 hDrawWnd = GetDlgItem(hDlg, rct1);
3113 TRACE("set property to %p", pda);
3114 SetPropA(hDlg, "__WINE_PAGESETUPDLGDATA", pda);
3115 SetPropA(hDrawWnd, "__WINE_PAGESETUPDLGDATA", pda);
3116 GetWindowRect(hDrawWnd, &pda->rtDrawRect); /* Calculating rect in client coordinates where paper draws */
3117 ScreenToClient(hDlg, (LPPOINT)&pda->rtDrawRect);
3118 ScreenToClient(hDlg, (LPPOINT)(&pda->rtDrawRect.right));
3119 lpfnStaticWndProc = (WNDPROC)SetWindowLongPtrW(
3122 (ULONG_PTR)PRINTDLG_PagePaintProc);
3124 /* FIXME: Paint hook. Must it be at begin of initializtion or at end? */
3126 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3127 if (!pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,(LPARAM)pda->dlga))
3128 FIXME("Setup page hook failed?\n");
3131 /* if printer button disabled */
3132 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
3133 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
3134 /* if margin edit boxes disabled */
3135 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
3136 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
3137 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
3138 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
3139 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
3141 /* Set orientation radiobutton properly */
3142 dm = GlobalLock(pda->dlga->hDevMode);
3143 if (dm->u1.s1.dmOrientation == DMORIENT_LANDSCAPE)
3144 CheckRadioButton(hDlg, rad1, rad2, rad2);
3145 else /* this is default if papersize is not set */
3146 CheckRadioButton(hDlg, rad1, rad2, rad1);
3147 GlobalUnlock(pda->dlga->hDevMode);
3149 /* if orientation disabled */
3150 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
3151 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
3152 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
3154 /* We fill them out enabled or not */
3155 if (pda->dlga->Flags & PSD_MARGINS) {
3157 _c_size2strA(pda,pda->dlga->rtMargin.left,str);
3158 SetDlgItemTextA(hDlg,edt4,str);
3159 _c_size2strA(pda,pda->dlga->rtMargin.top,str);
3160 SetDlgItemTextA(hDlg,edt5,str);
3161 _c_size2strA(pda,pda->dlga->rtMargin.right,str);
3162 SetDlgItemTextA(hDlg,edt6,str);
3163 _c_size2strA(pda,pda->dlga->rtMargin.bottom,str);
3164 SetDlgItemTextA(hDlg,edt7,str);
3166 /* default is 1 inch */
3167 DWORD size = _c_inch2size(pda->dlga,1000);
3169 _c_size2strA(pda,size,str);
3170 SetDlgItemTextA(hDlg,edt4,str);
3171 SetDlgItemTextA(hDlg,edt5,str);
3172 SetDlgItemTextA(hDlg,edt6,str);
3173 SetDlgItemTextA(hDlg,edt7,str);
3174 pda->curdlg.rtMargin.left = size;
3175 pda->curdlg.rtMargin.top = size;
3176 pda->curdlg.rtMargin.right = size;
3177 pda->curdlg.rtMargin.bottom = size;
3179 /* if paper disabled */
3180 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
3181 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
3182 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
3184 /* filling combos: printer, paper, source. selecting current printer (from DEVMODEA) */
3185 PRINTDLG_PS_ChangePrinterA(hDlg, pda);
3186 dm = GlobalLock(pda->pdlg.hDevMode);
3188 dm->dmDefaultSource = 15; /*FIXME: Automatic select. Does it always 15 at start? */
3189 PRINTDLG_PaperSizeA(&(pda->pdlg), dm->u1.s1.dmPaperSize, &pda->curdlg.ptPaperSize);
3190 GlobalUnlock(pda->pdlg.hDevMode);
3191 pda->curdlg.ptPaperSize.x = _c_10mm2size(pda->dlga, pda->curdlg.ptPaperSize.x);
3192 pda->curdlg.ptPaperSize.y = _c_10mm2size(pda->dlga, pda->curdlg.ptPaperSize.y);
3193 if (IsDlgButtonChecked(hDlg, rad2) == BST_CHECKED) { /* Landscape orientation */
3194 DWORD tmp = pda->curdlg.ptPaperSize.y;
3195 pda->curdlg.ptPaperSize.y = pda->curdlg.ptPaperSize.x;
3196 pda->curdlg.ptPaperSize.x = tmp;
3199 WARN("GlobalLock(pda->pdlg.hDevMode) fail? hDevMode=%p", pda->pdlg.hDevMode);
3200 /* Drawing paper prev */
3201 PRINTDLG_PS_ChangePaperPrev(pda);
3204 pda = (PageSetupDataA*)GetPropA(hDlg,"__WINE_PAGESETUPDLGDATA");
3206 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3209 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3210 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3211 if (res) return res;
3216 return PRINTDLG_PS_WMCommandA(hDlg, wParam, lParam, pda);
3221 static INT_PTR CALLBACK
3222 PageDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
3224 static const WCHAR __WINE_PAGESETUPDLGDATA[] =
3225 { '_', '_', 'W', 'I', 'N', 'E', '_', 'P', 'A', 'G', 'E',
3226 'S', 'E', 'T', 'U', 'P', 'D', 'L', 'G', 'D', 'A', 'T', 'A', 0 };
3227 PageSetupDataW *pda;
3230 if (uMsg==WM_INITDIALOG) {
3232 pda = (PageSetupDataW*)lParam;
3233 SetPropW(hDlg, __WINE_PAGESETUPDLGDATA, pda);
3234 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3235 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,(LPARAM)pda->dlga);
3237 FIXME("Setup page hook failed?\n");
3242 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK) {
3243 FIXME("PagePaintHook not yet implemented!\n");
3245 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
3246 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
3247 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
3248 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
3249 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
3250 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
3251 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
3253 /* width larger as height -> landscape */
3254 if (pda->dlga->ptPaperSize.x > pda->dlga->ptPaperSize.y)
3255 CheckRadioButton(hDlg, rad1, rad2, rad2);
3256 else /* this is default if papersize is not set */
3257 CheckRadioButton(hDlg, rad1, rad2, rad1);
3258 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
3259 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
3260 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
3262 /* We fill them out enabled or not */
3263 if (pda->dlga->Flags & PSD_MARGINS) {
3265 _c_size2strW(pda,pda->dlga->rtMargin.left,str);
3266 SetDlgItemTextW(hDlg,edt4,str);
3267 _c_size2strW(pda,pda->dlga->rtMargin.top,str);
3268 SetDlgItemTextW(hDlg,edt5,str);
3269 _c_size2strW(pda,pda->dlga->rtMargin.right,str);
3270 SetDlgItemTextW(hDlg,edt6,str);
3271 _c_size2strW(pda,pda->dlga->rtMargin.bottom,str);
3272 SetDlgItemTextW(hDlg,edt7,str);
3274 /* default is 1 inch */
3275 DWORD size = _c_inch2size((LPPAGESETUPDLGA)pda->dlga,1000);
3277 _c_size2strW(pda,size,str);
3278 SetDlgItemTextW(hDlg,edt4,str);
3279 SetDlgItemTextW(hDlg,edt5,str);
3280 SetDlgItemTextW(hDlg,edt6,str);
3281 SetDlgItemTextW(hDlg,edt7,str);
3283 PRINTDLG_PS_ChangePrinterW(hDlg,pda);
3284 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
3285 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
3286 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
3291 pda = (PageSetupDataW*)GetPropW(hDlg, __WINE_PAGESETUPDLGDATA);
3293 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3296 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3297 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3298 if (res) return res;
3303 return PRINTDLG_PS_WMCommandW(hDlg, wParam, lParam, pda);
3308 /***********************************************************************
3309 * PageSetupDlgA (COMDLG32.@)
3311 * Displays the the PAGE SETUP dialog box, which enables the user to specify
3312 * specific properties of a printed page such as
3313 * size, source, orientation and the width of the page margins.
3316 * setupdlg [IO] PAGESETUPDLGA struct
3319 * TRUE if the user pressed the OK button
3320 * FALSE if the user cancelled the window or an error occurred
3323 * The values of hDevMode and hDevNames are filled on output and can be
3324 * changed in PAGESETUPDLG when they are passed in PageSetupDlg.
3328 BOOL WINAPI PageSetupDlgA(LPPAGESETUPDLGA setupdlg) {
3332 PageSetupDataA *pda;
3336 if(TRACE_ON(commdlg)) {
3337 char flagstr[1000] = "";
3338 struct pd_flags *pflag = psd_flags;
3339 for( ; pflag->name; pflag++) {
3340 if(setupdlg->Flags & pflag->flag) {
3341 strcat(flagstr, pflag->name);
3342 strcat(flagstr, "|");
3345 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3346 "hinst %p, flags %08lx (%s)\n",
3347 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
3348 setupdlg->hDevNames,
3349 setupdlg->hInstance, setupdlg->Flags, flagstr);
3351 /* Checking setupdlg structure */
3352 if (setupdlg == NULL) {
3353 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION);
3356 if(setupdlg->lStructSize != sizeof(PAGESETUPDLGA)) {
3357 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
3360 if ((setupdlg->Flags & PSD_ENABLEPAGEPAINTHOOK) &&
3361 (setupdlg->lpfnPagePaintHook == NULL)) {
3362 COMDLG32_SetCommDlgExtendedError(CDERR_NOHOOK);
3366 /* Initialize default printer struct. If no printer device info is specified
3367 retrieve the default printer data. */
3368 memset(&pdlg,0,sizeof(pdlg));
3369 pdlg.lStructSize = sizeof(pdlg);
3370 if (setupdlg->hDevMode && setupdlg->hDevNames) {
3371 pdlg.hDevMode = setupdlg->hDevMode;
3372 pdlg.hDevNames = setupdlg->hDevNames;
3374 pdlg.Flags = PD_RETURNDEFAULT;
3375 bRet = PrintDlgA(&pdlg);
3377 if (!(setupdlg->Flags & PSD_NOWARNING)) {
3379 LoadStringA(COMDLG32_hInstance, PD32_NO_DEFAULT_PRINTER, errstr, 255);
3380 MessageBoxA(setupdlg->hwndOwner, errstr, 0, MB_OK | MB_ICONERROR);
3386 /* short cut exit, just return default values */
3387 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
3390 dm = GlobalLock(pdlg.hDevMode);
3391 PRINTDLG_PaperSizeA(&pdlg, dm->u1.s1.dmPaperSize, &setupdlg->ptPaperSize);
3392 GlobalUnlock(pdlg.hDevMode);
3393 setupdlg->ptPaperSize.x=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.x);
3394 setupdlg->ptPaperSize.y=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.y);
3398 /* get dialog template */
3399 hDlgTmpl = PRINTDLG_GetPGSTemplateA(setupdlg);
3401 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3404 ptr = LockResource( hDlgTmpl );
3406 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3410 pda = HeapAlloc(GetProcessHeap(),0,sizeof(*pda));
3411 pda->dlga = setupdlg;
3412 memcpy(&pda->pdlg,&pdlg,sizeof(pdlg));
3414 bRet = (0<DialogBoxIndirectParamA(
3415 setupdlg->hInstance,
3417 setupdlg->hwndOwner,
3418 PRINTDLG_PageDlgProcA,
3422 HeapFree(GetProcessHeap(),0,pda);
3425 /***********************************************************************
3426 * PageSetupDlgW (COMDLG32.@)
3428 * See PageSetupDlgA.
3430 BOOL WINAPI PageSetupDlgW(LPPAGESETUPDLGW setupdlg) {
3434 PageSetupDataW *pdw;
3437 FIXME("Unicode implementation is not done yet\n");
3438 if(TRACE_ON(commdlg)) {
3439 char flagstr[1000] = "";
3440 struct pd_flags *pflag = psd_flags;
3441 for( ; pflag->name; pflag++) {
3442 if(setupdlg->Flags & pflag->flag) {
3443 strcat(flagstr, pflag->name);
3444 strcat(flagstr, "|");
3447 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3448 "hinst %p, flags %08lx (%s)\n",
3449 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
3450 setupdlg->hDevNames,
3451 setupdlg->hInstance, setupdlg->Flags, flagstr);
3454 /* Initialize default printer struct. If no printer device info is specified
3455 retrieve the default printer data. */
3456 memset(&pdlg,0,sizeof(pdlg));
3457 pdlg.lStructSize = sizeof(pdlg);
3458 if (setupdlg->hDevMode && setupdlg->hDevNames) {
3459 pdlg.hDevMode = setupdlg->hDevMode;
3460 pdlg.hDevNames = setupdlg->hDevNames;
3462 pdlg.Flags = PD_RETURNDEFAULT;
3463 bRet = PrintDlgW(&pdlg);
3465 if (!(setupdlg->Flags & PSD_NOWARNING)) {
3467 LoadStringW(COMDLG32_hInstance, PD32_NO_DEFAULT_PRINTER, errstr, 255);
3468 MessageBoxW(setupdlg->hwndOwner, errstr, 0, MB_OK | MB_ICONERROR);
3474 /* short cut exit, just return default values */
3475 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
3476 static const WCHAR a4[] = {'A','4',0};
3477 setupdlg->hDevMode = pdlg.hDevMode;
3478 setupdlg->hDevNames = pdlg.hDevNames;
3479 /* FIXME: Just return "A4" for now. */
3480 PRINTDLG_PaperSizeW(&pdlg,a4,&setupdlg->ptPaperSize);
3481 setupdlg->ptPaperSize.x=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.x);
3482 setupdlg->ptPaperSize.y=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.y);
3485 hDlgTmpl = PRINTDLG_GetPGSTemplateW(setupdlg);
3487 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3490 ptr = LockResource( hDlgTmpl );
3492 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3495 pdw = HeapAlloc(GetProcessHeap(),0,sizeof(*pdw));
3496 pdw->dlga = setupdlg;
3497 memcpy(&pdw->pdlg,&pdlg,sizeof(pdlg));
3499 bRet = (0<DialogBoxIndirectParamW(
3500 setupdlg->hInstance,
3502 setupdlg->hwndOwner,
3509 /***********************************************************************
3510 * PrintDlgExA (COMDLG32.@)
3517 HRESULT WINAPI PrintDlgExA(LPPRINTDLGEXA lpPrintDlgExA)
3523 /***********************************************************************
3524 * PrintDlgExW (COMDLG32.@)
3526 * Display the the PRINT dialog box, which enables the user to specify
3527 * specific properties of the print job. The property sheet can also have
3528 * additional application-specific and driver-specific property pages.
3531 * lppd [IO] ptr to PRINTDLGEX struct
3535 * Failure: One of the following COM error codes:
3536 * E_OUTOFMEMORY Insufficient memory.
3537 * E_INVALIDARG One or more arguments are invalid.
3538 * E_POINTER Invalid pointer.
3539 * E_HANDLE Invalid handle.
3540 * E_FAIL Unspecified error.
3545 HRESULT WINAPI PrintDlgExW(LPPRINTDLGEXW lpPrintDlgExW)