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 const 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, const char* DeviceDriverName,
189 const char* DeviceName, const 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, rad2) == BST_CHECKED) /* Selection */
328 lppd->Flags |= PD_SELECTION;
330 lppd->Flags &= ~PD_SELECTION;
332 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
333 static char file[] = "FILE:";
334 lppd->Flags |= PD_PRINTTOFILE;
335 pi->pPortName = file;
338 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
339 FIXME("Collate lppd not yet implemented as output\n");
342 /* set PD_Collate and nCopies */
343 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
344 /* The application doesn't support multiple copies or collate...
346 lppd->Flags &= ~PD_COLLATE;
348 /* if the printer driver supports it... store info there
349 * otherwise no collate & multiple copies !
351 if (lpdm->dmFields & DM_COLLATE)
353 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
354 if (lpdm->dmFields & DM_COPIES)
355 lpdm->dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
357 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
358 lppd->Flags |= PD_COLLATE;
360 lppd->Flags &= ~PD_COLLATE;
361 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
367 static BOOL PRINTDLG_UpdatePrintDlgW(HWND hDlg,
368 PRINT_PTRW* PrintStructures)
370 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
371 PDEVMODEW lpdm = PrintStructures->lpDevMode;
372 LPPRINTER_INFO_2W pi = PrintStructures->lpPrinterInfo;
376 FIXME("No lpdm ptr?\n");
381 if(!(lppd->Flags & PD_PRINTSETUP)) {
382 /* check whether nFromPage and nToPage are within range defined by
383 * nMinPage and nMaxPage
385 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
388 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
389 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
390 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
391 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
392 WCHAR resourcestr[256];
393 WCHAR resultstr[256];
394 LoadStringW(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
396 wsprintfW(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
397 LoadStringW(COMDLG32_hInstance, PD32_PRINT_TITLE,
399 MessageBoxW(hDlg, resultstr, resourcestr,
400 MB_OK | MB_ICONWARNING);
403 lppd->nFromPage = nFromPage;
404 lppd->nToPage = nToPage;
405 lppd->Flags |= PD_PAGENUMS;
408 lppd->Flags &= ~PD_PAGENUMS;
410 if (IsDlgButtonChecked(hDlg, rad2) == BST_CHECKED) /* Selection */
411 lppd->Flags |= PD_SELECTION;
413 lppd->Flags &= ~PD_SELECTION;
415 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
416 static WCHAR file[] = {'F','I','L','E',':',0};
417 lppd->Flags |= PD_PRINTTOFILE;
418 pi->pPortName = file;
421 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
422 FIXME("Collate lppd not yet implemented as output\n");
425 /* set PD_Collate and nCopies */
426 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
427 /* The application doesn't support multiple copies or collate...
429 lppd->Flags &= ~PD_COLLATE;
431 /* if the printer driver supports it... store info there
432 * otherwise no collate & multiple copies !
434 if (lpdm->dmFields & DM_COLLATE)
436 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
437 if (lpdm->dmFields & DM_COPIES)
438 lpdm->dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
440 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
441 lppd->Flags |= PD_COLLATE;
443 lppd->Flags &= ~PD_COLLATE;
444 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
450 static BOOL PRINTDLG_PaperSizeA(
451 PRINTDLGA *pdlga,const WORD PaperSize,LPPOINT size
455 LPSTR devname,portname;
459 POINT *points = NULL;
462 dn = GlobalLock(pdlga->hDevNames);
463 dm = GlobalLock(pdlga->hDevMode);
464 devname = ((char*)dn)+dn->wDeviceOffset;
465 portname = ((char*)dn)+dn->wOutputOffset;
468 NrOfEntries = DeviceCapabilitiesA(devname,portname,DC_PAPERNAMES,NULL,dm);
470 FIXME("No papernames found for %s/%s\n",devname,portname);
473 if (NrOfEntries == -1) {
474 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
478 Words = HeapAlloc(GetProcessHeap(),0,NrOfEntries*sizeof(WORD));
479 if (NrOfEntries != (ret=DeviceCapabilitiesA(devname,portname,DC_PAPERS,(LPSTR)Words,dm))) {
480 FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
483 for (i=0;i<NrOfEntries;i++)
484 if (Words[i] == PaperSize)
486 HeapFree(GetProcessHeap(),0,Words);
487 if (i == NrOfEntries) {
488 FIXME("Papersize %d not found in list?\n",PaperSize);
491 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
492 if (NrOfEntries!=(ret=DeviceCapabilitiesA(devname,portname,DC_PAPERSIZE,(LPSTR)points,dm))) {
493 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
496 /* this is _10ths_ of a millimeter */
501 GlobalUnlock(pdlga->hDevNames);
502 GlobalUnlock(pdlga->hDevMode);
503 HeapFree(GetProcessHeap(),0,Words);
504 HeapFree(GetProcessHeap(),0,points);
508 static BOOL PRINTDLG_PaperSizeW(
509 PRINTDLGW *pdlga,const WCHAR *PaperSize,LPPOINT size
513 LPWSTR devname,portname;
517 POINT *points = NULL;
520 dn = GlobalLock(pdlga->hDevNames);
521 dm = GlobalLock(pdlga->hDevMode);
522 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
523 portname = ((WCHAR*)dn)+dn->wOutputOffset;
526 NrOfEntries = DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,NULL,dm);
528 FIXME("No papernames found for %s/%s\n",debugstr_w(devname),debugstr_w(portname));
531 if (NrOfEntries == -1) {
532 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
536 Names = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*NrOfEntries*64);
537 if (NrOfEntries != (ret=DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,Names,dm))) {
538 FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
541 for (i=0;i<NrOfEntries;i++)
542 if (!lstrcmpW(PaperSize,Names+(64*i)))
544 HeapFree(GetProcessHeap(),0,Names);
545 if (i==NrOfEntries) {
546 FIXME("Papersize %s not found in list?\n",debugstr_w(PaperSize));
549 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
550 if (NrOfEntries!=(ret=DeviceCapabilitiesW(devname,portname,DC_PAPERSIZE,(LPWSTR)points,dm))) {
551 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
554 /* this is _10ths_ of a millimeter */
559 GlobalUnlock(pdlga->hDevNames);
560 GlobalUnlock(pdlga->hDevMode);
561 HeapFree(GetProcessHeap(),0,Names);
562 HeapFree(GetProcessHeap(),0,points);
567 /************************************************************************
568 * PRINTDLG_SetUpPaperComboBox
570 * Initialize either the papersize or inputslot combos of the Printer Setup
571 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
572 * We also try to re-select the old selection.
574 static BOOL PRINTDLG_SetUpPaperComboBoxA(HWND hDlg,
587 int fwCapability_Names;
588 int fwCapability_Words;
590 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName,PortName,nIDComboBox);
592 /* query the dialog box for the current selected value */
593 Sel = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
595 /* we enter here only if a different printer is selected after
596 * the Print Setup dialog is opened. The current settings are
597 * stored into the newly selected printer.
599 oldWord = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA,
602 if (nIDComboBox == cmb2)
603 dm->u1.s1.dmPaperSize = oldWord;
605 dm->dmDefaultSource = oldWord;
609 /* we enter here only when the Print setup dialog is initially
610 * opened. In this case the settings are restored from when
611 * the dialog was last closed.
614 if (nIDComboBox == cmb2)
615 oldWord = dm->u1.s1.dmPaperSize;
617 oldWord = dm->dmDefaultSource;
621 if (nIDComboBox == cmb2) {
623 fwCapability_Names = DC_PAPERNAMES;
624 fwCapability_Words = DC_PAPERS;
628 fwCapability_Names = DC_BINNAMES;
629 fwCapability_Words = DC_BINS;
632 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
633 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
635 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
636 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
637 fwCapability_Names, NULL, dm);
638 if (NrOfEntries == 0)
639 WARN("no Name Entries found!\n");
640 else if (NrOfEntries < 0)
643 if(DeviceCapabilitiesA(PrinterName, PortName, fwCapability_Words, NULL, dm)
645 ERR("Number of caps is different\n");
649 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(char)*NamesSize);
650 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
651 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
652 fwCapability_Names, Names, dm);
653 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
654 fwCapability_Words, (LPSTR)Words, dm);
656 /* reset any current content in the combobox */
657 SendDlgItemMessageA(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
659 /* store new content */
660 for (i = 0; i < NrOfEntries; i++) {
661 DWORD pos = SendDlgItemMessageA(hDlg, nIDComboBox, CB_ADDSTRING, 0,
662 (LPARAM)(&Names[i*NamesSize]) );
663 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
667 /* Look for old selection - can't do this is previous loop since
668 item order will change as more items are added */
670 for (i = 0; i < NrOfEntries; i++) {
671 if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
677 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
679 HeapFree(GetProcessHeap(),0,Words);
680 HeapFree(GetProcessHeap(),0,Names);
684 static BOOL PRINTDLG_SetUpPaperComboBoxW(HWND hDlg,
686 const WCHAR* PrinterName,
687 const WCHAR* PortName,
697 int fwCapability_Names;
698 int fwCapability_Words;
700 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName),debugstr_w(PortName),nIDComboBox);
702 /* query the dialog box for the current selected value */
703 Sel = SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
705 /* we enter here only if a different printer is selected after
706 * the Print Setup dialog is opened. The current settings are
707 * stored into the newly selected printer.
709 oldWord = SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETITEMDATA,
712 if (nIDComboBox == cmb2)
713 dm->u1.s1.dmPaperSize = oldWord;
715 dm->dmDefaultSource = oldWord;
719 /* we enter here only when the Print setup dialog is initially
720 * opened. In this case the settings are restored from when
721 * the dialog was last closed.
724 if (nIDComboBox == cmb2)
725 oldWord = dm->u1.s1.dmPaperSize;
727 oldWord = dm->dmDefaultSource;
731 if (nIDComboBox == cmb2) {
733 fwCapability_Names = DC_PAPERNAMES;
734 fwCapability_Words = DC_PAPERS;
738 fwCapability_Names = DC_BINNAMES;
739 fwCapability_Words = DC_BINS;
742 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
743 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
745 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
746 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
747 fwCapability_Names, NULL, dm);
748 if (NrOfEntries == 0)
749 WARN("no Name Entries found!\n");
750 else if (NrOfEntries < 0)
753 if(DeviceCapabilitiesW(PrinterName, PortName, fwCapability_Words, NULL, dm)
755 ERR("Number of caps is different\n");
759 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WCHAR)*NamesSize);
760 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
761 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
762 fwCapability_Names, Names, dm);
763 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
764 fwCapability_Words, (LPWSTR)Words, dm);
766 /* reset any current content in the combobox */
767 SendDlgItemMessageW(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
769 /* store new content */
770 for (i = 0; i < NrOfEntries; i++) {
771 DWORD pos = SendDlgItemMessageW(hDlg, nIDComboBox, CB_ADDSTRING, 0,
772 (LPARAM)(&Names[i*NamesSize]) );
773 SendDlgItemMessageW(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
777 /* Look for old selection - can't do this is previous loop since
778 item order will change as more items are added */
780 for (i = 0; i < NrOfEntries; i++) {
781 if(SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
787 SendDlgItemMessageW(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
789 HeapFree(GetProcessHeap(),0,Words);
790 HeapFree(GetProcessHeap(),0,Names);
795 /***********************************************************************
796 * PRINTDLG_UpdatePrinterInfoTexts [internal]
798 static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg, const PRINTER_INFO_2A *pi)
801 char ResourceString[256];
807 /* add all status messages */
808 for (i = 0; i < 25; i++) {
809 if (pi->Status & (1<<i)) {
810 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
811 ResourceString, 255);
812 strcat(StatusMsg,ResourceString);
816 /* FIXME: status==ready must only be appended if really so.
817 but how to detect? */
818 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
819 ResourceString, 255);
820 strcat(StatusMsg,ResourceString);
821 SetDlgItemTextA(hDlg, stc12, StatusMsg);
823 /* set all other printer info texts */
824 SetDlgItemTextA(hDlg, stc11, pi->pDriverName);
826 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
827 SetDlgItemTextA(hDlg, stc14, pi->pLocation);
829 SetDlgItemTextA(hDlg, stc14, pi->pPortName);
830 SetDlgItemTextA(hDlg, stc13, pi->pComment ? pi->pComment : "");
834 static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg, const PRINTER_INFO_2W *pi)
836 WCHAR StatusMsg[256];
837 WCHAR ResourceString[256];
838 static const WCHAR emptyW[] = {0};
844 /* add all status messages */
845 for (i = 0; i < 25; i++) {
846 if (pi->Status & (1<<i)) {
847 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
848 ResourceString, 255);
849 lstrcatW(StatusMsg,ResourceString);
853 /* FIXME: status==ready must only be appended if really so.
854 but how to detect? */
855 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
856 ResourceString, 255);
857 lstrcatW(StatusMsg,ResourceString);
858 SetDlgItemTextW(hDlg, stc12, StatusMsg);
860 /* set all other printer info texts */
861 SetDlgItemTextW(hDlg, stc11, pi->pDriverName);
862 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
863 SetDlgItemTextW(hDlg, stc14, pi->pLocation);
865 SetDlgItemTextW(hDlg, stc14, pi->pPortName);
866 SetDlgItemTextW(hDlg, stc13, pi->pComment ? pi->pComment : emptyW);
870 /*******************************************************************
872 * PRINTDLG_ChangePrinter
875 BOOL PRINTDLG_ChangePrinterA(HWND hDlg, char *name,
876 PRINT_PTRA *PrintStructures)
878 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
879 LPDEVMODEA lpdm = NULL;
884 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
885 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
886 if(!OpenPrinterA(name, &hprn, NULL)) {
887 ERR("Can't open printer %s\n", name);
890 GetPrinterA(hprn, 2, NULL, 0, &needed);
891 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,needed);
892 GetPrinterA(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
894 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
895 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,needed);
896 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
898 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures->lpPrinterInfo->pPrinterName);
903 PRINTDLG_UpdatePrinterInfoTextsA(hDlg, PrintStructures->lpPrinterInfo);
905 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
906 PrintStructures->lpDevMode = NULL;
908 dmSize = DocumentPropertiesA(0, 0, name, NULL, NULL, 0);
910 ERR("DocumentProperties fails on %s\n", debugstr_a(name));
913 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
914 dmSize = DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, NULL,
916 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
917 !lstrcmpA( (LPSTR) lpdm->dmDeviceName,
918 (LPSTR) PrintStructures->lpDevMode->dmDeviceName)) {
919 /* Supplied devicemode matches current printer so try to use it */
920 DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, lpdm,
921 DM_OUT_BUFFER | DM_IN_BUFFER);
924 GlobalUnlock(lppd->hDevMode);
926 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
928 if(!(lppd->Flags & PD_PRINTSETUP)) {
929 /* Print range (All/Range/Selection) */
930 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
931 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
932 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
933 if (lppd->Flags & PD_NOSELECTION)
934 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
936 if (lppd->Flags & PD_SELECTION)
937 CheckRadioButton(hDlg, rad1, rad3, rad2);
938 if (lppd->Flags & PD_NOPAGENUMS) {
939 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
940 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
941 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
942 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
943 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
945 if (lppd->Flags & PD_PAGENUMS)
946 CheckRadioButton(hDlg, rad1, rad3, rad3);
951 * FIXME: The ico3 is not displayed for some reason. I don't know why.
953 if (lppd->Flags & PD_COLLATE) {
954 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
955 (LPARAM)PrintStructures->hCollateIcon);
956 CheckDlgButton(hDlg, chx2, 1);
958 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
959 (LPARAM)PrintStructures->hNoCollateIcon);
960 CheckDlgButton(hDlg, chx2, 0);
963 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
964 /* if printer doesn't support it: no Collate */
965 if (!(lpdm->dmFields & DM_COLLATE)) {
966 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
967 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
974 if (lppd->hDevMode == 0)
975 copies = lppd->nCopies;
977 copies = lpdm->dmCopies;
978 if(copies == 0) copies = 1;
979 else if(copies < 0) copies = MAX_COPIES;
980 SetDlgItemInt(hDlg, edt3, copies, FALSE);
983 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
984 /* if printer doesn't support it: no nCopies */
985 if (!(lpdm->dmFields & DM_COPIES)) {
986 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
987 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
992 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
993 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
994 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
995 if (lppd->Flags & PD_HIDEPRINTTOFILE)
996 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
998 } else { /* PD_PRINTSETUP */
999 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
1001 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb2,
1002 PrintStructures->lpPrinterInfo->pPrinterName,
1003 PrintStructures->lpPrinterInfo->pPortName,
1005 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb3,
1006 PrintStructures->lpPrinterInfo->pPrinterName,
1007 PrintStructures->lpPrinterInfo->pPortName,
1009 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1010 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1011 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1012 PrintStructures->hLandscapeIcon));
1017 if ((lppd->Flags & PD_SHOWHELP)==0) {
1018 /* hide if PD_SHOWHELP not specified */
1019 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1024 static BOOL PRINTDLG_ChangePrinterW(HWND hDlg, WCHAR *name,
1025 PRINT_PTRW *PrintStructures)
1027 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1028 LPDEVMODEW lpdm = NULL;
1033 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
1034 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
1035 if(!OpenPrinterW(name, &hprn, NULL)) {
1036 ERR("Can't open printer %s\n", debugstr_w(name));
1039 GetPrinterW(hprn, 2, NULL, 0, &needed);
1040 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
1041 GetPrinterW(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
1043 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
1044 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
1045 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
1047 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures->lpPrinterInfo->pPrinterName));
1052 PRINTDLG_UpdatePrinterInfoTextsW(hDlg, PrintStructures->lpPrinterInfo);
1054 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
1055 PrintStructures->lpDevMode = NULL;
1057 dmSize = DocumentPropertiesW(0, 0, name, NULL, NULL, 0);
1059 ERR("DocumentProperties fails on %s\n", debugstr_w(name));
1062 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
1063 dmSize = DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, NULL,
1065 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
1066 !lstrcmpW(lpdm->dmDeviceName,
1067 PrintStructures->lpDevMode->dmDeviceName)) {
1068 /* Supplied devicemode matches current printer so try to use it */
1069 DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, lpdm,
1070 DM_OUT_BUFFER | DM_IN_BUFFER);
1073 GlobalUnlock(lppd->hDevMode);
1075 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
1077 if(!(lppd->Flags & PD_PRINTSETUP)) {
1078 /* Print range (All/Range/Selection) */
1079 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
1080 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
1081 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
1082 if (lppd->Flags & PD_NOSELECTION)
1083 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
1085 if (lppd->Flags & PD_SELECTION)
1086 CheckRadioButton(hDlg, rad1, rad3, rad2);
1087 if (lppd->Flags & PD_NOPAGENUMS) {
1088 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
1089 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
1090 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
1091 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
1092 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
1094 if (lppd->Flags & PD_PAGENUMS)
1095 CheckRadioButton(hDlg, rad1, rad3, rad3);
1100 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1102 if (lppd->Flags & PD_COLLATE) {
1103 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1104 (LPARAM)PrintStructures->hCollateIcon);
1105 CheckDlgButton(hDlg, chx2, 1);
1107 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1108 (LPARAM)PrintStructures->hNoCollateIcon);
1109 CheckDlgButton(hDlg, chx2, 0);
1112 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1113 /* if printer doesn't support it: no Collate */
1114 if (!(lpdm->dmFields & DM_COLLATE)) {
1115 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1116 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
1123 if (lppd->hDevMode == 0)
1124 copies = lppd->nCopies;
1126 copies = lpdm->dmCopies;
1127 if(copies == 0) copies = 1;
1128 else if(copies < 0) copies = MAX_COPIES;
1129 SetDlgItemInt(hDlg, edt3, copies, FALSE);
1132 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1133 /* if printer doesn't support it: no nCopies */
1134 if (!(lpdm->dmFields & DM_COPIES)) {
1135 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
1136 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
1141 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
1142 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
1143 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
1144 if (lppd->Flags & PD_HIDEPRINTTOFILE)
1145 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
1147 } else { /* PD_PRINTSETUP */
1148 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
1150 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb2,
1151 PrintStructures->lpPrinterInfo->pPrinterName,
1152 PrintStructures->lpPrinterInfo->pPortName,
1154 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb3,
1155 PrintStructures->lpPrinterInfo->pPrinterName,
1156 PrintStructures->lpPrinterInfo->pPortName,
1158 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1159 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1160 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1161 PrintStructures->hLandscapeIcon));
1166 if ((lppd->Flags & PD_SHOWHELP)==0) {
1167 /* hide if PD_SHOWHELP not specified */
1168 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1173 /***********************************************************************
1174 * check_printer_setup [internal]
1176 static LRESULT check_printer_setup(HWND hDlg)
1179 WCHAR resourcestr[256],resultstr[256];
1182 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
1185 EnumPrintersW(PRINTER_ENUM_CONNECTIONS, NULL, 2, NULL, 0, &needed, &num);
1191 LoadStringW(COMDLG32_hInstance, PD32_NO_DEVICES,resultstr, 255);
1192 LoadStringW(COMDLG32_hInstance, PD32_PRINT_TITLE,resourcestr, 255);
1193 res = MessageBoxW(hDlg, resultstr, resourcestr,MB_OK | MB_ICONWARNING);
1198 /***********************************************************************
1199 * PRINTDLG_WMInitDialog [internal]
1201 static LRESULT PRINTDLG_WMInitDialog(HWND hDlg, WPARAM wParam,
1202 PRINT_PTRA* PrintStructures)
1204 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
1208 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1210 /* load Collate ICONs */
1211 /* We load these with LoadImage because they are not a standard
1212 size and we don't want them rescaled */
1213 PrintStructures->hCollateIcon =
1214 LoadImageA(COMDLG32_hInstance, "PD32_COLLATE", IMAGE_ICON, 0, 0, 0);
1215 PrintStructures->hNoCollateIcon =
1216 LoadImageA(COMDLG32_hInstance, "PD32_NOCOLLATE", IMAGE_ICON, 0, 0, 0);
1218 /* These can be done with LoadIcon */
1219 PrintStructures->hPortraitIcon =
1220 LoadIconA(COMDLG32_hInstance, "PD32_PORTRAIT");
1221 PrintStructures->hLandscapeIcon =
1222 LoadIconA(COMDLG32_hInstance, "PD32_LANDSCAPE");
1224 /* display the collate/no_collate icon */
1225 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1226 (LPARAM)PrintStructures->hNoCollateIcon);
1228 if(PrintStructures->hCollateIcon == 0 ||
1229 PrintStructures->hNoCollateIcon == 0 ||
1230 PrintStructures->hPortraitIcon == 0 ||
1231 PrintStructures->hLandscapeIcon == 0) {
1232 ERR("no icon in resourcefile\n");
1233 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1234 EndDialog(hDlg, FALSE);
1238 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1239 * must be registered and the Help button must be shown.
1241 if (lppd->Flags & PD_SHOWHELP) {
1242 if((PrintStructures->HelpMessageID =
1243 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
1244 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1248 PrintStructures->HelpMessageID = 0;
1250 if(!(lppd->Flags &PD_PRINTSETUP)) {
1251 PrintStructures->hwndUpDown =
1252 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1253 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1254 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1255 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1256 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1259 /* FIXME: I allow more freedom than either Win95 or WinNT,
1260 * which do not agree to what errors should be thrown or not
1261 * in case nToPage or nFromPage is out-of-range.
1263 if (lppd->nMaxPage < lppd->nMinPage)
1264 lppd->nMaxPage = lppd->nMinPage;
1265 if (lppd->nMinPage == lppd->nMaxPage)
1266 lppd->Flags |= PD_NOPAGENUMS;
1267 if (lppd->nToPage < lppd->nMinPage)
1268 lppd->nToPage = lppd->nMinPage;
1269 if (lppd->nToPage > lppd->nMaxPage)
1270 lppd->nToPage = lppd->nMaxPage;
1271 if (lppd->nFromPage < lppd->nMinPage)
1272 lppd->nFromPage = lppd->nMinPage;
1273 if (lppd->nFromPage > lppd->nMaxPage)
1274 lppd->nFromPage = lppd->nMaxPage;
1276 /* if we have the combo box, fill it */
1277 if (GetDlgItem(hDlg,comboID)) {
1280 pdn = GlobalLock(lppd->hDevNames);
1281 pdm = GlobalLock(lppd->hDevMode);
1283 name = (char*)pdn + pdn->wDeviceOffset;
1285 name = (char*)pdm->dmDeviceName;
1286 PRINTDLG_SetUpPrinterListComboA(hDlg, comboID, name);
1287 if(pdm) GlobalUnlock(lppd->hDevMode);
1288 if(pdn) GlobalUnlock(lppd->hDevNames);
1290 /* Now find selected printer and update rest of dlg */
1291 name = HeapAlloc(GetProcessHeap(),0,256);
1292 if (GetDlgItemTextA(hDlg, comboID, name, 255))
1293 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1294 HeapFree(GetProcessHeap(),0,name);
1296 /* else use default printer */
1298 DWORD dwBufLen = sizeof(name);
1299 BOOL ret = GetDefaultPrinterA(name, &dwBufLen);
1302 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1304 FIXME("No default printer found, expect problems!\n");
1309 static LRESULT PRINTDLG_WMInitDialogW(HWND hDlg, WPARAM wParam,
1310 PRINT_PTRW* PrintStructures)
1312 static const WCHAR PD32_COLLATE[] = { 'P', 'D', '3', '2', '_', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
1313 static const WCHAR PD32_NOCOLLATE[] = { 'P', 'D', '3', '2', '_', 'N', 'O', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
1314 static const WCHAR PD32_PORTRAIT[] = { 'P', 'D', '3', '2', '_', 'P', 'O', 'R', 'T', 'R', 'A', 'I', 'T', 0 };
1315 static const WCHAR PD32_LANDSCAPE[] = { 'P', 'D', '3', '2', '_', 'L', 'A', 'N', 'D', 'S', 'C', 'A', 'P', 'E', 0 };
1316 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1320 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1322 /* load Collate ICONs */
1323 /* We load these with LoadImage because they are not a standard
1324 size and we don't want them rescaled */
1325 PrintStructures->hCollateIcon =
1326 LoadImageW(COMDLG32_hInstance, PD32_COLLATE, IMAGE_ICON, 0, 0, 0);
1327 PrintStructures->hNoCollateIcon =
1328 LoadImageW(COMDLG32_hInstance, PD32_NOCOLLATE, IMAGE_ICON, 0, 0, 0);
1330 /* These can be done with LoadIcon */
1331 PrintStructures->hPortraitIcon =
1332 LoadIconW(COMDLG32_hInstance, PD32_PORTRAIT);
1333 PrintStructures->hLandscapeIcon =
1334 LoadIconW(COMDLG32_hInstance, PD32_LANDSCAPE);
1336 /* display the collate/no_collate icon */
1337 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1338 (LPARAM)PrintStructures->hNoCollateIcon);
1340 if(PrintStructures->hCollateIcon == 0 ||
1341 PrintStructures->hNoCollateIcon == 0 ||
1342 PrintStructures->hPortraitIcon == 0 ||
1343 PrintStructures->hLandscapeIcon == 0) {
1344 ERR("no icon in resourcefile\n");
1345 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1346 EndDialog(hDlg, FALSE);
1350 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1351 * must be registered and the Help button must be shown.
1353 if (lppd->Flags & PD_SHOWHELP) {
1354 if((PrintStructures->HelpMessageID =
1355 RegisterWindowMessageW(HELPMSGSTRINGW)) == 0) {
1356 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1360 PrintStructures->HelpMessageID = 0;
1362 if(!(lppd->Flags &PD_PRINTSETUP)) {
1363 PrintStructures->hwndUpDown =
1364 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1365 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1366 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1367 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1368 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1371 /* FIXME: I allow more freedom than either Win95 or WinNT,
1372 * which do not agree to what errors should be thrown or not
1373 * in case nToPage or nFromPage is out-of-range.
1375 if (lppd->nMaxPage < lppd->nMinPage)
1376 lppd->nMaxPage = lppd->nMinPage;
1377 if (lppd->nMinPage == lppd->nMaxPage)
1378 lppd->Flags |= PD_NOPAGENUMS;
1379 if (lppd->nToPage < lppd->nMinPage)
1380 lppd->nToPage = lppd->nMinPage;
1381 if (lppd->nToPage > lppd->nMaxPage)
1382 lppd->nToPage = lppd->nMaxPage;
1383 if (lppd->nFromPage < lppd->nMinPage)
1384 lppd->nFromPage = lppd->nMinPage;
1385 if (lppd->nFromPage > lppd->nMaxPage)
1386 lppd->nFromPage = lppd->nMaxPage;
1388 /* if we have the combo box, fill it */
1389 if (GetDlgItem(hDlg,comboID)) {
1392 pdn = GlobalLock(lppd->hDevNames);
1393 pdm = GlobalLock(lppd->hDevMode);
1395 name = (WCHAR*)pdn + pdn->wDeviceOffset;
1397 name = pdm->dmDeviceName;
1398 PRINTDLG_SetUpPrinterListComboW(hDlg, comboID, name);
1399 if(pdm) GlobalUnlock(lppd->hDevMode);
1400 if(pdn) GlobalUnlock(lppd->hDevNames);
1402 /* Now find selected printer and update rest of dlg */
1403 /* ansi is ok here */
1404 name = HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR));
1405 if (GetDlgItemTextW(hDlg, comboID, name, 255))
1406 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1407 HeapFree(GetProcessHeap(),0,name);
1409 /* else use default printer */
1411 DWORD dwBufLen = sizeof(name) / sizeof(WCHAR);
1412 BOOL ret = GetDefaultPrinterW(name, &dwBufLen);
1415 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1417 FIXME("No default printer found, expect problems!\n");
1422 /***********************************************************************
1423 * PRINTDLG_WMCommand [internal]
1425 LRESULT PRINTDLG_WMCommandA(HWND hDlg, WPARAM wParam,
1426 LPARAM lParam, PRINT_PTRA* PrintStructures)
1428 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
1429 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1430 LPDEVMODEA lpdm = PrintStructures->lpDevMode;
1432 switch (LOWORD(wParam)) {
1434 TRACE(" OK button was hit\n");
1435 if (!PRINTDLG_UpdatePrintDlgA(hDlg, PrintStructures)) {
1436 FIXME("Update printdlg was not successful!\n");
1439 EndDialog(hDlg, TRUE);
1443 TRACE(" CANCEL button was hit\n");
1444 EndDialog(hDlg, FALSE);
1448 TRACE(" HELP button was hit\n");
1449 SendMessageA(lppd->hwndOwner, PrintStructures->HelpMessageID,
1450 (WPARAM) hDlg, (LPARAM) lppd);
1453 case chx2: /* collate pages checkbox */
1454 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1455 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1456 (LPARAM)PrintStructures->hCollateIcon);
1458 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1459 (LPARAM)PrintStructures->hNoCollateIcon);
1461 case edt1: /* from page nr editbox */
1462 case edt2: /* to page nr editbox */
1463 if (HIWORD(wParam)==EN_CHANGE) {
1466 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1467 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1468 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1469 CheckRadioButton(hDlg, rad1, rad3, rad3);
1474 if(HIWORD(wParam) == EN_CHANGE) {
1475 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1477 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1479 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1484 case psh1: /* Print Setup */
1488 if (!PrintStructures->dlg.lpPrintDlg16) {
1489 FIXME("The 32bit print dialog does not have this button!?\n");
1493 memcpy(&pdlg,PrintStructures->dlg.lpPrintDlg16,sizeof(pdlg));
1494 pdlg.Flags |= PD_PRINTSETUP;
1495 pdlg.hwndOwner = HWND_16(hDlg);
1496 if (!PrintDlg16(&pdlg))
1501 case psh2: /* Properties button */
1504 char PrinterName[256];
1506 GetDlgItemTextA(hDlg, PrinterComboID, PrinterName, 255);
1507 if (!OpenPrinterA(PrinterName, &hPrinter, NULL)) {
1508 FIXME(" Call to OpenPrinter did not succeed!\n");
1511 DocumentPropertiesA(hDlg, hPrinter, PrinterName,
1512 PrintStructures->lpDevMode,
1513 PrintStructures->lpDevMode,
1514 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1515 ClosePrinter(hPrinter);
1519 case rad1: /* Paperorientation */
1520 if (lppd->Flags & PD_PRINTSETUP)
1522 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1523 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1524 (LPARAM)(PrintStructures->hPortraitIcon));
1528 case rad2: /* Paperorientation */
1529 if (lppd->Flags & PD_PRINTSETUP)
1531 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1532 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1533 (LPARAM)(PrintStructures->hLandscapeIcon));
1537 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1538 if (PrinterComboID != LOWORD(wParam)) {
1539 FIXME("No handling for print quality combo box yet.\n");
1543 case cmb4: /* Printer combobox */
1544 if (HIWORD(wParam)==CBN_SELCHANGE) {
1545 char PrinterName[256];
1546 GetDlgItemTextA(hDlg, LOWORD(wParam), PrinterName, 255);
1547 PRINTDLG_ChangePrinterA(hDlg, PrinterName, PrintStructures);
1551 case cmb2: /* Papersize */
1553 DWORD Sel = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1555 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
1561 case cmb3: /* Bin */
1563 DWORD Sel = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1565 lpdm->dmDefaultSource = SendDlgItemMessageA(hDlg, cmb3,
1566 CB_GETITEMDATA, Sel,
1571 if(lppd->Flags & PD_PRINTSETUP) {
1572 switch (LOWORD(wParam)) {
1573 case rad1: /* orientation */
1575 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1576 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1577 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1578 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1580 (LPARAM)PrintStructures->hPortraitIcon);
1581 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1583 (LPARAM)PrintStructures->hPortraitIcon);
1586 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1587 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1588 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1590 (LPARAM)PrintStructures->hLandscapeIcon);
1591 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1593 (LPARAM)PrintStructures->hLandscapeIcon);
1602 static LRESULT PRINTDLG_WMCommandW(HWND hDlg, WPARAM wParam,
1603 LPARAM lParam, PRINT_PTRW* PrintStructures)
1605 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1606 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1607 LPDEVMODEW lpdm = PrintStructures->lpDevMode;
1609 switch (LOWORD(wParam)) {
1611 TRACE(" OK button was hit\n");
1612 if (!PRINTDLG_UpdatePrintDlgW(hDlg, PrintStructures)) {
1613 FIXME("Update printdlg was not successful!\n");
1616 EndDialog(hDlg, TRUE);
1620 TRACE(" CANCEL button was hit\n");
1621 EndDialog(hDlg, FALSE);
1625 TRACE(" HELP button was hit\n");
1626 SendMessageW(lppd->hwndOwner, PrintStructures->HelpMessageID,
1627 (WPARAM) hDlg, (LPARAM) lppd);
1630 case chx2: /* collate pages checkbox */
1631 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1632 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1633 (LPARAM)PrintStructures->hCollateIcon);
1635 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1636 (LPARAM)PrintStructures->hNoCollateIcon);
1638 case edt1: /* from page nr editbox */
1639 case edt2: /* to page nr editbox */
1640 if (HIWORD(wParam)==EN_CHANGE) {
1643 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1644 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1645 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1646 CheckRadioButton(hDlg, rad1, rad3, rad3);
1651 if(HIWORD(wParam) == EN_CHANGE) {
1652 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1654 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1656 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1660 case psh1: /* Print Setup */
1662 ERR("psh1 is called from 16bit code only, we should not get here.\n");
1665 case psh2: /* Properties button */
1668 WCHAR PrinterName[256];
1670 if (!GetDlgItemTextW(hDlg, PrinterComboID, PrinterName, 255)) break;
1671 if (!OpenPrinterW(PrinterName, &hPrinter, NULL)) {
1672 FIXME(" Call to OpenPrinter did not succeed!\n");
1675 DocumentPropertiesW(hDlg, hPrinter, PrinterName,
1676 PrintStructures->lpDevMode,
1677 PrintStructures->lpDevMode,
1678 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1679 ClosePrinter(hPrinter);
1683 case rad1: /* Paperorientation */
1684 if (lppd->Flags & PD_PRINTSETUP)
1686 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1687 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1688 (LPARAM)(PrintStructures->hPortraitIcon));
1692 case rad2: /* Paperorientation */
1693 if (lppd->Flags & PD_PRINTSETUP)
1695 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1696 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1697 (LPARAM)(PrintStructures->hLandscapeIcon));
1701 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1702 if (PrinterComboID != LOWORD(wParam)) {
1703 FIXME("No handling for print quality combo box yet.\n");
1707 case cmb4: /* Printer combobox */
1708 if (HIWORD(wParam)==CBN_SELCHANGE) {
1709 WCHAR PrinterName[256];
1710 GetDlgItemTextW(hDlg, LOWORD(wParam), PrinterName, 255);
1711 PRINTDLG_ChangePrinterW(hDlg, PrinterName, PrintStructures);
1715 case cmb2: /* Papersize */
1717 DWORD Sel = SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1719 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageW(hDlg, cmb2,
1725 case cmb3: /* Bin */
1727 DWORD Sel = SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1729 lpdm->dmDefaultSource = SendDlgItemMessageW(hDlg, cmb3,
1730 CB_GETITEMDATA, Sel,
1735 if(lppd->Flags & PD_PRINTSETUP) {
1736 switch (LOWORD(wParam)) {
1737 case rad1: /* orientation */
1739 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1740 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1741 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1742 SendDlgItemMessageW(hDlg, stc10, STM_SETIMAGE,
1744 (LPARAM)PrintStructures->hPortraitIcon);
1745 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE,
1747 (LPARAM)PrintStructures->hPortraitIcon);
1750 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1751 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1752 SendDlgItemMessageW(hDlg, stc10, STM_SETIMAGE,
1754 (LPARAM)PrintStructures->hLandscapeIcon);
1755 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE,
1757 (LPARAM)PrintStructures->hLandscapeIcon);
1766 /***********************************************************************
1767 * PrintDlgProcA [internal]
1769 static INT_PTR CALLBACK PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
1772 PRINT_PTRA* PrintStructures;
1773 INT_PTR res = FALSE;
1775 if (uMsg!=WM_INITDIALOG) {
1776 PrintStructures = (PRINT_PTRA*)GetPropA(hDlg,"__WINE_PRINTDLGDATA");
1777 if (!PrintStructures)
1780 PrintStructures = (PRINT_PTRA*) lParam;
1781 SetPropA(hDlg,"__WINE_PRINTDLGDATA",PrintStructures);
1782 if(!check_printer_setup(hDlg))
1784 EndDialog(hDlg,FALSE);
1787 res = PRINTDLG_WMInitDialog(hDlg, wParam, PrintStructures);
1789 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
1790 res = PrintStructures->lpPrintDlg->lpfnPrintHook(
1791 hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg
1796 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
1797 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam,
1804 return PRINTDLG_WMCommandA(hDlg, wParam, lParam, PrintStructures);
1807 DestroyIcon(PrintStructures->hCollateIcon);
1808 DestroyIcon(PrintStructures->hNoCollateIcon);
1809 DestroyIcon(PrintStructures->hPortraitIcon);
1810 DestroyIcon(PrintStructures->hLandscapeIcon);
1811 if(PrintStructures->hwndUpDown)
1812 DestroyWindow(PrintStructures->hwndUpDown);
1818 static INT_PTR CALLBACK PrintDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
1821 static const WCHAR propW[] = {'_','_','W','I','N','E','_','P','R','I','N','T','D','L','G','D','A','T','A',0};
1822 PRINT_PTRW* PrintStructures;
1823 INT_PTR res = FALSE;
1825 if (uMsg!=WM_INITDIALOG) {
1826 PrintStructures = (PRINT_PTRW*) GetPropW(hDlg, propW);
1827 if (!PrintStructures)
1830 PrintStructures = (PRINT_PTRW*) lParam;
1831 SetPropW(hDlg, propW, PrintStructures);
1832 if(!check_printer_setup(hDlg))
1834 EndDialog(hDlg,FALSE);
1837 res = PRINTDLG_WMInitDialogW(hDlg, wParam, PrintStructures);
1839 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
1840 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg);
1844 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
1845 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam, lParam);
1851 return PRINTDLG_WMCommandW(hDlg, wParam, lParam, PrintStructures);
1854 DestroyIcon(PrintStructures->hCollateIcon);
1855 DestroyIcon(PrintStructures->hNoCollateIcon);
1856 DestroyIcon(PrintStructures->hPortraitIcon);
1857 DestroyIcon(PrintStructures->hLandscapeIcon);
1858 if(PrintStructures->hwndUpDown)
1859 DestroyWindow(PrintStructures->hwndUpDown);
1865 /************************************************************
1867 * PRINTDLG_GetDlgTemplate
1870 static HGLOBAL PRINTDLG_GetDlgTemplateA(const PRINTDLGA *lppd)
1875 if (lppd->Flags & PD_PRINTSETUP) {
1876 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
1877 hDlgTmpl = lppd->hSetupTemplate;
1878 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
1879 hResInfo = FindResourceA(lppd->hInstance,
1880 lppd->lpSetupTemplateName, (LPSTR)RT_DIALOG);
1881 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1883 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32_SETUP",
1885 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1888 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
1889 hDlgTmpl = lppd->hPrintTemplate;
1890 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
1891 hResInfo = FindResourceA(lppd->hInstance,
1892 lppd->lpPrintTemplateName,
1894 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1896 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32",
1898 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1904 static HGLOBAL PRINTDLG_GetDlgTemplateW(const PRINTDLGW *lppd)
1908 static const WCHAR xpsetup[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
1909 static const WCHAR xprint[] = { 'P','R','I','N','T','3','2',0};
1911 if (lppd->Flags & PD_PRINTSETUP) {
1912 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
1913 hDlgTmpl = lppd->hSetupTemplate;
1914 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
1915 hResInfo = FindResourceW(lppd->hInstance,
1916 lppd->lpSetupTemplateName, (LPWSTR)RT_DIALOG);
1917 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1919 hResInfo = FindResourceW(COMDLG32_hInstance, xpsetup, (LPWSTR)RT_DIALOG);
1920 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1923 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
1924 hDlgTmpl = lppd->hPrintTemplate;
1925 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
1926 hResInfo = FindResourceW(lppd->hInstance,
1927 lppd->lpPrintTemplateName,
1929 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1931 hResInfo = FindResourceW(COMDLG32_hInstance, xprint, (LPWSTR)RT_DIALOG);
1932 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1938 /***********************************************************************
1943 static BOOL PRINTDLG_CreateDCA(LPPRINTDLGA lppd)
1945 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
1946 DEVMODEA *pdm = GlobalLock(lppd->hDevMode);
1948 if(lppd->Flags & PD_RETURNDC) {
1949 lppd->hDC = CreateDCA((char*)pdn + pdn->wDriverOffset,
1950 (char*)pdn + pdn->wDeviceOffset,
1951 (char*)pdn + pdn->wOutputOffset,
1953 } else if(lppd->Flags & PD_RETURNIC) {
1954 lppd->hDC = CreateICA((char*)pdn + pdn->wDriverOffset,
1955 (char*)pdn + pdn->wDeviceOffset,
1956 (char*)pdn + pdn->wOutputOffset,
1959 GlobalUnlock(lppd->hDevNames);
1960 GlobalUnlock(lppd->hDevMode);
1961 return lppd->hDC ? TRUE : FALSE;
1964 static BOOL PRINTDLG_CreateDCW(LPPRINTDLGW lppd)
1966 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
1967 DEVMODEW *pdm = GlobalLock(lppd->hDevMode);
1969 if(lppd->Flags & PD_RETURNDC) {
1970 lppd->hDC = CreateDCW((WCHAR*)pdn + pdn->wDriverOffset,
1971 (WCHAR*)pdn + pdn->wDeviceOffset,
1972 (WCHAR*)pdn + pdn->wOutputOffset,
1974 } else if(lppd->Flags & PD_RETURNIC) {
1975 lppd->hDC = CreateICW((WCHAR*)pdn + pdn->wDriverOffset,
1976 (WCHAR*)pdn + pdn->wDeviceOffset,
1977 (WCHAR*)pdn + pdn->wOutputOffset,
1980 GlobalUnlock(lppd->hDevNames);
1981 GlobalUnlock(lppd->hDevMode);
1982 return lppd->hDC ? TRUE : FALSE;
1985 /***********************************************************************
1986 * PrintDlgA (COMDLG32.@)
1988 * Displays the the PRINT dialog box, which enables the user to specify
1989 * specific properties of the print job.
1992 * lppd [IO] ptr to PRINTDLG32 struct
1995 * nonzero if the user pressed the OK button
1996 * zero if the user cancelled the window or an error occurred
2000 * * The Collate Icons do not display, even though they are in the code.
2001 * * The Properties Button(s) should call DocumentPropertiesA().
2004 BOOL WINAPI PrintDlgA(LPPRINTDLGA lppd)
2012 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION);
2016 hInst = (HINSTANCE)GetWindowLongPtrA( lppd->hwndOwner, GWLP_HINSTANCE );
2017 if(TRACE_ON(commdlg)) {
2018 char flagstr[1000] = "";
2019 const struct pd_flags *pflag = pd_flags;
2020 for( ; pflag->name; pflag++) {
2021 if(lppd->Flags & pflag->flag)
2022 strcat(flagstr, pflag->name);
2024 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2025 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2026 "flags %08x (%s)\n",
2027 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2028 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2029 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2032 if(lppd->lStructSize != sizeof(PRINTDLGA)) {
2033 WARN("structure size failure !!!\n");
2034 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2038 if(lppd->Flags & PD_RETURNDEFAULT) {
2039 PRINTER_INFO_2A *pbuf;
2040 DRIVER_INFO_3A *dbuf;
2044 if(lppd->hDevMode || lppd->hDevNames) {
2045 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2046 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2049 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2050 WARN("Can't find default printer\n");
2051 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2055 GetPrinterA(hprn, 2, NULL, 0, &needed);
2056 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
2057 GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2059 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
2060 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
2061 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2062 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",GetLastError(),pbuf->pPrinterName);
2063 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2068 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2072 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2073 pbuf->pDevMode->dmDriverExtra);
2074 ptr = GlobalLock(lppd->hDevMode);
2075 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2076 pbuf->pDevMode->dmDriverExtra);
2077 GlobalUnlock(lppd->hDevMode);
2078 HeapFree(GetProcessHeap(), 0, pbuf);
2079 HeapFree(GetProcessHeap(), 0, dbuf);
2083 PRINT_PTRA *PrintStructures;
2085 /* load Dialog resources,
2086 * depending on Flags indicates Print32 or Print32_setup dialog
2088 hDlgTmpl = PRINTDLG_GetDlgTemplateA(lppd);
2090 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2093 ptr = LockResource( hDlgTmpl );
2095 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2099 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2100 sizeof(PRINT_PTRA));
2101 PrintStructures->lpPrintDlg = lppd;
2103 /* and create & process the dialog .
2104 * -1 is failure, 0 is broken hwnd, everything else is ok.
2106 bRet = (0<DialogBoxIndirectParamA(hInst, ptr, lppd->hwndOwner,
2108 (LPARAM)PrintStructures));
2111 DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2112 PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
2113 DRIVER_INFO_3A *di = PrintStructures->lpDriverInfo;
2115 if (lppd->hDevMode == 0) {
2116 TRACE(" No hDevMode yet... Need to create my own\n");
2117 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2118 lpdm->dmSize + lpdm->dmDriverExtra);
2120 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2121 lpdm->dmSize + lpdm->dmDriverExtra,
2124 lpdmReturn = GlobalLock(lppd->hDevMode);
2125 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2127 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2132 GlobalUnlock(lppd->hDevMode);
2134 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2135 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2136 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2137 HeapFree(GetProcessHeap(), 0, PrintStructures);
2139 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2140 bRet = PRINTDLG_CreateDCA(lppd);
2142 TRACE("exit! (%d)\n", bRet);
2146 /***********************************************************************
2147 * PrintDlgW (COMDLG32.@)
2151 BOOL WINAPI PrintDlgW(LPPRINTDLGW lppd)
2159 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION);
2163 hInst = (HINSTANCE)GetWindowLongPtrW( lppd->hwndOwner, GWLP_HINSTANCE );
2164 if(TRACE_ON(commdlg)) {
2165 char flagstr[1000] = "";
2166 const struct pd_flags *pflag = pd_flags;
2167 for( ; pflag->name; pflag++) {
2168 if(lppd->Flags & pflag->flag)
2169 strcat(flagstr, pflag->name);
2171 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2172 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2173 "flags %08x (%s)\n",
2174 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2175 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2176 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2179 if(lppd->lStructSize != sizeof(PRINTDLGW)) {
2180 WARN("structure size failure !!!\n");
2181 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2185 if(lppd->Flags & PD_RETURNDEFAULT) {
2186 PRINTER_INFO_2W *pbuf;
2187 DRIVER_INFO_3W *dbuf;
2191 if(lppd->hDevMode || lppd->hDevNames) {
2192 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2193 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2196 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2197 WARN("Can't find default printer\n");
2198 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2202 GetPrinterW(hprn, 2, NULL, 0, &needed);
2203 pbuf = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*needed);
2204 GetPrinterW(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2206 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
2207 dbuf = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
2208 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2209 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",GetLastError(),debugstr_w(pbuf->pPrinterName));
2210 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2215 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2219 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2220 pbuf->pDevMode->dmDriverExtra);
2221 ptr = GlobalLock(lppd->hDevMode);
2222 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2223 pbuf->pDevMode->dmDriverExtra);
2224 GlobalUnlock(lppd->hDevMode);
2225 HeapFree(GetProcessHeap(), 0, pbuf);
2226 HeapFree(GetProcessHeap(), 0, dbuf);
2230 PRINT_PTRW *PrintStructures;
2232 /* load Dialog resources,
2233 * depending on Flags indicates Print32 or Print32_setup dialog
2235 hDlgTmpl = PRINTDLG_GetDlgTemplateW(lppd);
2237 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2240 ptr = LockResource( hDlgTmpl );
2242 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2246 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2247 sizeof(PRINT_PTRW));
2248 PrintStructures->lpPrintDlg = lppd;
2250 /* and create & process the dialog .
2251 * -1 is failure, 0 is broken hwnd, everything else is ok.
2253 bRet = (0<DialogBoxIndirectParamW(hInst, ptr, lppd->hwndOwner,
2255 (LPARAM)PrintStructures));
2258 DEVMODEW *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2259 PRINTER_INFO_2W *pi = PrintStructures->lpPrinterInfo;
2260 DRIVER_INFO_3W *di = PrintStructures->lpDriverInfo;
2262 if (lppd->hDevMode == 0) {
2263 TRACE(" No hDevMode yet... Need to create my own\n");
2264 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2265 lpdm->dmSize + lpdm->dmDriverExtra);
2268 if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
2269 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2271 GlobalUnlock(lppd->hDevMode);
2272 TRACE("Now got %d locks\n", locks);
2275 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2276 lpdm->dmSize + lpdm->dmDriverExtra,
2279 lpdmReturn = GlobalLock(lppd->hDevMode);
2280 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2282 if (lppd->hDevNames != 0) {
2284 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
2285 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2287 GlobalUnlock(lppd->hDevNames);
2290 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2295 GlobalUnlock(lppd->hDevMode);
2297 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2298 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2299 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2300 HeapFree(GetProcessHeap(), 0, PrintStructures);
2302 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2303 bRet = PRINTDLG_CreateDCW(lppd);
2305 TRACE("exit! (%d)\n", bRet);
2309 /***********************************************************************
2314 * cmb1 - printer select (not in standard dialog template)
2316 * cmb3 - source (tray?)
2317 * edt4 - border left
2319 * edt6 - border right
2320 * edt7 - border bottom
2321 * psh3 - "Printer..."
2325 LPPAGESETUPDLGA dlga; /* Handler to user defined struct */
2327 HWND hDlg; /* Page Setup dialog handler */
2328 PAGESETUPDLGA curdlg; /* Stores the current dialog state */
2329 RECT rtDrawRect; /* Drawing rect for page */
2333 LPPAGESETUPDLGW dlga;
2338 static HGLOBAL PRINTDLG_GetPGSTemplateA(const PAGESETUPDLGA *lppd)
2343 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2344 hDlgTmpl = lppd->hPageSetupTemplate;
2345 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2346 hResInfo = FindResourceA(lppd->hInstance,
2347 lppd->lpPageSetupTemplateName, (LPSTR)RT_DIALOG);
2348 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2350 hResInfo = FindResourceA(COMDLG32_hInstance,(LPCSTR)PAGESETUPDLGORD,(LPSTR)RT_DIALOG);
2351 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2356 static HGLOBAL PRINTDLG_GetPGSTemplateW(const PAGESETUPDLGW *lppd)
2361 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2362 hDlgTmpl = lppd->hPageSetupTemplate;
2363 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2364 hResInfo = FindResourceW(lppd->hInstance,
2365 lppd->lpPageSetupTemplateName, (LPWSTR)RT_DIALOG);
2366 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2368 hResInfo = FindResourceW(COMDLG32_hInstance,(LPCWSTR)PAGESETUPDLGORD,(LPWSTR)RT_DIALOG);
2369 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2375 _c_10mm2size(PAGESETUPDLGA *dlga,DWORD size) {
2376 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2377 return 10*size*100/254;
2378 /* If we don't have a flag, we can choose one. Use millimeters
2379 * to avoid confusing me
2381 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2387 _c_inch2size(PAGESETUPDLGA *dlga,DWORD size) {
2388 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2390 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
2391 return (size*254)/100;
2392 /* if we don't have a flag, we can choose one. Use millimeters
2393 * to avoid confusing me
2395 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2396 return (size*254)/100;
2400 _c_size2strA(PageSetupDataA *pda,DWORD size,LPSTR strout) {
2401 strcpy(strout,"<undef>");
2402 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2403 sprintf(strout,"%d",(size)/100);
2406 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2407 sprintf(strout,"%din",(size)/1000);
2410 pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2411 sprintf(strout,"%d",(size)/100);
2415 _c_size2strW(PageSetupDataW *pda,DWORD size,LPWSTR strout) {
2416 static const char mm_fmt[] = "%.2f mm";
2417 static const char in_fmt[] = "%.2f in";
2419 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2420 sprintf(buf, mm_fmt, (size * 1.0) / 100.0);
2421 } else if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2422 sprintf(buf, in_fmt, (size * 1.0) / 1000.0);
2424 pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2425 sprintf(buf, mm_fmt, (size * 1.0) / 100.0);
2428 MultiByteToWideChar(CP_ACP, 0, buf, -1, strout, 20);
2432 _c_str2sizeA(const PAGESETUPDLGA *dlga, LPCSTR strin) {
2437 if (!sscanf(strin,"%f%s",&val,rest))
2440 if (!strcmp(rest,"in") || !strcmp(rest,"inch")) {
2441 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2444 return val*25.4*100;
2446 if (!strcmp(rest,"cm")) { rest[0]='m'; val = val*10.0; }
2447 if (!strcmp(rest,"m")) { strcpy(rest,"mm"); val = val*1000.0; }
2449 if (!strcmp(rest,"mm")) {
2450 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
2453 return 1000.0*val/25.4;
2455 if (rest[0]=='\0') {
2456 /* use application supplied default */
2457 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2461 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2466 ERR("Did not find a conversion for type '%s'!\n",rest);
2472 _c_str2sizeW(const PAGESETUPDLGW *dlga, LPCWSTR strin) {
2475 /* this W -> A transition is OK */
2476 /* we need a unicode version of sscanf to avoid it */
2477 WideCharToMultiByte(CP_ACP, 0, strin, -1, buf, sizeof(buf), NULL, NULL);
2478 return _c_str2sizeA((const PAGESETUPDLGA *)dlga, buf);
2482 /****************************************************************************
2483 * PRINTDLG_PS_UpdateDlgStructA
2485 * Updates pda->dlga structure
2486 * Function calls when user presses OK button
2489 * hDlg [in] main window dialog HANDLE
2490 * pda [in/out] ptr to PageSetupDataA structure
2496 PRINTDLG_PS_UpdateDlgStructA(HWND hDlg, PageSetupDataA *pda) {
2501 memcpy(pda->dlga, &pda->curdlg, sizeof(pda->curdlg));
2502 pda->dlga->hDevMode = pda->pdlg.hDevMode;
2503 pda->dlga->hDevNames = pda->pdlg.hDevNames;
2505 dn = GlobalLock(pda->pdlg.hDevNames);
2506 dm = GlobalLock(pda->pdlg.hDevMode);
2508 /* Save paper orientation into device context */
2509 if(pda->curdlg.ptPaperSize.x > pda->curdlg.ptPaperSize.y)
2510 dm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
2512 dm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
2514 /* Save paper size into the device context */
2515 paperword = SendDlgItemMessageA(hDlg,cmb2,CB_GETITEMDATA,
2516 SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0), 0);
2517 if (paperword != CB_ERR)
2518 dm->u1.s1.dmPaperSize = paperword;
2520 FIXME("could not get dialog text for papersize cmbbox?\n");
2522 /* Save paper source into the device context */
2523 paperword = SendDlgItemMessageA(hDlg,cmb1,CB_GETITEMDATA,
2524 SendDlgItemMessageA(hDlg, cmb1, CB_GETCURSEL, 0, 0), 0);
2525 if (paperword != CB_ERR)
2526 dm->dmDefaultSource = paperword;
2528 FIXME("could not get dialog text for papersize cmbbox?\n");
2530 GlobalUnlock(pda->pdlg.hDevNames);
2531 GlobalUnlock(pda->pdlg.hDevMode);
2537 PRINTDLG_PS_UpdateDlgStructW(HWND hDlg, PageSetupDataW *pda) {
2540 LPWSTR devname,portname;
2541 WCHAR papername[64];
2544 dn = GlobalLock(pda->pdlg.hDevNames);
2545 dm = GlobalLock(pda->pdlg.hDevMode);
2546 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
2547 portname = ((WCHAR*)dn)+dn->wOutputOffset;
2549 /* Save paper size into device context */
2550 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
2551 /* Save paper source into device context */
2552 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
2554 if (GetDlgItemTextW(hDlg,cmb2,papername,sizeof(papername))>0) {
2555 PRINTDLG_PaperSizeW(&(pda->pdlg),papername,&(pda->dlga->ptPaperSize));
2556 pda->dlga->ptPaperSize.x = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga,pda->dlga->ptPaperSize.x);
2557 pda->dlga->ptPaperSize.y = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga,pda->dlga->ptPaperSize.y);
2559 FIXME("could not get dialog text for papersize cmbbox?\n");
2560 #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); }
2561 GETVAL(edt4,pda->dlga->rtMargin.left);
2562 GETVAL(edt5,pda->dlga->rtMargin.top);
2563 GETVAL(edt6,pda->dlga->rtMargin.right);
2564 GETVAL(edt7,pda->dlga->rtMargin.bottom);
2567 /* If we are in landscape, swap x and y of page size */
2568 if (IsDlgButtonChecked(hDlg, rad2)) {
2570 tmp = pda->dlga->ptPaperSize.x;
2571 pda->dlga->ptPaperSize.x = pda->dlga->ptPaperSize.y;
2572 pda->dlga->ptPaperSize.y = tmp;
2575 /* Save orientation */
2576 if (pda->dlga->ptPaperSize.x > pda->dlga->ptPaperSize.y)
2577 dm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
2579 dm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
2581 GlobalUnlock(pda->pdlg.hDevNames);
2582 GlobalUnlock(pda->pdlg.hDevMode);
2586 /**********************************************************************************************
2587 * PRINTDLG_PS_ChangeActivePrinerA
2589 * Redefines hDevMode and hDevNames HANDLES and initialises it.
2592 * name [in] Name of a printer for activation
2593 * pda [in/out] ptr to PageSetupDataA structure
2600 PRINTDLG_PS_ChangeActivePrinterA(LPSTR name, PageSetupDataA *pda){
2603 LPPRINTER_INFO_2A lpPrinterInfo;
2604 LPDRIVER_INFO_3A lpDriverInfo;
2605 DEVMODEA *pDevMode, *dm;
2607 if(!OpenPrinterA(name, &hprn, NULL)){
2608 ERR("Can't open printer %s\n", name);
2611 GetPrinterA(hprn, 2, NULL, 0, &needed);
2612 lpPrinterInfo = HeapAlloc(GetProcessHeap(), 0, needed);
2613 GetPrinterA(hprn, 2, (LPBYTE)lpPrinterInfo, needed, &needed);
2614 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
2615 lpDriverInfo = HeapAlloc(GetProcessHeap(), 0, needed);
2616 if(!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)lpDriverInfo, needed, &needed)) {
2617 ERR("GetPrinterDriverA failed for %s, fix your config!\n", lpPrinterInfo->pPrinterName);
2622 needed = DocumentPropertiesA(0, 0, name, NULL, NULL, 0);
2624 ERR("DocumentProperties fails on %s\n", debugstr_a(name));
2627 pDevMode = HeapAlloc(GetProcessHeap(), 0, needed);
2628 DocumentPropertiesA(0, 0, name, pDevMode, NULL, DM_OUT_BUFFER);
2630 pda->pdlg.hDevMode = GlobalReAlloc(pda->pdlg.hDevMode,
2631 pDevMode->dmSize + pDevMode->dmDriverExtra,
2633 dm = GlobalLock(pda->pdlg.hDevMode);
2634 memcpy(dm, pDevMode, pDevMode->dmSize + pDevMode->dmDriverExtra);
2636 PRINTDLG_CreateDevNames(&(pda->pdlg.hDevNames),
2637 lpDriverInfo->pDriverPath,
2638 lpPrinterInfo->pPrinterName,
2639 lpPrinterInfo->pPortName);
2641 GlobalUnlock(pda->pdlg.hDevMode);
2642 HeapFree(GetProcessHeap(), 0, pDevMode);
2643 HeapFree(GetProcessHeap(), 0, lpPrinterInfo);
2644 HeapFree(GetProcessHeap(), 0, lpDriverInfo);
2648 /****************************************************************************************
2649 * PRINTDLG_PS_ChangePrinterA
2651 * Fills Printers, Paper and Source combo
2657 PRINTDLG_PS_ChangePrinterA(HWND hDlg, PageSetupDataA *pda) {
2660 LPSTR devname,portname;
2662 dn = GlobalLock(pda->pdlg.hDevNames);
2663 dm = GlobalLock(pda->pdlg.hDevMode);
2664 devname = ((char*)dn)+dn->wDeviceOffset;
2665 portname = ((char*)dn)+dn->wOutputOffset;
2666 PRINTDLG_SetUpPrinterListComboA(hDlg, cmb1, devname);
2667 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb2,devname,portname,dm);
2668 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb3,devname,portname,dm);
2669 GlobalUnlock(pda->pdlg.hDevNames);
2670 GlobalUnlock(pda->pdlg.hDevMode);
2675 PRINTDLG_PS_ChangePrinterW(HWND hDlg, PageSetupDataW *pda) {
2678 LPWSTR devname,portname;
2680 dn = GlobalLock(pda->pdlg.hDevNames);
2681 dm = GlobalLock(pda->pdlg.hDevMode);
2682 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
2683 portname = ((WCHAR*)dn)+dn->wOutputOffset;
2684 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
2685 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
2686 GlobalUnlock(pda->pdlg.hDevNames);
2687 GlobalUnlock(pda->pdlg.hDevMode);
2691 /******************************************************************************************
2692 * PRINTDLG_PS_ChangePaperPrev
2694 * Changes paper preview size / position
2697 * pda [i] Pointer for current PageSetupDataA structure
2703 PRINTDLG_PS_ChangePaperPrev(const PageSetupDataA *pda)
2705 LONG width, height, x, y;
2708 if(pda->curdlg.ptPaperSize.x > pda->curdlg.ptPaperSize.y) {
2709 width = pda->rtDrawRect.right - pda->rtDrawRect.left;
2710 height = pda->curdlg.ptPaperSize.y * width / pda->curdlg.ptPaperSize.x;
2712 height = pda->rtDrawRect.bottom - pda->rtDrawRect.top;
2713 width = pda->curdlg.ptPaperSize.x * height / pda->curdlg.ptPaperSize.y;
2715 x = (pda->rtDrawRect.right + pda->rtDrawRect.left - width) / 2;
2716 y = (pda->rtDrawRect.bottom + pda->rtDrawRect.top - height) / 2;
2717 TRACE("rtDrawRect(%d, %d, %d, %d) x=%d, y=%d, w=%d, h=%d\n",
2718 pda->rtDrawRect.left, pda->rtDrawRect.top, pda->rtDrawRect.right, pda->rtDrawRect.bottom,
2719 x, y, width, height);
2722 MoveWindow(GetDlgItem(pda->hDlg, rct2), x+width, y+SHADOW, SHADOW, height, FALSE);
2723 MoveWindow(GetDlgItem(pda->hDlg, rct3), x+SHADOW, y+height, width, SHADOW, FALSE);
2724 MoveWindow(GetDlgItem(pda->hDlg, rct1), x, y, width, height, FALSE);
2725 memcpy(&rtTmp, &pda->rtDrawRect, sizeof(RECT));
2726 rtTmp.right += SHADOW;
2727 rtTmp.bottom += SHADOW;
2730 InvalidateRect(pda->hDlg, &rtTmp, TRUE);
2734 #define GETVAL(idc,val) \
2735 if(msg == EN_CHANGE){ \
2736 if (GetDlgItemTextA(hDlg,idc,buf,sizeof(buf)) > 0)\
2737 val = _c_str2sizeA(pda->dlga,buf); \
2739 FIXME("could not get dlgitemtexta for %x\n",id); \
2742 /********************************************************************************
2743 * PRINTDLG_PS_WMCommandA
2744 * process WM_COMMAND message for PageSetupDlgA
2747 * hDlg [in] Main dialog HANDLE
2748 * wParam [in] WM_COMMAND wParam
2749 * lParam [in] WM_COMMAND lParam
2750 * pda [in/out] ptr to PageSetupDataA
2754 PRINTDLG_PS_WMCommandA(
2755 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataA *pda
2757 WORD msg = HIWORD(wParam);
2758 WORD id = LOWORD(wParam);
2761 TRACE("loword (lparam) %d, wparam 0x%lx, lparam %08lx\n",
2762 LOWORD(lParam),wParam,lParam);
2765 if (!PRINTDLG_PS_UpdateDlgStructA(hDlg, pda))
2767 EndDialog(hDlg, TRUE);
2771 EndDialog(hDlg, FALSE);
2775 pda->pdlg.Flags = 0;
2776 pda->pdlg.hwndOwner = hDlg;
2777 if (PrintDlgA(&(pda->pdlg)))
2778 PRINTDLG_PS_ChangePrinterA(hDlg,pda);
2782 if (pda->curdlg.ptPaperSize.x > pda->curdlg.ptPaperSize.y){
2783 DWORD tmp = pda->curdlg.ptPaperSize.x;
2784 pda->curdlg.ptPaperSize.x = pda->curdlg.ptPaperSize.y;
2785 pda->curdlg.ptPaperSize.y = tmp;
2787 PRINTDLG_PS_ChangePaperPrev(pda);
2790 if (pda->curdlg.ptPaperSize.y > pda->curdlg.ptPaperSize.x){
2791 DWORD tmp = pda->curdlg.ptPaperSize.x;
2792 pda->curdlg.ptPaperSize.x = pda->curdlg.ptPaperSize.y;
2793 pda->curdlg.ptPaperSize.y = tmp;
2795 PRINTDLG_PS_ChangePaperPrev(pda);
2797 case cmb1: /* Printer combo */
2798 if(msg == CBN_SELCHANGE){
2799 char crPrinterName[256];
2800 GetDlgItemTextA(hDlg, id, crPrinterName, 255);
2801 PRINTDLG_PS_ChangeActivePrinterA(crPrinterName, pda);
2802 PRINTDLG_PS_ChangePrinterA(hDlg, pda);
2805 case cmb2: /* Paper combo */
2806 if(msg == CBN_SELCHANGE){
2807 DWORD paperword = SendDlgItemMessageA(hDlg,cmb2,CB_GETITEMDATA,
2808 SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0), 0);
2809 if (paperword != CB_ERR) {
2810 PRINTDLG_PaperSizeA(&(pda->pdlg), paperword,&(pda->curdlg.ptPaperSize));
2811 pda->curdlg.ptPaperSize.x = _c_10mm2size(pda->dlga,pda->curdlg.ptPaperSize.x);
2812 pda->curdlg.ptPaperSize.y = _c_10mm2size(pda->dlga,pda->curdlg.ptPaperSize.y);
2814 if (IsDlgButtonChecked(hDlg, rad2)) {
2815 DWORD tmp = pda->curdlg.ptPaperSize.x;
2816 pda->curdlg.ptPaperSize.x = pda->curdlg.ptPaperSize.y;
2817 pda->curdlg.ptPaperSize.y = tmp;
2819 PRINTDLG_PS_ChangePaperPrev(pda);
2821 FIXME("could not get dialog text for papersize cmbbox?\n");
2825 if(msg == CBN_SELCHANGE){
2826 DEVMODEA *dm = GlobalLock(pda->pdlg.hDevMode);
2827 dm->dmDefaultSource = SendDlgItemMessageA(hDlg, cmb3,CB_GETITEMDATA,
2828 SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0), 0);
2829 GlobalUnlock(pda->pdlg.hDevMode);
2832 case psh2: /* Printer Properties button */
2835 char PrinterName[256];
2840 GetDlgItemTextA(hDlg, cmb1, PrinterName, 255);
2841 if (!OpenPrinterA(PrinterName, &hPrinter, NULL)) {
2842 FIXME("Call to OpenPrinter did not succeed!\n");
2845 dm = GlobalLock(pda->pdlg.hDevMode);
2846 DocumentPropertiesA(hDlg, hPrinter, PrinterName, dm, dm,
2847 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
2848 ClosePrinter(hPrinter);
2849 /* Changing paper */
2850 PRINTDLG_PaperSizeA(&(pda->pdlg), dm->u1.s1.dmPaperSize, &(pda->curdlg.ptPaperSize));
2851 pda->curdlg.ptPaperSize.x = _c_10mm2size(pda->dlga, pda->curdlg.ptPaperSize.x);
2852 pda->curdlg.ptPaperSize.y = _c_10mm2size(pda->dlga, pda->curdlg.ptPaperSize.y);
2853 if (dm->u1.s1.dmOrientation == DMORIENT_LANDSCAPE){
2854 DWORD tmp = pda->curdlg.ptPaperSize.x;
2855 pda->curdlg.ptPaperSize.x = pda->curdlg.ptPaperSize.y;
2856 pda->curdlg.ptPaperSize.y = tmp;
2857 CheckRadioButton(hDlg, rad1, rad2, rad2);
2860 CheckRadioButton(hDlg, rad1, rad2, rad1);
2861 /* Changing paper preview */
2862 PRINTDLG_PS_ChangePaperPrev(pda);
2863 /* Selecting paper in combo */
2864 count = SendDlgItemMessageA(hDlg, cmb2, CB_GETCOUNT, 0, 0);
2865 if(count != CB_ERR){
2866 for(i=0; i<count; ++i){
2867 if(SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, i, 0) == dm->u1.s1.dmPaperSize) {
2868 SendDlgItemMessageA(hDlg, cmb2, CB_SETCURSEL, i, 0);
2874 GlobalUnlock(pda->pdlg.hDevMode);
2878 GETVAL(id, pda->curdlg.rtMargin.left);
2881 GETVAL(id, pda->curdlg.rtMargin.right);
2884 GETVAL(id, pda->curdlg.rtMargin.top);
2887 GETVAL(id, pda->curdlg.rtMargin.bottom);
2890 InvalidateRect(GetDlgItem(hDlg, rct1), NULL, TRUE);
2896 PRINTDLG_PS_WMCommandW(
2897 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataW *pda
2899 TRACE("loword (lparam) %d, wparam 0x%lx, lparam %08lx\n",
2900 LOWORD(lParam),wParam,lParam);
2901 switch (LOWORD(wParam)) {
2903 if (!PRINTDLG_PS_UpdateDlgStructW(hDlg, pda))
2905 EndDialog(hDlg, TRUE);
2909 EndDialog(hDlg, FALSE);
2913 pda->pdlg.Flags = 0;
2914 pda->pdlg.hwndOwner = hDlg;
2915 if (PrintDlgW(&(pda->pdlg)))
2916 PRINTDLG_PS_ChangePrinterW(hDlg,pda);
2924 /***********************************************************************
2925 * DefaultPagePaintHook
2926 * Default hook paint procedure that receives WM_PSD_* messages from the dialog box
2927 * whenever the sample page is redrawn.
2931 PRINTDLG_DefaultPagePaintHook(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam,
2932 const PageSetupDataA *pda)
2934 LPRECT lprc = (LPRECT) lParam;
2935 HDC hdc = (HDC) wParam;
2938 HFONT hfont, holdfont;
2940 TRACE("uMsg: WM_USER+%d\n",uMsg-WM_USER);
2941 /* Call user paint hook if enable */
2942 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK)
2943 if (pda->dlga->lpfnPagePaintHook(hwndDlg, uMsg, wParam, lParam))
2947 /* LPPAGESETUPDLG in lParam */
2948 case WM_PSD_PAGESETUPDLG:
2949 /* Inform about the sample page rectangle */
2950 case WM_PSD_FULLPAGERECT:
2951 /* Inform about the margin rectangle */
2952 case WM_PSD_MINMARGINRECT:
2955 /* Draw dashed rectangle showing margins */
2956 case WM_PSD_MARGINRECT:
2957 hpen = CreatePen(PS_DASH, 1, GetSysColor(COLOR_3DSHADOW));
2958 holdpen = SelectObject(hdc, hpen);
2959 Rectangle(hdc, lprc->left, lprc->top, lprc->right, lprc->bottom);
2960 DeleteObject(SelectObject(hdc, holdpen));
2962 /* Draw the fake document */
2963 case WM_PSD_GREEKTEXTRECT:
2964 /* select a nice scalable font, because we want the text really small */
2965 SystemParametersInfoW(SPI_GETICONTITLELOGFONT, sizeof(lf), &lf, 0);
2966 lf.lfHeight = 6; /* value chosen based on visual effect */
2967 hfont = CreateFontIndirectW(&lf);
2968 holdfont = SelectObject(hdc, hfont);
2970 /* if text not loaded, then do so now */
2971 if (wszFakeDocumentText[0] == '\0')
2972 LoadStringW(COMDLG32_hInstance,
2974 wszFakeDocumentText,
2975 sizeof(wszFakeDocumentText)/sizeof(wszFakeDocumentText[0]));
2977 oldbkmode = SetBkMode(hdc, TRANSPARENT);
2978 DrawTextW(hdc, wszFakeDocumentText, -1, lprc, DT_TOP|DT_LEFT|DT_NOPREFIX|DT_WORDBREAK);
2979 SetBkMode(hdc, oldbkmode);
2981 DeleteObject(SelectObject(hdc, holdfont));
2984 /* Envelope stamp */
2985 case WM_PSD_ENVSTAMPRECT:
2986 /* Return address */
2987 case WM_PSD_YAFULLPAGERECT:
2988 FIXME("envelope/stamp is not implemented\n");
2991 FIXME("Unknown message %x\n",uMsg);
2997 /***********************************************************************
2999 * The main paint procedure for the PageSetupDlg function.
3000 * The Page Setup dialog box includes an image of a sample page that shows how
3001 * the user's selections affect the appearance of the printed output.
3002 * The image consists of a rectangle that represents the selected paper
3003 * or envelope type, with a dotted-line rectangle representing
3004 * the current margins, and partial (Greek text) characters
3005 * to show how text looks on the printed page.
3007 * The following messages in the order sends to user hook procedure:
3008 * WM_PSD_PAGESETUPDLG Draw the contents of the sample page
3009 * WM_PSD_FULLPAGERECT Inform about the bounding rectangle
3010 * WM_PSD_MINMARGINRECT Inform about the margin rectangle (min margin?)
3011 * WM_PSD_MARGINRECT Draw the margin rectangle
3012 * WM_PSD_GREEKTEXTRECT Draw the Greek text inside the margin rectangle
3013 * If any of first three messages returns TRUE, painting done.
3016 * hWnd [in] Handle to the Page Setup dialog box
3017 * uMsg [in] Received message
3020 * WM_PSD_ENVSTAMPRECT Draw in the envelope-stamp rectangle (for envelopes only)
3021 * WM_PSD_YAFULLPAGERECT Draw the return address portion (for envelopes and other paper sizes)
3024 * FALSE if all done correctly
3029 static LRESULT CALLBACK
3030 PRINTDLG_PagePaintProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3033 RECT rcClient, rcMargin;
3036 HBRUSH hbrush, holdbrush;
3037 PageSetupDataA *pda;
3038 int papersize=0, orientation=0; /* FIXME: set this values for user paint hook */
3039 double scalx, scaly;
3040 #define CALLPAINTHOOK(msg,lprc) PRINTDLG_DefaultPagePaintHook( hWnd, msg, (WPARAM)hdc, (LPARAM)lprc, pda)
3042 if (uMsg != WM_PAINT)
3043 return CallWindowProcA(lpfnStaticWndProc, hWnd, uMsg, wParam, lParam);
3045 /* Processing WM_PAINT message */
3046 pda = (PageSetupDataA*)GetPropA(hWnd, "__WINE_PAGESETUPDLGDATA");
3048 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3051 if (PRINTDLG_DefaultPagePaintHook(hWnd, WM_PSD_PAGESETUPDLG, MAKELONG(papersize, orientation), (LPARAM)pda->dlga, pda))
3054 hdc = BeginPaint(hWnd, &ps);
3055 GetClientRect(hWnd, &rcClient);
3057 scalx = rcClient.right / (double)pda->curdlg.ptPaperSize.x;
3058 scaly = rcClient.bottom / (double)pda->curdlg.ptPaperSize.y;
3059 rcMargin = rcClient;
3061 rcMargin.left += (LONG)pda->curdlg.rtMargin.left * scalx;
3062 rcMargin.top += (LONG)pda->curdlg.rtMargin.top * scalx;
3063 rcMargin.right -= (LONG)pda->curdlg.rtMargin.right * scaly;
3064 rcMargin.bottom -= (LONG)pda->curdlg.rtMargin.bottom * scaly;
3066 /* if the space is too small then we make sure to not draw anything */
3067 rcMargin.left = min(rcMargin.left, rcMargin.right);
3068 rcMargin.top = min(rcMargin.top, rcMargin.bottom);
3070 if (!CALLPAINTHOOK(WM_PSD_FULLPAGERECT, &rcClient) &&
3071 !CALLPAINTHOOK(WM_PSD_MINMARGINRECT, &rcMargin) )
3073 /* fill background */
3074 hbrush = GetSysColorBrush(COLOR_3DHIGHLIGHT);
3075 FillRect(hdc, &rcClient, hbrush);
3076 holdbrush = SelectObject(hdc, hbrush);
3078 hpen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW));
3079 holdpen = SelectObject(hdc, hpen);
3081 /* paint left edge */
3082 MoveToEx(hdc, rcClient.left, rcClient.top, NULL);
3083 LineTo(hdc, rcClient.left, rcClient.bottom-1);
3085 /* paint top edge */
3086 MoveToEx(hdc, rcClient.left, rcClient.top, NULL);
3087 LineTo(hdc, rcClient.right, rcClient.top);
3089 hpen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DDKSHADOW));
3090 DeleteObject(SelectObject(hdc, hpen));
3092 /* paint right edge */
3093 MoveToEx(hdc, rcClient.right-1, rcClient.top, NULL);
3094 LineTo(hdc, rcClient.right-1, rcClient.bottom);
3096 /* paint bottom edge */
3097 MoveToEx(hdc, rcClient.left, rcClient.bottom-1, NULL);
3098 LineTo(hdc, rcClient.right, rcClient.bottom-1);
3100 DeleteObject(SelectObject(hdc, holdpen));
3101 DeleteObject(SelectObject(hdc, holdbrush));
3103 CALLPAINTHOOK(WM_PSD_MARGINRECT, &rcMargin);
3105 /* give text a bit of a space from the frame */
3108 rcMargin.right -= 2;
3109 rcMargin.bottom -= 2;
3111 /* if the space is too small then we make sure to not draw anything */
3112 rcMargin.left = min(rcMargin.left, rcMargin.right);
3113 rcMargin.top = min(rcMargin.top, rcMargin.bottom);
3115 CALLPAINTHOOK(WM_PSD_GREEKTEXTRECT, &rcMargin);
3118 EndPaint(hWnd, &ps);
3120 #undef CALLPAINTHOOK
3123 /***********************************************************************
3124 * PRINTDLG_PageDlgProcA
3125 * Message handler for PageSetupDlgA
3127 static INT_PTR CALLBACK
3128 PRINTDLG_PageDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
3131 PageSetupDataA *pda;
3132 INT_PTR res = FALSE;
3135 if (uMsg == WM_INITDIALOG) { /*Init dialog*/
3136 pda = (PageSetupDataA*)lParam;
3137 pda->hDlg = hDlg; /* saving handle to main window to PageSetupDataA structure */
3138 memcpy(&pda->curdlg, pda->dlga, sizeof(pda->curdlg));
3140 hDrawWnd = GetDlgItem(hDlg, rct1);
3141 TRACE("set property to %p\n", pda);
3142 SetPropA(hDlg, "__WINE_PAGESETUPDLGDATA", pda);
3143 SetPropA(hDrawWnd, "__WINE_PAGESETUPDLGDATA", pda);
3144 GetWindowRect(hDrawWnd, &pda->rtDrawRect); /* Calculating rect in client coordinates where paper draws */
3145 ScreenToClient(hDlg, (LPPOINT)&pda->rtDrawRect);
3146 ScreenToClient(hDlg, (LPPOINT)(&pda->rtDrawRect.right));
3147 lpfnStaticWndProc = (WNDPROC)SetWindowLongPtrW(
3150 (ULONG_PTR)PRINTDLG_PagePaintProc);
3152 /* FIXME: Paint hook. Must it be at begin of initializtion or at end? */
3154 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3155 if (!pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,(LPARAM)pda->dlga))
3156 FIXME("Setup page hook failed?\n");
3159 /* if printer button disabled */
3160 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
3161 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
3162 /* if margin edit boxes disabled */
3163 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
3164 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
3165 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
3166 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
3167 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
3169 /* Set orientation radiobutton properly */
3170 if(pda->dlga->hDevMode)
3172 dm = GlobalLock(pda->dlga->hDevMode);
3173 if (dm->u1.s1.dmOrientation == DMORIENT_LANDSCAPE)
3174 CheckRadioButton(hDlg, rad1, rad2, rad2);
3175 else /* this is default if papersize is not set */
3176 CheckRadioButton(hDlg, rad1, rad2, rad1);
3177 GlobalUnlock(pda->dlga->hDevMode);
3180 /* if orientation disabled */
3181 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
3182 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
3183 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
3185 /* We fill them out enabled or not */
3186 if (pda->dlga->Flags & PSD_MARGINS) {
3188 _c_size2strA(pda,pda->dlga->rtMargin.left,str);
3189 SetDlgItemTextA(hDlg,edt4,str);
3190 _c_size2strA(pda,pda->dlga->rtMargin.top,str);
3191 SetDlgItemTextA(hDlg,edt5,str);
3192 _c_size2strA(pda,pda->dlga->rtMargin.right,str);
3193 SetDlgItemTextA(hDlg,edt6,str);
3194 _c_size2strA(pda,pda->dlga->rtMargin.bottom,str);
3195 SetDlgItemTextA(hDlg,edt7,str);
3197 /* default is 1 inch */
3198 DWORD size = _c_inch2size(pda->dlga,1000);
3200 _c_size2strA(pda,size,str);
3201 SetDlgItemTextA(hDlg,edt4,str);
3202 SetDlgItemTextA(hDlg,edt5,str);
3203 SetDlgItemTextA(hDlg,edt6,str);
3204 SetDlgItemTextA(hDlg,edt7,str);
3205 pda->curdlg.rtMargin.left = size;
3206 pda->curdlg.rtMargin.top = size;
3207 pda->curdlg.rtMargin.right = size;
3208 pda->curdlg.rtMargin.bottom = size;
3210 /* if paper disabled */
3211 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
3212 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
3213 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
3215 /* filling combos: printer, paper, source. selecting current printer (from DEVMODEA) */
3216 PRINTDLG_PS_ChangePrinterA(hDlg, pda);
3217 dm = GlobalLock(pda->pdlg.hDevMode);
3219 dm->dmDefaultSource = 15; /*FIXME: Automatic select. Does it always 15 at start? */
3220 PRINTDLG_PaperSizeA(&(pda->pdlg), dm->u1.s1.dmPaperSize, &pda->curdlg.ptPaperSize);
3221 GlobalUnlock(pda->pdlg.hDevMode);
3222 pda->curdlg.ptPaperSize.x = _c_10mm2size(pda->dlga, pda->curdlg.ptPaperSize.x);
3223 pda->curdlg.ptPaperSize.y = _c_10mm2size(pda->dlga, pda->curdlg.ptPaperSize.y);
3224 if (IsDlgButtonChecked(hDlg, rad2) == BST_CHECKED) { /* Landscape orientation */
3225 DWORD tmp = pda->curdlg.ptPaperSize.y;
3226 pda->curdlg.ptPaperSize.y = pda->curdlg.ptPaperSize.x;
3227 pda->curdlg.ptPaperSize.x = tmp;
3230 WARN("GlobalLock(pda->pdlg.hDevMode) fail? hDevMode=%p\n", pda->pdlg.hDevMode);
3231 /* Drawing paper prev */
3232 PRINTDLG_PS_ChangePaperPrev(pda);
3235 pda = (PageSetupDataA*)GetPropA(hDlg,"__WINE_PAGESETUPDLGDATA");
3237 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3240 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3241 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3242 if (res) return res;
3247 return PRINTDLG_PS_WMCommandA(hDlg, wParam, lParam, pda);
3252 static INT_PTR CALLBACK
3253 PageDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
3255 static const WCHAR __WINE_PAGESETUPDLGDATA[] =
3256 { '_', '_', 'W', 'I', 'N', 'E', '_', 'P', 'A', 'G', 'E',
3257 'S', 'E', 'T', 'U', 'P', 'D', 'L', 'G', 'D', 'A', 'T', 'A', 0 };
3258 PageSetupDataW *pda;
3262 if (uMsg==WM_INITDIALOG) {
3264 pda = (PageSetupDataW*)lParam;
3265 SetPropW(hDlg, __WINE_PAGESETUPDLGDATA, pda);
3266 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3267 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,(LPARAM)pda->dlga);
3269 FIXME("Setup page hook failed?\n");
3274 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK) {
3275 FIXME("PagePaintHook not yet implemented!\n");
3277 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
3278 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
3279 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
3280 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
3281 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
3282 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
3283 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
3286 if(pda->dlga->hDevMode)
3288 dm = GlobalLock(pda->dlga->hDevMode);
3289 /* Landscape orientation */
3290 if (dm->u1.s1.dmOrientation == DMORIENT_LANDSCAPE)
3291 CheckRadioButton(hDlg, rad1, rad2, rad2);
3292 else /* this is default if papersize is not set */
3293 CheckRadioButton(hDlg, rad1, rad2, rad1);
3294 GlobalUnlock(pda->dlga->hDevMode);
3297 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
3298 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
3299 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
3301 /* We fill them out enabled or not */
3302 if (pda->dlga->Flags & PSD_MARGINS) {
3304 _c_size2strW(pda,pda->dlga->rtMargin.left,str);
3305 SetDlgItemTextW(hDlg,edt4,str);
3306 _c_size2strW(pda,pda->dlga->rtMargin.top,str);
3307 SetDlgItemTextW(hDlg,edt5,str);
3308 _c_size2strW(pda,pda->dlga->rtMargin.right,str);
3309 SetDlgItemTextW(hDlg,edt6,str);
3310 _c_size2strW(pda,pda->dlga->rtMargin.bottom,str);
3311 SetDlgItemTextW(hDlg,edt7,str);
3313 /* default is 1 inch */
3314 DWORD size = _c_inch2size((LPPAGESETUPDLGA)pda->dlga,1000);
3316 _c_size2strW(pda,size,str);
3317 SetDlgItemTextW(hDlg,edt4,str);
3318 SetDlgItemTextW(hDlg,edt5,str);
3319 SetDlgItemTextW(hDlg,edt6,str);
3320 SetDlgItemTextW(hDlg,edt7,str);
3322 PRINTDLG_PS_ChangePrinterW(hDlg,pda);
3323 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
3324 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
3325 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
3330 pda = (PageSetupDataW*)GetPropW(hDlg, __WINE_PAGESETUPDLGDATA);
3332 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3335 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3336 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3337 if (res) return res;
3342 return PRINTDLG_PS_WMCommandW(hDlg, wParam, lParam, pda);
3347 /***********************************************************************
3348 * PageSetupDlgA (COMDLG32.@)
3350 * Displays the the PAGE SETUP dialog box, which enables the user to specify
3351 * specific properties of a printed page such as
3352 * size, source, orientation and the width of the page margins.
3355 * setupdlg [IO] PAGESETUPDLGA struct
3358 * TRUE if the user pressed the OK button
3359 * FALSE if the user cancelled the window or an error occurred
3362 * The values of hDevMode and hDevNames are filled on output and can be
3363 * changed in PAGESETUPDLG when they are passed in PageSetupDlg.
3367 BOOL WINAPI PageSetupDlgA(LPPAGESETUPDLGA setupdlg) {
3371 PageSetupDataA *pda;
3375 if(TRACE_ON(commdlg)) {
3376 char flagstr[1000] = "";
3377 const struct pd_flags *pflag = psd_flags;
3378 for( ; pflag->name; pflag++) {
3379 if(setupdlg->Flags & pflag->flag) {
3380 strcat(flagstr, pflag->name);
3381 strcat(flagstr, "|");
3384 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3385 "hinst %p, flags %08x (%s)\n",
3386 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
3387 setupdlg->hDevNames,
3388 setupdlg->hInstance, setupdlg->Flags, flagstr);
3390 /* Checking setupdlg structure */
3391 if (setupdlg == NULL) {
3392 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION);
3395 if(setupdlg->lStructSize != sizeof(PAGESETUPDLGA)) {
3396 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
3399 if ((setupdlg->Flags & PSD_ENABLEPAGEPAINTHOOK) &&
3400 (setupdlg->lpfnPagePaintHook == NULL)) {
3401 COMDLG32_SetCommDlgExtendedError(CDERR_NOHOOK);
3405 /* Initialize default printer struct. If no printer device info is specified
3406 retrieve the default printer data. */
3407 memset(&pdlg,0,sizeof(pdlg));
3408 pdlg.lStructSize = sizeof(pdlg);
3409 if (setupdlg->hDevMode && setupdlg->hDevNames) {
3410 pdlg.hDevMode = setupdlg->hDevMode;
3411 pdlg.hDevNames = setupdlg->hDevNames;
3413 pdlg.Flags = PD_RETURNDEFAULT;
3414 bRet = PrintDlgA(&pdlg);
3416 if (!(setupdlg->Flags & PSD_NOWARNING)) {
3418 LoadStringA(COMDLG32_hInstance, PD32_NO_DEFAULT_PRINTER, errstr, 255);
3419 MessageBoxA(setupdlg->hwndOwner, errstr, 0, MB_OK | MB_ICONERROR);
3425 /* short cut exit, just return default values */
3426 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
3429 setupdlg->hDevMode = pdlg.hDevMode;
3430 setupdlg->hDevNames = pdlg.hDevNames;
3431 dm = GlobalLock(pdlg.hDevMode);
3432 PRINTDLG_PaperSizeA(&pdlg, dm->u1.s1.dmPaperSize, &setupdlg->ptPaperSize);
3433 GlobalUnlock(pdlg.hDevMode);
3434 setupdlg->ptPaperSize.x=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.x);
3435 setupdlg->ptPaperSize.y=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.y);
3439 /* get dialog template */
3440 hDlgTmpl = PRINTDLG_GetPGSTemplateA(setupdlg);
3442 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3445 ptr = LockResource( hDlgTmpl );
3447 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3451 pda = HeapAlloc(GetProcessHeap(),0,sizeof(*pda));
3452 pda->dlga = setupdlg;
3453 memcpy(&pda->pdlg,&pdlg,sizeof(pdlg));
3455 bRet = (0<DialogBoxIndirectParamA(
3456 setupdlg->hInstance,
3458 setupdlg->hwndOwner,
3459 PRINTDLG_PageDlgProcA,
3463 HeapFree(GetProcessHeap(),0,pda);
3466 /***********************************************************************
3467 * PageSetupDlgW (COMDLG32.@)
3469 * See PageSetupDlgA.
3471 BOOL WINAPI PageSetupDlgW(LPPAGESETUPDLGW setupdlg) {
3475 PageSetupDataW *pdw;
3478 FIXME("Unicode implementation is not done yet\n");
3479 if(TRACE_ON(commdlg)) {
3480 char flagstr[1000] = "";
3481 const struct pd_flags *pflag = psd_flags;
3482 for( ; pflag->name; pflag++) {
3483 if(setupdlg->Flags & pflag->flag) {
3484 strcat(flagstr, pflag->name);
3485 strcat(flagstr, "|");
3488 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3489 "hinst %p, flags %08x (%s)\n",
3490 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
3491 setupdlg->hDevNames,
3492 setupdlg->hInstance, setupdlg->Flags, flagstr);
3495 /* Initialize default printer struct. If no printer device info is specified
3496 retrieve the default printer data. */
3497 memset(&pdlg,0,sizeof(pdlg));
3498 pdlg.lStructSize = sizeof(pdlg);
3499 if (setupdlg->hDevMode && setupdlg->hDevNames) {
3500 pdlg.hDevMode = setupdlg->hDevMode;
3501 pdlg.hDevNames = setupdlg->hDevNames;
3503 pdlg.Flags = PD_RETURNDEFAULT;
3504 bRet = PrintDlgW(&pdlg);
3506 if (!(setupdlg->Flags & PSD_NOWARNING)) {
3508 LoadStringW(COMDLG32_hInstance, PD32_NO_DEFAULT_PRINTER, errstr, 255);
3509 MessageBoxW(setupdlg->hwndOwner, errstr, 0, MB_OK | MB_ICONERROR);
3515 /* short cut exit, just return default values */
3516 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
3517 static const WCHAR a4[] = {'A','4',0};
3518 setupdlg->hDevMode = pdlg.hDevMode;
3519 setupdlg->hDevNames = pdlg.hDevNames;
3520 /* FIXME: Just return "A4" for now. */
3521 PRINTDLG_PaperSizeW(&pdlg,a4,&setupdlg->ptPaperSize);
3522 setupdlg->ptPaperSize.x=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.x);
3523 setupdlg->ptPaperSize.y=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.y);
3526 hDlgTmpl = PRINTDLG_GetPGSTemplateW(setupdlg);
3528 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3531 ptr = LockResource( hDlgTmpl );
3533 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3536 pdw = HeapAlloc(GetProcessHeap(),0,sizeof(*pdw));
3537 pdw->dlga = setupdlg;
3538 memcpy(&pdw->pdlg,&pdlg,sizeof(pdlg));
3540 bRet = (0<DialogBoxIndirectParamW(
3541 setupdlg->hInstance,
3543 setupdlg->hwndOwner,
3550 /***********************************************************************
3551 * PrintDlgExA (COMDLG32.@)
3558 HRESULT WINAPI PrintDlgExA(LPPRINTDLGEXA lpPrintDlgExA)
3564 /***********************************************************************
3565 * PrintDlgExW (COMDLG32.@)
3567 * Display the the PRINT dialog box, which enables the user to specify
3568 * specific properties of the print job. The property sheet can also have
3569 * additional application-specific and driver-specific property pages.
3572 * lppd [IO] ptr to PRINTDLGEX struct
3576 * Failure: One of the following COM error codes:
3577 * E_OUTOFMEMORY Insufficient memory.
3578 * E_INVALIDARG One or more arguments are invalid.
3579 * E_POINTER Invalid pointer.
3580 * E_HANDLE Invalid handle.
3581 * E_FAIL Unspecified error.
3586 HRESULT WINAPI PrintDlgExW(LPPRINTDLGEXW lpPrintDlgExW)