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
28 #define NONAMELESSUNION
29 #define NONAMELESSSTRUCT
33 #include "wine/wingdi16.h"
35 #include "wine/winuser16.h"
38 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
47 /* This PRINTDLGA internal structure stores
48 * pointers to several throughout useful structures.
55 LPPRINTDLGA lpPrintDlg;
56 LPPRINTDLG16 lpPrintDlg16;
58 LPPRINTER_INFO_2A lpPrinterInfo;
59 LPDRIVER_INFO_3A lpDriverInfo;
61 HICON hCollateIcon; /* PrintDlg only */
62 HICON hNoCollateIcon; /* PrintDlg only */
63 HICON hPortraitIcon; /* PrintSetupDlg only */
64 HICON hLandscapeIcon; /* PrintSetupDlg only */
72 LPPRINTDLGW lpPrintDlg;
74 LPPRINTER_INFO_2W lpPrinterInfo;
75 LPDRIVER_INFO_3W lpDriverInfo;
77 HICON hCollateIcon; /* PrintDlg only */
78 HICON hNoCollateIcon; /* PrintDlg only */
79 HICON hPortraitIcon; /* PrintSetupDlg only */
80 HICON hLandscapeIcon; /* PrintSetupDlg only */
85 static struct pd_flags {
89 {PD_SELECTION, "PD_SELECTION "},
90 {PD_PAGENUMS, "PD_PAGENUMS "},
91 {PD_NOSELECTION, "PD_NOSELECTION "},
92 {PD_NOPAGENUMS, "PD_NOPAGENUMS "},
93 {PD_COLLATE, "PD_COLLATE "},
94 {PD_PRINTTOFILE, "PD_PRINTTOFILE "},
95 {PD_PRINTSETUP, "PD_PRINTSETUP "},
96 {PD_NOWARNING, "PD_NOWARNING "},
97 {PD_RETURNDC, "PD_RETURNDC "},
98 {PD_RETURNIC, "PD_RETURNIC "},
99 {PD_RETURNDEFAULT, "PD_RETURNDEFAULT "},
100 {PD_SHOWHELP, "PD_SHOWHELP "},
101 {PD_ENABLEPRINTHOOK, "PD_ENABLEPRINTHOOK "},
102 {PD_ENABLESETUPHOOK, "PD_ENABLESETUPHOOK "},
103 {PD_ENABLEPRINTTEMPLATE, "PD_ENABLEPRINTTEMPLATE "},
104 {PD_ENABLESETUPTEMPLATE, "PD_ENABLESETUPTEMPLATE "},
105 {PD_ENABLEPRINTTEMPLATEHANDLE, "PD_ENABLEPRINTTEMPLATEHANDLE "},
106 {PD_ENABLESETUPTEMPLATEHANDLE, "PD_ENABLESETUPTEMPLATEHANDLE "},
107 {PD_USEDEVMODECOPIES, "PD_USEDEVMODECOPIES[ANDCOLLATE] "},
108 {PD_DISABLEPRINTTOFILE, "PD_DISABLEPRINTTOFILE "},
109 {PD_HIDEPRINTTOFILE, "PD_HIDEPRINTTOFILE "},
110 {PD_NONETWORKBUTTON, "PD_NONETWORKBUTTON "},
115 static struct pd_flags psd_flags[] = {
116 {PSD_MINMARGINS,"PSD_MINMARGINS"},
117 {PSD_MARGINS,"PSD_MARGINS"},
118 {PSD_INTHOUSANDTHSOFINCHES,"PSD_INTHOUSANDTHSOFINCHES"},
119 {PSD_INHUNDREDTHSOFMILLIMETERS,"PSD_INHUNDREDTHSOFMILLIMETERS"},
120 {PSD_DISABLEMARGINS,"PSD_DISABLEMARGINS"},
121 {PSD_DISABLEPRINTER,"PSD_DISABLEPRINTER"},
122 {PSD_NOWARNING,"PSD_NOWARNING"},
123 {PSD_DISABLEORIENTATION,"PSD_DISABLEORIENTATION"},
124 {PSD_RETURNDEFAULT,"PSD_RETURNDEFAULT"},
125 {PSD_DISABLEPAPER,"PSD_DISABLEPAPER"},
126 {PSD_SHOWHELP,"PSD_SHOWHELP"},
127 {PSD_ENABLEPAGESETUPHOOK,"PSD_ENABLEPAGESETUPHOOK"},
128 {PSD_ENABLEPAGESETUPTEMPLATE,"PSD_ENABLEPAGESETUPTEMPLATE"},
129 {PSD_ENABLEPAGESETUPTEMPLATEHANDLE,"PSD_ENABLEPAGESETUPTEMPLATEHANDLE"},
130 {PSD_ENABLEPAGEPAINTHOOK,"PSD_ENABLEPAGEPAINTHOOK"},
131 {PSD_DISABLEPAGEPAINTING,"PSD_DISABLEPAGEPAINTING"},
135 /* Yes these constants are the same, but we're just copying win98 */
136 #define UPDOWN_ID 0x270f
137 #define MAX_COPIES 9999
139 /***********************************************************************
140 * PRINTDLG_GetDefaultPrinterName
142 * Returns the default printer name in buf.
143 * Even under WinNT/2000 default printer is retrieved via GetProfileString -
144 * these entries are mapped somewhere in the registry rather than win.ini.
146 * Returns TRUE on success else FALSE
148 static BOOL PRINTDLG_GetDefaultPrinterNameA(LPSTR buf, DWORD len)
152 if(!GetProfileStringA("windows", "device", "", buf, len)) {
153 TRACE("No profile entry for default printer found.\n");
156 if((ptr = strchr(buf, ',')) == NULL) {
157 FIXME("bad format for default printer (%s)!\n",buf);
164 static BOOL PRINTDLG_GetDefaultPrinterNameW(LPWSTR buf, DWORD len)
166 LPSTR ptr, bufA = (LPSTR)HeapAlloc(GetProcessHeap(),0,len+1);
169 if(!GetProfileStringA("windows", "device", "", bufA, len)) {
170 TRACE("No profile entry for default printer found.\n");
171 HeapFree(GetProcessHeap(),0,bufA);
174 if((ptr = strchr(bufA, ',')) == NULL) {
175 FIXME("bad format for default printer (%s)!\n",bufA);
176 HeapFree(GetProcessHeap(),0,bufA);
180 MultiByteToWideChar( CP_ACP, 0, bufA, -1, buf, len );
181 HeapFree(GetProcessHeap(),0,bufA);
185 /***********************************************************************
186 * PRINTDLG_OpenDefaultPrinter
188 * Returns a winspool printer handle to the default printer in *hprn
189 * Caller must call ClosePrinter on the handle
191 * Returns TRUE on success else FALSE
193 static BOOL PRINTDLG_OpenDefaultPrinter(HANDLE *hprn)
197 if(!PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf)))
199 res = OpenPrinterA(buf, hprn, NULL);
201 FIXME("Could not open printer %s?!\n",buf);
205 /***********************************************************************
206 * PRINTDLG_SetUpPrinterListCombo
208 * Initializes printer list combox.
209 * hDlg: HWND of dialog
210 * id: Control id of combo
211 * name: Name of printer to select
213 * Initializes combo with list of available printers. Selects printer 'name'
214 * If name is NULL or does not exist select the default printer.
216 * Returns number of printers added to list.
218 static INT PRINTDLG_SetUpPrinterListComboA(HWND hDlg, UINT id, LPCSTR name)
222 LPPRINTER_INFO_2A pi;
223 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
224 pi = HeapAlloc(GetProcessHeap(), 0, needed);
225 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
228 for(i = 0; i < num; i++) {
229 SendDlgItemMessageA(hDlg, id, CB_ADDSTRING, 0,
230 (LPARAM)pi[i].pPrinterName );
232 HeapFree(GetProcessHeap(), 0, pi);
234 (i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1,
235 (LPARAM)name)) == CB_ERR) {
238 FIXME("Can't find '%s' in printer list so trying to find default\n",
240 if(!PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf)))
242 i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
244 FIXME("Can't find default printer in printer list\n");
246 SendDlgItemMessageA(hDlg, id, CB_SETCURSEL, i, 0);
250 static INT PRINTDLG_SetUpPrinterListComboW(HWND hDlg, UINT id, LPCWSTR name)
254 LPPRINTER_INFO_2W pi;
255 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
256 pi = HeapAlloc(GetProcessHeap(), 0, needed);
257 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
260 for(i = 0; i < num; i++) {
261 SendDlgItemMessageW(hDlg, id, CB_ADDSTRING, 0,
262 (LPARAM)pi[i].pPrinterName );
264 HeapFree(GetProcessHeap(), 0, pi);
266 (i = SendDlgItemMessageW(hDlg, id, CB_FINDSTRINGEXACT, -1,
267 (LPARAM)name)) == CB_ERR) {
271 FIXME("Can't find '%s' in printer list so trying to find default\n",
273 if(!PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf)))
275 i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
277 FIXME("Can't find default printer in printer list\n");
279 SendDlgItemMessageW(hDlg, id, CB_SETCURSEL, i, 0);
283 /***********************************************************************
284 * PRINTDLG_CreateDevNames [internal]
287 * creates a DevNames structure.
289 * (NB. when we handle unicode the offsets will be in wchars).
291 static BOOL PRINTDLG_CreateDevNames(HGLOBAL *hmem, char* DeviceDriverName,
292 char* DeviceName, char* OutputPort)
295 char* pDevNamesSpace;
297 LPDEVNAMES lpDevNames;
300 size = strlen(DeviceDriverName) + 1
301 + strlen(DeviceName) + 1
302 + strlen(OutputPort) + 1
306 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
308 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
312 pDevNamesSpace = GlobalLock(*hmem);
313 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
315 pTempPtr = pDevNamesSpace + sizeof(DEVNAMES);
316 strcpy(pTempPtr, DeviceDriverName);
317 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
319 pTempPtr += strlen(DeviceDriverName) + 1;
320 strcpy(pTempPtr, DeviceName);
321 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
323 pTempPtr += strlen(DeviceName) + 1;
324 strcpy(pTempPtr, OutputPort);
325 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
327 PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf));
328 lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
333 static BOOL PRINTDLG_CreateDevNamesW(HGLOBAL *hmem, LPCWSTR DeviceDriverName,
334 LPCWSTR DeviceName, LPCWSTR OutputPort)
337 LPWSTR pDevNamesSpace;
339 LPDEVNAMES lpDevNames;
343 size = sizeof(WCHAR)*lstrlenW(DeviceDriverName) + 2
344 + sizeof(WCHAR)*lstrlenW(DeviceName) + 2
345 + sizeof(WCHAR)*lstrlenW(OutputPort) + 2
349 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
351 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
355 pDevNamesSpace = GlobalLock(*hmem);
356 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
358 pTempPtr = (LPWSTR)((LPDEVNAMES)pDevNamesSpace + 1);
359 lstrcpyW(pTempPtr, DeviceDriverName);
360 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
362 pTempPtr += lstrlenW(DeviceDriverName) + 1;
363 lstrcpyW(pTempPtr, DeviceName);
364 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
366 pTempPtr += lstrlenW(DeviceName) + 1;
367 lstrcpyW(pTempPtr, OutputPort);
368 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
370 PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf));
371 MultiByteToWideChar(CP_ACP, 0, buf, -1, bufW, -1);
372 lpDevNames->wDefault = (lstrcmpW(bufW, DeviceName) == 0) ? 1 : 0;
378 static BOOL PRINTDLG_CreateDevNames16(HGLOBAL16 *hmem, char* DeviceDriverName,
379 char* DeviceName, char* OutputPort)
382 char* pDevNamesSpace;
384 LPDEVNAMES lpDevNames;
387 size = strlen(DeviceDriverName) + 1
388 + strlen(DeviceName) + 1
389 + strlen(OutputPort) + 1
393 *hmem = GlobalReAlloc16(*hmem, size, GMEM_MOVEABLE);
395 *hmem = GlobalAlloc16(GMEM_MOVEABLE, size);
399 pDevNamesSpace = GlobalLock16(*hmem);
400 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
402 pTempPtr = pDevNamesSpace + sizeof(DEVNAMES);
403 strcpy(pTempPtr, DeviceDriverName);
404 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
406 pTempPtr += strlen(DeviceDriverName) + 1;
407 strcpy(pTempPtr, DeviceName);
408 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
410 pTempPtr += strlen(DeviceName) + 1;
411 strcpy(pTempPtr, OutputPort);
412 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
414 PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf));
415 lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
416 GlobalUnlock16(*hmem);
421 /***********************************************************************
422 * PRINTDLG_UpdatePrintDlg [internal]
425 * updates the PrintDlg structure for returnvalues.
428 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
431 static BOOL PRINTDLG_UpdatePrintDlgA(HWND hDlg,
432 PRINT_PTRA* PrintStructures)
434 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
435 PDEVMODEA lpdm = PrintStructures->lpDevMode;
436 LPPRINTER_INFO_2A pi = PrintStructures->lpPrinterInfo;
440 FIXME("No lpdm ptr?\n");
445 if(!(lppd->Flags & PD_PRINTSETUP)) {
446 /* check whether nFromPage and nToPage are within range defined by
447 * nMinPage and nMaxPage
449 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
452 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
453 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
454 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
455 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
456 char resourcestr[256];
458 LoadStringA(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
460 sprintf(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
461 LoadStringA(COMDLG32_hInstance, PD32_PRINT_TITLE,
463 MessageBoxA(hDlg, resultstr, resourcestr,
464 MB_OK | MB_ICONWARNING);
467 lppd->nFromPage = nFromPage;
468 lppd->nToPage = nToPage;
469 lppd->Flags |= PD_PAGENUMS;
472 lppd->Flags &= ~PD_PAGENUMS;
474 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
475 lppd->Flags |= PD_PRINTTOFILE;
476 pi->pPortName = "FILE:";
479 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
480 FIXME("Collate lppd not yet implemented as output\n");
483 /* set PD_Collate and nCopies */
484 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
485 /* The application doesn't support multiple copies or collate...
487 lppd->Flags &= ~PD_COLLATE;
489 /* if the printer driver supports it... store info there
490 * otherwise no collate & multiple copies !
492 if (lpdm->dmFields & DM_COLLATE)
494 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
495 if (lpdm->dmFields & DM_COPIES)
496 lpdm->dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
498 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
499 lppd->Flags |= PD_COLLATE;
501 lppd->Flags &= ~PD_COLLATE;
502 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
508 static BOOL PRINTDLG_UpdatePrintDlgW(HWND hDlg,
509 PRINT_PTRW* PrintStructures)
511 LPPRINTDLGW lppd = PrintStructures->dlg.lpPrintDlg;
512 PDEVMODEW lpdm = PrintStructures->lpDevMode;
513 LPPRINTER_INFO_2W pi = PrintStructures->lpPrinterInfo;
517 FIXME("No lpdm ptr?\n");
522 if(!(lppd->Flags & PD_PRINTSETUP)) {
523 /* check whether nFromPage and nToPage are within range defined by
524 * nMinPage and nMaxPage
526 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
529 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
530 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
531 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
532 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
533 char resourcestr[256];
535 LoadStringA(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
537 sprintf(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
538 LoadStringA(COMDLG32_hInstance, PD32_PRINT_TITLE,
540 MessageBoxA(hDlg, resultstr, resourcestr,
541 MB_OK | MB_ICONWARNING);
544 lppd->nFromPage = nFromPage;
545 lppd->nToPage = nToPage;
548 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
549 static WCHAR file[] = {'F','I','L','E',':',0};
550 lppd->Flags |= PD_PRINTTOFILE;
551 pi->pPortName = file;
554 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
555 FIXME("Collate lppd not yet implemented as output\n");
558 /* set PD_Collate and nCopies */
559 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
560 /* The application doesn't support multiple copies or collate...
562 lppd->Flags &= ~PD_COLLATE;
564 /* if the printer driver supports it... store info there
565 * otherwise no collate & multiple copies !
567 if (lpdm->dmFields & DM_COLLATE)
569 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
570 if (lpdm->dmFields & DM_COPIES)
571 lpdm->dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
573 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
574 lppd->Flags |= PD_COLLATE;
576 lppd->Flags &= ~PD_COLLATE;
577 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
583 static BOOL PRINTDLG_PaperSizeA(
584 PRINTDLGA *pdlga,const char *PaperSize,LPPOINT size
588 LPSTR devname,portname;
592 POINT *points = NULL;
595 dn = GlobalLock(pdlga->hDevNames);
596 dm = GlobalLock(pdlga->hDevMode);
597 devname = ((char*)dn)+dn->wDeviceOffset;
598 portname = ((char*)dn)+dn->wOutputOffset;
601 NrOfEntries = DeviceCapabilitiesA(devname,portname,DC_PAPERNAMES,NULL,dm);
603 FIXME("No papernames found for %s/%s\n",devname,portname);
606 if (NrOfEntries == -1) {
607 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
611 Names = (char*)HeapAlloc(GetProcessHeap(),0,NrOfEntries*64);
612 if (NrOfEntries != (ret=DeviceCapabilitiesA(devname,portname,DC_PAPERNAMES,Names,dm))) {
613 FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
616 for (i=0;i<NrOfEntries;i++)
617 if (!strcmp(PaperSize,Names+(64*i)))
619 HeapFree(GetProcessHeap(),0,Names);
620 if (i==NrOfEntries) {
621 FIXME("Papersize %s not found in list?\n",PaperSize);
624 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
625 if (NrOfEntries!=(ret=DeviceCapabilitiesA(devname,portname,DC_PAPERSIZE,(LPBYTE)points,dm))) {
626 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
629 /* this is _10ths_ of a millimeter */
634 GlobalUnlock(pdlga->hDevNames);
635 GlobalUnlock(pdlga->hDevMode);
636 if (Names) HeapFree(GetProcessHeap(),0,Names);
637 if (points) HeapFree(GetProcessHeap(),0,points);
641 static BOOL PRINTDLG_PaperSizeW(
642 PRINTDLGW *pdlga,const WCHAR *PaperSize,LPPOINT size
646 LPWSTR devname,portname;
650 POINT *points = NULL;
653 dn = GlobalLock(pdlga->hDevNames);
654 dm = GlobalLock(pdlga->hDevMode);
655 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
656 portname = ((WCHAR*)dn)+dn->wOutputOffset;
659 NrOfEntries = DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,NULL,dm);
661 FIXME("No papernames found for %s/%s\n",debugstr_w(devname),debugstr_w(portname));
664 if (NrOfEntries == -1) {
665 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
669 Names = (WCHAR*)HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*NrOfEntries*64);
670 if (NrOfEntries != (ret=DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,Names,dm))) {
671 FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
674 for (i=0;i<NrOfEntries;i++)
675 if (!lstrcmpW(PaperSize,Names+(64*i)))
677 HeapFree(GetProcessHeap(),0,Names);
678 if (i==NrOfEntries) {
679 FIXME("Papersize %s not found in list?\n",debugstr_w(PaperSize));
682 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
683 if (NrOfEntries!=(ret=DeviceCapabilitiesW(devname,portname,DC_PAPERSIZE,(LPWSTR)points,dm))) {
684 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
687 /* this is _10ths_ of a millimeter */
692 GlobalUnlock(pdlga->hDevNames);
693 GlobalUnlock(pdlga->hDevMode);
694 if (Names) HeapFree(GetProcessHeap(),0,Names);
695 if (points) HeapFree(GetProcessHeap(),0,points);
700 /************************************************************************
701 * PRINTDLG_SetUpPaperComboBox
703 * Initialize either the papersize or inputslot combos of the Printer Setup
704 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
705 * We also try to re-select the old selection.
707 static BOOL PRINTDLG_SetUpPaperComboBoxA(HWND hDlg,
720 int fwCapability_Names;
721 int fwCapability_Words;
723 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName,PortName,nIDComboBox);
725 /* query the dialog box for the current selected value */
726 Sel = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
728 /* we enter here only if a different printer is selected after
729 * the Print Setup dialog is opened. The current settings are
730 * stored into the newly selected printer.
732 oldWord = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA,
735 if (nIDComboBox == cmb2)
736 dm->u1.s1.dmPaperSize = oldWord;
738 dm->dmDefaultSource = oldWord;
742 /* we enter here only when the Print setup dialog is initially
743 * opened. In this case the settings are restored from when
744 * the dialog was last closed.
747 if (nIDComboBox == cmb2)
748 oldWord = dm->u1.s1.dmPaperSize;
750 oldWord = dm->dmDefaultSource;
754 if (nIDComboBox == cmb2) {
756 fwCapability_Names = DC_PAPERNAMES;
757 fwCapability_Words = DC_PAPERS;
761 fwCapability_Names = DC_BINNAMES;
762 fwCapability_Words = DC_BINS;
765 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
766 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
768 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
769 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
770 fwCapability_Names, NULL, dm);
771 if (NrOfEntries == 0)
772 WARN("no Name Entries found!\n");
773 else if (NrOfEntries < 0)
776 if(DeviceCapabilitiesA(PrinterName, PortName, fwCapability_Words, NULL, dm)
778 ERR("Number of caps is different\n");
782 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(char)*NamesSize);
783 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
784 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
785 fwCapability_Names, Names, dm);
786 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
787 fwCapability_Words, (LPSTR)Words, dm);
789 /* reset any current content in the combobox */
790 SendDlgItemMessageA(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
792 /* store new content */
793 for (i = 0; i < NrOfEntries; i++) {
794 DWORD pos = SendDlgItemMessageA(hDlg, nIDComboBox, CB_ADDSTRING, 0,
795 (LPARAM)(&Names[i*NamesSize]) );
796 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
800 /* Look for old selection - can't do this is previous loop since
801 item order will change as more items are added */
803 for (i = 0; i < NrOfEntries; i++) {
804 if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
810 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
812 HeapFree(GetProcessHeap(),0,Words);
813 HeapFree(GetProcessHeap(),0,Names);
817 static BOOL PRINTDLG_SetUpPaperComboBoxW(HWND hDlg,
830 int fwCapability_Names;
831 int fwCapability_Words;
833 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName),debugstr_w(PortName),nIDComboBox);
835 /* query the dialog box for the current selected value */
836 Sel = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
838 /* we enter here only if a different printer is selected after
839 * the Print Setup dialog is opened. The current settings are
840 * stored into the newly selected printer.
842 oldWord = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA,
845 if (nIDComboBox == cmb2)
846 dm->u1.s1.dmPaperSize = oldWord;
848 dm->dmDefaultSource = oldWord;
852 /* we enter here only when the Print setup dialog is initially
853 * opened. In this case the settings are restored from when
854 * the dialog was last closed.
857 if (nIDComboBox == cmb2)
858 oldWord = dm->u1.s1.dmPaperSize;
860 oldWord = dm->dmDefaultSource;
864 if (nIDComboBox == cmb2) {
866 fwCapability_Names = DC_PAPERNAMES;
867 fwCapability_Words = DC_PAPERS;
871 fwCapability_Names = DC_BINNAMES;
872 fwCapability_Words = DC_BINS;
875 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
876 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
878 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
879 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
880 fwCapability_Names, NULL, dm);
881 if (NrOfEntries == 0)
882 WARN("no Name Entries found!\n");
883 else if (NrOfEntries < 0)
886 if(DeviceCapabilitiesW(PrinterName, PortName, fwCapability_Words, NULL, dm)
888 ERR("Number of caps is different\n");
892 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WCHAR)*NamesSize);
893 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
894 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
895 fwCapability_Names, Names, dm);
896 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
897 fwCapability_Words, (LPWSTR)Words, dm);
899 /* reset any current content in the combobox */
900 SendDlgItemMessageA(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
902 /* store new content */
903 for (i = 0; i < NrOfEntries; i++) {
904 DWORD pos = SendDlgItemMessageW(hDlg, nIDComboBox, CB_ADDSTRING, 0,
905 (LPARAM)(&Names[i*NamesSize]) );
906 SendDlgItemMessageW(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
910 /* Look for old selection - can't do this is previous loop since
911 item order will change as more items are added */
913 for (i = 0; i < NrOfEntries; i++) {
914 if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
920 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
922 HeapFree(GetProcessHeap(),0,Words);
923 HeapFree(GetProcessHeap(),0,Names);
928 /***********************************************************************
929 * PRINTDLG_UpdatePrinterInfoTexts [internal]
931 static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg, LPPRINTER_INFO_2A pi)
934 char ResourceString[256];
940 /* add all status messages */
941 for (i = 0; i < 25; i++) {
942 if (pi->Status & (1<<i)) {
943 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
944 ResourceString, 255);
945 strcat(StatusMsg,ResourceString);
949 /* FIXME: status==ready must only be appended if really so.
950 but how to detect? */
951 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
952 ResourceString, 255);
953 strcat(StatusMsg,ResourceString);
955 SendDlgItemMessageA(hDlg, stc12, WM_SETTEXT, 0, (LPARAM)StatusMsg);
957 /* set all other printer info texts */
958 SendDlgItemMessageA(hDlg, stc11, WM_SETTEXT, 0, (LPARAM)pi->pDriverName);
959 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
960 SendDlgItemMessageA(hDlg, stc14, WM_SETTEXT, 0,(LPARAM)pi->pLocation);
962 SendDlgItemMessageA(hDlg, stc14, WM_SETTEXT, 0,(LPARAM)pi->pPortName);
963 SendDlgItemMessageA(hDlg, stc13, WM_SETTEXT, 0, (LPARAM)(pi->pComment ?
968 static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg, LPPRINTER_INFO_2W pi)
970 WCHAR StatusMsg[256];
971 WCHAR ResourceString[256];
977 /* add all status messages */
978 for (i = 0; i < 25; i++) {
979 if (pi->Status & (1<<i)) {
980 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
981 ResourceString, 255);
982 lstrcatW(StatusMsg,ResourceString);
986 /* FIXME: status==ready must only be appended if really so.
987 but how to detect? */
988 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
989 ResourceString, 255);
990 lstrcatW(StatusMsg,ResourceString);
992 SendDlgItemMessageW(hDlg, stc12, WM_SETTEXT, 0, (LPARAM)StatusMsg);
994 /* set all other printer info texts */
995 SendDlgItemMessageW(hDlg, stc11, WM_SETTEXT, 0, (LPARAM)pi->pDriverName);
996 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
997 SendDlgItemMessageW(hDlg, stc14, WM_SETTEXT, 0,(LPARAM)pi->pLocation);
999 SendDlgItemMessageW(hDlg, stc14, WM_SETTEXT, 0,(LPARAM)pi->pPortName);
1000 SendDlgItemMessageW(hDlg, stc13, WM_SETTEXT, 0, (LPARAM)(pi->pComment ?
1001 pi->pComment : (LPCWSTR)"\0\0"));
1006 /*******************************************************************
1008 * PRINTDLG_ChangePrinter
1011 static BOOL PRINTDLG_ChangePrinterA(HWND hDlg, char *name,
1012 PRINT_PTRA *PrintStructures)
1014 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
1015 LPDEVMODEA lpdm = NULL;
1020 if(PrintStructures->lpPrinterInfo)
1021 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
1022 if(PrintStructures->lpDriverInfo)
1023 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
1024 if(!OpenPrinterA(name, &hprn, NULL)) {
1025 ERR("Can't open printer %s\n", name);
1028 GetPrinterA(hprn, 2, NULL, 0, &needed);
1029 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,needed);
1030 GetPrinterA(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
1032 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
1033 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,needed);
1034 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
1036 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures->lpPrinterInfo->pPrinterName);
1041 PRINTDLG_UpdatePrinterInfoTextsA(hDlg, PrintStructures->lpPrinterInfo);
1043 if(PrintStructures->lpDevMode) {
1044 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
1045 PrintStructures->lpDevMode = NULL;
1048 dmSize = DocumentPropertiesA(0, 0, name, NULL, NULL, 0);
1050 ERR("DocumentProperties fails on %s\n", debugstr_a(name));
1053 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
1054 dmSize = DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, NULL,
1056 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
1057 !strcmp(lpdm->dmDeviceName,
1058 PrintStructures->lpDevMode->dmDeviceName)) {
1059 /* Supplied devicemode matches current printer so try to use it */
1060 DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, lpdm,
1061 DM_OUT_BUFFER | DM_IN_BUFFER);
1064 GlobalUnlock(lppd->hDevMode);
1066 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
1068 if(!(lppd->Flags & PD_PRINTSETUP)) {
1069 /* Print range (All/Range/Selection) */
1070 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
1071 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
1072 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
1073 if (lppd->Flags & PD_NOSELECTION)
1074 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
1076 if (lppd->Flags & PD_SELECTION)
1077 CheckRadioButton(hDlg, rad1, rad3, rad2);
1078 if (lppd->Flags & PD_NOPAGENUMS) {
1079 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
1080 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
1081 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
1082 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
1083 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
1085 if (lppd->Flags & PD_PAGENUMS)
1086 CheckRadioButton(hDlg, rad1, rad3, rad3);
1088 /* "All xxx pages"... */
1090 char resourcestr[64];
1092 LoadStringA(COMDLG32_hInstance, PD32_PRINT_ALL_X_PAGES,
1094 sprintf(result,resourcestr,lppd->nMaxPage - lppd->nMinPage + 1);
1095 SendDlgItemMessageA(hDlg, rad1, WM_SETTEXT, 0, (LPARAM) result);
1100 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1102 if (lppd->Flags & PD_COLLATE) {
1103 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1104 (LPARAM)PrintStructures->hCollateIcon);
1105 CheckDlgButton(hDlg, chx2, 1);
1107 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1108 (LPARAM)PrintStructures->hNoCollateIcon);
1109 CheckDlgButton(hDlg, chx2, 0);
1112 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1113 /* if printer doesn't support it: no Collate */
1114 if (!(lpdm->dmFields & DM_COLLATE)) {
1115 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1116 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
1123 if (lppd->hDevMode == 0)
1124 copies = lppd->nCopies;
1126 copies = lpdm->dmCopies;
1127 if(copies == 0) copies = 1;
1128 else if(copies < 0) copies = MAX_COPIES;
1129 SetDlgItemInt(hDlg, edt3, copies, FALSE);
1132 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1133 /* if printer doesn't support it: no nCopies */
1134 if (!(lpdm->dmFields & DM_COPIES)) {
1135 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
1136 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
1141 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
1142 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
1143 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
1144 if (lppd->Flags & PD_HIDEPRINTTOFILE)
1145 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
1147 } else { /* PD_PRINTSETUP */
1148 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
1150 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb2,
1151 PrintStructures->lpPrinterInfo->pPrinterName,
1152 PrintStructures->lpPrinterInfo->pPortName,
1154 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb3,
1155 PrintStructures->lpPrinterInfo->pPrinterName,
1156 PrintStructures->lpPrinterInfo->pPortName,
1158 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1159 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1160 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1161 PrintStructures->hLandscapeIcon));
1166 if ((lppd->Flags & PD_SHOWHELP)==0) {
1167 /* hide if PD_SHOWHELP not specified */
1168 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1173 static BOOL PRINTDLG_ChangePrinterW(HWND hDlg, WCHAR *name,
1174 PRINT_PTRW *PrintStructures)
1176 LPPRINTDLGW lppd = PrintStructures->dlg.lpPrintDlg;
1177 LPDEVMODEW lpdm = NULL;
1182 if(PrintStructures->lpPrinterInfo)
1183 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
1184 if(PrintStructures->lpDriverInfo)
1185 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
1186 if(!OpenPrinterW(name, &hprn, NULL)) {
1187 ERR("Can't open printer %s\n", debugstr_w(name));
1190 GetPrinterW(hprn, 2, NULL, 0, &needed);
1191 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
1192 GetPrinterW(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
1194 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
1195 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
1196 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
1198 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures->lpPrinterInfo->pPrinterName));
1203 PRINTDLG_UpdatePrinterInfoTextsW(hDlg, PrintStructures->lpPrinterInfo);
1205 if(PrintStructures->lpDevMode) {
1206 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
1207 PrintStructures->lpDevMode = NULL;
1210 dmSize = DocumentPropertiesW(0, 0, name, NULL, NULL, 0);
1212 ERR("DocumentProperties fails on %s\n", debugstr_w(name));
1215 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
1216 dmSize = DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, NULL,
1218 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
1219 !lstrcmpW(lpdm->dmDeviceName,
1220 PrintStructures->lpDevMode->dmDeviceName)) {
1221 /* Supplied devicemode matches current printer so try to use it */
1222 DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, lpdm,
1223 DM_OUT_BUFFER | DM_IN_BUFFER);
1226 GlobalUnlock(lppd->hDevMode);
1228 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
1230 if(!(lppd->Flags & PD_PRINTSETUP)) {
1231 /* Print range (All/Range/Selection) */
1232 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
1233 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
1234 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
1235 if (lppd->Flags & PD_NOSELECTION)
1236 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
1238 if (lppd->Flags & PD_SELECTION)
1239 CheckRadioButton(hDlg, rad1, rad3, rad2);
1240 if (lppd->Flags & PD_NOPAGENUMS) {
1241 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
1242 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
1243 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
1244 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
1245 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
1247 if (lppd->Flags & PD_PAGENUMS)
1248 CheckRadioButton(hDlg, rad1, rad3, rad3);
1250 /* "All xxx pages"... */
1253 char resourcestr[64];
1255 LoadStringA(COMDLG32_hInstance, PD32_PRINT_ALL_X_PAGES,
1257 sprintf(result,resourcestr,lppd->nMaxPage - lppd->nMinPage + 1);
1258 SendDlgItemMessageA(hDlg, rad1, WM_SETTEXT, 0, (LPARAM) result);
1263 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1265 if (lppd->Flags & PD_COLLATE) {
1266 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1267 (LPARAM)PrintStructures->hCollateIcon);
1268 CheckDlgButton(hDlg, chx2, 1);
1270 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1271 (LPARAM)PrintStructures->hNoCollateIcon);
1272 CheckDlgButton(hDlg, chx2, 0);
1275 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1276 /* if printer doesn't support it: no Collate */
1277 if (!(lpdm->dmFields & DM_COLLATE)) {
1278 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1279 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
1286 if (lppd->hDevMode == 0)
1287 copies = lppd->nCopies;
1289 copies = lpdm->dmCopies;
1290 if(copies == 0) copies = 1;
1291 else if(copies < 0) copies = MAX_COPIES;
1292 SetDlgItemInt(hDlg, edt3, copies, FALSE);
1295 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1296 /* if printer doesn't support it: no nCopies */
1297 if (!(lpdm->dmFields & DM_COPIES)) {
1298 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
1299 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
1304 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
1305 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
1306 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
1307 if (lppd->Flags & PD_HIDEPRINTTOFILE)
1308 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
1310 } else { /* PD_PRINTSETUP */
1311 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
1313 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb2,
1314 PrintStructures->lpPrinterInfo->pPrinterName,
1315 PrintStructures->lpPrinterInfo->pPortName,
1317 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb3,
1318 PrintStructures->lpPrinterInfo->pPrinterName,
1319 PrintStructures->lpPrinterInfo->pPortName,
1321 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1322 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1323 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1324 PrintStructures->hLandscapeIcon));
1329 if ((lppd->Flags & PD_SHOWHELP)==0) {
1330 /* hide if PD_SHOWHELP not specified */
1331 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1336 /***********************************************************************
1337 * PRINTDLG_WMInitDialog [internal]
1339 static LRESULT PRINTDLG_WMInitDialog(HWND hDlg, WPARAM wParam,
1340 PRINT_PTRA* PrintStructures)
1342 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
1346 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1348 /* load Collate ICONs */
1349 /* We load these with LoadImage because they are not a standard
1350 size and we don't want them rescaled */
1351 PrintStructures->hCollateIcon =
1352 LoadImageA(COMDLG32_hInstance, "PD32_COLLATE", IMAGE_ICON, 0, 0, 0);
1353 PrintStructures->hNoCollateIcon =
1354 LoadImageA(COMDLG32_hInstance, "PD32_NOCOLLATE", IMAGE_ICON, 0, 0, 0);
1356 /* These can be done with LoadIcon */
1357 PrintStructures->hPortraitIcon =
1358 LoadIconA(COMDLG32_hInstance, "PD32_PORTRAIT");
1359 PrintStructures->hLandscapeIcon =
1360 LoadIconA(COMDLG32_hInstance, "PD32_LANDSCAPE");
1362 if(PrintStructures->hCollateIcon == 0 ||
1363 PrintStructures->hNoCollateIcon == 0 ||
1364 PrintStructures->hPortraitIcon == 0 ||
1365 PrintStructures->hLandscapeIcon == 0) {
1366 ERR("no icon in resourcefile\n");
1367 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1368 EndDialog(hDlg, FALSE);
1372 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1373 * must be registered and the Help button must be shown.
1375 if (lppd->Flags & PD_SHOWHELP) {
1376 if((PrintStructures->HelpMessageID =
1377 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
1378 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1382 PrintStructures->HelpMessageID = 0;
1384 if(!(lppd->Flags &PD_PRINTSETUP)) {
1385 PrintStructures->hwndUpDown =
1386 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1387 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1388 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1389 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1390 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1393 /* FIXME: I allow more freedom than either Win95 or WinNT,
1394 * which do not agree to what errors should be thrown or not
1395 * in case nToPage or nFromPage is out-of-range.
1397 if (lppd->nMaxPage < lppd->nMinPage)
1398 lppd->nMaxPage = lppd->nMinPage;
1399 if (lppd->nMinPage == lppd->nMaxPage)
1400 lppd->Flags |= PD_NOPAGENUMS;
1401 if (lppd->nToPage < lppd->nMinPage)
1402 lppd->nToPage = lppd->nMinPage;
1403 if (lppd->nToPage > lppd->nMaxPage)
1404 lppd->nToPage = lppd->nMaxPage;
1405 if (lppd->nFromPage < lppd->nMinPage)
1406 lppd->nFromPage = lppd->nMinPage;
1407 if (lppd->nFromPage > lppd->nMaxPage)
1408 lppd->nFromPage = lppd->nMaxPage;
1410 /* if we have the combo box, fill it */
1411 if (GetDlgItem(hDlg,comboID)) {
1414 pdn = GlobalLock(lppd->hDevNames);
1415 pdm = GlobalLock(lppd->hDevMode);
1417 name = (char*)pdn + pdn->wDeviceOffset;
1419 name = pdm->dmDeviceName;
1420 PRINTDLG_SetUpPrinterListComboA(hDlg, comboID, name);
1421 if(pdm) GlobalUnlock(lppd->hDevMode);
1422 if(pdn) GlobalUnlock(lppd->hDevNames);
1424 /* Now find selected printer and update rest of dlg */
1425 name = HeapAlloc(GetProcessHeap(),0,256);
1426 if (GetDlgItemTextA(hDlg, comboID, name, 255))
1427 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1428 HeapFree(GetProcessHeap(),0,name);
1430 /* else use default printer */
1432 BOOL ret = PRINTDLG_GetDefaultPrinterNameA(name, sizeof(name));
1435 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1437 FIXME("No default printer found, expect problems!\n");
1442 static LRESULT PRINTDLG_WMInitDialogW(HWND hDlg, WPARAM wParam,
1443 PRINT_PTRW* PrintStructures)
1445 LPPRINTDLGW lppd = PrintStructures->dlg.lpPrintDlg;
1449 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1451 /* load Collate ICONs */
1452 /* We load these with LoadImage because they are not a standard
1453 size and we don't want them rescaled */
1454 PrintStructures->hCollateIcon =
1455 LoadImageA(COMDLG32_hInstance, "PD32_COLLATE", IMAGE_ICON, 0, 0, 0);
1456 PrintStructures->hNoCollateIcon =
1457 LoadImageA(COMDLG32_hInstance, "PD32_NOCOLLATE", IMAGE_ICON, 0, 0, 0);
1459 /* These can be done with LoadIcon */
1460 PrintStructures->hPortraitIcon =
1461 LoadIconA(COMDLG32_hInstance, "PD32_PORTRAIT");
1462 PrintStructures->hLandscapeIcon =
1463 LoadIconA(COMDLG32_hInstance, "PD32_LANDSCAPE");
1465 if(PrintStructures->hCollateIcon == 0 ||
1466 PrintStructures->hNoCollateIcon == 0 ||
1467 PrintStructures->hPortraitIcon == 0 ||
1468 PrintStructures->hLandscapeIcon == 0) {
1469 ERR("no icon in resourcefile\n");
1470 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1471 EndDialog(hDlg, FALSE);
1475 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1476 * must be registered and the Help button must be shown.
1478 if (lppd->Flags & PD_SHOWHELP) {
1479 if((PrintStructures->HelpMessageID =
1480 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
1481 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1485 PrintStructures->HelpMessageID = 0;
1487 if(!(lppd->Flags &PD_PRINTSETUP)) {
1488 PrintStructures->hwndUpDown =
1489 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1490 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1491 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1492 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1493 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1496 /* FIXME: I allow more freedom than either Win95 or WinNT,
1497 * which do not agree to what errors should be thrown or not
1498 * in case nToPage or nFromPage is out-of-range.
1500 if (lppd->nMaxPage < lppd->nMinPage)
1501 lppd->nMaxPage = lppd->nMinPage;
1502 if (lppd->nMinPage == lppd->nMaxPage)
1503 lppd->Flags |= PD_NOPAGENUMS;
1504 if (lppd->nToPage < lppd->nMinPage)
1505 lppd->nToPage = lppd->nMinPage;
1506 if (lppd->nToPage > lppd->nMaxPage)
1507 lppd->nToPage = lppd->nMaxPage;
1508 if (lppd->nFromPage < lppd->nMinPage)
1509 lppd->nFromPage = lppd->nMinPage;
1510 if (lppd->nFromPage > lppd->nMaxPage)
1511 lppd->nFromPage = lppd->nMaxPage;
1513 /* if we have the combo box, fill it */
1514 if (GetDlgItem(hDlg,comboID)) {
1517 pdn = GlobalLock(lppd->hDevNames);
1518 pdm = GlobalLock(lppd->hDevMode);
1520 name = (WCHAR*)pdn + pdn->wDeviceOffset;
1522 name = pdm->dmDeviceName;
1523 PRINTDLG_SetUpPrinterListComboW(hDlg, comboID, name);
1524 if(pdm) GlobalUnlock(lppd->hDevMode);
1525 if(pdn) GlobalUnlock(lppd->hDevNames);
1527 /* Now find selected printer and update rest of dlg */
1528 /* ansi is ok here */
1529 name = HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR));
1530 if (GetDlgItemTextW(hDlg, comboID, name, 255))
1531 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1532 HeapFree(GetProcessHeap(),0,name);
1534 /* else use default printer */
1536 BOOL ret = PRINTDLG_GetDefaultPrinterNameW(name, sizeof(name));
1539 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1541 FIXME("No default printer found, expect problems!\n");
1547 /***********************************************************************
1548 * PRINTDLG_WMInitDialog [internal]
1550 static LRESULT PRINTDLG_WMInitDialog16(HWND hDlg, WPARAM wParam,
1551 PRINT_PTRA* PrintStructures)
1553 LPPRINTDLG16 lppd = PrintStructures->dlg.lpPrintDlg16;
1557 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1559 /* load Collate ICONs */
1560 PrintStructures->hCollateIcon =
1561 LoadIconA(COMDLG32_hInstance, "PD32_COLLATE");
1562 PrintStructures->hNoCollateIcon =
1563 LoadIconA(COMDLG32_hInstance, "PD32_NOCOLLATE");
1564 if(PrintStructures->hCollateIcon == 0 ||
1565 PrintStructures->hNoCollateIcon == 0) {
1566 ERR("no icon in resourcefile\n");
1567 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1568 EndDialog(hDlg, FALSE);
1571 /* load Paper Orientation ICON */
1572 /* FIXME: not implemented yet */
1575 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1576 * must be registered and the Help button must be shown.
1578 if (lppd->Flags & PD_SHOWHELP) {
1579 if((PrintStructures->HelpMessageID =
1580 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
1581 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1585 PrintStructures->HelpMessageID = 0;
1587 if (!(lppd->Flags & PD_PRINTSETUP)) {
1588 /* We have a print quality combo box. What shall we do? */
1589 if (GetDlgItem(hDlg,cmb1)) {
1592 FIXME("Print quality only displaying currently.\n");
1594 pdm = GlobalLock16(lppd->hDevMode);
1596 switch (pdm->dmPrintQuality) {
1597 case DMRES_HIGH : strcpy(buf,"High");break;
1598 case DMRES_MEDIUM : strcpy(buf,"Medium");break;
1599 case DMRES_LOW : strcpy(buf,"Low");break;
1600 case DMRES_DRAFT : strcpy(buf,"Draft");break;
1601 case 0 : strcpy(buf,"Default");break;
1602 default : sprintf(buf,"%ddpi",pdm->dmPrintQuality);break;
1604 GlobalUnlock16(lppd->hDevMode);
1606 strcpy(buf,"Default");
1607 SendDlgItemMessageA(hDlg,cmb1,CB_ADDSTRING,0,(LPARAM)buf);
1608 SendDlgItemMessageA(hDlg,cmb1,CB_SETCURSEL,0,0);
1609 EnableWindow(GetDlgItem(hDlg,cmb1),FALSE);
1613 /* FIXME: I allow more freedom than either Win95 or WinNT,
1614 * which do not agree to what errors should be thrown or not
1615 * in case nToPage or nFromPage is out-of-range.
1617 if (lppd->nMaxPage < lppd->nMinPage)
1618 lppd->nMaxPage = lppd->nMinPage;
1619 if (lppd->nMinPage == lppd->nMaxPage)
1620 lppd->Flags |= PD_NOPAGENUMS;
1621 if (lppd->nToPage < lppd->nMinPage)
1622 lppd->nToPage = lppd->nMinPage;
1623 if (lppd->nToPage > lppd->nMaxPage)
1624 lppd->nToPage = lppd->nMaxPage;
1625 if (lppd->nFromPage < lppd->nMinPage)
1626 lppd->nFromPage = lppd->nMinPage;
1627 if (lppd->nFromPage > lppd->nMaxPage)
1628 lppd->nFromPage = lppd->nMaxPage;
1630 /* If the printer combo box is in the dialog, fill it */
1631 if (GetDlgItem(hDlg,comboID)) {
1634 pdn = GlobalLock16(lppd->hDevNames);
1635 pdm = GlobalLock16(lppd->hDevMode);
1637 name = (char*)pdn + pdn->wDeviceOffset;
1639 name = pdm->dmDeviceName;
1640 PRINTDLG_SetUpPrinterListComboA(hDlg, comboID, name);
1641 if(pdm) GlobalUnlock16(lppd->hDevMode);
1642 if(pdn) GlobalUnlock16(lppd->hDevNames);
1644 /* Now find selected printer and update rest of dlg */
1645 name = HeapAlloc(GetProcessHeap(),0,256);
1646 if (GetDlgItemTextA(hDlg, comboID, name, 255))
1647 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1649 /* else just use default printer */
1651 BOOL ret = PRINTDLG_GetDefaultPrinterNameA(name, sizeof(name));
1654 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1656 FIXME("No default printer found, expect problems!\n");
1658 HeapFree(GetProcessHeap(),0,name);
1663 /***********************************************************************
1664 * PRINTDLG_WMCommand [internal]
1666 static LRESULT PRINTDLG_WMCommandA(HWND hDlg, WPARAM wParam,
1667 LPARAM lParam, PRINT_PTRA* PrintStructures)
1669 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
1670 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1671 LPDEVMODEA lpdm = PrintStructures->lpDevMode;
1673 switch (LOWORD(wParam)) {
1675 TRACE(" OK button was hit\n");
1676 if (PRINTDLG_UpdatePrintDlgA(hDlg, PrintStructures)!=TRUE) {
1677 FIXME("Update printdlg was not successful!\n");
1680 EndDialog(hDlg, TRUE);
1684 TRACE(" CANCEL button was hit\n");
1685 EndDialog(hDlg, FALSE);
1689 TRACE(" HELP button was hit\n");
1690 SendMessageA(lppd->hwndOwner, PrintStructures->HelpMessageID,
1691 (WPARAM) hDlg, (LPARAM) lppd);
1694 case chx2: /* collate pages checkbox */
1695 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1696 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1697 (LPARAM)PrintStructures->hCollateIcon);
1699 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1700 (LPARAM)PrintStructures->hNoCollateIcon);
1702 case edt1: /* from page nr editbox */
1703 case edt2: /* to page nr editbox */
1704 if (HIWORD(wParam)==EN_CHANGE) {
1707 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1708 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1709 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1710 CheckRadioButton(hDlg, rad1, rad3, rad3);
1715 if(HIWORD(wParam) == EN_CHANGE) {
1716 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1718 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1720 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1724 case psh1: /* Print Setup */
1728 if (!PrintStructures->dlg.lpPrintDlg16) {
1729 FIXME("The 32bit print dialog does not have this button!?\n");
1733 memcpy(&pdlg,PrintStructures->dlg.lpPrintDlg16,sizeof(pdlg));
1734 pdlg.Flags |= PD_PRINTSETUP;
1735 pdlg.hwndOwner = HWND_16(hDlg);
1736 if (!PrintDlg16(&pdlg))
1740 case psh2: /* Properties button */
1743 char PrinterName[256];
1745 GetDlgItemTextA(hDlg, PrinterComboID, PrinterName, 255);
1746 if (!OpenPrinterA(PrinterName, &hPrinter, NULL)) {
1747 FIXME(" Call to OpenPrinter did not succeed!\n");
1750 DocumentPropertiesA(hDlg, hPrinter, PrinterName,
1751 PrintStructures->lpDevMode,
1752 PrintStructures->lpDevMode,
1753 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1754 ClosePrinter(hPrinter);
1758 case rad1: /* Paperorientation */
1759 if (lppd->Flags & PD_PRINTSETUP)
1761 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1762 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1763 (LPARAM)(PrintStructures->hPortraitIcon));
1767 case rad2: /* Paperorientation */
1768 if (lppd->Flags & PD_PRINTSETUP)
1770 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1771 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1772 (LPARAM)(PrintStructures->hLandscapeIcon));
1776 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1777 if (PrinterComboID != wParam) {
1778 FIXME("No handling for print quality combo box yet.\n");
1782 case cmb4: /* Printer combobox */
1783 if (HIWORD(wParam)==CBN_SELCHANGE) {
1784 char PrinterName[256];
1785 GetDlgItemTextA(hDlg, LOWORD(wParam), PrinterName, 255);
1786 PRINTDLG_ChangePrinterA(hDlg, PrinterName, PrintStructures);
1790 case cmb2: /* Papersize */
1792 DWORD Sel = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1794 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
1800 case cmb3: /* Bin */
1802 DWORD Sel = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1804 lpdm->dmDefaultSource = SendDlgItemMessageA(hDlg, cmb3,
1805 CB_GETITEMDATA, Sel,
1810 if(lppd->Flags & PD_PRINTSETUP) {
1811 switch (LOWORD(wParam)) {
1812 case rad1: /* orientation */
1814 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1815 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1816 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1817 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1819 (LPARAM)PrintStructures->hPortraitIcon);
1820 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1822 (LPARAM)PrintStructures->hPortraitIcon);
1825 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1826 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1827 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1829 (LPARAM)PrintStructures->hLandscapeIcon);
1830 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1832 (LPARAM)PrintStructures->hLandscapeIcon);
1841 static LRESULT PRINTDLG_WMCommandW(HWND hDlg, WPARAM wParam,
1842 LPARAM lParam, PRINT_PTRW* PrintStructures)
1844 LPPRINTDLGW lppd = PrintStructures->dlg.lpPrintDlg;
1845 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1846 LPDEVMODEW lpdm = PrintStructures->lpDevMode;
1848 switch (LOWORD(wParam)) {
1850 TRACE(" OK button was hit\n");
1851 if (PRINTDLG_UpdatePrintDlgW(hDlg, PrintStructures)!=TRUE) {
1852 FIXME("Update printdlg was not successful!\n");
1855 EndDialog(hDlg, TRUE);
1859 TRACE(" CANCEL button was hit\n");
1860 EndDialog(hDlg, FALSE);
1864 TRACE(" HELP button was hit\n");
1865 SendMessageW(lppd->hwndOwner, PrintStructures->HelpMessageID,
1866 (WPARAM) hDlg, (LPARAM) lppd);
1869 case chx2: /* collate pages checkbox */
1870 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1871 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1872 (LPARAM)PrintStructures->hCollateIcon);
1874 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1875 (LPARAM)PrintStructures->hNoCollateIcon);
1877 case edt1: /* from page nr editbox */
1878 case edt2: /* to page nr editbox */
1879 if (HIWORD(wParam)==EN_CHANGE) {
1882 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1883 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1884 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1885 CheckRadioButton(hDlg, rad1, rad3, rad3);
1890 if(HIWORD(wParam) == EN_CHANGE) {
1891 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1893 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1895 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1899 case psh1: /* Print Setup */
1901 ERR("psh1 is called from 16bit code only, we should not get here.\n");
1904 case psh2: /* Properties button */
1907 WCHAR PrinterName[256];
1909 GetDlgItemTextW(hDlg, PrinterComboID, PrinterName, 255);
1910 if (!OpenPrinterW(PrinterName, &hPrinter, NULL)) {
1911 FIXME(" Call to OpenPrinter did not succeed!\n");
1914 DocumentPropertiesW(hDlg, hPrinter, PrinterName,
1915 PrintStructures->lpDevMode,
1916 PrintStructures->lpDevMode,
1917 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1918 ClosePrinter(hPrinter);
1922 case rad1: /* Paperorientation */
1923 if (lppd->Flags & PD_PRINTSETUP)
1925 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1926 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1927 (LPARAM)(PrintStructures->hPortraitIcon));
1931 case rad2: /* Paperorientation */
1932 if (lppd->Flags & PD_PRINTSETUP)
1934 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1935 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1936 (LPARAM)(PrintStructures->hLandscapeIcon));
1940 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1941 if (PrinterComboID != wParam) {
1942 FIXME("No handling for print quality combo box yet.\n");
1946 case cmb4: /* Printer combobox */
1947 if (HIWORD(wParam)==CBN_SELCHANGE) {
1948 WCHAR PrinterName[256];
1949 GetDlgItemTextW(hDlg, LOWORD(wParam), PrinterName, 255);
1950 PRINTDLG_ChangePrinterW(hDlg, PrinterName, PrintStructures);
1954 case cmb2: /* Papersize */
1956 DWORD Sel = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1958 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
1964 case cmb3: /* Bin */
1966 DWORD Sel = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1968 lpdm->dmDefaultSource = SendDlgItemMessageW(hDlg, cmb3,
1969 CB_GETITEMDATA, Sel,
1974 if(lppd->Flags & PD_PRINTSETUP) {
1975 switch (LOWORD(wParam)) {
1976 case rad1: /* orientation */
1978 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1979 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1980 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1981 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1983 (LPARAM)PrintStructures->hPortraitIcon);
1984 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1986 (LPARAM)PrintStructures->hPortraitIcon);
1989 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1990 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1991 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1993 (LPARAM)PrintStructures->hLandscapeIcon);
1994 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1996 (LPARAM)PrintStructures->hLandscapeIcon);
2005 /***********************************************************************
2006 * PrintDlgProcA [internal]
2008 INT_PTR CALLBACK PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
2011 PRINT_PTRA* PrintStructures;
2012 INT_PTR res = FALSE;
2014 if (uMsg!=WM_INITDIALOG) {
2015 PrintStructures = (PRINT_PTRA*)GetPropA(hDlg,"__WINE_PRINTDLGDATA");
2016 if (!PrintStructures)
2019 PrintStructures = (PRINT_PTRA*) lParam;
2020 SetPropA(hDlg,"__WINE_PRINTDLGDATA",PrintStructures);
2021 res = PRINTDLG_WMInitDialog(hDlg, wParam, PrintStructures);
2023 if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
2024 res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(
2025 hDlg, uMsg, wParam, (LPARAM)PrintStructures->dlg.lpPrintDlg
2030 if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
2031 res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam,
2038 return PRINTDLG_WMCommandA(hDlg, wParam, lParam, PrintStructures);
2041 DestroyIcon(PrintStructures->hCollateIcon);
2042 DestroyIcon(PrintStructures->hNoCollateIcon);
2043 DestroyIcon(PrintStructures->hPortraitIcon);
2044 DestroyIcon(PrintStructures->hLandscapeIcon);
2045 if(PrintStructures->hwndUpDown)
2046 DestroyWindow(PrintStructures->hwndUpDown);
2052 INT_PTR CALLBACK PrintDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
2055 PRINT_PTRW* PrintStructures;
2056 INT_PTR res = FALSE;
2058 if (uMsg!=WM_INITDIALOG) {
2059 PrintStructures = (PRINT_PTRW*) GetWindowLongW(hDlg, DWL_USER);
2060 if (!PrintStructures)
2063 PrintStructures = (PRINT_PTRW*) lParam;
2064 SetWindowLongA(hDlg, DWL_USER, lParam);
2065 res = PRINTDLG_WMInitDialogW(hDlg, wParam, PrintStructures);
2067 if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
2068 res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(
2069 hDlg, uMsg, wParam, (LPARAM)PrintStructures->dlg.lpPrintDlg
2074 if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
2075 res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam,
2082 return PRINTDLG_WMCommandW(hDlg, wParam, lParam, PrintStructures);
2085 DestroyIcon(PrintStructures->hCollateIcon);
2086 DestroyIcon(PrintStructures->hNoCollateIcon);
2087 DestroyIcon(PrintStructures->hPortraitIcon);
2088 DestroyIcon(PrintStructures->hLandscapeIcon);
2089 if(PrintStructures->hwndUpDown)
2090 DestroyWindow(PrintStructures->hwndUpDown);
2097 /************************************************************
2099 * PRINTDLG_Get16TemplateFrom32 [Internal]
2100 * Generates a 16 bits template from the Wine 32 bits resource
2103 static HGLOBAL16 PRINTDLG_Get16TemplateFrom32(char *PrintResourceName)
2109 HGLOBAL16 hGlobal16;
2112 if (!(hResInfo = FindResourceA(COMDLG32_hInstance,
2113 PrintResourceName, RT_DIALOGA)))
2115 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
2118 if (!(hDlgTmpl32 = LoadResource(COMDLG32_hInstance, hResInfo )) ||
2119 !(template32 = LockResource( hDlgTmpl32 )))
2121 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2124 size = SizeofResource(COMDLG32_hInstance, hResInfo);
2125 hGlobal16 = GlobalAlloc16(0, size);
2128 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
2129 ERR("alloc failure for %ld bytes\n", size);
2132 template = GlobalLock16(hGlobal16);
2135 COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE);
2136 ERR("global lock failure for %x handle\n", hGlobal16);
2137 GlobalFree16(hGlobal16);
2140 ConvertDialog32To16((LPVOID)template32, size, (LPVOID)template);
2141 GlobalUnlock16(hGlobal16);
2145 /************************************************************
2147 * PRINTDLG_GetDlgTemplate
2150 static HGLOBAL PRINTDLG_GetDlgTemplateA(PRINTDLGA *lppd)
2155 if (lppd->Flags & PD_PRINTSETUP) {
2156 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
2157 hDlgTmpl = lppd->hSetupTemplate;
2158 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
2159 hResInfo = FindResourceA(lppd->hInstance,
2160 lppd->lpSetupTemplateName, RT_DIALOGA);
2161 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2163 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32_SETUP",
2165 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
2168 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
2169 hDlgTmpl = lppd->hPrintTemplate;
2170 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
2171 hResInfo = FindResourceA(lppd->hInstance,
2172 lppd->lpPrintTemplateName,
2174 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2176 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32",
2178 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
2184 static HGLOBAL PRINTDLG_GetDlgTemplateW(PRINTDLGW *lppd)
2188 const WCHAR xpsetup[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
2189 const WCHAR xprint[] = { 'P','R','I','N','T','3','2',0};
2191 if (lppd->Flags & PD_PRINTSETUP) {
2192 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
2193 hDlgTmpl = lppd->hSetupTemplate;
2194 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
2195 hResInfo = FindResourceW(lppd->hInstance,
2196 lppd->lpSetupTemplateName, RT_DIALOGW);
2197 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2199 hResInfo = FindResourceW(COMDLG32_hInstance, xpsetup, RT_DIALOGW);
2200 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
2203 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
2204 hDlgTmpl = lppd->hPrintTemplate;
2205 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
2206 hResInfo = FindResourceW(lppd->hInstance,
2207 lppd->lpPrintTemplateName,
2209 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2211 hResInfo = FindResourceW(COMDLG32_hInstance, xprint, RT_DIALOGW);
2212 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
2220 /************************************************************
2222 * PRINTDLG_GetDlgTemplate
2225 static HGLOBAL16 PRINTDLG_GetDlgTemplate16(PRINTDLG16 *lppd)
2227 HGLOBAL16 hDlgTmpl, hResInfo;
2229 if (lppd->Flags & PD_PRINTSETUP) {
2230 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
2231 hDlgTmpl = lppd->hSetupTemplate;
2232 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
2233 hResInfo = FindResource16(lppd->hInstance,
2234 MapSL(lppd->lpSetupTemplateName), RT_DIALOGA);
2235 hDlgTmpl = LoadResource16(lppd->hInstance, hResInfo);
2237 hDlgTmpl = PRINTDLG_Get16TemplateFrom32("PRINT32_SETUP");
2240 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
2241 hDlgTmpl = lppd->hPrintTemplate;
2242 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
2243 hResInfo = FindResource16(lppd->hInstance,
2244 MapSL(lppd->lpPrintTemplateName),
2246 hDlgTmpl = LoadResource16(lppd->hInstance, hResInfo);
2248 hDlgTmpl = PRINTDLG_Get16TemplateFrom32("PRINT32");
2254 /***********************************************************************
2259 static BOOL PRINTDLG_CreateDCA(LPPRINTDLGA lppd)
2261 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
2262 DEVMODEA *pdm = GlobalLock(lppd->hDevMode);
2264 if(lppd->Flags & PD_RETURNDC) {
2265 lppd->hDC = CreateDCA((char*)pdn + pdn->wDriverOffset,
2266 (char*)pdn + pdn->wDeviceOffset,
2267 (char*)pdn + pdn->wOutputOffset,
2269 } else if(lppd->Flags & PD_RETURNIC) {
2270 lppd->hDC = CreateICA((char*)pdn + pdn->wDriverOffset,
2271 (char*)pdn + pdn->wDeviceOffset,
2272 (char*)pdn + pdn->wOutputOffset,
2275 GlobalUnlock(lppd->hDevNames);
2276 GlobalUnlock(lppd->hDevMode);
2277 return lppd->hDC ? TRUE : FALSE;
2280 static BOOL PRINTDLG_CreateDCW(LPPRINTDLGW lppd)
2282 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
2283 DEVMODEW *pdm = GlobalLock(lppd->hDevMode);
2285 if(lppd->Flags & PD_RETURNDC) {
2286 lppd->hDC = CreateDCW((WCHAR*)pdn + pdn->wDriverOffset,
2287 (WCHAR*)pdn + pdn->wDeviceOffset,
2288 (WCHAR*)pdn + pdn->wOutputOffset,
2290 } else if(lppd->Flags & PD_RETURNIC) {
2291 lppd->hDC = CreateICW((WCHAR*)pdn + pdn->wDriverOffset,
2292 (WCHAR*)pdn + pdn->wDeviceOffset,
2293 (WCHAR*)pdn + pdn->wOutputOffset,
2296 GlobalUnlock(lppd->hDevNames);
2297 GlobalUnlock(lppd->hDevMode);
2298 return lppd->hDC ? TRUE : FALSE;
2301 static BOOL PRINTDLG_CreateDC16(LPPRINTDLG16 lppd)
2303 DEVNAMES *pdn = GlobalLock16(lppd->hDevNames);
2304 DEVMODEA *pdm = GlobalLock16(lppd->hDevMode);
2306 if(lppd->Flags & PD_RETURNDC) {
2307 lppd->hDC = HDC_16(CreateDCA((char*)pdn + pdn->wDriverOffset,
2308 (char*)pdn + pdn->wDeviceOffset,
2309 (char*)pdn + pdn->wOutputOffset,
2311 } else if(lppd->Flags & PD_RETURNIC) {
2312 lppd->hDC = HDC_16(CreateICA((char*)pdn + pdn->wDriverOffset,
2313 (char*)pdn + pdn->wDeviceOffset,
2314 (char*)pdn + pdn->wOutputOffset,
2317 GlobalUnlock16(lppd->hDevNames);
2318 GlobalUnlock16(lppd->hDevMode);
2319 return lppd->hDC ? TRUE : FALSE;
2322 /***********************************************************************
2323 * PrintDlgA (COMDLG32.@)
2325 * Displays the the PRINT dialog box, which enables the user to specify
2326 * specific properties of the print job.
2329 * nonzero if the user pressed the OK button
2330 * zero if the user cancelled the window or an error occurred
2334 * * The Collate Icons do not display, even though they are in the code.
2335 * * The Properties Button(s) should call DocumentPropertiesA().
2337 * * The Paper Orientation Icons are not implemented yet.
2338 * * The Properties Button(s) should call DocumentPropertiesA().
2339 * * Settings are not yet taken from a provided DevMode or
2340 * default printer settings.
2343 BOOL WINAPI PrintDlgA(
2344 LPPRINTDLGA lppd /* [in/out] ptr to PRINTDLG32 struct */
2349 HINSTANCE hInst = (HINSTANCE)GetWindowLongA( lppd->hwndOwner, GWL_HINSTANCE );
2351 if(TRACE_ON(commdlg)) {
2352 char flagstr[1000] = "";
2353 struct pd_flags *pflag = pd_flags;
2354 for( ; pflag->name; pflag++) {
2355 if(lppd->Flags & pflag->flag)
2356 strcat(flagstr, pflag->name);
2358 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2359 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2360 "flags %08lx (%s)\n",
2361 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2362 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2363 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2366 if(lppd->lStructSize != sizeof(PRINTDLGA)) {
2367 WARN("structure size failure !!!\n");
2368 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2372 if(lppd->Flags & PD_RETURNDEFAULT) {
2373 PRINTER_INFO_2A *pbuf;
2374 DRIVER_INFO_3A *dbuf;
2378 if(lppd->hDevMode || lppd->hDevNames) {
2379 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2380 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2383 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2384 WARN("Can't find default printer\n");
2385 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2389 GetPrinterA(hprn, 2, NULL, 0, &needed);
2390 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
2391 GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2393 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
2394 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
2395 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2396 ERR("GetPrinterDriverA failed, le %ld, fix your config for printer %s!\n",GetLastError(),pbuf->pPrinterName);
2397 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2402 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2406 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2407 pbuf->pDevMode->dmDriverExtra);
2408 ptr = GlobalLock(lppd->hDevMode);
2409 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2410 pbuf->pDevMode->dmDriverExtra);
2411 GlobalUnlock(lppd->hDevMode);
2412 HeapFree(GetProcessHeap(), 0, pbuf);
2413 HeapFree(GetProcessHeap(), 0, dbuf);
2417 PRINT_PTRA *PrintStructures;
2419 /* load Dialog resources,
2420 * depending on Flags indicates Print32 or Print32_setup dialog
2422 hDlgTmpl = PRINTDLG_GetDlgTemplateA(lppd);
2424 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2427 ptr = LockResource( hDlgTmpl );
2429 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2433 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2434 sizeof(PRINT_PTRA));
2435 PrintStructures->dlg.lpPrintDlg = lppd;
2437 /* and create & process the dialog .
2438 * -1 is failure, 0 is broken hwnd, everything else is ok.
2440 bRet = (0<DialogBoxIndirectParamA(hInst, ptr, lppd->hwndOwner,
2442 (LPARAM)PrintStructures));
2445 DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2446 PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
2447 DRIVER_INFO_3A *di = PrintStructures->lpDriverInfo;
2449 if (lppd->hDevMode == 0) {
2450 TRACE(" No hDevMode yet... Need to create my own\n");
2451 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2452 lpdm->dmSize + lpdm->dmDriverExtra);
2455 if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
2456 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2458 GlobalUnlock(lppd->hDevMode);
2459 TRACE("Now got %d locks\n", locks);
2462 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2463 lpdm->dmSize + lpdm->dmDriverExtra,
2466 lpdmReturn = GlobalLock(lppd->hDevMode);
2467 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2469 if (lppd->hDevNames != 0) {
2471 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
2472 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2474 GlobalUnlock(lppd->hDevNames);
2477 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2482 GlobalUnlock(lppd->hDevMode);
2484 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2485 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2486 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2487 HeapFree(GetProcessHeap(), 0, PrintStructures);
2489 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2490 bRet = PRINTDLG_CreateDCA(lppd);
2492 TRACE("exit! (%d)\n", bRet);
2496 /***********************************************************************
2497 * PrintDlgW (COMDLG32.@)
2499 BOOL WINAPI PrintDlgW(
2500 LPPRINTDLGW lppd /* [in/out] ptr to PRINTDLG32 struct */
2505 HINSTANCE hInst = (HINSTANCE)GetWindowLongW( lppd->hwndOwner, GWL_HINSTANCE );
2507 if(TRACE_ON(commdlg)) {
2508 char flagstr[1000] = "";
2509 struct pd_flags *pflag = pd_flags;
2510 for( ; pflag->name; pflag++) {
2511 if(lppd->Flags & pflag->flag)
2512 strcat(flagstr, pflag->name);
2514 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2515 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2516 "flags %08lx (%s)\n",
2517 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2518 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2519 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2522 if(lppd->lStructSize != sizeof(PRINTDLGW)) {
2523 WARN("structure size failure !!!\n");
2524 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2528 if(lppd->Flags & PD_RETURNDEFAULT) {
2529 PRINTER_INFO_2W *pbuf;
2530 DRIVER_INFO_3W *dbuf;
2534 if(lppd->hDevMode || lppd->hDevNames) {
2535 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2536 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2539 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2540 WARN("Can't find default printer\n");
2541 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2545 GetPrinterW(hprn, 2, NULL, 0, &needed);
2546 pbuf = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*needed);
2547 GetPrinterW(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2549 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
2550 dbuf = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
2551 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2552 ERR("GetPrinterDriverA failed, le %ld, fix your config for printer %s!\n",GetLastError(),debugstr_w(pbuf->pPrinterName));
2553 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2558 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2562 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2563 pbuf->pDevMode->dmDriverExtra);
2564 ptr = GlobalLock(lppd->hDevMode);
2565 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2566 pbuf->pDevMode->dmDriverExtra);
2567 GlobalUnlock(lppd->hDevMode);
2568 HeapFree(GetProcessHeap(), 0, pbuf);
2569 HeapFree(GetProcessHeap(), 0, dbuf);
2573 PRINT_PTRW *PrintStructures;
2575 /* load Dialog resources,
2576 * depending on Flags indicates Print32 or Print32_setup dialog
2578 hDlgTmpl = PRINTDLG_GetDlgTemplateW(lppd);
2580 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2583 ptr = LockResource( hDlgTmpl );
2585 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2589 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2590 sizeof(PRINT_PTRW));
2591 PrintStructures->dlg.lpPrintDlg = lppd;
2593 /* and create & process the dialog .
2594 * -1 is failure, 0 is broken hwnd, everything else is ok.
2596 bRet = (0<DialogBoxIndirectParamW(hInst, ptr, lppd->hwndOwner,
2598 (LPARAM)PrintStructures));
2601 DEVMODEW *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2602 PRINTER_INFO_2W *pi = PrintStructures->lpPrinterInfo;
2603 DRIVER_INFO_3W *di = PrintStructures->lpDriverInfo;
2605 if (lppd->hDevMode == 0) {
2606 TRACE(" No hDevMode yet... Need to create my own\n");
2607 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2608 lpdm->dmSize + lpdm->dmDriverExtra);
2611 if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
2612 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2614 GlobalUnlock(lppd->hDevMode);
2615 TRACE("Now got %d locks\n", locks);
2618 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2619 lpdm->dmSize + lpdm->dmDriverExtra,
2622 lpdmReturn = GlobalLock(lppd->hDevMode);
2623 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2625 if (lppd->hDevNames != 0) {
2627 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
2628 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2630 GlobalUnlock(lppd->hDevNames);
2633 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2638 GlobalUnlock(lppd->hDevMode);
2640 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2641 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2642 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2643 HeapFree(GetProcessHeap(), 0, PrintStructures);
2645 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2646 bRet = PRINTDLG_CreateDCW(lppd);
2648 TRACE("exit! (%d)\n", bRet);
2652 /***********************************************************************
2653 * PrintDlg (COMMDLG.20)
2655 * Displays the the PRINT dialog box, which enables the user to specify
2656 * specific properties of the print job.
2659 * nonzero if the user pressed the OK button
2660 * zero if the user cancelled the window or an error occurred
2663 * * calls up to the 32-bit versions of the Dialogs, which look different
2664 * * Customizing is *not* implemented.
2667 BOOL16 WINAPI PrintDlg16(
2668 LPPRINTDLG16 lppd /* [in/out] ptr to PRINTDLG struct */
2672 HINSTANCE16 hInst = GetWindowWord( HWND_32(lppd->hwndOwner), GWL_HINSTANCE );
2674 if(TRACE_ON(commdlg)) {
2675 char flagstr[1000] = "";
2676 struct pd_flags *pflag = pd_flags;
2677 for( ; pflag->name; pflag++) {
2678 if(lppd->Flags & pflag->flag)
2679 strcat(flagstr, pflag->name);
2681 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
2682 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %08x\n"
2683 "flags %08lx (%s)\n",
2684 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2685 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2686 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2689 if(lppd->lStructSize != sizeof(PRINTDLG16)) {
2690 ERR("structure size (%ld/%d)\n",lppd->lStructSize,sizeof(PRINTDLG16));
2691 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2695 if(lppd->Flags & PD_RETURNDEFAULT) {
2696 PRINTER_INFO_2A *pbuf;
2697 DRIVER_INFO_3A *dbuf;
2701 if(lppd->hDevMode || lppd->hDevNames) {
2702 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2703 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2706 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2707 WARN("Can't find default printer\n");
2708 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2712 GetPrinterA(hprn, 2, NULL, 0, &needed);
2713 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
2714 GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2715 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
2716 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
2717 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2718 ERR("GetPrinterDriverA failed for %s, le %ld, fix your config!\n",
2719 pbuf->pPrinterName,GetLastError());
2720 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2724 PRINTDLG_CreateDevNames16(&(lppd->hDevNames),
2728 lppd->hDevMode = GlobalAlloc16(GMEM_MOVEABLE,pbuf->pDevMode->dmSize+
2729 pbuf->pDevMode->dmDriverExtra);
2730 ptr = GlobalLock16(lppd->hDevMode);
2731 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2732 pbuf->pDevMode->dmDriverExtra);
2733 GlobalUnlock16(lppd->hDevMode);
2734 HeapFree(GetProcessHeap(), 0, pbuf);
2735 HeapFree(GetProcessHeap(), 0, dbuf);
2739 PRINT_PTRA *PrintStructures;
2741 /* load Dialog resources,
2742 * depending on Flags indicates Print32 or Print32_setup dialog
2744 hDlgTmpl = PRINTDLG_GetDlgTemplate16(lppd);
2746 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2749 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2750 sizeof(PRINT_PTRA));
2751 PrintStructures->dlg.lpPrintDlg16 = lppd;
2752 PrintStructures->dlg.lpPrintDlg = (LPPRINTDLGA)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(PRINTDLGA));
2753 #define CVAL(x) PrintStructures->dlg.lpPrintDlg->x = lppd->x;
2754 #define MVAL(x) PrintStructures->dlg.lpPrintDlg->x = MapSL(lppd->x);
2756 PrintStructures->dlg.lpPrintDlg->hwndOwner = HWND_32(lppd->hwndOwner);
2757 PrintStructures->dlg.lpPrintDlg->hDC = HDC_32(lppd->hDC);
2758 CVAL(nFromPage);CVAL(nToPage);CVAL(nMinPage);CVAL(nMaxPage);
2760 PrintStructures->dlg.lpPrintDlg->hInstance = HINSTANCE_32(lppd->hInstance);
2762 MVAL(lpPrintTemplateName);MVAL(lpSetupTemplateName);
2763 /* Don't copy rest, it is 16 bit specific */
2767 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(),0,sizeof(DEVMODEA));
2769 /* and create & process the dialog .
2770 * -1 is failure, 0 is broken hwnd, everything else is ok.
2772 bRet = (0<DialogBoxIndirectParam16(
2773 hInst, hDlgTmpl, lppd->hwndOwner,
2774 (DLGPROC16)GetProcAddress16(GetModuleHandle16("COMMDLG"),(LPCSTR)21),
2775 (LPARAM)PrintStructures
2778 if (!PrintStructures->lpPrinterInfo) bRet = FALSE;
2780 DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2781 PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
2782 DRIVER_INFO_3A *di = PrintStructures->lpDriverInfo;
2784 if (lppd->hDevMode == 0) {
2785 TRACE(" No hDevMode yet... Need to create my own\n");
2786 lppd->hDevMode = GlobalAlloc16(GMEM_MOVEABLE,
2787 lpdm->dmSize + lpdm->dmDriverExtra);
2790 if((locks = (GlobalFlags16(lppd->hDevMode)&GMEM_LOCKCOUNT))) {
2791 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2793 GlobalUnlock16(lppd->hDevMode);
2794 TRACE("Now got %d locks\n", locks);
2797 lppd->hDevMode = GlobalReAlloc16(lppd->hDevMode,
2798 lpdm->dmSize + lpdm->dmDriverExtra,
2801 lpdmReturn = GlobalLock16(lppd->hDevMode);
2802 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2804 if (lppd->hDevNames != 0) {
2806 if((locks = (GlobalFlags16(lppd->hDevNames)&GMEM_LOCKCOUNT))) {
2807 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2809 GlobalUnlock16(lppd->hDevNames);
2812 PRINTDLG_CreateDevNames16(&(lppd->hDevNames),
2817 GlobalUnlock16(lppd->hDevMode);
2819 if (!(lppd->Flags & (PD_ENABLESETUPTEMPLATEHANDLE | PD_ENABLESETUPTEMPLATE)))
2820 GlobalFree16(hDlgTmpl); /* created from the 32 bits resource */
2821 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2822 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2823 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2824 HeapFree(GetProcessHeap(), 0, PrintStructures);
2826 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2827 bRet = PRINTDLG_CreateDC16(lppd);
2829 TRACE("exit! (%d)\n", bRet);
2834 /***********************************************************************
2840 * cmb3 - source (tray?)
2841 * edt4 - border left
2843 * edt6 - border right
2844 * edt7 - border bottom
2845 * psh3 - "Printer..."
2849 LPPAGESETUPDLGA dlga;
2854 LPPAGESETUPDLGW dlga;
2858 static HGLOBAL PRINTDLG_GetPGSTemplateA(PAGESETUPDLGA *lppd)
2863 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2864 hDlgTmpl = lppd->hPageSetupTemplate;
2865 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2866 hResInfo = FindResourceA(lppd->hInstance,
2867 lppd->lpPageSetupTemplateName, RT_DIALOGA);
2868 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2870 hResInfo = FindResourceA(COMDLG32_hInstance,(LPCSTR)PAGESETUPDLGORD,RT_DIALOGA);
2871 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2876 static HGLOBAL PRINTDLG_GetPGSTemplateW(PAGESETUPDLGW *lppd)
2881 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2882 hDlgTmpl = lppd->hPageSetupTemplate;
2883 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2884 hResInfo = FindResourceW(lppd->hInstance,
2885 lppd->lpPageSetupTemplateName, RT_DIALOGW);
2886 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2888 hResInfo = FindResourceW(COMDLG32_hInstance,(LPCWSTR)PAGESETUPDLGORD,RT_DIALOGW);
2889 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2895 _c_10mm2size(PAGESETUPDLGA *dlga,DWORD size) {
2896 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2897 return 10*size*10/25.4;
2898 /* If we don't have a flag, we can choose one. Use millimeters
2899 * to avoid confusing me
2901 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2907 _c_inch2size(PAGESETUPDLGA *dlga,DWORD size) {
2908 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2910 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
2911 return (size*254)/10;
2912 /* if we don't have a flag, we can choose one. Use millimeters
2913 * to avoid confusing me
2915 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2916 return (size*254)/10;
2920 _c_size2strA(PageSetupDataA *pda,DWORD size,LPSTR strout) {
2921 strcpy(strout,"<undef>");
2922 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2923 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
2926 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2927 sprintf(strout,"%.2fin",(size*1.0)/1000.0);
2930 pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2931 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
2935 _c_size2strW(PageSetupDataW *pda,DWORD size,LPSTR strout) {
2936 strcpy(strout,"<undef>");
2937 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2938 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
2941 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2942 sprintf(strout,"%.2fin",(size*1.0)/1000.0);
2945 pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2946 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
2951 _c_str2size(PAGESETUPDLGA *dlga,LPCSTR strin) {
2956 if (!sscanf(strin,"%f%s",&val,rest))
2959 if (!strcmp(rest,"in") || !strcmp(rest,"inch")) {
2960 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2963 return val*25.4*100;
2965 if (!strcmp(rest,"cm")) { rest[0]='m'; val = val*10.0; }
2966 if (!strcmp(rest,"m")) { strcpy(rest,"mm"); val = val*1000.0; }
2968 if (!strcmp(rest,"mm")) {
2969 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
2972 return 1000.0*val/25.4;
2974 if (rest[0]=='\0') {
2975 /* use application supplied default */
2976 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2980 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2985 ERR("Did not find a conversion for type '%s'!\n",rest);
2991 * This is called on finish and will update the output fields of the
2995 PRINTDLG_PS_UpdateDlgStructA(HWND hDlg, PageSetupDataA *pda) {
2998 LPSTR devname,portname;
3002 dn = GlobalLock(pda->pdlg.hDevNames);
3003 dm = GlobalLock(pda->pdlg.hDevMode);
3004 devname = ((char*)dn)+dn->wDeviceOffset;
3005 portname = ((char*)dn)+dn->wOutputOffset;
3006 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb2,devname,portname,dm);
3007 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb3,devname,portname,dm);
3009 if (GetDlgItemTextA(hDlg,cmb2,papername,sizeof(papername))>0) {
3010 PRINTDLG_PaperSizeA(&(pda->pdlg),papername,&(pda->dlga->ptPaperSize));
3011 pda->dlga->ptPaperSize.x = _c_10mm2size(pda->dlga,pda->dlga->ptPaperSize.x);
3012 pda->dlga->ptPaperSize.y = _c_10mm2size(pda->dlga,pda->dlga->ptPaperSize.y);
3014 FIXME("could not get dialog text for papersize cmbbox?\n");
3015 #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); }
3016 GETVAL(edt4,pda->dlga->rtMargin.left);
3017 GETVAL(edt5,pda->dlga->rtMargin.top);
3018 GETVAL(edt6,pda->dlga->rtMargin.right);
3019 GETVAL(edt7,pda->dlga->rtMargin.bottom);
3022 /* If we are in landscape, swap x and y of page size */
3023 if (IsDlgButtonChecked(hDlg, rad2)) {
3025 tmp = pda->dlga->ptPaperSize.x;
3026 pda->dlga->ptPaperSize.x = pda->dlga->ptPaperSize.y;
3027 pda->dlga->ptPaperSize.y = tmp;
3029 GlobalUnlock(pda->pdlg.hDevNames);
3030 GlobalUnlock(pda->pdlg.hDevMode);
3035 PRINTDLG_PS_UpdateDlgStructW(HWND hDlg, PageSetupDataW *pda) {
3038 LPWSTR devname,portname;
3039 WCHAR papername[64];
3043 dn = GlobalLock(pda->pdlg.hDevNames);
3044 dm = GlobalLock(pda->pdlg.hDevMode);
3045 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
3046 portname = ((WCHAR*)dn)+dn->wOutputOffset;
3047 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
3048 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
3050 if (GetDlgItemTextW(hDlg,cmb2,papername,sizeof(papername))>0) {
3051 PRINTDLG_PaperSizeW(&(pda->pdlg),papername,&(pda->dlga->ptPaperSize));
3052 pda->dlga->ptPaperSize.x = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga,pda->dlga->ptPaperSize.x);
3053 pda->dlga->ptPaperSize.y = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga,pda->dlga->ptPaperSize.y);
3055 FIXME("could not get dialog text for papersize cmbbox?\n");
3056 #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); }
3057 GETVAL(edt4,pda->dlga->rtMargin.left);
3058 GETVAL(edt5,pda->dlga->rtMargin.top);
3059 GETVAL(edt6,pda->dlga->rtMargin.right);
3060 GETVAL(edt7,pda->dlga->rtMargin.bottom);
3063 /* If we are in landscape, swap x and y of page size */
3064 if (IsDlgButtonChecked(hDlg, rad2)) {
3066 tmp = pda->dlga->ptPaperSize.x;
3067 pda->dlga->ptPaperSize.x = pda->dlga->ptPaperSize.y;
3068 pda->dlga->ptPaperSize.y = tmp;
3070 GlobalUnlock(pda->pdlg.hDevNames);
3071 GlobalUnlock(pda->pdlg.hDevMode);
3076 * This is called after returning from PrintDlg().
3079 PRINTDLG_PS_ChangePrinterA(HWND hDlg, PageSetupDataA *pda) {
3082 LPSTR devname,portname;
3084 dn = GlobalLock(pda->pdlg.hDevNames);
3085 dm = GlobalLock(pda->pdlg.hDevMode);
3086 devname = ((char*)dn)+dn->wDeviceOffset;
3087 portname = ((char*)dn)+dn->wOutputOffset;
3088 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb2,devname,portname,dm);
3089 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb3,devname,portname,dm);
3090 GlobalUnlock(pda->pdlg.hDevNames);
3091 GlobalUnlock(pda->pdlg.hDevMode);
3096 PRINTDLG_PS_ChangePrinterW(HWND hDlg, PageSetupDataW *pda) {
3099 LPWSTR devname,portname;
3101 dn = GlobalLock(pda->pdlg.hDevNames);
3102 dm = GlobalLock(pda->pdlg.hDevMode);
3103 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
3104 portname = ((WCHAR*)dn)+dn->wOutputOffset;
3105 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
3106 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
3107 GlobalUnlock(pda->pdlg.hDevNames);
3108 GlobalUnlock(pda->pdlg.hDevMode);
3113 PRINTDLG_PS_WMCommandA(
3114 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataA *pda
3116 switch (LOWORD(wParam)) {
3118 if (!PRINTDLG_PS_UpdateDlgStructA(hDlg, pda))
3120 EndDialog(hDlg, TRUE);
3124 EndDialog(hDlg, FALSE);
3128 pda->pdlg.Flags = 0;
3129 pda->pdlg.hwndOwner = hDlg;
3130 if (PrintDlgA(&(pda->pdlg)))
3131 PRINTDLG_PS_ChangePrinterA(hDlg,pda);
3135 FIXME("loword (lparam) %d, wparam 0x%x, lparam %08lx, STUB mostly.\n",
3136 LOWORD(lParam),wParam,lParam
3142 PRINTDLG_PS_WMCommandW(
3143 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataW *pda
3145 switch (LOWORD(wParam)) {
3147 if (!PRINTDLG_PS_UpdateDlgStructW(hDlg, pda))
3149 EndDialog(hDlg, TRUE);
3153 EndDialog(hDlg, FALSE);
3157 pda->pdlg.Flags = 0;
3158 pda->pdlg.hwndOwner = hDlg;
3159 if (PrintDlgW(&(pda->pdlg)))
3160 PRINTDLG_PS_ChangePrinterW(hDlg,pda);
3164 FIXME("loword (lparam) %d, wparam 0x%x, lparam %08lx, STUB mostly.\n",
3165 LOWORD(lParam),wParam,lParam
3171 static INT_PTR CALLBACK
3172 PageDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
3174 PageSetupDataA *pda;
3175 INT_PTR res = FALSE;
3177 if (uMsg==WM_INITDIALOG) {
3179 pda = (PageSetupDataA*)lParam;
3180 SetPropA(hDlg,"__WINE_PAGESETUPDLGDATA",pda);
3181 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3182 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3184 FIXME("Setup page hook failed?\n");
3188 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK) {
3189 FIXME("PagePaintHook not yet implemented!\n");
3191 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
3192 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
3193 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
3194 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
3195 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
3196 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
3197 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
3199 /* width larger as height -> landscape */
3200 if (pda->dlga->ptPaperSize.x > pda->dlga->ptPaperSize.y)
3201 CheckRadioButton(hDlg, rad1, rad2, rad2);
3202 else /* this is default if papersize is not set */
3203 CheckRadioButton(hDlg, rad1, rad2, rad1);
3204 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
3205 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
3206 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
3208 /* We fill them out enabled or not */
3209 if (pda->dlga->Flags & PSD_MARGINS) {
3211 _c_size2strA(pda,pda->dlga->rtMargin.left,str);
3212 SetDlgItemTextA(hDlg,edt4,str);
3213 _c_size2strA(pda,pda->dlga->rtMargin.top,str);
3214 SetDlgItemTextA(hDlg,edt5,str);
3215 _c_size2strA(pda,pda->dlga->rtMargin.right,str);
3216 SetDlgItemTextA(hDlg,edt6,str);
3217 _c_size2strA(pda,pda->dlga->rtMargin.bottom,str);
3218 SetDlgItemTextA(hDlg,edt7,str);
3220 /* default is 1 inch */
3221 DWORD size = _c_inch2size(pda->dlga,1000);
3223 _c_size2strA(pda,size,str);
3224 SetDlgItemTextA(hDlg,edt4,str);
3225 SetDlgItemTextA(hDlg,edt5,str);
3226 SetDlgItemTextA(hDlg,edt6,str);
3227 SetDlgItemTextA(hDlg,edt7,str);
3229 PRINTDLG_PS_ChangePrinterA(hDlg,pda);
3230 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
3231 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
3232 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
3236 pda = (PageSetupDataA*)GetPropA(hDlg,"__WINE_PAGESETUPDLGDATA");
3238 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3241 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3242 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3243 if (res) return res;
3248 return PRINTDLG_PS_WMCommandA(hDlg, wParam, lParam, pda);
3253 static INT_PTR CALLBACK
3254 PageDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
3256 PageSetupDataW *pda;
3259 if (uMsg==WM_INITDIALOG) {
3261 pda = (PageSetupDataW*)lParam;
3262 SetPropA(hDlg,"__WINE_PAGESETUPDLGDATA",pda);
3263 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3264 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3266 FIXME("Setup page hook failed?\n");
3270 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK) {
3271 FIXME("PagePaintHook not yet implemented!\n");
3273 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
3274 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
3275 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
3276 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
3277 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
3278 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
3279 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
3281 /* width larger as height -> landscape */
3282 if (pda->dlga->ptPaperSize.x > pda->dlga->ptPaperSize.y)
3283 CheckRadioButton(hDlg, rad1, rad2, rad2);
3284 else /* this is default if papersize is not set */
3285 CheckRadioButton(hDlg, rad1, rad2, rad1);
3286 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
3287 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
3288 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
3290 /* We fill them out enabled or not */
3291 if (pda->dlga->Flags & PSD_MARGINS) {
3293 _c_size2strW(pda,pda->dlga->rtMargin.left,str);
3294 SetDlgItemTextA(hDlg,edt4,str);
3295 _c_size2strW(pda,pda->dlga->rtMargin.top,str);
3296 SetDlgItemTextA(hDlg,edt5,str);
3297 _c_size2strW(pda,pda->dlga->rtMargin.right,str);
3298 SetDlgItemTextA(hDlg,edt6,str);
3299 _c_size2strW(pda,pda->dlga->rtMargin.bottom,str);
3300 SetDlgItemTextA(hDlg,edt7,str);
3302 /* default is 1 inch */
3303 DWORD size = _c_inch2size((LPPAGESETUPDLGA)pda->dlga,1000);
3305 _c_size2strW(pda,size,str);
3306 SetDlgItemTextA(hDlg,edt4,str);
3307 SetDlgItemTextA(hDlg,edt5,str);
3308 SetDlgItemTextA(hDlg,edt6,str);
3309 SetDlgItemTextA(hDlg,edt7,str);
3311 PRINTDLG_PS_ChangePrinterW(hDlg,pda);
3312 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
3313 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
3314 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
3318 pda = (PageSetupDataW*)GetPropA(hDlg,"__WINE_PAGESETUPDLGDATA");
3320 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3323 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3324 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3325 if (res) return res;
3330 return PRINTDLG_PS_WMCommandW(hDlg, wParam, lParam, pda);
3335 /***********************************************************************
3336 * PageSetupDlgA (COMDLG32.@)
3338 BOOL WINAPI PageSetupDlgA(LPPAGESETUPDLGA setupdlg) {
3342 PageSetupDataA *pda;
3345 if(TRACE_ON(commdlg)) {
3346 char flagstr[1000] = "";
3347 struct pd_flags *pflag = psd_flags;
3348 for( ; pflag->name; pflag++) {
3349 if(setupdlg->Flags & pflag->flag) {
3350 strcat(flagstr, pflag->name);
3351 strcat(flagstr, "|");
3354 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3355 "hinst %p, flags %08lx (%s)\n",
3356 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
3357 setupdlg->hDevNames,
3358 setupdlg->hInstance, setupdlg->Flags, flagstr);
3361 /* First get default printer data, we need it right after that. */
3362 memset(&pdlg,0,sizeof(pdlg));
3363 pdlg.lStructSize = sizeof(pdlg);
3364 pdlg.Flags = PD_RETURNDEFAULT;
3365 bRet = PrintDlgA(&pdlg);
3366 if (!bRet) return FALSE;
3368 /* short cut exit, just return default values */
3369 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
3370 setupdlg->hDevMode = pdlg.hDevMode;
3371 setupdlg->hDevNames = pdlg.hDevNames;
3372 /* FIXME: Just return "A4" for now. */
3373 PRINTDLG_PaperSizeA(&pdlg,"A4",&setupdlg->ptPaperSize);
3374 setupdlg->ptPaperSize.x=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.x);
3375 setupdlg->ptPaperSize.y=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.y);
3378 hDlgTmpl = PRINTDLG_GetPGSTemplateA(setupdlg);
3380 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3383 ptr = LockResource( hDlgTmpl );
3385 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3388 pda = HeapAlloc(GetProcessHeap(),0,sizeof(*pda));
3389 pda->dlga = setupdlg;
3390 memcpy(&pda->pdlg,&pdlg,sizeof(pdlg));
3392 bRet = (0<DialogBoxIndirectParamA(
3393 setupdlg->hInstance,
3395 setupdlg->hwndOwner,
3401 /***********************************************************************
3402 * PageSetupDlgW (COMDLG32.@)
3404 BOOL WINAPI PageSetupDlgW(LPPAGESETUPDLGW setupdlg) {
3408 PageSetupDataW *pdw;
3411 if(TRACE_ON(commdlg)) {
3412 char flagstr[1000] = "";
3413 struct pd_flags *pflag = psd_flags;
3414 for( ; pflag->name; pflag++) {
3415 if(setupdlg->Flags & pflag->flag) {
3416 strcat(flagstr, pflag->name);
3417 strcat(flagstr, "|");
3420 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3421 "hinst %p, flags %08lx (%s)\n",
3422 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
3423 setupdlg->hDevNames,
3424 setupdlg->hInstance, setupdlg->Flags, flagstr);
3427 /* First get default printer data, we need it right after that. */
3428 memset(&pdlg,0,sizeof(pdlg));
3429 pdlg.lStructSize = sizeof(pdlg);
3430 pdlg.Flags = PD_RETURNDEFAULT;
3431 bRet = PrintDlgW(&pdlg);
3432 if (!bRet) return FALSE;
3434 /* short cut exit, just return default values */
3435 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
3436 const WCHAR a4[] = {'A','4',0};
3437 setupdlg->hDevMode = pdlg.hDevMode;
3438 setupdlg->hDevNames = pdlg.hDevNames;
3439 /* FIXME: Just return "A4" for now. */
3440 PRINTDLG_PaperSizeW(&pdlg,a4,&setupdlg->ptPaperSize);
3441 setupdlg->ptPaperSize.x=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.x);
3442 setupdlg->ptPaperSize.y=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.y);
3445 hDlgTmpl = PRINTDLG_GetPGSTemplateW(setupdlg);
3447 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3450 ptr = LockResource( hDlgTmpl );
3452 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3455 pdw = HeapAlloc(GetProcessHeap(),0,sizeof(*pdw));
3456 pdw->dlga = setupdlg;
3457 memcpy(&pdw->pdlg,&pdlg,sizeof(pdlg));
3459 bRet = (0<DialogBoxIndirectParamW(
3460 setupdlg->hInstance,
3462 setupdlg->hwndOwner,
3469 /**********************************************************************
3474 /***********************************************************************
3475 * PrintDlgProc (COMMDLG.21)
3477 BOOL16 CALLBACK PrintDlgProc16(HWND16 hDlg16, UINT16 uMsg, WPARAM16 wParam,
3480 HWND hDlg = HWND_32(hDlg16);
3481 PRINT_PTRA* PrintStructures;
3484 if (uMsg!=WM_INITDIALOG) {
3485 PrintStructures = (PRINT_PTRA*)GetPropA(hDlg,"__WINE_PRINTDLGDATA");
3486 if (!PrintStructures)
3489 PrintStructures = (PRINT_PTRA*) lParam;
3490 SetPropA(hDlg,"__WINE_PRINTDLGDATA",PrintStructures);
3491 res = PRINTDLG_WMInitDialog16(hDlg, wParam, PrintStructures);
3493 if(PrintStructures->dlg.lpPrintDlg16->Flags & PD_ENABLEPRINTHOOK) {
3494 res = CallWindowProc16(
3495 (WNDPROC16)PrintStructures->dlg.lpPrintDlg16->lpfnPrintHook,
3496 hDlg16, uMsg, wParam, (LPARAM)PrintStructures->dlg.lpPrintDlg16
3502 if(PrintStructures->dlg.lpPrintDlg16->Flags & PD_ENABLEPRINTHOOK) {
3503 res = CallWindowProc16(
3504 (WNDPROC16)PrintStructures->dlg.lpPrintDlg16->lpfnPrintHook,
3505 hDlg16,uMsg, wParam, lParam
3507 if(LOWORD(res)) return res;
3512 /* We need to map those for the 32bit window procedure, compare
3513 * with 32Ato16 mapper in winproc.c
3515 return PRINTDLG_WMCommandA(
3517 MAKEWPARAM(wParam,HIWORD(lParam)),
3523 DestroyIcon(PrintStructures->hCollateIcon);
3524 DestroyIcon(PrintStructures->hNoCollateIcon);
3525 /* FIXME: don't forget to delete the paper orientation icons here! */
3533 /***********************************************************************
3534 * PrintSetupDlgProc (COMMDLG.22)
3536 BOOL16 CALLBACK PrintSetupDlgProc16(HWND16 hWnd16, UINT16 wMsg, WPARAM16 wParam,
3539 HWND hWnd = HWND_32(hWnd16);
3543 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
3544 ShowWindow(hWnd, SW_SHOWNORMAL);
3549 EndDialog(hWnd, TRUE);
3552 EndDialog(hWnd, FALSE);
3561 /***********************************************************************
3562 * PrintDlgExA (COMDLG32.@)
3564 HRESULT WINAPI PrintDlgExA(LPVOID lpPrintDlgExA) /* [???] FIXME: LPPRINTDLGEXA */
3569 /***********************************************************************
3570 * PrintDlgExW (COMDLG32.@)
3572 HRESULT WINAPI PrintDlgExW(LPVOID lpPrintDlgExW) /* [???] FIXME: LPPRINTDLGEXW */