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
8 * Copyright 2010 Vitaly Perov
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define WIN32_NO_STATUS
26 #define COM_NO_WINDOWS_H
35 #define NONAMELESSUNION
36 #define NONAMELESSSTRUCT
42 //#include "winerror.h"
44 #include <wine/unicode.h>
45 #include <wine/debug.h>
52 WINE_DEFAULT_DEBUG_CHANNEL(commdlg
);
54 /* Yes these constants are the same, but we're just copying win98 */
55 #define UPDOWN_ID 0x270f
56 #define MAX_COPIES 9999
58 /* This PRINTDLGA internal structure stores
59 * pointers to several throughout useful structures.
65 LPPRINTDLGA lpPrintDlg
;
66 LPPRINTER_INFO_2A lpPrinterInfo
;
67 LPDRIVER_INFO_3A lpDriverInfo
;
69 HICON hCollateIcon
; /* PrintDlg only */
70 HICON hNoCollateIcon
; /* PrintDlg only */
71 HICON hPortraitIcon
; /* PrintSetupDlg only */
72 HICON hLandscapeIcon
; /* PrintSetupDlg only */
79 LPPRINTDLGW lpPrintDlg
;
80 LPPRINTER_INFO_2W lpPrinterInfo
;
81 LPDRIVER_INFO_3W lpDriverInfo
;
83 HICON hCollateIcon
; /* PrintDlg only */
84 HICON hNoCollateIcon
; /* PrintDlg only */
85 HICON hPortraitIcon
; /* PrintSetupDlg only */
86 HICON hLandscapeIcon
; /* PrintSetupDlg only */
97 static const struct pd_flags psd_flags
[] = {
98 {PSD_MINMARGINS
,"PSD_MINMARGINS"},
99 {PSD_MARGINS
,"PSD_MARGINS"},
100 {PSD_INTHOUSANDTHSOFINCHES
,"PSD_INTHOUSANDTHSOFINCHES"},
101 {PSD_INHUNDREDTHSOFMILLIMETERS
,"PSD_INHUNDREDTHSOFMILLIMETERS"},
102 {PSD_DISABLEMARGINS
,"PSD_DISABLEMARGINS"},
103 {PSD_DISABLEPRINTER
,"PSD_DISABLEPRINTER"},
104 {PSD_NOWARNING
,"PSD_NOWARNING"},
105 {PSD_DISABLEORIENTATION
,"PSD_DISABLEORIENTATION"},
106 {PSD_RETURNDEFAULT
,"PSD_RETURNDEFAULT"},
107 {PSD_DISABLEPAPER
,"PSD_DISABLEPAPER"},
108 {PSD_SHOWHELP
,"PSD_SHOWHELP"},
109 {PSD_ENABLEPAGESETUPHOOK
,"PSD_ENABLEPAGESETUPHOOK"},
110 {PSD_ENABLEPAGESETUPTEMPLATE
,"PSD_ENABLEPAGESETUPTEMPLATE"},
111 {PSD_ENABLEPAGESETUPTEMPLATEHANDLE
,"PSD_ENABLEPAGESETUPTEMPLATEHANDLE"},
112 {PSD_ENABLEPAGEPAINTHOOK
,"PSD_ENABLEPAGEPAINTHOOK"},
113 {PSD_DISABLEPAGEPAINTING
,"PSD_DISABLEPAGEPAINTING"},
117 static const struct pd_flags pd_flags
[] = {
118 {PD_SELECTION
, "PD_SELECTION "},
119 {PD_PAGENUMS
, "PD_PAGENUMS "},
120 {PD_NOSELECTION
, "PD_NOSELECTION "},
121 {PD_NOPAGENUMS
, "PD_NOPAGENUMS "},
122 {PD_COLLATE
, "PD_COLLATE "},
123 {PD_PRINTTOFILE
, "PD_PRINTTOFILE "},
124 {PD_PRINTSETUP
, "PD_PRINTSETUP "},
125 {PD_NOWARNING
, "PD_NOWARNING "},
126 {PD_RETURNDC
, "PD_RETURNDC "},
127 {PD_RETURNIC
, "PD_RETURNIC "},
128 {PD_RETURNDEFAULT
, "PD_RETURNDEFAULT "},
129 {PD_SHOWHELP
, "PD_SHOWHELP "},
130 {PD_ENABLEPRINTHOOK
, "PD_ENABLEPRINTHOOK "},
131 {PD_ENABLESETUPHOOK
, "PD_ENABLESETUPHOOK "},
132 {PD_ENABLEPRINTTEMPLATE
, "PD_ENABLEPRINTTEMPLATE "},
133 {PD_ENABLESETUPTEMPLATE
, "PD_ENABLESETUPTEMPLATE "},
134 {PD_ENABLEPRINTTEMPLATEHANDLE
, "PD_ENABLEPRINTTEMPLATEHANDLE "},
135 {PD_ENABLESETUPTEMPLATEHANDLE
, "PD_ENABLESETUPTEMPLATEHANDLE "},
136 {PD_USEDEVMODECOPIES
, "PD_USEDEVMODECOPIES[ANDCOLLATE] "},
137 {PD_DISABLEPRINTTOFILE
, "PD_DISABLEPRINTTOFILE "},
138 {PD_HIDEPRINTTOFILE
, "PD_HIDEPRINTTOFILE "},
139 {PD_NONETWORKBUTTON
, "PD_NONETWORKBUTTON "},
142 /* address of wndproc for subclassed Static control */
143 static WNDPROC lpfnStaticWndProc
;
144 static WNDPROC edit_wndproc
;
145 /* the text of the fake document to render for the Page Setup dialog */
146 static WCHAR wszFakeDocumentText
[1024];
147 static const WCHAR pd32_collateW
[] = { 'P', 'D', '3', '2', '_', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
148 static const WCHAR pd32_nocollateW
[] = { 'P', 'D', '3', '2', '_', 'N', 'O', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
149 static const WCHAR pd32_portraitW
[] = { 'P', 'D', '3', '2', '_', 'P', 'O', 'R', 'T', 'R', 'A', 'I', 'T', 0 };
150 static const WCHAR pd32_landscapeW
[] = { 'P', 'D', '3', '2', '_', 'L', 'A', 'N', 'D', 'S', 'C', 'A', 'P', 'E', 0 };
151 static const WCHAR printdlg_prop
[] = {'_','_','W','I','N','E','_','P','R','I','N','T','D','L','G','D','A','T','A',0};
152 static const WCHAR pagesetupdlg_prop
[] = { '_', '_', 'W', 'I', 'N', 'E', '_', 'P', 'A', 'G', 'E',
153 'S', 'E', 'T', 'U', 'P', 'D', 'L', 'G', 'D', 'A', 'T', 'A', 0 };
156 static LPWSTR
strdupW(LPCWSTR p
)
162 len
= (strlenW(p
) + 1) * sizeof(WCHAR
);
163 ret
= HeapAlloc(GetProcessHeap(), 0, len
);
168 /***********************************************************
169 * convert_to_devmodeA
171 * Creates an ansi copy of supplied devmode
173 static DEVMODEA
*convert_to_devmodeA(const DEVMODEW
*dmW
)
178 if (!dmW
) return NULL
;
179 size
= dmW
->dmSize
- CCHDEVICENAME
-
180 ((dmW
->dmSize
> FIELD_OFFSET(DEVMODEW
, dmFormName
)) ? CCHFORMNAME
: 0);
182 dmA
= HeapAlloc(GetProcessHeap(), 0, size
+ dmW
->dmDriverExtra
);
183 if (!dmA
) return NULL
;
185 WideCharToMultiByte(CP_ACP
, 0, dmW
->dmDeviceName
, -1,
186 (LPSTR
)dmA
->dmDeviceName
, CCHDEVICENAME
, NULL
, NULL
);
188 if (FIELD_OFFSET(DEVMODEW
, dmFormName
) >= dmW
->dmSize
)
190 memcpy(&dmA
->dmSpecVersion
, &dmW
->dmSpecVersion
,
191 dmW
->dmSize
- FIELD_OFFSET(DEVMODEW
, dmSpecVersion
));
195 memcpy(&dmA
->dmSpecVersion
, &dmW
->dmSpecVersion
,
196 FIELD_OFFSET(DEVMODEW
, dmFormName
) - FIELD_OFFSET(DEVMODEW
, dmSpecVersion
));
197 WideCharToMultiByte(CP_ACP
, 0, dmW
->dmFormName
, -1,
198 (LPSTR
)dmA
->dmFormName
, CCHFORMNAME
, NULL
, NULL
);
200 memcpy(&dmA
->dmLogPixels
, &dmW
->dmLogPixels
, dmW
->dmSize
- FIELD_OFFSET(DEVMODEW
, dmLogPixels
));
204 memcpy((char *)dmA
+ dmA
->dmSize
, (const char *)dmW
+ dmW
->dmSize
, dmW
->dmDriverExtra
);
208 /***********************************************************************
209 * PRINTDLG_OpenDefaultPrinter
211 * Returns a winspool printer handle to the default printer in *hprn
212 * Caller must call ClosePrinter on the handle
214 * Returns TRUE on success else FALSE
216 static BOOL
PRINTDLG_OpenDefaultPrinter(HANDLE
*hprn
)
219 DWORD dwBufLen
= sizeof(buf
) / sizeof(buf
[0]);
221 if(!GetDefaultPrinterW(buf
, &dwBufLen
))
223 res
= OpenPrinterW(buf
, hprn
, NULL
);
225 WARN("Could not open printer %s\n", debugstr_w(buf
));
229 /***********************************************************************
230 * PRINTDLG_SetUpPrinterListCombo
232 * Initializes printer list combox.
233 * hDlg: HWND of dialog
234 * id: Control id of combo
235 * name: Name of printer to select
237 * Initializes combo with list of available printers. Selects printer 'name'
238 * If name is NULL or does not exist select the default printer.
240 * Returns number of printers added to list.
242 static INT
PRINTDLG_SetUpPrinterListComboA(HWND hDlg
, UINT id
, LPCSTR name
)
246 LPPRINTER_INFO_2A pi
;
247 EnumPrintersA(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
248 pi
= HeapAlloc(GetProcessHeap(), 0, needed
);
249 EnumPrintersA(PRINTER_ENUM_LOCAL
, NULL
, 2, (LPBYTE
)pi
, needed
, &needed
,
252 SendDlgItemMessageA(hDlg
, id
, CB_RESETCONTENT
, 0, 0);
254 for(i
= 0; i
< num
; i
++) {
255 SendDlgItemMessageA(hDlg
, id
, CB_ADDSTRING
, 0,
256 (LPARAM
)pi
[i
].pPrinterName
);
258 HeapFree(GetProcessHeap(), 0, pi
);
260 (i
= SendDlgItemMessageA(hDlg
, id
, CB_FINDSTRINGEXACT
, -1,
261 (LPARAM
)name
)) == CB_ERR
) {
264 DWORD dwBufLen
= sizeof(buf
);
266 WARN("Can't find %s in printer list so trying to find default\n",
268 if(!GetDefaultPrinterA(buf
, &dwBufLen
))
270 i
= SendDlgItemMessageA(hDlg
, id
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buf
);
272 FIXME("Can't find default printer in printer list\n");
274 SendDlgItemMessageA(hDlg
, id
, CB_SETCURSEL
, i
, 0);
278 static INT
PRINTDLG_SetUpPrinterListComboW(HWND hDlg
, UINT id
, LPCWSTR name
)
282 LPPRINTER_INFO_2W pi
;
283 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
284 pi
= HeapAlloc(GetProcessHeap(), 0, needed
);
285 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, (LPBYTE
)pi
, needed
, &needed
,
288 for(i
= 0; i
< num
; i
++) {
289 SendDlgItemMessageW(hDlg
, id
, CB_ADDSTRING
, 0,
290 (LPARAM
)pi
[i
].pPrinterName
);
292 HeapFree(GetProcessHeap(), 0, pi
);
294 (i
= SendDlgItemMessageW(hDlg
, id
, CB_FINDSTRINGEXACT
, -1,
295 (LPARAM
)name
)) == CB_ERR
) {
297 DWORD dwBufLen
= sizeof(buf
)/sizeof(buf
[0]);
299 WARN("Can't find %s in printer list so trying to find default\n",
301 if(!GetDefaultPrinterW(buf
, &dwBufLen
))
303 i
= SendDlgItemMessageW(hDlg
, id
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buf
);
305 TRACE("Can't find default printer in printer list\n");
307 SendDlgItemMessageW(hDlg
, id
, CB_SETCURSEL
, i
, 0);
311 /***********************************************************************
312 * PRINTDLG_CreateDevNames [internal]
315 * creates a DevNames structure.
317 * (NB. when we handle unicode the offsets will be in wchars).
319 static BOOL
PRINTDLG_CreateDevNames(HGLOBAL
*hmem
, const char* DeviceDriverName
,
320 const char* DeviceName
, const char* OutputPort
)
323 char* pDevNamesSpace
;
325 LPDEVNAMES lpDevNames
;
327 DWORD dwBufLen
= sizeof(buf
);
329 size
= strlen(DeviceDriverName
) + 1
330 + strlen(DeviceName
) + 1
331 + strlen(OutputPort
) + 1
335 *hmem
= GlobalReAlloc(*hmem
, size
, GMEM_MOVEABLE
);
337 *hmem
= GlobalAlloc(GMEM_MOVEABLE
, size
);
341 pDevNamesSpace
= GlobalLock(*hmem
);
342 lpDevNames
= (LPDEVNAMES
) pDevNamesSpace
;
344 pTempPtr
= pDevNamesSpace
+ sizeof(DEVNAMES
);
345 strcpy(pTempPtr
, DeviceDriverName
);
346 lpDevNames
->wDriverOffset
= pTempPtr
- pDevNamesSpace
;
348 pTempPtr
+= strlen(DeviceDriverName
) + 1;
349 strcpy(pTempPtr
, DeviceName
);
350 lpDevNames
->wDeviceOffset
= pTempPtr
- pDevNamesSpace
;
352 pTempPtr
+= strlen(DeviceName
) + 1;
353 strcpy(pTempPtr
, OutputPort
);
354 lpDevNames
->wOutputOffset
= pTempPtr
- pDevNamesSpace
;
356 GetDefaultPrinterA(buf
, &dwBufLen
);
357 lpDevNames
->wDefault
= (strcmp(buf
, DeviceName
) == 0) ? 1 : 0;
362 static BOOL
PRINTDLG_CreateDevNamesW(HGLOBAL
*hmem
, LPCWSTR DeviceDriverName
,
363 LPCWSTR DeviceName
, LPCWSTR OutputPort
)
366 LPWSTR pDevNamesSpace
;
368 LPDEVNAMES lpDevNames
;
370 DWORD dwBufLen
= sizeof(bufW
) / sizeof(WCHAR
);
372 size
= sizeof(WCHAR
)*lstrlenW(DeviceDriverName
) + 2
373 + sizeof(WCHAR
)*lstrlenW(DeviceName
) + 2
374 + sizeof(WCHAR
)*lstrlenW(OutputPort
) + 2
378 *hmem
= GlobalReAlloc(*hmem
, size
, GMEM_MOVEABLE
);
380 *hmem
= GlobalAlloc(GMEM_MOVEABLE
, size
);
384 pDevNamesSpace
= GlobalLock(*hmem
);
385 lpDevNames
= (LPDEVNAMES
) pDevNamesSpace
;
387 pTempPtr
= (LPWSTR
)((LPDEVNAMES
)pDevNamesSpace
+ 1);
388 lstrcpyW(pTempPtr
, DeviceDriverName
);
389 lpDevNames
->wDriverOffset
= pTempPtr
- pDevNamesSpace
;
391 pTempPtr
+= lstrlenW(DeviceDriverName
) + 1;
392 lstrcpyW(pTempPtr
, DeviceName
);
393 lpDevNames
->wDeviceOffset
= pTempPtr
- pDevNamesSpace
;
395 pTempPtr
+= lstrlenW(DeviceName
) + 1;
396 lstrcpyW(pTempPtr
, OutputPort
);
397 lpDevNames
->wOutputOffset
= pTempPtr
- pDevNamesSpace
;
399 GetDefaultPrinterW(bufW
, &dwBufLen
);
400 lpDevNames
->wDefault
= (lstrcmpW(bufW
, DeviceName
) == 0) ? 1 : 0;
405 /***********************************************************************
406 * PRINTDLG_UpdatePrintDlg [internal]
409 * updates the PrintDlg structure for return values.
412 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
413 * TRUE if successful.
415 static BOOL
PRINTDLG_UpdatePrintDlgA(HWND hDlg
,
416 PRINT_PTRA
* PrintStructures
)
418 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
419 PDEVMODEA lpdm
= PrintStructures
->lpDevMode
;
420 LPPRINTER_INFO_2A pi
= PrintStructures
->lpPrinterInfo
;
424 FIXME("No lpdm ptr?\n");
429 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
430 /* check whether nFromPage and nToPage are within range defined by
431 * nMinPage and nMaxPage
433 if (IsDlgButtonChecked(hDlg
, rad3
) == BST_CHECKED
) { /* Pages */
437 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
438 nToPage
= GetDlgItemInt(hDlg
, edt2
, &translated
, FALSE
);
440 /* if no ToPage value is entered, use the FromPage value */
441 if(!translated
) nToPage
= nFromPage
;
443 if (nFromPage
< lppd
->nMinPage
|| nFromPage
> lppd
->nMaxPage
||
444 nToPage
< lppd
->nMinPage
|| nToPage
> lppd
->nMaxPage
) {
445 WCHAR resourcestr
[256];
446 WCHAR resultstr
[256];
447 LoadStringW(COMDLG32_hInstance
, PD32_INVALID_PAGE_RANGE
, resourcestr
, 255);
448 wsprintfW(resultstr
,resourcestr
, lppd
->nMinPage
, lppd
->nMaxPage
);
449 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
, resourcestr
, 255);
450 MessageBoxW(hDlg
, resultstr
, resourcestr
, MB_OK
| MB_ICONWARNING
);
453 lppd
->nFromPage
= nFromPage
;
454 lppd
->nToPage
= nToPage
;
455 lppd
->Flags
|= PD_PAGENUMS
;
458 lppd
->Flags
&= ~PD_PAGENUMS
;
460 if (IsDlgButtonChecked(hDlg
, rad2
) == BST_CHECKED
) /* Selection */
461 lppd
->Flags
|= PD_SELECTION
;
463 lppd
->Flags
&= ~PD_SELECTION
;
465 if (IsDlgButtonChecked(hDlg
, chx1
) == BST_CHECKED
) {/* Print to file */
466 static char file
[] = "FILE:";
467 lppd
->Flags
|= PD_PRINTTOFILE
;
468 pi
->pPortName
= file
;
471 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
) { /* Collate */
472 FIXME("Collate lppd not yet implemented as output\n");
475 /* set PD_Collate and nCopies */
476 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
477 /* The application doesn't support multiple copies or collate...
479 lppd
->Flags
&= ~PD_COLLATE
;
481 /* if the printer driver supports it... store info there
482 * otherwise no collate & multiple copies !
484 if (lpdm
->dmFields
& DM_COLLATE
)
486 (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
);
487 if (lpdm
->dmFields
& DM_COPIES
)
488 lpdm
->u1
.s1
.dmCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
490 /* Application is responsible for multiple copies */
491 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
492 lppd
->Flags
|= PD_COLLATE
;
494 lppd
->Flags
&= ~PD_COLLATE
;
495 lppd
->nCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
496 /* multiple copies already included in the document. Driver must print only one copy */
497 lpdm
->u1
.s1
.dmCopies
= 1;
500 /* Print quality, PrintDlg16 */
501 if(GetDlgItem(hDlg
, cmb1
))
503 HWND hQuality
= GetDlgItem(hDlg
, cmb1
);
504 int Sel
= SendMessageA(hQuality
, CB_GETCURSEL
, 0, 0);
508 LONG dpi
= SendMessageA(hQuality
, CB_GETITEMDATA
, Sel
, 0);
509 lpdm
->dmFields
|= DM_PRINTQUALITY
| DM_YRESOLUTION
;
510 lpdm
->u1
.s1
.dmPrintQuality
= LOWORD(dpi
);
511 lpdm
->dmYResolution
= HIWORD(dpi
);
518 static BOOL
PRINTDLG_UpdatePrintDlgW(HWND hDlg
,
519 PRINT_PTRW
* PrintStructures
)
521 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
522 PDEVMODEW lpdm
= PrintStructures
->lpDevMode
;
523 LPPRINTER_INFO_2W pi
= PrintStructures
->lpPrinterInfo
;
527 FIXME("No lpdm ptr?\n");
532 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
533 /* check whether nFromPage and nToPage are within range defined by
534 * nMinPage and nMaxPage
536 if (IsDlgButtonChecked(hDlg
, rad3
) == BST_CHECKED
) { /* Pages */
540 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
541 nToPage
= GetDlgItemInt(hDlg
, edt2
, &translated
, FALSE
);
543 /* if no ToPage value is entered, use the FromPage value */
544 if(!translated
) nToPage
= nFromPage
;
546 if (nFromPage
< lppd
->nMinPage
|| nFromPage
> lppd
->nMaxPage
||
547 nToPage
< lppd
->nMinPage
|| nToPage
> lppd
->nMaxPage
) {
548 WCHAR resourcestr
[256];
549 WCHAR resultstr
[256];
551 LoadStringW(COMDLG32_hInstance
, PD32_INVALID_PAGE_RANGE
,
553 args
[0] = lppd
->nMinPage
;
554 args
[1] = lppd
->nMaxPage
;
555 FormatMessageW(FORMAT_MESSAGE_FROM_STRING
|FORMAT_MESSAGE_ARGUMENT_ARRAY
,
556 resourcestr
, 0, 0, resultstr
,
557 sizeof(resultstr
)/sizeof(*resultstr
),
558 (__ms_va_list
*)args
);
559 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
,
561 MessageBoxW(hDlg
, resultstr
, resourcestr
,
562 MB_OK
| MB_ICONWARNING
);
565 lppd
->nFromPage
= nFromPage
;
566 lppd
->nToPage
= nToPage
;
567 lppd
->Flags
|= PD_PAGENUMS
;
570 lppd
->Flags
&= ~PD_PAGENUMS
;
572 if (IsDlgButtonChecked(hDlg
, rad2
) == BST_CHECKED
) /* Selection */
573 lppd
->Flags
|= PD_SELECTION
;
575 lppd
->Flags
&= ~PD_SELECTION
;
577 if (IsDlgButtonChecked(hDlg
, chx1
) == BST_CHECKED
) {/* Print to file */
578 static WCHAR file
[] = {'F','I','L','E',':',0};
579 lppd
->Flags
|= PD_PRINTTOFILE
;
580 pi
->pPortName
= file
;
583 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
) { /* Collate */
584 FIXME("Collate lppd not yet implemented as output\n");
587 /* set PD_Collate and nCopies */
588 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
589 /* The application doesn't support multiple copies or collate...
591 lppd
->Flags
&= ~PD_COLLATE
;
593 /* if the printer driver supports it... store info there
594 * otherwise no collate & multiple copies !
596 if (lpdm
->dmFields
& DM_COLLATE
)
598 (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
);
599 if (lpdm
->dmFields
& DM_COPIES
)
600 lpdm
->u1
.s1
.dmCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
602 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
603 lppd
->Flags
|= PD_COLLATE
;
605 lppd
->Flags
&= ~PD_COLLATE
;
606 lppd
->nCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
612 /************************************************************************
613 * PRINTDLG_SetUpPaperComboBox
615 * Initialize either the papersize or inputslot combos of the Printer Setup
616 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
617 * We also try to re-select the old selection.
619 static BOOL
PRINTDLG_SetUpPaperComboBoxA(HWND hDlg
,
630 WORD oldWord
= 0, newWord
= 0; /* DMPAPER_ and DMBIN_ start at 1 */
632 int fwCapability_Names
;
633 int fwCapability_Words
;
635 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName
,PortName
,nIDComboBox
);
637 /* query the dialog box for the current selected value */
638 Sel
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETCURSEL
, 0, 0);
640 /* we enter here only if a different printer is selected after
641 * the Print Setup dialog is opened. The current settings are
642 * stored into the newly selected printer.
644 oldWord
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
,
646 if(oldWord
>= DMPAPER_USER
) /* DMPAPER_USER == DMBIN_USER */
647 oldWord
= 0; /* There's no point in trying to keep custom
648 paper / bin sizes across printers */
652 newWord
= (nIDComboBox
== cmb2
) ? dm
->u1
.s1
.dmPaperSize
: dm
->u1
.s1
.dmDefaultSource
;
654 if (nIDComboBox
== cmb2
) {
656 fwCapability_Names
= DC_PAPERNAMES
;
657 fwCapability_Words
= DC_PAPERS
;
661 fwCapability_Names
= DC_BINNAMES
;
662 fwCapability_Words
= DC_BINS
;
665 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
666 fwCapability_Names
, NULL
, dm
);
667 if (NrOfEntries
== 0)
668 WARN("no Name Entries found!\n");
669 else if (NrOfEntries
< 0)
672 if(DeviceCapabilitiesA(PrinterName
, PortName
, fwCapability_Words
, NULL
, dm
)
674 ERR("Number of caps is different\n");
678 Names
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(char)*NamesSize
);
679 Words
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WORD
));
680 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
681 fwCapability_Names
, Names
, dm
);
682 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
683 fwCapability_Words
, (LPSTR
)Words
, dm
);
685 /* reset any current content in the combobox */
686 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_RESETCONTENT
, 0, 0);
688 /* store new content */
689 for (i
= 0; i
< NrOfEntries
; i
++) {
690 DWORD pos
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_ADDSTRING
, 0,
691 (LPARAM
)(&Names
[i
*NamesSize
]) );
692 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_SETITEMDATA
, pos
,
696 /* Look for old selection or the new default.
697 Can't do this is previous loop since item order will change as more items are added */
699 old_Sel
= NrOfEntries
;
700 for (i
= 0; i
< NrOfEntries
; i
++) {
701 if(SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) ==
706 if(SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) == newWord
)
710 if(old_Sel
< NrOfEntries
)
714 if(nIDComboBox
== cmb2
)
715 dm
->u1
.s1
.dmPaperSize
= oldWord
;
717 dm
->u1
.s1
.dmDefaultSource
= oldWord
;
722 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_SETCURSEL
, Sel
, 0);
724 HeapFree(GetProcessHeap(),0,Words
);
725 HeapFree(GetProcessHeap(),0,Names
);
729 static BOOL
PRINTDLG_SetUpPaperComboBoxW(HWND hDlg
,
731 const WCHAR
* PrinterName
,
732 const WCHAR
* PortName
,
740 WORD oldWord
= 0, newWord
= 0; /* DMPAPER_ and DMBIN_ start at 1 */
742 int fwCapability_Names
;
743 int fwCapability_Words
;
745 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName
),debugstr_w(PortName
),nIDComboBox
);
747 /* query the dialog box for the current selected value */
748 Sel
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETCURSEL
, 0, 0);
750 /* we enter here only if a different printer is selected after
751 * the Print Setup dialog is opened. The current settings are
752 * stored into the newly selected printer.
754 oldWord
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETITEMDATA
,
757 if(oldWord
>= DMPAPER_USER
) /* DMPAPER_USER == DMBIN_USER */
758 oldWord
= 0; /* There's no point in trying to keep custom
759 paper / bin sizes across printers */
763 newWord
= (nIDComboBox
== cmb2
) ? dm
->u1
.s1
.dmPaperSize
: dm
->u1
.s1
.dmDefaultSource
;
765 if (nIDComboBox
== cmb2
) {
767 fwCapability_Names
= DC_PAPERNAMES
;
768 fwCapability_Words
= DC_PAPERS
;
772 fwCapability_Names
= DC_BINNAMES
;
773 fwCapability_Words
= DC_BINS
;
776 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
777 fwCapability_Names
, NULL
, dm
);
778 if (NrOfEntries
== 0)
779 WARN("no Name Entries found!\n");
780 else if (NrOfEntries
< 0)
783 if(DeviceCapabilitiesW(PrinterName
, PortName
, fwCapability_Words
, NULL
, dm
)
785 ERR("Number of caps is different\n");
789 Names
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WCHAR
)*NamesSize
);
790 Words
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WORD
));
791 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
792 fwCapability_Names
, Names
, dm
);
793 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
794 fwCapability_Words
, Words
, dm
);
796 /* reset any current content in the combobox */
797 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_RESETCONTENT
, 0, 0);
799 /* store new content */
800 for (i
= 0; i
< NrOfEntries
; i
++) {
801 DWORD pos
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_ADDSTRING
, 0,
802 (LPARAM
)(&Names
[i
*NamesSize
]) );
803 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_SETITEMDATA
, pos
,
807 /* Look for old selection or the new default.
808 Can't do this is previous loop since item order will change as more items are added */
810 old_Sel
= NrOfEntries
;
811 for (i
= 0; i
< NrOfEntries
; i
++) {
812 if(SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) ==
817 if(SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) == newWord
)
821 if(old_Sel
< NrOfEntries
)
825 if(nIDComboBox
== cmb2
)
826 dm
->u1
.s1
.dmPaperSize
= oldWord
;
828 dm
->u1
.s1
.dmDefaultSource
= oldWord
;
833 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_SETCURSEL
, Sel
, 0);
835 HeapFree(GetProcessHeap(),0,Words
);
836 HeapFree(GetProcessHeap(),0,Names
);
841 /***********************************************************************
842 * PRINTDLG_UpdatePrinterInfoTexts [internal]
844 static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg
, const PRINTER_INFO_2A
*pi
)
847 char ResourceString
[256];
853 /* add all status messages */
854 for (i
= 0; i
< 25; i
++) {
855 if (pi
->Status
& (1<<i
)) {
856 LoadStringA(COMDLG32_hInstance
, PD32_PRINTER_STATUS_PAUSED
+i
,
857 ResourceString
, 255);
858 strcat(StatusMsg
,ResourceString
);
862 /* FIXME: status==ready must only be appended if really so.
863 but how to detect? */
864 LoadStringA(COMDLG32_hInstance
, PD32_PRINTER_STATUS_READY
,
865 ResourceString
, 255);
866 strcat(StatusMsg
,ResourceString
);
867 SetDlgItemTextA(hDlg
, stc12
, StatusMsg
);
869 /* set all other printer info texts */
870 SetDlgItemTextA(hDlg
, stc11
, pi
->pDriverName
);
872 if (pi
->pLocation
!= NULL
&& pi
->pLocation
[0] != '\0')
873 SetDlgItemTextA(hDlg
, stc14
, pi
->pLocation
);
875 SetDlgItemTextA(hDlg
, stc14
, pi
->pPortName
);
876 SetDlgItemTextA(hDlg
, stc13
, pi
->pComment
? pi
->pComment
: "");
880 static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg
, const PRINTER_INFO_2W
*pi
)
882 WCHAR StatusMsg
[256];
883 WCHAR ResourceString
[256];
884 static const WCHAR emptyW
[] = {0};
890 /* add all status messages */
891 for (i
= 0; i
< 25; i
++) {
892 if (pi
->Status
& (1<<i
)) {
893 LoadStringW(COMDLG32_hInstance
, PD32_PRINTER_STATUS_PAUSED
+i
,
894 ResourceString
, 255);
895 lstrcatW(StatusMsg
,ResourceString
);
899 /* FIXME: status==ready must only be appended if really so.
900 but how to detect? */
901 LoadStringW(COMDLG32_hInstance
, PD32_PRINTER_STATUS_READY
,
902 ResourceString
, 255);
903 lstrcatW(StatusMsg
,ResourceString
);
904 SetDlgItemTextW(hDlg
, stc12
, StatusMsg
);
906 /* set all other printer info texts */
907 SetDlgItemTextW(hDlg
, stc11
, pi
->pDriverName
);
908 if (pi
->pLocation
!= NULL
&& pi
->pLocation
[0] != '\0')
909 SetDlgItemTextW(hDlg
, stc14
, pi
->pLocation
);
911 SetDlgItemTextW(hDlg
, stc14
, pi
->pPortName
);
912 SetDlgItemTextW(hDlg
, stc13
, pi
->pComment
? pi
->pComment
: emptyW
);
916 /*******************************************************************
918 * PRINTDLG_ChangePrinter
921 static BOOL
PRINTDLG_ChangePrinterA(HWND hDlg
, char *name
, PRINT_PTRA
*PrintStructures
)
923 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
924 LPDEVMODEA lpdm
= NULL
;
929 HeapFree(GetProcessHeap(),0, PrintStructures
->lpPrinterInfo
);
930 HeapFree(GetProcessHeap(),0, PrintStructures
->lpDriverInfo
);
931 if(!OpenPrinterA(name
, &hprn
, NULL
)) {
932 ERR("Can't open printer %s\n", name
);
935 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
936 PrintStructures
->lpPrinterInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
937 GetPrinterA(hprn
, 2, (LPBYTE
)PrintStructures
->lpPrinterInfo
, needed
,
939 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
940 PrintStructures
->lpDriverInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
941 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)PrintStructures
->lpDriverInfo
,
943 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures
->lpPrinterInfo
->pPrinterName
);
948 PRINTDLG_UpdatePrinterInfoTextsA(hDlg
, PrintStructures
->lpPrinterInfo
);
950 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
951 PrintStructures
->lpDevMode
= NULL
;
953 dmSize
= DocumentPropertiesA(0, 0, name
, NULL
, NULL
, 0);
955 ERR("DocumentProperties fails on %s\n", debugstr_a(name
));
958 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(), 0, dmSize
);
959 dmSize
= DocumentPropertiesA(0, 0, name
, PrintStructures
->lpDevMode
, NULL
,
961 if(lppd
->hDevMode
&& (lpdm
= GlobalLock(lppd
->hDevMode
)) &&
962 !lstrcmpA( (LPSTR
) lpdm
->dmDeviceName
,
963 (LPSTR
) PrintStructures
->lpDevMode
->dmDeviceName
)) {
964 /* Supplied devicemode matches current printer so try to use it */
965 DocumentPropertiesA(0, 0, name
, PrintStructures
->lpDevMode
, lpdm
,
966 DM_OUT_BUFFER
| DM_IN_BUFFER
);
969 GlobalUnlock(lppd
->hDevMode
);
971 lpdm
= PrintStructures
->lpDevMode
; /* use this as a shortcut */
973 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
974 /* Print range (All/Range/Selection) */
975 if(lppd
->nFromPage
!= 0xffff)
976 SetDlgItemInt(hDlg
, edt1
, lppd
->nFromPage
, FALSE
);
977 if(lppd
->nToPage
!= 0xffff)
978 SetDlgItemInt(hDlg
, edt2
, lppd
->nToPage
, FALSE
);
980 CheckRadioButton(hDlg
, rad1
, rad3
, rad1
); /* default */
981 if (lppd
->Flags
& PD_NOSELECTION
)
982 EnableWindow(GetDlgItem(hDlg
, rad2
), FALSE
);
984 if (lppd
->Flags
& PD_SELECTION
)
985 CheckRadioButton(hDlg
, rad1
, rad3
, rad2
);
986 if (lppd
->Flags
& PD_NOPAGENUMS
) {
987 EnableWindow(GetDlgItem(hDlg
, rad3
), FALSE
);
988 EnableWindow(GetDlgItem(hDlg
, stc2
),FALSE
);
989 EnableWindow(GetDlgItem(hDlg
, edt1
), FALSE
);
990 EnableWindow(GetDlgItem(hDlg
, stc3
),FALSE
);
991 EnableWindow(GetDlgItem(hDlg
, edt2
), FALSE
);
993 if (lppd
->Flags
& PD_PAGENUMS
)
994 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
999 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1001 if (lppd
->Flags
& PD_COLLATE
) {
1002 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1003 (LPARAM
)PrintStructures
->hCollateIcon
);
1004 CheckDlgButton(hDlg
, chx2
, 1);
1006 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1007 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1008 CheckDlgButton(hDlg
, chx2
, 0);
1011 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1012 /* if printer doesn't support it: no Collate */
1013 if (!(lpdm
->dmFields
& DM_COLLATE
)) {
1014 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1015 EnableWindow(GetDlgItem(hDlg
, ico3
), FALSE
);
1022 if (lppd
->hDevMode
== 0)
1023 copies
= lppd
->nCopies
;
1025 copies
= lpdm
->u1
.s1
.dmCopies
;
1026 if(copies
== 0) copies
= 1;
1027 else if(copies
< 0) copies
= MAX_COPIES
;
1028 SetDlgItemInt(hDlg
, edt3
, copies
, FALSE
);
1031 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1032 /* if printer doesn't support it: no nCopies */
1033 if (!(lpdm
->dmFields
& DM_COPIES
)) {
1034 EnableWindow(GetDlgItem(hDlg
, edt3
), FALSE
);
1035 EnableWindow(GetDlgItem(hDlg
, stc5
), FALSE
);
1040 CheckDlgButton(hDlg
, chx1
, (lppd
->Flags
& PD_PRINTTOFILE
) ? 1 : 0);
1041 if (lppd
->Flags
& PD_DISABLEPRINTTOFILE
)
1042 EnableWindow(GetDlgItem(hDlg
, chx1
), FALSE
);
1043 if (lppd
->Flags
& PD_HIDEPRINTTOFILE
)
1044 ShowWindow(GetDlgItem(hDlg
, chx1
), SW_HIDE
);
1046 /* Fill print quality combo, PrintDlg16 */
1047 if(GetDlgItem(hDlg
, cmb1
))
1049 DWORD numResolutions
= DeviceCapabilitiesA(PrintStructures
->lpPrinterInfo
->pPrinterName
,
1050 PrintStructures
->lpPrinterInfo
->pPortName
,
1051 DC_ENUMRESOLUTIONS
, NULL
, lpdm
);
1053 if(numResolutions
!= -1)
1055 HWND hQuality
= GetDlgItem(hDlg
, cmb1
);
1060 HDC hPrinterDC
= CreateDCA(PrintStructures
->lpPrinterInfo
->pDriverName
,
1061 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1064 Resolutions
= HeapAlloc(GetProcessHeap(), 0, numResolutions
*sizeof(LONG
)*2);
1065 DeviceCapabilitiesA(PrintStructures
->lpPrinterInfo
->pPrinterName
,
1066 PrintStructures
->lpPrinterInfo
->pPortName
,
1067 DC_ENUMRESOLUTIONS
, (LPSTR
)Resolutions
, lpdm
);
1069 dpiX
= GetDeviceCaps(hPrinterDC
, LOGPIXELSX
);
1070 dpiY
= GetDeviceCaps(hPrinterDC
, LOGPIXELSY
);
1071 DeleteDC(hPrinterDC
);
1073 SendMessageA(hQuality
, CB_RESETCONTENT
, 0, 0);
1074 for(i
= 0; i
< (numResolutions
* 2); i
+= 2)
1076 BOOL IsDefault
= FALSE
;
1079 if(Resolutions
[i
] == Resolutions
[i
+1])
1081 if(dpiX
== Resolutions
[i
])
1083 sprintf(buf
, "%d dpi", Resolutions
[i
]);
1086 if(dpiX
== Resolutions
[i
] && dpiY
== Resolutions
[i
+1])
1088 sprintf(buf
, "%d dpi x %d dpi", Resolutions
[i
], Resolutions
[i
+1]);
1091 Index
= SendMessageA(hQuality
, CB_ADDSTRING
, 0, (LPARAM
)buf
);
1094 SendMessageA(hQuality
, CB_SETCURSEL
, Index
, 0);
1096 SendMessageA(hQuality
, CB_SETITEMDATA
, Index
, MAKELONG(dpiX
,dpiY
));
1098 HeapFree(GetProcessHeap(), 0, Resolutions
);
1101 } else { /* PD_PRINTSETUP */
1102 BOOL bPortrait
= (lpdm
->u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
);
1104 PRINTDLG_SetUpPaperComboBoxA(hDlg
, cmb2
,
1105 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1106 PrintStructures
->lpPrinterInfo
->pPortName
,
1108 PRINTDLG_SetUpPaperComboBoxA(hDlg
, cmb3
,
1109 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1110 PrintStructures
->lpPrinterInfo
->pPortName
,
1112 CheckRadioButton(hDlg
, rad1
, rad2
, bPortrait
? rad1
: rad2
);
1113 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1114 (LPARAM
)(bPortrait
? PrintStructures
->hPortraitIcon
:
1115 PrintStructures
->hLandscapeIcon
));
1120 if ((lppd
->Flags
& PD_SHOWHELP
)==0) {
1121 /* hide if PD_SHOWHELP not specified */
1122 ShowWindow(GetDlgItem(hDlg
, pshHelp
), SW_HIDE
);
1127 static BOOL
PRINTDLG_ChangePrinterW(HWND hDlg
, WCHAR
*name
,
1128 PRINT_PTRW
*PrintStructures
)
1130 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1131 LPDEVMODEW lpdm
= NULL
;
1136 HeapFree(GetProcessHeap(),0, PrintStructures
->lpPrinterInfo
);
1137 HeapFree(GetProcessHeap(),0, PrintStructures
->lpDriverInfo
);
1138 if(!OpenPrinterW(name
, &hprn
, NULL
)) {
1139 ERR("Can't open printer %s\n", debugstr_w(name
));
1142 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
1143 PrintStructures
->lpPrinterInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
1144 GetPrinterW(hprn
, 2, (LPBYTE
)PrintStructures
->lpPrinterInfo
, needed
,
1146 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
1147 PrintStructures
->lpDriverInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
1148 if (!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)PrintStructures
->lpDriverInfo
,
1150 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures
->lpPrinterInfo
->pPrinterName
));
1155 PRINTDLG_UpdatePrinterInfoTextsW(hDlg
, PrintStructures
->lpPrinterInfo
);
1157 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
1158 PrintStructures
->lpDevMode
= NULL
;
1160 dmSize
= DocumentPropertiesW(0, 0, name
, NULL
, NULL
, 0);
1162 ERR("DocumentProperties fails on %s\n", debugstr_w(name
));
1165 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(), 0, dmSize
);
1166 dmSize
= DocumentPropertiesW(0, 0, name
, PrintStructures
->lpDevMode
, NULL
,
1168 if(lppd
->hDevMode
&& (lpdm
= GlobalLock(lppd
->hDevMode
)) &&
1169 !lstrcmpW(lpdm
->dmDeviceName
,
1170 PrintStructures
->lpDevMode
->dmDeviceName
)) {
1171 /* Supplied devicemode matches current printer so try to use it */
1172 DocumentPropertiesW(0, 0, name
, PrintStructures
->lpDevMode
, lpdm
,
1173 DM_OUT_BUFFER
| DM_IN_BUFFER
);
1176 GlobalUnlock(lppd
->hDevMode
);
1178 lpdm
= PrintStructures
->lpDevMode
; /* use this as a shortcut */
1180 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
1181 /* Print range (All/Range/Selection) */
1182 if(lppd
->nFromPage
!= 0xffff)
1183 SetDlgItemInt(hDlg
, edt1
, lppd
->nFromPage
, FALSE
);
1184 if(lppd
->nToPage
!= 0xffff)
1185 SetDlgItemInt(hDlg
, edt2
, lppd
->nToPage
, FALSE
);
1187 CheckRadioButton(hDlg
, rad1
, rad3
, rad1
); /* default */
1188 if (lppd
->Flags
& PD_NOSELECTION
)
1189 EnableWindow(GetDlgItem(hDlg
, rad2
), FALSE
);
1191 if (lppd
->Flags
& PD_SELECTION
)
1192 CheckRadioButton(hDlg
, rad1
, rad3
, rad2
);
1193 if (lppd
->Flags
& PD_NOPAGENUMS
) {
1194 EnableWindow(GetDlgItem(hDlg
, rad3
), FALSE
);
1195 EnableWindow(GetDlgItem(hDlg
, stc2
),FALSE
);
1196 EnableWindow(GetDlgItem(hDlg
, edt1
), FALSE
);
1197 EnableWindow(GetDlgItem(hDlg
, stc3
),FALSE
);
1198 EnableWindow(GetDlgItem(hDlg
, edt2
), FALSE
);
1200 if (lppd
->Flags
& PD_PAGENUMS
)
1201 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1206 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1208 if (lppd
->Flags
& PD_COLLATE
) {
1209 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1210 (LPARAM
)PrintStructures
->hCollateIcon
);
1211 CheckDlgButton(hDlg
, chx2
, 1);
1213 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1214 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1215 CheckDlgButton(hDlg
, chx2
, 0);
1218 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1219 /* if printer doesn't support it: no Collate */
1220 if (!(lpdm
->dmFields
& DM_COLLATE
)) {
1221 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1222 EnableWindow(GetDlgItem(hDlg
, ico3
), FALSE
);
1229 if (lppd
->hDevMode
== 0)
1230 copies
= lppd
->nCopies
;
1232 copies
= lpdm
->u1
.s1
.dmCopies
;
1233 if(copies
== 0) copies
= 1;
1234 else if(copies
< 0) copies
= MAX_COPIES
;
1235 SetDlgItemInt(hDlg
, edt3
, copies
, FALSE
);
1238 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1239 /* if printer doesn't support it: no nCopies */
1240 if (!(lpdm
->dmFields
& DM_COPIES
)) {
1241 EnableWindow(GetDlgItem(hDlg
, edt3
), FALSE
);
1242 EnableWindow(GetDlgItem(hDlg
, stc5
), FALSE
);
1247 CheckDlgButton(hDlg
, chx1
, (lppd
->Flags
& PD_PRINTTOFILE
) ? 1 : 0);
1248 if (lppd
->Flags
& PD_DISABLEPRINTTOFILE
)
1249 EnableWindow(GetDlgItem(hDlg
, chx1
), FALSE
);
1250 if (lppd
->Flags
& PD_HIDEPRINTTOFILE
)
1251 ShowWindow(GetDlgItem(hDlg
, chx1
), SW_HIDE
);
1253 } else { /* PD_PRINTSETUP */
1254 BOOL bPortrait
= (lpdm
->u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
);
1256 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb2
,
1257 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1258 PrintStructures
->lpPrinterInfo
->pPortName
,
1260 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb3
,
1261 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1262 PrintStructures
->lpPrinterInfo
->pPortName
,
1264 CheckRadioButton(hDlg
, rad1
, rad2
, bPortrait
? rad1
: rad2
);
1265 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1266 (LPARAM
)(bPortrait
? PrintStructures
->hPortraitIcon
:
1267 PrintStructures
->hLandscapeIcon
));
1272 if ((lppd
->Flags
& PD_SHOWHELP
)==0) {
1273 /* hide if PD_SHOWHELP not specified */
1274 ShowWindow(GetDlgItem(hDlg
, pshHelp
), SW_HIDE
);
1279 /***********************************************************************
1280 * check_printer_setup [internal]
1282 static LRESULT
check_printer_setup(HWND hDlg
)
1285 WCHAR resourcestr
[256],resultstr
[256];
1287 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
1290 EnumPrintersW(PRINTER_ENUM_CONNECTIONS
, NULL
, 2, NULL
, 0, &needed
, &num
);
1296 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEVICES
,resultstr
, 255);
1297 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
,resourcestr
, 255);
1298 MessageBoxW(hDlg
, resultstr
, resourcestr
,MB_OK
| MB_ICONWARNING
);
1303 /***********************************************************************
1304 * PRINTDLG_WMInitDialog [internal]
1306 static LRESULT
PRINTDLG_WMInitDialog(HWND hDlg
,
1307 PRINT_PTRA
* PrintStructures
)
1309 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1313 UINT comboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1315 /* load Collate ICONs */
1316 /* We load these with LoadImage because they are not a standard
1317 size and we don't want them rescaled */
1318 PrintStructures
->hCollateIcon
=
1319 LoadImageA(COMDLG32_hInstance
, "PD32_COLLATE", IMAGE_ICON
, 0, 0, 0);
1320 PrintStructures
->hNoCollateIcon
=
1321 LoadImageA(COMDLG32_hInstance
, "PD32_NOCOLLATE", IMAGE_ICON
, 0, 0, 0);
1323 /* These can be done with LoadIcon */
1324 PrintStructures
->hPortraitIcon
=
1325 LoadIconA(COMDLG32_hInstance
, "PD32_PORTRAIT");
1326 PrintStructures
->hLandscapeIcon
=
1327 LoadIconA(COMDLG32_hInstance
, "PD32_LANDSCAPE");
1329 /* display the collate/no_collate icon */
1330 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1331 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1333 if(PrintStructures
->hCollateIcon
== 0 ||
1334 PrintStructures
->hNoCollateIcon
== 0 ||
1335 PrintStructures
->hPortraitIcon
== 0 ||
1336 PrintStructures
->hLandscapeIcon
== 0) {
1337 ERR("no icon in resourcefile\n");
1338 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1339 EndDialog(hDlg
, FALSE
);
1343 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1344 * must be registered and the Help button must be shown.
1346 if (lppd
->Flags
& PD_SHOWHELP
) {
1347 if((PrintStructures
->HelpMessageID
=
1348 RegisterWindowMessageA(HELPMSGSTRINGA
)) == 0) {
1349 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL
);
1353 PrintStructures
->HelpMessageID
= 0;
1355 if(!(lppd
->Flags
&PD_PRINTSETUP
)) {
1356 PrintStructures
->hwndUpDown
=
1357 CreateUpDownControl(WS_CHILD
| WS_VISIBLE
| WS_BORDER
|
1358 UDS_NOTHOUSANDS
| UDS_ARROWKEYS
|
1359 UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, 0, 0, 0, 0,
1360 hDlg
, UPDOWN_ID
, COMDLG32_hInstance
,
1361 GetDlgItem(hDlg
, edt3
), MAX_COPIES
, 1, 1);
1364 /* FIXME: I allow more freedom than either Win95 or WinNT,
1365 * which do not agree to what errors should be thrown or not
1366 * in case nToPage or nFromPage is out-of-range.
1368 if (lppd
->nMaxPage
< lppd
->nMinPage
)
1369 lppd
->nMaxPage
= lppd
->nMinPage
;
1370 if (lppd
->nMinPage
== lppd
->nMaxPage
)
1371 lppd
->Flags
|= PD_NOPAGENUMS
;
1372 if (lppd
->nToPage
< lppd
->nMinPage
)
1373 lppd
->nToPage
= lppd
->nMinPage
;
1374 if (lppd
->nToPage
> lppd
->nMaxPage
)
1375 lppd
->nToPage
= lppd
->nMaxPage
;
1376 if (lppd
->nFromPage
< lppd
->nMinPage
)
1377 lppd
->nFromPage
= lppd
->nMinPage
;
1378 if (lppd
->nFromPage
> lppd
->nMaxPage
)
1379 lppd
->nFromPage
= lppd
->nMaxPage
;
1381 /* if we have the combo box, fill it */
1382 if (GetDlgItem(hDlg
,comboID
)) {
1385 pdn
= GlobalLock(lppd
->hDevNames
);
1386 pdm
= GlobalLock(lppd
->hDevMode
);
1388 name
= (char*)pdn
+ pdn
->wDeviceOffset
;
1390 name
= (char*)pdm
->dmDeviceName
;
1391 PRINTDLG_SetUpPrinterListComboA(hDlg
, comboID
, name
);
1392 if(pdm
) GlobalUnlock(lppd
->hDevMode
);
1393 if(pdn
) GlobalUnlock(lppd
->hDevNames
);
1395 /* Now find selected printer and update rest of dlg */
1396 name
= HeapAlloc(GetProcessHeap(),0,256);
1397 if (GetDlgItemTextA(hDlg
, comboID
, name
, 255))
1398 PRINTDLG_ChangePrinterA(hDlg
, name
, PrintStructures
);
1399 HeapFree(GetProcessHeap(),0,name
);
1401 /* else use default printer */
1403 DWORD dwBufLen
= sizeof(name
);
1404 BOOL ret
= GetDefaultPrinterA(name
, &dwBufLen
);
1407 PRINTDLG_ChangePrinterA(hDlg
, name
, PrintStructures
);
1409 FIXME("No default printer found, expect problems!\n");
1414 static LRESULT
PRINTDLG_WMInitDialogW(HWND hDlg
,
1415 PRINT_PTRW
* PrintStructures
)
1417 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1421 UINT comboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1423 /* load Collate ICONs */
1424 /* We load these with LoadImage because they are not a standard
1425 size and we don't want them rescaled */
1426 PrintStructures
->hCollateIcon
=
1427 LoadImageW(COMDLG32_hInstance
, pd32_collateW
, IMAGE_ICON
, 0, 0, 0);
1428 PrintStructures
->hNoCollateIcon
=
1429 LoadImageW(COMDLG32_hInstance
, pd32_nocollateW
, IMAGE_ICON
, 0, 0, 0);
1431 /* These can be done with LoadIcon */
1432 PrintStructures
->hPortraitIcon
=
1433 LoadIconW(COMDLG32_hInstance
, pd32_portraitW
);
1434 PrintStructures
->hLandscapeIcon
=
1435 LoadIconW(COMDLG32_hInstance
, pd32_landscapeW
);
1437 /* display the collate/no_collate icon */
1438 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1439 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1441 if(PrintStructures
->hCollateIcon
== 0 ||
1442 PrintStructures
->hNoCollateIcon
== 0 ||
1443 PrintStructures
->hPortraitIcon
== 0 ||
1444 PrintStructures
->hLandscapeIcon
== 0) {
1445 ERR("no icon in resourcefile\n");
1446 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1447 EndDialog(hDlg
, FALSE
);
1451 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1452 * must be registered and the Help button must be shown.
1454 if (lppd
->Flags
& PD_SHOWHELP
) {
1455 if((PrintStructures
->HelpMessageID
=
1456 RegisterWindowMessageW(HELPMSGSTRINGW
)) == 0) {
1457 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL
);
1461 PrintStructures
->HelpMessageID
= 0;
1463 if(!(lppd
->Flags
&PD_PRINTSETUP
)) {
1464 PrintStructures
->hwndUpDown
=
1465 CreateUpDownControl(WS_CHILD
| WS_VISIBLE
| WS_BORDER
|
1466 UDS_NOTHOUSANDS
| UDS_ARROWKEYS
|
1467 UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, 0, 0, 0, 0,
1468 hDlg
, UPDOWN_ID
, COMDLG32_hInstance
,
1469 GetDlgItem(hDlg
, edt3
), MAX_COPIES
, 1, 1);
1472 /* FIXME: I allow more freedom than either Win95 or WinNT,
1473 * which do not agree to what errors should be thrown or not
1474 * in case nToPage or nFromPage is out-of-range.
1476 if (lppd
->nMaxPage
< lppd
->nMinPage
)
1477 lppd
->nMaxPage
= lppd
->nMinPage
;
1478 if (lppd
->nMinPage
== lppd
->nMaxPage
)
1479 lppd
->Flags
|= PD_NOPAGENUMS
;
1480 if (lppd
->nToPage
< lppd
->nMinPage
)
1481 lppd
->nToPage
= lppd
->nMinPage
;
1482 if (lppd
->nToPage
> lppd
->nMaxPage
)
1483 lppd
->nToPage
= lppd
->nMaxPage
;
1484 if (lppd
->nFromPage
< lppd
->nMinPage
)
1485 lppd
->nFromPage
= lppd
->nMinPage
;
1486 if (lppd
->nFromPage
> lppd
->nMaxPage
)
1487 lppd
->nFromPage
= lppd
->nMaxPage
;
1489 /* if we have the combo box, fill it */
1490 if (GetDlgItem(hDlg
,comboID
)) {
1493 pdn
= GlobalLock(lppd
->hDevNames
);
1494 pdm
= GlobalLock(lppd
->hDevMode
);
1496 name
= (WCHAR
*)pdn
+ pdn
->wDeviceOffset
;
1498 name
= pdm
->dmDeviceName
;
1499 PRINTDLG_SetUpPrinterListComboW(hDlg
, comboID
, name
);
1500 if(pdm
) GlobalUnlock(lppd
->hDevMode
);
1501 if(pdn
) GlobalUnlock(lppd
->hDevNames
);
1503 /* Now find selected printer and update rest of dlg */
1504 /* ansi is ok here */
1505 name
= HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR
));
1506 if (GetDlgItemTextW(hDlg
, comboID
, name
, 255))
1507 PRINTDLG_ChangePrinterW(hDlg
, name
, PrintStructures
);
1508 HeapFree(GetProcessHeap(),0,name
);
1510 /* else use default printer */
1512 DWORD dwBufLen
= sizeof(name
) / sizeof(WCHAR
);
1513 BOOL ret
= GetDefaultPrinterW(name
, &dwBufLen
);
1516 PRINTDLG_ChangePrinterW(hDlg
, name
, PrintStructures
);
1518 FIXME("No default printer found, expect problems!\n");
1523 /***********************************************************************
1524 * PRINTDLG_WMCommand [internal]
1526 static LRESULT
PRINTDLG_WMCommandA(HWND hDlg
, WPARAM wParam
,
1527 PRINT_PTRA
* PrintStructures
)
1529 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1530 UINT PrinterComboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1531 LPDEVMODEA lpdm
= PrintStructures
->lpDevMode
;
1533 switch (LOWORD(wParam
)) {
1535 TRACE(" OK button was hit\n");
1536 if (!PRINTDLG_UpdatePrintDlgA(hDlg
, PrintStructures
)) {
1537 FIXME("Update printdlg was not successful!\n");
1540 EndDialog(hDlg
, TRUE
);
1544 TRACE(" CANCEL button was hit\n");
1545 EndDialog(hDlg
, FALSE
);
1549 TRACE(" HELP button was hit\n");
1550 SendMessageA(lppd
->hwndOwner
, PrintStructures
->HelpMessageID
,
1551 (WPARAM
) hDlg
, (LPARAM
) lppd
);
1554 case chx2
: /* collate pages checkbox */
1555 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
1556 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1557 (LPARAM
)PrintStructures
->hCollateIcon
);
1559 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1560 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1562 case edt1
: /* from page nr editbox */
1563 case edt2
: /* to page nr editbox */
1564 if (HIWORD(wParam
)==EN_CHANGE
) {
1567 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
1568 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
1569 if (nFromPage
!= lppd
->nFromPage
|| nToPage
!= lppd
->nToPage
)
1570 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1575 if(HIWORD(wParam
) == EN_CHANGE
) {
1576 INT copies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
1578 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1580 EnableWindow(GetDlgItem(hDlg
, chx2
), TRUE
);
1584 case psh2
: /* Properties button */
1587 char PrinterName
[256];
1589 GetDlgItemTextA(hDlg
, PrinterComboID
, PrinterName
, 255);
1590 if (!OpenPrinterA(PrinterName
, &hPrinter
, NULL
)) {
1591 FIXME(" Call to OpenPrinter did not succeed!\n");
1594 DocumentPropertiesA(hDlg
, hPrinter
, PrinterName
,
1595 PrintStructures
->lpDevMode
,
1596 PrintStructures
->lpDevMode
,
1597 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
1598 ClosePrinter(hPrinter
);
1602 case rad1
: /* Paperorientation */
1603 if (lppd
->Flags
& PD_PRINTSETUP
)
1605 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1606 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1607 (LPARAM
)(PrintStructures
->hPortraitIcon
));
1611 case rad2
: /* Paperorientation */
1612 if (lppd
->Flags
& PD_PRINTSETUP
)
1614 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1615 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1616 (LPARAM
)(PrintStructures
->hLandscapeIcon
));
1620 case cmb1
: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT16 */
1621 if (PrinterComboID
!= LOWORD(wParam
)) {
1625 case cmb4
: /* Printer combobox */
1626 if (HIWORD(wParam
)==CBN_SELCHANGE
) {
1627 char PrinterName
[256];
1628 GetDlgItemTextA(hDlg
, LOWORD(wParam
), PrinterName
, 255);
1629 PRINTDLG_ChangePrinterA(hDlg
, PrinterName
, PrintStructures
);
1633 case cmb2
: /* Papersize */
1635 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
1637 lpdm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageA(hDlg
, cmb2
,
1643 case cmb3
: /* Bin */
1645 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
1647 lpdm
->u1
.s1
.dmDefaultSource
= SendDlgItemMessageA(hDlg
, cmb3
,
1648 CB_GETITEMDATA
, Sel
,
1653 if(lppd
->Flags
& PD_PRINTSETUP
) {
1654 switch (LOWORD(wParam
)) {
1655 case rad1
: /* orientation */
1657 if (IsDlgButtonChecked(hDlg
, rad1
) == BST_CHECKED
) {
1658 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_PORTRAIT
) {
1659 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1660 SendDlgItemMessageA(hDlg
, stc10
, STM_SETIMAGE
, IMAGE_ICON
,
1661 (LPARAM
)PrintStructures
->hPortraitIcon
);
1662 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1663 (LPARAM
)PrintStructures
->hPortraitIcon
);
1666 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_LANDSCAPE
) {
1667 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1668 SendDlgItemMessageA(hDlg
, stc10
, STM_SETIMAGE
, IMAGE_ICON
,
1669 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1670 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1671 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1680 static LRESULT
PRINTDLG_WMCommandW(HWND hDlg
, WPARAM wParam
,
1681 PRINT_PTRW
* PrintStructures
)
1683 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1684 UINT PrinterComboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1685 LPDEVMODEW lpdm
= PrintStructures
->lpDevMode
;
1687 switch (LOWORD(wParam
)) {
1689 TRACE(" OK button was hit\n");
1690 if (!PRINTDLG_UpdatePrintDlgW(hDlg
, PrintStructures
)) {
1691 FIXME("Update printdlg was not successful!\n");
1694 EndDialog(hDlg
, TRUE
);
1698 TRACE(" CANCEL button was hit\n");
1699 EndDialog(hDlg
, FALSE
);
1703 TRACE(" HELP button was hit\n");
1704 SendMessageW(lppd
->hwndOwner
, PrintStructures
->HelpMessageID
,
1705 (WPARAM
) hDlg
, (LPARAM
) lppd
);
1708 case chx2
: /* collate pages checkbox */
1709 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
1710 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1711 (LPARAM
)PrintStructures
->hCollateIcon
);
1713 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1714 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1716 case edt1
: /* from page nr editbox */
1717 case edt2
: /* to page nr editbox */
1718 if (HIWORD(wParam
)==EN_CHANGE
) {
1721 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
1722 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
1723 if (nFromPage
!= lppd
->nFromPage
|| nToPage
!= lppd
->nToPage
)
1724 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1729 if(HIWORD(wParam
) == EN_CHANGE
) {
1730 INT copies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
1732 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1734 EnableWindow(GetDlgItem(hDlg
, chx2
), TRUE
);
1738 case psh2
: /* Properties button */
1741 WCHAR PrinterName
[256];
1743 if (!GetDlgItemTextW(hDlg
, PrinterComboID
, PrinterName
, 255)) break;
1744 if (!OpenPrinterW(PrinterName
, &hPrinter
, NULL
)) {
1745 FIXME(" Call to OpenPrinter did not succeed!\n");
1748 DocumentPropertiesW(hDlg
, hPrinter
, PrinterName
,
1749 PrintStructures
->lpDevMode
,
1750 PrintStructures
->lpDevMode
,
1751 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
1752 ClosePrinter(hPrinter
);
1756 case rad1
: /* Paperorientation */
1757 if (lppd
->Flags
& PD_PRINTSETUP
)
1759 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1760 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1761 (LPARAM
)(PrintStructures
->hPortraitIcon
));
1765 case rad2
: /* Paperorientation */
1766 if (lppd
->Flags
& PD_PRINTSETUP
)
1768 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1769 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1770 (LPARAM
)(PrintStructures
->hLandscapeIcon
));
1774 case cmb1
: /* Printer Combobox in PRINT SETUP */
1776 case cmb4
: /* Printer combobox */
1777 if (HIWORD(wParam
)==CBN_SELCHANGE
) {
1778 WCHAR PrinterName
[256];
1779 GetDlgItemTextW(hDlg
, LOWORD(wParam
), PrinterName
, 255);
1780 PRINTDLG_ChangePrinterW(hDlg
, PrinterName
, PrintStructures
);
1784 case cmb2
: /* Papersize */
1786 DWORD Sel
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
1788 lpdm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageW(hDlg
, cmb2
,
1794 case cmb3
: /* Bin */
1796 DWORD Sel
= SendDlgItemMessageW(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
1798 lpdm
->u1
.s1
.dmDefaultSource
= SendDlgItemMessageW(hDlg
, cmb3
,
1799 CB_GETITEMDATA
, Sel
,
1804 if(lppd
->Flags
& PD_PRINTSETUP
) {
1805 switch (LOWORD(wParam
)) {
1806 case rad1
: /* orientation */
1808 if (IsDlgButtonChecked(hDlg
, rad1
) == BST_CHECKED
) {
1809 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_PORTRAIT
) {
1810 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1811 SendDlgItemMessageW(hDlg
, stc10
, STM_SETIMAGE
, IMAGE_ICON
,
1812 (LPARAM
)PrintStructures
->hPortraitIcon
);
1813 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1814 (LPARAM
)PrintStructures
->hPortraitIcon
);
1817 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_LANDSCAPE
) {
1818 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1819 SendDlgItemMessageW(hDlg
, stc10
, STM_SETIMAGE
, IMAGE_ICON
,
1820 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1821 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
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
= GetPropW(hDlg
, printdlg_prop
);
1842 if (!PrintStructures
)
1845 PrintStructures
= (PRINT_PTRA
*) lParam
;
1846 SetPropW(hDlg
, printdlg_prop
, PrintStructures
);
1847 if(!check_printer_setup(hDlg
))
1849 EndDialog(hDlg
,FALSE
);
1852 res
= PRINTDLG_WMInitDialog(hDlg
, 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
, 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 PRINT_PTRW
* PrintStructures
;
1887 INT_PTR res
= FALSE
;
1889 if (uMsg
!=WM_INITDIALOG
) {
1890 PrintStructures
= GetPropW(hDlg
, printdlg_prop
);
1891 if (!PrintStructures
)
1894 PrintStructures
= (PRINT_PTRW
*) lParam
;
1895 SetPropW(hDlg
, printdlg_prop
, PrintStructures
);
1896 if(!check_printer_setup(hDlg
))
1898 EndDialog(hDlg
,FALSE
);
1901 res
= PRINTDLG_WMInitDialogW(hDlg
, PrintStructures
);
1903 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
)
1904 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->lpPrintDlg
);
1908 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
) {
1909 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
,uMsg
,wParam
, lParam
);
1915 return PRINTDLG_WMCommandW(hDlg
, wParam
, PrintStructures
);
1918 DestroyIcon(PrintStructures
->hCollateIcon
);
1919 DestroyIcon(PrintStructures
->hNoCollateIcon
);
1920 DestroyIcon(PrintStructures
->hPortraitIcon
);
1921 DestroyIcon(PrintStructures
->hLandscapeIcon
);
1922 if(PrintStructures
->hwndUpDown
)
1923 DestroyWindow(PrintStructures
->hwndUpDown
);
1929 /************************************************************
1931 * PRINTDLG_GetDlgTemplate
1934 static HGLOBAL
PRINTDLG_GetDlgTemplateA(const PRINTDLGA
*lppd
)
1939 if (lppd
->Flags
& PD_PRINTSETUP
) {
1940 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
1941 hDlgTmpl
= lppd
->hSetupTemplate
;
1942 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
1943 hResInfo
= FindResourceA(lppd
->hInstance
,
1944 lppd
->lpSetupTemplateName
, (LPSTR
)RT_DIALOG
);
1945 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1947 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32_SETUP",
1949 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1952 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
1953 hDlgTmpl
= lppd
->hPrintTemplate
;
1954 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
1955 hResInfo
= FindResourceA(lppd
->hInstance
,
1956 lppd
->lpPrintTemplateName
,
1958 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1960 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32",
1962 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1968 static HGLOBAL
PRINTDLG_GetDlgTemplateW(const PRINTDLGW
*lppd
)
1972 static const WCHAR xpsetup
[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
1973 static const WCHAR xprint
[] = { 'P','R','I','N','T','3','2',0};
1975 if (lppd
->Flags
& PD_PRINTSETUP
) {
1976 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
1977 hDlgTmpl
= lppd
->hSetupTemplate
;
1978 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
1979 hResInfo
= FindResourceW(lppd
->hInstance
,
1980 lppd
->lpSetupTemplateName
, (LPWSTR
)RT_DIALOG
);
1981 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1983 hResInfo
= FindResourceW(COMDLG32_hInstance
, xpsetup
, (LPWSTR
)RT_DIALOG
);
1984 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1987 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
1988 hDlgTmpl
= lppd
->hPrintTemplate
;
1989 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
1990 hResInfo
= FindResourceW(lppd
->hInstance
,
1991 lppd
->lpPrintTemplateName
,
1993 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1995 hResInfo
= FindResourceW(COMDLG32_hInstance
, xprint
, (LPWSTR
)RT_DIALOG
);
1996 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
2002 /***********************************************************************
2007 static BOOL
PRINTDLG_CreateDCA(LPPRINTDLGA lppd
)
2009 DEVNAMES
*pdn
= GlobalLock(lppd
->hDevNames
);
2010 DEVMODEA
*pdm
= GlobalLock(lppd
->hDevMode
);
2012 if(lppd
->Flags
& PD_RETURNDC
) {
2013 lppd
->hDC
= CreateDCA((char*)pdn
+ pdn
->wDriverOffset
,
2014 (char*)pdn
+ pdn
->wDeviceOffset
,
2015 (char*)pdn
+ pdn
->wOutputOffset
,
2017 } else if(lppd
->Flags
& PD_RETURNIC
) {
2018 lppd
->hDC
= CreateICA((char*)pdn
+ pdn
->wDriverOffset
,
2019 (char*)pdn
+ pdn
->wDeviceOffset
,
2020 (char*)pdn
+ pdn
->wOutputOffset
,
2023 GlobalUnlock(lppd
->hDevNames
);
2024 GlobalUnlock(lppd
->hDevMode
);
2025 return lppd
->hDC
? TRUE
: FALSE
;
2028 static BOOL
PRINTDLG_CreateDCW(LPPRINTDLGW lppd
)
2030 DEVNAMES
*pdn
= GlobalLock(lppd
->hDevNames
);
2031 DEVMODEW
*pdm
= GlobalLock(lppd
->hDevMode
);
2033 if(lppd
->Flags
& PD_RETURNDC
) {
2034 lppd
->hDC
= CreateDCW((WCHAR
*)pdn
+ pdn
->wDriverOffset
,
2035 (WCHAR
*)pdn
+ pdn
->wDeviceOffset
,
2036 (WCHAR
*)pdn
+ pdn
->wOutputOffset
,
2038 } else if(lppd
->Flags
& PD_RETURNIC
) {
2039 lppd
->hDC
= CreateICW((WCHAR
*)pdn
+ pdn
->wDriverOffset
,
2040 (WCHAR
*)pdn
+ pdn
->wDeviceOffset
,
2041 (WCHAR
*)pdn
+ pdn
->wOutputOffset
,
2044 GlobalUnlock(lppd
->hDevNames
);
2045 GlobalUnlock(lppd
->hDevMode
);
2046 return lppd
->hDC
? TRUE
: FALSE
;
2049 /***********************************************************************
2050 * PrintDlgA (COMDLG32.@)
2052 * Displays the PRINT dialog box, which enables the user to specify
2053 * specific properties of the print job.
2056 * lppd [IO] ptr to PRINTDLG32 struct
2059 * nonzero if the user pressed the OK button
2060 * zero if the user cancelled the window or an error occurred
2064 * * The Collate Icons do not display, even though they are in the code.
2065 * * The Properties Button(s) should call DocumentPropertiesA().
2068 BOOL WINAPI
PrintDlgA(LPPRINTDLGA lppd
)
2076 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
2080 if(TRACE_ON(commdlg
)) {
2081 char flagstr
[1000] = "";
2082 const struct pd_flags
*pflag
= pd_flags
;
2083 for( ; pflag
->name
; pflag
++) {
2084 if(lppd
->Flags
& pflag
->flag
)
2085 strcat(flagstr
, pflag
->name
);
2087 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2088 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2089 "flags %08x (%s)\n",
2090 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
2091 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
2092 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
2095 if(lppd
->lStructSize
!= sizeof(PRINTDLGA
)) {
2096 WARN("structure size failure !!!\n");
2097 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
2101 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
2102 PRINTER_INFO_2A
*pbuf
;
2103 DRIVER_INFO_3A
*dbuf
;
2107 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
2108 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2109 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2112 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
2113 WARN("Can't find default printer\n");
2114 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
2118 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
2119 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
2120 GetPrinterA(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
2122 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
2123 dbuf
= HeapAlloc(GetProcessHeap(),0,needed
);
2124 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
2125 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2126 GetLastError(),pbuf
->pPrinterName
);
2127 HeapFree(GetProcessHeap(), 0, dbuf
);
2128 HeapFree(GetProcessHeap(), 0, pbuf
);
2129 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2134 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
2138 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
2139 pbuf
->pDevMode
->dmDriverExtra
);
2140 ptr
= GlobalLock(lppd
->hDevMode
);
2141 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
2142 pbuf
->pDevMode
->dmDriverExtra
);
2143 GlobalUnlock(lppd
->hDevMode
);
2144 HeapFree(GetProcessHeap(), 0, pbuf
);
2145 HeapFree(GetProcessHeap(), 0, dbuf
);
2149 PRINT_PTRA
*PrintStructures
;
2151 /* load Dialog resources,
2152 * depending on Flags indicates Print32 or Print32_setup dialog
2154 hDlgTmpl
= PRINTDLG_GetDlgTemplateA(lppd
);
2156 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2159 ptr
= LockResource( hDlgTmpl
);
2161 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2165 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2166 sizeof(PRINT_PTRA
));
2167 PrintStructures
->lpPrintDlg
= lppd
;
2169 /* and create & process the dialog .
2170 * -1 is failure, 0 is broken hwnd, everything else is ok.
2172 hInst
= COMDLG32_hInstance
;
2173 if (lppd
->Flags
& (PD_ENABLESETUPTEMPLATE
| PD_ENABLEPRINTTEMPLATE
)) hInst
= lppd
->hInstance
;
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 if(TRACE_ON(commdlg
)) {
2232 char flagstr
[1000] = "";
2233 const struct pd_flags
*pflag
= pd_flags
;
2234 for( ; pflag
->name
; pflag
++) {
2235 if(lppd
->Flags
& pflag
->flag
)
2236 strcat(flagstr
, pflag
->name
);
2238 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2239 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2240 "flags %08x (%s)\n",
2241 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
2242 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
2243 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
2246 if(lppd
->lStructSize
!= sizeof(PRINTDLGW
)) {
2247 WARN("structure size failure !!!\n");
2248 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
2252 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
2253 PRINTER_INFO_2W
*pbuf
;
2254 DRIVER_INFO_3W
*dbuf
;
2258 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
2259 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2260 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2263 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
2264 WARN("Can't find default printer\n");
2265 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
2269 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
2270 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
2271 GetPrinterW(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
2273 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
2274 dbuf
= HeapAlloc(GetProcessHeap(),0,needed
);
2275 if (!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
2276 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2277 GetLastError(),debugstr_w(pbuf
->pPrinterName
));
2278 HeapFree(GetProcessHeap(), 0, dbuf
);
2279 HeapFree(GetProcessHeap(), 0, pbuf
);
2280 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2285 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
2289 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
2290 pbuf
->pDevMode
->dmDriverExtra
);
2291 ptr
= GlobalLock(lppd
->hDevMode
);
2292 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
2293 pbuf
->pDevMode
->dmDriverExtra
);
2294 GlobalUnlock(lppd
->hDevMode
);
2295 HeapFree(GetProcessHeap(), 0, pbuf
);
2296 HeapFree(GetProcessHeap(), 0, dbuf
);
2300 PRINT_PTRW
*PrintStructures
;
2302 /* load Dialog resources,
2303 * depending on Flags indicates Print32 or Print32_setup dialog
2305 hDlgTmpl
= PRINTDLG_GetDlgTemplateW(lppd
);
2307 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2310 ptr
= LockResource( hDlgTmpl
);
2312 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2316 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2317 sizeof(PRINT_PTRW
));
2318 PrintStructures
->lpPrintDlg
= lppd
;
2320 /* and create & process the dialog .
2321 * -1 is failure, 0 is broken hwnd, everything else is ok.
2323 hInst
= COMDLG32_hInstance
;
2324 if (lppd
->Flags
& (PD_ENABLESETUPTEMPLATE
| PD_ENABLEPRINTTEMPLATE
)) hInst
= lppd
->hInstance
;
2325 bRet
= (0<DialogBoxIndirectParamW(hInst
, ptr
, lppd
->hwndOwner
,
2327 (LPARAM
)PrintStructures
));
2330 DEVMODEW
*lpdm
= PrintStructures
->lpDevMode
, *lpdmReturn
;
2331 PRINTER_INFO_2W
*pi
= PrintStructures
->lpPrinterInfo
;
2332 DRIVER_INFO_3W
*di
= PrintStructures
->lpDriverInfo
;
2334 if (lppd
->hDevMode
== 0) {
2335 TRACE(" No hDevMode yet... Need to create my own\n");
2336 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
,
2337 lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2340 if((locks
= (GlobalFlags(lppd
->hDevMode
) & GMEM_LOCKCOUNT
))) {
2341 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks
);
2343 GlobalUnlock(lppd
->hDevMode
);
2344 TRACE("Now got %d locks\n", locks
);
2347 lppd
->hDevMode
= GlobalReAlloc(lppd
->hDevMode
,
2348 lpdm
->dmSize
+ lpdm
->dmDriverExtra
,
2351 lpdmReturn
= GlobalLock(lppd
->hDevMode
);
2352 memcpy(lpdmReturn
, lpdm
, lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2354 if (lppd
->hDevNames
!= 0) {
2356 if((locks
= (GlobalFlags(lppd
->hDevNames
) & GMEM_LOCKCOUNT
))) {
2357 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks
);
2359 GlobalUnlock(lppd
->hDevNames
);
2362 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
2367 GlobalUnlock(lppd
->hDevMode
);
2369 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
2370 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpPrinterInfo
);
2371 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDriverInfo
);
2372 HeapFree(GetProcessHeap(), 0, PrintStructures
);
2374 if(bRet
&& (lppd
->Flags
& PD_RETURNDC
|| lppd
->Flags
& PD_RETURNIC
))
2375 bRet
= PRINTDLG_CreateDCW(lppd
);
2377 TRACE("exit! (%d)\n", bRet
);
2381 /***********************************************************************
2386 * cmb1 - printer select (not in standard dialog template)
2388 * cmb3 - source (tray?)
2389 * edt4 - border left
2391 * edt6 - border right
2392 * edt7 - border bottom
2393 * psh3 - "Printer..."
2401 LPPAGESETUPDLGA dlga
;
2402 LPPAGESETUPDLGW dlgw
;
2404 HWND hDlg
; /* Page Setup dialog handle */
2405 RECT rtDrawRect
; /* Drawing rect for page */
2408 static inline DWORD
pagesetup_get_flags(const pagesetup_data
*data
)
2410 return data
->u
.dlgw
->Flags
;
2413 static inline BOOL
is_metric(const pagesetup_data
*data
)
2415 return pagesetup_get_flags(data
) & PSD_INHUNDREDTHSOFMILLIMETERS
;
2418 static inline LONG
tenths_mm_to_size(const pagesetup_data
*data
, LONG size
)
2420 if (is_metric(data
))
2423 return 10 * size
* 100 / 254;
2426 static inline LONG
thousandths_inch_to_size(const pagesetup_data
*data
, LONG size
)
2428 if (is_metric(data
))
2429 return size
* 254 / 100;
2434 static WCHAR
get_decimal_sep(void)
2440 WCHAR buf
[] = {'.', 0};
2441 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SDECIMAL
, buf
, sizeof(buf
) / sizeof(buf
[0]));
2447 static void size2str(const pagesetup_data
*data
, DWORD size
, LPWSTR strout
)
2449 WCHAR integer_fmt
[] = {'%','d',0};
2450 WCHAR hundredths_fmt
[] = {'%','d','%','c','%','0','2','d',0};
2451 WCHAR thousandths_fmt
[] = {'%','d','%','c','%','0','3','d',0};
2453 /* FIXME use LOCALE_SDECIMAL when the edit parsing code can cope */
2455 if (is_metric(data
))
2458 wsprintfW(strout
, hundredths_fmt
, size
/ 100, get_decimal_sep(), size
% 100);
2460 wsprintfW(strout
, integer_fmt
, size
/ 100);
2465 wsprintfW(strout
, thousandths_fmt
, size
/ 1000, get_decimal_sep(), size
% 1000);
2467 wsprintfW(strout
, integer_fmt
, size
/ 1000);
2472 static inline BOOL
is_default_metric(void)
2475 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_IMEASURE
| LOCALE_RETURN_NUMBER
,
2476 (LPWSTR
)&system
, sizeof(system
));
2480 /**********************************************
2482 * Cyclically permute the four members of rc
2483 * If sense is TRUE l -> t -> r -> b
2484 * otherwise l <- t <- r <- b
2486 static inline void rotate_rect(RECT
*rc
, BOOL sense
)
2492 rc
->bottom
= rc
->right
;
2493 rc
->right
= rc
->top
;
2501 rc
->top
= rc
->right
;
2502 rc
->right
= rc
->bottom
;
2507 static void pagesetup_set_orientation(pagesetup_data
*data
, WORD orient
)
2509 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2511 assert(orient
== DMORIENT_PORTRAIT
|| orient
== DMORIENT_LANDSCAPE
);
2514 dm
->u1
.s1
.dmOrientation
= orient
;
2517 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2518 dmA
->u1
.s1
.dmOrientation
= orient
;
2520 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2523 static WORD
pagesetup_get_orientation(const pagesetup_data
*data
)
2525 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2529 orient
= dm
->u1
.s1
.dmOrientation
;
2532 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2533 orient
= dmA
->u1
.s1
.dmOrientation
;
2535 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2539 static void pagesetup_set_papersize(pagesetup_data
*data
, WORD paper
)
2541 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2544 dm
->u1
.s1
.dmPaperSize
= paper
;
2547 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2548 dmA
->u1
.s1
.dmPaperSize
= paper
;
2550 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2553 static WORD
pagesetup_get_papersize(const pagesetup_data
*data
)
2555 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2559 paper
= dm
->u1
.s1
.dmPaperSize
;
2562 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2563 paper
= dmA
->u1
.s1
.dmPaperSize
;
2565 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2569 static void pagesetup_set_defaultsource(pagesetup_data
*data
, WORD source
)
2571 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2574 dm
->u1
.s1
.dmDefaultSource
= source
;
2577 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2578 dmA
->u1
.s1
.dmDefaultSource
= source
;
2580 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2585 devnames_driver_name
,
2586 devnames_device_name
,
2587 devnames_output_name
2591 static inline WORD
get_devname_offset(const DEVNAMES
*dn
, devnames_name which
)
2595 case devnames_driver_name
: return dn
->wDriverOffset
;
2596 case devnames_device_name
: return dn
->wDeviceOffset
;
2597 case devnames_output_name
: return dn
->wOutputOffset
;
2599 ERR("Shouldn't be here\n");
2603 static WCHAR
*pagesetup_get_a_devname(const pagesetup_data
*data
, devnames_name which
)
2608 dn
= GlobalLock(data
->u
.dlgw
->hDevNames
);
2610 name
= strdupW((WCHAR
*)dn
+ get_devname_offset(dn
, which
));
2613 int len
= MultiByteToWideChar(CP_ACP
, 0, (char*)dn
+ get_devname_offset(dn
, which
), -1, NULL
, 0);
2614 name
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
2615 MultiByteToWideChar(CP_ACP
, 0, (char*)dn
+ get_devname_offset(dn
, which
), -1, name
, len
);
2617 GlobalUnlock(data
->u
.dlgw
->hDevNames
);
2621 static WCHAR
*pagesetup_get_drvname(const pagesetup_data
*data
)
2623 return pagesetup_get_a_devname(data
, devnames_driver_name
);
2626 static WCHAR
*pagesetup_get_devname(const pagesetup_data
*data
)
2628 return pagesetup_get_a_devname(data
, devnames_device_name
);
2631 static WCHAR
*pagesetup_get_portname(const pagesetup_data
*data
)
2633 return pagesetup_get_a_devname(data
, devnames_output_name
);
2636 static void pagesetup_release_a_devname(const pagesetup_data
*data
, WCHAR
*name
)
2638 HeapFree(GetProcessHeap(), 0, name
);
2641 static void pagesetup_set_devnames(pagesetup_data
*data
, LPCWSTR drv
, LPCWSTR devname
, LPCWSTR port
)
2645 DWORD len
= sizeof(DEVNAMES
), drv_len
, dev_len
, port_len
;
2649 drv_len
= (strlenW(drv
) + 1) * sizeof(WCHAR
);
2650 dev_len
= (strlenW(devname
) + 1) * sizeof(WCHAR
);
2651 port_len
= (strlenW(port
) + 1) * sizeof(WCHAR
);
2655 drv_len
= WideCharToMultiByte(CP_ACP
, 0, drv
, -1, NULL
, 0, NULL
, NULL
);
2656 dev_len
= WideCharToMultiByte(CP_ACP
, 0, devname
, -1, NULL
, 0, NULL
, NULL
);
2657 port_len
= WideCharToMultiByte(CP_ACP
, 0, port
, -1, NULL
, 0, NULL
, NULL
);
2659 len
+= drv_len
+ dev_len
+ port_len
;
2661 if(data
->u
.dlgw
->hDevNames
)
2662 data
->u
.dlgw
->hDevNames
= GlobalReAlloc(data
->u
.dlgw
->hDevNames
, len
, GMEM_MOVEABLE
);
2664 data
->u
.dlgw
->hDevNames
= GlobalAlloc(GMEM_MOVEABLE
, len
);
2666 dn
= GlobalLock(data
->u
.dlgw
->hDevNames
);
2670 WCHAR
*ptr
= (WCHAR
*)(dn
+ 1);
2671 len
= sizeof(DEVNAMES
) / sizeof(WCHAR
);
2672 dn
->wDriverOffset
= len
;
2674 ptr
+= drv_len
/ sizeof(WCHAR
);
2675 len
+= drv_len
/ sizeof(WCHAR
);
2676 dn
->wDeviceOffset
= len
;
2677 strcpyW(ptr
, devname
);
2678 ptr
+= dev_len
/ sizeof(WCHAR
);
2679 len
+= dev_len
/ sizeof(WCHAR
);
2680 dn
->wOutputOffset
= len
;
2685 char *ptr
= (char *)(dn
+ 1);
2686 len
= sizeof(DEVNAMES
);
2687 dn
->wDriverOffset
= len
;
2688 WideCharToMultiByte(CP_ACP
, 0, drv
, -1, ptr
, drv_len
, NULL
, NULL
);
2691 dn
->wDeviceOffset
= len
;
2692 WideCharToMultiByte(CP_ACP
, 0, devname
, -1, ptr
, dev_len
, NULL
, NULL
);
2695 dn
->wOutputOffset
= len
;
2696 WideCharToMultiByte(CP_ACP
, 0, port
, -1, ptr
, port_len
, NULL
, NULL
);
2700 len
= sizeof(def
) / sizeof(def
[0]);
2701 GetDefaultPrinterW(def
, &len
);
2702 if(!lstrcmpW(def
, devname
))
2705 GlobalUnlock(data
->u
.dlgw
->hDevNames
);
2708 static DEVMODEW
*pagesetup_get_devmode(const pagesetup_data
*data
)
2710 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2715 /* We make a copy even in the unicode case because the ptr
2716 may get passed back to us in pagesetup_set_devmode. */
2717 ret
= HeapAlloc(GetProcessHeap(), 0, dm
->dmSize
+ dm
->dmDriverExtra
);
2718 memcpy(ret
, dm
, dm
->dmSize
+ dm
->dmDriverExtra
);
2721 ret
= GdiConvertToDevmodeW((DEVMODEA
*)dm
);
2723 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2727 static void pagesetup_release_devmode(const pagesetup_data
*data
, DEVMODEW
*dm
)
2729 HeapFree(GetProcessHeap(), 0, dm
);
2732 static void pagesetup_set_devmode(pagesetup_data
*data
, DEVMODEW
*dm
)
2734 DEVMODEA
*dmA
= NULL
;
2740 size
= dm
->dmSize
+ dm
->dmDriverExtra
;
2745 dmA
= convert_to_devmodeA(dm
);
2746 size
= dmA
->dmSize
+ dmA
->dmDriverExtra
;
2750 if(data
->u
.dlgw
->hDevMode
)
2751 data
->u
.dlgw
->hDevMode
= GlobalReAlloc(data
->u
.dlgw
->hDevMode
, size
,
2754 data
->u
.dlgw
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, size
);
2756 dst
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2757 memcpy(dst
, src
, size
);
2758 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2759 HeapFree(GetProcessHeap(), 0, dmA
);
2762 static inline POINT
*pagesetup_get_papersize_pt(const pagesetup_data
*data
)
2764 return &data
->u
.dlgw
->ptPaperSize
;
2767 static inline RECT
*pagesetup_get_margin_rect(const pagesetup_data
*data
)
2769 return &data
->u
.dlgw
->rtMargin
;
2778 static inline LPPAGESETUPHOOK
pagesetup_get_hook(const pagesetup_data
*data
, hook_type which
)
2782 case page_setup_hook
: return data
->u
.dlgw
->lpfnPageSetupHook
;
2783 case page_paint_hook
: return data
->u
.dlgw
->lpfnPagePaintHook
;
2788 /* This should only be used in calls to hook procs so we return the ptr
2789 already cast to LPARAM */
2790 static inline LPARAM
pagesetup_get_dlg_struct(const pagesetup_data
*data
)
2792 return (LPARAM
)data
->u
.dlgw
;
2795 static inline void swap_point(POINT
*pt
)
2802 static BOOL
pagesetup_update_papersize(pagesetup_data
*data
)
2805 LPWSTR devname
, portname
;
2807 WORD
*words
= NULL
, paperword
;
2808 POINT
*points
= NULL
;
2809 BOOL retval
= FALSE
;
2811 dm
= pagesetup_get_devmode(data
);
2812 devname
= pagesetup_get_devname(data
);
2813 portname
= pagesetup_get_portname(data
);
2815 num
= DeviceCapabilitiesW(devname
, portname
, DC_PAPERS
, NULL
, dm
);
2818 FIXME("No papernames found for %s/%s\n", debugstr_w(devname
), debugstr_w(portname
));
2822 words
= HeapAlloc(GetProcessHeap(), 0, num
* sizeof(WORD
));
2823 points
= HeapAlloc(GetProcessHeap(), 0, num
* sizeof(POINT
));
2825 if (num
!= DeviceCapabilitiesW(devname
, portname
, DC_PAPERS
, (LPWSTR
)words
, dm
))
2827 FIXME("Number of returned words is not %d\n", num
);
2831 if (num
!= DeviceCapabilitiesW(devname
, portname
, DC_PAPERSIZE
, (LPWSTR
)points
, dm
))
2833 FIXME("Number of returned sizes is not %d\n", num
);
2837 paperword
= pagesetup_get_papersize(data
);
2839 for (i
= 0; i
< num
; i
++)
2840 if (words
[i
] == paperword
)
2845 FIXME("Papersize %d not found in list?\n", paperword
);
2849 /* this is _10ths_ of a millimeter */
2850 pagesetup_get_papersize_pt(data
)->x
= tenths_mm_to_size(data
, points
[i
].x
);
2851 pagesetup_get_papersize_pt(data
)->y
= tenths_mm_to_size(data
, points
[i
].y
);
2853 if(pagesetup_get_orientation(data
) == DMORIENT_LANDSCAPE
)
2854 swap_point(pagesetup_get_papersize_pt(data
));
2859 HeapFree(GetProcessHeap(), 0, words
);
2860 HeapFree(GetProcessHeap(), 0, points
);
2861 pagesetup_release_a_devname(data
, portname
);
2862 pagesetup_release_a_devname(data
, devname
);
2863 pagesetup_release_devmode(data
, dm
);
2868 /**********************************************************************************************
2869 * pagesetup_change_printer
2871 * Redefines hDevMode and hDevNames HANDLES and initialises it.
2874 static BOOL
pagesetup_change_printer(LPWSTR name
, pagesetup_data
*data
)
2878 PRINTER_INFO_2W
*prn_info
= NULL
;
2879 DRIVER_INFO_3W
*drv_info
= NULL
;
2880 DEVMODEW
*dm
= NULL
;
2881 BOOL retval
= FALSE
;
2883 if(!OpenPrinterW(name
, &hprn
, NULL
))
2885 ERR("Can't open printer %s\n", debugstr_w(name
));
2889 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
2890 prn_info
= HeapAlloc(GetProcessHeap(), 0, needed
);
2891 GetPrinterW(hprn
, 2, (LPBYTE
)prn_info
, needed
, &needed
);
2892 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
2893 drv_info
= HeapAlloc(GetProcessHeap(), 0, needed
);
2894 if(!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)drv_info
, needed
, &needed
))
2896 ERR("GetPrinterDriverA failed for %s, fix your config!\n", debugstr_w(prn_info
->pPrinterName
));
2901 needed
= DocumentPropertiesW(0, 0, name
, NULL
, NULL
, 0);
2904 ERR("DocumentProperties fails on %s\n", debugstr_w(name
));
2908 dm
= HeapAlloc(GetProcessHeap(), 0, needed
);
2909 DocumentPropertiesW(0, 0, name
, dm
, NULL
, DM_OUT_BUFFER
);
2911 pagesetup_set_devmode(data
, dm
);
2912 pagesetup_set_devnames(data
, drv_info
->pDriverPath
, prn_info
->pPrinterName
,
2913 prn_info
->pPortName
);
2917 HeapFree(GetProcessHeap(), 0, dm
);
2918 HeapFree(GetProcessHeap(), 0, prn_info
);
2919 HeapFree(GetProcessHeap(), 0, drv_info
);
2923 /****************************************************************************************
2924 * pagesetup_init_combos
2926 * Fills Printers, Paper and Source combos
2929 static void pagesetup_init_combos(HWND hDlg
, pagesetup_data
*data
)
2932 LPWSTR devname
, portname
;
2934 dm
= pagesetup_get_devmode(data
);
2935 devname
= pagesetup_get_devname(data
);
2936 portname
= pagesetup_get_portname(data
);
2938 PRINTDLG_SetUpPrinterListComboW(hDlg
, cmb1
, devname
);
2939 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb2
, devname
, portname
, dm
);
2940 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb3
, devname
, portname
, dm
);
2942 pagesetup_release_a_devname(data
, portname
);
2943 pagesetup_release_a_devname(data
, devname
);
2944 pagesetup_release_devmode(data
, dm
);
2948 /****************************************************************************************
2949 * pagesetup_change_printer_dialog
2951 * Pops up another dialog that lets the user pick another printer.
2953 * For now we display the PrintDlg, this should display a striped down version of it.
2955 static void pagesetup_change_printer_dialog(HWND hDlg
, pagesetup_data
*data
)
2958 LPWSTR drvname
, devname
, portname
;
2959 DEVMODEW
*tmp_dm
, *dm
;
2961 memset(&prnt
, 0, sizeof(prnt
));
2962 prnt
.lStructSize
= sizeof(prnt
);
2964 prnt
.hwndOwner
= hDlg
;
2966 drvname
= pagesetup_get_drvname(data
);
2967 devname
= pagesetup_get_devname(data
);
2968 portname
= pagesetup_get_portname(data
);
2970 PRINTDLG_CreateDevNamesW(&prnt
.hDevNames
, drvname
, devname
, portname
);
2971 pagesetup_release_a_devname(data
, portname
);
2972 pagesetup_release_a_devname(data
, devname
);
2973 pagesetup_release_a_devname(data
, drvname
);
2975 tmp_dm
= pagesetup_get_devmode(data
);
2976 prnt
.hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, tmp_dm
->dmSize
+ tmp_dm
->dmDriverExtra
);
2977 dm
= GlobalLock(prnt
.hDevMode
);
2978 memcpy(dm
, tmp_dm
, tmp_dm
->dmSize
+ tmp_dm
->dmDriverExtra
);
2979 GlobalUnlock(prnt
.hDevMode
);
2980 pagesetup_release_devmode(data
, tmp_dm
);
2982 if (PrintDlgW(&prnt
))
2984 DEVMODEW
*dm
= GlobalLock(prnt
.hDevMode
);
2985 DEVNAMES
*dn
= GlobalLock(prnt
.hDevNames
);
2987 pagesetup_set_devnames(data
, (WCHAR
*)dn
+ dn
->wDriverOffset
,
2988 (WCHAR
*)dn
+ dn
->wDeviceOffset
, (WCHAR
*)dn
+ dn
->wOutputOffset
);
2989 pagesetup_set_devmode(data
, dm
);
2990 GlobalUnlock(prnt
.hDevNames
);
2991 GlobalUnlock(prnt
.hDevMode
);
2992 pagesetup_init_combos(hDlg
, data
);
2995 GlobalFree(prnt
.hDevMode
);
2996 GlobalFree(prnt
.hDevNames
);
3000 /******************************************************************************************
3001 * pagesetup_change_preview
3003 * Changes paper preview size / position
3006 static void pagesetup_change_preview(const pagesetup_data
*data
)
3008 LONG width
, height
, x
, y
;
3010 const int shadow
= 4;
3012 if(pagesetup_get_orientation(data
) == DMORIENT_LANDSCAPE
)
3014 width
= data
->rtDrawRect
.right
- data
->rtDrawRect
.left
;
3015 height
= pagesetup_get_papersize_pt(data
)->y
* width
/ pagesetup_get_papersize_pt(data
)->x
;
3019 height
= data
->rtDrawRect
.bottom
- data
->rtDrawRect
.top
;
3020 width
= pagesetup_get_papersize_pt(data
)->x
* height
/ pagesetup_get_papersize_pt(data
)->y
;
3022 x
= (data
->rtDrawRect
.right
+ data
->rtDrawRect
.left
- width
) / 2;
3023 y
= (data
->rtDrawRect
.bottom
+ data
->rtDrawRect
.top
- height
) / 2;
3024 TRACE("draw rect %s x=%d, y=%d, w=%d, h=%d\n",
3025 wine_dbgstr_rect(&data
->rtDrawRect
), x
, y
, width
, height
);
3027 MoveWindow(GetDlgItem(data
->hDlg
, rct2
), x
+ width
, y
+ shadow
, shadow
, height
, FALSE
);
3028 MoveWindow(GetDlgItem(data
->hDlg
, rct3
), x
+ shadow
, y
+ height
, width
, shadow
, FALSE
);
3029 MoveWindow(GetDlgItem(data
->hDlg
, rct1
), x
, y
, width
, height
, FALSE
);
3031 tmp
= data
->rtDrawRect
;
3032 tmp
.right
+= shadow
;
3033 tmp
.bottom
+= shadow
;
3034 InvalidateRect(data
->hDlg
, &tmp
, TRUE
);
3037 static inline LONG
*element_from_margin_id(RECT
*rc
, WORD id
)
3041 case edt4
: return &rc
->left
;
3042 case edt5
: return &rc
->top
;
3043 case edt6
: return &rc
->right
;
3044 case edt7
: return &rc
->bottom
;
3049 static void update_margin_edits(HWND hDlg
, const pagesetup_data
*data
, WORD id
)
3054 for(idx
= edt4
; idx
<= edt7
; idx
++)
3056 if(id
== 0 || id
== idx
)
3058 size2str(data
, *element_from_margin_id(pagesetup_get_margin_rect(data
), idx
), str
);
3059 SetDlgItemTextW(hDlg
, idx
, str
);
3064 static void margin_edit_notification(HWND hDlg
, const pagesetup_data
*data
, WORD msg
, WORD id
)
3072 LONG
*value
= element_from_margin_id(pagesetup_get_margin_rect(data
), id
);
3074 if (GetDlgItemTextW(hDlg
, id
, buf
, sizeof(buf
) / sizeof(buf
[0])) != 0)
3077 WCHAR decimal
= get_decimal_sep();
3079 val
= strtolW(buf
, &end
, 10);
3080 if(end
!= buf
|| *end
== decimal
)
3082 int mult
= is_metric(data
) ? 100 : 1000;
3091 val
+= (*end
- '0') * mult
;
3103 update_margin_edits(hDlg
, data
, id
);
3108 static void set_margin_groupbox_title(HWND hDlg
, const pagesetup_data
*data
)
3112 if(LoadStringW(COMDLG32_hInstance
, is_metric(data
) ? PD32_MARGINS_IN_MILLIMETERS
: PD32_MARGINS_IN_INCHES
,
3113 title
, sizeof(title
)/sizeof(title
[0])))
3114 SetDlgItemTextW(hDlg
, grp4
, title
);
3117 static void pagesetup_update_orientation_buttons(HWND hDlg
, const pagesetup_data
*data
)
3119 if (pagesetup_get_orientation(data
) == DMORIENT_LANDSCAPE
)
3120 CheckRadioButton(hDlg
, rad1
, rad2
, rad2
);
3122 CheckRadioButton(hDlg
, rad1
, rad2
, rad1
);
3125 /****************************************************************************************
3126 * pagesetup_printer_properties
3128 * Handle invocation of the 'Properties' button (not present in the default template).
3130 static void pagesetup_printer_properties(HWND hDlg
, pagesetup_data
*data
)
3138 devname
= pagesetup_get_devname(data
);
3140 if (!OpenPrinterW(devname
, &hprn
, NULL
))
3142 FIXME("Call to OpenPrinter did not succeed!\n");
3143 pagesetup_release_a_devname(data
, devname
);
3147 dm
= pagesetup_get_devmode(data
);
3148 DocumentPropertiesW(hDlg
, hprn
, devname
, dm
, dm
, DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
3149 pagesetup_set_devmode(data
, dm
);
3150 pagesetup_release_devmode(data
, dm
);
3151 pagesetup_release_a_devname(data
, devname
);
3154 /* Changing paper */
3155 pagesetup_update_papersize(data
);
3156 pagesetup_update_orientation_buttons(hDlg
, data
);
3158 /* Changing paper preview */
3159 pagesetup_change_preview(data
);
3161 /* Selecting paper in combo */
3162 count
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCOUNT
, 0, 0);
3165 WORD paperword
= pagesetup_get_papersize(data
);
3166 for(i
= 0; i
< count
; i
++)
3168 if(SendDlgItemMessageW(hDlg
, cmb2
, CB_GETITEMDATA
, i
, 0) == paperword
) {
3169 SendDlgItemMessageW(hDlg
, cmb2
, CB_SETCURSEL
, i
, 0);
3176 /********************************************************************************
3177 * pagesetup_wm_command
3178 * process WM_COMMAND message for PageSetupDlg
3181 * hDlg [in] Main dialog HANDLE
3182 * wParam [in] WM_COMMAND wParam
3183 * lParam [in] WM_COMMAND lParam
3184 * pda [in/out] ptr to PageSetupDataA
3187 static BOOL
pagesetup_wm_command(HWND hDlg
, WPARAM wParam
, LPARAM lParam
, pagesetup_data
*data
)
3189 WORD msg
= HIWORD(wParam
);
3190 WORD id
= LOWORD(wParam
);
3192 TRACE("loword (lparam) %d, wparam 0x%lx, lparam %08lx\n",
3193 LOWORD(lParam
),wParam
,lParam
);
3196 EndDialog(hDlg
, TRUE
);
3200 EndDialog(hDlg
, FALSE
);
3203 case psh3
: /* Printer... */
3204 pagesetup_change_printer_dialog(hDlg
, data
);
3207 case rad1
: /* Portrait */
3208 case rad2
: /* Landscape */
3209 if((id
== rad1
&& pagesetup_get_orientation(data
) == DMORIENT_LANDSCAPE
) ||
3210 (id
== rad2
&& pagesetup_get_orientation(data
) == DMORIENT_PORTRAIT
))
3212 pagesetup_set_orientation(data
, (id
== rad1
) ? DMORIENT_PORTRAIT
: DMORIENT_LANDSCAPE
);
3213 pagesetup_update_papersize(data
);
3214 rotate_rect(pagesetup_get_margin_rect(data
), (id
== rad2
));
3215 update_margin_edits(hDlg
, data
, 0);
3216 pagesetup_change_preview(data
);
3219 case cmb1
: /* Printer combo */
3220 if(msg
== CBN_SELCHANGE
)
3223 GetDlgItemTextW(hDlg
, id
, name
, sizeof(name
) / sizeof(name
[0]));
3224 pagesetup_change_printer(name
, data
);
3225 pagesetup_init_combos(hDlg
, data
);
3228 case cmb2
: /* Paper combo */
3229 if(msg
== CBN_SELCHANGE
)
3231 DWORD paperword
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETITEMDATA
,
3232 SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0), 0);
3233 if (paperword
!= CB_ERR
)
3235 pagesetup_set_papersize(data
, paperword
);
3236 pagesetup_update_papersize(data
);
3237 pagesetup_change_preview(data
);
3239 FIXME("could not get dialog text for papersize cmbbox?\n");
3242 case cmb3
: /* Paper Source */
3243 if(msg
== CBN_SELCHANGE
)
3245 WORD source
= SendDlgItemMessageW(hDlg
, cmb3
, CB_GETITEMDATA
,
3246 SendDlgItemMessageW(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0), 0);
3247 pagesetup_set_defaultsource(data
, source
);
3250 case psh2
: /* Printer Properties button */
3251 pagesetup_printer_properties(hDlg
, data
);
3257 margin_edit_notification(hDlg
, data
, msg
, id
);
3260 InvalidateRect(GetDlgItem(hDlg
, rct1
), NULL
, TRUE
);
3264 /***********************************************************************
3265 * default_page_paint_hook
3266 * Default hook paint procedure that receives WM_PSD_* messages from the dialog box
3267 * whenever the sample page is redrawn.
3269 static UINT_PTR
default_page_paint_hook(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
,
3270 const pagesetup_data
*data
)
3272 LPRECT lprc
= (LPRECT
) lParam
;
3273 HDC hdc
= (HDC
) wParam
;
3276 HFONT hfont
, holdfont
;
3278 TRACE("uMsg: WM_USER+%d\n",uMsg
-WM_USER
);
3279 /* Call user paint hook if enable */
3280 if (pagesetup_get_flags(data
) & PSD_ENABLEPAGEPAINTHOOK
)
3281 if (pagesetup_get_hook(data
, page_paint_hook
)(hwndDlg
, uMsg
, wParam
, lParam
))
3285 /* LPPAGESETUPDLG in lParam */
3286 case WM_PSD_PAGESETUPDLG
:
3287 /* Inform about the sample page rectangle */
3288 case WM_PSD_FULLPAGERECT
:
3289 /* Inform about the margin rectangle */
3290 case WM_PSD_MINMARGINRECT
:
3293 /* Draw dashed rectangle showing margins */
3294 case WM_PSD_MARGINRECT
:
3295 hpen
= CreatePen(PS_DASH
, 1, GetSysColor(COLOR_3DSHADOW
));
3296 holdpen
= SelectObject(hdc
, hpen
);
3297 Rectangle(hdc
, lprc
->left
, lprc
->top
, lprc
->right
, lprc
->bottom
);
3298 DeleteObject(SelectObject(hdc
, holdpen
));
3300 /* Draw the fake document */
3301 case WM_PSD_GREEKTEXTRECT
:
3302 /* select a nice scalable font, because we want the text really small */
3303 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, sizeof(lf
), &lf
, 0);
3304 lf
.lfHeight
= 6; /* value chosen based on visual effect */
3305 hfont
= CreateFontIndirectW(&lf
);
3306 holdfont
= SelectObject(hdc
, hfont
);
3308 /* if text not loaded, then do so now */
3309 if (wszFakeDocumentText
[0] == '\0')
3310 LoadStringW(COMDLG32_hInstance
,
3312 wszFakeDocumentText
,
3313 sizeof(wszFakeDocumentText
)/sizeof(wszFakeDocumentText
[0]));
3315 oldbkmode
= SetBkMode(hdc
, TRANSPARENT
);
3316 DrawTextW(hdc
, wszFakeDocumentText
, -1, lprc
, DT_TOP
|DT_LEFT
|DT_NOPREFIX
|DT_WORDBREAK
);
3317 SetBkMode(hdc
, oldbkmode
);
3319 DeleteObject(SelectObject(hdc
, holdfont
));
3322 /* Envelope stamp */
3323 case WM_PSD_ENVSTAMPRECT
:
3324 /* Return address */
3325 case WM_PSD_YAFULLPAGERECT
:
3326 FIXME("envelope/stamp is not implemented\n");
3329 FIXME("Unknown message %x\n",uMsg
);
3335 /***********************************************************************
3337 * The main paint procedure for the PageSetupDlg function.
3338 * The Page Setup dialog box includes an image of a sample page that shows how
3339 * the user's selections affect the appearance of the printed output.
3340 * The image consists of a rectangle that represents the selected paper
3341 * or envelope type, with a dotted-line rectangle representing
3342 * the current margins, and partial (Greek text) characters
3343 * to show how text looks on the printed page.
3345 * The following messages in the order sends to user hook procedure:
3346 * WM_PSD_PAGESETUPDLG Draw the contents of the sample page
3347 * WM_PSD_FULLPAGERECT Inform about the bounding rectangle
3348 * WM_PSD_MINMARGINRECT Inform about the margin rectangle (min margin?)
3349 * WM_PSD_MARGINRECT Draw the margin rectangle
3350 * WM_PSD_GREEKTEXTRECT Draw the Greek text inside the margin rectangle
3351 * If any of first three messages returns TRUE, painting done.
3354 * hWnd [in] Handle to the Page Setup dialog box
3355 * uMsg [in] Received message
3358 * WM_PSD_ENVSTAMPRECT Draw in the envelope-stamp rectangle (for envelopes only)
3359 * WM_PSD_YAFULLPAGERECT Draw the return address portion (for envelopes and other paper sizes)
3362 * FALSE if all done correctly
3367 static LRESULT CALLBACK
3368 PRINTDLG_PagePaintProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3371 RECT rcClient
, rcMargin
;
3374 HBRUSH hbrush
, holdbrush
;
3375 pagesetup_data
*data
;
3376 int papersize
=0, orientation
=0; /* FIXME: set these values for the user paint hook */
3377 double scalx
, scaly
;
3379 if (uMsg
!= WM_PAINT
)
3380 return CallWindowProcA(lpfnStaticWndProc
, hWnd
, uMsg
, wParam
, lParam
);
3382 /* Processing WM_PAINT message */
3383 data
= GetPropW(hWnd
, pagesetupdlg_prop
);
3385 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3388 if (default_page_paint_hook(hWnd
, WM_PSD_PAGESETUPDLG
, MAKELONG(papersize
, orientation
),
3389 pagesetup_get_dlg_struct(data
), data
))
3392 hdc
= BeginPaint(hWnd
, &ps
);
3393 GetClientRect(hWnd
, &rcClient
);
3395 scalx
= rcClient
.right
/ (double)pagesetup_get_papersize_pt(data
)->x
;
3396 scaly
= rcClient
.bottom
/ (double)pagesetup_get_papersize_pt(data
)->y
;
3397 rcMargin
= rcClient
;
3399 rcMargin
.left
+= pagesetup_get_margin_rect(data
)->left
* scalx
;
3400 rcMargin
.top
+= pagesetup_get_margin_rect(data
)->top
* scaly
;
3401 rcMargin
.right
-= pagesetup_get_margin_rect(data
)->right
* scalx
;
3402 rcMargin
.bottom
-= pagesetup_get_margin_rect(data
)->bottom
* scaly
;
3404 /* if the space is too small then we make sure to not draw anything */
3405 rcMargin
.left
= min(rcMargin
.left
, rcMargin
.right
);
3406 rcMargin
.top
= min(rcMargin
.top
, rcMargin
.bottom
);
3408 if (!default_page_paint_hook(hWnd
, WM_PSD_FULLPAGERECT
, (WPARAM
)hdc
, (LPARAM
)&rcClient
, data
) &&
3409 !default_page_paint_hook(hWnd
, WM_PSD_MINMARGINRECT
, (WPARAM
)hdc
, (LPARAM
)&rcMargin
, data
) )
3411 /* fill background */
3412 hbrush
= GetSysColorBrush(COLOR_3DHIGHLIGHT
);
3413 FillRect(hdc
, &rcClient
, hbrush
);
3414 holdbrush
= SelectObject(hdc
, hbrush
);
3416 hpen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DSHADOW
));
3417 holdpen
= SelectObject(hdc
, hpen
);
3419 /* paint left edge */
3420 MoveToEx(hdc
, rcClient
.left
, rcClient
.top
, NULL
);
3421 LineTo(hdc
, rcClient
.left
, rcClient
.bottom
-1);
3423 /* paint top edge */
3424 MoveToEx(hdc
, rcClient
.left
, rcClient
.top
, NULL
);
3425 LineTo(hdc
, rcClient
.right
, rcClient
.top
);
3427 hpen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DDKSHADOW
));
3428 DeleteObject(SelectObject(hdc
, hpen
));
3430 /* paint right edge */
3431 MoveToEx(hdc
, rcClient
.right
-1, rcClient
.top
, NULL
);
3432 LineTo(hdc
, rcClient
.right
-1, rcClient
.bottom
);
3434 /* paint bottom edge */
3435 MoveToEx(hdc
, rcClient
.left
, rcClient
.bottom
-1, NULL
);
3436 LineTo(hdc
, rcClient
.right
, rcClient
.bottom
-1);
3438 DeleteObject(SelectObject(hdc
, holdpen
));
3439 DeleteObject(SelectObject(hdc
, holdbrush
));
3441 default_page_paint_hook(hWnd
, WM_PSD_MARGINRECT
, (WPARAM
)hdc
, (LPARAM
)&rcMargin
, data
);
3443 /* give text a bit of a space from the frame */
3446 rcMargin
.right
-= 2;
3447 rcMargin
.bottom
-= 2;
3449 /* if the space is too small then we make sure to not draw anything */
3450 rcMargin
.left
= min(rcMargin
.left
, rcMargin
.right
);
3451 rcMargin
.top
= min(rcMargin
.top
, rcMargin
.bottom
);
3453 default_page_paint_hook(hWnd
, WM_PSD_GREEKTEXTRECT
, (WPARAM
)hdc
, (LPARAM
)&rcMargin
, data
);
3456 EndPaint(hWnd
, &ps
);
3460 /*******************************************************
3461 * The margin edit controls are subclassed to filter
3462 * anything other than numbers and the decimal separator.
3464 static LRESULT CALLBACK
pagesetup_margin_editproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3468 WCHAR decimal
= get_decimal_sep();
3469 WCHAR wc
= (WCHAR
)wparam
;
3470 if(!isdigitW(wc
) && wc
!= decimal
&& wc
!= VK_BACK
) return 0;
3472 return CallWindowProcW(edit_wndproc
, hwnd
, msg
, wparam
, lparam
);
3475 static void subclass_margin_edits(HWND hDlg
)
3480 for(id
= edt4
; id
<= edt7
; id
++)
3482 old_proc
= (WNDPROC
)SetWindowLongPtrW(GetDlgItem(hDlg
, id
),
3484 (ULONG_PTR
)pagesetup_margin_editproc
);
3485 InterlockedCompareExchangePointer((void**)&edit_wndproc
, old_proc
, NULL
);
3489 /***********************************************************************
3490 * pagesetup_dlg_proc
3492 * Message handler for PageSetupDlg
3494 static INT_PTR CALLBACK
pagesetup_dlg_proc(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3496 pagesetup_data
*data
;
3497 INT_PTR res
= FALSE
;
3500 if (uMsg
== WM_INITDIALOG
) { /*Init dialog*/
3501 data
= (pagesetup_data
*)lParam
;
3504 hDrawWnd
= GetDlgItem(hDlg
, rct1
);
3505 TRACE("set property to %p\n", data
);
3506 SetPropW(hDlg
, pagesetupdlg_prop
, data
);
3507 SetPropW(hDrawWnd
, pagesetupdlg_prop
, data
);
3508 GetWindowRect(hDrawWnd
, &data
->rtDrawRect
); /* Calculating rect in client coordinates where paper draws */
3509 MapWindowPoints( 0, hDlg
, (LPPOINT
)&data
->rtDrawRect
, 2 );
3510 lpfnStaticWndProc
= (WNDPROC
)SetWindowLongPtrW(
3513 (ULONG_PTR
)PRINTDLG_PagePaintProc
);
3515 /* FIXME: Paint hook. Must it be at begin of initialization or at end? */
3517 if (pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPHOOK
)
3519 if (!pagesetup_get_hook(data
, page_setup_hook
)(hDlg
, uMsg
, wParam
,
3520 pagesetup_get_dlg_struct(data
)))
3521 FIXME("Setup page hook failed?\n");
3524 /* if printer button disabled */
3525 if (pagesetup_get_flags(data
) & PSD_DISABLEPRINTER
)
3526 EnableWindow(GetDlgItem(hDlg
, psh3
), FALSE
);
3527 /* if margin edit boxes disabled */
3528 if (pagesetup_get_flags(data
) & PSD_DISABLEMARGINS
)
3530 EnableWindow(GetDlgItem(hDlg
, edt4
), FALSE
);
3531 EnableWindow(GetDlgItem(hDlg
, edt5
), FALSE
);
3532 EnableWindow(GetDlgItem(hDlg
, edt6
), FALSE
);
3533 EnableWindow(GetDlgItem(hDlg
, edt7
), FALSE
);
3536 /* Set orientation radiobuttons properly */
3537 pagesetup_update_orientation_buttons(hDlg
, data
);
3539 /* if orientation disabled */
3540 if (pagesetup_get_flags(data
) & PSD_DISABLEORIENTATION
)
3542 EnableWindow(GetDlgItem(hDlg
,rad1
),FALSE
);
3543 EnableWindow(GetDlgItem(hDlg
,rad2
),FALSE
);
3546 /* We fill them out enabled or not */
3547 if (!(pagesetup_get_flags(data
) & PSD_MARGINS
))
3549 /* default is 1 inch */
3550 LONG size
= thousandths_inch_to_size(data
, 1000);
3551 SetRect(pagesetup_get_margin_rect(data
), size
, size
, size
, size
);
3553 update_margin_edits(hDlg
, data
, 0);
3554 subclass_margin_edits(hDlg
);
3555 set_margin_groupbox_title(hDlg
, data
);
3557 /* if paper disabled */
3558 if (pagesetup_get_flags(data
) & PSD_DISABLEPAPER
)
3560 EnableWindow(GetDlgItem(hDlg
,cmb2
),FALSE
);
3561 EnableWindow(GetDlgItem(hDlg
,cmb3
),FALSE
);
3564 /* filling combos: printer, paper, source. selecting current printer (from DEVMODEA) */
3565 pagesetup_init_combos(hDlg
, data
);
3566 pagesetup_update_papersize(data
);
3567 pagesetup_set_defaultsource(data
, DMBIN_FORMSOURCE
); /* FIXME: This is the auto select bin. Is this correct? */
3569 /* Drawing paper prev */
3570 pagesetup_change_preview(data
);
3573 data
= GetPropW(hDlg
, pagesetupdlg_prop
);
3576 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3579 if (pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPHOOK
)
3581 res
= pagesetup_get_hook(data
, page_setup_hook
)(hDlg
, uMsg
, wParam
, lParam
);
3582 if (res
) return res
;
3587 return pagesetup_wm_command(hDlg
, wParam
, lParam
, data
);
3592 static WCHAR
*get_default_printer(void)
3597 GetDefaultPrinterW(NULL
, &len
);
3600 name
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3601 GetDefaultPrinterW(name
, &len
);
3606 static void pagesetup_dump_dlg_struct(const pagesetup_data
*data
)
3608 if(TRACE_ON(commdlg
))
3610 char flagstr
[1000] = "";
3611 const struct pd_flags
*pflag
= psd_flags
;
3612 for( ; pflag
->name
; pflag
++)
3614 if(pagesetup_get_flags(data
) & pflag
->flag
)
3616 strcat(flagstr
, pflag
->name
);
3617 strcat(flagstr
, "|");
3620 TRACE("%s: (%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3621 "hinst %p, flags %08x (%s)\n",
3622 data
->unicode
? "unicode" : "ansi",
3623 data
->u
.dlgw
, data
->u
.dlgw
->hwndOwner
, data
->u
.dlgw
->hDevMode
,
3624 data
->u
.dlgw
->hDevNames
, data
->u
.dlgw
->hInstance
,
3625 pagesetup_get_flags(data
), flagstr
);
3629 static void *pagesetup_get_template(pagesetup_data
*data
)
3632 HGLOBAL tmpl_handle
;
3634 if(pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPTEMPLATEHANDLE
)
3636 tmpl_handle
= data
->u
.dlgw
->hPageSetupTemplate
;
3638 else if(pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPTEMPLATE
)
3641 res
= FindResourceW(data
->u
.dlgw
->hInstance
,
3642 data
->u
.dlgw
->lpPageSetupTemplateName
, MAKEINTRESOURCEW(RT_DIALOG
));
3644 res
= FindResourceA(data
->u
.dlga
->hInstance
,
3645 data
->u
.dlga
->lpPageSetupTemplateName
, MAKEINTRESOURCEA(RT_DIALOG
));
3646 tmpl_handle
= LoadResource(data
->u
.dlgw
->hInstance
, res
);
3650 res
= FindResourceW(COMDLG32_hInstance
, MAKEINTRESOURCEW(PAGESETUPDLGORD
),
3651 MAKEINTRESOURCEW(RT_DIALOG
));
3652 tmpl_handle
= LoadResource(COMDLG32_hInstance
, res
);
3654 return LockResource(tmpl_handle
);
3657 static BOOL
pagesetup_common(pagesetup_data
*data
)
3662 if(!pagesetup_get_dlg_struct(data
))
3664 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
3668 pagesetup_dump_dlg_struct(data
);
3670 if(data
->u
.dlgw
->lStructSize
!= sizeof(PAGESETUPDLGW
))
3672 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
3676 if ((pagesetup_get_flags(data
) & PSD_ENABLEPAGEPAINTHOOK
) &&
3677 (pagesetup_get_hook(data
, page_paint_hook
) == NULL
))
3679 COMDLG32_SetCommDlgExtendedError(CDERR_NOHOOK
);
3683 if(!(pagesetup_get_flags(data
) & (PSD_INTHOUSANDTHSOFINCHES
| PSD_INHUNDREDTHSOFMILLIMETERS
)))
3684 data
->u
.dlgw
->Flags
|= is_default_metric() ?
3685 PSD_INHUNDREDTHSOFMILLIMETERS
: PSD_INTHOUSANDTHSOFINCHES
;
3687 if (!data
->u
.dlgw
->hDevMode
|| !data
->u
.dlgw
->hDevNames
)
3689 WCHAR
*def
= get_default_printer();
3692 if (!(pagesetup_get_flags(data
) & PSD_NOWARNING
))
3695 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEFAULT_PRINTER
, errstr
, 255);
3696 MessageBoxW(data
->u
.dlgw
->hwndOwner
, errstr
, 0, MB_OK
| MB_ICONERROR
);
3698 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
3701 pagesetup_change_printer(def
, data
);
3702 HeapFree(GetProcessHeap(), 0, def
);
3705 if (pagesetup_get_flags(data
) & PSD_RETURNDEFAULT
)
3707 pagesetup_update_papersize(data
);
3711 tmpl
= pagesetup_get_template(data
);
3713 ret
= DialogBoxIndirectParamW(data
->u
.dlgw
->hInstance
, tmpl
,
3714 data
->u
.dlgw
->hwndOwner
,
3715 pagesetup_dlg_proc
, (LPARAM
)data
) > 0;
3719 /***********************************************************************
3720 * PageSetupDlgA (COMDLG32.@)
3722 * Displays the PAGE SETUP dialog box, which enables the user to specify
3723 * specific properties of a printed page such as
3724 * size, source, orientation and the width of the page margins.
3727 * setupdlg [IO] PAGESETUPDLGA struct
3730 * TRUE if the user pressed the OK button
3731 * FALSE if the user cancelled the window or an error occurred
3734 * The values of hDevMode and hDevNames are filled on output and can be
3735 * changed in PAGESETUPDLG when they are passed in PageSetupDlg.
3738 BOOL WINAPI
PageSetupDlgA(LPPAGESETUPDLGA setupdlg
)
3740 pagesetup_data data
;
3742 data
.unicode
= FALSE
;
3743 data
.u
.dlga
= setupdlg
;
3745 return pagesetup_common(&data
);
3748 /***********************************************************************
3749 * PageSetupDlgW (COMDLG32.@)
3751 * See PageSetupDlgA.
3753 BOOL WINAPI
PageSetupDlgW(LPPAGESETUPDLGW setupdlg
)
3755 pagesetup_data data
;
3757 data
.unicode
= TRUE
;
3758 data
.u
.dlgw
= setupdlg
;
3760 return pagesetup_common(&data
);
3763 /***********************************************************************
3764 * PrintDlgExA (COMDLG32.@)
3772 HRESULT WINAPI
PrintDlgExA(LPPRINTDLGEXA lppd
)
3777 FIXME("(%p) not fully implemented\n", lppd
);
3778 if ((lppd
== NULL
) || (lppd
->lStructSize
!= sizeof(PRINTDLGEXA
)))
3779 return E_INVALIDARG
;
3781 if (!IsWindow(lppd
->hwndOwner
))
3784 if (lppd
->Flags
& PD_RETURNDEFAULT
)
3786 PRINTER_INFO_2A
*pbuf
;
3787 DRIVER_INFO_2A
*dbuf
;
3789 DWORD needed
= 1024;
3792 if (lppd
->hDevMode
|| lppd
->hDevNames
)
3794 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
3795 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
3796 return E_INVALIDARG
;
3798 if (!PRINTDLG_OpenDefaultPrinter(&hprn
))
3800 WARN("Can't find default printer\n");
3801 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
3805 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
3806 bRet
= GetPrinterA(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
3807 if (!bRet
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
3809 HeapFree(GetProcessHeap(), 0, pbuf
);
3810 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
3811 bRet
= GetPrinterA(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
3815 HeapFree(GetProcessHeap(), 0, pbuf
);
3821 dbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
3822 bRet
= GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
);
3823 if (!bRet
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
3825 HeapFree(GetProcessHeap(), 0, dbuf
);
3826 dbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
3827 bRet
= GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
);
3831 ERR("GetPrinterDriverŠ failed, last error %d, fix your config for printer %s!\n",
3832 GetLastError(), pbuf
->pPrinterName
);
3833 HeapFree(GetProcessHeap(), 0, dbuf
);
3834 HeapFree(GetProcessHeap(), 0, pbuf
);
3835 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
3841 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
3845 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
3846 pbuf
->pDevMode
->dmDriverExtra
);
3849 ptr
= GlobalLock(lppd
->hDevMode
);
3852 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
3853 pbuf
->pDevMode
->dmDriverExtra
);
3854 GlobalUnlock(lppd
->hDevMode
);
3858 HeapFree(GetProcessHeap(), 0, pbuf
);
3859 HeapFree(GetProcessHeap(), 0, dbuf
);
3867 /***********************************************************************
3868 * PrintDlgExW (COMDLG32.@)
3870 * Display the property sheet style PRINT dialog box
3873 * lppd [IO] ptr to PRINTDLGEX struct
3877 * Failure: One of the following COM error codes:
3878 * E_OUTOFMEMORY Insufficient memory.
3879 * E_INVALIDARG One or more arguments are invalid.
3880 * E_POINTER Invalid pointer.
3881 * E_HANDLE Invalid handle.
3882 * E_FAIL Unspecified error.
3885 * This Dialog enables the user to specify specific properties of the print job.
3886 * The property sheet can also have additional application-specific and
3887 * driver-specific property pages.
3890 * Not fully implemented
3893 HRESULT WINAPI
PrintDlgExW(LPPRINTDLGEXW lppd
)
3898 FIXME("(%p) not fully implemented\n", lppd
);
3900 if ((lppd
== NULL
) || (lppd
->lStructSize
!= sizeof(PRINTDLGEXW
))) {
3901 return E_INVALIDARG
;
3904 if (!IsWindow(lppd
->hwndOwner
)) {
3908 if (lppd
->Flags
& PD_RETURNDEFAULT
) {
3909 PRINTER_INFO_2W
*pbuf
;
3910 DRIVER_INFO_2W
*dbuf
;
3912 DWORD needed
= 1024;
3915 if (lppd
->hDevMode
|| lppd
->hDevNames
) {
3916 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
3917 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
3918 return E_INVALIDARG
;
3920 if (!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
3921 WARN("Can't find default printer\n");
3922 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
3926 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
3927 bRet
= GetPrinterW(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
3928 if (!bRet
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
3929 HeapFree(GetProcessHeap(), 0, pbuf
);
3930 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
3931 bRet
= GetPrinterW(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
3934 HeapFree(GetProcessHeap(), 0, pbuf
);
3940 dbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
3941 bRet
= GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
);
3942 if (!bRet
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
3943 HeapFree(GetProcessHeap(), 0, dbuf
);
3944 dbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
3945 bRet
= GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
);
3948 ERR("GetPrinterDriverW failed, last error %d, fix your config for printer %s!\n",
3949 GetLastError(), debugstr_w(pbuf
->pPrinterName
));
3950 HeapFree(GetProcessHeap(), 0, dbuf
);
3951 HeapFree(GetProcessHeap(), 0, pbuf
);
3952 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
3958 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
3962 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
3963 pbuf
->pDevMode
->dmDriverExtra
);
3964 if (lppd
->hDevMode
) {
3965 ptr
= GlobalLock(lppd
->hDevMode
);
3967 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
3968 pbuf
->pDevMode
->dmDriverExtra
);
3969 GlobalUnlock(lppd
->hDevMode
);
3973 HeapFree(GetProcessHeap(), 0, pbuf
);
3974 HeapFree(GetProcessHeap(), 0, dbuf
);