2 * COMMDLG - Print Dialog
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
6 * Copyright 1999 Klaas van Gend
7 * Copyright 2000 Huw D M Davies
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "wine/wingdi16.h"
32 #include "wine/winuser16.h"
35 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
44 /* This PRINTDLGA internal structure stores
45 * pointers to several throughout useful structures.
52 LPPRINTDLGA lpPrintDlg;
53 LPPRINTDLG16 lpPrintDlg16;
55 LPPRINTER_INFO_2A lpPrinterInfo;
56 LPDRIVER_INFO_3A lpDriverInfo;
58 HICON hCollateIcon; /* PrintDlg only */
59 HICON hNoCollateIcon; /* PrintDlg only */
60 HICON hPortraitIcon; /* PrintSetupDlg only */
61 HICON hLandscapeIcon; /* PrintSetupDlg only */
66 static struct pd_flags {
70 {PD_SELECTION, "PD_SELECTION "},
71 {PD_PAGENUMS, "PD_PAGENUMS "},
72 {PD_NOSELECTION, "PD_NOSELECTION "},
73 {PD_NOPAGENUMS, "PD_NOPAGENUMS "},
74 {PD_COLLATE, "PD_COLLATE "},
75 {PD_PRINTTOFILE, "PD_PRINTTOFILE "},
76 {PD_PRINTSETUP, "PD_PRINTSETUP "},
77 {PD_NOWARNING, "PD_NOWARNING "},
78 {PD_RETURNDC, "PD_RETURNDC "},
79 {PD_RETURNIC, "PD_RETURNIC "},
80 {PD_RETURNDEFAULT, "PD_RETURNDEFAULT "},
81 {PD_SHOWHELP, "PD_SHOWHELP "},
82 {PD_ENABLEPRINTHOOK, "PD_ENABLEPRINTHOOK "},
83 {PD_ENABLESETUPHOOK, "PD_ENABLESETUPHOOK "},
84 {PD_ENABLEPRINTTEMPLATE, "PD_ENABLEPRINTTEMPLATE "},
85 {PD_ENABLESETUPTEMPLATE, "PD_ENABLESETUPTEMPLATE "},
86 {PD_ENABLEPRINTTEMPLATEHANDLE, "PD_ENABLEPRINTTEMPLATEHANDLE "},
87 {PD_ENABLESETUPTEMPLATEHANDLE, "PD_ENABLESETUPTEMPLATEHANDLE "},
88 {PD_USEDEVMODECOPIES, "PD_USEDEVMODECOPIES[ANDCOLLATE] "},
89 {PD_DISABLEPRINTTOFILE, "PD_DISABLEPRINTTOFILE "},
90 {PD_HIDEPRINTTOFILE, "PD_HIDEPRINTTOFILE "},
91 {PD_NONETWORKBUTTON, "PD_NONETWORKBUTTON "},
96 static struct pd_flags psd_flags[] = {
97 {PSD_MINMARGINS,"PSD_MINMARGINS"},
98 {PSD_MARGINS,"PSD_MARGINS"},
99 {PSD_INTHOUSANDTHSOFINCHES,"PSD_INTHOUSANDTHSOFINCHES"},
100 {PSD_INHUNDREDTHSOFMILLIMETERS,"PSD_INHUNDREDTHSOFMILLIMETERS"},
101 {PSD_DISABLEMARGINS,"PSD_DISABLEMARGINS"},
102 {PSD_DISABLEPRINTER,"PSD_DISABLEPRINTER"},
103 {PSD_NOWARNING,"PSD_NOWARNING"},
104 {PSD_DISABLEORIENTATION,"PSD_DISABLEORIENTATION"},
105 {PSD_RETURNDEFAULT,"PSD_RETURNDEFAULT"},
106 {PSD_DISABLEPAPER,"PSD_DISABLEPAPER"},
107 {PSD_SHOWHELP,"PSD_SHOWHELP"},
108 {PSD_ENABLEPAGESETUPHOOK,"PSD_ENABLEPAGESETUPHOOK"},
109 {PSD_ENABLEPAGESETUPTEMPLATE,"PSD_ENABLEPAGESETUPTEMPLATE"},
110 {PSD_ENABLEPAGESETUPTEMPLATEHANDLE,"PSD_ENABLEPAGESETUPTEMPLATEHANDLE"},
111 {PSD_ENABLEPAGEPAINTHOOK,"PSD_ENABLEPAGEPAINTHOOK"},
112 {PSD_DISABLEPAGEPAINTING,"PSD_DISABLEPAGEPAINTING"},
116 /* Yes these constants are the same, but we're just copying win98 */
117 #define UPDOWN_ID 0x270f
118 #define MAX_COPIES 9999
120 /***********************************************************************
121 * PRINTDLG_GetDefaultPrinterName
123 * Returns the default printer name in buf.
124 * Even under WinNT/2000 default printer is retrieved via GetProfileString -
125 * these entries are mapped somewhere in the registry rather than win.ini.
127 * Returns TRUE on success else FALSE
129 static BOOL PRINTDLG_GetDefaultPrinterName(LPSTR buf, DWORD len)
133 if(!GetProfileStringA("windows", "device", "", buf, len)) {
134 TRACE("No profile entry for default printer found.\n");
137 if((ptr = strchr(buf, ',')) == NULL) {
138 FIXME("bad format for default printer (%s)!\n",buf);
145 /***********************************************************************
146 * PRINTDLG_OpenDefaultPrinter
148 * Returns a winspool printer handle to the default printer in *hprn
149 * Caller must call ClosePrinter on the handle
151 * Returns TRUE on success else FALSE
153 static BOOL PRINTDLG_OpenDefaultPrinter(HANDLE *hprn)
157 if(!PRINTDLG_GetDefaultPrinterName(buf, sizeof(buf)))
159 res = OpenPrinterA(buf, hprn, NULL);
161 FIXME("Could not open printer %s?!\n",buf);
165 /***********************************************************************
166 * PRINTDLG_SetUpPrinterListCombo
168 * Initializes printer list combox.
169 * hDlg: HWND of dialog
170 * id: Control id of combo
171 * name: Name of printer to select
173 * Initializes combo with list of available printers. Selects printer 'name'
174 * If name is NULL or does not exist select the default printer.
176 * Returns number of printers added to list.
178 static INT PRINTDLG_SetUpPrinterListCombo(HWND hDlg, UINT id, LPCSTR name)
182 LPPRINTER_INFO_2A pi;
183 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
184 pi = HeapAlloc(GetProcessHeap(), 0, needed);
185 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
188 for(i = 0; i < num; i++) {
189 SendDlgItemMessageA(hDlg, id, CB_ADDSTRING, 0,
190 (LPARAM)pi[i].pPrinterName );
192 HeapFree(GetProcessHeap(), 0, pi);
194 (i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1,
195 (LPARAM)name)) == CB_ERR) {
198 FIXME("Can't find '%s' in printer list so trying to find default\n",
200 if(!PRINTDLG_GetDefaultPrinterName(buf, sizeof(buf)))
202 i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
204 FIXME("Can't find default printer in printer list\n");
206 SendDlgItemMessageA(hDlg, id, CB_SETCURSEL, i, 0);
210 /***********************************************************************
211 * PRINTDLG_CreateDevNames [internal]
214 * creates a DevNames structure.
216 * (NB. when we handle unicode the offsets will be in wchars).
218 static BOOL PRINTDLG_CreateDevNames(HGLOBAL *hmem, char* DeviceDriverName,
219 char* DeviceName, char* OutputPort)
222 char* pDevNamesSpace;
224 LPDEVNAMES lpDevNames;
227 size = strlen(DeviceDriverName) + 1
228 + strlen(DeviceName) + 1
229 + strlen(OutputPort) + 1
233 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
235 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
239 pDevNamesSpace = GlobalLock(*hmem);
240 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
242 pTempPtr = pDevNamesSpace + sizeof(DEVNAMES);
243 strcpy(pTempPtr, DeviceDriverName);
244 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
246 pTempPtr += strlen(DeviceDriverName) + 1;
247 strcpy(pTempPtr, DeviceName);
248 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
250 pTempPtr += strlen(DeviceName) + 1;
251 strcpy(pTempPtr, OutputPort);
252 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
254 PRINTDLG_GetDefaultPrinterName(buf, sizeof(buf));
255 lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
260 static BOOL PRINTDLG_CreateDevNames16(HGLOBAL16 *hmem, char* DeviceDriverName,
261 char* DeviceName, char* OutputPort)
264 char* pDevNamesSpace;
266 LPDEVNAMES lpDevNames;
269 size = strlen(DeviceDriverName) + 1
270 + strlen(DeviceName) + 1
271 + strlen(OutputPort) + 1
275 *hmem = GlobalReAlloc16(*hmem, size, GMEM_MOVEABLE);
277 *hmem = GlobalAlloc16(GMEM_MOVEABLE, size);
281 pDevNamesSpace = GlobalLock16(*hmem);
282 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
284 pTempPtr = pDevNamesSpace + sizeof(DEVNAMES);
285 strcpy(pTempPtr, DeviceDriverName);
286 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
288 pTempPtr += strlen(DeviceDriverName) + 1;
289 strcpy(pTempPtr, DeviceName);
290 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
292 pTempPtr += strlen(DeviceName) + 1;
293 strcpy(pTempPtr, OutputPort);
294 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
296 PRINTDLG_GetDefaultPrinterName(buf, sizeof(buf));
297 lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
298 GlobalUnlock16(*hmem);
303 /***********************************************************************
304 * PRINTDLG_UpdatePrintDlg [internal]
307 * updates the PrintDlg structure for returnvalues.
310 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
313 static BOOL PRINTDLG_UpdatePrintDlg(HWND hDlg,
314 PRINT_PTRA* PrintStructures)
316 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
317 PDEVMODEA lpdm = PrintStructures->lpDevMode;
318 LPPRINTER_INFO_2A pi = PrintStructures->lpPrinterInfo;
322 FIXME("No lpdm ptr?\n");
327 if(!(lppd->Flags & PD_PRINTSETUP)) {
328 /* check whether nFromPage and nToPage are within range defined by
329 * nMinPage and nMaxPage
331 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
334 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
335 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
336 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
337 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
338 char resourcestr[256];
340 LoadStringA(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
342 sprintf(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
343 LoadStringA(COMDLG32_hInstance, PD32_PRINT_TITLE,
345 MessageBoxA(hDlg, resultstr, resourcestr,
346 MB_OK | MB_ICONWARNING);
349 lppd->nFromPage = nFromPage;
350 lppd->nToPage = nToPage;
353 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
354 lppd->Flags |= PD_PRINTTOFILE;
355 pi->pPortName = "FILE:";
358 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
359 FIXME("Collate lppd not yet implemented as output\n");
362 /* set PD_Collate and nCopies */
363 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
364 /* The application doesn't support multiple copies or collate...
366 lppd->Flags &= ~PD_COLLATE;
368 /* if the printer driver supports it... store info there
369 * otherwise no collate & multiple copies !
371 if (lpdm->dmFields & DM_COLLATE)
373 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
374 if (lpdm->dmFields & DM_COPIES)
375 lpdm->dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
377 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
378 lppd->Flags |= PD_COLLATE;
380 lppd->Flags &= ~PD_COLLATE;
381 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
387 static BOOL PRINTDLG_PaperSize(
388 PRINTDLGA *pdlga,const char *PaperSize,LPPOINT size
392 LPSTR devname,portname;
396 POINT *points = NULL;
399 dn = GlobalLock(pdlga->hDevNames);
400 dm = GlobalLock(pdlga->hDevMode);
401 devname = ((char*)dn)+dn->wDeviceOffset;
402 portname = ((char*)dn)+dn->wOutputOffset;
405 NrOfEntries = DeviceCapabilitiesA(devname,portname,DC_PAPERNAMES,NULL,dm);
407 FIXME("No papernames found for %s/%s\n",devname,portname);
410 if (NrOfEntries == -1) {
411 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
415 Names = (char*)HeapAlloc(GetProcessHeap(),0,NrOfEntries*64);
416 if (NrOfEntries != (ret=DeviceCapabilitiesA(devname,portname,DC_PAPERNAMES,Names,dm))) {
417 FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
420 for (i=0;i<NrOfEntries;i++)
421 if (!strcmp(PaperSize,Names+(64*i)))
423 HeapFree(GetProcessHeap(),0,Names);
424 if (i==NrOfEntries) {
425 FIXME("Papersize %s not found in list?\n",PaperSize);
428 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
429 if (NrOfEntries!=(ret=DeviceCapabilitiesA(devname,portname,DC_PAPERSIZE,(LPBYTE)points,dm))) {
430 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
433 /* this is _10ths_ of a millimeter */
436 FIXME("papersize is %ld x %ld\n",size->x,size->y);
439 GlobalUnlock(pdlga->hDevNames);
440 GlobalUnlock(pdlga->hDevMode);
441 if (Names) HeapFree(GetProcessHeap(),0,Names);
442 if (points) HeapFree(GetProcessHeap(),0,points);
447 /************************************************************************
448 * PRINTDLG_SetUpPaperComboBox
450 * Initialize either the papersize or inputslot combos of the Printer Setup
451 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
452 * We also try to re-select the old selection.
454 static BOOL PRINTDLG_SetUpPaperComboBox(HWND hDlg,
467 int fwCapability_Names;
468 int fwCapability_Words;
470 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName,PortName,nIDComboBox);
472 /* query the dialog box for the current selected value */
473 Sel = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
475 /* we enter here only if a different printer is selected after
476 * the Print Setup dialog is opened. The current settings are
477 * stored into the newly selected printer.
479 oldWord = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA,
482 if (nIDComboBox == cmb2)
483 dm->u1.s1.dmPaperSize = oldWord;
485 dm->dmDefaultSource = oldWord;
489 /* we enter here only when the Print setup dialog is initially
490 * opened. In this case the settings are restored from when
491 * the dialog was last closed.
494 if (nIDComboBox == cmb2)
495 oldWord = dm->u1.s1.dmPaperSize;
497 oldWord = dm->dmDefaultSource;
501 if (nIDComboBox == cmb2) {
503 fwCapability_Names = DC_PAPERNAMES;
504 fwCapability_Words = DC_PAPERS;
508 fwCapability_Names = DC_BINNAMES;
509 fwCapability_Words = DC_BINS;
512 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
513 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
515 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
516 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
517 fwCapability_Names, NULL, dm);
518 if (NrOfEntries == 0)
519 WARN("no Name Entries found!\n");
520 else if (NrOfEntries < 0)
523 if(DeviceCapabilitiesA(PrinterName, PortName, fwCapability_Words, NULL, dm)
525 ERR("Number of caps is different\n");
529 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*NamesSize);
530 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
531 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
532 fwCapability_Names, Names, dm);
533 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
534 fwCapability_Words, (LPSTR)Words, dm);
536 /* reset any current content in the combobox */
537 SendDlgItemMessageA(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
539 /* store new content */
540 for (i = 0; i < NrOfEntries; i++) {
541 DWORD pos = SendDlgItemMessageA(hDlg, nIDComboBox, CB_ADDSTRING, 0,
542 (LPARAM)(&Names[i*NamesSize]) );
543 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
547 /* Look for old selection - can't do this is previous loop since
548 item order will change as more items are added */
550 for (i = 0; i < NrOfEntries; i++) {
551 if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
557 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
559 HeapFree(GetProcessHeap(),0,Words);
560 HeapFree(GetProcessHeap(),0,Names);
564 /***********************************************************************
565 * PRINTDLG_UpdatePrinterInfoTexts [internal]
567 static void PRINTDLG_UpdatePrinterInfoTexts(HWND hDlg, LPPRINTER_INFO_2A pi)
570 char ResourceString[256];
576 /* add all status messages */
577 for (i = 0; i < 25; i++) {
578 if (pi->Status & (1<<i)) {
579 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
580 ResourceString, 255);
581 strcat(StatusMsg,ResourceString);
585 /* FIXME: status==ready must only be appended if really so.
586 but how to detect? */
587 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
588 ResourceString, 255);
589 strcat(StatusMsg,ResourceString);
591 SendDlgItemMessageA(hDlg, stc12, WM_SETTEXT, 0, (LPARAM)StatusMsg);
593 /* set all other printer info texts */
594 SendDlgItemMessageA(hDlg, stc11, WM_SETTEXT, 0, (LPARAM)pi->pDriverName);
595 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
596 SendDlgItemMessageA(hDlg, stc14, WM_SETTEXT, 0,(LPARAM)pi->pLocation);
598 SendDlgItemMessageA(hDlg, stc14, WM_SETTEXT, 0,(LPARAM)pi->pPortName);
599 SendDlgItemMessageA(hDlg, stc13, WM_SETTEXT, 0, (LPARAM)(pi->pComment ?
605 /*******************************************************************
607 * PRINTDLG_ChangePrinter
610 static BOOL PRINTDLG_ChangePrinter(HWND hDlg, char *name,
611 PRINT_PTRA *PrintStructures)
613 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
614 LPDEVMODEA lpdm = NULL;
619 if(PrintStructures->lpPrinterInfo)
620 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
621 if(PrintStructures->lpDriverInfo)
622 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
623 if(!OpenPrinterA(name, &hprn, NULL)) {
624 ERR("Can't open printer %s\n", name);
627 GetPrinterA(hprn, 2, NULL, 0, &needed);
628 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,needed);
629 GetPrinterA(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
631 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
632 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,needed);
633 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
635 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures->lpPrinterInfo->pPrinterName);
640 PRINTDLG_UpdatePrinterInfoTexts(hDlg, PrintStructures->lpPrinterInfo);
642 if(PrintStructures->lpDevMode) {
643 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
644 PrintStructures->lpDevMode = NULL;
647 dmSize = DocumentPropertiesA(0, 0, name, NULL, NULL, 0);
649 ERR("DocumentProperties fails on %s\n", debugstr_a(name));
652 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
653 dmSize = DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, NULL,
655 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
656 !strcmp(lpdm->dmDeviceName,
657 PrintStructures->lpDevMode->dmDeviceName)) {
658 /* Supplied devicemode matches current printer so try to use it */
659 DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, lpdm,
660 DM_OUT_BUFFER | DM_IN_BUFFER);
663 GlobalUnlock(lppd->hDevMode);
665 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
667 if(!(lppd->Flags & PD_PRINTSETUP)) {
668 /* Print range (All/Range/Selection) */
669 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
670 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
671 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
672 if (lppd->Flags & PD_NOSELECTION)
673 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
675 if (lppd->Flags & PD_SELECTION)
676 CheckRadioButton(hDlg, rad1, rad3, rad2);
677 if (lppd->Flags & PD_NOPAGENUMS) {
678 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
679 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
680 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
681 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
682 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
684 if (lppd->Flags & PD_PAGENUMS)
685 CheckRadioButton(hDlg, rad1, rad3, rad3);
687 /* "All xxx pages"... */
689 char resourcestr[64];
691 LoadStringA(COMDLG32_hInstance, PD32_PRINT_ALL_X_PAGES,
693 sprintf(result,resourcestr,lppd->nMaxPage - lppd->nMinPage + 1);
694 SendDlgItemMessageA(hDlg, rad1, WM_SETTEXT, 0, (LPARAM) result);
699 * FIXME: The ico3 is not displayed for some reason. I don't know why.
701 if (lppd->Flags & PD_COLLATE) {
702 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
703 (LPARAM)PrintStructures->hCollateIcon);
704 CheckDlgButton(hDlg, chx2, 1);
706 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
707 (LPARAM)PrintStructures->hNoCollateIcon);
708 CheckDlgButton(hDlg, chx2, 0);
711 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
712 /* if printer doesn't support it: no Collate */
713 if (!(lpdm->dmFields & DM_COLLATE)) {
714 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
715 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
722 if (lppd->hDevMode == 0)
723 copies = lppd->nCopies;
725 copies = lpdm->dmCopies;
726 if(copies == 0) copies = 1;
727 else if(copies < 0) copies = MAX_COPIES;
728 SetDlgItemInt(hDlg, edt3, copies, FALSE);
731 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
732 /* if printer doesn't support it: no nCopies */
733 if (!(lpdm->dmFields & DM_COPIES)) {
734 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
735 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
740 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
741 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
742 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
743 if (lppd->Flags & PD_HIDEPRINTTOFILE)
744 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
746 } else { /* PD_PRINTSETUP */
747 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
749 PRINTDLG_SetUpPaperComboBox(hDlg, cmb2,
750 PrintStructures->lpPrinterInfo->pPrinterName,
751 PrintStructures->lpPrinterInfo->pPortName,
753 PRINTDLG_SetUpPaperComboBox(hDlg, cmb3,
754 PrintStructures->lpPrinterInfo->pPrinterName,
755 PrintStructures->lpPrinterInfo->pPortName,
757 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
758 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
759 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
760 PrintStructures->hLandscapeIcon));
765 if ((lppd->Flags & PD_SHOWHELP)==0) {
766 /* hide if PD_SHOWHELP not specified */
767 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
772 /***********************************************************************
773 * PRINTDLG_WMInitDialog [internal]
775 static LRESULT PRINTDLG_WMInitDialog(HWND hDlg, WPARAM wParam,
776 PRINT_PTRA* PrintStructures)
778 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
782 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
784 /* load Collate ICONs */
785 /* We load these with LoadImage because they are not a standard
786 size and we don't want them rescaled */
787 PrintStructures->hCollateIcon =
788 LoadImageA(COMDLG32_hInstance, "PD32_COLLATE", IMAGE_ICON, 0, 0, 0);
789 PrintStructures->hNoCollateIcon =
790 LoadImageA(COMDLG32_hInstance, "PD32_NOCOLLATE", IMAGE_ICON, 0, 0, 0);
792 /* These can be done with LoadIcon */
793 PrintStructures->hPortraitIcon =
794 LoadIconA(COMDLG32_hInstance, "PD32_PORTRAIT");
795 PrintStructures->hLandscapeIcon =
796 LoadIconA(COMDLG32_hInstance, "PD32_LANDSCAPE");
798 if(PrintStructures->hCollateIcon == 0 ||
799 PrintStructures->hNoCollateIcon == 0 ||
800 PrintStructures->hPortraitIcon == 0 ||
801 PrintStructures->hLandscapeIcon == 0) {
802 ERR("no icon in resourcefile\n");
803 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
804 EndDialog(hDlg, FALSE);
808 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
809 * must be registered and the Help button must be shown.
811 if (lppd->Flags & PD_SHOWHELP) {
812 if((PrintStructures->HelpMessageID =
813 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
814 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
818 PrintStructures->HelpMessageID = 0;
820 if(!(lppd->Flags &PD_PRINTSETUP)) {
821 PrintStructures->hwndUpDown =
822 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
823 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
824 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
825 hDlg, UPDOWN_ID, COMDLG32_hInstance,
826 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
829 /* FIXME: I allow more freedom than either Win95 or WinNT,
830 * which do not agree to what errors should be thrown or not
831 * in case nToPage or nFromPage is out-of-range.
833 if (lppd->nMaxPage < lppd->nMinPage)
834 lppd->nMaxPage = lppd->nMinPage;
835 if (lppd->nMinPage == lppd->nMaxPage)
836 lppd->Flags |= PD_NOPAGENUMS;
837 if (lppd->nToPage < lppd->nMinPage)
838 lppd->nToPage = lppd->nMinPage;
839 if (lppd->nToPage > lppd->nMaxPage)
840 lppd->nToPage = lppd->nMaxPage;
841 if (lppd->nFromPage < lppd->nMinPage)
842 lppd->nFromPage = lppd->nMinPage;
843 if (lppd->nFromPage > lppd->nMaxPage)
844 lppd->nFromPage = lppd->nMaxPage;
846 /* if we have the combo box, fill it */
847 if (GetDlgItem(hDlg,comboID)) {
850 pdn = GlobalLock(lppd->hDevNames);
851 pdm = GlobalLock(lppd->hDevMode);
853 name = (char*)pdn + pdn->wDeviceOffset;
855 name = pdm->dmDeviceName;
856 PRINTDLG_SetUpPrinterListCombo(hDlg, comboID, name);
857 if(pdm) GlobalUnlock(lppd->hDevMode);
858 if(pdn) GlobalUnlock(lppd->hDevNames);
860 /* Now find selected printer and update rest of dlg */
861 name = HeapAlloc(GetProcessHeap(),0,256);
862 if (GetDlgItemTextA(hDlg, comboID, name, 255))
863 PRINTDLG_ChangePrinter(hDlg, name, PrintStructures);
864 HeapFree(GetProcessHeap(),0,name);
866 /* else use default printer */
868 BOOL ret = PRINTDLG_GetDefaultPrinterName(name, sizeof(name));
871 PRINTDLG_ChangePrinter(hDlg, name, PrintStructures);
873 FIXME("No default printer found, expect problems!\n");
878 /***********************************************************************
879 * PRINTDLG_WMInitDialog [internal]
881 static LRESULT PRINTDLG_WMInitDialog16(HWND hDlg, WPARAM wParam,
882 PRINT_PTRA* PrintStructures)
884 LPPRINTDLG16 lppd = PrintStructures->dlg.lpPrintDlg16;
888 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
890 /* load Collate ICONs */
891 PrintStructures->hCollateIcon =
892 LoadIconA(COMDLG32_hInstance, "PD32_COLLATE");
893 PrintStructures->hNoCollateIcon =
894 LoadIconA(COMDLG32_hInstance, "PD32_NOCOLLATE");
895 if(PrintStructures->hCollateIcon == 0 ||
896 PrintStructures->hNoCollateIcon == 0) {
897 ERR("no icon in resourcefile\n");
898 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
899 EndDialog(hDlg, FALSE);
902 /* load Paper Orientation ICON */
903 /* FIXME: not implemented yet */
906 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
907 * must be registered and the Help button must be shown.
909 if (lppd->Flags & PD_SHOWHELP) {
910 if((PrintStructures->HelpMessageID =
911 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
912 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
916 PrintStructures->HelpMessageID = 0;
918 if (!(lppd->Flags & PD_PRINTSETUP)) {
919 /* We have a print quality combo box. What shall we do? */
920 if (GetDlgItem(hDlg,cmb1)) {
923 FIXME("Print quality only displaying currently.\n");
925 pdm = GlobalLock16(lppd->hDevMode);
927 switch (pdm->dmPrintQuality) {
928 case DMRES_HIGH : strcpy(buf,"High");break;
929 case DMRES_MEDIUM : strcpy(buf,"Medium");break;
930 case DMRES_LOW : strcpy(buf,"Low");break;
931 case DMRES_DRAFT : strcpy(buf,"Draft");break;
932 case 0 : strcpy(buf,"Default");break;
933 default : sprintf(buf,"%ddpi",pdm->dmPrintQuality);break;
935 GlobalUnlock16(lppd->hDevMode);
937 strcpy(buf,"Default");
938 SendDlgItemMessageA(hDlg,cmb1,CB_ADDSTRING,0,(LPARAM)buf);
939 SendDlgItemMessageA(hDlg,cmb1,CB_SETCURSEL,0,0);
940 EnableWindow(GetDlgItem(hDlg,cmb1),FALSE);
944 /* FIXME: I allow more freedom than either Win95 or WinNT,
945 * which do not agree to what errors should be thrown or not
946 * in case nToPage or nFromPage is out-of-range.
948 if (lppd->nMaxPage < lppd->nMinPage)
949 lppd->nMaxPage = lppd->nMinPage;
950 if (lppd->nMinPage == lppd->nMaxPage)
951 lppd->Flags |= PD_NOPAGENUMS;
952 if (lppd->nToPage < lppd->nMinPage)
953 lppd->nToPage = lppd->nMinPage;
954 if (lppd->nToPage > lppd->nMaxPage)
955 lppd->nToPage = lppd->nMaxPage;
956 if (lppd->nFromPage < lppd->nMinPage)
957 lppd->nFromPage = lppd->nMinPage;
958 if (lppd->nFromPage > lppd->nMaxPage)
959 lppd->nFromPage = lppd->nMaxPage;
961 /* If the printer combo box is in the dialog, fill it */
962 if (GetDlgItem(hDlg,comboID)) {
965 pdn = GlobalLock16(lppd->hDevNames);
966 pdm = GlobalLock16(lppd->hDevMode);
968 name = (char*)pdn + pdn->wDeviceOffset;
970 name = pdm->dmDeviceName;
971 PRINTDLG_SetUpPrinterListCombo(hDlg, comboID, name);
972 if(pdm) GlobalUnlock16(lppd->hDevMode);
973 if(pdn) GlobalUnlock16(lppd->hDevNames);
975 /* Now find selected printer and update rest of dlg */
976 name = HeapAlloc(GetProcessHeap(),0,256);
977 if (GetDlgItemTextA(hDlg, comboID, name, 255))
978 PRINTDLG_ChangePrinter(hDlg, name, PrintStructures);
980 /* else just use default printer */
982 BOOL ret = PRINTDLG_GetDefaultPrinterName(name, sizeof(name));
985 PRINTDLG_ChangePrinter(hDlg, name, PrintStructures);
987 FIXME("No default printer found, expect problems!\n");
989 HeapFree(GetProcessHeap(),0,name);
994 /***********************************************************************
995 * PRINTDLG_WMCommand [internal]
997 static LRESULT PRINTDLG_WMCommand(HWND hDlg, WPARAM wParam,
998 LPARAM lParam, PRINT_PTRA* PrintStructures)
1000 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
1001 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1002 LPDEVMODEA lpdm = PrintStructures->lpDevMode;
1004 switch (LOWORD(wParam)) {
1006 TRACE(" OK button was hit\n");
1007 if (PRINTDLG_UpdatePrintDlg(hDlg, PrintStructures)!=TRUE) {
1008 FIXME("Update printdlg was not successful!\n");
1011 EndDialog(hDlg, TRUE);
1015 TRACE(" CANCEL button was hit\n");
1016 EndDialog(hDlg, FALSE);
1020 TRACE(" HELP button was hit\n");
1021 SendMessageA(lppd->hwndOwner, PrintStructures->HelpMessageID,
1022 (WPARAM) hDlg, (LPARAM) lppd);
1025 case chx2: /* collate pages checkbox */
1026 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1027 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1028 (LPARAM)PrintStructures->hCollateIcon);
1030 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1031 (LPARAM)PrintStructures->hNoCollateIcon);
1033 case edt1: /* from page nr editbox */
1034 case edt2: /* to page nr editbox */
1035 if (HIWORD(wParam)==EN_CHANGE) {
1038 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1039 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1040 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1041 CheckRadioButton(hDlg, rad1, rad3, rad3);
1046 if(HIWORD(wParam) == EN_CHANGE) {
1047 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1049 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1051 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1055 case psh1: /* Print Setup */
1059 if (!PrintStructures->dlg.lpPrintDlg16) {
1060 FIXME("The 32bit print dialog does not have this button!?\n");
1064 memcpy(&pdlg,PrintStructures->dlg.lpPrintDlg16,sizeof(pdlg));
1065 pdlg.Flags |= PD_PRINTSETUP;
1066 pdlg.hwndOwner = hDlg;
1067 if (!PrintDlg16(&pdlg))
1071 case psh2: /* Properties button */
1074 char PrinterName[256];
1076 GetDlgItemTextA(hDlg, PrinterComboID, PrinterName, 255);
1077 if (!OpenPrinterA(PrinterName, &hPrinter, NULL)) {
1078 FIXME(" Call to OpenPrinter did not succeed!\n");
1081 DocumentPropertiesA(hDlg, hPrinter, PrinterName,
1082 PrintStructures->lpDevMode,
1083 PrintStructures->lpDevMode,
1084 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1085 ClosePrinter(hPrinter);
1089 case rad1: /* Paperorientation */
1090 if (lppd->Flags & PD_PRINTSETUP)
1092 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1093 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1094 (LPARAM)(PrintStructures->hPortraitIcon));
1098 case rad2: /* Paperorientation */
1099 if (lppd->Flags & PD_PRINTSETUP)
1101 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1102 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1103 (LPARAM)(PrintStructures->hLandscapeIcon));
1107 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1108 if (PrinterComboID != wParam) {
1109 FIXME("No handling for print quality combo box yet.\n");
1113 case cmb4: /* Printer combobox */
1114 if (HIWORD(wParam)==CBN_SELCHANGE) {
1115 char PrinterName[256];
1116 GetDlgItemTextA(hDlg, LOWORD(wParam), PrinterName, 255);
1117 PRINTDLG_ChangePrinter(hDlg, PrinterName, PrintStructures);
1121 case cmb2: /* Papersize */
1123 DWORD Sel = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1125 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
1131 case cmb3: /* Bin */
1133 DWORD Sel = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1135 lpdm->dmDefaultSource = SendDlgItemMessageA(hDlg, cmb3,
1136 CB_GETITEMDATA, Sel,
1141 if(lppd->Flags & PD_PRINTSETUP) {
1142 switch (LOWORD(wParam)) {
1143 case rad1: /* orientation */
1145 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1146 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1147 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1148 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1150 (LPARAM)PrintStructures->hPortraitIcon);
1151 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1153 (LPARAM)PrintStructures->hPortraitIcon);
1156 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1157 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1158 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1160 (LPARAM)PrintStructures->hLandscapeIcon);
1161 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1163 (LPARAM)PrintStructures->hLandscapeIcon);
1172 /***********************************************************************
1173 * PrintDlgProcA [internal]
1175 BOOL WINAPI PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
1178 PRINT_PTRA* PrintStructures;
1181 if (uMsg!=WM_INITDIALOG) {
1182 PrintStructures = (PRINT_PTRA*) GetWindowLongA(hDlg, DWL_USER);
1183 if (!PrintStructures)
1186 PrintStructures = (PRINT_PTRA*) lParam;
1187 SetWindowLongA(hDlg, DWL_USER, lParam);
1188 res = PRINTDLG_WMInitDialog(hDlg, wParam, PrintStructures);
1190 if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
1191 res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(
1192 hDlg, uMsg, wParam, (LPARAM)PrintStructures->dlg.lpPrintDlg
1197 if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
1198 res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam,
1205 return PRINTDLG_WMCommand(hDlg, wParam, lParam, PrintStructures);
1208 DestroyIcon(PrintStructures->hCollateIcon);
1209 DestroyIcon(PrintStructures->hNoCollateIcon);
1210 DestroyIcon(PrintStructures->hPortraitIcon);
1211 DestroyIcon(PrintStructures->hLandscapeIcon);
1212 if(PrintStructures->hwndUpDown)
1213 DestroyWindow(PrintStructures->hwndUpDown);
1220 /************************************************************
1222 * PRINTDLG_Get16TemplateFrom32 [Internal]
1223 * Generates a 16 bits template from the Wine 32 bits resource
1226 static HGLOBAL16 PRINTDLG_Get16TemplateFrom32(char *PrintResourceName)
1228 HANDLE hResInfo, hDlgTmpl32;
1231 HGLOBAL16 hGlobal16;
1234 if (!(hResInfo = FindResourceA(COMMDLG_hInstance32,
1235 PrintResourceName, RT_DIALOGA)))
1237 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
1240 if (!(hDlgTmpl32 = LoadResource(COMMDLG_hInstance32, hResInfo )) ||
1241 !(template32 = LockResource( hDlgTmpl32 )))
1243 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1246 size = SizeofResource(COMMDLG_hInstance32, hResInfo);
1247 hGlobal16 = GlobalAlloc16(0, size);
1250 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
1251 ERR("alloc failure for %ld bytes\n", size);
1254 template = GlobalLock16(hGlobal16);
1257 COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE);
1258 ERR("global lock failure for %x handle\n", hGlobal16);
1259 GlobalFree16(hGlobal16);
1262 ConvertDialog32To16((LPVOID)template32, size, (LPVOID)template);
1263 GlobalUnlock16(hGlobal16);
1267 /************************************************************
1269 * PRINTDLG_GetDlgTemplate
1272 static HGLOBAL PRINTDLG_GetDlgTemplate(PRINTDLGA *lppd)
1274 HGLOBAL hDlgTmpl, hResInfo;
1276 if (lppd->Flags & PD_PRINTSETUP) {
1277 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
1278 hDlgTmpl = lppd->hSetupTemplate;
1279 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
1280 hResInfo = FindResourceA(lppd->hInstance,
1281 lppd->lpSetupTemplateName, RT_DIALOGA);
1282 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1284 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32_SETUP",
1286 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1289 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
1290 hDlgTmpl = lppd->hPrintTemplate;
1291 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
1292 hResInfo = FindResourceA(lppd->hInstance,
1293 lppd->lpPrintTemplateName,
1295 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1297 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32",
1299 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1306 /************************************************************
1308 * PRINTDLG_GetDlgTemplate
1311 static HGLOBAL16 PRINTDLG_GetDlgTemplate16(PRINTDLG16 *lppd)
1313 HGLOBAL16 hDlgTmpl, hResInfo;
1315 if (lppd->Flags & PD_PRINTSETUP) {
1316 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
1317 hDlgTmpl = lppd->hSetupTemplate;
1318 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
1319 hResInfo = FindResource16(lppd->hInstance,
1320 MapSL(lppd->lpSetupTemplateName), RT_DIALOGA);
1321 hDlgTmpl = LoadResource16(lppd->hInstance, hResInfo);
1323 hDlgTmpl = PRINTDLG_Get16TemplateFrom32("PRINT32_SETUP");
1326 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
1327 hDlgTmpl = lppd->hPrintTemplate;
1328 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
1329 hResInfo = FindResource16(lppd->hInstance,
1330 MapSL(lppd->lpPrintTemplateName),
1332 hDlgTmpl = LoadResource16(lppd->hInstance, hResInfo);
1334 hDlgTmpl = PRINTDLG_Get16TemplateFrom32("PRINT32");
1340 /***********************************************************************
1345 static BOOL PRINTDLG_CreateDC(LPPRINTDLGA lppd)
1347 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
1348 DEVMODEA *pdm = GlobalLock(lppd->hDevMode);
1350 if(lppd->Flags & PD_RETURNDC) {
1351 lppd->hDC = CreateDCA((char*)pdn + pdn->wDriverOffset,
1352 (char*)pdn + pdn->wDeviceOffset,
1353 (char*)pdn + pdn->wOutputOffset,
1355 } else if(lppd->Flags & PD_RETURNIC) {
1356 lppd->hDC = CreateICA((char*)pdn + pdn->wDriverOffset,
1357 (char*)pdn + pdn->wDeviceOffset,
1358 (char*)pdn + pdn->wOutputOffset,
1361 GlobalUnlock(lppd->hDevNames);
1362 GlobalUnlock(lppd->hDevMode);
1363 return lppd->hDC ? TRUE : FALSE;
1366 static BOOL PRINTDLG_CreateDC16(LPPRINTDLG16 lppd)
1368 DEVNAMES *pdn = GlobalLock16(lppd->hDevNames);
1369 DEVMODEA *pdm = GlobalLock16(lppd->hDevMode);
1371 if(lppd->Flags & PD_RETURNDC) {
1372 lppd->hDC = CreateDCA((char*)pdn + pdn->wDriverOffset,
1373 (char*)pdn + pdn->wDeviceOffset,
1374 (char*)pdn + pdn->wOutputOffset,
1376 } else if(lppd->Flags & PD_RETURNIC) {
1377 lppd->hDC = CreateICA((char*)pdn + pdn->wDriverOffset,
1378 (char*)pdn + pdn->wDeviceOffset,
1379 (char*)pdn + pdn->wOutputOffset,
1382 GlobalUnlock16(lppd->hDevNames);
1383 GlobalUnlock16(lppd->hDevMode);
1384 return lppd->hDC ? TRUE : FALSE;
1387 /***********************************************************************
1388 * PrintDlgA (COMDLG32.@)
1390 * Displays the the PRINT dialog box, which enables the user to specify
1391 * specific properties of the print job.
1394 * nonzero if the user pressed the OK button
1395 * zero if the user cancelled the window or an error occurred
1399 * * The Collate Icons do not display, even though they are in the code.
1400 * * The Properties Button(s) should call DocumentPropertiesA().
1402 * * The Paper Orientation Icons are not implemented yet.
1403 * * The Properties Button(s) should call DocumentPropertiesA().
1404 * * Settings are not yet taken from a provided DevMode or
1405 * default printer settings.
1407 BOOL WINAPI PrintDlgA(
1408 LPPRINTDLGA lppd /* [in/out] ptr to PRINTDLG32 struct */
1413 HINSTANCE hInst = GetWindowLongA( lppd->hwndOwner, GWL_HINSTANCE );
1415 if(TRACE_ON(commdlg)) {
1416 char flagstr[1000] = "";
1417 struct pd_flags *pflag = pd_flags;
1418 for( ; pflag->name; pflag++) {
1419 if(lppd->Flags & pflag->flag)
1420 strcat(flagstr, pflag->name);
1422 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
1423 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %08x\n"
1424 "flags %08lx (%s)\n",
1425 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
1426 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
1427 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
1430 if(lppd->lStructSize != sizeof(PRINTDLGA)) {
1431 WARN("structure size failure !!!\n");
1432 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
1436 if(lppd->Flags & PD_RETURNDEFAULT) {
1437 PRINTER_INFO_2A *pbuf;
1438 DRIVER_INFO_3A *dbuf;
1442 if(lppd->hDevMode || lppd->hDevNames) {
1443 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
1444 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
1447 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
1448 WARN("Can't find default printer\n");
1449 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
1453 GetPrinterA(hprn, 2, NULL, 0, &needed);
1454 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
1455 GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
1457 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
1458 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
1459 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
1460 ERR("GetPrinterDriverA failed, le %ld, fix your config for printer %s!\n",GetLastError(),pbuf->pPrinterName);
1461 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
1466 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
1470 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
1471 pbuf->pDevMode->dmDriverExtra);
1472 ptr = GlobalLock(lppd->hDevMode);
1473 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
1474 pbuf->pDevMode->dmDriverExtra);
1475 GlobalUnlock(lppd->hDevMode);
1476 HeapFree(GetProcessHeap(), 0, pbuf);
1477 HeapFree(GetProcessHeap(), 0, dbuf);
1481 PRINT_PTRA *PrintStructures;
1483 /* load Dialog resources,
1484 * depending on Flags indicates Print32 or Print32_setup dialog
1486 hDlgTmpl = PRINTDLG_GetDlgTemplate(lppd);
1488 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1491 ptr = LockResource( hDlgTmpl );
1493 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1497 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
1498 sizeof(PRINT_PTRA));
1499 PrintStructures->dlg.lpPrintDlg = lppd;
1501 /* and create & process the dialog .
1502 * -1 is failure, 0 is broken hwnd, everything else is ok.
1504 bRet = (0<DialogBoxIndirectParamA(hInst, ptr, lppd->hwndOwner,
1506 (LPARAM)PrintStructures));
1509 DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
1510 PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
1511 DRIVER_INFO_3A *di = PrintStructures->lpDriverInfo;
1513 if (lppd->hDevMode == 0) {
1514 TRACE(" No hDevMode yet... Need to create my own\n");
1515 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
1516 lpdm->dmSize + lpdm->dmDriverExtra);
1519 if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
1520 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
1522 GlobalUnlock(lppd->hDevMode);
1523 TRACE("Now got %d locks\n", locks);
1526 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
1527 lpdm->dmSize + lpdm->dmDriverExtra,
1530 lpdmReturn = GlobalLock(lppd->hDevMode);
1531 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
1533 if (lppd->hDevNames != 0) {
1535 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
1536 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
1538 GlobalUnlock(lppd->hDevNames);
1541 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
1546 GlobalUnlock(lppd->hDevMode);
1548 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
1549 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
1550 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
1551 HeapFree(GetProcessHeap(), 0, PrintStructures);
1553 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
1554 bRet = PRINTDLG_CreateDC(lppd);
1556 TRACE("exit! (%d)\n", bRet);
1560 /***********************************************************************
1561 * PrintDlg (COMMDLG.20)
1563 * Displays the the PRINT dialog box, which enables the user to specify
1564 * specific properties of the print job.
1567 * nonzero if the user pressed the OK button
1568 * zero if the user cancelled the window or an error occurred
1571 * * calls up to the 32-bit versions of the Dialogs, which look different
1572 * * Customizing is *not* implemented.
1575 BOOL16 WINAPI PrintDlg16(
1576 LPPRINTDLG16 lppd /* [in/out] ptr to PRINTDLG struct */
1580 HINSTANCE hInst = GetWindowLongA( lppd->hwndOwner, GWL_HINSTANCE );
1582 if(TRACE_ON(commdlg)) {
1583 char flagstr[1000] = "";
1584 struct pd_flags *pflag = pd_flags;
1585 for( ; pflag->name; pflag++) {
1586 if(lppd->Flags & pflag->flag)
1587 strcat(flagstr, pflag->name);
1589 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
1590 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %08x\n"
1591 "flags %08lx (%s)\n",
1592 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
1593 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
1594 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
1597 if(lppd->lStructSize != sizeof(PRINTDLG16)) {
1598 ERR("structure size (%ld/%d)\n",lppd->lStructSize,sizeof(PRINTDLG16));
1599 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
1603 if(lppd->Flags & PD_RETURNDEFAULT) {
1604 PRINTER_INFO_2A *pbuf;
1605 DRIVER_INFO_3A *dbuf;
1609 if(lppd->hDevMode || lppd->hDevNames) {
1610 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
1611 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
1614 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
1615 WARN("Can't find default printer\n");
1616 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
1620 GetPrinterA(hprn, 2, NULL, 0, &needed);
1621 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
1622 GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
1623 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
1624 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
1625 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
1626 ERR("GetPrinterDriverA failed for %s, le %ld, fix your config!\n",
1627 pbuf->pPrinterName,GetLastError());
1628 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
1632 PRINTDLG_CreateDevNames16(&(lppd->hDevNames),
1636 lppd->hDevMode = GlobalAlloc16(GMEM_MOVEABLE,pbuf->pDevMode->dmSize+
1637 pbuf->pDevMode->dmDriverExtra);
1638 ptr = GlobalLock16(lppd->hDevMode);
1639 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
1640 pbuf->pDevMode->dmDriverExtra);
1641 GlobalUnlock16(lppd->hDevMode);
1642 HeapFree(GetProcessHeap(), 0, pbuf);
1643 HeapFree(GetProcessHeap(), 0, dbuf);
1647 PRINT_PTRA *PrintStructures;
1649 /* load Dialog resources,
1650 * depending on Flags indicates Print32 or Print32_setup dialog
1652 hDlgTmpl = PRINTDLG_GetDlgTemplate16(lppd);
1654 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1657 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
1658 sizeof(PRINT_PTRA));
1659 PrintStructures->dlg.lpPrintDlg16 = lppd;
1660 PrintStructures->dlg.lpPrintDlg = (LPPRINTDLGA)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(PRINTDLGA));
1661 #define CVAL(x) PrintStructures->dlg.lpPrintDlg->x = lppd->x;
1662 #define MVAL(x) PrintStructures->dlg.lpPrintDlg->x = MapSL(lppd->x);
1663 CVAL(Flags);CVAL(hwndOwner);CVAL(hDC);
1664 CVAL(nFromPage);CVAL(nToPage);CVAL(nMinPage);CVAL(nMaxPage);
1665 CVAL(nCopies);CVAL(hInstance);CVAL(lCustData);
1666 MVAL(lpPrintTemplateName);MVAL(lpSetupTemplateName);
1667 /* Don't copy rest, it is 16 bit specific */
1671 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(),0,sizeof(DEVMODEA));
1673 /* and create & process the dialog .
1674 * -1 is failure, 0 is broken hwnd, everything else is ok.
1676 bRet = (0<DialogBoxIndirectParam16(
1677 hInst, hDlgTmpl, lppd->hwndOwner,
1678 (DLGPROC16)GetProcAddress16(GetModuleHandle16("COMMDLG"),(LPCSTR)21),
1679 (LPARAM)PrintStructures
1682 if (!PrintStructures->lpPrinterInfo) bRet = FALSE;
1684 DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
1685 PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
1686 DRIVER_INFO_3A *di = PrintStructures->lpDriverInfo;
1688 if (lppd->hDevMode == 0) {
1689 TRACE(" No hDevMode yet... Need to create my own\n");
1690 lppd->hDevMode = GlobalAlloc16(GMEM_MOVEABLE,
1691 lpdm->dmSize + lpdm->dmDriverExtra);
1694 if((locks = (GlobalFlags16(lppd->hDevMode)&GMEM_LOCKCOUNT))) {
1695 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
1697 GlobalUnlock16(lppd->hDevMode);
1698 TRACE("Now got %d locks\n", locks);
1701 lppd->hDevMode = GlobalReAlloc16(lppd->hDevMode,
1702 lpdm->dmSize + lpdm->dmDriverExtra,
1705 lpdmReturn = GlobalLock16(lppd->hDevMode);
1706 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
1708 if (lppd->hDevNames != 0) {
1710 if((locks = (GlobalFlags16(lppd->hDevNames)&GMEM_LOCKCOUNT))) {
1711 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
1713 GlobalUnlock16(lppd->hDevNames);
1716 PRINTDLG_CreateDevNames16(&(lppd->hDevNames),
1721 GlobalUnlock16(lppd->hDevMode);
1723 if (!(lppd->Flags & (PD_ENABLESETUPTEMPLATEHANDLE | PD_ENABLESETUPTEMPLATE)))
1724 GlobalFree16(hDlgTmpl); /* created from the 32 bits resource */
1725 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
1726 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
1727 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
1728 HeapFree(GetProcessHeap(), 0, PrintStructures);
1730 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
1731 bRet = PRINTDLG_CreateDC16(lppd);
1733 TRACE("exit! (%d)\n", bRet);
1739 /***********************************************************************
1740 * PrintDlgW (COMDLG32.@)
1742 BOOL WINAPI PrintDlgW( LPPRINTDLGW printdlg )
1744 FIXME("A really empty stub\n" );
1748 /***********************************************************************
1754 * cmb3 - source (tray?)
1755 * edt4 - border left
1757 * edt6 - border right
1758 * edt7 - border bottom
1759 * psh3 - "Printer..."
1763 LPPAGESETUPDLGA dlga;
1768 static HGLOBAL PRINTDLG_GetPGSTemplate(PAGESETUPDLGA *lppd)
1770 HGLOBAL hDlgTmpl, hResInfo;
1772 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
1773 hDlgTmpl = lppd->hPageSetupTemplate;
1774 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
1775 hResInfo = FindResourceA(lppd->hInstance,
1776 lppd->lpPageSetupTemplateName, RT_DIALOGA);
1777 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1779 hResInfo = FindResourceA(COMDLG32_hInstance,(LPCSTR)PAGESETUPDLGORD,RT_DIALOGA);
1780 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
1786 _c_10mm2size(PAGESETUPDLGA *dlga,DWORD size) {
1787 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
1788 return 10*size*10/25.4;
1789 /* If we don't have a flag, we can choose one. Use millimeters
1790 * to avoid confusing me
1792 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
1793 FIXME("returning %ld/100 mm \n",size);
1799 _c_inch2size(PAGESETUPDLGA *dlga,DWORD size) {
1800 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
1802 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
1803 return (size*254)/10;
1804 /* if we don't have a flag, we can choose one. Use millimeters
1805 * to avoid confusing me
1807 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
1808 return (size*254)/10;
1812 _c_size2str(PageSetupData *pda,DWORD size,LPSTR strout) {
1813 strcpy(strout,"<undef>");
1814 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
1815 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
1818 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
1819 sprintf(strout,"%.2fin",(size*1.0)/1000.0);
1822 pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
1823 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
1828 _c_str2size(PageSetupData *pda,LPCSTR strin) {
1833 if (!sscanf(strin,"%f%s",&val,rest))
1836 if (!strcmp(rest,"in") || !strcmp(rest,"inch")) {
1837 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
1840 return val*25.4*100;
1842 if (!strcmp(rest,"cm")) { rest[0]='m'; val = val*10.0; }
1843 if (!strcmp(rest,"m")) { strcpy(rest,"mm"); val = val*1000.0; }
1845 if (!strcmp(rest,"mm")) {
1846 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
1849 return 1000.0*val/25.4;
1851 if (rest[0]=='\0') {
1852 /* use application supplied default */
1853 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
1857 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
1862 ERR("Did not find a conversion for type '%s'!\n",rest);
1868 * This is called on finish and will update the output fields of the
1872 PRINTDLG_PS_UpdateDlgStruct(HWND hDlg, PageSetupData *pda) {
1875 LPSTR devname,portname;
1879 dn = GlobalLock(pda->pdlg.hDevNames);
1880 dm = GlobalLock(pda->pdlg.hDevMode);
1881 devname = ((char*)dn)+dn->wDeviceOffset;
1882 portname = ((char*)dn)+dn->wOutputOffset;
1883 PRINTDLG_SetUpPaperComboBox(hDlg,cmb2,devname,portname,dm);
1884 PRINTDLG_SetUpPaperComboBox(hDlg,cmb3,devname,portname,dm);
1886 if (GetDlgItemTextA(hDlg,cmb2,papername,sizeof(papername))>0) {
1887 PRINTDLG_PaperSize(&(pda->pdlg),papername,&(pda->dlga->ptPaperSize));
1888 pda->dlga->ptPaperSize.x = _c_10mm2size(pda->dlga,pda->dlga->ptPaperSize.x);
1889 pda->dlga->ptPaperSize.y = _c_10mm2size(pda->dlga,pda->dlga->ptPaperSize.y);
1891 FIXME("could not get dialog text for papersize cmbbox?\n");
1892 #define GETVAL(id,val) if (GetDlgItemTextA(hDlg,id,buf,sizeof(buf))>0) { val = _c_str2size(pda,buf); } else { FIXME("could not get dlgitemtexta for %x\n",id); }
1893 GETVAL(edt4,pda->dlga->rtMargin.left);
1894 GETVAL(edt5,pda->dlga->rtMargin.top);
1895 GETVAL(edt6,pda->dlga->rtMargin.right);
1896 GETVAL(edt7,pda->dlga->rtMargin.bottom);
1899 /* If we are in landscape, swap x and y of page size */
1900 if (IsDlgButtonChecked(hDlg, rad2)) {
1902 tmp = pda->dlga->ptPaperSize.x;
1903 pda->dlga->ptPaperSize.x = pda->dlga->ptPaperSize.y;
1904 pda->dlga->ptPaperSize.y = tmp;
1906 GlobalUnlock(pda->pdlg.hDevNames);
1907 GlobalUnlock(pda->pdlg.hDevMode);
1912 * This is called after returning from PrintDlg().
1915 PRINTDLG_PS_ChangePrinter(HWND hDlg, PageSetupData *pda) {
1918 LPSTR devname,portname;
1920 dn = GlobalLock(pda->pdlg.hDevNames);
1921 dm = GlobalLock(pda->pdlg.hDevMode);
1922 devname = ((char*)dn)+dn->wDeviceOffset;
1923 portname = ((char*)dn)+dn->wOutputOffset;
1924 PRINTDLG_SetUpPaperComboBox(hDlg,cmb2,devname,portname,dm);
1925 PRINTDLG_SetUpPaperComboBox(hDlg,cmb3,devname,portname,dm);
1926 GlobalUnlock(pda->pdlg.hDevNames);
1927 GlobalUnlock(pda->pdlg.hDevMode);
1932 PRINTDLG_PS_WMCommand(
1933 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupData *pda
1935 switch (LOWORD(wParam)) {
1937 if (!PRINTDLG_PS_UpdateDlgStruct(hDlg, pda))
1939 EndDialog(hDlg, TRUE);
1943 EndDialog(hDlg, FALSE);
1947 pda->pdlg.Flags = 0;
1948 pda->pdlg.hwndOwner = hDlg;
1949 if (PrintDlgA(&(pda->pdlg)))
1950 PRINTDLG_PS_ChangePrinter(hDlg,pda);
1954 FIXME("loword (lparam) %d, wparam 0x%x, lparam %08lx, STUB mostly.\n",
1955 LOWORD(lParam),wParam,lParam
1962 PageDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1967 if (uMsg==WM_INITDIALOG) {
1969 pda = (PageSetupData*)lParam;
1970 SetPropA(hDlg,"__WINE_PAGESETUPDLGDATA",lParam);
1971 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
1972 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
1974 FIXME("Setup page hook failed?\n");
1978 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK) {
1979 FIXME("PagePaintHook not yet implemented!\n");
1981 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
1982 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
1983 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
1984 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
1985 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
1986 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
1987 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
1989 /* width larger as height -> landscape */
1990 if (pda->dlga->ptPaperSize.x > pda->dlga->ptPaperSize.y)
1991 CheckRadioButton(hDlg, rad1, rad2, rad2);
1992 else /* this is default if papersize is not set */
1993 CheckRadioButton(hDlg, rad1, rad2, rad1);
1994 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
1995 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
1996 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
1998 /* We fill them out enabled or not */
1999 if (pda->dlga->Flags & PSD_MARGINS) {
2001 _c_size2str(pda,pda->dlga->rtMargin.left,str);
2002 SetDlgItemTextA(hDlg,edt4,str);
2003 _c_size2str(pda,pda->dlga->rtMargin.top,str);
2004 SetDlgItemTextA(hDlg,edt5,str);
2005 _c_size2str(pda,pda->dlga->rtMargin.right,str);
2006 SetDlgItemTextA(hDlg,edt6,str);
2007 _c_size2str(pda,pda->dlga->rtMargin.bottom,str);
2008 SetDlgItemTextA(hDlg,edt7,str);
2010 /* default is 1 inch */
2011 DWORD size = _c_inch2size(pda->dlga,1000);
2013 _c_size2str(pda,size,str);
2014 SetDlgItemTextA(hDlg,edt4,str);
2015 SetDlgItemTextA(hDlg,edt5,str);
2016 SetDlgItemTextA(hDlg,edt6,str);
2017 SetDlgItemTextA(hDlg,edt7,str);
2019 PRINTDLG_PS_ChangePrinter(hDlg,pda);
2020 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
2021 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
2022 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
2026 pda = (PageSetupData*)GetPropA(hDlg,"__WINE_PAGESETUPDLGDATA");
2028 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
2031 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
2032 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
2033 if (res) return res;
2038 return PRINTDLG_PS_WMCommand(hDlg, wParam, lParam, pda);
2043 /***********************************************************************
2044 * PageSetupDlgA (COMDLG32.@)
2046 BOOL WINAPI PageSetupDlgA(LPPAGESETUPDLGA setupdlg) {
2053 if(TRACE_ON(commdlg)) {
2054 char flagstr[1000] = "";
2055 struct pd_flags *pflag = psd_flags;
2056 for( ; pflag->name; pflag++) {
2057 if(setupdlg->Flags & pflag->flag) {
2058 strcat(flagstr, pflag->name);
2059 strcat(flagstr, "|");
2062 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
2063 "hinst %08x, flags %08lx (%s)\n",
2064 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
2065 setupdlg->hDevNames,
2066 setupdlg->hInstance, setupdlg->Flags, flagstr);
2069 /* First get default printer data, we need it right after that. */
2070 memset(&pdlg,0,sizeof(pdlg));
2071 pdlg.lStructSize = sizeof(pdlg);
2072 pdlg.Flags = PD_RETURNDEFAULT;
2073 bRet = PrintDlgA(&pdlg);
2074 if (!bRet) return FALSE;
2076 /* short cut exit, just return default values */
2077 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
2078 setupdlg->hDevMode = pdlg.hDevMode;
2079 setupdlg->hDevNames = pdlg.hDevNames;
2080 /* FIXME: Just return "A4" for now. */
2081 PRINTDLG_PaperSize(&pdlg,"A4",&setupdlg->ptPaperSize);
2082 setupdlg->ptPaperSize.x=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.x);
2083 setupdlg->ptPaperSize.y=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.y);
2086 hDlgTmpl = PRINTDLG_GetPGSTemplate(setupdlg);
2088 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2091 ptr = LockResource( hDlgTmpl );
2093 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2096 pda = HeapAlloc(GetProcessHeap(),0,sizeof(*pda));
2097 pda->dlga = setupdlg;
2098 memcpy(&pda->pdlg,&pdlg,sizeof(pdlg));
2100 bRet = (0<DialogBoxIndirectParamA(
2101 setupdlg->hInstance,
2103 setupdlg->hwndOwner,
2109 /***********************************************************************
2110 * PageSetupDlgW (COMDLG32.@)
2112 BOOL WINAPI PageSetupDlgW(LPPAGESETUPDLGW setupdlg) {
2113 FIXME("(%p), stub!\n",setupdlg);
2117 /**********************************************************************
2122 /***********************************************************************
2123 * PrintDlgProc (COMMDLG.21)
2125 LRESULT WINAPI PrintDlgProc16(HWND16 hDlg, UINT16 uMsg, WPARAM16 wParam,
2128 PRINT_PTRA* PrintStructures;
2131 if (uMsg!=WM_INITDIALOG) {
2132 PrintStructures = (PRINT_PTRA*) GetWindowLongA(hDlg, DWL_USER);
2133 if (!PrintStructures)
2136 PrintStructures = (PRINT_PTRA*) lParam;
2137 SetWindowLongA(hDlg, DWL_USER, lParam);
2138 res = PRINTDLG_WMInitDialog16(hDlg, wParam, PrintStructures);
2140 if(PrintStructures->dlg.lpPrintDlg16->Flags & PD_ENABLEPRINTHOOK) {
2141 res = CallWindowProc16(
2142 (WNDPROC16)PrintStructures->dlg.lpPrintDlg16->lpfnPrintHook,
2143 hDlg, uMsg, wParam, (LPARAM)PrintStructures->dlg.lpPrintDlg16
2149 if(PrintStructures->dlg.lpPrintDlg16->Flags & PD_ENABLEPRINTHOOK) {
2150 res = CallWindowProc16(
2151 (WNDPROC16)PrintStructures->dlg.lpPrintDlg16->lpfnPrintHook,
2152 hDlg,uMsg, wParam, lParam
2154 if(LOWORD(res)) return res;
2159 /* We need to map those for the 32bit window procedure, compare
2160 * with 32Ato16 mapper in winproc.c
2162 return PRINTDLG_WMCommand(
2164 MAKEWPARAM(wParam,HIWORD(lParam)),
2170 DestroyIcon(PrintStructures->hCollateIcon);
2171 DestroyIcon(PrintStructures->hNoCollateIcon);
2172 /* FIXME: don't forget to delete the paper orientation icons here! */
2180 /***********************************************************************
2181 * PrintSetupDlgProc (COMMDLG.22)
2183 LRESULT WINAPI PrintSetupDlgProc16(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
2189 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
2190 ShowWindow(hWnd, SW_SHOWNORMAL);
2195 EndDialog(hWnd, TRUE);
2198 EndDialog(hWnd, FALSE);
2207 /***********************************************************************
2208 * PrintDlgExA (COMDLG32.@)
2210 HRESULT WINAPI PrintDlgExA(LPVOID lpPrintDlgExA) /* [???] FIXME: LPPRINTDLGEXA */
2215 /***********************************************************************
2216 * PrintDlgExW (COMDLG32.@)
2218 HRESULT WINAPI PrintDlgExW(LPVOID lpPrintDlgExW) /* [???] FIXME: LPPRINTDLGEXW */