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
30 #include "wine/wingdi16.h"
32 #include "wine/winuser16.h"
35 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
44 /* This PRINTDLGA internal structure stores
45 * pointers to several throughout useful structures.
52 LPPRINTDLGA lpPrintDlg;
53 LPPRINTDLG16 lpPrintDlg16;
55 LPPRINTER_INFO_2A lpPrinterInfo;
56 LPDRIVER_INFO_3A lpDriverInfo;
58 HICON hCollateIcon; /* PrintDlg only */
59 HICON hNoCollateIcon; /* PrintDlg only */
60 HICON hPortraitIcon; /* PrintSetupDlg only */
61 HICON hLandscapeIcon; /* PrintSetupDlg only */
69 LPPRINTDLGW lpPrintDlg;
71 LPPRINTER_INFO_2W lpPrinterInfo;
72 LPDRIVER_INFO_3W lpDriverInfo;
74 HICON hCollateIcon; /* PrintDlg only */
75 HICON hNoCollateIcon; /* PrintDlg only */
76 HICON hPortraitIcon; /* PrintSetupDlg only */
77 HICON hLandscapeIcon; /* PrintSetupDlg only */
82 static struct pd_flags {
86 {PD_SELECTION, "PD_SELECTION "},
87 {PD_PAGENUMS, "PD_PAGENUMS "},
88 {PD_NOSELECTION, "PD_NOSELECTION "},
89 {PD_NOPAGENUMS, "PD_NOPAGENUMS "},
90 {PD_COLLATE, "PD_COLLATE "},
91 {PD_PRINTTOFILE, "PD_PRINTTOFILE "},
92 {PD_PRINTSETUP, "PD_PRINTSETUP "},
93 {PD_NOWARNING, "PD_NOWARNING "},
94 {PD_RETURNDC, "PD_RETURNDC "},
95 {PD_RETURNIC, "PD_RETURNIC "},
96 {PD_RETURNDEFAULT, "PD_RETURNDEFAULT "},
97 {PD_SHOWHELP, "PD_SHOWHELP "},
98 {PD_ENABLEPRINTHOOK, "PD_ENABLEPRINTHOOK "},
99 {PD_ENABLESETUPHOOK, "PD_ENABLESETUPHOOK "},
100 {PD_ENABLEPRINTTEMPLATE, "PD_ENABLEPRINTTEMPLATE "},
101 {PD_ENABLESETUPTEMPLATE, "PD_ENABLESETUPTEMPLATE "},
102 {PD_ENABLEPRINTTEMPLATEHANDLE, "PD_ENABLEPRINTTEMPLATEHANDLE "},
103 {PD_ENABLESETUPTEMPLATEHANDLE, "PD_ENABLESETUPTEMPLATEHANDLE "},
104 {PD_USEDEVMODECOPIES, "PD_USEDEVMODECOPIES[ANDCOLLATE] "},
105 {PD_DISABLEPRINTTOFILE, "PD_DISABLEPRINTTOFILE "},
106 {PD_HIDEPRINTTOFILE, "PD_HIDEPRINTTOFILE "},
107 {PD_NONETWORKBUTTON, "PD_NONETWORKBUTTON "},
112 static struct pd_flags psd_flags[] = {
113 {PSD_MINMARGINS,"PSD_MINMARGINS"},
114 {PSD_MARGINS,"PSD_MARGINS"},
115 {PSD_INTHOUSANDTHSOFINCHES,"PSD_INTHOUSANDTHSOFINCHES"},
116 {PSD_INHUNDREDTHSOFMILLIMETERS,"PSD_INHUNDREDTHSOFMILLIMETERS"},
117 {PSD_DISABLEMARGINS,"PSD_DISABLEMARGINS"},
118 {PSD_DISABLEPRINTER,"PSD_DISABLEPRINTER"},
119 {PSD_NOWARNING,"PSD_NOWARNING"},
120 {PSD_DISABLEORIENTATION,"PSD_DISABLEORIENTATION"},
121 {PSD_RETURNDEFAULT,"PSD_RETURNDEFAULT"},
122 {PSD_DISABLEPAPER,"PSD_DISABLEPAPER"},
123 {PSD_SHOWHELP,"PSD_SHOWHELP"},
124 {PSD_ENABLEPAGESETUPHOOK,"PSD_ENABLEPAGESETUPHOOK"},
125 {PSD_ENABLEPAGESETUPTEMPLATE,"PSD_ENABLEPAGESETUPTEMPLATE"},
126 {PSD_ENABLEPAGESETUPTEMPLATEHANDLE,"PSD_ENABLEPAGESETUPTEMPLATEHANDLE"},
127 {PSD_ENABLEPAGEPAINTHOOK,"PSD_ENABLEPAGEPAINTHOOK"},
128 {PSD_DISABLEPAGEPAINTING,"PSD_DISABLEPAGEPAINTING"},
132 /* Yes these constants are the same, but we're just copying win98 */
133 #define UPDOWN_ID 0x270f
134 #define MAX_COPIES 9999
136 /***********************************************************************
137 * PRINTDLG_GetDefaultPrinterName
139 * Returns the default printer name in buf.
140 * Even under WinNT/2000 default printer is retrieved via GetProfileString -
141 * these entries are mapped somewhere in the registry rather than win.ini.
143 * Returns TRUE on success else FALSE
145 static BOOL PRINTDLG_GetDefaultPrinterNameA(LPSTR buf, DWORD len)
149 if(!GetProfileStringA("windows", "device", "", buf, len)) {
150 TRACE("No profile entry for default printer found.\n");
153 if((ptr = strchr(buf, ',')) == NULL) {
154 FIXME("bad format for default printer (%s)!\n",buf);
161 static BOOL PRINTDLG_GetDefaultPrinterNameW(LPWSTR buf, DWORD len)
163 LPSTR ptr, bufA = (LPSTR)HeapAlloc(GetProcessHeap(),0,len+1);
166 if(!GetProfileStringA("windows", "device", "", bufA, len)) {
167 TRACE("No profile entry for default printer found.\n");
168 HeapFree(GetProcessHeap(),0,bufA);
171 if((ptr = strchr(bufA, ',')) == NULL) {
172 FIXME("bad format for default printer (%s)!\n",bufA);
173 HeapFree(GetProcessHeap(),0,bufA);
177 MultiByteToWideChar( CP_ACP, 0, bufA, -1, buf, len );
178 HeapFree(GetProcessHeap(),0,bufA);
182 /***********************************************************************
183 * PRINTDLG_OpenDefaultPrinter
185 * Returns a winspool printer handle to the default printer in *hprn
186 * Caller must call ClosePrinter on the handle
188 * Returns TRUE on success else FALSE
190 static BOOL PRINTDLG_OpenDefaultPrinter(HANDLE *hprn)
194 if(!PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf)))
196 res = OpenPrinterA(buf, hprn, NULL);
198 FIXME("Could not open printer %s?!\n",buf);
202 /***********************************************************************
203 * PRINTDLG_SetUpPrinterListCombo
205 * Initializes printer list combox.
206 * hDlg: HWND of dialog
207 * id: Control id of combo
208 * name: Name of printer to select
210 * Initializes combo with list of available printers. Selects printer 'name'
211 * If name is NULL or does not exist select the default printer.
213 * Returns number of printers added to list.
215 static INT PRINTDLG_SetUpPrinterListComboA(HWND hDlg, UINT id, LPCSTR name)
219 LPPRINTER_INFO_2A pi;
220 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
221 pi = HeapAlloc(GetProcessHeap(), 0, needed);
222 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
225 for(i = 0; i < num; i++) {
226 SendDlgItemMessageA(hDlg, id, CB_ADDSTRING, 0,
227 (LPARAM)pi[i].pPrinterName );
229 HeapFree(GetProcessHeap(), 0, pi);
231 (i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1,
232 (LPARAM)name)) == CB_ERR) {
235 FIXME("Can't find '%s' in printer list so trying to find default\n",
237 if(!PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf)))
239 i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
241 FIXME("Can't find default printer in printer list\n");
243 SendDlgItemMessageA(hDlg, id, CB_SETCURSEL, i, 0);
247 static INT PRINTDLG_SetUpPrinterListComboW(HWND hDlg, UINT id, LPCWSTR name)
251 LPPRINTER_INFO_2W pi;
252 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
253 pi = HeapAlloc(GetProcessHeap(), 0, needed);
254 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
257 for(i = 0; i < num; i++) {
258 SendDlgItemMessageW(hDlg, id, CB_ADDSTRING, 0,
259 (LPARAM)pi[i].pPrinterName );
261 HeapFree(GetProcessHeap(), 0, pi);
263 (i = SendDlgItemMessageW(hDlg, id, CB_FINDSTRINGEXACT, -1,
264 (LPARAM)name)) == CB_ERR) {
268 FIXME("Can't find '%s' in printer list so trying to find default\n",
270 if(!PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf)))
272 i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
274 FIXME("Can't find default printer in printer list\n");
276 SendDlgItemMessageW(hDlg, id, CB_SETCURSEL, i, 0);
280 /***********************************************************************
281 * PRINTDLG_CreateDevNames [internal]
284 * creates a DevNames structure.
286 * (NB. when we handle unicode the offsets will be in wchars).
288 static BOOL PRINTDLG_CreateDevNames(HGLOBAL *hmem, char* DeviceDriverName,
289 char* DeviceName, char* OutputPort)
292 char* pDevNamesSpace;
294 LPDEVNAMES lpDevNames;
297 size = strlen(DeviceDriverName) + 1
298 + strlen(DeviceName) + 1
299 + strlen(OutputPort) + 1
303 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
305 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
309 pDevNamesSpace = GlobalLock(*hmem);
310 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
312 pTempPtr = pDevNamesSpace + sizeof(DEVNAMES);
313 strcpy(pTempPtr, DeviceDriverName);
314 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
316 pTempPtr += strlen(DeviceDriverName) + 1;
317 strcpy(pTempPtr, DeviceName);
318 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
320 pTempPtr += strlen(DeviceName) + 1;
321 strcpy(pTempPtr, OutputPort);
322 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
324 PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf));
325 lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
330 static BOOL PRINTDLG_CreateDevNamesW(HGLOBAL *hmem, LPCWSTR DeviceDriverName,
331 LPCWSTR DeviceName, LPCWSTR OutputPort)
334 LPWSTR pDevNamesSpace;
336 LPDEVNAMES lpDevNames;
340 size = sizeof(WCHAR)*lstrlenW(DeviceDriverName) + 2
341 + sizeof(WCHAR)*lstrlenW(DeviceName) + 2
342 + sizeof(WCHAR)*lstrlenW(OutputPort) + 2
346 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
348 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
352 pDevNamesSpace = GlobalLock(*hmem);
353 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
355 pTempPtr = (LPWSTR)((LPDEVNAMES)pDevNamesSpace + 1);
356 lstrcpyW(pTempPtr, DeviceDriverName);
357 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
359 pTempPtr += lstrlenW(DeviceDriverName) + 1;
360 lstrcpyW(pTempPtr, DeviceName);
361 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
363 pTempPtr += lstrlenW(DeviceName) + 1;
364 lstrcpyW(pTempPtr, OutputPort);
365 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
367 PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf));
368 MultiByteToWideChar(CP_ACP, 0, buf, -1, bufW, -1);
369 lpDevNames->wDefault = (lstrcmpW(bufW, DeviceName) == 0) ? 1 : 0;
375 static BOOL PRINTDLG_CreateDevNames16(HGLOBAL16 *hmem, char* DeviceDriverName,
376 char* DeviceName, char* OutputPort)
379 char* pDevNamesSpace;
381 LPDEVNAMES lpDevNames;
384 size = strlen(DeviceDriverName) + 1
385 + strlen(DeviceName) + 1
386 + strlen(OutputPort) + 1
390 *hmem = GlobalReAlloc16(*hmem, size, GMEM_MOVEABLE);
392 *hmem = GlobalAlloc16(GMEM_MOVEABLE, size);
396 pDevNamesSpace = GlobalLock16(*hmem);
397 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
399 pTempPtr = pDevNamesSpace + sizeof(DEVNAMES);
400 strcpy(pTempPtr, DeviceDriverName);
401 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
403 pTempPtr += strlen(DeviceDriverName) + 1;
404 strcpy(pTempPtr, DeviceName);
405 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
407 pTempPtr += strlen(DeviceName) + 1;
408 strcpy(pTempPtr, OutputPort);
409 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
411 PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf));
412 lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
413 GlobalUnlock16(*hmem);
418 /***********************************************************************
419 * PRINTDLG_UpdatePrintDlg [internal]
422 * updates the PrintDlg structure for returnvalues.
425 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
428 static BOOL PRINTDLG_UpdatePrintDlgA(HWND hDlg,
429 PRINT_PTRA* PrintStructures)
431 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
432 PDEVMODEA lpdm = PrintStructures->lpDevMode;
433 LPPRINTER_INFO_2A pi = PrintStructures->lpPrinterInfo;
437 FIXME("No lpdm ptr?\n");
442 if(!(lppd->Flags & PD_PRINTSETUP)) {
443 /* check whether nFromPage and nToPage are within range defined by
444 * nMinPage and nMaxPage
446 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
449 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
450 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
451 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
452 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
453 char resourcestr[256];
455 LoadStringA(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
457 sprintf(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
458 LoadStringA(COMDLG32_hInstance, PD32_PRINT_TITLE,
460 MessageBoxA(hDlg, resultstr, resourcestr,
461 MB_OK | MB_ICONWARNING);
464 lppd->nFromPage = nFromPage;
465 lppd->nToPage = nToPage;
468 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
469 lppd->Flags |= PD_PRINTTOFILE;
470 pi->pPortName = "FILE:";
473 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
474 FIXME("Collate lppd not yet implemented as output\n");
477 /* set PD_Collate and nCopies */
478 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
479 /* The application doesn't support multiple copies or collate...
481 lppd->Flags &= ~PD_COLLATE;
483 /* if the printer driver supports it... store info there
484 * otherwise no collate & multiple copies !
486 if (lpdm->dmFields & DM_COLLATE)
488 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
489 if (lpdm->dmFields & DM_COPIES)
490 lpdm->dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
492 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
493 lppd->Flags |= PD_COLLATE;
495 lppd->Flags &= ~PD_COLLATE;
496 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
502 static BOOL PRINTDLG_UpdatePrintDlgW(HWND hDlg,
503 PRINT_PTRW* PrintStructures)
505 LPPRINTDLGW lppd = PrintStructures->dlg.lpPrintDlg;
506 PDEVMODEW lpdm = PrintStructures->lpDevMode;
507 LPPRINTER_INFO_2W pi = PrintStructures->lpPrinterInfo;
511 FIXME("No lpdm ptr?\n");
516 if(!(lppd->Flags & PD_PRINTSETUP)) {
517 /* check whether nFromPage and nToPage are within range defined by
518 * nMinPage and nMaxPage
520 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
523 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
524 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
525 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
526 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
527 char resourcestr[256];
529 LoadStringA(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
531 sprintf(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
532 LoadStringA(COMDLG32_hInstance, PD32_PRINT_TITLE,
534 MessageBoxA(hDlg, resultstr, resourcestr,
535 MB_OK | MB_ICONWARNING);
538 lppd->nFromPage = nFromPage;
539 lppd->nToPage = nToPage;
542 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
543 static WCHAR file[] = {'F','I','L','E',':',0};
544 lppd->Flags |= PD_PRINTTOFILE;
545 pi->pPortName = file;
548 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
549 FIXME("Collate lppd not yet implemented as output\n");
552 /* set PD_Collate and nCopies */
553 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
554 /* The application doesn't support multiple copies or collate...
556 lppd->Flags &= ~PD_COLLATE;
558 /* if the printer driver supports it... store info there
559 * otherwise no collate & multiple copies !
561 if (lpdm->dmFields & DM_COLLATE)
563 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
564 if (lpdm->dmFields & DM_COPIES)
565 lpdm->dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
567 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
568 lppd->Flags |= PD_COLLATE;
570 lppd->Flags &= ~PD_COLLATE;
571 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
577 static BOOL PRINTDLG_PaperSizeA(
578 PRINTDLGA *pdlga,const char *PaperSize,LPPOINT size
582 LPSTR devname,portname;
586 POINT *points = NULL;
589 dn = GlobalLock(pdlga->hDevNames);
590 dm = GlobalLock(pdlga->hDevMode);
591 devname = ((char*)dn)+dn->wDeviceOffset;
592 portname = ((char*)dn)+dn->wOutputOffset;
595 NrOfEntries = DeviceCapabilitiesA(devname,portname,DC_PAPERNAMES,NULL,dm);
597 FIXME("No papernames found for %s/%s\n",devname,portname);
600 if (NrOfEntries == -1) {
601 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
605 Names = (char*)HeapAlloc(GetProcessHeap(),0,NrOfEntries*64);
606 if (NrOfEntries != (ret=DeviceCapabilitiesA(devname,portname,DC_PAPERNAMES,Names,dm))) {
607 FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
610 for (i=0;i<NrOfEntries;i++)
611 if (!strcmp(PaperSize,Names+(64*i)))
613 HeapFree(GetProcessHeap(),0,Names);
614 if (i==NrOfEntries) {
615 FIXME("Papersize %s not found in list?\n",PaperSize);
618 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
619 if (NrOfEntries!=(ret=DeviceCapabilitiesA(devname,portname,DC_PAPERSIZE,(LPBYTE)points,dm))) {
620 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
623 /* this is _10ths_ of a millimeter */
628 GlobalUnlock(pdlga->hDevNames);
629 GlobalUnlock(pdlga->hDevMode);
630 if (Names) HeapFree(GetProcessHeap(),0,Names);
631 if (points) HeapFree(GetProcessHeap(),0,points);
635 static BOOL PRINTDLG_PaperSizeW(
636 PRINTDLGW *pdlga,const WCHAR *PaperSize,LPPOINT size
640 LPWSTR devname,portname;
644 POINT *points = NULL;
647 dn = GlobalLock(pdlga->hDevNames);
648 dm = GlobalLock(pdlga->hDevMode);
649 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
650 portname = ((WCHAR*)dn)+dn->wOutputOffset;
653 NrOfEntries = DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,NULL,dm);
655 FIXME("No papernames found for %s/%s\n",debugstr_w(devname),debugstr_w(portname));
658 if (NrOfEntries == -1) {
659 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
663 Names = (WCHAR*)HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*NrOfEntries*64);
664 if (NrOfEntries != (ret=DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,Names,dm))) {
665 FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
668 for (i=0;i<NrOfEntries;i++)
669 if (!lstrcmpW(PaperSize,Names+(64*i)))
671 HeapFree(GetProcessHeap(),0,Names);
672 if (i==NrOfEntries) {
673 FIXME("Papersize %s not found in list?\n",debugstr_w(PaperSize));
676 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
677 if (NrOfEntries!=(ret=DeviceCapabilitiesW(devname,portname,DC_PAPERSIZE,(LPWSTR)points,dm))) {
678 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
681 /* this is _10ths_ of a millimeter */
686 GlobalUnlock(pdlga->hDevNames);
687 GlobalUnlock(pdlga->hDevMode);
688 if (Names) HeapFree(GetProcessHeap(),0,Names);
689 if (points) HeapFree(GetProcessHeap(),0,points);
694 /************************************************************************
695 * PRINTDLG_SetUpPaperComboBox
697 * Initialize either the papersize or inputslot combos of the Printer Setup
698 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
699 * We also try to re-select the old selection.
701 static BOOL PRINTDLG_SetUpPaperComboBoxA(HWND hDlg,
714 int fwCapability_Names;
715 int fwCapability_Words;
717 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName,PortName,nIDComboBox);
719 /* query the dialog box for the current selected value */
720 Sel = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
722 /* we enter here only if a different printer is selected after
723 * the Print Setup dialog is opened. The current settings are
724 * stored into the newly selected printer.
726 oldWord = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA,
729 if (nIDComboBox == cmb2)
730 dm->u1.s1.dmPaperSize = oldWord;
732 dm->dmDefaultSource = oldWord;
736 /* we enter here only when the Print setup dialog is initially
737 * opened. In this case the settings are restored from when
738 * the dialog was last closed.
741 if (nIDComboBox == cmb2)
742 oldWord = dm->u1.s1.dmPaperSize;
744 oldWord = dm->dmDefaultSource;
748 if (nIDComboBox == cmb2) {
750 fwCapability_Names = DC_PAPERNAMES;
751 fwCapability_Words = DC_PAPERS;
755 fwCapability_Names = DC_BINNAMES;
756 fwCapability_Words = DC_BINS;
759 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
760 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
762 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
763 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
764 fwCapability_Names, NULL, dm);
765 if (NrOfEntries == 0)
766 WARN("no Name Entries found!\n");
767 else if (NrOfEntries < 0)
770 if(DeviceCapabilitiesA(PrinterName, PortName, fwCapability_Words, NULL, dm)
772 ERR("Number of caps is different\n");
776 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(char)*NamesSize);
777 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
778 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
779 fwCapability_Names, Names, dm);
780 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
781 fwCapability_Words, (LPSTR)Words, dm);
783 /* reset any current content in the combobox */
784 SendDlgItemMessageA(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
786 /* store new content */
787 for (i = 0; i < NrOfEntries; i++) {
788 DWORD pos = SendDlgItemMessageA(hDlg, nIDComboBox, CB_ADDSTRING, 0,
789 (LPARAM)(&Names[i*NamesSize]) );
790 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
794 /* Look for old selection - can't do this is previous loop since
795 item order will change as more items are added */
797 for (i = 0; i < NrOfEntries; i++) {
798 if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
804 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
806 HeapFree(GetProcessHeap(),0,Words);
807 HeapFree(GetProcessHeap(),0,Names);
811 static BOOL PRINTDLG_SetUpPaperComboBoxW(HWND hDlg,
824 int fwCapability_Names;
825 int fwCapability_Words;
827 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName),debugstr_w(PortName),nIDComboBox);
829 /* query the dialog box for the current selected value */
830 Sel = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
832 /* we enter here only if a different printer is selected after
833 * the Print Setup dialog is opened. The current settings are
834 * stored into the newly selected printer.
836 oldWord = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA,
839 if (nIDComboBox == cmb2)
840 dm->u1.s1.dmPaperSize = oldWord;
842 dm->dmDefaultSource = oldWord;
846 /* we enter here only when the Print setup dialog is initially
847 * opened. In this case the settings are restored from when
848 * the dialog was last closed.
851 if (nIDComboBox == cmb2)
852 oldWord = dm->u1.s1.dmPaperSize;
854 oldWord = dm->dmDefaultSource;
858 if (nIDComboBox == cmb2) {
860 fwCapability_Names = DC_PAPERNAMES;
861 fwCapability_Words = DC_PAPERS;
865 fwCapability_Names = DC_BINNAMES;
866 fwCapability_Words = DC_BINS;
869 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
870 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
872 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
873 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
874 fwCapability_Names, NULL, dm);
875 if (NrOfEntries == 0)
876 WARN("no Name Entries found!\n");
877 else if (NrOfEntries < 0)
880 if(DeviceCapabilitiesW(PrinterName, PortName, fwCapability_Words, NULL, dm)
882 ERR("Number of caps is different\n");
886 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WCHAR)*NamesSize);
887 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
888 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
889 fwCapability_Names, Names, dm);
890 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
891 fwCapability_Words, (LPWSTR)Words, dm);
893 /* reset any current content in the combobox */
894 SendDlgItemMessageA(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
896 /* store new content */
897 for (i = 0; i < NrOfEntries; i++) {
898 DWORD pos = SendDlgItemMessageW(hDlg, nIDComboBox, CB_ADDSTRING, 0,
899 (LPARAM)(&Names[i*NamesSize]) );
900 SendDlgItemMessageW(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
904 /* Look for old selection - can't do this is previous loop since
905 item order will change as more items are added */
907 for (i = 0; i < NrOfEntries; i++) {
908 if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
914 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
916 HeapFree(GetProcessHeap(),0,Words);
917 HeapFree(GetProcessHeap(),0,Names);
922 /***********************************************************************
923 * PRINTDLG_UpdatePrinterInfoTexts [internal]
925 static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg, LPPRINTER_INFO_2A pi)
928 char ResourceString[256];
934 /* add all status messages */
935 for (i = 0; i < 25; i++) {
936 if (pi->Status & (1<<i)) {
937 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
938 ResourceString, 255);
939 strcat(StatusMsg,ResourceString);
943 /* FIXME: status==ready must only be appended if really so.
944 but how to detect? */
945 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
946 ResourceString, 255);
947 strcat(StatusMsg,ResourceString);
949 SendDlgItemMessageA(hDlg, stc12, WM_SETTEXT, 0, (LPARAM)StatusMsg);
951 /* set all other printer info texts */
952 SendDlgItemMessageA(hDlg, stc11, WM_SETTEXT, 0, (LPARAM)pi->pDriverName);
953 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
954 SendDlgItemMessageA(hDlg, stc14, WM_SETTEXT, 0,(LPARAM)pi->pLocation);
956 SendDlgItemMessageA(hDlg, stc14, WM_SETTEXT, 0,(LPARAM)pi->pPortName);
957 SendDlgItemMessageA(hDlg, stc13, WM_SETTEXT, 0, (LPARAM)(pi->pComment ?
962 static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg, LPPRINTER_INFO_2W pi)
964 WCHAR StatusMsg[256];
965 WCHAR ResourceString[256];
971 /* add all status messages */
972 for (i = 0; i < 25; i++) {
973 if (pi->Status & (1<<i)) {
974 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
975 ResourceString, 255);
976 lstrcatW(StatusMsg,ResourceString);
980 /* FIXME: status==ready must only be appended if really so.
981 but how to detect? */
982 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
983 ResourceString, 255);
984 lstrcatW(StatusMsg,ResourceString);
986 SendDlgItemMessageW(hDlg, stc12, WM_SETTEXT, 0, (LPARAM)StatusMsg);
988 /* set all other printer info texts */
989 SendDlgItemMessageW(hDlg, stc11, WM_SETTEXT, 0, (LPARAM)pi->pDriverName);
990 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
991 SendDlgItemMessageW(hDlg, stc14, WM_SETTEXT, 0,(LPARAM)pi->pLocation);
993 SendDlgItemMessageW(hDlg, stc14, WM_SETTEXT, 0,(LPARAM)pi->pPortName);
994 SendDlgItemMessageW(hDlg, stc13, WM_SETTEXT, 0, (LPARAM)(pi->pComment ?
995 pi->pComment : (LPCWSTR)"\0\0"));
1000 /*******************************************************************
1002 * PRINTDLG_ChangePrinter
1005 static BOOL PRINTDLG_ChangePrinterA(HWND hDlg, char *name,
1006 PRINT_PTRA *PrintStructures)
1008 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
1009 LPDEVMODEA lpdm = NULL;
1014 if(PrintStructures->lpPrinterInfo)
1015 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
1016 if(PrintStructures->lpDriverInfo)
1017 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
1018 if(!OpenPrinterA(name, &hprn, NULL)) {
1019 ERR("Can't open printer %s\n", name);
1022 GetPrinterA(hprn, 2, NULL, 0, &needed);
1023 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,needed);
1024 GetPrinterA(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
1026 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
1027 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,needed);
1028 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
1030 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures->lpPrinterInfo->pPrinterName);
1035 PRINTDLG_UpdatePrinterInfoTextsA(hDlg, PrintStructures->lpPrinterInfo);
1037 if(PrintStructures->lpDevMode) {
1038 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
1039 PrintStructures->lpDevMode = NULL;
1042 dmSize = DocumentPropertiesA(0, 0, name, NULL, NULL, 0);
1044 ERR("DocumentProperties fails on %s\n", debugstr_a(name));
1047 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
1048 dmSize = DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, NULL,
1050 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
1051 !strcmp(lpdm->dmDeviceName,
1052 PrintStructures->lpDevMode->dmDeviceName)) {
1053 /* Supplied devicemode matches current printer so try to use it */
1054 DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, lpdm,
1055 DM_OUT_BUFFER | DM_IN_BUFFER);
1058 GlobalUnlock(lppd->hDevMode);
1060 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
1062 if(!(lppd->Flags & PD_PRINTSETUP)) {
1063 /* Print range (All/Range/Selection) */
1064 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
1065 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
1066 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
1067 if (lppd->Flags & PD_NOSELECTION)
1068 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
1070 if (lppd->Flags & PD_SELECTION)
1071 CheckRadioButton(hDlg, rad1, rad3, rad2);
1072 if (lppd->Flags & PD_NOPAGENUMS) {
1073 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
1074 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
1075 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
1076 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
1077 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
1079 if (lppd->Flags & PD_PAGENUMS)
1080 CheckRadioButton(hDlg, rad1, rad3, rad3);
1082 /* "All xxx pages"... */
1084 char resourcestr[64];
1086 LoadStringA(COMDLG32_hInstance, PD32_PRINT_ALL_X_PAGES,
1088 sprintf(result,resourcestr,lppd->nMaxPage - lppd->nMinPage + 1);
1089 SendDlgItemMessageA(hDlg, rad1, WM_SETTEXT, 0, (LPARAM) result);
1094 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1096 if (lppd->Flags & PD_COLLATE) {
1097 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1098 (LPARAM)PrintStructures->hCollateIcon);
1099 CheckDlgButton(hDlg, chx2, 1);
1101 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1102 (LPARAM)PrintStructures->hNoCollateIcon);
1103 CheckDlgButton(hDlg, chx2, 0);
1106 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1107 /* if printer doesn't support it: no Collate */
1108 if (!(lpdm->dmFields & DM_COLLATE)) {
1109 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1110 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
1117 if (lppd->hDevMode == 0)
1118 copies = lppd->nCopies;
1120 copies = lpdm->dmCopies;
1121 if(copies == 0) copies = 1;
1122 else if(copies < 0) copies = MAX_COPIES;
1123 SetDlgItemInt(hDlg, edt3, copies, FALSE);
1126 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1127 /* if printer doesn't support it: no nCopies */
1128 if (!(lpdm->dmFields & DM_COPIES)) {
1129 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
1130 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
1135 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
1136 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
1137 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
1138 if (lppd->Flags & PD_HIDEPRINTTOFILE)
1139 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
1141 } else { /* PD_PRINTSETUP */
1142 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
1144 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb2,
1145 PrintStructures->lpPrinterInfo->pPrinterName,
1146 PrintStructures->lpPrinterInfo->pPortName,
1148 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb3,
1149 PrintStructures->lpPrinterInfo->pPrinterName,
1150 PrintStructures->lpPrinterInfo->pPortName,
1152 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1153 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1154 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1155 PrintStructures->hLandscapeIcon));
1160 if ((lppd->Flags & PD_SHOWHELP)==0) {
1161 /* hide if PD_SHOWHELP not specified */
1162 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1167 static BOOL PRINTDLG_ChangePrinterW(HWND hDlg, WCHAR *name,
1168 PRINT_PTRW *PrintStructures)
1170 LPPRINTDLGW lppd = PrintStructures->dlg.lpPrintDlg;
1171 LPDEVMODEW lpdm = NULL;
1176 if(PrintStructures->lpPrinterInfo)
1177 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
1178 if(PrintStructures->lpDriverInfo)
1179 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
1180 if(!OpenPrinterW(name, &hprn, NULL)) {
1181 ERR("Can't open printer %s\n", debugstr_w(name));
1184 GetPrinterW(hprn, 2, NULL, 0, &needed);
1185 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
1186 GetPrinterW(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
1188 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
1189 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
1190 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
1192 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures->lpPrinterInfo->pPrinterName));
1197 PRINTDLG_UpdatePrinterInfoTextsW(hDlg, PrintStructures->lpPrinterInfo);
1199 if(PrintStructures->lpDevMode) {
1200 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
1201 PrintStructures->lpDevMode = NULL;
1204 dmSize = DocumentPropertiesW(0, 0, name, NULL, NULL, 0);
1206 ERR("DocumentProperties fails on %s\n", debugstr_w(name));
1209 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
1210 dmSize = DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, NULL,
1212 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
1213 !lstrcmpW(lpdm->dmDeviceName,
1214 PrintStructures->lpDevMode->dmDeviceName)) {
1215 /* Supplied devicemode matches current printer so try to use it */
1216 DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, lpdm,
1217 DM_OUT_BUFFER | DM_IN_BUFFER);
1220 GlobalUnlock(lppd->hDevMode);
1222 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
1224 if(!(lppd->Flags & PD_PRINTSETUP)) {
1225 /* Print range (All/Range/Selection) */
1226 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
1227 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
1228 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
1229 if (lppd->Flags & PD_NOSELECTION)
1230 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
1232 if (lppd->Flags & PD_SELECTION)
1233 CheckRadioButton(hDlg, rad1, rad3, rad2);
1234 if (lppd->Flags & PD_NOPAGENUMS) {
1235 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
1236 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
1237 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
1238 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
1239 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
1241 if (lppd->Flags & PD_PAGENUMS)
1242 CheckRadioButton(hDlg, rad1, rad3, rad3);
1244 /* "All xxx pages"... */
1247 char resourcestr[64];
1249 LoadStringA(COMDLG32_hInstance, PD32_PRINT_ALL_X_PAGES,
1251 sprintf(result,resourcestr,lppd->nMaxPage - lppd->nMinPage + 1);
1252 SendDlgItemMessageA(hDlg, rad1, WM_SETTEXT, 0, (LPARAM) result);
1257 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1259 if (lppd->Flags & PD_COLLATE) {
1260 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1261 (LPARAM)PrintStructures->hCollateIcon);
1262 CheckDlgButton(hDlg, chx2, 1);
1264 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1265 (LPARAM)PrintStructures->hNoCollateIcon);
1266 CheckDlgButton(hDlg, chx2, 0);
1269 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1270 /* if printer doesn't support it: no Collate */
1271 if (!(lpdm->dmFields & DM_COLLATE)) {
1272 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1273 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
1280 if (lppd->hDevMode == 0)
1281 copies = lppd->nCopies;
1283 copies = lpdm->dmCopies;
1284 if(copies == 0) copies = 1;
1285 else if(copies < 0) copies = MAX_COPIES;
1286 SetDlgItemInt(hDlg, edt3, copies, FALSE);
1289 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1290 /* if printer doesn't support it: no nCopies */
1291 if (!(lpdm->dmFields & DM_COPIES)) {
1292 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
1293 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
1298 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
1299 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
1300 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
1301 if (lppd->Flags & PD_HIDEPRINTTOFILE)
1302 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
1304 } else { /* PD_PRINTSETUP */
1305 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
1307 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb2,
1308 PrintStructures->lpPrinterInfo->pPrinterName,
1309 PrintStructures->lpPrinterInfo->pPortName,
1311 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb3,
1312 PrintStructures->lpPrinterInfo->pPrinterName,
1313 PrintStructures->lpPrinterInfo->pPortName,
1315 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1316 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1317 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1318 PrintStructures->hLandscapeIcon));
1323 if ((lppd->Flags & PD_SHOWHELP)==0) {
1324 /* hide if PD_SHOWHELP not specified */
1325 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1330 /***********************************************************************
1331 * PRINTDLG_WMInitDialog [internal]
1333 static LRESULT PRINTDLG_WMInitDialog(HWND hDlg, WPARAM wParam,
1334 PRINT_PTRA* PrintStructures)
1336 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
1340 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1342 /* load Collate ICONs */
1343 /* We load these with LoadImage because they are not a standard
1344 size and we don't want them rescaled */
1345 PrintStructures->hCollateIcon =
1346 LoadImageA(COMDLG32_hInstance, "PD32_COLLATE", IMAGE_ICON, 0, 0, 0);
1347 PrintStructures->hNoCollateIcon =
1348 LoadImageA(COMDLG32_hInstance, "PD32_NOCOLLATE", IMAGE_ICON, 0, 0, 0);
1350 /* These can be done with LoadIcon */
1351 PrintStructures->hPortraitIcon =
1352 LoadIconA(COMDLG32_hInstance, "PD32_PORTRAIT");
1353 PrintStructures->hLandscapeIcon =
1354 LoadIconA(COMDLG32_hInstance, "PD32_LANDSCAPE");
1356 if(PrintStructures->hCollateIcon == 0 ||
1357 PrintStructures->hNoCollateIcon == 0 ||
1358 PrintStructures->hPortraitIcon == 0 ||
1359 PrintStructures->hLandscapeIcon == 0) {
1360 ERR("no icon in resourcefile\n");
1361 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1362 EndDialog(hDlg, FALSE);
1366 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1367 * must be registered and the Help button must be shown.
1369 if (lppd->Flags & PD_SHOWHELP) {
1370 if((PrintStructures->HelpMessageID =
1371 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
1372 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1376 PrintStructures->HelpMessageID = 0;
1378 if(!(lppd->Flags &PD_PRINTSETUP)) {
1379 PrintStructures->hwndUpDown =
1380 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1381 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1382 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1383 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1384 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1387 /* FIXME: I allow more freedom than either Win95 or WinNT,
1388 * which do not agree to what errors should be thrown or not
1389 * in case nToPage or nFromPage is out-of-range.
1391 if (lppd->nMaxPage < lppd->nMinPage)
1392 lppd->nMaxPage = lppd->nMinPage;
1393 if (lppd->nMinPage == lppd->nMaxPage)
1394 lppd->Flags |= PD_NOPAGENUMS;
1395 if (lppd->nToPage < lppd->nMinPage)
1396 lppd->nToPage = lppd->nMinPage;
1397 if (lppd->nToPage > lppd->nMaxPage)
1398 lppd->nToPage = lppd->nMaxPage;
1399 if (lppd->nFromPage < lppd->nMinPage)
1400 lppd->nFromPage = lppd->nMinPage;
1401 if (lppd->nFromPage > lppd->nMaxPage)
1402 lppd->nFromPage = lppd->nMaxPage;
1404 /* if we have the combo box, fill it */
1405 if (GetDlgItem(hDlg,comboID)) {
1408 pdn = GlobalLock(lppd->hDevNames);
1409 pdm = GlobalLock(lppd->hDevMode);
1411 name = (char*)pdn + pdn->wDeviceOffset;
1413 name = pdm->dmDeviceName;
1414 PRINTDLG_SetUpPrinterListComboA(hDlg, comboID, name);
1415 if(pdm) GlobalUnlock(lppd->hDevMode);
1416 if(pdn) GlobalUnlock(lppd->hDevNames);
1418 /* Now find selected printer and update rest of dlg */
1419 name = HeapAlloc(GetProcessHeap(),0,256);
1420 if (GetDlgItemTextA(hDlg, comboID, name, 255))
1421 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1422 HeapFree(GetProcessHeap(),0,name);
1424 /* else use default printer */
1426 BOOL ret = PRINTDLG_GetDefaultPrinterNameA(name, sizeof(name));
1429 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1431 FIXME("No default printer found, expect problems!\n");
1436 static LRESULT PRINTDLG_WMInitDialogW(HWND hDlg, WPARAM wParam,
1437 PRINT_PTRW* PrintStructures)
1439 LPPRINTDLGW lppd = PrintStructures->dlg.lpPrintDlg;
1443 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1445 /* load Collate ICONs */
1446 /* We load these with LoadImage because they are not a standard
1447 size and we don't want them rescaled */
1448 PrintStructures->hCollateIcon =
1449 LoadImageA(COMDLG32_hInstance, "PD32_COLLATE", IMAGE_ICON, 0, 0, 0);
1450 PrintStructures->hNoCollateIcon =
1451 LoadImageA(COMDLG32_hInstance, "PD32_NOCOLLATE", IMAGE_ICON, 0, 0, 0);
1453 /* These can be done with LoadIcon */
1454 PrintStructures->hPortraitIcon =
1455 LoadIconA(COMDLG32_hInstance, "PD32_PORTRAIT");
1456 PrintStructures->hLandscapeIcon =
1457 LoadIconA(COMDLG32_hInstance, "PD32_LANDSCAPE");
1459 if(PrintStructures->hCollateIcon == 0 ||
1460 PrintStructures->hNoCollateIcon == 0 ||
1461 PrintStructures->hPortraitIcon == 0 ||
1462 PrintStructures->hLandscapeIcon == 0) {
1463 ERR("no icon in resourcefile\n");
1464 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1465 EndDialog(hDlg, FALSE);
1469 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1470 * must be registered and the Help button must be shown.
1472 if (lppd->Flags & PD_SHOWHELP) {
1473 if((PrintStructures->HelpMessageID =
1474 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
1475 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1479 PrintStructures->HelpMessageID = 0;
1481 if(!(lppd->Flags &PD_PRINTSETUP)) {
1482 PrintStructures->hwndUpDown =
1483 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1484 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1485 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1486 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1487 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1490 /* FIXME: I allow more freedom than either Win95 or WinNT,
1491 * which do not agree to what errors should be thrown or not
1492 * in case nToPage or nFromPage is out-of-range.
1494 if (lppd->nMaxPage < lppd->nMinPage)
1495 lppd->nMaxPage = lppd->nMinPage;
1496 if (lppd->nMinPage == lppd->nMaxPage)
1497 lppd->Flags |= PD_NOPAGENUMS;
1498 if (lppd->nToPage < lppd->nMinPage)
1499 lppd->nToPage = lppd->nMinPage;
1500 if (lppd->nToPage > lppd->nMaxPage)
1501 lppd->nToPage = lppd->nMaxPage;
1502 if (lppd->nFromPage < lppd->nMinPage)
1503 lppd->nFromPage = lppd->nMinPage;
1504 if (lppd->nFromPage > lppd->nMaxPage)
1505 lppd->nFromPage = lppd->nMaxPage;
1507 /* if we have the combo box, fill it */
1508 if (GetDlgItem(hDlg,comboID)) {
1511 pdn = GlobalLock(lppd->hDevNames);
1512 pdm = GlobalLock(lppd->hDevMode);
1514 name = (WCHAR*)pdn + pdn->wDeviceOffset;
1516 name = pdm->dmDeviceName;
1517 PRINTDLG_SetUpPrinterListComboW(hDlg, comboID, name);
1518 if(pdm) GlobalUnlock(lppd->hDevMode);
1519 if(pdn) GlobalUnlock(lppd->hDevNames);
1521 /* Now find selected printer and update rest of dlg */
1522 /* ansi is ok here */
1523 name = HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR));
1524 if (GetDlgItemTextW(hDlg, comboID, name, 255))
1525 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1526 HeapFree(GetProcessHeap(),0,name);
1528 /* else use default printer */
1530 BOOL ret = PRINTDLG_GetDefaultPrinterNameW(name, sizeof(name));
1533 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1535 FIXME("No default printer found, expect problems!\n");
1541 /***********************************************************************
1542 * PRINTDLG_WMInitDialog [internal]
1544 static LRESULT PRINTDLG_WMInitDialog16(HWND hDlg, WPARAM wParam,
1545 PRINT_PTRA* PrintStructures)
1547 LPPRINTDLG16 lppd = PrintStructures->dlg.lpPrintDlg16;
1551 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1553 /* load Collate ICONs */
1554 PrintStructures->hCollateIcon =
1555 LoadIconA(COMDLG32_hInstance, "PD32_COLLATE");
1556 PrintStructures->hNoCollateIcon =
1557 LoadIconA(COMDLG32_hInstance, "PD32_NOCOLLATE");
1558 if(PrintStructures->hCollateIcon == 0 ||
1559 PrintStructures->hNoCollateIcon == 0) {
1560 ERR("no icon in resourcefile\n");
1561 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1562 EndDialog(hDlg, FALSE);
1565 /* load Paper Orientation ICON */
1566 /* FIXME: not implemented yet */
1569 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1570 * must be registered and the Help button must be shown.
1572 if (lppd->Flags & PD_SHOWHELP) {
1573 if((PrintStructures->HelpMessageID =
1574 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
1575 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1579 PrintStructures->HelpMessageID = 0;
1581 if (!(lppd->Flags & PD_PRINTSETUP)) {
1582 /* We have a print quality combo box. What shall we do? */
1583 if (GetDlgItem(hDlg,cmb1)) {
1586 FIXME("Print quality only displaying currently.\n");
1588 pdm = GlobalLock16(lppd->hDevMode);
1590 switch (pdm->dmPrintQuality) {
1591 case DMRES_HIGH : strcpy(buf,"High");break;
1592 case DMRES_MEDIUM : strcpy(buf,"Medium");break;
1593 case DMRES_LOW : strcpy(buf,"Low");break;
1594 case DMRES_DRAFT : strcpy(buf,"Draft");break;
1595 case 0 : strcpy(buf,"Default");break;
1596 default : sprintf(buf,"%ddpi",pdm->dmPrintQuality);break;
1598 GlobalUnlock16(lppd->hDevMode);
1600 strcpy(buf,"Default");
1601 SendDlgItemMessageA(hDlg,cmb1,CB_ADDSTRING,0,(LPARAM)buf);
1602 SendDlgItemMessageA(hDlg,cmb1,CB_SETCURSEL,0,0);
1603 EnableWindow(GetDlgItem(hDlg,cmb1),FALSE);
1607 /* FIXME: I allow more freedom than either Win95 or WinNT,
1608 * which do not agree to what errors should be thrown or not
1609 * in case nToPage or nFromPage is out-of-range.
1611 if (lppd->nMaxPage < lppd->nMinPage)
1612 lppd->nMaxPage = lppd->nMinPage;
1613 if (lppd->nMinPage == lppd->nMaxPage)
1614 lppd->Flags |= PD_NOPAGENUMS;
1615 if (lppd->nToPage < lppd->nMinPage)
1616 lppd->nToPage = lppd->nMinPage;
1617 if (lppd->nToPage > lppd->nMaxPage)
1618 lppd->nToPage = lppd->nMaxPage;
1619 if (lppd->nFromPage < lppd->nMinPage)
1620 lppd->nFromPage = lppd->nMinPage;
1621 if (lppd->nFromPage > lppd->nMaxPage)
1622 lppd->nFromPage = lppd->nMaxPage;
1624 /* If the printer combo box is in the dialog, fill it */
1625 if (GetDlgItem(hDlg,comboID)) {
1628 pdn = GlobalLock16(lppd->hDevNames);
1629 pdm = GlobalLock16(lppd->hDevMode);
1631 name = (char*)pdn + pdn->wDeviceOffset;
1633 name = pdm->dmDeviceName;
1634 PRINTDLG_SetUpPrinterListComboA(hDlg, comboID, name);
1635 if(pdm) GlobalUnlock16(lppd->hDevMode);
1636 if(pdn) GlobalUnlock16(lppd->hDevNames);
1638 /* Now find selected printer and update rest of dlg */
1639 name = HeapAlloc(GetProcessHeap(),0,256);
1640 if (GetDlgItemTextA(hDlg, comboID, name, 255))
1641 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1643 /* else just use default printer */
1645 BOOL ret = PRINTDLG_GetDefaultPrinterNameA(name, sizeof(name));
1648 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1650 FIXME("No default printer found, expect problems!\n");
1652 HeapFree(GetProcessHeap(),0,name);
1657 /***********************************************************************
1658 * PRINTDLG_WMCommand [internal]
1660 static LRESULT PRINTDLG_WMCommandA(HWND hDlg, WPARAM wParam,
1661 LPARAM lParam, PRINT_PTRA* PrintStructures)
1663 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
1664 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1665 LPDEVMODEA lpdm = PrintStructures->lpDevMode;
1667 switch (LOWORD(wParam)) {
1669 TRACE(" OK button was hit\n");
1670 if (PRINTDLG_UpdatePrintDlgA(hDlg, PrintStructures)!=TRUE) {
1671 FIXME("Update printdlg was not successful!\n");
1674 EndDialog(hDlg, TRUE);
1678 TRACE(" CANCEL button was hit\n");
1679 EndDialog(hDlg, FALSE);
1683 TRACE(" HELP button was hit\n");
1684 SendMessageA(lppd->hwndOwner, PrintStructures->HelpMessageID,
1685 (WPARAM) hDlg, (LPARAM) lppd);
1688 case chx2: /* collate pages checkbox */
1689 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1690 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1691 (LPARAM)PrintStructures->hCollateIcon);
1693 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1694 (LPARAM)PrintStructures->hNoCollateIcon);
1696 case edt1: /* from page nr editbox */
1697 case edt2: /* to page nr editbox */
1698 if (HIWORD(wParam)==EN_CHANGE) {
1701 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1702 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1703 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1704 CheckRadioButton(hDlg, rad1, rad3, rad3);
1709 if(HIWORD(wParam) == EN_CHANGE) {
1710 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1712 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1714 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1718 case psh1: /* Print Setup */
1722 if (!PrintStructures->dlg.lpPrintDlg16) {
1723 FIXME("The 32bit print dialog does not have this button!?\n");
1727 memcpy(&pdlg,PrintStructures->dlg.lpPrintDlg16,sizeof(pdlg));
1728 pdlg.Flags |= PD_PRINTSETUP;
1729 pdlg.hwndOwner = HWND_16(hDlg);
1730 if (!PrintDlg16(&pdlg))
1734 case psh2: /* Properties button */
1737 char PrinterName[256];
1739 GetDlgItemTextA(hDlg, PrinterComboID, PrinterName, 255);
1740 if (!OpenPrinterA(PrinterName, &hPrinter, NULL)) {
1741 FIXME(" Call to OpenPrinter did not succeed!\n");
1744 DocumentPropertiesA(hDlg, hPrinter, PrinterName,
1745 PrintStructures->lpDevMode,
1746 PrintStructures->lpDevMode,
1747 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1748 ClosePrinter(hPrinter);
1752 case rad1: /* Paperorientation */
1753 if (lppd->Flags & PD_PRINTSETUP)
1755 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1756 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1757 (LPARAM)(PrintStructures->hPortraitIcon));
1761 case rad2: /* Paperorientation */
1762 if (lppd->Flags & PD_PRINTSETUP)
1764 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1765 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1766 (LPARAM)(PrintStructures->hLandscapeIcon));
1770 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1771 if (PrinterComboID != wParam) {
1772 FIXME("No handling for print quality combo box yet.\n");
1776 case cmb4: /* Printer combobox */
1777 if (HIWORD(wParam)==CBN_SELCHANGE) {
1778 char PrinterName[256];
1779 GetDlgItemTextA(hDlg, LOWORD(wParam), PrinterName, 255);
1780 PRINTDLG_ChangePrinterA(hDlg, PrinterName, PrintStructures);
1784 case cmb2: /* Papersize */
1786 DWORD Sel = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1788 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
1794 case cmb3: /* Bin */
1796 DWORD Sel = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1798 lpdm->dmDefaultSource = SendDlgItemMessageA(hDlg, cmb3,
1799 CB_GETITEMDATA, Sel,
1804 if(lppd->Flags & PD_PRINTSETUP) {
1805 switch (LOWORD(wParam)) {
1806 case rad1: /* orientation */
1808 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1809 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1810 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1811 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1813 (LPARAM)PrintStructures->hPortraitIcon);
1814 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1816 (LPARAM)PrintStructures->hPortraitIcon);
1819 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1820 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1821 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1823 (LPARAM)PrintStructures->hLandscapeIcon);
1824 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1826 (LPARAM)PrintStructures->hLandscapeIcon);
1835 static LRESULT PRINTDLG_WMCommandW(HWND hDlg, WPARAM wParam,
1836 LPARAM lParam, PRINT_PTRW* PrintStructures)
1838 LPPRINTDLGW lppd = PrintStructures->dlg.lpPrintDlg;
1839 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1840 LPDEVMODEW lpdm = PrintStructures->lpDevMode;
1842 switch (LOWORD(wParam)) {
1844 TRACE(" OK button was hit\n");
1845 if (PRINTDLG_UpdatePrintDlgW(hDlg, PrintStructures)!=TRUE) {
1846 FIXME("Update printdlg was not successful!\n");
1849 EndDialog(hDlg, TRUE);
1853 TRACE(" CANCEL button was hit\n");
1854 EndDialog(hDlg, FALSE);
1858 TRACE(" HELP button was hit\n");
1859 SendMessageW(lppd->hwndOwner, PrintStructures->HelpMessageID,
1860 (WPARAM) hDlg, (LPARAM) lppd);
1863 case chx2: /* collate pages checkbox */
1864 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1865 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1866 (LPARAM)PrintStructures->hCollateIcon);
1868 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1869 (LPARAM)PrintStructures->hNoCollateIcon);
1871 case edt1: /* from page nr editbox */
1872 case edt2: /* to page nr editbox */
1873 if (HIWORD(wParam)==EN_CHANGE) {
1876 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1877 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1878 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1879 CheckRadioButton(hDlg, rad1, rad3, rad3);
1884 if(HIWORD(wParam) == EN_CHANGE) {
1885 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1887 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1889 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1893 case psh1: /* Print Setup */
1895 ERR("psh1 is called from 16bit code only, we should not get here.\n");
1898 case psh2: /* Properties button */
1901 WCHAR PrinterName[256];
1903 GetDlgItemTextW(hDlg, PrinterComboID, PrinterName, 255);
1904 if (!OpenPrinterW(PrinterName, &hPrinter, NULL)) {
1905 FIXME(" Call to OpenPrinter did not succeed!\n");
1908 DocumentPropertiesW(hDlg, hPrinter, PrinterName,
1909 PrintStructures->lpDevMode,
1910 PrintStructures->lpDevMode,
1911 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1912 ClosePrinter(hPrinter);
1916 case rad1: /* Paperorientation */
1917 if (lppd->Flags & PD_PRINTSETUP)
1919 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1920 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1921 (LPARAM)(PrintStructures->hPortraitIcon));
1925 case rad2: /* Paperorientation */
1926 if (lppd->Flags & PD_PRINTSETUP)
1928 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1929 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1930 (LPARAM)(PrintStructures->hLandscapeIcon));
1934 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1935 if (PrinterComboID != wParam) {
1936 FIXME("No handling for print quality combo box yet.\n");
1940 case cmb4: /* Printer combobox */
1941 if (HIWORD(wParam)==CBN_SELCHANGE) {
1942 WCHAR PrinterName[256];
1943 GetDlgItemTextW(hDlg, LOWORD(wParam), PrinterName, 255);
1944 PRINTDLG_ChangePrinterW(hDlg, PrinterName, PrintStructures);
1948 case cmb2: /* Papersize */
1950 DWORD Sel = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1952 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
1958 case cmb3: /* Bin */
1960 DWORD Sel = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1962 lpdm->dmDefaultSource = SendDlgItemMessageW(hDlg, cmb3,
1963 CB_GETITEMDATA, Sel,
1968 if(lppd->Flags & PD_PRINTSETUP) {
1969 switch (LOWORD(wParam)) {
1970 case rad1: /* orientation */
1972 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1973 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1974 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1975 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1977 (LPARAM)PrintStructures->hPortraitIcon);
1978 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1980 (LPARAM)PrintStructures->hPortraitIcon);
1983 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1984 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1985 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1987 (LPARAM)PrintStructures->hLandscapeIcon);
1988 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1990 (LPARAM)PrintStructures->hLandscapeIcon);
1999 /***********************************************************************
2000 * PrintDlgProcA [internal]
2002 BOOL WINAPI PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
2005 PRINT_PTRA* PrintStructures;
2008 if (uMsg!=WM_INITDIALOG) {
2009 PrintStructures = (PRINT_PTRA*)GetPropA(hDlg,"__WINE_PRINTDLGDATA");
2010 if (!PrintStructures)
2013 PrintStructures = (PRINT_PTRA*) lParam;
2014 SetPropA(hDlg,"__WINE_PRINTDLGDATA",lParam);
2015 res = PRINTDLG_WMInitDialog(hDlg, wParam, PrintStructures);
2017 if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
2018 res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(
2019 hDlg, uMsg, wParam, (LPARAM)PrintStructures->dlg.lpPrintDlg
2024 if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
2025 res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam,
2032 return PRINTDLG_WMCommandA(hDlg, wParam, lParam, PrintStructures);
2035 DestroyIcon(PrintStructures->hCollateIcon);
2036 DestroyIcon(PrintStructures->hNoCollateIcon);
2037 DestroyIcon(PrintStructures->hPortraitIcon);
2038 DestroyIcon(PrintStructures->hLandscapeIcon);
2039 if(PrintStructures->hwndUpDown)
2040 DestroyWindow(PrintStructures->hwndUpDown);
2046 BOOL WINAPI PrintDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
2049 PRINT_PTRW* PrintStructures;
2052 if (uMsg!=WM_INITDIALOG) {
2053 PrintStructures = (PRINT_PTRW*) GetWindowLongA(hDlg, DWL_USER);
2054 if (!PrintStructures)
2057 PrintStructures = (PRINT_PTRW*) lParam;
2058 SetWindowLongA(hDlg, DWL_USER, lParam);
2059 res = PRINTDLG_WMInitDialogW(hDlg, wParam, PrintStructures);
2061 if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
2062 res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(
2063 hDlg, uMsg, wParam, (LPARAM)PrintStructures->dlg.lpPrintDlg
2068 if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
2069 res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam,
2076 return PRINTDLG_WMCommandW(hDlg, wParam, lParam, PrintStructures);
2079 DestroyIcon(PrintStructures->hCollateIcon);
2080 DestroyIcon(PrintStructures->hNoCollateIcon);
2081 DestroyIcon(PrintStructures->hPortraitIcon);
2082 DestroyIcon(PrintStructures->hLandscapeIcon);
2083 if(PrintStructures->hwndUpDown)
2084 DestroyWindow(PrintStructures->hwndUpDown);
2091 /************************************************************
2093 * PRINTDLG_Get16TemplateFrom32 [Internal]
2094 * Generates a 16 bits template from the Wine 32 bits resource
2097 static HGLOBAL16 PRINTDLG_Get16TemplateFrom32(char *PrintResourceName)
2103 HGLOBAL16 hGlobal16;
2106 if (!(hResInfo = FindResourceA(COMMDLG_hInstance32,
2107 PrintResourceName, RT_DIALOGA)))
2109 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
2112 if (!(hDlgTmpl32 = LoadResource(COMMDLG_hInstance32, hResInfo )) ||
2113 !(template32 = LockResource( hDlgTmpl32 )))
2115 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2118 size = SizeofResource(COMMDLG_hInstance32, hResInfo);
2119 hGlobal16 = GlobalAlloc16(0, size);
2122 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
2123 ERR("alloc failure for %ld bytes\n", size);
2126 template = GlobalLock16(hGlobal16);
2129 COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE);
2130 ERR("global lock failure for %x handle\n", hGlobal16);
2131 GlobalFree16(hGlobal16);
2134 ConvertDialog32To16((LPVOID)template32, size, (LPVOID)template);
2135 GlobalUnlock16(hGlobal16);
2139 /************************************************************
2141 * PRINTDLG_GetDlgTemplate
2144 static HGLOBAL PRINTDLG_GetDlgTemplateA(PRINTDLGA *lppd)
2149 if (lppd->Flags & PD_PRINTSETUP) {
2150 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
2151 hDlgTmpl = lppd->hSetupTemplate;
2152 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
2153 hResInfo = FindResourceA(lppd->hInstance,
2154 lppd->lpSetupTemplateName, RT_DIALOGA);
2155 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2157 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32_SETUP",
2159 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
2162 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
2163 hDlgTmpl = lppd->hPrintTemplate;
2164 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
2165 hResInfo = FindResourceA(lppd->hInstance,
2166 lppd->lpPrintTemplateName,
2168 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2170 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32",
2172 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
2178 static HGLOBAL PRINTDLG_GetDlgTemplateW(PRINTDLGW *lppd)
2182 const WCHAR xpsetup[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
2183 const WCHAR xprint[] = { 'P','R','I','N','T','3','2',0};
2185 if (lppd->Flags & PD_PRINTSETUP) {
2186 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
2187 hDlgTmpl = lppd->hSetupTemplate;
2188 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
2189 hResInfo = FindResourceW(lppd->hInstance,
2190 lppd->lpSetupTemplateName, RT_DIALOGW);
2191 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2193 hResInfo = FindResourceW(COMDLG32_hInstance, xpsetup, RT_DIALOGW);
2194 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
2197 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
2198 hDlgTmpl = lppd->hPrintTemplate;
2199 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
2200 hResInfo = FindResourceW(lppd->hInstance,
2201 lppd->lpPrintTemplateName,
2203 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2205 hResInfo = FindResourceW(COMDLG32_hInstance, xprint, RT_DIALOGW);
2206 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
2214 /************************************************************
2216 * PRINTDLG_GetDlgTemplate
2219 static HGLOBAL16 PRINTDLG_GetDlgTemplate16(PRINTDLG16 *lppd)
2221 HGLOBAL16 hDlgTmpl, hResInfo;
2223 if (lppd->Flags & PD_PRINTSETUP) {
2224 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
2225 hDlgTmpl = lppd->hSetupTemplate;
2226 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
2227 hResInfo = FindResource16(lppd->hInstance,
2228 MapSL(lppd->lpSetupTemplateName), RT_DIALOGA);
2229 hDlgTmpl = LoadResource16(lppd->hInstance, hResInfo);
2231 hDlgTmpl = PRINTDLG_Get16TemplateFrom32("PRINT32_SETUP");
2234 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
2235 hDlgTmpl = lppd->hPrintTemplate;
2236 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
2237 hResInfo = FindResource16(lppd->hInstance,
2238 MapSL(lppd->lpPrintTemplateName),
2240 hDlgTmpl = LoadResource16(lppd->hInstance, hResInfo);
2242 hDlgTmpl = PRINTDLG_Get16TemplateFrom32("PRINT32");
2248 /***********************************************************************
2253 static BOOL PRINTDLG_CreateDCA(LPPRINTDLGA lppd)
2255 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
2256 DEVMODEA *pdm = GlobalLock(lppd->hDevMode);
2258 if(lppd->Flags & PD_RETURNDC) {
2259 lppd->hDC = CreateDCA((char*)pdn + pdn->wDriverOffset,
2260 (char*)pdn + pdn->wDeviceOffset,
2261 (char*)pdn + pdn->wOutputOffset,
2263 } else if(lppd->Flags & PD_RETURNIC) {
2264 lppd->hDC = CreateICA((char*)pdn + pdn->wDriverOffset,
2265 (char*)pdn + pdn->wDeviceOffset,
2266 (char*)pdn + pdn->wOutputOffset,
2269 GlobalUnlock(lppd->hDevNames);
2270 GlobalUnlock(lppd->hDevMode);
2271 return lppd->hDC ? TRUE : FALSE;
2274 static BOOL PRINTDLG_CreateDCW(LPPRINTDLGW lppd)
2276 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
2277 DEVMODEW *pdm = GlobalLock(lppd->hDevMode);
2279 if(lppd->Flags & PD_RETURNDC) {
2280 lppd->hDC = CreateDCW((WCHAR*)pdn + pdn->wDriverOffset,
2281 (WCHAR*)pdn + pdn->wDeviceOffset,
2282 (WCHAR*)pdn + pdn->wOutputOffset,
2284 } else if(lppd->Flags & PD_RETURNIC) {
2285 lppd->hDC = CreateICW((WCHAR*)pdn + pdn->wDriverOffset,
2286 (WCHAR*)pdn + pdn->wDeviceOffset,
2287 (WCHAR*)pdn + pdn->wOutputOffset,
2290 GlobalUnlock(lppd->hDevNames);
2291 GlobalUnlock(lppd->hDevMode);
2292 return lppd->hDC ? TRUE : FALSE;
2295 static BOOL PRINTDLG_CreateDC16(LPPRINTDLG16 lppd)
2297 DEVNAMES *pdn = GlobalLock16(lppd->hDevNames);
2298 DEVMODEA *pdm = GlobalLock16(lppd->hDevMode);
2300 if(lppd->Flags & PD_RETURNDC) {
2301 lppd->hDC = CreateDCA((char*)pdn + pdn->wDriverOffset,
2302 (char*)pdn + pdn->wDeviceOffset,
2303 (char*)pdn + pdn->wOutputOffset,
2305 } else if(lppd->Flags & PD_RETURNIC) {
2306 lppd->hDC = CreateICA((char*)pdn + pdn->wDriverOffset,
2307 (char*)pdn + pdn->wDeviceOffset,
2308 (char*)pdn + pdn->wOutputOffset,
2311 GlobalUnlock16(lppd->hDevNames);
2312 GlobalUnlock16(lppd->hDevMode);
2313 return lppd->hDC ? TRUE : FALSE;
2316 /***********************************************************************
2317 * PrintDlgA (COMDLG32.@)
2319 * Displays the the PRINT dialog box, which enables the user to specify
2320 * specific properties of the print job.
2323 * nonzero if the user pressed the OK button
2324 * zero if the user cancelled the window or an error occurred
2328 * * The Collate Icons do not display, even though they are in the code.
2329 * * The Properties Button(s) should call DocumentPropertiesA().
2331 * * The Paper Orientation Icons are not implemented yet.
2332 * * The Properties Button(s) should call DocumentPropertiesA().
2333 * * Settings are not yet taken from a provided DevMode or
2334 * default printer settings.
2337 BOOL WINAPI PrintDlgA(
2338 LPPRINTDLGA lppd /* [in/out] ptr to PRINTDLG32 struct */
2343 HINSTANCE hInst = GetWindowLongA( lppd->hwndOwner, GWL_HINSTANCE );
2345 if(TRACE_ON(commdlg)) {
2346 char flagstr[1000] = "";
2347 struct pd_flags *pflag = pd_flags;
2348 for( ; pflag->name; pflag++) {
2349 if(lppd->Flags & pflag->flag)
2350 strcat(flagstr, pflag->name);
2352 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
2353 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %08x\n"
2354 "flags %08lx (%s)\n",
2355 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2356 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2357 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2360 if(lppd->lStructSize != sizeof(PRINTDLGA)) {
2361 WARN("structure size failure !!!\n");
2362 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2366 if(lppd->Flags & PD_RETURNDEFAULT) {
2367 PRINTER_INFO_2A *pbuf;
2368 DRIVER_INFO_3A *dbuf;
2372 if(lppd->hDevMode || lppd->hDevNames) {
2373 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2374 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2377 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2378 WARN("Can't find default printer\n");
2379 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2383 GetPrinterA(hprn, 2, NULL, 0, &needed);
2384 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
2385 GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2387 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
2388 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
2389 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2390 ERR("GetPrinterDriverA failed, le %ld, fix your config for printer %s!\n",GetLastError(),pbuf->pPrinterName);
2391 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2396 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2400 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2401 pbuf->pDevMode->dmDriverExtra);
2402 ptr = GlobalLock(lppd->hDevMode);
2403 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2404 pbuf->pDevMode->dmDriverExtra);
2405 GlobalUnlock(lppd->hDevMode);
2406 HeapFree(GetProcessHeap(), 0, pbuf);
2407 HeapFree(GetProcessHeap(), 0, dbuf);
2411 PRINT_PTRA *PrintStructures;
2413 /* load Dialog resources,
2414 * depending on Flags indicates Print32 or Print32_setup dialog
2416 hDlgTmpl = PRINTDLG_GetDlgTemplateA(lppd);
2418 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2421 ptr = LockResource( hDlgTmpl );
2423 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2427 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2428 sizeof(PRINT_PTRA));
2429 PrintStructures->dlg.lpPrintDlg = lppd;
2431 /* and create & process the dialog .
2432 * -1 is failure, 0 is broken hwnd, everything else is ok.
2434 bRet = (0<DialogBoxIndirectParamA(hInst, ptr, lppd->hwndOwner,
2436 (LPARAM)PrintStructures));
2439 DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2440 PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
2441 DRIVER_INFO_3A *di = PrintStructures->lpDriverInfo;
2443 if (lppd->hDevMode == 0) {
2444 TRACE(" No hDevMode yet... Need to create my own\n");
2445 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2446 lpdm->dmSize + lpdm->dmDriverExtra);
2449 if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
2450 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2452 GlobalUnlock(lppd->hDevMode);
2453 TRACE("Now got %d locks\n", locks);
2456 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2457 lpdm->dmSize + lpdm->dmDriverExtra,
2460 lpdmReturn = GlobalLock(lppd->hDevMode);
2461 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2463 if (lppd->hDevNames != 0) {
2465 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
2466 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2468 GlobalUnlock(lppd->hDevNames);
2471 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2476 GlobalUnlock(lppd->hDevMode);
2478 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2479 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2480 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2481 HeapFree(GetProcessHeap(), 0, PrintStructures);
2483 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2484 bRet = PRINTDLG_CreateDCA(lppd);
2486 TRACE("exit! (%d)\n", bRet);
2490 /***********************************************************************
2491 * PrintDlgW (COMDLG32.@)
2493 BOOL WINAPI PrintDlgW(
2494 LPPRINTDLGW lppd /* [in/out] ptr to PRINTDLG32 struct */
2499 HINSTANCE hInst = GetWindowLongA( lppd->hwndOwner, GWL_HINSTANCE );
2501 if(TRACE_ON(commdlg)) {
2502 char flagstr[1000] = "";
2503 struct pd_flags *pflag = pd_flags;
2504 for( ; pflag->name; pflag++) {
2505 if(lppd->Flags & pflag->flag)
2506 strcat(flagstr, pflag->name);
2508 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
2509 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %08x\n"
2510 "flags %08lx (%s)\n",
2511 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2512 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2513 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2516 if(lppd->lStructSize != sizeof(PRINTDLGW)) {
2517 WARN("structure size failure !!!\n");
2518 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2522 if(lppd->Flags & PD_RETURNDEFAULT) {
2523 PRINTER_INFO_2W *pbuf;
2524 DRIVER_INFO_3W *dbuf;
2528 if(lppd->hDevMode || lppd->hDevNames) {
2529 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2530 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2533 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2534 WARN("Can't find default printer\n");
2535 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2539 GetPrinterW(hprn, 2, NULL, 0, &needed);
2540 pbuf = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*needed);
2541 GetPrinterW(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2543 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
2544 dbuf = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
2545 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2546 ERR("GetPrinterDriverA failed, le %ld, fix your config for printer %s!\n",GetLastError(),debugstr_w(pbuf->pPrinterName));
2547 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2552 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2556 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2557 pbuf->pDevMode->dmDriverExtra);
2558 ptr = GlobalLock(lppd->hDevMode);
2559 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2560 pbuf->pDevMode->dmDriverExtra);
2561 GlobalUnlock(lppd->hDevMode);
2562 HeapFree(GetProcessHeap(), 0, pbuf);
2563 HeapFree(GetProcessHeap(), 0, dbuf);
2567 PRINT_PTRW *PrintStructures;
2569 /* load Dialog resources,
2570 * depending on Flags indicates Print32 or Print32_setup dialog
2572 hDlgTmpl = PRINTDLG_GetDlgTemplateW(lppd);
2574 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2577 ptr = LockResource( hDlgTmpl );
2579 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2583 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2584 sizeof(PRINT_PTRW));
2585 PrintStructures->dlg.lpPrintDlg = lppd;
2587 /* and create & process the dialog .
2588 * -1 is failure, 0 is broken hwnd, everything else is ok.
2590 bRet = (0<DialogBoxIndirectParamW(hInst, ptr, lppd->hwndOwner,
2592 (LPARAM)PrintStructures));
2595 DEVMODEW *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2596 PRINTER_INFO_2W *pi = PrintStructures->lpPrinterInfo;
2597 DRIVER_INFO_3W *di = PrintStructures->lpDriverInfo;
2599 if (lppd->hDevMode == 0) {
2600 TRACE(" No hDevMode yet... Need to create my own\n");
2601 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2602 lpdm->dmSize + lpdm->dmDriverExtra);
2605 if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
2606 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2608 GlobalUnlock(lppd->hDevMode);
2609 TRACE("Now got %d locks\n", locks);
2612 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2613 lpdm->dmSize + lpdm->dmDriverExtra,
2616 lpdmReturn = GlobalLock(lppd->hDevMode);
2617 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2619 if (lppd->hDevNames != 0) {
2621 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
2622 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2624 GlobalUnlock(lppd->hDevNames);
2627 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2632 GlobalUnlock(lppd->hDevMode);
2634 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2635 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2636 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2637 HeapFree(GetProcessHeap(), 0, PrintStructures);
2639 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2640 bRet = PRINTDLG_CreateDCW(lppd);
2642 TRACE("exit! (%d)\n", bRet);
2646 /***********************************************************************
2647 * PrintDlg (COMMDLG.20)
2649 * Displays the the PRINT dialog box, which enables the user to specify
2650 * specific properties of the print job.
2653 * nonzero if the user pressed the OK button
2654 * zero if the user cancelled the window or an error occurred
2657 * * calls up to the 32-bit versions of the Dialogs, which look different
2658 * * Customizing is *not* implemented.
2661 BOOL16 WINAPI PrintDlg16(
2662 LPPRINTDLG16 lppd /* [in/out] ptr to PRINTDLG struct */
2666 HINSTANCE hInst = GetWindowLongA( HWND_32(lppd->hwndOwner), GWL_HINSTANCE );
2668 if(TRACE_ON(commdlg)) {
2669 char flagstr[1000] = "";
2670 struct pd_flags *pflag = pd_flags;
2671 for( ; pflag->name; pflag++) {
2672 if(lppd->Flags & pflag->flag)
2673 strcat(flagstr, pflag->name);
2675 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
2676 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %08x\n"
2677 "flags %08lx (%s)\n",
2678 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2679 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2680 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2683 if(lppd->lStructSize != sizeof(PRINTDLG16)) {
2684 ERR("structure size (%ld/%d)\n",lppd->lStructSize,sizeof(PRINTDLG16));
2685 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2689 if(lppd->Flags & PD_RETURNDEFAULT) {
2690 PRINTER_INFO_2A *pbuf;
2691 DRIVER_INFO_3A *dbuf;
2695 if(lppd->hDevMode || lppd->hDevNames) {
2696 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2697 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2700 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2701 WARN("Can't find default printer\n");
2702 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2706 GetPrinterA(hprn, 2, NULL, 0, &needed);
2707 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
2708 GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2709 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
2710 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
2711 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2712 ERR("GetPrinterDriverA failed for %s, le %ld, fix your config!\n",
2713 pbuf->pPrinterName,GetLastError());
2714 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2718 PRINTDLG_CreateDevNames16(&(lppd->hDevNames),
2722 lppd->hDevMode = GlobalAlloc16(GMEM_MOVEABLE,pbuf->pDevMode->dmSize+
2723 pbuf->pDevMode->dmDriverExtra);
2724 ptr = GlobalLock16(lppd->hDevMode);
2725 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2726 pbuf->pDevMode->dmDriverExtra);
2727 GlobalUnlock16(lppd->hDevMode);
2728 HeapFree(GetProcessHeap(), 0, pbuf);
2729 HeapFree(GetProcessHeap(), 0, dbuf);
2733 PRINT_PTRA *PrintStructures;
2735 /* load Dialog resources,
2736 * depending on Flags indicates Print32 or Print32_setup dialog
2738 hDlgTmpl = PRINTDLG_GetDlgTemplate16(lppd);
2740 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2743 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2744 sizeof(PRINT_PTRA));
2745 PrintStructures->dlg.lpPrintDlg16 = lppd;
2746 PrintStructures->dlg.lpPrintDlg = (LPPRINTDLGA)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(PRINTDLGA));
2747 #define CVAL(x) PrintStructures->dlg.lpPrintDlg->x = lppd->x;
2748 #define MVAL(x) PrintStructures->dlg.lpPrintDlg->x = MapSL(lppd->x);
2750 PrintStructures->dlg.lpPrintDlg->hwndOwner = HWND_32(lppd->hwndOwner);
2752 CVAL(nFromPage);CVAL(nToPage);CVAL(nMinPage);CVAL(nMaxPage);
2753 CVAL(nCopies);CVAL(hInstance);CVAL(lCustData);
2754 MVAL(lpPrintTemplateName);MVAL(lpSetupTemplateName);
2755 /* Don't copy rest, it is 16 bit specific */
2759 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(),0,sizeof(DEVMODEA));
2761 /* and create & process the dialog .
2762 * -1 is failure, 0 is broken hwnd, everything else is ok.
2764 bRet = (0<DialogBoxIndirectParam16(
2765 hInst, hDlgTmpl, lppd->hwndOwner,
2766 (DLGPROC16)GetProcAddress16(GetModuleHandle16("COMMDLG"),(LPCSTR)21),
2767 (LPARAM)PrintStructures
2770 if (!PrintStructures->lpPrinterInfo) bRet = FALSE;
2772 DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2773 PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
2774 DRIVER_INFO_3A *di = PrintStructures->lpDriverInfo;
2776 if (lppd->hDevMode == 0) {
2777 TRACE(" No hDevMode yet... Need to create my own\n");
2778 lppd->hDevMode = GlobalAlloc16(GMEM_MOVEABLE,
2779 lpdm->dmSize + lpdm->dmDriverExtra);
2782 if((locks = (GlobalFlags16(lppd->hDevMode)&GMEM_LOCKCOUNT))) {
2783 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2785 GlobalUnlock16(lppd->hDevMode);
2786 TRACE("Now got %d locks\n", locks);
2789 lppd->hDevMode = GlobalReAlloc16(lppd->hDevMode,
2790 lpdm->dmSize + lpdm->dmDriverExtra,
2793 lpdmReturn = GlobalLock16(lppd->hDevMode);
2794 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2796 if (lppd->hDevNames != 0) {
2798 if((locks = (GlobalFlags16(lppd->hDevNames)&GMEM_LOCKCOUNT))) {
2799 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2801 GlobalUnlock16(lppd->hDevNames);
2804 PRINTDLG_CreateDevNames16(&(lppd->hDevNames),
2809 GlobalUnlock16(lppd->hDevMode);
2811 if (!(lppd->Flags & (PD_ENABLESETUPTEMPLATEHANDLE | PD_ENABLESETUPTEMPLATE)))
2812 GlobalFree16(hDlgTmpl); /* created from the 32 bits resource */
2813 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2814 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2815 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2816 HeapFree(GetProcessHeap(), 0, PrintStructures);
2818 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2819 bRet = PRINTDLG_CreateDC16(lppd);
2821 TRACE("exit! (%d)\n", bRet);
2826 /***********************************************************************
2832 * cmb3 - source (tray?)
2833 * edt4 - border left
2835 * edt6 - border right
2836 * edt7 - border bottom
2837 * psh3 - "Printer..."
2841 LPPAGESETUPDLGA dlga;
2846 LPPAGESETUPDLGW dlga;
2850 static HGLOBAL PRINTDLG_GetPGSTemplateA(PAGESETUPDLGA *lppd)
2855 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2856 hDlgTmpl = lppd->hPageSetupTemplate;
2857 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2858 hResInfo = FindResourceA(lppd->hInstance,
2859 lppd->lpPageSetupTemplateName, RT_DIALOGA);
2860 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2862 hResInfo = FindResourceA(COMDLG32_hInstance,(LPCSTR)PAGESETUPDLGORD,RT_DIALOGA);
2863 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2868 static HGLOBAL PRINTDLG_GetPGSTemplateW(PAGESETUPDLGW *lppd)
2873 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2874 hDlgTmpl = lppd->hPageSetupTemplate;
2875 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2876 hResInfo = FindResourceW(lppd->hInstance,
2877 lppd->lpPageSetupTemplateName, RT_DIALOGW);
2878 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2880 hResInfo = FindResourceW(COMDLG32_hInstance,(LPCWSTR)PAGESETUPDLGORD,RT_DIALOGW);
2881 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2887 _c_10mm2size(PAGESETUPDLGA *dlga,DWORD size) {
2888 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2889 return 10*size*10/25.4;
2890 /* If we don't have a flag, we can choose one. Use millimeters
2891 * to avoid confusing me
2893 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2899 _c_inch2size(PAGESETUPDLGA *dlga,DWORD size) {
2900 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2902 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
2903 return (size*254)/10;
2904 /* if we don't have a flag, we can choose one. Use millimeters
2905 * to avoid confusing me
2907 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2908 return (size*254)/10;
2912 _c_size2strA(PageSetupDataA *pda,DWORD size,LPSTR strout) {
2913 strcpy(strout,"<undef>");
2914 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2915 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
2918 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2919 sprintf(strout,"%.2fin",(size*1.0)/1000.0);
2922 pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2923 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
2927 _c_size2strW(PageSetupDataW *pda,DWORD size,LPSTR strout) {
2928 strcpy(strout,"<undef>");
2929 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2930 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
2933 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2934 sprintf(strout,"%.2fin",(size*1.0)/1000.0);
2937 pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2938 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
2943 _c_str2size(PAGESETUPDLGA *dlga,LPCSTR strin) {
2948 if (!sscanf(strin,"%f%s",&val,rest))
2951 if (!strcmp(rest,"in") || !strcmp(rest,"inch")) {
2952 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2955 return val*25.4*100;
2957 if (!strcmp(rest,"cm")) { rest[0]='m'; val = val*10.0; }
2958 if (!strcmp(rest,"m")) { strcpy(rest,"mm"); val = val*1000.0; }
2960 if (!strcmp(rest,"mm")) {
2961 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
2964 return 1000.0*val/25.4;
2966 if (rest[0]=='\0') {
2967 /* use application supplied default */
2968 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2972 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2977 ERR("Did not find a conversion for type '%s'!\n",rest);
2983 * This is called on finish and will update the output fields of the
2987 PRINTDLG_PS_UpdateDlgStructA(HWND hDlg, PageSetupDataA *pda) {
2990 LPSTR devname,portname;
2994 dn = GlobalLock(pda->pdlg.hDevNames);
2995 dm = GlobalLock(pda->pdlg.hDevMode);
2996 devname = ((char*)dn)+dn->wDeviceOffset;
2997 portname = ((char*)dn)+dn->wOutputOffset;
2998 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb2,devname,portname,dm);
2999 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb3,devname,portname,dm);
3001 if (GetDlgItemTextA(hDlg,cmb2,papername,sizeof(papername))>0) {
3002 PRINTDLG_PaperSizeA(&(pda->pdlg),papername,&(pda->dlga->ptPaperSize));
3003 pda->dlga->ptPaperSize.x = _c_10mm2size(pda->dlga,pda->dlga->ptPaperSize.x);
3004 pda->dlga->ptPaperSize.y = _c_10mm2size(pda->dlga,pda->dlga->ptPaperSize.y);
3006 FIXME("could not get dialog text for papersize cmbbox?\n");
3007 #define GETVAL(id,val) if (GetDlgItemTextA(hDlg,id,buf,sizeof(buf))>0) { val = _c_str2size(pda->dlga,buf); } else { FIXME("could not get dlgitemtexta for %x\n",id); }
3008 GETVAL(edt4,pda->dlga->rtMargin.left);
3009 GETVAL(edt5,pda->dlga->rtMargin.top);
3010 GETVAL(edt6,pda->dlga->rtMargin.right);
3011 GETVAL(edt7,pda->dlga->rtMargin.bottom);
3014 /* If we are in landscape, swap x and y of page size */
3015 if (IsDlgButtonChecked(hDlg, rad2)) {
3017 tmp = pda->dlga->ptPaperSize.x;
3018 pda->dlga->ptPaperSize.x = pda->dlga->ptPaperSize.y;
3019 pda->dlga->ptPaperSize.y = tmp;
3021 GlobalUnlock(pda->pdlg.hDevNames);
3022 GlobalUnlock(pda->pdlg.hDevMode);
3027 PRINTDLG_PS_UpdateDlgStructW(HWND hDlg, PageSetupDataW *pda) {
3030 LPWSTR devname,portname;
3031 WCHAR papername[64];
3035 dn = GlobalLock(pda->pdlg.hDevNames);
3036 dm = GlobalLock(pda->pdlg.hDevMode);
3037 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
3038 portname = ((WCHAR*)dn)+dn->wOutputOffset;
3039 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
3040 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
3042 if (GetDlgItemTextW(hDlg,cmb2,papername,sizeof(papername))>0) {
3043 PRINTDLG_PaperSizeW(&(pda->pdlg),papername,&(pda->dlga->ptPaperSize));
3044 pda->dlga->ptPaperSize.x = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga,pda->dlga->ptPaperSize.x);
3045 pda->dlga->ptPaperSize.y = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga,pda->dlga->ptPaperSize.y);
3047 FIXME("could not get dialog text for papersize cmbbox?\n");
3048 #define GETVAL(id,val) if (GetDlgItemTextA(hDlg,id,buf,sizeof(buf))>0) { val = _c_str2size((LPPAGESETUPDLGA)pda->dlga,buf); } else { FIXME("could not get dlgitemtexta for %x\n",id); }
3049 GETVAL(edt4,pda->dlga->rtMargin.left);
3050 GETVAL(edt5,pda->dlga->rtMargin.top);
3051 GETVAL(edt6,pda->dlga->rtMargin.right);
3052 GETVAL(edt7,pda->dlga->rtMargin.bottom);
3055 /* If we are in landscape, swap x and y of page size */
3056 if (IsDlgButtonChecked(hDlg, rad2)) {
3058 tmp = pda->dlga->ptPaperSize.x;
3059 pda->dlga->ptPaperSize.x = pda->dlga->ptPaperSize.y;
3060 pda->dlga->ptPaperSize.y = tmp;
3062 GlobalUnlock(pda->pdlg.hDevNames);
3063 GlobalUnlock(pda->pdlg.hDevMode);
3068 * This is called after returning from PrintDlg().
3071 PRINTDLG_PS_ChangePrinterA(HWND hDlg, PageSetupDataA *pda) {
3074 LPSTR devname,portname;
3076 dn = GlobalLock(pda->pdlg.hDevNames);
3077 dm = GlobalLock(pda->pdlg.hDevMode);
3078 devname = ((char*)dn)+dn->wDeviceOffset;
3079 portname = ((char*)dn)+dn->wOutputOffset;
3080 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb2,devname,portname,dm);
3081 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb3,devname,portname,dm);
3082 GlobalUnlock(pda->pdlg.hDevNames);
3083 GlobalUnlock(pda->pdlg.hDevMode);
3088 PRINTDLG_PS_ChangePrinterW(HWND hDlg, PageSetupDataW *pda) {
3091 LPWSTR devname,portname;
3093 dn = GlobalLock(pda->pdlg.hDevNames);
3094 dm = GlobalLock(pda->pdlg.hDevMode);
3095 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
3096 portname = ((WCHAR*)dn)+dn->wOutputOffset;
3097 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
3098 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
3099 GlobalUnlock(pda->pdlg.hDevNames);
3100 GlobalUnlock(pda->pdlg.hDevMode);
3105 PRINTDLG_PS_WMCommandA(
3106 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataA *pda
3108 switch (LOWORD(wParam)) {
3110 if (!PRINTDLG_PS_UpdateDlgStructA(hDlg, pda))
3112 EndDialog(hDlg, TRUE);
3116 EndDialog(hDlg, FALSE);
3120 pda->pdlg.Flags = 0;
3121 pda->pdlg.hwndOwner = hDlg;
3122 if (PrintDlgA(&(pda->pdlg)))
3123 PRINTDLG_PS_ChangePrinterA(hDlg,pda);
3127 FIXME("loword (lparam) %d, wparam 0x%x, lparam %08lx, STUB mostly.\n",
3128 LOWORD(lParam),wParam,lParam
3134 PRINTDLG_PS_WMCommandW(
3135 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataW *pda
3137 switch (LOWORD(wParam)) {
3139 if (!PRINTDLG_PS_UpdateDlgStructW(hDlg, pda))
3141 EndDialog(hDlg, TRUE);
3145 EndDialog(hDlg, FALSE);
3149 pda->pdlg.Flags = 0;
3150 pda->pdlg.hwndOwner = hDlg;
3151 if (PrintDlgW(&(pda->pdlg)))
3152 PRINTDLG_PS_ChangePrinterW(hDlg,pda);
3156 FIXME("loword (lparam) %d, wparam 0x%x, lparam %08lx, STUB mostly.\n",
3157 LOWORD(lParam),wParam,lParam
3164 PageDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
3166 PageSetupDataA *pda;
3169 if (uMsg==WM_INITDIALOG) {
3171 pda = (PageSetupDataA*)lParam;
3172 SetPropA(hDlg,"__WINE_PAGESETUPDLGDATA",lParam);
3173 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3174 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3176 FIXME("Setup page hook failed?\n");
3180 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK) {
3181 FIXME("PagePaintHook not yet implemented!\n");
3183 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
3184 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
3185 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
3186 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
3187 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
3188 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
3189 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
3191 /* width larger as height -> landscape */
3192 if (pda->dlga->ptPaperSize.x > pda->dlga->ptPaperSize.y)
3193 CheckRadioButton(hDlg, rad1, rad2, rad2);
3194 else /* this is default if papersize is not set */
3195 CheckRadioButton(hDlg, rad1, rad2, rad1);
3196 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
3197 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
3198 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
3200 /* We fill them out enabled or not */
3201 if (pda->dlga->Flags & PSD_MARGINS) {
3203 _c_size2strA(pda,pda->dlga->rtMargin.left,str);
3204 SetDlgItemTextA(hDlg,edt4,str);
3205 _c_size2strA(pda,pda->dlga->rtMargin.top,str);
3206 SetDlgItemTextA(hDlg,edt5,str);
3207 _c_size2strA(pda,pda->dlga->rtMargin.right,str);
3208 SetDlgItemTextA(hDlg,edt6,str);
3209 _c_size2strA(pda,pda->dlga->rtMargin.bottom,str);
3210 SetDlgItemTextA(hDlg,edt7,str);
3212 /* default is 1 inch */
3213 DWORD size = _c_inch2size(pda->dlga,1000);
3215 _c_size2strA(pda,size,str);
3216 SetDlgItemTextA(hDlg,edt4,str);
3217 SetDlgItemTextA(hDlg,edt5,str);
3218 SetDlgItemTextA(hDlg,edt6,str);
3219 SetDlgItemTextA(hDlg,edt7,str);
3221 PRINTDLG_PS_ChangePrinterA(hDlg,pda);
3222 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
3223 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
3224 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
3228 pda = (PageSetupDataA*)GetPropA(hDlg,"__WINE_PAGESETUPDLGDATA");
3230 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3233 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3234 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3235 if (res) return res;
3240 return PRINTDLG_PS_WMCommandA(hDlg, wParam, lParam, pda);
3246 PageDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
3248 PageSetupDataW *pda;
3251 if (uMsg==WM_INITDIALOG) {
3253 pda = (PageSetupDataW*)lParam;
3254 SetPropA(hDlg,"__WINE_PAGESETUPDLGDATA",lParam);
3255 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3256 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3258 FIXME("Setup page hook failed?\n");
3262 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK) {
3263 FIXME("PagePaintHook not yet implemented!\n");
3265 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
3266 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
3267 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
3268 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
3269 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
3270 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
3271 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
3273 /* width larger as height -> landscape */
3274 if (pda->dlga->ptPaperSize.x > pda->dlga->ptPaperSize.y)
3275 CheckRadioButton(hDlg, rad1, rad2, rad2);
3276 else /* this is default if papersize is not set */
3277 CheckRadioButton(hDlg, rad1, rad2, rad1);
3278 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
3279 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
3280 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
3282 /* We fill them out enabled or not */
3283 if (pda->dlga->Flags & PSD_MARGINS) {
3285 _c_size2strW(pda,pda->dlga->rtMargin.left,str);
3286 SetDlgItemTextA(hDlg,edt4,str);
3287 _c_size2strW(pda,pda->dlga->rtMargin.top,str);
3288 SetDlgItemTextA(hDlg,edt5,str);
3289 _c_size2strW(pda,pda->dlga->rtMargin.right,str);
3290 SetDlgItemTextA(hDlg,edt6,str);
3291 _c_size2strW(pda,pda->dlga->rtMargin.bottom,str);
3292 SetDlgItemTextA(hDlg,edt7,str);
3294 /* default is 1 inch */
3295 DWORD size = _c_inch2size((LPPAGESETUPDLGA)pda->dlga,1000);
3297 _c_size2strW(pda,size,str);
3298 SetDlgItemTextA(hDlg,edt4,str);
3299 SetDlgItemTextA(hDlg,edt5,str);
3300 SetDlgItemTextA(hDlg,edt6,str);
3301 SetDlgItemTextA(hDlg,edt7,str);
3303 PRINTDLG_PS_ChangePrinterW(hDlg,pda);
3304 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
3305 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
3306 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
3310 pda = (PageSetupDataW*)GetPropA(hDlg,"__WINE_PAGESETUPDLGDATA");
3312 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3315 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3316 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3317 if (res) return res;
3322 return PRINTDLG_PS_WMCommandW(hDlg, wParam, lParam, pda);
3327 /***********************************************************************
3328 * PageSetupDlgA (COMDLG32.@)
3330 BOOL WINAPI PageSetupDlgA(LPPAGESETUPDLGA setupdlg) {
3334 PageSetupDataA *pda;
3337 if(TRACE_ON(commdlg)) {
3338 char flagstr[1000] = "";
3339 struct pd_flags *pflag = psd_flags;
3340 for( ; pflag->name; pflag++) {
3341 if(setupdlg->Flags & pflag->flag) {
3342 strcat(flagstr, pflag->name);
3343 strcat(flagstr, "|");
3346 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
3347 "hinst %08x, flags %08lx (%s)\n",
3348 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
3349 setupdlg->hDevNames,
3350 setupdlg->hInstance, setupdlg->Flags, flagstr);
3353 /* First get default printer data, we need it right after that. */
3354 memset(&pdlg,0,sizeof(pdlg));
3355 pdlg.lStructSize = sizeof(pdlg);
3356 pdlg.Flags = PD_RETURNDEFAULT;
3357 bRet = PrintDlgA(&pdlg);
3358 if (!bRet) return FALSE;
3360 /* short cut exit, just return default values */
3361 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
3362 setupdlg->hDevMode = pdlg.hDevMode;
3363 setupdlg->hDevNames = pdlg.hDevNames;
3364 /* FIXME: Just return "A4" for now. */
3365 PRINTDLG_PaperSizeA(&pdlg,"A4",&setupdlg->ptPaperSize);
3366 setupdlg->ptPaperSize.x=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.x);
3367 setupdlg->ptPaperSize.y=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.y);
3370 hDlgTmpl = PRINTDLG_GetPGSTemplateA(setupdlg);
3372 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3375 ptr = LockResource( hDlgTmpl );
3377 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3380 pda = HeapAlloc(GetProcessHeap(),0,sizeof(*pda));
3381 pda->dlga = setupdlg;
3382 memcpy(&pda->pdlg,&pdlg,sizeof(pdlg));
3384 bRet = (0<DialogBoxIndirectParamA(
3385 setupdlg->hInstance,
3387 setupdlg->hwndOwner,
3393 /***********************************************************************
3394 * PageSetupDlgW (COMDLG32.@)
3396 BOOL WINAPI PageSetupDlgW(LPPAGESETUPDLGW setupdlg) {
3400 PageSetupDataW *pdw;
3403 if(TRACE_ON(commdlg)) {
3404 char flagstr[1000] = "";
3405 struct pd_flags *pflag = psd_flags;
3406 for( ; pflag->name; pflag++) {
3407 if(setupdlg->Flags & pflag->flag) {
3408 strcat(flagstr, pflag->name);
3409 strcat(flagstr, "|");
3412 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
3413 "hinst %08x, flags %08lx (%s)\n",
3414 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
3415 setupdlg->hDevNames,
3416 setupdlg->hInstance, setupdlg->Flags, flagstr);
3419 /* First get default printer data, we need it right after that. */
3420 memset(&pdlg,0,sizeof(pdlg));
3421 pdlg.lStructSize = sizeof(pdlg);
3422 pdlg.Flags = PD_RETURNDEFAULT;
3423 bRet = PrintDlgW(&pdlg);
3424 if (!bRet) return FALSE;
3426 /* short cut exit, just return default values */
3427 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
3428 const WCHAR a4[] = {'A','4',0};
3429 setupdlg->hDevMode = pdlg.hDevMode;
3430 setupdlg->hDevNames = pdlg.hDevNames;
3431 /* FIXME: Just return "A4" for now. */
3432 PRINTDLG_PaperSizeW(&pdlg,a4,&setupdlg->ptPaperSize);
3433 setupdlg->ptPaperSize.x=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.x);
3434 setupdlg->ptPaperSize.y=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.y);
3437 hDlgTmpl = PRINTDLG_GetPGSTemplateW(setupdlg);
3439 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3442 ptr = LockResource( hDlgTmpl );
3444 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3447 pdw = HeapAlloc(GetProcessHeap(),0,sizeof(*pdw));
3448 pdw->dlga = setupdlg;
3449 memcpy(&pdw->pdlg,&pdlg,sizeof(pdlg));
3451 bRet = (0<DialogBoxIndirectParamW(
3452 setupdlg->hInstance,
3454 setupdlg->hwndOwner,
3461 /**********************************************************************
3466 /***********************************************************************
3467 * PrintDlgProc (COMMDLG.21)
3469 LRESULT WINAPI PrintDlgProc16(HWND16 hDlg16, UINT16 uMsg, WPARAM16 wParam,
3472 HWND hDlg = HWND_32(hDlg16);
3473 PRINT_PTRA* PrintStructures;
3476 if (uMsg!=WM_INITDIALOG) {
3477 PrintStructures = (PRINT_PTRA*)GetPropA(hDlg,"__WINE_PRINTDLGDATA");
3478 if (!PrintStructures)
3481 PrintStructures = (PRINT_PTRA*) lParam;
3482 SetPropA(hDlg,"__WINE_PRINTDLGDATA",lParam);
3483 res = PRINTDLG_WMInitDialog16(hDlg, wParam, PrintStructures);
3485 if(PrintStructures->dlg.lpPrintDlg16->Flags & PD_ENABLEPRINTHOOK) {
3486 res = CallWindowProc16(
3487 (WNDPROC16)PrintStructures->dlg.lpPrintDlg16->lpfnPrintHook,
3488 hDlg16, uMsg, wParam, (LPARAM)PrintStructures->dlg.lpPrintDlg16
3494 if(PrintStructures->dlg.lpPrintDlg16->Flags & PD_ENABLEPRINTHOOK) {
3495 res = CallWindowProc16(
3496 (WNDPROC16)PrintStructures->dlg.lpPrintDlg16->lpfnPrintHook,
3497 hDlg16,uMsg, wParam, lParam
3499 if(LOWORD(res)) return res;
3504 /* We need to map those for the 32bit window procedure, compare
3505 * with 32Ato16 mapper in winproc.c
3507 return PRINTDLG_WMCommandA(
3509 MAKEWPARAM(wParam,HIWORD(lParam)),
3515 DestroyIcon(PrintStructures->hCollateIcon);
3516 DestroyIcon(PrintStructures->hNoCollateIcon);
3517 /* FIXME: don't forget to delete the paper orientation icons here! */
3525 /***********************************************************************
3526 * PrintSetupDlgProc (COMMDLG.22)
3528 LRESULT WINAPI PrintSetupDlgProc16(HWND16 hWnd16, UINT16 wMsg, WPARAM16 wParam,
3531 HWND hWnd = HWND_32(hWnd16);
3535 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
3536 ShowWindow(hWnd, SW_SHOWNORMAL);
3541 EndDialog(hWnd, TRUE);
3544 EndDialog(hWnd, FALSE);
3553 /***********************************************************************
3554 * PrintDlgExA (COMDLG32.@)
3556 HRESULT WINAPI PrintDlgExA(LPVOID lpPrintDlgExA) /* [???] FIXME: LPPRINTDLGEXA */
3561 /***********************************************************************
3562 * PrintDlgExW (COMDLG32.@)
3564 HRESULT WINAPI PrintDlgExW(LPVOID lpPrintDlgExW) /* [???] FIXME: LPPRINTDLGEXW */