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);
931 /* "All xxx pages"... */
933 char resourcestr[64];
935 LoadStringA(COMDLG32_hInstance, PD32_PRINT_ALL_X_PAGES,
937 sprintf(result,resourcestr,lppd->nMaxPage - lppd->nMinPage + 1);
938 SendDlgItemMessageA(hDlg, rad1, WM_SETTEXT, 0, (LPARAM) result);
943 * FIXME: The ico3 is not displayed for some reason. I don't know why.
945 if (lppd->Flags & PD_COLLATE) {
946 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
947 (LPARAM)PrintStructures->hCollateIcon);
948 CheckDlgButton(hDlg, chx2, 1);
950 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
951 (LPARAM)PrintStructures->hNoCollateIcon);
952 CheckDlgButton(hDlg, chx2, 0);
955 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
956 /* if printer doesn't support it: no Collate */
957 if (!(lpdm->dmFields & DM_COLLATE)) {
958 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
959 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
966 if (lppd->hDevMode == 0)
967 copies = lppd->nCopies;
969 copies = lpdm->dmCopies;
970 if(copies == 0) copies = 1;
971 else if(copies < 0) copies = MAX_COPIES;
972 SetDlgItemInt(hDlg, edt3, copies, FALSE);
975 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
976 /* if printer doesn't support it: no nCopies */
977 if (!(lpdm->dmFields & DM_COPIES)) {
978 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
979 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
984 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
985 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
986 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
987 if (lppd->Flags & PD_HIDEPRINTTOFILE)
988 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
990 } else { /* PD_PRINTSETUP */
991 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
993 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb2,
994 PrintStructures->lpPrinterInfo->pPrinterName,
995 PrintStructures->lpPrinterInfo->pPortName,
997 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb3,
998 PrintStructures->lpPrinterInfo->pPrinterName,
999 PrintStructures->lpPrinterInfo->pPortName,
1001 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1002 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1003 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1004 PrintStructures->hLandscapeIcon));
1009 if ((lppd->Flags & PD_SHOWHELP)==0) {
1010 /* hide if PD_SHOWHELP not specified */
1011 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1016 static BOOL PRINTDLG_ChangePrinterW(HWND hDlg, WCHAR *name,
1017 PRINT_PTRW *PrintStructures)
1019 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1020 LPDEVMODEW lpdm = NULL;
1025 if(PrintStructures->lpPrinterInfo)
1026 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
1027 if(PrintStructures->lpDriverInfo)
1028 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
1029 if(!OpenPrinterW(name, &hprn, NULL)) {
1030 ERR("Can't open printer %s\n", debugstr_w(name));
1033 GetPrinterW(hprn, 2, NULL, 0, &needed);
1034 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
1035 GetPrinterW(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
1037 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
1038 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
1039 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
1041 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures->lpPrinterInfo->pPrinterName));
1046 PRINTDLG_UpdatePrinterInfoTextsW(hDlg, PrintStructures->lpPrinterInfo);
1048 if(PrintStructures->lpDevMode) {
1049 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
1050 PrintStructures->lpDevMode = NULL;
1053 dmSize = DocumentPropertiesW(0, 0, name, NULL, NULL, 0);
1055 ERR("DocumentProperties fails on %s\n", debugstr_w(name));
1058 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
1059 dmSize = DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, NULL,
1061 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
1062 !lstrcmpW(lpdm->dmDeviceName,
1063 PrintStructures->lpDevMode->dmDeviceName)) {
1064 /* Supplied devicemode matches current printer so try to use it */
1065 DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, lpdm,
1066 DM_OUT_BUFFER | DM_IN_BUFFER);
1069 GlobalUnlock(lppd->hDevMode);
1071 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
1073 if(!(lppd->Flags & PD_PRINTSETUP)) {
1074 /* Print range (All/Range/Selection) */
1075 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
1076 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
1077 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
1078 if (lppd->Flags & PD_NOSELECTION)
1079 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
1081 if (lppd->Flags & PD_SELECTION)
1082 CheckRadioButton(hDlg, rad1, rad3, rad2);
1083 if (lppd->Flags & PD_NOPAGENUMS) {
1084 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
1085 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
1086 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
1087 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
1088 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
1090 if (lppd->Flags & PD_PAGENUMS)
1091 CheckRadioButton(hDlg, rad1, rad3, rad3);
1093 /* "All xxx pages"... */
1095 WCHAR resourcestr[64];
1097 LoadStringW(COMDLG32_hInstance, PD32_PRINT_ALL_X_PAGES,
1099 wsprintfW(result,resourcestr,lppd->nMaxPage - lppd->nMinPage + 1);
1100 SendDlgItemMessageW(hDlg, rad1, WM_SETTEXT, 0, (LPARAM) result);
1105 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1107 if (lppd->Flags & PD_COLLATE) {
1108 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1109 (LPARAM)PrintStructures->hCollateIcon);
1110 CheckDlgButton(hDlg, chx2, 1);
1112 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1113 (LPARAM)PrintStructures->hNoCollateIcon);
1114 CheckDlgButton(hDlg, chx2, 0);
1117 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1118 /* if printer doesn't support it: no Collate */
1119 if (!(lpdm->dmFields & DM_COLLATE)) {
1120 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1121 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
1128 if (lppd->hDevMode == 0)
1129 copies = lppd->nCopies;
1131 copies = lpdm->dmCopies;
1132 if(copies == 0) copies = 1;
1133 else if(copies < 0) copies = MAX_COPIES;
1134 SetDlgItemInt(hDlg, edt3, copies, FALSE);
1137 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1138 /* if printer doesn't support it: no nCopies */
1139 if (!(lpdm->dmFields & DM_COPIES)) {
1140 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
1141 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
1146 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
1147 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
1148 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
1149 if (lppd->Flags & PD_HIDEPRINTTOFILE)
1150 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
1152 } else { /* PD_PRINTSETUP */
1153 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
1155 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb2,
1156 PrintStructures->lpPrinterInfo->pPrinterName,
1157 PrintStructures->lpPrinterInfo->pPortName,
1159 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb3,
1160 PrintStructures->lpPrinterInfo->pPrinterName,
1161 PrintStructures->lpPrinterInfo->pPortName,
1163 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1164 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1165 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1166 PrintStructures->hLandscapeIcon));
1171 if ((lppd->Flags & PD_SHOWHELP)==0) {
1172 /* hide if PD_SHOWHELP not specified */
1173 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1178 /***********************************************************************
1179 * PRINTDLG_WMInitDialog [internal]
1181 static LRESULT PRINTDLG_WMInitDialog(HWND hDlg, WPARAM wParam,
1182 PRINT_PTRA* PrintStructures)
1184 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
1188 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1190 /* load Collate ICONs */
1191 /* We load these with LoadImage because they are not a standard
1192 size and we don't want them rescaled */
1193 PrintStructures->hCollateIcon =
1194 LoadImageA(COMDLG32_hInstance, "PD32_COLLATE", IMAGE_ICON, 0, 0, 0);
1195 PrintStructures->hNoCollateIcon =
1196 LoadImageA(COMDLG32_hInstance, "PD32_NOCOLLATE", IMAGE_ICON, 0, 0, 0);
1198 /* These can be done with LoadIcon */
1199 PrintStructures->hPortraitIcon =
1200 LoadIconA(COMDLG32_hInstance, "PD32_PORTRAIT");
1201 PrintStructures->hLandscapeIcon =
1202 LoadIconA(COMDLG32_hInstance, "PD32_LANDSCAPE");
1204 /* display the collate/no_collate icon */
1205 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1206 (LPARAM)PrintStructures->hNoCollateIcon);
1208 if(PrintStructures->hCollateIcon == 0 ||
1209 PrintStructures->hNoCollateIcon == 0 ||
1210 PrintStructures->hPortraitIcon == 0 ||
1211 PrintStructures->hLandscapeIcon == 0) {
1212 ERR("no icon in resourcefile\n");
1213 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1214 EndDialog(hDlg, FALSE);
1218 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1219 * must be registered and the Help button must be shown.
1221 if (lppd->Flags & PD_SHOWHELP) {
1222 if((PrintStructures->HelpMessageID =
1223 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
1224 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1228 PrintStructures->HelpMessageID = 0;
1230 if(!(lppd->Flags &PD_PRINTSETUP)) {
1231 PrintStructures->hwndUpDown =
1232 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1233 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1234 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1235 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1236 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1239 /* FIXME: I allow more freedom than either Win95 or WinNT,
1240 * which do not agree to what errors should be thrown or not
1241 * in case nToPage or nFromPage is out-of-range.
1243 if (lppd->nMaxPage < lppd->nMinPage)
1244 lppd->nMaxPage = lppd->nMinPage;
1245 if (lppd->nMinPage == lppd->nMaxPage)
1246 lppd->Flags |= PD_NOPAGENUMS;
1247 if (lppd->nToPage < lppd->nMinPage)
1248 lppd->nToPage = lppd->nMinPage;
1249 if (lppd->nToPage > lppd->nMaxPage)
1250 lppd->nToPage = lppd->nMaxPage;
1251 if (lppd->nFromPage < lppd->nMinPage)
1252 lppd->nFromPage = lppd->nMinPage;
1253 if (lppd->nFromPage > lppd->nMaxPage)
1254 lppd->nFromPage = lppd->nMaxPage;
1256 /* if we have the combo box, fill it */
1257 if (GetDlgItem(hDlg,comboID)) {
1260 pdn = GlobalLock(lppd->hDevNames);
1261 pdm = GlobalLock(lppd->hDevMode);
1263 name = (char*)pdn + pdn->wDeviceOffset;
1265 name = pdm->dmDeviceName;
1266 PRINTDLG_SetUpPrinterListComboA(hDlg, comboID, name);
1267 if(pdm) GlobalUnlock(lppd->hDevMode);
1268 if(pdn) GlobalUnlock(lppd->hDevNames);
1270 /* Now find selected printer and update rest of dlg */
1271 name = HeapAlloc(GetProcessHeap(),0,256);
1272 if (GetDlgItemTextA(hDlg, comboID, name, 255))
1273 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1274 HeapFree(GetProcessHeap(),0,name);
1276 /* else use default printer */
1278 DWORD dwBufLen = sizeof(name);
1279 BOOL ret = GetDefaultPrinterA(name, &dwBufLen);
1282 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1284 FIXME("No default printer found, expect problems!\n");
1289 static LRESULT PRINTDLG_WMInitDialogW(HWND hDlg, WPARAM wParam,
1290 PRINT_PTRW* PrintStructures)
1292 const static WCHAR PD32_COLLATE[] = { 'P', 'D', '3', '2', '_', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
1293 const static WCHAR PD32_NOCOLLATE[] = { 'P', 'D', '3', '2', '_', 'N', 'O', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
1294 const static WCHAR PD32_PORTRAIT[] = { 'P', 'D', '3', '2', '_', 'P', 'O', 'R', 'T', 'R', 'A', 'I', 'T', 0 };
1295 const static WCHAR PD32_LANDSCAPE[] = { 'P', 'D', '3', '2', '_', 'L', 'A', 'N', 'D', 'S', 'C', 'A', 'P', 'E', 0 };
1296 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1300 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1302 /* load Collate ICONs */
1303 /* We load these with LoadImage because they are not a standard
1304 size and we don't want them rescaled */
1305 PrintStructures->hCollateIcon =
1306 LoadImageW(COMDLG32_hInstance, PD32_COLLATE, IMAGE_ICON, 0, 0, 0);
1307 PrintStructures->hNoCollateIcon =
1308 LoadImageW(COMDLG32_hInstance, PD32_NOCOLLATE, IMAGE_ICON, 0, 0, 0);
1310 /* These can be done with LoadIcon */
1311 PrintStructures->hPortraitIcon =
1312 LoadIconW(COMDLG32_hInstance, PD32_PORTRAIT);
1313 PrintStructures->hLandscapeIcon =
1314 LoadIconW(COMDLG32_hInstance, PD32_LANDSCAPE);
1316 /* display the collate/no_collate icon */
1317 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1318 (LPARAM)PrintStructures->hNoCollateIcon);
1320 if(PrintStructures->hCollateIcon == 0 ||
1321 PrintStructures->hNoCollateIcon == 0 ||
1322 PrintStructures->hPortraitIcon == 0 ||
1323 PrintStructures->hLandscapeIcon == 0) {
1324 ERR("no icon in resourcefile\n");
1325 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1326 EndDialog(hDlg, FALSE);
1330 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1331 * must be registered and the Help button must be shown.
1333 if (lppd->Flags & PD_SHOWHELP) {
1334 if((PrintStructures->HelpMessageID =
1335 RegisterWindowMessageW(HELPMSGSTRINGW)) == 0) {
1336 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1340 PrintStructures->HelpMessageID = 0;
1342 if(!(lppd->Flags &PD_PRINTSETUP)) {
1343 PrintStructures->hwndUpDown =
1344 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1345 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1346 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1347 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1348 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1351 /* FIXME: I allow more freedom than either Win95 or WinNT,
1352 * which do not agree to what errors should be thrown or not
1353 * in case nToPage or nFromPage is out-of-range.
1355 if (lppd->nMaxPage < lppd->nMinPage)
1356 lppd->nMaxPage = lppd->nMinPage;
1357 if (lppd->nMinPage == lppd->nMaxPage)
1358 lppd->Flags |= PD_NOPAGENUMS;
1359 if (lppd->nToPage < lppd->nMinPage)
1360 lppd->nToPage = lppd->nMinPage;
1361 if (lppd->nToPage > lppd->nMaxPage)
1362 lppd->nToPage = lppd->nMaxPage;
1363 if (lppd->nFromPage < lppd->nMinPage)
1364 lppd->nFromPage = lppd->nMinPage;
1365 if (lppd->nFromPage > lppd->nMaxPage)
1366 lppd->nFromPage = lppd->nMaxPage;
1368 /* if we have the combo box, fill it */
1369 if (GetDlgItem(hDlg,comboID)) {
1372 pdn = GlobalLock(lppd->hDevNames);
1373 pdm = GlobalLock(lppd->hDevMode);
1375 name = (WCHAR*)pdn + pdn->wDeviceOffset;
1377 name = pdm->dmDeviceName;
1378 PRINTDLG_SetUpPrinterListComboW(hDlg, comboID, name);
1379 if(pdm) GlobalUnlock(lppd->hDevMode);
1380 if(pdn) GlobalUnlock(lppd->hDevNames);
1382 /* Now find selected printer and update rest of dlg */
1383 /* ansi is ok here */
1384 name = HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR));
1385 if (GetDlgItemTextW(hDlg, comboID, name, 255))
1386 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1387 HeapFree(GetProcessHeap(),0,name);
1389 /* else use default printer */
1391 DWORD dwBufLen = sizeof(name) / sizeof(WCHAR);
1392 BOOL ret = GetDefaultPrinterW(name, &dwBufLen);
1395 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1397 FIXME("No default printer found, expect problems!\n");
1402 /***********************************************************************
1403 * PRINTDLG_WMCommand [internal]
1405 LRESULT PRINTDLG_WMCommandA(HWND hDlg, WPARAM wParam,
1406 LPARAM lParam, PRINT_PTRA* PrintStructures)
1408 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
1409 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1410 LPDEVMODEA lpdm = PrintStructures->lpDevMode;
1412 switch (LOWORD(wParam)) {
1414 TRACE(" OK button was hit\n");
1415 if (!PRINTDLG_UpdatePrintDlgA(hDlg, PrintStructures)) {
1416 FIXME("Update printdlg was not successful!\n");
1419 EndDialog(hDlg, TRUE);
1423 TRACE(" CANCEL button was hit\n");
1424 EndDialog(hDlg, FALSE);
1428 TRACE(" HELP button was hit\n");
1429 SendMessageA(lppd->hwndOwner, PrintStructures->HelpMessageID,
1430 (WPARAM) hDlg, (LPARAM) lppd);
1433 case chx2: /* collate pages checkbox */
1434 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1435 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1436 (LPARAM)PrintStructures->hCollateIcon);
1438 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1439 (LPARAM)PrintStructures->hNoCollateIcon);
1441 case edt1: /* from page nr editbox */
1442 case edt2: /* to page nr editbox */
1443 if (HIWORD(wParam)==EN_CHANGE) {
1446 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1447 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1448 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1449 CheckRadioButton(hDlg, rad1, rad3, rad3);
1454 if(HIWORD(wParam) == EN_CHANGE) {
1455 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1457 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1459 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1464 case psh1: /* Print Setup */
1468 if (!PrintStructures->dlg.lpPrintDlg16) {
1469 FIXME("The 32bit print dialog does not have this button!?\n");
1473 memcpy(&pdlg,PrintStructures->dlg.lpPrintDlg16,sizeof(pdlg));
1474 pdlg.Flags |= PD_PRINTSETUP;
1475 pdlg.hwndOwner = HWND_16(hDlg);
1476 if (!PrintDlg16(&pdlg))
1481 case psh2: /* Properties button */
1484 char PrinterName[256];
1486 GetDlgItemTextA(hDlg, PrinterComboID, PrinterName, 255);
1487 if (!OpenPrinterA(PrinterName, &hPrinter, NULL)) {
1488 FIXME(" Call to OpenPrinter did not succeed!\n");
1491 DocumentPropertiesA(hDlg, hPrinter, PrinterName,
1492 PrintStructures->lpDevMode,
1493 PrintStructures->lpDevMode,
1494 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1495 ClosePrinter(hPrinter);
1499 case rad1: /* Paperorientation */
1500 if (lppd->Flags & PD_PRINTSETUP)
1502 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1503 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1504 (LPARAM)(PrintStructures->hPortraitIcon));
1508 case rad2: /* Paperorientation */
1509 if (lppd->Flags & PD_PRINTSETUP)
1511 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1512 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1513 (LPARAM)(PrintStructures->hLandscapeIcon));
1517 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1518 if (PrinterComboID != LOWORD(wParam)) {
1519 FIXME("No handling for print quality combo box yet.\n");
1523 case cmb4: /* Printer combobox */
1524 if (HIWORD(wParam)==CBN_SELCHANGE) {
1525 char PrinterName[256];
1526 GetDlgItemTextA(hDlg, LOWORD(wParam), PrinterName, 255);
1527 PRINTDLG_ChangePrinterA(hDlg, PrinterName, PrintStructures);
1531 case cmb2: /* Papersize */
1533 DWORD Sel = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1535 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
1541 case cmb3: /* Bin */
1543 DWORD Sel = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1545 lpdm->dmDefaultSource = SendDlgItemMessageA(hDlg, cmb3,
1546 CB_GETITEMDATA, Sel,
1551 if(lppd->Flags & PD_PRINTSETUP) {
1552 switch (LOWORD(wParam)) {
1553 case rad1: /* orientation */
1555 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1556 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1557 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1558 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1560 (LPARAM)PrintStructures->hPortraitIcon);
1561 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1563 (LPARAM)PrintStructures->hPortraitIcon);
1566 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1567 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1568 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1570 (LPARAM)PrintStructures->hLandscapeIcon);
1571 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1573 (LPARAM)PrintStructures->hLandscapeIcon);
1582 static LRESULT PRINTDLG_WMCommandW(HWND hDlg, WPARAM wParam,
1583 LPARAM lParam, PRINT_PTRW* PrintStructures)
1585 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1586 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1587 LPDEVMODEW lpdm = PrintStructures->lpDevMode;
1589 switch (LOWORD(wParam)) {
1591 TRACE(" OK button was hit\n");
1592 if (!PRINTDLG_UpdatePrintDlgW(hDlg, PrintStructures)) {
1593 FIXME("Update printdlg was not successful!\n");
1596 EndDialog(hDlg, TRUE);
1600 TRACE(" CANCEL button was hit\n");
1601 EndDialog(hDlg, FALSE);
1605 TRACE(" HELP button was hit\n");
1606 SendMessageW(lppd->hwndOwner, PrintStructures->HelpMessageID,
1607 (WPARAM) hDlg, (LPARAM) lppd);
1610 case chx2: /* collate pages checkbox */
1611 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1612 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1613 (LPARAM)PrintStructures->hCollateIcon);
1615 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1616 (LPARAM)PrintStructures->hNoCollateIcon);
1618 case edt1: /* from page nr editbox */
1619 case edt2: /* to page nr editbox */
1620 if (HIWORD(wParam)==EN_CHANGE) {
1623 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1624 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1625 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1626 CheckRadioButton(hDlg, rad1, rad3, rad3);
1631 if(HIWORD(wParam) == EN_CHANGE) {
1632 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1634 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1636 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1640 case psh1: /* Print Setup */
1642 ERR("psh1 is called from 16bit code only, we should not get here.\n");
1645 case psh2: /* Properties button */
1648 WCHAR PrinterName[256];
1650 if (!GetDlgItemTextW(hDlg, PrinterComboID, PrinterName, 255)) break;
1651 if (!OpenPrinterW(PrinterName, &hPrinter, NULL)) {
1652 FIXME(" Call to OpenPrinter did not succeed!\n");
1655 DocumentPropertiesW(hDlg, hPrinter, PrinterName,
1656 PrintStructures->lpDevMode,
1657 PrintStructures->lpDevMode,
1658 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1659 ClosePrinter(hPrinter);
1663 case rad1: /* Paperorientation */
1664 if (lppd->Flags & PD_PRINTSETUP)
1666 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1667 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1668 (LPARAM)(PrintStructures->hPortraitIcon));
1672 case rad2: /* Paperorientation */
1673 if (lppd->Flags & PD_PRINTSETUP)
1675 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1676 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1677 (LPARAM)(PrintStructures->hLandscapeIcon));
1681 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1682 if (PrinterComboID != LOWORD(wParam)) {
1683 FIXME("No handling for print quality combo box yet.\n");
1687 case cmb4: /* Printer combobox */
1688 if (HIWORD(wParam)==CBN_SELCHANGE) {
1689 WCHAR PrinterName[256];
1690 GetDlgItemTextW(hDlg, LOWORD(wParam), PrinterName, 255);
1691 PRINTDLG_ChangePrinterW(hDlg, PrinterName, PrintStructures);
1695 case cmb2: /* Papersize */
1697 DWORD Sel = SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1699 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageW(hDlg, cmb2,
1705 case cmb3: /* Bin */
1707 DWORD Sel = SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1709 lpdm->dmDefaultSource = SendDlgItemMessageW(hDlg, cmb3,
1710 CB_GETITEMDATA, Sel,
1715 if(lppd->Flags & PD_PRINTSETUP) {
1716 switch (LOWORD(wParam)) {
1717 case rad1: /* orientation */
1719 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1720 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1721 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1722 SendDlgItemMessageW(hDlg, stc10, STM_SETIMAGE,
1724 (LPARAM)PrintStructures->hPortraitIcon);
1725 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE,
1727 (LPARAM)PrintStructures->hPortraitIcon);
1730 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1731 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1732 SendDlgItemMessageW(hDlg, stc10, STM_SETIMAGE,
1734 (LPARAM)PrintStructures->hLandscapeIcon);
1735 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE,
1737 (LPARAM)PrintStructures->hLandscapeIcon);
1746 /***********************************************************************
1747 * PrintDlgProcA [internal]
1749 static INT_PTR CALLBACK PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
1752 PRINT_PTRA* PrintStructures;
1753 INT_PTR res = FALSE;
1755 if (uMsg!=WM_INITDIALOG) {
1756 PrintStructures = (PRINT_PTRA*)GetPropA(hDlg,"__WINE_PRINTDLGDATA");
1757 if (!PrintStructures)
1760 PrintStructures = (PRINT_PTRA*) lParam;
1761 SetPropA(hDlg,"__WINE_PRINTDLGDATA",PrintStructures);
1762 res = PRINTDLG_WMInitDialog(hDlg, wParam, PrintStructures);
1764 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
1765 res = PrintStructures->lpPrintDlg->lpfnPrintHook(
1766 hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg
1771 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
1772 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam,
1779 return PRINTDLG_WMCommandA(hDlg, wParam, lParam, PrintStructures);
1782 DestroyIcon(PrintStructures->hCollateIcon);
1783 DestroyIcon(PrintStructures->hNoCollateIcon);
1784 DestroyIcon(PrintStructures->hPortraitIcon);
1785 DestroyIcon(PrintStructures->hLandscapeIcon);
1786 if(PrintStructures->hwndUpDown)
1787 DestroyWindow(PrintStructures->hwndUpDown);
1793 static INT_PTR CALLBACK PrintDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
1796 static const WCHAR propW[] = {'_','_','W','I','N','E','_','P','R','I','N','T','D','L','G','D','A','T','A',0};
1797 PRINT_PTRW* PrintStructures;
1798 INT_PTR res = FALSE;
1800 if (uMsg!=WM_INITDIALOG) {
1801 PrintStructures = (PRINT_PTRW*) GetPropW(hDlg, propW);
1802 if (!PrintStructures)
1805 PrintStructures = (PRINT_PTRW*) lParam;
1806 SetPropW(hDlg, propW, PrintStructures);
1807 res = PRINTDLG_WMInitDialogW(hDlg, wParam, PrintStructures);
1809 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
1810 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg);
1814 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
1815 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam, lParam);
1821 return PRINTDLG_WMCommandW(hDlg, wParam, lParam, PrintStructures);
1824 DestroyIcon(PrintStructures->hCollateIcon);
1825 DestroyIcon(PrintStructures->hNoCollateIcon);
1826 DestroyIcon(PrintStructures->hPortraitIcon);
1827 DestroyIcon(PrintStructures->hLandscapeIcon);
1828 if(PrintStructures->hwndUpDown)
1829 DestroyWindow(PrintStructures->hwndUpDown);
1835 /************************************************************
1837 * PRINTDLG_GetDlgTemplate
1840 static HGLOBAL PRINTDLG_GetDlgTemplateA(PRINTDLGA *lppd)
1845 if (lppd->Flags & PD_PRINTSETUP) {
1846 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
1847 hDlgTmpl = lppd->hSetupTemplate;
1848 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
1849 hResInfo = FindResourceA(lppd->hInstance,
1850 lppd->lpSetupTemplateName, (LPSTR)RT_DIALOG);
1851 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1853 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32_SETUP",
1855 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1858 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
1859 hDlgTmpl = lppd->hPrintTemplate;
1860 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
1861 hResInfo = FindResourceA(lppd->hInstance,
1862 lppd->lpPrintTemplateName,
1864 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1866 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32",
1868 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1874 static HGLOBAL PRINTDLG_GetDlgTemplateW(PRINTDLGW *lppd)
1878 static const WCHAR xpsetup[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
1879 static const WCHAR xprint[] = { 'P','R','I','N','T','3','2',0};
1881 if (lppd->Flags & PD_PRINTSETUP) {
1882 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
1883 hDlgTmpl = lppd->hSetupTemplate;
1884 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
1885 hResInfo = FindResourceW(lppd->hInstance,
1886 lppd->lpSetupTemplateName, (LPWSTR)RT_DIALOG);
1887 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1889 hResInfo = FindResourceW(COMDLG32_hInstance, xpsetup, (LPWSTR)RT_DIALOG);
1890 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1893 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
1894 hDlgTmpl = lppd->hPrintTemplate;
1895 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
1896 hResInfo = FindResourceW(lppd->hInstance,
1897 lppd->lpPrintTemplateName,
1899 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1901 hResInfo = FindResourceW(COMDLG32_hInstance, xprint, (LPWSTR)RT_DIALOG);
1902 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1908 /***********************************************************************
1913 static BOOL PRINTDLG_CreateDCA(LPPRINTDLGA lppd)
1915 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
1916 DEVMODEA *pdm = GlobalLock(lppd->hDevMode);
1918 if(lppd->Flags & PD_RETURNDC) {
1919 lppd->hDC = CreateDCA((char*)pdn + pdn->wDriverOffset,
1920 (char*)pdn + pdn->wDeviceOffset,
1921 (char*)pdn + pdn->wOutputOffset,
1923 } else if(lppd->Flags & PD_RETURNIC) {
1924 lppd->hDC = CreateICA((char*)pdn + pdn->wDriverOffset,
1925 (char*)pdn + pdn->wDeviceOffset,
1926 (char*)pdn + pdn->wOutputOffset,
1929 GlobalUnlock(lppd->hDevNames);
1930 GlobalUnlock(lppd->hDevMode);
1931 return lppd->hDC ? TRUE : FALSE;
1934 static BOOL PRINTDLG_CreateDCW(LPPRINTDLGW lppd)
1936 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
1937 DEVMODEW *pdm = GlobalLock(lppd->hDevMode);
1939 if(lppd->Flags & PD_RETURNDC) {
1940 lppd->hDC = CreateDCW((WCHAR*)pdn + pdn->wDriverOffset,
1941 (WCHAR*)pdn + pdn->wDeviceOffset,
1942 (WCHAR*)pdn + pdn->wOutputOffset,
1944 } else if(lppd->Flags & PD_RETURNIC) {
1945 lppd->hDC = CreateICW((WCHAR*)pdn + pdn->wDriverOffset,
1946 (WCHAR*)pdn + pdn->wDeviceOffset,
1947 (WCHAR*)pdn + pdn->wOutputOffset,
1950 GlobalUnlock(lppd->hDevNames);
1951 GlobalUnlock(lppd->hDevMode);
1952 return lppd->hDC ? TRUE : FALSE;
1955 /***********************************************************************
1956 * PrintDlgA (COMDLG32.@)
1958 * Displays the the PRINT dialog box, which enables the user to specify
1959 * specific properties of the print job.
1962 * nonzero if the user pressed the OK button
1963 * zero if the user cancelled the window or an error occurred
1967 * * The Collate Icons do not display, even though they are in the code.
1968 * * The Properties Button(s) should call DocumentPropertiesA().
1970 * * The Paper Orientation Icons are not implemented yet.
1971 * * The Properties Button(s) should call DocumentPropertiesA().
1972 * * Settings are not yet taken from a provided DevMode or
1973 * default printer settings.
1976 BOOL WINAPI PrintDlgA(
1977 LPPRINTDLGA lppd /* [in/out] ptr to PRINTDLG32 struct */
1982 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrA( lppd->hwndOwner, GWLP_HINSTANCE );
1984 if(TRACE_ON(commdlg)) {
1985 char flagstr[1000] = "";
1986 struct pd_flags *pflag = pd_flags;
1987 for( ; pflag->name; pflag++) {
1988 if(lppd->Flags & pflag->flag)
1989 strcat(flagstr, pflag->name);
1991 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
1992 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
1993 "flags %08lx (%s)\n",
1994 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
1995 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
1996 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
1999 if(lppd->lStructSize != sizeof(PRINTDLGA)) {
2000 WARN("structure size failure !!!\n");
2001 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2005 if(lppd->Flags & PD_RETURNDEFAULT) {
2006 PRINTER_INFO_2A *pbuf;
2007 DRIVER_INFO_3A *dbuf;
2011 if(lppd->hDevMode || lppd->hDevNames) {
2012 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2013 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2016 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2017 WARN("Can't find default printer\n");
2018 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2022 GetPrinterA(hprn, 2, NULL, 0, &needed);
2023 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
2024 GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2026 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
2027 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
2028 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2029 ERR("GetPrinterDriverA failed, le %ld, fix your config for printer %s!\n",GetLastError(),pbuf->pPrinterName);
2030 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2035 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2039 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2040 pbuf->pDevMode->dmDriverExtra);
2041 ptr = GlobalLock(lppd->hDevMode);
2042 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2043 pbuf->pDevMode->dmDriverExtra);
2044 GlobalUnlock(lppd->hDevMode);
2045 HeapFree(GetProcessHeap(), 0, pbuf);
2046 HeapFree(GetProcessHeap(), 0, dbuf);
2050 PRINT_PTRA *PrintStructures;
2052 /* load Dialog resources,
2053 * depending on Flags indicates Print32 or Print32_setup dialog
2055 hDlgTmpl = PRINTDLG_GetDlgTemplateA(lppd);
2057 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2060 ptr = LockResource( hDlgTmpl );
2062 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2066 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2067 sizeof(PRINT_PTRA));
2068 PrintStructures->lpPrintDlg = lppd;
2070 /* and create & process the dialog .
2071 * -1 is failure, 0 is broken hwnd, everything else is ok.
2073 bRet = (0<DialogBoxIndirectParamA(hInst, ptr, lppd->hwndOwner,
2075 (LPARAM)PrintStructures));
2078 DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2079 PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
2080 DRIVER_INFO_3A *di = PrintStructures->lpDriverInfo;
2082 if (lppd->hDevMode == 0) {
2083 TRACE(" No hDevMode yet... Need to create my own\n");
2084 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2085 lpdm->dmSize + lpdm->dmDriverExtra);
2088 if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
2089 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2091 GlobalUnlock(lppd->hDevMode);
2092 TRACE("Now got %d locks\n", locks);
2095 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2096 lpdm->dmSize + lpdm->dmDriverExtra,
2099 lpdmReturn = GlobalLock(lppd->hDevMode);
2100 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2102 if (lppd->hDevNames != 0) {
2104 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
2105 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2107 GlobalUnlock(lppd->hDevNames);
2110 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2115 GlobalUnlock(lppd->hDevMode);
2117 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2118 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2119 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2120 HeapFree(GetProcessHeap(), 0, PrintStructures);
2122 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2123 bRet = PRINTDLG_CreateDCA(lppd);
2125 TRACE("exit! (%d)\n", bRet);
2129 /***********************************************************************
2130 * PrintDlgW (COMDLG32.@)
2132 BOOL WINAPI PrintDlgW(
2133 LPPRINTDLGW lppd /* [in/out] ptr to PRINTDLG32 struct */
2138 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW( lppd->hwndOwner, GWLP_HINSTANCE );
2140 if(TRACE_ON(commdlg)) {
2141 char flagstr[1000] = "";
2142 struct pd_flags *pflag = pd_flags;
2143 for( ; pflag->name; pflag++) {
2144 if(lppd->Flags & pflag->flag)
2145 strcat(flagstr, pflag->name);
2147 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2148 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2149 "flags %08lx (%s)\n",
2150 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2151 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2152 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2155 if(lppd->lStructSize != sizeof(PRINTDLGW)) {
2156 WARN("structure size failure !!!\n");
2157 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2161 if(lppd->Flags & PD_RETURNDEFAULT) {
2162 PRINTER_INFO_2W *pbuf;
2163 DRIVER_INFO_3W *dbuf;
2167 if(lppd->hDevMode || lppd->hDevNames) {
2168 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2169 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2172 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2173 WARN("Can't find default printer\n");
2174 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2178 GetPrinterW(hprn, 2, NULL, 0, &needed);
2179 pbuf = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*needed);
2180 GetPrinterW(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2182 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
2183 dbuf = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
2184 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2185 ERR("GetPrinterDriverA failed, le %ld, fix your config for printer %s!\n",GetLastError(),debugstr_w(pbuf->pPrinterName));
2186 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2191 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2195 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2196 pbuf->pDevMode->dmDriverExtra);
2197 ptr = GlobalLock(lppd->hDevMode);
2198 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2199 pbuf->pDevMode->dmDriverExtra);
2200 GlobalUnlock(lppd->hDevMode);
2201 HeapFree(GetProcessHeap(), 0, pbuf);
2202 HeapFree(GetProcessHeap(), 0, dbuf);
2206 PRINT_PTRW *PrintStructures;
2208 /* load Dialog resources,
2209 * depending on Flags indicates Print32 or Print32_setup dialog
2211 hDlgTmpl = PRINTDLG_GetDlgTemplateW(lppd);
2213 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2216 ptr = LockResource( hDlgTmpl );
2218 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2222 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2223 sizeof(PRINT_PTRW));
2224 PrintStructures->lpPrintDlg = lppd;
2226 /* and create & process the dialog .
2227 * -1 is failure, 0 is broken hwnd, everything else is ok.
2229 bRet = (0<DialogBoxIndirectParamW(hInst, ptr, lppd->hwndOwner,
2231 (LPARAM)PrintStructures));
2234 DEVMODEW *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2235 PRINTER_INFO_2W *pi = PrintStructures->lpPrinterInfo;
2236 DRIVER_INFO_3W *di = PrintStructures->lpDriverInfo;
2238 if (lppd->hDevMode == 0) {
2239 TRACE(" No hDevMode yet... Need to create my own\n");
2240 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2241 lpdm->dmSize + lpdm->dmDriverExtra);
2244 if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
2245 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2247 GlobalUnlock(lppd->hDevMode);
2248 TRACE("Now got %d locks\n", locks);
2251 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2252 lpdm->dmSize + lpdm->dmDriverExtra,
2255 lpdmReturn = GlobalLock(lppd->hDevMode);
2256 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2258 if (lppd->hDevNames != 0) {
2260 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
2261 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2263 GlobalUnlock(lppd->hDevNames);
2266 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2271 GlobalUnlock(lppd->hDevMode);
2273 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2274 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2275 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2276 HeapFree(GetProcessHeap(), 0, PrintStructures);
2278 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2279 bRet = PRINTDLG_CreateDCW(lppd);
2281 TRACE("exit! (%d)\n", bRet);
2285 /***********************************************************************
2291 * cmb3 - source (tray?)
2292 * edt4 - border left
2294 * edt6 - border right
2295 * edt7 - border bottom
2296 * psh3 - "Printer..."
2300 LPPAGESETUPDLGA dlga;
2305 LPPAGESETUPDLGW dlga;
2309 static HGLOBAL PRINTDLG_GetPGSTemplateA(PAGESETUPDLGA *lppd)
2314 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2315 hDlgTmpl = lppd->hPageSetupTemplate;
2316 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2317 hResInfo = FindResourceA(lppd->hInstance,
2318 lppd->lpPageSetupTemplateName, (LPSTR)RT_DIALOG);
2319 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2321 hResInfo = FindResourceA(COMDLG32_hInstance,(LPCSTR)PAGESETUPDLGORD,(LPSTR)RT_DIALOG);
2322 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2327 static HGLOBAL PRINTDLG_GetPGSTemplateW(PAGESETUPDLGW *lppd)
2332 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2333 hDlgTmpl = lppd->hPageSetupTemplate;
2334 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2335 hResInfo = FindResourceW(lppd->hInstance,
2336 lppd->lpPageSetupTemplateName, (LPWSTR)RT_DIALOG);
2337 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2339 hResInfo = FindResourceW(COMDLG32_hInstance,(LPCWSTR)PAGESETUPDLGORD,(LPWSTR)RT_DIALOG);
2340 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2346 _c_10mm2size(PAGESETUPDLGA *dlga,DWORD size) {
2347 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2348 return 10*size*10/25.4;
2349 /* If we don't have a flag, we can choose one. Use millimeters
2350 * to avoid confusing me
2352 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2358 _c_inch2size(PAGESETUPDLGA *dlga,DWORD size) {
2359 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2361 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
2362 return (size*254)/10;
2363 /* if we don't have a flag, we can choose one. Use millimeters
2364 * to avoid confusing me
2366 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2367 return (size*254)/10;
2371 _c_size2strA(PageSetupDataA *pda,DWORD size,LPSTR strout) {
2372 strcpy(strout,"<undef>");
2373 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2374 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
2377 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2378 sprintf(strout,"%.2fin",(size*1.0)/1000.0);
2381 pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2382 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
2386 _c_size2strW(PageSetupDataW *pda,DWORD size,LPWSTR strout) {
2387 const static WCHAR UNDEF[] = { '<', 'u', 'n', 'd', 'e', 'f', '>', 0 };
2388 const static WCHAR mm_fmt[] = { '%', '.', '2', 'f', 'm', 'm', 0 };
2389 const static WCHAR in_fmt[] = { '%', '.', '2', 'f', 'i', 'n', 0 };
2390 lstrcpyW(strout, UNDEF);
2391 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2392 wsprintfW(strout,mm_fmt,(size*1.0)/100.0);
2395 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2396 wsprintfW(strout,in_fmt,(size*1.0)/1000.0);
2399 pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2400 wsprintfW(strout,mm_fmt,(size*1.0)/100.0);
2405 _c_str2sizeA(PAGESETUPDLGA *dlga,LPCSTR strin) {
2410 if (!sscanf(strin,"%f%s",&val,rest))
2413 if (!strcmp(rest,"in") || !strcmp(rest,"inch")) {
2414 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2417 return val*25.4*100;
2419 if (!strcmp(rest,"cm")) { rest[0]='m'; val = val*10.0; }
2420 if (!strcmp(rest,"m")) { strcpy(rest,"mm"); val = val*1000.0; }
2422 if (!strcmp(rest,"mm")) {
2423 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
2426 return 1000.0*val/25.4;
2428 if (rest[0]=='\0') {
2429 /* use application supplied default */
2430 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2434 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2439 ERR("Did not find a conversion for type '%s'!\n",rest);
2445 _c_str2sizeW(PAGESETUPDLGW *dlga, LPCWSTR strin) {
2448 /* this W -> A transition is OK */
2449 /* we need a unicode version of sscanf to avoid it */
2450 WideCharToMultiByte(CP_ACP, 0, strin, -1, buf, sizeof(buf), NULL, NULL);
2451 return _c_str2sizeA((PAGESETUPDLGA *)dlga, buf);
2456 * This is called on finish and will update the output fields of the
2460 PRINTDLG_PS_UpdateDlgStructA(HWND hDlg, PageSetupDataA *pda) {
2463 LPSTR devname,portname;
2467 dn = GlobalLock(pda->pdlg.hDevNames);
2468 dm = GlobalLock(pda->pdlg.hDevMode);
2469 devname = ((char*)dn)+dn->wDeviceOffset;
2470 portname = ((char*)dn)+dn->wOutputOffset;
2471 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb2,devname,portname,dm);
2472 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb3,devname,portname,dm);
2474 if (GetDlgItemTextA(hDlg,cmb2,papername,sizeof(papername))>0) {
2475 PRINTDLG_PaperSizeA(&(pda->pdlg),papername,&(pda->dlga->ptPaperSize));
2476 pda->dlga->ptPaperSize.x = _c_10mm2size(pda->dlga,pda->dlga->ptPaperSize.x);
2477 pda->dlga->ptPaperSize.y = _c_10mm2size(pda->dlga,pda->dlga->ptPaperSize.y);
2479 FIXME("could not get dialog text for papersize cmbbox?\n");
2480 #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); }
2481 GETVAL(edt4,pda->dlga->rtMargin.left);
2482 GETVAL(edt5,pda->dlga->rtMargin.top);
2483 GETVAL(edt6,pda->dlga->rtMargin.right);
2484 GETVAL(edt7,pda->dlga->rtMargin.bottom);
2487 /* If we are in landscape, swap x and y of page size */
2488 if (IsDlgButtonChecked(hDlg, rad2)) {
2490 tmp = pda->dlga->ptPaperSize.x;
2491 pda->dlga->ptPaperSize.x = pda->dlga->ptPaperSize.y;
2492 pda->dlga->ptPaperSize.y = tmp;
2494 GlobalUnlock(pda->pdlg.hDevNames);
2495 GlobalUnlock(pda->pdlg.hDevMode);
2500 PRINTDLG_PS_UpdateDlgStructW(HWND hDlg, PageSetupDataW *pda) {
2503 LPWSTR devname,portname;
2504 WCHAR papername[64];
2507 dn = GlobalLock(pda->pdlg.hDevNames);
2508 dm = GlobalLock(pda->pdlg.hDevMode);
2509 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
2510 portname = ((WCHAR*)dn)+dn->wOutputOffset;
2511 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
2512 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
2514 if (GetDlgItemTextW(hDlg,cmb2,papername,sizeof(papername))>0) {
2515 PRINTDLG_PaperSizeW(&(pda->pdlg),papername,&(pda->dlga->ptPaperSize));
2516 pda->dlga->ptPaperSize.x = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga,pda->dlga->ptPaperSize.x);
2517 pda->dlga->ptPaperSize.y = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga,pda->dlga->ptPaperSize.y);
2519 FIXME("could not get dialog text for papersize cmbbox?\n");
2520 #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); }
2521 GETVAL(edt4,pda->dlga->rtMargin.left);
2522 GETVAL(edt5,pda->dlga->rtMargin.top);
2523 GETVAL(edt6,pda->dlga->rtMargin.right);
2524 GETVAL(edt7,pda->dlga->rtMargin.bottom);
2527 /* If we are in landscape, swap x and y of page size */
2528 if (IsDlgButtonChecked(hDlg, rad2)) {
2530 tmp = pda->dlga->ptPaperSize.x;
2531 pda->dlga->ptPaperSize.x = pda->dlga->ptPaperSize.y;
2532 pda->dlga->ptPaperSize.y = tmp;
2534 GlobalUnlock(pda->pdlg.hDevNames);
2535 GlobalUnlock(pda->pdlg.hDevMode);
2540 * This is called after returning from PrintDlg().
2543 PRINTDLG_PS_ChangePrinterA(HWND hDlg, PageSetupDataA *pda) {
2546 LPSTR devname,portname;
2548 dn = GlobalLock(pda->pdlg.hDevNames);
2549 dm = GlobalLock(pda->pdlg.hDevMode);
2550 devname = ((char*)dn)+dn->wDeviceOffset;
2551 portname = ((char*)dn)+dn->wOutputOffset;
2552 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb2,devname,portname,dm);
2553 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb3,devname,portname,dm);
2554 GlobalUnlock(pda->pdlg.hDevNames);
2555 GlobalUnlock(pda->pdlg.hDevMode);
2560 PRINTDLG_PS_ChangePrinterW(HWND hDlg, PageSetupDataW *pda) {
2563 LPWSTR devname,portname;
2565 dn = GlobalLock(pda->pdlg.hDevNames);
2566 dm = GlobalLock(pda->pdlg.hDevMode);
2567 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
2568 portname = ((WCHAR*)dn)+dn->wOutputOffset;
2569 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
2570 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
2571 GlobalUnlock(pda->pdlg.hDevNames);
2572 GlobalUnlock(pda->pdlg.hDevMode);
2577 PRINTDLG_PS_WMCommandA(
2578 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataA *pda
2580 switch (LOWORD(wParam)) {
2582 if (!PRINTDLG_PS_UpdateDlgStructA(hDlg, pda))
2584 EndDialog(hDlg, TRUE);
2588 EndDialog(hDlg, FALSE);
2592 pda->pdlg.Flags = 0;
2593 pda->pdlg.hwndOwner = hDlg;
2594 if (PrintDlgA(&(pda->pdlg)))
2595 PRINTDLG_PS_ChangePrinterA(hDlg,pda);
2599 FIXME("loword (lparam) %d, wparam 0x%x, lparam %08lx, STUB mostly.\n",
2600 LOWORD(lParam),wParam,lParam
2606 PRINTDLG_PS_WMCommandW(
2607 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataW *pda
2609 switch (LOWORD(wParam)) {
2611 if (!PRINTDLG_PS_UpdateDlgStructW(hDlg, pda))
2613 EndDialog(hDlg, TRUE);
2617 EndDialog(hDlg, FALSE);
2621 pda->pdlg.Flags = 0;
2622 pda->pdlg.hwndOwner = hDlg;
2623 if (PrintDlgW(&(pda->pdlg)))
2624 PRINTDLG_PS_ChangePrinterW(hDlg,pda);
2628 FIXME("loword (lparam) %d, wparam 0x%x, lparam %08lx, STUB mostly.\n",
2629 LOWORD(lParam),wParam,lParam
2635 static INT_PTR CALLBACK
2636 PageDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
2638 PageSetupDataA *pda;
2639 INT_PTR res = FALSE;
2641 if (uMsg==WM_INITDIALOG) {
2643 pda = (PageSetupDataA*)lParam;
2644 SetPropA(hDlg,"__WINE_PAGESETUPDLGDATA",pda);
2645 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
2646 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,(LPARAM)pda->dlga);
2648 FIXME("Setup page hook failed?\n");
2652 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK) {
2653 FIXME("PagePaintHook not yet implemented!\n");
2655 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
2656 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
2657 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
2658 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
2659 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
2660 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
2661 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
2663 /* width larger as height -> landscape */
2664 if (pda->dlga->ptPaperSize.x > pda->dlga->ptPaperSize.y)
2665 CheckRadioButton(hDlg, rad1, rad2, rad2);
2666 else /* this is default if papersize is not set */
2667 CheckRadioButton(hDlg, rad1, rad2, rad1);
2668 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
2669 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
2670 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
2672 /* We fill them out enabled or not */
2673 if (pda->dlga->Flags & PSD_MARGINS) {
2675 _c_size2strA(pda,pda->dlga->rtMargin.left,str);
2676 SetDlgItemTextA(hDlg,edt4,str);
2677 _c_size2strA(pda,pda->dlga->rtMargin.top,str);
2678 SetDlgItemTextA(hDlg,edt5,str);
2679 _c_size2strA(pda,pda->dlga->rtMargin.right,str);
2680 SetDlgItemTextA(hDlg,edt6,str);
2681 _c_size2strA(pda,pda->dlga->rtMargin.bottom,str);
2682 SetDlgItemTextA(hDlg,edt7,str);
2684 /* default is 1 inch */
2685 DWORD size = _c_inch2size(pda->dlga,1000);
2687 _c_size2strA(pda,size,str);
2688 SetDlgItemTextA(hDlg,edt4,str);
2689 SetDlgItemTextA(hDlg,edt5,str);
2690 SetDlgItemTextA(hDlg,edt6,str);
2691 SetDlgItemTextA(hDlg,edt7,str);
2693 PRINTDLG_PS_ChangePrinterA(hDlg,pda);
2694 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
2695 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
2696 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
2700 pda = (PageSetupDataA*)GetPropA(hDlg,"__WINE_PAGESETUPDLGDATA");
2702 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
2705 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
2706 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
2707 if (res) return res;
2712 return PRINTDLG_PS_WMCommandA(hDlg, wParam, lParam, pda);
2717 static INT_PTR CALLBACK
2718 PageDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
2720 const static WCHAR __WINE_PAGESETUPDLGDATA[] =
2721 { '_', '_', 'W', 'I', 'N', 'E', '_', 'P', 'A', 'G', 'E',
2722 'S', 'E', 'T', 'U', 'P', 'D', 'L', 'G', 'D', 'A', 'T', 'A', 0 };
2723 PageSetupDataW *pda;
2726 if (uMsg==WM_INITDIALOG) {
2728 pda = (PageSetupDataW*)lParam;
2729 SetPropW(hDlg, __WINE_PAGESETUPDLGDATA, pda);
2730 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
2731 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,(LPARAM)pda->dlga);
2733 FIXME("Setup page hook failed?\n");
2737 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK) {
2738 FIXME("PagePaintHook not yet implemented!\n");
2740 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
2741 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
2742 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
2743 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
2744 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
2745 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
2746 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
2748 /* width larger as height -> landscape */
2749 if (pda->dlga->ptPaperSize.x > pda->dlga->ptPaperSize.y)
2750 CheckRadioButton(hDlg, rad1, rad2, rad2);
2751 else /* this is default if papersize is not set */
2752 CheckRadioButton(hDlg, rad1, rad2, rad1);
2753 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
2754 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
2755 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
2757 /* We fill them out enabled or not */
2758 if (pda->dlga->Flags & PSD_MARGINS) {
2760 _c_size2strW(pda,pda->dlga->rtMargin.left,str);
2761 SetDlgItemTextW(hDlg,edt4,str);
2762 _c_size2strW(pda,pda->dlga->rtMargin.top,str);
2763 SetDlgItemTextW(hDlg,edt5,str);
2764 _c_size2strW(pda,pda->dlga->rtMargin.right,str);
2765 SetDlgItemTextW(hDlg,edt6,str);
2766 _c_size2strW(pda,pda->dlga->rtMargin.bottom,str);
2767 SetDlgItemTextW(hDlg,edt7,str);
2769 /* default is 1 inch */
2770 DWORD size = _c_inch2size((LPPAGESETUPDLGA)pda->dlga,1000);
2772 _c_size2strW(pda,size,str);
2773 SetDlgItemTextW(hDlg,edt4,str);
2774 SetDlgItemTextW(hDlg,edt5,str);
2775 SetDlgItemTextW(hDlg,edt6,str);
2776 SetDlgItemTextW(hDlg,edt7,str);
2778 PRINTDLG_PS_ChangePrinterW(hDlg,pda);
2779 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
2780 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
2781 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
2785 pda = (PageSetupDataW*)GetPropW(hDlg, __WINE_PAGESETUPDLGDATA);
2787 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
2790 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
2791 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
2792 if (res) return res;
2797 return PRINTDLG_PS_WMCommandW(hDlg, wParam, lParam, pda);
2802 /***********************************************************************
2803 * PageSetupDlgA (COMDLG32.@)
2805 BOOL WINAPI PageSetupDlgA(LPPAGESETUPDLGA setupdlg) {
2809 PageSetupDataA *pda;
2812 if(TRACE_ON(commdlg)) {
2813 char flagstr[1000] = "";
2814 struct pd_flags *pflag = psd_flags;
2815 for( ; pflag->name; pflag++) {
2816 if(setupdlg->Flags & pflag->flag) {
2817 strcat(flagstr, pflag->name);
2818 strcat(flagstr, "|");
2821 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2822 "hinst %p, flags %08lx (%s)\n",
2823 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
2824 setupdlg->hDevNames,
2825 setupdlg->hInstance, setupdlg->Flags, flagstr);
2828 /* First get default printer data, we need it right after that. */
2829 memset(&pdlg,0,sizeof(pdlg));
2830 pdlg.lStructSize = sizeof(pdlg);
2831 pdlg.Flags = PD_RETURNDEFAULT;
2832 bRet = PrintDlgA(&pdlg);
2833 if (!bRet) return FALSE;
2835 /* short cut exit, just return default values */
2836 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
2837 setupdlg->hDevMode = pdlg.hDevMode;
2838 setupdlg->hDevNames = pdlg.hDevNames;
2839 /* FIXME: Just return "A4" for now. */
2840 PRINTDLG_PaperSizeA(&pdlg,"A4",&setupdlg->ptPaperSize);
2841 setupdlg->ptPaperSize.x=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.x);
2842 setupdlg->ptPaperSize.y=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.y);
2845 hDlgTmpl = PRINTDLG_GetPGSTemplateA(setupdlg);
2847 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2850 ptr = LockResource( hDlgTmpl );
2852 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2855 pda = HeapAlloc(GetProcessHeap(),0,sizeof(*pda));
2856 pda->dlga = setupdlg;
2857 memcpy(&pda->pdlg,&pdlg,sizeof(pdlg));
2859 bRet = (0<DialogBoxIndirectParamA(
2860 setupdlg->hInstance,
2862 setupdlg->hwndOwner,
2868 /***********************************************************************
2869 * PageSetupDlgW (COMDLG32.@)
2871 BOOL WINAPI PageSetupDlgW(LPPAGESETUPDLGW setupdlg) {
2875 PageSetupDataW *pdw;
2878 if(TRACE_ON(commdlg)) {
2879 char flagstr[1000] = "";
2880 struct pd_flags *pflag = psd_flags;
2881 for( ; pflag->name; pflag++) {
2882 if(setupdlg->Flags & pflag->flag) {
2883 strcat(flagstr, pflag->name);
2884 strcat(flagstr, "|");
2887 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2888 "hinst %p, flags %08lx (%s)\n",
2889 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
2890 setupdlg->hDevNames,
2891 setupdlg->hInstance, setupdlg->Flags, flagstr);
2894 /* First get default printer data, we need it right after that. */
2895 memset(&pdlg,0,sizeof(pdlg));
2896 pdlg.lStructSize = sizeof(pdlg);
2897 pdlg.Flags = PD_RETURNDEFAULT;
2898 bRet = PrintDlgW(&pdlg);
2899 if (!bRet) return FALSE;
2901 /* short cut exit, just return default values */
2902 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
2903 static const WCHAR a4[] = {'A','4',0};
2904 setupdlg->hDevMode = pdlg.hDevMode;
2905 setupdlg->hDevNames = pdlg.hDevNames;
2906 /* FIXME: Just return "A4" for now. */
2907 PRINTDLG_PaperSizeW(&pdlg,a4,&setupdlg->ptPaperSize);
2908 setupdlg->ptPaperSize.x=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.x);
2909 setupdlg->ptPaperSize.y=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.y);
2912 hDlgTmpl = PRINTDLG_GetPGSTemplateW(setupdlg);
2914 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2917 ptr = LockResource( hDlgTmpl );
2919 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2922 pdw = HeapAlloc(GetProcessHeap(),0,sizeof(*pdw));
2923 pdw->dlga = setupdlg;
2924 memcpy(&pdw->pdlg,&pdlg,sizeof(pdlg));
2926 bRet = (0<DialogBoxIndirectParamW(
2927 setupdlg->hInstance,
2929 setupdlg->hwndOwner,
2936 /***********************************************************************
2937 * PrintDlgExA (COMDLG32.@)
2939 HRESULT WINAPI PrintDlgExA(LPVOID lpPrintDlgExA) /* [???] FIXME: LPPRINTDLGEXA */
2944 /***********************************************************************
2945 * PrintDlgExW (COMDLG32.@)
2947 HRESULT WINAPI PrintDlgExW(LPVOID lpPrintDlgExW) /* [???] FIXME: LPPRINTDLGEXW */