2 * COMMDLG - Print Dialog
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
6 * Copyright 1999 Klaas van Gend
7 * Copyright 2000 Huw D M Davies
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #define NONAMELESSUNION
30 #define NONAMELESSSTRUCT
38 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(commdlg
);
49 /* Yes these constants are the same, but we're just copying win98 */
50 #define UPDOWN_ID 0x270f
51 #define MAX_COPIES 9999
54 static const struct pd_flags psd_flags
[] = {
55 {PSD_MINMARGINS
,"PSD_MINMARGINS"},
56 {PSD_MARGINS
,"PSD_MARGINS"},
57 {PSD_INTHOUSANDTHSOFINCHES
,"PSD_INTHOUSANDTHSOFINCHES"},
58 {PSD_INHUNDREDTHSOFMILLIMETERS
,"PSD_INHUNDREDTHSOFMILLIMETERS"},
59 {PSD_DISABLEMARGINS
,"PSD_DISABLEMARGINS"},
60 {PSD_DISABLEPRINTER
,"PSD_DISABLEPRINTER"},
61 {PSD_NOWARNING
,"PSD_NOWARNING"},
62 {PSD_DISABLEORIENTATION
,"PSD_DISABLEORIENTATION"},
63 {PSD_RETURNDEFAULT
,"PSD_RETURNDEFAULT"},
64 {PSD_DISABLEPAPER
,"PSD_DISABLEPAPER"},
65 {PSD_SHOWHELP
,"PSD_SHOWHELP"},
66 {PSD_ENABLEPAGESETUPHOOK
,"PSD_ENABLEPAGESETUPHOOK"},
67 {PSD_ENABLEPAGESETUPTEMPLATE
,"PSD_ENABLEPAGESETUPTEMPLATE"},
68 {PSD_ENABLEPAGESETUPTEMPLATEHANDLE
,"PSD_ENABLEPAGESETUPTEMPLATEHANDLE"},
69 {PSD_ENABLEPAGEPAINTHOOK
,"PSD_ENABLEPAGEPAINTHOOK"},
70 {PSD_DISABLEPAGEPAINTING
,"PSD_DISABLEPAGEPAINTING"},
74 /* address of wndproc for subclassed Static control */
75 static WNDPROC lpfnStaticWndProc
;
76 /* the text of the fake document to render for the Page Setup dialog */
77 static WCHAR wszFakeDocumentText
[1024];
79 /***********************************************************************
80 * PRINTDLG_OpenDefaultPrinter
82 * Returns a winspool printer handle to the default printer in *hprn
83 * Caller must call ClosePrinter on the handle
85 * Returns TRUE on success else FALSE
87 BOOL
PRINTDLG_OpenDefaultPrinter(HANDLE
*hprn
)
90 DWORD dwBufLen
= sizeof(buf
) / sizeof(buf
[0]);
92 if(!GetDefaultPrinterW(buf
, &dwBufLen
))
94 res
= OpenPrinterW(buf
, hprn
, NULL
);
96 WARN("Could not open printer %s\n", debugstr_w(buf
));
100 /***********************************************************************
101 * PRINTDLG_SetUpPrinterListCombo
103 * Initializes printer list combox.
104 * hDlg: HWND of dialog
105 * id: Control id of combo
106 * name: Name of printer to select
108 * Initializes combo with list of available printers. Selects printer 'name'
109 * If name is NULL or does not exist select the default printer.
111 * Returns number of printers added to list.
113 INT
PRINTDLG_SetUpPrinterListComboA(HWND hDlg
, UINT id
, LPCSTR name
)
117 LPPRINTER_INFO_2A pi
;
118 EnumPrintersA(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
119 pi
= HeapAlloc(GetProcessHeap(), 0, needed
);
120 EnumPrintersA(PRINTER_ENUM_LOCAL
, NULL
, 2, (LPBYTE
)pi
, needed
, &needed
,
123 SendDlgItemMessageA(hDlg
, id
, CB_RESETCONTENT
, 0, 0);
125 for(i
= 0; i
< num
; i
++) {
126 SendDlgItemMessageA(hDlg
, id
, CB_ADDSTRING
, 0,
127 (LPARAM
)pi
[i
].pPrinterName
);
129 HeapFree(GetProcessHeap(), 0, pi
);
131 (i
= SendDlgItemMessageA(hDlg
, id
, CB_FINDSTRINGEXACT
, -1,
132 (LPARAM
)name
)) == CB_ERR
) {
135 DWORD dwBufLen
= sizeof(buf
);
137 WARN("Can't find %s in printer list so trying to find default\n",
139 if(!GetDefaultPrinterA(buf
, &dwBufLen
))
141 i
= SendDlgItemMessageA(hDlg
, id
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buf
);
143 FIXME("Can't find default printer in printer list\n");
145 SendDlgItemMessageA(hDlg
, id
, CB_SETCURSEL
, i
, 0);
149 static INT
PRINTDLG_SetUpPrinterListComboW(HWND hDlg
, UINT id
, LPCWSTR name
)
153 LPPRINTER_INFO_2W pi
;
154 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
155 pi
= HeapAlloc(GetProcessHeap(), 0, needed
);
156 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, (LPBYTE
)pi
, needed
, &needed
,
159 for(i
= 0; i
< num
; i
++) {
160 SendDlgItemMessageW(hDlg
, id
, CB_ADDSTRING
, 0,
161 (LPARAM
)pi
[i
].pPrinterName
);
163 HeapFree(GetProcessHeap(), 0, pi
);
165 (i
= SendDlgItemMessageW(hDlg
, id
, CB_FINDSTRINGEXACT
, -1,
166 (LPARAM
)name
)) == CB_ERR
) {
168 DWORD dwBufLen
= sizeof(buf
)/sizeof(buf
[0]);
170 WARN("Can't find %s in printer list so trying to find default\n",
172 if(!GetDefaultPrinterW(buf
, &dwBufLen
))
174 i
= SendDlgItemMessageW(hDlg
, id
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buf
);
176 TRACE("Can't find default printer in printer list\n");
178 SendDlgItemMessageW(hDlg
, id
, CB_SETCURSEL
, i
, 0);
182 /***********************************************************************
183 * PRINTDLG_CreateDevNames [internal]
186 * creates a DevNames structure.
188 * (NB. when we handle unicode the offsets will be in wchars).
190 static BOOL
PRINTDLG_CreateDevNames(HGLOBAL
*hmem
, const char* DeviceDriverName
,
191 const char* DeviceName
, const char* OutputPort
)
194 char* pDevNamesSpace
;
196 LPDEVNAMES lpDevNames
;
198 DWORD dwBufLen
= sizeof(buf
);
200 size
= strlen(DeviceDriverName
) + 1
201 + strlen(DeviceName
) + 1
202 + strlen(OutputPort
) + 1
206 *hmem
= GlobalReAlloc(*hmem
, size
, GMEM_MOVEABLE
);
208 *hmem
= GlobalAlloc(GMEM_MOVEABLE
, size
);
212 pDevNamesSpace
= GlobalLock(*hmem
);
213 lpDevNames
= (LPDEVNAMES
) pDevNamesSpace
;
215 pTempPtr
= pDevNamesSpace
+ sizeof(DEVNAMES
);
216 strcpy(pTempPtr
, DeviceDriverName
);
217 lpDevNames
->wDriverOffset
= pTempPtr
- pDevNamesSpace
;
219 pTempPtr
+= strlen(DeviceDriverName
) + 1;
220 strcpy(pTempPtr
, DeviceName
);
221 lpDevNames
->wDeviceOffset
= pTempPtr
- pDevNamesSpace
;
223 pTempPtr
+= strlen(DeviceName
) + 1;
224 strcpy(pTempPtr
, OutputPort
);
225 lpDevNames
->wOutputOffset
= pTempPtr
- pDevNamesSpace
;
227 GetDefaultPrinterA(buf
, &dwBufLen
);
228 lpDevNames
->wDefault
= (strcmp(buf
, DeviceName
) == 0) ? 1 : 0;
233 static BOOL
PRINTDLG_CreateDevNamesW(HGLOBAL
*hmem
, LPCWSTR DeviceDriverName
,
234 LPCWSTR DeviceName
, LPCWSTR OutputPort
)
237 LPWSTR pDevNamesSpace
;
239 LPDEVNAMES lpDevNames
;
241 DWORD dwBufLen
= sizeof(bufW
) / sizeof(WCHAR
);
243 size
= sizeof(WCHAR
)*lstrlenW(DeviceDriverName
) + 2
244 + sizeof(WCHAR
)*lstrlenW(DeviceName
) + 2
245 + sizeof(WCHAR
)*lstrlenW(OutputPort
) + 2
249 *hmem
= GlobalReAlloc(*hmem
, size
, GMEM_MOVEABLE
);
251 *hmem
= GlobalAlloc(GMEM_MOVEABLE
, size
);
255 pDevNamesSpace
= GlobalLock(*hmem
);
256 lpDevNames
= (LPDEVNAMES
) pDevNamesSpace
;
258 pTempPtr
= (LPWSTR
)((LPDEVNAMES
)pDevNamesSpace
+ 1);
259 lstrcpyW(pTempPtr
, DeviceDriverName
);
260 lpDevNames
->wDriverOffset
= pTempPtr
- pDevNamesSpace
;
262 pTempPtr
+= lstrlenW(DeviceDriverName
) + 1;
263 lstrcpyW(pTempPtr
, DeviceName
);
264 lpDevNames
->wDeviceOffset
= pTempPtr
- pDevNamesSpace
;
266 pTempPtr
+= lstrlenW(DeviceName
) + 1;
267 lstrcpyW(pTempPtr
, OutputPort
);
268 lpDevNames
->wOutputOffset
= pTempPtr
- pDevNamesSpace
;
270 GetDefaultPrinterW(bufW
, &dwBufLen
);
271 lpDevNames
->wDefault
= (lstrcmpW(bufW
, DeviceName
) == 0) ? 1 : 0;
276 /***********************************************************************
277 * PRINTDLG_UpdatePrintDlg [internal]
280 * updates the PrintDlg structure for return values.
283 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
284 * TRUE if successful.
286 static BOOL
PRINTDLG_UpdatePrintDlgA(HWND hDlg
,
287 PRINT_PTRA
* PrintStructures
)
289 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
290 PDEVMODEA lpdm
= PrintStructures
->lpDevMode
;
291 LPPRINTER_INFO_2A pi
= PrintStructures
->lpPrinterInfo
;
295 FIXME("No lpdm ptr?\n");
300 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
301 /* check whether nFromPage and nToPage are within range defined by
302 * nMinPage and nMaxPage
304 if (IsDlgButtonChecked(hDlg
, rad3
) == BST_CHECKED
) { /* Pages */
307 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
308 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
309 if (nFromPage
< lppd
->nMinPage
|| nFromPage
> lppd
->nMaxPage
||
310 nToPage
< lppd
->nMinPage
|| nToPage
> lppd
->nMaxPage
) {
311 WCHAR resourcestr
[256];
312 WCHAR resultstr
[256];
313 LoadStringW(COMDLG32_hInstance
, PD32_INVALID_PAGE_RANGE
, resourcestr
, 255);
314 wsprintfW(resultstr
,resourcestr
, lppd
->nMinPage
, lppd
->nMaxPage
);
315 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
, resourcestr
, 255);
316 MessageBoxW(hDlg
, resultstr
, resourcestr
, MB_OK
| MB_ICONWARNING
);
319 lppd
->nFromPage
= nFromPage
;
320 lppd
->nToPage
= nToPage
;
321 lppd
->Flags
|= PD_PAGENUMS
;
324 lppd
->Flags
&= ~PD_PAGENUMS
;
326 if (IsDlgButtonChecked(hDlg
, rad2
) == BST_CHECKED
) /* Selection */
327 lppd
->Flags
|= PD_SELECTION
;
329 lppd
->Flags
&= ~PD_SELECTION
;
331 if (IsDlgButtonChecked(hDlg
, chx1
) == BST_CHECKED
) {/* Print to file */
332 static char file
[] = "FILE:";
333 lppd
->Flags
|= PD_PRINTTOFILE
;
334 pi
->pPortName
= file
;
337 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
) { /* Collate */
338 FIXME("Collate lppd not yet implemented as output\n");
341 /* set PD_Collate and nCopies */
342 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
343 /* The application doesn't support multiple copies or collate...
345 lppd
->Flags
&= ~PD_COLLATE
;
347 /* if the printer driver supports it... store info there
348 * otherwise no collate & multiple copies !
350 if (lpdm
->dmFields
& DM_COLLATE
)
352 (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
);
353 if (lpdm
->dmFields
& DM_COPIES
)
354 lpdm
->u1
.s1
.dmCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
356 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
357 lppd
->Flags
|= PD_COLLATE
;
359 lppd
->Flags
&= ~PD_COLLATE
;
360 lppd
->nCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
363 /* Print quality, PrintDlg16 */
364 if(GetDlgItem(hDlg
, cmb1
))
366 HWND hQuality
= GetDlgItem(hDlg
, cmb1
);
367 int Sel
= SendMessageA(hQuality
, CB_GETCURSEL
, 0, 0);
371 LONG dpi
= SendMessageA(hQuality
, CB_GETITEMDATA
, Sel
, 0);
372 lpdm
->dmFields
|= DM_PRINTQUALITY
| DM_YRESOLUTION
;
373 lpdm
->u1
.s1
.dmPrintQuality
= LOWORD(dpi
);
374 lpdm
->dmYResolution
= HIWORD(dpi
);
381 static BOOL
PRINTDLG_UpdatePrintDlgW(HWND hDlg
,
382 PRINT_PTRW
* PrintStructures
)
384 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
385 PDEVMODEW lpdm
= PrintStructures
->lpDevMode
;
386 LPPRINTER_INFO_2W pi
= PrintStructures
->lpPrinterInfo
;
390 FIXME("No lpdm ptr?\n");
395 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
396 /* check whether nFromPage and nToPage are within range defined by
397 * nMinPage and nMaxPage
399 if (IsDlgButtonChecked(hDlg
, rad3
) == BST_CHECKED
) { /* Pages */
402 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
403 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
404 if (nFromPage
< lppd
->nMinPage
|| nFromPage
> lppd
->nMaxPage
||
405 nToPage
< lppd
->nMinPage
|| nToPage
> lppd
->nMaxPage
) {
406 WCHAR resourcestr
[256];
407 WCHAR resultstr
[256];
408 LoadStringW(COMDLG32_hInstance
, PD32_INVALID_PAGE_RANGE
,
410 wsprintfW(resultstr
,resourcestr
, lppd
->nMinPage
, lppd
->nMaxPage
);
411 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
,
413 MessageBoxW(hDlg
, resultstr
, resourcestr
,
414 MB_OK
| MB_ICONWARNING
);
417 lppd
->nFromPage
= nFromPage
;
418 lppd
->nToPage
= nToPage
;
419 lppd
->Flags
|= PD_PAGENUMS
;
422 lppd
->Flags
&= ~PD_PAGENUMS
;
424 if (IsDlgButtonChecked(hDlg
, rad2
) == BST_CHECKED
) /* Selection */
425 lppd
->Flags
|= PD_SELECTION
;
427 lppd
->Flags
&= ~PD_SELECTION
;
429 if (IsDlgButtonChecked(hDlg
, chx1
) == BST_CHECKED
) {/* Print to file */
430 static WCHAR file
[] = {'F','I','L','E',':',0};
431 lppd
->Flags
|= PD_PRINTTOFILE
;
432 pi
->pPortName
= file
;
435 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
) { /* Collate */
436 FIXME("Collate lppd not yet implemented as output\n");
439 /* set PD_Collate and nCopies */
440 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
441 /* The application doesn't support multiple copies or collate...
443 lppd
->Flags
&= ~PD_COLLATE
;
445 /* if the printer driver supports it... store info there
446 * otherwise no collate & multiple copies !
448 if (lpdm
->dmFields
& DM_COLLATE
)
450 (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
);
451 if (lpdm
->dmFields
& DM_COPIES
)
452 lpdm
->u1
.s1
.dmCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
454 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
455 lppd
->Flags
|= PD_COLLATE
;
457 lppd
->Flags
&= ~PD_COLLATE
;
458 lppd
->nCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
464 static BOOL
PRINTDLG_PaperSizeA(
465 PRINTDLGA
*pdlga
,const WORD PaperSize
,LPPOINT size
469 LPSTR devname
,portname
;
473 POINT
*points
= NULL
;
476 dn
= GlobalLock(pdlga
->hDevNames
);
477 dm
= GlobalLock(pdlga
->hDevMode
);
478 devname
= ((char*)dn
)+dn
->wDeviceOffset
;
479 portname
= ((char*)dn
)+dn
->wOutputOffset
;
482 NrOfEntries
= DeviceCapabilitiesA(devname
,portname
,DC_PAPERNAMES
,NULL
,dm
);
484 FIXME("No papernames found for %s/%s\n",devname
,portname
);
487 if (NrOfEntries
== -1) {
488 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
492 Words
= HeapAlloc(GetProcessHeap(),0,NrOfEntries
*sizeof(WORD
));
493 if (NrOfEntries
!= (ret
=DeviceCapabilitiesA(devname
,portname
,DC_PAPERS
,(LPSTR
)Words
,dm
))) {
494 FIXME("Number of returned vals %d is not %d\n",NrOfEntries
,ret
);
497 for (i
=0;i
<NrOfEntries
;i
++)
498 if (Words
[i
] == PaperSize
)
500 HeapFree(GetProcessHeap(),0,Words
);
501 if (i
== NrOfEntries
) {
502 FIXME("Papersize %d not found in list?\n",PaperSize
);
505 points
= HeapAlloc(GetProcessHeap(),0,sizeof(points
[0])*NrOfEntries
);
506 if (NrOfEntries
!=(ret
=DeviceCapabilitiesA(devname
,portname
,DC_PAPERSIZE
,(LPSTR
)points
,dm
))) {
507 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries
,ret
);
510 /* this is _10ths_ of a millimeter */
515 GlobalUnlock(pdlga
->hDevNames
);
516 GlobalUnlock(pdlga
->hDevMode
);
517 HeapFree(GetProcessHeap(),0,Words
);
518 HeapFree(GetProcessHeap(),0,points
);
522 static BOOL
PRINTDLG_PaperSizeW(
523 PRINTDLGW
*pdlga
,const WCHAR
*PaperSize
,LPPOINT size
527 LPWSTR devname
,portname
;
531 POINT
*points
= NULL
;
534 dn
= GlobalLock(pdlga
->hDevNames
);
535 dm
= GlobalLock(pdlga
->hDevMode
);
536 devname
= ((WCHAR
*)dn
)+dn
->wDeviceOffset
;
537 portname
= ((WCHAR
*)dn
)+dn
->wOutputOffset
;
540 NrOfEntries
= DeviceCapabilitiesW(devname
,portname
,DC_PAPERNAMES
,NULL
,dm
);
542 FIXME("No papernames found for %s/%s\n",debugstr_w(devname
),debugstr_w(portname
));
545 if (NrOfEntries
== -1) {
546 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
550 Names
= HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*NrOfEntries
*64);
551 if (NrOfEntries
!= (ret
=DeviceCapabilitiesW(devname
,portname
,DC_PAPERNAMES
,Names
,dm
))) {
552 FIXME("Number of returned vals %d is not %d\n",NrOfEntries
,ret
);
555 for (i
=0;i
<NrOfEntries
;i
++)
556 if (!lstrcmpW(PaperSize
,Names
+(64*i
)))
558 HeapFree(GetProcessHeap(),0,Names
);
559 if (i
==NrOfEntries
) {
560 FIXME("Papersize %s not found in list?\n",debugstr_w(PaperSize
));
563 points
= HeapAlloc(GetProcessHeap(),0,sizeof(points
[0])*NrOfEntries
);
564 if (NrOfEntries
!=(ret
=DeviceCapabilitiesW(devname
,portname
,DC_PAPERSIZE
,(LPWSTR
)points
,dm
))) {
565 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries
,ret
);
568 /* this is _10ths_ of a millimeter */
573 GlobalUnlock(pdlga
->hDevNames
);
574 GlobalUnlock(pdlga
->hDevMode
);
575 HeapFree(GetProcessHeap(),0,Names
);
576 HeapFree(GetProcessHeap(),0,points
);
581 /************************************************************************
582 * PRINTDLG_SetUpPaperComboBox
584 * Initialize either the papersize or inputslot combos of the Printer Setup
585 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
586 * We also try to re-select the old selection.
588 static BOOL
PRINTDLG_SetUpPaperComboBoxA(HWND hDlg
,
601 int fwCapability_Names
;
602 int fwCapability_Words
;
604 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName
,PortName
,nIDComboBox
);
606 /* query the dialog box for the current selected value */
607 Sel
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETCURSEL
, 0, 0);
609 /* we enter here only if a different printer is selected after
610 * the Print Setup dialog is opened. The current settings are
611 * stored into the newly selected printer.
613 oldWord
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
,
616 if (nIDComboBox
== cmb2
)
617 dm
->u1
.s1
.dmPaperSize
= oldWord
;
619 dm
->u1
.s1
.dmDefaultSource
= oldWord
;
623 /* we enter here only when the Print setup dialog is initially
624 * opened. In this case the settings are restored from when
625 * the dialog was last closed.
628 if (nIDComboBox
== cmb2
)
629 oldWord
= dm
->u1
.s1
.dmPaperSize
;
631 oldWord
= dm
->u1
.s1
.dmDefaultSource
;
635 if (nIDComboBox
== cmb2
) {
637 fwCapability_Names
= DC_PAPERNAMES
;
638 fwCapability_Words
= DC_PAPERS
;
642 fwCapability_Names
= DC_BINNAMES
;
643 fwCapability_Words
= DC_BINS
;
646 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
647 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
649 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
650 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
651 fwCapability_Names
, NULL
, dm
);
652 if (NrOfEntries
== 0)
653 WARN("no Name Entries found!\n");
654 else if (NrOfEntries
< 0)
657 if(DeviceCapabilitiesA(PrinterName
, PortName
, fwCapability_Words
, NULL
, dm
)
659 ERR("Number of caps is different\n");
663 Names
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(char)*NamesSize
);
664 Words
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WORD
));
665 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
666 fwCapability_Names
, Names
, dm
);
667 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
668 fwCapability_Words
, (LPSTR
)Words
, dm
);
670 /* reset any current content in the combobox */
671 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_RESETCONTENT
, 0, 0);
673 /* store new content */
674 for (i
= 0; i
< NrOfEntries
; i
++) {
675 DWORD pos
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_ADDSTRING
, 0,
676 (LPARAM
)(&Names
[i
*NamesSize
]) );
677 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_SETITEMDATA
, pos
,
681 /* Look for old selection - can't do this is previous loop since
682 item order will change as more items are added */
684 for (i
= 0; i
< NrOfEntries
; i
++) {
685 if(SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) ==
691 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_SETCURSEL
, Sel
, 0);
693 HeapFree(GetProcessHeap(),0,Words
);
694 HeapFree(GetProcessHeap(),0,Names
);
698 static BOOL
PRINTDLG_SetUpPaperComboBoxW(HWND hDlg
,
700 const WCHAR
* PrinterName
,
701 const WCHAR
* PortName
,
711 int fwCapability_Names
;
712 int fwCapability_Words
;
714 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName
),debugstr_w(PortName
),nIDComboBox
);
716 /* query the dialog box for the current selected value */
717 Sel
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETCURSEL
, 0, 0);
719 /* we enter here only if a different printer is selected after
720 * the Print Setup dialog is opened. The current settings are
721 * stored into the newly selected printer.
723 oldWord
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETITEMDATA
,
726 if (nIDComboBox
== cmb2
)
727 dm
->u1
.s1
.dmPaperSize
= oldWord
;
729 dm
->u1
.s1
.dmDefaultSource
= oldWord
;
733 /* we enter here only when the Print setup dialog is initially
734 * opened. In this case the settings are restored from when
735 * the dialog was last closed.
738 if (nIDComboBox
== cmb2
)
739 oldWord
= dm
->u1
.s1
.dmPaperSize
;
741 oldWord
= dm
->u1
.s1
.dmDefaultSource
;
745 if (nIDComboBox
== cmb2
) {
747 fwCapability_Names
= DC_PAPERNAMES
;
748 fwCapability_Words
= DC_PAPERS
;
752 fwCapability_Names
= DC_BINNAMES
;
753 fwCapability_Words
= DC_BINS
;
756 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
757 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
759 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
760 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
761 fwCapability_Names
, NULL
, dm
);
762 if (NrOfEntries
== 0)
763 WARN("no Name Entries found!\n");
764 else if (NrOfEntries
< 0)
767 if(DeviceCapabilitiesW(PrinterName
, PortName
, fwCapability_Words
, NULL
, dm
)
769 ERR("Number of caps is different\n");
773 Names
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WCHAR
)*NamesSize
);
774 Words
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WORD
));
775 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
776 fwCapability_Names
, Names
, dm
);
777 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
778 fwCapability_Words
, (LPWSTR
)Words
, dm
);
780 /* reset any current content in the combobox */
781 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_RESETCONTENT
, 0, 0);
783 /* store new content */
784 for (i
= 0; i
< NrOfEntries
; i
++) {
785 DWORD pos
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_ADDSTRING
, 0,
786 (LPARAM
)(&Names
[i
*NamesSize
]) );
787 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_SETITEMDATA
, pos
,
791 /* Look for old selection - can't do this is previous loop since
792 item order will change as more items are added */
794 for (i
= 0; i
< NrOfEntries
; i
++) {
795 if(SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) ==
801 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_SETCURSEL
, Sel
, 0);
803 HeapFree(GetProcessHeap(),0,Words
);
804 HeapFree(GetProcessHeap(),0,Names
);
809 /***********************************************************************
810 * PRINTDLG_UpdatePrinterInfoTexts [internal]
812 static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg
, const PRINTER_INFO_2A
*pi
)
815 char ResourceString
[256];
821 /* add all status messages */
822 for (i
= 0; i
< 25; i
++) {
823 if (pi
->Status
& (1<<i
)) {
824 LoadStringA(COMDLG32_hInstance
, PD32_PRINTER_STATUS_PAUSED
+i
,
825 ResourceString
, 255);
826 strcat(StatusMsg
,ResourceString
);
830 /* FIXME: status==ready must only be appended if really so.
831 but how to detect? */
832 LoadStringA(COMDLG32_hInstance
, PD32_PRINTER_STATUS_READY
,
833 ResourceString
, 255);
834 strcat(StatusMsg
,ResourceString
);
835 SetDlgItemTextA(hDlg
, stc12
, StatusMsg
);
837 /* set all other printer info texts */
838 SetDlgItemTextA(hDlg
, stc11
, pi
->pDriverName
);
840 if (pi
->pLocation
!= NULL
&& pi
->pLocation
[0] != '\0')
841 SetDlgItemTextA(hDlg
, stc14
, pi
->pLocation
);
843 SetDlgItemTextA(hDlg
, stc14
, pi
->pPortName
);
844 SetDlgItemTextA(hDlg
, stc13
, pi
->pComment
? pi
->pComment
: "");
848 static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg
, const PRINTER_INFO_2W
*pi
)
850 WCHAR StatusMsg
[256];
851 WCHAR ResourceString
[256];
852 static const WCHAR emptyW
[] = {0};
858 /* add all status messages */
859 for (i
= 0; i
< 25; i
++) {
860 if (pi
->Status
& (1<<i
)) {
861 LoadStringW(COMDLG32_hInstance
, PD32_PRINTER_STATUS_PAUSED
+i
,
862 ResourceString
, 255);
863 lstrcatW(StatusMsg
,ResourceString
);
867 /* FIXME: status==ready must only be appended if really so.
868 but how to detect? */
869 LoadStringW(COMDLG32_hInstance
, PD32_PRINTER_STATUS_READY
,
870 ResourceString
, 255);
871 lstrcatW(StatusMsg
,ResourceString
);
872 SetDlgItemTextW(hDlg
, stc12
, StatusMsg
);
874 /* set all other printer info texts */
875 SetDlgItemTextW(hDlg
, stc11
, pi
->pDriverName
);
876 if (pi
->pLocation
!= NULL
&& pi
->pLocation
[0] != '\0')
877 SetDlgItemTextW(hDlg
, stc14
, pi
->pLocation
);
879 SetDlgItemTextW(hDlg
, stc14
, pi
->pPortName
);
880 SetDlgItemTextW(hDlg
, stc13
, pi
->pComment
? pi
->pComment
: emptyW
);
884 /*******************************************************************
886 * PRINTDLG_ChangePrinter
889 BOOL
PRINTDLG_ChangePrinterA(HWND hDlg
, char *name
,
890 PRINT_PTRA
*PrintStructures
)
892 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
893 LPDEVMODEA lpdm
= NULL
;
898 HeapFree(GetProcessHeap(),0, PrintStructures
->lpPrinterInfo
);
899 HeapFree(GetProcessHeap(),0, PrintStructures
->lpDriverInfo
);
900 if(!OpenPrinterA(name
, &hprn
, NULL
)) {
901 ERR("Can't open printer %s\n", name
);
904 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
905 PrintStructures
->lpPrinterInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
906 GetPrinterA(hprn
, 2, (LPBYTE
)PrintStructures
->lpPrinterInfo
, needed
,
908 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
909 PrintStructures
->lpDriverInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
910 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)PrintStructures
->lpDriverInfo
,
912 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures
->lpPrinterInfo
->pPrinterName
);
917 PRINTDLG_UpdatePrinterInfoTextsA(hDlg
, PrintStructures
->lpPrinterInfo
);
919 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
920 PrintStructures
->lpDevMode
= NULL
;
922 dmSize
= DocumentPropertiesA(0, 0, name
, NULL
, NULL
, 0);
924 ERR("DocumentProperties fails on %s\n", debugstr_a(name
));
927 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(), 0, dmSize
);
928 dmSize
= DocumentPropertiesA(0, 0, name
, PrintStructures
->lpDevMode
, NULL
,
930 if(lppd
->hDevMode
&& (lpdm
= GlobalLock(lppd
->hDevMode
)) &&
931 !lstrcmpA( (LPSTR
) lpdm
->dmDeviceName
,
932 (LPSTR
) PrintStructures
->lpDevMode
->dmDeviceName
)) {
933 /* Supplied devicemode matches current printer so try to use it */
934 DocumentPropertiesA(0, 0, name
, PrintStructures
->lpDevMode
, lpdm
,
935 DM_OUT_BUFFER
| DM_IN_BUFFER
);
938 GlobalUnlock(lppd
->hDevMode
);
940 lpdm
= PrintStructures
->lpDevMode
; /* use this as a shortcut */
942 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
943 /* Print range (All/Range/Selection) */
944 SetDlgItemInt(hDlg
, edt1
, lppd
->nFromPage
, FALSE
);
945 SetDlgItemInt(hDlg
, edt2
, lppd
->nToPage
, FALSE
);
946 CheckRadioButton(hDlg
, rad1
, rad3
, rad1
); /* default */
947 if (lppd
->Flags
& PD_NOSELECTION
)
948 EnableWindow(GetDlgItem(hDlg
, rad2
), FALSE
);
950 if (lppd
->Flags
& PD_SELECTION
)
951 CheckRadioButton(hDlg
, rad1
, rad3
, rad2
);
952 if (lppd
->Flags
& PD_NOPAGENUMS
) {
953 EnableWindow(GetDlgItem(hDlg
, rad3
), FALSE
);
954 EnableWindow(GetDlgItem(hDlg
, stc2
),FALSE
);
955 EnableWindow(GetDlgItem(hDlg
, edt1
), FALSE
);
956 EnableWindow(GetDlgItem(hDlg
, stc3
),FALSE
);
957 EnableWindow(GetDlgItem(hDlg
, edt2
), FALSE
);
959 if (lppd
->Flags
& PD_PAGENUMS
)
960 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
965 * FIXME: The ico3 is not displayed for some reason. I don't know why.
967 if (lppd
->Flags
& PD_COLLATE
) {
968 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
969 (LPARAM
)PrintStructures
->hCollateIcon
);
970 CheckDlgButton(hDlg
, chx2
, 1);
972 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
973 (LPARAM
)PrintStructures
->hNoCollateIcon
);
974 CheckDlgButton(hDlg
, chx2
, 0);
977 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
978 /* if printer doesn't support it: no Collate */
979 if (!(lpdm
->dmFields
& DM_COLLATE
)) {
980 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
981 EnableWindow(GetDlgItem(hDlg
, ico3
), FALSE
);
988 if (lppd
->hDevMode
== 0)
989 copies
= lppd
->nCopies
;
991 copies
= lpdm
->u1
.s1
.dmCopies
;
992 if(copies
== 0) copies
= 1;
993 else if(copies
< 0) copies
= MAX_COPIES
;
994 SetDlgItemInt(hDlg
, edt3
, copies
, FALSE
);
997 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
998 /* if printer doesn't support it: no nCopies */
999 if (!(lpdm
->dmFields
& DM_COPIES
)) {
1000 EnableWindow(GetDlgItem(hDlg
, edt3
), FALSE
);
1001 EnableWindow(GetDlgItem(hDlg
, stc5
), FALSE
);
1006 CheckDlgButton(hDlg
, chx1
, (lppd
->Flags
& PD_PRINTTOFILE
) ? 1 : 0);
1007 if (lppd
->Flags
& PD_DISABLEPRINTTOFILE
)
1008 EnableWindow(GetDlgItem(hDlg
, chx1
), FALSE
);
1009 if (lppd
->Flags
& PD_HIDEPRINTTOFILE
)
1010 ShowWindow(GetDlgItem(hDlg
, chx1
), SW_HIDE
);
1012 /* Fill print quality combo, PrintDlg16 */
1013 if(GetDlgItem(hDlg
, cmb1
))
1015 DWORD numResolutions
= DeviceCapabilitiesA(PrintStructures
->lpPrinterInfo
->pPrinterName
,
1016 PrintStructures
->lpPrinterInfo
->pPortName
,
1017 DC_ENUMRESOLUTIONS
, NULL
, lpdm
);
1019 if(numResolutions
!= -1)
1021 HWND hQuality
= GetDlgItem(hDlg
, cmb1
);
1026 HDC hPrinterDC
= CreateDCA(PrintStructures
->lpPrinterInfo
->pDriverName
,
1027 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1030 Resolutions
= HeapAlloc(GetProcessHeap(), 0, numResolutions
*sizeof(LONG
)*2);
1031 DeviceCapabilitiesA(PrintStructures
->lpPrinterInfo
->pPrinterName
,
1032 PrintStructures
->lpPrinterInfo
->pPortName
,
1033 DC_ENUMRESOLUTIONS
, (LPSTR
)Resolutions
, lpdm
);
1035 dpiX
= GetDeviceCaps(hPrinterDC
, LOGPIXELSX
);
1036 dpiY
= GetDeviceCaps(hPrinterDC
, LOGPIXELSY
);
1037 DeleteDC(hPrinterDC
);
1039 SendMessageA(hQuality
, CB_RESETCONTENT
, 0, 0);
1040 for(i
= 0; i
< (numResolutions
* 2); i
+= 2)
1042 BOOL IsDefault
= FALSE
;
1045 if(Resolutions
[i
] == Resolutions
[i
+1])
1047 if(dpiX
== Resolutions
[i
])
1049 sprintf(buf
, "%d dpi", Resolutions
[i
]);
1052 if(dpiX
== Resolutions
[i
] && dpiY
== Resolutions
[i
+1])
1054 sprintf(buf
, "%d dpi x %d dpi", Resolutions
[i
], Resolutions
[i
+1]);
1057 Index
= SendMessageA(hQuality
, CB_ADDSTRING
, 0, (LPARAM
)buf
);
1060 SendMessageA(hQuality
, CB_SETCURSEL
, Index
, 0);
1062 SendMessageA(hQuality
, CB_SETITEMDATA
, Index
, MAKELONG(dpiX
,dpiY
));
1064 HeapFree(GetProcessHeap(), 0, Resolutions
);
1067 } else { /* PD_PRINTSETUP */
1068 BOOL bPortrait
= (lpdm
->u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
);
1070 PRINTDLG_SetUpPaperComboBoxA(hDlg
, cmb2
,
1071 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1072 PrintStructures
->lpPrinterInfo
->pPortName
,
1074 PRINTDLG_SetUpPaperComboBoxA(hDlg
, cmb3
,
1075 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1076 PrintStructures
->lpPrinterInfo
->pPortName
,
1078 CheckRadioButton(hDlg
, rad1
, rad2
, bPortrait
? rad1
: rad2
);
1079 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1080 (LPARAM
)(bPortrait
? PrintStructures
->hPortraitIcon
:
1081 PrintStructures
->hLandscapeIcon
));
1086 if ((lppd
->Flags
& PD_SHOWHELP
)==0) {
1087 /* hide if PD_SHOWHELP not specified */
1088 ShowWindow(GetDlgItem(hDlg
, pshHelp
), SW_HIDE
);
1093 static BOOL
PRINTDLG_ChangePrinterW(HWND hDlg
, WCHAR
*name
,
1094 PRINT_PTRW
*PrintStructures
)
1096 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1097 LPDEVMODEW lpdm
= NULL
;
1102 HeapFree(GetProcessHeap(),0, PrintStructures
->lpPrinterInfo
);
1103 HeapFree(GetProcessHeap(),0, PrintStructures
->lpDriverInfo
);
1104 if(!OpenPrinterW(name
, &hprn
, NULL
)) {
1105 ERR("Can't open printer %s\n", debugstr_w(name
));
1108 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
1109 PrintStructures
->lpPrinterInfo
= HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*needed
);
1110 GetPrinterW(hprn
, 2, (LPBYTE
)PrintStructures
->lpPrinterInfo
, needed
,
1112 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
1113 PrintStructures
->lpDriverInfo
= HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*needed
);
1114 if (!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)PrintStructures
->lpDriverInfo
,
1116 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures
->lpPrinterInfo
->pPrinterName
));
1121 PRINTDLG_UpdatePrinterInfoTextsW(hDlg
, PrintStructures
->lpPrinterInfo
);
1123 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
1124 PrintStructures
->lpDevMode
= NULL
;
1126 dmSize
= DocumentPropertiesW(0, 0, name
, NULL
, NULL
, 0);
1128 ERR("DocumentProperties fails on %s\n", debugstr_w(name
));
1131 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(), 0, dmSize
);
1132 dmSize
= DocumentPropertiesW(0, 0, name
, PrintStructures
->lpDevMode
, NULL
,
1134 if(lppd
->hDevMode
&& (lpdm
= GlobalLock(lppd
->hDevMode
)) &&
1135 !lstrcmpW(lpdm
->dmDeviceName
,
1136 PrintStructures
->lpDevMode
->dmDeviceName
)) {
1137 /* Supplied devicemode matches current printer so try to use it */
1138 DocumentPropertiesW(0, 0, name
, PrintStructures
->lpDevMode
, lpdm
,
1139 DM_OUT_BUFFER
| DM_IN_BUFFER
);
1142 GlobalUnlock(lppd
->hDevMode
);
1144 lpdm
= PrintStructures
->lpDevMode
; /* use this as a shortcut */
1146 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
1147 /* Print range (All/Range/Selection) */
1148 SetDlgItemInt(hDlg
, edt1
, lppd
->nFromPage
, FALSE
);
1149 SetDlgItemInt(hDlg
, edt2
, lppd
->nToPage
, FALSE
);
1150 CheckRadioButton(hDlg
, rad1
, rad3
, rad1
); /* default */
1151 if (lppd
->Flags
& PD_NOSELECTION
)
1152 EnableWindow(GetDlgItem(hDlg
, rad2
), FALSE
);
1154 if (lppd
->Flags
& PD_SELECTION
)
1155 CheckRadioButton(hDlg
, rad1
, rad3
, rad2
);
1156 if (lppd
->Flags
& PD_NOPAGENUMS
) {
1157 EnableWindow(GetDlgItem(hDlg
, rad3
), FALSE
);
1158 EnableWindow(GetDlgItem(hDlg
, stc2
),FALSE
);
1159 EnableWindow(GetDlgItem(hDlg
, edt1
), FALSE
);
1160 EnableWindow(GetDlgItem(hDlg
, stc3
),FALSE
);
1161 EnableWindow(GetDlgItem(hDlg
, edt2
), FALSE
);
1163 if (lppd
->Flags
& PD_PAGENUMS
)
1164 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1169 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1171 if (lppd
->Flags
& PD_COLLATE
) {
1172 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1173 (LPARAM
)PrintStructures
->hCollateIcon
);
1174 CheckDlgButton(hDlg
, chx2
, 1);
1176 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1177 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1178 CheckDlgButton(hDlg
, chx2
, 0);
1181 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1182 /* if printer doesn't support it: no Collate */
1183 if (!(lpdm
->dmFields
& DM_COLLATE
)) {
1184 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1185 EnableWindow(GetDlgItem(hDlg
, ico3
), FALSE
);
1192 if (lppd
->hDevMode
== 0)
1193 copies
= lppd
->nCopies
;
1195 copies
= lpdm
->u1
.s1
.dmCopies
;
1196 if(copies
== 0) copies
= 1;
1197 else if(copies
< 0) copies
= MAX_COPIES
;
1198 SetDlgItemInt(hDlg
, edt3
, copies
, FALSE
);
1201 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1202 /* if printer doesn't support it: no nCopies */
1203 if (!(lpdm
->dmFields
& DM_COPIES
)) {
1204 EnableWindow(GetDlgItem(hDlg
, edt3
), FALSE
);
1205 EnableWindow(GetDlgItem(hDlg
, stc5
), FALSE
);
1210 CheckDlgButton(hDlg
, chx1
, (lppd
->Flags
& PD_PRINTTOFILE
) ? 1 : 0);
1211 if (lppd
->Flags
& PD_DISABLEPRINTTOFILE
)
1212 EnableWindow(GetDlgItem(hDlg
, chx1
), FALSE
);
1213 if (lppd
->Flags
& PD_HIDEPRINTTOFILE
)
1214 ShowWindow(GetDlgItem(hDlg
, chx1
), SW_HIDE
);
1216 } else { /* PD_PRINTSETUP */
1217 BOOL bPortrait
= (lpdm
->u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
);
1219 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb2
,
1220 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1221 PrintStructures
->lpPrinterInfo
->pPortName
,
1223 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb3
,
1224 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1225 PrintStructures
->lpPrinterInfo
->pPortName
,
1227 CheckRadioButton(hDlg
, rad1
, rad2
, bPortrait
? rad1
: rad2
);
1228 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1229 (LPARAM
)(bPortrait
? PrintStructures
->hPortraitIcon
:
1230 PrintStructures
->hLandscapeIcon
));
1235 if ((lppd
->Flags
& PD_SHOWHELP
)==0) {
1236 /* hide if PD_SHOWHELP not specified */
1237 ShowWindow(GetDlgItem(hDlg
, pshHelp
), SW_HIDE
);
1242 /***********************************************************************
1243 * check_printer_setup [internal]
1245 static LRESULT
check_printer_setup(HWND hDlg
)
1248 WCHAR resourcestr
[256],resultstr
[256];
1251 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
1254 EnumPrintersW(PRINTER_ENUM_CONNECTIONS
, NULL
, 2, NULL
, 0, &needed
, &num
);
1260 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEVICES
,resultstr
, 255);
1261 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
,resourcestr
, 255);
1262 res
= MessageBoxW(hDlg
, resultstr
, resourcestr
,MB_OK
| MB_ICONWARNING
);
1267 /***********************************************************************
1268 * PRINTDLG_WMInitDialog [internal]
1270 static LRESULT
PRINTDLG_WMInitDialog(HWND hDlg
, WPARAM wParam
,
1271 PRINT_PTRA
* PrintStructures
)
1273 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1277 UINT comboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1279 /* load Collate ICONs */
1280 /* We load these with LoadImage because they are not a standard
1281 size and we don't want them rescaled */
1282 PrintStructures
->hCollateIcon
=
1283 LoadImageA(COMDLG32_hInstance
, "PD32_COLLATE", IMAGE_ICON
, 0, 0, 0);
1284 PrintStructures
->hNoCollateIcon
=
1285 LoadImageA(COMDLG32_hInstance
, "PD32_NOCOLLATE", IMAGE_ICON
, 0, 0, 0);
1287 /* These can be done with LoadIcon */
1288 PrintStructures
->hPortraitIcon
=
1289 LoadIconA(COMDLG32_hInstance
, "PD32_PORTRAIT");
1290 PrintStructures
->hLandscapeIcon
=
1291 LoadIconA(COMDLG32_hInstance
, "PD32_LANDSCAPE");
1293 /* display the collate/no_collate icon */
1294 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1295 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1297 if(PrintStructures
->hCollateIcon
== 0 ||
1298 PrintStructures
->hNoCollateIcon
== 0 ||
1299 PrintStructures
->hPortraitIcon
== 0 ||
1300 PrintStructures
->hLandscapeIcon
== 0) {
1301 ERR("no icon in resourcefile\n");
1302 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1303 EndDialog(hDlg
, FALSE
);
1307 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1308 * must be registered and the Help button must be shown.
1310 if (lppd
->Flags
& PD_SHOWHELP
) {
1311 if((PrintStructures
->HelpMessageID
=
1312 RegisterWindowMessageA(HELPMSGSTRINGA
)) == 0) {
1313 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL
);
1317 PrintStructures
->HelpMessageID
= 0;
1319 if(!(lppd
->Flags
&PD_PRINTSETUP
)) {
1320 PrintStructures
->hwndUpDown
=
1321 CreateUpDownControl(WS_CHILD
| WS_VISIBLE
| WS_BORDER
|
1322 UDS_NOTHOUSANDS
| UDS_ARROWKEYS
|
1323 UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, 0, 0, 0, 0,
1324 hDlg
, UPDOWN_ID
, COMDLG32_hInstance
,
1325 GetDlgItem(hDlg
, edt3
), MAX_COPIES
, 1, 1);
1328 /* FIXME: I allow more freedom than either Win95 or WinNT,
1329 * which do not agree to what errors should be thrown or not
1330 * in case nToPage or nFromPage is out-of-range.
1332 if (lppd
->nMaxPage
< lppd
->nMinPage
)
1333 lppd
->nMaxPage
= lppd
->nMinPage
;
1334 if (lppd
->nMinPage
== lppd
->nMaxPage
)
1335 lppd
->Flags
|= PD_NOPAGENUMS
;
1336 if (lppd
->nToPage
< lppd
->nMinPage
)
1337 lppd
->nToPage
= lppd
->nMinPage
;
1338 if (lppd
->nToPage
> lppd
->nMaxPage
)
1339 lppd
->nToPage
= lppd
->nMaxPage
;
1340 if (lppd
->nFromPage
< lppd
->nMinPage
)
1341 lppd
->nFromPage
= lppd
->nMinPage
;
1342 if (lppd
->nFromPage
> lppd
->nMaxPage
)
1343 lppd
->nFromPage
= lppd
->nMaxPage
;
1345 /* if we have the combo box, fill it */
1346 if (GetDlgItem(hDlg
,comboID
)) {
1349 pdn
= GlobalLock(lppd
->hDevNames
);
1350 pdm
= GlobalLock(lppd
->hDevMode
);
1352 name
= (char*)pdn
+ pdn
->wDeviceOffset
;
1354 name
= (char*)pdm
->dmDeviceName
;
1355 PRINTDLG_SetUpPrinterListComboA(hDlg
, comboID
, name
);
1356 if(pdm
) GlobalUnlock(lppd
->hDevMode
);
1357 if(pdn
) GlobalUnlock(lppd
->hDevNames
);
1359 /* Now find selected printer and update rest of dlg */
1360 name
= HeapAlloc(GetProcessHeap(),0,256);
1361 if (GetDlgItemTextA(hDlg
, comboID
, name
, 255))
1362 PRINTDLG_ChangePrinterA(hDlg
, name
, PrintStructures
);
1363 HeapFree(GetProcessHeap(),0,name
);
1365 /* else use default printer */
1367 DWORD dwBufLen
= sizeof(name
);
1368 BOOL ret
= GetDefaultPrinterA(name
, &dwBufLen
);
1371 PRINTDLG_ChangePrinterA(hDlg
, name
, PrintStructures
);
1373 FIXME("No default printer found, expect problems!\n");
1378 static LRESULT
PRINTDLG_WMInitDialogW(HWND hDlg
, WPARAM wParam
,
1379 PRINT_PTRW
* PrintStructures
)
1381 static const WCHAR PD32_COLLATE
[] = { 'P', 'D', '3', '2', '_', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
1382 static const WCHAR PD32_NOCOLLATE
[] = { 'P', 'D', '3', '2', '_', 'N', 'O', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
1383 static const WCHAR PD32_PORTRAIT
[] = { 'P', 'D', '3', '2', '_', 'P', 'O', 'R', 'T', 'R', 'A', 'I', 'T', 0 };
1384 static const WCHAR PD32_LANDSCAPE
[] = { 'P', 'D', '3', '2', '_', 'L', 'A', 'N', 'D', 'S', 'C', 'A', 'P', 'E', 0 };
1385 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1389 UINT comboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1391 /* load Collate ICONs */
1392 /* We load these with LoadImage because they are not a standard
1393 size and we don't want them rescaled */
1394 PrintStructures
->hCollateIcon
=
1395 LoadImageW(COMDLG32_hInstance
, PD32_COLLATE
, IMAGE_ICON
, 0, 0, 0);
1396 PrintStructures
->hNoCollateIcon
=
1397 LoadImageW(COMDLG32_hInstance
, PD32_NOCOLLATE
, IMAGE_ICON
, 0, 0, 0);
1399 /* These can be done with LoadIcon */
1400 PrintStructures
->hPortraitIcon
=
1401 LoadIconW(COMDLG32_hInstance
, PD32_PORTRAIT
);
1402 PrintStructures
->hLandscapeIcon
=
1403 LoadIconW(COMDLG32_hInstance
, PD32_LANDSCAPE
);
1405 /* display the collate/no_collate icon */
1406 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1407 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1409 if(PrintStructures
->hCollateIcon
== 0 ||
1410 PrintStructures
->hNoCollateIcon
== 0 ||
1411 PrintStructures
->hPortraitIcon
== 0 ||
1412 PrintStructures
->hLandscapeIcon
== 0) {
1413 ERR("no icon in resourcefile\n");
1414 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1415 EndDialog(hDlg
, FALSE
);
1419 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1420 * must be registered and the Help button must be shown.
1422 if (lppd
->Flags
& PD_SHOWHELP
) {
1423 if((PrintStructures
->HelpMessageID
=
1424 RegisterWindowMessageW(HELPMSGSTRINGW
)) == 0) {
1425 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL
);
1429 PrintStructures
->HelpMessageID
= 0;
1431 if(!(lppd
->Flags
&PD_PRINTSETUP
)) {
1432 PrintStructures
->hwndUpDown
=
1433 CreateUpDownControl(WS_CHILD
| WS_VISIBLE
| WS_BORDER
|
1434 UDS_NOTHOUSANDS
| UDS_ARROWKEYS
|
1435 UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, 0, 0, 0, 0,
1436 hDlg
, UPDOWN_ID
, COMDLG32_hInstance
,
1437 GetDlgItem(hDlg
, edt3
), MAX_COPIES
, 1, 1);
1440 /* FIXME: I allow more freedom than either Win95 or WinNT,
1441 * which do not agree to what errors should be thrown or not
1442 * in case nToPage or nFromPage is out-of-range.
1444 if (lppd
->nMaxPage
< lppd
->nMinPage
)
1445 lppd
->nMaxPage
= lppd
->nMinPage
;
1446 if (lppd
->nMinPage
== lppd
->nMaxPage
)
1447 lppd
->Flags
|= PD_NOPAGENUMS
;
1448 if (lppd
->nToPage
< lppd
->nMinPage
)
1449 lppd
->nToPage
= lppd
->nMinPage
;
1450 if (lppd
->nToPage
> lppd
->nMaxPage
)
1451 lppd
->nToPage
= lppd
->nMaxPage
;
1452 if (lppd
->nFromPage
< lppd
->nMinPage
)
1453 lppd
->nFromPage
= lppd
->nMinPage
;
1454 if (lppd
->nFromPage
> lppd
->nMaxPage
)
1455 lppd
->nFromPage
= lppd
->nMaxPage
;
1457 /* if we have the combo box, fill it */
1458 if (GetDlgItem(hDlg
,comboID
)) {
1461 pdn
= GlobalLock(lppd
->hDevNames
);
1462 pdm
= GlobalLock(lppd
->hDevMode
);
1464 name
= (WCHAR
*)pdn
+ pdn
->wDeviceOffset
;
1466 name
= pdm
->dmDeviceName
;
1467 PRINTDLG_SetUpPrinterListComboW(hDlg
, comboID
, name
);
1468 if(pdm
) GlobalUnlock(lppd
->hDevMode
);
1469 if(pdn
) GlobalUnlock(lppd
->hDevNames
);
1471 /* Now find selected printer and update rest of dlg */
1472 /* ansi is ok here */
1473 name
= HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR
));
1474 if (GetDlgItemTextW(hDlg
, comboID
, name
, 255))
1475 PRINTDLG_ChangePrinterW(hDlg
, name
, PrintStructures
);
1476 HeapFree(GetProcessHeap(),0,name
);
1478 /* else use default printer */
1480 DWORD dwBufLen
= sizeof(name
) / sizeof(WCHAR
);
1481 BOOL ret
= GetDefaultPrinterW(name
, &dwBufLen
);
1484 PRINTDLG_ChangePrinterW(hDlg
, name
, PrintStructures
);
1486 FIXME("No default printer found, expect problems!\n");
1491 /***********************************************************************
1492 * PRINTDLG_WMCommand [internal]
1494 LRESULT
PRINTDLG_WMCommandA(HWND hDlg
, WPARAM wParam
,
1495 LPARAM lParam
, PRINT_PTRA
* PrintStructures
)
1497 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1498 UINT PrinterComboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1499 LPDEVMODEA lpdm
= PrintStructures
->lpDevMode
;
1501 switch (LOWORD(wParam
)) {
1503 TRACE(" OK button was hit\n");
1504 if (!PRINTDLG_UpdatePrintDlgA(hDlg
, PrintStructures
)) {
1505 FIXME("Update printdlg was not successful!\n");
1508 EndDialog(hDlg
, TRUE
);
1512 TRACE(" CANCEL button was hit\n");
1513 EndDialog(hDlg
, FALSE
);
1517 TRACE(" HELP button was hit\n");
1518 SendMessageA(lppd
->hwndOwner
, PrintStructures
->HelpMessageID
,
1519 (WPARAM
) hDlg
, (LPARAM
) lppd
);
1522 case chx2
: /* collate pages checkbox */
1523 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
1524 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1525 (LPARAM
)PrintStructures
->hCollateIcon
);
1527 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1528 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1530 case edt1
: /* from page nr editbox */
1531 case edt2
: /* to page nr editbox */
1532 if (HIWORD(wParam
)==EN_CHANGE
) {
1535 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
1536 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
1537 if (nFromPage
!= lppd
->nFromPage
|| nToPage
!= lppd
->nToPage
)
1538 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1543 if(HIWORD(wParam
) == EN_CHANGE
) {
1544 INT copies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
1546 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1548 EnableWindow(GetDlgItem(hDlg
, chx2
), TRUE
);
1553 case psh1
: /* Print Setup */
1557 if (!PrintStructures
->dlg
.lpPrintDlg16
) {
1558 FIXME("The 32bit print dialog does not have this button!?\n");
1562 memcpy(&pdlg
,PrintStructures
->dlg
.lpPrintDlg16
,sizeof(pdlg
));
1563 pdlg
.Flags
|= PD_PRINTSETUP
;
1564 pdlg
.hwndOwner
= HWND_16(hDlg
);
1565 if (!PrintDlg16(&pdlg
))
1570 case psh2
: /* Properties button */
1573 char PrinterName
[256];
1575 GetDlgItemTextA(hDlg
, PrinterComboID
, PrinterName
, 255);
1576 if (!OpenPrinterA(PrinterName
, &hPrinter
, NULL
)) {
1577 FIXME(" Call to OpenPrinter did not succeed!\n");
1580 DocumentPropertiesA(hDlg
, hPrinter
, PrinterName
,
1581 PrintStructures
->lpDevMode
,
1582 PrintStructures
->lpDevMode
,
1583 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
1584 ClosePrinter(hPrinter
);
1588 case rad1
: /* Paperorientation */
1589 if (lppd
->Flags
& PD_PRINTSETUP
)
1591 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1592 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1593 (LPARAM
)(PrintStructures
->hPortraitIcon
));
1597 case rad2
: /* Paperorientation */
1598 if (lppd
->Flags
& PD_PRINTSETUP
)
1600 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1601 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1602 (LPARAM
)(PrintStructures
->hLandscapeIcon
));
1606 case cmb1
: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT16 */
1607 if (PrinterComboID
!= LOWORD(wParam
)) {
1611 case cmb4
: /* Printer combobox */
1612 if (HIWORD(wParam
)==CBN_SELCHANGE
) {
1613 char PrinterName
[256];
1614 GetDlgItemTextA(hDlg
, LOWORD(wParam
), PrinterName
, 255);
1615 PRINTDLG_ChangePrinterA(hDlg
, PrinterName
, PrintStructures
);
1619 case cmb2
: /* Papersize */
1621 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
1623 lpdm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageA(hDlg
, cmb2
,
1629 case cmb3
: /* Bin */
1631 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
1633 lpdm
->u1
.s1
.dmDefaultSource
= SendDlgItemMessageA(hDlg
, cmb3
,
1634 CB_GETITEMDATA
, Sel
,
1639 if(lppd
->Flags
& PD_PRINTSETUP
) {
1640 switch (LOWORD(wParam
)) {
1641 case rad1
: /* orientation */
1643 if (IsDlgButtonChecked(hDlg
, rad1
) == BST_CHECKED
) {
1644 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_PORTRAIT
) {
1645 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1646 SendDlgItemMessageA(hDlg
, stc10
, STM_SETIMAGE
,
1648 (LPARAM
)PrintStructures
->hPortraitIcon
);
1649 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
,
1651 (LPARAM
)PrintStructures
->hPortraitIcon
);
1654 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_LANDSCAPE
) {
1655 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1656 SendDlgItemMessageA(hDlg
, stc10
, STM_SETIMAGE
,
1658 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1659 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
,
1661 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1670 static LRESULT
PRINTDLG_WMCommandW(HWND hDlg
, WPARAM wParam
,
1671 LPARAM lParam
, PRINT_PTRW
* PrintStructures
)
1673 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1674 UINT PrinterComboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1675 LPDEVMODEW lpdm
= PrintStructures
->lpDevMode
;
1677 switch (LOWORD(wParam
)) {
1679 TRACE(" OK button was hit\n");
1680 if (!PRINTDLG_UpdatePrintDlgW(hDlg
, PrintStructures
)) {
1681 FIXME("Update printdlg was not successful!\n");
1684 EndDialog(hDlg
, TRUE
);
1688 TRACE(" CANCEL button was hit\n");
1689 EndDialog(hDlg
, FALSE
);
1693 TRACE(" HELP button was hit\n");
1694 SendMessageW(lppd
->hwndOwner
, PrintStructures
->HelpMessageID
,
1695 (WPARAM
) hDlg
, (LPARAM
) lppd
);
1698 case chx2
: /* collate pages checkbox */
1699 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
1700 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1701 (LPARAM
)PrintStructures
->hCollateIcon
);
1703 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1704 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1706 case edt1
: /* from page nr editbox */
1707 case edt2
: /* to page nr editbox */
1708 if (HIWORD(wParam
)==EN_CHANGE
) {
1711 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
1712 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
1713 if (nFromPage
!= lppd
->nFromPage
|| nToPage
!= lppd
->nToPage
)
1714 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1719 if(HIWORD(wParam
) == EN_CHANGE
) {
1720 INT copies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
1722 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1724 EnableWindow(GetDlgItem(hDlg
, chx2
), TRUE
);
1728 case psh1
: /* Print Setup */
1730 ERR("psh1 is called from 16bit code only, we should not get here.\n");
1733 case psh2
: /* Properties button */
1736 WCHAR PrinterName
[256];
1738 if (!GetDlgItemTextW(hDlg
, PrinterComboID
, PrinterName
, 255)) break;
1739 if (!OpenPrinterW(PrinterName
, &hPrinter
, NULL
)) {
1740 FIXME(" Call to OpenPrinter did not succeed!\n");
1743 DocumentPropertiesW(hDlg
, hPrinter
, PrinterName
,
1744 PrintStructures
->lpDevMode
,
1745 PrintStructures
->lpDevMode
,
1746 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
1747 ClosePrinter(hPrinter
);
1751 case rad1
: /* Paperorientation */
1752 if (lppd
->Flags
& PD_PRINTSETUP
)
1754 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1755 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1756 (LPARAM
)(PrintStructures
->hPortraitIcon
));
1760 case rad2
: /* Paperorientation */
1761 if (lppd
->Flags
& PD_PRINTSETUP
)
1763 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1764 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1765 (LPARAM
)(PrintStructures
->hLandscapeIcon
));
1769 case cmb1
: /* Printer Combobox in PRINT SETUP */
1771 case cmb4
: /* Printer combobox */
1772 if (HIWORD(wParam
)==CBN_SELCHANGE
) {
1773 WCHAR PrinterName
[256];
1774 GetDlgItemTextW(hDlg
, LOWORD(wParam
), PrinterName
, 255);
1775 PRINTDLG_ChangePrinterW(hDlg
, PrinterName
, PrintStructures
);
1779 case cmb2
: /* Papersize */
1781 DWORD Sel
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
1783 lpdm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageW(hDlg
, cmb2
,
1789 case cmb3
: /* Bin */
1791 DWORD Sel
= SendDlgItemMessageW(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
1793 lpdm
->u1
.s1
.dmDefaultSource
= SendDlgItemMessageW(hDlg
, cmb3
,
1794 CB_GETITEMDATA
, Sel
,
1799 if(lppd
->Flags
& PD_PRINTSETUP
) {
1800 switch (LOWORD(wParam
)) {
1801 case rad1
: /* orientation */
1803 if (IsDlgButtonChecked(hDlg
, rad1
) == BST_CHECKED
) {
1804 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_PORTRAIT
) {
1805 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1806 SendDlgItemMessageW(hDlg
, stc10
, STM_SETIMAGE
,
1808 (LPARAM
)PrintStructures
->hPortraitIcon
);
1809 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
,
1811 (LPARAM
)PrintStructures
->hPortraitIcon
);
1814 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_LANDSCAPE
) {
1815 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1816 SendDlgItemMessageW(hDlg
, stc10
, STM_SETIMAGE
,
1818 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1819 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
,
1821 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1830 /***********************************************************************
1831 * PrintDlgProcA [internal]
1833 static INT_PTR CALLBACK
PrintDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
1836 PRINT_PTRA
* PrintStructures
;
1837 INT_PTR res
= FALSE
;
1839 if (uMsg
!=WM_INITDIALOG
) {
1840 PrintStructures
= (PRINT_PTRA
*)GetPropA(hDlg
,"__WINE_PRINTDLGDATA");
1841 if (!PrintStructures
)
1844 PrintStructures
= (PRINT_PTRA
*) lParam
;
1845 SetPropA(hDlg
,"__WINE_PRINTDLGDATA",PrintStructures
);
1846 if(!check_printer_setup(hDlg
))
1848 EndDialog(hDlg
,FALSE
);
1851 res
= PRINTDLG_WMInitDialog(hDlg
, wParam
, PrintStructures
);
1853 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
)
1854 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(
1855 hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->lpPrintDlg
1860 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
) {
1861 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
,uMsg
,wParam
,
1868 return PRINTDLG_WMCommandA(hDlg
, wParam
, lParam
, PrintStructures
);
1871 DestroyIcon(PrintStructures
->hCollateIcon
);
1872 DestroyIcon(PrintStructures
->hNoCollateIcon
);
1873 DestroyIcon(PrintStructures
->hPortraitIcon
);
1874 DestroyIcon(PrintStructures
->hLandscapeIcon
);
1875 if(PrintStructures
->hwndUpDown
)
1876 DestroyWindow(PrintStructures
->hwndUpDown
);
1882 static INT_PTR CALLBACK
PrintDlgProcW(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
1885 static const WCHAR propW
[] = {'_','_','W','I','N','E','_','P','R','I','N','T','D','L','G','D','A','T','A',0};
1886 PRINT_PTRW
* PrintStructures
;
1887 INT_PTR res
= FALSE
;
1889 if (uMsg
!=WM_INITDIALOG
) {
1890 PrintStructures
= (PRINT_PTRW
*) GetPropW(hDlg
, propW
);
1891 if (!PrintStructures
)
1894 PrintStructures
= (PRINT_PTRW
*) lParam
;
1895 SetPropW(hDlg
, propW
, PrintStructures
);
1896 if(!check_printer_setup(hDlg
))
1898 EndDialog(hDlg
,FALSE
);
1901 res
= PRINTDLG_WMInitDialogW(hDlg
, wParam
, PrintStructures
);
1903 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
)
1904 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->lpPrintDlg
);
1908 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
) {
1909 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
,uMsg
,wParam
, lParam
);
1915 return PRINTDLG_WMCommandW(hDlg
, wParam
, lParam
, PrintStructures
);
1918 DestroyIcon(PrintStructures
->hCollateIcon
);
1919 DestroyIcon(PrintStructures
->hNoCollateIcon
);
1920 DestroyIcon(PrintStructures
->hPortraitIcon
);
1921 DestroyIcon(PrintStructures
->hLandscapeIcon
);
1922 if(PrintStructures
->hwndUpDown
)
1923 DestroyWindow(PrintStructures
->hwndUpDown
);
1929 /************************************************************
1931 * PRINTDLG_GetDlgTemplate
1934 static HGLOBAL
PRINTDLG_GetDlgTemplateA(const PRINTDLGA
*lppd
)
1939 if (lppd
->Flags
& PD_PRINTSETUP
) {
1940 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
1941 hDlgTmpl
= lppd
->hSetupTemplate
;
1942 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
1943 hResInfo
= FindResourceA(lppd
->hInstance
,
1944 lppd
->lpSetupTemplateName
, (LPSTR
)RT_DIALOG
);
1945 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1947 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32_SETUP",
1949 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1952 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
1953 hDlgTmpl
= lppd
->hPrintTemplate
;
1954 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
1955 hResInfo
= FindResourceA(lppd
->hInstance
,
1956 lppd
->lpPrintTemplateName
,
1958 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1960 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32",
1962 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1968 static HGLOBAL
PRINTDLG_GetDlgTemplateW(const PRINTDLGW
*lppd
)
1972 static const WCHAR xpsetup
[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
1973 static const WCHAR xprint
[] = { 'P','R','I','N','T','3','2',0};
1975 if (lppd
->Flags
& PD_PRINTSETUP
) {
1976 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
1977 hDlgTmpl
= lppd
->hSetupTemplate
;
1978 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
1979 hResInfo
= FindResourceW(lppd
->hInstance
,
1980 lppd
->lpSetupTemplateName
, (LPWSTR
)RT_DIALOG
);
1981 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1983 hResInfo
= FindResourceW(COMDLG32_hInstance
, xpsetup
, (LPWSTR
)RT_DIALOG
);
1984 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1987 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
1988 hDlgTmpl
= lppd
->hPrintTemplate
;
1989 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
1990 hResInfo
= FindResourceW(lppd
->hInstance
,
1991 lppd
->lpPrintTemplateName
,
1993 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1995 hResInfo
= FindResourceW(COMDLG32_hInstance
, xprint
, (LPWSTR
)RT_DIALOG
);
1996 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
2002 /***********************************************************************
2007 static BOOL
PRINTDLG_CreateDCA(LPPRINTDLGA lppd
)
2009 DEVNAMES
*pdn
= GlobalLock(lppd
->hDevNames
);
2010 DEVMODEA
*pdm
= GlobalLock(lppd
->hDevMode
);
2012 if(lppd
->Flags
& PD_RETURNDC
) {
2013 lppd
->hDC
= CreateDCA((char*)pdn
+ pdn
->wDriverOffset
,
2014 (char*)pdn
+ pdn
->wDeviceOffset
,
2015 (char*)pdn
+ pdn
->wOutputOffset
,
2017 } else if(lppd
->Flags
& PD_RETURNIC
) {
2018 lppd
->hDC
= CreateICA((char*)pdn
+ pdn
->wDriverOffset
,
2019 (char*)pdn
+ pdn
->wDeviceOffset
,
2020 (char*)pdn
+ pdn
->wOutputOffset
,
2023 GlobalUnlock(lppd
->hDevNames
);
2024 GlobalUnlock(lppd
->hDevMode
);
2025 return lppd
->hDC
? TRUE
: FALSE
;
2028 static BOOL
PRINTDLG_CreateDCW(LPPRINTDLGW lppd
)
2030 DEVNAMES
*pdn
= GlobalLock(lppd
->hDevNames
);
2031 DEVMODEW
*pdm
= GlobalLock(lppd
->hDevMode
);
2033 if(lppd
->Flags
& PD_RETURNDC
) {
2034 lppd
->hDC
= CreateDCW((WCHAR
*)pdn
+ pdn
->wDriverOffset
,
2035 (WCHAR
*)pdn
+ pdn
->wDeviceOffset
,
2036 (WCHAR
*)pdn
+ pdn
->wOutputOffset
,
2038 } else if(lppd
->Flags
& PD_RETURNIC
) {
2039 lppd
->hDC
= CreateICW((WCHAR
*)pdn
+ pdn
->wDriverOffset
,
2040 (WCHAR
*)pdn
+ pdn
->wDeviceOffset
,
2041 (WCHAR
*)pdn
+ pdn
->wOutputOffset
,
2044 GlobalUnlock(lppd
->hDevNames
);
2045 GlobalUnlock(lppd
->hDevMode
);
2046 return lppd
->hDC
? TRUE
: FALSE
;
2049 /***********************************************************************
2050 * PrintDlgA (COMDLG32.@)
2052 * Displays the PRINT dialog box, which enables the user to specify
2053 * specific properties of the print job.
2056 * lppd [IO] ptr to PRINTDLG32 struct
2059 * nonzero if the user pressed the OK button
2060 * zero if the user cancelled the window or an error occurred
2064 * * The Collate Icons do not display, even though they are in the code.
2065 * * The Properties Button(s) should call DocumentPropertiesA().
2068 BOOL WINAPI
PrintDlgA(LPPRINTDLGA lppd
)
2076 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
2080 hInst
= (HINSTANCE
)GetWindowLongPtrA( lppd
->hwndOwner
, GWLP_HINSTANCE
);
2081 if(TRACE_ON(commdlg
)) {
2082 char flagstr
[1000] = "";
2083 const struct pd_flags
*pflag
= pd_flags
;
2084 for( ; pflag
->name
; pflag
++) {
2085 if(lppd
->Flags
& pflag
->flag
)
2086 strcat(flagstr
, pflag
->name
);
2088 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2089 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2090 "flags %08x (%s)\n",
2091 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
2092 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
2093 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
2096 if(lppd
->lStructSize
!= sizeof(PRINTDLGA
)) {
2097 WARN("structure size failure !!!\n");
2098 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
2102 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
2103 PRINTER_INFO_2A
*pbuf
;
2104 DRIVER_INFO_3A
*dbuf
;
2108 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
2109 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2110 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2113 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
2114 WARN("Can't find default printer\n");
2115 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
2119 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
2120 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
2121 GetPrinterA(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
2123 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
2124 dbuf
= HeapAlloc(GetProcessHeap(),0,needed
);
2125 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
2126 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2127 GetLastError(),pbuf
->pPrinterName
);
2128 HeapFree(GetProcessHeap(), 0, dbuf
);
2129 HeapFree(GetProcessHeap(), 0, pbuf
);
2130 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2135 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
2139 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
2140 pbuf
->pDevMode
->dmDriverExtra
);
2141 ptr
= GlobalLock(lppd
->hDevMode
);
2142 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
2143 pbuf
->pDevMode
->dmDriverExtra
);
2144 GlobalUnlock(lppd
->hDevMode
);
2145 HeapFree(GetProcessHeap(), 0, pbuf
);
2146 HeapFree(GetProcessHeap(), 0, dbuf
);
2150 PRINT_PTRA
*PrintStructures
;
2152 /* load Dialog resources,
2153 * depending on Flags indicates Print32 or Print32_setup dialog
2155 hDlgTmpl
= PRINTDLG_GetDlgTemplateA(lppd
);
2157 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2160 ptr
= LockResource( hDlgTmpl
);
2162 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2166 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2167 sizeof(PRINT_PTRA
));
2168 PrintStructures
->lpPrintDlg
= lppd
;
2170 /* and create & process the dialog .
2171 * -1 is failure, 0 is broken hwnd, everything else is ok.
2173 bRet
= (0<DialogBoxIndirectParamA(hInst
, ptr
, lppd
->hwndOwner
,
2175 (LPARAM
)PrintStructures
));
2178 DEVMODEA
*lpdm
= PrintStructures
->lpDevMode
, *lpdmReturn
;
2179 PRINTER_INFO_2A
*pi
= PrintStructures
->lpPrinterInfo
;
2180 DRIVER_INFO_3A
*di
= PrintStructures
->lpDriverInfo
;
2182 if (lppd
->hDevMode
== 0) {
2183 TRACE(" No hDevMode yet... Need to create my own\n");
2184 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
,
2185 lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2187 lppd
->hDevMode
= GlobalReAlloc(lppd
->hDevMode
,
2188 lpdm
->dmSize
+ lpdm
->dmDriverExtra
,
2191 lpdmReturn
= GlobalLock(lppd
->hDevMode
);
2192 memcpy(lpdmReturn
, lpdm
, lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2194 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
2199 GlobalUnlock(lppd
->hDevMode
);
2201 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
2202 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpPrinterInfo
);
2203 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDriverInfo
);
2204 HeapFree(GetProcessHeap(), 0, PrintStructures
);
2206 if(bRet
&& (lppd
->Flags
& PD_RETURNDC
|| lppd
->Flags
& PD_RETURNIC
))
2207 bRet
= PRINTDLG_CreateDCA(lppd
);
2209 TRACE("exit! (%d)\n", bRet
);
2213 /***********************************************************************
2214 * PrintDlgW (COMDLG32.@)
2218 BOOL WINAPI
PrintDlgW(LPPRINTDLGW lppd
)
2226 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
2230 hInst
= (HINSTANCE
)GetWindowLongPtrW( lppd
->hwndOwner
, GWLP_HINSTANCE
);
2231 if(TRACE_ON(commdlg
)) {
2232 char flagstr
[1000] = "";
2233 const struct pd_flags
*pflag
= pd_flags
;
2234 for( ; pflag
->name
; pflag
++) {
2235 if(lppd
->Flags
& pflag
->flag
)
2236 strcat(flagstr
, pflag
->name
);
2238 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2239 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2240 "flags %08x (%s)\n",
2241 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
2242 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
2243 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
2246 if(lppd
->lStructSize
!= sizeof(PRINTDLGW
)) {
2247 WARN("structure size failure !!!\n");
2248 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
2252 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
2253 PRINTER_INFO_2W
*pbuf
;
2254 DRIVER_INFO_3W
*dbuf
;
2258 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
2259 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2260 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2263 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
2264 WARN("Can't find default printer\n");
2265 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
2269 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
2270 pbuf
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*needed
);
2271 GetPrinterW(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
2273 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
2274 dbuf
= HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*needed
);
2275 if (!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
2276 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2277 GetLastError(),debugstr_w(pbuf
->pPrinterName
));
2278 HeapFree(GetProcessHeap(), 0, dbuf
);
2279 HeapFree(GetProcessHeap(), 0, pbuf
);
2280 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2285 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
2289 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
2290 pbuf
->pDevMode
->dmDriverExtra
);
2291 ptr
= GlobalLock(lppd
->hDevMode
);
2292 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
2293 pbuf
->pDevMode
->dmDriverExtra
);
2294 GlobalUnlock(lppd
->hDevMode
);
2295 HeapFree(GetProcessHeap(), 0, pbuf
);
2296 HeapFree(GetProcessHeap(), 0, dbuf
);
2300 PRINT_PTRW
*PrintStructures
;
2302 /* load Dialog resources,
2303 * depending on Flags indicates Print32 or Print32_setup dialog
2305 hDlgTmpl
= PRINTDLG_GetDlgTemplateW(lppd
);
2307 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2310 ptr
= LockResource( hDlgTmpl
);
2312 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2316 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2317 sizeof(PRINT_PTRW
));
2318 PrintStructures
->lpPrintDlg
= lppd
;
2320 /* and create & process the dialog .
2321 * -1 is failure, 0 is broken hwnd, everything else is ok.
2323 bRet
= (0<DialogBoxIndirectParamW(hInst
, ptr
, lppd
->hwndOwner
,
2325 (LPARAM
)PrintStructures
));
2328 DEVMODEW
*lpdm
= PrintStructures
->lpDevMode
, *lpdmReturn
;
2329 PRINTER_INFO_2W
*pi
= PrintStructures
->lpPrinterInfo
;
2330 DRIVER_INFO_3W
*di
= PrintStructures
->lpDriverInfo
;
2332 if (lppd
->hDevMode
== 0) {
2333 TRACE(" No hDevMode yet... Need to create my own\n");
2334 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
,
2335 lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2338 if((locks
= (GlobalFlags(lppd
->hDevMode
) & GMEM_LOCKCOUNT
))) {
2339 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks
);
2341 GlobalUnlock(lppd
->hDevMode
);
2342 TRACE("Now got %d locks\n", locks
);
2345 lppd
->hDevMode
= GlobalReAlloc(lppd
->hDevMode
,
2346 lpdm
->dmSize
+ lpdm
->dmDriverExtra
,
2349 lpdmReturn
= GlobalLock(lppd
->hDevMode
);
2350 memcpy(lpdmReturn
, lpdm
, lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2352 if (lppd
->hDevNames
!= 0) {
2354 if((locks
= (GlobalFlags(lppd
->hDevNames
) & GMEM_LOCKCOUNT
))) {
2355 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks
);
2357 GlobalUnlock(lppd
->hDevNames
);
2360 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
2365 GlobalUnlock(lppd
->hDevMode
);
2367 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
2368 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpPrinterInfo
);
2369 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDriverInfo
);
2370 HeapFree(GetProcessHeap(), 0, PrintStructures
);
2372 if(bRet
&& (lppd
->Flags
& PD_RETURNDC
|| lppd
->Flags
& PD_RETURNIC
))
2373 bRet
= PRINTDLG_CreateDCW(lppd
);
2375 TRACE("exit! (%d)\n", bRet
);
2379 /***********************************************************************
2384 * cmb1 - printer select (not in standard dialog template)
2386 * cmb3 - source (tray?)
2387 * edt4 - border left
2389 * edt6 - border right
2390 * edt7 - border bottom
2391 * psh3 - "Printer..."
2395 LPPAGESETUPDLGA dlga
; /* Handler to user defined struct */
2397 HWND hDlg
; /* Page Setup dialog handler */
2398 PAGESETUPDLGA curdlg
; /* Stores the current dialog state */
2399 RECT rtDrawRect
; /* Drawing rect for page */
2403 LPPAGESETUPDLGW dlgw
;
2405 PAGESETUPDLGW curdlg
; /* Current dialog state */
2409 static HGLOBAL
PRINTDLG_GetPGSTemplateA(const PAGESETUPDLGA
*lppd
)
2414 if(lppd
->Flags
& PSD_ENABLEPAGESETUPTEMPLATEHANDLE
) {
2415 hDlgTmpl
= lppd
->hPageSetupTemplate
;
2416 } else if(lppd
->Flags
& PSD_ENABLEPAGESETUPTEMPLATE
) {
2417 hResInfo
= FindResourceA(lppd
->hInstance
,
2418 lppd
->lpPageSetupTemplateName
, (LPSTR
)RT_DIALOG
);
2419 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
2421 hResInfo
= FindResourceA(COMDLG32_hInstance
,(LPCSTR
)PAGESETUPDLGORD
,(LPSTR
)RT_DIALOG
);
2422 hDlgTmpl
= LoadResource(COMDLG32_hInstance
,hResInfo
);
2427 static HGLOBAL
PRINTDLG_GetPGSTemplateW(const PAGESETUPDLGW
*lppd
)
2432 if(lppd
->Flags
& PSD_ENABLEPAGESETUPTEMPLATEHANDLE
) {
2433 hDlgTmpl
= lppd
->hPageSetupTemplate
;
2434 } else if(lppd
->Flags
& PSD_ENABLEPAGESETUPTEMPLATE
) {
2435 hResInfo
= FindResourceW(lppd
->hInstance
,
2436 lppd
->lpPageSetupTemplateName
, (LPWSTR
)RT_DIALOG
);
2437 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
2439 hResInfo
= FindResourceW(COMDLG32_hInstance
,(LPCWSTR
)PAGESETUPDLGORD
,(LPWSTR
)RT_DIALOG
);
2440 hDlgTmpl
= LoadResource(COMDLG32_hInstance
,hResInfo
);
2446 _c_10mm2size(PAGESETUPDLGA
*dlga
,DWORD size
) {
2447 if (dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
)
2448 return 10*size
*100/254;
2449 /* If we don't have a flag, we can choose one. Use millimeters
2450 * to avoid confusing me
2452 dlga
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
2458 _c_inch2size(PAGESETUPDLGA
*dlga
,DWORD size
) {
2459 if (dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
)
2461 if (dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
)
2462 return (size
*254)/100;
2463 /* if we don't have a flag, we can choose one. Use millimeters
2464 * to avoid confusing me
2466 dlga
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
2467 return (size
*254)/100;
2471 _c_size2strA(PageSetupDataA
*pda
,DWORD size
,LPSTR strout
) {
2472 strcpy(strout
,"<undef>");
2473 if (pda
->dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
) {
2474 sprintf(strout
,"%d",(size
)/100);
2477 if (pda
->dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
) {
2478 sprintf(strout
,"%din",(size
)/1000);
2481 pda
->dlga
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
2482 sprintf(strout
,"%d",(size
)/100);
2486 _c_size2strW(PageSetupDataW
*pdw
,DWORD size
,LPWSTR strout
) {
2487 static const char mm_fmt
[] = "%.2f mm";
2488 static const char in_fmt
[] = "%.2f in";
2490 if (pdw
->dlgw
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
) {
2491 sprintf(buf
, mm_fmt
, (size
* 1.0) / 100.0);
2492 } else if (pdw
->dlgw
->Flags
& PSD_INTHOUSANDTHSOFINCHES
) {
2493 sprintf(buf
, in_fmt
, (size
* 1.0) / 1000.0);
2495 pdw
->dlgw
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
2496 sprintf(buf
, mm_fmt
, (size
* 1.0) / 100.0);
2499 MultiByteToWideChar(CP_ACP
, 0, buf
, -1, strout
, 20);
2503 _c_str2sizeA(const PAGESETUPDLGA
*dlga
, LPCSTR strin
) {
2508 if (!sscanf(strin
,"%f%s",&val
,rest
))
2511 if (!strcmp(rest
,"in") || !strcmp(rest
,"inch")) {
2512 if (dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
)
2515 return val
*25.4*100;
2517 if (!strcmp(rest
,"cm")) { rest
[0]='m'; val
= val
*10.0; }
2518 if (!strcmp(rest
,"m")) { strcpy(rest
,"mm"); val
= val
*1000.0; }
2520 if (!strcmp(rest
,"mm")) {
2521 if (dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
)
2524 return 1000.0*val
/25.4;
2526 if (rest
[0]=='\0') {
2527 /* use application supplied default */
2528 if (dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
) {
2532 if (dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
) {
2537 ERR("Did not find a conversion for type '%s'!\n",rest
);
2543 _c_str2sizeW(const PAGESETUPDLGW
*dlga
, LPCWSTR strin
) {
2546 /* this W -> A transition is OK */
2547 /* we need a unicode version of sscanf to avoid it */
2548 WideCharToMultiByte(CP_ACP
, 0, strin
, -1, buf
, sizeof(buf
), NULL
, NULL
);
2549 return _c_str2sizeA((const PAGESETUPDLGA
*)dlga
, buf
);
2553 /****************************************************************************
2554 * PRINTDLG_PS_UpdateDlgStructA
2556 * Updates pda->dlga structure
2557 * Function calls when user presses OK button
2560 * hDlg [in] main window dialog HANDLE
2561 * pda [in/out] ptr to PageSetupDataA structure
2567 PRINTDLG_PS_UpdateDlgStructA(HWND hDlg
, PageSetupDataA
*pda
) {
2572 memcpy(pda
->dlga
, &pda
->curdlg
, sizeof(pda
->curdlg
));
2573 pda
->dlga
->hDevMode
= pda
->pdlg
.hDevMode
;
2574 pda
->dlga
->hDevNames
= pda
->pdlg
.hDevNames
;
2576 dn
= GlobalLock(pda
->pdlg
.hDevNames
);
2577 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2579 /* Save paper orientation into device context */
2580 if(pda
->curdlg
.ptPaperSize
.x
> pda
->curdlg
.ptPaperSize
.y
)
2581 dm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
2583 dm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
2585 /* Save paper size into the device context */
2586 paperword
= SendDlgItemMessageA(hDlg
,cmb2
,CB_GETITEMDATA
,
2587 SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0), 0);
2588 if (paperword
!= CB_ERR
)
2589 dm
->u1
.s1
.dmPaperSize
= paperword
;
2591 FIXME("could not get dialog text for papersize cmbbox?\n");
2593 /* Save paper source into the device context */
2594 paperword
= SendDlgItemMessageA(hDlg
,cmb1
,CB_GETITEMDATA
,
2595 SendDlgItemMessageA(hDlg
, cmb1
, CB_GETCURSEL
, 0, 0), 0);
2596 if (paperword
!= CB_ERR
)
2597 dm
->u1
.s1
.dmDefaultSource
= paperword
;
2599 FIXME("could not get dialog text for papersize cmbbox?\n");
2601 GlobalUnlock(pda
->pdlg
.hDevNames
);
2602 GlobalUnlock(pda
->pdlg
.hDevMode
);
2608 PRINTDLG_PS_UpdateDlgStructW(HWND hDlg
, PageSetupDataW
*pdw
) {
2611 LPWSTR devname
,portname
;
2612 WCHAR papername
[64];
2615 dn
= GlobalLock(pdw
->pdlg
.hDevNames
);
2616 dm
= GlobalLock(pdw
->pdlg
.hDevMode
);
2617 devname
= ((WCHAR
*)dn
)+dn
->wDeviceOffset
;
2618 portname
= ((WCHAR
*)dn
)+dn
->wOutputOffset
;
2620 /* Save paper size into device context */
2621 PRINTDLG_SetUpPaperComboBoxW(hDlg
,cmb2
,devname
,portname
,dm
);
2622 /* Save paper source into device context */
2623 PRINTDLG_SetUpPaperComboBoxW(hDlg
,cmb3
,devname
,portname
,dm
);
2625 if (GetDlgItemTextW(hDlg
,cmb2
,papername
,sizeof(papername
)/sizeof(papername
[0]))>0) {
2626 PRINTDLG_PaperSizeW(&(pdw
->pdlg
),papername
,&(pdw
->dlgw
->ptPaperSize
));
2627 pdw
->dlgw
->ptPaperSize
.x
= _c_10mm2size((LPPAGESETUPDLGA
)pdw
->dlgw
,pdw
->dlgw
->ptPaperSize
.x
);
2628 pdw
->dlgw
->ptPaperSize
.y
= _c_10mm2size((LPPAGESETUPDLGA
)pdw
->dlgw
,pdw
->dlgw
->ptPaperSize
.y
);
2630 FIXME("could not get dialog text for papersize cmbbox?\n");
2631 #define GETVAL(id,val) if (GetDlgItemTextW(hDlg,id,buf,sizeof(buf)/sizeof(buf[0]))>0) { val = _c_str2sizeW(pdw->dlgw,buf); } else { FIXME("could not get dlgitemtextw for %x\n",id); }
2632 GETVAL(edt4
,pdw
->dlgw
->rtMargin
.left
);
2633 GETVAL(edt5
,pdw
->dlgw
->rtMargin
.top
);
2634 GETVAL(edt6
,pdw
->dlgw
->rtMargin
.right
);
2635 GETVAL(edt7
,pdw
->dlgw
->rtMargin
.bottom
);
2638 /* If we are in landscape, swap x and y of page size */
2639 if (IsDlgButtonChecked(hDlg
, rad2
)) {
2641 tmp
= pdw
->dlgw
->ptPaperSize
.x
;
2642 pdw
->dlgw
->ptPaperSize
.x
= pdw
->dlgw
->ptPaperSize
.y
;
2643 pdw
->dlgw
->ptPaperSize
.y
= tmp
;
2646 /* Save orientation */
2647 if (pdw
->dlgw
->ptPaperSize
.x
> pdw
->dlgw
->ptPaperSize
.y
)
2648 dm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
2650 dm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
2652 GlobalUnlock(pdw
->pdlg
.hDevNames
);
2653 GlobalUnlock(pdw
->pdlg
.hDevMode
);
2657 /**********************************************************************************************
2658 * PRINTDLG_PS_ChangeActivePrinerA
2660 * Redefines hDevMode and hDevNames HANDLES and initialises it.
2663 * name [in] Name of a printer for activation
2664 * pda [in/out] ptr to PageSetupDataA structure
2671 PRINTDLG_PS_ChangeActivePrinterA(LPSTR name
, PageSetupDataA
*pda
){
2674 LPPRINTER_INFO_2A lpPrinterInfo
;
2675 LPDRIVER_INFO_3A lpDriverInfo
;
2676 DEVMODEA
*pDevMode
, *dm
;
2678 if(!OpenPrinterA(name
, &hprn
, NULL
)){
2679 ERR("Can't open printer %s\n", name
);
2682 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
2683 lpPrinterInfo
= HeapAlloc(GetProcessHeap(), 0, needed
);
2684 GetPrinterA(hprn
, 2, (LPBYTE
)lpPrinterInfo
, needed
, &needed
);
2685 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
2686 lpDriverInfo
= HeapAlloc(GetProcessHeap(), 0, needed
);
2687 if(!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)lpDriverInfo
, needed
, &needed
)) {
2688 ERR("GetPrinterDriverA failed for %s, fix your config!\n", lpPrinterInfo
->pPrinterName
);
2689 HeapFree(GetProcessHeap(), 0, lpDriverInfo
);
2690 HeapFree(GetProcessHeap(), 0, lpPrinterInfo
);
2695 needed
= DocumentPropertiesA(0, 0, name
, NULL
, NULL
, 0);
2697 ERR("DocumentProperties fails on %s\n", debugstr_a(name
));
2698 HeapFree(GetProcessHeap(), 0, lpDriverInfo
);
2699 HeapFree(GetProcessHeap(), 0, lpPrinterInfo
);
2702 pDevMode
= HeapAlloc(GetProcessHeap(), 0, needed
);
2703 DocumentPropertiesA(0, 0, name
, pDevMode
, NULL
, DM_OUT_BUFFER
);
2705 pda
->pdlg
.hDevMode
= GlobalReAlloc(pda
->pdlg
.hDevMode
,
2706 pDevMode
->dmSize
+ pDevMode
->dmDriverExtra
,
2708 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2709 memcpy(dm
, pDevMode
, pDevMode
->dmSize
+ pDevMode
->dmDriverExtra
);
2711 PRINTDLG_CreateDevNames(&(pda
->pdlg
.hDevNames
),
2712 lpDriverInfo
->pDriverPath
,
2713 lpPrinterInfo
->pPrinterName
,
2714 lpPrinterInfo
->pPortName
);
2716 GlobalUnlock(pda
->pdlg
.hDevMode
);
2717 HeapFree(GetProcessHeap(), 0, pDevMode
);
2718 HeapFree(GetProcessHeap(), 0, lpPrinterInfo
);
2719 HeapFree(GetProcessHeap(), 0, lpDriverInfo
);
2723 /****************************************************************************************
2724 * PRINTDLG_PS_ChangePrinterA
2726 * Fills Printers, Paper and Source combo
2732 PRINTDLG_PS_ChangePrinterA(HWND hDlg
, PageSetupDataA
*pda
) {
2735 LPSTR devname
,portname
;
2737 dn
= GlobalLock(pda
->pdlg
.hDevNames
);
2738 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2739 devname
= ((char*)dn
)+dn
->wDeviceOffset
;
2740 portname
= ((char*)dn
)+dn
->wOutputOffset
;
2741 PRINTDLG_SetUpPrinterListComboA(hDlg
, cmb1
, devname
);
2742 PRINTDLG_SetUpPaperComboBoxA(hDlg
,cmb2
,devname
,portname
,dm
);
2743 PRINTDLG_SetUpPaperComboBoxA(hDlg
,cmb3
,devname
,portname
,dm
);
2744 GlobalUnlock(pda
->pdlg
.hDevNames
);
2745 GlobalUnlock(pda
->pdlg
.hDevMode
);
2749 static void PRINTDLG_PS_SetOrientationW(HWND hDlg
, PageSetupDataW
* pdw
)
2751 WCHAR PaperName
[64];
2753 GetDlgItemTextW(hDlg
, cmb2
, PaperName
, sizeof(PaperName
)/sizeof(WCHAR
));
2754 PRINTDLG_PaperSizeW(&pdw
->pdlg
, PaperName
, &pdw
->curdlg
.ptPaperSize
);
2755 pdw
->curdlg
.ptPaperSize
.x
= _c_10mm2size((LPPAGESETUPDLGA
)pdw
->dlgw
, pdw
->curdlg
.ptPaperSize
.x
);
2756 pdw
->curdlg
.ptPaperSize
.y
= _c_10mm2size((LPPAGESETUPDLGA
)pdw
->dlgw
, pdw
->curdlg
.ptPaperSize
.y
);
2758 if(IsDlgButtonChecked(hDlg
, rad2
))
2760 DWORD tmp
= pdw
->curdlg
.ptPaperSize
.x
;
2761 pdw
->curdlg
.ptPaperSize
.x
= pdw
->curdlg
.ptPaperSize
.y
;
2762 pdw
->curdlg
.ptPaperSize
.y
= tmp
;
2766 static void PRINTDLG_PS_UpdatePrintDlgW(PageSetupDataW
* pdw
, HWND hDlg
)
2771 dm
= GlobalLock(pdw
->pdlg
.hDevMode
);
2776 if(pdw
->curdlg
.ptPaperSize
.y
> pdw
->curdlg
.ptPaperSize
.x
)
2777 dm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
2779 dm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
2781 sel
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
2784 dm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETITEMDATA
, sel
, 0);
2786 GlobalUnlock(pdw
->pdlg
.hDevMode
);
2790 PRINTDLG_PS_ChangePrinterW(HWND hDlg
, PageSetupDataW
*pdw
) {
2793 LPWSTR devname
,portname
;
2795 dn
= GlobalLock(pdw
->pdlg
.hDevNames
);
2796 dm
= GlobalLock(pdw
->pdlg
.hDevMode
);
2797 devname
= ((WCHAR
*)dn
)+dn
->wDeviceOffset
;
2798 portname
= ((WCHAR
*)dn
)+dn
->wOutputOffset
;
2799 PRINTDLG_SetUpPaperComboBoxW(hDlg
,cmb2
,devname
,portname
,dm
);
2800 PRINTDLG_SetUpPaperComboBoxW(hDlg
,cmb3
,devname
,portname
,dm
);
2802 /* Landscape orientation */
2803 if (dm
->u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
)
2804 CheckRadioButton(hDlg
, rad1
, rad2
, rad2
);
2805 else /* this is default if papersize is not set */
2806 CheckRadioButton(hDlg
, rad1
, rad2
, rad1
);
2808 GlobalUnlock(pdw
->pdlg
.hDevNames
);
2809 GlobalUnlock(pdw
->pdlg
.hDevMode
);
2811 PRINTDLG_PS_SetOrientationW(hDlg
, pdw
);
2816 /******************************************************************************************
2817 * PRINTDLG_PS_ChangePaperPrev
2819 * Changes paper preview size / position
2822 * pda [i] Pointer for current PageSetupDataA structure
2828 PRINTDLG_PS_ChangePaperPrev(const PageSetupDataA
*pda
)
2830 LONG width
, height
, x
, y
;
2833 if(pda
->curdlg
.ptPaperSize
.x
> pda
->curdlg
.ptPaperSize
.y
) {
2834 width
= pda
->rtDrawRect
.right
- pda
->rtDrawRect
.left
;
2835 height
= pda
->curdlg
.ptPaperSize
.y
* width
/ pda
->curdlg
.ptPaperSize
.x
;
2837 height
= pda
->rtDrawRect
.bottom
- pda
->rtDrawRect
.top
;
2838 width
= pda
->curdlg
.ptPaperSize
.x
* height
/ pda
->curdlg
.ptPaperSize
.y
;
2840 x
= (pda
->rtDrawRect
.right
+ pda
->rtDrawRect
.left
- width
) / 2;
2841 y
= (pda
->rtDrawRect
.bottom
+ pda
->rtDrawRect
.top
- height
) / 2;
2842 TRACE("rtDrawRect(%d, %d, %d, %d) x=%d, y=%d, w=%d, h=%d\n",
2843 pda
->rtDrawRect
.left
, pda
->rtDrawRect
.top
, pda
->rtDrawRect
.right
, pda
->rtDrawRect
.bottom
,
2844 x
, y
, width
, height
);
2847 MoveWindow(GetDlgItem(pda
->hDlg
, rct2
), x
+width
, y
+SHADOW
, SHADOW
, height
, FALSE
);
2848 MoveWindow(GetDlgItem(pda
->hDlg
, rct3
), x
+SHADOW
, y
+height
, width
, SHADOW
, FALSE
);
2849 MoveWindow(GetDlgItem(pda
->hDlg
, rct1
), x
, y
, width
, height
, FALSE
);
2850 rtTmp
= pda
->rtDrawRect
;
2851 rtTmp
.right
+= SHADOW
;
2852 rtTmp
.bottom
+= SHADOW
;
2855 InvalidateRect(pda
->hDlg
, &rtTmp
, TRUE
);
2859 #define GETVAL(idc,val) \
2860 if(msg == EN_CHANGE){ \
2861 if (GetDlgItemTextA(hDlg,idc,buf,sizeof(buf)) > 0)\
2862 val = _c_str2sizeA(pda->dlga,buf); \
2864 FIXME("could not get dlgitemtexta for %x\n",id); \
2867 /********************************************************************************
2868 * PRINTDLG_PS_WMCommandA
2869 * process WM_COMMAND message for PageSetupDlgA
2872 * hDlg [in] Main dialog HANDLE
2873 * wParam [in] WM_COMMAND wParam
2874 * lParam [in] WM_COMMAND lParam
2875 * pda [in/out] ptr to PageSetupDataA
2879 PRINTDLG_PS_WMCommandA(
2880 HWND hDlg
, WPARAM wParam
, LPARAM lParam
, PageSetupDataA
*pda
2882 WORD msg
= HIWORD(wParam
);
2883 WORD id
= LOWORD(wParam
);
2886 TRACE("loword (lparam) %d, wparam 0x%lx, lparam %08lx\n",
2887 LOWORD(lParam
),wParam
,lParam
);
2890 if (!PRINTDLG_PS_UpdateDlgStructA(hDlg
, pda
))
2892 EndDialog(hDlg
, TRUE
);
2896 EndDialog(hDlg
, FALSE
);
2900 pda
->pdlg
.Flags
= 0;
2901 pda
->pdlg
.hwndOwner
= hDlg
;
2902 if (PrintDlgA(&(pda
->pdlg
)))
2903 PRINTDLG_PS_ChangePrinterA(hDlg
,pda
);
2908 if((id
== rad1
&& pda
->curdlg
.ptPaperSize
.x
> pda
->curdlg
.ptPaperSize
.y
) ||
2909 (id
== rad2
&& pda
->curdlg
.ptPaperSize
.y
> pda
->curdlg
.ptPaperSize
.x
))
2913 DWORD tmp
= pda
->curdlg
.ptPaperSize
.x
;
2915 pda
->curdlg
.ptPaperSize
.x
= pda
->curdlg
.ptPaperSize
.y
;
2916 pda
->curdlg
.ptPaperSize
.y
= tmp
;
2918 GetDlgItemTextA(hDlg
, edt4
, TmpText
, sizeof(TmpText
));
2919 GetDlgItemTextA(hDlg
, edt5
, TmpText2
, sizeof(TmpText2
));
2920 SetDlgItemTextA(hDlg
, edt5
, TmpText
);
2921 SetDlgItemTextA(hDlg
, edt4
, TmpText2
);
2923 GetDlgItemTextA(hDlg
, edt6
, TmpText
, sizeof(TmpText
));
2924 GetDlgItemTextA(hDlg
, edt7
, TmpText2
, sizeof(TmpText2
));
2925 SetDlgItemTextA(hDlg
, edt7
, TmpText
);
2926 SetDlgItemTextA(hDlg
, edt6
, TmpText2
);
2928 PRINTDLG_PS_ChangePaperPrev(pda
);
2931 case cmb1
: /* Printer combo */
2932 if(msg
== CBN_SELCHANGE
){
2933 char crPrinterName
[256];
2934 GetDlgItemTextA(hDlg
, id
, crPrinterName
, 255);
2935 PRINTDLG_PS_ChangeActivePrinterA(crPrinterName
, pda
);
2936 PRINTDLG_PS_ChangePrinterA(hDlg
, pda
);
2939 case cmb2
: /* Paper combo */
2940 if(msg
== CBN_SELCHANGE
){
2941 DWORD paperword
= SendDlgItemMessageA(hDlg
,cmb2
,CB_GETITEMDATA
,
2942 SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0), 0);
2943 if (paperword
!= CB_ERR
) {
2944 PRINTDLG_PaperSizeA(&(pda
->pdlg
), paperword
,&(pda
->curdlg
.ptPaperSize
));
2945 pda
->curdlg
.ptPaperSize
.x
= _c_10mm2size(pda
->dlga
,pda
->curdlg
.ptPaperSize
.x
);
2946 pda
->curdlg
.ptPaperSize
.y
= _c_10mm2size(pda
->dlga
,pda
->curdlg
.ptPaperSize
.y
);
2948 if (IsDlgButtonChecked(hDlg
, rad2
)) {
2949 DWORD tmp
= pda
->curdlg
.ptPaperSize
.x
;
2950 pda
->curdlg
.ptPaperSize
.x
= pda
->curdlg
.ptPaperSize
.y
;
2951 pda
->curdlg
.ptPaperSize
.y
= tmp
;
2953 PRINTDLG_PS_ChangePaperPrev(pda
);
2955 FIXME("could not get dialog text for papersize cmbbox?\n");
2959 if(msg
== CBN_SELCHANGE
){
2960 DEVMODEA
*dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2961 dm
->u1
.s1
.dmDefaultSource
= SendDlgItemMessageA(hDlg
, cmb3
,CB_GETITEMDATA
,
2962 SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0), 0);
2963 GlobalUnlock(pda
->pdlg
.hDevMode
);
2966 case psh2
: /* Printer Properties button */
2969 char PrinterName
[256];
2974 GetDlgItemTextA(hDlg
, cmb1
, PrinterName
, 255);
2975 if (!OpenPrinterA(PrinterName
, &hPrinter
, NULL
)) {
2976 FIXME("Call to OpenPrinter did not succeed!\n");
2979 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2980 DocumentPropertiesA(hDlg
, hPrinter
, PrinterName
, dm
, dm
,
2981 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
2982 ClosePrinter(hPrinter
);
2983 /* Changing paper */
2984 PRINTDLG_PaperSizeA(&(pda
->pdlg
), dm
->u1
.s1
.dmPaperSize
, &(pda
->curdlg
.ptPaperSize
));
2985 pda
->curdlg
.ptPaperSize
.x
= _c_10mm2size(pda
->dlga
, pda
->curdlg
.ptPaperSize
.x
);
2986 pda
->curdlg
.ptPaperSize
.y
= _c_10mm2size(pda
->dlga
, pda
->curdlg
.ptPaperSize
.y
);
2987 if (dm
->u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
){
2988 DWORD tmp
= pda
->curdlg
.ptPaperSize
.x
;
2989 pda
->curdlg
.ptPaperSize
.x
= pda
->curdlg
.ptPaperSize
.y
;
2990 pda
->curdlg
.ptPaperSize
.y
= tmp
;
2991 CheckRadioButton(hDlg
, rad1
, rad2
, rad2
);
2994 CheckRadioButton(hDlg
, rad1
, rad2
, rad1
);
2995 /* Changing paper preview */
2996 PRINTDLG_PS_ChangePaperPrev(pda
);
2997 /* Selecting paper in combo */
2998 count
= SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCOUNT
, 0, 0);
2999 if(count
!= CB_ERR
){
3000 for(i
=0; i
<count
; ++i
){
3001 if(SendDlgItemMessageA(hDlg
, cmb2
, CB_GETITEMDATA
, i
, 0) == dm
->u1
.s1
.dmPaperSize
) {
3002 SendDlgItemMessageA(hDlg
, cmb2
, CB_SETCURSEL
, i
, 0);
3008 GlobalUnlock(pda
->pdlg
.hDevMode
);
3012 GETVAL(id
, pda
->curdlg
.rtMargin
.left
);
3015 GETVAL(id
, pda
->curdlg
.rtMargin
.top
);
3018 GETVAL(id
, pda
->curdlg
.rtMargin
.right
);
3021 GETVAL(id
, pda
->curdlg
.rtMargin
.bottom
);
3024 InvalidateRect(GetDlgItem(hDlg
, rct1
), NULL
, TRUE
);
3030 PRINTDLG_PS_WMCommandW(
3031 HWND hDlg
, WPARAM wParam
, LPARAM lParam
, PageSetupDataW
*pdw
3033 TRACE("loword (lparam) %d, wparam 0x%lx, lparam %08lx\n",
3034 LOWORD(lParam
),wParam
,lParam
);
3035 switch (LOWORD(wParam
)) {
3037 if (!PRINTDLG_PS_UpdateDlgStructW(hDlg
, pdw
))
3039 EndDialog(hDlg
, TRUE
);
3043 EndDialog(hDlg
, FALSE
);
3048 if((LOWORD(wParam
) == rad1
&& pdw
->curdlg
.ptPaperSize
.x
> pdw
->curdlg
.ptPaperSize
.y
) ||
3049 (LOWORD(wParam
) == rad2
&& pdw
->curdlg
.ptPaperSize
.y
> pdw
->curdlg
.ptPaperSize
.x
))
3053 DWORD tmp
= pdw
->curdlg
.ptPaperSize
.y
;
3055 pdw
->curdlg
.ptPaperSize
.y
= pdw
->curdlg
.ptPaperSize
.x
;
3056 pdw
->curdlg
.ptPaperSize
.x
= tmp
;
3058 GetDlgItemTextW(hDlg
, edt4
, tmpText
, sizeof(tmpText
)/sizeof(WCHAR
));
3059 GetDlgItemTextW(hDlg
, edt5
, tmpText2
, sizeof(tmpText2
)/sizeof(WCHAR
));
3060 SetDlgItemTextW(hDlg
, edt5
, tmpText
);
3061 SetDlgItemTextW(hDlg
, edt4
, tmpText2
);
3063 GetDlgItemTextW(hDlg
, edt6
, tmpText
, sizeof(tmpText
)/sizeof(WCHAR
));
3064 GetDlgItemTextW(hDlg
, edt7
, tmpText2
, sizeof(tmpText2
)/sizeof(WCHAR
));
3065 SetDlgItemTextW(hDlg
, edt7
, tmpText
);
3066 SetDlgItemTextW(hDlg
, edt6
, tmpText2
);
3071 pdw
->pdlg
.Flags
= 0;
3072 pdw
->pdlg
.hwndOwner
= hDlg
;
3073 PRINTDLG_PS_UpdatePrintDlgW(pdw
, hDlg
);
3074 if (PrintDlgW(&(pdw
->pdlg
)))
3075 PRINTDLG_PS_ChangePrinterW(hDlg
,pdw
);
3083 /***********************************************************************
3084 * DefaultPagePaintHook
3085 * Default hook paint procedure that receives WM_PSD_* messages from the dialog box
3086 * whenever the sample page is redrawn.
3090 PRINTDLG_DefaultPagePaintHook(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
,
3091 const PageSetupDataA
*pda
)
3093 LPRECT lprc
= (LPRECT
) lParam
;
3094 HDC hdc
= (HDC
) wParam
;
3097 HFONT hfont
, holdfont
;
3099 TRACE("uMsg: WM_USER+%d\n",uMsg
-WM_USER
);
3100 /* Call user paint hook if enable */
3101 if (pda
->dlga
->Flags
& PSD_ENABLEPAGEPAINTHOOK
)
3102 if (pda
->dlga
->lpfnPagePaintHook(hwndDlg
, uMsg
, wParam
, lParam
))
3106 /* LPPAGESETUPDLG in lParam */
3107 case WM_PSD_PAGESETUPDLG
:
3108 /* Inform about the sample page rectangle */
3109 case WM_PSD_FULLPAGERECT
:
3110 /* Inform about the margin rectangle */
3111 case WM_PSD_MINMARGINRECT
:
3114 /* Draw dashed rectangle showing margins */
3115 case WM_PSD_MARGINRECT
:
3116 hpen
= CreatePen(PS_DASH
, 1, GetSysColor(COLOR_3DSHADOW
));
3117 holdpen
= SelectObject(hdc
, hpen
);
3118 Rectangle(hdc
, lprc
->left
, lprc
->top
, lprc
->right
, lprc
->bottom
);
3119 DeleteObject(SelectObject(hdc
, holdpen
));
3121 /* Draw the fake document */
3122 case WM_PSD_GREEKTEXTRECT
:
3123 /* select a nice scalable font, because we want the text really small */
3124 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, sizeof(lf
), &lf
, 0);
3125 lf
.lfHeight
= 6; /* value chosen based on visual effect */
3126 hfont
= CreateFontIndirectW(&lf
);
3127 holdfont
= SelectObject(hdc
, hfont
);
3129 /* if text not loaded, then do so now */
3130 if (wszFakeDocumentText
[0] == '\0')
3131 LoadStringW(COMDLG32_hInstance
,
3133 wszFakeDocumentText
,
3134 sizeof(wszFakeDocumentText
)/sizeof(wszFakeDocumentText
[0]));
3136 oldbkmode
= SetBkMode(hdc
, TRANSPARENT
);
3137 DrawTextW(hdc
, wszFakeDocumentText
, -1, lprc
, DT_TOP
|DT_LEFT
|DT_NOPREFIX
|DT_WORDBREAK
);
3138 SetBkMode(hdc
, oldbkmode
);
3140 DeleteObject(SelectObject(hdc
, holdfont
));
3143 /* Envelope stamp */
3144 case WM_PSD_ENVSTAMPRECT
:
3145 /* Return address */
3146 case WM_PSD_YAFULLPAGERECT
:
3147 FIXME("envelope/stamp is not implemented\n");
3150 FIXME("Unknown message %x\n",uMsg
);
3156 /***********************************************************************
3158 * The main paint procedure for the PageSetupDlg function.
3159 * The Page Setup dialog box includes an image of a sample page that shows how
3160 * the user's selections affect the appearance of the printed output.
3161 * The image consists of a rectangle that represents the selected paper
3162 * or envelope type, with a dotted-line rectangle representing
3163 * the current margins, and partial (Greek text) characters
3164 * to show how text looks on the printed page.
3166 * The following messages in the order sends to user hook procedure:
3167 * WM_PSD_PAGESETUPDLG Draw the contents of the sample page
3168 * WM_PSD_FULLPAGERECT Inform about the bounding rectangle
3169 * WM_PSD_MINMARGINRECT Inform about the margin rectangle (min margin?)
3170 * WM_PSD_MARGINRECT Draw the margin rectangle
3171 * WM_PSD_GREEKTEXTRECT Draw the Greek text inside the margin rectangle
3172 * If any of first three messages returns TRUE, painting done.
3175 * hWnd [in] Handle to the Page Setup dialog box
3176 * uMsg [in] Received message
3179 * WM_PSD_ENVSTAMPRECT Draw in the envelope-stamp rectangle (for envelopes only)
3180 * WM_PSD_YAFULLPAGERECT Draw the return address portion (for envelopes and other paper sizes)
3183 * FALSE if all done correctly
3188 static LRESULT CALLBACK
3189 PRINTDLG_PagePaintProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3192 RECT rcClient
, rcMargin
;
3195 HBRUSH hbrush
, holdbrush
;
3196 PageSetupDataA
*pda
;
3197 int papersize
=0, orientation
=0; /* FIXME: set this values for user paint hook */
3198 double scalx
, scaly
;
3199 #define CALLPAINTHOOK(msg,lprc) PRINTDLG_DefaultPagePaintHook( hWnd, msg, (WPARAM)hdc, (LPARAM)lprc, pda)
3201 if (uMsg
!= WM_PAINT
)
3202 return CallWindowProcA(lpfnStaticWndProc
, hWnd
, uMsg
, wParam
, lParam
);
3204 /* Processing WM_PAINT message */
3205 pda
= (PageSetupDataA
*)GetPropA(hWnd
, "__WINE_PAGESETUPDLGDATA");
3207 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3210 if (PRINTDLG_DefaultPagePaintHook(hWnd
, WM_PSD_PAGESETUPDLG
, MAKELONG(papersize
, orientation
), (LPARAM
)pda
->dlga
, pda
))
3213 hdc
= BeginPaint(hWnd
, &ps
);
3214 GetClientRect(hWnd
, &rcClient
);
3216 scalx
= rcClient
.right
/ (double)pda
->curdlg
.ptPaperSize
.x
;
3217 scaly
= rcClient
.bottom
/ (double)pda
->curdlg
.ptPaperSize
.y
;
3218 rcMargin
= rcClient
;
3220 rcMargin
.left
+= pda
->curdlg
.rtMargin
.left
* scalx
;
3221 rcMargin
.top
+= pda
->curdlg
.rtMargin
.top
* scalx
;
3222 rcMargin
.right
-= pda
->curdlg
.rtMargin
.right
* scaly
;
3223 rcMargin
.bottom
-= pda
->curdlg
.rtMargin
.bottom
* scaly
;
3225 /* if the space is too small then we make sure to not draw anything */
3226 rcMargin
.left
= min(rcMargin
.left
, rcMargin
.right
);
3227 rcMargin
.top
= min(rcMargin
.top
, rcMargin
.bottom
);
3229 if (!CALLPAINTHOOK(WM_PSD_FULLPAGERECT
, &rcClient
) &&
3230 !CALLPAINTHOOK(WM_PSD_MINMARGINRECT
, &rcMargin
) )
3232 /* fill background */
3233 hbrush
= GetSysColorBrush(COLOR_3DHIGHLIGHT
);
3234 FillRect(hdc
, &rcClient
, hbrush
);
3235 holdbrush
= SelectObject(hdc
, hbrush
);
3237 hpen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DSHADOW
));
3238 holdpen
= SelectObject(hdc
, hpen
);
3240 /* paint left edge */
3241 MoveToEx(hdc
, rcClient
.left
, rcClient
.top
, NULL
);
3242 LineTo(hdc
, rcClient
.left
, rcClient
.bottom
-1);
3244 /* paint top edge */
3245 MoveToEx(hdc
, rcClient
.left
, rcClient
.top
, NULL
);
3246 LineTo(hdc
, rcClient
.right
, rcClient
.top
);
3248 hpen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DDKSHADOW
));
3249 DeleteObject(SelectObject(hdc
, hpen
));
3251 /* paint right edge */
3252 MoveToEx(hdc
, rcClient
.right
-1, rcClient
.top
, NULL
);
3253 LineTo(hdc
, rcClient
.right
-1, rcClient
.bottom
);
3255 /* paint bottom edge */
3256 MoveToEx(hdc
, rcClient
.left
, rcClient
.bottom
-1, NULL
);
3257 LineTo(hdc
, rcClient
.right
, rcClient
.bottom
-1);
3259 DeleteObject(SelectObject(hdc
, holdpen
));
3260 DeleteObject(SelectObject(hdc
, holdbrush
));
3262 CALLPAINTHOOK(WM_PSD_MARGINRECT
, &rcMargin
);
3264 /* give text a bit of a space from the frame */
3267 rcMargin
.right
-= 2;
3268 rcMargin
.bottom
-= 2;
3270 /* if the space is too small then we make sure to not draw anything */
3271 rcMargin
.left
= min(rcMargin
.left
, rcMargin
.right
);
3272 rcMargin
.top
= min(rcMargin
.top
, rcMargin
.bottom
);
3274 CALLPAINTHOOK(WM_PSD_GREEKTEXTRECT
, &rcMargin
);
3277 EndPaint(hWnd
, &ps
);
3279 #undef CALLPAINTHOOK
3282 /***********************************************************************
3283 * PRINTDLG_PageDlgProcA
3284 * Message handler for PageSetupDlgA
3286 static INT_PTR CALLBACK
3287 PRINTDLG_PageDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3290 PageSetupDataA
*pda
;
3291 INT_PTR res
= FALSE
;
3294 if (uMsg
== WM_INITDIALOG
) { /*Init dialog*/
3295 pda
= (PageSetupDataA
*)lParam
;
3296 pda
->hDlg
= hDlg
; /* saving handle to main window to PageSetupDataA structure */
3297 pda
->curdlg
= *pda
->dlga
;
3299 hDrawWnd
= GetDlgItem(hDlg
, rct1
);
3300 TRACE("set property to %p\n", pda
);
3301 SetPropA(hDlg
, "__WINE_PAGESETUPDLGDATA", pda
);
3302 SetPropA(hDrawWnd
, "__WINE_PAGESETUPDLGDATA", pda
);
3303 GetWindowRect(hDrawWnd
, &pda
->rtDrawRect
); /* Calculating rect in client coordinates where paper draws */
3304 ScreenToClient(hDlg
, (LPPOINT
)&pda
->rtDrawRect
);
3305 ScreenToClient(hDlg
, (LPPOINT
)(&pda
->rtDrawRect
.right
));
3306 lpfnStaticWndProc
= (WNDPROC
)SetWindowLongPtrW(
3309 (ULONG_PTR
)PRINTDLG_PagePaintProc
);
3311 /* FIXME: Paint hook. Must it be at begin of initialization or at end? */
3313 if (pda
->dlga
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
3314 if (!pda
->dlga
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,(LPARAM
)pda
->dlga
))
3315 FIXME("Setup page hook failed?\n");
3318 /* if printer button disabled */
3319 if (pda
->dlga
->Flags
& PSD_DISABLEPRINTER
)
3320 EnableWindow(GetDlgItem(hDlg
, psh3
), FALSE
);
3321 /* if margin edit boxes disabled */
3322 if (pda
->dlga
->Flags
& PSD_DISABLEMARGINS
) {
3323 EnableWindow(GetDlgItem(hDlg
, edt4
), FALSE
);
3324 EnableWindow(GetDlgItem(hDlg
, edt5
), FALSE
);
3325 EnableWindow(GetDlgItem(hDlg
, edt6
), FALSE
);
3326 EnableWindow(GetDlgItem(hDlg
, edt7
), FALSE
);
3328 /* Set orientation radiobutton properly */
3329 if(pda
->dlga
->hDevMode
)
3331 dm
= GlobalLock(pda
->dlga
->hDevMode
);
3332 if (dm
->u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
)
3333 CheckRadioButton(hDlg
, rad1
, rad2
, rad2
);
3334 else /* this is default if papersize is not set */
3335 CheckRadioButton(hDlg
, rad1
, rad2
, rad1
);
3336 GlobalUnlock(pda
->dlga
->hDevMode
);
3339 /* if orientation disabled */
3340 if (pda
->dlga
->Flags
& PSD_DISABLEORIENTATION
) {
3341 EnableWindow(GetDlgItem(hDlg
,rad1
),FALSE
);
3342 EnableWindow(GetDlgItem(hDlg
,rad2
),FALSE
);
3344 /* We fill them out enabled or not */
3345 if (pda
->dlga
->Flags
& PSD_MARGINS
) {
3347 _c_size2strA(pda
,pda
->dlga
->rtMargin
.left
,str
);
3348 SetDlgItemTextA(hDlg
,edt4
,str
);
3349 _c_size2strA(pda
,pda
->dlga
->rtMargin
.top
,str
);
3350 SetDlgItemTextA(hDlg
,edt5
,str
);
3351 _c_size2strA(pda
,pda
->dlga
->rtMargin
.right
,str
);
3352 SetDlgItemTextA(hDlg
,edt6
,str
);
3353 _c_size2strA(pda
,pda
->dlga
->rtMargin
.bottom
,str
);
3354 SetDlgItemTextA(hDlg
,edt7
,str
);
3356 /* default is 1 inch */
3357 DWORD size
= _c_inch2size(pda
->dlga
,1000);
3359 _c_size2strA(pda
,size
,str
);
3360 SetDlgItemTextA(hDlg
,edt4
,str
);
3361 SetDlgItemTextA(hDlg
,edt5
,str
);
3362 SetDlgItemTextA(hDlg
,edt6
,str
);
3363 SetDlgItemTextA(hDlg
,edt7
,str
);
3364 pda
->curdlg
.rtMargin
.left
= size
;
3365 pda
->curdlg
.rtMargin
.top
= size
;
3366 pda
->curdlg
.rtMargin
.right
= size
;
3367 pda
->curdlg
.rtMargin
.bottom
= size
;
3369 /* if paper disabled */
3370 if (pda
->dlga
->Flags
& PSD_DISABLEPAPER
) {
3371 EnableWindow(GetDlgItem(hDlg
,cmb2
),FALSE
);
3372 EnableWindow(GetDlgItem(hDlg
,cmb3
),FALSE
);
3374 /* filling combos: printer, paper, source. selecting current printer (from DEVMODEA) */
3375 PRINTDLG_PS_ChangePrinterA(hDlg
, pda
);
3376 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
3378 dm
->u1
.s1
.dmDefaultSource
= 15; /*FIXME: Automatic select. Does it always 15 at start? */
3379 PRINTDLG_PaperSizeA(&(pda
->pdlg
), dm
->u1
.s1
.dmPaperSize
, &pda
->curdlg
.ptPaperSize
);
3380 GlobalUnlock(pda
->pdlg
.hDevMode
);
3381 pda
->curdlg
.ptPaperSize
.x
= _c_10mm2size(pda
->dlga
, pda
->curdlg
.ptPaperSize
.x
);
3382 pda
->curdlg
.ptPaperSize
.y
= _c_10mm2size(pda
->dlga
, pda
->curdlg
.ptPaperSize
.y
);
3383 if (IsDlgButtonChecked(hDlg
, rad2
) == BST_CHECKED
) { /* Landscape orientation */
3384 DWORD tmp
= pda
->curdlg
.ptPaperSize
.y
;
3385 pda
->curdlg
.ptPaperSize
.y
= pda
->curdlg
.ptPaperSize
.x
;
3386 pda
->curdlg
.ptPaperSize
.x
= tmp
;
3389 WARN("GlobalLock(pda->pdlg.hDevMode) fail? hDevMode=%p\n", pda
->pdlg
.hDevMode
);
3390 /* Drawing paper prev */
3391 PRINTDLG_PS_ChangePaperPrev(pda
);
3394 pda
= (PageSetupDataA
*)GetPropA(hDlg
,"__WINE_PAGESETUPDLGDATA");
3396 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3399 if (pda
->dlga
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
3400 res
= pda
->dlga
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,lParam
);
3401 if (res
) return res
;
3406 return PRINTDLG_PS_WMCommandA(hDlg
, wParam
, lParam
, pda
);
3411 static INT_PTR CALLBACK
3412 PageDlgProcW(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3414 static const WCHAR __WINE_PAGESETUPDLGDATA
[] =
3415 { '_', '_', 'W', 'I', 'N', 'E', '_', 'P', 'A', 'G', 'E',
3416 'S', 'E', 'T', 'U', 'P', 'D', 'L', 'G', 'D', 'A', 'T', 'A', 0 };
3417 PageSetupDataW
*pdw
;
3420 if (uMsg
==WM_INITDIALOG
) {
3422 pdw
= (PageSetupDataW
*)lParam
;
3423 pdw
->curdlg
= *pdw
->dlgw
;
3424 SetPropW(hDlg
, __WINE_PAGESETUPDLGDATA
, pdw
);
3425 if (pdw
->dlgw
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
3426 res
= pdw
->dlgw
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,(LPARAM
)pdw
->dlgw
);
3428 FIXME("Setup page hook failed?\n");
3433 if (pdw
->dlgw
->Flags
& PSD_ENABLEPAGEPAINTHOOK
) {
3434 FIXME("PagePaintHook not yet implemented!\n");
3436 if (pdw
->dlgw
->Flags
& PSD_DISABLEPRINTER
)
3437 EnableWindow(GetDlgItem(hDlg
, psh3
), FALSE
);
3438 if (pdw
->dlgw
->Flags
& PSD_DISABLEMARGINS
) {
3439 EnableWindow(GetDlgItem(hDlg
, edt4
), FALSE
);
3440 EnableWindow(GetDlgItem(hDlg
, edt5
), FALSE
);
3441 EnableWindow(GetDlgItem(hDlg
, edt6
), FALSE
);
3442 EnableWindow(GetDlgItem(hDlg
, edt7
), FALSE
);
3445 PRINTDLG_PS_ChangePrinterW(hDlg
,pdw
);
3447 if (pdw
->dlgw
->Flags
& PSD_DISABLEORIENTATION
) {
3448 EnableWindow(GetDlgItem(hDlg
,rad1
),FALSE
);
3449 EnableWindow(GetDlgItem(hDlg
,rad2
),FALSE
);
3451 /* We fill them out enabled or not */
3452 if (pdw
->dlgw
->Flags
& PSD_MARGINS
) {
3454 _c_size2strW(pdw
,pdw
->dlgw
->rtMargin
.left
,str
);
3455 SetDlgItemTextW(hDlg
,edt4
,str
);
3456 _c_size2strW(pdw
,pdw
->dlgw
->rtMargin
.top
,str
);
3457 SetDlgItemTextW(hDlg
,edt5
,str
);
3458 _c_size2strW(pdw
,pdw
->dlgw
->rtMargin
.right
,str
);
3459 SetDlgItemTextW(hDlg
,edt6
,str
);
3460 _c_size2strW(pdw
,pdw
->dlgw
->rtMargin
.bottom
,str
);
3461 SetDlgItemTextW(hDlg
,edt7
,str
);
3463 /* default is 1 inch */
3464 DWORD size
= _c_inch2size((LPPAGESETUPDLGA
)pdw
->dlgw
,1000);
3466 _c_size2strW(pdw
,size
,str
);
3467 SetDlgItemTextW(hDlg
,edt4
,str
);
3468 SetDlgItemTextW(hDlg
,edt5
,str
);
3469 SetDlgItemTextW(hDlg
,edt6
,str
);
3470 SetDlgItemTextW(hDlg
,edt7
,str
);
3473 if (pdw
->dlgw
->Flags
& PSD_DISABLEPAPER
) {
3474 EnableWindow(GetDlgItem(hDlg
,cmb2
),FALSE
);
3475 EnableWindow(GetDlgItem(hDlg
,cmb3
),FALSE
);
3480 pdw
= (PageSetupDataW
*)GetPropW(hDlg
, __WINE_PAGESETUPDLGDATA
);
3482 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3485 if (pdw
->dlgw
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
3486 res
= pdw
->dlgw
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,lParam
);
3487 if (res
) return res
;
3492 return PRINTDLG_PS_WMCommandW(hDlg
, wParam
, lParam
, pdw
);
3497 /***********************************************************************
3498 * PageSetupDlgA (COMDLG32.@)
3500 * Displays the PAGE SETUP dialog box, which enables the user to specify
3501 * specific properties of a printed page such as
3502 * size, source, orientation and the width of the page margins.
3505 * setupdlg [IO] PAGESETUPDLGA struct
3508 * TRUE if the user pressed the OK button
3509 * FALSE if the user cancelled the window or an error occurred
3512 * The values of hDevMode and hDevNames are filled on output and can be
3513 * changed in PAGESETUPDLG when they are passed in PageSetupDlg.
3517 BOOL WINAPI
PageSetupDlgA(LPPAGESETUPDLGA setupdlg
) {
3521 PageSetupDataA
*pda
;
3524 if (setupdlg
== NULL
) {
3525 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
3530 if(TRACE_ON(commdlg
)) {
3531 char flagstr
[1000] = "";
3532 const struct pd_flags
*pflag
= psd_flags
;
3533 for( ; pflag
->name
; pflag
++) {
3534 if(setupdlg
->Flags
& pflag
->flag
) {
3535 strcat(flagstr
, pflag
->name
);
3536 strcat(flagstr
, "|");
3539 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3540 "hinst %p, flags %08x (%s)\n",
3541 setupdlg
, setupdlg
->hwndOwner
, setupdlg
->hDevMode
,
3542 setupdlg
->hDevNames
,
3543 setupdlg
->hInstance
, setupdlg
->Flags
, flagstr
);
3546 /* Checking setupdlg structure */
3547 if(setupdlg
->lStructSize
!= sizeof(PAGESETUPDLGA
)) {
3548 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
3551 if ((setupdlg
->Flags
& PSD_ENABLEPAGEPAINTHOOK
) &&
3552 (setupdlg
->lpfnPagePaintHook
== NULL
)) {
3553 COMDLG32_SetCommDlgExtendedError(CDERR_NOHOOK
);
3557 /* Initialize default printer struct. If no printer device info is specified
3558 retrieve the default printer data. */
3559 memset(&pdlg
,0,sizeof(pdlg
));
3560 pdlg
.lStructSize
= sizeof(pdlg
);
3561 if (setupdlg
->hDevMode
&& setupdlg
->hDevNames
) {
3562 pdlg
.hDevMode
= setupdlg
->hDevMode
;
3563 pdlg
.hDevNames
= setupdlg
->hDevNames
;
3565 pdlg
.Flags
= PD_RETURNDEFAULT
;
3566 bRet
= PrintDlgA(&pdlg
);
3568 if (!(setupdlg
->Flags
& PSD_NOWARNING
)) {
3570 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEFAULT_PRINTER
, errstr
, 255);
3571 MessageBoxW(setupdlg
->hwndOwner
, errstr
, 0, MB_OK
| MB_ICONERROR
);
3577 /* short cut exit, just return default values */
3578 if (setupdlg
->Flags
& PSD_RETURNDEFAULT
) {
3581 setupdlg
->hDevMode
= pdlg
.hDevMode
;
3582 setupdlg
->hDevNames
= pdlg
.hDevNames
;
3583 dm
= GlobalLock(pdlg
.hDevMode
);
3584 PRINTDLG_PaperSizeA(&pdlg
, dm
->u1
.s1
.dmPaperSize
, &setupdlg
->ptPaperSize
);
3585 GlobalUnlock(pdlg
.hDevMode
);
3586 setupdlg
->ptPaperSize
.x
=_c_10mm2size(setupdlg
,setupdlg
->ptPaperSize
.x
);
3587 setupdlg
->ptPaperSize
.y
=_c_10mm2size(setupdlg
,setupdlg
->ptPaperSize
.y
);
3591 /* get dialog template */
3592 hDlgTmpl
= PRINTDLG_GetPGSTemplateA(setupdlg
);
3594 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
3597 ptr
= LockResource( hDlgTmpl
);
3599 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
3603 pda
= HeapAlloc(GetProcessHeap(),0,sizeof(*pda
));
3604 pda
->dlga
= setupdlg
;
3607 bRet
= (0<DialogBoxIndirectParamA(
3608 setupdlg
->hInstance
,
3610 setupdlg
->hwndOwner
,
3611 PRINTDLG_PageDlgProcA
,
3615 HeapFree(GetProcessHeap(),0,pda
);
3618 /***********************************************************************
3619 * PageSetupDlgW (COMDLG32.@)
3621 * See PageSetupDlgA.
3623 BOOL WINAPI
PageSetupDlgW(LPPAGESETUPDLGW setupdlg
) {
3627 PageSetupDataW
*pdw
;
3630 FIXME("Unicode implementation is not done yet\n");
3632 if (setupdlg
== NULL
) {
3633 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
3637 if(TRACE_ON(commdlg
)) {
3638 char flagstr
[1000] = "";
3639 const struct pd_flags
*pflag
= psd_flags
;
3640 for( ; pflag
->name
; pflag
++) {
3641 if(setupdlg
->Flags
& pflag
->flag
) {
3642 strcat(flagstr
, pflag
->name
);
3643 strcat(flagstr
, "|");
3646 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3647 "hinst %p, flags %08x (%s)\n",
3648 setupdlg
, setupdlg
->hwndOwner
, setupdlg
->hDevMode
,
3649 setupdlg
->hDevNames
,
3650 setupdlg
->hInstance
, setupdlg
->Flags
, flagstr
);
3653 /* Initialize default printer struct. If no printer device info is specified
3654 retrieve the default printer data. */
3655 memset(&pdlg
,0,sizeof(pdlg
));
3656 pdlg
.lStructSize
= sizeof(pdlg
);
3657 if (setupdlg
->hDevMode
&& setupdlg
->hDevNames
) {
3658 pdlg
.hDevMode
= setupdlg
->hDevMode
;
3659 pdlg
.hDevNames
= setupdlg
->hDevNames
;
3661 pdlg
.Flags
= PD_RETURNDEFAULT
;
3662 bRet
= PrintDlgW(&pdlg
);
3664 if (!(setupdlg
->Flags
& PSD_NOWARNING
)) {
3666 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEFAULT_PRINTER
, errstr
, 255);
3667 MessageBoxW(setupdlg
->hwndOwner
, errstr
, 0, MB_OK
| MB_ICONERROR
);
3673 /* short cut exit, just return default values */
3674 if (setupdlg
->Flags
& PSD_RETURNDEFAULT
) {
3675 static const WCHAR a4
[] = {'A','4',0};
3676 setupdlg
->hDevMode
= pdlg
.hDevMode
;
3677 setupdlg
->hDevNames
= pdlg
.hDevNames
;
3678 /* FIXME: Just return "A4" for now. */
3679 PRINTDLG_PaperSizeW(&pdlg
,a4
,&setupdlg
->ptPaperSize
);
3680 setupdlg
->ptPaperSize
.x
=_c_10mm2size((LPPAGESETUPDLGA
)setupdlg
,setupdlg
->ptPaperSize
.x
);
3681 setupdlg
->ptPaperSize
.y
=_c_10mm2size((LPPAGESETUPDLGA
)setupdlg
,setupdlg
->ptPaperSize
.y
);
3684 hDlgTmpl
= PRINTDLG_GetPGSTemplateW(setupdlg
);
3686 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
3689 ptr
= LockResource( hDlgTmpl
);
3691 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
3694 pdw
= HeapAlloc(GetProcessHeap(),0,sizeof(*pdw
));
3695 pdw
->dlgw
= setupdlg
;
3698 bRet
= (0<DialogBoxIndirectParamW(
3699 setupdlg
->hInstance
,
3701 setupdlg
->hwndOwner
,
3708 /***********************************************************************
3709 * PrintDlgExA (COMDLG32.@)
3717 HRESULT WINAPI
PrintDlgExA(LPPRINTDLGEXA lppd
)
3720 FIXME("(%p) stub\n", lppd
);
3721 if ((lppd
== NULL
) || (lppd
->lStructSize
!= sizeof(PRINTDLGEXA
))) {
3722 return E_INVALIDARG
;
3725 if (!IsWindow(lppd
->hwndOwner
)) {
3732 /***********************************************************************
3733 * PrintDlgExW (COMDLG32.@)
3735 * Display the property sheet style PRINT dialog box
3738 * lppd [IO] ptr to PRINTDLGEX struct
3742 * Failure: One of the following COM error codes:
3743 * E_OUTOFMEMORY Insufficient memory.
3744 * E_INVALIDARG One or more arguments are invalid.
3745 * E_POINTER Invalid pointer.
3746 * E_HANDLE Invalid handle.
3747 * E_FAIL Unspecified error.
3750 * This Dialog enables the user to specify specific properties of the print job.
3751 * The property sheet can also have additional application-specific and
3752 * driver-specific property pages.
3758 HRESULT WINAPI
PrintDlgExW(LPPRINTDLGEXW lppd
)
3761 FIXME("(%p) stub\n", lppd
);
3762 if ((lppd
== NULL
) || (lppd
->lStructSize
!= sizeof(PRINTDLGEXW
))) {
3763 return E_INVALIDARG
;
3766 if (!IsWindow(lppd
->hwndOwner
)) {