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
;
380 DWORD NrOfEntries
,ret
;
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 Names
= (char*)HeapAlloc(GetProcessHeap(),0,NrOfEntries
*64);
397 if (NrOfEntries
!= (ret
=DeviceCapabilitiesA(devname
,portname
,DC_PAPERNAMES
,Names
,dm
))) {
398 FIXME("Number of returned vals %ld is not %ld\n",NrOfEntries
,ret
);
401 for (i
=0;i
<NrOfEntries
;i
++)
402 if (!strcmp(PaperSize
,Names
+(64*i
)))
404 HeapFree(GetProcessHeap(),0,Names
);
405 if (i
==NrOfEntries
) {
406 FIXME("Papersize %s not found in list?\n",PaperSize
);
409 points
= HeapAlloc(GetProcessHeap(),0,sizeof(points
[0])*NrOfEntries
);
410 if (NrOfEntries
!=(ret
=DeviceCapabilitiesA(devname
,portname
,DC_PAPERSIZE
,(LPBYTE
)points
,dm
))) {
411 FIXME("Number of returned sizes %ld is not %ld?\n",NrOfEntries
,ret
);
414 /* this is _10ths_ of a millimeter */
417 FIXME("papersize is %ld x %ld\n",size
->x
,size
->y
);
420 GlobalUnlock(pdlga
->hDevNames
);
421 GlobalUnlock(pdlga
->hDevMode
);
422 if (Names
) HeapFree(GetProcessHeap(),0,Names
);
423 if (points
) HeapFree(GetProcessHeap(),0,points
);
428 /************************************************************************
429 * PRINTDLG_SetUpPaperComboBox
431 * Initialize either the papersize or inputslot combos of the Printer Setup
432 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
433 * We also try to re-select the old selection.
435 static BOOL
PRINTDLG_SetUpPaperComboBox(HWND hDlg
,
448 int fwCapability_Names
;
449 int fwCapability_Words
;
451 TRACE(" Printer: %s, ComboID: %d\n",PrinterName
,nIDComboBox
);
453 /* query the dialog box for the current selected value */
454 Sel
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETCURSEL
, 0, 0);
456 /* we enter here only if a different printer is selected after
457 * the Print Setup dialog is opened. The current settings are
458 * stored into the newly selected printer.
460 oldWord
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
,
463 if (nIDComboBox
== cmb2
)
464 dm
->u1
.s1
.dmPaperSize
= oldWord
;
466 dm
->dmDefaultSource
= oldWord
;
470 /* we enter here only when the Print setup dialog is initially
471 * opened. In this case the settings are restored from when
472 * the dialog was last closed.
475 if (nIDComboBox
== cmb2
)
476 oldWord
= dm
->u1
.s1
.dmPaperSize
;
478 oldWord
= dm
->dmDefaultSource
;
482 if (nIDComboBox
== cmb2
) {
484 fwCapability_Names
= DC_PAPERNAMES
;
485 fwCapability_Words
= DC_PAPERS
;
489 fwCapability_Names
= DC_BINNAMES
;
490 fwCapability_Words
= DC_BINS
;
493 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
494 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
496 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
497 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
498 fwCapability_Names
, NULL
, dm
);
499 if (NrOfEntries
== 0)
500 WARN("no Name Entries found!\n");
502 if(DeviceCapabilitiesA(PrinterName
, PortName
, fwCapability_Words
, NULL
, dm
)
504 ERR("Number of caps is different\n");
508 Names
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*NamesSize
);
509 Words
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WORD
));
510 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
511 fwCapability_Names
, Names
, dm
);
512 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
513 fwCapability_Words
, (LPSTR
)Words
, dm
);
515 /* reset any current content in the combobox */
516 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_RESETCONTENT
, 0, 0);
518 /* store new content */
519 for (i
= 0; i
< NrOfEntries
; i
++) {
520 DWORD pos
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_ADDSTRING
, 0,
521 (LPARAM
)(&Names
[i
*NamesSize
]) );
522 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_SETITEMDATA
, pos
,
526 /* Look for old selection - can't do this is previous loop since
527 item order will change as more items are added */
529 for (i
= 0; i
< NrOfEntries
; i
++) {
530 if(SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) ==
536 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_SETCURSEL
, Sel
, 0);
538 HeapFree(GetProcessHeap(),0,Words
);
539 HeapFree(GetProcessHeap(),0,Names
);
543 /***********************************************************************
544 * PRINTDLG_UpdatePrinterInfoTexts [internal]
546 static void PRINTDLG_UpdatePrinterInfoTexts(HWND hDlg
, LPPRINTER_INFO_2A pi
)
549 char ResourceString
[256];
555 /* add all status messages */
556 for (i
= 0; i
< 25; i
++) {
557 if (pi
->Status
& (1<<i
)) {
558 LoadStringA(COMDLG32_hInstance
, PD32_PRINTER_STATUS_PAUSED
+i
,
559 ResourceString
, 255);
560 strcat(StatusMsg
,ResourceString
);
564 /* FIXME: status==ready must only be appended if really so.
565 but how to detect? */
566 LoadStringA(COMDLG32_hInstance
, PD32_PRINTER_STATUS_READY
,
567 ResourceString
, 255);
568 strcat(StatusMsg
,ResourceString
);
570 SendDlgItemMessageA(hDlg
, stc12
, WM_SETTEXT
, 0, (LPARAM
)StatusMsg
);
572 /* set all other printer info texts */
573 SendDlgItemMessageA(hDlg
, stc11
, WM_SETTEXT
, 0, (LPARAM
)pi
->pDriverName
);
574 if (pi
->pLocation
!= NULL
&& pi
->pLocation
[0] != '\0')
575 SendDlgItemMessageA(hDlg
, stc14
, WM_SETTEXT
, 0,(LPARAM
)pi
->pLocation
);
577 SendDlgItemMessageA(hDlg
, stc14
, WM_SETTEXT
, 0,(LPARAM
)pi
->pPortName
);
578 SendDlgItemMessageA(hDlg
, stc13
, WM_SETTEXT
, 0, (LPARAM
)(pi
->pComment
?
584 /*******************************************************************
586 * PRINTDLG_ChangePrinter
589 static BOOL
PRINTDLG_ChangePrinter(HWND hDlg
, char *name
,
590 PRINT_PTRA
*PrintStructures
)
592 LPPRINTDLGA lppd
= PrintStructures
->dlg
.lpPrintDlg
;
593 LPDEVMODEA lpdm
= NULL
;
598 if(PrintStructures
->lpPrinterInfo
)
599 HeapFree(GetProcessHeap(),0, PrintStructures
->lpPrinterInfo
);
600 if(PrintStructures
->lpDriverInfo
)
601 HeapFree(GetProcessHeap(),0, PrintStructures
->lpDriverInfo
);
602 if(!OpenPrinterA(name
, &hprn
, NULL
)) {
603 ERR("Can't open printer %s\n", name
);
606 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
607 PrintStructures
->lpPrinterInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
608 GetPrinterA(hprn
, 2, (LPBYTE
)PrintStructures
->lpPrinterInfo
, needed
,
610 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
611 PrintStructures
->lpDriverInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
612 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)PrintStructures
->lpDriverInfo
,
614 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures
->lpPrinterInfo
->pPrinterName
);
619 PRINTDLG_UpdatePrinterInfoTexts(hDlg
, PrintStructures
->lpPrinterInfo
);
621 if(PrintStructures
->lpDevMode
) {
622 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
623 PrintStructures
->lpDevMode
= NULL
;
626 dmSize
= DocumentPropertiesA(0, 0, name
, NULL
, NULL
, 0);
628 ERR("DocumentProperties fails on %s\n", debugstr_a(name
));
631 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(), 0, dmSize
);
632 dmSize
= DocumentPropertiesA(0, 0, name
, PrintStructures
->lpDevMode
, NULL
,
634 if(lppd
->hDevMode
&& (lpdm
= GlobalLock(lppd
->hDevMode
)) &&
635 !strcmp(lpdm
->dmDeviceName
,
636 PrintStructures
->lpDevMode
->dmDeviceName
)) {
637 /* Supplied devicemode matches current printer so try to use it */
638 DocumentPropertiesA(0, 0, name
, PrintStructures
->lpDevMode
, lpdm
,
639 DM_OUT_BUFFER
| DM_IN_BUFFER
);
642 GlobalUnlock(lppd
->hDevMode
);
644 lpdm
= PrintStructures
->lpDevMode
; /* use this as a shortcut */
646 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
647 /* Print range (All/Range/Selection) */
648 SetDlgItemInt(hDlg
, edt1
, lppd
->nFromPage
, FALSE
);
649 SetDlgItemInt(hDlg
, edt2
, lppd
->nToPage
, FALSE
);
650 CheckRadioButton(hDlg
, rad1
, rad3
, rad1
); /* default */
651 if (lppd
->Flags
& PD_NOSELECTION
)
652 EnableWindow(GetDlgItem(hDlg
, rad2
), FALSE
);
654 if (lppd
->Flags
& PD_SELECTION
)
655 CheckRadioButton(hDlg
, rad1
, rad3
, rad2
);
656 if (lppd
->Flags
& PD_NOPAGENUMS
) {
657 EnableWindow(GetDlgItem(hDlg
, rad3
), FALSE
);
658 EnableWindow(GetDlgItem(hDlg
, stc2
),FALSE
);
659 EnableWindow(GetDlgItem(hDlg
, edt1
), FALSE
);
660 EnableWindow(GetDlgItem(hDlg
, stc3
),FALSE
);
661 EnableWindow(GetDlgItem(hDlg
, edt2
), FALSE
);
663 if (lppd
->Flags
& PD_PAGENUMS
)
664 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
666 /* "All xxx pages"... */
668 char resourcestr
[64];
670 LoadStringA(COMDLG32_hInstance
, PD32_PRINT_ALL_X_PAGES
,
672 sprintf(result
,resourcestr
,lppd
->nMaxPage
- lppd
->nMinPage
+ 1);
673 SendDlgItemMessageA(hDlg
, rad1
, WM_SETTEXT
, 0, (LPARAM
) result
);
678 * FIXME: The ico3 is not displayed for some reason. I don't know why.
680 if (lppd
->Flags
& PD_COLLATE
) {
681 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
682 (LPARAM
)PrintStructures
->hCollateIcon
);
683 CheckDlgButton(hDlg
, chx2
, 1);
685 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
686 (LPARAM
)PrintStructures
->hNoCollateIcon
);
687 CheckDlgButton(hDlg
, chx2
, 0);
690 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
691 /* if printer doesn't support it: no Collate */
692 if (!(lpdm
->dmFields
& DM_COLLATE
)) {
693 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
694 EnableWindow(GetDlgItem(hDlg
, ico3
), FALSE
);
701 if (lppd
->hDevMode
== 0)
702 copies
= lppd
->nCopies
;
704 copies
= lpdm
->dmCopies
;
705 if(copies
== 0) copies
= 1;
706 else if(copies
< 0) copies
= MAX_COPIES
;
707 SetDlgItemInt(hDlg
, edt3
, copies
, FALSE
);
710 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
711 /* if printer doesn't support it: no nCopies */
712 if (!(lpdm
->dmFields
& DM_COPIES
)) {
713 EnableWindow(GetDlgItem(hDlg
, edt3
), FALSE
);
714 EnableWindow(GetDlgItem(hDlg
, stc5
), FALSE
);
719 CheckDlgButton(hDlg
, chx1
, (lppd
->Flags
& PD_PRINTTOFILE
) ? 1 : 0);
720 if (lppd
->Flags
& PD_DISABLEPRINTTOFILE
)
721 EnableWindow(GetDlgItem(hDlg
, chx1
), FALSE
);
722 if (lppd
->Flags
& PD_HIDEPRINTTOFILE
)
723 ShowWindow(GetDlgItem(hDlg
, chx1
), SW_HIDE
);
725 } else { /* PD_PRINTSETUP */
726 BOOL bPortrait
= (lpdm
->u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
);
728 PRINTDLG_SetUpPaperComboBox(hDlg
, cmb2
,
729 PrintStructures
->lpPrinterInfo
->pPrinterName
,
730 PrintStructures
->lpPrinterInfo
->pPortName
,
732 PRINTDLG_SetUpPaperComboBox(hDlg
, cmb3
,
733 PrintStructures
->lpPrinterInfo
->pPrinterName
,
734 PrintStructures
->lpPrinterInfo
->pPortName
,
736 CheckRadioButton(hDlg
, rad1
, rad2
, bPortrait
? rad1
: rad2
);
737 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
738 (LPARAM
)(bPortrait
? PrintStructures
->hPortraitIcon
:
739 PrintStructures
->hLandscapeIcon
));
744 if ((lppd
->Flags
& PD_SHOWHELP
)==0) {
745 /* hide if PD_SHOWHELP not specified */
746 ShowWindow(GetDlgItem(hDlg
, pshHelp
), SW_HIDE
);
751 /***********************************************************************
752 * PRINTDLG_WMInitDialog [internal]
754 static LRESULT
PRINTDLG_WMInitDialog(HWND hDlg
, WPARAM wParam
,
755 PRINT_PTRA
* PrintStructures
)
757 LPPRINTDLGA lppd
= PrintStructures
->dlg
.lpPrintDlg
;
761 UINT comboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
763 /* load Collate ICONs */
764 /* We load these with LoadImage becasue they are not a standard
765 size and we don't want them rescaled */
766 PrintStructures
->hCollateIcon
=
767 LoadImageA(COMDLG32_hInstance
, "PD32_COLLATE", IMAGE_ICON
, 0, 0, 0);
768 PrintStructures
->hNoCollateIcon
=
769 LoadImageA(COMDLG32_hInstance
, "PD32_NOCOLLATE", IMAGE_ICON
, 0, 0, 0);
771 /* These can be done with LoadIcon */
772 PrintStructures
->hPortraitIcon
=
773 LoadIconA(COMDLG32_hInstance
, "PD32_PORTRAIT");
774 PrintStructures
->hLandscapeIcon
=
775 LoadIconA(COMDLG32_hInstance
, "PD32_LANDSCAPE");
777 if(PrintStructures
->hCollateIcon
== 0 ||
778 PrintStructures
->hNoCollateIcon
== 0 ||
779 PrintStructures
->hPortraitIcon
== 0 ||
780 PrintStructures
->hLandscapeIcon
== 0) {
781 ERR("no icon in resourcefile\n");
782 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
783 EndDialog(hDlg
, FALSE
);
787 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
788 * must be registered and the Help button must be shown.
790 if (lppd
->Flags
& PD_SHOWHELP
) {
791 if((PrintStructures
->HelpMessageID
=
792 RegisterWindowMessageA(HELPMSGSTRINGA
)) == 0) {
793 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL
);
797 PrintStructures
->HelpMessageID
= 0;
799 if(!(lppd
->Flags
&PD_PRINTSETUP
)) {
800 PrintStructures
->hwndUpDown
=
801 CreateUpDownControl(WS_CHILD
| WS_VISIBLE
| WS_BORDER
|
802 UDS_NOTHOUSANDS
| UDS_ARROWKEYS
|
803 UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, 0, 0, 0, 0,
804 hDlg
, UPDOWN_ID
, COMDLG32_hInstance
,
805 GetDlgItem(hDlg
, edt3
), MAX_COPIES
, 1, 1);
808 /* FIXME: I allow more freedom than either Win95 or WinNT,
809 * which do not agree to what errors should be thrown or not
810 * in case nToPage or nFromPage is out-of-range.
812 if (lppd
->nMaxPage
< lppd
->nMinPage
)
813 lppd
->nMaxPage
= lppd
->nMinPage
;
814 if (lppd
->nMinPage
== lppd
->nMaxPage
)
815 lppd
->Flags
|= PD_NOPAGENUMS
;
816 if (lppd
->nToPage
< lppd
->nMinPage
)
817 lppd
->nToPage
= lppd
->nMinPage
;
818 if (lppd
->nToPage
> lppd
->nMaxPage
)
819 lppd
->nToPage
= lppd
->nMaxPage
;
820 if (lppd
->nFromPage
< lppd
->nMinPage
)
821 lppd
->nFromPage
= lppd
->nMinPage
;
822 if (lppd
->nFromPage
> lppd
->nMaxPage
)
823 lppd
->nFromPage
= lppd
->nMaxPage
;
825 /* if we have the combo box, fill it */
826 if (GetDlgItem(hDlg
,comboID
)) {
829 pdn
= GlobalLock(lppd
->hDevNames
);
830 pdm
= GlobalLock(lppd
->hDevMode
);
832 name
= (char*)pdn
+ pdn
->wDeviceOffset
;
834 name
= pdm
->dmDeviceName
;
835 PRINTDLG_SetUpPrinterListCombo(hDlg
, comboID
, name
);
836 if(pdm
) GlobalUnlock(lppd
->hDevMode
);
837 if(pdn
) GlobalUnlock(lppd
->hDevNames
);
839 /* Now find selected printer and update rest of dlg */
840 name
= HeapAlloc(GetProcessHeap(),0,256);
841 if (GetDlgItemTextA(hDlg
, comboID
, name
, 255))
842 PRINTDLG_ChangePrinter(hDlg
, name
, PrintStructures
);
843 HeapFree(GetProcessHeap(),0,name
);
845 /* else use default printer */
847 BOOL ret
= PRINTDLG_GetDefaultPrinterName(name
, sizeof(name
));
850 PRINTDLG_ChangePrinter(hDlg
, name
, PrintStructures
);
852 FIXME("No default printer found, expect problems!\n");
857 /***********************************************************************
858 * PRINTDLG_WMInitDialog [internal]
860 static LRESULT
PRINTDLG_WMInitDialog16(HWND hDlg
, WPARAM wParam
,
861 PRINT_PTRA
* PrintStructures
)
863 LPPRINTDLG16 lppd
= PrintStructures
->dlg
.lpPrintDlg16
;
867 UINT comboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
869 /* load Collate ICONs */
870 PrintStructures
->hCollateIcon
=
871 LoadIconA(COMDLG32_hInstance
, "PD32_COLLATE");
872 PrintStructures
->hNoCollateIcon
=
873 LoadIconA(COMDLG32_hInstance
, "PD32_NOCOLLATE");
874 if(PrintStructures
->hCollateIcon
== 0 ||
875 PrintStructures
->hNoCollateIcon
== 0) {
876 ERR("no icon in resourcefile\n");
877 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
878 EndDialog(hDlg
, FALSE
);
881 /* load Paper Orientation ICON */
882 /* FIXME: not implemented yet */
885 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
886 * must be registered and the Help button must be shown.
888 if (lppd
->Flags
& PD_SHOWHELP
) {
889 if((PrintStructures
->HelpMessageID
=
890 RegisterWindowMessageA(HELPMSGSTRINGA
)) == 0) {
891 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL
);
895 PrintStructures
->HelpMessageID
= 0;
897 if (!(lppd
->Flags
& PD_PRINTSETUP
)) {
898 /* We have a print quality combo box. What shall we do? */
899 if (GetDlgItem(hDlg
,cmb1
)) {
902 FIXME("Print quality only displaying currently.\n");
904 pdm
= GlobalLock16(lppd
->hDevMode
);
906 switch (pdm
->dmPrintQuality
) {
907 case DMRES_HIGH
: strcpy(buf
,"High");break;
908 case DMRES_MEDIUM
: strcpy(buf
,"Medium");break;
909 case DMRES_LOW
: strcpy(buf
,"Low");break;
910 case DMRES_DRAFT
: strcpy(buf
,"Draft");break;
911 case 0 : strcpy(buf
,"Default");break;
912 default : sprintf(buf
,"%ddpi",pdm
->dmPrintQuality
);break;
914 GlobalUnlock16(lppd
->hDevMode
);
916 strcpy(buf
,"Default");
917 SendDlgItemMessageA(hDlg
,cmb1
,CB_ADDSTRING
,0,(LPARAM
)buf
);
918 SendDlgItemMessageA(hDlg
,cmb1
,CB_SETCURSEL
,0,0);
919 EnableWindow(GetDlgItem(hDlg
,cmb1
),FALSE
);
923 /* FIXME: I allow more freedom than either Win95 or WinNT,
924 * which do not agree to what errors should be thrown or not
925 * in case nToPage or nFromPage is out-of-range.
927 if (lppd
->nMaxPage
< lppd
->nMinPage
)
928 lppd
->nMaxPage
= lppd
->nMinPage
;
929 if (lppd
->nMinPage
== lppd
->nMaxPage
)
930 lppd
->Flags
|= PD_NOPAGENUMS
;
931 if (lppd
->nToPage
< lppd
->nMinPage
)
932 lppd
->nToPage
= lppd
->nMinPage
;
933 if (lppd
->nToPage
> lppd
->nMaxPage
)
934 lppd
->nToPage
= lppd
->nMaxPage
;
935 if (lppd
->nFromPage
< lppd
->nMinPage
)
936 lppd
->nFromPage
= lppd
->nMinPage
;
937 if (lppd
->nFromPage
> lppd
->nMaxPage
)
938 lppd
->nFromPage
= lppd
->nMaxPage
;
940 /* If the printer combo box is in the dialog, fill it */
941 if (GetDlgItem(hDlg
,comboID
)) {
944 pdn
= GlobalLock16(lppd
->hDevNames
);
945 pdm
= GlobalLock16(lppd
->hDevMode
);
947 name
= (char*)pdn
+ pdn
->wDeviceOffset
;
949 name
= pdm
->dmDeviceName
;
950 PRINTDLG_SetUpPrinterListCombo(hDlg
, comboID
, name
);
951 if(pdm
) GlobalUnlock16(lppd
->hDevMode
);
952 if(pdn
) GlobalUnlock16(lppd
->hDevNames
);
954 /* Now find selected printer and update rest of dlg */
955 name
= HeapAlloc(GetProcessHeap(),0,256);
956 if (GetDlgItemTextA(hDlg
, comboID
, name
, 255))
957 PRINTDLG_ChangePrinter(hDlg
, name
, PrintStructures
);
959 /* else just use default printer */
961 BOOL ret
= PRINTDLG_GetDefaultPrinterName(name
, sizeof(name
));
964 PRINTDLG_ChangePrinter(hDlg
, name
, PrintStructures
);
966 FIXME("No default printer found, expect problems!\n");
968 HeapFree(GetProcessHeap(),0,name
);
973 /***********************************************************************
974 * PRINTDLG_WMCommand [internal]
976 static LRESULT
PRINTDLG_WMCommand(HWND hDlg
, WPARAM wParam
,
977 LPARAM lParam
, PRINT_PTRA
* PrintStructures
)
979 LPPRINTDLGA lppd
= PrintStructures
->dlg
.lpPrintDlg
;
980 UINT PrinterComboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
981 LPDEVMODEA lpdm
= PrintStructures
->lpDevMode
;
983 switch (LOWORD(wParam
)) {
985 TRACE(" OK button was hit\n");
986 if (PRINTDLG_UpdatePrintDlg(hDlg
, PrintStructures
)!=TRUE
) {
987 FIXME("Update printdlg was not successful!\n");
990 EndDialog(hDlg
, TRUE
);
994 TRACE(" CANCEL button was hit\n");
995 EndDialog(hDlg
, FALSE
);
999 TRACE(" HELP button was hit\n");
1000 SendMessageA(lppd
->hwndOwner
, PrintStructures
->HelpMessageID
,
1001 (WPARAM
) hDlg
, (LPARAM
) lppd
);
1004 case chx2
: /* collate pages checkbox */
1005 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
1006 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1007 (LPARAM
)PrintStructures
->hCollateIcon
);
1009 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1010 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1012 case edt1
: /* from page nr editbox */
1013 case edt2
: /* to page nr editbox */
1014 if (HIWORD(wParam
)==EN_CHANGE
) {
1017 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
1018 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
1019 if (nFromPage
!= lppd
->nFromPage
|| nToPage
!= lppd
->nToPage
)
1020 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1025 if(HIWORD(wParam
) == EN_CHANGE
) {
1026 INT copies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
1028 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1030 EnableWindow(GetDlgItem(hDlg
, chx2
), TRUE
);
1034 case psh1
: /* Print Setup */
1038 if (!PrintStructures
->dlg
.lpPrintDlg16
) {
1039 FIXME("The 32bit print dialog does not have this button!?\n");
1043 memcpy(&pdlg
,PrintStructures
->dlg
.lpPrintDlg16
,sizeof(pdlg
));
1044 pdlg
.Flags
|= PD_PRINTSETUP
;
1045 pdlg
.hwndOwner
= hDlg
;
1046 if (!PrintDlg16(&pdlg
))
1050 case psh2
: /* Properties button */
1053 char PrinterName
[256];
1055 GetDlgItemTextA(hDlg
, PrinterComboID
, PrinterName
, 255);
1056 if (!OpenPrinterA(PrinterName
, &hPrinter
, NULL
)) {
1057 FIXME(" Call to OpenPrinter did not succeed!\n");
1060 DocumentPropertiesA(hDlg
, hPrinter
, PrinterName
,
1061 PrintStructures
->lpDevMode
,
1062 PrintStructures
->lpDevMode
,
1063 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
1064 ClosePrinter(hPrinter
);
1068 case rad1
: /* Paperorientation */
1069 if (lppd
->Flags
& PD_PRINTSETUP
)
1071 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1072 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1073 (LPARAM
)(PrintStructures
->hPortraitIcon
));
1077 case rad2
: /* Paperorientation */
1078 if (lppd
->Flags
& PD_PRINTSETUP
)
1080 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1081 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1082 (LPARAM
)(PrintStructures
->hLandscapeIcon
));
1086 case cmb1
: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1087 if (PrinterComboID
!= wParam
) {
1088 FIXME("No handling for print quality combo box yet.\n");
1092 case cmb4
: /* Printer combobox */
1093 if (HIWORD(wParam
)==CBN_SELCHANGE
) {
1094 char PrinterName
[256];
1095 GetDlgItemTextA(hDlg
, LOWORD(wParam
), PrinterName
, 255);
1096 PRINTDLG_ChangePrinter(hDlg
, PrinterName
, PrintStructures
);
1100 case cmb2
: /* Papersize */
1102 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
1104 lpdm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageA(hDlg
, cmb2
,
1110 case cmb3
: /* Bin */
1112 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
1114 lpdm
->dmDefaultSource
= SendDlgItemMessageA(hDlg
, cmb3
,
1115 CB_GETITEMDATA
, Sel
,
1120 if(lppd
->Flags
& PD_PRINTSETUP
) {
1121 switch (LOWORD(wParam
)) {
1122 case rad1
: /* orientation */
1124 if (IsDlgButtonChecked(hDlg
, rad1
) == BST_CHECKED
) {
1125 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_PORTRAIT
) {
1126 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1127 SendDlgItemMessageA(hDlg
, stc10
, STM_SETIMAGE
,
1129 (LPARAM
)PrintStructures
->hPortraitIcon
);
1130 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
,
1132 (LPARAM
)PrintStructures
->hPortraitIcon
);
1135 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_LANDSCAPE
) {
1136 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1137 SendDlgItemMessageA(hDlg
, stc10
, STM_SETIMAGE
,
1139 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1140 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
,
1142 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1151 /***********************************************************************
1152 * PrintDlgProcA [internal]
1154 BOOL WINAPI
PrintDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
1157 PRINT_PTRA
* PrintStructures
;
1160 if (uMsg
!=WM_INITDIALOG
) {
1161 PrintStructures
= (PRINT_PTRA
*) GetWindowLongA(hDlg
, DWL_USER
);
1162 if (!PrintStructures
)
1165 PrintStructures
= (PRINT_PTRA
*) lParam
;
1166 SetWindowLongA(hDlg
, DWL_USER
, lParam
);
1167 res
= PRINTDLG_WMInitDialog(hDlg
, wParam
, PrintStructures
);
1169 if(PrintStructures
->dlg
.lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
)
1170 res
= PrintStructures
->dlg
.lpPrintDlg
->lpfnPrintHook(
1171 hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->dlg
.lpPrintDlg
1176 if(PrintStructures
->dlg
.lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
) {
1177 res
= PrintStructures
->dlg
.lpPrintDlg
->lpfnPrintHook(hDlg
,uMsg
,wParam
,
1184 return PRINTDLG_WMCommand(hDlg
, wParam
, lParam
, PrintStructures
);
1187 DestroyIcon(PrintStructures
->hCollateIcon
);
1188 DestroyIcon(PrintStructures
->hNoCollateIcon
);
1189 DestroyIcon(PrintStructures
->hPortraitIcon
);
1190 DestroyIcon(PrintStructures
->hLandscapeIcon
);
1191 if(PrintStructures
->hwndUpDown
)
1192 DestroyWindow(PrintStructures
->hwndUpDown
);
1199 /************************************************************
1201 * PRINTDLG_Get16TemplateFrom32 [Internal]
1202 * Generates a 16 bits template from the Wine 32 bits resource
1205 static HGLOBAL16
PRINTDLG_Get16TemplateFrom32(char *PrintResourceName
)
1207 HANDLE hResInfo
, hDlgTmpl32
;
1210 HGLOBAL16 hGlobal16
;
1213 if (!(hResInfo
= FindResourceA(COMMDLG_hInstance32
,
1214 PrintResourceName
, RT_DIALOGA
)))
1216 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
1219 if (!(hDlgTmpl32
= LoadResource(COMMDLG_hInstance32
, hResInfo
)) ||
1220 !(template32
= LockResource( hDlgTmpl32
)))
1222 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1225 size
= SizeofResource(COMMDLG_hInstance32
, hResInfo
);
1226 hGlobal16
= GlobalAlloc16(0, size
);
1229 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE
);
1230 ERR("alloc failure for %ld bytes\n", size
);
1233 template = GlobalLock16(hGlobal16
);
1236 COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE
);
1237 ERR("global lock failure for %x handle\n", hGlobal16
);
1238 GlobalFree16(hGlobal16
);
1241 ConvertDialog32To16((LPVOID
)template32
, size
, (LPVOID
)template);
1242 GlobalUnlock16(hGlobal16
);
1246 /************************************************************
1248 * PRINTDLG_GetDlgTemplate
1251 static HGLOBAL
PRINTDLG_GetDlgTemplate(PRINTDLGA
*lppd
)
1253 HGLOBAL hDlgTmpl
, hResInfo
;
1255 if (lppd
->Flags
& PD_PRINTSETUP
) {
1256 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
1257 hDlgTmpl
= lppd
->hSetupTemplate
;
1258 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
1259 hResInfo
= FindResourceA(lppd
->hInstance
,
1260 lppd
->lpSetupTemplateName
, RT_DIALOGA
);
1261 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1263 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32_SETUP",
1265 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1268 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
1269 hDlgTmpl
= lppd
->hPrintTemplate
;
1270 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
1271 hResInfo
= FindResourceA(lppd
->hInstance
,
1272 lppd
->lpPrintTemplateName
,
1274 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1276 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32",
1278 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1285 /************************************************************
1287 * PRINTDLG_GetDlgTemplate
1290 static HGLOBAL16
PRINTDLG_GetDlgTemplate16(PRINTDLG16
*lppd
)
1292 HGLOBAL16 hDlgTmpl
, hResInfo
;
1294 if (lppd
->Flags
& PD_PRINTSETUP
) {
1295 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
1296 hDlgTmpl
= lppd
->hSetupTemplate
;
1297 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
1298 hResInfo
= FindResource16(lppd
->hInstance
,
1299 MapSL(lppd
->lpSetupTemplateName
), RT_DIALOGA
);
1300 hDlgTmpl
= LoadResource16(lppd
->hInstance
, hResInfo
);
1302 hDlgTmpl
= PRINTDLG_Get16TemplateFrom32("PRINT32_SETUP");
1305 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
1306 hDlgTmpl
= lppd
->hPrintTemplate
;
1307 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
1308 hResInfo
= FindResource16(lppd
->hInstance
,
1309 MapSL(lppd
->lpPrintTemplateName
),
1311 hDlgTmpl
= LoadResource16(lppd
->hInstance
, hResInfo
);
1313 hDlgTmpl
= PRINTDLG_Get16TemplateFrom32("PRINT32");
1319 /***********************************************************************
1324 static BOOL
PRINTDLG_CreateDC(LPPRINTDLGA lppd
)
1326 DEVNAMES
*pdn
= GlobalLock(lppd
->hDevNames
);
1327 DEVMODEA
*pdm
= GlobalLock(lppd
->hDevMode
);
1329 if(lppd
->Flags
& PD_RETURNDC
) {
1330 lppd
->hDC
= CreateDCA((char*)pdn
+ pdn
->wDriverOffset
,
1331 (char*)pdn
+ pdn
->wDeviceOffset
,
1332 (char*)pdn
+ pdn
->wOutputOffset
,
1334 } else if(lppd
->Flags
& PD_RETURNIC
) {
1335 lppd
->hDC
= CreateICA((char*)pdn
+ pdn
->wDriverOffset
,
1336 (char*)pdn
+ pdn
->wDeviceOffset
,
1337 (char*)pdn
+ pdn
->wOutputOffset
,
1340 GlobalUnlock(lppd
->hDevNames
);
1341 GlobalUnlock(lppd
->hDevMode
);
1342 return lppd
->hDC
? TRUE
: FALSE
;
1345 static BOOL
PRINTDLG_CreateDC16(LPPRINTDLG16 lppd
)
1347 DEVNAMES
*pdn
= GlobalLock16(lppd
->hDevNames
);
1348 DEVMODEA
*pdm
= GlobalLock16(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 GlobalUnlock16(lppd
->hDevNames
);
1362 GlobalUnlock16(lppd
->hDevMode
);
1363 return lppd
->hDC
? TRUE
: FALSE
;
1366 /***********************************************************************
1367 * PrintDlgA (COMDLG32.@)
1369 * Displays the the PRINT dialog box, which enables the user to specify
1370 * specific properties of the print job.
1373 * nonzero if the user pressed the OK button
1374 * zero if the user cancelled the window or an error occurred
1378 * * The Collate Icons do not display, even though they are in the code.
1379 * * The Properties Button(s) should call DocumentPropertiesA().
1381 * * The Paper Orientation Icons are not implemented yet.
1382 * * The Properties Button(s) should call DocumentPropertiesA().
1383 * * Settings are not yet taken from a provided DevMode or
1384 * default printer settings.
1386 BOOL WINAPI
PrintDlgA(
1387 LPPRINTDLGA lppd
/* [in/out] ptr to PRINTDLG32 struct */
1392 HINSTANCE hInst
= GetWindowLongA( lppd
->hwndOwner
, GWL_HINSTANCE
);
1394 if(TRACE_ON(commdlg
)) {
1395 char flagstr
[1000] = "";
1396 struct pd_flags
*pflag
= pd_flags
;
1397 for( ; pflag
->name
; pflag
++) {
1398 if(lppd
->Flags
& pflag
->flag
)
1399 strcat(flagstr
, pflag
->name
);
1401 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
1402 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %08x\n"
1403 "flags %08lx (%s)\n",
1404 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
1405 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
1406 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
1409 if(lppd
->lStructSize
!= sizeof(PRINTDLGA
)) {
1410 WARN("structure size failure !!!\n");
1411 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
1415 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
1416 PRINTER_INFO_2A
*pbuf
;
1417 DRIVER_INFO_3A
*dbuf
;
1421 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
1422 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
1423 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
1426 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
1427 WARN("Can't find default printer\n");
1428 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
1432 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
1433 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
1434 GetPrinterA(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
1436 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
1437 dbuf
= HeapAlloc(GetProcessHeap(),0,needed
);
1438 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
1439 ERR("GetPrinterDriverA failed, le %ld, fix your config for printer %s!\n",GetLastError(),pbuf
->pPrinterName
);
1440 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
1445 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
1449 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
1450 pbuf
->pDevMode
->dmDriverExtra
);
1451 ptr
= GlobalLock(lppd
->hDevMode
);
1452 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
1453 pbuf
->pDevMode
->dmDriverExtra
);
1454 GlobalUnlock(lppd
->hDevMode
);
1455 HeapFree(GetProcessHeap(), 0, pbuf
);
1456 HeapFree(GetProcessHeap(), 0, dbuf
);
1460 PRINT_PTRA
*PrintStructures
;
1462 /* load Dialog resources,
1463 * depending on Flags indicates Print32 or Print32_setup dialog
1465 hDlgTmpl
= PRINTDLG_GetDlgTemplate(lppd
);
1467 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1470 ptr
= LockResource( hDlgTmpl
);
1472 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1476 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1477 sizeof(PRINT_PTRA
));
1478 PrintStructures
->dlg
.lpPrintDlg
= lppd
;
1480 /* and create & process the dialog .
1481 * -1 is failure, 0 is broken hwnd, everything else is ok.
1483 bRet
= (0<DialogBoxIndirectParamA(hInst
, ptr
, lppd
->hwndOwner
,
1485 (LPARAM
)PrintStructures
));
1488 DEVMODEA
*lpdm
= PrintStructures
->lpDevMode
, *lpdmReturn
;
1489 PRINTER_INFO_2A
*pi
= PrintStructures
->lpPrinterInfo
;
1490 DRIVER_INFO_3A
*di
= PrintStructures
->lpDriverInfo
;
1492 if (lppd
->hDevMode
== 0) {
1493 TRACE(" No hDevMode yet... Need to create my own\n");
1494 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
,
1495 lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
1498 if((locks
= (GlobalFlags(lppd
->hDevMode
) & GMEM_LOCKCOUNT
))) {
1499 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks
);
1501 GlobalUnlock(lppd
->hDevMode
);
1502 TRACE("Now got %d locks\n", locks
);
1505 lppd
->hDevMode
= GlobalReAlloc(lppd
->hDevMode
,
1506 lpdm
->dmSize
+ lpdm
->dmDriverExtra
,
1509 lpdmReturn
= GlobalLock(lppd
->hDevMode
);
1510 memcpy(lpdmReturn
, lpdm
, lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
1512 if (lppd
->hDevNames
!= 0) {
1514 if((locks
= (GlobalFlags(lppd
->hDevNames
) & GMEM_LOCKCOUNT
))) {
1515 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks
);
1517 GlobalUnlock(lppd
->hDevNames
);
1520 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
1525 GlobalUnlock(lppd
->hDevMode
);
1527 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
1528 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpPrinterInfo
);
1529 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDriverInfo
);
1530 HeapFree(GetProcessHeap(), 0, PrintStructures
);
1532 if(bRet
&& (lppd
->Flags
& PD_RETURNDC
|| lppd
->Flags
& PD_RETURNIC
))
1533 bRet
= PRINTDLG_CreateDC(lppd
);
1535 TRACE("exit! (%d)\n", bRet
);
1539 /***********************************************************************
1540 * PrintDlg (COMMDLG.20)
1542 * Displays the the PRINT dialog box, which enables the user to specify
1543 * specific properties of the print job.
1546 * nonzero if the user pressed the OK button
1547 * zero if the user cancelled the window or an error occurred
1550 * * calls up to the 32-bit versions of the Dialogs, which look different
1551 * * Customizing is *not* implemented.
1554 BOOL16 WINAPI
PrintDlg16(
1555 LPPRINTDLG16 lppd
/* [in/out] ptr to PRINTDLG struct */
1559 HINSTANCE hInst
= GetWindowLongA( lppd
->hwndOwner
, GWL_HINSTANCE
);
1561 if(TRACE_ON(commdlg
)) {
1562 char flagstr
[1000] = "";
1563 struct pd_flags
*pflag
= pd_flags
;
1564 for( ; pflag
->name
; pflag
++) {
1565 if(lppd
->Flags
& pflag
->flag
)
1566 strcat(flagstr
, pflag
->name
);
1568 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
1569 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %08x\n"
1570 "flags %08lx (%s)\n",
1571 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
1572 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
1573 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
1576 if(lppd
->lStructSize
!= sizeof(PRINTDLG16
)) {
1577 ERR("structure size (%ld/%d)\n",lppd
->lStructSize
,sizeof(PRINTDLG16
));
1578 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
1582 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
1583 PRINTER_INFO_2A
*pbuf
;
1584 DRIVER_INFO_3A
*dbuf
;
1588 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
1589 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
1590 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
1593 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
1594 WARN("Can't find default printer\n");
1595 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
1599 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
1600 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
1601 GetPrinterA(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
1602 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
1603 dbuf
= HeapAlloc(GetProcessHeap(),0,needed
);
1604 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
1605 ERR("GetPrinterDriverA failed for %s, le %ld, fix your config!\n",
1606 pbuf
->pPrinterName
,GetLastError());
1607 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
1611 PRINTDLG_CreateDevNames16(&(lppd
->hDevNames
),
1615 lppd
->hDevMode
= GlobalAlloc16(GMEM_MOVEABLE
,pbuf
->pDevMode
->dmSize
+
1616 pbuf
->pDevMode
->dmDriverExtra
);
1617 ptr
= GlobalLock16(lppd
->hDevMode
);
1618 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
1619 pbuf
->pDevMode
->dmDriverExtra
);
1620 GlobalUnlock16(lppd
->hDevMode
);
1621 HeapFree(GetProcessHeap(), 0, pbuf
);
1622 HeapFree(GetProcessHeap(), 0, dbuf
);
1626 PRINT_PTRA
*PrintStructures
;
1628 /* load Dialog resources,
1629 * depending on Flags indicates Print32 or Print32_setup dialog
1631 hDlgTmpl
= PRINTDLG_GetDlgTemplate16(lppd
);
1633 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1636 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1637 sizeof(PRINT_PTRA
));
1638 PrintStructures
->dlg
.lpPrintDlg16
= lppd
;
1639 PrintStructures
->dlg
.lpPrintDlg
= (LPPRINTDLGA
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(PRINTDLGA
));
1640 #define CVAL(x) PrintStructures->dlg.lpPrintDlg->x = lppd->x;
1641 #define MVAL(x) PrintStructures->dlg.lpPrintDlg->x = MapSL(lppd->x);
1642 CVAL(Flags
);CVAL(hwndOwner
);CVAL(hDC
);
1643 CVAL(nFromPage
);CVAL(nToPage
);CVAL(nMinPage
);CVAL(nMaxPage
);
1644 CVAL(nCopies
);CVAL(hInstance
);CVAL(lCustData
);
1645 MVAL(lpPrintTemplateName
);MVAL(lpSetupTemplateName
);
1646 /* Don't copy rest, it is 16 bit specific */
1650 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(),0,sizeof(DEVMODEA
));
1652 /* and create & process the dialog .
1653 * -1 is failure, 0 is broken hwnd, everything else is ok.
1655 bRet
= (0<DialogBoxIndirectParam16(
1656 hInst
, hDlgTmpl
, lppd
->hwndOwner
,
1657 (DLGPROC16
)GetProcAddress16(GetModuleHandle16("COMMDLG"),(LPCSTR
)21),
1658 (LPARAM
)PrintStructures
1661 if (!PrintStructures
->lpPrinterInfo
) bRet
= FALSE
;
1663 DEVMODEA
*lpdm
= PrintStructures
->lpDevMode
, *lpdmReturn
;
1664 PRINTER_INFO_2A
*pi
= PrintStructures
->lpPrinterInfo
;
1665 DRIVER_INFO_3A
*di
= PrintStructures
->lpDriverInfo
;
1667 if (lppd
->hDevMode
== 0) {
1668 TRACE(" No hDevMode yet... Need to create my own\n");
1669 lppd
->hDevMode
= GlobalAlloc16(GMEM_MOVEABLE
,
1670 lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
1673 if((locks
= (GlobalFlags16(lppd
->hDevMode
)&GMEM_LOCKCOUNT
))) {
1674 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks
);
1676 GlobalUnlock16(lppd
->hDevMode
);
1677 TRACE("Now got %d locks\n", locks
);
1680 lppd
->hDevMode
= GlobalReAlloc16(lppd
->hDevMode
,
1681 lpdm
->dmSize
+ lpdm
->dmDriverExtra
,
1684 lpdmReturn
= GlobalLock16(lppd
->hDevMode
);
1685 memcpy(lpdmReturn
, lpdm
, lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
1687 if (lppd
->hDevNames
!= 0) {
1689 if((locks
= (GlobalFlags16(lppd
->hDevNames
)&GMEM_LOCKCOUNT
))) {
1690 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks
);
1692 GlobalUnlock16(lppd
->hDevNames
);
1695 PRINTDLG_CreateDevNames16(&(lppd
->hDevNames
),
1700 GlobalUnlock16(lppd
->hDevMode
);
1702 if (!(lppd
->Flags
& (PD_ENABLESETUPTEMPLATEHANDLE
| PD_ENABLESETUPTEMPLATE
)))
1703 GlobalFree16(hDlgTmpl
); /* created from the 32 bits resource */
1704 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
1705 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpPrinterInfo
);
1706 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDriverInfo
);
1707 HeapFree(GetProcessHeap(), 0, PrintStructures
);
1709 if(bRet
&& (lppd
->Flags
& PD_RETURNDC
|| lppd
->Flags
& PD_RETURNIC
))
1710 bRet
= PRINTDLG_CreateDC16(lppd
);
1712 TRACE("exit! (%d)\n", bRet
);
1718 /***********************************************************************
1719 * PrintDlgW (COMDLG32.@)
1721 BOOL WINAPI
PrintDlgW( LPPRINTDLGW printdlg
)
1723 FIXME("A really empty stub\n" );
1727 /***********************************************************************
1733 * cmb3 - source (tray?)
1734 * edt4 - border left
1736 * edt6 - border right
1737 * edt7 - border bottom
1738 * psh3 - "Printer..."
1742 LPPAGESETUPDLGA dlga
;
1747 static HGLOBAL
PRINTDLG_GetPGSTemplate(PAGESETUPDLGA
*lppd
)
1749 HGLOBAL hDlgTmpl
, hResInfo
;
1751 if(lppd
->Flags
& PSD_ENABLEPAGESETUPTEMPLATEHANDLE
) {
1752 hDlgTmpl
= lppd
->hPageSetupTemplate
;
1753 } else if(lppd
->Flags
& PSD_ENABLEPAGESETUPTEMPLATE
) {
1754 hResInfo
= FindResourceA(lppd
->hInstance
,
1755 lppd
->lpPageSetupTemplateName
, RT_DIALOGA
);
1756 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1758 hResInfo
= FindResourceA(COMDLG32_hInstance
,(LPCSTR
)PAGESETUPDLGORD
,RT_DIALOGA
);
1759 hDlgTmpl
= LoadResource(COMDLG32_hInstance
,hResInfo
);
1765 _c_10mm2size(PAGESETUPDLGA
*dlga
,DWORD size
) {
1766 if (dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
)
1767 return 10*size
*10/25.4;
1768 /* If we don't have a flag, we can choose one. Use millimeters
1769 * to avoid confusing me
1771 dlga
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
1772 FIXME("returning %ld/100 mm \n",size
);
1778 _c_inch2size(PAGESETUPDLGA
*dlga
,DWORD size
) {
1779 if (dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
)
1781 if (dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
)
1782 return (size
*254)/10;
1783 /* if we don't have a flag, we can choose one. Use millimeters
1784 * to avoid confusing me
1786 dlga
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
1787 return (size
*254)/10;
1791 _c_size2str(PageSetupData
*pda
,DWORD size
,LPSTR strout
) {
1792 strcpy(strout
,"<undef>");
1793 if (pda
->dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
) {
1794 sprintf(strout
,"%.2fmm",(size
*1.0)/100.0);
1797 if (pda
->dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
) {
1798 sprintf(strout
,"%.2fin",(size
*1.0)/1000.0);
1801 pda
->dlga
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
1802 sprintf(strout
,"%.2fmm",(size
*1.0)/100.0);
1807 _c_str2size(PageSetupData
*pda
,LPCSTR strin
) {
1812 if (!sscanf(strin
,"%f%s",&val
,rest
))
1815 if (!strcmp(rest
,"in") || !strcmp(rest
,"inch")) {
1816 if (pda
->dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
)
1819 return val
*25.4*100;
1821 if (!strcmp(rest
,"cm")) { rest
[0]='m'; val
= val
*10.0; }
1822 if (!strcmp(rest
,"m")) { strcpy(rest
,"mm"); val
= val
*1000.0; }
1824 if (!strcmp(rest
,"mm")) {
1825 if (pda
->dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
)
1828 return 1000.0*val
/25.4;
1830 if (rest
[0]=='\0') {
1831 /* use application supplied default */
1832 if (pda
->dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
) {
1836 if (pda
->dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
) {
1841 ERR("Did not find a conversion for type '%s'!\n",rest
);
1847 * This is called on finish and will update the output fields of the
1851 PRINTDLG_PS_UpdateDlgStruct(HWND hDlg
, PageSetupData
*pda
) {
1854 LPSTR devname
,portname
;
1858 dn
= GlobalLock(pda
->pdlg
.hDevNames
);
1859 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
1860 devname
= ((char*)dn
)+dn
->wDeviceOffset
;
1861 portname
= ((char*)dn
)+dn
->wOutputOffset
;
1862 PRINTDLG_SetUpPaperComboBox(hDlg
,cmb2
,devname
,portname
,dm
);
1863 PRINTDLG_SetUpPaperComboBox(hDlg
,cmb3
,devname
,portname
,dm
);
1865 if (GetDlgItemTextA(hDlg
,cmb2
,papername
,sizeof(papername
))>0) {
1866 PRINTDLG_PaperSize(&(pda
->pdlg
),papername
,&(pda
->dlga
->ptPaperSize
));
1867 pda
->dlga
->ptPaperSize
.x
= _c_10mm2size(pda
->dlga
,pda
->dlga
->ptPaperSize
.x
);
1868 pda
->dlga
->ptPaperSize
.y
= _c_10mm2size(pda
->dlga
,pda
->dlga
->ptPaperSize
.y
);
1870 FIXME("could not get dialog text for papersize cmbbox?\n");
1871 #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); }
1872 GETVAL(edt4
,pda
->dlga
->rtMargin
.left
);
1873 GETVAL(edt5
,pda
->dlga
->rtMargin
.top
);
1874 GETVAL(edt6
,pda
->dlga
->rtMargin
.right
);
1875 GETVAL(edt7
,pda
->dlga
->rtMargin
.bottom
);
1878 /* If we are in landscape, swap x and y of page size */
1879 if (IsDlgButtonChecked(hDlg
, rad2
)) {
1881 tmp
= pda
->dlga
->ptPaperSize
.x
;
1882 pda
->dlga
->ptPaperSize
.x
= pda
->dlga
->ptPaperSize
.y
;
1883 pda
->dlga
->ptPaperSize
.y
= tmp
;
1885 GlobalUnlock(pda
->pdlg
.hDevNames
);
1886 GlobalUnlock(pda
->pdlg
.hDevMode
);
1891 * This is called after returning from PrintDlg().
1894 PRINTDLG_PS_ChangePrinter(HWND hDlg
, PageSetupData
*pda
) {
1897 LPSTR devname
,portname
;
1899 dn
= GlobalLock(pda
->pdlg
.hDevNames
);
1900 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
1901 devname
= ((char*)dn
)+dn
->wDeviceOffset
;
1902 portname
= ((char*)dn
)+dn
->wOutputOffset
;
1903 PRINTDLG_SetUpPaperComboBox(hDlg
,cmb2
,devname
,portname
,dm
);
1904 PRINTDLG_SetUpPaperComboBox(hDlg
,cmb3
,devname
,portname
,dm
);
1905 GlobalUnlock(pda
->pdlg
.hDevNames
);
1906 GlobalUnlock(pda
->pdlg
.hDevMode
);
1911 PRINTDLG_PS_WMCommand(
1912 HWND hDlg
, WPARAM wParam
, LPARAM lParam
, PageSetupData
*pda
1914 switch (LOWORD(wParam
)) {
1916 if (!PRINTDLG_PS_UpdateDlgStruct(hDlg
, pda
))
1918 EndDialog(hDlg
, TRUE
);
1922 EndDialog(hDlg
, FALSE
);
1926 pda
->pdlg
.Flags
= 0;
1927 pda
->pdlg
.hwndOwner
= hDlg
;
1928 if (PrintDlgA(&(pda
->pdlg
)))
1929 PRINTDLG_PS_ChangePrinter(hDlg
,pda
);
1933 FIXME("loword (lparam) %d, wparam 0x%x, lparam %08lx, STUB mostly.\n",
1934 LOWORD(lParam
),wParam
,lParam
1941 PageDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1946 if (uMsg
==WM_INITDIALOG
) {
1948 pda
= (PageSetupData
*)lParam
;
1949 SetPropA(hDlg
,"__WINE_PAGESETUPDLGDATA",lParam
);
1950 if (pda
->dlga
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
1951 res
= pda
->dlga
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,lParam
);
1953 FIXME("Setup page hook failed?\n");
1957 if (pda
->dlga
->Flags
& PSD_ENABLEPAGEPAINTHOOK
) {
1958 FIXME("PagePaintHook not yet implemented!\n");
1960 if (pda
->dlga
->Flags
& PSD_DISABLEPRINTER
)
1961 EnableWindow(GetDlgItem(hDlg
, psh3
), FALSE
);
1962 if (pda
->dlga
->Flags
& PSD_DISABLEMARGINS
) {
1963 EnableWindow(GetDlgItem(hDlg
, edt4
), FALSE
);
1964 EnableWindow(GetDlgItem(hDlg
, edt5
), FALSE
);
1965 EnableWindow(GetDlgItem(hDlg
, edt6
), FALSE
);
1966 EnableWindow(GetDlgItem(hDlg
, edt7
), FALSE
);
1968 /* width larger as height -> landscape */
1969 if (pda
->dlga
->ptPaperSize
.x
> pda
->dlga
->ptPaperSize
.y
)
1970 CheckRadioButton(hDlg
, rad1
, rad2
, rad2
);
1971 else /* this is default if papersize is not set */
1972 CheckRadioButton(hDlg
, rad1
, rad2
, rad1
);
1973 if (pda
->dlga
->Flags
& PSD_DISABLEORIENTATION
) {
1974 EnableWindow(GetDlgItem(hDlg
,rad1
),FALSE
);
1975 EnableWindow(GetDlgItem(hDlg
,rad2
),FALSE
);
1977 /* We fill them out enabled or not */
1978 if (pda
->dlga
->Flags
& PSD_MARGINS
) {
1980 _c_size2str(pda
,pda
->dlga
->rtMargin
.left
,str
);
1981 SetDlgItemTextA(hDlg
,edt4
,str
);
1982 _c_size2str(pda
,pda
->dlga
->rtMargin
.top
,str
);
1983 SetDlgItemTextA(hDlg
,edt5
,str
);
1984 _c_size2str(pda
,pda
->dlga
->rtMargin
.right
,str
);
1985 SetDlgItemTextA(hDlg
,edt6
,str
);
1986 _c_size2str(pda
,pda
->dlga
->rtMargin
.bottom
,str
);
1987 SetDlgItemTextA(hDlg
,edt7
,str
);
1989 /* default is 1 inch */
1990 DWORD size
= _c_inch2size(pda
->dlga
,1000);
1992 _c_size2str(pda
,size
,str
);
1993 SetDlgItemTextA(hDlg
,edt4
,str
);
1994 SetDlgItemTextA(hDlg
,edt5
,str
);
1995 SetDlgItemTextA(hDlg
,edt6
,str
);
1996 SetDlgItemTextA(hDlg
,edt7
,str
);
1998 PRINTDLG_PS_ChangePrinter(hDlg
,pda
);
1999 if (pda
->dlga
->Flags
& PSD_DISABLEPAPER
) {
2000 EnableWindow(GetDlgItem(hDlg
,cmb2
),FALSE
);
2001 EnableWindow(GetDlgItem(hDlg
,cmb3
),FALSE
);
2005 pda
= (PageSetupData
*)GetPropA(hDlg
,"__WINE_PAGESETUPDLGDATA");
2007 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
2010 if (pda
->dlga
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
2011 res
= pda
->dlga
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,lParam
);
2012 if (res
) return res
;
2017 return PRINTDLG_PS_WMCommand(hDlg
, wParam
, lParam
, pda
);
2022 /***********************************************************************
2023 * PageSetupDlgA (COMDLG32.@)
2025 BOOL WINAPI
PageSetupDlgA(LPPAGESETUPDLGA setupdlg
) {
2032 if(TRACE_ON(commdlg
)) {
2033 char flagstr
[1000] = "";
2034 struct pd_flags
*pflag
= psd_flags
;
2035 for( ; pflag
->name
; pflag
++) {
2036 if(setupdlg
->Flags
& pflag
->flag
) {
2037 strcat(flagstr
, pflag
->name
);
2038 strcat(flagstr
, "|");
2041 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
2042 "hinst %08x, flags %08lx (%s)\n",
2043 setupdlg
, setupdlg
->hwndOwner
, setupdlg
->hDevMode
,
2044 setupdlg
->hDevNames
,
2045 setupdlg
->hInstance
, setupdlg
->Flags
, flagstr
);
2048 /* First get default printer data, we need it right after that. */
2049 memset(&pdlg
,0,sizeof(pdlg
));
2050 pdlg
.lStructSize
= sizeof(pdlg
);
2051 pdlg
.Flags
= PD_RETURNDEFAULT
;
2052 bRet
= PrintDlgA(&pdlg
);
2053 if (!bRet
) return FALSE
;
2055 /* short cut exit, just return default values */
2056 if (setupdlg
->Flags
& PSD_RETURNDEFAULT
) {
2057 setupdlg
->hDevMode
= pdlg
.hDevMode
;
2058 setupdlg
->hDevNames
= pdlg
.hDevNames
;
2059 /* FIXME: Just return "A4" for now. */
2060 PRINTDLG_PaperSize(&pdlg
,"A4",&setupdlg
->ptPaperSize
);
2061 setupdlg
->ptPaperSize
.x
=_c_10mm2size(setupdlg
,setupdlg
->ptPaperSize
.x
);
2062 setupdlg
->ptPaperSize
.y
=_c_10mm2size(setupdlg
,setupdlg
->ptPaperSize
.y
);
2065 hDlgTmpl
= PRINTDLG_GetPGSTemplate(setupdlg
);
2067 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2070 ptr
= LockResource( hDlgTmpl
);
2072 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2075 pda
= HeapAlloc(GetProcessHeap(),0,sizeof(*pda
));
2076 pda
->dlga
= setupdlg
;
2077 memcpy(&pda
->pdlg
,&pdlg
,sizeof(pdlg
));
2079 bRet
= (0<DialogBoxIndirectParamA(
2080 setupdlg
->hInstance
,
2082 setupdlg
->hwndOwner
,
2088 /***********************************************************************
2089 * PageSetupDlgW (COMDLG32.@)
2091 BOOL WINAPI
PageSetupDlgW(LPPAGESETUPDLGW setupdlg
) {
2092 FIXME("(%p), stub!\n",setupdlg
);
2096 /**********************************************************************
2101 /***********************************************************************
2102 * PrintDlgProc (COMMDLG.21)
2104 LRESULT WINAPI
PrintDlgProc16(HWND16 hDlg
, UINT16 uMsg
, WPARAM16 wParam
,
2107 PRINT_PTRA
* PrintStructures
;
2110 if (uMsg
!=WM_INITDIALOG
) {
2111 PrintStructures
= (PRINT_PTRA
*) GetWindowLongA(hDlg
, DWL_USER
);
2112 if (!PrintStructures
)
2115 PrintStructures
= (PRINT_PTRA
*) lParam
;
2116 SetWindowLongA(hDlg
, DWL_USER
, lParam
);
2117 res
= PRINTDLG_WMInitDialog16(hDlg
, wParam
, PrintStructures
);
2119 if(PrintStructures
->dlg
.lpPrintDlg16
->Flags
& PD_ENABLEPRINTHOOK
) {
2120 res
= CallWindowProc16(
2121 (WNDPROC16
)PrintStructures
->dlg
.lpPrintDlg16
->lpfnPrintHook
,
2122 hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->dlg
.lpPrintDlg16
2128 if(PrintStructures
->dlg
.lpPrintDlg16
->Flags
& PD_ENABLEPRINTHOOK
) {
2129 res
= CallWindowProc16(
2130 (WNDPROC16
)PrintStructures
->dlg
.lpPrintDlg16
->lpfnPrintHook
,
2131 hDlg
,uMsg
, wParam
, lParam
2133 if(LOWORD(res
)) return res
;
2138 /* We need to map those for the 32bit window procedure, compare
2139 * with 32Ato16 mapper in winproc.c
2141 return PRINTDLG_WMCommand(
2143 MAKEWPARAM(wParam
,HIWORD(lParam
)),
2149 DestroyIcon(PrintStructures
->hCollateIcon
);
2150 DestroyIcon(PrintStructures
->hNoCollateIcon
);
2151 /* FIXME: don't forget to delete the paper orientation icons here! */
2159 /***********************************************************************
2160 * PrintSetupDlgProc (COMMDLG.22)
2162 LRESULT WINAPI
PrintSetupDlgProc16(HWND16 hWnd
, UINT16 wMsg
, WPARAM16 wParam
,
2168 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam
);
2169 ShowWindow(hWnd
, SW_SHOWNORMAL
);
2174 EndDialog(hWnd
, TRUE
);
2177 EndDialog(hWnd
, FALSE
);
2186 /***********************************************************************
2187 * PrintDlgExA (COMDLG32.@)
2189 HRESULT WINAPI
PrintDlgExA(LPVOID lpPrintDlgExA
) /* [???] FIXME: LPPRINTDLGEXA */
2194 /***********************************************************************
2195 * PrintDlgExW (COMDLG32.@)
2197 HRESULT WINAPI
PrintDlgExW(LPVOID lpPrintDlgExW
) /* [???] FIXME: LPPRINTDLGEXW */