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 /* FIXME: I allow more freedom than either Win95 or WinNT,
898 * which do not agree to what errors should be thrown or not
899 * in case nToPage or nFromPage is out-of-range.
901 if (lppd
->nMaxPage
< lppd
->nMinPage
)
902 lppd
->nMaxPage
= lppd
->nMinPage
;
903 if (lppd
->nMinPage
== lppd
->nMaxPage
)
904 lppd
->Flags
|= PD_NOPAGENUMS
;
905 if (lppd
->nToPage
< lppd
->nMinPage
)
906 lppd
->nToPage
= lppd
->nMinPage
;
907 if (lppd
->nToPage
> lppd
->nMaxPage
)
908 lppd
->nToPage
= lppd
->nMaxPage
;
909 if (lppd
->nFromPage
< lppd
->nMinPage
)
910 lppd
->nFromPage
= lppd
->nMinPage
;
911 if (lppd
->nFromPage
> lppd
->nMaxPage
)
912 lppd
->nFromPage
= lppd
->nMaxPage
;
914 /* If the printer combo box is in the dialog, fill it */
915 if (GetDlgItem(hDlg
,comboID
)) {
918 pdn
= GlobalLock16(lppd
->hDevNames
);
919 pdm
= GlobalLock16(lppd
->hDevMode
);
921 name
= (char*)pdn
+ pdn
->wDeviceOffset
;
923 name
= pdm
->dmDeviceName
;
924 PRINTDLG_SetUpPrinterListCombo(hDlg
, comboID
, name
);
925 if(pdm
) GlobalUnlock16(lppd
->hDevMode
);
926 if(pdn
) GlobalUnlock16(lppd
->hDevNames
);
928 /* Now find selected printer and update rest of dlg */
929 name
= HeapAlloc(GetProcessHeap(),0,256);
930 if (GetDlgItemTextA(hDlg
, comboID
, name
, 255))
931 PRINTDLG_ChangePrinter(hDlg
, name
, PrintStructures
);
933 /* else just use default printer */
935 BOOL ret
= PRINTDLG_GetDefaultPrinterName(name
, sizeof(name
));
938 PRINTDLG_ChangePrinter(hDlg
, name
, PrintStructures
);
940 FIXME("No default printer found, expect problems!\n");
942 HeapFree(GetProcessHeap(),0,name
);
947 /***********************************************************************
948 * PRINTDLG_WMCommand [internal]
950 static LRESULT
PRINTDLG_WMCommand(HWND hDlg
, WPARAM wParam
,
951 LPARAM lParam
, PRINT_PTRA
* PrintStructures
)
953 LPPRINTDLGA lppd
= PrintStructures
->dlg
.lpPrintDlg
;
954 UINT PrinterComboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
955 LPDEVMODEA lpdm
= PrintStructures
->lpDevMode
;
957 switch (LOWORD(wParam
)) {
959 TRACE(" OK button was hit\n");
960 if (PRINTDLG_UpdatePrintDlg(hDlg
, PrintStructures
)!=TRUE
) {
961 FIXME("Update printdlg was not successful!\n");
964 EndDialog(hDlg
, TRUE
);
968 TRACE(" CANCEL button was hit\n");
969 EndDialog(hDlg
, FALSE
);
973 TRACE(" HELP button was hit\n");
974 SendMessageA(lppd
->hwndOwner
, PrintStructures
->HelpMessageID
,
975 (WPARAM
) hDlg
, (LPARAM
) lppd
);
978 case chx2
: /* collate pages checkbox */
979 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
980 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
981 (LPARAM
)PrintStructures
->hCollateIcon
);
983 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
984 (LPARAM
)PrintStructures
->hNoCollateIcon
);
986 case edt1
: /* from page nr editbox */
987 case edt2
: /* to page nr editbox */
988 if (HIWORD(wParam
)==EN_CHANGE
) {
991 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
992 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
993 if (nFromPage
!= lppd
->nFromPage
|| nToPage
!= lppd
->nToPage
)
994 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
999 if(HIWORD(wParam
) == EN_CHANGE
) {
1000 INT copies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
1002 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1004 EnableWindow(GetDlgItem(hDlg
, chx2
), TRUE
);
1008 case psh2
: /* Properties button */
1011 char PrinterName
[256];
1013 GetDlgItemTextA(hDlg
, PrinterComboID
, PrinterName
, 255);
1014 if (!OpenPrinterA(PrinterName
, &hPrinter
, NULL
)) {
1015 FIXME(" Call to OpenPrinter did not succeed!\n");
1018 DocumentPropertiesA(hDlg
, hPrinter
, PrinterName
,
1019 PrintStructures
->lpDevMode
,
1020 PrintStructures
->lpDevMode
,
1021 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
1022 ClosePrinter(hPrinter
);
1026 case rad1
: /* Paperorientation */
1027 if (lppd
->Flags
& PD_PRINTSETUP
)
1029 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1030 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1031 (LPARAM
)(PrintStructures
->hPortraitIcon
));
1035 case rad2
: /* Paperorientation */
1036 if (lppd
->Flags
& PD_PRINTSETUP
)
1038 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1039 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1040 (LPARAM
)(PrintStructures
->hLandscapeIcon
));
1045 case cmb4
: /* Printer combobox */
1046 if (HIWORD(wParam
)==CBN_SELCHANGE
) {
1047 char PrinterName
[256];
1048 GetDlgItemTextA(hDlg
, LOWORD(wParam
), PrinterName
, 255);
1049 PRINTDLG_ChangePrinter(hDlg
, PrinterName
, PrintStructures
);
1053 case cmb2
: /* Papersize */
1055 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
1057 lpdm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageA(hDlg
, cmb2
,
1063 case cmb3
: /* Bin */
1065 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
1067 lpdm
->dmDefaultSource
= SendDlgItemMessageA(hDlg
, cmb3
,
1068 CB_GETITEMDATA
, Sel
,
1073 if(lppd
->Flags
& PD_PRINTSETUP
) {
1074 switch (LOWORD(wParam
)) {
1075 case rad1
: /* orientation */
1077 if (IsDlgButtonChecked(hDlg
, rad1
) == BST_CHECKED
) {
1078 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_PORTRAIT
) {
1079 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1080 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
,
1082 (LPARAM
)PrintStructures
->hPortraitIcon
);
1085 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_LANDSCAPE
) {
1086 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1087 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
,
1089 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1098 /***********************************************************************
1099 * PrintDlgProcA [internal]
1101 BOOL WINAPI
PrintDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
1104 PRINT_PTRA
* PrintStructures
;
1107 if (uMsg
!=WM_INITDIALOG
) {
1108 PrintStructures
= (PRINT_PTRA
*) GetWindowLongA(hDlg
, DWL_USER
);
1109 if (!PrintStructures
)
1112 PrintStructures
= (PRINT_PTRA
*) lParam
;
1113 SetWindowLongA(hDlg
, DWL_USER
, lParam
);
1114 res
= PRINTDLG_WMInitDialog(hDlg
, wParam
, PrintStructures
);
1116 if(PrintStructures
->dlg
.lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
)
1117 res
= PrintStructures
->dlg
.lpPrintDlg
->lpfnPrintHook(
1118 hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->dlg
.lpPrintDlg
1123 if(PrintStructures
->dlg
.lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
) {
1124 res
= PrintStructures
->dlg
.lpPrintDlg
->lpfnPrintHook(hDlg
,uMsg
,wParam
,
1131 return PRINTDLG_WMCommand(hDlg
, wParam
, lParam
, PrintStructures
);
1134 DestroyIcon(PrintStructures
->hCollateIcon
);
1135 DestroyIcon(PrintStructures
->hNoCollateIcon
);
1136 DestroyIcon(PrintStructures
->hPortraitIcon
);
1137 DestroyIcon(PrintStructures
->hLandscapeIcon
);
1138 if(PrintStructures
->hwndUpDown
)
1139 DestroyWindow(PrintStructures
->hwndUpDown
);
1146 /************************************************************
1148 * PRINTDLG_Get16TemplateFrom32 [Internal]
1149 * Generates a 16 bits template from the Wine 32 bits resource
1152 static HGLOBAL16
PRINTDLG_Get16TemplateFrom32(char *PrintResourceName
)
1154 HANDLE hResInfo
, hDlgTmpl32
;
1157 HGLOBAL16 hGlobal16
;
1160 if (!(hResInfo
= FindResourceA(COMMDLG_hInstance32
,
1161 PrintResourceName
, RT_DIALOGA
)))
1163 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
1166 if (!(hDlgTmpl32
= LoadResource(COMMDLG_hInstance32
, hResInfo
)) ||
1167 !(template32
= LockResource( hDlgTmpl32
)))
1169 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1172 size
= SizeofResource(COMMDLG_hInstance32
, hResInfo
);
1173 hGlobal16
= GlobalAlloc16(0, size
);
1176 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE
);
1177 ERR("alloc failure for %ld bytes\n", size
);
1180 template = GlobalLock16(hGlobal16
);
1183 COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE
);
1184 ERR("global lock failure for %x handle\n", hGlobal16
);
1185 GlobalFree16(hGlobal16
);
1188 ConvertDialog32To16((LPVOID
)template32
, size
, (LPVOID
)template);
1189 GlobalUnlock16(hGlobal16
);
1193 /************************************************************
1195 * PRINTDLG_GetDlgTemplate
1198 static HGLOBAL
PRINTDLG_GetDlgTemplate(PRINTDLGA
*lppd
)
1200 HGLOBAL hDlgTmpl
, hResInfo
;
1202 if (lppd
->Flags
& PD_PRINTSETUP
) {
1203 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
1204 hDlgTmpl
= lppd
->hSetupTemplate
;
1205 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
1206 hResInfo
= FindResourceA(lppd
->hInstance
,
1207 lppd
->lpSetupTemplateName
, RT_DIALOGA
);
1208 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1210 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32_SETUP",
1212 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1215 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
1216 hDlgTmpl
= lppd
->hPrintTemplate
;
1217 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
1218 hResInfo
= FindResourceA(lppd
->hInstance
,
1219 lppd
->lpPrintTemplateName
,
1221 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1223 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32",
1225 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1232 /************************************************************
1234 * PRINTDLG_GetDlgTemplate
1237 static HGLOBAL16
PRINTDLG_GetDlgTemplate16(PRINTDLG16
*lppd
)
1239 HGLOBAL16 hDlgTmpl
, hResInfo
;
1241 if (lppd
->Flags
& PD_PRINTSETUP
) {
1242 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
1243 hDlgTmpl
= lppd
->hSetupTemplate
;
1244 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
1245 hResInfo
= FindResource16(lppd
->hInstance
,
1246 MapSL(lppd
->lpSetupTemplateName
), RT_DIALOGA
);
1247 hDlgTmpl
= LoadResource16(lppd
->hInstance
, hResInfo
);
1249 hDlgTmpl
= PRINTDLG_Get16TemplateFrom32("PRINT32_SETUP");
1252 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
1253 hDlgTmpl
= lppd
->hPrintTemplate
;
1254 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
1255 hResInfo
= FindResource16(lppd
->hInstance
,
1256 MapSL(lppd
->lpPrintTemplateName
),
1258 hDlgTmpl
= LoadResource16(lppd
->hInstance
, hResInfo
);
1260 hDlgTmpl
= PRINTDLG_Get16TemplateFrom32("PRINT32");
1266 /***********************************************************************
1271 static BOOL
PRINTDLG_CreateDC(LPPRINTDLGA lppd
)
1273 DEVNAMES
*pdn
= GlobalLock(lppd
->hDevNames
);
1274 DEVMODEA
*pdm
= GlobalLock(lppd
->hDevMode
);
1276 if(lppd
->Flags
& PD_RETURNDC
) {
1277 lppd
->hDC
= CreateDCA((char*)pdn
+ pdn
->wDriverOffset
,
1278 (char*)pdn
+ pdn
->wDeviceOffset
,
1279 (char*)pdn
+ pdn
->wOutputOffset
,
1281 } else if(lppd
->Flags
& PD_RETURNIC
) {
1282 lppd
->hDC
= CreateICA((char*)pdn
+ pdn
->wDriverOffset
,
1283 (char*)pdn
+ pdn
->wDeviceOffset
,
1284 (char*)pdn
+ pdn
->wOutputOffset
,
1287 GlobalUnlock(lppd
->hDevNames
);
1288 GlobalUnlock(lppd
->hDevMode
);
1289 return lppd
->hDC
? TRUE
: FALSE
;
1292 static BOOL
PRINTDLG_CreateDC16(LPPRINTDLG16 lppd
)
1294 DEVNAMES
*pdn
= GlobalLock16(lppd
->hDevNames
);
1295 DEVMODEA
*pdm
= GlobalLock16(lppd
->hDevMode
);
1297 if(lppd
->Flags
& PD_RETURNDC
) {
1298 lppd
->hDC
= CreateDCA((char*)pdn
+ pdn
->wDriverOffset
,
1299 (char*)pdn
+ pdn
->wDeviceOffset
,
1300 (char*)pdn
+ pdn
->wOutputOffset
,
1302 } else if(lppd
->Flags
& PD_RETURNIC
) {
1303 lppd
->hDC
= CreateICA((char*)pdn
+ pdn
->wDriverOffset
,
1304 (char*)pdn
+ pdn
->wDeviceOffset
,
1305 (char*)pdn
+ pdn
->wOutputOffset
,
1308 GlobalUnlock16(lppd
->hDevNames
);
1309 GlobalUnlock16(lppd
->hDevMode
);
1310 return lppd
->hDC
? TRUE
: FALSE
;
1313 /***********************************************************************
1314 * PrintDlgA (COMDLG32.17)
1316 * Displays the the PRINT dialog box, which enables the user to specify
1317 * specific properties of the print job.
1320 * nonzero if the user pressed the OK button
1321 * zero if the user cancelled the window or an error occurred
1325 * * The Collate Icons do not display, even though they are in the code.
1326 * * The Properties Button(s) should call DocumentPropertiesA().
1328 * * The Paper Orientation Icons are not implemented yet.
1329 * * The Properties Button(s) should call DocumentPropertiesA().
1330 * * Settings are not yet taken from a provided DevMode or
1331 * default printer settings.
1333 BOOL WINAPI
PrintDlgA(
1334 LPPRINTDLGA lppd
/* [in/out] ptr to PRINTDLG32 struct */
1339 HINSTANCE hInst
= GetWindowLongA( lppd
->hwndOwner
, GWL_HINSTANCE
);
1341 if(TRACE_ON(commdlg
)) {
1342 char flagstr
[1000] = "";
1343 struct pd_flags
*pflag
= pd_flags
;
1344 for( ; pflag
->name
; pflag
++) {
1345 if(lppd
->Flags
& pflag
->flag
)
1346 strcat(flagstr
, pflag
->name
);
1348 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
1349 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %08x\n"
1350 "flags %08lx (%s)\n",
1351 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
1352 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
1353 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
1356 if(lppd
->lStructSize
!= sizeof(PRINTDLGA
)) {
1357 WARN("structure size failure !!!\n");
1358 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
1362 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
1363 PRINTER_INFO_2A
*pbuf
;
1364 DRIVER_INFO_3A
*dbuf
;
1368 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
1369 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
1370 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
1373 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
1374 WARN("Can't find default printer\n");
1375 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
1379 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
1380 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
1381 GetPrinterA(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
1383 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
1384 dbuf
= HeapAlloc(GetProcessHeap(),0,needed
);
1385 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
1386 ERR("GetPrinterDriverA failed, le %ld, fix your config for printer %s!\n",GetLastError(),pbuf
->pPrinterName
);
1387 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
1392 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
1396 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
1397 pbuf
->pDevMode
->dmDriverExtra
);
1398 ptr
= GlobalLock(lppd
->hDevMode
);
1399 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
1400 pbuf
->pDevMode
->dmDriverExtra
);
1401 GlobalUnlock(lppd
->hDevMode
);
1402 HeapFree(GetProcessHeap(), 0, pbuf
);
1403 HeapFree(GetProcessHeap(), 0, dbuf
);
1407 PRINT_PTRA
*PrintStructures
;
1409 /* load Dialog resources,
1410 * depending on Flags indicates Print32 or Print32_setup dialog
1412 hDlgTmpl
= PRINTDLG_GetDlgTemplate(lppd
);
1414 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1417 ptr
= LockResource( hDlgTmpl
);
1419 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1423 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1424 sizeof(PRINT_PTRA
));
1425 PrintStructures
->dlg
.lpPrintDlg
= lppd
;
1427 /* and create & process the dialog .
1428 * -1 is failure, 0 is broken hwnd, everything else is ok.
1430 bRet
= (0<DialogBoxIndirectParamA(hInst
, ptr
, lppd
->hwndOwner
,
1432 (LPARAM
)PrintStructures
));
1435 DEVMODEA
*lpdm
= PrintStructures
->lpDevMode
, *lpdmReturn
;
1436 PRINTER_INFO_2A
*pi
= PrintStructures
->lpPrinterInfo
;
1437 DRIVER_INFO_3A
*di
= PrintStructures
->lpDriverInfo
;
1439 if (lppd
->hDevMode
== 0) {
1440 TRACE(" No hDevMode yet... Need to create my own\n");
1441 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
,
1442 lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
1445 if((locks
= (GlobalFlags(lppd
->hDevMode
) & GMEM_LOCKCOUNT
))) {
1446 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks
);
1448 GlobalUnlock(lppd
->hDevMode
);
1449 TRACE("Now got %d locks\n", locks
);
1452 lppd
->hDevMode
= GlobalReAlloc(lppd
->hDevMode
,
1453 lpdm
->dmSize
+ lpdm
->dmDriverExtra
,
1456 lpdmReturn
= GlobalLock(lppd
->hDevMode
);
1457 memcpy(lpdmReturn
, lpdm
, lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
1459 if (lppd
->hDevNames
!= 0) {
1461 if((locks
= (GlobalFlags(lppd
->hDevNames
) & GMEM_LOCKCOUNT
))) {
1462 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks
);
1464 GlobalUnlock(lppd
->hDevNames
);
1467 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
1472 GlobalUnlock(lppd
->hDevMode
);
1474 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
1475 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpPrinterInfo
);
1476 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDriverInfo
);
1477 HeapFree(GetProcessHeap(), 0, PrintStructures
);
1479 if(bRet
&& (lppd
->Flags
& PD_RETURNDC
|| lppd
->Flags
& PD_RETURNIC
))
1480 bRet
= PRINTDLG_CreateDC(lppd
);
1482 TRACE("exit! (%d)\n", bRet
);
1486 /***********************************************************************
1487 * PrintDlg16 (COMMDLG.20)
1489 * Displays the the PRINT dialog box, which enables the user to specify
1490 * specific properties of the print job.
1493 * nonzero if the user pressed the OK button
1494 * zero if the user cancelled the window or an error occurred
1497 * * calls up to the 32-bit versions of the Dialogs, which look different
1498 * * Customizing is *not* implemented.
1501 BOOL16 WINAPI
PrintDlg16(
1502 LPPRINTDLG16 lppd
/* [in/out] ptr to PRINTDLG struct */
1506 HINSTANCE hInst
= GetWindowLongA( lppd
->hwndOwner
, GWL_HINSTANCE
);
1508 if(TRACE_ON(commdlg
)) {
1509 char flagstr
[1000] = "";
1510 struct pd_flags
*pflag
= pd_flags
;
1511 for( ; pflag
->name
; pflag
++) {
1512 if(lppd
->Flags
& pflag
->flag
)
1513 strcat(flagstr
, pflag
->name
);
1515 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
1516 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %08x\n"
1517 "flags %08lx (%s)\n",
1518 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
1519 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
1520 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
1523 if(lppd
->lStructSize
!= sizeof(PRINTDLG16
)) {
1524 ERR("structure size (%ld/%d)\n",lppd
->lStructSize
,sizeof(PRINTDLG16
));
1525 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
1529 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
1530 PRINTER_INFO_2A
*pbuf
;
1531 DRIVER_INFO_3A
*dbuf
;
1535 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
1536 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
1537 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
1540 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
1541 WARN("Can't find default printer\n");
1542 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
1546 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
1547 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
1548 GetPrinterA(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
1549 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
1550 dbuf
= HeapAlloc(GetProcessHeap(),0,needed
);
1551 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
1552 ERR("GetPrinterDriverA failed for %s, le %ld, fix your config!\n",
1553 pbuf
->pPrinterName
,GetLastError());
1554 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
1558 PRINTDLG_CreateDevNames16(&(lppd
->hDevNames
),
1562 lppd
->hDevMode
= GlobalAlloc16(GMEM_MOVEABLE
,pbuf
->pDevMode
->dmSize
+
1563 pbuf
->pDevMode
->dmDriverExtra
);
1564 ptr
= GlobalLock16(lppd
->hDevMode
);
1565 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
1566 pbuf
->pDevMode
->dmDriverExtra
);
1567 GlobalUnlock16(lppd
->hDevMode
);
1568 HeapFree(GetProcessHeap(), 0, pbuf
);
1569 HeapFree(GetProcessHeap(), 0, dbuf
);
1573 PRINT_PTRA
*PrintStructures
;
1575 /* load Dialog resources,
1576 * depending on Flags indicates Print32 or Print32_setup dialog
1578 hDlgTmpl
= PRINTDLG_GetDlgTemplate16(lppd
);
1580 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1583 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1584 sizeof(PRINT_PTRA
));
1585 PrintStructures
->dlg
.lpPrintDlg16
= lppd
;
1586 PrintStructures
->dlg
.lpPrintDlg
= (LPPRINTDLGA
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(PRINTDLGA
));
1587 #define CVAL(x) PrintStructures->dlg.lpPrintDlg->x = lppd->x;
1588 #define MVAL(x) PrintStructures->dlg.lpPrintDlg->x = MapSL(lppd->x);
1589 CVAL(Flags
);CVAL(hwndOwner
);CVAL(hDC
);
1590 CVAL(nFromPage
);CVAL(nToPage
);CVAL(nMinPage
);CVAL(nMaxPage
);
1591 CVAL(nCopies
);CVAL(hInstance
);CVAL(lCustData
);
1592 MVAL(lpPrintTemplateName
);MVAL(lpSetupTemplateName
);
1593 /* Don't copy rest, it is 16 bit specific */
1597 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(),0,sizeof(DEVMODEA
));
1599 /* and create & process the dialog .
1600 * -1 is failure, 0 is broken hwnd, everything else is ok.
1602 bRet
= (0<DialogBoxIndirectParam16(
1603 hInst
, hDlgTmpl
, lppd
->hwndOwner
,
1604 (DLGPROC16
)GetProcAddress16(GetModuleHandle16("COMMDLG"),(LPCSTR
)21),
1605 (LPARAM
)PrintStructures
1608 if (!PrintStructures
->lpPrinterInfo
) bRet
= FALSE
;
1610 DEVMODEA
*lpdm
= PrintStructures
->lpDevMode
, *lpdmReturn
;
1611 PRINTER_INFO_2A
*pi
= PrintStructures
->lpPrinterInfo
;
1612 DRIVER_INFO_3A
*di
= PrintStructures
->lpDriverInfo
;
1614 if (lppd
->hDevMode
== 0) {
1615 TRACE(" No hDevMode yet... Need to create my own\n");
1616 lppd
->hDevMode
= GlobalAlloc16(GMEM_MOVEABLE
,
1617 lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
1620 if((locks
= (GlobalFlags16(lppd
->hDevMode
)&GMEM_LOCKCOUNT
))) {
1621 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks
);
1623 GlobalUnlock16(lppd
->hDevMode
);
1624 TRACE("Now got %d locks\n", locks
);
1627 lppd
->hDevMode
= GlobalReAlloc16(lppd
->hDevMode
,
1628 lpdm
->dmSize
+ lpdm
->dmDriverExtra
,
1631 lpdmReturn
= GlobalLock16(lppd
->hDevMode
);
1632 memcpy(lpdmReturn
, lpdm
, lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
1634 if (lppd
->hDevNames
!= 0) {
1636 if((locks
= (GlobalFlags16(lppd
->hDevNames
)&GMEM_LOCKCOUNT
))) {
1637 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks
);
1639 GlobalUnlock16(lppd
->hDevNames
);
1642 PRINTDLG_CreateDevNames16(&(lppd
->hDevNames
),
1647 GlobalUnlock16(lppd
->hDevMode
);
1649 if (!(lppd
->Flags
& (PD_ENABLESETUPTEMPLATEHANDLE
| PD_ENABLESETUPTEMPLATE
)))
1650 GlobalFree16(hDlgTmpl
); /* created from the 32 bits resource */
1651 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
1652 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpPrinterInfo
);
1653 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDriverInfo
);
1654 HeapFree(GetProcessHeap(), 0, PrintStructures
);
1656 if(bRet
&& (lppd
->Flags
& PD_RETURNDC
|| lppd
->Flags
& PD_RETURNIC
))
1657 bRet
= PRINTDLG_CreateDC16(lppd
);
1659 TRACE("exit! (%d)\n", bRet
);
1665 /***********************************************************************
1666 * PrintDlgW (COMDLG32.18)
1668 BOOL WINAPI
PrintDlgW( LPPRINTDLGW printdlg
)
1670 FIXME("A really empty stub\n" );
1674 /***********************************************************************
1680 * cmb3 - source (tray?)
1681 * edt4 - border left
1683 * edt6 - border right
1684 * edt7 - border bottom
1685 * psh3 - "Printer..."
1689 LPPAGESETUPDLGA dlga
;
1694 static HGLOBAL
PRINTDLG_GetPGSTemplate(PAGESETUPDLGA
*lppd
)
1696 HGLOBAL hDlgTmpl
, hResInfo
;
1698 if(lppd
->Flags
& PSD_ENABLEPAGESETUPTEMPLATEHANDLE
) {
1699 hDlgTmpl
= lppd
->hPageSetupTemplate
;
1700 } else if(lppd
->Flags
& PSD_ENABLEPAGESETUPTEMPLATE
) {
1701 hResInfo
= FindResourceA(lppd
->hInstance
,
1702 lppd
->lpPageSetupTemplateName
, RT_DIALOGA
);
1703 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1705 hResInfo
= FindResourceA(COMDLG32_hInstance
,(LPCSTR
)PAGESETUPDLGORD
,RT_DIALOGA
);
1706 hDlgTmpl
= LoadResource(COMDLG32_hInstance
,hResInfo
);
1712 _c_10mm2size(PAGESETUPDLGA
*dlga
,DWORD size
) {
1713 if (dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
)
1714 return 10*size
*10/25.4;
1715 /* If we don't have a flag, we can choose one. Use millimeters
1716 * to avoid confusing me
1718 dlga
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
1719 FIXME("returning %ld/100 mm \n",size
);
1725 _c_inch2size(PAGESETUPDLGA
*dlga
,DWORD size
) {
1726 if (dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
)
1728 if (dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
)
1729 return (size
*254)/10;
1730 /* if we don't have a flag, we can choose one. Use millimeters
1731 * to avoid confusing me
1733 dlga
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
1734 return (size
*254)/10;
1738 _c_size2str(PageSetupData
*pda
,DWORD size
,LPSTR strout
) {
1739 strcpy(strout
,"<undef>");
1740 if (pda
->dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
) {
1741 sprintf(strout
,"%.2fmm",(size
*1.0)/100.0);
1744 if (pda
->dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
) {
1745 sprintf(strout
,"%.2fin",(size
*1.0)/1000.0);
1748 pda
->dlga
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
1749 sprintf(strout
,"%.2fmm",(size
*1.0)/100.0);
1754 _c_str2size(PageSetupData
*pda
,LPCSTR strin
) {
1759 if (!sscanf(strin
,"%f%s",&val
,rest
))
1762 if (!strcmp(rest
,"in") || !strcmp(rest
,"inch")) {
1763 if (pda
->dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
)
1766 return val
*25.4*100;
1768 if (!strcmp(rest
,"cm")) { rest
[0]='m'; val
= val
*10.0; }
1769 if (!strcmp(rest
,"m")) { strcpy(rest
,"mm"); val
= val
*1000.0; }
1771 if (!strcmp(rest
,"mm")) {
1772 if (pda
->dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
)
1775 return 1000.0*val
/25.4;
1777 if (rest
[0]=='\0') {
1778 /* use application supplied default */
1779 if (pda
->dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
) {
1783 if (pda
->dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
) {
1788 ERR("Did not find a conversion for type '%s'!\n",rest
);
1794 * This is called on finish and will update the output fields of the
1798 PRINTDLG_PS_UpdateDlgStruct(HWND hDlg
, PageSetupData
*pda
) {
1801 LPSTR devname
,portname
;
1805 dn
= GlobalLock(pda
->pdlg
.hDevNames
);
1806 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
1807 devname
= ((char*)dn
)+dn
->wDeviceOffset
;
1808 portname
= ((char*)dn
)+dn
->wOutputOffset
;
1809 PRINTDLG_SetUpPaperComboBox(hDlg
,cmb2
,devname
,portname
,dm
);
1810 PRINTDLG_SetUpPaperComboBox(hDlg
,cmb3
,devname
,portname
,dm
);
1812 if (GetDlgItemTextA(hDlg
,cmb2
,papername
,sizeof(papername
))>0) {
1813 PRINTDLG_PaperSize(&(pda
->pdlg
),papername
,&(pda
->dlga
->ptPaperSize
));
1814 pda
->dlga
->ptPaperSize
.x
= _c_10mm2size(pda
->dlga
,pda
->dlga
->ptPaperSize
.x
);
1815 pda
->dlga
->ptPaperSize
.y
= _c_10mm2size(pda
->dlga
,pda
->dlga
->ptPaperSize
.y
);
1817 FIXME("could not get dialog text for papersize cmbbox?\n");
1818 #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); }
1819 GETVAL(edt4
,pda
->dlga
->rtMargin
.left
);
1820 GETVAL(edt5
,pda
->dlga
->rtMargin
.top
);
1821 GETVAL(edt6
,pda
->dlga
->rtMargin
.right
);
1822 GETVAL(edt7
,pda
->dlga
->rtMargin
.bottom
);
1825 /* If we are in landscape, swap x and y of page size */
1826 if (IsDlgButtonChecked(hDlg
, rad2
)) {
1828 tmp
= pda
->dlga
->ptPaperSize
.x
;
1829 pda
->dlga
->ptPaperSize
.x
= pda
->dlga
->ptPaperSize
.y
;
1830 pda
->dlga
->ptPaperSize
.y
= tmp
;
1832 GlobalUnlock(pda
->pdlg
.hDevNames
);
1833 GlobalUnlock(pda
->pdlg
.hDevMode
);
1838 * This is called after returning from PrintDlg().
1841 PRINTDLG_PS_ChangePrinter(HWND hDlg
, PageSetupData
*pda
) {
1844 LPSTR devname
,portname
;
1846 dn
= GlobalLock(pda
->pdlg
.hDevNames
);
1847 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
1848 devname
= ((char*)dn
)+dn
->wDeviceOffset
;
1849 portname
= ((char*)dn
)+dn
->wOutputOffset
;
1850 PRINTDLG_SetUpPaperComboBox(hDlg
,cmb2
,devname
,portname
,dm
);
1851 PRINTDLG_SetUpPaperComboBox(hDlg
,cmb3
,devname
,portname
,dm
);
1852 GlobalUnlock(pda
->pdlg
.hDevNames
);
1853 GlobalUnlock(pda
->pdlg
.hDevMode
);
1858 PRINTDLG_PS_WMCommand(
1859 HWND hDlg
, WPARAM wParam
, LPARAM lParam
, PageSetupData
*pda
1861 switch (LOWORD(wParam
)) {
1863 if (!PRINTDLG_PS_UpdateDlgStruct(hDlg
, pda
))
1865 EndDialog(hDlg
, TRUE
);
1869 EndDialog(hDlg
, FALSE
);
1873 pda
->pdlg
.Flags
= 0;
1874 pda
->pdlg
.hwndOwner
= hDlg
;
1875 if (PrintDlgA(&(pda
->pdlg
)))
1876 PRINTDLG_PS_ChangePrinter(hDlg
,pda
);
1880 FIXME("loword (lparam) %d, wparam 0x%x, lparam %08lx, STUB mostly.\n",
1881 LOWORD(lParam
),wParam
,lParam
1888 PageDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1893 if (uMsg
==WM_INITDIALOG
) {
1895 pda
= (PageSetupData
*)lParam
;
1896 SetPropA(hDlg
,"__WINE_PAGESETUPDLGDATA",lParam
);
1897 if (pda
->dlga
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
1898 res
= pda
->dlga
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,lParam
);
1900 FIXME("Setup page hook failed?\n");
1904 if (pda
->dlga
->Flags
& PSD_ENABLEPAGEPAINTHOOK
) {
1905 FIXME("PagePaintHook not yet implemented!\n");
1907 if (pda
->dlga
->Flags
& PSD_DISABLEPRINTER
)
1908 EnableWindow(GetDlgItem(hDlg
, psh3
), FALSE
);
1909 if (pda
->dlga
->Flags
& PSD_DISABLEMARGINS
) {
1910 EnableWindow(GetDlgItem(hDlg
, edt4
), FALSE
);
1911 EnableWindow(GetDlgItem(hDlg
, edt5
), FALSE
);
1912 EnableWindow(GetDlgItem(hDlg
, edt6
), FALSE
);
1913 EnableWindow(GetDlgItem(hDlg
, edt7
), FALSE
);
1915 /* width larger as height -> landscape */
1916 if (pda
->dlga
->ptPaperSize
.x
> pda
->dlga
->ptPaperSize
.y
)
1917 CheckRadioButton(hDlg
, rad1
, rad2
, rad2
);
1918 else /* this is default if papersize is not set */
1919 CheckRadioButton(hDlg
, rad1
, rad2
, rad1
);
1920 if (pda
->dlga
->Flags
& PSD_DISABLEORIENTATION
) {
1921 EnableWindow(GetDlgItem(hDlg
,rad1
),FALSE
);
1922 EnableWindow(GetDlgItem(hDlg
,rad2
),FALSE
);
1924 /* We fill them out enabled or not */
1925 if (pda
->dlga
->Flags
& PSD_MARGINS
) {
1927 _c_size2str(pda
,pda
->dlga
->rtMargin
.left
,str
);
1928 SetDlgItemTextA(hDlg
,edt4
,str
);
1929 _c_size2str(pda
,pda
->dlga
->rtMargin
.top
,str
);
1930 SetDlgItemTextA(hDlg
,edt5
,str
);
1931 _c_size2str(pda
,pda
->dlga
->rtMargin
.right
,str
);
1932 SetDlgItemTextA(hDlg
,edt6
,str
);
1933 _c_size2str(pda
,pda
->dlga
->rtMargin
.bottom
,str
);
1934 SetDlgItemTextA(hDlg
,edt7
,str
);
1936 /* default is 1 inch */
1937 DWORD size
= _c_inch2size(pda
->dlga
,1000);
1939 _c_size2str(pda
,size
,str
);
1940 SetDlgItemTextA(hDlg
,edt4
,str
);
1941 SetDlgItemTextA(hDlg
,edt5
,str
);
1942 SetDlgItemTextA(hDlg
,edt6
,str
);
1943 SetDlgItemTextA(hDlg
,edt7
,str
);
1945 PRINTDLG_PS_ChangePrinter(hDlg
,pda
);
1946 if (pda
->dlga
->Flags
& PSD_DISABLEPAPER
) {
1947 EnableWindow(GetDlgItem(hDlg
,cmb2
),FALSE
);
1948 EnableWindow(GetDlgItem(hDlg
,cmb3
),FALSE
);
1952 pda
= (PageSetupData
*)GetPropA(hDlg
,"__WINE_PAGESETUPDLGDATA");
1954 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
1957 if (pda
->dlga
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
1958 res
= pda
->dlga
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,lParam
);
1959 if (res
) return res
;
1964 return PRINTDLG_PS_WMCommand(hDlg
, wParam
, lParam
, pda
);
1969 /***********************************************************************
1970 * PageSetupDlgA (COMDLG32.15)
1972 BOOL WINAPI
PageSetupDlgA(LPPAGESETUPDLGA setupdlg
) {
1979 if(TRACE_ON(commdlg
)) {
1980 char flagstr
[1000] = "";
1981 struct pd_flags
*pflag
= psd_flags
;
1982 for( ; pflag
->name
; pflag
++) {
1983 if(setupdlg
->Flags
& pflag
->flag
) {
1984 strcat(flagstr
, pflag
->name
);
1985 strcat(flagstr
, "|");
1988 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
1989 "hinst %08x, flags %08lx (%s)\n",
1990 setupdlg
, setupdlg
->hwndOwner
, setupdlg
->hDevMode
,
1991 setupdlg
->hDevNames
,
1992 setupdlg
->hInstance
, setupdlg
->Flags
, flagstr
);
1995 /* First get default printer data, we need it right after that. */
1996 memset(&pdlg
,0,sizeof(pdlg
));
1997 pdlg
.lStructSize
= sizeof(pdlg
);
1998 pdlg
.Flags
= PD_RETURNDEFAULT
;
1999 bRet
= PrintDlgA(&pdlg
);
2000 if (!bRet
) return FALSE
;
2002 /* short cut exit, just return default values */
2003 if (setupdlg
->Flags
& PSD_RETURNDEFAULT
) {
2004 setupdlg
->hDevMode
= pdlg
.hDevMode
;
2005 setupdlg
->hDevNames
= pdlg
.hDevNames
;
2006 /* FIXME: Just return "A4" for now. */
2007 PRINTDLG_PaperSize(&pdlg
,"A4",&setupdlg
->ptPaperSize
);
2008 setupdlg
->ptPaperSize
.x
=_c_10mm2size(setupdlg
,setupdlg
->ptPaperSize
.x
);
2009 setupdlg
->ptPaperSize
.y
=_c_10mm2size(setupdlg
,setupdlg
->ptPaperSize
.y
);
2012 hDlgTmpl
= PRINTDLG_GetPGSTemplate(setupdlg
);
2014 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2017 ptr
= LockResource( hDlgTmpl
);
2019 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2022 pda
= HeapAlloc(GetProcessHeap(),0,sizeof(*pda
));
2023 pda
->dlga
= setupdlg
;
2024 memcpy(&pda
->pdlg
,&pdlg
,sizeof(pdlg
));
2026 bRet
= (0<DialogBoxIndirectParamA(
2027 setupdlg
->hInstance
,
2029 setupdlg
->hwndOwner
,
2035 /***********************************************************************
2036 * PageSetupDlgW (COMDLG32.16)
2038 BOOL WINAPI
PageSetupDlgW(LPPAGESETUPDLGW setupdlg
) {
2039 FIXME("(%p), stub!\n",setupdlg
);
2043 /**********************************************************************
2048 /***********************************************************************
2049 * PrintDlgProc16 (COMMDLG.21)
2051 LRESULT WINAPI
PrintDlgProc16(HWND16 hDlg
, UINT16 uMsg
, WPARAM16 wParam
,
2054 PRINT_PTRA
* PrintStructures
;
2057 if (uMsg
!=WM_INITDIALOG
) {
2058 PrintStructures
= (PRINT_PTRA
*) GetWindowLongA(hDlg
, DWL_USER
);
2059 if (!PrintStructures
)
2062 PrintStructures
= (PRINT_PTRA
*) lParam
;
2063 SetWindowLongA(hDlg
, DWL_USER
, lParam
);
2064 res
= PRINTDLG_WMInitDialog16(hDlg
, wParam
, PrintStructures
);
2066 if(PrintStructures
->dlg
.lpPrintDlg16
->Flags
& PD_ENABLEPRINTHOOK
) {
2067 res
= CallWindowProc16(
2068 (WNDPROC16
)PrintStructures
->dlg
.lpPrintDlg16
->lpfnPrintHook
,
2069 hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->dlg
.lpPrintDlg16
2075 if(PrintStructures
->dlg
.lpPrintDlg16
->Flags
& PD_ENABLEPRINTHOOK
) {
2076 res
= CallWindowProc16(
2077 (WNDPROC16
)PrintStructures
->dlg
.lpPrintDlg16
->lpfnPrintHook
,
2078 hDlg
,uMsg
, wParam
, lParam
2080 if(LOWORD(res
)) return res
;
2085 /* We need to map those for the 32bit window procedure, compare
2086 * with 32Ato16 mapper in winproc.c
2088 return PRINTDLG_WMCommand(
2090 MAKEWPARAM(wParam
,HIWORD(lParam
)),
2096 DestroyIcon(PrintStructures
->hCollateIcon
);
2097 DestroyIcon(PrintStructures
->hNoCollateIcon
);
2098 /* FIXME: don't forget to delete the paper orientation icons here! */
2106 /***********************************************************************
2107 * PrintSetupDlgProc16 (COMMDLG.22)
2109 LRESULT WINAPI
PrintSetupDlgProc16(HWND16 hWnd
, UINT16 wMsg
, WPARAM16 wParam
,
2115 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam
);
2116 ShowWindow(hWnd
, SW_SHOWNORMAL
);
2121 EndDialog(hWnd
, TRUE
);
2124 EndDialog(hWnd
, FALSE
);
2133 /***********************************************************************
2136 HRESULT WINAPI
PrintDlgExA(LPVOID lpPrintDlgExA
) /* [???] FIXME: LPPRINTDLGEXA */
2141 /***********************************************************************
2144 HRESULT WINAPI
PrintDlgExW(LPVOID lpPrintDlgExW
) /* [???] FIXME: LPPRINTDLGEXW */