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 /* Application is responsible for multiple copies */
357 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
358 lppd
->Flags
|= PD_COLLATE
;
360 lppd
->Flags
&= ~PD_COLLATE
;
361 lppd
->nCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
362 /* multiple copies already included in the document. Driver must print only one copy */
363 lpdm
->u1
.s1
.dmCopies
= 1;
366 /* Print quality, PrintDlg16 */
367 if(GetDlgItem(hDlg
, cmb1
))
369 HWND hQuality
= GetDlgItem(hDlg
, cmb1
);
370 int Sel
= SendMessageA(hQuality
, CB_GETCURSEL
, 0, 0);
374 LONG dpi
= SendMessageA(hQuality
, CB_GETITEMDATA
, Sel
, 0);
375 lpdm
->dmFields
|= DM_PRINTQUALITY
| DM_YRESOLUTION
;
376 lpdm
->u1
.s1
.dmPrintQuality
= LOWORD(dpi
);
377 lpdm
->dmYResolution
= HIWORD(dpi
);
384 static BOOL
PRINTDLG_UpdatePrintDlgW(HWND hDlg
,
385 PRINT_PTRW
* PrintStructures
)
387 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
388 PDEVMODEW lpdm
= PrintStructures
->lpDevMode
;
389 LPPRINTER_INFO_2W pi
= PrintStructures
->lpPrinterInfo
;
393 FIXME("No lpdm ptr?\n");
398 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
399 /* check whether nFromPage and nToPage are within range defined by
400 * nMinPage and nMaxPage
402 if (IsDlgButtonChecked(hDlg
, rad3
) == BST_CHECKED
) { /* Pages */
405 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
406 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
407 if (nFromPage
< lppd
->nMinPage
|| nFromPage
> lppd
->nMaxPage
||
408 nToPage
< lppd
->nMinPage
|| nToPage
> lppd
->nMaxPage
) {
409 WCHAR resourcestr
[256];
410 WCHAR resultstr
[256];
411 LoadStringW(COMDLG32_hInstance
, PD32_INVALID_PAGE_RANGE
,
413 wsprintfW(resultstr
,resourcestr
, lppd
->nMinPage
, lppd
->nMaxPage
);
414 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
,
416 MessageBoxW(hDlg
, resultstr
, resourcestr
,
417 MB_OK
| MB_ICONWARNING
);
420 lppd
->nFromPage
= nFromPage
;
421 lppd
->nToPage
= nToPage
;
422 lppd
->Flags
|= PD_PAGENUMS
;
425 lppd
->Flags
&= ~PD_PAGENUMS
;
427 if (IsDlgButtonChecked(hDlg
, rad2
) == BST_CHECKED
) /* Selection */
428 lppd
->Flags
|= PD_SELECTION
;
430 lppd
->Flags
&= ~PD_SELECTION
;
432 if (IsDlgButtonChecked(hDlg
, chx1
) == BST_CHECKED
) {/* Print to file */
433 static WCHAR file
[] = {'F','I','L','E',':',0};
434 lppd
->Flags
|= PD_PRINTTOFILE
;
435 pi
->pPortName
= file
;
438 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
) { /* Collate */
439 FIXME("Collate lppd not yet implemented as output\n");
442 /* set PD_Collate and nCopies */
443 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
444 /* The application doesn't support multiple copies or collate...
446 lppd
->Flags
&= ~PD_COLLATE
;
448 /* if the printer driver supports it... store info there
449 * otherwise no collate & multiple copies !
451 if (lpdm
->dmFields
& DM_COLLATE
)
453 (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
);
454 if (lpdm
->dmFields
& DM_COPIES
)
455 lpdm
->u1
.s1
.dmCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
457 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
458 lppd
->Flags
|= PD_COLLATE
;
460 lppd
->Flags
&= ~PD_COLLATE
;
461 lppd
->nCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
467 static BOOL
PRINTDLG_PaperSizeA(
468 PRINTDLGA
*pdlga
,const WORD PaperSize
,LPPOINT size
472 LPSTR devname
,portname
;
476 POINT
*points
= NULL
;
479 dn
= GlobalLock(pdlga
->hDevNames
);
480 dm
= GlobalLock(pdlga
->hDevMode
);
481 devname
= ((char*)dn
)+dn
->wDeviceOffset
;
482 portname
= ((char*)dn
)+dn
->wOutputOffset
;
485 NrOfEntries
= DeviceCapabilitiesA(devname
,portname
,DC_PAPERNAMES
,NULL
,dm
);
487 FIXME("No papernames found for %s/%s\n",devname
,portname
);
490 if (NrOfEntries
== -1) {
491 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
495 Words
= HeapAlloc(GetProcessHeap(),0,NrOfEntries
*sizeof(WORD
));
496 if (NrOfEntries
!= (ret
=DeviceCapabilitiesA(devname
,portname
,DC_PAPERS
,(LPSTR
)Words
,dm
))) {
497 FIXME("Number of returned vals %d is not %d\n",NrOfEntries
,ret
);
500 for (i
=0;i
<NrOfEntries
;i
++)
501 if (Words
[i
] == PaperSize
)
503 if (i
== NrOfEntries
) {
504 FIXME("Papersize %d not found in list?\n",PaperSize
);
507 points
= HeapAlloc(GetProcessHeap(),0,sizeof(points
[0])*NrOfEntries
);
508 if (NrOfEntries
!=(ret
=DeviceCapabilitiesA(devname
,portname
,DC_PAPERSIZE
,(LPSTR
)points
,dm
))) {
509 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries
,ret
);
512 /* this is _10ths_ of a millimeter */
517 GlobalUnlock(pdlga
->hDevNames
);
518 GlobalUnlock(pdlga
->hDevMode
);
519 HeapFree(GetProcessHeap(),0,Words
);
520 HeapFree(GetProcessHeap(),0,points
);
524 static BOOL
PRINTDLG_PaperSizeW(
525 PRINTDLGW
*pdlga
,const WCHAR
*PaperSize
,LPPOINT size
529 LPWSTR devname
,portname
;
533 POINT
*points
= NULL
;
536 dn
= GlobalLock(pdlga
->hDevNames
);
537 dm
= GlobalLock(pdlga
->hDevMode
);
538 devname
= ((WCHAR
*)dn
)+dn
->wDeviceOffset
;
539 portname
= ((WCHAR
*)dn
)+dn
->wOutputOffset
;
542 NrOfEntries
= DeviceCapabilitiesW(devname
,portname
,DC_PAPERNAMES
,NULL
,dm
);
544 FIXME("No papernames found for %s/%s\n",debugstr_w(devname
),debugstr_w(portname
));
547 if (NrOfEntries
== -1) {
548 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
552 Names
= HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*NrOfEntries
*64);
553 if (NrOfEntries
!= (ret
=DeviceCapabilitiesW(devname
,portname
,DC_PAPERNAMES
,Names
,dm
))) {
554 FIXME("Number of returned vals %d is not %d\n",NrOfEntries
,ret
);
557 for (i
=0;i
<NrOfEntries
;i
++)
558 if (!lstrcmpW(PaperSize
,Names
+(64*i
)))
560 if (i
==NrOfEntries
) {
561 FIXME("Papersize %s not found in list?\n",debugstr_w(PaperSize
));
564 points
= HeapAlloc(GetProcessHeap(),0,sizeof(points
[0])*NrOfEntries
);
565 if (NrOfEntries
!=(ret
=DeviceCapabilitiesW(devname
,portname
,DC_PAPERSIZE
,(LPWSTR
)points
,dm
))) {
566 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries
,ret
);
569 /* this is _10ths_ of a millimeter */
574 GlobalUnlock(pdlga
->hDevNames
);
575 GlobalUnlock(pdlga
->hDevMode
);
576 HeapFree(GetProcessHeap(),0,Names
);
577 HeapFree(GetProcessHeap(),0,points
);
582 /************************************************************************
583 * PRINTDLG_SetUpPaperComboBox
585 * Initialize either the papersize or inputslot combos of the Printer Setup
586 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
587 * We also try to re-select the old selection.
589 static BOOL
PRINTDLG_SetUpPaperComboBoxA(HWND hDlg
,
602 int fwCapability_Names
;
603 int fwCapability_Words
;
605 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName
,PortName
,nIDComboBox
);
607 /* query the dialog box for the current selected value */
608 Sel
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETCURSEL
, 0, 0);
610 /* we enter here only if a different printer is selected after
611 * the Print Setup dialog is opened. The current settings are
612 * stored into the newly selected printer.
614 oldWord
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
,
617 if (nIDComboBox
== cmb2
)
618 dm
->u1
.s1
.dmPaperSize
= oldWord
;
620 dm
->u1
.s1
.dmDefaultSource
= oldWord
;
624 /* we enter here only when the Print setup dialog is initially
625 * opened. In this case the settings are restored from when
626 * the dialog was last closed.
629 if (nIDComboBox
== cmb2
)
630 oldWord
= dm
->u1
.s1
.dmPaperSize
;
632 oldWord
= dm
->u1
.s1
.dmDefaultSource
;
636 if (nIDComboBox
== cmb2
) {
638 fwCapability_Names
= DC_PAPERNAMES
;
639 fwCapability_Words
= DC_PAPERS
;
643 fwCapability_Names
= DC_BINNAMES
;
644 fwCapability_Words
= DC_BINS
;
647 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
648 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
650 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
651 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
652 fwCapability_Names
, NULL
, dm
);
653 if (NrOfEntries
== 0)
654 WARN("no Name Entries found!\n");
655 else if (NrOfEntries
< 0)
658 if(DeviceCapabilitiesA(PrinterName
, PortName
, fwCapability_Words
, NULL
, dm
)
660 ERR("Number of caps is different\n");
664 Names
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(char)*NamesSize
);
665 Words
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WORD
));
666 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
667 fwCapability_Names
, Names
, dm
);
668 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
669 fwCapability_Words
, (LPSTR
)Words
, dm
);
671 /* reset any current content in the combobox */
672 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_RESETCONTENT
, 0, 0);
674 /* store new content */
675 for (i
= 0; i
< NrOfEntries
; i
++) {
676 DWORD pos
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_ADDSTRING
, 0,
677 (LPARAM
)(&Names
[i
*NamesSize
]) );
678 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_SETITEMDATA
, pos
,
682 /* Look for old selection - can't do this is previous loop since
683 item order will change as more items are added */
685 for (i
= 0; i
< NrOfEntries
; i
++) {
686 if(SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) ==
692 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_SETCURSEL
, Sel
, 0);
694 HeapFree(GetProcessHeap(),0,Words
);
695 HeapFree(GetProcessHeap(),0,Names
);
699 static BOOL
PRINTDLG_SetUpPaperComboBoxW(HWND hDlg
,
701 const WCHAR
* PrinterName
,
702 const WCHAR
* PortName
,
712 int fwCapability_Names
;
713 int fwCapability_Words
;
715 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName
),debugstr_w(PortName
),nIDComboBox
);
717 /* query the dialog box for the current selected value */
718 Sel
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETCURSEL
, 0, 0);
720 /* we enter here only if a different printer is selected after
721 * the Print Setup dialog is opened. The current settings are
722 * stored into the newly selected printer.
724 oldWord
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETITEMDATA
,
727 if (nIDComboBox
== cmb2
)
728 dm
->u1
.s1
.dmPaperSize
= oldWord
;
730 dm
->u1
.s1
.dmDefaultSource
= oldWord
;
734 /* we enter here only when the Print setup dialog is initially
735 * opened. In this case the settings are restored from when
736 * the dialog was last closed.
739 if (nIDComboBox
== cmb2
)
740 oldWord
= dm
->u1
.s1
.dmPaperSize
;
742 oldWord
= dm
->u1
.s1
.dmDefaultSource
;
746 if (nIDComboBox
== cmb2
) {
748 fwCapability_Names
= DC_PAPERNAMES
;
749 fwCapability_Words
= DC_PAPERS
;
753 fwCapability_Names
= DC_BINNAMES
;
754 fwCapability_Words
= DC_BINS
;
757 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
758 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
760 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
761 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
762 fwCapability_Names
, NULL
, dm
);
763 if (NrOfEntries
== 0)
764 WARN("no Name Entries found!\n");
765 else if (NrOfEntries
< 0)
768 if(DeviceCapabilitiesW(PrinterName
, PortName
, fwCapability_Words
, NULL
, dm
)
770 ERR("Number of caps is different\n");
774 Names
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WCHAR
)*NamesSize
);
775 Words
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WORD
));
776 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
777 fwCapability_Names
, Names
, dm
);
778 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
779 fwCapability_Words
, (LPWSTR
)Words
, dm
);
781 /* reset any current content in the combobox */
782 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_RESETCONTENT
, 0, 0);
784 /* store new content */
785 for (i
= 0; i
< NrOfEntries
; i
++) {
786 DWORD pos
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_ADDSTRING
, 0,
787 (LPARAM
)(&Names
[i
*NamesSize
]) );
788 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_SETITEMDATA
, pos
,
792 /* Look for old selection - can't do this is previous loop since
793 item order will change as more items are added */
795 for (i
= 0; i
< NrOfEntries
; i
++) {
796 if(SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) ==
802 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_SETCURSEL
, Sel
, 0);
804 HeapFree(GetProcessHeap(),0,Words
);
805 HeapFree(GetProcessHeap(),0,Names
);
810 /***********************************************************************
811 * PRINTDLG_UpdatePrinterInfoTexts [internal]
813 static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg
, const PRINTER_INFO_2A
*pi
)
816 char ResourceString
[256];
822 /* add all status messages */
823 for (i
= 0; i
< 25; i
++) {
824 if (pi
->Status
& (1<<i
)) {
825 LoadStringA(COMDLG32_hInstance
, PD32_PRINTER_STATUS_PAUSED
+i
,
826 ResourceString
, 255);
827 strcat(StatusMsg
,ResourceString
);
831 /* FIXME: status==ready must only be appended if really so.
832 but how to detect? */
833 LoadStringA(COMDLG32_hInstance
, PD32_PRINTER_STATUS_READY
,
834 ResourceString
, 255);
835 strcat(StatusMsg
,ResourceString
);
836 SetDlgItemTextA(hDlg
, stc12
, StatusMsg
);
838 /* set all other printer info texts */
839 SetDlgItemTextA(hDlg
, stc11
, pi
->pDriverName
);
841 if (pi
->pLocation
!= NULL
&& pi
->pLocation
[0] != '\0')
842 SetDlgItemTextA(hDlg
, stc14
, pi
->pLocation
);
844 SetDlgItemTextA(hDlg
, stc14
, pi
->pPortName
);
845 SetDlgItemTextA(hDlg
, stc13
, pi
->pComment
? pi
->pComment
: "");
849 static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg
, const PRINTER_INFO_2W
*pi
)
851 WCHAR StatusMsg
[256];
852 WCHAR ResourceString
[256];
853 static const WCHAR emptyW
[] = {0};
859 /* add all status messages */
860 for (i
= 0; i
< 25; i
++) {
861 if (pi
->Status
& (1<<i
)) {
862 LoadStringW(COMDLG32_hInstance
, PD32_PRINTER_STATUS_PAUSED
+i
,
863 ResourceString
, 255);
864 lstrcatW(StatusMsg
,ResourceString
);
868 /* FIXME: status==ready must only be appended if really so.
869 but how to detect? */
870 LoadStringW(COMDLG32_hInstance
, PD32_PRINTER_STATUS_READY
,
871 ResourceString
, 255);
872 lstrcatW(StatusMsg
,ResourceString
);
873 SetDlgItemTextW(hDlg
, stc12
, StatusMsg
);
875 /* set all other printer info texts */
876 SetDlgItemTextW(hDlg
, stc11
, pi
->pDriverName
);
877 if (pi
->pLocation
!= NULL
&& pi
->pLocation
[0] != '\0')
878 SetDlgItemTextW(hDlg
, stc14
, pi
->pLocation
);
880 SetDlgItemTextW(hDlg
, stc14
, pi
->pPortName
);
881 SetDlgItemTextW(hDlg
, stc13
, pi
->pComment
? pi
->pComment
: emptyW
);
885 /*******************************************************************
887 * PRINTDLG_ChangePrinter
890 BOOL
PRINTDLG_ChangePrinterA(HWND hDlg
, char *name
,
891 PRINT_PTRA
*PrintStructures
)
893 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
894 LPDEVMODEA lpdm
= NULL
;
899 HeapFree(GetProcessHeap(),0, PrintStructures
->lpPrinterInfo
);
900 HeapFree(GetProcessHeap(),0, PrintStructures
->lpDriverInfo
);
901 if(!OpenPrinterA(name
, &hprn
, NULL
)) {
902 ERR("Can't open printer %s\n", name
);
905 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
906 PrintStructures
->lpPrinterInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
907 GetPrinterA(hprn
, 2, (LPBYTE
)PrintStructures
->lpPrinterInfo
, needed
,
909 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
910 PrintStructures
->lpDriverInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
911 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)PrintStructures
->lpDriverInfo
,
913 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures
->lpPrinterInfo
->pPrinterName
);
918 PRINTDLG_UpdatePrinterInfoTextsA(hDlg
, PrintStructures
->lpPrinterInfo
);
920 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
921 PrintStructures
->lpDevMode
= NULL
;
923 dmSize
= DocumentPropertiesA(0, 0, name
, NULL
, NULL
, 0);
925 ERR("DocumentProperties fails on %s\n", debugstr_a(name
));
928 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(), 0, dmSize
);
929 dmSize
= DocumentPropertiesA(0, 0, name
, PrintStructures
->lpDevMode
, NULL
,
931 if(lppd
->hDevMode
&& (lpdm
= GlobalLock(lppd
->hDevMode
)) &&
932 !lstrcmpA( (LPSTR
) lpdm
->dmDeviceName
,
933 (LPSTR
) PrintStructures
->lpDevMode
->dmDeviceName
)) {
934 /* Supplied devicemode matches current printer so try to use it */
935 DocumentPropertiesA(0, 0, name
, PrintStructures
->lpDevMode
, lpdm
,
936 DM_OUT_BUFFER
| DM_IN_BUFFER
);
939 GlobalUnlock(lppd
->hDevMode
);
941 lpdm
= PrintStructures
->lpDevMode
; /* use this as a shortcut */
943 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
944 /* Print range (All/Range/Selection) */
945 SetDlgItemInt(hDlg
, edt1
, lppd
->nFromPage
, FALSE
);
946 SetDlgItemInt(hDlg
, edt2
, lppd
->nToPage
, FALSE
);
947 CheckRadioButton(hDlg
, rad1
, rad3
, rad1
); /* default */
948 if (lppd
->Flags
& PD_NOSELECTION
)
949 EnableWindow(GetDlgItem(hDlg
, rad2
), FALSE
);
951 if (lppd
->Flags
& PD_SELECTION
)
952 CheckRadioButton(hDlg
, rad1
, rad3
, rad2
);
953 if (lppd
->Flags
& PD_NOPAGENUMS
) {
954 EnableWindow(GetDlgItem(hDlg
, rad3
), FALSE
);
955 EnableWindow(GetDlgItem(hDlg
, stc2
),FALSE
);
956 EnableWindow(GetDlgItem(hDlg
, edt1
), FALSE
);
957 EnableWindow(GetDlgItem(hDlg
, stc3
),FALSE
);
958 EnableWindow(GetDlgItem(hDlg
, edt2
), FALSE
);
960 if (lppd
->Flags
& PD_PAGENUMS
)
961 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
966 * FIXME: The ico3 is not displayed for some reason. I don't know why.
968 if (lppd
->Flags
& PD_COLLATE
) {
969 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
970 (LPARAM
)PrintStructures
->hCollateIcon
);
971 CheckDlgButton(hDlg
, chx2
, 1);
973 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
974 (LPARAM
)PrintStructures
->hNoCollateIcon
);
975 CheckDlgButton(hDlg
, chx2
, 0);
978 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
979 /* if printer doesn't support it: no Collate */
980 if (!(lpdm
->dmFields
& DM_COLLATE
)) {
981 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
982 EnableWindow(GetDlgItem(hDlg
, ico3
), FALSE
);
989 if (lppd
->hDevMode
== 0)
990 copies
= lppd
->nCopies
;
992 copies
= lpdm
->u1
.s1
.dmCopies
;
993 if(copies
== 0) copies
= 1;
994 else if(copies
< 0) copies
= MAX_COPIES
;
995 SetDlgItemInt(hDlg
, edt3
, copies
, FALSE
);
998 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
999 /* if printer doesn't support it: no nCopies */
1000 if (!(lpdm
->dmFields
& DM_COPIES
)) {
1001 EnableWindow(GetDlgItem(hDlg
, edt3
), FALSE
);
1002 EnableWindow(GetDlgItem(hDlg
, stc5
), FALSE
);
1007 CheckDlgButton(hDlg
, chx1
, (lppd
->Flags
& PD_PRINTTOFILE
) ? 1 : 0);
1008 if (lppd
->Flags
& PD_DISABLEPRINTTOFILE
)
1009 EnableWindow(GetDlgItem(hDlg
, chx1
), FALSE
);
1010 if (lppd
->Flags
& PD_HIDEPRINTTOFILE
)
1011 ShowWindow(GetDlgItem(hDlg
, chx1
), SW_HIDE
);
1013 /* Fill print quality combo, PrintDlg16 */
1014 if(GetDlgItem(hDlg
, cmb1
))
1016 DWORD numResolutions
= DeviceCapabilitiesA(PrintStructures
->lpPrinterInfo
->pPrinterName
,
1017 PrintStructures
->lpPrinterInfo
->pPortName
,
1018 DC_ENUMRESOLUTIONS
, NULL
, lpdm
);
1020 if(numResolutions
!= -1)
1022 HWND hQuality
= GetDlgItem(hDlg
, cmb1
);
1027 HDC hPrinterDC
= CreateDCA(PrintStructures
->lpPrinterInfo
->pDriverName
,
1028 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1031 Resolutions
= HeapAlloc(GetProcessHeap(), 0, numResolutions
*sizeof(LONG
)*2);
1032 DeviceCapabilitiesA(PrintStructures
->lpPrinterInfo
->pPrinterName
,
1033 PrintStructures
->lpPrinterInfo
->pPortName
,
1034 DC_ENUMRESOLUTIONS
, (LPSTR
)Resolutions
, lpdm
);
1036 dpiX
= GetDeviceCaps(hPrinterDC
, LOGPIXELSX
);
1037 dpiY
= GetDeviceCaps(hPrinterDC
, LOGPIXELSY
);
1038 DeleteDC(hPrinterDC
);
1040 SendMessageA(hQuality
, CB_RESETCONTENT
, 0, 0);
1041 for(i
= 0; i
< (numResolutions
* 2); i
+= 2)
1043 BOOL IsDefault
= FALSE
;
1046 if(Resolutions
[i
] == Resolutions
[i
+1])
1048 if(dpiX
== Resolutions
[i
])
1050 sprintf(buf
, "%d dpi", Resolutions
[i
]);
1053 if(dpiX
== Resolutions
[i
] && dpiY
== Resolutions
[i
+1])
1055 sprintf(buf
, "%d dpi x %d dpi", Resolutions
[i
], Resolutions
[i
+1]);
1058 Index
= SendMessageA(hQuality
, CB_ADDSTRING
, 0, (LPARAM
)buf
);
1061 SendMessageA(hQuality
, CB_SETCURSEL
, Index
, 0);
1063 SendMessageA(hQuality
, CB_SETITEMDATA
, Index
, MAKELONG(dpiX
,dpiY
));
1065 HeapFree(GetProcessHeap(), 0, Resolutions
);
1068 } else { /* PD_PRINTSETUP */
1069 BOOL bPortrait
= (lpdm
->u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
);
1071 PRINTDLG_SetUpPaperComboBoxA(hDlg
, cmb2
,
1072 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1073 PrintStructures
->lpPrinterInfo
->pPortName
,
1075 PRINTDLG_SetUpPaperComboBoxA(hDlg
, cmb3
,
1076 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1077 PrintStructures
->lpPrinterInfo
->pPortName
,
1079 CheckRadioButton(hDlg
, rad1
, rad2
, bPortrait
? rad1
: rad2
);
1080 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1081 (LPARAM
)(bPortrait
? PrintStructures
->hPortraitIcon
:
1082 PrintStructures
->hLandscapeIcon
));
1087 if ((lppd
->Flags
& PD_SHOWHELP
)==0) {
1088 /* hide if PD_SHOWHELP not specified */
1089 ShowWindow(GetDlgItem(hDlg
, pshHelp
), SW_HIDE
);
1094 static BOOL
PRINTDLG_ChangePrinterW(HWND hDlg
, WCHAR
*name
,
1095 PRINT_PTRW
*PrintStructures
)
1097 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1098 LPDEVMODEW lpdm
= NULL
;
1103 HeapFree(GetProcessHeap(),0, PrintStructures
->lpPrinterInfo
);
1104 HeapFree(GetProcessHeap(),0, PrintStructures
->lpDriverInfo
);
1105 if(!OpenPrinterW(name
, &hprn
, NULL
)) {
1106 ERR("Can't open printer %s\n", debugstr_w(name
));
1109 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
1110 PrintStructures
->lpPrinterInfo
= HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*needed
);
1111 GetPrinterW(hprn
, 2, (LPBYTE
)PrintStructures
->lpPrinterInfo
, needed
,
1113 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
1114 PrintStructures
->lpDriverInfo
= HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*needed
);
1115 if (!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)PrintStructures
->lpDriverInfo
,
1117 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures
->lpPrinterInfo
->pPrinterName
));
1122 PRINTDLG_UpdatePrinterInfoTextsW(hDlg
, PrintStructures
->lpPrinterInfo
);
1124 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
1125 PrintStructures
->lpDevMode
= NULL
;
1127 dmSize
= DocumentPropertiesW(0, 0, name
, NULL
, NULL
, 0);
1129 ERR("DocumentProperties fails on %s\n", debugstr_w(name
));
1132 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(), 0, dmSize
);
1133 dmSize
= DocumentPropertiesW(0, 0, name
, PrintStructures
->lpDevMode
, NULL
,
1135 if(lppd
->hDevMode
&& (lpdm
= GlobalLock(lppd
->hDevMode
)) &&
1136 !lstrcmpW(lpdm
->dmDeviceName
,
1137 PrintStructures
->lpDevMode
->dmDeviceName
)) {
1138 /* Supplied devicemode matches current printer so try to use it */
1139 DocumentPropertiesW(0, 0, name
, PrintStructures
->lpDevMode
, lpdm
,
1140 DM_OUT_BUFFER
| DM_IN_BUFFER
);
1143 GlobalUnlock(lppd
->hDevMode
);
1145 lpdm
= PrintStructures
->lpDevMode
; /* use this as a shortcut */
1147 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
1148 /* Print range (All/Range/Selection) */
1149 SetDlgItemInt(hDlg
, edt1
, lppd
->nFromPage
, FALSE
);
1150 SetDlgItemInt(hDlg
, edt2
, lppd
->nToPage
, FALSE
);
1151 CheckRadioButton(hDlg
, rad1
, rad3
, rad1
); /* default */
1152 if (lppd
->Flags
& PD_NOSELECTION
)
1153 EnableWindow(GetDlgItem(hDlg
, rad2
), FALSE
);
1155 if (lppd
->Flags
& PD_SELECTION
)
1156 CheckRadioButton(hDlg
, rad1
, rad3
, rad2
);
1157 if (lppd
->Flags
& PD_NOPAGENUMS
) {
1158 EnableWindow(GetDlgItem(hDlg
, rad3
), FALSE
);
1159 EnableWindow(GetDlgItem(hDlg
, stc2
),FALSE
);
1160 EnableWindow(GetDlgItem(hDlg
, edt1
), FALSE
);
1161 EnableWindow(GetDlgItem(hDlg
, stc3
),FALSE
);
1162 EnableWindow(GetDlgItem(hDlg
, edt2
), FALSE
);
1164 if (lppd
->Flags
& PD_PAGENUMS
)
1165 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1170 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1172 if (lppd
->Flags
& PD_COLLATE
) {
1173 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1174 (LPARAM
)PrintStructures
->hCollateIcon
);
1175 CheckDlgButton(hDlg
, chx2
, 1);
1177 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1178 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1179 CheckDlgButton(hDlg
, chx2
, 0);
1182 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1183 /* if printer doesn't support it: no Collate */
1184 if (!(lpdm
->dmFields
& DM_COLLATE
)) {
1185 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1186 EnableWindow(GetDlgItem(hDlg
, ico3
), FALSE
);
1193 if (lppd
->hDevMode
== 0)
1194 copies
= lppd
->nCopies
;
1196 copies
= lpdm
->u1
.s1
.dmCopies
;
1197 if(copies
== 0) copies
= 1;
1198 else if(copies
< 0) copies
= MAX_COPIES
;
1199 SetDlgItemInt(hDlg
, edt3
, copies
, FALSE
);
1202 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1203 /* if printer doesn't support it: no nCopies */
1204 if (!(lpdm
->dmFields
& DM_COPIES
)) {
1205 EnableWindow(GetDlgItem(hDlg
, edt3
), FALSE
);
1206 EnableWindow(GetDlgItem(hDlg
, stc5
), FALSE
);
1211 CheckDlgButton(hDlg
, chx1
, (lppd
->Flags
& PD_PRINTTOFILE
) ? 1 : 0);
1212 if (lppd
->Flags
& PD_DISABLEPRINTTOFILE
)
1213 EnableWindow(GetDlgItem(hDlg
, chx1
), FALSE
);
1214 if (lppd
->Flags
& PD_HIDEPRINTTOFILE
)
1215 ShowWindow(GetDlgItem(hDlg
, chx1
), SW_HIDE
);
1217 } else { /* PD_PRINTSETUP */
1218 BOOL bPortrait
= (lpdm
->u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
);
1220 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb2
,
1221 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1222 PrintStructures
->lpPrinterInfo
->pPortName
,
1224 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb3
,
1225 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1226 PrintStructures
->lpPrinterInfo
->pPortName
,
1228 CheckRadioButton(hDlg
, rad1
, rad2
, bPortrait
? rad1
: rad2
);
1229 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1230 (LPARAM
)(bPortrait
? PrintStructures
->hPortraitIcon
:
1231 PrintStructures
->hLandscapeIcon
));
1236 if ((lppd
->Flags
& PD_SHOWHELP
)==0) {
1237 /* hide if PD_SHOWHELP not specified */
1238 ShowWindow(GetDlgItem(hDlg
, pshHelp
), SW_HIDE
);
1243 /***********************************************************************
1244 * check_printer_setup [internal]
1246 static LRESULT
check_printer_setup(HWND hDlg
)
1249 WCHAR resourcestr
[256],resultstr
[256];
1252 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
1255 EnumPrintersW(PRINTER_ENUM_CONNECTIONS
, NULL
, 2, NULL
, 0, &needed
, &num
);
1261 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEVICES
,resultstr
, 255);
1262 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
,resourcestr
, 255);
1263 res
= MessageBoxW(hDlg
, resultstr
, resourcestr
,MB_OK
| MB_ICONWARNING
);
1268 /***********************************************************************
1269 * PRINTDLG_WMInitDialog [internal]
1271 static LRESULT
PRINTDLG_WMInitDialog(HWND hDlg
, WPARAM wParam
,
1272 PRINT_PTRA
* PrintStructures
)
1274 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1278 UINT comboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1280 /* load Collate ICONs */
1281 /* We load these with LoadImage because they are not a standard
1282 size and we don't want them rescaled */
1283 PrintStructures
->hCollateIcon
=
1284 LoadImageA(COMDLG32_hInstance
, "PD32_COLLATE", IMAGE_ICON
, 0, 0, 0);
1285 PrintStructures
->hNoCollateIcon
=
1286 LoadImageA(COMDLG32_hInstance
, "PD32_NOCOLLATE", IMAGE_ICON
, 0, 0, 0);
1288 /* These can be done with LoadIcon */
1289 PrintStructures
->hPortraitIcon
=
1290 LoadIconA(COMDLG32_hInstance
, "PD32_PORTRAIT");
1291 PrintStructures
->hLandscapeIcon
=
1292 LoadIconA(COMDLG32_hInstance
, "PD32_LANDSCAPE");
1294 /* display the collate/no_collate icon */
1295 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1296 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1298 if(PrintStructures
->hCollateIcon
== 0 ||
1299 PrintStructures
->hNoCollateIcon
== 0 ||
1300 PrintStructures
->hPortraitIcon
== 0 ||
1301 PrintStructures
->hLandscapeIcon
== 0) {
1302 ERR("no icon in resourcefile\n");
1303 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1304 EndDialog(hDlg
, FALSE
);
1308 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1309 * must be registered and the Help button must be shown.
1311 if (lppd
->Flags
& PD_SHOWHELP
) {
1312 if((PrintStructures
->HelpMessageID
=
1313 RegisterWindowMessageA(HELPMSGSTRINGA
)) == 0) {
1314 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL
);
1318 PrintStructures
->HelpMessageID
= 0;
1320 if(!(lppd
->Flags
&PD_PRINTSETUP
)) {
1321 PrintStructures
->hwndUpDown
=
1322 CreateUpDownControl(WS_CHILD
| WS_VISIBLE
| WS_BORDER
|
1323 UDS_NOTHOUSANDS
| UDS_ARROWKEYS
|
1324 UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, 0, 0, 0, 0,
1325 hDlg
, UPDOWN_ID
, COMDLG32_hInstance
,
1326 GetDlgItem(hDlg
, edt3
), MAX_COPIES
, 1, 1);
1329 /* FIXME: I allow more freedom than either Win95 or WinNT,
1330 * which do not agree to what errors should be thrown or not
1331 * in case nToPage or nFromPage is out-of-range.
1333 if (lppd
->nMaxPage
< lppd
->nMinPage
)
1334 lppd
->nMaxPage
= lppd
->nMinPage
;
1335 if (lppd
->nMinPage
== lppd
->nMaxPage
)
1336 lppd
->Flags
|= PD_NOPAGENUMS
;
1337 if (lppd
->nToPage
< lppd
->nMinPage
)
1338 lppd
->nToPage
= lppd
->nMinPage
;
1339 if (lppd
->nToPage
> lppd
->nMaxPage
)
1340 lppd
->nToPage
= lppd
->nMaxPage
;
1341 if (lppd
->nFromPage
< lppd
->nMinPage
)
1342 lppd
->nFromPage
= lppd
->nMinPage
;
1343 if (lppd
->nFromPage
> lppd
->nMaxPage
)
1344 lppd
->nFromPage
= lppd
->nMaxPage
;
1346 /* if we have the combo box, fill it */
1347 if (GetDlgItem(hDlg
,comboID
)) {
1350 pdn
= GlobalLock(lppd
->hDevNames
);
1351 pdm
= GlobalLock(lppd
->hDevMode
);
1353 name
= (char*)pdn
+ pdn
->wDeviceOffset
;
1355 name
= (char*)pdm
->dmDeviceName
;
1356 PRINTDLG_SetUpPrinterListComboA(hDlg
, comboID
, name
);
1357 if(pdm
) GlobalUnlock(lppd
->hDevMode
);
1358 if(pdn
) GlobalUnlock(lppd
->hDevNames
);
1360 /* Now find selected printer and update rest of dlg */
1361 name
= HeapAlloc(GetProcessHeap(),0,256);
1362 if (GetDlgItemTextA(hDlg
, comboID
, name
, 255))
1363 PRINTDLG_ChangePrinterA(hDlg
, name
, PrintStructures
);
1364 HeapFree(GetProcessHeap(),0,name
);
1366 /* else use default printer */
1368 DWORD dwBufLen
= sizeof(name
);
1369 BOOL ret
= GetDefaultPrinterA(name
, &dwBufLen
);
1372 PRINTDLG_ChangePrinterA(hDlg
, name
, PrintStructures
);
1374 FIXME("No default printer found, expect problems!\n");
1379 static LRESULT
PRINTDLG_WMInitDialogW(HWND hDlg
, WPARAM wParam
,
1380 PRINT_PTRW
* PrintStructures
)
1382 static const WCHAR PD32_COLLATE
[] = { 'P', 'D', '3', '2', '_', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
1383 static const WCHAR PD32_NOCOLLATE
[] = { 'P', 'D', '3', '2', '_', 'N', 'O', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
1384 static const WCHAR PD32_PORTRAIT
[] = { 'P', 'D', '3', '2', '_', 'P', 'O', 'R', 'T', 'R', 'A', 'I', 'T', 0 };
1385 static const WCHAR PD32_LANDSCAPE
[] = { 'P', 'D', '3', '2', '_', 'L', 'A', 'N', 'D', 'S', 'C', 'A', 'P', 'E', 0 };
1386 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1390 UINT comboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1392 /* load Collate ICONs */
1393 /* We load these with LoadImage because they are not a standard
1394 size and we don't want them rescaled */
1395 PrintStructures
->hCollateIcon
=
1396 LoadImageW(COMDLG32_hInstance
, PD32_COLLATE
, IMAGE_ICON
, 0, 0, 0);
1397 PrintStructures
->hNoCollateIcon
=
1398 LoadImageW(COMDLG32_hInstance
, PD32_NOCOLLATE
, IMAGE_ICON
, 0, 0, 0);
1400 /* These can be done with LoadIcon */
1401 PrintStructures
->hPortraitIcon
=
1402 LoadIconW(COMDLG32_hInstance
, PD32_PORTRAIT
);
1403 PrintStructures
->hLandscapeIcon
=
1404 LoadIconW(COMDLG32_hInstance
, PD32_LANDSCAPE
);
1406 /* display the collate/no_collate icon */
1407 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1408 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1410 if(PrintStructures
->hCollateIcon
== 0 ||
1411 PrintStructures
->hNoCollateIcon
== 0 ||
1412 PrintStructures
->hPortraitIcon
== 0 ||
1413 PrintStructures
->hLandscapeIcon
== 0) {
1414 ERR("no icon in resourcefile\n");
1415 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1416 EndDialog(hDlg
, FALSE
);
1420 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1421 * must be registered and the Help button must be shown.
1423 if (lppd
->Flags
& PD_SHOWHELP
) {
1424 if((PrintStructures
->HelpMessageID
=
1425 RegisterWindowMessageW(HELPMSGSTRINGW
)) == 0) {
1426 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL
);
1430 PrintStructures
->HelpMessageID
= 0;
1432 if(!(lppd
->Flags
&PD_PRINTSETUP
)) {
1433 PrintStructures
->hwndUpDown
=
1434 CreateUpDownControl(WS_CHILD
| WS_VISIBLE
| WS_BORDER
|
1435 UDS_NOTHOUSANDS
| UDS_ARROWKEYS
|
1436 UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, 0, 0, 0, 0,
1437 hDlg
, UPDOWN_ID
, COMDLG32_hInstance
,
1438 GetDlgItem(hDlg
, edt3
), MAX_COPIES
, 1, 1);
1441 /* FIXME: I allow more freedom than either Win95 or WinNT,
1442 * which do not agree to what errors should be thrown or not
1443 * in case nToPage or nFromPage is out-of-range.
1445 if (lppd
->nMaxPage
< lppd
->nMinPage
)
1446 lppd
->nMaxPage
= lppd
->nMinPage
;
1447 if (lppd
->nMinPage
== lppd
->nMaxPage
)
1448 lppd
->Flags
|= PD_NOPAGENUMS
;
1449 if (lppd
->nToPage
< lppd
->nMinPage
)
1450 lppd
->nToPage
= lppd
->nMinPage
;
1451 if (lppd
->nToPage
> lppd
->nMaxPage
)
1452 lppd
->nToPage
= lppd
->nMaxPage
;
1453 if (lppd
->nFromPage
< lppd
->nMinPage
)
1454 lppd
->nFromPage
= lppd
->nMinPage
;
1455 if (lppd
->nFromPage
> lppd
->nMaxPage
)
1456 lppd
->nFromPage
= lppd
->nMaxPage
;
1458 /* if we have the combo box, fill it */
1459 if (GetDlgItem(hDlg
,comboID
)) {
1462 pdn
= GlobalLock(lppd
->hDevNames
);
1463 pdm
= GlobalLock(lppd
->hDevMode
);
1465 name
= (WCHAR
*)pdn
+ pdn
->wDeviceOffset
;
1467 name
= pdm
->dmDeviceName
;
1468 PRINTDLG_SetUpPrinterListComboW(hDlg
, comboID
, name
);
1469 if(pdm
) GlobalUnlock(lppd
->hDevMode
);
1470 if(pdn
) GlobalUnlock(lppd
->hDevNames
);
1472 /* Now find selected printer and update rest of dlg */
1473 /* ansi is ok here */
1474 name
= HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR
));
1475 if (GetDlgItemTextW(hDlg
, comboID
, name
, 255))
1476 PRINTDLG_ChangePrinterW(hDlg
, name
, PrintStructures
);
1477 HeapFree(GetProcessHeap(),0,name
);
1479 /* else use default printer */
1481 DWORD dwBufLen
= sizeof(name
) / sizeof(WCHAR
);
1482 BOOL ret
= GetDefaultPrinterW(name
, &dwBufLen
);
1485 PRINTDLG_ChangePrinterW(hDlg
, name
, PrintStructures
);
1487 FIXME("No default printer found, expect problems!\n");
1492 /***********************************************************************
1493 * PRINTDLG_WMCommand [internal]
1495 LRESULT
PRINTDLG_WMCommandA(HWND hDlg
, WPARAM wParam
,
1496 LPARAM lParam
, PRINT_PTRA
* PrintStructures
)
1498 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1499 UINT PrinterComboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1500 LPDEVMODEA lpdm
= PrintStructures
->lpDevMode
;
1502 switch (LOWORD(wParam
)) {
1504 TRACE(" OK button was hit\n");
1505 if (!PRINTDLG_UpdatePrintDlgA(hDlg
, PrintStructures
)) {
1506 FIXME("Update printdlg was not successful!\n");
1509 EndDialog(hDlg
, TRUE
);
1513 TRACE(" CANCEL button was hit\n");
1514 EndDialog(hDlg
, FALSE
);
1518 TRACE(" HELP button was hit\n");
1519 SendMessageA(lppd
->hwndOwner
, PrintStructures
->HelpMessageID
,
1520 (WPARAM
) hDlg
, (LPARAM
) lppd
);
1523 case chx2
: /* collate pages checkbox */
1524 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
1525 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1526 (LPARAM
)PrintStructures
->hCollateIcon
);
1528 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1529 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1531 case edt1
: /* from page nr editbox */
1532 case edt2
: /* to page nr editbox */
1533 if (HIWORD(wParam
)==EN_CHANGE
) {
1536 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
1537 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
1538 if (nFromPage
!= lppd
->nFromPage
|| nToPage
!= lppd
->nToPage
)
1539 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1544 if(HIWORD(wParam
) == EN_CHANGE
) {
1545 INT copies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
1547 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1549 EnableWindow(GetDlgItem(hDlg
, chx2
), TRUE
);
1554 case psh1
: /* Print Setup */
1558 if (!PrintStructures
->dlg
.lpPrintDlg16
) {
1559 FIXME("The 32bit print dialog does not have this button!?\n");
1563 memcpy(&pdlg
,PrintStructures
->dlg
.lpPrintDlg16
,sizeof(pdlg
));
1564 pdlg
.Flags
|= PD_PRINTSETUP
;
1565 pdlg
.hwndOwner
= HWND_16(hDlg
);
1566 if (!PrintDlg16(&pdlg
))
1571 case psh2
: /* Properties button */
1574 char PrinterName
[256];
1576 GetDlgItemTextA(hDlg
, PrinterComboID
, PrinterName
, 255);
1577 if (!OpenPrinterA(PrinterName
, &hPrinter
, NULL
)) {
1578 FIXME(" Call to OpenPrinter did not succeed!\n");
1581 DocumentPropertiesA(hDlg
, hPrinter
, PrinterName
,
1582 PrintStructures
->lpDevMode
,
1583 PrintStructures
->lpDevMode
,
1584 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
1585 ClosePrinter(hPrinter
);
1589 case rad1
: /* Paperorientation */
1590 if (lppd
->Flags
& PD_PRINTSETUP
)
1592 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1593 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1594 (LPARAM
)(PrintStructures
->hPortraitIcon
));
1598 case rad2
: /* Paperorientation */
1599 if (lppd
->Flags
& PD_PRINTSETUP
)
1601 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1602 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1603 (LPARAM
)(PrintStructures
->hLandscapeIcon
));
1607 case cmb1
: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT16 */
1608 if (PrinterComboID
!= LOWORD(wParam
)) {
1612 case cmb4
: /* Printer combobox */
1613 if (HIWORD(wParam
)==CBN_SELCHANGE
) {
1614 char PrinterName
[256];
1615 GetDlgItemTextA(hDlg
, LOWORD(wParam
), PrinterName
, 255);
1616 PRINTDLG_ChangePrinterA(hDlg
, PrinterName
, PrintStructures
);
1620 case cmb2
: /* Papersize */
1622 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
1624 lpdm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageA(hDlg
, cmb2
,
1630 case cmb3
: /* Bin */
1632 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
1634 lpdm
->u1
.s1
.dmDefaultSource
= SendDlgItemMessageA(hDlg
, cmb3
,
1635 CB_GETITEMDATA
, Sel
,
1640 if(lppd
->Flags
& PD_PRINTSETUP
) {
1641 switch (LOWORD(wParam
)) {
1642 case rad1
: /* orientation */
1644 if (IsDlgButtonChecked(hDlg
, rad1
) == BST_CHECKED
) {
1645 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_PORTRAIT
) {
1646 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1647 SendDlgItemMessageA(hDlg
, stc10
, STM_SETIMAGE
,
1649 (LPARAM
)PrintStructures
->hPortraitIcon
);
1650 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
,
1652 (LPARAM
)PrintStructures
->hPortraitIcon
);
1655 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_LANDSCAPE
) {
1656 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1657 SendDlgItemMessageA(hDlg
, stc10
, STM_SETIMAGE
,
1659 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1660 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
,
1662 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1671 static LRESULT
PRINTDLG_WMCommandW(HWND hDlg
, WPARAM wParam
,
1672 LPARAM lParam
, PRINT_PTRW
* PrintStructures
)
1674 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1675 UINT PrinterComboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1676 LPDEVMODEW lpdm
= PrintStructures
->lpDevMode
;
1678 switch (LOWORD(wParam
)) {
1680 TRACE(" OK button was hit\n");
1681 if (!PRINTDLG_UpdatePrintDlgW(hDlg
, PrintStructures
)) {
1682 FIXME("Update printdlg was not successful!\n");
1685 EndDialog(hDlg
, TRUE
);
1689 TRACE(" CANCEL button was hit\n");
1690 EndDialog(hDlg
, FALSE
);
1694 TRACE(" HELP button was hit\n");
1695 SendMessageW(lppd
->hwndOwner
, PrintStructures
->HelpMessageID
,
1696 (WPARAM
) hDlg
, (LPARAM
) lppd
);
1699 case chx2
: /* collate pages checkbox */
1700 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
1701 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1702 (LPARAM
)PrintStructures
->hCollateIcon
);
1704 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1705 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1707 case edt1
: /* from page nr editbox */
1708 case edt2
: /* to page nr editbox */
1709 if (HIWORD(wParam
)==EN_CHANGE
) {
1712 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
1713 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
1714 if (nFromPage
!= lppd
->nFromPage
|| nToPage
!= lppd
->nToPage
)
1715 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1720 if(HIWORD(wParam
) == EN_CHANGE
) {
1721 INT copies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
1723 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1725 EnableWindow(GetDlgItem(hDlg
, chx2
), TRUE
);
1729 case psh1
: /* Print Setup */
1731 ERR("psh1 is called from 16bit code only, we should not get here.\n");
1734 case psh2
: /* Properties button */
1737 WCHAR PrinterName
[256];
1739 if (!GetDlgItemTextW(hDlg
, PrinterComboID
, PrinterName
, 255)) break;
1740 if (!OpenPrinterW(PrinterName
, &hPrinter
, NULL
)) {
1741 FIXME(" Call to OpenPrinter did not succeed!\n");
1744 DocumentPropertiesW(hDlg
, hPrinter
, PrinterName
,
1745 PrintStructures
->lpDevMode
,
1746 PrintStructures
->lpDevMode
,
1747 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
1748 ClosePrinter(hPrinter
);
1752 case rad1
: /* Paperorientation */
1753 if (lppd
->Flags
& PD_PRINTSETUP
)
1755 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1756 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1757 (LPARAM
)(PrintStructures
->hPortraitIcon
));
1761 case rad2
: /* Paperorientation */
1762 if (lppd
->Flags
& PD_PRINTSETUP
)
1764 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1765 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1766 (LPARAM
)(PrintStructures
->hLandscapeIcon
));
1770 case cmb1
: /* Printer Combobox in PRINT SETUP */
1772 case cmb4
: /* Printer combobox */
1773 if (HIWORD(wParam
)==CBN_SELCHANGE
) {
1774 WCHAR PrinterName
[256];
1775 GetDlgItemTextW(hDlg
, LOWORD(wParam
), PrinterName
, 255);
1776 PRINTDLG_ChangePrinterW(hDlg
, PrinterName
, PrintStructures
);
1780 case cmb2
: /* Papersize */
1782 DWORD Sel
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
1784 lpdm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageW(hDlg
, cmb2
,
1790 case cmb3
: /* Bin */
1792 DWORD Sel
= SendDlgItemMessageW(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
1794 lpdm
->u1
.s1
.dmDefaultSource
= SendDlgItemMessageW(hDlg
, cmb3
,
1795 CB_GETITEMDATA
, Sel
,
1800 if(lppd
->Flags
& PD_PRINTSETUP
) {
1801 switch (LOWORD(wParam
)) {
1802 case rad1
: /* orientation */
1804 if (IsDlgButtonChecked(hDlg
, rad1
) == BST_CHECKED
) {
1805 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_PORTRAIT
) {
1806 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1807 SendDlgItemMessageW(hDlg
, stc10
, STM_SETIMAGE
,
1809 (LPARAM
)PrintStructures
->hPortraitIcon
);
1810 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
,
1812 (LPARAM
)PrintStructures
->hPortraitIcon
);
1815 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_LANDSCAPE
) {
1816 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1817 SendDlgItemMessageW(hDlg
, stc10
, STM_SETIMAGE
,
1819 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1820 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
,
1822 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1831 /***********************************************************************
1832 * PrintDlgProcA [internal]
1834 static INT_PTR CALLBACK
PrintDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
1837 PRINT_PTRA
* PrintStructures
;
1838 INT_PTR res
= FALSE
;
1840 if (uMsg
!=WM_INITDIALOG
) {
1841 PrintStructures
= (PRINT_PTRA
*)GetPropA(hDlg
,"__WINE_PRINTDLGDATA");
1842 if (!PrintStructures
)
1845 PrintStructures
= (PRINT_PTRA
*) lParam
;
1846 SetPropA(hDlg
,"__WINE_PRINTDLGDATA",PrintStructures
);
1847 if(!check_printer_setup(hDlg
))
1849 EndDialog(hDlg
,FALSE
);
1852 res
= PRINTDLG_WMInitDialog(hDlg
, wParam
, PrintStructures
);
1854 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
)
1855 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(
1856 hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->lpPrintDlg
1861 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
) {
1862 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
,uMsg
,wParam
,
1869 return PRINTDLG_WMCommandA(hDlg
, wParam
, lParam
, PrintStructures
);
1872 DestroyIcon(PrintStructures
->hCollateIcon
);
1873 DestroyIcon(PrintStructures
->hNoCollateIcon
);
1874 DestroyIcon(PrintStructures
->hPortraitIcon
);
1875 DestroyIcon(PrintStructures
->hLandscapeIcon
);
1876 if(PrintStructures
->hwndUpDown
)
1877 DestroyWindow(PrintStructures
->hwndUpDown
);
1883 static INT_PTR CALLBACK
PrintDlgProcW(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
1886 static const WCHAR propW
[] = {'_','_','W','I','N','E','_','P','R','I','N','T','D','L','G','D','A','T','A',0};
1887 PRINT_PTRW
* PrintStructures
;
1888 INT_PTR res
= FALSE
;
1890 if (uMsg
!=WM_INITDIALOG
) {
1891 PrintStructures
= (PRINT_PTRW
*) GetPropW(hDlg
, propW
);
1892 if (!PrintStructures
)
1895 PrintStructures
= (PRINT_PTRW
*) lParam
;
1896 SetPropW(hDlg
, propW
, PrintStructures
);
1897 if(!check_printer_setup(hDlg
))
1899 EndDialog(hDlg
,FALSE
);
1902 res
= PRINTDLG_WMInitDialogW(hDlg
, wParam
, PrintStructures
);
1904 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
)
1905 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->lpPrintDlg
);
1909 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
) {
1910 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
,uMsg
,wParam
, lParam
);
1916 return PRINTDLG_WMCommandW(hDlg
, wParam
, lParam
, PrintStructures
);
1919 DestroyIcon(PrintStructures
->hCollateIcon
);
1920 DestroyIcon(PrintStructures
->hNoCollateIcon
);
1921 DestroyIcon(PrintStructures
->hPortraitIcon
);
1922 DestroyIcon(PrintStructures
->hLandscapeIcon
);
1923 if(PrintStructures
->hwndUpDown
)
1924 DestroyWindow(PrintStructures
->hwndUpDown
);
1930 /************************************************************
1932 * PRINTDLG_GetDlgTemplate
1935 static HGLOBAL
PRINTDLG_GetDlgTemplateA(const PRINTDLGA
*lppd
)
1940 if (lppd
->Flags
& PD_PRINTSETUP
) {
1941 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
1942 hDlgTmpl
= lppd
->hSetupTemplate
;
1943 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
1944 hResInfo
= FindResourceA(lppd
->hInstance
,
1945 lppd
->lpSetupTemplateName
, (LPSTR
)RT_DIALOG
);
1946 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1948 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32_SETUP",
1950 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1953 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
1954 hDlgTmpl
= lppd
->hPrintTemplate
;
1955 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
1956 hResInfo
= FindResourceA(lppd
->hInstance
,
1957 lppd
->lpPrintTemplateName
,
1959 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1961 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32",
1963 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1969 static HGLOBAL
PRINTDLG_GetDlgTemplateW(const PRINTDLGW
*lppd
)
1973 static const WCHAR xpsetup
[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
1974 static const WCHAR xprint
[] = { 'P','R','I','N','T','3','2',0};
1976 if (lppd
->Flags
& PD_PRINTSETUP
) {
1977 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
1978 hDlgTmpl
= lppd
->hSetupTemplate
;
1979 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
1980 hResInfo
= FindResourceW(lppd
->hInstance
,
1981 lppd
->lpSetupTemplateName
, (LPWSTR
)RT_DIALOG
);
1982 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1984 hResInfo
= FindResourceW(COMDLG32_hInstance
, xpsetup
, (LPWSTR
)RT_DIALOG
);
1985 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1988 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
1989 hDlgTmpl
= lppd
->hPrintTemplate
;
1990 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
1991 hResInfo
= FindResourceW(lppd
->hInstance
,
1992 lppd
->lpPrintTemplateName
,
1994 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1996 hResInfo
= FindResourceW(COMDLG32_hInstance
, xprint
, (LPWSTR
)RT_DIALOG
);
1997 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
2003 /***********************************************************************
2008 static BOOL
PRINTDLG_CreateDCA(LPPRINTDLGA lppd
)
2010 DEVNAMES
*pdn
= GlobalLock(lppd
->hDevNames
);
2011 DEVMODEA
*pdm
= GlobalLock(lppd
->hDevMode
);
2013 if(lppd
->Flags
& PD_RETURNDC
) {
2014 lppd
->hDC
= CreateDCA((char*)pdn
+ pdn
->wDriverOffset
,
2015 (char*)pdn
+ pdn
->wDeviceOffset
,
2016 (char*)pdn
+ pdn
->wOutputOffset
,
2018 } else if(lppd
->Flags
& PD_RETURNIC
) {
2019 lppd
->hDC
= CreateICA((char*)pdn
+ pdn
->wDriverOffset
,
2020 (char*)pdn
+ pdn
->wDeviceOffset
,
2021 (char*)pdn
+ pdn
->wOutputOffset
,
2024 GlobalUnlock(lppd
->hDevNames
);
2025 GlobalUnlock(lppd
->hDevMode
);
2026 return lppd
->hDC
? TRUE
: FALSE
;
2029 static BOOL
PRINTDLG_CreateDCW(LPPRINTDLGW lppd
)
2031 DEVNAMES
*pdn
= GlobalLock(lppd
->hDevNames
);
2032 DEVMODEW
*pdm
= GlobalLock(lppd
->hDevMode
);
2034 if(lppd
->Flags
& PD_RETURNDC
) {
2035 lppd
->hDC
= CreateDCW((WCHAR
*)pdn
+ pdn
->wDriverOffset
,
2036 (WCHAR
*)pdn
+ pdn
->wDeviceOffset
,
2037 (WCHAR
*)pdn
+ pdn
->wOutputOffset
,
2039 } else if(lppd
->Flags
& PD_RETURNIC
) {
2040 lppd
->hDC
= CreateICW((WCHAR
*)pdn
+ pdn
->wDriverOffset
,
2041 (WCHAR
*)pdn
+ pdn
->wDeviceOffset
,
2042 (WCHAR
*)pdn
+ pdn
->wOutputOffset
,
2045 GlobalUnlock(lppd
->hDevNames
);
2046 GlobalUnlock(lppd
->hDevMode
);
2047 return lppd
->hDC
? TRUE
: FALSE
;
2050 /***********************************************************************
2051 * PrintDlgA (COMDLG32.@)
2053 * Displays the PRINT dialog box, which enables the user to specify
2054 * specific properties of the print job.
2057 * lppd [IO] ptr to PRINTDLG32 struct
2060 * nonzero if the user pressed the OK button
2061 * zero if the user cancelled the window or an error occurred
2065 * * The Collate Icons do not display, even though they are in the code.
2066 * * The Properties Button(s) should call DocumentPropertiesA().
2069 BOOL WINAPI
PrintDlgA(LPPRINTDLGA lppd
)
2077 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
2081 hInst
= (HINSTANCE
)GetWindowLongPtrA( lppd
->hwndOwner
, GWLP_HINSTANCE
);
2082 if(TRACE_ON(commdlg
)) {
2083 char flagstr
[1000] = "";
2084 const struct pd_flags
*pflag
= pd_flags
;
2085 for( ; pflag
->name
; pflag
++) {
2086 if(lppd
->Flags
& pflag
->flag
)
2087 strcat(flagstr
, pflag
->name
);
2089 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2090 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2091 "flags %08x (%s)\n",
2092 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
2093 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
2094 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
2097 if(lppd
->lStructSize
!= sizeof(PRINTDLGA
)) {
2098 WARN("structure size failure !!!\n");
2099 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
2103 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
2104 PRINTER_INFO_2A
*pbuf
;
2105 DRIVER_INFO_3A
*dbuf
;
2109 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
2110 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2111 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2114 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
2115 WARN("Can't find default printer\n");
2116 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
2120 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
2121 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
2122 GetPrinterA(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
2124 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
2125 dbuf
= HeapAlloc(GetProcessHeap(),0,needed
);
2126 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
2127 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2128 GetLastError(),pbuf
->pPrinterName
);
2129 HeapFree(GetProcessHeap(), 0, dbuf
);
2130 HeapFree(GetProcessHeap(), 0, pbuf
);
2131 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2136 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
2140 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
2141 pbuf
->pDevMode
->dmDriverExtra
);
2142 ptr
= GlobalLock(lppd
->hDevMode
);
2143 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
2144 pbuf
->pDevMode
->dmDriverExtra
);
2145 GlobalUnlock(lppd
->hDevMode
);
2146 HeapFree(GetProcessHeap(), 0, pbuf
);
2147 HeapFree(GetProcessHeap(), 0, dbuf
);
2151 PRINT_PTRA
*PrintStructures
;
2153 /* load Dialog resources,
2154 * depending on Flags indicates Print32 or Print32_setup dialog
2156 hDlgTmpl
= PRINTDLG_GetDlgTemplateA(lppd
);
2158 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2161 ptr
= LockResource( hDlgTmpl
);
2163 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2167 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2168 sizeof(PRINT_PTRA
));
2169 PrintStructures
->lpPrintDlg
= lppd
;
2171 /* and create & process the dialog .
2172 * -1 is failure, 0 is broken hwnd, everything else is ok.
2174 bRet
= (0<DialogBoxIndirectParamA(hInst
, ptr
, lppd
->hwndOwner
,
2176 (LPARAM
)PrintStructures
));
2179 DEVMODEA
*lpdm
= PrintStructures
->lpDevMode
, *lpdmReturn
;
2180 PRINTER_INFO_2A
*pi
= PrintStructures
->lpPrinterInfo
;
2181 DRIVER_INFO_3A
*di
= PrintStructures
->lpDriverInfo
;
2183 if (lppd
->hDevMode
== 0) {
2184 TRACE(" No hDevMode yet... Need to create my own\n");
2185 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
,
2186 lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2188 lppd
->hDevMode
= GlobalReAlloc(lppd
->hDevMode
,
2189 lpdm
->dmSize
+ lpdm
->dmDriverExtra
,
2192 lpdmReturn
= GlobalLock(lppd
->hDevMode
);
2193 memcpy(lpdmReturn
, lpdm
, lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2195 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
2200 GlobalUnlock(lppd
->hDevMode
);
2202 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
2203 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpPrinterInfo
);
2204 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDriverInfo
);
2205 HeapFree(GetProcessHeap(), 0, PrintStructures
);
2207 if(bRet
&& (lppd
->Flags
& PD_RETURNDC
|| lppd
->Flags
& PD_RETURNIC
))
2208 bRet
= PRINTDLG_CreateDCA(lppd
);
2210 TRACE("exit! (%d)\n", bRet
);
2214 /***********************************************************************
2215 * PrintDlgW (COMDLG32.@)
2219 BOOL WINAPI
PrintDlgW(LPPRINTDLGW lppd
)
2227 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
2231 hInst
= (HINSTANCE
)GetWindowLongPtrW( lppd
->hwndOwner
, GWLP_HINSTANCE
);
2232 if(TRACE_ON(commdlg
)) {
2233 char flagstr
[1000] = "";
2234 const struct pd_flags
*pflag
= pd_flags
;
2235 for( ; pflag
->name
; pflag
++) {
2236 if(lppd
->Flags
& pflag
->flag
)
2237 strcat(flagstr
, pflag
->name
);
2239 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2240 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2241 "flags %08x (%s)\n",
2242 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
2243 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
2244 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
2247 if(lppd
->lStructSize
!= sizeof(PRINTDLGW
)) {
2248 WARN("structure size failure !!!\n");
2249 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
2253 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
2254 PRINTER_INFO_2W
*pbuf
;
2255 DRIVER_INFO_3W
*dbuf
;
2259 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
2260 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2261 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2264 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
2265 WARN("Can't find default printer\n");
2266 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
2270 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
2271 pbuf
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*needed
);
2272 GetPrinterW(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
2274 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
2275 dbuf
= HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*needed
);
2276 if (!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
2277 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2278 GetLastError(),debugstr_w(pbuf
->pPrinterName
));
2279 HeapFree(GetProcessHeap(), 0, dbuf
);
2280 HeapFree(GetProcessHeap(), 0, pbuf
);
2281 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2286 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
2290 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
2291 pbuf
->pDevMode
->dmDriverExtra
);
2292 ptr
= GlobalLock(lppd
->hDevMode
);
2293 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
2294 pbuf
->pDevMode
->dmDriverExtra
);
2295 GlobalUnlock(lppd
->hDevMode
);
2296 HeapFree(GetProcessHeap(), 0, pbuf
);
2297 HeapFree(GetProcessHeap(), 0, dbuf
);
2301 PRINT_PTRW
*PrintStructures
;
2303 /* load Dialog resources,
2304 * depending on Flags indicates Print32 or Print32_setup dialog
2306 hDlgTmpl
= PRINTDLG_GetDlgTemplateW(lppd
);
2308 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2311 ptr
= LockResource( hDlgTmpl
);
2313 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2317 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2318 sizeof(PRINT_PTRW
));
2319 PrintStructures
->lpPrintDlg
= lppd
;
2321 /* and create & process the dialog .
2322 * -1 is failure, 0 is broken hwnd, everything else is ok.
2324 bRet
= (0<DialogBoxIndirectParamW(hInst
, ptr
, lppd
->hwndOwner
,
2326 (LPARAM
)PrintStructures
));
2329 DEVMODEW
*lpdm
= PrintStructures
->lpDevMode
, *lpdmReturn
;
2330 PRINTER_INFO_2W
*pi
= PrintStructures
->lpPrinterInfo
;
2331 DRIVER_INFO_3W
*di
= PrintStructures
->lpDriverInfo
;
2333 if (lppd
->hDevMode
== 0) {
2334 TRACE(" No hDevMode yet... Need to create my own\n");
2335 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
,
2336 lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2339 if((locks
= (GlobalFlags(lppd
->hDevMode
) & GMEM_LOCKCOUNT
))) {
2340 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks
);
2342 GlobalUnlock(lppd
->hDevMode
);
2343 TRACE("Now got %d locks\n", locks
);
2346 lppd
->hDevMode
= GlobalReAlloc(lppd
->hDevMode
,
2347 lpdm
->dmSize
+ lpdm
->dmDriverExtra
,
2350 lpdmReturn
= GlobalLock(lppd
->hDevMode
);
2351 memcpy(lpdmReturn
, lpdm
, lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2353 if (lppd
->hDevNames
!= 0) {
2355 if((locks
= (GlobalFlags(lppd
->hDevNames
) & GMEM_LOCKCOUNT
))) {
2356 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks
);
2358 GlobalUnlock(lppd
->hDevNames
);
2361 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
2366 GlobalUnlock(lppd
->hDevMode
);
2368 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
2369 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpPrinterInfo
);
2370 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDriverInfo
);
2371 HeapFree(GetProcessHeap(), 0, PrintStructures
);
2373 if(bRet
&& (lppd
->Flags
& PD_RETURNDC
|| lppd
->Flags
& PD_RETURNIC
))
2374 bRet
= PRINTDLG_CreateDCW(lppd
);
2376 TRACE("exit! (%d)\n", bRet
);
2380 /***********************************************************************
2385 * cmb1 - printer select (not in standard dialog template)
2387 * cmb3 - source (tray?)
2388 * edt4 - border left
2390 * edt6 - border right
2391 * edt7 - border bottom
2392 * psh3 - "Printer..."
2396 LPPAGESETUPDLGA dlga
; /* Handler to user defined struct */
2398 HWND hDlg
; /* Page Setup dialog handler */
2399 PAGESETUPDLGA curdlg
; /* Stores the current dialog state */
2400 RECT rtDrawRect
; /* Drawing rect for page */
2404 LPPAGESETUPDLGW dlgw
;
2406 PAGESETUPDLGW curdlg
; /* Current dialog state */
2410 static HGLOBAL
PRINTDLG_GetPGSTemplateA(const PAGESETUPDLGA
*lppd
)
2415 if(lppd
->Flags
& PSD_ENABLEPAGESETUPTEMPLATEHANDLE
) {
2416 hDlgTmpl
= lppd
->hPageSetupTemplate
;
2417 } else if(lppd
->Flags
& PSD_ENABLEPAGESETUPTEMPLATE
) {
2418 hResInfo
= FindResourceA(lppd
->hInstance
,
2419 lppd
->lpPageSetupTemplateName
, (LPSTR
)RT_DIALOG
);
2420 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
2422 hResInfo
= FindResourceA(COMDLG32_hInstance
,(LPCSTR
)PAGESETUPDLGORD
,(LPSTR
)RT_DIALOG
);
2423 hDlgTmpl
= LoadResource(COMDLG32_hInstance
,hResInfo
);
2428 static HGLOBAL
PRINTDLG_GetPGSTemplateW(const PAGESETUPDLGW
*lppd
)
2433 if(lppd
->Flags
& PSD_ENABLEPAGESETUPTEMPLATEHANDLE
) {
2434 hDlgTmpl
= lppd
->hPageSetupTemplate
;
2435 } else if(lppd
->Flags
& PSD_ENABLEPAGESETUPTEMPLATE
) {
2436 hResInfo
= FindResourceW(lppd
->hInstance
,
2437 lppd
->lpPageSetupTemplateName
, (LPWSTR
)RT_DIALOG
);
2438 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
2440 hResInfo
= FindResourceW(COMDLG32_hInstance
,(LPCWSTR
)PAGESETUPDLGORD
,(LPWSTR
)RT_DIALOG
);
2441 hDlgTmpl
= LoadResource(COMDLG32_hInstance
,hResInfo
);
2447 _c_10mm2size(PAGESETUPDLGA
*dlga
,DWORD size
) {
2448 if (dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
)
2449 return 10*size
*100/254;
2450 /* If we don't have a flag, we can choose one. Use millimeters
2451 * to avoid confusing me
2453 dlga
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
2459 _c_inch2size(PAGESETUPDLGA
*dlga
,DWORD size
) {
2460 if (dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
)
2462 if (dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
)
2463 return (size
*254)/100;
2464 /* if we don't have a flag, we can choose one. Use millimeters
2465 * to avoid confusing me
2467 dlga
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
2468 return (size
*254)/100;
2472 _c_size2strA(PageSetupDataA
*pda
,DWORD size
,LPSTR strout
) {
2473 strcpy(strout
,"<undef>");
2474 if (pda
->dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
) {
2475 sprintf(strout
,"%d",(size
)/100);
2478 if (pda
->dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
) {
2479 sprintf(strout
,"%din",(size
)/1000);
2482 pda
->dlga
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
2483 sprintf(strout
,"%d",(size
)/100);
2487 _c_size2strW(PageSetupDataW
*pdw
,DWORD size
,LPWSTR strout
) {
2488 static const char mm_fmt
[] = "%.2f mm";
2489 static const char in_fmt
[] = "%.2f in";
2491 if (pdw
->dlgw
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
) {
2492 sprintf(buf
, mm_fmt
, (size
* 1.0) / 100.0);
2493 } else if (pdw
->dlgw
->Flags
& PSD_INTHOUSANDTHSOFINCHES
) {
2494 sprintf(buf
, in_fmt
, (size
* 1.0) / 1000.0);
2496 pdw
->dlgw
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
2497 sprintf(buf
, mm_fmt
, (size
* 1.0) / 100.0);
2500 MultiByteToWideChar(CP_ACP
, 0, buf
, -1, strout
, 20);
2504 _c_str2sizeA(const PAGESETUPDLGA
*dlga
, LPCSTR strin
) {
2509 if (!sscanf(strin
,"%f%s",&val
,rest
))
2512 if (!strcmp(rest
,"in") || !strcmp(rest
,"inch")) {
2513 if (dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
)
2516 return val
*25.4*100;
2518 if (!strcmp(rest
,"cm")) { rest
[0]='m'; val
= val
*10.0; }
2519 if (!strcmp(rest
,"m")) { strcpy(rest
,"mm"); val
= val
*1000.0; }
2521 if (!strcmp(rest
,"mm")) {
2522 if (dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
)
2525 return 1000.0*val
/25.4;
2527 if (rest
[0]=='\0') {
2528 /* use application supplied default */
2529 if (dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
) {
2533 if (dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
) {
2538 ERR("Did not find a conversion for type '%s'!\n",rest
);
2544 _c_str2sizeW(const PAGESETUPDLGW
*dlga
, LPCWSTR strin
) {
2547 /* this W -> A transition is OK */
2548 /* we need a unicode version of sscanf to avoid it */
2549 WideCharToMultiByte(CP_ACP
, 0, strin
, -1, buf
, sizeof(buf
), NULL
, NULL
);
2550 return _c_str2sizeA((const PAGESETUPDLGA
*)dlga
, buf
);
2554 /****************************************************************************
2555 * PRINTDLG_PS_UpdateDlgStructA
2557 * Updates pda->dlga structure
2558 * Function calls when user presses OK button
2561 * hDlg [in] main window dialog HANDLE
2562 * pda [in/out] ptr to PageSetupDataA structure
2568 PRINTDLG_PS_UpdateDlgStructA(HWND hDlg
, PageSetupDataA
*pda
) {
2573 memcpy(pda
->dlga
, &pda
->curdlg
, sizeof(pda
->curdlg
));
2574 pda
->dlga
->hDevMode
= pda
->pdlg
.hDevMode
;
2575 pda
->dlga
->hDevNames
= pda
->pdlg
.hDevNames
;
2577 dn
= GlobalLock(pda
->pdlg
.hDevNames
);
2578 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2580 /* Save paper orientation into device context */
2581 if(pda
->curdlg
.ptPaperSize
.x
> pda
->curdlg
.ptPaperSize
.y
)
2582 dm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
2584 dm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
2586 /* Save paper size into the device context */
2587 paperword
= SendDlgItemMessageA(hDlg
,cmb2
,CB_GETITEMDATA
,
2588 SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0), 0);
2589 if (paperword
!= CB_ERR
)
2590 dm
->u1
.s1
.dmPaperSize
= paperword
;
2592 FIXME("could not get dialog text for papersize cmbbox?\n");
2594 /* Save paper source into the device context */
2595 paperword
= SendDlgItemMessageA(hDlg
,cmb1
,CB_GETITEMDATA
,
2596 SendDlgItemMessageA(hDlg
, cmb1
, CB_GETCURSEL
, 0, 0), 0);
2597 if (paperword
!= CB_ERR
)
2598 dm
->u1
.s1
.dmDefaultSource
= paperword
;
2600 FIXME("could not get dialog text for papersize cmbbox?\n");
2602 GlobalUnlock(pda
->pdlg
.hDevNames
);
2603 GlobalUnlock(pda
->pdlg
.hDevMode
);
2609 PRINTDLG_PS_UpdateDlgStructW(HWND hDlg
, PageSetupDataW
*pdw
) {
2612 LPWSTR devname
,portname
;
2613 WCHAR papername
[64];
2616 dn
= GlobalLock(pdw
->pdlg
.hDevNames
);
2617 dm
= GlobalLock(pdw
->pdlg
.hDevMode
);
2618 devname
= ((WCHAR
*)dn
)+dn
->wDeviceOffset
;
2619 portname
= ((WCHAR
*)dn
)+dn
->wOutputOffset
;
2621 /* Save paper size into device context */
2622 PRINTDLG_SetUpPaperComboBoxW(hDlg
,cmb2
,devname
,portname
,dm
);
2623 /* Save paper source into device context */
2624 PRINTDLG_SetUpPaperComboBoxW(hDlg
,cmb3
,devname
,portname
,dm
);
2626 if (GetDlgItemTextW(hDlg
,cmb2
,papername
,sizeof(papername
)/sizeof(papername
[0]))>0) {
2627 PRINTDLG_PaperSizeW(&(pdw
->pdlg
),papername
,&(pdw
->dlgw
->ptPaperSize
));
2628 pdw
->dlgw
->ptPaperSize
.x
= _c_10mm2size((LPPAGESETUPDLGA
)pdw
->dlgw
,pdw
->dlgw
->ptPaperSize
.x
);
2629 pdw
->dlgw
->ptPaperSize
.y
= _c_10mm2size((LPPAGESETUPDLGA
)pdw
->dlgw
,pdw
->dlgw
->ptPaperSize
.y
);
2631 FIXME("could not get dialog text for papersize cmbbox?\n");
2632 #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); }
2633 GETVAL(edt4
,pdw
->dlgw
->rtMargin
.left
);
2634 GETVAL(edt5
,pdw
->dlgw
->rtMargin
.top
);
2635 GETVAL(edt6
,pdw
->dlgw
->rtMargin
.right
);
2636 GETVAL(edt7
,pdw
->dlgw
->rtMargin
.bottom
);
2639 /* If we are in landscape, swap x and y of page size */
2640 if (IsDlgButtonChecked(hDlg
, rad2
)) {
2642 tmp
= pdw
->dlgw
->ptPaperSize
.x
;
2643 pdw
->dlgw
->ptPaperSize
.x
= pdw
->dlgw
->ptPaperSize
.y
;
2644 pdw
->dlgw
->ptPaperSize
.y
= tmp
;
2647 /* Save orientation */
2648 if (pdw
->dlgw
->ptPaperSize
.x
> pdw
->dlgw
->ptPaperSize
.y
)
2649 dm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
2651 dm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
2653 GlobalUnlock(pdw
->pdlg
.hDevNames
);
2654 GlobalUnlock(pdw
->pdlg
.hDevMode
);
2658 /**********************************************************************************************
2659 * PRINTDLG_PS_ChangeActivePrinerA
2661 * Redefines hDevMode and hDevNames HANDLES and initialises it.
2664 * name [in] Name of a printer for activation
2665 * pda [in/out] ptr to PageSetupDataA structure
2672 PRINTDLG_PS_ChangeActivePrinterA(LPSTR name
, PageSetupDataA
*pda
){
2675 LPPRINTER_INFO_2A lpPrinterInfo
;
2676 LPDRIVER_INFO_3A lpDriverInfo
;
2677 DEVMODEA
*pDevMode
, *dm
;
2679 if(!OpenPrinterA(name
, &hprn
, NULL
)){
2680 ERR("Can't open printer %s\n", name
);
2683 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
2684 lpPrinterInfo
= HeapAlloc(GetProcessHeap(), 0, needed
);
2685 GetPrinterA(hprn
, 2, (LPBYTE
)lpPrinterInfo
, needed
, &needed
);
2686 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
2687 lpDriverInfo
= HeapAlloc(GetProcessHeap(), 0, needed
);
2688 if(!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)lpDriverInfo
, needed
, &needed
)) {
2689 ERR("GetPrinterDriverA failed for %s, fix your config!\n", lpPrinterInfo
->pPrinterName
);
2690 HeapFree(GetProcessHeap(), 0, lpDriverInfo
);
2691 HeapFree(GetProcessHeap(), 0, lpPrinterInfo
);
2696 needed
= DocumentPropertiesA(0, 0, name
, NULL
, NULL
, 0);
2698 ERR("DocumentProperties fails on %s\n", debugstr_a(name
));
2699 HeapFree(GetProcessHeap(), 0, lpDriverInfo
);
2700 HeapFree(GetProcessHeap(), 0, lpPrinterInfo
);
2703 pDevMode
= HeapAlloc(GetProcessHeap(), 0, needed
);
2704 DocumentPropertiesA(0, 0, name
, pDevMode
, NULL
, DM_OUT_BUFFER
);
2706 pda
->pdlg
.hDevMode
= GlobalReAlloc(pda
->pdlg
.hDevMode
,
2707 pDevMode
->dmSize
+ pDevMode
->dmDriverExtra
,
2709 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2710 memcpy(dm
, pDevMode
, pDevMode
->dmSize
+ pDevMode
->dmDriverExtra
);
2712 PRINTDLG_CreateDevNames(&(pda
->pdlg
.hDevNames
),
2713 lpDriverInfo
->pDriverPath
,
2714 lpPrinterInfo
->pPrinterName
,
2715 lpPrinterInfo
->pPortName
);
2717 GlobalUnlock(pda
->pdlg
.hDevMode
);
2718 HeapFree(GetProcessHeap(), 0, pDevMode
);
2719 HeapFree(GetProcessHeap(), 0, lpPrinterInfo
);
2720 HeapFree(GetProcessHeap(), 0, lpDriverInfo
);
2724 /****************************************************************************************
2725 * PRINTDLG_PS_ChangePrinterA
2727 * Fills Printers, Paper and Source combo
2733 PRINTDLG_PS_ChangePrinterA(HWND hDlg
, PageSetupDataA
*pda
) {
2736 LPSTR devname
,portname
;
2738 dn
= GlobalLock(pda
->pdlg
.hDevNames
);
2739 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2740 devname
= ((char*)dn
)+dn
->wDeviceOffset
;
2741 portname
= ((char*)dn
)+dn
->wOutputOffset
;
2742 PRINTDLG_SetUpPrinterListComboA(hDlg
, cmb1
, devname
);
2743 PRINTDLG_SetUpPaperComboBoxA(hDlg
,cmb2
,devname
,portname
,dm
);
2744 PRINTDLG_SetUpPaperComboBoxA(hDlg
,cmb3
,devname
,portname
,dm
);
2745 GlobalUnlock(pda
->pdlg
.hDevNames
);
2746 GlobalUnlock(pda
->pdlg
.hDevMode
);
2750 static void PRINTDLG_PS_SetOrientationW(HWND hDlg
, PageSetupDataW
* pdw
)
2752 WCHAR PaperName
[64];
2754 GetDlgItemTextW(hDlg
, cmb2
, PaperName
, sizeof(PaperName
)/sizeof(WCHAR
));
2755 PRINTDLG_PaperSizeW(&pdw
->pdlg
, PaperName
, &pdw
->curdlg
.ptPaperSize
);
2756 pdw
->curdlg
.ptPaperSize
.x
= _c_10mm2size((LPPAGESETUPDLGA
)pdw
->dlgw
, pdw
->curdlg
.ptPaperSize
.x
);
2757 pdw
->curdlg
.ptPaperSize
.y
= _c_10mm2size((LPPAGESETUPDLGA
)pdw
->dlgw
, pdw
->curdlg
.ptPaperSize
.y
);
2759 if(IsDlgButtonChecked(hDlg
, rad2
))
2761 DWORD tmp
= pdw
->curdlg
.ptPaperSize
.x
;
2762 pdw
->curdlg
.ptPaperSize
.x
= pdw
->curdlg
.ptPaperSize
.y
;
2763 pdw
->curdlg
.ptPaperSize
.y
= tmp
;
2767 static void PRINTDLG_PS_UpdatePrintDlgW(PageSetupDataW
* pdw
, HWND hDlg
)
2772 dm
= GlobalLock(pdw
->pdlg
.hDevMode
);
2777 if(pdw
->curdlg
.ptPaperSize
.y
> pdw
->curdlg
.ptPaperSize
.x
)
2778 dm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
2780 dm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
2782 sel
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
2785 dm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETITEMDATA
, sel
, 0);
2787 GlobalUnlock(pdw
->pdlg
.hDevMode
);
2791 PRINTDLG_PS_ChangePrinterW(HWND hDlg
, PageSetupDataW
*pdw
) {
2794 LPWSTR devname
,portname
;
2796 dn
= GlobalLock(pdw
->pdlg
.hDevNames
);
2797 dm
= GlobalLock(pdw
->pdlg
.hDevMode
);
2798 devname
= ((WCHAR
*)dn
)+dn
->wDeviceOffset
;
2799 portname
= ((WCHAR
*)dn
)+dn
->wOutputOffset
;
2800 PRINTDLG_SetUpPaperComboBoxW(hDlg
,cmb2
,devname
,portname
,dm
);
2801 PRINTDLG_SetUpPaperComboBoxW(hDlg
,cmb3
,devname
,portname
,dm
);
2803 /* Landscape orientation */
2804 if (dm
->u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
)
2805 CheckRadioButton(hDlg
, rad1
, rad2
, rad2
);
2806 else /* this is default if papersize is not set */
2807 CheckRadioButton(hDlg
, rad1
, rad2
, rad1
);
2809 GlobalUnlock(pdw
->pdlg
.hDevNames
);
2810 GlobalUnlock(pdw
->pdlg
.hDevMode
);
2812 PRINTDLG_PS_SetOrientationW(hDlg
, pdw
);
2817 /******************************************************************************************
2818 * PRINTDLG_PS_ChangePaperPrev
2820 * Changes paper preview size / position
2823 * pda [i] Pointer for current PageSetupDataA structure
2829 PRINTDLG_PS_ChangePaperPrev(const PageSetupDataA
*pda
)
2831 LONG width
, height
, x
, y
;
2834 if(pda
->curdlg
.ptPaperSize
.x
> pda
->curdlg
.ptPaperSize
.y
) {
2835 width
= pda
->rtDrawRect
.right
- pda
->rtDrawRect
.left
;
2836 height
= pda
->curdlg
.ptPaperSize
.y
* width
/ pda
->curdlg
.ptPaperSize
.x
;
2838 height
= pda
->rtDrawRect
.bottom
- pda
->rtDrawRect
.top
;
2839 width
= pda
->curdlg
.ptPaperSize
.x
* height
/ pda
->curdlg
.ptPaperSize
.y
;
2841 x
= (pda
->rtDrawRect
.right
+ pda
->rtDrawRect
.left
- width
) / 2;
2842 y
= (pda
->rtDrawRect
.bottom
+ pda
->rtDrawRect
.top
- height
) / 2;
2843 TRACE("rtDrawRect(%d, %d, %d, %d) x=%d, y=%d, w=%d, h=%d\n",
2844 pda
->rtDrawRect
.left
, pda
->rtDrawRect
.top
, pda
->rtDrawRect
.right
, pda
->rtDrawRect
.bottom
,
2845 x
, y
, width
, height
);
2848 MoveWindow(GetDlgItem(pda
->hDlg
, rct2
), x
+width
, y
+SHADOW
, SHADOW
, height
, FALSE
);
2849 MoveWindow(GetDlgItem(pda
->hDlg
, rct3
), x
+SHADOW
, y
+height
, width
, SHADOW
, FALSE
);
2850 MoveWindow(GetDlgItem(pda
->hDlg
, rct1
), x
, y
, width
, height
, FALSE
);
2851 rtTmp
= pda
->rtDrawRect
;
2852 rtTmp
.right
+= SHADOW
;
2853 rtTmp
.bottom
+= SHADOW
;
2856 InvalidateRect(pda
->hDlg
, &rtTmp
, TRUE
);
2860 #define GETVAL(idc,val) \
2861 if(msg == EN_CHANGE){ \
2862 if (GetDlgItemTextA(hDlg,idc,buf,sizeof(buf)) > 0)\
2863 val = _c_str2sizeA(pda->dlga,buf); \
2865 FIXME("could not get dlgitemtexta for %x\n",id); \
2868 /********************************************************************************
2869 * PRINTDLG_PS_WMCommandA
2870 * process WM_COMMAND message for PageSetupDlgA
2873 * hDlg [in] Main dialog HANDLE
2874 * wParam [in] WM_COMMAND wParam
2875 * lParam [in] WM_COMMAND lParam
2876 * pda [in/out] ptr to PageSetupDataA
2880 PRINTDLG_PS_WMCommandA(
2881 HWND hDlg
, WPARAM wParam
, LPARAM lParam
, PageSetupDataA
*pda
2883 WORD msg
= HIWORD(wParam
);
2884 WORD id
= LOWORD(wParam
);
2887 TRACE("loword (lparam) %d, wparam 0x%lx, lparam %08lx\n",
2888 LOWORD(lParam
),wParam
,lParam
);
2891 if (!PRINTDLG_PS_UpdateDlgStructA(hDlg
, pda
))
2893 EndDialog(hDlg
, TRUE
);
2897 EndDialog(hDlg
, FALSE
);
2901 pda
->pdlg
.Flags
= 0;
2902 pda
->pdlg
.hwndOwner
= hDlg
;
2903 if (PrintDlgA(&(pda
->pdlg
)))
2904 PRINTDLG_PS_ChangePrinterA(hDlg
,pda
);
2909 if((id
== rad1
&& pda
->curdlg
.ptPaperSize
.x
> pda
->curdlg
.ptPaperSize
.y
) ||
2910 (id
== rad2
&& pda
->curdlg
.ptPaperSize
.y
> pda
->curdlg
.ptPaperSize
.x
))
2914 DWORD tmp
= pda
->curdlg
.ptPaperSize
.x
;
2916 pda
->curdlg
.ptPaperSize
.x
= pda
->curdlg
.ptPaperSize
.y
;
2917 pda
->curdlg
.ptPaperSize
.y
= tmp
;
2919 GetDlgItemTextA(hDlg
, edt4
, TmpText
, sizeof(TmpText
));
2920 GetDlgItemTextA(hDlg
, edt5
, TmpText2
, sizeof(TmpText2
));
2921 SetDlgItemTextA(hDlg
, edt5
, TmpText
);
2922 SetDlgItemTextA(hDlg
, edt4
, TmpText2
);
2924 GetDlgItemTextA(hDlg
, edt6
, TmpText
, sizeof(TmpText
));
2925 GetDlgItemTextA(hDlg
, edt7
, TmpText2
, sizeof(TmpText2
));
2926 SetDlgItemTextA(hDlg
, edt7
, TmpText
);
2927 SetDlgItemTextA(hDlg
, edt6
, TmpText2
);
2929 PRINTDLG_PS_ChangePaperPrev(pda
);
2932 case cmb1
: /* Printer combo */
2933 if(msg
== CBN_SELCHANGE
){
2934 char crPrinterName
[256];
2935 GetDlgItemTextA(hDlg
, id
, crPrinterName
, 255);
2936 PRINTDLG_PS_ChangeActivePrinterA(crPrinterName
, pda
);
2937 PRINTDLG_PS_ChangePrinterA(hDlg
, pda
);
2940 case cmb2
: /* Paper combo */
2941 if(msg
== CBN_SELCHANGE
){
2942 DWORD paperword
= SendDlgItemMessageA(hDlg
,cmb2
,CB_GETITEMDATA
,
2943 SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0), 0);
2944 if (paperword
!= CB_ERR
) {
2945 PRINTDLG_PaperSizeA(&(pda
->pdlg
), paperword
,&(pda
->curdlg
.ptPaperSize
));
2946 pda
->curdlg
.ptPaperSize
.x
= _c_10mm2size(pda
->dlga
,pda
->curdlg
.ptPaperSize
.x
);
2947 pda
->curdlg
.ptPaperSize
.y
= _c_10mm2size(pda
->dlga
,pda
->curdlg
.ptPaperSize
.y
);
2949 if (IsDlgButtonChecked(hDlg
, rad2
)) {
2950 DWORD tmp
= pda
->curdlg
.ptPaperSize
.x
;
2951 pda
->curdlg
.ptPaperSize
.x
= pda
->curdlg
.ptPaperSize
.y
;
2952 pda
->curdlg
.ptPaperSize
.y
= tmp
;
2954 PRINTDLG_PS_ChangePaperPrev(pda
);
2956 FIXME("could not get dialog text for papersize cmbbox?\n");
2960 if(msg
== CBN_SELCHANGE
){
2961 DEVMODEA
*dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2962 dm
->u1
.s1
.dmDefaultSource
= SendDlgItemMessageA(hDlg
, cmb3
,CB_GETITEMDATA
,
2963 SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0), 0);
2964 GlobalUnlock(pda
->pdlg
.hDevMode
);
2967 case psh2
: /* Printer Properties button */
2970 char PrinterName
[256];
2975 GetDlgItemTextA(hDlg
, cmb1
, PrinterName
, 255);
2976 if (!OpenPrinterA(PrinterName
, &hPrinter
, NULL
)) {
2977 FIXME("Call to OpenPrinter did not succeed!\n");
2980 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2981 DocumentPropertiesA(hDlg
, hPrinter
, PrinterName
, dm
, dm
,
2982 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
2983 ClosePrinter(hPrinter
);
2984 /* Changing paper */
2985 PRINTDLG_PaperSizeA(&(pda
->pdlg
), dm
->u1
.s1
.dmPaperSize
, &(pda
->curdlg
.ptPaperSize
));
2986 pda
->curdlg
.ptPaperSize
.x
= _c_10mm2size(pda
->dlga
, pda
->curdlg
.ptPaperSize
.x
);
2987 pda
->curdlg
.ptPaperSize
.y
= _c_10mm2size(pda
->dlga
, pda
->curdlg
.ptPaperSize
.y
);
2988 if (dm
->u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
){
2989 DWORD tmp
= pda
->curdlg
.ptPaperSize
.x
;
2990 pda
->curdlg
.ptPaperSize
.x
= pda
->curdlg
.ptPaperSize
.y
;
2991 pda
->curdlg
.ptPaperSize
.y
= tmp
;
2992 CheckRadioButton(hDlg
, rad1
, rad2
, rad2
);
2995 CheckRadioButton(hDlg
, rad1
, rad2
, rad1
);
2996 /* Changing paper preview */
2997 PRINTDLG_PS_ChangePaperPrev(pda
);
2998 /* Selecting paper in combo */
2999 count
= SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCOUNT
, 0, 0);
3000 if(count
!= CB_ERR
){
3001 for(i
=0; i
<count
; ++i
){
3002 if(SendDlgItemMessageA(hDlg
, cmb2
, CB_GETITEMDATA
, i
, 0) == dm
->u1
.s1
.dmPaperSize
) {
3003 SendDlgItemMessageA(hDlg
, cmb2
, CB_SETCURSEL
, i
, 0);
3009 GlobalUnlock(pda
->pdlg
.hDevMode
);
3013 GETVAL(id
, pda
->curdlg
.rtMargin
.left
);
3016 GETVAL(id
, pda
->curdlg
.rtMargin
.top
);
3019 GETVAL(id
, pda
->curdlg
.rtMargin
.right
);
3022 GETVAL(id
, pda
->curdlg
.rtMargin
.bottom
);
3025 InvalidateRect(GetDlgItem(hDlg
, rct1
), NULL
, TRUE
);
3031 PRINTDLG_PS_WMCommandW(
3032 HWND hDlg
, WPARAM wParam
, LPARAM lParam
, PageSetupDataW
*pdw
3034 TRACE("loword (lparam) %d, wparam 0x%lx, lparam %08lx\n",
3035 LOWORD(lParam
),wParam
,lParam
);
3036 switch (LOWORD(wParam
)) {
3038 if (!PRINTDLG_PS_UpdateDlgStructW(hDlg
, pdw
))
3040 EndDialog(hDlg
, TRUE
);
3044 EndDialog(hDlg
, FALSE
);
3049 if((LOWORD(wParam
) == rad1
&& pdw
->curdlg
.ptPaperSize
.x
> pdw
->curdlg
.ptPaperSize
.y
) ||
3050 (LOWORD(wParam
) == rad2
&& pdw
->curdlg
.ptPaperSize
.y
> pdw
->curdlg
.ptPaperSize
.x
))
3054 DWORD tmp
= pdw
->curdlg
.ptPaperSize
.y
;
3056 pdw
->curdlg
.ptPaperSize
.y
= pdw
->curdlg
.ptPaperSize
.x
;
3057 pdw
->curdlg
.ptPaperSize
.x
= tmp
;
3059 GetDlgItemTextW(hDlg
, edt4
, tmpText
, sizeof(tmpText
)/sizeof(WCHAR
));
3060 GetDlgItemTextW(hDlg
, edt5
, tmpText2
, sizeof(tmpText2
)/sizeof(WCHAR
));
3061 SetDlgItemTextW(hDlg
, edt5
, tmpText
);
3062 SetDlgItemTextW(hDlg
, edt4
, tmpText2
);
3064 GetDlgItemTextW(hDlg
, edt6
, tmpText
, sizeof(tmpText
)/sizeof(WCHAR
));
3065 GetDlgItemTextW(hDlg
, edt7
, tmpText2
, sizeof(tmpText2
)/sizeof(WCHAR
));
3066 SetDlgItemTextW(hDlg
, edt7
, tmpText
);
3067 SetDlgItemTextW(hDlg
, edt6
, tmpText2
);
3072 pdw
->pdlg
.Flags
= 0;
3073 pdw
->pdlg
.hwndOwner
= hDlg
;
3074 PRINTDLG_PS_UpdatePrintDlgW(pdw
, hDlg
);
3075 if (PrintDlgW(&(pdw
->pdlg
)))
3076 PRINTDLG_PS_ChangePrinterW(hDlg
,pdw
);
3084 /***********************************************************************
3085 * DefaultPagePaintHook
3086 * Default hook paint procedure that receives WM_PSD_* messages from the dialog box
3087 * whenever the sample page is redrawn.
3091 PRINTDLG_DefaultPagePaintHook(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
,
3092 const PageSetupDataA
*pda
)
3094 LPRECT lprc
= (LPRECT
) lParam
;
3095 HDC hdc
= (HDC
) wParam
;
3098 HFONT hfont
, holdfont
;
3100 TRACE("uMsg: WM_USER+%d\n",uMsg
-WM_USER
);
3101 /* Call user paint hook if enable */
3102 if (pda
->dlga
->Flags
& PSD_ENABLEPAGEPAINTHOOK
)
3103 if (pda
->dlga
->lpfnPagePaintHook(hwndDlg
, uMsg
, wParam
, lParam
))
3107 /* LPPAGESETUPDLG in lParam */
3108 case WM_PSD_PAGESETUPDLG
:
3109 /* Inform about the sample page rectangle */
3110 case WM_PSD_FULLPAGERECT
:
3111 /* Inform about the margin rectangle */
3112 case WM_PSD_MINMARGINRECT
:
3115 /* Draw dashed rectangle showing margins */
3116 case WM_PSD_MARGINRECT
:
3117 hpen
= CreatePen(PS_DASH
, 1, GetSysColor(COLOR_3DSHADOW
));
3118 holdpen
= SelectObject(hdc
, hpen
);
3119 Rectangle(hdc
, lprc
->left
, lprc
->top
, lprc
->right
, lprc
->bottom
);
3120 DeleteObject(SelectObject(hdc
, holdpen
));
3122 /* Draw the fake document */
3123 case WM_PSD_GREEKTEXTRECT
:
3124 /* select a nice scalable font, because we want the text really small */
3125 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, sizeof(lf
), &lf
, 0);
3126 lf
.lfHeight
= 6; /* value chosen based on visual effect */
3127 hfont
= CreateFontIndirectW(&lf
);
3128 holdfont
= SelectObject(hdc
, hfont
);
3130 /* if text not loaded, then do so now */
3131 if (wszFakeDocumentText
[0] == '\0')
3132 LoadStringW(COMDLG32_hInstance
,
3134 wszFakeDocumentText
,
3135 sizeof(wszFakeDocumentText
)/sizeof(wszFakeDocumentText
[0]));
3137 oldbkmode
= SetBkMode(hdc
, TRANSPARENT
);
3138 DrawTextW(hdc
, wszFakeDocumentText
, -1, lprc
, DT_TOP
|DT_LEFT
|DT_NOPREFIX
|DT_WORDBREAK
);
3139 SetBkMode(hdc
, oldbkmode
);
3141 DeleteObject(SelectObject(hdc
, holdfont
));
3144 /* Envelope stamp */
3145 case WM_PSD_ENVSTAMPRECT
:
3146 /* Return address */
3147 case WM_PSD_YAFULLPAGERECT
:
3148 FIXME("envelope/stamp is not implemented\n");
3151 FIXME("Unknown message %x\n",uMsg
);
3157 /***********************************************************************
3159 * The main paint procedure for the PageSetupDlg function.
3160 * The Page Setup dialog box includes an image of a sample page that shows how
3161 * the user's selections affect the appearance of the printed output.
3162 * The image consists of a rectangle that represents the selected paper
3163 * or envelope type, with a dotted-line rectangle representing
3164 * the current margins, and partial (Greek text) characters
3165 * to show how text looks on the printed page.
3167 * The following messages in the order sends to user hook procedure:
3168 * WM_PSD_PAGESETUPDLG Draw the contents of the sample page
3169 * WM_PSD_FULLPAGERECT Inform about the bounding rectangle
3170 * WM_PSD_MINMARGINRECT Inform about the margin rectangle (min margin?)
3171 * WM_PSD_MARGINRECT Draw the margin rectangle
3172 * WM_PSD_GREEKTEXTRECT Draw the Greek text inside the margin rectangle
3173 * If any of first three messages returns TRUE, painting done.
3176 * hWnd [in] Handle to the Page Setup dialog box
3177 * uMsg [in] Received message
3180 * WM_PSD_ENVSTAMPRECT Draw in the envelope-stamp rectangle (for envelopes only)
3181 * WM_PSD_YAFULLPAGERECT Draw the return address portion (for envelopes and other paper sizes)
3184 * FALSE if all done correctly
3189 static LRESULT CALLBACK
3190 PRINTDLG_PagePaintProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3193 RECT rcClient
, rcMargin
;
3196 HBRUSH hbrush
, holdbrush
;
3197 PageSetupDataA
*pda
;
3198 int papersize
=0, orientation
=0; /* FIXME: set this values for user paint hook */
3199 double scalx
, scaly
;
3200 #define CALLPAINTHOOK(msg,lprc) PRINTDLG_DefaultPagePaintHook( hWnd, msg, (WPARAM)hdc, (LPARAM)lprc, pda)
3202 if (uMsg
!= WM_PAINT
)
3203 return CallWindowProcA(lpfnStaticWndProc
, hWnd
, uMsg
, wParam
, lParam
);
3205 /* Processing WM_PAINT message */
3206 pda
= (PageSetupDataA
*)GetPropA(hWnd
, "__WINE_PAGESETUPDLGDATA");
3208 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3211 if (PRINTDLG_DefaultPagePaintHook(hWnd
, WM_PSD_PAGESETUPDLG
, MAKELONG(papersize
, orientation
), (LPARAM
)pda
->dlga
, pda
))
3214 hdc
= BeginPaint(hWnd
, &ps
);
3215 GetClientRect(hWnd
, &rcClient
);
3217 scalx
= rcClient
.right
/ (double)pda
->curdlg
.ptPaperSize
.x
;
3218 scaly
= rcClient
.bottom
/ (double)pda
->curdlg
.ptPaperSize
.y
;
3219 rcMargin
= rcClient
;
3221 rcMargin
.left
+= pda
->curdlg
.rtMargin
.left
* scalx
;
3222 rcMargin
.top
+= pda
->curdlg
.rtMargin
.top
* scalx
;
3223 rcMargin
.right
-= pda
->curdlg
.rtMargin
.right
* scaly
;
3224 rcMargin
.bottom
-= pda
->curdlg
.rtMargin
.bottom
* scaly
;
3226 /* if the space is too small then we make sure to not draw anything */
3227 rcMargin
.left
= min(rcMargin
.left
, rcMargin
.right
);
3228 rcMargin
.top
= min(rcMargin
.top
, rcMargin
.bottom
);
3230 if (!CALLPAINTHOOK(WM_PSD_FULLPAGERECT
, &rcClient
) &&
3231 !CALLPAINTHOOK(WM_PSD_MINMARGINRECT
, &rcMargin
) )
3233 /* fill background */
3234 hbrush
= GetSysColorBrush(COLOR_3DHIGHLIGHT
);
3235 FillRect(hdc
, &rcClient
, hbrush
);
3236 holdbrush
= SelectObject(hdc
, hbrush
);
3238 hpen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DSHADOW
));
3239 holdpen
= SelectObject(hdc
, hpen
);
3241 /* paint left edge */
3242 MoveToEx(hdc
, rcClient
.left
, rcClient
.top
, NULL
);
3243 LineTo(hdc
, rcClient
.left
, rcClient
.bottom
-1);
3245 /* paint top edge */
3246 MoveToEx(hdc
, rcClient
.left
, rcClient
.top
, NULL
);
3247 LineTo(hdc
, rcClient
.right
, rcClient
.top
);
3249 hpen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DDKSHADOW
));
3250 DeleteObject(SelectObject(hdc
, hpen
));
3252 /* paint right edge */
3253 MoveToEx(hdc
, rcClient
.right
-1, rcClient
.top
, NULL
);
3254 LineTo(hdc
, rcClient
.right
-1, rcClient
.bottom
);
3256 /* paint bottom edge */
3257 MoveToEx(hdc
, rcClient
.left
, rcClient
.bottom
-1, NULL
);
3258 LineTo(hdc
, rcClient
.right
, rcClient
.bottom
-1);
3260 DeleteObject(SelectObject(hdc
, holdpen
));
3261 DeleteObject(SelectObject(hdc
, holdbrush
));
3263 CALLPAINTHOOK(WM_PSD_MARGINRECT
, &rcMargin
);
3265 /* give text a bit of a space from the frame */
3268 rcMargin
.right
-= 2;
3269 rcMargin
.bottom
-= 2;
3271 /* if the space is too small then we make sure to not draw anything */
3272 rcMargin
.left
= min(rcMargin
.left
, rcMargin
.right
);
3273 rcMargin
.top
= min(rcMargin
.top
, rcMargin
.bottom
);
3275 CALLPAINTHOOK(WM_PSD_GREEKTEXTRECT
, &rcMargin
);
3278 EndPaint(hWnd
, &ps
);
3280 #undef CALLPAINTHOOK
3283 /***********************************************************************
3284 * PRINTDLG_PageDlgProcA
3285 * Message handler for PageSetupDlgA
3287 static INT_PTR CALLBACK
3288 PRINTDLG_PageDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3291 PageSetupDataA
*pda
;
3292 INT_PTR res
= FALSE
;
3295 if (uMsg
== WM_INITDIALOG
) { /*Init dialog*/
3296 pda
= (PageSetupDataA
*)lParam
;
3297 pda
->hDlg
= hDlg
; /* saving handle to main window to PageSetupDataA structure */
3298 pda
->curdlg
= *pda
->dlga
;
3300 hDrawWnd
= GetDlgItem(hDlg
, rct1
);
3301 TRACE("set property to %p\n", pda
);
3302 SetPropA(hDlg
, "__WINE_PAGESETUPDLGDATA", pda
);
3303 SetPropA(hDrawWnd
, "__WINE_PAGESETUPDLGDATA", pda
);
3304 GetWindowRect(hDrawWnd
, &pda
->rtDrawRect
); /* Calculating rect in client coordinates where paper draws */
3305 ScreenToClient(hDlg
, (LPPOINT
)&pda
->rtDrawRect
);
3306 ScreenToClient(hDlg
, (LPPOINT
)(&pda
->rtDrawRect
.right
));
3307 lpfnStaticWndProc
= (WNDPROC
)SetWindowLongPtrW(
3310 (ULONG_PTR
)PRINTDLG_PagePaintProc
);
3312 /* FIXME: Paint hook. Must it be at begin of initialization or at end? */
3314 if (pda
->dlga
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
3315 if (!pda
->dlga
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,(LPARAM
)pda
->dlga
))
3316 FIXME("Setup page hook failed?\n");
3319 /* if printer button disabled */
3320 if (pda
->dlga
->Flags
& PSD_DISABLEPRINTER
)
3321 EnableWindow(GetDlgItem(hDlg
, psh3
), FALSE
);
3322 /* if margin edit boxes disabled */
3323 if (pda
->dlga
->Flags
& PSD_DISABLEMARGINS
) {
3324 EnableWindow(GetDlgItem(hDlg
, edt4
), FALSE
);
3325 EnableWindow(GetDlgItem(hDlg
, edt5
), FALSE
);
3326 EnableWindow(GetDlgItem(hDlg
, edt6
), FALSE
);
3327 EnableWindow(GetDlgItem(hDlg
, edt7
), FALSE
);
3329 /* Set orientation radiobutton properly */
3330 if(pda
->dlga
->hDevMode
)
3332 dm
= GlobalLock(pda
->dlga
->hDevMode
);
3333 if (dm
->u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
)
3334 CheckRadioButton(hDlg
, rad1
, rad2
, rad2
);
3335 else /* this is default if papersize is not set */
3336 CheckRadioButton(hDlg
, rad1
, rad2
, rad1
);
3337 GlobalUnlock(pda
->dlga
->hDevMode
);
3340 /* if orientation disabled */
3341 if (pda
->dlga
->Flags
& PSD_DISABLEORIENTATION
) {
3342 EnableWindow(GetDlgItem(hDlg
,rad1
),FALSE
);
3343 EnableWindow(GetDlgItem(hDlg
,rad2
),FALSE
);
3345 /* We fill them out enabled or not */
3346 if (pda
->dlga
->Flags
& PSD_MARGINS
) {
3348 _c_size2strA(pda
,pda
->dlga
->rtMargin
.left
,str
);
3349 SetDlgItemTextA(hDlg
,edt4
,str
);
3350 _c_size2strA(pda
,pda
->dlga
->rtMargin
.top
,str
);
3351 SetDlgItemTextA(hDlg
,edt5
,str
);
3352 _c_size2strA(pda
,pda
->dlga
->rtMargin
.right
,str
);
3353 SetDlgItemTextA(hDlg
,edt6
,str
);
3354 _c_size2strA(pda
,pda
->dlga
->rtMargin
.bottom
,str
);
3355 SetDlgItemTextA(hDlg
,edt7
,str
);
3357 /* default is 1 inch */
3358 DWORD size
= _c_inch2size(pda
->dlga
,1000);
3360 _c_size2strA(pda
,size
,str
);
3361 SetDlgItemTextA(hDlg
,edt4
,str
);
3362 SetDlgItemTextA(hDlg
,edt5
,str
);
3363 SetDlgItemTextA(hDlg
,edt6
,str
);
3364 SetDlgItemTextA(hDlg
,edt7
,str
);
3365 pda
->curdlg
.rtMargin
.left
= size
;
3366 pda
->curdlg
.rtMargin
.top
= size
;
3367 pda
->curdlg
.rtMargin
.right
= size
;
3368 pda
->curdlg
.rtMargin
.bottom
= size
;
3370 /* if paper disabled */
3371 if (pda
->dlga
->Flags
& PSD_DISABLEPAPER
) {
3372 EnableWindow(GetDlgItem(hDlg
,cmb2
),FALSE
);
3373 EnableWindow(GetDlgItem(hDlg
,cmb3
),FALSE
);
3375 /* filling combos: printer, paper, source. selecting current printer (from DEVMODEA) */
3376 PRINTDLG_PS_ChangePrinterA(hDlg
, pda
);
3377 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
3379 dm
->u1
.s1
.dmDefaultSource
= 15; /*FIXME: Automatic select. Does it always 15 at start? */
3380 PRINTDLG_PaperSizeA(&(pda
->pdlg
), dm
->u1
.s1
.dmPaperSize
, &pda
->curdlg
.ptPaperSize
);
3381 GlobalUnlock(pda
->pdlg
.hDevMode
);
3382 pda
->curdlg
.ptPaperSize
.x
= _c_10mm2size(pda
->dlga
, pda
->curdlg
.ptPaperSize
.x
);
3383 pda
->curdlg
.ptPaperSize
.y
= _c_10mm2size(pda
->dlga
, pda
->curdlg
.ptPaperSize
.y
);
3384 if (IsDlgButtonChecked(hDlg
, rad2
) == BST_CHECKED
) { /* Landscape orientation */
3385 DWORD tmp
= pda
->curdlg
.ptPaperSize
.y
;
3386 pda
->curdlg
.ptPaperSize
.y
= pda
->curdlg
.ptPaperSize
.x
;
3387 pda
->curdlg
.ptPaperSize
.x
= tmp
;
3390 WARN("GlobalLock(pda->pdlg.hDevMode) fail? hDevMode=%p\n", pda
->pdlg
.hDevMode
);
3391 /* Drawing paper prev */
3392 PRINTDLG_PS_ChangePaperPrev(pda
);
3395 pda
= (PageSetupDataA
*)GetPropA(hDlg
,"__WINE_PAGESETUPDLGDATA");
3397 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3400 if (pda
->dlga
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
3401 res
= pda
->dlga
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,lParam
);
3402 if (res
) return res
;
3407 return PRINTDLG_PS_WMCommandA(hDlg
, wParam
, lParam
, pda
);
3412 static INT_PTR CALLBACK
3413 PageDlgProcW(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3415 static const WCHAR __WINE_PAGESETUPDLGDATA
[] =
3416 { '_', '_', 'W', 'I', 'N', 'E', '_', 'P', 'A', 'G', 'E',
3417 'S', 'E', 'T', 'U', 'P', 'D', 'L', 'G', 'D', 'A', 'T', 'A', 0 };
3418 PageSetupDataW
*pdw
;
3421 if (uMsg
==WM_INITDIALOG
) {
3423 pdw
= (PageSetupDataW
*)lParam
;
3424 pdw
->curdlg
= *pdw
->dlgw
;
3425 SetPropW(hDlg
, __WINE_PAGESETUPDLGDATA
, pdw
);
3426 if (pdw
->dlgw
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
3427 res
= pdw
->dlgw
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,(LPARAM
)pdw
->dlgw
);
3429 FIXME("Setup page hook failed?\n");
3434 if (pdw
->dlgw
->Flags
& PSD_ENABLEPAGEPAINTHOOK
) {
3435 FIXME("PagePaintHook not yet implemented!\n");
3437 if (pdw
->dlgw
->Flags
& PSD_DISABLEPRINTER
)
3438 EnableWindow(GetDlgItem(hDlg
, psh3
), FALSE
);
3439 if (pdw
->dlgw
->Flags
& PSD_DISABLEMARGINS
) {
3440 EnableWindow(GetDlgItem(hDlg
, edt4
), FALSE
);
3441 EnableWindow(GetDlgItem(hDlg
, edt5
), FALSE
);
3442 EnableWindow(GetDlgItem(hDlg
, edt6
), FALSE
);
3443 EnableWindow(GetDlgItem(hDlg
, edt7
), FALSE
);
3446 PRINTDLG_PS_ChangePrinterW(hDlg
,pdw
);
3448 if (pdw
->dlgw
->Flags
& PSD_DISABLEORIENTATION
) {
3449 EnableWindow(GetDlgItem(hDlg
,rad1
),FALSE
);
3450 EnableWindow(GetDlgItem(hDlg
,rad2
),FALSE
);
3452 /* We fill them out enabled or not */
3453 if (pdw
->dlgw
->Flags
& PSD_MARGINS
) {
3455 _c_size2strW(pdw
,pdw
->dlgw
->rtMargin
.left
,str
);
3456 SetDlgItemTextW(hDlg
,edt4
,str
);
3457 _c_size2strW(pdw
,pdw
->dlgw
->rtMargin
.top
,str
);
3458 SetDlgItemTextW(hDlg
,edt5
,str
);
3459 _c_size2strW(pdw
,pdw
->dlgw
->rtMargin
.right
,str
);
3460 SetDlgItemTextW(hDlg
,edt6
,str
);
3461 _c_size2strW(pdw
,pdw
->dlgw
->rtMargin
.bottom
,str
);
3462 SetDlgItemTextW(hDlg
,edt7
,str
);
3464 /* default is 1 inch */
3465 DWORD size
= _c_inch2size((LPPAGESETUPDLGA
)pdw
->dlgw
,1000);
3467 _c_size2strW(pdw
,size
,str
);
3468 SetDlgItemTextW(hDlg
,edt4
,str
);
3469 SetDlgItemTextW(hDlg
,edt5
,str
);
3470 SetDlgItemTextW(hDlg
,edt6
,str
);
3471 SetDlgItemTextW(hDlg
,edt7
,str
);
3474 if (pdw
->dlgw
->Flags
& PSD_DISABLEPAPER
) {
3475 EnableWindow(GetDlgItem(hDlg
,cmb2
),FALSE
);
3476 EnableWindow(GetDlgItem(hDlg
,cmb3
),FALSE
);
3481 pdw
= (PageSetupDataW
*)GetPropW(hDlg
, __WINE_PAGESETUPDLGDATA
);
3483 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3486 if (pdw
->dlgw
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
3487 res
= pdw
->dlgw
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,lParam
);
3488 if (res
) return res
;
3493 return PRINTDLG_PS_WMCommandW(hDlg
, wParam
, lParam
, pdw
);
3498 /***********************************************************************
3499 * PageSetupDlgA (COMDLG32.@)
3501 * Displays the PAGE SETUP dialog box, which enables the user to specify
3502 * specific properties of a printed page such as
3503 * size, source, orientation and the width of the page margins.
3506 * setupdlg [IO] PAGESETUPDLGA struct
3509 * TRUE if the user pressed the OK button
3510 * FALSE if the user cancelled the window or an error occurred
3513 * The values of hDevMode and hDevNames are filled on output and can be
3514 * changed in PAGESETUPDLG when they are passed in PageSetupDlg.
3518 BOOL WINAPI
PageSetupDlgA(LPPAGESETUPDLGA setupdlg
) {
3522 PageSetupDataA
*pda
;
3525 if (setupdlg
== NULL
) {
3526 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
3531 if(TRACE_ON(commdlg
)) {
3532 char flagstr
[1000] = "";
3533 const struct pd_flags
*pflag
= psd_flags
;
3534 for( ; pflag
->name
; pflag
++) {
3535 if(setupdlg
->Flags
& pflag
->flag
) {
3536 strcat(flagstr
, pflag
->name
);
3537 strcat(flagstr
, "|");
3540 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3541 "hinst %p, flags %08x (%s)\n",
3542 setupdlg
, setupdlg
->hwndOwner
, setupdlg
->hDevMode
,
3543 setupdlg
->hDevNames
,
3544 setupdlg
->hInstance
, setupdlg
->Flags
, flagstr
);
3547 /* Checking setupdlg structure */
3548 if(setupdlg
->lStructSize
!= sizeof(PAGESETUPDLGA
)) {
3549 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
3552 if ((setupdlg
->Flags
& PSD_ENABLEPAGEPAINTHOOK
) &&
3553 (setupdlg
->lpfnPagePaintHook
== NULL
)) {
3554 COMDLG32_SetCommDlgExtendedError(CDERR_NOHOOK
);
3558 /* Initialize default printer struct. If no printer device info is specified
3559 retrieve the default printer data. */
3560 memset(&pdlg
,0,sizeof(pdlg
));
3561 pdlg
.lStructSize
= sizeof(pdlg
);
3562 if (setupdlg
->hDevMode
&& setupdlg
->hDevNames
) {
3563 pdlg
.hDevMode
= setupdlg
->hDevMode
;
3564 pdlg
.hDevNames
= setupdlg
->hDevNames
;
3566 pdlg
.Flags
= PD_RETURNDEFAULT
;
3567 bRet
= PrintDlgA(&pdlg
);
3569 if (!(setupdlg
->Flags
& PSD_NOWARNING
)) {
3571 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEFAULT_PRINTER
, errstr
, 255);
3572 MessageBoxW(setupdlg
->hwndOwner
, errstr
, 0, MB_OK
| MB_ICONERROR
);
3578 /* short cut exit, just return default values */
3579 if (setupdlg
->Flags
& PSD_RETURNDEFAULT
) {
3582 setupdlg
->hDevMode
= pdlg
.hDevMode
;
3583 setupdlg
->hDevNames
= pdlg
.hDevNames
;
3584 dm
= GlobalLock(pdlg
.hDevMode
);
3585 PRINTDLG_PaperSizeA(&pdlg
, dm
->u1
.s1
.dmPaperSize
, &setupdlg
->ptPaperSize
);
3586 GlobalUnlock(pdlg
.hDevMode
);
3587 setupdlg
->ptPaperSize
.x
=_c_10mm2size(setupdlg
,setupdlg
->ptPaperSize
.x
);
3588 setupdlg
->ptPaperSize
.y
=_c_10mm2size(setupdlg
,setupdlg
->ptPaperSize
.y
);
3592 /* get dialog template */
3593 hDlgTmpl
= PRINTDLG_GetPGSTemplateA(setupdlg
);
3595 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
3598 ptr
= LockResource( hDlgTmpl
);
3600 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
3604 pda
= HeapAlloc(GetProcessHeap(),0,sizeof(*pda
));
3605 pda
->dlga
= setupdlg
;
3608 bRet
= (0<DialogBoxIndirectParamA(
3609 setupdlg
->hInstance
,
3611 setupdlg
->hwndOwner
,
3612 PRINTDLG_PageDlgProcA
,
3616 HeapFree(GetProcessHeap(),0,pda
);
3619 /***********************************************************************
3620 * PageSetupDlgW (COMDLG32.@)
3622 * See PageSetupDlgA.
3624 BOOL WINAPI
PageSetupDlgW(LPPAGESETUPDLGW setupdlg
) {
3628 PageSetupDataW
*pdw
;
3631 FIXME("Unicode implementation is not done yet\n");
3633 if (setupdlg
== NULL
) {
3634 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
3638 if(TRACE_ON(commdlg
)) {
3639 char flagstr
[1000] = "";
3640 const struct pd_flags
*pflag
= psd_flags
;
3641 for( ; pflag
->name
; pflag
++) {
3642 if(setupdlg
->Flags
& pflag
->flag
) {
3643 strcat(flagstr
, pflag
->name
);
3644 strcat(flagstr
, "|");
3647 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3648 "hinst %p, flags %08x (%s)\n",
3649 setupdlg
, setupdlg
->hwndOwner
, setupdlg
->hDevMode
,
3650 setupdlg
->hDevNames
,
3651 setupdlg
->hInstance
, setupdlg
->Flags
, flagstr
);
3654 /* Initialize default printer struct. If no printer device info is specified
3655 retrieve the default printer data. */
3656 memset(&pdlg
,0,sizeof(pdlg
));
3657 pdlg
.lStructSize
= sizeof(pdlg
);
3658 if (setupdlg
->hDevMode
&& setupdlg
->hDevNames
) {
3659 pdlg
.hDevMode
= setupdlg
->hDevMode
;
3660 pdlg
.hDevNames
= setupdlg
->hDevNames
;
3662 pdlg
.Flags
= PD_RETURNDEFAULT
;
3663 bRet
= PrintDlgW(&pdlg
);
3665 if (!(setupdlg
->Flags
& PSD_NOWARNING
)) {
3667 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEFAULT_PRINTER
, errstr
, 255);
3668 MessageBoxW(setupdlg
->hwndOwner
, errstr
, 0, MB_OK
| MB_ICONERROR
);
3674 /* short cut exit, just return default values */
3675 if (setupdlg
->Flags
& PSD_RETURNDEFAULT
) {
3676 static const WCHAR a4
[] = {'A','4',0};
3677 setupdlg
->hDevMode
= pdlg
.hDevMode
;
3678 setupdlg
->hDevNames
= pdlg
.hDevNames
;
3679 /* FIXME: Just return "A4" for now. */
3680 PRINTDLG_PaperSizeW(&pdlg
,a4
,&setupdlg
->ptPaperSize
);
3681 setupdlg
->ptPaperSize
.x
=_c_10mm2size((LPPAGESETUPDLGA
)setupdlg
,setupdlg
->ptPaperSize
.x
);
3682 setupdlg
->ptPaperSize
.y
=_c_10mm2size((LPPAGESETUPDLGA
)setupdlg
,setupdlg
->ptPaperSize
.y
);
3685 hDlgTmpl
= PRINTDLG_GetPGSTemplateW(setupdlg
);
3687 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
3690 ptr
= LockResource( hDlgTmpl
);
3692 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
3695 pdw
= HeapAlloc(GetProcessHeap(),0,sizeof(*pdw
));
3696 pdw
->dlgw
= setupdlg
;
3699 bRet
= (0<DialogBoxIndirectParamW(
3700 setupdlg
->hInstance
,
3702 setupdlg
->hwndOwner
,
3709 /***********************************************************************
3710 * PrintDlgExA (COMDLG32.@)
3718 HRESULT WINAPI
PrintDlgExA(LPPRINTDLGEXA lppd
)
3721 FIXME("(%p) stub\n", lppd
);
3722 if ((lppd
== NULL
) || (lppd
->lStructSize
!= sizeof(PRINTDLGEXA
))) {
3723 return E_INVALIDARG
;
3726 if (!IsWindow(lppd
->hwndOwner
)) {
3733 /***********************************************************************
3734 * PrintDlgExW (COMDLG32.@)
3736 * Display the property sheet style PRINT dialog box
3739 * lppd [IO] ptr to PRINTDLGEX struct
3743 * Failure: One of the following COM error codes:
3744 * E_OUTOFMEMORY Insufficient memory.
3745 * E_INVALIDARG One or more arguments are invalid.
3746 * E_POINTER Invalid pointer.
3747 * E_HANDLE Invalid handle.
3748 * E_FAIL Unspecified error.
3751 * This Dialog enables the user to specify specific properties of the print job.
3752 * The property sheet can also have additional application-specific and
3753 * driver-specific property pages.
3759 HRESULT WINAPI
PrintDlgExW(LPPRINTDLGEXW lppd
)
3762 FIXME("(%p) stub\n", lppd
);
3763 if ((lppd
== NULL
) || (lppd
->lStructSize
!= sizeof(PRINTDLGEXW
))) {
3764 return E_INVALIDARG
;
3767 if (!IsWindow(lppd
->hwndOwner
)) {