2 * COMMDLG - Print Dialog
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
6 * Copyright 1999 Klaas van Gend
7 * Copyright 2000 Huw D M Davies
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #define NONAMELESSUNION
30 #define NONAMELESSSTRUCT
38 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
49 /* Yes these constants are the same, but we're just copying win98 */
50 #define UPDOWN_ID 0x270f
51 #define MAX_COPIES 9999
54 static struct pd_flags psd_flags[] = {
55 {PSD_MINMARGINS,"PSD_MINMARGINS"},
56 {PSD_MARGINS,"PSD_MARGINS"},
57 {PSD_INTHOUSANDTHSOFINCHES,"PSD_INTHOUSANDTHSOFINCHES"},
58 {PSD_INHUNDREDTHSOFMILLIMETERS,"PSD_INHUNDREDTHSOFMILLIMETERS"},
59 {PSD_DISABLEMARGINS,"PSD_DISABLEMARGINS"},
60 {PSD_DISABLEPRINTER,"PSD_DISABLEPRINTER"},
61 {PSD_NOWARNING,"PSD_NOWARNING"},
62 {PSD_DISABLEORIENTATION,"PSD_DISABLEORIENTATION"},
63 {PSD_RETURNDEFAULT,"PSD_RETURNDEFAULT"},
64 {PSD_DISABLEPAPER,"PSD_DISABLEPAPER"},
65 {PSD_SHOWHELP,"PSD_SHOWHELP"},
66 {PSD_ENABLEPAGESETUPHOOK,"PSD_ENABLEPAGESETUPHOOK"},
67 {PSD_ENABLEPAGESETUPTEMPLATE,"PSD_ENABLEPAGESETUPTEMPLATE"},
68 {PSD_ENABLEPAGESETUPTEMPLATEHANDLE,"PSD_ENABLEPAGESETUPTEMPLATEHANDLE"},
69 {PSD_ENABLEPAGEPAINTHOOK,"PSD_ENABLEPAGEPAINTHOOK"},
70 {PSD_DISABLEPAGEPAINTING,"PSD_DISABLEPAGEPAINTING"},
74 /***********************************************************************
75 * PRINTDLG_OpenDefaultPrinter
77 * Returns a winspool printer handle to the default printer in *hprn
78 * Caller must call ClosePrinter on the handle
80 * Returns TRUE on success else FALSE
82 BOOL PRINTDLG_OpenDefaultPrinter(HANDLE *hprn)
85 DWORD dwBufLen = sizeof(buf);
87 if(!GetDefaultPrinterA(buf, &dwBufLen))
89 res = OpenPrinterA(buf, hprn, NULL);
91 FIXME("Could not open printer %s?!\n",buf);
95 /***********************************************************************
96 * PRINTDLG_SetUpPrinterListCombo
98 * Initializes printer list combox.
99 * hDlg: HWND of dialog
100 * id: Control id of combo
101 * name: Name of printer to select
103 * Initializes combo with list of available printers. Selects printer 'name'
104 * If name is NULL or does not exist select the default printer.
106 * Returns number of printers added to list.
108 INT PRINTDLG_SetUpPrinterListComboA(HWND hDlg, UINT id, LPCSTR name)
112 LPPRINTER_INFO_2A pi;
113 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
114 pi = HeapAlloc(GetProcessHeap(), 0, needed);
115 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
118 for(i = 0; i < num; i++) {
119 SendDlgItemMessageA(hDlg, id, CB_ADDSTRING, 0,
120 (LPARAM)pi[i].pPrinterName );
122 HeapFree(GetProcessHeap(), 0, pi);
124 (i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1,
125 (LPARAM)name)) == CB_ERR) {
128 DWORD dwBufLen = sizeof(buf);
129 FIXME("Can't find '%s' in printer list so trying to find default\n",
131 if(!GetDefaultPrinterA(buf, &dwBufLen))
133 i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
135 FIXME("Can't find default printer in printer list\n");
137 SendDlgItemMessageA(hDlg, id, CB_SETCURSEL, i, 0);
141 static INT PRINTDLG_SetUpPrinterListComboW(HWND hDlg, UINT id, LPCWSTR name)
145 LPPRINTER_INFO_2W pi;
146 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
147 pi = HeapAlloc(GetProcessHeap(), 0, needed);
148 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
151 for(i = 0; i < num; i++) {
152 SendDlgItemMessageW(hDlg, id, CB_ADDSTRING, 0,
153 (LPARAM)pi[i].pPrinterName );
155 HeapFree(GetProcessHeap(), 0, pi);
157 (i = SendDlgItemMessageW(hDlg, id, CB_FINDSTRINGEXACT, -1,
158 (LPARAM)name)) == CB_ERR) {
160 DWORD dwBufLen = sizeof(buf)/sizeof(buf[0]);
161 TRACE("Can't find '%s' in printer list so trying to find default\n",
163 if(!GetDefaultPrinterW(buf, &dwBufLen))
165 i = SendDlgItemMessageW(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
167 TRACE("Can't find default printer in printer list\n");
169 SendDlgItemMessageW(hDlg, id, CB_SETCURSEL, i, 0);
173 /***********************************************************************
174 * PRINTDLG_CreateDevNames [internal]
177 * creates a DevNames structure.
179 * (NB. when we handle unicode the offsets will be in wchars).
181 static BOOL PRINTDLG_CreateDevNames(HGLOBAL *hmem, char* DeviceDriverName,
182 char* DeviceName, char* OutputPort)
185 char* pDevNamesSpace;
187 LPDEVNAMES lpDevNames;
189 DWORD dwBufLen = sizeof(buf);
191 size = strlen(DeviceDriverName) + 1
192 + strlen(DeviceName) + 1
193 + strlen(OutputPort) + 1
197 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
199 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
203 pDevNamesSpace = GlobalLock(*hmem);
204 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
206 pTempPtr = pDevNamesSpace + sizeof(DEVNAMES);
207 strcpy(pTempPtr, DeviceDriverName);
208 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
210 pTempPtr += strlen(DeviceDriverName) + 1;
211 strcpy(pTempPtr, DeviceName);
212 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
214 pTempPtr += strlen(DeviceName) + 1;
215 strcpy(pTempPtr, OutputPort);
216 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
218 GetDefaultPrinterA(buf, &dwBufLen);
219 lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
224 static BOOL PRINTDLG_CreateDevNamesW(HGLOBAL *hmem, LPCWSTR DeviceDriverName,
225 LPCWSTR DeviceName, LPCWSTR OutputPort)
228 LPWSTR pDevNamesSpace;
230 LPDEVNAMES lpDevNames;
232 DWORD dwBufLen = sizeof(bufW) / sizeof(WCHAR);
234 size = sizeof(WCHAR)*lstrlenW(DeviceDriverName) + 2
235 + sizeof(WCHAR)*lstrlenW(DeviceName) + 2
236 + sizeof(WCHAR)*lstrlenW(OutputPort) + 2
240 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
242 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
246 pDevNamesSpace = GlobalLock(*hmem);
247 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
249 pTempPtr = (LPWSTR)((LPDEVNAMES)pDevNamesSpace + 1);
250 lstrcpyW(pTempPtr, DeviceDriverName);
251 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
253 pTempPtr += lstrlenW(DeviceDriverName) + 1;
254 lstrcpyW(pTempPtr, DeviceName);
255 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
257 pTempPtr += lstrlenW(DeviceName) + 1;
258 lstrcpyW(pTempPtr, OutputPort);
259 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
261 GetDefaultPrinterW(bufW, &dwBufLen);
262 lpDevNames->wDefault = (lstrcmpW(bufW, DeviceName) == 0) ? 1 : 0;
267 /***********************************************************************
268 * PRINTDLG_UpdatePrintDlg [internal]
271 * updates the PrintDlg structure for return values.
274 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
275 * TRUE if successful.
277 static BOOL PRINTDLG_UpdatePrintDlgA(HWND hDlg,
278 PRINT_PTRA* PrintStructures)
280 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
281 PDEVMODEA lpdm = PrintStructures->lpDevMode;
282 LPPRINTER_INFO_2A pi = PrintStructures->lpPrinterInfo;
286 FIXME("No lpdm ptr?\n");
291 if(!(lppd->Flags & PD_PRINTSETUP)) {
292 /* check whether nFromPage and nToPage are within range defined by
293 * nMinPage and nMaxPage
295 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
298 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
299 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
300 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
301 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
302 char resourcestr[256];
304 LoadStringA(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
306 sprintf(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
307 LoadStringA(COMDLG32_hInstance, PD32_PRINT_TITLE,
309 MessageBoxA(hDlg, resultstr, resourcestr,
310 MB_OK | MB_ICONWARNING);
313 lppd->nFromPage = nFromPage;
314 lppd->nToPage = nToPage;
315 lppd->Flags |= PD_PAGENUMS;
318 lppd->Flags &= ~PD_PAGENUMS;
320 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
321 lppd->Flags |= PD_PRINTTOFILE;
322 pi->pPortName = "FILE:";
325 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
326 FIXME("Collate lppd not yet implemented as output\n");
329 /* set PD_Collate and nCopies */
330 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
331 /* The application doesn't support multiple copies or collate...
333 lppd->Flags &= ~PD_COLLATE;
335 /* if the printer driver supports it... store info there
336 * otherwise no collate & multiple copies !
338 if (lpdm->dmFields & DM_COLLATE)
340 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
341 if (lpdm->dmFields & DM_COPIES)
342 lpdm->dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
344 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
345 lppd->Flags |= PD_COLLATE;
347 lppd->Flags &= ~PD_COLLATE;
348 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
354 static BOOL PRINTDLG_UpdatePrintDlgW(HWND hDlg,
355 PRINT_PTRW* PrintStructures)
357 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
358 PDEVMODEW lpdm = PrintStructures->lpDevMode;
359 LPPRINTER_INFO_2W pi = PrintStructures->lpPrinterInfo;
363 FIXME("No lpdm ptr?\n");
368 if(!(lppd->Flags & PD_PRINTSETUP)) {
369 /* check whether nFromPage and nToPage are within range defined by
370 * nMinPage and nMaxPage
372 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
375 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
376 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
377 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
378 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
379 WCHAR resourcestr[256];
380 WCHAR resultstr[256];
381 LoadStringW(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
383 wsprintfW(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
384 LoadStringW(COMDLG32_hInstance, PD32_PRINT_TITLE,
386 MessageBoxW(hDlg, resultstr, resourcestr,
387 MB_OK | MB_ICONWARNING);
390 lppd->nFromPage = nFromPage;
391 lppd->nToPage = nToPage;
394 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
395 static WCHAR file[] = {'F','I','L','E',':',0};
396 lppd->Flags |= PD_PRINTTOFILE;
397 pi->pPortName = file;
400 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
401 FIXME("Collate lppd not yet implemented as output\n");
404 /* set PD_Collate and nCopies */
405 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
406 /* The application doesn't support multiple copies or collate...
408 lppd->Flags &= ~PD_COLLATE;
410 /* if the printer driver supports it... store info there
411 * otherwise no collate & multiple copies !
413 if (lpdm->dmFields & DM_COLLATE)
415 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
416 if (lpdm->dmFields & DM_COPIES)
417 lpdm->dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
419 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
420 lppd->Flags |= PD_COLLATE;
422 lppd->Flags &= ~PD_COLLATE;
423 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
429 static BOOL PRINTDLG_PaperSizeA(
430 PRINTDLGA *pdlga,const char *PaperSize,LPPOINT size
434 LPSTR devname,portname;
438 POINT *points = NULL;
441 dn = GlobalLock(pdlga->hDevNames);
442 dm = GlobalLock(pdlga->hDevMode);
443 devname = ((char*)dn)+dn->wDeviceOffset;
444 portname = ((char*)dn)+dn->wOutputOffset;
447 NrOfEntries = DeviceCapabilitiesA(devname,portname,DC_PAPERNAMES,NULL,dm);
449 FIXME("No papernames found for %s/%s\n",devname,portname);
452 if (NrOfEntries == -1) {
453 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
457 Names = (char*)HeapAlloc(GetProcessHeap(),0,NrOfEntries*64);
458 if (NrOfEntries != (ret=DeviceCapabilitiesA(devname,portname,DC_PAPERNAMES,Names,dm))) {
459 FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
462 for (i=0;i<NrOfEntries;i++)
463 if (!strcmp(PaperSize,Names+(64*i)))
465 HeapFree(GetProcessHeap(),0,Names);
466 if (i==NrOfEntries) {
467 FIXME("Papersize %s not found in list?\n",PaperSize);
470 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
471 if (NrOfEntries!=(ret=DeviceCapabilitiesA(devname,portname,DC_PAPERSIZE,(LPBYTE)points,dm))) {
472 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
475 /* this is _10ths_ of a millimeter */
480 GlobalUnlock(pdlga->hDevNames);
481 GlobalUnlock(pdlga->hDevMode);
482 if (Names) HeapFree(GetProcessHeap(),0,Names);
483 if (points) HeapFree(GetProcessHeap(),0,points);
487 static BOOL PRINTDLG_PaperSizeW(
488 PRINTDLGW *pdlga,const WCHAR *PaperSize,LPPOINT size
492 LPWSTR devname,portname;
496 POINT *points = NULL;
499 dn = GlobalLock(pdlga->hDevNames);
500 dm = GlobalLock(pdlga->hDevMode);
501 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
502 portname = ((WCHAR*)dn)+dn->wOutputOffset;
505 NrOfEntries = DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,NULL,dm);
507 FIXME("No papernames found for %s/%s\n",debugstr_w(devname),debugstr_w(portname));
510 if (NrOfEntries == -1) {
511 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
515 Names = (WCHAR*)HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*NrOfEntries*64);
516 if (NrOfEntries != (ret=DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,Names,dm))) {
517 FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
520 for (i=0;i<NrOfEntries;i++)
521 if (!lstrcmpW(PaperSize,Names+(64*i)))
523 HeapFree(GetProcessHeap(),0,Names);
524 if (i==NrOfEntries) {
525 FIXME("Papersize %s not found in list?\n",debugstr_w(PaperSize));
528 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
529 if (NrOfEntries!=(ret=DeviceCapabilitiesW(devname,portname,DC_PAPERSIZE,(LPWSTR)points,dm))) {
530 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
533 /* this is _10ths_ of a millimeter */
538 GlobalUnlock(pdlga->hDevNames);
539 GlobalUnlock(pdlga->hDevMode);
540 if (Names) HeapFree(GetProcessHeap(),0,Names);
541 if (points) HeapFree(GetProcessHeap(),0,points);
546 /************************************************************************
547 * PRINTDLG_SetUpPaperComboBox
549 * Initialize either the papersize or inputslot combos of the Printer Setup
550 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
551 * We also try to re-select the old selection.
553 static BOOL PRINTDLG_SetUpPaperComboBoxA(HWND hDlg,
566 int fwCapability_Names;
567 int fwCapability_Words;
569 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName,PortName,nIDComboBox);
571 /* query the dialog box for the current selected value */
572 Sel = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
574 /* we enter here only if a different printer is selected after
575 * the Print Setup dialog is opened. The current settings are
576 * stored into the newly selected printer.
578 oldWord = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA,
581 if (nIDComboBox == cmb2)
582 dm->u1.s1.dmPaperSize = oldWord;
584 dm->dmDefaultSource = oldWord;
588 /* we enter here only when the Print setup dialog is initially
589 * opened. In this case the settings are restored from when
590 * the dialog was last closed.
593 if (nIDComboBox == cmb2)
594 oldWord = dm->u1.s1.dmPaperSize;
596 oldWord = dm->dmDefaultSource;
600 if (nIDComboBox == cmb2) {
602 fwCapability_Names = DC_PAPERNAMES;
603 fwCapability_Words = DC_PAPERS;
607 fwCapability_Names = DC_BINNAMES;
608 fwCapability_Words = DC_BINS;
611 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
612 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
614 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
615 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
616 fwCapability_Names, NULL, dm);
617 if (NrOfEntries == 0)
618 WARN("no Name Entries found!\n");
619 else if (NrOfEntries < 0)
622 if(DeviceCapabilitiesA(PrinterName, PortName, fwCapability_Words, NULL, dm)
624 ERR("Number of caps is different\n");
628 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(char)*NamesSize);
629 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
630 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
631 fwCapability_Names, Names, dm);
632 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
633 fwCapability_Words, (LPSTR)Words, dm);
635 /* reset any current content in the combobox */
636 SendDlgItemMessageA(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
638 /* store new content */
639 for (i = 0; i < NrOfEntries; i++) {
640 DWORD pos = SendDlgItemMessageA(hDlg, nIDComboBox, CB_ADDSTRING, 0,
641 (LPARAM)(&Names[i*NamesSize]) );
642 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
646 /* Look for old selection - can't do this is previous loop since
647 item order will change as more items are added */
649 for (i = 0; i < NrOfEntries; i++) {
650 if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
656 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
658 HeapFree(GetProcessHeap(),0,Words);
659 HeapFree(GetProcessHeap(),0,Names);
663 static BOOL PRINTDLG_SetUpPaperComboBoxW(HWND hDlg,
676 int fwCapability_Names;
677 int fwCapability_Words;
679 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName),debugstr_w(PortName),nIDComboBox);
681 /* query the dialog box for the current selected value */
682 Sel = SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
684 /* we enter here only if a different printer is selected after
685 * the Print Setup dialog is opened. The current settings are
686 * stored into the newly selected printer.
688 oldWord = SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETITEMDATA,
691 if (nIDComboBox == cmb2)
692 dm->u1.s1.dmPaperSize = oldWord;
694 dm->dmDefaultSource = oldWord;
698 /* we enter here only when the Print setup dialog is initially
699 * opened. In this case the settings are restored from when
700 * the dialog was last closed.
703 if (nIDComboBox == cmb2)
704 oldWord = dm->u1.s1.dmPaperSize;
706 oldWord = dm->dmDefaultSource;
710 if (nIDComboBox == cmb2) {
712 fwCapability_Names = DC_PAPERNAMES;
713 fwCapability_Words = DC_PAPERS;
717 fwCapability_Names = DC_BINNAMES;
718 fwCapability_Words = DC_BINS;
721 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
722 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
724 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
725 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
726 fwCapability_Names, NULL, dm);
727 if (NrOfEntries == 0)
728 WARN("no Name Entries found!\n");
729 else if (NrOfEntries < 0)
732 if(DeviceCapabilitiesW(PrinterName, PortName, fwCapability_Words, NULL, dm)
734 ERR("Number of caps is different\n");
738 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WCHAR)*NamesSize);
739 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
740 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
741 fwCapability_Names, Names, dm);
742 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
743 fwCapability_Words, (LPWSTR)Words, dm);
745 /* reset any current content in the combobox */
746 SendDlgItemMessageW(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
748 /* store new content */
749 for (i = 0; i < NrOfEntries; i++) {
750 DWORD pos = SendDlgItemMessageW(hDlg, nIDComboBox, CB_ADDSTRING, 0,
751 (LPARAM)(&Names[i*NamesSize]) );
752 SendDlgItemMessageW(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
756 /* Look for old selection - can't do this is previous loop since
757 item order will change as more items are added */
759 for (i = 0; i < NrOfEntries; i++) {
760 if(SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
766 SendDlgItemMessageW(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
768 HeapFree(GetProcessHeap(),0,Words);
769 HeapFree(GetProcessHeap(),0,Names);
774 /***********************************************************************
775 * PRINTDLG_UpdatePrinterInfoTexts [internal]
777 static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg, LPPRINTER_INFO_2A pi)
780 char ResourceString[256];
786 /* add all status messages */
787 for (i = 0; i < 25; i++) {
788 if (pi->Status & (1<<i)) {
789 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
790 ResourceString, 255);
791 strcat(StatusMsg,ResourceString);
795 /* FIXME: status==ready must only be appended if really so.
796 but how to detect? */
797 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
798 ResourceString, 255);
799 strcat(StatusMsg,ResourceString);
800 SetDlgItemTextA(hDlg, stc12, StatusMsg);
802 /* set all other printer info texts */
803 SetDlgItemTextA(hDlg, stc11, pi->pDriverName);
805 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
806 SetDlgItemTextA(hDlg, stc14, pi->pLocation);
808 SetDlgItemTextA(hDlg, stc14, pi->pPortName);
809 SetDlgItemTextA(hDlg, stc13, pi->pComment ? pi->pComment : "");
813 static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg, LPPRINTER_INFO_2W pi)
815 WCHAR StatusMsg[256];
816 WCHAR ResourceString[256];
817 static const WCHAR emptyW[] = {0};
823 /* add all status messages */
824 for (i = 0; i < 25; i++) {
825 if (pi->Status & (1<<i)) {
826 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
827 ResourceString, 255);
828 lstrcatW(StatusMsg,ResourceString);
832 /* FIXME: status==ready must only be appended if really so.
833 but how to detect? */
834 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
835 ResourceString, 255);
836 lstrcatW(StatusMsg,ResourceString);
837 SetDlgItemTextW(hDlg, stc12, StatusMsg);
839 /* set all other printer info texts */
840 SetDlgItemTextW(hDlg, stc11, pi->pDriverName);
841 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
842 SetDlgItemTextW(hDlg, stc14, pi->pLocation);
844 SetDlgItemTextW(hDlg, stc14, pi->pPortName);
845 SetDlgItemTextW(hDlg, stc13, pi->pComment ? pi->pComment : emptyW);
849 /*******************************************************************
851 * PRINTDLG_ChangePrinter
854 BOOL PRINTDLG_ChangePrinterA(HWND hDlg, char *name,
855 PRINT_PTRA *PrintStructures)
857 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
858 LPDEVMODEA lpdm = NULL;
863 if(PrintStructures->lpPrinterInfo)
864 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
865 if(PrintStructures->lpDriverInfo)
866 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
867 if(!OpenPrinterA(name, &hprn, NULL)) {
868 ERR("Can't open printer %s\n", name);
871 GetPrinterA(hprn, 2, NULL, 0, &needed);
872 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,needed);
873 GetPrinterA(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
875 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
876 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,needed);
877 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
879 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures->lpPrinterInfo->pPrinterName);
884 PRINTDLG_UpdatePrinterInfoTextsA(hDlg, PrintStructures->lpPrinterInfo);
886 if(PrintStructures->lpDevMode) {
887 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
888 PrintStructures->lpDevMode = NULL;
891 dmSize = DocumentPropertiesA(0, 0, name, NULL, NULL, 0);
893 ERR("DocumentProperties fails on %s\n", debugstr_a(name));
896 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
897 dmSize = DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, NULL,
899 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
900 !strcmp(lpdm->dmDeviceName,
901 PrintStructures->lpDevMode->dmDeviceName)) {
902 /* Supplied devicemode matches current printer so try to use it */
903 DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, lpdm,
904 DM_OUT_BUFFER | DM_IN_BUFFER);
907 GlobalUnlock(lppd->hDevMode);
909 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
911 if(!(lppd->Flags & PD_PRINTSETUP)) {
912 /* Print range (All/Range/Selection) */
913 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
914 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
915 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
916 if (lppd->Flags & PD_NOSELECTION)
917 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
919 if (lppd->Flags & PD_SELECTION)
920 CheckRadioButton(hDlg, rad1, rad3, rad2);
921 if (lppd->Flags & PD_NOPAGENUMS) {
922 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
923 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
924 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
925 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
926 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
928 if (lppd->Flags & PD_PAGENUMS)
929 CheckRadioButton(hDlg, rad1, rad3, rad3);
934 * FIXME: The ico3 is not displayed for some reason. I don't know why.
936 if (lppd->Flags & PD_COLLATE) {
937 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
938 (LPARAM)PrintStructures->hCollateIcon);
939 CheckDlgButton(hDlg, chx2, 1);
941 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
942 (LPARAM)PrintStructures->hNoCollateIcon);
943 CheckDlgButton(hDlg, chx2, 0);
946 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
947 /* if printer doesn't support it: no Collate */
948 if (!(lpdm->dmFields & DM_COLLATE)) {
949 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
950 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
957 if (lppd->hDevMode == 0)
958 copies = lppd->nCopies;
960 copies = lpdm->dmCopies;
961 if(copies == 0) copies = 1;
962 else if(copies < 0) copies = MAX_COPIES;
963 SetDlgItemInt(hDlg, edt3, copies, FALSE);
966 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
967 /* if printer doesn't support it: no nCopies */
968 if (!(lpdm->dmFields & DM_COPIES)) {
969 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
970 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
975 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
976 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
977 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
978 if (lppd->Flags & PD_HIDEPRINTTOFILE)
979 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
981 } else { /* PD_PRINTSETUP */
982 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
984 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb2,
985 PrintStructures->lpPrinterInfo->pPrinterName,
986 PrintStructures->lpPrinterInfo->pPortName,
988 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb3,
989 PrintStructures->lpPrinterInfo->pPrinterName,
990 PrintStructures->lpPrinterInfo->pPortName,
992 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
993 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
994 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
995 PrintStructures->hLandscapeIcon));
1000 if ((lppd->Flags & PD_SHOWHELP)==0) {
1001 /* hide if PD_SHOWHELP not specified */
1002 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1007 static BOOL PRINTDLG_ChangePrinterW(HWND hDlg, WCHAR *name,
1008 PRINT_PTRW *PrintStructures)
1010 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1011 LPDEVMODEW lpdm = NULL;
1016 if(PrintStructures->lpPrinterInfo)
1017 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
1018 if(PrintStructures->lpDriverInfo)
1019 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
1020 if(!OpenPrinterW(name, &hprn, NULL)) {
1021 ERR("Can't open printer %s\n", debugstr_w(name));
1024 GetPrinterW(hprn, 2, NULL, 0, &needed);
1025 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
1026 GetPrinterW(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
1028 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
1029 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
1030 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
1032 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures->lpPrinterInfo->pPrinterName));
1037 PRINTDLG_UpdatePrinterInfoTextsW(hDlg, PrintStructures->lpPrinterInfo);
1039 if(PrintStructures->lpDevMode) {
1040 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
1041 PrintStructures->lpDevMode = NULL;
1044 dmSize = DocumentPropertiesW(0, 0, name, NULL, NULL, 0);
1046 ERR("DocumentProperties fails on %s\n", debugstr_w(name));
1049 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
1050 dmSize = DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, NULL,
1052 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
1053 !lstrcmpW(lpdm->dmDeviceName,
1054 PrintStructures->lpDevMode->dmDeviceName)) {
1055 /* Supplied devicemode matches current printer so try to use it */
1056 DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, lpdm,
1057 DM_OUT_BUFFER | DM_IN_BUFFER);
1060 GlobalUnlock(lppd->hDevMode);
1062 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
1064 if(!(lppd->Flags & PD_PRINTSETUP)) {
1065 /* Print range (All/Range/Selection) */
1066 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
1067 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
1068 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
1069 if (lppd->Flags & PD_NOSELECTION)
1070 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
1072 if (lppd->Flags & PD_SELECTION)
1073 CheckRadioButton(hDlg, rad1, rad3, rad2);
1074 if (lppd->Flags & PD_NOPAGENUMS) {
1075 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
1076 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
1077 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
1078 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
1079 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
1081 if (lppd->Flags & PD_PAGENUMS)
1082 CheckRadioButton(hDlg, rad1, rad3, rad3);
1087 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1089 if (lppd->Flags & PD_COLLATE) {
1090 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1091 (LPARAM)PrintStructures->hCollateIcon);
1092 CheckDlgButton(hDlg, chx2, 1);
1094 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1095 (LPARAM)PrintStructures->hNoCollateIcon);
1096 CheckDlgButton(hDlg, chx2, 0);
1099 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1100 /* if printer doesn't support it: no Collate */
1101 if (!(lpdm->dmFields & DM_COLLATE)) {
1102 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1103 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
1110 if (lppd->hDevMode == 0)
1111 copies = lppd->nCopies;
1113 copies = lpdm->dmCopies;
1114 if(copies == 0) copies = 1;
1115 else if(copies < 0) copies = MAX_COPIES;
1116 SetDlgItemInt(hDlg, edt3, copies, FALSE);
1119 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1120 /* if printer doesn't support it: no nCopies */
1121 if (!(lpdm->dmFields & DM_COPIES)) {
1122 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
1123 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
1128 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
1129 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
1130 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
1131 if (lppd->Flags & PD_HIDEPRINTTOFILE)
1132 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
1134 } else { /* PD_PRINTSETUP */
1135 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
1137 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb2,
1138 PrintStructures->lpPrinterInfo->pPrinterName,
1139 PrintStructures->lpPrinterInfo->pPortName,
1141 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb3,
1142 PrintStructures->lpPrinterInfo->pPrinterName,
1143 PrintStructures->lpPrinterInfo->pPortName,
1145 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1146 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1147 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1148 PrintStructures->hLandscapeIcon));
1153 if ((lppd->Flags & PD_SHOWHELP)==0) {
1154 /* hide if PD_SHOWHELP not specified */
1155 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1160 /***********************************************************************
1161 * PRINTDLG_WMInitDialog [internal]
1163 static LRESULT PRINTDLG_WMInitDialog(HWND hDlg, WPARAM wParam,
1164 PRINT_PTRA* PrintStructures)
1166 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
1170 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1172 /* load Collate ICONs */
1173 /* We load these with LoadImage because they are not a standard
1174 size and we don't want them rescaled */
1175 PrintStructures->hCollateIcon =
1176 LoadImageA(COMDLG32_hInstance, "PD32_COLLATE", IMAGE_ICON, 0, 0, 0);
1177 PrintStructures->hNoCollateIcon =
1178 LoadImageA(COMDLG32_hInstance, "PD32_NOCOLLATE", IMAGE_ICON, 0, 0, 0);
1180 /* These can be done with LoadIcon */
1181 PrintStructures->hPortraitIcon =
1182 LoadIconA(COMDLG32_hInstance, "PD32_PORTRAIT");
1183 PrintStructures->hLandscapeIcon =
1184 LoadIconA(COMDLG32_hInstance, "PD32_LANDSCAPE");
1186 /* display the collate/no_collate icon */
1187 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1188 (LPARAM)PrintStructures->hNoCollateIcon);
1190 if(PrintStructures->hCollateIcon == 0 ||
1191 PrintStructures->hNoCollateIcon == 0 ||
1192 PrintStructures->hPortraitIcon == 0 ||
1193 PrintStructures->hLandscapeIcon == 0) {
1194 ERR("no icon in resourcefile\n");
1195 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1196 EndDialog(hDlg, FALSE);
1200 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1201 * must be registered and the Help button must be shown.
1203 if (lppd->Flags & PD_SHOWHELP) {
1204 if((PrintStructures->HelpMessageID =
1205 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
1206 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1210 PrintStructures->HelpMessageID = 0;
1212 if(!(lppd->Flags &PD_PRINTSETUP)) {
1213 PrintStructures->hwndUpDown =
1214 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1215 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1216 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1217 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1218 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1221 /* FIXME: I allow more freedom than either Win95 or WinNT,
1222 * which do not agree to what errors should be thrown or not
1223 * in case nToPage or nFromPage is out-of-range.
1225 if (lppd->nMaxPage < lppd->nMinPage)
1226 lppd->nMaxPage = lppd->nMinPage;
1227 if (lppd->nMinPage == lppd->nMaxPage)
1228 lppd->Flags |= PD_NOPAGENUMS;
1229 if (lppd->nToPage < lppd->nMinPage)
1230 lppd->nToPage = lppd->nMinPage;
1231 if (lppd->nToPage > lppd->nMaxPage)
1232 lppd->nToPage = lppd->nMaxPage;
1233 if (lppd->nFromPage < lppd->nMinPage)
1234 lppd->nFromPage = lppd->nMinPage;
1235 if (lppd->nFromPage > lppd->nMaxPage)
1236 lppd->nFromPage = lppd->nMaxPage;
1238 /* if we have the combo box, fill it */
1239 if (GetDlgItem(hDlg,comboID)) {
1242 pdn = GlobalLock(lppd->hDevNames);
1243 pdm = GlobalLock(lppd->hDevMode);
1245 name = (char*)pdn + pdn->wDeviceOffset;
1247 name = pdm->dmDeviceName;
1248 PRINTDLG_SetUpPrinterListComboA(hDlg, comboID, name);
1249 if(pdm) GlobalUnlock(lppd->hDevMode);
1250 if(pdn) GlobalUnlock(lppd->hDevNames);
1252 /* Now find selected printer and update rest of dlg */
1253 name = HeapAlloc(GetProcessHeap(),0,256);
1254 if (GetDlgItemTextA(hDlg, comboID, name, 255))
1255 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1256 HeapFree(GetProcessHeap(),0,name);
1258 /* else use default printer */
1260 DWORD dwBufLen = sizeof(name);
1261 BOOL ret = GetDefaultPrinterA(name, &dwBufLen);
1264 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1266 FIXME("No default printer found, expect problems!\n");
1271 static LRESULT PRINTDLG_WMInitDialogW(HWND hDlg, WPARAM wParam,
1272 PRINT_PTRW* PrintStructures)
1274 const static WCHAR PD32_COLLATE[] = { 'P', 'D', '3', '2', '_', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
1275 const static WCHAR PD32_NOCOLLATE[] = { 'P', 'D', '3', '2', '_', 'N', 'O', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
1276 const static WCHAR PD32_PORTRAIT[] = { 'P', 'D', '3', '2', '_', 'P', 'O', 'R', 'T', 'R', 'A', 'I', 'T', 0 };
1277 const static WCHAR PD32_LANDSCAPE[] = { 'P', 'D', '3', '2', '_', 'L', 'A', 'N', 'D', 'S', 'C', 'A', 'P', 'E', 0 };
1278 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1282 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1284 /* load Collate ICONs */
1285 /* We load these with LoadImage because they are not a standard
1286 size and we don't want them rescaled */
1287 PrintStructures->hCollateIcon =
1288 LoadImageW(COMDLG32_hInstance, PD32_COLLATE, IMAGE_ICON, 0, 0, 0);
1289 PrintStructures->hNoCollateIcon =
1290 LoadImageW(COMDLG32_hInstance, PD32_NOCOLLATE, IMAGE_ICON, 0, 0, 0);
1292 /* These can be done with LoadIcon */
1293 PrintStructures->hPortraitIcon =
1294 LoadIconW(COMDLG32_hInstance, PD32_PORTRAIT);
1295 PrintStructures->hLandscapeIcon =
1296 LoadIconW(COMDLG32_hInstance, PD32_LANDSCAPE);
1298 /* display the collate/no_collate icon */
1299 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1300 (LPARAM)PrintStructures->hNoCollateIcon);
1302 if(PrintStructures->hCollateIcon == 0 ||
1303 PrintStructures->hNoCollateIcon == 0 ||
1304 PrintStructures->hPortraitIcon == 0 ||
1305 PrintStructures->hLandscapeIcon == 0) {
1306 ERR("no icon in resourcefile\n");
1307 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1308 EndDialog(hDlg, FALSE);
1312 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1313 * must be registered and the Help button must be shown.
1315 if (lppd->Flags & PD_SHOWHELP) {
1316 if((PrintStructures->HelpMessageID =
1317 RegisterWindowMessageW(HELPMSGSTRINGW)) == 0) {
1318 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1322 PrintStructures->HelpMessageID = 0;
1324 if(!(lppd->Flags &PD_PRINTSETUP)) {
1325 PrintStructures->hwndUpDown =
1326 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1327 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1328 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1329 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1330 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1333 /* FIXME: I allow more freedom than either Win95 or WinNT,
1334 * which do not agree to what errors should be thrown or not
1335 * in case nToPage or nFromPage is out-of-range.
1337 if (lppd->nMaxPage < lppd->nMinPage)
1338 lppd->nMaxPage = lppd->nMinPage;
1339 if (lppd->nMinPage == lppd->nMaxPage)
1340 lppd->Flags |= PD_NOPAGENUMS;
1341 if (lppd->nToPage < lppd->nMinPage)
1342 lppd->nToPage = lppd->nMinPage;
1343 if (lppd->nToPage > lppd->nMaxPage)
1344 lppd->nToPage = lppd->nMaxPage;
1345 if (lppd->nFromPage < lppd->nMinPage)
1346 lppd->nFromPage = lppd->nMinPage;
1347 if (lppd->nFromPage > lppd->nMaxPage)
1348 lppd->nFromPage = lppd->nMaxPage;
1350 /* if we have the combo box, fill it */
1351 if (GetDlgItem(hDlg,comboID)) {
1354 pdn = GlobalLock(lppd->hDevNames);
1355 pdm = GlobalLock(lppd->hDevMode);
1357 name = (WCHAR*)pdn + pdn->wDeviceOffset;
1359 name = pdm->dmDeviceName;
1360 PRINTDLG_SetUpPrinterListComboW(hDlg, comboID, name);
1361 if(pdm) GlobalUnlock(lppd->hDevMode);
1362 if(pdn) GlobalUnlock(lppd->hDevNames);
1364 /* Now find selected printer and update rest of dlg */
1365 /* ansi is ok here */
1366 name = HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR));
1367 if (GetDlgItemTextW(hDlg, comboID, name, 255))
1368 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1369 HeapFree(GetProcessHeap(),0,name);
1371 /* else use default printer */
1373 DWORD dwBufLen = sizeof(name) / sizeof(WCHAR);
1374 BOOL ret = GetDefaultPrinterW(name, &dwBufLen);
1377 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1379 FIXME("No default printer found, expect problems!\n");
1384 /***********************************************************************
1385 * PRINTDLG_WMCommand [internal]
1387 LRESULT PRINTDLG_WMCommandA(HWND hDlg, WPARAM wParam,
1388 LPARAM lParam, PRINT_PTRA* PrintStructures)
1390 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
1391 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1392 LPDEVMODEA lpdm = PrintStructures->lpDevMode;
1394 switch (LOWORD(wParam)) {
1396 TRACE(" OK button was hit\n");
1397 if (!PRINTDLG_UpdatePrintDlgA(hDlg, PrintStructures)) {
1398 FIXME("Update printdlg was not successful!\n");
1401 EndDialog(hDlg, TRUE);
1405 TRACE(" CANCEL button was hit\n");
1406 EndDialog(hDlg, FALSE);
1410 TRACE(" HELP button was hit\n");
1411 SendMessageA(lppd->hwndOwner, PrintStructures->HelpMessageID,
1412 (WPARAM) hDlg, (LPARAM) lppd);
1415 case chx2: /* collate pages checkbox */
1416 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1417 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1418 (LPARAM)PrintStructures->hCollateIcon);
1420 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1421 (LPARAM)PrintStructures->hNoCollateIcon);
1423 case edt1: /* from page nr editbox */
1424 case edt2: /* to page nr editbox */
1425 if (HIWORD(wParam)==EN_CHANGE) {
1428 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1429 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1430 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1431 CheckRadioButton(hDlg, rad1, rad3, rad3);
1436 if(HIWORD(wParam) == EN_CHANGE) {
1437 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1439 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1441 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1446 case psh1: /* Print Setup */
1450 if (!PrintStructures->dlg.lpPrintDlg16) {
1451 FIXME("The 32bit print dialog does not have this button!?\n");
1455 memcpy(&pdlg,PrintStructures->dlg.lpPrintDlg16,sizeof(pdlg));
1456 pdlg.Flags |= PD_PRINTSETUP;
1457 pdlg.hwndOwner = HWND_16(hDlg);
1458 if (!PrintDlg16(&pdlg))
1463 case psh2: /* Properties button */
1466 char PrinterName[256];
1468 GetDlgItemTextA(hDlg, PrinterComboID, PrinterName, 255);
1469 if (!OpenPrinterA(PrinterName, &hPrinter, NULL)) {
1470 FIXME(" Call to OpenPrinter did not succeed!\n");
1473 DocumentPropertiesA(hDlg, hPrinter, PrinterName,
1474 PrintStructures->lpDevMode,
1475 PrintStructures->lpDevMode,
1476 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1477 ClosePrinter(hPrinter);
1481 case rad1: /* Paperorientation */
1482 if (lppd->Flags & PD_PRINTSETUP)
1484 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1485 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1486 (LPARAM)(PrintStructures->hPortraitIcon));
1490 case rad2: /* Paperorientation */
1491 if (lppd->Flags & PD_PRINTSETUP)
1493 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1494 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1495 (LPARAM)(PrintStructures->hLandscapeIcon));
1499 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1500 if (PrinterComboID != LOWORD(wParam)) {
1501 FIXME("No handling for print quality combo box yet.\n");
1505 case cmb4: /* Printer combobox */
1506 if (HIWORD(wParam)==CBN_SELCHANGE) {
1507 char PrinterName[256];
1508 GetDlgItemTextA(hDlg, LOWORD(wParam), PrinterName, 255);
1509 PRINTDLG_ChangePrinterA(hDlg, PrinterName, PrintStructures);
1513 case cmb2: /* Papersize */
1515 DWORD Sel = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1517 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
1523 case cmb3: /* Bin */
1525 DWORD Sel = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1527 lpdm->dmDefaultSource = SendDlgItemMessageA(hDlg, cmb3,
1528 CB_GETITEMDATA, Sel,
1533 if(lppd->Flags & PD_PRINTSETUP) {
1534 switch (LOWORD(wParam)) {
1535 case rad1: /* orientation */
1537 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1538 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1539 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1540 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1542 (LPARAM)PrintStructures->hPortraitIcon);
1543 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1545 (LPARAM)PrintStructures->hPortraitIcon);
1548 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1549 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1550 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1552 (LPARAM)PrintStructures->hLandscapeIcon);
1553 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1555 (LPARAM)PrintStructures->hLandscapeIcon);
1564 static LRESULT PRINTDLG_WMCommandW(HWND hDlg, WPARAM wParam,
1565 LPARAM lParam, PRINT_PTRW* PrintStructures)
1567 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1568 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1569 LPDEVMODEW lpdm = PrintStructures->lpDevMode;
1571 switch (LOWORD(wParam)) {
1573 TRACE(" OK button was hit\n");
1574 if (!PRINTDLG_UpdatePrintDlgW(hDlg, PrintStructures)) {
1575 FIXME("Update printdlg was not successful!\n");
1578 EndDialog(hDlg, TRUE);
1582 TRACE(" CANCEL button was hit\n");
1583 EndDialog(hDlg, FALSE);
1587 TRACE(" HELP button was hit\n");
1588 SendMessageW(lppd->hwndOwner, PrintStructures->HelpMessageID,
1589 (WPARAM) hDlg, (LPARAM) lppd);
1592 case chx2: /* collate pages checkbox */
1593 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1594 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1595 (LPARAM)PrintStructures->hCollateIcon);
1597 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1598 (LPARAM)PrintStructures->hNoCollateIcon);
1600 case edt1: /* from page nr editbox */
1601 case edt2: /* to page nr editbox */
1602 if (HIWORD(wParam)==EN_CHANGE) {
1605 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1606 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1607 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1608 CheckRadioButton(hDlg, rad1, rad3, rad3);
1613 if(HIWORD(wParam) == EN_CHANGE) {
1614 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1616 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1618 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1622 case psh1: /* Print Setup */
1624 ERR("psh1 is called from 16bit code only, we should not get here.\n");
1627 case psh2: /* Properties button */
1630 WCHAR PrinterName[256];
1632 if (!GetDlgItemTextW(hDlg, PrinterComboID, PrinterName, 255)) break;
1633 if (!OpenPrinterW(PrinterName, &hPrinter, NULL)) {
1634 FIXME(" Call to OpenPrinter did not succeed!\n");
1637 DocumentPropertiesW(hDlg, hPrinter, PrinterName,
1638 PrintStructures->lpDevMode,
1639 PrintStructures->lpDevMode,
1640 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1641 ClosePrinter(hPrinter);
1645 case rad1: /* Paperorientation */
1646 if (lppd->Flags & PD_PRINTSETUP)
1648 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1649 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1650 (LPARAM)(PrintStructures->hPortraitIcon));
1654 case rad2: /* Paperorientation */
1655 if (lppd->Flags & PD_PRINTSETUP)
1657 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1658 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1659 (LPARAM)(PrintStructures->hLandscapeIcon));
1663 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1664 if (PrinterComboID != LOWORD(wParam)) {
1665 FIXME("No handling for print quality combo box yet.\n");
1669 case cmb4: /* Printer combobox */
1670 if (HIWORD(wParam)==CBN_SELCHANGE) {
1671 WCHAR PrinterName[256];
1672 GetDlgItemTextW(hDlg, LOWORD(wParam), PrinterName, 255);
1673 PRINTDLG_ChangePrinterW(hDlg, PrinterName, PrintStructures);
1677 case cmb2: /* Papersize */
1679 DWORD Sel = SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1681 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageW(hDlg, cmb2,
1687 case cmb3: /* Bin */
1689 DWORD Sel = SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1691 lpdm->dmDefaultSource = SendDlgItemMessageW(hDlg, cmb3,
1692 CB_GETITEMDATA, Sel,
1697 if(lppd->Flags & PD_PRINTSETUP) {
1698 switch (LOWORD(wParam)) {
1699 case rad1: /* orientation */
1701 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1702 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1703 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1704 SendDlgItemMessageW(hDlg, stc10, STM_SETIMAGE,
1706 (LPARAM)PrintStructures->hPortraitIcon);
1707 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE,
1709 (LPARAM)PrintStructures->hPortraitIcon);
1712 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1713 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1714 SendDlgItemMessageW(hDlg, stc10, STM_SETIMAGE,
1716 (LPARAM)PrintStructures->hLandscapeIcon);
1717 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE,
1719 (LPARAM)PrintStructures->hLandscapeIcon);
1728 /***********************************************************************
1729 * PrintDlgProcA [internal]
1731 static INT_PTR CALLBACK PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
1734 PRINT_PTRA* PrintStructures;
1735 INT_PTR res = FALSE;
1737 if (uMsg!=WM_INITDIALOG) {
1738 PrintStructures = (PRINT_PTRA*)GetPropA(hDlg,"__WINE_PRINTDLGDATA");
1739 if (!PrintStructures)
1742 PrintStructures = (PRINT_PTRA*) lParam;
1743 SetPropA(hDlg,"__WINE_PRINTDLGDATA",PrintStructures);
1744 res = PRINTDLG_WMInitDialog(hDlg, wParam, PrintStructures);
1746 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
1747 res = PrintStructures->lpPrintDlg->lpfnPrintHook(
1748 hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg
1753 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
1754 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam,
1761 return PRINTDLG_WMCommandA(hDlg, wParam, lParam, PrintStructures);
1764 DestroyIcon(PrintStructures->hCollateIcon);
1765 DestroyIcon(PrintStructures->hNoCollateIcon);
1766 DestroyIcon(PrintStructures->hPortraitIcon);
1767 DestroyIcon(PrintStructures->hLandscapeIcon);
1768 if(PrintStructures->hwndUpDown)
1769 DestroyWindow(PrintStructures->hwndUpDown);
1775 static INT_PTR CALLBACK PrintDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
1778 static const WCHAR propW[] = {'_','_','W','I','N','E','_','P','R','I','N','T','D','L','G','D','A','T','A',0};
1779 PRINT_PTRW* PrintStructures;
1780 INT_PTR res = FALSE;
1782 if (uMsg!=WM_INITDIALOG) {
1783 PrintStructures = (PRINT_PTRW*) GetPropW(hDlg, propW);
1784 if (!PrintStructures)
1787 PrintStructures = (PRINT_PTRW*) lParam;
1788 SetPropW(hDlg, propW, PrintStructures);
1789 res = PRINTDLG_WMInitDialogW(hDlg, wParam, PrintStructures);
1791 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
1792 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg);
1796 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
1797 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam, lParam);
1803 return PRINTDLG_WMCommandW(hDlg, wParam, lParam, PrintStructures);
1806 DestroyIcon(PrintStructures->hCollateIcon);
1807 DestroyIcon(PrintStructures->hNoCollateIcon);
1808 DestroyIcon(PrintStructures->hPortraitIcon);
1809 DestroyIcon(PrintStructures->hLandscapeIcon);
1810 if(PrintStructures->hwndUpDown)
1811 DestroyWindow(PrintStructures->hwndUpDown);
1817 /************************************************************
1819 * PRINTDLG_GetDlgTemplate
1822 static HGLOBAL PRINTDLG_GetDlgTemplateA(PRINTDLGA *lppd)
1827 if (lppd->Flags & PD_PRINTSETUP) {
1828 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
1829 hDlgTmpl = lppd->hSetupTemplate;
1830 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
1831 hResInfo = FindResourceA(lppd->hInstance,
1832 lppd->lpSetupTemplateName, (LPSTR)RT_DIALOG);
1833 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1835 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32_SETUP",
1837 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1840 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
1841 hDlgTmpl = lppd->hPrintTemplate;
1842 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
1843 hResInfo = FindResourceA(lppd->hInstance,
1844 lppd->lpPrintTemplateName,
1846 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1848 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32",
1850 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1856 static HGLOBAL PRINTDLG_GetDlgTemplateW(PRINTDLGW *lppd)
1860 static const WCHAR xpsetup[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
1861 static const WCHAR xprint[] = { 'P','R','I','N','T','3','2',0};
1863 if (lppd->Flags & PD_PRINTSETUP) {
1864 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
1865 hDlgTmpl = lppd->hSetupTemplate;
1866 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
1867 hResInfo = FindResourceW(lppd->hInstance,
1868 lppd->lpSetupTemplateName, (LPWSTR)RT_DIALOG);
1869 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1871 hResInfo = FindResourceW(COMDLG32_hInstance, xpsetup, (LPWSTR)RT_DIALOG);
1872 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1875 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
1876 hDlgTmpl = lppd->hPrintTemplate;
1877 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
1878 hResInfo = FindResourceW(lppd->hInstance,
1879 lppd->lpPrintTemplateName,
1881 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1883 hResInfo = FindResourceW(COMDLG32_hInstance, xprint, (LPWSTR)RT_DIALOG);
1884 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1890 /***********************************************************************
1895 static BOOL PRINTDLG_CreateDCA(LPPRINTDLGA lppd)
1897 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
1898 DEVMODEA *pdm = GlobalLock(lppd->hDevMode);
1900 if(lppd->Flags & PD_RETURNDC) {
1901 lppd->hDC = CreateDCA((char*)pdn + pdn->wDriverOffset,
1902 (char*)pdn + pdn->wDeviceOffset,
1903 (char*)pdn + pdn->wOutputOffset,
1905 } else if(lppd->Flags & PD_RETURNIC) {
1906 lppd->hDC = CreateICA((char*)pdn + pdn->wDriverOffset,
1907 (char*)pdn + pdn->wDeviceOffset,
1908 (char*)pdn + pdn->wOutputOffset,
1911 GlobalUnlock(lppd->hDevNames);
1912 GlobalUnlock(lppd->hDevMode);
1913 return lppd->hDC ? TRUE : FALSE;
1916 static BOOL PRINTDLG_CreateDCW(LPPRINTDLGW lppd)
1918 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
1919 DEVMODEW *pdm = GlobalLock(lppd->hDevMode);
1921 if(lppd->Flags & PD_RETURNDC) {
1922 lppd->hDC = CreateDCW((WCHAR*)pdn + pdn->wDriverOffset,
1923 (WCHAR*)pdn + pdn->wDeviceOffset,
1924 (WCHAR*)pdn + pdn->wOutputOffset,
1926 } else if(lppd->Flags & PD_RETURNIC) {
1927 lppd->hDC = CreateICW((WCHAR*)pdn + pdn->wDriverOffset,
1928 (WCHAR*)pdn + pdn->wDeviceOffset,
1929 (WCHAR*)pdn + pdn->wOutputOffset,
1932 GlobalUnlock(lppd->hDevNames);
1933 GlobalUnlock(lppd->hDevMode);
1934 return lppd->hDC ? TRUE : FALSE;
1937 /***********************************************************************
1938 * PrintDlgA (COMDLG32.@)
1940 * Displays the the PRINT dialog box, which enables the user to specify
1941 * specific properties of the print job.
1944 * nonzero if the user pressed the OK button
1945 * zero if the user cancelled the window or an error occurred
1949 * * The Collate Icons do not display, even though they are in the code.
1950 * * The Properties Button(s) should call DocumentPropertiesA().
1952 * * The Paper Orientation Icons are not implemented yet.
1953 * * The Properties Button(s) should call DocumentPropertiesA().
1954 * * Settings are not yet taken from a provided DevMode or
1955 * default printer settings.
1958 BOOL WINAPI PrintDlgA(
1959 LPPRINTDLGA lppd /* [in/out] ptr to PRINTDLG32 struct */
1964 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrA( lppd->hwndOwner, GWLP_HINSTANCE );
1966 if(TRACE_ON(commdlg)) {
1967 char flagstr[1000] = "";
1968 struct pd_flags *pflag = pd_flags;
1969 for( ; pflag->name; pflag++) {
1970 if(lppd->Flags & pflag->flag)
1971 strcat(flagstr, pflag->name);
1973 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
1974 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
1975 "flags %08lx (%s)\n",
1976 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
1977 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
1978 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
1981 if(lppd->lStructSize != sizeof(PRINTDLGA)) {
1982 WARN("structure size failure !!!\n");
1983 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
1987 if(lppd->Flags & PD_RETURNDEFAULT) {
1988 PRINTER_INFO_2A *pbuf;
1989 DRIVER_INFO_3A *dbuf;
1993 if(lppd->hDevMode || lppd->hDevNames) {
1994 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
1995 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
1998 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
1999 WARN("Can't find default printer\n");
2000 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2004 GetPrinterA(hprn, 2, NULL, 0, &needed);
2005 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
2006 GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2008 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
2009 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
2010 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2011 ERR("GetPrinterDriverA failed, le %ld, fix your config for printer %s!\n",GetLastError(),pbuf->pPrinterName);
2012 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2017 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2021 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2022 pbuf->pDevMode->dmDriverExtra);
2023 ptr = GlobalLock(lppd->hDevMode);
2024 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2025 pbuf->pDevMode->dmDriverExtra);
2026 GlobalUnlock(lppd->hDevMode);
2027 HeapFree(GetProcessHeap(), 0, pbuf);
2028 HeapFree(GetProcessHeap(), 0, dbuf);
2032 PRINT_PTRA *PrintStructures;
2034 /* load Dialog resources,
2035 * depending on Flags indicates Print32 or Print32_setup dialog
2037 hDlgTmpl = PRINTDLG_GetDlgTemplateA(lppd);
2039 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2042 ptr = LockResource( hDlgTmpl );
2044 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2048 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2049 sizeof(PRINT_PTRA));
2050 PrintStructures->lpPrintDlg = lppd;
2052 /* and create & process the dialog .
2053 * -1 is failure, 0 is broken hwnd, everything else is ok.
2055 bRet = (0<DialogBoxIndirectParamA(hInst, ptr, lppd->hwndOwner,
2057 (LPARAM)PrintStructures));
2060 DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2061 PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
2062 DRIVER_INFO_3A *di = PrintStructures->lpDriverInfo;
2064 if (lppd->hDevMode == 0) {
2065 TRACE(" No hDevMode yet... Need to create my own\n");
2066 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2067 lpdm->dmSize + lpdm->dmDriverExtra);
2070 if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
2071 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2073 GlobalUnlock(lppd->hDevMode);
2074 TRACE("Now got %d locks\n", locks);
2077 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2078 lpdm->dmSize + lpdm->dmDriverExtra,
2081 lpdmReturn = GlobalLock(lppd->hDevMode);
2082 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2084 if (lppd->hDevNames != 0) {
2086 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
2087 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2089 GlobalUnlock(lppd->hDevNames);
2092 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2097 GlobalUnlock(lppd->hDevMode);
2099 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2100 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2101 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2102 HeapFree(GetProcessHeap(), 0, PrintStructures);
2104 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2105 bRet = PRINTDLG_CreateDCA(lppd);
2107 TRACE("exit! (%d)\n", bRet);
2111 /***********************************************************************
2112 * PrintDlgW (COMDLG32.@)
2114 BOOL WINAPI PrintDlgW(
2115 LPPRINTDLGW lppd /* [in/out] ptr to PRINTDLG32 struct */
2120 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW( lppd->hwndOwner, GWLP_HINSTANCE );
2122 if(TRACE_ON(commdlg)) {
2123 char flagstr[1000] = "";
2124 struct pd_flags *pflag = pd_flags;
2125 for( ; pflag->name; pflag++) {
2126 if(lppd->Flags & pflag->flag)
2127 strcat(flagstr, pflag->name);
2129 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2130 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2131 "flags %08lx (%s)\n",
2132 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2133 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2134 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2137 if(lppd->lStructSize != sizeof(PRINTDLGW)) {
2138 WARN("structure size failure !!!\n");
2139 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2143 if(lppd->Flags & PD_RETURNDEFAULT) {
2144 PRINTER_INFO_2W *pbuf;
2145 DRIVER_INFO_3W *dbuf;
2149 if(lppd->hDevMode || lppd->hDevNames) {
2150 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2151 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2154 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2155 WARN("Can't find default printer\n");
2156 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2160 GetPrinterW(hprn, 2, NULL, 0, &needed);
2161 pbuf = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*needed);
2162 GetPrinterW(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2164 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
2165 dbuf = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
2166 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2167 ERR("GetPrinterDriverA failed, le %ld, fix your config for printer %s!\n",GetLastError(),debugstr_w(pbuf->pPrinterName));
2168 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2173 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2177 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2178 pbuf->pDevMode->dmDriverExtra);
2179 ptr = GlobalLock(lppd->hDevMode);
2180 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2181 pbuf->pDevMode->dmDriverExtra);
2182 GlobalUnlock(lppd->hDevMode);
2183 HeapFree(GetProcessHeap(), 0, pbuf);
2184 HeapFree(GetProcessHeap(), 0, dbuf);
2188 PRINT_PTRW *PrintStructures;
2190 /* load Dialog resources,
2191 * depending on Flags indicates Print32 or Print32_setup dialog
2193 hDlgTmpl = PRINTDLG_GetDlgTemplateW(lppd);
2195 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2198 ptr = LockResource( hDlgTmpl );
2200 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2204 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2205 sizeof(PRINT_PTRW));
2206 PrintStructures->lpPrintDlg = lppd;
2208 /* and create & process the dialog .
2209 * -1 is failure, 0 is broken hwnd, everything else is ok.
2211 bRet = (0<DialogBoxIndirectParamW(hInst, ptr, lppd->hwndOwner,
2213 (LPARAM)PrintStructures));
2216 DEVMODEW *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2217 PRINTER_INFO_2W *pi = PrintStructures->lpPrinterInfo;
2218 DRIVER_INFO_3W *di = PrintStructures->lpDriverInfo;
2220 if (lppd->hDevMode == 0) {
2221 TRACE(" No hDevMode yet... Need to create my own\n");
2222 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2223 lpdm->dmSize + lpdm->dmDriverExtra);
2226 if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
2227 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2229 GlobalUnlock(lppd->hDevMode);
2230 TRACE("Now got %d locks\n", locks);
2233 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2234 lpdm->dmSize + lpdm->dmDriverExtra,
2237 lpdmReturn = GlobalLock(lppd->hDevMode);
2238 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2240 if (lppd->hDevNames != 0) {
2242 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
2243 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2245 GlobalUnlock(lppd->hDevNames);
2248 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2253 GlobalUnlock(lppd->hDevMode);
2255 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2256 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2257 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2258 HeapFree(GetProcessHeap(), 0, PrintStructures);
2260 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2261 bRet = PRINTDLG_CreateDCW(lppd);
2263 TRACE("exit! (%d)\n", bRet);
2267 /***********************************************************************
2273 * cmb3 - source (tray?)
2274 * edt4 - border left
2276 * edt6 - border right
2277 * edt7 - border bottom
2278 * psh3 - "Printer..."
2282 LPPAGESETUPDLGA dlga;
2287 LPPAGESETUPDLGW dlga;
2291 static HGLOBAL PRINTDLG_GetPGSTemplateA(PAGESETUPDLGA *lppd)
2296 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2297 hDlgTmpl = lppd->hPageSetupTemplate;
2298 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2299 hResInfo = FindResourceA(lppd->hInstance,
2300 lppd->lpPageSetupTemplateName, (LPSTR)RT_DIALOG);
2301 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2303 hResInfo = FindResourceA(COMDLG32_hInstance,(LPCSTR)PAGESETUPDLGORD,(LPSTR)RT_DIALOG);
2304 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2309 static HGLOBAL PRINTDLG_GetPGSTemplateW(PAGESETUPDLGW *lppd)
2314 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2315 hDlgTmpl = lppd->hPageSetupTemplate;
2316 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2317 hResInfo = FindResourceW(lppd->hInstance,
2318 lppd->lpPageSetupTemplateName, (LPWSTR)RT_DIALOG);
2319 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2321 hResInfo = FindResourceW(COMDLG32_hInstance,(LPCWSTR)PAGESETUPDLGORD,(LPWSTR)RT_DIALOG);
2322 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2328 _c_10mm2size(PAGESETUPDLGA *dlga,DWORD size) {
2329 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2330 return 10*size*10/25.4;
2331 /* If we don't have a flag, we can choose one. Use millimeters
2332 * to avoid confusing me
2334 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2340 _c_inch2size(PAGESETUPDLGA *dlga,DWORD size) {
2341 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2343 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
2344 return (size*254)/10;
2345 /* if we don't have a flag, we can choose one. Use millimeters
2346 * to avoid confusing me
2348 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2349 return (size*254)/10;
2353 _c_size2strA(PageSetupDataA *pda,DWORD size,LPSTR strout) {
2354 strcpy(strout,"<undef>");
2355 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2356 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
2359 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2360 sprintf(strout,"%.2fin",(size*1.0)/1000.0);
2363 pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2364 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
2368 _c_size2strW(PageSetupDataW *pda,DWORD size,LPWSTR strout) {
2369 const static WCHAR UNDEF[] = { '<', 'u', 'n', 'd', 'e', 'f', '>', 0 };
2370 const static WCHAR mm_fmt[] = { '%', '.', '2', 'f', 'm', 'm', 0 };
2371 const static WCHAR in_fmt[] = { '%', '.', '2', 'f', 'i', 'n', 0 };
2372 lstrcpyW(strout, UNDEF);
2373 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2374 wsprintfW(strout,mm_fmt,(size*1.0)/100.0);
2377 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2378 wsprintfW(strout,in_fmt,(size*1.0)/1000.0);
2381 pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2382 wsprintfW(strout,mm_fmt,(size*1.0)/100.0);
2387 _c_str2sizeA(PAGESETUPDLGA *dlga,LPCSTR strin) {
2392 if (!sscanf(strin,"%f%s",&val,rest))
2395 if (!strcmp(rest,"in") || !strcmp(rest,"inch")) {
2396 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2399 return val*25.4*100;
2401 if (!strcmp(rest,"cm")) { rest[0]='m'; val = val*10.0; }
2402 if (!strcmp(rest,"m")) { strcpy(rest,"mm"); val = val*1000.0; }
2404 if (!strcmp(rest,"mm")) {
2405 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
2408 return 1000.0*val/25.4;
2410 if (rest[0]=='\0') {
2411 /* use application supplied default */
2412 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2416 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2421 ERR("Did not find a conversion for type '%s'!\n",rest);
2427 _c_str2sizeW(PAGESETUPDLGW *dlga, LPCWSTR strin) {
2430 /* this W -> A transition is OK */
2431 /* we need a unicode version of sscanf to avoid it */
2432 WideCharToMultiByte(CP_ACP, 0, strin, -1, buf, sizeof(buf), NULL, NULL);
2433 return _c_str2sizeA((PAGESETUPDLGA *)dlga, buf);
2438 * This is called on finish and will update the output fields of the
2442 PRINTDLG_PS_UpdateDlgStructA(HWND hDlg, PageSetupDataA *pda) {
2445 LPSTR devname,portname;
2449 dn = GlobalLock(pda->pdlg.hDevNames);
2450 dm = GlobalLock(pda->pdlg.hDevMode);
2451 devname = ((char*)dn)+dn->wDeviceOffset;
2452 portname = ((char*)dn)+dn->wOutputOffset;
2453 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb2,devname,portname,dm);
2454 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb3,devname,portname,dm);
2456 if (GetDlgItemTextA(hDlg,cmb2,papername,sizeof(papername))>0) {
2457 PRINTDLG_PaperSizeA(&(pda->pdlg),papername,&(pda->dlga->ptPaperSize));
2458 pda->dlga->ptPaperSize.x = _c_10mm2size(pda->dlga,pda->dlga->ptPaperSize.x);
2459 pda->dlga->ptPaperSize.y = _c_10mm2size(pda->dlga,pda->dlga->ptPaperSize.y);
2461 FIXME("could not get dialog text for papersize cmbbox?\n");
2462 #define GETVAL(id,val) if (GetDlgItemTextA(hDlg,id,buf,sizeof(buf))>0) { val = _c_str2sizeA(pda->dlga,buf); } else { FIXME("could not get dlgitemtexta for %x\n",id); }
2463 GETVAL(edt4,pda->dlga->rtMargin.left);
2464 GETVAL(edt5,pda->dlga->rtMargin.top);
2465 GETVAL(edt6,pda->dlga->rtMargin.right);
2466 GETVAL(edt7,pda->dlga->rtMargin.bottom);
2469 /* If we are in landscape, swap x and y of page size */
2470 if (IsDlgButtonChecked(hDlg, rad2)) {
2472 tmp = pda->dlga->ptPaperSize.x;
2473 pda->dlga->ptPaperSize.x = pda->dlga->ptPaperSize.y;
2474 pda->dlga->ptPaperSize.y = tmp;
2476 GlobalUnlock(pda->pdlg.hDevNames);
2477 GlobalUnlock(pda->pdlg.hDevMode);
2482 PRINTDLG_PS_UpdateDlgStructW(HWND hDlg, PageSetupDataW *pda) {
2485 LPWSTR devname,portname;
2486 WCHAR papername[64];
2489 dn = GlobalLock(pda->pdlg.hDevNames);
2490 dm = GlobalLock(pda->pdlg.hDevMode);
2491 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
2492 portname = ((WCHAR*)dn)+dn->wOutputOffset;
2493 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
2494 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
2496 if (GetDlgItemTextW(hDlg,cmb2,papername,sizeof(papername))>0) {
2497 PRINTDLG_PaperSizeW(&(pda->pdlg),papername,&(pda->dlga->ptPaperSize));
2498 pda->dlga->ptPaperSize.x = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga,pda->dlga->ptPaperSize.x);
2499 pda->dlga->ptPaperSize.y = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga,pda->dlga->ptPaperSize.y);
2501 FIXME("could not get dialog text for papersize cmbbox?\n");
2502 #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); }
2503 GETVAL(edt4,pda->dlga->rtMargin.left);
2504 GETVAL(edt5,pda->dlga->rtMargin.top);
2505 GETVAL(edt6,pda->dlga->rtMargin.right);
2506 GETVAL(edt7,pda->dlga->rtMargin.bottom);
2509 /* If we are in landscape, swap x and y of page size */
2510 if (IsDlgButtonChecked(hDlg, rad2)) {
2512 tmp = pda->dlga->ptPaperSize.x;
2513 pda->dlga->ptPaperSize.x = pda->dlga->ptPaperSize.y;
2514 pda->dlga->ptPaperSize.y = tmp;
2516 GlobalUnlock(pda->pdlg.hDevNames);
2517 GlobalUnlock(pda->pdlg.hDevMode);
2522 * This is called after returning from PrintDlg().
2525 PRINTDLG_PS_ChangePrinterA(HWND hDlg, PageSetupDataA *pda) {
2528 LPSTR devname,portname;
2530 dn = GlobalLock(pda->pdlg.hDevNames);
2531 dm = GlobalLock(pda->pdlg.hDevMode);
2532 devname = ((char*)dn)+dn->wDeviceOffset;
2533 portname = ((char*)dn)+dn->wOutputOffset;
2534 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb2,devname,portname,dm);
2535 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb3,devname,portname,dm);
2536 GlobalUnlock(pda->pdlg.hDevNames);
2537 GlobalUnlock(pda->pdlg.hDevMode);
2542 PRINTDLG_PS_ChangePrinterW(HWND hDlg, PageSetupDataW *pda) {
2545 LPWSTR devname,portname;
2547 dn = GlobalLock(pda->pdlg.hDevNames);
2548 dm = GlobalLock(pda->pdlg.hDevMode);
2549 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
2550 portname = ((WCHAR*)dn)+dn->wOutputOffset;
2551 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
2552 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
2553 GlobalUnlock(pda->pdlg.hDevNames);
2554 GlobalUnlock(pda->pdlg.hDevMode);
2559 PRINTDLG_PS_WMCommandA(
2560 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataA *pda
2562 switch (LOWORD(wParam)) {
2564 if (!PRINTDLG_PS_UpdateDlgStructA(hDlg, pda))
2566 EndDialog(hDlg, TRUE);
2570 EndDialog(hDlg, FALSE);
2574 pda->pdlg.Flags = 0;
2575 pda->pdlg.hwndOwner = hDlg;
2576 if (PrintDlgA(&(pda->pdlg)))
2577 PRINTDLG_PS_ChangePrinterA(hDlg,pda);
2581 FIXME("loword (lparam) %d, wparam 0x%x, lparam %08lx, STUB mostly.\n",
2582 LOWORD(lParam),wParam,lParam
2588 PRINTDLG_PS_WMCommandW(
2589 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataW *pda
2591 switch (LOWORD(wParam)) {
2593 if (!PRINTDLG_PS_UpdateDlgStructW(hDlg, pda))
2595 EndDialog(hDlg, TRUE);
2599 EndDialog(hDlg, FALSE);
2603 pda->pdlg.Flags = 0;
2604 pda->pdlg.hwndOwner = hDlg;
2605 if (PrintDlgW(&(pda->pdlg)))
2606 PRINTDLG_PS_ChangePrinterW(hDlg,pda);
2610 FIXME("loword (lparam) %d, wparam 0x%x, lparam %08lx, STUB mostly.\n",
2611 LOWORD(lParam),wParam,lParam
2617 static INT_PTR CALLBACK
2618 PageDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
2620 PageSetupDataA *pda;
2621 INT_PTR res = FALSE;
2623 if (uMsg==WM_INITDIALOG) {
2625 pda = (PageSetupDataA*)lParam;
2626 SetPropA(hDlg,"__WINE_PAGESETUPDLGDATA",pda);
2627 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
2628 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,(LPARAM)pda->dlga);
2630 FIXME("Setup page hook failed?\n");
2634 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK) {
2635 FIXME("PagePaintHook not yet implemented!\n");
2637 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
2638 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
2639 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
2640 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
2641 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
2642 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
2643 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
2645 /* width larger as height -> landscape */
2646 if (pda->dlga->ptPaperSize.x > pda->dlga->ptPaperSize.y)
2647 CheckRadioButton(hDlg, rad1, rad2, rad2);
2648 else /* this is default if papersize is not set */
2649 CheckRadioButton(hDlg, rad1, rad2, rad1);
2650 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
2651 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
2652 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
2654 /* We fill them out enabled or not */
2655 if (pda->dlga->Flags & PSD_MARGINS) {
2657 _c_size2strA(pda,pda->dlga->rtMargin.left,str);
2658 SetDlgItemTextA(hDlg,edt4,str);
2659 _c_size2strA(pda,pda->dlga->rtMargin.top,str);
2660 SetDlgItemTextA(hDlg,edt5,str);
2661 _c_size2strA(pda,pda->dlga->rtMargin.right,str);
2662 SetDlgItemTextA(hDlg,edt6,str);
2663 _c_size2strA(pda,pda->dlga->rtMargin.bottom,str);
2664 SetDlgItemTextA(hDlg,edt7,str);
2666 /* default is 1 inch */
2667 DWORD size = _c_inch2size(pda->dlga,1000);
2669 _c_size2strA(pda,size,str);
2670 SetDlgItemTextA(hDlg,edt4,str);
2671 SetDlgItemTextA(hDlg,edt5,str);
2672 SetDlgItemTextA(hDlg,edt6,str);
2673 SetDlgItemTextA(hDlg,edt7,str);
2675 PRINTDLG_PS_ChangePrinterA(hDlg,pda);
2676 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
2677 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
2678 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
2682 pda = (PageSetupDataA*)GetPropA(hDlg,"__WINE_PAGESETUPDLGDATA");
2684 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
2687 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
2688 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
2689 if (res) return res;
2694 return PRINTDLG_PS_WMCommandA(hDlg, wParam, lParam, pda);
2699 static INT_PTR CALLBACK
2700 PageDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
2702 const static WCHAR __WINE_PAGESETUPDLGDATA[] =
2703 { '_', '_', 'W', 'I', 'N', 'E', '_', 'P', 'A', 'G', 'E',
2704 'S', 'E', 'T', 'U', 'P', 'D', 'L', 'G', 'D', 'A', 'T', 'A', 0 };
2705 PageSetupDataW *pda;
2708 if (uMsg==WM_INITDIALOG) {
2710 pda = (PageSetupDataW*)lParam;
2711 SetPropW(hDlg, __WINE_PAGESETUPDLGDATA, pda);
2712 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
2713 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,(LPARAM)pda->dlga);
2715 FIXME("Setup page hook failed?\n");
2719 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK) {
2720 FIXME("PagePaintHook not yet implemented!\n");
2722 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
2723 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
2724 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
2725 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
2726 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
2727 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
2728 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
2730 /* width larger as height -> landscape */
2731 if (pda->dlga->ptPaperSize.x > pda->dlga->ptPaperSize.y)
2732 CheckRadioButton(hDlg, rad1, rad2, rad2);
2733 else /* this is default if papersize is not set */
2734 CheckRadioButton(hDlg, rad1, rad2, rad1);
2735 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
2736 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
2737 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
2739 /* We fill them out enabled or not */
2740 if (pda->dlga->Flags & PSD_MARGINS) {
2742 _c_size2strW(pda,pda->dlga->rtMargin.left,str);
2743 SetDlgItemTextW(hDlg,edt4,str);
2744 _c_size2strW(pda,pda->dlga->rtMargin.top,str);
2745 SetDlgItemTextW(hDlg,edt5,str);
2746 _c_size2strW(pda,pda->dlga->rtMargin.right,str);
2747 SetDlgItemTextW(hDlg,edt6,str);
2748 _c_size2strW(pda,pda->dlga->rtMargin.bottom,str);
2749 SetDlgItemTextW(hDlg,edt7,str);
2751 /* default is 1 inch */
2752 DWORD size = _c_inch2size((LPPAGESETUPDLGA)pda->dlga,1000);
2754 _c_size2strW(pda,size,str);
2755 SetDlgItemTextW(hDlg,edt4,str);
2756 SetDlgItemTextW(hDlg,edt5,str);
2757 SetDlgItemTextW(hDlg,edt6,str);
2758 SetDlgItemTextW(hDlg,edt7,str);
2760 PRINTDLG_PS_ChangePrinterW(hDlg,pda);
2761 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
2762 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
2763 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
2767 pda = (PageSetupDataW*)GetPropW(hDlg, __WINE_PAGESETUPDLGDATA);
2769 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
2772 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
2773 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
2774 if (res) return res;
2779 return PRINTDLG_PS_WMCommandW(hDlg, wParam, lParam, pda);
2784 /***********************************************************************
2785 * PageSetupDlgA (COMDLG32.@)
2787 BOOL WINAPI PageSetupDlgA(LPPAGESETUPDLGA setupdlg) {
2791 PageSetupDataA *pda;
2794 if(TRACE_ON(commdlg)) {
2795 char flagstr[1000] = "";
2796 struct pd_flags *pflag = psd_flags;
2797 for( ; pflag->name; pflag++) {
2798 if(setupdlg->Flags & pflag->flag) {
2799 strcat(flagstr, pflag->name);
2800 strcat(flagstr, "|");
2803 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2804 "hinst %p, flags %08lx (%s)\n",
2805 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
2806 setupdlg->hDevNames,
2807 setupdlg->hInstance, setupdlg->Flags, flagstr);
2810 /* First get default printer data, we need it right after that. */
2811 memset(&pdlg,0,sizeof(pdlg));
2812 pdlg.lStructSize = sizeof(pdlg);
2813 pdlg.Flags = PD_RETURNDEFAULT;
2814 bRet = PrintDlgA(&pdlg);
2815 if (!bRet) return FALSE;
2817 /* short cut exit, just return default values */
2818 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
2819 setupdlg->hDevMode = pdlg.hDevMode;
2820 setupdlg->hDevNames = pdlg.hDevNames;
2821 /* FIXME: Just return "A4" for now. */
2822 PRINTDLG_PaperSizeA(&pdlg,"A4",&setupdlg->ptPaperSize);
2823 setupdlg->ptPaperSize.x=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.x);
2824 setupdlg->ptPaperSize.y=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.y);
2827 hDlgTmpl = PRINTDLG_GetPGSTemplateA(setupdlg);
2829 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2832 ptr = LockResource( hDlgTmpl );
2834 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2837 pda = HeapAlloc(GetProcessHeap(),0,sizeof(*pda));
2838 pda->dlga = setupdlg;
2839 memcpy(&pda->pdlg,&pdlg,sizeof(pdlg));
2841 bRet = (0<DialogBoxIndirectParamA(
2842 setupdlg->hInstance,
2844 setupdlg->hwndOwner,
2850 /***********************************************************************
2851 * PageSetupDlgW (COMDLG32.@)
2853 BOOL WINAPI PageSetupDlgW(LPPAGESETUPDLGW setupdlg) {
2857 PageSetupDataW *pdw;
2860 if(TRACE_ON(commdlg)) {
2861 char flagstr[1000] = "";
2862 struct pd_flags *pflag = psd_flags;
2863 for( ; pflag->name; pflag++) {
2864 if(setupdlg->Flags & pflag->flag) {
2865 strcat(flagstr, pflag->name);
2866 strcat(flagstr, "|");
2869 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2870 "hinst %p, flags %08lx (%s)\n",
2871 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
2872 setupdlg->hDevNames,
2873 setupdlg->hInstance, setupdlg->Flags, flagstr);
2876 /* First get default printer data, we need it right after that. */
2877 memset(&pdlg,0,sizeof(pdlg));
2878 pdlg.lStructSize = sizeof(pdlg);
2879 pdlg.Flags = PD_RETURNDEFAULT;
2880 bRet = PrintDlgW(&pdlg);
2881 if (!bRet) return FALSE;
2883 /* short cut exit, just return default values */
2884 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
2885 static const WCHAR a4[] = {'A','4',0};
2886 setupdlg->hDevMode = pdlg.hDevMode;
2887 setupdlg->hDevNames = pdlg.hDevNames;
2888 /* FIXME: Just return "A4" for now. */
2889 PRINTDLG_PaperSizeW(&pdlg,a4,&setupdlg->ptPaperSize);
2890 setupdlg->ptPaperSize.x=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.x);
2891 setupdlg->ptPaperSize.y=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.y);
2894 hDlgTmpl = PRINTDLG_GetPGSTemplateW(setupdlg);
2896 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2899 ptr = LockResource( hDlgTmpl );
2901 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2904 pdw = HeapAlloc(GetProcessHeap(),0,sizeof(*pdw));
2905 pdw->dlga = setupdlg;
2906 memcpy(&pdw->pdlg,&pdlg,sizeof(pdlg));
2908 bRet = (0<DialogBoxIndirectParamW(
2909 setupdlg->hInstance,
2911 setupdlg->hwndOwner,
2918 /***********************************************************************
2919 * PrintDlgExA (COMDLG32.@)
2921 HRESULT WINAPI PrintDlgExA(LPVOID lpPrintDlgExA) /* [???] FIXME: LPPRINTDLGEXA */
2926 /***********************************************************************
2927 * PrintDlgExW (COMDLG32.@)
2929 HRESULT WINAPI PrintDlgExW(LPVOID lpPrintDlgExW) /* [???] FIXME: LPPRINTDLGEXW */