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
16 #include "wine/wingdi16.h"
18 #include "wine/winuser16.h"
21 #include "debugtools.h"
26 DEFAULT_DEBUG_CHANNEL(commdlg);
30 /* This PRINTDLGA internal structure stores
31 * pointers to several throughout useful structures.
38 LPPRINTDLGA lpPrintDlg;
39 LPPRINTDLG16 lpPrintDlg16;
41 LPPRINTER_INFO_2A lpPrinterInfo;
42 LPDRIVER_INFO_3A lpDriverInfo;
44 HICON hCollateIcon; /* PrintDlg only */
45 HICON hNoCollateIcon; /* PrintDlg only */
46 HICON hPortraitIcon; /* PrintSetupDlg only */
47 HICON hLandscapeIcon; /* PrintSetupDlg only */
52 static struct pd_flags {
56 {PD_SELECTION, "PD_SELECTION "},
57 {PD_PAGENUMS, "PD_PAGENUMS "},
58 {PD_NOSELECTION, "PD_NOSELECTION "},
59 {PD_NOPAGENUMS, "PD_NOPAGENUMS "},
60 {PD_COLLATE, "PD_COLLATE "},
61 {PD_PRINTTOFILE, "PD_PRINTTOFILE "},
62 {PD_PRINTSETUP, "PD_PRINTSETUP "},
63 {PD_NOWARNING, "PD_NOWARNING "},
64 {PD_RETURNDC, "PD_RETURNDC "},
65 {PD_RETURNIC, "PD_RETURNIC "},
66 {PD_RETURNDEFAULT, "PD_RETURNDEFAULT "},
67 {PD_SHOWHELP, "PD_SHOWHELP "},
68 {PD_ENABLEPRINTHOOK, "PD_ENABLEPRINTHOOK "},
69 {PD_ENABLESETUPHOOK, "PD_ENABLESETUPHOOK "},
70 {PD_ENABLEPRINTTEMPLATE, "PD_ENABLEPRINTTEMPLATE "},
71 {PD_ENABLESETUPTEMPLATE, "PD_ENABLESETUPTEMPLATE "},
72 {PD_ENABLEPRINTTEMPLATEHANDLE, "PD_ENABLEPRINTTEMPLATEHANDLE "},
73 {PD_ENABLESETUPTEMPLATEHANDLE, "PD_ENABLESETUPTEMPLATEHANDLE "},
74 {PD_USEDEVMODECOPIES, "PD_USEDEVMODECOPIES[ANDCOLLATE] "},
75 {PD_DISABLEPRINTTOFILE, "PD_DISABLEPRINTTOFILE "},
76 {PD_HIDEPRINTTOFILE, "PD_HIDEPRINTTOFILE "},
77 {PD_NONETWORKBUTTON, "PD_NONETWORKBUTTON "},
82 static struct pd_flags psd_flags[] = {
83 {PSD_MINMARGINS,"PSD_MINMARGINS"},
84 {PSD_MARGINS,"PSD_MARGINS"},
85 {PSD_INTHOUSANDTHSOFINCHES,"PSD_INTHOUSANDTHSOFINCHES"},
86 {PSD_INHUNDREDTHSOFMILLIMETERS,"PSD_INHUNDREDTHSOFMILLIMETERS"},
87 {PSD_DISABLEMARGINS,"PSD_DISABLEMARGINS"},
88 {PSD_DISABLEPRINTER,"PSD_DISABLEPRINTER"},
89 {PSD_NOWARNING,"PSD_NOWARNING"},
90 {PSD_DISABLEORIENTATION,"PSD_DISABLEORIENTATION"},
91 {PSD_RETURNDEFAULT,"PSD_RETURNDEFAULT"},
92 {PSD_DISABLEPAPER,"PSD_DISABLEPAPER"},
93 {PSD_SHOWHELP,"PSD_SHOWHELP"},
94 {PSD_ENABLEPAGESETUPHOOK,"PSD_ENABLEPAGESETUPHOOK"},
95 {PSD_ENABLEPAGESETUPTEMPLATE,"PSD_ENABLEPAGESETUPTEMPLATE"},
96 {PSD_ENABLEPAGESETUPTEMPLATEHANDLE,"PSD_ENABLEPAGESETUPTEMPLATEHANDLE"},
97 {PSD_ENABLEPAGEPAINTHOOK,"PSD_ENABLEPAGEPAINTHOOK"},
98 {PSD_DISABLEPAGEPAINTING,"PSD_DISABLEPAGEPAINTING"},
102 /* Yes these constants are the same, but we're just copying win98 */
103 #define UPDOWN_ID 0x270f
104 #define MAX_COPIES 9999
106 /***********************************************************************
107 * PRINTDLG_GetDefaultPrinterName
109 * Returns the default printer name in buf.
110 * Even under WinNT/2000 default printer is retrieved via GetProfileString -
111 * these entries are mapped somewhere in the registry rather than win.ini.
113 * Returns TRUE on success else FALSE
115 static BOOL PRINTDLG_GetDefaultPrinterName(LPSTR buf, DWORD len)
119 if(!GetProfileStringA("windows", "device", "", buf, len)) {
120 TRACE("No profile entry for default printer found.\n");
123 if((ptr = strchr(buf, ',')) == NULL) {
124 FIXME("bad format for default printer (%s)!\n",buf);
131 /***********************************************************************
132 * PRINTDLG_OpenDefaultPrinter
134 * Returns a winspool printer handle to the default printer in *hprn
135 * Caller must call ClosePrinter on the handle
137 * Returns TRUE on success else FALSE
139 static BOOL PRINTDLG_OpenDefaultPrinter(HANDLE *hprn)
143 if(!PRINTDLG_GetDefaultPrinterName(buf, sizeof(buf)))
145 res = OpenPrinterA(buf, hprn, NULL);
147 FIXME("Could not open printer %s?!\n",buf);
151 /***********************************************************************
152 * PRINTDLG_SetUpPrinterListCombo
154 * Initializes printer list combox.
155 * hDlg: HWND of dialog
156 * id: Control id of combo
157 * name: Name of printer to select
159 * Initializes combo with list of available printers. Selects printer 'name'
160 * If name is NULL or does not exist select the default printer.
162 * Returns number of printers added to list.
164 static INT PRINTDLG_SetUpPrinterListCombo(HWND hDlg, UINT id, LPCSTR name)
168 LPPRINTER_INFO_2A pi;
169 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
170 pi = HeapAlloc(GetProcessHeap(), 0, needed);
171 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
174 for(i = 0; i < num; i++) {
175 SendDlgItemMessageA(hDlg, id, CB_ADDSTRING, 0,
176 (LPARAM)pi[i].pPrinterName );
178 HeapFree(GetProcessHeap(), 0, pi);
180 (i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1,
181 (LPARAM)name)) == CB_ERR) {
184 FIXME("Can't find '%s' in printer list so trying to find default\n",
186 if(!PRINTDLG_GetDefaultPrinterName(buf, sizeof(buf)))
188 i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
190 FIXME("Can't find default printer in printer list\n");
192 SendDlgItemMessageA(hDlg, id, CB_SETCURSEL, i, 0);
196 /***********************************************************************
197 * PRINTDLG_CreateDevNames [internal]
200 * creates a DevNames structure.
202 * (NB. when we handle unicode the offsets will be in wchars).
204 static BOOL PRINTDLG_CreateDevNames(HGLOBAL *hmem, char* DeviceDriverName,
205 char* DeviceName, char* OutputPort)
208 char* pDevNamesSpace;
210 LPDEVNAMES lpDevNames;
213 size = strlen(DeviceDriverName) + 1
214 + strlen(DeviceName) + 1
215 + strlen(OutputPort) + 1
219 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
221 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
225 pDevNamesSpace = GlobalLock(*hmem);
226 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
228 pTempPtr = pDevNamesSpace + sizeof(DEVNAMES);
229 strcpy(pTempPtr, DeviceDriverName);
230 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
232 pTempPtr += strlen(DeviceDriverName) + 1;
233 strcpy(pTempPtr, DeviceName);
234 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
236 pTempPtr += strlen(DeviceName) + 1;
237 strcpy(pTempPtr, OutputPort);
238 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
240 PRINTDLG_GetDefaultPrinterName(buf, sizeof(buf));
241 lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
246 static BOOL PRINTDLG_CreateDevNames16(HGLOBAL16 *hmem, char* DeviceDriverName,
247 char* DeviceName, char* OutputPort)
250 char* pDevNamesSpace;
252 LPDEVNAMES lpDevNames;
255 size = strlen(DeviceDriverName) + 1
256 + strlen(DeviceName) + 1
257 + strlen(OutputPort) + 1
261 *hmem = GlobalReAlloc16(*hmem, size, GMEM_MOVEABLE);
263 *hmem = GlobalAlloc16(GMEM_MOVEABLE, size);
267 pDevNamesSpace = GlobalLock16(*hmem);
268 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
270 pTempPtr = pDevNamesSpace + sizeof(DEVNAMES);
271 strcpy(pTempPtr, DeviceDriverName);
272 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
274 pTempPtr += strlen(DeviceDriverName) + 1;
275 strcpy(pTempPtr, DeviceName);
276 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
278 pTempPtr += strlen(DeviceName) + 1;
279 strcpy(pTempPtr, OutputPort);
280 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
282 PRINTDLG_GetDefaultPrinterName(buf, sizeof(buf));
283 lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
284 GlobalUnlock16(*hmem);
289 /***********************************************************************
290 * PRINTDLG_UpdatePrintDlg [internal]
293 * updates the PrintDlg structure for returnvalues.
296 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
299 static BOOL PRINTDLG_UpdatePrintDlg(HWND hDlg,
300 PRINT_PTRA* PrintStructures)
302 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
303 PDEVMODEA lpdm = PrintStructures->lpDevMode;
304 LPPRINTER_INFO_2A pi = PrintStructures->lpPrinterInfo;
308 FIXME("No lpdm ptr?\n");
313 if(!(lppd->Flags & PD_PRINTSETUP)) {
314 /* check whether nFromPage and nToPage are within range defined by
315 * nMinPage and nMaxPage
317 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
320 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
321 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
322 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
323 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
324 char resourcestr[256];
326 LoadStringA(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
328 sprintf(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
329 LoadStringA(COMDLG32_hInstance, PD32_PRINT_TITLE,
331 MessageBoxA(hDlg, resultstr, resourcestr,
332 MB_OK | MB_ICONWARNING);
335 lppd->nFromPage = nFromPage;
336 lppd->nToPage = nToPage;
339 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
340 lppd->Flags |= PD_PRINTTOFILE;
341 pi->pPortName = "FILE:";
344 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
345 FIXME("Collate lppd not yet implemented as output\n");
348 /* set PD_Collate and nCopies */
349 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
350 /* The application doesn't support multiple copies or collate...
352 lppd->Flags &= ~PD_COLLATE;
354 /* if the printer driver supports it... store info there
355 * otherwise no collate & multiple copies !
357 if (lpdm->dmFields & DM_COLLATE)
359 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
360 if (lpdm->dmFields & DM_COPIES)
361 lpdm->dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
363 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
364 lppd->Flags |= PD_COLLATE;
366 lppd->Flags &= ~PD_COLLATE;
367 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
373 static BOOL PRINTDLG_PaperSize(
374 PRINTDLGA *pdlga,const char *PaperSize,LPPOINT size
378 LPSTR devname,portname;
382 POINT *points = NULL;
385 dn = GlobalLock(pdlga->hDevNames);
386 dm = GlobalLock(pdlga->hDevMode);
387 devname = ((char*)dn)+dn->wDeviceOffset;
388 portname = ((char*)dn)+dn->wOutputOffset;
391 NrOfEntries = DeviceCapabilitiesA(devname,portname,DC_PAPERNAMES,NULL,dm);
393 FIXME("No papernames found for %s/%s\n",devname,portname);
396 if (NrOfEntries == -1) {
397 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
401 Names = (char*)HeapAlloc(GetProcessHeap(),0,NrOfEntries*64);
402 if (NrOfEntries != (ret=DeviceCapabilitiesA(devname,portname,DC_PAPERNAMES,Names,dm))) {
403 FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
406 for (i=0;i<NrOfEntries;i++)
407 if (!strcmp(PaperSize,Names+(64*i)))
409 HeapFree(GetProcessHeap(),0,Names);
410 if (i==NrOfEntries) {
411 FIXME("Papersize %s not found in list?\n",PaperSize);
414 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
415 if (NrOfEntries!=(ret=DeviceCapabilitiesA(devname,portname,DC_PAPERSIZE,(LPBYTE)points,dm))) {
416 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
419 /* this is _10ths_ of a millimeter */
422 FIXME("papersize is %ld x %ld\n",size->x,size->y);
425 GlobalUnlock(pdlga->hDevNames);
426 GlobalUnlock(pdlga->hDevMode);
427 if (Names) HeapFree(GetProcessHeap(),0,Names);
428 if (points) HeapFree(GetProcessHeap(),0,points);
433 /************************************************************************
434 * PRINTDLG_SetUpPaperComboBox
436 * Initialize either the papersize or inputslot combos of the Printer Setup
437 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
438 * We also try to re-select the old selection.
440 static BOOL PRINTDLG_SetUpPaperComboBox(HWND hDlg,
453 int fwCapability_Names;
454 int fwCapability_Words;
456 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName,PortName,nIDComboBox);
458 /* query the dialog box for the current selected value */
459 Sel = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
461 /* we enter here only if a different printer is selected after
462 * the Print Setup dialog is opened. The current settings are
463 * stored into the newly selected printer.
465 oldWord = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA,
468 if (nIDComboBox == cmb2)
469 dm->u1.s1.dmPaperSize = oldWord;
471 dm->dmDefaultSource = oldWord;
475 /* we enter here only when the Print setup dialog is initially
476 * opened. In this case the settings are restored from when
477 * the dialog was last closed.
480 if (nIDComboBox == cmb2)
481 oldWord = dm->u1.s1.dmPaperSize;
483 oldWord = dm->dmDefaultSource;
487 if (nIDComboBox == cmb2) {
489 fwCapability_Names = DC_PAPERNAMES;
490 fwCapability_Words = DC_PAPERS;
494 fwCapability_Names = DC_BINNAMES;
495 fwCapability_Words = DC_BINS;
498 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
499 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
501 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
502 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
503 fwCapability_Names, NULL, dm);
504 if (NrOfEntries == 0)
505 WARN("no Name Entries found!\n");
506 else if (NrOfEntries < 0)
509 if(DeviceCapabilitiesA(PrinterName, PortName, fwCapability_Words, NULL, dm)
511 ERR("Number of caps is different\n");
515 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*NamesSize);
516 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
517 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
518 fwCapability_Names, Names, dm);
519 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
520 fwCapability_Words, (LPSTR)Words, dm);
522 /* reset any current content in the combobox */
523 SendDlgItemMessageA(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
525 /* store new content */
526 for (i = 0; i < NrOfEntries; i++) {
527 DWORD pos = SendDlgItemMessageA(hDlg, nIDComboBox, CB_ADDSTRING, 0,
528 (LPARAM)(&Names[i*NamesSize]) );
529 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
533 /* Look for old selection - can't do this is previous loop since
534 item order will change as more items are added */
536 for (i = 0; i < NrOfEntries; i++) {
537 if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
543 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
545 HeapFree(GetProcessHeap(),0,Words);
546 HeapFree(GetProcessHeap(),0,Names);
550 /***********************************************************************
551 * PRINTDLG_UpdatePrinterInfoTexts [internal]
553 static void PRINTDLG_UpdatePrinterInfoTexts(HWND hDlg, LPPRINTER_INFO_2A pi)
556 char ResourceString[256];
562 /* add all status messages */
563 for (i = 0; i < 25; i++) {
564 if (pi->Status & (1<<i)) {
565 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
566 ResourceString, 255);
567 strcat(StatusMsg,ResourceString);
571 /* FIXME: status==ready must only be appended if really so.
572 but how to detect? */
573 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
574 ResourceString, 255);
575 strcat(StatusMsg,ResourceString);
577 SendDlgItemMessageA(hDlg, stc12, WM_SETTEXT, 0, (LPARAM)StatusMsg);
579 /* set all other printer info texts */
580 SendDlgItemMessageA(hDlg, stc11, WM_SETTEXT, 0, (LPARAM)pi->pDriverName);
581 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
582 SendDlgItemMessageA(hDlg, stc14, WM_SETTEXT, 0,(LPARAM)pi->pLocation);
584 SendDlgItemMessageA(hDlg, stc14, WM_SETTEXT, 0,(LPARAM)pi->pPortName);
585 SendDlgItemMessageA(hDlg, stc13, WM_SETTEXT, 0, (LPARAM)(pi->pComment ?
591 /*******************************************************************
593 * PRINTDLG_ChangePrinter
596 static BOOL PRINTDLG_ChangePrinter(HWND hDlg, char *name,
597 PRINT_PTRA *PrintStructures)
599 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
600 LPDEVMODEA lpdm = NULL;
605 if(PrintStructures->lpPrinterInfo)
606 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
607 if(PrintStructures->lpDriverInfo)
608 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
609 if(!OpenPrinterA(name, &hprn, NULL)) {
610 ERR("Can't open printer %s\n", name);
613 GetPrinterA(hprn, 2, NULL, 0, &needed);
614 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,needed);
615 GetPrinterA(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
617 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
618 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,needed);
619 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
621 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures->lpPrinterInfo->pPrinterName);
626 PRINTDLG_UpdatePrinterInfoTexts(hDlg, PrintStructures->lpPrinterInfo);
628 if(PrintStructures->lpDevMode) {
629 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
630 PrintStructures->lpDevMode = NULL;
633 dmSize = DocumentPropertiesA(0, 0, name, NULL, NULL, 0);
635 ERR("DocumentProperties fails on %s\n", debugstr_a(name));
638 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
639 dmSize = DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, NULL,
641 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
642 !strcmp(lpdm->dmDeviceName,
643 PrintStructures->lpDevMode->dmDeviceName)) {
644 /* Supplied devicemode matches current printer so try to use it */
645 DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, lpdm,
646 DM_OUT_BUFFER | DM_IN_BUFFER);
649 GlobalUnlock(lppd->hDevMode);
651 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
653 if(!(lppd->Flags & PD_PRINTSETUP)) {
654 /* Print range (All/Range/Selection) */
655 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
656 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
657 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
658 if (lppd->Flags & PD_NOSELECTION)
659 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
661 if (lppd->Flags & PD_SELECTION)
662 CheckRadioButton(hDlg, rad1, rad3, rad2);
663 if (lppd->Flags & PD_NOPAGENUMS) {
664 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
665 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
666 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
667 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
668 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
670 if (lppd->Flags & PD_PAGENUMS)
671 CheckRadioButton(hDlg, rad1, rad3, rad3);
673 /* "All xxx pages"... */
675 char resourcestr[64];
677 LoadStringA(COMDLG32_hInstance, PD32_PRINT_ALL_X_PAGES,
679 sprintf(result,resourcestr,lppd->nMaxPage - lppd->nMinPage + 1);
680 SendDlgItemMessageA(hDlg, rad1, WM_SETTEXT, 0, (LPARAM) result);
685 * FIXME: The ico3 is not displayed for some reason. I don't know why.
687 if (lppd->Flags & PD_COLLATE) {
688 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
689 (LPARAM)PrintStructures->hCollateIcon);
690 CheckDlgButton(hDlg, chx2, 1);
692 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
693 (LPARAM)PrintStructures->hNoCollateIcon);
694 CheckDlgButton(hDlg, chx2, 0);
697 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
698 /* if printer doesn't support it: no Collate */
699 if (!(lpdm->dmFields & DM_COLLATE)) {
700 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
701 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
708 if (lppd->hDevMode == 0)
709 copies = lppd->nCopies;
711 copies = lpdm->dmCopies;
712 if(copies == 0) copies = 1;
713 else if(copies < 0) copies = MAX_COPIES;
714 SetDlgItemInt(hDlg, edt3, copies, FALSE);
717 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
718 /* if printer doesn't support it: no nCopies */
719 if (!(lpdm->dmFields & DM_COPIES)) {
720 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
721 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
726 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
727 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
728 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
729 if (lppd->Flags & PD_HIDEPRINTTOFILE)
730 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
732 } else { /* PD_PRINTSETUP */
733 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
735 PRINTDLG_SetUpPaperComboBox(hDlg, cmb2,
736 PrintStructures->lpPrinterInfo->pPrinterName,
737 PrintStructures->lpPrinterInfo->pPortName,
739 PRINTDLG_SetUpPaperComboBox(hDlg, cmb3,
740 PrintStructures->lpPrinterInfo->pPrinterName,
741 PrintStructures->lpPrinterInfo->pPortName,
743 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
744 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
745 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
746 PrintStructures->hLandscapeIcon));
751 if ((lppd->Flags & PD_SHOWHELP)==0) {
752 /* hide if PD_SHOWHELP not specified */
753 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
758 /***********************************************************************
759 * PRINTDLG_WMInitDialog [internal]
761 static LRESULT PRINTDLG_WMInitDialog(HWND hDlg, WPARAM wParam,
762 PRINT_PTRA* PrintStructures)
764 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
768 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
770 /* load Collate ICONs */
771 /* We load these with LoadImage because they are not a standard
772 size and we don't want them rescaled */
773 PrintStructures->hCollateIcon =
774 LoadImageA(COMDLG32_hInstance, "PD32_COLLATE", IMAGE_ICON, 0, 0, 0);
775 PrintStructures->hNoCollateIcon =
776 LoadImageA(COMDLG32_hInstance, "PD32_NOCOLLATE", IMAGE_ICON, 0, 0, 0);
778 /* These can be done with LoadIcon */
779 PrintStructures->hPortraitIcon =
780 LoadIconA(COMDLG32_hInstance, "PD32_PORTRAIT");
781 PrintStructures->hLandscapeIcon =
782 LoadIconA(COMDLG32_hInstance, "PD32_LANDSCAPE");
784 if(PrintStructures->hCollateIcon == 0 ||
785 PrintStructures->hNoCollateIcon == 0 ||
786 PrintStructures->hPortraitIcon == 0 ||
787 PrintStructures->hLandscapeIcon == 0) {
788 ERR("no icon in resourcefile\n");
789 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
790 EndDialog(hDlg, FALSE);
794 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
795 * must be registered and the Help button must be shown.
797 if (lppd->Flags & PD_SHOWHELP) {
798 if((PrintStructures->HelpMessageID =
799 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
800 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
804 PrintStructures->HelpMessageID = 0;
806 if(!(lppd->Flags &PD_PRINTSETUP)) {
807 PrintStructures->hwndUpDown =
808 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
809 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
810 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
811 hDlg, UPDOWN_ID, COMDLG32_hInstance,
812 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
815 /* FIXME: I allow more freedom than either Win95 or WinNT,
816 * which do not agree to what errors should be thrown or not
817 * in case nToPage or nFromPage is out-of-range.
819 if (lppd->nMaxPage < lppd->nMinPage)
820 lppd->nMaxPage = lppd->nMinPage;
821 if (lppd->nMinPage == lppd->nMaxPage)
822 lppd->Flags |= PD_NOPAGENUMS;
823 if (lppd->nToPage < lppd->nMinPage)
824 lppd->nToPage = lppd->nMinPage;
825 if (lppd->nToPage > lppd->nMaxPage)
826 lppd->nToPage = lppd->nMaxPage;
827 if (lppd->nFromPage < lppd->nMinPage)
828 lppd->nFromPage = lppd->nMinPage;
829 if (lppd->nFromPage > lppd->nMaxPage)
830 lppd->nFromPage = lppd->nMaxPage;
832 /* if we have the combo box, fill it */
833 if (GetDlgItem(hDlg,comboID)) {
836 pdn = GlobalLock(lppd->hDevNames);
837 pdm = GlobalLock(lppd->hDevMode);
839 name = (char*)pdn + pdn->wDeviceOffset;
841 name = pdm->dmDeviceName;
842 PRINTDLG_SetUpPrinterListCombo(hDlg, comboID, name);
843 if(pdm) GlobalUnlock(lppd->hDevMode);
844 if(pdn) GlobalUnlock(lppd->hDevNames);
846 /* Now find selected printer and update rest of dlg */
847 name = HeapAlloc(GetProcessHeap(),0,256);
848 if (GetDlgItemTextA(hDlg, comboID, name, 255))
849 PRINTDLG_ChangePrinter(hDlg, name, PrintStructures);
850 HeapFree(GetProcessHeap(),0,name);
852 /* else use default printer */
854 BOOL ret = PRINTDLG_GetDefaultPrinterName(name, sizeof(name));
857 PRINTDLG_ChangePrinter(hDlg, name, PrintStructures);
859 FIXME("No default printer found, expect problems!\n");
864 /***********************************************************************
865 * PRINTDLG_WMInitDialog [internal]
867 static LRESULT PRINTDLG_WMInitDialog16(HWND hDlg, WPARAM wParam,
868 PRINT_PTRA* PrintStructures)
870 LPPRINTDLG16 lppd = PrintStructures->dlg.lpPrintDlg16;
874 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
876 /* load Collate ICONs */
877 PrintStructures->hCollateIcon =
878 LoadIconA(COMDLG32_hInstance, "PD32_COLLATE");
879 PrintStructures->hNoCollateIcon =
880 LoadIconA(COMDLG32_hInstance, "PD32_NOCOLLATE");
881 if(PrintStructures->hCollateIcon == 0 ||
882 PrintStructures->hNoCollateIcon == 0) {
883 ERR("no icon in resourcefile\n");
884 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
885 EndDialog(hDlg, FALSE);
888 /* load Paper Orientation ICON */
889 /* FIXME: not implemented yet */
892 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
893 * must be registered and the Help button must be shown.
895 if (lppd->Flags & PD_SHOWHELP) {
896 if((PrintStructures->HelpMessageID =
897 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
898 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
902 PrintStructures->HelpMessageID = 0;
904 if (!(lppd->Flags & PD_PRINTSETUP)) {
905 /* We have a print quality combo box. What shall we do? */
906 if (GetDlgItem(hDlg,cmb1)) {
909 FIXME("Print quality only displaying currently.\n");
911 pdm = GlobalLock16(lppd->hDevMode);
913 switch (pdm->dmPrintQuality) {
914 case DMRES_HIGH : strcpy(buf,"High");break;
915 case DMRES_MEDIUM : strcpy(buf,"Medium");break;
916 case DMRES_LOW : strcpy(buf,"Low");break;
917 case DMRES_DRAFT : strcpy(buf,"Draft");break;
918 case 0 : strcpy(buf,"Default");break;
919 default : sprintf(buf,"%ddpi",pdm->dmPrintQuality);break;
921 GlobalUnlock16(lppd->hDevMode);
923 strcpy(buf,"Default");
924 SendDlgItemMessageA(hDlg,cmb1,CB_ADDSTRING,0,(LPARAM)buf);
925 SendDlgItemMessageA(hDlg,cmb1,CB_SETCURSEL,0,0);
926 EnableWindow(GetDlgItem(hDlg,cmb1),FALSE);
930 /* FIXME: I allow more freedom than either Win95 or WinNT,
931 * which do not agree to what errors should be thrown or not
932 * in case nToPage or nFromPage is out-of-range.
934 if (lppd->nMaxPage < lppd->nMinPage)
935 lppd->nMaxPage = lppd->nMinPage;
936 if (lppd->nMinPage == lppd->nMaxPage)
937 lppd->Flags |= PD_NOPAGENUMS;
938 if (lppd->nToPage < lppd->nMinPage)
939 lppd->nToPage = lppd->nMinPage;
940 if (lppd->nToPage > lppd->nMaxPage)
941 lppd->nToPage = lppd->nMaxPage;
942 if (lppd->nFromPage < lppd->nMinPage)
943 lppd->nFromPage = lppd->nMinPage;
944 if (lppd->nFromPage > lppd->nMaxPage)
945 lppd->nFromPage = lppd->nMaxPage;
947 /* If the printer combo box is in the dialog, fill it */
948 if (GetDlgItem(hDlg,comboID)) {
951 pdn = GlobalLock16(lppd->hDevNames);
952 pdm = GlobalLock16(lppd->hDevMode);
954 name = (char*)pdn + pdn->wDeviceOffset;
956 name = pdm->dmDeviceName;
957 PRINTDLG_SetUpPrinterListCombo(hDlg, comboID, name);
958 if(pdm) GlobalUnlock16(lppd->hDevMode);
959 if(pdn) GlobalUnlock16(lppd->hDevNames);
961 /* Now find selected printer and update rest of dlg */
962 name = HeapAlloc(GetProcessHeap(),0,256);
963 if (GetDlgItemTextA(hDlg, comboID, name, 255))
964 PRINTDLG_ChangePrinter(hDlg, name, PrintStructures);
966 /* else just use default printer */
968 BOOL ret = PRINTDLG_GetDefaultPrinterName(name, sizeof(name));
971 PRINTDLG_ChangePrinter(hDlg, name, PrintStructures);
973 FIXME("No default printer found, expect problems!\n");
975 HeapFree(GetProcessHeap(),0,name);
980 /***********************************************************************
981 * PRINTDLG_WMCommand [internal]
983 static LRESULT PRINTDLG_WMCommand(HWND hDlg, WPARAM wParam,
984 LPARAM lParam, PRINT_PTRA* PrintStructures)
986 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
987 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
988 LPDEVMODEA lpdm = PrintStructures->lpDevMode;
990 switch (LOWORD(wParam)) {
992 TRACE(" OK button was hit\n");
993 if (PRINTDLG_UpdatePrintDlg(hDlg, PrintStructures)!=TRUE) {
994 FIXME("Update printdlg was not successful!\n");
997 EndDialog(hDlg, TRUE);
1001 TRACE(" CANCEL button was hit\n");
1002 EndDialog(hDlg, FALSE);
1006 TRACE(" HELP button was hit\n");
1007 SendMessageA(lppd->hwndOwner, PrintStructures->HelpMessageID,
1008 (WPARAM) hDlg, (LPARAM) lppd);
1011 case chx2: /* collate pages checkbox */
1012 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1013 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1014 (LPARAM)PrintStructures->hCollateIcon);
1016 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1017 (LPARAM)PrintStructures->hNoCollateIcon);
1019 case edt1: /* from page nr editbox */
1020 case edt2: /* to page nr editbox */
1021 if (HIWORD(wParam)==EN_CHANGE) {
1024 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1025 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1026 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1027 CheckRadioButton(hDlg, rad1, rad3, rad3);
1032 if(HIWORD(wParam) == EN_CHANGE) {
1033 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1035 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1037 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1041 case psh1: /* Print Setup */
1045 if (!PrintStructures->dlg.lpPrintDlg16) {
1046 FIXME("The 32bit print dialog does not have this button!?\n");
1050 memcpy(&pdlg,PrintStructures->dlg.lpPrintDlg16,sizeof(pdlg));
1051 pdlg.Flags |= PD_PRINTSETUP;
1052 pdlg.hwndOwner = hDlg;
1053 if (!PrintDlg16(&pdlg))
1057 case psh2: /* Properties button */
1060 char PrinterName[256];
1062 GetDlgItemTextA(hDlg, PrinterComboID, PrinterName, 255);
1063 if (!OpenPrinterA(PrinterName, &hPrinter, NULL)) {
1064 FIXME(" Call to OpenPrinter did not succeed!\n");
1067 DocumentPropertiesA(hDlg, hPrinter, PrinterName,
1068 PrintStructures->lpDevMode,
1069 PrintStructures->lpDevMode,
1070 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1071 ClosePrinter(hPrinter);
1075 case rad1: /* Paperorientation */
1076 if (lppd->Flags & PD_PRINTSETUP)
1078 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1079 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1080 (LPARAM)(PrintStructures->hPortraitIcon));
1084 case rad2: /* Paperorientation */
1085 if (lppd->Flags & PD_PRINTSETUP)
1087 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1088 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1089 (LPARAM)(PrintStructures->hLandscapeIcon));
1093 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1094 if (PrinterComboID != wParam) {
1095 FIXME("No handling for print quality combo box yet.\n");
1099 case cmb4: /* Printer combobox */
1100 if (HIWORD(wParam)==CBN_SELCHANGE) {
1101 char PrinterName[256];
1102 GetDlgItemTextA(hDlg, LOWORD(wParam), PrinterName, 255);
1103 PRINTDLG_ChangePrinter(hDlg, PrinterName, PrintStructures);
1107 case cmb2: /* Papersize */
1109 DWORD Sel = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1111 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
1117 case cmb3: /* Bin */
1119 DWORD Sel = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1121 lpdm->dmDefaultSource = SendDlgItemMessageA(hDlg, cmb3,
1122 CB_GETITEMDATA, Sel,
1127 if(lppd->Flags & PD_PRINTSETUP) {
1128 switch (LOWORD(wParam)) {
1129 case rad1: /* orientation */
1131 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1132 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1133 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1134 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1136 (LPARAM)PrintStructures->hPortraitIcon);
1137 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1139 (LPARAM)PrintStructures->hPortraitIcon);
1142 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1143 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1144 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1146 (LPARAM)PrintStructures->hLandscapeIcon);
1147 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1149 (LPARAM)PrintStructures->hLandscapeIcon);
1158 /***********************************************************************
1159 * PrintDlgProcA [internal]
1161 BOOL WINAPI PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
1164 PRINT_PTRA* PrintStructures;
1167 if (uMsg!=WM_INITDIALOG) {
1168 PrintStructures = (PRINT_PTRA*) GetWindowLongA(hDlg, DWL_USER);
1169 if (!PrintStructures)
1172 PrintStructures = (PRINT_PTRA*) lParam;
1173 SetWindowLongA(hDlg, DWL_USER, lParam);
1174 res = PRINTDLG_WMInitDialog(hDlg, wParam, PrintStructures);
1176 if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
1177 res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(
1178 hDlg, uMsg, wParam, (LPARAM)PrintStructures->dlg.lpPrintDlg
1183 if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
1184 res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam,
1191 return PRINTDLG_WMCommand(hDlg, wParam, lParam, PrintStructures);
1194 DestroyIcon(PrintStructures->hCollateIcon);
1195 DestroyIcon(PrintStructures->hNoCollateIcon);
1196 DestroyIcon(PrintStructures->hPortraitIcon);
1197 DestroyIcon(PrintStructures->hLandscapeIcon);
1198 if(PrintStructures->hwndUpDown)
1199 DestroyWindow(PrintStructures->hwndUpDown);
1206 /************************************************************
1208 * PRINTDLG_Get16TemplateFrom32 [Internal]
1209 * Generates a 16 bits template from the Wine 32 bits resource
1212 static HGLOBAL16 PRINTDLG_Get16TemplateFrom32(char *PrintResourceName)
1214 HANDLE hResInfo, hDlgTmpl32;
1217 HGLOBAL16 hGlobal16;
1220 if (!(hResInfo = FindResourceA(COMMDLG_hInstance32,
1221 PrintResourceName, RT_DIALOGA)))
1223 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
1226 if (!(hDlgTmpl32 = LoadResource(COMMDLG_hInstance32, hResInfo )) ||
1227 !(template32 = LockResource( hDlgTmpl32 )))
1229 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1232 size = SizeofResource(COMMDLG_hInstance32, hResInfo);
1233 hGlobal16 = GlobalAlloc16(0, size);
1236 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
1237 ERR("alloc failure for %ld bytes\n", size);
1240 template = GlobalLock16(hGlobal16);
1243 COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE);
1244 ERR("global lock failure for %x handle\n", hGlobal16);
1245 GlobalFree16(hGlobal16);
1248 ConvertDialog32To16((LPVOID)template32, size, (LPVOID)template);
1249 GlobalUnlock16(hGlobal16);
1253 /************************************************************
1255 * PRINTDLG_GetDlgTemplate
1258 static HGLOBAL PRINTDLG_GetDlgTemplate(PRINTDLGA *lppd)
1260 HGLOBAL hDlgTmpl, hResInfo;
1262 if (lppd->Flags & PD_PRINTSETUP) {
1263 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
1264 hDlgTmpl = lppd->hSetupTemplate;
1265 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
1266 hResInfo = FindResourceA(lppd->hInstance,
1267 lppd->lpSetupTemplateName, RT_DIALOGA);
1268 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1270 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32_SETUP",
1272 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1275 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
1276 hDlgTmpl = lppd->hPrintTemplate;
1277 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
1278 hResInfo = FindResourceA(lppd->hInstance,
1279 lppd->lpPrintTemplateName,
1281 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1283 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32",
1285 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1292 /************************************************************
1294 * PRINTDLG_GetDlgTemplate
1297 static HGLOBAL16 PRINTDLG_GetDlgTemplate16(PRINTDLG16 *lppd)
1299 HGLOBAL16 hDlgTmpl, hResInfo;
1301 if (lppd->Flags & PD_PRINTSETUP) {
1302 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
1303 hDlgTmpl = lppd->hSetupTemplate;
1304 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
1305 hResInfo = FindResource16(lppd->hInstance,
1306 MapSL(lppd->lpSetupTemplateName), RT_DIALOGA);
1307 hDlgTmpl = LoadResource16(lppd->hInstance, hResInfo);
1309 hDlgTmpl = PRINTDLG_Get16TemplateFrom32("PRINT32_SETUP");
1312 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
1313 hDlgTmpl = lppd->hPrintTemplate;
1314 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
1315 hResInfo = FindResource16(lppd->hInstance,
1316 MapSL(lppd->lpPrintTemplateName),
1318 hDlgTmpl = LoadResource16(lppd->hInstance, hResInfo);
1320 hDlgTmpl = PRINTDLG_Get16TemplateFrom32("PRINT32");
1326 /***********************************************************************
1331 static BOOL PRINTDLG_CreateDC(LPPRINTDLGA lppd)
1333 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
1334 DEVMODEA *pdm = GlobalLock(lppd->hDevMode);
1336 if(lppd->Flags & PD_RETURNDC) {
1337 lppd->hDC = CreateDCA((char*)pdn + pdn->wDriverOffset,
1338 (char*)pdn + pdn->wDeviceOffset,
1339 (char*)pdn + pdn->wOutputOffset,
1341 } else if(lppd->Flags & PD_RETURNIC) {
1342 lppd->hDC = CreateICA((char*)pdn + pdn->wDriverOffset,
1343 (char*)pdn + pdn->wDeviceOffset,
1344 (char*)pdn + pdn->wOutputOffset,
1347 GlobalUnlock(lppd->hDevNames);
1348 GlobalUnlock(lppd->hDevMode);
1349 return lppd->hDC ? TRUE : FALSE;
1352 static BOOL PRINTDLG_CreateDC16(LPPRINTDLG16 lppd)
1354 DEVNAMES *pdn = GlobalLock16(lppd->hDevNames);
1355 DEVMODEA *pdm = GlobalLock16(lppd->hDevMode);
1357 if(lppd->Flags & PD_RETURNDC) {
1358 lppd->hDC = CreateDCA((char*)pdn + pdn->wDriverOffset,
1359 (char*)pdn + pdn->wDeviceOffset,
1360 (char*)pdn + pdn->wOutputOffset,
1362 } else if(lppd->Flags & PD_RETURNIC) {
1363 lppd->hDC = CreateICA((char*)pdn + pdn->wDriverOffset,
1364 (char*)pdn + pdn->wDeviceOffset,
1365 (char*)pdn + pdn->wOutputOffset,
1368 GlobalUnlock16(lppd->hDevNames);
1369 GlobalUnlock16(lppd->hDevMode);
1370 return lppd->hDC ? TRUE : FALSE;
1373 /***********************************************************************
1374 * PrintDlgA (COMDLG32.@)
1376 * Displays the the PRINT dialog box, which enables the user to specify
1377 * specific properties of the print job.
1380 * nonzero if the user pressed the OK button
1381 * zero if the user cancelled the window or an error occurred
1385 * * The Collate Icons do not display, even though they are in the code.
1386 * * The Properties Button(s) should call DocumentPropertiesA().
1388 * * The Paper Orientation Icons are not implemented yet.
1389 * * The Properties Button(s) should call DocumentPropertiesA().
1390 * * Settings are not yet taken from a provided DevMode or
1391 * default printer settings.
1393 BOOL WINAPI PrintDlgA(
1394 LPPRINTDLGA lppd /* [in/out] ptr to PRINTDLG32 struct */
1399 HINSTANCE hInst = GetWindowLongA( lppd->hwndOwner, GWL_HINSTANCE );
1401 if(TRACE_ON(commdlg)) {
1402 char flagstr[1000] = "";
1403 struct pd_flags *pflag = pd_flags;
1404 for( ; pflag->name; pflag++) {
1405 if(lppd->Flags & pflag->flag)
1406 strcat(flagstr, pflag->name);
1408 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
1409 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %08x\n"
1410 "flags %08lx (%s)\n",
1411 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
1412 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
1413 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
1416 if(lppd->lStructSize != sizeof(PRINTDLGA)) {
1417 WARN("structure size failure !!!\n");
1418 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
1422 if(lppd->Flags & PD_RETURNDEFAULT) {
1423 PRINTER_INFO_2A *pbuf;
1424 DRIVER_INFO_3A *dbuf;
1428 if(lppd->hDevMode || lppd->hDevNames) {
1429 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
1430 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
1433 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
1434 WARN("Can't find default printer\n");
1435 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
1439 GetPrinterA(hprn, 2, NULL, 0, &needed);
1440 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
1441 GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
1443 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
1444 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
1445 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
1446 ERR("GetPrinterDriverA failed, le %ld, fix your config for printer %s!\n",GetLastError(),pbuf->pPrinterName);
1447 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
1452 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
1456 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
1457 pbuf->pDevMode->dmDriverExtra);
1458 ptr = GlobalLock(lppd->hDevMode);
1459 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
1460 pbuf->pDevMode->dmDriverExtra);
1461 GlobalUnlock(lppd->hDevMode);
1462 HeapFree(GetProcessHeap(), 0, pbuf);
1463 HeapFree(GetProcessHeap(), 0, dbuf);
1467 PRINT_PTRA *PrintStructures;
1469 /* load Dialog resources,
1470 * depending on Flags indicates Print32 or Print32_setup dialog
1472 hDlgTmpl = PRINTDLG_GetDlgTemplate(lppd);
1474 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1477 ptr = LockResource( hDlgTmpl );
1479 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1483 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
1484 sizeof(PRINT_PTRA));
1485 PrintStructures->dlg.lpPrintDlg = lppd;
1487 /* and create & process the dialog .
1488 * -1 is failure, 0 is broken hwnd, everything else is ok.
1490 bRet = (0<DialogBoxIndirectParamA(hInst, ptr, lppd->hwndOwner,
1492 (LPARAM)PrintStructures));
1495 DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
1496 PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
1497 DRIVER_INFO_3A *di = PrintStructures->lpDriverInfo;
1499 if (lppd->hDevMode == 0) {
1500 TRACE(" No hDevMode yet... Need to create my own\n");
1501 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
1502 lpdm->dmSize + lpdm->dmDriverExtra);
1505 if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
1506 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
1508 GlobalUnlock(lppd->hDevMode);
1509 TRACE("Now got %d locks\n", locks);
1512 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
1513 lpdm->dmSize + lpdm->dmDriverExtra,
1516 lpdmReturn = GlobalLock(lppd->hDevMode);
1517 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
1519 if (lppd->hDevNames != 0) {
1521 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
1522 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
1524 GlobalUnlock(lppd->hDevNames);
1527 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
1532 GlobalUnlock(lppd->hDevMode);
1534 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
1535 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
1536 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
1537 HeapFree(GetProcessHeap(), 0, PrintStructures);
1539 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
1540 bRet = PRINTDLG_CreateDC(lppd);
1542 TRACE("exit! (%d)\n", bRet);
1546 /***********************************************************************
1547 * PrintDlg (COMMDLG.20)
1549 * Displays the the PRINT dialog box, which enables the user to specify
1550 * specific properties of the print job.
1553 * nonzero if the user pressed the OK button
1554 * zero if the user cancelled the window or an error occurred
1557 * * calls up to the 32-bit versions of the Dialogs, which look different
1558 * * Customizing is *not* implemented.
1561 BOOL16 WINAPI PrintDlg16(
1562 LPPRINTDLG16 lppd /* [in/out] ptr to PRINTDLG struct */
1566 HINSTANCE hInst = GetWindowLongA( lppd->hwndOwner, GWL_HINSTANCE );
1568 if(TRACE_ON(commdlg)) {
1569 char flagstr[1000] = "";
1570 struct pd_flags *pflag = pd_flags;
1571 for( ; pflag->name; pflag++) {
1572 if(lppd->Flags & pflag->flag)
1573 strcat(flagstr, pflag->name);
1575 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
1576 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %08x\n"
1577 "flags %08lx (%s)\n",
1578 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
1579 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
1580 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
1583 if(lppd->lStructSize != sizeof(PRINTDLG16)) {
1584 ERR("structure size (%ld/%d)\n",lppd->lStructSize,sizeof(PRINTDLG16));
1585 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
1589 if(lppd->Flags & PD_RETURNDEFAULT) {
1590 PRINTER_INFO_2A *pbuf;
1591 DRIVER_INFO_3A *dbuf;
1595 if(lppd->hDevMode || lppd->hDevNames) {
1596 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
1597 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
1600 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
1601 WARN("Can't find default printer\n");
1602 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
1606 GetPrinterA(hprn, 2, NULL, 0, &needed);
1607 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
1608 GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
1609 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
1610 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
1611 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
1612 ERR("GetPrinterDriverA failed for %s, le %ld, fix your config!\n",
1613 pbuf->pPrinterName,GetLastError());
1614 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
1618 PRINTDLG_CreateDevNames16(&(lppd->hDevNames),
1622 lppd->hDevMode = GlobalAlloc16(GMEM_MOVEABLE,pbuf->pDevMode->dmSize+
1623 pbuf->pDevMode->dmDriverExtra);
1624 ptr = GlobalLock16(lppd->hDevMode);
1625 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
1626 pbuf->pDevMode->dmDriverExtra);
1627 GlobalUnlock16(lppd->hDevMode);
1628 HeapFree(GetProcessHeap(), 0, pbuf);
1629 HeapFree(GetProcessHeap(), 0, dbuf);
1633 PRINT_PTRA *PrintStructures;
1635 /* load Dialog resources,
1636 * depending on Flags indicates Print32 or Print32_setup dialog
1638 hDlgTmpl = PRINTDLG_GetDlgTemplate16(lppd);
1640 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1643 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
1644 sizeof(PRINT_PTRA));
1645 PrintStructures->dlg.lpPrintDlg16 = lppd;
1646 PrintStructures->dlg.lpPrintDlg = (LPPRINTDLGA)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(PRINTDLGA));
1647 #define CVAL(x) PrintStructures->dlg.lpPrintDlg->x = lppd->x;
1648 #define MVAL(x) PrintStructures->dlg.lpPrintDlg->x = MapSL(lppd->x);
1649 CVAL(Flags);CVAL(hwndOwner);CVAL(hDC);
1650 CVAL(nFromPage);CVAL(nToPage);CVAL(nMinPage);CVAL(nMaxPage);
1651 CVAL(nCopies);CVAL(hInstance);CVAL(lCustData);
1652 MVAL(lpPrintTemplateName);MVAL(lpSetupTemplateName);
1653 /* Don't copy rest, it is 16 bit specific */
1657 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(),0,sizeof(DEVMODEA));
1659 /* and create & process the dialog .
1660 * -1 is failure, 0 is broken hwnd, everything else is ok.
1662 bRet = (0<DialogBoxIndirectParam16(
1663 hInst, hDlgTmpl, lppd->hwndOwner,
1664 (DLGPROC16)GetProcAddress16(GetModuleHandle16("COMMDLG"),(LPCSTR)21),
1665 (LPARAM)PrintStructures
1668 if (!PrintStructures->lpPrinterInfo) bRet = FALSE;
1670 DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
1671 PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
1672 DRIVER_INFO_3A *di = PrintStructures->lpDriverInfo;
1674 if (lppd->hDevMode == 0) {
1675 TRACE(" No hDevMode yet... Need to create my own\n");
1676 lppd->hDevMode = GlobalAlloc16(GMEM_MOVEABLE,
1677 lpdm->dmSize + lpdm->dmDriverExtra);
1680 if((locks = (GlobalFlags16(lppd->hDevMode)&GMEM_LOCKCOUNT))) {
1681 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
1683 GlobalUnlock16(lppd->hDevMode);
1684 TRACE("Now got %d locks\n", locks);
1687 lppd->hDevMode = GlobalReAlloc16(lppd->hDevMode,
1688 lpdm->dmSize + lpdm->dmDriverExtra,
1691 lpdmReturn = GlobalLock16(lppd->hDevMode);
1692 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
1694 if (lppd->hDevNames != 0) {
1696 if((locks = (GlobalFlags16(lppd->hDevNames)&GMEM_LOCKCOUNT))) {
1697 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
1699 GlobalUnlock16(lppd->hDevNames);
1702 PRINTDLG_CreateDevNames16(&(lppd->hDevNames),
1707 GlobalUnlock16(lppd->hDevMode);
1709 if (!(lppd->Flags & (PD_ENABLESETUPTEMPLATEHANDLE | PD_ENABLESETUPTEMPLATE)))
1710 GlobalFree16(hDlgTmpl); /* created from the 32 bits resource */
1711 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
1712 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
1713 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
1714 HeapFree(GetProcessHeap(), 0, PrintStructures);
1716 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
1717 bRet = PRINTDLG_CreateDC16(lppd);
1719 TRACE("exit! (%d)\n", bRet);
1725 /***********************************************************************
1726 * PrintDlgW (COMDLG32.@)
1728 BOOL WINAPI PrintDlgW( LPPRINTDLGW printdlg )
1730 FIXME("A really empty stub\n" );
1734 /***********************************************************************
1740 * cmb3 - source (tray?)
1741 * edt4 - border left
1743 * edt6 - border right
1744 * edt7 - border bottom
1745 * psh3 - "Printer..."
1749 LPPAGESETUPDLGA dlga;
1754 static HGLOBAL PRINTDLG_GetPGSTemplate(PAGESETUPDLGA *lppd)
1756 HGLOBAL hDlgTmpl, hResInfo;
1758 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
1759 hDlgTmpl = lppd->hPageSetupTemplate;
1760 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
1761 hResInfo = FindResourceA(lppd->hInstance,
1762 lppd->lpPageSetupTemplateName, RT_DIALOGA);
1763 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1765 hResInfo = FindResourceA(COMDLG32_hInstance,(LPCSTR)PAGESETUPDLGORD,RT_DIALOGA);
1766 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
1772 _c_10mm2size(PAGESETUPDLGA *dlga,DWORD size) {
1773 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
1774 return 10*size*10/25.4;
1775 /* If we don't have a flag, we can choose one. Use millimeters
1776 * to avoid confusing me
1778 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
1779 FIXME("returning %ld/100 mm \n",size);
1785 _c_inch2size(PAGESETUPDLGA *dlga,DWORD size) {
1786 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
1788 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
1789 return (size*254)/10;
1790 /* if we don't have a flag, we can choose one. Use millimeters
1791 * to avoid confusing me
1793 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
1794 return (size*254)/10;
1798 _c_size2str(PageSetupData *pda,DWORD size,LPSTR strout) {
1799 strcpy(strout,"<undef>");
1800 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
1801 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
1804 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
1805 sprintf(strout,"%.2fin",(size*1.0)/1000.0);
1808 pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
1809 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
1814 _c_str2size(PageSetupData *pda,LPCSTR strin) {
1819 if (!sscanf(strin,"%f%s",&val,rest))
1822 if (!strcmp(rest,"in") || !strcmp(rest,"inch")) {
1823 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
1826 return val*25.4*100;
1828 if (!strcmp(rest,"cm")) { rest[0]='m'; val = val*10.0; }
1829 if (!strcmp(rest,"m")) { strcpy(rest,"mm"); val = val*1000.0; }
1831 if (!strcmp(rest,"mm")) {
1832 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
1835 return 1000.0*val/25.4;
1837 if (rest[0]=='\0') {
1838 /* use application supplied default */
1839 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
1843 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
1848 ERR("Did not find a conversion for type '%s'!\n",rest);
1854 * This is called on finish and will update the output fields of the
1858 PRINTDLG_PS_UpdateDlgStruct(HWND hDlg, PageSetupData *pda) {
1861 LPSTR devname,portname;
1865 dn = GlobalLock(pda->pdlg.hDevNames);
1866 dm = GlobalLock(pda->pdlg.hDevMode);
1867 devname = ((char*)dn)+dn->wDeviceOffset;
1868 portname = ((char*)dn)+dn->wOutputOffset;
1869 PRINTDLG_SetUpPaperComboBox(hDlg,cmb2,devname,portname,dm);
1870 PRINTDLG_SetUpPaperComboBox(hDlg,cmb3,devname,portname,dm);
1872 if (GetDlgItemTextA(hDlg,cmb2,papername,sizeof(papername))>0) {
1873 PRINTDLG_PaperSize(&(pda->pdlg),papername,&(pda->dlga->ptPaperSize));
1874 pda->dlga->ptPaperSize.x = _c_10mm2size(pda->dlga,pda->dlga->ptPaperSize.x);
1875 pda->dlga->ptPaperSize.y = _c_10mm2size(pda->dlga,pda->dlga->ptPaperSize.y);
1877 FIXME("could not get dialog text for papersize cmbbox?\n");
1878 #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); }
1879 GETVAL(edt4,pda->dlga->rtMargin.left);
1880 GETVAL(edt5,pda->dlga->rtMargin.top);
1881 GETVAL(edt6,pda->dlga->rtMargin.right);
1882 GETVAL(edt7,pda->dlga->rtMargin.bottom);
1885 /* If we are in landscape, swap x and y of page size */
1886 if (IsDlgButtonChecked(hDlg, rad2)) {
1888 tmp = pda->dlga->ptPaperSize.x;
1889 pda->dlga->ptPaperSize.x = pda->dlga->ptPaperSize.y;
1890 pda->dlga->ptPaperSize.y = tmp;
1892 GlobalUnlock(pda->pdlg.hDevNames);
1893 GlobalUnlock(pda->pdlg.hDevMode);
1898 * This is called after returning from PrintDlg().
1901 PRINTDLG_PS_ChangePrinter(HWND hDlg, PageSetupData *pda) {
1904 LPSTR devname,portname;
1906 dn = GlobalLock(pda->pdlg.hDevNames);
1907 dm = GlobalLock(pda->pdlg.hDevMode);
1908 devname = ((char*)dn)+dn->wDeviceOffset;
1909 portname = ((char*)dn)+dn->wOutputOffset;
1910 PRINTDLG_SetUpPaperComboBox(hDlg,cmb2,devname,portname,dm);
1911 PRINTDLG_SetUpPaperComboBox(hDlg,cmb3,devname,portname,dm);
1912 GlobalUnlock(pda->pdlg.hDevNames);
1913 GlobalUnlock(pda->pdlg.hDevMode);
1918 PRINTDLG_PS_WMCommand(
1919 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupData *pda
1921 switch (LOWORD(wParam)) {
1923 if (!PRINTDLG_PS_UpdateDlgStruct(hDlg, pda))
1925 EndDialog(hDlg, TRUE);
1929 EndDialog(hDlg, FALSE);
1933 pda->pdlg.Flags = 0;
1934 pda->pdlg.hwndOwner = hDlg;
1935 if (PrintDlgA(&(pda->pdlg)))
1936 PRINTDLG_PS_ChangePrinter(hDlg,pda);
1940 FIXME("loword (lparam) %d, wparam 0x%x, lparam %08lx, STUB mostly.\n",
1941 LOWORD(lParam),wParam,lParam
1948 PageDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1953 if (uMsg==WM_INITDIALOG) {
1955 pda = (PageSetupData*)lParam;
1956 SetPropA(hDlg,"__WINE_PAGESETUPDLGDATA",lParam);
1957 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
1958 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
1960 FIXME("Setup page hook failed?\n");
1964 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK) {
1965 FIXME("PagePaintHook not yet implemented!\n");
1967 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
1968 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
1969 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
1970 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
1971 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
1972 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
1973 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
1975 /* width larger as height -> landscape */
1976 if (pda->dlga->ptPaperSize.x > pda->dlga->ptPaperSize.y)
1977 CheckRadioButton(hDlg, rad1, rad2, rad2);
1978 else /* this is default if papersize is not set */
1979 CheckRadioButton(hDlg, rad1, rad2, rad1);
1980 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
1981 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
1982 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
1984 /* We fill them out enabled or not */
1985 if (pda->dlga->Flags & PSD_MARGINS) {
1987 _c_size2str(pda,pda->dlga->rtMargin.left,str);
1988 SetDlgItemTextA(hDlg,edt4,str);
1989 _c_size2str(pda,pda->dlga->rtMargin.top,str);
1990 SetDlgItemTextA(hDlg,edt5,str);
1991 _c_size2str(pda,pda->dlga->rtMargin.right,str);
1992 SetDlgItemTextA(hDlg,edt6,str);
1993 _c_size2str(pda,pda->dlga->rtMargin.bottom,str);
1994 SetDlgItemTextA(hDlg,edt7,str);
1996 /* default is 1 inch */
1997 DWORD size = _c_inch2size(pda->dlga,1000);
1999 _c_size2str(pda,size,str);
2000 SetDlgItemTextA(hDlg,edt4,str);
2001 SetDlgItemTextA(hDlg,edt5,str);
2002 SetDlgItemTextA(hDlg,edt6,str);
2003 SetDlgItemTextA(hDlg,edt7,str);
2005 PRINTDLG_PS_ChangePrinter(hDlg,pda);
2006 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
2007 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
2008 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
2012 pda = (PageSetupData*)GetPropA(hDlg,"__WINE_PAGESETUPDLGDATA");
2014 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
2017 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
2018 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
2019 if (res) return res;
2024 return PRINTDLG_PS_WMCommand(hDlg, wParam, lParam, pda);
2029 /***********************************************************************
2030 * PageSetupDlgA (COMDLG32.@)
2032 BOOL WINAPI PageSetupDlgA(LPPAGESETUPDLGA setupdlg) {
2039 if(TRACE_ON(commdlg)) {
2040 char flagstr[1000] = "";
2041 struct pd_flags *pflag = psd_flags;
2042 for( ; pflag->name; pflag++) {
2043 if(setupdlg->Flags & pflag->flag) {
2044 strcat(flagstr, pflag->name);
2045 strcat(flagstr, "|");
2048 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
2049 "hinst %08x, flags %08lx (%s)\n",
2050 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
2051 setupdlg->hDevNames,
2052 setupdlg->hInstance, setupdlg->Flags, flagstr);
2055 /* First get default printer data, we need it right after that. */
2056 memset(&pdlg,0,sizeof(pdlg));
2057 pdlg.lStructSize = sizeof(pdlg);
2058 pdlg.Flags = PD_RETURNDEFAULT;
2059 bRet = PrintDlgA(&pdlg);
2060 if (!bRet) return FALSE;
2062 /* short cut exit, just return default values */
2063 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
2064 setupdlg->hDevMode = pdlg.hDevMode;
2065 setupdlg->hDevNames = pdlg.hDevNames;
2066 /* FIXME: Just return "A4" for now. */
2067 PRINTDLG_PaperSize(&pdlg,"A4",&setupdlg->ptPaperSize);
2068 setupdlg->ptPaperSize.x=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.x);
2069 setupdlg->ptPaperSize.y=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.y);
2072 hDlgTmpl = PRINTDLG_GetPGSTemplate(setupdlg);
2074 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2077 ptr = LockResource( hDlgTmpl );
2079 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2082 pda = HeapAlloc(GetProcessHeap(),0,sizeof(*pda));
2083 pda->dlga = setupdlg;
2084 memcpy(&pda->pdlg,&pdlg,sizeof(pdlg));
2086 bRet = (0<DialogBoxIndirectParamA(
2087 setupdlg->hInstance,
2089 setupdlg->hwndOwner,
2095 /***********************************************************************
2096 * PageSetupDlgW (COMDLG32.@)
2098 BOOL WINAPI PageSetupDlgW(LPPAGESETUPDLGW setupdlg) {
2099 FIXME("(%p), stub!\n",setupdlg);
2103 /**********************************************************************
2108 /***********************************************************************
2109 * PrintDlgProc (COMMDLG.21)
2111 LRESULT WINAPI PrintDlgProc16(HWND16 hDlg, UINT16 uMsg, WPARAM16 wParam,
2114 PRINT_PTRA* PrintStructures;
2117 if (uMsg!=WM_INITDIALOG) {
2118 PrintStructures = (PRINT_PTRA*) GetWindowLongA(hDlg, DWL_USER);
2119 if (!PrintStructures)
2122 PrintStructures = (PRINT_PTRA*) lParam;
2123 SetWindowLongA(hDlg, DWL_USER, lParam);
2124 res = PRINTDLG_WMInitDialog16(hDlg, wParam, PrintStructures);
2126 if(PrintStructures->dlg.lpPrintDlg16->Flags & PD_ENABLEPRINTHOOK) {
2127 res = CallWindowProc16(
2128 (WNDPROC16)PrintStructures->dlg.lpPrintDlg16->lpfnPrintHook,
2129 hDlg, uMsg, wParam, (LPARAM)PrintStructures->dlg.lpPrintDlg16
2135 if(PrintStructures->dlg.lpPrintDlg16->Flags & PD_ENABLEPRINTHOOK) {
2136 res = CallWindowProc16(
2137 (WNDPROC16)PrintStructures->dlg.lpPrintDlg16->lpfnPrintHook,
2138 hDlg,uMsg, wParam, lParam
2140 if(LOWORD(res)) return res;
2145 /* We need to map those for the 32bit window procedure, compare
2146 * with 32Ato16 mapper in winproc.c
2148 return PRINTDLG_WMCommand(
2150 MAKEWPARAM(wParam,HIWORD(lParam)),
2156 DestroyIcon(PrintStructures->hCollateIcon);
2157 DestroyIcon(PrintStructures->hNoCollateIcon);
2158 /* FIXME: don't forget to delete the paper orientation icons here! */
2166 /***********************************************************************
2167 * PrintSetupDlgProc (COMMDLG.22)
2169 LRESULT WINAPI PrintSetupDlgProc16(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
2175 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
2176 ShowWindow(hWnd, SW_SHOWNORMAL);
2181 EndDialog(hWnd, TRUE);
2184 EndDialog(hWnd, FALSE);
2193 /***********************************************************************
2194 * PrintDlgExA (COMDLG32.@)
2196 HRESULT WINAPI PrintDlgExA(LPVOID lpPrintDlgExA) /* [???] FIXME: LPPRINTDLGEXA */
2201 /***********************************************************************
2202 * PrintDlgExW (COMDLG32.@)
2204 HRESULT WINAPI PrintDlgExW(LPVOID lpPrintDlgExW) /* [???] FIXME: LPPRINTDLGEXW */