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
31 #define NONAMELESSUNION
32 #define NONAMELESSSTRUCT
40 #include "wine/unicode.h"
41 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(commdlg
);
50 /* Yes these constants are the same, but we're just copying win98 */
51 #define UPDOWN_ID 0x270f
52 #define MAX_COPIES 9999
54 /* This PRINTDLGA internal structure stores
55 * pointers to several throughout useful structures.
61 LPPRINTDLGA lpPrintDlg
;
62 LPPRINTER_INFO_2A lpPrinterInfo
;
63 LPDRIVER_INFO_3A lpDriverInfo
;
65 HICON hCollateIcon
; /* PrintDlg only */
66 HICON hNoCollateIcon
; /* PrintDlg only */
67 HICON hPortraitIcon
; /* PrintSetupDlg only */
68 HICON hLandscapeIcon
; /* PrintSetupDlg only */
75 LPPRINTDLGW lpPrintDlg
;
76 LPPRINTER_INFO_2W lpPrinterInfo
;
77 LPDRIVER_INFO_3W lpDriverInfo
;
79 HICON hCollateIcon
; /* PrintDlg only */
80 HICON hNoCollateIcon
; /* PrintDlg only */
81 HICON hPortraitIcon
; /* PrintSetupDlg only */
82 HICON hLandscapeIcon
; /* PrintSetupDlg only */
93 static const struct pd_flags psd_flags
[] = {
94 {PSD_MINMARGINS
,"PSD_MINMARGINS"},
95 {PSD_MARGINS
,"PSD_MARGINS"},
96 {PSD_INTHOUSANDTHSOFINCHES
,"PSD_INTHOUSANDTHSOFINCHES"},
97 {PSD_INHUNDREDTHSOFMILLIMETERS
,"PSD_INHUNDREDTHSOFMILLIMETERS"},
98 {PSD_DISABLEMARGINS
,"PSD_DISABLEMARGINS"},
99 {PSD_DISABLEPRINTER
,"PSD_DISABLEPRINTER"},
100 {PSD_NOWARNING
,"PSD_NOWARNING"},
101 {PSD_DISABLEORIENTATION
,"PSD_DISABLEORIENTATION"},
102 {PSD_RETURNDEFAULT
,"PSD_RETURNDEFAULT"},
103 {PSD_DISABLEPAPER
,"PSD_DISABLEPAPER"},
104 {PSD_SHOWHELP
,"PSD_SHOWHELP"},
105 {PSD_ENABLEPAGESETUPHOOK
,"PSD_ENABLEPAGESETUPHOOK"},
106 {PSD_ENABLEPAGESETUPTEMPLATE
,"PSD_ENABLEPAGESETUPTEMPLATE"},
107 {PSD_ENABLEPAGESETUPTEMPLATEHANDLE
,"PSD_ENABLEPAGESETUPTEMPLATEHANDLE"},
108 {PSD_ENABLEPAGEPAINTHOOK
,"PSD_ENABLEPAGEPAINTHOOK"},
109 {PSD_DISABLEPAGEPAINTING
,"PSD_DISABLEPAGEPAINTING"},
113 static const struct pd_flags pd_flags
[] = {
114 {PD_SELECTION
, "PD_SELECTION "},
115 {PD_PAGENUMS
, "PD_PAGENUMS "},
116 {PD_NOSELECTION
, "PD_NOSELECTION "},
117 {PD_NOPAGENUMS
, "PD_NOPAGENUMS "},
118 {PD_COLLATE
, "PD_COLLATE "},
119 {PD_PRINTTOFILE
, "PD_PRINTTOFILE "},
120 {PD_PRINTSETUP
, "PD_PRINTSETUP "},
121 {PD_NOWARNING
, "PD_NOWARNING "},
122 {PD_RETURNDC
, "PD_RETURNDC "},
123 {PD_RETURNIC
, "PD_RETURNIC "},
124 {PD_RETURNDEFAULT
, "PD_RETURNDEFAULT "},
125 {PD_SHOWHELP
, "PD_SHOWHELP "},
126 {PD_ENABLEPRINTHOOK
, "PD_ENABLEPRINTHOOK "},
127 {PD_ENABLESETUPHOOK
, "PD_ENABLESETUPHOOK "},
128 {PD_ENABLEPRINTTEMPLATE
, "PD_ENABLEPRINTTEMPLATE "},
129 {PD_ENABLESETUPTEMPLATE
, "PD_ENABLESETUPTEMPLATE "},
130 {PD_ENABLEPRINTTEMPLATEHANDLE
, "PD_ENABLEPRINTTEMPLATEHANDLE "},
131 {PD_ENABLESETUPTEMPLATEHANDLE
, "PD_ENABLESETUPTEMPLATEHANDLE "},
132 {PD_USEDEVMODECOPIES
, "PD_USEDEVMODECOPIES[ANDCOLLATE] "},
133 {PD_DISABLEPRINTTOFILE
, "PD_DISABLEPRINTTOFILE "},
134 {PD_HIDEPRINTTOFILE
, "PD_HIDEPRINTTOFILE "},
135 {PD_NONETWORKBUTTON
, "PD_NONETWORKBUTTON "},
138 /* address of wndproc for subclassed Static control */
139 static WNDPROC lpfnStaticWndProc
;
140 static WNDPROC edit_wndproc
;
141 /* the text of the fake document to render for the Page Setup dialog */
142 static WCHAR wszFakeDocumentText
[1024];
143 static const WCHAR pd32_collateW
[] = { 'P', 'D', '3', '2', '_', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
144 static const WCHAR pd32_nocollateW
[] = { 'P', 'D', '3', '2', '_', 'N', 'O', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
145 static const WCHAR pd32_portraitW
[] = { 'P', 'D', '3', '2', '_', 'P', 'O', 'R', 'T', 'R', 'A', 'I', 'T', 0 };
146 static const WCHAR pd32_landscapeW
[] = { 'P', 'D', '3', '2', '_', 'L', 'A', 'N', 'D', 'S', 'C', 'A', 'P', 'E', 0 };
147 static const WCHAR printdlg_prop
[] = {'_','_','W','I','N','E','_','P','R','I','N','T','D','L','G','D','A','T','A',0};
148 static const WCHAR pagesetupdlg_prop
[] = { '_', '_', 'W', 'I', 'N', 'E', '_', 'P', 'A', 'G', 'E',
149 'S', 'E', 'T', 'U', 'P', 'D', 'L', 'G', 'D', 'A', 'T', 'A', 0 };
152 static LPWSTR
strdupW(LPCWSTR p
)
158 len
= (strlenW(p
) + 1) * sizeof(WCHAR
);
159 ret
= HeapAlloc(GetProcessHeap(), 0, len
);
164 /***********************************************************
165 * convert_to_devmodeA
167 * Creates an ansi copy of supplied devmode
169 static DEVMODEA
*convert_to_devmodeA(const DEVMODEW
*dmW
)
174 if (!dmW
) return NULL
;
175 size
= dmW
->dmSize
- CCHDEVICENAME
-
176 ((dmW
->dmSize
> FIELD_OFFSET(DEVMODEW
, dmFormName
)) ? CCHFORMNAME
: 0);
178 dmA
= HeapAlloc(GetProcessHeap(), 0, size
+ dmW
->dmDriverExtra
);
179 if (!dmA
) return NULL
;
181 WideCharToMultiByte(CP_ACP
, 0, dmW
->dmDeviceName
, -1,
182 (LPSTR
)dmA
->dmDeviceName
, CCHDEVICENAME
, NULL
, NULL
);
184 if (FIELD_OFFSET(DEVMODEW
, dmFormName
) >= dmW
->dmSize
)
186 memcpy(&dmA
->dmSpecVersion
, &dmW
->dmSpecVersion
,
187 dmW
->dmSize
- FIELD_OFFSET(DEVMODEW
, dmSpecVersion
));
191 memcpy(&dmA
->dmSpecVersion
, &dmW
->dmSpecVersion
,
192 FIELD_OFFSET(DEVMODEW
, dmFormName
) - FIELD_OFFSET(DEVMODEW
, dmSpecVersion
));
193 WideCharToMultiByte(CP_ACP
, 0, dmW
->dmFormName
, -1,
194 (LPSTR
)dmA
->dmFormName
, CCHFORMNAME
, NULL
, NULL
);
196 memcpy(&dmA
->dmLogPixels
, &dmW
->dmLogPixels
, dmW
->dmSize
- FIELD_OFFSET(DEVMODEW
, dmLogPixels
));
200 memcpy((char *)dmA
+ dmA
->dmSize
, (const char *)dmW
+ dmW
->dmSize
, dmW
->dmDriverExtra
);
204 /***********************************************************************
205 * PRINTDLG_OpenDefaultPrinter
207 * Returns a winspool printer handle to the default printer in *hprn
208 * Caller must call ClosePrinter on the handle
210 * Returns TRUE on success else FALSE
212 static BOOL
PRINTDLG_OpenDefaultPrinter(HANDLE
*hprn
)
215 DWORD dwBufLen
= sizeof(buf
) / sizeof(buf
[0]);
217 if(!GetDefaultPrinterW(buf
, &dwBufLen
))
219 res
= OpenPrinterW(buf
, hprn
, NULL
);
221 WARN("Could not open printer %s\n", debugstr_w(buf
));
225 /***********************************************************************
226 * PRINTDLG_SetUpPrinterListCombo
228 * Initializes printer list combox.
229 * hDlg: HWND of dialog
230 * id: Control id of combo
231 * name: Name of printer to select
233 * Initializes combo with list of available printers. Selects printer 'name'
234 * If name is NULL or does not exist select the default printer.
236 * Returns number of printers added to list.
238 static INT
PRINTDLG_SetUpPrinterListComboA(HWND hDlg
, UINT id
, LPCSTR name
)
242 LPPRINTER_INFO_2A pi
;
243 EnumPrintersA(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
244 pi
= HeapAlloc(GetProcessHeap(), 0, needed
);
245 EnumPrintersA(PRINTER_ENUM_LOCAL
, NULL
, 2, (LPBYTE
)pi
, needed
, &needed
,
248 SendDlgItemMessageA(hDlg
, id
, CB_RESETCONTENT
, 0, 0);
250 for(i
= 0; i
< num
; i
++) {
251 SendDlgItemMessageA(hDlg
, id
, CB_ADDSTRING
, 0,
252 (LPARAM
)pi
[i
].pPrinterName
);
254 HeapFree(GetProcessHeap(), 0, pi
);
256 (i
= SendDlgItemMessageA(hDlg
, id
, CB_FINDSTRINGEXACT
, -1,
257 (LPARAM
)name
)) == CB_ERR
) {
260 DWORD dwBufLen
= sizeof(buf
);
262 WARN("Can't find %s in printer list so trying to find default\n",
264 if(!GetDefaultPrinterA(buf
, &dwBufLen
))
266 i
= SendDlgItemMessageA(hDlg
, id
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buf
);
268 FIXME("Can't find default printer in printer list\n");
270 SendDlgItemMessageA(hDlg
, id
, CB_SETCURSEL
, i
, 0);
274 static INT
PRINTDLG_SetUpPrinterListComboW(HWND hDlg
, UINT id
, LPCWSTR name
)
278 LPPRINTER_INFO_2W pi
;
279 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
280 pi
= HeapAlloc(GetProcessHeap(), 0, needed
);
281 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, (LPBYTE
)pi
, needed
, &needed
,
284 for(i
= 0; i
< num
; i
++) {
285 SendDlgItemMessageW(hDlg
, id
, CB_ADDSTRING
, 0,
286 (LPARAM
)pi
[i
].pPrinterName
);
288 HeapFree(GetProcessHeap(), 0, pi
);
290 (i
= SendDlgItemMessageW(hDlg
, id
, CB_FINDSTRINGEXACT
, -1,
291 (LPARAM
)name
)) == CB_ERR
) {
293 DWORD dwBufLen
= sizeof(buf
)/sizeof(buf
[0]);
295 WARN("Can't find %s in printer list so trying to find default\n",
297 if(!GetDefaultPrinterW(buf
, &dwBufLen
))
299 i
= SendDlgItemMessageW(hDlg
, id
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buf
);
301 TRACE("Can't find default printer in printer list\n");
303 SendDlgItemMessageW(hDlg
, id
, CB_SETCURSEL
, i
, 0);
307 /***********************************************************************
308 * PRINTDLG_CreateDevNames [internal]
311 * creates a DevNames structure.
313 * (NB. when we handle unicode the offsets will be in wchars).
315 static BOOL
PRINTDLG_CreateDevNames(HGLOBAL
*hmem
, const char* DeviceDriverName
,
316 const char* DeviceName
, const char* OutputPort
)
319 char* pDevNamesSpace
;
321 LPDEVNAMES lpDevNames
;
323 DWORD dwBufLen
= sizeof(buf
);
325 size
= strlen(DeviceDriverName
) + 1
326 + strlen(DeviceName
) + 1
327 + strlen(OutputPort
) + 1
331 *hmem
= GlobalReAlloc(*hmem
, size
, GMEM_MOVEABLE
);
333 *hmem
= GlobalAlloc(GMEM_MOVEABLE
, size
);
337 pDevNamesSpace
= GlobalLock(*hmem
);
338 lpDevNames
= (LPDEVNAMES
) pDevNamesSpace
;
340 pTempPtr
= pDevNamesSpace
+ sizeof(DEVNAMES
);
341 strcpy(pTempPtr
, DeviceDriverName
);
342 lpDevNames
->wDriverOffset
= pTempPtr
- pDevNamesSpace
;
344 pTempPtr
+= strlen(DeviceDriverName
) + 1;
345 strcpy(pTempPtr
, DeviceName
);
346 lpDevNames
->wDeviceOffset
= pTempPtr
- pDevNamesSpace
;
348 pTempPtr
+= strlen(DeviceName
) + 1;
349 strcpy(pTempPtr
, OutputPort
);
350 lpDevNames
->wOutputOffset
= pTempPtr
- pDevNamesSpace
;
352 GetDefaultPrinterA(buf
, &dwBufLen
);
353 lpDevNames
->wDefault
= (strcmp(buf
, DeviceName
) == 0) ? 1 : 0;
358 static BOOL
PRINTDLG_CreateDevNamesW(HGLOBAL
*hmem
, LPCWSTR DeviceDriverName
,
359 LPCWSTR DeviceName
, LPCWSTR OutputPort
)
362 LPWSTR pDevNamesSpace
;
364 LPDEVNAMES lpDevNames
;
366 DWORD dwBufLen
= sizeof(bufW
) / sizeof(WCHAR
);
368 size
= sizeof(WCHAR
)*lstrlenW(DeviceDriverName
) + 2
369 + sizeof(WCHAR
)*lstrlenW(DeviceName
) + 2
370 + sizeof(WCHAR
)*lstrlenW(OutputPort
) + 2
374 *hmem
= GlobalReAlloc(*hmem
, size
, GMEM_MOVEABLE
);
376 *hmem
= GlobalAlloc(GMEM_MOVEABLE
, size
);
380 pDevNamesSpace
= GlobalLock(*hmem
);
381 lpDevNames
= (LPDEVNAMES
) pDevNamesSpace
;
383 pTempPtr
= (LPWSTR
)((LPDEVNAMES
)pDevNamesSpace
+ 1);
384 lstrcpyW(pTempPtr
, DeviceDriverName
);
385 lpDevNames
->wDriverOffset
= pTempPtr
- pDevNamesSpace
;
387 pTempPtr
+= lstrlenW(DeviceDriverName
) + 1;
388 lstrcpyW(pTempPtr
, DeviceName
);
389 lpDevNames
->wDeviceOffset
= pTempPtr
- pDevNamesSpace
;
391 pTempPtr
+= lstrlenW(DeviceName
) + 1;
392 lstrcpyW(pTempPtr
, OutputPort
);
393 lpDevNames
->wOutputOffset
= pTempPtr
- pDevNamesSpace
;
395 GetDefaultPrinterW(bufW
, &dwBufLen
);
396 lpDevNames
->wDefault
= (lstrcmpW(bufW
, DeviceName
) == 0) ? 1 : 0;
401 /***********************************************************************
402 * PRINTDLG_UpdatePrintDlg [internal]
405 * updates the PrintDlg structure for return values.
408 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
409 * TRUE if successful.
411 static BOOL
PRINTDLG_UpdatePrintDlgA(HWND hDlg
,
412 PRINT_PTRA
* PrintStructures
)
414 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
415 PDEVMODEA lpdm
= PrintStructures
->lpDevMode
;
416 LPPRINTER_INFO_2A pi
= PrintStructures
->lpPrinterInfo
;
420 FIXME("No lpdm ptr?\n");
425 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
426 /* check whether nFromPage and nToPage are within range defined by
427 * nMinPage and nMaxPage
429 if (IsDlgButtonChecked(hDlg
, rad3
) == BST_CHECKED
) { /* Pages */
433 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
434 nToPage
= GetDlgItemInt(hDlg
, edt2
, &translated
, FALSE
);
436 /* if no ToPage value is entered, use the FromPage value */
437 if(!translated
) nToPage
= nFromPage
;
439 if (nFromPage
< lppd
->nMinPage
|| nFromPage
> lppd
->nMaxPage
||
440 nToPage
< lppd
->nMinPage
|| nToPage
> lppd
->nMaxPage
) {
441 WCHAR resourcestr
[256];
442 WCHAR resultstr
[256];
443 LoadStringW(COMDLG32_hInstance
, PD32_INVALID_PAGE_RANGE
, resourcestr
, 255);
444 wsprintfW(resultstr
,resourcestr
, lppd
->nMinPage
, lppd
->nMaxPage
);
445 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
, resourcestr
, 255);
446 MessageBoxW(hDlg
, resultstr
, resourcestr
, MB_OK
| MB_ICONWARNING
);
449 lppd
->nFromPage
= nFromPage
;
450 lppd
->nToPage
= nToPage
;
451 lppd
->Flags
|= PD_PAGENUMS
;
454 lppd
->Flags
&= ~PD_PAGENUMS
;
456 if (IsDlgButtonChecked(hDlg
, rad2
) == BST_CHECKED
) /* Selection */
457 lppd
->Flags
|= PD_SELECTION
;
459 lppd
->Flags
&= ~PD_SELECTION
;
461 if (IsDlgButtonChecked(hDlg
, chx1
) == BST_CHECKED
) {/* Print to file */
462 static char file
[] = "FILE:";
463 lppd
->Flags
|= PD_PRINTTOFILE
;
464 pi
->pPortName
= file
;
467 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
) { /* Collate */
468 FIXME("Collate lppd not yet implemented as output\n");
471 /* set PD_Collate and nCopies */
472 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
473 /* The application doesn't support multiple copies or collate...
475 lppd
->Flags
&= ~PD_COLLATE
;
477 /* if the printer driver supports it... store info there
478 * otherwise no collate & multiple copies !
480 if (lpdm
->dmFields
& DM_COLLATE
)
482 (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
);
483 if (lpdm
->dmFields
& DM_COPIES
)
484 lpdm
->u1
.s1
.dmCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
486 /* Application is responsible for multiple copies */
487 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
488 lppd
->Flags
|= PD_COLLATE
;
490 lppd
->Flags
&= ~PD_COLLATE
;
491 lppd
->nCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
492 /* multiple copies already included in the document. Driver must print only one copy */
493 lpdm
->u1
.s1
.dmCopies
= 1;
496 /* Print quality, PrintDlg16 */
497 if(GetDlgItem(hDlg
, cmb1
))
499 HWND hQuality
= GetDlgItem(hDlg
, cmb1
);
500 int Sel
= SendMessageA(hQuality
, CB_GETCURSEL
, 0, 0);
504 LONG dpi
= SendMessageA(hQuality
, CB_GETITEMDATA
, Sel
, 0);
505 lpdm
->dmFields
|= DM_PRINTQUALITY
| DM_YRESOLUTION
;
506 lpdm
->u1
.s1
.dmPrintQuality
= LOWORD(dpi
);
507 lpdm
->dmYResolution
= HIWORD(dpi
);
514 static BOOL
PRINTDLG_UpdatePrintDlgW(HWND hDlg
,
515 PRINT_PTRW
* PrintStructures
)
517 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
518 PDEVMODEW lpdm
= PrintStructures
->lpDevMode
;
519 LPPRINTER_INFO_2W pi
= PrintStructures
->lpPrinterInfo
;
523 FIXME("No lpdm ptr?\n");
528 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
529 /* check whether nFromPage and nToPage are within range defined by
530 * nMinPage and nMaxPage
532 if (IsDlgButtonChecked(hDlg
, rad3
) == BST_CHECKED
) { /* Pages */
536 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
537 nToPage
= GetDlgItemInt(hDlg
, edt2
, &translated
, FALSE
);
539 /* if no ToPage value is entered, use the FromPage value */
540 if(!translated
) nToPage
= nFromPage
;
542 if (nFromPage
< lppd
->nMinPage
|| nFromPage
> lppd
->nMaxPage
||
543 nToPage
< lppd
->nMinPage
|| nToPage
> lppd
->nMaxPage
) {
544 WCHAR resourcestr
[256];
545 WCHAR resultstr
[256];
546 LoadStringW(COMDLG32_hInstance
, PD32_INVALID_PAGE_RANGE
,
548 wsprintfW(resultstr
,resourcestr
, lppd
->nMinPage
, lppd
->nMaxPage
);
549 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
,
551 MessageBoxW(hDlg
, resultstr
, resourcestr
,
552 MB_OK
| MB_ICONWARNING
);
555 lppd
->nFromPage
= nFromPage
;
556 lppd
->nToPage
= nToPage
;
557 lppd
->Flags
|= PD_PAGENUMS
;
560 lppd
->Flags
&= ~PD_PAGENUMS
;
562 if (IsDlgButtonChecked(hDlg
, rad2
) == BST_CHECKED
) /* Selection */
563 lppd
->Flags
|= PD_SELECTION
;
565 lppd
->Flags
&= ~PD_SELECTION
;
567 if (IsDlgButtonChecked(hDlg
, chx1
) == BST_CHECKED
) {/* Print to file */
568 static WCHAR file
[] = {'F','I','L','E',':',0};
569 lppd
->Flags
|= PD_PRINTTOFILE
;
570 pi
->pPortName
= file
;
573 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
) { /* Collate */
574 FIXME("Collate lppd not yet implemented as output\n");
577 /* set PD_Collate and nCopies */
578 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
579 /* The application doesn't support multiple copies or collate...
581 lppd
->Flags
&= ~PD_COLLATE
;
583 /* if the printer driver supports it... store info there
584 * otherwise no collate & multiple copies !
586 if (lpdm
->dmFields
& DM_COLLATE
)
588 (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
);
589 if (lpdm
->dmFields
& DM_COPIES
)
590 lpdm
->u1
.s1
.dmCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
592 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
593 lppd
->Flags
|= PD_COLLATE
;
595 lppd
->Flags
&= ~PD_COLLATE
;
596 lppd
->nCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
602 /************************************************************************
603 * PRINTDLG_SetUpPaperComboBox
605 * Initialize either the papersize or inputslot combos of the Printer Setup
606 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
607 * We also try to re-select the old selection.
609 static BOOL
PRINTDLG_SetUpPaperComboBoxA(HWND hDlg
,
620 WORD oldWord
= 0, newWord
= 0; /* DMPAPER_ and DMBIN_ start at 1 */
622 int fwCapability_Names
;
623 int fwCapability_Words
;
625 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName
,PortName
,nIDComboBox
);
627 /* query the dialog box for the current selected value */
628 Sel
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETCURSEL
, 0, 0);
630 /* we enter here only if a different printer is selected after
631 * the Print Setup dialog is opened. The current settings are
632 * stored into the newly selected printer.
634 oldWord
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
,
636 if(oldWord
>= DMPAPER_USER
) /* DMPAPER_USER == DMBIN_USER */
637 oldWord
= 0; /* There's no point in trying to keep custom
638 paper / bin sizes across printers */
642 newWord
= (nIDComboBox
== cmb2
) ? dm
->u1
.s1
.dmPaperSize
: dm
->u1
.s1
.dmDefaultSource
;
644 if (nIDComboBox
== cmb2
) {
646 fwCapability_Names
= DC_PAPERNAMES
;
647 fwCapability_Words
= DC_PAPERS
;
651 fwCapability_Names
= DC_BINNAMES
;
652 fwCapability_Words
= DC_BINS
;
655 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
656 fwCapability_Names
, NULL
, dm
);
657 if (NrOfEntries
== 0)
658 WARN("no Name Entries found!\n");
659 else if (NrOfEntries
< 0)
662 if(DeviceCapabilitiesA(PrinterName
, PortName
, fwCapability_Words
, NULL
, dm
)
664 ERR("Number of caps is different\n");
668 Names
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(char)*NamesSize
);
669 Words
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WORD
));
670 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
671 fwCapability_Names
, Names
, dm
);
672 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
673 fwCapability_Words
, (LPSTR
)Words
, dm
);
675 /* reset any current content in the combobox */
676 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_RESETCONTENT
, 0, 0);
678 /* store new content */
679 for (i
= 0; i
< NrOfEntries
; i
++) {
680 DWORD pos
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_ADDSTRING
, 0,
681 (LPARAM
)(&Names
[i
*NamesSize
]) );
682 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_SETITEMDATA
, pos
,
686 /* Look for old selection or the new default.
687 Can't do this is previous loop since item order will change as more items are added */
689 old_Sel
= NrOfEntries
;
690 for (i
= 0; i
< NrOfEntries
; i
++) {
691 if(SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) ==
696 if(SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) == newWord
)
700 if(old_Sel
< NrOfEntries
)
704 if(nIDComboBox
== cmb2
)
705 dm
->u1
.s1
.dmPaperSize
= oldWord
;
707 dm
->u1
.s1
.dmDefaultSource
= oldWord
;
712 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_SETCURSEL
, Sel
, 0);
714 HeapFree(GetProcessHeap(),0,Words
);
715 HeapFree(GetProcessHeap(),0,Names
);
719 static BOOL
PRINTDLG_SetUpPaperComboBoxW(HWND hDlg
,
721 const WCHAR
* PrinterName
,
722 const WCHAR
* PortName
,
730 WORD oldWord
= 0, newWord
= 0; /* DMPAPER_ and DMBIN_ start at 1 */
732 int fwCapability_Names
;
733 int fwCapability_Words
;
735 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName
),debugstr_w(PortName
),nIDComboBox
);
737 /* query the dialog box for the current selected value */
738 Sel
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETCURSEL
, 0, 0);
740 /* we enter here only if a different printer is selected after
741 * the Print Setup dialog is opened. The current settings are
742 * stored into the newly selected printer.
744 oldWord
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETITEMDATA
,
747 if(oldWord
>= DMPAPER_USER
) /* DMPAPER_USER == DMBIN_USER */
748 oldWord
= 0; /* There's no point in trying to keep custom
749 paper / bin sizes across printers */
753 newWord
= (nIDComboBox
== cmb2
) ? dm
->u1
.s1
.dmPaperSize
: dm
->u1
.s1
.dmDefaultSource
;
755 if (nIDComboBox
== cmb2
) {
757 fwCapability_Names
= DC_PAPERNAMES
;
758 fwCapability_Words
= DC_PAPERS
;
762 fwCapability_Names
= DC_BINNAMES
;
763 fwCapability_Words
= DC_BINS
;
766 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
767 fwCapability_Names
, NULL
, dm
);
768 if (NrOfEntries
== 0)
769 WARN("no Name Entries found!\n");
770 else if (NrOfEntries
< 0)
773 if(DeviceCapabilitiesW(PrinterName
, PortName
, fwCapability_Words
, NULL
, dm
)
775 ERR("Number of caps is different\n");
779 Names
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WCHAR
)*NamesSize
);
780 Words
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WORD
));
781 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
782 fwCapability_Names
, Names
, dm
);
783 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
784 fwCapability_Words
, Words
, dm
);
786 /* reset any current content in the combobox */
787 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_RESETCONTENT
, 0, 0);
789 /* store new content */
790 for (i
= 0; i
< NrOfEntries
; i
++) {
791 DWORD pos
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_ADDSTRING
, 0,
792 (LPARAM
)(&Names
[i
*NamesSize
]) );
793 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_SETITEMDATA
, pos
,
797 /* Look for old selection or the new default.
798 Can't do this is previous loop since item order will change as more items are added */
800 old_Sel
= NrOfEntries
;
801 for (i
= 0; i
< NrOfEntries
; i
++) {
802 if(SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) ==
807 if(SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) == newWord
)
811 if(old_Sel
< NrOfEntries
)
815 if(nIDComboBox
== cmb2
)
816 dm
->u1
.s1
.dmPaperSize
= oldWord
;
818 dm
->u1
.s1
.dmDefaultSource
= oldWord
;
823 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_SETCURSEL
, Sel
, 0);
825 HeapFree(GetProcessHeap(),0,Words
);
826 HeapFree(GetProcessHeap(),0,Names
);
831 /***********************************************************************
832 * PRINTDLG_UpdatePrinterInfoTexts [internal]
834 static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg
, const PRINTER_INFO_2A
*pi
)
837 char ResourceString
[256];
843 /* add all status messages */
844 for (i
= 0; i
< 25; i
++) {
845 if (pi
->Status
& (1<<i
)) {
846 LoadStringA(COMDLG32_hInstance
, PD32_PRINTER_STATUS_PAUSED
+i
,
847 ResourceString
, 255);
848 strcat(StatusMsg
,ResourceString
);
852 /* FIXME: status==ready must only be appended if really so.
853 but how to detect? */
854 LoadStringA(COMDLG32_hInstance
, PD32_PRINTER_STATUS_READY
,
855 ResourceString
, 255);
856 strcat(StatusMsg
,ResourceString
);
857 SetDlgItemTextA(hDlg
, stc12
, StatusMsg
);
859 /* set all other printer info texts */
860 SetDlgItemTextA(hDlg
, stc11
, pi
->pDriverName
);
862 if (pi
->pLocation
!= NULL
&& pi
->pLocation
[0] != '\0')
863 SetDlgItemTextA(hDlg
, stc14
, pi
->pLocation
);
865 SetDlgItemTextA(hDlg
, stc14
, pi
->pPortName
);
866 SetDlgItemTextA(hDlg
, stc13
, pi
->pComment
? pi
->pComment
: "");
870 static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg
, const PRINTER_INFO_2W
*pi
)
872 WCHAR StatusMsg
[256];
873 WCHAR ResourceString
[256];
874 static const WCHAR emptyW
[] = {0};
880 /* add all status messages */
881 for (i
= 0; i
< 25; i
++) {
882 if (pi
->Status
& (1<<i
)) {
883 LoadStringW(COMDLG32_hInstance
, PD32_PRINTER_STATUS_PAUSED
+i
,
884 ResourceString
, 255);
885 lstrcatW(StatusMsg
,ResourceString
);
889 /* FIXME: status==ready must only be appended if really so.
890 but how to detect? */
891 LoadStringW(COMDLG32_hInstance
, PD32_PRINTER_STATUS_READY
,
892 ResourceString
, 255);
893 lstrcatW(StatusMsg
,ResourceString
);
894 SetDlgItemTextW(hDlg
, stc12
, StatusMsg
);
896 /* set all other printer info texts */
897 SetDlgItemTextW(hDlg
, stc11
, pi
->pDriverName
);
898 if (pi
->pLocation
!= NULL
&& pi
->pLocation
[0] != '\0')
899 SetDlgItemTextW(hDlg
, stc14
, pi
->pLocation
);
901 SetDlgItemTextW(hDlg
, stc14
, pi
->pPortName
);
902 SetDlgItemTextW(hDlg
, stc13
, pi
->pComment
? pi
->pComment
: emptyW
);
906 /*******************************************************************
908 * PRINTDLG_ChangePrinter
911 static BOOL
PRINTDLG_ChangePrinterA(HWND hDlg
, char *name
, PRINT_PTRA
*PrintStructures
)
913 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
914 LPDEVMODEA lpdm
= NULL
;
919 HeapFree(GetProcessHeap(),0, PrintStructures
->lpPrinterInfo
);
920 HeapFree(GetProcessHeap(),0, PrintStructures
->lpDriverInfo
);
921 if(!OpenPrinterA(name
, &hprn
, NULL
)) {
922 ERR("Can't open printer %s\n", name
);
925 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
926 PrintStructures
->lpPrinterInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
927 GetPrinterA(hprn
, 2, (LPBYTE
)PrintStructures
->lpPrinterInfo
, needed
,
929 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
930 PrintStructures
->lpDriverInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
931 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)PrintStructures
->lpDriverInfo
,
933 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures
->lpPrinterInfo
->pPrinterName
);
938 PRINTDLG_UpdatePrinterInfoTextsA(hDlg
, PrintStructures
->lpPrinterInfo
);
940 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
941 PrintStructures
->lpDevMode
= NULL
;
943 dmSize
= DocumentPropertiesA(0, 0, name
, NULL
, NULL
, 0);
945 ERR("DocumentProperties fails on %s\n", debugstr_a(name
));
948 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(), 0, dmSize
);
949 dmSize
= DocumentPropertiesA(0, 0, name
, PrintStructures
->lpDevMode
, NULL
,
951 if(lppd
->hDevMode
&& (lpdm
= GlobalLock(lppd
->hDevMode
)) &&
952 !lstrcmpA( (LPSTR
) lpdm
->dmDeviceName
,
953 (LPSTR
) PrintStructures
->lpDevMode
->dmDeviceName
)) {
954 /* Supplied devicemode matches current printer so try to use it */
955 DocumentPropertiesA(0, 0, name
, PrintStructures
->lpDevMode
, lpdm
,
956 DM_OUT_BUFFER
| DM_IN_BUFFER
);
959 GlobalUnlock(lppd
->hDevMode
);
961 lpdm
= PrintStructures
->lpDevMode
; /* use this as a shortcut */
963 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
964 /* Print range (All/Range/Selection) */
965 if(lppd
->nFromPage
!= 0xffff)
966 SetDlgItemInt(hDlg
, edt1
, lppd
->nFromPage
, FALSE
);
967 if(lppd
->nToPage
!= 0xffff)
968 SetDlgItemInt(hDlg
, edt2
, lppd
->nToPage
, FALSE
);
970 CheckRadioButton(hDlg
, rad1
, rad3
, rad1
); /* default */
971 if (lppd
->Flags
& PD_NOSELECTION
)
972 EnableWindow(GetDlgItem(hDlg
, rad2
), FALSE
);
974 if (lppd
->Flags
& PD_SELECTION
)
975 CheckRadioButton(hDlg
, rad1
, rad3
, rad2
);
976 if (lppd
->Flags
& PD_NOPAGENUMS
) {
977 EnableWindow(GetDlgItem(hDlg
, rad3
), FALSE
);
978 EnableWindow(GetDlgItem(hDlg
, stc2
),FALSE
);
979 EnableWindow(GetDlgItem(hDlg
, edt1
), FALSE
);
980 EnableWindow(GetDlgItem(hDlg
, stc3
),FALSE
);
981 EnableWindow(GetDlgItem(hDlg
, edt2
), FALSE
);
983 if (lppd
->Flags
& PD_PAGENUMS
)
984 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
989 * FIXME: The ico3 is not displayed for some reason. I don't know why.
991 if (lppd
->Flags
& PD_COLLATE
) {
992 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
993 (LPARAM
)PrintStructures
->hCollateIcon
);
994 CheckDlgButton(hDlg
, chx2
, 1);
996 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
997 (LPARAM
)PrintStructures
->hNoCollateIcon
);
998 CheckDlgButton(hDlg
, chx2
, 0);
1001 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1002 /* if printer doesn't support it: no Collate */
1003 if (!(lpdm
->dmFields
& DM_COLLATE
)) {
1004 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1005 EnableWindow(GetDlgItem(hDlg
, ico3
), FALSE
);
1012 if (lppd
->hDevMode
== 0)
1013 copies
= lppd
->nCopies
;
1015 copies
= lpdm
->u1
.s1
.dmCopies
;
1016 if(copies
== 0) copies
= 1;
1017 else if(copies
< 0) copies
= MAX_COPIES
;
1018 SetDlgItemInt(hDlg
, edt3
, copies
, FALSE
);
1021 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1022 /* if printer doesn't support it: no nCopies */
1023 if (!(lpdm
->dmFields
& DM_COPIES
)) {
1024 EnableWindow(GetDlgItem(hDlg
, edt3
), FALSE
);
1025 EnableWindow(GetDlgItem(hDlg
, stc5
), FALSE
);
1030 CheckDlgButton(hDlg
, chx1
, (lppd
->Flags
& PD_PRINTTOFILE
) ? 1 : 0);
1031 if (lppd
->Flags
& PD_DISABLEPRINTTOFILE
)
1032 EnableWindow(GetDlgItem(hDlg
, chx1
), FALSE
);
1033 if (lppd
->Flags
& PD_HIDEPRINTTOFILE
)
1034 ShowWindow(GetDlgItem(hDlg
, chx1
), SW_HIDE
);
1036 /* Fill print quality combo, PrintDlg16 */
1037 if(GetDlgItem(hDlg
, cmb1
))
1039 DWORD numResolutions
= DeviceCapabilitiesA(PrintStructures
->lpPrinterInfo
->pPrinterName
,
1040 PrintStructures
->lpPrinterInfo
->pPortName
,
1041 DC_ENUMRESOLUTIONS
, NULL
, lpdm
);
1043 if(numResolutions
!= -1)
1045 HWND hQuality
= GetDlgItem(hDlg
, cmb1
);
1050 HDC hPrinterDC
= CreateDCA(PrintStructures
->lpPrinterInfo
->pDriverName
,
1051 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1054 Resolutions
= HeapAlloc(GetProcessHeap(), 0, numResolutions
*sizeof(LONG
)*2);
1055 DeviceCapabilitiesA(PrintStructures
->lpPrinterInfo
->pPrinterName
,
1056 PrintStructures
->lpPrinterInfo
->pPortName
,
1057 DC_ENUMRESOLUTIONS
, (LPSTR
)Resolutions
, lpdm
);
1059 dpiX
= GetDeviceCaps(hPrinterDC
, LOGPIXELSX
);
1060 dpiY
= GetDeviceCaps(hPrinterDC
, LOGPIXELSY
);
1061 DeleteDC(hPrinterDC
);
1063 SendMessageA(hQuality
, CB_RESETCONTENT
, 0, 0);
1064 for(i
= 0; i
< (numResolutions
* 2); i
+= 2)
1066 BOOL IsDefault
= FALSE
;
1069 if(Resolutions
[i
] == Resolutions
[i
+1])
1071 if(dpiX
== Resolutions
[i
])
1073 sprintf(buf
, "%d dpi", Resolutions
[i
]);
1076 if(dpiX
== Resolutions
[i
] && dpiY
== Resolutions
[i
+1])
1078 sprintf(buf
, "%d dpi x %d dpi", Resolutions
[i
], Resolutions
[i
+1]);
1081 Index
= SendMessageA(hQuality
, CB_ADDSTRING
, 0, (LPARAM
)buf
);
1084 SendMessageA(hQuality
, CB_SETCURSEL
, Index
, 0);
1086 SendMessageA(hQuality
, CB_SETITEMDATA
, Index
, MAKELONG(dpiX
,dpiY
));
1088 HeapFree(GetProcessHeap(), 0, Resolutions
);
1091 } else { /* PD_PRINTSETUP */
1092 BOOL bPortrait
= (lpdm
->u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
);
1094 PRINTDLG_SetUpPaperComboBoxA(hDlg
, cmb2
,
1095 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1096 PrintStructures
->lpPrinterInfo
->pPortName
,
1098 PRINTDLG_SetUpPaperComboBoxA(hDlg
, cmb3
,
1099 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1100 PrintStructures
->lpPrinterInfo
->pPortName
,
1102 CheckRadioButton(hDlg
, rad1
, rad2
, bPortrait
? rad1
: rad2
);
1103 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1104 (LPARAM
)(bPortrait
? PrintStructures
->hPortraitIcon
:
1105 PrintStructures
->hLandscapeIcon
));
1110 if ((lppd
->Flags
& PD_SHOWHELP
)==0) {
1111 /* hide if PD_SHOWHELP not specified */
1112 ShowWindow(GetDlgItem(hDlg
, pshHelp
), SW_HIDE
);
1117 static BOOL
PRINTDLG_ChangePrinterW(HWND hDlg
, WCHAR
*name
,
1118 PRINT_PTRW
*PrintStructures
)
1120 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1121 LPDEVMODEW lpdm
= NULL
;
1126 HeapFree(GetProcessHeap(),0, PrintStructures
->lpPrinterInfo
);
1127 HeapFree(GetProcessHeap(),0, PrintStructures
->lpDriverInfo
);
1128 if(!OpenPrinterW(name
, &hprn
, NULL
)) {
1129 ERR("Can't open printer %s\n", debugstr_w(name
));
1132 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
1133 PrintStructures
->lpPrinterInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
1134 GetPrinterW(hprn
, 2, (LPBYTE
)PrintStructures
->lpPrinterInfo
, needed
,
1136 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
1137 PrintStructures
->lpDriverInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
1138 if (!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)PrintStructures
->lpDriverInfo
,
1140 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures
->lpPrinterInfo
->pPrinterName
));
1145 PRINTDLG_UpdatePrinterInfoTextsW(hDlg
, PrintStructures
->lpPrinterInfo
);
1147 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
1148 PrintStructures
->lpDevMode
= NULL
;
1150 dmSize
= DocumentPropertiesW(0, 0, name
, NULL
, NULL
, 0);
1152 ERR("DocumentProperties fails on %s\n", debugstr_w(name
));
1155 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(), 0, dmSize
);
1156 dmSize
= DocumentPropertiesW(0, 0, name
, PrintStructures
->lpDevMode
, NULL
,
1158 if(lppd
->hDevMode
&& (lpdm
= GlobalLock(lppd
->hDevMode
)) &&
1159 !lstrcmpW(lpdm
->dmDeviceName
,
1160 PrintStructures
->lpDevMode
->dmDeviceName
)) {
1161 /* Supplied devicemode matches current printer so try to use it */
1162 DocumentPropertiesW(0, 0, name
, PrintStructures
->lpDevMode
, lpdm
,
1163 DM_OUT_BUFFER
| DM_IN_BUFFER
);
1166 GlobalUnlock(lppd
->hDevMode
);
1168 lpdm
= PrintStructures
->lpDevMode
; /* use this as a shortcut */
1170 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
1171 /* Print range (All/Range/Selection) */
1172 if(lppd
->nFromPage
!= 0xffff)
1173 SetDlgItemInt(hDlg
, edt1
, lppd
->nFromPage
, FALSE
);
1174 if(lppd
->nToPage
!= 0xffff)
1175 SetDlgItemInt(hDlg
, edt2
, lppd
->nToPage
, FALSE
);
1177 CheckRadioButton(hDlg
, rad1
, rad3
, rad1
); /* default */
1178 if (lppd
->Flags
& PD_NOSELECTION
)
1179 EnableWindow(GetDlgItem(hDlg
, rad2
), FALSE
);
1181 if (lppd
->Flags
& PD_SELECTION
)
1182 CheckRadioButton(hDlg
, rad1
, rad3
, rad2
);
1183 if (lppd
->Flags
& PD_NOPAGENUMS
) {
1184 EnableWindow(GetDlgItem(hDlg
, rad3
), FALSE
);
1185 EnableWindow(GetDlgItem(hDlg
, stc2
),FALSE
);
1186 EnableWindow(GetDlgItem(hDlg
, edt1
), FALSE
);
1187 EnableWindow(GetDlgItem(hDlg
, stc3
),FALSE
);
1188 EnableWindow(GetDlgItem(hDlg
, edt2
), FALSE
);
1190 if (lppd
->Flags
& PD_PAGENUMS
)
1191 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1196 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1198 if (lppd
->Flags
& PD_COLLATE
) {
1199 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1200 (LPARAM
)PrintStructures
->hCollateIcon
);
1201 CheckDlgButton(hDlg
, chx2
, 1);
1203 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1204 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1205 CheckDlgButton(hDlg
, chx2
, 0);
1208 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1209 /* if printer doesn't support it: no Collate */
1210 if (!(lpdm
->dmFields
& DM_COLLATE
)) {
1211 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1212 EnableWindow(GetDlgItem(hDlg
, ico3
), FALSE
);
1219 if (lppd
->hDevMode
== 0)
1220 copies
= lppd
->nCopies
;
1222 copies
= lpdm
->u1
.s1
.dmCopies
;
1223 if(copies
== 0) copies
= 1;
1224 else if(copies
< 0) copies
= MAX_COPIES
;
1225 SetDlgItemInt(hDlg
, edt3
, copies
, FALSE
);
1228 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1229 /* if printer doesn't support it: no nCopies */
1230 if (!(lpdm
->dmFields
& DM_COPIES
)) {
1231 EnableWindow(GetDlgItem(hDlg
, edt3
), FALSE
);
1232 EnableWindow(GetDlgItem(hDlg
, stc5
), FALSE
);
1237 CheckDlgButton(hDlg
, chx1
, (lppd
->Flags
& PD_PRINTTOFILE
) ? 1 : 0);
1238 if (lppd
->Flags
& PD_DISABLEPRINTTOFILE
)
1239 EnableWindow(GetDlgItem(hDlg
, chx1
), FALSE
);
1240 if (lppd
->Flags
& PD_HIDEPRINTTOFILE
)
1241 ShowWindow(GetDlgItem(hDlg
, chx1
), SW_HIDE
);
1243 } else { /* PD_PRINTSETUP */
1244 BOOL bPortrait
= (lpdm
->u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
);
1246 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb2
,
1247 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1248 PrintStructures
->lpPrinterInfo
->pPortName
,
1250 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb3
,
1251 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1252 PrintStructures
->lpPrinterInfo
->pPortName
,
1254 CheckRadioButton(hDlg
, rad1
, rad2
, bPortrait
? rad1
: rad2
);
1255 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1256 (LPARAM
)(bPortrait
? PrintStructures
->hPortraitIcon
:
1257 PrintStructures
->hLandscapeIcon
));
1262 if ((lppd
->Flags
& PD_SHOWHELP
)==0) {
1263 /* hide if PD_SHOWHELP not specified */
1264 ShowWindow(GetDlgItem(hDlg
, pshHelp
), SW_HIDE
);
1269 /***********************************************************************
1270 * check_printer_setup [internal]
1272 static LRESULT
check_printer_setup(HWND hDlg
)
1275 WCHAR resourcestr
[256],resultstr
[256];
1277 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
1280 EnumPrintersW(PRINTER_ENUM_CONNECTIONS
, NULL
, 2, NULL
, 0, &needed
, &num
);
1286 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEVICES
,resultstr
, 255);
1287 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
,resourcestr
, 255);
1288 MessageBoxW(hDlg
, resultstr
, resourcestr
,MB_OK
| MB_ICONWARNING
);
1293 /***********************************************************************
1294 * PRINTDLG_WMInitDialog [internal]
1296 static LRESULT
PRINTDLG_WMInitDialog(HWND hDlg
,
1297 PRINT_PTRA
* PrintStructures
)
1299 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1303 UINT comboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1305 /* load Collate ICONs */
1306 /* We load these with LoadImage because they are not a standard
1307 size and we don't want them rescaled */
1308 PrintStructures
->hCollateIcon
=
1309 LoadImageA(COMDLG32_hInstance
, "PD32_COLLATE", IMAGE_ICON
, 0, 0, 0);
1310 PrintStructures
->hNoCollateIcon
=
1311 LoadImageA(COMDLG32_hInstance
, "PD32_NOCOLLATE", IMAGE_ICON
, 0, 0, 0);
1313 /* These can be done with LoadIcon */
1314 PrintStructures
->hPortraitIcon
=
1315 LoadIconA(COMDLG32_hInstance
, "PD32_PORTRAIT");
1316 PrintStructures
->hLandscapeIcon
=
1317 LoadIconA(COMDLG32_hInstance
, "PD32_LANDSCAPE");
1319 /* display the collate/no_collate icon */
1320 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1321 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1323 if(PrintStructures
->hCollateIcon
== 0 ||
1324 PrintStructures
->hNoCollateIcon
== 0 ||
1325 PrintStructures
->hPortraitIcon
== 0 ||
1326 PrintStructures
->hLandscapeIcon
== 0) {
1327 ERR("no icon in resourcefile\n");
1328 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1329 EndDialog(hDlg
, FALSE
);
1333 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1334 * must be registered and the Help button must be shown.
1336 if (lppd
->Flags
& PD_SHOWHELP
) {
1337 if((PrintStructures
->HelpMessageID
=
1338 RegisterWindowMessageA(HELPMSGSTRINGA
)) == 0) {
1339 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL
);
1343 PrintStructures
->HelpMessageID
= 0;
1345 if(!(lppd
->Flags
&PD_PRINTSETUP
)) {
1346 PrintStructures
->hwndUpDown
=
1347 CreateUpDownControl(WS_CHILD
| WS_VISIBLE
| WS_BORDER
|
1348 UDS_NOTHOUSANDS
| UDS_ARROWKEYS
|
1349 UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, 0, 0, 0, 0,
1350 hDlg
, UPDOWN_ID
, COMDLG32_hInstance
,
1351 GetDlgItem(hDlg
, edt3
), MAX_COPIES
, 1, 1);
1354 /* FIXME: I allow more freedom than either Win95 or WinNT,
1355 * which do not agree to what errors should be thrown or not
1356 * in case nToPage or nFromPage is out-of-range.
1358 if (lppd
->nMaxPage
< lppd
->nMinPage
)
1359 lppd
->nMaxPage
= lppd
->nMinPage
;
1360 if (lppd
->nMinPage
== lppd
->nMaxPage
)
1361 lppd
->Flags
|= PD_NOPAGENUMS
;
1362 if (lppd
->nToPage
< lppd
->nMinPage
)
1363 lppd
->nToPage
= lppd
->nMinPage
;
1364 if (lppd
->nToPage
> lppd
->nMaxPage
)
1365 lppd
->nToPage
= lppd
->nMaxPage
;
1366 if (lppd
->nFromPage
< lppd
->nMinPage
)
1367 lppd
->nFromPage
= lppd
->nMinPage
;
1368 if (lppd
->nFromPage
> lppd
->nMaxPage
)
1369 lppd
->nFromPage
= lppd
->nMaxPage
;
1371 /* if we have the combo box, fill it */
1372 if (GetDlgItem(hDlg
,comboID
)) {
1375 pdn
= GlobalLock(lppd
->hDevNames
);
1376 pdm
= GlobalLock(lppd
->hDevMode
);
1378 name
= (char*)pdn
+ pdn
->wDeviceOffset
;
1380 name
= (char*)pdm
->dmDeviceName
;
1381 PRINTDLG_SetUpPrinterListComboA(hDlg
, comboID
, name
);
1382 if(pdm
) GlobalUnlock(lppd
->hDevMode
);
1383 if(pdn
) GlobalUnlock(lppd
->hDevNames
);
1385 /* Now find selected printer and update rest of dlg */
1386 name
= HeapAlloc(GetProcessHeap(),0,256);
1387 if (GetDlgItemTextA(hDlg
, comboID
, name
, 255))
1388 PRINTDLG_ChangePrinterA(hDlg
, name
, PrintStructures
);
1389 HeapFree(GetProcessHeap(),0,name
);
1391 /* else use default printer */
1393 DWORD dwBufLen
= sizeof(name
);
1394 BOOL ret
= GetDefaultPrinterA(name
, &dwBufLen
);
1397 PRINTDLG_ChangePrinterA(hDlg
, name
, PrintStructures
);
1399 FIXME("No default printer found, expect problems!\n");
1404 static LRESULT
PRINTDLG_WMInitDialogW(HWND hDlg
,
1405 PRINT_PTRW
* PrintStructures
)
1407 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1411 UINT comboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1413 /* load Collate ICONs */
1414 /* We load these with LoadImage because they are not a standard
1415 size and we don't want them rescaled */
1416 PrintStructures
->hCollateIcon
=
1417 LoadImageW(COMDLG32_hInstance
, pd32_collateW
, IMAGE_ICON
, 0, 0, 0);
1418 PrintStructures
->hNoCollateIcon
=
1419 LoadImageW(COMDLG32_hInstance
, pd32_nocollateW
, IMAGE_ICON
, 0, 0, 0);
1421 /* These can be done with LoadIcon */
1422 PrintStructures
->hPortraitIcon
=
1423 LoadIconW(COMDLG32_hInstance
, pd32_portraitW
);
1424 PrintStructures
->hLandscapeIcon
=
1425 LoadIconW(COMDLG32_hInstance
, pd32_landscapeW
);
1427 /* display the collate/no_collate icon */
1428 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1429 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1431 if(PrintStructures
->hCollateIcon
== 0 ||
1432 PrintStructures
->hNoCollateIcon
== 0 ||
1433 PrintStructures
->hPortraitIcon
== 0 ||
1434 PrintStructures
->hLandscapeIcon
== 0) {
1435 ERR("no icon in resourcefile\n");
1436 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1437 EndDialog(hDlg
, FALSE
);
1441 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1442 * must be registered and the Help button must be shown.
1444 if (lppd
->Flags
& PD_SHOWHELP
) {
1445 if((PrintStructures
->HelpMessageID
=
1446 RegisterWindowMessageW(HELPMSGSTRINGW
)) == 0) {
1447 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL
);
1451 PrintStructures
->HelpMessageID
= 0;
1453 if(!(lppd
->Flags
&PD_PRINTSETUP
)) {
1454 PrintStructures
->hwndUpDown
=
1455 CreateUpDownControl(WS_CHILD
| WS_VISIBLE
| WS_BORDER
|
1456 UDS_NOTHOUSANDS
| UDS_ARROWKEYS
|
1457 UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, 0, 0, 0, 0,
1458 hDlg
, UPDOWN_ID
, COMDLG32_hInstance
,
1459 GetDlgItem(hDlg
, edt3
), MAX_COPIES
, 1, 1);
1462 /* FIXME: I allow more freedom than either Win95 or WinNT,
1463 * which do not agree to what errors should be thrown or not
1464 * in case nToPage or nFromPage is out-of-range.
1466 if (lppd
->nMaxPage
< lppd
->nMinPage
)
1467 lppd
->nMaxPage
= lppd
->nMinPage
;
1468 if (lppd
->nMinPage
== lppd
->nMaxPage
)
1469 lppd
->Flags
|= PD_NOPAGENUMS
;
1470 if (lppd
->nToPage
< lppd
->nMinPage
)
1471 lppd
->nToPage
= lppd
->nMinPage
;
1472 if (lppd
->nToPage
> lppd
->nMaxPage
)
1473 lppd
->nToPage
= lppd
->nMaxPage
;
1474 if (lppd
->nFromPage
< lppd
->nMinPage
)
1475 lppd
->nFromPage
= lppd
->nMinPage
;
1476 if (lppd
->nFromPage
> lppd
->nMaxPage
)
1477 lppd
->nFromPage
= lppd
->nMaxPage
;
1479 /* if we have the combo box, fill it */
1480 if (GetDlgItem(hDlg
,comboID
)) {
1483 pdn
= GlobalLock(lppd
->hDevNames
);
1484 pdm
= GlobalLock(lppd
->hDevMode
);
1486 name
= (WCHAR
*)pdn
+ pdn
->wDeviceOffset
;
1488 name
= pdm
->dmDeviceName
;
1489 PRINTDLG_SetUpPrinterListComboW(hDlg
, comboID
, name
);
1490 if(pdm
) GlobalUnlock(lppd
->hDevMode
);
1491 if(pdn
) GlobalUnlock(lppd
->hDevNames
);
1493 /* Now find selected printer and update rest of dlg */
1494 /* ansi is ok here */
1495 name
= HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR
));
1496 if (GetDlgItemTextW(hDlg
, comboID
, name
, 255))
1497 PRINTDLG_ChangePrinterW(hDlg
, name
, PrintStructures
);
1498 HeapFree(GetProcessHeap(),0,name
);
1500 /* else use default printer */
1502 DWORD dwBufLen
= sizeof(name
) / sizeof(WCHAR
);
1503 BOOL ret
= GetDefaultPrinterW(name
, &dwBufLen
);
1506 PRINTDLG_ChangePrinterW(hDlg
, name
, PrintStructures
);
1508 FIXME("No default printer found, expect problems!\n");
1513 /***********************************************************************
1514 * PRINTDLG_WMCommand [internal]
1516 static LRESULT
PRINTDLG_WMCommandA(HWND hDlg
, WPARAM wParam
,
1517 PRINT_PTRA
* PrintStructures
)
1519 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1520 UINT PrinterComboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1521 LPDEVMODEA lpdm
= PrintStructures
->lpDevMode
;
1523 switch (LOWORD(wParam
)) {
1525 TRACE(" OK button was hit\n");
1526 if (!PRINTDLG_UpdatePrintDlgA(hDlg
, PrintStructures
)) {
1527 FIXME("Update printdlg was not successful!\n");
1530 EndDialog(hDlg
, TRUE
);
1534 TRACE(" CANCEL button was hit\n");
1535 EndDialog(hDlg
, FALSE
);
1539 TRACE(" HELP button was hit\n");
1540 SendMessageA(lppd
->hwndOwner
, PrintStructures
->HelpMessageID
,
1541 (WPARAM
) hDlg
, (LPARAM
) lppd
);
1544 case chx2
: /* collate pages checkbox */
1545 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
1546 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1547 (LPARAM
)PrintStructures
->hCollateIcon
);
1549 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1550 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1552 case edt1
: /* from page nr editbox */
1553 case edt2
: /* to page nr editbox */
1554 if (HIWORD(wParam
)==EN_CHANGE
) {
1557 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
1558 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
1559 if (nFromPage
!= lppd
->nFromPage
|| nToPage
!= lppd
->nToPage
)
1560 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1565 if(HIWORD(wParam
) == EN_CHANGE
) {
1566 INT copies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
1568 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1570 EnableWindow(GetDlgItem(hDlg
, chx2
), TRUE
);
1574 case psh2
: /* Properties button */
1577 char PrinterName
[256];
1579 GetDlgItemTextA(hDlg
, PrinterComboID
, PrinterName
, 255);
1580 if (!OpenPrinterA(PrinterName
, &hPrinter
, NULL
)) {
1581 FIXME(" Call to OpenPrinter did not succeed!\n");
1584 DocumentPropertiesA(hDlg
, hPrinter
, PrinterName
,
1585 PrintStructures
->lpDevMode
,
1586 PrintStructures
->lpDevMode
,
1587 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
1588 ClosePrinter(hPrinter
);
1592 case rad1
: /* Paperorientation */
1593 if (lppd
->Flags
& PD_PRINTSETUP
)
1595 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1596 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1597 (LPARAM
)(PrintStructures
->hPortraitIcon
));
1601 case rad2
: /* Paperorientation */
1602 if (lppd
->Flags
& PD_PRINTSETUP
)
1604 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1605 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1606 (LPARAM
)(PrintStructures
->hLandscapeIcon
));
1610 case cmb1
: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT16 */
1611 if (PrinterComboID
!= LOWORD(wParam
)) {
1615 case cmb4
: /* Printer combobox */
1616 if (HIWORD(wParam
)==CBN_SELCHANGE
) {
1617 char PrinterName
[256];
1618 GetDlgItemTextA(hDlg
, LOWORD(wParam
), PrinterName
, 255);
1619 PRINTDLG_ChangePrinterA(hDlg
, PrinterName
, PrintStructures
);
1623 case cmb2
: /* Papersize */
1625 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
1627 lpdm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageA(hDlg
, cmb2
,
1633 case cmb3
: /* Bin */
1635 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
1637 lpdm
->u1
.s1
.dmDefaultSource
= SendDlgItemMessageA(hDlg
, cmb3
,
1638 CB_GETITEMDATA
, Sel
,
1643 if(lppd
->Flags
& PD_PRINTSETUP
) {
1644 switch (LOWORD(wParam
)) {
1645 case rad1
: /* orientation */
1647 if (IsDlgButtonChecked(hDlg
, rad1
) == BST_CHECKED
) {
1648 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_PORTRAIT
) {
1649 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1650 SendDlgItemMessageA(hDlg
, stc10
, STM_SETIMAGE
, IMAGE_ICON
,
1651 (LPARAM
)PrintStructures
->hPortraitIcon
);
1652 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1653 (LPARAM
)PrintStructures
->hPortraitIcon
);
1656 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_LANDSCAPE
) {
1657 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1658 SendDlgItemMessageA(hDlg
, stc10
, STM_SETIMAGE
, IMAGE_ICON
,
1659 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1660 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1661 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1670 static LRESULT
PRINTDLG_WMCommandW(HWND hDlg
, WPARAM wParam
,
1671 PRINT_PTRW
* PrintStructures
)
1673 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1674 UINT PrinterComboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1675 LPDEVMODEW lpdm
= PrintStructures
->lpDevMode
;
1677 switch (LOWORD(wParam
)) {
1679 TRACE(" OK button was hit\n");
1680 if (!PRINTDLG_UpdatePrintDlgW(hDlg
, PrintStructures
)) {
1681 FIXME("Update printdlg was not successful!\n");
1684 EndDialog(hDlg
, TRUE
);
1688 TRACE(" CANCEL button was hit\n");
1689 EndDialog(hDlg
, FALSE
);
1693 TRACE(" HELP button was hit\n");
1694 SendMessageW(lppd
->hwndOwner
, PrintStructures
->HelpMessageID
,
1695 (WPARAM
) hDlg
, (LPARAM
) lppd
);
1698 case chx2
: /* collate pages checkbox */
1699 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
1700 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1701 (LPARAM
)PrintStructures
->hCollateIcon
);
1703 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1704 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1706 case edt1
: /* from page nr editbox */
1707 case edt2
: /* to page nr editbox */
1708 if (HIWORD(wParam
)==EN_CHANGE
) {
1711 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
1712 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
1713 if (nFromPage
!= lppd
->nFromPage
|| nToPage
!= lppd
->nToPage
)
1714 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1719 if(HIWORD(wParam
) == EN_CHANGE
) {
1720 INT copies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
1722 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1724 EnableWindow(GetDlgItem(hDlg
, chx2
), TRUE
);
1728 case psh2
: /* Properties button */
1731 WCHAR PrinterName
[256];
1733 if (!GetDlgItemTextW(hDlg
, PrinterComboID
, PrinterName
, 255)) break;
1734 if (!OpenPrinterW(PrinterName
, &hPrinter
, NULL
)) {
1735 FIXME(" Call to OpenPrinter did not succeed!\n");
1738 DocumentPropertiesW(hDlg
, hPrinter
, PrinterName
,
1739 PrintStructures
->lpDevMode
,
1740 PrintStructures
->lpDevMode
,
1741 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
1742 ClosePrinter(hPrinter
);
1746 case rad1
: /* Paperorientation */
1747 if (lppd
->Flags
& PD_PRINTSETUP
)
1749 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1750 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1751 (LPARAM
)(PrintStructures
->hPortraitIcon
));
1755 case rad2
: /* Paperorientation */
1756 if (lppd
->Flags
& PD_PRINTSETUP
)
1758 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1759 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1760 (LPARAM
)(PrintStructures
->hLandscapeIcon
));
1764 case cmb1
: /* Printer Combobox in PRINT SETUP */
1766 case cmb4
: /* Printer combobox */
1767 if (HIWORD(wParam
)==CBN_SELCHANGE
) {
1768 WCHAR PrinterName
[256];
1769 GetDlgItemTextW(hDlg
, LOWORD(wParam
), PrinterName
, 255);
1770 PRINTDLG_ChangePrinterW(hDlg
, PrinterName
, PrintStructures
);
1774 case cmb2
: /* Papersize */
1776 DWORD Sel
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
1778 lpdm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageW(hDlg
, cmb2
,
1784 case cmb3
: /* Bin */
1786 DWORD Sel
= SendDlgItemMessageW(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
1788 lpdm
->u1
.s1
.dmDefaultSource
= SendDlgItemMessageW(hDlg
, cmb3
,
1789 CB_GETITEMDATA
, Sel
,
1794 if(lppd
->Flags
& PD_PRINTSETUP
) {
1795 switch (LOWORD(wParam
)) {
1796 case rad1
: /* orientation */
1798 if (IsDlgButtonChecked(hDlg
, rad1
) == BST_CHECKED
) {
1799 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_PORTRAIT
) {
1800 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1801 SendDlgItemMessageW(hDlg
, stc10
, STM_SETIMAGE
, IMAGE_ICON
,
1802 (LPARAM
)PrintStructures
->hPortraitIcon
);
1803 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1804 (LPARAM
)PrintStructures
->hPortraitIcon
);
1807 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_LANDSCAPE
) {
1808 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1809 SendDlgItemMessageW(hDlg
, stc10
, STM_SETIMAGE
, IMAGE_ICON
,
1810 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1811 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1812 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1821 /***********************************************************************
1822 * PrintDlgProcA [internal]
1824 static INT_PTR CALLBACK
PrintDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
1827 PRINT_PTRA
* PrintStructures
;
1828 INT_PTR res
= FALSE
;
1830 if (uMsg
!=WM_INITDIALOG
) {
1831 PrintStructures
= GetPropW(hDlg
, printdlg_prop
);
1832 if (!PrintStructures
)
1835 PrintStructures
= (PRINT_PTRA
*) lParam
;
1836 SetPropW(hDlg
, printdlg_prop
, PrintStructures
);
1837 if(!check_printer_setup(hDlg
))
1839 EndDialog(hDlg
,FALSE
);
1842 res
= PRINTDLG_WMInitDialog(hDlg
, PrintStructures
);
1844 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
)
1845 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(
1846 hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->lpPrintDlg
1851 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
) {
1852 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
,uMsg
,wParam
,
1859 return PRINTDLG_WMCommandA(hDlg
, wParam
, PrintStructures
);
1862 DestroyIcon(PrintStructures
->hCollateIcon
);
1863 DestroyIcon(PrintStructures
->hNoCollateIcon
);
1864 DestroyIcon(PrintStructures
->hPortraitIcon
);
1865 DestroyIcon(PrintStructures
->hLandscapeIcon
);
1866 if(PrintStructures
->hwndUpDown
)
1867 DestroyWindow(PrintStructures
->hwndUpDown
);
1873 static INT_PTR CALLBACK
PrintDlgProcW(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
1876 PRINT_PTRW
* PrintStructures
;
1877 INT_PTR res
= FALSE
;
1879 if (uMsg
!=WM_INITDIALOG
) {
1880 PrintStructures
= GetPropW(hDlg
, printdlg_prop
);
1881 if (!PrintStructures
)
1884 PrintStructures
= (PRINT_PTRW
*) lParam
;
1885 SetPropW(hDlg
, printdlg_prop
, PrintStructures
);
1886 if(!check_printer_setup(hDlg
))
1888 EndDialog(hDlg
,FALSE
);
1891 res
= PRINTDLG_WMInitDialogW(hDlg
, PrintStructures
);
1893 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
)
1894 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->lpPrintDlg
);
1898 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
) {
1899 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
,uMsg
,wParam
, lParam
);
1905 return PRINTDLG_WMCommandW(hDlg
, wParam
, PrintStructures
);
1908 DestroyIcon(PrintStructures
->hCollateIcon
);
1909 DestroyIcon(PrintStructures
->hNoCollateIcon
);
1910 DestroyIcon(PrintStructures
->hPortraitIcon
);
1911 DestroyIcon(PrintStructures
->hLandscapeIcon
);
1912 if(PrintStructures
->hwndUpDown
)
1913 DestroyWindow(PrintStructures
->hwndUpDown
);
1919 /************************************************************
1921 * PRINTDLG_GetDlgTemplate
1924 static HGLOBAL
PRINTDLG_GetDlgTemplateA(const PRINTDLGA
*lppd
)
1929 if (lppd
->Flags
& PD_PRINTSETUP
) {
1930 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
1931 hDlgTmpl
= lppd
->hSetupTemplate
;
1932 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
1933 hResInfo
= FindResourceA(lppd
->hInstance
,
1934 lppd
->lpSetupTemplateName
, (LPSTR
)RT_DIALOG
);
1935 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1937 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32_SETUP",
1939 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1942 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
1943 hDlgTmpl
= lppd
->hPrintTemplate
;
1944 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
1945 hResInfo
= FindResourceA(lppd
->hInstance
,
1946 lppd
->lpPrintTemplateName
,
1948 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1950 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32",
1952 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1958 static HGLOBAL
PRINTDLG_GetDlgTemplateW(const PRINTDLGW
*lppd
)
1962 static const WCHAR xpsetup
[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
1963 static const WCHAR xprint
[] = { 'P','R','I','N','T','3','2',0};
1965 if (lppd
->Flags
& PD_PRINTSETUP
) {
1966 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
1967 hDlgTmpl
= lppd
->hSetupTemplate
;
1968 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
1969 hResInfo
= FindResourceW(lppd
->hInstance
,
1970 lppd
->lpSetupTemplateName
, (LPWSTR
)RT_DIALOG
);
1971 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1973 hResInfo
= FindResourceW(COMDLG32_hInstance
, xpsetup
, (LPWSTR
)RT_DIALOG
);
1974 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1977 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
1978 hDlgTmpl
= lppd
->hPrintTemplate
;
1979 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
1980 hResInfo
= FindResourceW(lppd
->hInstance
,
1981 lppd
->lpPrintTemplateName
,
1983 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1985 hResInfo
= FindResourceW(COMDLG32_hInstance
, xprint
, (LPWSTR
)RT_DIALOG
);
1986 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1992 /***********************************************************************
1997 static BOOL
PRINTDLG_CreateDCA(LPPRINTDLGA lppd
)
1999 DEVNAMES
*pdn
= GlobalLock(lppd
->hDevNames
);
2000 DEVMODEA
*pdm
= GlobalLock(lppd
->hDevMode
);
2002 if(lppd
->Flags
& PD_RETURNDC
) {
2003 lppd
->hDC
= CreateDCA((char*)pdn
+ pdn
->wDriverOffset
,
2004 (char*)pdn
+ pdn
->wDeviceOffset
,
2005 (char*)pdn
+ pdn
->wOutputOffset
,
2007 } else if(lppd
->Flags
& PD_RETURNIC
) {
2008 lppd
->hDC
= CreateICA((char*)pdn
+ pdn
->wDriverOffset
,
2009 (char*)pdn
+ pdn
->wDeviceOffset
,
2010 (char*)pdn
+ pdn
->wOutputOffset
,
2013 GlobalUnlock(lppd
->hDevNames
);
2014 GlobalUnlock(lppd
->hDevMode
);
2015 return lppd
->hDC
? TRUE
: FALSE
;
2018 static BOOL
PRINTDLG_CreateDCW(LPPRINTDLGW lppd
)
2020 DEVNAMES
*pdn
= GlobalLock(lppd
->hDevNames
);
2021 DEVMODEW
*pdm
= GlobalLock(lppd
->hDevMode
);
2023 if(lppd
->Flags
& PD_RETURNDC
) {
2024 lppd
->hDC
= CreateDCW((WCHAR
*)pdn
+ pdn
->wDriverOffset
,
2025 (WCHAR
*)pdn
+ pdn
->wDeviceOffset
,
2026 (WCHAR
*)pdn
+ pdn
->wOutputOffset
,
2028 } else if(lppd
->Flags
& PD_RETURNIC
) {
2029 lppd
->hDC
= CreateICW((WCHAR
*)pdn
+ pdn
->wDriverOffset
,
2030 (WCHAR
*)pdn
+ pdn
->wDeviceOffset
,
2031 (WCHAR
*)pdn
+ pdn
->wOutputOffset
,
2034 GlobalUnlock(lppd
->hDevNames
);
2035 GlobalUnlock(lppd
->hDevMode
);
2036 return lppd
->hDC
? TRUE
: FALSE
;
2039 /***********************************************************************
2040 * PrintDlgA (COMDLG32.@)
2042 * Displays the PRINT dialog box, which enables the user to specify
2043 * specific properties of the print job.
2046 * lppd [IO] ptr to PRINTDLG32 struct
2049 * nonzero if the user pressed the OK button
2050 * zero if the user cancelled the window or an error occurred
2054 * * The Collate Icons do not display, even though they are in the code.
2055 * * The Properties Button(s) should call DocumentPropertiesA().
2058 BOOL WINAPI
PrintDlgA(LPPRINTDLGA lppd
)
2066 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
2070 if(TRACE_ON(commdlg
)) {
2071 char flagstr
[1000] = "";
2072 const struct pd_flags
*pflag
= pd_flags
;
2073 for( ; pflag
->name
; pflag
++) {
2074 if(lppd
->Flags
& pflag
->flag
)
2075 strcat(flagstr
, pflag
->name
);
2077 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2078 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2079 "flags %08x (%s)\n",
2080 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
2081 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
2082 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
2085 if(lppd
->lStructSize
!= sizeof(PRINTDLGA
)) {
2086 WARN("structure size failure !!!\n");
2087 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
2091 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
2092 PRINTER_INFO_2A
*pbuf
;
2093 DRIVER_INFO_3A
*dbuf
;
2097 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
2098 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2099 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2102 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
2103 WARN("Can't find default printer\n");
2104 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
2108 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
2109 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
2110 GetPrinterA(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
2112 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
2113 dbuf
= HeapAlloc(GetProcessHeap(),0,needed
);
2114 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
2115 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2116 GetLastError(),pbuf
->pPrinterName
);
2117 HeapFree(GetProcessHeap(), 0, dbuf
);
2118 HeapFree(GetProcessHeap(), 0, pbuf
);
2119 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2124 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
2128 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
2129 pbuf
->pDevMode
->dmDriverExtra
);
2130 ptr
= GlobalLock(lppd
->hDevMode
);
2131 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
2132 pbuf
->pDevMode
->dmDriverExtra
);
2133 GlobalUnlock(lppd
->hDevMode
);
2134 HeapFree(GetProcessHeap(), 0, pbuf
);
2135 HeapFree(GetProcessHeap(), 0, dbuf
);
2139 PRINT_PTRA
*PrintStructures
;
2141 /* load Dialog resources,
2142 * depending on Flags indicates Print32 or Print32_setup dialog
2144 hDlgTmpl
= PRINTDLG_GetDlgTemplateA(lppd
);
2146 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2149 ptr
= LockResource( hDlgTmpl
);
2151 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2155 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2156 sizeof(PRINT_PTRA
));
2157 PrintStructures
->lpPrintDlg
= lppd
;
2159 /* and create & process the dialog .
2160 * -1 is failure, 0 is broken hwnd, everything else is ok.
2162 hInst
= COMDLG32_hInstance
;
2163 if (lppd
->Flags
& (PD_ENABLESETUPTEMPLATE
| PD_ENABLEPRINTTEMPLATE
)) hInst
= lppd
->hInstance
;
2164 bRet
= (0<DialogBoxIndirectParamA(hInst
, ptr
, lppd
->hwndOwner
,
2166 (LPARAM
)PrintStructures
));
2169 DEVMODEA
*lpdm
= PrintStructures
->lpDevMode
, *lpdmReturn
;
2170 PRINTER_INFO_2A
*pi
= PrintStructures
->lpPrinterInfo
;
2171 DRIVER_INFO_3A
*di
= PrintStructures
->lpDriverInfo
;
2173 if (lppd
->hDevMode
== 0) {
2174 TRACE(" No hDevMode yet... Need to create my own\n");
2175 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
,
2176 lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2178 lppd
->hDevMode
= GlobalReAlloc(lppd
->hDevMode
,
2179 lpdm
->dmSize
+ lpdm
->dmDriverExtra
,
2182 lpdmReturn
= GlobalLock(lppd
->hDevMode
);
2183 memcpy(lpdmReturn
, lpdm
, lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2185 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
2190 GlobalUnlock(lppd
->hDevMode
);
2192 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
2193 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpPrinterInfo
);
2194 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDriverInfo
);
2195 HeapFree(GetProcessHeap(), 0, PrintStructures
);
2197 if(bRet
&& (lppd
->Flags
& PD_RETURNDC
|| lppd
->Flags
& PD_RETURNIC
))
2198 bRet
= PRINTDLG_CreateDCA(lppd
);
2200 TRACE("exit! (%d)\n", bRet
);
2204 /***********************************************************************
2205 * PrintDlgW (COMDLG32.@)
2209 BOOL WINAPI
PrintDlgW(LPPRINTDLGW lppd
)
2217 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
2221 if(TRACE_ON(commdlg
)) {
2222 char flagstr
[1000] = "";
2223 const struct pd_flags
*pflag
= pd_flags
;
2224 for( ; pflag
->name
; pflag
++) {
2225 if(lppd
->Flags
& pflag
->flag
)
2226 strcat(flagstr
, pflag
->name
);
2228 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2229 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2230 "flags %08x (%s)\n",
2231 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
2232 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
2233 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
2236 if(lppd
->lStructSize
!= sizeof(PRINTDLGW
)) {
2237 WARN("structure size failure !!!\n");
2238 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
2242 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
2243 PRINTER_INFO_2W
*pbuf
;
2244 DRIVER_INFO_3W
*dbuf
;
2248 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
2249 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2250 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2253 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
2254 WARN("Can't find default printer\n");
2255 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
2259 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
2260 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
2261 GetPrinterW(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
2263 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
2264 dbuf
= HeapAlloc(GetProcessHeap(),0,needed
);
2265 if (!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
2266 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2267 GetLastError(),debugstr_w(pbuf
->pPrinterName
));
2268 HeapFree(GetProcessHeap(), 0, dbuf
);
2269 HeapFree(GetProcessHeap(), 0, pbuf
);
2270 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2275 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
2279 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
2280 pbuf
->pDevMode
->dmDriverExtra
);
2281 ptr
= GlobalLock(lppd
->hDevMode
);
2282 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
2283 pbuf
->pDevMode
->dmDriverExtra
);
2284 GlobalUnlock(lppd
->hDevMode
);
2285 HeapFree(GetProcessHeap(), 0, pbuf
);
2286 HeapFree(GetProcessHeap(), 0, dbuf
);
2290 PRINT_PTRW
*PrintStructures
;
2292 /* load Dialog resources,
2293 * depending on Flags indicates Print32 or Print32_setup dialog
2295 hDlgTmpl
= PRINTDLG_GetDlgTemplateW(lppd
);
2297 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2300 ptr
= LockResource( hDlgTmpl
);
2302 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2306 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2307 sizeof(PRINT_PTRW
));
2308 PrintStructures
->lpPrintDlg
= lppd
;
2310 /* and create & process the dialog .
2311 * -1 is failure, 0 is broken hwnd, everything else is ok.
2313 hInst
= COMDLG32_hInstance
;
2314 if (lppd
->Flags
& (PD_ENABLESETUPTEMPLATE
| PD_ENABLEPRINTTEMPLATE
)) hInst
= lppd
->hInstance
;
2315 bRet
= (0<DialogBoxIndirectParamW(hInst
, ptr
, lppd
->hwndOwner
,
2317 (LPARAM
)PrintStructures
));
2320 DEVMODEW
*lpdm
= PrintStructures
->lpDevMode
, *lpdmReturn
;
2321 PRINTER_INFO_2W
*pi
= PrintStructures
->lpPrinterInfo
;
2322 DRIVER_INFO_3W
*di
= PrintStructures
->lpDriverInfo
;
2324 if (lppd
->hDevMode
== 0) {
2325 TRACE(" No hDevMode yet... Need to create my own\n");
2326 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
,
2327 lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2330 if((locks
= (GlobalFlags(lppd
->hDevMode
) & GMEM_LOCKCOUNT
))) {
2331 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks
);
2333 GlobalUnlock(lppd
->hDevMode
);
2334 TRACE("Now got %d locks\n", locks
);
2337 lppd
->hDevMode
= GlobalReAlloc(lppd
->hDevMode
,
2338 lpdm
->dmSize
+ lpdm
->dmDriverExtra
,
2341 lpdmReturn
= GlobalLock(lppd
->hDevMode
);
2342 memcpy(lpdmReturn
, lpdm
, lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2344 if (lppd
->hDevNames
!= 0) {
2346 if((locks
= (GlobalFlags(lppd
->hDevNames
) & GMEM_LOCKCOUNT
))) {
2347 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks
);
2349 GlobalUnlock(lppd
->hDevNames
);
2352 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
2357 GlobalUnlock(lppd
->hDevMode
);
2359 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
2360 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpPrinterInfo
);
2361 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDriverInfo
);
2362 HeapFree(GetProcessHeap(), 0, PrintStructures
);
2364 if(bRet
&& (lppd
->Flags
& PD_RETURNDC
|| lppd
->Flags
& PD_RETURNIC
))
2365 bRet
= PRINTDLG_CreateDCW(lppd
);
2367 TRACE("exit! (%d)\n", bRet
);
2371 /***********************************************************************
2376 * cmb1 - printer select (not in standard dialog template)
2378 * cmb3 - source (tray?)
2379 * edt4 - border left
2381 * edt6 - border right
2382 * edt7 - border bottom
2383 * psh3 - "Printer..."
2391 LPPAGESETUPDLGA dlga
;
2392 LPPAGESETUPDLGW dlgw
;
2394 HWND hDlg
; /* Page Setup dialog handle */
2395 RECT rtDrawRect
; /* Drawing rect for page */
2398 static inline DWORD
pagesetup_get_flags(const pagesetup_data
*data
)
2400 return data
->u
.dlgw
->Flags
;
2403 static inline BOOL
is_metric(const pagesetup_data
*data
)
2405 return pagesetup_get_flags(data
) & PSD_INHUNDREDTHSOFMILLIMETERS
;
2408 static inline LONG
tenths_mm_to_size(const pagesetup_data
*data
, LONG size
)
2410 if (is_metric(data
))
2413 return 10 * size
* 100 / 254;
2416 static inline LONG
thousandths_inch_to_size(const pagesetup_data
*data
, LONG size
)
2418 if (is_metric(data
))
2419 return size
* 254 / 100;
2424 static WCHAR
get_decimal_sep(void)
2430 WCHAR buf
[2] = {'.',0};
2431 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SDECIMAL
, buf
, sizeof(buf
) / sizeof(buf
[0]));
2437 static void size2str(const pagesetup_data
*data
, DWORD size
, LPWSTR strout
)
2439 WCHAR integer_fmt
[] = {'%','d',0};
2440 WCHAR hundredths_fmt
[] = {'%','d','%','c','%','0','2','d',0};
2441 WCHAR thousandths_fmt
[] = {'%','d','%','c','%','0','3','d',0};
2443 /* FIXME use LOCALE_SDECIMAL when the edit parsing code can cope */
2445 if (is_metric(data
))
2448 wsprintfW(strout
, hundredths_fmt
, size
/ 100, get_decimal_sep(), size
% 100);
2450 wsprintfW(strout
, integer_fmt
, size
/ 100);
2455 wsprintfW(strout
, thousandths_fmt
, size
/ 1000, get_decimal_sep(), size
% 1000);
2457 wsprintfW(strout
, integer_fmt
, size
/ 1000);
2462 static inline BOOL
is_default_metric(void)
2465 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_IMEASURE
| LOCALE_RETURN_NUMBER
,
2466 (LPWSTR
)&system
, sizeof(system
));
2470 /**********************************************
2472 * Cyclically permute the four members of rc
2473 * If sense is TRUE l -> t -> r -> b
2474 * otherwise l <- t <- r <- b
2476 static inline void rotate_rect(RECT
*rc
, BOOL sense
)
2482 rc
->bottom
= rc
->right
;
2483 rc
->right
= rc
->top
;
2491 rc
->top
= rc
->right
;
2492 rc
->right
= rc
->bottom
;
2497 static void pagesetup_set_orientation(pagesetup_data
*data
, WORD orient
)
2499 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2501 assert(orient
== DMORIENT_PORTRAIT
|| orient
== DMORIENT_LANDSCAPE
);
2504 dm
->u1
.s1
.dmOrientation
= orient
;
2507 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2508 dmA
->u1
.s1
.dmOrientation
= orient
;
2510 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2513 static WORD
pagesetup_get_orientation(const pagesetup_data
*data
)
2515 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2519 orient
= dm
->u1
.s1
.dmOrientation
;
2522 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2523 orient
= dmA
->u1
.s1
.dmOrientation
;
2525 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2529 static void pagesetup_set_papersize(pagesetup_data
*data
, WORD paper
)
2531 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2534 dm
->u1
.s1
.dmPaperSize
= paper
;
2537 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2538 dmA
->u1
.s1
.dmPaperSize
= paper
;
2540 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2543 static WORD
pagesetup_get_papersize(const pagesetup_data
*data
)
2545 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2549 paper
= dm
->u1
.s1
.dmPaperSize
;
2552 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2553 paper
= dmA
->u1
.s1
.dmPaperSize
;
2555 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2559 static void pagesetup_set_defaultsource(pagesetup_data
*data
, WORD source
)
2561 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2564 dm
->u1
.s1
.dmDefaultSource
= source
;
2567 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2568 dmA
->u1
.s1
.dmDefaultSource
= source
;
2570 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2575 devnames_driver_name
,
2576 devnames_device_name
,
2577 devnames_output_name
2581 static inline WORD
get_devname_offset(const DEVNAMES
*dn
, devnames_name which
)
2585 case devnames_driver_name
: return dn
->wDriverOffset
;
2586 case devnames_device_name
: return dn
->wDeviceOffset
;
2587 case devnames_output_name
: return dn
->wOutputOffset
;
2589 ERR("Shouldn't be here\n");
2593 static WCHAR
*pagesetup_get_a_devname(const pagesetup_data
*data
, devnames_name which
)
2598 dn
= GlobalLock(data
->u
.dlgw
->hDevNames
);
2600 name
= strdupW((WCHAR
*)dn
+ get_devname_offset(dn
, which
));
2603 int len
= MultiByteToWideChar(CP_ACP
, 0, (char*)dn
+ get_devname_offset(dn
, which
), -1, NULL
, 0);
2604 name
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
2605 MultiByteToWideChar(CP_ACP
, 0, (char*)dn
+ get_devname_offset(dn
, which
), -1, name
, len
);
2607 GlobalUnlock(data
->u
.dlgw
->hDevNames
);
2611 static WCHAR
*pagesetup_get_drvname(const pagesetup_data
*data
)
2613 return pagesetup_get_a_devname(data
, devnames_driver_name
);
2616 static WCHAR
*pagesetup_get_devname(const pagesetup_data
*data
)
2618 return pagesetup_get_a_devname(data
, devnames_device_name
);
2621 static WCHAR
*pagesetup_get_portname(const pagesetup_data
*data
)
2623 return pagesetup_get_a_devname(data
, devnames_output_name
);
2626 static void pagesetup_release_a_devname(const pagesetup_data
*data
, WCHAR
*name
)
2628 HeapFree(GetProcessHeap(), 0, name
);
2631 static void pagesetup_set_devnames(pagesetup_data
*data
, LPCWSTR drv
, LPCWSTR devname
, LPCWSTR port
)
2635 DWORD len
= sizeof(DEVNAMES
), drv_len
, dev_len
, port_len
;
2639 drv_len
= (strlenW(drv
) + 1) * sizeof(WCHAR
);
2640 dev_len
= (strlenW(devname
) + 1) * sizeof(WCHAR
);
2641 port_len
= (strlenW(port
) + 1) * sizeof(WCHAR
);
2645 drv_len
= WideCharToMultiByte(CP_ACP
, 0, drv
, -1, NULL
, 0, NULL
, NULL
);
2646 dev_len
= WideCharToMultiByte(CP_ACP
, 0, devname
, -1, NULL
, 0, NULL
, NULL
);
2647 port_len
= WideCharToMultiByte(CP_ACP
, 0, port
, -1, NULL
, 0, NULL
, NULL
);
2649 len
+= drv_len
+ dev_len
+ port_len
;
2651 if(data
->u
.dlgw
->hDevNames
)
2652 data
->u
.dlgw
->hDevNames
= GlobalReAlloc(data
->u
.dlgw
->hDevNames
, len
, GMEM_MOVEABLE
);
2654 data
->u
.dlgw
->hDevNames
= GlobalAlloc(GMEM_MOVEABLE
, len
);
2656 dn
= GlobalLock(data
->u
.dlgw
->hDevNames
);
2660 WCHAR
*ptr
= (WCHAR
*)(dn
+ 1);
2661 len
= sizeof(DEVNAMES
) / sizeof(WCHAR
);
2662 dn
->wDriverOffset
= len
;
2664 ptr
+= drv_len
/ sizeof(WCHAR
);
2665 len
+= drv_len
/ sizeof(WCHAR
);
2666 dn
->wDeviceOffset
= len
;
2667 strcpyW(ptr
, devname
);
2668 ptr
+= dev_len
/ sizeof(WCHAR
);
2669 len
+= dev_len
/ sizeof(WCHAR
);
2670 dn
->wOutputOffset
= len
;
2675 char *ptr
= (char *)(dn
+ 1);
2676 len
= sizeof(DEVNAMES
);
2677 dn
->wDriverOffset
= len
;
2678 WideCharToMultiByte(CP_ACP
, 0, drv
, -1, ptr
, drv_len
, NULL
, NULL
);
2681 dn
->wDeviceOffset
= len
;
2682 WideCharToMultiByte(CP_ACP
, 0, devname
, -1, ptr
, dev_len
, NULL
, NULL
);
2685 dn
->wOutputOffset
= len
;
2686 WideCharToMultiByte(CP_ACP
, 0, port
, -1, ptr
, port_len
, NULL
, NULL
);
2690 len
= sizeof(def
) / sizeof(def
[0]);
2691 GetDefaultPrinterW(def
, &len
);
2692 if(!lstrcmpW(def
, devname
))
2695 GlobalUnlock(data
->u
.dlgw
->hDevNames
);
2698 static DEVMODEW
*pagesetup_get_devmode(const pagesetup_data
*data
)
2700 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2705 /* We make a copy even in the unicode case because the ptr
2706 may get passed back to us in pagesetup_set_devmode. */
2707 ret
= HeapAlloc(GetProcessHeap(), 0, dm
->dmSize
+ dm
->dmDriverExtra
);
2708 memcpy(ret
, dm
, dm
->dmSize
+ dm
->dmDriverExtra
);
2711 ret
= GdiConvertToDevmodeW((DEVMODEA
*)dm
);
2713 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2717 static void pagesetup_release_devmode(const pagesetup_data
*data
, DEVMODEW
*dm
)
2719 HeapFree(GetProcessHeap(), 0, dm
);
2722 static void pagesetup_set_devmode(pagesetup_data
*data
, DEVMODEW
*dm
)
2724 DEVMODEA
*dmA
= NULL
;
2730 size
= dm
->dmSize
+ dm
->dmDriverExtra
;
2735 dmA
= convert_to_devmodeA(dm
);
2736 size
= dmA
->dmSize
+ dmA
->dmDriverExtra
;
2740 if(data
->u
.dlgw
->hDevMode
)
2741 data
->u
.dlgw
->hDevMode
= GlobalReAlloc(data
->u
.dlgw
->hDevMode
, size
,
2744 data
->u
.dlgw
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, size
);
2746 dst
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2747 memcpy(dst
, src
, size
);
2748 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2749 HeapFree(GetProcessHeap(), 0, dmA
);
2752 static inline POINT
*pagesetup_get_papersize_pt(const pagesetup_data
*data
)
2754 return &data
->u
.dlgw
->ptPaperSize
;
2757 static inline RECT
*pagesetup_get_margin_rect(const pagesetup_data
*data
)
2759 return &data
->u
.dlgw
->rtMargin
;
2768 static inline LPPAGESETUPHOOK
pagesetup_get_hook(const pagesetup_data
*data
, hook_type which
)
2772 case page_setup_hook
: return data
->u
.dlgw
->lpfnPageSetupHook
;
2773 case page_paint_hook
: return data
->u
.dlgw
->lpfnPagePaintHook
;
2778 /* This should only be used in calls to hook procs so we return the ptr
2779 already cast to LPARAM */
2780 static inline LPARAM
pagesetup_get_dlg_struct(const pagesetup_data
*data
)
2782 return (LPARAM
)data
->u
.dlgw
;
2785 static inline void swap_point(POINT
*pt
)
2792 static BOOL
pagesetup_update_papersize(pagesetup_data
*data
)
2795 LPWSTR devname
, portname
;
2797 WORD
*words
= NULL
, paperword
;
2798 POINT
*points
= NULL
;
2799 BOOL retval
= FALSE
;
2801 dm
= pagesetup_get_devmode(data
);
2802 devname
= pagesetup_get_devname(data
);
2803 portname
= pagesetup_get_portname(data
);
2805 num
= DeviceCapabilitiesW(devname
, portname
, DC_PAPERS
, NULL
, dm
);
2808 FIXME("No papernames found for %s/%s\n", debugstr_w(devname
), debugstr_w(portname
));
2812 words
= HeapAlloc(GetProcessHeap(), 0, num
* sizeof(WORD
));
2813 points
= HeapAlloc(GetProcessHeap(), 0, num
* sizeof(POINT
));
2815 if (num
!= DeviceCapabilitiesW(devname
, portname
, DC_PAPERS
, (LPWSTR
)words
, dm
))
2817 FIXME("Number of returned words is not %d\n", num
);
2821 if (num
!= DeviceCapabilitiesW(devname
, portname
, DC_PAPERSIZE
, (LPWSTR
)points
, dm
))
2823 FIXME("Number of returned sizes is not %d\n", num
);
2827 paperword
= pagesetup_get_papersize(data
);
2829 for (i
= 0; i
< num
; i
++)
2830 if (words
[i
] == paperword
)
2835 FIXME("Papersize %d not found in list?\n", paperword
);
2839 /* this is _10ths_ of a millimeter */
2840 pagesetup_get_papersize_pt(data
)->x
= tenths_mm_to_size(data
, points
[i
].x
);
2841 pagesetup_get_papersize_pt(data
)->y
= tenths_mm_to_size(data
, points
[i
].y
);
2843 if(pagesetup_get_orientation(data
) == DMORIENT_LANDSCAPE
)
2844 swap_point(pagesetup_get_papersize_pt(data
));
2849 HeapFree(GetProcessHeap(), 0, words
);
2850 HeapFree(GetProcessHeap(), 0, points
);
2851 pagesetup_release_a_devname(data
, portname
);
2852 pagesetup_release_a_devname(data
, devname
);
2853 pagesetup_release_devmode(data
, dm
);
2858 /**********************************************************************************************
2859 * pagesetup_change_printer
2861 * Redefines hDevMode and hDevNames HANDLES and initialises it.
2864 static BOOL
pagesetup_change_printer(LPWSTR name
, pagesetup_data
*data
)
2868 PRINTER_INFO_2W
*prn_info
= NULL
;
2869 DRIVER_INFO_3W
*drv_info
= NULL
;
2870 DEVMODEW
*dm
= NULL
;
2871 BOOL retval
= FALSE
;
2873 if(!OpenPrinterW(name
, &hprn
, NULL
))
2875 ERR("Can't open printer %s\n", debugstr_w(name
));
2879 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
2880 prn_info
= HeapAlloc(GetProcessHeap(), 0, needed
);
2881 GetPrinterW(hprn
, 2, (LPBYTE
)prn_info
, needed
, &needed
);
2882 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
2883 drv_info
= HeapAlloc(GetProcessHeap(), 0, needed
);
2884 if(!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)drv_info
, needed
, &needed
))
2886 ERR("GetPrinterDriverA failed for %s, fix your config!\n", debugstr_w(prn_info
->pPrinterName
));
2891 needed
= DocumentPropertiesW(0, 0, name
, NULL
, NULL
, 0);
2894 ERR("DocumentProperties fails on %s\n", debugstr_w(name
));
2898 dm
= HeapAlloc(GetProcessHeap(), 0, needed
);
2899 DocumentPropertiesW(0, 0, name
, dm
, NULL
, DM_OUT_BUFFER
);
2901 pagesetup_set_devmode(data
, dm
);
2902 pagesetup_set_devnames(data
, drv_info
->pDriverPath
, prn_info
->pPrinterName
,
2903 prn_info
->pPortName
);
2907 HeapFree(GetProcessHeap(), 0, dm
);
2908 HeapFree(GetProcessHeap(), 0, prn_info
);
2909 HeapFree(GetProcessHeap(), 0, drv_info
);
2913 /****************************************************************************************
2914 * pagesetup_init_combos
2916 * Fills Printers, Paper and Source combos
2919 static void pagesetup_init_combos(HWND hDlg
, pagesetup_data
*data
)
2922 LPWSTR devname
, portname
;
2924 dm
= pagesetup_get_devmode(data
);
2925 devname
= pagesetup_get_devname(data
);
2926 portname
= pagesetup_get_portname(data
);
2928 PRINTDLG_SetUpPrinterListComboW(hDlg
, cmb1
, devname
);
2929 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb2
, devname
, portname
, dm
);
2930 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb3
, devname
, portname
, dm
);
2932 pagesetup_release_a_devname(data
, portname
);
2933 pagesetup_release_a_devname(data
, devname
);
2934 pagesetup_release_devmode(data
, dm
);
2938 /****************************************************************************************
2939 * pagesetup_change_printer_dialog
2941 * Pops up another dialog that lets the user pick another printer.
2943 * For now we display the PrintDlg, this should display a striped down version of it.
2945 static void pagesetup_change_printer_dialog(HWND hDlg
, pagesetup_data
*data
)
2948 LPWSTR drvname
, devname
, portname
;
2949 DEVMODEW
*tmp_dm
, *dm
;
2951 memset(&prnt
, 0, sizeof(prnt
));
2952 prnt
.lStructSize
= sizeof(prnt
);
2954 prnt
.hwndOwner
= hDlg
;
2956 drvname
= pagesetup_get_drvname(data
);
2957 devname
= pagesetup_get_devname(data
);
2958 portname
= pagesetup_get_portname(data
);
2960 PRINTDLG_CreateDevNamesW(&prnt
.hDevNames
, drvname
, devname
, portname
);
2961 pagesetup_release_a_devname(data
, portname
);
2962 pagesetup_release_a_devname(data
, devname
);
2963 pagesetup_release_a_devname(data
, drvname
);
2965 tmp_dm
= pagesetup_get_devmode(data
);
2966 prnt
.hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, tmp_dm
->dmSize
+ tmp_dm
->dmDriverExtra
);
2967 dm
= GlobalLock(prnt
.hDevMode
);
2968 memcpy(dm
, tmp_dm
, tmp_dm
->dmSize
+ tmp_dm
->dmDriverExtra
);
2969 GlobalUnlock(prnt
.hDevMode
);
2970 pagesetup_release_devmode(data
, tmp_dm
);
2972 if (PrintDlgW(&prnt
))
2974 DEVMODEW
*dm
= GlobalLock(prnt
.hDevMode
);
2975 DEVNAMES
*dn
= GlobalLock(prnt
.hDevNames
);
2977 pagesetup_set_devnames(data
, (WCHAR
*)dn
+ dn
->wDriverOffset
,
2978 (WCHAR
*)dn
+ dn
->wDeviceOffset
, (WCHAR
*)dn
+ dn
->wOutputOffset
);
2979 pagesetup_set_devmode(data
, dm
);
2980 GlobalUnlock(prnt
.hDevNames
);
2981 GlobalUnlock(prnt
.hDevMode
);
2982 pagesetup_init_combos(hDlg
, data
);
2985 GlobalFree(prnt
.hDevMode
);
2986 GlobalFree(prnt
.hDevNames
);
2990 /******************************************************************************************
2991 * pagesetup_change_preview
2993 * Changes paper preview size / position
2996 static void pagesetup_change_preview(const pagesetup_data
*data
)
2998 LONG width
, height
, x
, y
;
3000 const int shadow
= 4;
3002 if(pagesetup_get_orientation(data
) == DMORIENT_LANDSCAPE
)
3004 width
= data
->rtDrawRect
.right
- data
->rtDrawRect
.left
;
3005 height
= pagesetup_get_papersize_pt(data
)->y
* width
/ pagesetup_get_papersize_pt(data
)->x
;
3009 height
= data
->rtDrawRect
.bottom
- data
->rtDrawRect
.top
;
3010 width
= pagesetup_get_papersize_pt(data
)->x
* height
/ pagesetup_get_papersize_pt(data
)->y
;
3012 x
= (data
->rtDrawRect
.right
+ data
->rtDrawRect
.left
- width
) / 2;
3013 y
= (data
->rtDrawRect
.bottom
+ data
->rtDrawRect
.top
- height
) / 2;
3014 TRACE("draw rect %s x=%d, y=%d, w=%d, h=%d\n",
3015 wine_dbgstr_rect(&data
->rtDrawRect
), x
, y
, width
, height
);
3017 MoveWindow(GetDlgItem(data
->hDlg
, rct2
), x
+ width
, y
+ shadow
, shadow
, height
, FALSE
);
3018 MoveWindow(GetDlgItem(data
->hDlg
, rct3
), x
+ shadow
, y
+ height
, width
, shadow
, FALSE
);
3019 MoveWindow(GetDlgItem(data
->hDlg
, rct1
), x
, y
, width
, height
, FALSE
);
3021 tmp
= data
->rtDrawRect
;
3022 tmp
.right
+= shadow
;
3023 tmp
.bottom
+= shadow
;
3024 InvalidateRect(data
->hDlg
, &tmp
, TRUE
);
3027 static inline LONG
*element_from_margin_id(RECT
*rc
, WORD id
)
3031 case edt4
: return &rc
->left
;
3032 case edt5
: return &rc
->top
;
3033 case edt6
: return &rc
->right
;
3034 case edt7
: return &rc
->bottom
;
3039 static void update_margin_edits(HWND hDlg
, const pagesetup_data
*data
, WORD id
)
3044 for(idx
= edt4
; idx
<= edt7
; idx
++)
3046 if(id
== 0 || id
== idx
)
3048 size2str(data
, *element_from_margin_id(pagesetup_get_margin_rect(data
), idx
), str
);
3049 SetDlgItemTextW(hDlg
, idx
, str
);
3054 static void margin_edit_notification(HWND hDlg
, const pagesetup_data
*data
, WORD msg
, WORD id
)
3062 LONG
*value
= element_from_margin_id(pagesetup_get_margin_rect(data
), id
);
3064 if (GetDlgItemTextW(hDlg
, id
, buf
, sizeof(buf
) / sizeof(buf
[0])) != 0)
3067 WCHAR decimal
= get_decimal_sep();
3069 val
= strtolW(buf
, &end
, 10);
3070 if(end
!= buf
|| *end
== decimal
)
3072 int mult
= is_metric(data
) ? 100 : 1000;
3081 val
+= (*end
- '0') * mult
;
3093 update_margin_edits(hDlg
, data
, id
);
3098 static void set_margin_groupbox_title(HWND hDlg
, const pagesetup_data
*data
)
3102 if(LoadStringW(COMDLG32_hInstance
, is_metric(data
) ? PD32_MARGINS_IN_MILLIMETERS
: PD32_MARGINS_IN_INCHES
,
3103 title
, sizeof(title
)/sizeof(title
[0])))
3104 SetDlgItemTextW(hDlg
, grp4
, title
);
3107 static void pagesetup_update_orientation_buttons(HWND hDlg
, const pagesetup_data
*data
)
3109 if (pagesetup_get_orientation(data
) == DMORIENT_LANDSCAPE
)
3110 CheckRadioButton(hDlg
, rad1
, rad2
, rad2
);
3112 CheckRadioButton(hDlg
, rad1
, rad2
, rad1
);
3115 /****************************************************************************************
3116 * pagesetup_printer_properties
3118 * Handle invocation of the 'Properties' button (not present in the default template).
3120 static void pagesetup_printer_properties(HWND hDlg
, pagesetup_data
*data
)
3128 devname
= pagesetup_get_devname(data
);
3130 if (!OpenPrinterW(devname
, &hprn
, NULL
))
3132 FIXME("Call to OpenPrinter did not succeed!\n");
3133 pagesetup_release_a_devname(data
, devname
);
3137 dm
= pagesetup_get_devmode(data
);
3138 DocumentPropertiesW(hDlg
, hprn
, devname
, dm
, dm
, DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
3139 pagesetup_set_devmode(data
, dm
);
3140 pagesetup_release_devmode(data
, dm
);
3141 pagesetup_release_a_devname(data
, devname
);
3144 /* Changing paper */
3145 pagesetup_update_papersize(data
);
3146 pagesetup_update_orientation_buttons(hDlg
, data
);
3148 /* Changing paper preview */
3149 pagesetup_change_preview(data
);
3151 /* Selecting paper in combo */
3152 count
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCOUNT
, 0, 0);
3155 WORD paperword
= pagesetup_get_papersize(data
);
3156 for(i
= 0; i
< count
; i
++)
3158 if(SendDlgItemMessageW(hDlg
, cmb2
, CB_GETITEMDATA
, i
, 0) == paperword
) {
3159 SendDlgItemMessageW(hDlg
, cmb2
, CB_SETCURSEL
, i
, 0);
3166 /********************************************************************************
3167 * pagesetup_wm_command
3168 * process WM_COMMAND message for PageSetupDlg
3171 * hDlg [in] Main dialog HANDLE
3172 * wParam [in] WM_COMMAND wParam
3173 * lParam [in] WM_COMMAND lParam
3174 * pda [in/out] ptr to PageSetupDataA
3177 static BOOL
pagesetup_wm_command(HWND hDlg
, WPARAM wParam
, LPARAM lParam
, pagesetup_data
*data
)
3179 WORD msg
= HIWORD(wParam
);
3180 WORD id
= LOWORD(wParam
);
3182 TRACE("loword (lparam) %d, wparam 0x%lx, lparam %08lx\n",
3183 LOWORD(lParam
),wParam
,lParam
);
3186 EndDialog(hDlg
, TRUE
);
3190 EndDialog(hDlg
, FALSE
);
3193 case psh3
: /* Printer... */
3194 pagesetup_change_printer_dialog(hDlg
, data
);
3197 case rad1
: /* Portrait */
3198 case rad2
: /* Landscape */
3199 if((id
== rad1
&& pagesetup_get_orientation(data
) == DMORIENT_LANDSCAPE
) ||
3200 (id
== rad2
&& pagesetup_get_orientation(data
) == DMORIENT_PORTRAIT
))
3202 pagesetup_set_orientation(data
, (id
== rad1
) ? DMORIENT_PORTRAIT
: DMORIENT_LANDSCAPE
);
3203 pagesetup_update_papersize(data
);
3204 rotate_rect(pagesetup_get_margin_rect(data
), (id
== rad2
));
3205 update_margin_edits(hDlg
, data
, 0);
3206 pagesetup_change_preview(data
);
3209 case cmb1
: /* Printer combo */
3210 if(msg
== CBN_SELCHANGE
)
3213 GetDlgItemTextW(hDlg
, id
, name
, sizeof(name
) / sizeof(name
[0]));
3214 pagesetup_change_printer(name
, data
);
3215 pagesetup_init_combos(hDlg
, data
);
3218 case cmb2
: /* Paper combo */
3219 if(msg
== CBN_SELCHANGE
)
3221 DWORD paperword
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETITEMDATA
,
3222 SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0), 0);
3223 if (paperword
!= CB_ERR
)
3225 pagesetup_set_papersize(data
, paperword
);
3226 pagesetup_update_papersize(data
);
3227 pagesetup_change_preview(data
);
3229 FIXME("could not get dialog text for papersize cmbbox?\n");
3232 case cmb3
: /* Paper Source */
3233 if(msg
== CBN_SELCHANGE
)
3235 WORD source
= SendDlgItemMessageW(hDlg
, cmb3
, CB_GETITEMDATA
,
3236 SendDlgItemMessageW(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0), 0);
3237 pagesetup_set_defaultsource(data
, source
);
3240 case psh2
: /* Printer Properties button */
3241 pagesetup_printer_properties(hDlg
, data
);
3247 margin_edit_notification(hDlg
, data
, msg
, id
);
3250 InvalidateRect(GetDlgItem(hDlg
, rct1
), NULL
, TRUE
);
3254 /***********************************************************************
3255 * default_page_paint_hook
3256 * Default hook paint procedure that receives WM_PSD_* messages from the dialog box
3257 * whenever the sample page is redrawn.
3259 static UINT_PTR
default_page_paint_hook(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
,
3260 const pagesetup_data
*data
)
3262 LPRECT lprc
= (LPRECT
) lParam
;
3263 HDC hdc
= (HDC
) wParam
;
3266 HFONT hfont
, holdfont
;
3268 TRACE("uMsg: WM_USER+%d\n",uMsg
-WM_USER
);
3269 /* Call user paint hook if enable */
3270 if (pagesetup_get_flags(data
) & PSD_ENABLEPAGEPAINTHOOK
)
3271 if (pagesetup_get_hook(data
, page_paint_hook
)(hwndDlg
, uMsg
, wParam
, lParam
))
3275 /* LPPAGESETUPDLG in lParam */
3276 case WM_PSD_PAGESETUPDLG
:
3277 /* Inform about the sample page rectangle */
3278 case WM_PSD_FULLPAGERECT
:
3279 /* Inform about the margin rectangle */
3280 case WM_PSD_MINMARGINRECT
:
3283 /* Draw dashed rectangle showing margins */
3284 case WM_PSD_MARGINRECT
:
3285 hpen
= CreatePen(PS_DASH
, 1, GetSysColor(COLOR_3DSHADOW
));
3286 holdpen
= SelectObject(hdc
, hpen
);
3287 Rectangle(hdc
, lprc
->left
, lprc
->top
, lprc
->right
, lprc
->bottom
);
3288 DeleteObject(SelectObject(hdc
, holdpen
));
3290 /* Draw the fake document */
3291 case WM_PSD_GREEKTEXTRECT
:
3292 /* select a nice scalable font, because we want the text really small */
3293 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, sizeof(lf
), &lf
, 0);
3294 lf
.lfHeight
= 6; /* value chosen based on visual effect */
3295 hfont
= CreateFontIndirectW(&lf
);
3296 holdfont
= SelectObject(hdc
, hfont
);
3298 /* if text not loaded, then do so now */
3299 if (wszFakeDocumentText
[0] == '\0')
3300 LoadStringW(COMDLG32_hInstance
,
3302 wszFakeDocumentText
,
3303 sizeof(wszFakeDocumentText
)/sizeof(wszFakeDocumentText
[0]));
3305 oldbkmode
= SetBkMode(hdc
, TRANSPARENT
);
3306 DrawTextW(hdc
, wszFakeDocumentText
, -1, lprc
, DT_TOP
|DT_LEFT
|DT_NOPREFIX
|DT_WORDBREAK
);
3307 SetBkMode(hdc
, oldbkmode
);
3309 DeleteObject(SelectObject(hdc
, holdfont
));
3312 /* Envelope stamp */
3313 case WM_PSD_ENVSTAMPRECT
:
3314 /* Return address */
3315 case WM_PSD_YAFULLPAGERECT
:
3316 FIXME("envelope/stamp is not implemented\n");
3319 FIXME("Unknown message %x\n",uMsg
);
3325 /***********************************************************************
3327 * The main paint procedure for the PageSetupDlg function.
3328 * The Page Setup dialog box includes an image of a sample page that shows how
3329 * the user's selections affect the appearance of the printed output.
3330 * The image consists of a rectangle that represents the selected paper
3331 * or envelope type, with a dotted-line rectangle representing
3332 * the current margins, and partial (Greek text) characters
3333 * to show how text looks on the printed page.
3335 * The following messages in the order sends to user hook procedure:
3336 * WM_PSD_PAGESETUPDLG Draw the contents of the sample page
3337 * WM_PSD_FULLPAGERECT Inform about the bounding rectangle
3338 * WM_PSD_MINMARGINRECT Inform about the margin rectangle (min margin?)
3339 * WM_PSD_MARGINRECT Draw the margin rectangle
3340 * WM_PSD_GREEKTEXTRECT Draw the Greek text inside the margin rectangle
3341 * If any of first three messages returns TRUE, painting done.
3344 * hWnd [in] Handle to the Page Setup dialog box
3345 * uMsg [in] Received message
3348 * WM_PSD_ENVSTAMPRECT Draw in the envelope-stamp rectangle (for envelopes only)
3349 * WM_PSD_YAFULLPAGERECT Draw the return address portion (for envelopes and other paper sizes)
3352 * FALSE if all done correctly
3357 static LRESULT CALLBACK
3358 PRINTDLG_PagePaintProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3361 RECT rcClient
, rcMargin
;
3364 HBRUSH hbrush
, holdbrush
;
3365 pagesetup_data
*data
;
3366 int papersize
=0, orientation
=0; /* FIXME: set these values for the user paint hook */
3367 double scalx
, scaly
;
3369 if (uMsg
!= WM_PAINT
)
3370 return CallWindowProcA(lpfnStaticWndProc
, hWnd
, uMsg
, wParam
, lParam
);
3372 /* Processing WM_PAINT message */
3373 data
= GetPropW(hWnd
, pagesetupdlg_prop
);
3375 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3378 if (default_page_paint_hook(hWnd
, WM_PSD_PAGESETUPDLG
, MAKELONG(papersize
, orientation
),
3379 pagesetup_get_dlg_struct(data
), data
))
3382 hdc
= BeginPaint(hWnd
, &ps
);
3383 GetClientRect(hWnd
, &rcClient
);
3385 scalx
= rcClient
.right
/ (double)pagesetup_get_papersize_pt(data
)->x
;
3386 scaly
= rcClient
.bottom
/ (double)pagesetup_get_papersize_pt(data
)->y
;
3387 rcMargin
= rcClient
;
3389 rcMargin
.left
+= pagesetup_get_margin_rect(data
)->left
* scalx
;
3390 rcMargin
.top
+= pagesetup_get_margin_rect(data
)->top
* scaly
;
3391 rcMargin
.right
-= pagesetup_get_margin_rect(data
)->right
* scalx
;
3392 rcMargin
.bottom
-= pagesetup_get_margin_rect(data
)->bottom
* scaly
;
3394 /* if the space is too small then we make sure to not draw anything */
3395 rcMargin
.left
= min(rcMargin
.left
, rcMargin
.right
);
3396 rcMargin
.top
= min(rcMargin
.top
, rcMargin
.bottom
);
3398 if (!default_page_paint_hook(hWnd
, WM_PSD_FULLPAGERECT
, (WPARAM
)hdc
, (LPARAM
)&rcClient
, data
) &&
3399 !default_page_paint_hook(hWnd
, WM_PSD_MINMARGINRECT
, (WPARAM
)hdc
, (LPARAM
)&rcMargin
, data
) )
3401 /* fill background */
3402 hbrush
= GetSysColorBrush(COLOR_3DHIGHLIGHT
);
3403 FillRect(hdc
, &rcClient
, hbrush
);
3404 holdbrush
= SelectObject(hdc
, hbrush
);
3406 hpen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DSHADOW
));
3407 holdpen
= SelectObject(hdc
, hpen
);
3409 /* paint left edge */
3410 MoveToEx(hdc
, rcClient
.left
, rcClient
.top
, NULL
);
3411 LineTo(hdc
, rcClient
.left
, rcClient
.bottom
-1);
3413 /* paint top edge */
3414 MoveToEx(hdc
, rcClient
.left
, rcClient
.top
, NULL
);
3415 LineTo(hdc
, rcClient
.right
, rcClient
.top
);
3417 hpen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DDKSHADOW
));
3418 DeleteObject(SelectObject(hdc
, hpen
));
3420 /* paint right edge */
3421 MoveToEx(hdc
, rcClient
.right
-1, rcClient
.top
, NULL
);
3422 LineTo(hdc
, rcClient
.right
-1, rcClient
.bottom
);
3424 /* paint bottom edge */
3425 MoveToEx(hdc
, rcClient
.left
, rcClient
.bottom
-1, NULL
);
3426 LineTo(hdc
, rcClient
.right
, rcClient
.bottom
-1);
3428 DeleteObject(SelectObject(hdc
, holdpen
));
3429 DeleteObject(SelectObject(hdc
, holdbrush
));
3431 default_page_paint_hook(hWnd
, WM_PSD_MARGINRECT
, (WPARAM
)hdc
, (LPARAM
)&rcMargin
, data
);
3433 /* give text a bit of a space from the frame */
3436 rcMargin
.right
-= 2;
3437 rcMargin
.bottom
-= 2;
3439 /* if the space is too small then we make sure to not draw anything */
3440 rcMargin
.left
= min(rcMargin
.left
, rcMargin
.right
);
3441 rcMargin
.top
= min(rcMargin
.top
, rcMargin
.bottom
);
3443 default_page_paint_hook(hWnd
, WM_PSD_GREEKTEXTRECT
, (WPARAM
)hdc
, (LPARAM
)&rcMargin
, data
);
3446 EndPaint(hWnd
, &ps
);
3450 /*******************************************************
3451 * The margin edit controls are subclassed to filter
3452 * anything other than numbers and the decimal separator.
3454 static LRESULT CALLBACK
pagesetup_margin_editproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3458 WCHAR decimal
= get_decimal_sep();
3459 WCHAR wc
= (WCHAR
)wparam
;
3460 if(!isdigitW(wc
) && wc
!= decimal
&& wc
!= VK_BACK
) return 0;
3462 return CallWindowProcW(edit_wndproc
, hwnd
, msg
, wparam
, lparam
);
3465 static void subclass_margin_edits(HWND hDlg
)
3470 for(id
= edt4
; id
<= edt7
; id
++)
3472 old_proc
= (WNDPROC
)SetWindowLongPtrW(GetDlgItem(hDlg
, id
),
3474 (ULONG_PTR
)pagesetup_margin_editproc
);
3475 InterlockedCompareExchangePointer((void**)&edit_wndproc
, old_proc
, NULL
);
3479 /***********************************************************************
3480 * pagesetup_dlg_proc
3482 * Message handler for PageSetupDlg
3484 static INT_PTR CALLBACK
pagesetup_dlg_proc(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3486 pagesetup_data
*data
;
3487 INT_PTR res
= FALSE
;
3490 if (uMsg
== WM_INITDIALOG
) { /*Init dialog*/
3491 data
= (pagesetup_data
*)lParam
;
3494 hDrawWnd
= GetDlgItem(hDlg
, rct1
);
3495 TRACE("set property to %p\n", data
);
3496 SetPropW(hDlg
, pagesetupdlg_prop
, data
);
3497 SetPropW(hDrawWnd
, pagesetupdlg_prop
, data
);
3498 GetWindowRect(hDrawWnd
, &data
->rtDrawRect
); /* Calculating rect in client coordinates where paper draws */
3499 MapWindowPoints( 0, hDlg
, (LPPOINT
)&data
->rtDrawRect
, 2 );
3500 lpfnStaticWndProc
= (WNDPROC
)SetWindowLongPtrW(
3503 (ULONG_PTR
)PRINTDLG_PagePaintProc
);
3505 /* FIXME: Paint hook. Must it be at begin of initialization or at end? */
3507 if (pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPHOOK
)
3509 if (!pagesetup_get_hook(data
, page_setup_hook
)(hDlg
, uMsg
, wParam
,
3510 pagesetup_get_dlg_struct(data
)))
3511 FIXME("Setup page hook failed?\n");
3514 /* if printer button disabled */
3515 if (pagesetup_get_flags(data
) & PSD_DISABLEPRINTER
)
3516 EnableWindow(GetDlgItem(hDlg
, psh3
), FALSE
);
3517 /* if margin edit boxes disabled */
3518 if (pagesetup_get_flags(data
) & PSD_DISABLEMARGINS
)
3520 EnableWindow(GetDlgItem(hDlg
, edt4
), FALSE
);
3521 EnableWindow(GetDlgItem(hDlg
, edt5
), FALSE
);
3522 EnableWindow(GetDlgItem(hDlg
, edt6
), FALSE
);
3523 EnableWindow(GetDlgItem(hDlg
, edt7
), FALSE
);
3526 /* Set orientation radiobuttons properly */
3527 pagesetup_update_orientation_buttons(hDlg
, data
);
3529 /* if orientation disabled */
3530 if (pagesetup_get_flags(data
) & PSD_DISABLEORIENTATION
)
3532 EnableWindow(GetDlgItem(hDlg
,rad1
),FALSE
);
3533 EnableWindow(GetDlgItem(hDlg
,rad2
),FALSE
);
3536 /* We fill them out enabled or not */
3537 if (!(pagesetup_get_flags(data
) & PSD_MARGINS
))
3539 /* default is 1 inch */
3540 LONG size
= thousandths_inch_to_size(data
, 1000);
3541 SetRect(pagesetup_get_margin_rect(data
), size
, size
, size
, size
);
3543 update_margin_edits(hDlg
, data
, 0);
3544 subclass_margin_edits(hDlg
);
3545 set_margin_groupbox_title(hDlg
, data
);
3547 /* if paper disabled */
3548 if (pagesetup_get_flags(data
) & PSD_DISABLEPAPER
)
3550 EnableWindow(GetDlgItem(hDlg
,cmb2
),FALSE
);
3551 EnableWindow(GetDlgItem(hDlg
,cmb3
),FALSE
);
3554 /* filling combos: printer, paper, source. selecting current printer (from DEVMODEA) */
3555 pagesetup_init_combos(hDlg
, data
);
3556 pagesetup_update_papersize(data
);
3557 pagesetup_set_defaultsource(data
, DMBIN_FORMSOURCE
); /* FIXME: This is the auto select bin. Is this correct? */
3559 /* Drawing paper prev */
3560 pagesetup_change_preview(data
);
3563 data
= GetPropW(hDlg
, pagesetupdlg_prop
);
3566 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3569 if (pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPHOOK
)
3571 res
= pagesetup_get_hook(data
, page_setup_hook
)(hDlg
, uMsg
, wParam
, lParam
);
3572 if (res
) return res
;
3577 return pagesetup_wm_command(hDlg
, wParam
, lParam
, data
);
3582 static WCHAR
*get_default_printer(void)
3587 GetDefaultPrinterW(NULL
, &len
);
3590 name
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3591 GetDefaultPrinterW(name
, &len
);
3596 static void pagesetup_dump_dlg_struct(const pagesetup_data
*data
)
3598 if(TRACE_ON(commdlg
))
3600 char flagstr
[1000] = "";
3601 const struct pd_flags
*pflag
= psd_flags
;
3602 for( ; pflag
->name
; pflag
++)
3604 if(pagesetup_get_flags(data
) & pflag
->flag
)
3606 strcat(flagstr
, pflag
->name
);
3607 strcat(flagstr
, "|");
3610 TRACE("%s: (%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3611 "hinst %p, flags %08x (%s)\n",
3612 data
->unicode
? "unicode" : "ansi",
3613 data
->u
.dlgw
, data
->u
.dlgw
->hwndOwner
, data
->u
.dlgw
->hDevMode
,
3614 data
->u
.dlgw
->hDevNames
, data
->u
.dlgw
->hInstance
,
3615 pagesetup_get_flags(data
), flagstr
);
3619 static void *pagesetup_get_template(pagesetup_data
*data
)
3622 HGLOBAL tmpl_handle
;
3624 if(pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPTEMPLATEHANDLE
)
3626 tmpl_handle
= data
->u
.dlgw
->hPageSetupTemplate
;
3628 else if(pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPTEMPLATE
)
3631 res
= FindResourceW(data
->u
.dlgw
->hInstance
,
3632 data
->u
.dlgw
->lpPageSetupTemplateName
, MAKEINTRESOURCEW(RT_DIALOG
));
3634 res
= FindResourceA(data
->u
.dlga
->hInstance
,
3635 data
->u
.dlga
->lpPageSetupTemplateName
, MAKEINTRESOURCEA(RT_DIALOG
));
3636 tmpl_handle
= LoadResource(data
->u
.dlgw
->hInstance
, res
);
3640 res
= FindResourceW(COMDLG32_hInstance
, MAKEINTRESOURCEW(PAGESETUPDLGORD
),
3641 MAKEINTRESOURCEW(RT_DIALOG
));
3642 tmpl_handle
= LoadResource(COMDLG32_hInstance
, res
);
3644 return LockResource(tmpl_handle
);
3647 static BOOL
pagesetup_common(pagesetup_data
*data
)
3652 if(!pagesetup_get_dlg_struct(data
))
3654 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
3658 pagesetup_dump_dlg_struct(data
);
3660 if(data
->u
.dlgw
->lStructSize
!= sizeof(PAGESETUPDLGW
))
3662 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
3666 if ((pagesetup_get_flags(data
) & PSD_ENABLEPAGEPAINTHOOK
) &&
3667 (pagesetup_get_hook(data
, page_paint_hook
) == NULL
))
3669 COMDLG32_SetCommDlgExtendedError(CDERR_NOHOOK
);
3673 if(!(pagesetup_get_flags(data
) & (PSD_INTHOUSANDTHSOFINCHES
| PSD_INHUNDREDTHSOFMILLIMETERS
)))
3674 data
->u
.dlgw
->Flags
|= is_default_metric() ?
3675 PSD_INHUNDREDTHSOFMILLIMETERS
: PSD_INTHOUSANDTHSOFINCHES
;
3677 if (!data
->u
.dlgw
->hDevMode
|| !data
->u
.dlgw
->hDevNames
)
3679 WCHAR
*def
= get_default_printer();
3682 if (!(pagesetup_get_flags(data
) & PSD_NOWARNING
))
3685 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEFAULT_PRINTER
, errstr
, 255);
3686 MessageBoxW(data
->u
.dlgw
->hwndOwner
, errstr
, 0, MB_OK
| MB_ICONERROR
);
3688 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
3691 pagesetup_change_printer(def
, data
);
3692 HeapFree(GetProcessHeap(), 0, def
);
3695 if (pagesetup_get_flags(data
) & PSD_RETURNDEFAULT
)
3697 pagesetup_update_papersize(data
);
3701 tmpl
= pagesetup_get_template(data
);
3703 ret
= DialogBoxIndirectParamW(data
->u
.dlgw
->hInstance
, tmpl
,
3704 data
->u
.dlgw
->hwndOwner
,
3705 pagesetup_dlg_proc
, (LPARAM
)data
) > 0;
3709 /***********************************************************************
3710 * PageSetupDlgA (COMDLG32.@)
3712 * Displays the PAGE SETUP dialog box, which enables the user to specify
3713 * specific properties of a printed page such as
3714 * size, source, orientation and the width of the page margins.
3717 * setupdlg [IO] PAGESETUPDLGA struct
3720 * TRUE if the user pressed the OK button
3721 * FALSE if the user cancelled the window or an error occurred
3724 * The values of hDevMode and hDevNames are filled on output and can be
3725 * changed in PAGESETUPDLG when they are passed in PageSetupDlg.
3728 BOOL WINAPI
PageSetupDlgA(LPPAGESETUPDLGA setupdlg
)
3730 pagesetup_data data
;
3732 data
.unicode
= FALSE
;
3733 data
.u
.dlga
= setupdlg
;
3735 return pagesetup_common(&data
);
3738 /***********************************************************************
3739 * PageSetupDlgW (COMDLG32.@)
3741 * See PageSetupDlgA.
3743 BOOL WINAPI
PageSetupDlgW(LPPAGESETUPDLGW setupdlg
)
3745 pagesetup_data data
;
3747 data
.unicode
= TRUE
;
3748 data
.u
.dlgw
= setupdlg
;
3750 return pagesetup_common(&data
);
3753 /***********************************************************************
3754 * PrintDlgExA (COMDLG32.@)
3762 HRESULT WINAPI
PrintDlgExA(LPPRINTDLGEXA lppd
)
3767 FIXME("(%p) not fully implemented\n", lppd
);
3768 if ((lppd
== NULL
) || (lppd
->lStructSize
!= sizeof(PRINTDLGEXA
)))
3769 return E_INVALIDARG
;
3771 if (!IsWindow(lppd
->hwndOwner
))
3774 if (lppd
->Flags
& PD_RETURNDEFAULT
)
3776 PRINTER_INFO_2A
*pbuf
;
3777 DRIVER_INFO_2A
*dbuf
;
3779 DWORD needed
= 1024;
3782 if (lppd
->hDevMode
|| lppd
->hDevNames
)
3784 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
3785 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
3786 return E_INVALIDARG
;
3788 if (!PRINTDLG_OpenDefaultPrinter(&hprn
))
3790 WARN("Can't find default printer\n");
3791 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
3795 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
3796 bRet
= GetPrinterA(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
3797 if (!bRet
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
3799 HeapFree(GetProcessHeap(), 0, pbuf
);
3800 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
3801 bRet
= GetPrinterA(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
3805 HeapFree(GetProcessHeap(), 0, pbuf
);
3811 dbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
3812 bRet
= GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
);
3813 if (!bRet
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
3815 HeapFree(GetProcessHeap(), 0, dbuf
);
3816 dbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
3817 bRet
= GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
);
3821 ERR("GetPrinterDriverŠ failed, last error %d, fix your config for printer %s!\n",
3822 GetLastError(), pbuf
->pPrinterName
);
3823 HeapFree(GetProcessHeap(), 0, dbuf
);
3824 HeapFree(GetProcessHeap(), 0, pbuf
);
3825 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
3831 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
3835 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
3836 pbuf
->pDevMode
->dmDriverExtra
);
3839 ptr
= GlobalLock(lppd
->hDevMode
);
3842 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
3843 pbuf
->pDevMode
->dmDriverExtra
);
3844 GlobalUnlock(lppd
->hDevMode
);
3848 HeapFree(GetProcessHeap(), 0, pbuf
);
3849 HeapFree(GetProcessHeap(), 0, dbuf
);
3857 /***********************************************************************
3858 * PrintDlgExW (COMDLG32.@)
3860 * Display the property sheet style PRINT dialog box
3863 * lppd [IO] ptr to PRINTDLGEX struct
3867 * Failure: One of the following COM error codes:
3868 * E_OUTOFMEMORY Insufficient memory.
3869 * E_INVALIDARG One or more arguments are invalid.
3870 * E_POINTER Invalid pointer.
3871 * E_HANDLE Invalid handle.
3872 * E_FAIL Unspecified error.
3875 * This Dialog enables the user to specify specific properties of the print job.
3876 * The property sheet can also have additional application-specific and
3877 * driver-specific property pages.
3880 * Not fully implemented
3883 HRESULT WINAPI
PrintDlgExW(LPPRINTDLGEXW lppd
)
3888 FIXME("(%p) not fully implemented\n", lppd
);
3890 if ((lppd
== NULL
) || (lppd
->lStructSize
!= sizeof(PRINTDLGEXW
))) {
3891 return E_INVALIDARG
;
3894 if (!IsWindow(lppd
->hwndOwner
)) {
3898 if (lppd
->Flags
& PD_RETURNDEFAULT
) {
3899 PRINTER_INFO_2W
*pbuf
;
3900 DRIVER_INFO_2W
*dbuf
;
3902 DWORD needed
= 1024;
3905 if (lppd
->hDevMode
|| lppd
->hDevNames
) {
3906 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
3907 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
3908 return E_INVALIDARG
;
3910 if (!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
3911 WARN("Can't find default printer\n");
3912 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
3916 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
3917 bRet
= GetPrinterW(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
3918 if (!bRet
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
3919 HeapFree(GetProcessHeap(), 0, pbuf
);
3920 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
3921 bRet
= GetPrinterW(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
3924 HeapFree(GetProcessHeap(), 0, pbuf
);
3930 dbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
3931 bRet
= GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
);
3932 if (!bRet
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
3933 HeapFree(GetProcessHeap(), 0, dbuf
);
3934 dbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
3935 bRet
= GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
);
3938 ERR("GetPrinterDriverW failed, last error %d, fix your config for printer %s!\n",
3939 GetLastError(), debugstr_w(pbuf
->pPrinterName
));
3940 HeapFree(GetProcessHeap(), 0, dbuf
);
3941 HeapFree(GetProcessHeap(), 0, pbuf
);
3942 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
3948 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
3952 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
3953 pbuf
->pDevMode
->dmDriverExtra
);
3954 if (lppd
->hDevMode
) {
3955 ptr
= GlobalLock(lppd
->hDevMode
);
3957 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
3958 pbuf
->pDevMode
->dmDriverExtra
);
3959 GlobalUnlock(lppd
->hDevMode
);
3963 HeapFree(GetProcessHeap(), 0, pbuf
);
3964 HeapFree(GetProcessHeap(), 0, dbuf
);