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
30 /* Yes these constants are the same, but we're just copying win98 */
31 #define UPDOWN_ID 0x270f
32 #define MAX_COPIES 9999
34 /* This PRINTDLGA internal structure stores
35 * pointers to several throughout useful structures.
41 LPPRINTDLGA lpPrintDlg
;
42 LPPRINTER_INFO_2A lpPrinterInfo
;
43 LPDRIVER_INFO_3A lpDriverInfo
;
45 HICON hCollateIcon
; /* PrintDlg only */
46 HICON hNoCollateIcon
; /* PrintDlg only */
47 HICON hPortraitIcon
; /* PrintSetupDlg only */
48 HICON hLandscapeIcon
; /* PrintSetupDlg only */
55 LPPRINTDLGW lpPrintDlg
;
56 LPPRINTER_INFO_2W lpPrinterInfo
;
57 LPDRIVER_INFO_3W lpDriverInfo
;
59 HICON hCollateIcon
; /* PrintDlg only */
60 HICON hNoCollateIcon
; /* PrintDlg only */
61 HICON hPortraitIcon
; /* PrintSetupDlg only */
62 HICON hLandscapeIcon
; /* PrintSetupDlg only */
73 static const struct pd_flags psd_flags
[] = {
74 {PSD_MINMARGINS
,"PSD_MINMARGINS"},
75 {PSD_MARGINS
,"PSD_MARGINS"},
76 {PSD_INTHOUSANDTHSOFINCHES
,"PSD_INTHOUSANDTHSOFINCHES"},
77 {PSD_INHUNDREDTHSOFMILLIMETERS
,"PSD_INHUNDREDTHSOFMILLIMETERS"},
78 {PSD_DISABLEMARGINS
,"PSD_DISABLEMARGINS"},
79 {PSD_DISABLEPRINTER
,"PSD_DISABLEPRINTER"},
80 {PSD_NOWARNING
,"PSD_NOWARNING"},
81 {PSD_DISABLEORIENTATION
,"PSD_DISABLEORIENTATION"},
82 {PSD_RETURNDEFAULT
,"PSD_RETURNDEFAULT"},
83 {PSD_DISABLEPAPER
,"PSD_DISABLEPAPER"},
84 {PSD_SHOWHELP
,"PSD_SHOWHELP"},
85 {PSD_ENABLEPAGESETUPHOOK
,"PSD_ENABLEPAGESETUPHOOK"},
86 {PSD_ENABLEPAGESETUPTEMPLATE
,"PSD_ENABLEPAGESETUPTEMPLATE"},
87 {PSD_ENABLEPAGESETUPTEMPLATEHANDLE
,"PSD_ENABLEPAGESETUPTEMPLATEHANDLE"},
88 {PSD_ENABLEPAGEPAINTHOOK
,"PSD_ENABLEPAGEPAINTHOOK"},
89 {PSD_DISABLEPAGEPAINTING
,"PSD_DISABLEPAGEPAINTING"},
93 static const struct pd_flags pd_flags
[] = {
94 {PD_SELECTION
, "PD_SELECTION "},
95 {PD_PAGENUMS
, "PD_PAGENUMS "},
96 {PD_NOSELECTION
, "PD_NOSELECTION "},
97 {PD_NOPAGENUMS
, "PD_NOPAGENUMS "},
98 {PD_COLLATE
, "PD_COLLATE "},
99 {PD_PRINTTOFILE
, "PD_PRINTTOFILE "},
100 {PD_PRINTSETUP
, "PD_PRINTSETUP "},
101 {PD_NOWARNING
, "PD_NOWARNING "},
102 {PD_RETURNDC
, "PD_RETURNDC "},
103 {PD_RETURNIC
, "PD_RETURNIC "},
104 {PD_RETURNDEFAULT
, "PD_RETURNDEFAULT "},
105 {PD_SHOWHELP
, "PD_SHOWHELP "},
106 {PD_ENABLEPRINTHOOK
, "PD_ENABLEPRINTHOOK "},
107 {PD_ENABLESETUPHOOK
, "PD_ENABLESETUPHOOK "},
108 {PD_ENABLEPRINTTEMPLATE
, "PD_ENABLEPRINTTEMPLATE "},
109 {PD_ENABLESETUPTEMPLATE
, "PD_ENABLESETUPTEMPLATE "},
110 {PD_ENABLEPRINTTEMPLATEHANDLE
, "PD_ENABLEPRINTTEMPLATEHANDLE "},
111 {PD_ENABLESETUPTEMPLATEHANDLE
, "PD_ENABLESETUPTEMPLATEHANDLE "},
112 {PD_USEDEVMODECOPIES
, "PD_USEDEVMODECOPIES[ANDCOLLATE] "},
113 {PD_DISABLEPRINTTOFILE
, "PD_DISABLEPRINTTOFILE "},
114 {PD_HIDEPRINTTOFILE
, "PD_HIDEPRINTTOFILE "},
115 {PD_NONETWORKBUTTON
, "PD_NONETWORKBUTTON "},
118 /* address of wndproc for subclassed Static control */
119 static WNDPROC lpfnStaticWndProc
;
120 static WNDPROC edit_wndproc
;
121 /* the text of the fake document to render for the Page Setup dialog */
122 static WCHAR wszFakeDocumentText
[1024];
123 static const WCHAR pd32_collateW
[] = { 'P', 'D', '3', '2', '_', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
124 static const WCHAR pd32_nocollateW
[] = { 'P', 'D', '3', '2', '_', 'N', 'O', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
125 static const WCHAR pd32_portraitW
[] = { 'P', 'D', '3', '2', '_', 'P', 'O', 'R', 'T', 'R', 'A', 'I', 'T', 0 };
126 static const WCHAR pd32_landscapeW
[] = { 'P', 'D', '3', '2', '_', 'L', 'A', 'N', 'D', 'S', 'C', 'A', 'P', 'E', 0 };
127 static const WCHAR printdlg_prop
[] = {'_','_','W','I','N','E','_','P','R','I','N','T','D','L','G','D','A','T','A',0};
128 static const WCHAR pagesetupdlg_prop
[] = { '_', '_', 'W', 'I', 'N', 'E', '_', 'P', 'A', 'G', 'E',
129 'S', 'E', 'T', 'U', 'P', 'D', 'L', 'G', 'D', 'A', 'T', 'A', 0 };
132 static LPWSTR
strdupW(LPCWSTR p
)
138 len
= (strlenW(p
) + 1) * sizeof(WCHAR
);
139 ret
= HeapAlloc(GetProcessHeap(), 0, len
);
144 /***********************************************************************
145 * get_driver_info [internal]
147 * get DRIVER_INFO_3W for the current printer handle,
148 * alloc the buffer, when needed
150 static DRIVER_INFO_3W
* get_driver_infoW(HANDLE hprn
)
152 DRIVER_INFO_3W
*di3
= NULL
;
156 res
= GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
157 if (!res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
158 di3
= HeapAlloc(GetProcessHeap(), 0, needed
);
159 res
= GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)di3
, needed
, &needed
);
165 TRACE("GetPrinterDriverW failed with %u\n", GetLastError());
166 HeapFree(GetProcessHeap(), 0, di3
);
170 static DRIVER_INFO_3A
* get_driver_infoA(HANDLE hprn
)
172 DRIVER_INFO_3A
*di3
= NULL
;
176 res
= GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
177 if (!res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
178 di3
= HeapAlloc(GetProcessHeap(), 0, needed
);
179 res
= GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)di3
, needed
, &needed
);
185 TRACE("GetPrinterDriverA failed with %u\n", GetLastError());
186 HeapFree(GetProcessHeap(), 0, di3
);
191 /***********************************************************************
192 * get_printer_info [internal]
194 * get PRINTER_INFO_2W for the current printer handle,
195 * alloc the buffer, when needed
197 static PRINTER_INFO_2W
* get_printer_infoW(HANDLE hprn
)
199 PRINTER_INFO_2W
*pi2
= NULL
;
203 res
= GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
204 if (!res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
205 pi2
= HeapAlloc(GetProcessHeap(), 0, needed
);
206 res
= GetPrinterW(hprn
, 2, (LPBYTE
)pi2
, needed
, &needed
);
212 TRACE("GetPrinterW failed with %u\n", GetLastError());
213 HeapFree(GetProcessHeap(), 0, pi2
);
217 static PRINTER_INFO_2A
* get_printer_infoA(HANDLE hprn
)
219 PRINTER_INFO_2A
*pi2
= NULL
;
223 res
= GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
224 if (!res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
225 pi2
= HeapAlloc(GetProcessHeap(), 0, needed
);
226 res
= GetPrinterA(hprn
, 2, (LPBYTE
)pi2
, needed
, &needed
);
232 TRACE("GetPrinterA failed with %u\n", GetLastError());
233 HeapFree(GetProcessHeap(), 0, pi2
);
238 /***********************************************************************
239 * update_devmode_handle [internal]
241 * update a devmode handle for the given DEVMODE, alloc the buffer, when needed
243 static HGLOBAL
update_devmode_handleW(HGLOBAL hdm
, DEVMODEW
*dm
)
245 SIZE_T size
= GlobalSize(hdm
);
248 /* Increase / alloc the global memory block, when needed */
249 if ((dm
->dmSize
+ dm
->dmDriverExtra
) > size
) {
251 hdm
= GlobalReAlloc(hdm
, dm
->dmSize
+ dm
->dmDriverExtra
, 0);
253 hdm
= GlobalAlloc(GMEM_MOVEABLE
, dm
->dmSize
+ dm
->dmDriverExtra
);
257 ptr
= GlobalLock(hdm
);
259 memcpy(ptr
, dm
, dm
->dmSize
+ dm
->dmDriverExtra
);
271 static HGLOBAL
update_devmode_handleA(HGLOBAL hdm
, DEVMODEA
*dm
)
273 SIZE_T size
= GlobalSize(hdm
);
276 /* Increase / alloc the global memory block, when needed */
277 if ((dm
->dmSize
+ dm
->dmDriverExtra
) > size
) {
279 hdm
= GlobalReAlloc(hdm
, dm
->dmSize
+ dm
->dmDriverExtra
, 0);
281 hdm
= GlobalAlloc(GMEM_MOVEABLE
, dm
->dmSize
+ dm
->dmDriverExtra
);
285 ptr
= GlobalLock(hdm
);
287 memcpy(ptr
, dm
, dm
->dmSize
+ dm
->dmDriverExtra
);
299 /***********************************************************
300 * convert_to_devmodeA
302 * Creates an ansi copy of supplied devmode
304 static DEVMODEA
*convert_to_devmodeA(const DEVMODEW
*dmW
)
309 if (!dmW
) return NULL
;
310 size
= dmW
->dmSize
- CCHDEVICENAME
-
311 ((dmW
->dmSize
> FIELD_OFFSET(DEVMODEW
, dmFormName
)) ? CCHFORMNAME
: 0);
313 dmA
= HeapAlloc(GetProcessHeap(), 0, size
+ dmW
->dmDriverExtra
);
314 if (!dmA
) return NULL
;
316 WideCharToMultiByte(CP_ACP
, 0, dmW
->dmDeviceName
, -1,
317 (LPSTR
)dmA
->dmDeviceName
, CCHDEVICENAME
, NULL
, NULL
);
319 if (FIELD_OFFSET(DEVMODEW
, dmFormName
) >= dmW
->dmSize
)
321 memcpy(&dmA
->dmSpecVersion
, &dmW
->dmSpecVersion
,
322 dmW
->dmSize
- FIELD_OFFSET(DEVMODEW
, dmSpecVersion
));
326 memcpy(&dmA
->dmSpecVersion
, &dmW
->dmSpecVersion
,
327 FIELD_OFFSET(DEVMODEW
, dmFormName
) - FIELD_OFFSET(DEVMODEW
, dmSpecVersion
));
328 WideCharToMultiByte(CP_ACP
, 0, dmW
->dmFormName
, -1,
329 (LPSTR
)dmA
->dmFormName
, CCHFORMNAME
, NULL
, NULL
);
331 memcpy(&dmA
->dmLogPixels
, &dmW
->dmLogPixels
, dmW
->dmSize
- FIELD_OFFSET(DEVMODEW
, dmLogPixels
));
335 memcpy((char *)dmA
+ dmA
->dmSize
, (const char *)dmW
+ dmW
->dmSize
, dmW
->dmDriverExtra
);
339 /***********************************************************************
340 * PRINTDLG_OpenDefaultPrinter
342 * Returns a winspool printer handle to the default printer in *hprn
343 * Caller must call ClosePrinter on the handle
345 * Returns TRUE on success else FALSE
347 static BOOL
PRINTDLG_OpenDefaultPrinter(HANDLE
*hprn
)
350 DWORD dwBufLen
= sizeof(buf
) / sizeof(buf
[0]);
352 if(!GetDefaultPrinterW(buf
, &dwBufLen
))
354 res
= OpenPrinterW(buf
, hprn
, NULL
);
356 WARN("Could not open printer %s\n", debugstr_w(buf
));
360 /***********************************************************************
361 * PRINTDLG_SetUpPrinterListCombo
363 * Initializes printer list combox.
364 * hDlg: HWND of dialog
365 * id: Control id of combo
366 * name: Name of printer to select
368 * Initializes combo with list of available printers. Selects printer 'name'
369 * If name is NULL or does not exist select the default printer.
371 * Returns number of printers added to list.
373 static INT
PRINTDLG_SetUpPrinterListComboA(HWND hDlg
, UINT id
, LPCSTR name
)
377 LPPRINTER_INFO_2A pi
;
378 EnumPrintersA(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
379 pi
= HeapAlloc(GetProcessHeap(), 0, needed
);
380 EnumPrintersA(PRINTER_ENUM_LOCAL
, NULL
, 2, (LPBYTE
)pi
, needed
, &needed
,
383 SendDlgItemMessageA(hDlg
, id
, CB_RESETCONTENT
, 0, 0);
385 for(i
= 0; i
< num
; i
++) {
386 SendDlgItemMessageA(hDlg
, id
, CB_ADDSTRING
, 0,
387 (LPARAM
)pi
[i
].pPrinterName
);
389 HeapFree(GetProcessHeap(), 0, pi
);
391 (i
= SendDlgItemMessageA(hDlg
, id
, CB_FINDSTRINGEXACT
, -1,
392 (LPARAM
)name
)) == CB_ERR
) {
395 DWORD dwBufLen
= sizeof(buf
);
397 WARN("Can't find %s in printer list so trying to find default\n",
399 if(!GetDefaultPrinterA(buf
, &dwBufLen
))
401 i
= SendDlgItemMessageA(hDlg
, id
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buf
);
403 FIXME("Can't find default printer in printer list\n");
405 SendDlgItemMessageA(hDlg
, id
, CB_SETCURSEL
, i
, 0);
409 static INT
PRINTDLG_SetUpPrinterListComboW(HWND hDlg
, UINT id
, LPCWSTR name
)
413 LPPRINTER_INFO_2W pi
;
414 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
415 pi
= HeapAlloc(GetProcessHeap(), 0, needed
);
416 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, (LPBYTE
)pi
, needed
, &needed
,
419 for(i
= 0; i
< num
; i
++) {
420 SendDlgItemMessageW(hDlg
, id
, CB_ADDSTRING
, 0,
421 (LPARAM
)pi
[i
].pPrinterName
);
423 HeapFree(GetProcessHeap(), 0, pi
);
425 (i
= SendDlgItemMessageW(hDlg
, id
, CB_FINDSTRINGEXACT
, -1,
426 (LPARAM
)name
)) == CB_ERR
) {
428 DWORD dwBufLen
= sizeof(buf
)/sizeof(buf
[0]);
430 WARN("Can't find %s in printer list so trying to find default\n",
432 if(!GetDefaultPrinterW(buf
, &dwBufLen
))
434 i
= SendDlgItemMessageW(hDlg
, id
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buf
);
436 TRACE("Can't find default printer in printer list\n");
438 SendDlgItemMessageW(hDlg
, id
, CB_SETCURSEL
, i
, 0);
442 /***********************************************************************
443 * PRINTDLG_CreateDevNames [internal]
446 * creates a DevNames structure.
448 * (NB. when we handle unicode the offsets will be in wchars).
450 static BOOL
PRINTDLG_CreateDevNames(HGLOBAL
*hmem
, const char* DeviceDriverName
,
451 const char* DeviceName
, const char* OutputPort
)
454 char* pDevNamesSpace
;
456 LPDEVNAMES lpDevNames
;
458 DWORD dwBufLen
= sizeof(buf
);
461 p
= strrchr( DeviceDriverName
, '\\' );
462 if (p
) DeviceDriverName
= p
+ 1;
464 size
= strlen(DeviceDriverName
) + 1
465 + strlen(DeviceName
) + 1
466 + strlen(OutputPort
) + 1
470 *hmem
= GlobalReAlloc(*hmem
, size
, GMEM_MOVEABLE
);
472 *hmem
= GlobalAlloc(GMEM_MOVEABLE
, size
);
476 pDevNamesSpace
= GlobalLock(*hmem
);
477 lpDevNames
= (LPDEVNAMES
) pDevNamesSpace
;
479 pTempPtr
= pDevNamesSpace
+ sizeof(DEVNAMES
);
480 strcpy(pTempPtr
, DeviceDriverName
);
481 lpDevNames
->wDriverOffset
= pTempPtr
- pDevNamesSpace
;
483 pTempPtr
+= strlen(DeviceDriverName
) + 1;
484 strcpy(pTempPtr
, DeviceName
);
485 lpDevNames
->wDeviceOffset
= pTempPtr
- pDevNamesSpace
;
487 pTempPtr
+= strlen(DeviceName
) + 1;
488 strcpy(pTempPtr
, OutputPort
);
489 lpDevNames
->wOutputOffset
= pTempPtr
- pDevNamesSpace
;
491 GetDefaultPrinterA(buf
, &dwBufLen
);
492 lpDevNames
->wDefault
= (strcmp(buf
, DeviceName
) == 0) ? 1 : 0;
497 static BOOL
PRINTDLG_CreateDevNamesW(HGLOBAL
*hmem
, LPCWSTR DeviceDriverName
,
498 LPCWSTR DeviceName
, LPCWSTR OutputPort
)
501 LPWSTR pDevNamesSpace
;
503 LPDEVNAMES lpDevNames
;
505 DWORD dwBufLen
= sizeof(bufW
) / sizeof(WCHAR
);
508 p
= strrchrW( DeviceDriverName
, '\\' );
509 if (p
) DeviceDriverName
= p
+ 1;
511 size
= sizeof(WCHAR
)*lstrlenW(DeviceDriverName
) + 2
512 + sizeof(WCHAR
)*lstrlenW(DeviceName
) + 2
513 + sizeof(WCHAR
)*lstrlenW(OutputPort
) + 2
517 *hmem
= GlobalReAlloc(*hmem
, size
, GMEM_MOVEABLE
);
519 *hmem
= GlobalAlloc(GMEM_MOVEABLE
, size
);
523 pDevNamesSpace
= GlobalLock(*hmem
);
524 lpDevNames
= (LPDEVNAMES
) pDevNamesSpace
;
526 pTempPtr
= (LPWSTR
)((LPDEVNAMES
)pDevNamesSpace
+ 1);
527 lstrcpyW(pTempPtr
, DeviceDriverName
);
528 lpDevNames
->wDriverOffset
= pTempPtr
- pDevNamesSpace
;
530 pTempPtr
+= lstrlenW(DeviceDriverName
) + 1;
531 lstrcpyW(pTempPtr
, DeviceName
);
532 lpDevNames
->wDeviceOffset
= pTempPtr
- pDevNamesSpace
;
534 pTempPtr
+= lstrlenW(DeviceName
) + 1;
535 lstrcpyW(pTempPtr
, OutputPort
);
536 lpDevNames
->wOutputOffset
= pTempPtr
- pDevNamesSpace
;
538 GetDefaultPrinterW(bufW
, &dwBufLen
);
539 lpDevNames
->wDefault
= (lstrcmpW(bufW
, DeviceName
) == 0) ? 1 : 0;
544 /***********************************************************************
545 * PRINTDLG_UpdatePrintDlg [internal]
548 * updates the PrintDlg structure for return values.
551 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
552 * TRUE if successful.
554 static BOOL
PRINTDLG_UpdatePrintDlgA(HWND hDlg
,
555 PRINT_PTRA
* PrintStructures
)
557 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
558 PDEVMODEA lpdm
= PrintStructures
->lpDevMode
;
559 LPPRINTER_INFO_2A pi
= PrintStructures
->lpPrinterInfo
;
563 FIXME("No lpdm ptr?\n");
568 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
569 /* check whether nFromPage and nToPage are within range defined by
570 * nMinPage and nMaxPage
572 if (IsDlgButtonChecked(hDlg
, rad3
) == BST_CHECKED
) { /* Pages */
576 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
577 nToPage
= GetDlgItemInt(hDlg
, edt2
, &translated
, FALSE
);
579 /* if no ToPage value is entered, use the FromPage value */
580 if(!translated
) nToPage
= nFromPage
;
582 if (nFromPage
< lppd
->nMinPage
|| nFromPage
> lppd
->nMaxPage
||
583 nToPage
< lppd
->nMinPage
|| nToPage
> lppd
->nMaxPage
) {
584 WCHAR resourcestr
[256];
585 WCHAR resultstr
[256];
586 LoadStringW(COMDLG32_hInstance
, PD32_INVALID_PAGE_RANGE
, resourcestr
, 255);
587 wsprintfW(resultstr
,resourcestr
, lppd
->nMinPage
, lppd
->nMaxPage
);
588 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
, resourcestr
, 255);
589 MessageBoxW(hDlg
, resultstr
, resourcestr
, MB_OK
| MB_ICONWARNING
);
592 lppd
->nFromPage
= nFromPage
;
593 lppd
->nToPage
= nToPage
;
594 lppd
->Flags
|= PD_PAGENUMS
;
597 lppd
->Flags
&= ~PD_PAGENUMS
;
599 if (IsDlgButtonChecked(hDlg
, rad2
) == BST_CHECKED
) /* Selection */
600 lppd
->Flags
|= PD_SELECTION
;
602 lppd
->Flags
&= ~PD_SELECTION
;
604 if (IsDlgButtonChecked(hDlg
, chx1
) == BST_CHECKED
) {/* Print to file */
605 static char file
[] = "FILE:";
606 lppd
->Flags
|= PD_PRINTTOFILE
;
607 pi
->pPortName
= file
;
610 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
) { /* Collate */
611 FIXME("Collate lppd not yet implemented as output\n");
614 /* set PD_Collate and nCopies */
615 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
616 /* The application doesn't support multiple copies or collate...
618 lppd
->Flags
&= ~PD_COLLATE
;
620 /* if the printer driver supports it... store info there
621 * otherwise no collate & multiple copies !
623 if (lpdm
->dmFields
& DM_COLLATE
)
625 (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
);
626 if (lpdm
->dmFields
& DM_COPIES
)
627 lpdm
->u1
.s1
.dmCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
629 /* Application is responsible for multiple copies */
630 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
631 lppd
->Flags
|= PD_COLLATE
;
633 lppd
->Flags
&= ~PD_COLLATE
;
634 lppd
->nCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
635 /* multiple copies already included in the document. Driver must print only one copy */
636 lpdm
->u1
.s1
.dmCopies
= 1;
639 /* Print quality, PrintDlg16 */
640 if(GetDlgItem(hDlg
, cmb1
))
642 HWND hQuality
= GetDlgItem(hDlg
, cmb1
);
643 int Sel
= SendMessageA(hQuality
, CB_GETCURSEL
, 0, 0);
647 LONG dpi
= SendMessageA(hQuality
, CB_GETITEMDATA
, Sel
, 0);
648 lpdm
->dmFields
|= DM_PRINTQUALITY
| DM_YRESOLUTION
;
649 lpdm
->u1
.s1
.dmPrintQuality
= LOWORD(dpi
);
650 lpdm
->dmYResolution
= HIWORD(dpi
);
657 static BOOL
PRINTDLG_UpdatePrintDlgW(HWND hDlg
,
658 PRINT_PTRW
* PrintStructures
)
660 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
661 PDEVMODEW lpdm
= PrintStructures
->lpDevMode
;
662 LPPRINTER_INFO_2W pi
= PrintStructures
->lpPrinterInfo
;
666 FIXME("No lpdm ptr?\n");
671 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
672 /* check whether nFromPage and nToPage are within range defined by
673 * nMinPage and nMaxPage
675 if (IsDlgButtonChecked(hDlg
, rad3
) == BST_CHECKED
) { /* Pages */
679 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
680 nToPage
= GetDlgItemInt(hDlg
, edt2
, &translated
, FALSE
);
682 /* if no ToPage value is entered, use the FromPage value */
683 if(!translated
) nToPage
= nFromPage
;
685 if (nFromPage
< lppd
->nMinPage
|| nFromPage
> lppd
->nMaxPage
||
686 nToPage
< lppd
->nMinPage
|| nToPage
> lppd
->nMaxPage
) {
687 WCHAR resourcestr
[256];
688 WCHAR resultstr
[256];
690 LoadStringW(COMDLG32_hInstance
, PD32_INVALID_PAGE_RANGE
,
692 args
[0] = lppd
->nMinPage
;
693 args
[1] = lppd
->nMaxPage
;
694 FormatMessageW(FORMAT_MESSAGE_FROM_STRING
|FORMAT_MESSAGE_ARGUMENT_ARRAY
,
695 resourcestr
, 0, 0, resultstr
,
696 sizeof(resultstr
)/sizeof(*resultstr
),
697 (__ms_va_list
*)args
);
698 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
,
700 MessageBoxW(hDlg
, resultstr
, resourcestr
,
701 MB_OK
| MB_ICONWARNING
);
704 lppd
->nFromPage
= nFromPage
;
705 lppd
->nToPage
= nToPage
;
706 lppd
->Flags
|= PD_PAGENUMS
;
709 lppd
->Flags
&= ~PD_PAGENUMS
;
711 if (IsDlgButtonChecked(hDlg
, rad2
) == BST_CHECKED
) /* Selection */
712 lppd
->Flags
|= PD_SELECTION
;
714 lppd
->Flags
&= ~PD_SELECTION
;
716 if (IsDlgButtonChecked(hDlg
, chx1
) == BST_CHECKED
) {/* Print to file */
717 static WCHAR file
[] = {'F','I','L','E',':',0};
718 lppd
->Flags
|= PD_PRINTTOFILE
;
719 pi
->pPortName
= file
;
722 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
) { /* Collate */
723 FIXME("Collate lppd not yet implemented as output\n");
726 /* set PD_Collate and nCopies */
727 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
728 /* The application doesn't support multiple copies or collate...
730 lppd
->Flags
&= ~PD_COLLATE
;
732 /* if the printer driver supports it... store info there
733 * otherwise no collate & multiple copies !
735 if (lpdm
->dmFields
& DM_COLLATE
)
737 (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
);
738 if (lpdm
->dmFields
& DM_COPIES
)
739 lpdm
->u1
.s1
.dmCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
741 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
742 lppd
->Flags
|= PD_COLLATE
;
744 lppd
->Flags
&= ~PD_COLLATE
;
745 lppd
->nCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
751 /************************************************************************
752 * PRINTDLG_SetUpPaperComboBox
754 * Initialize either the papersize or inputslot combos of the Printer Setup
755 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
756 * We also try to re-select the old selection.
758 static BOOL
PRINTDLG_SetUpPaperComboBoxA(HWND hDlg
,
769 WORD oldWord
= 0, newWord
= 0; /* DMPAPER_ and DMBIN_ start at 1 */
771 int fwCapability_Names
;
772 int fwCapability_Words
;
774 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName
,PortName
,nIDComboBox
);
776 /* query the dialog box for the current selected value */
777 Sel
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETCURSEL
, 0, 0);
779 /* we enter here only if a different printer is selected after
780 * the Print Setup dialog is opened. The current settings are
781 * stored into the newly selected printer.
783 oldWord
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
,
785 if(oldWord
>= DMPAPER_USER
) /* DMPAPER_USER == DMBIN_USER */
786 oldWord
= 0; /* There's no point in trying to keep custom
787 paper / bin sizes across printers */
791 newWord
= (nIDComboBox
== cmb2
) ? dm
->u1
.s1
.dmPaperSize
: dm
->u1
.s1
.dmDefaultSource
;
793 if (nIDComboBox
== cmb2
) {
795 fwCapability_Names
= DC_PAPERNAMES
;
796 fwCapability_Words
= DC_PAPERS
;
800 fwCapability_Names
= DC_BINNAMES
;
801 fwCapability_Words
= DC_BINS
;
804 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
805 fwCapability_Names
, NULL
, dm
);
806 if (NrOfEntries
== 0)
807 WARN("no Name Entries found!\n");
808 else if (NrOfEntries
< 0)
811 if(DeviceCapabilitiesA(PrinterName
, PortName
, fwCapability_Words
, NULL
, dm
)
813 ERR("Number of caps is different\n");
817 Names
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(char)*NamesSize
);
818 Words
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WORD
));
819 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
820 fwCapability_Names
, Names
, dm
);
821 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
822 fwCapability_Words
, (LPSTR
)Words
, dm
);
824 /* reset any current content in the combobox */
825 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_RESETCONTENT
, 0, 0);
827 /* store new content */
828 for (i
= 0; i
< NrOfEntries
; i
++) {
829 DWORD pos
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_ADDSTRING
, 0,
830 (LPARAM
)(&Names
[i
*NamesSize
]) );
831 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_SETITEMDATA
, pos
,
835 /* Look for old selection or the new default.
836 Can't do this is previous loop since item order will change as more items are added */
838 old_Sel
= NrOfEntries
;
839 for (i
= 0; i
< NrOfEntries
; i
++) {
840 if(SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) ==
845 if(SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) == newWord
)
849 if(old_Sel
< NrOfEntries
)
853 if(nIDComboBox
== cmb2
)
854 dm
->u1
.s1
.dmPaperSize
= oldWord
;
856 dm
->u1
.s1
.dmDefaultSource
= oldWord
;
861 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_SETCURSEL
, Sel
, 0);
863 HeapFree(GetProcessHeap(),0,Words
);
864 HeapFree(GetProcessHeap(),0,Names
);
868 static BOOL
PRINTDLG_SetUpPaperComboBoxW(HWND hDlg
,
870 const WCHAR
* PrinterName
,
871 const WCHAR
* PortName
,
879 WORD oldWord
= 0, newWord
= 0; /* DMPAPER_ and DMBIN_ start at 1 */
881 int fwCapability_Names
;
882 int fwCapability_Words
;
884 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName
),debugstr_w(PortName
),nIDComboBox
);
886 /* query the dialog box for the current selected value */
887 Sel
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETCURSEL
, 0, 0);
889 /* we enter here only if a different printer is selected after
890 * the Print Setup dialog is opened. The current settings are
891 * stored into the newly selected printer.
893 oldWord
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETITEMDATA
,
896 if(oldWord
>= DMPAPER_USER
) /* DMPAPER_USER == DMBIN_USER */
897 oldWord
= 0; /* There's no point in trying to keep custom
898 paper / bin sizes across printers */
902 newWord
= (nIDComboBox
== cmb2
) ? dm
->u1
.s1
.dmPaperSize
: dm
->u1
.s1
.dmDefaultSource
;
904 if (nIDComboBox
== cmb2
) {
906 fwCapability_Names
= DC_PAPERNAMES
;
907 fwCapability_Words
= DC_PAPERS
;
911 fwCapability_Names
= DC_BINNAMES
;
912 fwCapability_Words
= DC_BINS
;
915 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
916 fwCapability_Names
, NULL
, dm
);
917 if (NrOfEntries
== 0)
918 WARN("no Name Entries found!\n");
919 else if (NrOfEntries
< 0)
922 if(DeviceCapabilitiesW(PrinterName
, PortName
, fwCapability_Words
, NULL
, dm
)
924 ERR("Number of caps is different\n");
928 Names
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WCHAR
)*NamesSize
);
929 Words
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WORD
));
930 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
931 fwCapability_Names
, Names
, dm
);
932 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
933 fwCapability_Words
, Words
, dm
);
935 /* reset any current content in the combobox */
936 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_RESETCONTENT
, 0, 0);
938 /* store new content */
939 for (i
= 0; i
< NrOfEntries
; i
++) {
940 DWORD pos
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_ADDSTRING
, 0,
941 (LPARAM
)(&Names
[i
*NamesSize
]) );
942 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_SETITEMDATA
, pos
,
946 /* Look for old selection or the new default.
947 Can't do this is previous loop since item order will change as more items are added */
949 old_Sel
= NrOfEntries
;
950 for (i
= 0; i
< NrOfEntries
; i
++) {
951 if(SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) ==
956 if(SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) == newWord
)
960 if(old_Sel
< NrOfEntries
)
964 if(nIDComboBox
== cmb2
)
965 dm
->u1
.s1
.dmPaperSize
= oldWord
;
967 dm
->u1
.s1
.dmDefaultSource
= oldWord
;
972 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_SETCURSEL
, Sel
, 0);
974 HeapFree(GetProcessHeap(),0,Words
);
975 HeapFree(GetProcessHeap(),0,Names
);
980 /***********************************************************************
981 * PRINTDLG_UpdatePrinterInfoTexts [internal]
983 static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg
, const PRINTER_INFO_2A
*pi
)
986 char ResourceString
[256];
992 /* add all status messages */
993 for (i
= 0; i
< 25; i
++) {
994 if (pi
->Status
& (1<<i
)) {
995 LoadStringA(COMDLG32_hInstance
, PD32_PRINTER_STATUS_PAUSED
+i
,
996 ResourceString
, 255);
997 strcat(StatusMsg
,ResourceString
);
1000 /* append "ready" */
1001 /* FIXME: status==ready must only be appended if really so.
1002 but how to detect? */
1003 LoadStringA(COMDLG32_hInstance
, PD32_PRINTER_STATUS_READY
,
1004 ResourceString
, 255);
1005 strcat(StatusMsg
,ResourceString
);
1006 SetDlgItemTextA(hDlg
, stc12
, StatusMsg
);
1008 /* set all other printer info texts */
1009 SetDlgItemTextA(hDlg
, stc11
, pi
->pDriverName
);
1011 if (pi
->pLocation
!= NULL
&& pi
->pLocation
[0] != '\0')
1012 SetDlgItemTextA(hDlg
, stc14
, pi
->pLocation
);
1014 SetDlgItemTextA(hDlg
, stc14
, pi
->pPortName
);
1015 SetDlgItemTextA(hDlg
, stc13
, pi
->pComment
? pi
->pComment
: "");
1019 static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg
, const PRINTER_INFO_2W
*pi
)
1021 WCHAR StatusMsg
[256];
1022 WCHAR ResourceString
[256];
1023 static const WCHAR emptyW
[] = {0};
1026 /* Status Message */
1029 /* add all status messages */
1030 for (i
= 0; i
< 25; i
++) {
1031 if (pi
->Status
& (1<<i
)) {
1032 LoadStringW(COMDLG32_hInstance
, PD32_PRINTER_STATUS_PAUSED
+i
,
1033 ResourceString
, 255);
1034 lstrcatW(StatusMsg
,ResourceString
);
1037 /* append "ready" */
1038 /* FIXME: status==ready must only be appended if really so.
1039 but how to detect? */
1040 LoadStringW(COMDLG32_hInstance
, PD32_PRINTER_STATUS_READY
,
1041 ResourceString
, 255);
1042 lstrcatW(StatusMsg
,ResourceString
);
1043 SetDlgItemTextW(hDlg
, stc12
, StatusMsg
);
1045 /* set all other printer info texts */
1046 SetDlgItemTextW(hDlg
, stc11
, pi
->pDriverName
);
1047 if (pi
->pLocation
!= NULL
&& pi
->pLocation
[0] != '\0')
1048 SetDlgItemTextW(hDlg
, stc14
, pi
->pLocation
);
1050 SetDlgItemTextW(hDlg
, stc14
, pi
->pPortName
);
1051 SetDlgItemTextW(hDlg
, stc13
, pi
->pComment
? pi
->pComment
: emptyW
);
1055 /*******************************************************************
1057 * PRINTDLG_ChangePrinter
1060 static BOOL
PRINTDLG_ChangePrinterA(HWND hDlg
, char *name
, PRINT_PTRA
*PrintStructures
)
1062 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1063 LPDEVMODEA lpdm
= NULL
;
1068 HeapFree(GetProcessHeap(),0, PrintStructures
->lpPrinterInfo
);
1069 HeapFree(GetProcessHeap(),0, PrintStructures
->lpDriverInfo
);
1070 if(!OpenPrinterA(name
, &hprn
, NULL
)) {
1071 ERR("Can't open printer %s\n", name
);
1074 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
1075 PrintStructures
->lpPrinterInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
1076 GetPrinterA(hprn
, 2, (LPBYTE
)PrintStructures
->lpPrinterInfo
, needed
,
1078 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
1079 PrintStructures
->lpDriverInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
1080 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)PrintStructures
->lpDriverInfo
,
1082 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures
->lpPrinterInfo
->pPrinterName
);
1087 PRINTDLG_UpdatePrinterInfoTextsA(hDlg
, PrintStructures
->lpPrinterInfo
);
1089 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
1090 PrintStructures
->lpDevMode
= NULL
;
1092 dmSize
= DocumentPropertiesA(0, 0, name
, NULL
, NULL
, 0);
1094 ERR("DocumentProperties fails on %s\n", debugstr_a(name
));
1097 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(), 0, dmSize
);
1098 dmSize
= DocumentPropertiesA(0, 0, name
, PrintStructures
->lpDevMode
, NULL
,
1100 if(lppd
->hDevMode
&& (lpdm
= GlobalLock(lppd
->hDevMode
)) &&
1101 !lstrcmpA( (LPSTR
) lpdm
->dmDeviceName
,
1102 (LPSTR
) PrintStructures
->lpDevMode
->dmDeviceName
)) {
1103 /* Supplied devicemode matches current printer so try to use it */
1104 DocumentPropertiesA(0, 0, name
, PrintStructures
->lpDevMode
, lpdm
,
1105 DM_OUT_BUFFER
| DM_IN_BUFFER
);
1108 GlobalUnlock(lppd
->hDevMode
);
1110 lpdm
= PrintStructures
->lpDevMode
; /* use this as a shortcut */
1112 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
1113 /* Print range (All/Range/Selection) */
1114 if(lppd
->nFromPage
!= 0xffff)
1115 SetDlgItemInt(hDlg
, edt1
, lppd
->nFromPage
, FALSE
);
1116 if(lppd
->nToPage
!= 0xffff)
1117 SetDlgItemInt(hDlg
, edt2
, lppd
->nToPage
, FALSE
);
1119 CheckRadioButton(hDlg
, rad1
, rad3
, rad1
); /* default */
1120 if (lppd
->Flags
& PD_NOSELECTION
)
1121 EnableWindow(GetDlgItem(hDlg
, rad2
), FALSE
);
1123 if (lppd
->Flags
& PD_SELECTION
)
1124 CheckRadioButton(hDlg
, rad1
, rad3
, rad2
);
1125 if (lppd
->Flags
& PD_NOPAGENUMS
) {
1126 EnableWindow(GetDlgItem(hDlg
, rad3
), FALSE
);
1127 EnableWindow(GetDlgItem(hDlg
, stc2
),FALSE
);
1128 EnableWindow(GetDlgItem(hDlg
, edt1
), FALSE
);
1129 EnableWindow(GetDlgItem(hDlg
, stc3
),FALSE
);
1130 EnableWindow(GetDlgItem(hDlg
, edt2
), FALSE
);
1132 if (lppd
->Flags
& PD_PAGENUMS
)
1133 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1138 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1140 if (lppd
->Flags
& PD_COLLATE
) {
1141 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1142 (LPARAM
)PrintStructures
->hCollateIcon
);
1143 CheckDlgButton(hDlg
, chx2
, 1);
1145 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1146 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1147 CheckDlgButton(hDlg
, chx2
, 0);
1150 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1151 /* if printer doesn't support it: no Collate */
1152 if (!(lpdm
->dmFields
& DM_COLLATE
)) {
1153 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1154 EnableWindow(GetDlgItem(hDlg
, ico3
), FALSE
);
1161 if (lppd
->hDevMode
== 0)
1162 copies
= lppd
->nCopies
;
1164 copies
= lpdm
->u1
.s1
.dmCopies
;
1165 if(copies
== 0) copies
= 1;
1166 else if(copies
< 0) copies
= MAX_COPIES
;
1167 SetDlgItemInt(hDlg
, edt3
, copies
, FALSE
);
1170 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1171 /* if printer doesn't support it: no nCopies */
1172 if (!(lpdm
->dmFields
& DM_COPIES
)) {
1173 EnableWindow(GetDlgItem(hDlg
, edt3
), FALSE
);
1174 EnableWindow(GetDlgItem(hDlg
, stc5
), FALSE
);
1179 CheckDlgButton(hDlg
, chx1
, (lppd
->Flags
& PD_PRINTTOFILE
) ? 1 : 0);
1180 if (lppd
->Flags
& PD_DISABLEPRINTTOFILE
)
1181 EnableWindow(GetDlgItem(hDlg
, chx1
), FALSE
);
1182 if (lppd
->Flags
& PD_HIDEPRINTTOFILE
)
1183 ShowWindow(GetDlgItem(hDlg
, chx1
), SW_HIDE
);
1185 /* Fill print quality combo, PrintDlg16 */
1186 if(GetDlgItem(hDlg
, cmb1
))
1188 DWORD numResolutions
= DeviceCapabilitiesA(PrintStructures
->lpPrinterInfo
->pPrinterName
,
1189 PrintStructures
->lpPrinterInfo
->pPortName
,
1190 DC_ENUMRESOLUTIONS
, NULL
, lpdm
);
1192 if(numResolutions
!= -1)
1194 HWND hQuality
= GetDlgItem(hDlg
, cmb1
);
1199 HDC hPrinterDC
= CreateDCA(PrintStructures
->lpPrinterInfo
->pDriverName
,
1200 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1203 Resolutions
= HeapAlloc(GetProcessHeap(), 0, numResolutions
*sizeof(LONG
)*2);
1204 DeviceCapabilitiesA(PrintStructures
->lpPrinterInfo
->pPrinterName
,
1205 PrintStructures
->lpPrinterInfo
->pPortName
,
1206 DC_ENUMRESOLUTIONS
, (LPSTR
)Resolutions
, lpdm
);
1208 dpiX
= GetDeviceCaps(hPrinterDC
, LOGPIXELSX
);
1209 dpiY
= GetDeviceCaps(hPrinterDC
, LOGPIXELSY
);
1210 DeleteDC(hPrinterDC
);
1212 SendMessageA(hQuality
, CB_RESETCONTENT
, 0, 0);
1213 for(i
= 0; i
< (numResolutions
* 2); i
+= 2)
1215 BOOL IsDefault
= FALSE
;
1218 if(Resolutions
[i
] == Resolutions
[i
+1])
1220 if(dpiX
== Resolutions
[i
])
1222 sprintf(buf
, "%d dpi", Resolutions
[i
]);
1225 if(dpiX
== Resolutions
[i
] && dpiY
== Resolutions
[i
+1])
1227 sprintf(buf
, "%d dpi x %d dpi", Resolutions
[i
], Resolutions
[i
+1]);
1230 Index
= SendMessageA(hQuality
, CB_ADDSTRING
, 0, (LPARAM
)buf
);
1233 SendMessageA(hQuality
, CB_SETCURSEL
, Index
, 0);
1235 SendMessageA(hQuality
, CB_SETITEMDATA
, Index
, MAKELONG(dpiX
,dpiY
));
1237 HeapFree(GetProcessHeap(), 0, Resolutions
);
1240 } else { /* PD_PRINTSETUP */
1241 BOOL bPortrait
= (lpdm
->u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
);
1243 PRINTDLG_SetUpPaperComboBoxA(hDlg
, cmb2
,
1244 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1245 PrintStructures
->lpPrinterInfo
->pPortName
,
1247 PRINTDLG_SetUpPaperComboBoxA(hDlg
, cmb3
,
1248 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1249 PrintStructures
->lpPrinterInfo
->pPortName
,
1251 CheckRadioButton(hDlg
, rad1
, rad2
, bPortrait
? rad1
: rad2
);
1252 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1253 (LPARAM
)(bPortrait
? PrintStructures
->hPortraitIcon
:
1254 PrintStructures
->hLandscapeIcon
));
1259 if ((lppd
->Flags
& PD_SHOWHELP
)==0) {
1260 /* hide if PD_SHOWHELP not specified */
1261 ShowWindow(GetDlgItem(hDlg
, pshHelp
), SW_HIDE
);
1266 static BOOL
PRINTDLG_ChangePrinterW(HWND hDlg
, WCHAR
*name
,
1267 PRINT_PTRW
*PrintStructures
)
1269 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1270 LPDEVMODEW lpdm
= NULL
;
1275 HeapFree(GetProcessHeap(),0, PrintStructures
->lpPrinterInfo
);
1276 HeapFree(GetProcessHeap(),0, PrintStructures
->lpDriverInfo
);
1277 if(!OpenPrinterW(name
, &hprn
, NULL
)) {
1278 ERR("Can't open printer %s\n", debugstr_w(name
));
1281 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
1282 PrintStructures
->lpPrinterInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
1283 GetPrinterW(hprn
, 2, (LPBYTE
)PrintStructures
->lpPrinterInfo
, needed
,
1285 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
1286 PrintStructures
->lpDriverInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
1287 if (!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)PrintStructures
->lpDriverInfo
,
1289 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures
->lpPrinterInfo
->pPrinterName
));
1294 PRINTDLG_UpdatePrinterInfoTextsW(hDlg
, PrintStructures
->lpPrinterInfo
);
1296 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
1297 PrintStructures
->lpDevMode
= NULL
;
1299 dmSize
= DocumentPropertiesW(0, 0, name
, NULL
, NULL
, 0);
1301 ERR("DocumentProperties fails on %s\n", debugstr_w(name
));
1304 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(), 0, dmSize
);
1305 dmSize
= DocumentPropertiesW(0, 0, name
, PrintStructures
->lpDevMode
, NULL
,
1307 if(lppd
->hDevMode
&& (lpdm
= GlobalLock(lppd
->hDevMode
)) &&
1308 !lstrcmpW(lpdm
->dmDeviceName
,
1309 PrintStructures
->lpDevMode
->dmDeviceName
)) {
1310 /* Supplied devicemode matches current printer so try to use it */
1311 DocumentPropertiesW(0, 0, name
, PrintStructures
->lpDevMode
, lpdm
,
1312 DM_OUT_BUFFER
| DM_IN_BUFFER
);
1315 GlobalUnlock(lppd
->hDevMode
);
1317 lpdm
= PrintStructures
->lpDevMode
; /* use this as a shortcut */
1319 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
1320 /* Print range (All/Range/Selection) */
1321 if(lppd
->nFromPage
!= 0xffff)
1322 SetDlgItemInt(hDlg
, edt1
, lppd
->nFromPage
, FALSE
);
1323 if(lppd
->nToPage
!= 0xffff)
1324 SetDlgItemInt(hDlg
, edt2
, lppd
->nToPage
, FALSE
);
1326 CheckRadioButton(hDlg
, rad1
, rad3
, rad1
); /* default */
1327 if (lppd
->Flags
& PD_NOSELECTION
)
1328 EnableWindow(GetDlgItem(hDlg
, rad2
), FALSE
);
1330 if (lppd
->Flags
& PD_SELECTION
)
1331 CheckRadioButton(hDlg
, rad1
, rad3
, rad2
);
1332 if (lppd
->Flags
& PD_NOPAGENUMS
) {
1333 EnableWindow(GetDlgItem(hDlg
, rad3
), FALSE
);
1334 EnableWindow(GetDlgItem(hDlg
, stc2
),FALSE
);
1335 EnableWindow(GetDlgItem(hDlg
, edt1
), FALSE
);
1336 EnableWindow(GetDlgItem(hDlg
, stc3
),FALSE
);
1337 EnableWindow(GetDlgItem(hDlg
, edt2
), FALSE
);
1339 if (lppd
->Flags
& PD_PAGENUMS
)
1340 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1345 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1347 if (lppd
->Flags
& PD_COLLATE
) {
1348 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1349 (LPARAM
)PrintStructures
->hCollateIcon
);
1350 CheckDlgButton(hDlg
, chx2
, 1);
1352 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1353 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1354 CheckDlgButton(hDlg
, chx2
, 0);
1357 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1358 /* if printer doesn't support it: no Collate */
1359 if (!(lpdm
->dmFields
& DM_COLLATE
)) {
1360 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1361 EnableWindow(GetDlgItem(hDlg
, ico3
), FALSE
);
1368 if (lppd
->hDevMode
== 0)
1369 copies
= lppd
->nCopies
;
1371 copies
= lpdm
->u1
.s1
.dmCopies
;
1372 if(copies
== 0) copies
= 1;
1373 else if(copies
< 0) copies
= MAX_COPIES
;
1374 SetDlgItemInt(hDlg
, edt3
, copies
, FALSE
);
1377 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1378 /* if printer doesn't support it: no nCopies */
1379 if (!(lpdm
->dmFields
& DM_COPIES
)) {
1380 EnableWindow(GetDlgItem(hDlg
, edt3
), FALSE
);
1381 EnableWindow(GetDlgItem(hDlg
, stc5
), FALSE
);
1386 CheckDlgButton(hDlg
, chx1
, (lppd
->Flags
& PD_PRINTTOFILE
) ? 1 : 0);
1387 if (lppd
->Flags
& PD_DISABLEPRINTTOFILE
)
1388 EnableWindow(GetDlgItem(hDlg
, chx1
), FALSE
);
1389 if (lppd
->Flags
& PD_HIDEPRINTTOFILE
)
1390 ShowWindow(GetDlgItem(hDlg
, chx1
), SW_HIDE
);
1392 } else { /* PD_PRINTSETUP */
1393 BOOL bPortrait
= (lpdm
->u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
);
1395 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb2
,
1396 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1397 PrintStructures
->lpPrinterInfo
->pPortName
,
1399 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb3
,
1400 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1401 PrintStructures
->lpPrinterInfo
->pPortName
,
1403 CheckRadioButton(hDlg
, rad1
, rad2
, bPortrait
? rad1
: rad2
);
1404 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1405 (LPARAM
)(bPortrait
? PrintStructures
->hPortraitIcon
:
1406 PrintStructures
->hLandscapeIcon
));
1411 if ((lppd
->Flags
& PD_SHOWHELP
)==0) {
1412 /* hide if PD_SHOWHELP not specified */
1413 ShowWindow(GetDlgItem(hDlg
, pshHelp
), SW_HIDE
);
1418 /***********************************************************************
1419 * check_printer_setup [internal]
1421 static LRESULT
check_printer_setup(HWND hDlg
)
1424 WCHAR resourcestr
[256],resultstr
[256];
1426 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
1429 EnumPrintersW(PRINTER_ENUM_CONNECTIONS
, NULL
, 2, NULL
, 0, &needed
, &num
);
1435 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEVICES
,resultstr
, 255);
1436 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
,resourcestr
, 255);
1437 MessageBoxW(hDlg
, resultstr
, resourcestr
,MB_OK
| MB_ICONWARNING
);
1442 /***********************************************************************
1443 * PRINTDLG_WMInitDialog [internal]
1445 static LRESULT
PRINTDLG_WMInitDialog(HWND hDlg
,
1446 PRINT_PTRA
* PrintStructures
)
1448 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1452 UINT comboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1454 /* load Collate ICONs */
1455 /* We load these with LoadImage because they are not a standard
1456 size and we don't want them rescaled */
1457 PrintStructures
->hCollateIcon
=
1458 LoadImageA(COMDLG32_hInstance
, "PD32_COLLATE", IMAGE_ICON
, 0, 0, 0);
1459 PrintStructures
->hNoCollateIcon
=
1460 LoadImageA(COMDLG32_hInstance
, "PD32_NOCOLLATE", IMAGE_ICON
, 0, 0, 0);
1462 /* These can be done with LoadIcon */
1463 PrintStructures
->hPortraitIcon
=
1464 LoadIconA(COMDLG32_hInstance
, "PD32_PORTRAIT");
1465 PrintStructures
->hLandscapeIcon
=
1466 LoadIconA(COMDLG32_hInstance
, "PD32_LANDSCAPE");
1468 /* display the collate/no_collate icon */
1469 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1470 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1472 if(PrintStructures
->hCollateIcon
== 0 ||
1473 PrintStructures
->hNoCollateIcon
== 0 ||
1474 PrintStructures
->hPortraitIcon
== 0 ||
1475 PrintStructures
->hLandscapeIcon
== 0) {
1476 ERR("no icon in resource file\n");
1477 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1478 EndDialog(hDlg
, FALSE
);
1482 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1483 * must be registered and the Help button must be shown.
1485 if (lppd
->Flags
& PD_SHOWHELP
) {
1486 if((PrintStructures
->HelpMessageID
=
1487 RegisterWindowMessageA(HELPMSGSTRINGA
)) == 0) {
1488 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL
);
1492 PrintStructures
->HelpMessageID
= 0;
1494 if(!(lppd
->Flags
&PD_PRINTSETUP
)) {
1495 PrintStructures
->hwndUpDown
=
1496 CreateUpDownControl(WS_CHILD
| WS_VISIBLE
| WS_BORDER
|
1497 UDS_NOTHOUSANDS
| UDS_ARROWKEYS
|
1498 UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, 0, 0, 0, 0,
1499 hDlg
, UPDOWN_ID
, COMDLG32_hInstance
,
1500 GetDlgItem(hDlg
, edt3
), MAX_COPIES
, 1, 1);
1503 /* FIXME: I allow more freedom than either Win95 or WinNT,
1504 * which do not agree on what errors should be thrown or not
1505 * in case nToPage or nFromPage is out-of-range.
1507 if (lppd
->nMaxPage
< lppd
->nMinPage
)
1508 lppd
->nMaxPage
= lppd
->nMinPage
;
1509 if (lppd
->nMinPage
== lppd
->nMaxPage
)
1510 lppd
->Flags
|= PD_NOPAGENUMS
;
1511 if (lppd
->nToPage
< lppd
->nMinPage
)
1512 lppd
->nToPage
= lppd
->nMinPage
;
1513 if (lppd
->nToPage
> lppd
->nMaxPage
)
1514 lppd
->nToPage
= lppd
->nMaxPage
;
1515 if (lppd
->nFromPage
< lppd
->nMinPage
)
1516 lppd
->nFromPage
= lppd
->nMinPage
;
1517 if (lppd
->nFromPage
> lppd
->nMaxPage
)
1518 lppd
->nFromPage
= lppd
->nMaxPage
;
1520 /* if we have the combo box, fill it */
1521 if (GetDlgItem(hDlg
,comboID
)) {
1524 pdn
= GlobalLock(lppd
->hDevNames
);
1525 pdm
= GlobalLock(lppd
->hDevMode
);
1527 name
= (char*)pdn
+ pdn
->wDeviceOffset
;
1529 name
= (char*)pdm
->dmDeviceName
;
1530 PRINTDLG_SetUpPrinterListComboA(hDlg
, comboID
, name
);
1531 if(pdm
) GlobalUnlock(lppd
->hDevMode
);
1532 if(pdn
) GlobalUnlock(lppd
->hDevNames
);
1534 /* Now find selected printer and update rest of dlg */
1535 name
= HeapAlloc(GetProcessHeap(),0,256);
1536 if (GetDlgItemTextA(hDlg
, comboID
, name
, 255))
1537 PRINTDLG_ChangePrinterA(hDlg
, name
, PrintStructures
);
1538 HeapFree(GetProcessHeap(),0,name
);
1540 /* else use default printer */
1542 DWORD dwBufLen
= sizeof(name
);
1543 BOOL ret
= GetDefaultPrinterA(name
, &dwBufLen
);
1546 PRINTDLG_ChangePrinterA(hDlg
, name
, PrintStructures
);
1548 FIXME("No default printer found, expect problems!\n");
1553 static LRESULT
PRINTDLG_WMInitDialogW(HWND hDlg
,
1554 PRINT_PTRW
* PrintStructures
)
1556 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1560 UINT comboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1562 /* load Collate ICONs */
1563 /* We load these with LoadImage because they are not a standard
1564 size and we don't want them rescaled */
1565 PrintStructures
->hCollateIcon
=
1566 LoadImageW(COMDLG32_hInstance
, pd32_collateW
, IMAGE_ICON
, 0, 0, 0);
1567 PrintStructures
->hNoCollateIcon
=
1568 LoadImageW(COMDLG32_hInstance
, pd32_nocollateW
, IMAGE_ICON
, 0, 0, 0);
1570 /* These can be done with LoadIcon */
1571 PrintStructures
->hPortraitIcon
=
1572 LoadIconW(COMDLG32_hInstance
, pd32_portraitW
);
1573 PrintStructures
->hLandscapeIcon
=
1574 LoadIconW(COMDLG32_hInstance
, pd32_landscapeW
);
1576 /* display the collate/no_collate icon */
1577 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1578 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1580 if(PrintStructures
->hCollateIcon
== 0 ||
1581 PrintStructures
->hNoCollateIcon
== 0 ||
1582 PrintStructures
->hPortraitIcon
== 0 ||
1583 PrintStructures
->hLandscapeIcon
== 0) {
1584 ERR("no icon in resource file\n");
1585 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1586 EndDialog(hDlg
, FALSE
);
1590 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1591 * must be registered and the Help button must be shown.
1593 if (lppd
->Flags
& PD_SHOWHELP
) {
1594 if((PrintStructures
->HelpMessageID
=
1595 RegisterWindowMessageW(HELPMSGSTRINGW
)) == 0) {
1596 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL
);
1600 PrintStructures
->HelpMessageID
= 0;
1602 if(!(lppd
->Flags
&PD_PRINTSETUP
)) {
1603 PrintStructures
->hwndUpDown
=
1604 CreateUpDownControl(WS_CHILD
| WS_VISIBLE
| WS_BORDER
|
1605 UDS_NOTHOUSANDS
| UDS_ARROWKEYS
|
1606 UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, 0, 0, 0, 0,
1607 hDlg
, UPDOWN_ID
, COMDLG32_hInstance
,
1608 GetDlgItem(hDlg
, edt3
), MAX_COPIES
, 1, 1);
1611 /* FIXME: I allow more freedom than either Win95 or WinNT,
1612 * which do not agree to what errors should be thrown or not
1613 * in case nToPage or nFromPage is out-of-range.
1615 if (lppd
->nMaxPage
< lppd
->nMinPage
)
1616 lppd
->nMaxPage
= lppd
->nMinPage
;
1617 if (lppd
->nMinPage
== lppd
->nMaxPage
)
1618 lppd
->Flags
|= PD_NOPAGENUMS
;
1619 if (lppd
->nToPage
< lppd
->nMinPage
)
1620 lppd
->nToPage
= lppd
->nMinPage
;
1621 if (lppd
->nToPage
> lppd
->nMaxPage
)
1622 lppd
->nToPage
= lppd
->nMaxPage
;
1623 if (lppd
->nFromPage
< lppd
->nMinPage
)
1624 lppd
->nFromPage
= lppd
->nMinPage
;
1625 if (lppd
->nFromPage
> lppd
->nMaxPage
)
1626 lppd
->nFromPage
= lppd
->nMaxPage
;
1628 /* if we have the combo box, fill it */
1629 if (GetDlgItem(hDlg
,comboID
)) {
1632 pdn
= GlobalLock(lppd
->hDevNames
);
1633 pdm
= GlobalLock(lppd
->hDevMode
);
1635 name
= (WCHAR
*)pdn
+ pdn
->wDeviceOffset
;
1637 name
= pdm
->dmDeviceName
;
1638 PRINTDLG_SetUpPrinterListComboW(hDlg
, comboID
, name
);
1639 if(pdm
) GlobalUnlock(lppd
->hDevMode
);
1640 if(pdn
) GlobalUnlock(lppd
->hDevNames
);
1642 /* Now find selected printer and update rest of dlg */
1643 /* ansi is ok here */
1644 name
= HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR
));
1645 if (GetDlgItemTextW(hDlg
, comboID
, name
, 255))
1646 PRINTDLG_ChangePrinterW(hDlg
, name
, PrintStructures
);
1647 HeapFree(GetProcessHeap(),0,name
);
1649 /* else use default printer */
1651 DWORD dwBufLen
= sizeof(name
) / sizeof(WCHAR
);
1652 BOOL ret
= GetDefaultPrinterW(name
, &dwBufLen
);
1655 PRINTDLG_ChangePrinterW(hDlg
, name
, PrintStructures
);
1657 FIXME("No default printer found, expect problems!\n");
1662 /***********************************************************************
1663 * PRINTDLG_WMCommand [internal]
1665 static LRESULT
PRINTDLG_WMCommandA(HWND hDlg
, WPARAM wParam
,
1666 PRINT_PTRA
* PrintStructures
)
1668 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1669 UINT PrinterComboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1670 LPDEVMODEA lpdm
= PrintStructures
->lpDevMode
;
1672 switch (LOWORD(wParam
)) {
1674 TRACE(" OK button was hit\n");
1675 if (!PRINTDLG_UpdatePrintDlgA(hDlg
, PrintStructures
)) {
1676 FIXME("Update printdlg was not successful!\n");
1679 EndDialog(hDlg
, TRUE
);
1683 TRACE(" CANCEL button was hit\n");
1684 EndDialog(hDlg
, FALSE
);
1688 TRACE(" HELP button was hit\n");
1689 SendMessageA(lppd
->hwndOwner
, PrintStructures
->HelpMessageID
,
1690 (WPARAM
) hDlg
, (LPARAM
) lppd
);
1693 case chx2
: /* collate pages checkbox */
1694 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
1695 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1696 (LPARAM
)PrintStructures
->hCollateIcon
);
1698 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1699 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1701 case edt1
: /* from page nr editbox */
1702 case edt2
: /* to page nr editbox */
1703 if (HIWORD(wParam
)==EN_CHANGE
) {
1706 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
1707 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
1708 if (nFromPage
!= lppd
->nFromPage
|| nToPage
!= lppd
->nToPage
)
1709 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1714 if(HIWORD(wParam
) == EN_CHANGE
) {
1715 INT copies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
1717 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1719 EnableWindow(GetDlgItem(hDlg
, chx2
), TRUE
);
1723 case psh2
: /* Properties button */
1726 char PrinterName
[256];
1728 GetDlgItemTextA(hDlg
, PrinterComboID
, PrinterName
, 255);
1729 if (!OpenPrinterA(PrinterName
, &hPrinter
, NULL
)) {
1730 FIXME(" Call to OpenPrinter did not succeed!\n");
1733 DocumentPropertiesA(hDlg
, hPrinter
, PrinterName
,
1734 PrintStructures
->lpDevMode
,
1735 PrintStructures
->lpDevMode
,
1736 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
1737 ClosePrinter(hPrinter
);
1741 case rad1
: /* Paperorientation */
1742 if (lppd
->Flags
& PD_PRINTSETUP
)
1744 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1745 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1746 (LPARAM
)(PrintStructures
->hPortraitIcon
));
1750 case rad2
: /* Paperorientation */
1751 if (lppd
->Flags
& PD_PRINTSETUP
)
1753 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1754 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1755 (LPARAM
)(PrintStructures
->hLandscapeIcon
));
1759 case cmb1
: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT16 */
1760 if (PrinterComboID
!= LOWORD(wParam
)) {
1764 case cmb4
: /* Printer combobox */
1765 if (HIWORD(wParam
)==CBN_SELCHANGE
) {
1767 INT index
= SendDlgItemMessageW(hDlg
, LOWORD(wParam
), CB_GETCURSEL
, 0, 0);
1768 INT length
= SendDlgItemMessageW(hDlg
, LOWORD(wParam
), CB_GETLBTEXTLEN
, index
, 0);
1769 PrinterName
= HeapAlloc(GetProcessHeap(),0,length
+1);
1770 SendDlgItemMessageA(hDlg
, LOWORD(wParam
), CB_GETLBTEXT
, index
, (LPARAM
)PrinterName
);
1771 PRINTDLG_ChangePrinterA(hDlg
, PrinterName
, PrintStructures
);
1772 HeapFree(GetProcessHeap(),0,PrinterName
);
1776 case cmb2
: /* Papersize */
1778 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
1780 lpdm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageA(hDlg
, cmb2
,
1786 case cmb3
: /* Bin */
1788 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
1790 lpdm
->u1
.s1
.dmDefaultSource
= SendDlgItemMessageA(hDlg
, cmb3
,
1791 CB_GETITEMDATA
, Sel
,
1796 if(lppd
->Flags
& PD_PRINTSETUP
) {
1797 switch (LOWORD(wParam
)) {
1798 case rad1
: /* orientation */
1800 if (IsDlgButtonChecked(hDlg
, rad1
) == BST_CHECKED
) {
1801 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_PORTRAIT
) {
1802 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1803 SendDlgItemMessageA(hDlg
, stc10
, STM_SETIMAGE
, IMAGE_ICON
,
1804 (LPARAM
)PrintStructures
->hPortraitIcon
);
1805 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1806 (LPARAM
)PrintStructures
->hPortraitIcon
);
1809 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_LANDSCAPE
) {
1810 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1811 SendDlgItemMessageA(hDlg
, stc10
, STM_SETIMAGE
, IMAGE_ICON
,
1812 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1813 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1814 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1823 static LRESULT
PRINTDLG_WMCommandW(HWND hDlg
, WPARAM wParam
,
1824 PRINT_PTRW
* PrintStructures
)
1826 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1827 UINT PrinterComboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1828 LPDEVMODEW lpdm
= PrintStructures
->lpDevMode
;
1830 switch (LOWORD(wParam
)) {
1832 TRACE(" OK button was hit\n");
1833 if (!PRINTDLG_UpdatePrintDlgW(hDlg
, PrintStructures
)) {
1834 FIXME("Update printdlg was not successful!\n");
1837 EndDialog(hDlg
, TRUE
);
1841 TRACE(" CANCEL button was hit\n");
1842 EndDialog(hDlg
, FALSE
);
1846 TRACE(" HELP button was hit\n");
1847 SendMessageW(lppd
->hwndOwner
, PrintStructures
->HelpMessageID
,
1848 (WPARAM
) hDlg
, (LPARAM
) lppd
);
1851 case chx2
: /* collate pages checkbox */
1852 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
1853 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1854 (LPARAM
)PrintStructures
->hCollateIcon
);
1856 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1857 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1859 case edt1
: /* from page nr editbox */
1860 case edt2
: /* to page nr editbox */
1861 if (HIWORD(wParam
)==EN_CHANGE
) {
1864 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
1865 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
1866 if (nFromPage
!= lppd
->nFromPage
|| nToPage
!= lppd
->nToPage
)
1867 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1872 if(HIWORD(wParam
) == EN_CHANGE
) {
1873 INT copies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
1875 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1877 EnableWindow(GetDlgItem(hDlg
, chx2
), TRUE
);
1881 case psh2
: /* Properties button */
1884 WCHAR PrinterName
[256];
1886 if (!GetDlgItemTextW(hDlg
, PrinterComboID
, PrinterName
, 255)) break;
1887 if (!OpenPrinterW(PrinterName
, &hPrinter
, NULL
)) {
1888 FIXME(" Call to OpenPrinter did not succeed!\n");
1891 DocumentPropertiesW(hDlg
, hPrinter
, PrinterName
,
1892 PrintStructures
->lpDevMode
,
1893 PrintStructures
->lpDevMode
,
1894 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
1895 ClosePrinter(hPrinter
);
1899 case rad1
: /* Paperorientation */
1900 if (lppd
->Flags
& PD_PRINTSETUP
)
1902 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1903 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1904 (LPARAM
)(PrintStructures
->hPortraitIcon
));
1908 case rad2
: /* Paperorientation */
1909 if (lppd
->Flags
& PD_PRINTSETUP
)
1911 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1912 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1913 (LPARAM
)(PrintStructures
->hLandscapeIcon
));
1917 case cmb1
: /* Printer Combobox in PRINT SETUP */
1919 case cmb4
: /* Printer combobox */
1920 if (HIWORD(wParam
)==CBN_SELCHANGE
) {
1922 INT index
= SendDlgItemMessageW(hDlg
, LOWORD(wParam
), CB_GETCURSEL
, 0, 0);
1923 INT length
= SendDlgItemMessageW(hDlg
, LOWORD(wParam
), CB_GETLBTEXTLEN
, index
, 0);
1925 PrinterName
= HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*(length
+1));
1926 SendDlgItemMessageW(hDlg
, LOWORD(wParam
), CB_GETLBTEXT
, index
, (LPARAM
)PrinterName
);
1927 PRINTDLG_ChangePrinterW(hDlg
, PrinterName
, PrintStructures
);
1928 HeapFree(GetProcessHeap(),0,PrinterName
);
1932 case cmb2
: /* Papersize */
1934 DWORD Sel
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
1936 lpdm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageW(hDlg
, cmb2
,
1942 case cmb3
: /* Bin */
1944 DWORD Sel
= SendDlgItemMessageW(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
1946 lpdm
->u1
.s1
.dmDefaultSource
= SendDlgItemMessageW(hDlg
, cmb3
,
1947 CB_GETITEMDATA
, Sel
,
1952 if(lppd
->Flags
& PD_PRINTSETUP
) {
1953 switch (LOWORD(wParam
)) {
1954 case rad1
: /* orientation */
1956 if (IsDlgButtonChecked(hDlg
, rad1
) == BST_CHECKED
) {
1957 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_PORTRAIT
) {
1958 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1959 SendDlgItemMessageW(hDlg
, stc10
, STM_SETIMAGE
, IMAGE_ICON
,
1960 (LPARAM
)PrintStructures
->hPortraitIcon
);
1961 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1962 (LPARAM
)PrintStructures
->hPortraitIcon
);
1965 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_LANDSCAPE
) {
1966 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1967 SendDlgItemMessageW(hDlg
, stc10
, STM_SETIMAGE
, IMAGE_ICON
,
1968 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1969 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1970 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1979 /***********************************************************************
1980 * PrintDlgProcA [internal]
1982 static INT_PTR CALLBACK
PrintDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
1985 PRINT_PTRA
* PrintStructures
;
1986 INT_PTR res
= FALSE
;
1988 if (uMsg
!=WM_INITDIALOG
) {
1989 PrintStructures
= GetPropW(hDlg
, printdlg_prop
);
1990 if (!PrintStructures
)
1993 PrintStructures
= (PRINT_PTRA
*) lParam
;
1994 SetPropW(hDlg
, printdlg_prop
, PrintStructures
);
1995 if(!check_printer_setup(hDlg
))
1997 EndDialog(hDlg
,FALSE
);
2000 res
= PRINTDLG_WMInitDialog(hDlg
, PrintStructures
);
2002 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
)
2003 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(
2004 hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->lpPrintDlg
2009 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
) {
2010 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
,uMsg
,wParam
,
2017 return PRINTDLG_WMCommandA(hDlg
, wParam
, PrintStructures
);
2020 DestroyIcon(PrintStructures
->hCollateIcon
);
2021 DestroyIcon(PrintStructures
->hNoCollateIcon
);
2022 DestroyIcon(PrintStructures
->hPortraitIcon
);
2023 DestroyIcon(PrintStructures
->hLandscapeIcon
);
2024 if(PrintStructures
->hwndUpDown
)
2025 DestroyWindow(PrintStructures
->hwndUpDown
);
2031 static INT_PTR CALLBACK
PrintDlgProcW(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
2034 PRINT_PTRW
* PrintStructures
;
2035 INT_PTR res
= FALSE
;
2037 if (uMsg
!=WM_INITDIALOG
) {
2038 PrintStructures
= GetPropW(hDlg
, printdlg_prop
);
2039 if (!PrintStructures
)
2042 PrintStructures
= (PRINT_PTRW
*) lParam
;
2043 SetPropW(hDlg
, printdlg_prop
, PrintStructures
);
2044 if(!check_printer_setup(hDlg
))
2046 EndDialog(hDlg
,FALSE
);
2049 res
= PRINTDLG_WMInitDialogW(hDlg
, PrintStructures
);
2051 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
)
2052 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->lpPrintDlg
);
2056 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
) {
2057 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
,uMsg
,wParam
, lParam
);
2063 return PRINTDLG_WMCommandW(hDlg
, wParam
, PrintStructures
);
2066 DestroyIcon(PrintStructures
->hCollateIcon
);
2067 DestroyIcon(PrintStructures
->hNoCollateIcon
);
2068 DestroyIcon(PrintStructures
->hPortraitIcon
);
2069 DestroyIcon(PrintStructures
->hLandscapeIcon
);
2070 if(PrintStructures
->hwndUpDown
)
2071 DestroyWindow(PrintStructures
->hwndUpDown
);
2077 /************************************************************
2079 * PRINTDLG_GetDlgTemplate
2082 static HGLOBAL
PRINTDLG_GetDlgTemplateA(const PRINTDLGA
*lppd
)
2087 if (lppd
->Flags
& PD_PRINTSETUP
) {
2088 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
2089 hDlgTmpl
= lppd
->hSetupTemplate
;
2090 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
2091 hResInfo
= FindResourceA(lppd
->hInstance
,
2092 lppd
->lpSetupTemplateName
, (LPSTR
)RT_DIALOG
);
2093 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
2095 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32_SETUP",
2097 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
2100 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
2101 hDlgTmpl
= lppd
->hPrintTemplate
;
2102 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
2103 hResInfo
= FindResourceA(lppd
->hInstance
,
2104 lppd
->lpPrintTemplateName
,
2106 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
2108 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32",
2110 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
2116 static HGLOBAL
PRINTDLG_GetDlgTemplateW(const PRINTDLGW
*lppd
)
2120 static const WCHAR xpsetup
[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
2121 static const WCHAR xprint
[] = { 'P','R','I','N','T','3','2',0};
2123 if (lppd
->Flags
& PD_PRINTSETUP
) {
2124 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
2125 hDlgTmpl
= lppd
->hSetupTemplate
;
2126 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
2127 hResInfo
= FindResourceW(lppd
->hInstance
,
2128 lppd
->lpSetupTemplateName
, (LPWSTR
)RT_DIALOG
);
2129 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
2131 hResInfo
= FindResourceW(COMDLG32_hInstance
, xpsetup
, (LPWSTR
)RT_DIALOG
);
2132 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
2135 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
2136 hDlgTmpl
= lppd
->hPrintTemplate
;
2137 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
2138 hResInfo
= FindResourceW(lppd
->hInstance
,
2139 lppd
->lpPrintTemplateName
,
2141 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
2143 hResInfo
= FindResourceW(COMDLG32_hInstance
, xprint
, (LPWSTR
)RT_DIALOG
);
2144 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
2150 /***********************************************************************
2155 static BOOL
PRINTDLG_CreateDCA(LPPRINTDLGA lppd
)
2157 DEVNAMES
*pdn
= GlobalLock(lppd
->hDevNames
);
2158 DEVMODEA
*pdm
= GlobalLock(lppd
->hDevMode
);
2160 if(lppd
->Flags
& PD_RETURNDC
) {
2161 lppd
->hDC
= CreateDCA((char*)pdn
+ pdn
->wDriverOffset
,
2162 (char*)pdn
+ pdn
->wDeviceOffset
,
2163 (char*)pdn
+ pdn
->wOutputOffset
,
2165 } else if(lppd
->Flags
& PD_RETURNIC
) {
2166 lppd
->hDC
= CreateICA((char*)pdn
+ pdn
->wDriverOffset
,
2167 (char*)pdn
+ pdn
->wDeviceOffset
,
2168 (char*)pdn
+ pdn
->wOutputOffset
,
2171 GlobalUnlock(lppd
->hDevNames
);
2172 GlobalUnlock(lppd
->hDevMode
);
2173 return lppd
->hDC
!= NULL
;
2176 static BOOL
PRINTDLG_CreateDCW(LPPRINTDLGW lppd
)
2178 DEVNAMES
*pdn
= GlobalLock(lppd
->hDevNames
);
2179 DEVMODEW
*pdm
= GlobalLock(lppd
->hDevMode
);
2181 if(lppd
->Flags
& PD_RETURNDC
) {
2182 lppd
->hDC
= CreateDCW((WCHAR
*)pdn
+ pdn
->wDriverOffset
,
2183 (WCHAR
*)pdn
+ pdn
->wDeviceOffset
,
2184 (WCHAR
*)pdn
+ pdn
->wOutputOffset
,
2186 } else if(lppd
->Flags
& PD_RETURNIC
) {
2187 lppd
->hDC
= CreateICW((WCHAR
*)pdn
+ pdn
->wDriverOffset
,
2188 (WCHAR
*)pdn
+ pdn
->wDeviceOffset
,
2189 (WCHAR
*)pdn
+ pdn
->wOutputOffset
,
2192 GlobalUnlock(lppd
->hDevNames
);
2193 GlobalUnlock(lppd
->hDevMode
);
2194 return lppd
->hDC
!= NULL
;
2197 /***********************************************************************
2198 * PrintDlgA (COMDLG32.@)
2200 * Displays the PRINT dialog box, which enables the user to specify
2201 * specific properties of the print job.
2204 * lppd [IO] ptr to PRINTDLG32 struct
2207 * nonzero if the user pressed the OK button
2208 * zero if the user cancelled the window or an error occurred
2212 * * The Collate Icons do not display, even though they are in the code.
2213 * * The Properties Button(s) should call DocumentPropertiesA().
2216 BOOL WINAPI
PrintDlgA(LPPRINTDLGA lppd
)
2224 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
2228 if(TRACE_ON(commdlg
)) {
2229 char flagstr
[1000] = "";
2230 const struct pd_flags
*pflag
= pd_flags
;
2231 for( ; pflag
->name
; pflag
++) {
2232 if(lppd
->Flags
& pflag
->flag
)
2233 strcat(flagstr
, pflag
->name
);
2235 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2236 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2237 "flags %08x (%s)\n",
2238 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
2239 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
2240 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
2243 if(lppd
->lStructSize
!= sizeof(PRINTDLGA
)) {
2244 WARN("structure size failure!!!\n");
2245 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
2249 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
2250 PRINTER_INFO_2A
*pbuf
;
2251 DRIVER_INFO_3A
*dbuf
;
2255 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
2256 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2257 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2260 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
2261 WARN("Can't find default printer\n");
2262 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
2266 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
2267 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
2268 GetPrinterA(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
2270 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
2271 dbuf
= HeapAlloc(GetProcessHeap(),0,needed
);
2272 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
2273 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2274 GetLastError(),pbuf
->pPrinterName
);
2275 HeapFree(GetProcessHeap(), 0, dbuf
);
2276 HeapFree(GetProcessHeap(), 0, pbuf
);
2277 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2282 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
2286 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
2287 pbuf
->pDevMode
->dmDriverExtra
);
2288 ptr
= GlobalLock(lppd
->hDevMode
);
2289 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
2290 pbuf
->pDevMode
->dmDriverExtra
);
2291 GlobalUnlock(lppd
->hDevMode
);
2292 HeapFree(GetProcessHeap(), 0, pbuf
);
2293 HeapFree(GetProcessHeap(), 0, dbuf
);
2297 PRINT_PTRA
*PrintStructures
;
2299 /* load Dialog resources,
2300 * depending on Flags indicates Print32 or Print32_setup dialog
2302 hDlgTmpl
= PRINTDLG_GetDlgTemplateA(lppd
);
2304 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2307 ptr
= LockResource( hDlgTmpl
);
2309 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2313 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2314 sizeof(PRINT_PTRA
));
2315 PrintStructures
->lpPrintDlg
= lppd
;
2317 /* and create & process the dialog .
2318 * -1 is failure, 0 is broken hwnd, everything else is ok.
2320 hInst
= COMDLG32_hInstance
;
2321 if (lppd
->Flags
& (PD_ENABLESETUPTEMPLATE
| PD_ENABLEPRINTTEMPLATE
)) hInst
= lppd
->hInstance
;
2322 bRet
= (0<DialogBoxIndirectParamA(hInst
, ptr
, lppd
->hwndOwner
,
2324 (LPARAM
)PrintStructures
));
2327 DEVMODEA
*lpdm
= PrintStructures
->lpDevMode
, *lpdmReturn
;
2328 PRINTER_INFO_2A
*pi
= PrintStructures
->lpPrinterInfo
;
2329 DRIVER_INFO_3A
*di
= PrintStructures
->lpDriverInfo
;
2331 if (lppd
->hDevMode
== 0) {
2332 TRACE(" No hDevMode yet... Need to create my own\n");
2333 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
,
2334 lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2336 lppd
->hDevMode
= GlobalReAlloc(lppd
->hDevMode
,
2337 lpdm
->dmSize
+ lpdm
->dmDriverExtra
,
2340 lpdmReturn
= GlobalLock(lppd
->hDevMode
);
2341 memcpy(lpdmReturn
, lpdm
, lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2343 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
2348 GlobalUnlock(lppd
->hDevMode
);
2350 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
2351 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpPrinterInfo
);
2352 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDriverInfo
);
2353 HeapFree(GetProcessHeap(), 0, PrintStructures
);
2355 if(bRet
&& (lppd
->Flags
& PD_RETURNDC
|| lppd
->Flags
& PD_RETURNIC
))
2356 bRet
= PRINTDLG_CreateDCA(lppd
);
2358 TRACE("exit! (%d)\n", bRet
);
2362 /***********************************************************************
2363 * PrintDlgW (COMDLG32.@)
2367 BOOL WINAPI
PrintDlgW(LPPRINTDLGW lppd
)
2375 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
2379 if(TRACE_ON(commdlg
)) {
2380 char flagstr
[1000] = "";
2381 const struct pd_flags
*pflag
= pd_flags
;
2382 for( ; pflag
->name
; pflag
++) {
2383 if(lppd
->Flags
& pflag
->flag
)
2384 strcat(flagstr
, pflag
->name
);
2386 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2387 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2388 "flags %08x (%s)\n",
2389 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
2390 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
2391 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
2394 if(lppd
->lStructSize
!= sizeof(PRINTDLGW
)) {
2395 WARN("structure size failure!!!\n");
2396 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
2400 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
2401 PRINTER_INFO_2W
*pbuf
;
2402 DRIVER_INFO_3W
*dbuf
;
2406 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
2407 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2408 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2411 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
2412 WARN("Can't find default printer\n");
2413 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
2417 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
2418 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
2419 GetPrinterW(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
2421 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
2422 dbuf
= HeapAlloc(GetProcessHeap(),0,needed
);
2423 if (!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
2424 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2425 GetLastError(),debugstr_w(pbuf
->pPrinterName
));
2426 HeapFree(GetProcessHeap(), 0, dbuf
);
2427 HeapFree(GetProcessHeap(), 0, pbuf
);
2428 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2433 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
2437 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
2438 pbuf
->pDevMode
->dmDriverExtra
);
2439 ptr
= GlobalLock(lppd
->hDevMode
);
2440 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
2441 pbuf
->pDevMode
->dmDriverExtra
);
2442 GlobalUnlock(lppd
->hDevMode
);
2443 HeapFree(GetProcessHeap(), 0, pbuf
);
2444 HeapFree(GetProcessHeap(), 0, dbuf
);
2448 PRINT_PTRW
*PrintStructures
;
2450 /* load Dialog resources,
2451 * depending on Flags indicates Print32 or Print32_setup dialog
2453 hDlgTmpl
= PRINTDLG_GetDlgTemplateW(lppd
);
2455 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2458 ptr
= LockResource( hDlgTmpl
);
2460 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2464 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2465 sizeof(PRINT_PTRW
));
2466 PrintStructures
->lpPrintDlg
= lppd
;
2468 /* and create & process the dialog .
2469 * -1 is failure, 0 is broken hwnd, everything else is ok.
2471 hInst
= COMDLG32_hInstance
;
2472 if (lppd
->Flags
& (PD_ENABLESETUPTEMPLATE
| PD_ENABLEPRINTTEMPLATE
)) hInst
= lppd
->hInstance
;
2473 bRet
= (0<DialogBoxIndirectParamW(hInst
, ptr
, lppd
->hwndOwner
,
2475 (LPARAM
)PrintStructures
));
2478 DEVMODEW
*lpdm
= PrintStructures
->lpDevMode
, *lpdmReturn
;
2479 PRINTER_INFO_2W
*pi
= PrintStructures
->lpPrinterInfo
;
2480 DRIVER_INFO_3W
*di
= PrintStructures
->lpDriverInfo
;
2482 if (lppd
->hDevMode
== 0) {
2483 TRACE(" No hDevMode yet... Need to create my own\n");
2484 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
,
2485 lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2488 if((locks
= (GlobalFlags(lppd
->hDevMode
) & GMEM_LOCKCOUNT
))) {
2489 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks
);
2491 GlobalUnlock(lppd
->hDevMode
);
2492 TRACE("Now got %d locks\n", locks
);
2495 lppd
->hDevMode
= GlobalReAlloc(lppd
->hDevMode
,
2496 lpdm
->dmSize
+ lpdm
->dmDriverExtra
,
2499 lpdmReturn
= GlobalLock(lppd
->hDevMode
);
2500 memcpy(lpdmReturn
, lpdm
, lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2502 if (lppd
->hDevNames
!= 0) {
2504 if((locks
= (GlobalFlags(lppd
->hDevNames
) & GMEM_LOCKCOUNT
))) {
2505 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks
);
2507 GlobalUnlock(lppd
->hDevNames
);
2510 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
2515 GlobalUnlock(lppd
->hDevMode
);
2517 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
2518 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpPrinterInfo
);
2519 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDriverInfo
);
2520 HeapFree(GetProcessHeap(), 0, PrintStructures
);
2522 if(bRet
&& (lppd
->Flags
& PD_RETURNDC
|| lppd
->Flags
& PD_RETURNIC
))
2523 bRet
= PRINTDLG_CreateDCW(lppd
);
2525 TRACE("exit! (%d)\n", bRet
);
2529 /***********************************************************************
2534 * cmb1 - printer select (not in standard dialog template)
2536 * cmb3 - source (tray?)
2537 * edt4 - border left
2539 * edt6 - border right
2540 * edt7 - border bottom
2541 * psh3 - "Printer..."
2549 LPPAGESETUPDLGA dlga
;
2550 LPPAGESETUPDLGW dlgw
;
2552 HWND hDlg
; /* Page Setup dialog handle */
2553 RECT rtDrawRect
; /* Drawing rect for page */
2556 static inline DWORD
pagesetup_get_flags(const pagesetup_data
*data
)
2558 return data
->u
.dlgw
->Flags
;
2561 static inline BOOL
is_metric(const pagesetup_data
*data
)
2563 return pagesetup_get_flags(data
) & PSD_INHUNDREDTHSOFMILLIMETERS
;
2566 static inline LONG
tenths_mm_to_size(const pagesetup_data
*data
, LONG size
)
2568 if (is_metric(data
))
2571 return 10 * size
* 100 / 254;
2574 static inline LONG
thousandths_inch_to_size(const pagesetup_data
*data
, LONG size
)
2576 if (is_metric(data
))
2577 return size
* 254 / 100;
2582 static WCHAR
get_decimal_sep(void)
2588 WCHAR buf
[] = {'.', 0};
2589 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SDECIMAL
, buf
, sizeof(buf
) / sizeof(buf
[0]));
2595 static void size2str(const pagesetup_data
*data
, DWORD size
, LPWSTR strout
)
2597 WCHAR integer_fmt
[] = {'%','d',0};
2598 WCHAR hundredths_fmt
[] = {'%','d','%','c','%','0','2','d',0};
2599 WCHAR thousandths_fmt
[] = {'%','d','%','c','%','0','3','d',0};
2601 /* FIXME use LOCALE_SDECIMAL when the edit parsing code can cope */
2603 if (is_metric(data
))
2606 wsprintfW(strout
, hundredths_fmt
, size
/ 100, get_decimal_sep(), size
% 100);
2608 wsprintfW(strout
, integer_fmt
, size
/ 100);
2613 wsprintfW(strout
, thousandths_fmt
, size
/ 1000, get_decimal_sep(), size
% 1000);
2615 wsprintfW(strout
, integer_fmt
, size
/ 1000);
2620 static inline BOOL
is_default_metric(void)
2623 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_IMEASURE
| LOCALE_RETURN_NUMBER
,
2624 (LPWSTR
)&system
, sizeof(system
));
2628 /**********************************************
2630 * Cyclically permute the four members of rc
2631 * If sense is TRUE l -> t -> r -> b
2632 * otherwise l <- t <- r <- b
2634 static inline void rotate_rect(RECT
*rc
, BOOL sense
)
2640 rc
->bottom
= rc
->right
;
2641 rc
->right
= rc
->top
;
2649 rc
->top
= rc
->right
;
2650 rc
->right
= rc
->bottom
;
2655 static void pagesetup_set_orientation(pagesetup_data
*data
, WORD orient
)
2657 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2659 assert(orient
== DMORIENT_PORTRAIT
|| orient
== DMORIENT_LANDSCAPE
);
2662 dm
->u1
.s1
.dmOrientation
= orient
;
2665 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2666 dmA
->u1
.s1
.dmOrientation
= orient
;
2668 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2671 static WORD
pagesetup_get_orientation(const pagesetup_data
*data
)
2673 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2677 orient
= dm
->u1
.s1
.dmOrientation
;
2680 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2681 orient
= dmA
->u1
.s1
.dmOrientation
;
2683 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2687 static void pagesetup_set_papersize(pagesetup_data
*data
, WORD paper
)
2689 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2692 dm
->u1
.s1
.dmPaperSize
= paper
;
2695 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2696 dmA
->u1
.s1
.dmPaperSize
= paper
;
2698 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2701 static WORD
pagesetup_get_papersize(const pagesetup_data
*data
)
2703 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2707 paper
= dm
->u1
.s1
.dmPaperSize
;
2710 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2711 paper
= dmA
->u1
.s1
.dmPaperSize
;
2713 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2717 static void pagesetup_set_defaultsource(pagesetup_data
*data
, WORD source
)
2719 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2722 dm
->u1
.s1
.dmDefaultSource
= source
;
2725 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2726 dmA
->u1
.s1
.dmDefaultSource
= source
;
2728 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2733 devnames_driver_name
,
2734 devnames_device_name
,
2735 devnames_output_name
2739 static inline WORD
get_devname_offset(const DEVNAMES
*dn
, devnames_name which
)
2743 case devnames_driver_name
: return dn
->wDriverOffset
;
2744 case devnames_device_name
: return dn
->wDeviceOffset
;
2745 case devnames_output_name
: return dn
->wOutputOffset
;
2747 ERR("Shouldn't be here\n");
2751 static WCHAR
*pagesetup_get_a_devname(const pagesetup_data
*data
, devnames_name which
)
2756 dn
= GlobalLock(data
->u
.dlgw
->hDevNames
);
2758 name
= strdupW((WCHAR
*)dn
+ get_devname_offset(dn
, which
));
2761 int len
= MultiByteToWideChar(CP_ACP
, 0, (char*)dn
+ get_devname_offset(dn
, which
), -1, NULL
, 0);
2762 name
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
2763 MultiByteToWideChar(CP_ACP
, 0, (char*)dn
+ get_devname_offset(dn
, which
), -1, name
, len
);
2765 GlobalUnlock(data
->u
.dlgw
->hDevNames
);
2769 static WCHAR
*pagesetup_get_drvname(const pagesetup_data
*data
)
2771 return pagesetup_get_a_devname(data
, devnames_driver_name
);
2774 static WCHAR
*pagesetup_get_devname(const pagesetup_data
*data
)
2776 return pagesetup_get_a_devname(data
, devnames_device_name
);
2779 static WCHAR
*pagesetup_get_portname(const pagesetup_data
*data
)
2781 return pagesetup_get_a_devname(data
, devnames_output_name
);
2784 static void pagesetup_release_a_devname(const pagesetup_data
*data
, WCHAR
*name
)
2786 HeapFree(GetProcessHeap(), 0, name
);
2789 static void pagesetup_set_devnames(pagesetup_data
*data
, LPCWSTR drv
, LPCWSTR devname
, LPCWSTR port
)
2793 DWORD len
= sizeof(DEVNAMES
), drv_len
, dev_len
, port_len
;
2797 drv_len
= (strlenW(drv
) + 1) * sizeof(WCHAR
);
2798 dev_len
= (strlenW(devname
) + 1) * sizeof(WCHAR
);
2799 port_len
= (strlenW(port
) + 1) * sizeof(WCHAR
);
2803 drv_len
= WideCharToMultiByte(CP_ACP
, 0, drv
, -1, NULL
, 0, NULL
, NULL
);
2804 dev_len
= WideCharToMultiByte(CP_ACP
, 0, devname
, -1, NULL
, 0, NULL
, NULL
);
2805 port_len
= WideCharToMultiByte(CP_ACP
, 0, port
, -1, NULL
, 0, NULL
, NULL
);
2807 len
+= drv_len
+ dev_len
+ port_len
;
2809 if(data
->u
.dlgw
->hDevNames
)
2810 data
->u
.dlgw
->hDevNames
= GlobalReAlloc(data
->u
.dlgw
->hDevNames
, len
, GMEM_MOVEABLE
);
2812 data
->u
.dlgw
->hDevNames
= GlobalAlloc(GMEM_MOVEABLE
, len
);
2814 dn
= GlobalLock(data
->u
.dlgw
->hDevNames
);
2818 WCHAR
*ptr
= (WCHAR
*)(dn
+ 1);
2819 len
= sizeof(DEVNAMES
) / sizeof(WCHAR
);
2820 dn
->wDriverOffset
= len
;
2822 ptr
+= drv_len
/ sizeof(WCHAR
);
2823 len
+= drv_len
/ sizeof(WCHAR
);
2824 dn
->wDeviceOffset
= len
;
2825 strcpyW(ptr
, devname
);
2826 ptr
+= dev_len
/ sizeof(WCHAR
);
2827 len
+= dev_len
/ sizeof(WCHAR
);
2828 dn
->wOutputOffset
= len
;
2833 char *ptr
= (char *)(dn
+ 1);
2834 len
= sizeof(DEVNAMES
);
2835 dn
->wDriverOffset
= len
;
2836 WideCharToMultiByte(CP_ACP
, 0, drv
, -1, ptr
, drv_len
, NULL
, NULL
);
2839 dn
->wDeviceOffset
= len
;
2840 WideCharToMultiByte(CP_ACP
, 0, devname
, -1, ptr
, dev_len
, NULL
, NULL
);
2843 dn
->wOutputOffset
= len
;
2844 WideCharToMultiByte(CP_ACP
, 0, port
, -1, ptr
, port_len
, NULL
, NULL
);
2848 len
= sizeof(def
) / sizeof(def
[0]);
2849 GetDefaultPrinterW(def
, &len
);
2850 if(!lstrcmpW(def
, devname
))
2853 GlobalUnlock(data
->u
.dlgw
->hDevNames
);
2856 static DEVMODEW
*pagesetup_get_devmode(const pagesetup_data
*data
)
2858 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2863 /* We make a copy even in the unicode case because the ptr
2864 may get passed back to us in pagesetup_set_devmode. */
2865 ret
= HeapAlloc(GetProcessHeap(), 0, dm
->dmSize
+ dm
->dmDriverExtra
);
2866 memcpy(ret
, dm
, dm
->dmSize
+ dm
->dmDriverExtra
);
2869 ret
= GdiConvertToDevmodeW((DEVMODEA
*)dm
);
2871 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2875 static void pagesetup_release_devmode(const pagesetup_data
*data
, DEVMODEW
*dm
)
2877 HeapFree(GetProcessHeap(), 0, dm
);
2880 static void pagesetup_set_devmode(pagesetup_data
*data
, DEVMODEW
*dm
)
2882 DEVMODEA
*dmA
= NULL
;
2888 size
= dm
->dmSize
+ dm
->dmDriverExtra
;
2893 dmA
= convert_to_devmodeA(dm
);
2894 size
= dmA
->dmSize
+ dmA
->dmDriverExtra
;
2898 if(data
->u
.dlgw
->hDevMode
)
2899 data
->u
.dlgw
->hDevMode
= GlobalReAlloc(data
->u
.dlgw
->hDevMode
, size
,
2902 data
->u
.dlgw
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, size
);
2904 dst
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2905 memcpy(dst
, src
, size
);
2906 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2907 HeapFree(GetProcessHeap(), 0, dmA
);
2910 static inline POINT
*pagesetup_get_papersize_pt(const pagesetup_data
*data
)
2912 return &data
->u
.dlgw
->ptPaperSize
;
2915 static inline RECT
*pagesetup_get_margin_rect(const pagesetup_data
*data
)
2917 return &data
->u
.dlgw
->rtMargin
;
2926 static inline LPPAGESETUPHOOK
pagesetup_get_hook(const pagesetup_data
*data
, hook_type which
)
2930 case page_setup_hook
: return data
->u
.dlgw
->lpfnPageSetupHook
;
2931 case page_paint_hook
: return data
->u
.dlgw
->lpfnPagePaintHook
;
2936 /* This should only be used in calls to hook procs so we return the ptr
2937 already cast to LPARAM */
2938 static inline LPARAM
pagesetup_get_dlg_struct(const pagesetup_data
*data
)
2940 return (LPARAM
)data
->u
.dlgw
;
2943 static inline void swap_point(POINT
*pt
)
2950 static BOOL
pagesetup_update_papersize(pagesetup_data
*data
)
2953 LPWSTR devname
, portname
;
2955 WORD
*words
= NULL
, paperword
;
2956 POINT
*points
= NULL
;
2957 BOOL retval
= FALSE
;
2959 dm
= pagesetup_get_devmode(data
);
2960 devname
= pagesetup_get_devname(data
);
2961 portname
= pagesetup_get_portname(data
);
2963 num
= DeviceCapabilitiesW(devname
, portname
, DC_PAPERS
, NULL
, dm
);
2966 FIXME("No papernames found for %s/%s\n", debugstr_w(devname
), debugstr_w(portname
));
2970 words
= HeapAlloc(GetProcessHeap(), 0, num
* sizeof(WORD
));
2971 points
= HeapAlloc(GetProcessHeap(), 0, num
* sizeof(POINT
));
2973 if (num
!= DeviceCapabilitiesW(devname
, portname
, DC_PAPERS
, (LPWSTR
)words
, dm
))
2975 FIXME("Number of returned words is not %d\n", num
);
2979 if (num
!= DeviceCapabilitiesW(devname
, portname
, DC_PAPERSIZE
, (LPWSTR
)points
, dm
))
2981 FIXME("Number of returned sizes is not %d\n", num
);
2985 paperword
= pagesetup_get_papersize(data
);
2987 for (i
= 0; i
< num
; i
++)
2988 if (words
[i
] == paperword
)
2993 FIXME("Papersize %d not found in list?\n", paperword
);
2997 /* this is _10ths_ of a millimeter */
2998 pagesetup_get_papersize_pt(data
)->x
= tenths_mm_to_size(data
, points
[i
].x
);
2999 pagesetup_get_papersize_pt(data
)->y
= tenths_mm_to_size(data
, points
[i
].y
);
3001 if(pagesetup_get_orientation(data
) == DMORIENT_LANDSCAPE
)
3002 swap_point(pagesetup_get_papersize_pt(data
));
3007 HeapFree(GetProcessHeap(), 0, words
);
3008 HeapFree(GetProcessHeap(), 0, points
);
3009 pagesetup_release_a_devname(data
, portname
);
3010 pagesetup_release_a_devname(data
, devname
);
3011 pagesetup_release_devmode(data
, dm
);
3016 /**********************************************************************************************
3017 * pagesetup_change_printer
3019 * Redefines hDevMode and hDevNames HANDLES and initialises it.
3022 static BOOL
pagesetup_change_printer(LPWSTR name
, pagesetup_data
*data
)
3026 PRINTER_INFO_2W
*prn_info
= NULL
;
3027 DRIVER_INFO_3W
*drv_info
= NULL
;
3028 DEVMODEW
*dm
= NULL
;
3029 BOOL retval
= FALSE
;
3031 if(!OpenPrinterW(name
, &hprn
, NULL
))
3033 ERR("Can't open printer %s\n", debugstr_w(name
));
3037 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
3038 prn_info
= HeapAlloc(GetProcessHeap(), 0, needed
);
3039 GetPrinterW(hprn
, 2, (LPBYTE
)prn_info
, needed
, &needed
);
3040 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
3041 drv_info
= HeapAlloc(GetProcessHeap(), 0, needed
);
3042 if(!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)drv_info
, needed
, &needed
))
3044 ERR("GetPrinterDriverA failed for %s, fix your config!\n", debugstr_w(prn_info
->pPrinterName
));
3049 needed
= DocumentPropertiesW(0, 0, name
, NULL
, NULL
, 0);
3052 ERR("DocumentProperties fails on %s\n", debugstr_w(name
));
3056 dm
= HeapAlloc(GetProcessHeap(), 0, needed
);
3057 DocumentPropertiesW(0, 0, name
, dm
, NULL
, DM_OUT_BUFFER
);
3059 pagesetup_set_devmode(data
, dm
);
3060 pagesetup_set_devnames(data
, drv_info
->pDriverPath
, prn_info
->pPrinterName
,
3061 prn_info
->pPortName
);
3065 HeapFree(GetProcessHeap(), 0, dm
);
3066 HeapFree(GetProcessHeap(), 0, prn_info
);
3067 HeapFree(GetProcessHeap(), 0, drv_info
);
3071 /****************************************************************************************
3072 * pagesetup_init_combos
3074 * Fills Printers, Paper and Source combos
3077 static void pagesetup_init_combos(HWND hDlg
, pagesetup_data
*data
)
3080 LPWSTR devname
, portname
;
3082 dm
= pagesetup_get_devmode(data
);
3083 devname
= pagesetup_get_devname(data
);
3084 portname
= pagesetup_get_portname(data
);
3086 PRINTDLG_SetUpPrinterListComboW(hDlg
, cmb1
, devname
);
3087 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb2
, devname
, portname
, dm
);
3088 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb3
, devname
, portname
, dm
);
3090 pagesetup_release_a_devname(data
, portname
);
3091 pagesetup_release_a_devname(data
, devname
);
3092 pagesetup_release_devmode(data
, dm
);
3096 /****************************************************************************************
3097 * pagesetup_change_printer_dialog
3099 * Pops up another dialog that lets the user pick another printer.
3101 * For now we display the PrintDlg, this should display a striped down version of it.
3103 static void pagesetup_change_printer_dialog(HWND hDlg
, pagesetup_data
*data
)
3106 LPWSTR drvname
, devname
, portname
;
3107 DEVMODEW
*tmp_dm
, *dm
;
3109 memset(&prnt
, 0, sizeof(prnt
));
3110 prnt
.lStructSize
= sizeof(prnt
);
3112 prnt
.hwndOwner
= hDlg
;
3114 drvname
= pagesetup_get_drvname(data
);
3115 devname
= pagesetup_get_devname(data
);
3116 portname
= pagesetup_get_portname(data
);
3118 PRINTDLG_CreateDevNamesW(&prnt
.hDevNames
, drvname
, devname
, portname
);
3119 pagesetup_release_a_devname(data
, portname
);
3120 pagesetup_release_a_devname(data
, devname
);
3121 pagesetup_release_a_devname(data
, drvname
);
3123 tmp_dm
= pagesetup_get_devmode(data
);
3124 prnt
.hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, tmp_dm
->dmSize
+ tmp_dm
->dmDriverExtra
);
3125 dm
= GlobalLock(prnt
.hDevMode
);
3126 memcpy(dm
, tmp_dm
, tmp_dm
->dmSize
+ tmp_dm
->dmDriverExtra
);
3127 GlobalUnlock(prnt
.hDevMode
);
3128 pagesetup_release_devmode(data
, tmp_dm
);
3130 if (PrintDlgW(&prnt
))
3132 DEVMODEW
*dm
= GlobalLock(prnt
.hDevMode
);
3133 DEVNAMES
*dn
= GlobalLock(prnt
.hDevNames
);
3135 pagesetup_set_devnames(data
, (WCHAR
*)dn
+ dn
->wDriverOffset
,
3136 (WCHAR
*)dn
+ dn
->wDeviceOffset
, (WCHAR
*)dn
+ dn
->wOutputOffset
);
3137 pagesetup_set_devmode(data
, dm
);
3138 GlobalUnlock(prnt
.hDevNames
);
3139 GlobalUnlock(prnt
.hDevMode
);
3140 pagesetup_init_combos(hDlg
, data
);
3143 GlobalFree(prnt
.hDevMode
);
3144 GlobalFree(prnt
.hDevNames
);
3148 /******************************************************************************************
3149 * pagesetup_change_preview
3151 * Changes paper preview size / position
3154 static void pagesetup_change_preview(const pagesetup_data
*data
)
3156 LONG width
, height
, x
, y
;
3158 const int shadow
= 4;
3160 if(pagesetup_get_orientation(data
) == DMORIENT_LANDSCAPE
)
3162 width
= data
->rtDrawRect
.right
- data
->rtDrawRect
.left
;
3163 height
= pagesetup_get_papersize_pt(data
)->y
* width
/ pagesetup_get_papersize_pt(data
)->x
;
3167 height
= data
->rtDrawRect
.bottom
- data
->rtDrawRect
.top
;
3168 width
= pagesetup_get_papersize_pt(data
)->x
* height
/ pagesetup_get_papersize_pt(data
)->y
;
3170 x
= (data
->rtDrawRect
.right
+ data
->rtDrawRect
.left
- width
) / 2;
3171 y
= (data
->rtDrawRect
.bottom
+ data
->rtDrawRect
.top
- height
) / 2;
3172 TRACE("draw rect %s x=%d, y=%d, w=%d, h=%d\n",
3173 wine_dbgstr_rect(&data
->rtDrawRect
), x
, y
, width
, height
);
3175 MoveWindow(GetDlgItem(data
->hDlg
, rct2
), x
+ width
, y
+ shadow
, shadow
, height
, FALSE
);
3176 MoveWindow(GetDlgItem(data
->hDlg
, rct3
), x
+ shadow
, y
+ height
, width
, shadow
, FALSE
);
3177 MoveWindow(GetDlgItem(data
->hDlg
, rct1
), x
, y
, width
, height
, FALSE
);
3179 tmp
= data
->rtDrawRect
;
3180 tmp
.right
+= shadow
;
3181 tmp
.bottom
+= shadow
;
3182 InvalidateRect(data
->hDlg
, &tmp
, TRUE
);
3185 static inline LONG
*element_from_margin_id(RECT
*rc
, WORD id
)
3189 case edt4
: return &rc
->left
;
3190 case edt5
: return &rc
->top
;
3191 case edt6
: return &rc
->right
;
3192 case edt7
: return &rc
->bottom
;
3197 static void update_margin_edits(HWND hDlg
, const pagesetup_data
*data
, WORD id
)
3202 for(idx
= edt4
; idx
<= edt7
; idx
++)
3204 if(id
== 0 || id
== idx
)
3206 size2str(data
, *element_from_margin_id(pagesetup_get_margin_rect(data
), idx
), str
);
3207 SetDlgItemTextW(hDlg
, idx
, str
);
3212 static void margin_edit_notification(HWND hDlg
, const pagesetup_data
*data
, WORD msg
, WORD id
)
3220 LONG
*value
= element_from_margin_id(pagesetup_get_margin_rect(data
), id
);
3222 if (GetDlgItemTextW(hDlg
, id
, buf
, sizeof(buf
) / sizeof(buf
[0])) != 0)
3225 WCHAR decimal
= get_decimal_sep();
3227 val
= strtolW(buf
, &end
, 10);
3228 if(end
!= buf
|| *end
== decimal
)
3230 int mult
= is_metric(data
) ? 100 : 1000;
3239 val
+= (*end
- '0') * mult
;
3251 update_margin_edits(hDlg
, data
, id
);
3256 static void set_margin_groupbox_title(HWND hDlg
, const pagesetup_data
*data
)
3260 if(LoadStringW(COMDLG32_hInstance
, is_metric(data
) ? PD32_MARGINS_IN_MILLIMETERS
: PD32_MARGINS_IN_INCHES
,
3261 title
, sizeof(title
)/sizeof(title
[0])))
3262 SetDlgItemTextW(hDlg
, grp4
, title
);
3265 static void pagesetup_update_orientation_buttons(HWND hDlg
, const pagesetup_data
*data
)
3267 if (pagesetup_get_orientation(data
) == DMORIENT_LANDSCAPE
)
3268 CheckRadioButton(hDlg
, rad1
, rad2
, rad2
);
3270 CheckRadioButton(hDlg
, rad1
, rad2
, rad1
);
3273 /****************************************************************************************
3274 * pagesetup_printer_properties
3276 * Handle invocation of the 'Properties' button (not present in the default template).
3278 static void pagesetup_printer_properties(HWND hDlg
, pagesetup_data
*data
)
3286 devname
= pagesetup_get_devname(data
);
3288 if (!OpenPrinterW(devname
, &hprn
, NULL
))
3290 FIXME("Call to OpenPrinter did not succeed!\n");
3291 pagesetup_release_a_devname(data
, devname
);
3295 dm
= pagesetup_get_devmode(data
);
3296 DocumentPropertiesW(hDlg
, hprn
, devname
, dm
, dm
, DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
3297 pagesetup_set_devmode(data
, dm
);
3298 pagesetup_release_devmode(data
, dm
);
3299 pagesetup_release_a_devname(data
, devname
);
3302 /* Changing paper */
3303 pagesetup_update_papersize(data
);
3304 pagesetup_update_orientation_buttons(hDlg
, data
);
3306 /* Changing paper preview */
3307 pagesetup_change_preview(data
);
3309 /* Selecting paper in combo */
3310 count
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCOUNT
, 0, 0);
3313 WORD paperword
= pagesetup_get_papersize(data
);
3314 for(i
= 0; i
< count
; i
++)
3316 if(SendDlgItemMessageW(hDlg
, cmb2
, CB_GETITEMDATA
, i
, 0) == paperword
) {
3317 SendDlgItemMessageW(hDlg
, cmb2
, CB_SETCURSEL
, i
, 0);
3324 /********************************************************************************
3325 * pagesetup_wm_command
3326 * process WM_COMMAND message for PageSetupDlg
3329 * hDlg [in] Main dialog HANDLE
3330 * wParam [in] WM_COMMAND wParam
3331 * lParam [in] WM_COMMAND lParam
3332 * pda [in/out] ptr to PageSetupDataA
3335 static BOOL
pagesetup_wm_command(HWND hDlg
, WPARAM wParam
, LPARAM lParam
, pagesetup_data
*data
)
3337 WORD msg
= HIWORD(wParam
);
3338 WORD id
= LOWORD(wParam
);
3340 TRACE("loword (lparam) %d, wparam 0x%lx, lparam %08lx\n",
3341 LOWORD(lParam
),wParam
,lParam
);
3344 EndDialog(hDlg
, TRUE
);
3348 EndDialog(hDlg
, FALSE
);
3351 case psh3
: /* Printer... */
3352 pagesetup_change_printer_dialog(hDlg
, data
);
3355 case rad1
: /* Portrait */
3356 case rad2
: /* Landscape */
3357 if((id
== rad1
&& pagesetup_get_orientation(data
) == DMORIENT_LANDSCAPE
) ||
3358 (id
== rad2
&& pagesetup_get_orientation(data
) == DMORIENT_PORTRAIT
))
3360 pagesetup_set_orientation(data
, (id
== rad1
) ? DMORIENT_PORTRAIT
: DMORIENT_LANDSCAPE
);
3361 pagesetup_update_papersize(data
);
3362 rotate_rect(pagesetup_get_margin_rect(data
), (id
== rad2
));
3363 update_margin_edits(hDlg
, data
, 0);
3364 pagesetup_change_preview(data
);
3367 case cmb1
: /* Printer combo */
3368 if(msg
== CBN_SELCHANGE
)
3371 INT index
= SendDlgItemMessageW(hDlg
, id
, CB_GETCURSEL
, 0, 0);
3372 INT length
= SendDlgItemMessageW(hDlg
, id
, CB_GETLBTEXTLEN
, index
, 0);
3373 name
= HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*(length
+1));
3374 SendDlgItemMessageW(hDlg
, id
, CB_GETLBTEXT
, index
, (LPARAM
)name
);
3375 pagesetup_change_printer(name
, data
);
3376 pagesetup_init_combos(hDlg
, data
);
3377 HeapFree(GetProcessHeap(),0,name
);
3380 case cmb2
: /* Paper combo */
3381 if(msg
== CBN_SELCHANGE
)
3383 DWORD paperword
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETITEMDATA
,
3384 SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0), 0);
3385 if (paperword
!= CB_ERR
)
3387 pagesetup_set_papersize(data
, paperword
);
3388 pagesetup_update_papersize(data
);
3389 pagesetup_change_preview(data
);
3391 FIXME("could not get dialog text for papersize cmbbox?\n");
3394 case cmb3
: /* Paper Source */
3395 if(msg
== CBN_SELCHANGE
)
3397 WORD source
= SendDlgItemMessageW(hDlg
, cmb3
, CB_GETITEMDATA
,
3398 SendDlgItemMessageW(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0), 0);
3399 pagesetup_set_defaultsource(data
, source
);
3402 case psh2
: /* Printer Properties button */
3403 pagesetup_printer_properties(hDlg
, data
);
3409 margin_edit_notification(hDlg
, data
, msg
, id
);
3412 InvalidateRect(GetDlgItem(hDlg
, rct1
), NULL
, TRUE
);
3416 /***********************************************************************
3417 * default_page_paint_hook
3418 * Default hook paint procedure that receives WM_PSD_* messages from the dialog box
3419 * whenever the sample page is redrawn.
3421 static UINT_PTR
default_page_paint_hook(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
,
3422 const pagesetup_data
*data
)
3424 LPRECT lprc
= (LPRECT
) lParam
;
3425 HDC hdc
= (HDC
) wParam
;
3428 HFONT hfont
, holdfont
;
3430 TRACE("uMsg: WM_USER+%d\n",uMsg
-WM_USER
);
3431 /* Call user paint hook if enable */
3432 if (pagesetup_get_flags(data
) & PSD_ENABLEPAGEPAINTHOOK
)
3433 if (pagesetup_get_hook(data
, page_paint_hook
)(hwndDlg
, uMsg
, wParam
, lParam
))
3437 /* LPPAGESETUPDLG in lParam */
3438 case WM_PSD_PAGESETUPDLG
:
3439 /* Inform about the sample page rectangle */
3440 case WM_PSD_FULLPAGERECT
:
3441 /* Inform about the margin rectangle */
3442 case WM_PSD_MINMARGINRECT
:
3445 /* Draw dashed rectangle showing margins */
3446 case WM_PSD_MARGINRECT
:
3447 hpen
= CreatePen(PS_DASH
, 1, GetSysColor(COLOR_3DSHADOW
));
3448 holdpen
= SelectObject(hdc
, hpen
);
3449 Rectangle(hdc
, lprc
->left
, lprc
->top
, lprc
->right
, lprc
->bottom
);
3450 DeleteObject(SelectObject(hdc
, holdpen
));
3452 /* Draw the fake document */
3453 case WM_PSD_GREEKTEXTRECT
:
3454 /* select a nice scalable font, because we want the text really small */
3455 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, sizeof(lf
), &lf
, 0);
3456 lf
.lfHeight
= 6; /* value chosen based on visual effect */
3457 hfont
= CreateFontIndirectW(&lf
);
3458 holdfont
= SelectObject(hdc
, hfont
);
3460 /* if text not loaded, then do so now */
3461 if (wszFakeDocumentText
[0] == '\0')
3462 LoadStringW(COMDLG32_hInstance
,
3464 wszFakeDocumentText
,
3465 sizeof(wszFakeDocumentText
)/sizeof(wszFakeDocumentText
[0]));
3467 oldbkmode
= SetBkMode(hdc
, TRANSPARENT
);
3468 DrawTextW(hdc
, wszFakeDocumentText
, -1, lprc
, DT_TOP
|DT_LEFT
|DT_NOPREFIX
|DT_WORDBREAK
);
3469 SetBkMode(hdc
, oldbkmode
);
3471 DeleteObject(SelectObject(hdc
, holdfont
));
3474 /* Envelope stamp */
3475 case WM_PSD_ENVSTAMPRECT
:
3476 /* Return address */
3477 case WM_PSD_YAFULLPAGERECT
:
3478 FIXME("envelope/stamp is not implemented\n");
3481 FIXME("Unknown message %x\n",uMsg
);
3487 /***********************************************************************
3489 * The main paint procedure for the PageSetupDlg function.
3490 * The Page Setup dialog box includes an image of a sample page that shows how
3491 * the user's selections affect the appearance of the printed output.
3492 * The image consists of a rectangle that represents the selected paper
3493 * or envelope type, with a dotted-line rectangle representing
3494 * the current margins, and partial (Greek text) characters
3495 * to show how text looks on the printed page.
3497 * The following messages in the order sends to user hook procedure:
3498 * WM_PSD_PAGESETUPDLG Draw the contents of the sample page
3499 * WM_PSD_FULLPAGERECT Inform about the bounding rectangle
3500 * WM_PSD_MINMARGINRECT Inform about the margin rectangle (min margin?)
3501 * WM_PSD_MARGINRECT Draw the margin rectangle
3502 * WM_PSD_GREEKTEXTRECT Draw the Greek text inside the margin rectangle
3503 * If any of first three messages returns TRUE, painting done.
3506 * hWnd [in] Handle to the Page Setup dialog box
3507 * uMsg [in] Received message
3510 * WM_PSD_ENVSTAMPRECT Draw in the envelope-stamp rectangle (for envelopes only)
3511 * WM_PSD_YAFULLPAGERECT Draw the return address portion (for envelopes and other paper sizes)
3514 * FALSE if all done correctly
3519 static LRESULT CALLBACK
3520 PRINTDLG_PagePaintProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3523 RECT rcClient
, rcMargin
;
3526 HBRUSH hbrush
, holdbrush
;
3527 pagesetup_data
*data
;
3528 int papersize
=0, orientation
=0; /* FIXME: set these values for the user paint hook */
3529 double scalx
, scaly
;
3531 if (uMsg
!= WM_PAINT
)
3532 return CallWindowProcA(lpfnStaticWndProc
, hWnd
, uMsg
, wParam
, lParam
);
3534 /* Processing WM_PAINT message */
3535 data
= GetPropW(hWnd
, pagesetupdlg_prop
);
3537 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3540 if (default_page_paint_hook(hWnd
, WM_PSD_PAGESETUPDLG
, MAKELONG(papersize
, orientation
),
3541 pagesetup_get_dlg_struct(data
), data
))
3544 hdc
= BeginPaint(hWnd
, &ps
);
3545 GetClientRect(hWnd
, &rcClient
);
3547 scalx
= rcClient
.right
/ (double)pagesetup_get_papersize_pt(data
)->x
;
3548 scaly
= rcClient
.bottom
/ (double)pagesetup_get_papersize_pt(data
)->y
;
3549 rcMargin
= rcClient
;
3551 rcMargin
.left
+= pagesetup_get_margin_rect(data
)->left
* scalx
;
3552 rcMargin
.top
+= pagesetup_get_margin_rect(data
)->top
* scaly
;
3553 rcMargin
.right
-= pagesetup_get_margin_rect(data
)->right
* scalx
;
3554 rcMargin
.bottom
-= pagesetup_get_margin_rect(data
)->bottom
* scaly
;
3556 /* if the space is too small then we make sure to not draw anything */
3557 rcMargin
.left
= min(rcMargin
.left
, rcMargin
.right
);
3558 rcMargin
.top
= min(rcMargin
.top
, rcMargin
.bottom
);
3560 if (!default_page_paint_hook(hWnd
, WM_PSD_FULLPAGERECT
, (WPARAM
)hdc
, (LPARAM
)&rcClient
, data
) &&
3561 !default_page_paint_hook(hWnd
, WM_PSD_MINMARGINRECT
, (WPARAM
)hdc
, (LPARAM
)&rcMargin
, data
) )
3563 /* fill background */
3564 hbrush
= GetSysColorBrush(COLOR_3DHIGHLIGHT
);
3565 FillRect(hdc
, &rcClient
, hbrush
);
3566 holdbrush
= SelectObject(hdc
, hbrush
);
3568 hpen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DSHADOW
));
3569 holdpen
= SelectObject(hdc
, hpen
);
3571 /* paint left edge */
3572 MoveToEx(hdc
, rcClient
.left
, rcClient
.top
, NULL
);
3573 LineTo(hdc
, rcClient
.left
, rcClient
.bottom
-1);
3575 /* paint top edge */
3576 MoveToEx(hdc
, rcClient
.left
, rcClient
.top
, NULL
);
3577 LineTo(hdc
, rcClient
.right
, rcClient
.top
);
3579 hpen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DDKSHADOW
));
3580 DeleteObject(SelectObject(hdc
, hpen
));
3582 /* paint right edge */
3583 MoveToEx(hdc
, rcClient
.right
-1, rcClient
.top
, NULL
);
3584 LineTo(hdc
, rcClient
.right
-1, rcClient
.bottom
);
3586 /* paint bottom edge */
3587 MoveToEx(hdc
, rcClient
.left
, rcClient
.bottom
-1, NULL
);
3588 LineTo(hdc
, rcClient
.right
, rcClient
.bottom
-1);
3590 DeleteObject(SelectObject(hdc
, holdpen
));
3591 DeleteObject(SelectObject(hdc
, holdbrush
));
3593 default_page_paint_hook(hWnd
, WM_PSD_MARGINRECT
, (WPARAM
)hdc
, (LPARAM
)&rcMargin
, data
);
3595 /* give text a bit of a space from the frame */
3598 rcMargin
.right
-= 2;
3599 rcMargin
.bottom
-= 2;
3601 /* if the space is too small then we make sure to not draw anything */
3602 rcMargin
.left
= min(rcMargin
.left
, rcMargin
.right
);
3603 rcMargin
.top
= min(rcMargin
.top
, rcMargin
.bottom
);
3605 default_page_paint_hook(hWnd
, WM_PSD_GREEKTEXTRECT
, (WPARAM
)hdc
, (LPARAM
)&rcMargin
, data
);
3608 EndPaint(hWnd
, &ps
);
3612 /*******************************************************
3613 * The margin edit controls are subclassed to filter
3614 * anything other than numbers and the decimal separator.
3616 static LRESULT CALLBACK
pagesetup_margin_editproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3620 WCHAR decimal
= get_decimal_sep();
3621 WCHAR wc
= (WCHAR
)wparam
;
3622 if(!isdigitW(wc
) && wc
!= decimal
&& wc
!= VK_BACK
) return 0;
3624 return CallWindowProcW(edit_wndproc
, hwnd
, msg
, wparam
, lparam
);
3627 static void subclass_margin_edits(HWND hDlg
)
3632 for(id
= edt4
; id
<= edt7
; id
++)
3634 old_proc
= (WNDPROC
)SetWindowLongPtrW(GetDlgItem(hDlg
, id
),
3636 (ULONG_PTR
)pagesetup_margin_editproc
);
3637 InterlockedCompareExchangePointer((void**)&edit_wndproc
, old_proc
, NULL
);
3641 /***********************************************************************
3642 * pagesetup_dlg_proc
3644 * Message handler for PageSetupDlg
3646 static INT_PTR CALLBACK
pagesetup_dlg_proc(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3648 pagesetup_data
*data
;
3649 INT_PTR res
= FALSE
;
3652 if (uMsg
== WM_INITDIALOG
) { /*Init dialog*/
3653 data
= (pagesetup_data
*)lParam
;
3656 hDrawWnd
= GetDlgItem(hDlg
, rct1
);
3657 TRACE("set property to %p\n", data
);
3658 SetPropW(hDlg
, pagesetupdlg_prop
, data
);
3659 SetPropW(hDrawWnd
, pagesetupdlg_prop
, data
);
3660 GetWindowRect(hDrawWnd
, &data
->rtDrawRect
); /* Calculating rect in client coordinates where paper draws */
3661 MapWindowPoints( 0, hDlg
, (LPPOINT
)&data
->rtDrawRect
, 2 );
3662 lpfnStaticWndProc
= (WNDPROC
)SetWindowLongPtrW(
3665 (ULONG_PTR
)PRINTDLG_PagePaintProc
);
3667 /* FIXME: Paint hook. Must it be at begin of initialization or at end? */
3669 if (pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPHOOK
)
3671 if (!pagesetup_get_hook(data
, page_setup_hook
)(hDlg
, uMsg
, wParam
,
3672 pagesetup_get_dlg_struct(data
)))
3673 FIXME("Setup page hook failed?\n");
3676 /* if printer button disabled */
3677 if (pagesetup_get_flags(data
) & PSD_DISABLEPRINTER
)
3678 EnableWindow(GetDlgItem(hDlg
, psh3
), FALSE
);
3679 /* if margin edit boxes disabled */
3680 if (pagesetup_get_flags(data
) & PSD_DISABLEMARGINS
)
3682 EnableWindow(GetDlgItem(hDlg
, edt4
), FALSE
);
3683 EnableWindow(GetDlgItem(hDlg
, edt5
), FALSE
);
3684 EnableWindow(GetDlgItem(hDlg
, edt6
), FALSE
);
3685 EnableWindow(GetDlgItem(hDlg
, edt7
), FALSE
);
3688 /* Set orientation radiobuttons properly */
3689 pagesetup_update_orientation_buttons(hDlg
, data
);
3691 /* if orientation disabled */
3692 if (pagesetup_get_flags(data
) & PSD_DISABLEORIENTATION
)
3694 EnableWindow(GetDlgItem(hDlg
,rad1
),FALSE
);
3695 EnableWindow(GetDlgItem(hDlg
,rad2
),FALSE
);
3698 /* We fill them out enabled or not */
3699 if (!(pagesetup_get_flags(data
) & PSD_MARGINS
))
3701 /* default is 1 inch */
3702 LONG size
= thousandths_inch_to_size(data
, 1000);
3703 SetRect(pagesetup_get_margin_rect(data
), size
, size
, size
, size
);
3705 update_margin_edits(hDlg
, data
, 0);
3706 subclass_margin_edits(hDlg
);
3707 set_margin_groupbox_title(hDlg
, data
);
3709 /* if paper disabled */
3710 if (pagesetup_get_flags(data
) & PSD_DISABLEPAPER
)
3712 EnableWindow(GetDlgItem(hDlg
,cmb2
),FALSE
);
3713 EnableWindow(GetDlgItem(hDlg
,cmb3
),FALSE
);
3716 /* filling combos: printer, paper, source. selecting current printer (from DEVMODEA) */
3717 pagesetup_init_combos(hDlg
, data
);
3718 pagesetup_update_papersize(data
);
3719 pagesetup_set_defaultsource(data
, DMBIN_FORMSOURCE
); /* FIXME: This is the auto select bin. Is this correct? */
3721 /* Drawing paper prev */
3722 pagesetup_change_preview(data
);
3725 data
= GetPropW(hDlg
, pagesetupdlg_prop
);
3728 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3731 if (pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPHOOK
)
3733 res
= pagesetup_get_hook(data
, page_setup_hook
)(hDlg
, uMsg
, wParam
, lParam
);
3734 if (res
) return res
;
3739 return pagesetup_wm_command(hDlg
, wParam
, lParam
, data
);
3744 static WCHAR
*get_default_printer(void)
3749 GetDefaultPrinterW(NULL
, &len
);
3752 name
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3753 GetDefaultPrinterW(name
, &len
);
3758 static void pagesetup_dump_dlg_struct(const pagesetup_data
*data
)
3760 if(TRACE_ON(commdlg
))
3762 char flagstr
[1000] = "";
3763 const struct pd_flags
*pflag
= psd_flags
;
3764 for( ; pflag
->name
; pflag
++)
3766 if(pagesetup_get_flags(data
) & pflag
->flag
)
3768 strcat(flagstr
, pflag
->name
);
3769 strcat(flagstr
, "|");
3772 TRACE("%s: (%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3773 "hinst %p, flags %08x (%s)\n",
3774 data
->unicode
? "unicode" : "ansi",
3775 data
->u
.dlgw
, data
->u
.dlgw
->hwndOwner
, data
->u
.dlgw
->hDevMode
,
3776 data
->u
.dlgw
->hDevNames
, data
->u
.dlgw
->hInstance
,
3777 pagesetup_get_flags(data
), flagstr
);
3781 static void *pagesetup_get_template(pagesetup_data
*data
)
3784 HGLOBAL tmpl_handle
;
3786 if(pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPTEMPLATEHANDLE
)
3788 tmpl_handle
= data
->u
.dlgw
->hPageSetupTemplate
;
3790 else if(pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPTEMPLATE
)
3793 res
= FindResourceW(data
->u
.dlgw
->hInstance
,
3794 data
->u
.dlgw
->lpPageSetupTemplateName
, MAKEINTRESOURCEW(RT_DIALOG
));
3796 res
= FindResourceA(data
->u
.dlga
->hInstance
,
3797 data
->u
.dlga
->lpPageSetupTemplateName
, MAKEINTRESOURCEA(RT_DIALOG
));
3798 tmpl_handle
= LoadResource(data
->u
.dlgw
->hInstance
, res
);
3802 res
= FindResourceW(COMDLG32_hInstance
, MAKEINTRESOURCEW(PAGESETUPDLGORD
),
3803 MAKEINTRESOURCEW(RT_DIALOG
));
3804 tmpl_handle
= LoadResource(COMDLG32_hInstance
, res
);
3806 return LockResource(tmpl_handle
);
3809 static BOOL
pagesetup_common(pagesetup_data
*data
)
3814 if(!pagesetup_get_dlg_struct(data
))
3816 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
3820 pagesetup_dump_dlg_struct(data
);
3822 if(data
->u
.dlgw
->lStructSize
!= sizeof(PAGESETUPDLGW
))
3824 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
3828 if ((pagesetup_get_flags(data
) & PSD_ENABLEPAGEPAINTHOOK
) &&
3829 (pagesetup_get_hook(data
, page_paint_hook
) == NULL
))
3831 COMDLG32_SetCommDlgExtendedError(CDERR_NOHOOK
);
3835 if(!(pagesetup_get_flags(data
) & (PSD_INTHOUSANDTHSOFINCHES
| PSD_INHUNDREDTHSOFMILLIMETERS
)))
3836 data
->u
.dlgw
->Flags
|= is_default_metric() ?
3837 PSD_INHUNDREDTHSOFMILLIMETERS
: PSD_INTHOUSANDTHSOFINCHES
;
3839 if (!data
->u
.dlgw
->hDevMode
|| !data
->u
.dlgw
->hDevNames
)
3841 WCHAR
*def
= get_default_printer();
3844 if (!(pagesetup_get_flags(data
) & PSD_NOWARNING
))
3847 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEFAULT_PRINTER
, errstr
, 255);
3848 MessageBoxW(data
->u
.dlgw
->hwndOwner
, errstr
, 0, MB_OK
| MB_ICONERROR
);
3850 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
3853 pagesetup_change_printer(def
, data
);
3854 HeapFree(GetProcessHeap(), 0, def
);
3857 if (pagesetup_get_flags(data
) & PSD_RETURNDEFAULT
)
3859 pagesetup_update_papersize(data
);
3863 tmpl
= pagesetup_get_template(data
);
3865 ret
= DialogBoxIndirectParamW(data
->u
.dlgw
->hInstance
, tmpl
,
3866 data
->u
.dlgw
->hwndOwner
,
3867 pagesetup_dlg_proc
, (LPARAM
)data
) > 0;
3871 /***********************************************************************
3872 * PageSetupDlgA (COMDLG32.@)
3874 * Displays the PAGE SETUP dialog box, which enables the user to specify
3875 * specific properties of a printed page such as
3876 * size, source, orientation and the width of the page margins.
3879 * setupdlg [IO] PAGESETUPDLGA struct
3882 * TRUE if the user pressed the OK button
3883 * FALSE if the user cancelled the window or an error occurred
3886 * The values of hDevMode and hDevNames are filled on output and can be
3887 * changed in PAGESETUPDLG when they are passed in PageSetupDlg.
3890 BOOL WINAPI
PageSetupDlgA(LPPAGESETUPDLGA setupdlg
)
3892 pagesetup_data data
;
3894 data
.unicode
= FALSE
;
3895 data
.u
.dlga
= setupdlg
;
3897 return pagesetup_common(&data
);
3900 /***********************************************************************
3901 * PageSetupDlgW (COMDLG32.@)
3903 * See PageSetupDlgA.
3905 BOOL WINAPI
PageSetupDlgW(LPPAGESETUPDLGW setupdlg
)
3907 pagesetup_data data
;
3909 data
.unicode
= TRUE
;
3910 data
.u
.dlgw
= setupdlg
;
3912 return pagesetup_common(&data
);
3915 static void pdlgex_to_pdlg(const PRINTDLGEXW
*pdlgex
, PRINTDLGW
*pdlg
)
3917 pdlg
->lStructSize
= sizeof(*pdlg
);
3918 pdlg
->hwndOwner
= pdlgex
->hwndOwner
;
3919 pdlg
->hDevMode
= pdlgex
->hDevMode
;
3920 pdlg
->hDevNames
= pdlgex
->hDevNames
;
3921 pdlg
->hDC
= pdlgex
->hDC
;
3922 pdlg
->Flags
= pdlgex
->Flags
;
3923 if ((pdlgex
->Flags
& PD_NOPAGENUMS
) || !pdlgex
->nPageRanges
|| !pdlgex
->lpPageRanges
)
3925 pdlg
->nFromPage
= 0;
3926 pdlg
->nToPage
= 65534;
3930 pdlg
->nFromPage
= pdlgex
->lpPageRanges
[0].nFromPage
;
3931 pdlg
->nToPage
= pdlgex
->lpPageRanges
[0].nToPage
;
3933 pdlg
->nMinPage
= pdlgex
->nMinPage
;
3934 pdlg
->nMaxPage
= pdlgex
->nMaxPage
;
3935 pdlg
->nCopies
= pdlgex
->nCopies
;
3936 pdlg
->hInstance
= pdlgex
->hInstance
;
3937 pdlg
->lCustData
= 0;
3938 pdlg
->lpfnPrintHook
= NULL
;
3939 pdlg
->lpfnSetupHook
= NULL
;
3940 pdlg
->lpPrintTemplateName
= pdlgex
->lpPrintTemplateName
;
3941 pdlg
->lpSetupTemplateName
= NULL
;
3942 pdlg
->hPrintTemplate
= NULL
;
3943 pdlg
->hSetupTemplate
= NULL
;
3946 /* Only copy fields that are supposed to be changed. */
3947 static void pdlg_to_pdlgex(const PRINTDLGW
*pdlg
, PRINTDLGEXW
*pdlgex
)
3949 pdlgex
->hDevMode
= pdlg
->hDevMode
;
3950 pdlgex
->hDevNames
= pdlg
->hDevNames
;
3951 pdlgex
->hDC
= pdlg
->hDC
;
3952 if (!(pdlgex
->Flags
& PD_NOPAGENUMS
) && pdlgex
->nPageRanges
&& pdlgex
->lpPageRanges
)
3954 pdlgex
->lpPageRanges
[0].nFromPage
= pdlg
->nFromPage
;
3955 pdlgex
->lpPageRanges
[0].nToPage
= pdlg
->nToPage
;
3957 pdlgex
->nMinPage
= pdlg
->nMinPage
;
3958 pdlgex
->nMaxPage
= pdlg
->nMaxPage
;
3959 pdlgex
->nCopies
= pdlg
->nCopies
;
3962 struct callback_data
3964 IPrintDialogCallback
*callback
;
3965 IObjectWithSite
*object
;
3968 static UINT_PTR CALLBACK
pdlgex_hook_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
3970 if (msg
== WM_INITDIALOG
)
3972 PRINTDLGW
*pd
= (PRINTDLGW
*)lp
;
3973 struct callback_data
*cb
= (struct callback_data
*)pd
->lCustData
;
3977 cb
->callback
->lpVtbl
->SelectionChange(cb
->callback
);
3978 cb
->callback
->lpVtbl
->InitDone(cb
->callback
);
3983 /* FIXME: store interface pointer somewhere in window properties and call it
3985 cb->callback->lpVtbl->HandleMessage(cb->callback, hwnd, msg, wp, lp, &hres);
3992 /***********************************************************************
3993 * PrintDlgExA (COMDLG32.@)
4001 HRESULT WINAPI
PrintDlgExA(LPPRINTDLGEXA lppd
)
4003 PRINTER_INFO_2A
*pbuf
;
4004 DRIVER_INFO_3A
*dbuf
;
4009 if ((lppd
== NULL
) || (lppd
->lStructSize
!= sizeof(PRINTDLGEXA
)))
4010 return E_INVALIDARG
;
4012 if (!IsWindow(lppd
->hwndOwner
))
4015 if (lppd
->nStartPage
!= START_PAGE_GENERAL
)
4017 if (!lppd
->nPropertyPages
)
4018 return E_INVALIDARG
;
4020 FIXME("custom property sheets (%d at %p) not supported\n", lppd
->nPropertyPages
, lppd
->lphPropertyPages
);
4023 /* Use PD_NOPAGENUMS or set nMaxPageRanges and lpPageRanges */
4024 if (!(lppd
->Flags
& PD_NOPAGENUMS
) && (!lppd
->nMaxPageRanges
|| !lppd
->lpPageRanges
))
4026 return E_INVALIDARG
;
4029 if (lppd
->Flags
& PD_RETURNDEFAULT
)
4031 if (lppd
->hDevMode
|| lppd
->hDevNames
)
4033 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
4034 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
4035 return E_INVALIDARG
;
4037 if (!PRINTDLG_OpenDefaultPrinter(&hprn
))
4039 WARN("Can't find default printer\n");
4040 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
4044 pbuf
= get_printer_infoA(hprn
);
4051 dbuf
= get_driver_infoA(hprn
);
4054 HeapFree(GetProcessHeap(), 0, pbuf
);
4055 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
4059 dm
= pbuf
->pDevMode
;
4064 struct callback_data cb_data
= { 0 };
4066 FIXME("(%p) semi-stub\n", lppd
);
4068 if (lppd
->lpCallback
)
4070 IUnknown_QueryInterface((IUnknown
*)lppd
->lpCallback
, &IID_IPrintDialogCallback
, (void **)&cb_data
.callback
);
4071 IUnknown_QueryInterface((IUnknown
*)lppd
->lpCallback
, &IID_IObjectWithSite
, (void **)&cb_data
.object
);
4075 * PRINTDLGEXA/W and PRINTDLGA/W layout is the same for A and W variants.
4077 pdlgex_to_pdlg((const PRINTDLGEXW
*)lppd
, (PRINTDLGW
*)&pdlg
);
4078 pdlg
.Flags
|= PD_ENABLEPRINTHOOK
;
4079 pdlg
.lpfnPrintHook
= pdlgex_hook_proc
;
4080 pdlg
.lCustData
= (LPARAM
)&cb_data
;
4082 if (PrintDlgA(&pdlg
))
4084 pdlg_to_pdlgex((const PRINTDLGW
*)&pdlg
, (PRINTDLGEXW
*)lppd
);
4085 lppd
->dwResultAction
= PD_RESULT_PRINT
;
4088 lppd
->dwResultAction
= PD_RESULT_CANCEL
;
4090 if (cb_data
.callback
)
4091 cb_data
.callback
->lpVtbl
->Release(cb_data
.callback
);
4093 cb_data
.object
->lpVtbl
->Release(cb_data
.object
);
4100 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
), dbuf
->pDriverPath
, pbuf
->pPrinterName
, pbuf
->pPortName
);
4101 if (!lppd
->hDevNames
)
4104 lppd
->hDevMode
= update_devmode_handleA(lppd
->hDevMode
, dm
);
4105 if (!hr
&& lppd
->hDevMode
) {
4106 if (lppd
->Flags
& PD_RETURNDC
) {
4107 lppd
->hDC
= CreateDCA(dbuf
->pDriverPath
, pbuf
->pPrinterName
, pbuf
->pPortName
, dm
);
4111 else if (lppd
->Flags
& PD_RETURNIC
) {
4112 lppd
->hDC
= CreateICA(dbuf
->pDriverPath
, pbuf
->pPrinterName
, pbuf
->pPortName
, dm
);
4120 HeapFree(GetProcessHeap(), 0, pbuf
);
4121 HeapFree(GetProcessHeap(), 0, dbuf
);
4126 /***********************************************************************
4127 * PrintDlgExW (COMDLG32.@)
4129 * Display the property sheet style PRINT dialog box
4132 * lppd [IO] ptr to PRINTDLGEX struct
4136 * Failure: One of the following COM error codes:
4137 * E_OUTOFMEMORY Insufficient memory.
4138 * E_INVALIDARG One or more arguments are invalid.
4139 * E_POINTER Invalid pointer.
4140 * E_HANDLE Invalid handle.
4141 * E_FAIL Unspecified error.
4144 * This Dialog enables the user to specify specific properties of the print job.
4145 * The property sheet can also have additional application-specific and
4146 * driver-specific property pages.
4149 * Not fully implemented
4152 HRESULT WINAPI
PrintDlgExW(LPPRINTDLGEXW lppd
)
4154 PRINTER_INFO_2W
*pbuf
;
4155 DRIVER_INFO_3W
*dbuf
;
4160 if ((lppd
== NULL
) || (lppd
->lStructSize
!= sizeof(PRINTDLGEXW
))) {
4161 return E_INVALIDARG
;
4164 if (!IsWindow(lppd
->hwndOwner
)) {
4168 if (lppd
->nStartPage
!= START_PAGE_GENERAL
)
4170 if (!lppd
->nPropertyPages
)
4171 return E_INVALIDARG
;
4173 FIXME("custom property sheets (%d at %p) not supported\n", lppd
->nPropertyPages
, lppd
->lphPropertyPages
);
4176 /* Use PD_NOPAGENUMS or set nMaxPageRanges and lpPageRanges */
4177 if (!(lppd
->Flags
& PD_NOPAGENUMS
) && (!lppd
->nMaxPageRanges
|| !lppd
->lpPageRanges
))
4179 return E_INVALIDARG
;
4182 if (lppd
->Flags
& PD_RETURNDEFAULT
) {
4184 if (lppd
->hDevMode
|| lppd
->hDevNames
) {
4185 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
4186 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
4187 return E_INVALIDARG
;
4189 if (!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
4190 WARN("Can't find default printer\n");
4191 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
4195 pbuf
= get_printer_infoW(hprn
);
4202 dbuf
= get_driver_infoW(hprn
);
4205 HeapFree(GetProcessHeap(), 0, pbuf
);
4206 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
4210 dm
= pbuf
->pDevMode
;
4215 struct callback_data cb_data
= { 0 };
4217 FIXME("(%p) semi-stub\n", lppd
);
4219 if (lppd
->lpCallback
)
4221 IUnknown_QueryInterface((IUnknown
*)lppd
->lpCallback
, &IID_IPrintDialogCallback
, (void **)&cb_data
.callback
);
4222 IUnknown_QueryInterface((IUnknown
*)lppd
->lpCallback
, &IID_IObjectWithSite
, (void **)&cb_data
.object
);
4225 pdlgex_to_pdlg(lppd
, &pdlg
);
4226 pdlg
.Flags
|= PD_ENABLEPRINTHOOK
;
4227 pdlg
.lpfnPrintHook
= pdlgex_hook_proc
;
4228 pdlg
.lCustData
= (LPARAM
)&cb_data
;
4230 if (PrintDlgW(&pdlg
))
4232 pdlg_to_pdlgex(&pdlg
, lppd
);
4233 lppd
->dwResultAction
= PD_RESULT_PRINT
;
4236 lppd
->dwResultAction
= PD_RESULT_CANCEL
;
4238 if (cb_data
.callback
)
4239 cb_data
.callback
->lpVtbl
->Release(cb_data
.callback
);
4241 cb_data
.object
->lpVtbl
->Release(cb_data
.object
);
4248 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
), dbuf
->pDriverPath
, pbuf
->pPrinterName
, pbuf
->pPortName
);
4249 if (!lppd
->hDevNames
)
4252 lppd
->hDevMode
= update_devmode_handleW(lppd
->hDevMode
, dm
);
4253 if (!hr
&& lppd
->hDevMode
) {
4254 if (lppd
->Flags
& PD_RETURNDC
) {
4255 lppd
->hDC
= CreateDCW(dbuf
->pDriverPath
, pbuf
->pPrinterName
, pbuf
->pPortName
, dm
);
4259 else if (lppd
->Flags
& PD_RETURNIC
) {
4260 lppd
->hDC
= CreateICW(dbuf
->pDriverPath
, pbuf
->pPrinterName
, pbuf
->pPortName
, dm
);
4268 HeapFree(GetProcessHeap(), 0, pbuf
);
4269 HeapFree(GetProcessHeap(), 0, dbuf
);