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
32 #define NONAMELESSUNION
33 #define NONAMELESSSTRUCT
43 #include "wine/debug.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(commdlg
);
51 /* Yes these constants are the same, but we're just copying win98 */
52 #define UPDOWN_ID 0x270f
53 #define MAX_COPIES 9999
55 /* This PRINTDLGA internal structure stores
56 * pointers to several throughout useful structures.
62 LPPRINTDLGA lpPrintDlg
;
63 LPPRINTER_INFO_2A lpPrinterInfo
;
64 LPDRIVER_INFO_3A lpDriverInfo
;
66 HICON hCollateIcon
; /* PrintDlg only */
67 HICON hNoCollateIcon
; /* PrintDlg only */
68 HICON hPortraitIcon
; /* PrintSetupDlg only */
69 HICON hLandscapeIcon
; /* PrintSetupDlg only */
76 LPPRINTDLGW lpPrintDlg
;
77 LPPRINTER_INFO_2W lpPrinterInfo
;
78 LPDRIVER_INFO_3W lpDriverInfo
;
80 HICON hCollateIcon
; /* PrintDlg only */
81 HICON hNoCollateIcon
; /* PrintDlg only */
82 HICON hPortraitIcon
; /* PrintSetupDlg only */
83 HICON hLandscapeIcon
; /* PrintSetupDlg only */
94 static const struct pd_flags psd_flags
[] = {
95 {PSD_MINMARGINS
,"PSD_MINMARGINS"},
96 {PSD_MARGINS
,"PSD_MARGINS"},
97 {PSD_INTHOUSANDTHSOFINCHES
,"PSD_INTHOUSANDTHSOFINCHES"},
98 {PSD_INHUNDREDTHSOFMILLIMETERS
,"PSD_INHUNDREDTHSOFMILLIMETERS"},
99 {PSD_DISABLEMARGINS
,"PSD_DISABLEMARGINS"},
100 {PSD_DISABLEPRINTER
,"PSD_DISABLEPRINTER"},
101 {PSD_NOWARNING
,"PSD_NOWARNING"},
102 {PSD_DISABLEORIENTATION
,"PSD_DISABLEORIENTATION"},
103 {PSD_RETURNDEFAULT
,"PSD_RETURNDEFAULT"},
104 {PSD_DISABLEPAPER
,"PSD_DISABLEPAPER"},
105 {PSD_SHOWHELP
,"PSD_SHOWHELP"},
106 {PSD_ENABLEPAGESETUPHOOK
,"PSD_ENABLEPAGESETUPHOOK"},
107 {PSD_ENABLEPAGESETUPTEMPLATE
,"PSD_ENABLEPAGESETUPTEMPLATE"},
108 {PSD_ENABLEPAGESETUPTEMPLATEHANDLE
,"PSD_ENABLEPAGESETUPTEMPLATEHANDLE"},
109 {PSD_ENABLEPAGEPAINTHOOK
,"PSD_ENABLEPAGEPAINTHOOK"},
110 {PSD_DISABLEPAGEPAINTING
,"PSD_DISABLEPAGEPAINTING"},
114 static const struct pd_flags pd_flags
[] = {
115 {PD_SELECTION
, "PD_SELECTION "},
116 {PD_PAGENUMS
, "PD_PAGENUMS "},
117 {PD_NOSELECTION
, "PD_NOSELECTION "},
118 {PD_NOPAGENUMS
, "PD_NOPAGENUMS "},
119 {PD_COLLATE
, "PD_COLLATE "},
120 {PD_PRINTTOFILE
, "PD_PRINTTOFILE "},
121 {PD_PRINTSETUP
, "PD_PRINTSETUP "},
122 {PD_NOWARNING
, "PD_NOWARNING "},
123 {PD_RETURNDC
, "PD_RETURNDC "},
124 {PD_RETURNIC
, "PD_RETURNIC "},
125 {PD_RETURNDEFAULT
, "PD_RETURNDEFAULT "},
126 {PD_SHOWHELP
, "PD_SHOWHELP "},
127 {PD_ENABLEPRINTHOOK
, "PD_ENABLEPRINTHOOK "},
128 {PD_ENABLESETUPHOOK
, "PD_ENABLESETUPHOOK "},
129 {PD_ENABLEPRINTTEMPLATE
, "PD_ENABLEPRINTTEMPLATE "},
130 {PD_ENABLESETUPTEMPLATE
, "PD_ENABLESETUPTEMPLATE "},
131 {PD_ENABLEPRINTTEMPLATEHANDLE
, "PD_ENABLEPRINTTEMPLATEHANDLE "},
132 {PD_ENABLESETUPTEMPLATEHANDLE
, "PD_ENABLESETUPTEMPLATEHANDLE "},
133 {PD_USEDEVMODECOPIES
, "PD_USEDEVMODECOPIES[ANDCOLLATE] "},
134 {PD_DISABLEPRINTTOFILE
, "PD_DISABLEPRINTTOFILE "},
135 {PD_HIDEPRINTTOFILE
, "PD_HIDEPRINTTOFILE "},
136 {PD_NONETWORKBUTTON
, "PD_NONETWORKBUTTON "},
139 /* address of wndproc for subclassed Static control */
140 static WNDPROC lpfnStaticWndProc
;
141 static WNDPROC edit_wndproc
;
142 /* the text of the fake document to render for the Page Setup dialog */
143 static WCHAR wszFakeDocumentText
[1024];
144 static const WCHAR pd32_collateW
[] = { 'P', 'D', '3', '2', '_', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
145 static const WCHAR pd32_nocollateW
[] = { 'P', 'D', '3', '2', '_', 'N', 'O', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
146 static const WCHAR pd32_portraitW
[] = { 'P', 'D', '3', '2', '_', 'P', 'O', 'R', 'T', 'R', 'A', 'I', 'T', 0 };
147 static const WCHAR pd32_landscapeW
[] = { 'P', 'D', '3', '2', '_', 'L', 'A', 'N', 'D', 'S', 'C', 'A', 'P', 'E', 0 };
148 static const WCHAR printdlg_prop
[] = {'_','_','W','I','N','E','_','P','R','I','N','T','D','L','G','D','A','T','A',0};
149 static const WCHAR pagesetupdlg_prop
[] = { '_', '_', 'W', 'I', 'N', 'E', '_', 'P', 'A', 'G', 'E',
150 'S', 'E', 'T', 'U', 'P', 'D', 'L', 'G', 'D', 'A', 'T', 'A', 0 };
153 static LPWSTR
strdupW(LPCWSTR p
)
159 len
= (lstrlenW(p
) + 1) * sizeof(WCHAR
);
160 ret
= HeapAlloc(GetProcessHeap(), 0, len
);
165 /***********************************************************************
166 * get_driver_info [internal]
168 * get DRIVER_INFO_3W for the current printer handle,
169 * alloc the buffer, when needed
171 static DRIVER_INFO_3W
* get_driver_infoW(HANDLE hprn
)
173 DRIVER_INFO_3W
*di3
= NULL
;
177 res
= GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
178 if (!res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
179 di3
= HeapAlloc(GetProcessHeap(), 0, needed
);
180 res
= GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)di3
, needed
, &needed
);
186 TRACE("GetPrinterDriverW failed with %u\n", GetLastError());
187 HeapFree(GetProcessHeap(), 0, di3
);
191 static DRIVER_INFO_3A
* get_driver_infoA(HANDLE hprn
)
193 DRIVER_INFO_3A
*di3
= NULL
;
197 res
= GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
198 if (!res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
199 di3
= HeapAlloc(GetProcessHeap(), 0, needed
);
200 res
= GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)di3
, needed
, &needed
);
206 TRACE("GetPrinterDriverA failed with %u\n", GetLastError());
207 HeapFree(GetProcessHeap(), 0, di3
);
212 /***********************************************************************
213 * get_printer_info [internal]
215 * get PRINTER_INFO_2W for the current printer handle,
216 * alloc the buffer, when needed
218 static PRINTER_INFO_2W
* get_printer_infoW(HANDLE hprn
)
220 PRINTER_INFO_2W
*pi2
= NULL
;
224 res
= GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
225 if (!res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
226 pi2
= HeapAlloc(GetProcessHeap(), 0, needed
);
227 res
= GetPrinterW(hprn
, 2, (LPBYTE
)pi2
, needed
, &needed
);
233 TRACE("GetPrinterW failed with %u\n", GetLastError());
234 HeapFree(GetProcessHeap(), 0, pi2
);
238 static PRINTER_INFO_2A
* get_printer_infoA(HANDLE hprn
)
240 PRINTER_INFO_2A
*pi2
= NULL
;
244 res
= GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
245 if (!res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
246 pi2
= HeapAlloc(GetProcessHeap(), 0, needed
);
247 res
= GetPrinterA(hprn
, 2, (LPBYTE
)pi2
, needed
, &needed
);
253 TRACE("GetPrinterA failed with %u\n", GetLastError());
254 HeapFree(GetProcessHeap(), 0, pi2
);
259 /***********************************************************************
260 * update_devmode_handle [internal]
262 * update a devmode handle for the given DEVMODE, alloc the buffer, when needed
264 static HGLOBAL
update_devmode_handleW(HGLOBAL hdm
, DEVMODEW
*dm
)
266 SIZE_T size
= GlobalSize(hdm
);
269 /* Increase / alloc the global memory block, when needed */
270 if ((dm
->dmSize
+ dm
->dmDriverExtra
) > size
) {
272 hdm
= GlobalReAlloc(hdm
, dm
->dmSize
+ dm
->dmDriverExtra
, 0);
274 hdm
= GlobalAlloc(GMEM_MOVEABLE
, dm
->dmSize
+ dm
->dmDriverExtra
);
278 ptr
= GlobalLock(hdm
);
280 memcpy(ptr
, dm
, dm
->dmSize
+ dm
->dmDriverExtra
);
292 static HGLOBAL
update_devmode_handleA(HGLOBAL hdm
, DEVMODEA
*dm
)
294 SIZE_T size
= GlobalSize(hdm
);
297 /* Increase / alloc the global memory block, when needed */
298 if ((dm
->dmSize
+ dm
->dmDriverExtra
) > size
) {
300 hdm
= GlobalReAlloc(hdm
, dm
->dmSize
+ dm
->dmDriverExtra
, 0);
302 hdm
= GlobalAlloc(GMEM_MOVEABLE
, dm
->dmSize
+ dm
->dmDriverExtra
);
306 ptr
= GlobalLock(hdm
);
308 memcpy(ptr
, dm
, dm
->dmSize
+ dm
->dmDriverExtra
);
320 /***********************************************************
321 * convert_to_devmodeA
323 * Creates an ansi copy of supplied devmode
325 static DEVMODEA
*convert_to_devmodeA(const DEVMODEW
*dmW
)
330 if (!dmW
) return NULL
;
331 size
= dmW
->dmSize
- CCHDEVICENAME
-
332 ((dmW
->dmSize
> FIELD_OFFSET(DEVMODEW
, dmFormName
)) ? CCHFORMNAME
: 0);
334 dmA
= HeapAlloc(GetProcessHeap(), 0, size
+ dmW
->dmDriverExtra
);
335 if (!dmA
) return NULL
;
337 WideCharToMultiByte(CP_ACP
, 0, dmW
->dmDeviceName
, -1,
338 (LPSTR
)dmA
->dmDeviceName
, CCHDEVICENAME
, NULL
, NULL
);
340 if (FIELD_OFFSET(DEVMODEW
, dmFormName
) >= dmW
->dmSize
)
342 memcpy(&dmA
->dmSpecVersion
, &dmW
->dmSpecVersion
,
343 dmW
->dmSize
- FIELD_OFFSET(DEVMODEW
, dmSpecVersion
));
347 memcpy(&dmA
->dmSpecVersion
, &dmW
->dmSpecVersion
,
348 FIELD_OFFSET(DEVMODEW
, dmFormName
) - FIELD_OFFSET(DEVMODEW
, dmSpecVersion
));
349 WideCharToMultiByte(CP_ACP
, 0, dmW
->dmFormName
, -1,
350 (LPSTR
)dmA
->dmFormName
, CCHFORMNAME
, NULL
, NULL
);
352 memcpy(&dmA
->dmLogPixels
, &dmW
->dmLogPixels
, dmW
->dmSize
- FIELD_OFFSET(DEVMODEW
, dmLogPixels
));
356 memcpy((char *)dmA
+ dmA
->dmSize
, (const char *)dmW
+ dmW
->dmSize
, dmW
->dmDriverExtra
);
360 /***********************************************************************
361 * PRINTDLG_OpenDefaultPrinter
363 * Returns a winspool printer handle to the default printer in *hprn
364 * Caller must call ClosePrinter on the handle
366 * Returns TRUE on success else FALSE
368 static BOOL
PRINTDLG_OpenDefaultPrinter(HANDLE
*hprn
)
371 DWORD dwBufLen
= ARRAY_SIZE(buf
);
373 if(!GetDefaultPrinterW(buf
, &dwBufLen
))
375 res
= OpenPrinterW(buf
, hprn
, NULL
);
377 WARN("Could not open printer %s\n", debugstr_w(buf
));
381 /***********************************************************************
382 * PRINTDLG_SetUpPrinterListCombo
384 * Initializes printer list combox.
385 * hDlg: HWND of dialog
386 * id: Control id of combo
387 * name: Name of printer to select
389 * Initializes combo with list of available printers. Selects printer 'name'
390 * If name is NULL or does not exist select the default printer.
392 * Returns number of printers added to list.
394 static INT
PRINTDLG_SetUpPrinterListComboA(HWND hDlg
, UINT id
, LPCSTR name
)
398 LPPRINTER_INFO_2A pi
;
399 EnumPrintersA(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
400 pi
= HeapAlloc(GetProcessHeap(), 0, needed
);
401 EnumPrintersA(PRINTER_ENUM_LOCAL
, NULL
, 2, (LPBYTE
)pi
, needed
, &needed
,
404 SendDlgItemMessageA(hDlg
, id
, CB_RESETCONTENT
, 0, 0);
406 for(i
= 0; i
< num
; i
++) {
407 SendDlgItemMessageA(hDlg
, id
, CB_ADDSTRING
, 0,
408 (LPARAM
)pi
[i
].pPrinterName
);
410 HeapFree(GetProcessHeap(), 0, pi
);
412 (i
= SendDlgItemMessageA(hDlg
, id
, CB_FINDSTRINGEXACT
, -1,
413 (LPARAM
)name
)) == CB_ERR
) {
416 DWORD dwBufLen
= ARRAY_SIZE(buf
);
418 WARN("Can't find %s in printer list so trying to find default\n",
420 if(!GetDefaultPrinterA(buf
, &dwBufLen
))
422 i
= SendDlgItemMessageA(hDlg
, id
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buf
);
424 FIXME("Can't find default printer in printer list\n");
426 SendDlgItemMessageA(hDlg
, id
, CB_SETCURSEL
, i
, 0);
430 static INT
PRINTDLG_SetUpPrinterListComboW(HWND hDlg
, UINT id
, LPCWSTR name
)
434 LPPRINTER_INFO_2W pi
;
435 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
436 pi
= HeapAlloc(GetProcessHeap(), 0, needed
);
437 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, (LPBYTE
)pi
, needed
, &needed
,
440 for(i
= 0; i
< num
; i
++) {
441 SendDlgItemMessageW(hDlg
, id
, CB_ADDSTRING
, 0,
442 (LPARAM
)pi
[i
].pPrinterName
);
444 HeapFree(GetProcessHeap(), 0, pi
);
446 (i
= SendDlgItemMessageW(hDlg
, id
, CB_FINDSTRINGEXACT
, -1,
447 (LPARAM
)name
)) == CB_ERR
) {
449 DWORD dwBufLen
= ARRAY_SIZE(buf
);
451 WARN("Can't find %s in printer list so trying to find default\n",
453 if(!GetDefaultPrinterW(buf
, &dwBufLen
))
455 i
= SendDlgItemMessageW(hDlg
, id
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buf
);
457 TRACE("Can't find default printer in printer list\n");
459 SendDlgItemMessageW(hDlg
, id
, CB_SETCURSEL
, i
, 0);
464 static const CHAR cDriverName
[] = "winspool";
465 static const WCHAR wDriverName
[] = L
"winspool";
468 /***********************************************************************
469 * PRINTDLG_CreateDevNames [internal]
472 * creates a DevNames structure.
474 * (NB. when we handle unicode the offsets will be in wchars).
476 static BOOL
PRINTDLG_CreateDevNames(HGLOBAL
*hmem
, const char* DeviceDriverName
,
477 const char* DeviceName
, const char* OutputPort
)
480 char* pDevNamesSpace
;
482 LPDEVNAMES lpDevNames
;
484 DWORD dwBufLen
= ARRAY_SIZE(buf
);
487 p
= strrchr( DeviceDriverName
, '\\' );
488 if (p
) DeviceDriverName
= p
+ 1;
490 size
= strlen(DeviceDriverName
) + 1
492 size
= strlen(cDriverName
) + 1
494 + strlen(DeviceName
) + 1
495 + strlen(OutputPort
) + 1
499 *hmem
= GlobalReAlloc(*hmem
, size
, GMEM_MOVEABLE
);
501 *hmem
= GlobalAlloc(GMEM_MOVEABLE
, size
);
505 pDevNamesSpace
= GlobalLock(*hmem
);
506 lpDevNames
= (LPDEVNAMES
) pDevNamesSpace
;
508 pTempPtr
= pDevNamesSpace
+ sizeof(DEVNAMES
);
510 strcpy(pTempPtr
, DeviceDriverName
);
512 strcpy(pTempPtr
, cDriverName
);
514 lpDevNames
->wDriverOffset
= pTempPtr
- pDevNamesSpace
;
516 pTempPtr
+= strlen(DeviceDriverName
) + 1;
517 strcpy(pTempPtr
, DeviceName
);
518 lpDevNames
->wDeviceOffset
= pTempPtr
- pDevNamesSpace
;
520 pTempPtr
+= strlen(DeviceName
) + 1;
521 strcpy(pTempPtr
, OutputPort
);
522 lpDevNames
->wOutputOffset
= pTempPtr
- pDevNamesSpace
;
524 GetDefaultPrinterA(buf
, &dwBufLen
);
525 lpDevNames
->wDefault
= (strcmp(buf
, DeviceName
) == 0) ? 1 : 0;
530 static BOOL
PRINTDLG_CreateDevNamesW(HGLOBAL
*hmem
, LPCWSTR DeviceDriverName
,
531 LPCWSTR DeviceName
, LPCWSTR OutputPort
)
534 LPWSTR pDevNamesSpace
;
536 LPDEVNAMES lpDevNames
;
538 DWORD dwBufLen
= ARRAY_SIZE(bufW
);
541 p
= wcsrchr( DeviceDriverName
, '\\' );
542 if (p
) DeviceDriverName
= p
+ 1;
544 size
= sizeof(WCHAR
)*lstrlenW(DeviceDriverName
) + 2
546 size
= sizeof(WCHAR
)*lstrlenW(wDriverName
) + 2
548 + sizeof(WCHAR
)*lstrlenW(DeviceName
) + 2
549 + sizeof(WCHAR
)*lstrlenW(OutputPort
) + 2
553 *hmem
= GlobalReAlloc(*hmem
, size
, GMEM_MOVEABLE
);
555 *hmem
= GlobalAlloc(GMEM_MOVEABLE
, size
);
559 pDevNamesSpace
= GlobalLock(*hmem
);
560 lpDevNames
= (LPDEVNAMES
) pDevNamesSpace
;
562 pTempPtr
= (LPWSTR
)((LPDEVNAMES
)pDevNamesSpace
+ 1);
564 lstrcpyW(pTempPtr
, DeviceDriverName
);
566 lstrcpyW(pTempPtr
, wDriverName
);
568 lpDevNames
->wDriverOffset
= pTempPtr
- pDevNamesSpace
;
570 pTempPtr
+= lstrlenW(DeviceDriverName
) + 1;
571 lstrcpyW(pTempPtr
, DeviceName
);
572 lpDevNames
->wDeviceOffset
= pTempPtr
- pDevNamesSpace
;
574 pTempPtr
+= lstrlenW(DeviceName
) + 1;
575 lstrcpyW(pTempPtr
, OutputPort
);
576 lpDevNames
->wOutputOffset
= pTempPtr
- pDevNamesSpace
;
578 GetDefaultPrinterW(bufW
, &dwBufLen
);
579 lpDevNames
->wDefault
= (lstrcmpW(bufW
, DeviceName
) == 0) ? 1 : 0;
584 /***********************************************************************
585 * PRINTDLG_UpdatePrintDlg [internal]
588 * updates the PrintDlg structure for return values.
591 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
592 * TRUE if successful.
594 static BOOL
PRINTDLG_UpdatePrintDlgA(HWND hDlg
,
595 PRINT_PTRA
* PrintStructures
)
597 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
598 PDEVMODEA lpdm
= PrintStructures
->lpDevMode
;
599 LPPRINTER_INFO_2A pi
= PrintStructures
->lpPrinterInfo
;
603 FIXME("No lpdm ptr?\n");
608 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
609 /* check whether nFromPage and nToPage are within range defined by
610 * nMinPage and nMaxPage
612 if (IsDlgButtonChecked(hDlg
, rad3
) == BST_CHECKED
) { /* Pages */
616 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
617 nToPage
= GetDlgItemInt(hDlg
, edt2
, &translated
, FALSE
);
619 /* if no ToPage value is entered, use the FromPage value */
620 if(!translated
) nToPage
= nFromPage
;
622 if (nFromPage
< lppd
->nMinPage
|| nFromPage
> lppd
->nMaxPage
||
623 nToPage
< lppd
->nMinPage
|| nToPage
> lppd
->nMaxPage
) {
624 WCHAR resourcestr
[256];
625 WCHAR resultstr
[256];
626 LoadStringW(COMDLG32_hInstance
, PD32_INVALID_PAGE_RANGE
, resourcestr
, 255);
627 wsprintfW(resultstr
,resourcestr
, lppd
->nMinPage
, lppd
->nMaxPage
);
628 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
, resourcestr
, 255);
629 MessageBoxW(hDlg
, resultstr
, resourcestr
, MB_OK
| MB_ICONWARNING
);
632 lppd
->nFromPage
= nFromPage
;
633 lppd
->nToPage
= nToPage
;
634 lppd
->Flags
|= PD_PAGENUMS
;
637 lppd
->Flags
&= ~PD_PAGENUMS
;
639 if (IsDlgButtonChecked(hDlg
, rad2
) == BST_CHECKED
) /* Selection */
640 lppd
->Flags
|= PD_SELECTION
;
642 lppd
->Flags
&= ~PD_SELECTION
;
644 if (IsDlgButtonChecked(hDlg
, chx1
) == BST_CHECKED
) {/* Print to file */
645 static char file
[] = "FILE:";
646 lppd
->Flags
|= PD_PRINTTOFILE
;
647 pi
->pPortName
= file
;
650 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
) { /* Collate */
651 FIXME("Collate lppd not yet implemented as output\n");
654 /* set PD_Collate and nCopies */
655 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
656 /* The application doesn't support multiple copies or collate...
658 lppd
->Flags
&= ~PD_COLLATE
;
660 /* if the printer driver supports it... store info there
661 * otherwise no collate & multiple copies !
663 if (lpdm
->dmFields
& DM_COLLATE
)
665 (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
);
666 if (lpdm
->dmFields
& DM_COPIES
)
667 lpdm
->u1
.s1
.dmCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
669 /* Application is responsible for multiple copies */
670 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
671 lppd
->Flags
|= PD_COLLATE
;
673 lppd
->Flags
&= ~PD_COLLATE
;
674 lppd
->nCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
675 /* multiple copies already included in the document. Driver must print only one copy */
676 lpdm
->u1
.s1
.dmCopies
= 1;
679 /* Print quality, PrintDlg16 */
680 if(GetDlgItem(hDlg
, cmb1
))
682 HWND hQuality
= GetDlgItem(hDlg
, cmb1
);
683 int Sel
= SendMessageA(hQuality
, CB_GETCURSEL
, 0, 0);
687 LONG dpi
= SendMessageA(hQuality
, CB_GETITEMDATA
, Sel
, 0);
688 lpdm
->dmFields
|= DM_PRINTQUALITY
| DM_YRESOLUTION
;
689 lpdm
->u1
.s1
.dmPrintQuality
= LOWORD(dpi
);
690 lpdm
->dmYResolution
= HIWORD(dpi
);
697 static BOOL
PRINTDLG_UpdatePrintDlgW(HWND hDlg
,
698 PRINT_PTRW
* PrintStructures
)
700 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
701 PDEVMODEW lpdm
= PrintStructures
->lpDevMode
;
702 LPPRINTER_INFO_2W pi
= PrintStructures
->lpPrinterInfo
;
706 FIXME("No lpdm ptr?\n");
711 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
712 /* check whether nFromPage and nToPage are within range defined by
713 * nMinPage and nMaxPage
715 if (IsDlgButtonChecked(hDlg
, rad3
) == BST_CHECKED
) { /* Pages */
719 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
720 nToPage
= GetDlgItemInt(hDlg
, edt2
, &translated
, FALSE
);
722 /* if no ToPage value is entered, use the FromPage value */
723 if(!translated
) nToPage
= nFromPage
;
725 if (nFromPage
< lppd
->nMinPage
|| nFromPage
> lppd
->nMaxPage
||
726 nToPage
< lppd
->nMinPage
|| nToPage
> lppd
->nMaxPage
) {
727 WCHAR resourcestr
[256];
728 WCHAR resultstr
[256];
730 LoadStringW(COMDLG32_hInstance
, PD32_INVALID_PAGE_RANGE
,
732 args
[0] = lppd
->nMinPage
;
733 args
[1] = lppd
->nMaxPage
;
734 FormatMessageW(FORMAT_MESSAGE_FROM_STRING
|FORMAT_MESSAGE_ARGUMENT_ARRAY
,
735 resourcestr
, 0, 0, resultstr
,
736 ARRAY_SIZE(resultstr
),
737 (__ms_va_list
*)args
);
738 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
,
740 MessageBoxW(hDlg
, resultstr
, resourcestr
,
741 MB_OK
| MB_ICONWARNING
);
744 lppd
->nFromPage
= nFromPage
;
745 lppd
->nToPage
= nToPage
;
746 lppd
->Flags
|= PD_PAGENUMS
;
749 lppd
->Flags
&= ~PD_PAGENUMS
;
751 if (IsDlgButtonChecked(hDlg
, rad2
) == BST_CHECKED
) /* Selection */
752 lppd
->Flags
|= PD_SELECTION
;
754 lppd
->Flags
&= ~PD_SELECTION
;
756 if (IsDlgButtonChecked(hDlg
, chx1
) == BST_CHECKED
) {/* Print to file */
757 static WCHAR file
[] = {'F','I','L','E',':',0};
758 lppd
->Flags
|= PD_PRINTTOFILE
;
759 pi
->pPortName
= file
;
762 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
) { /* Collate */
763 FIXME("Collate lppd not yet implemented as output\n");
766 /* set PD_Collate and nCopies */
767 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
768 /* The application doesn't support multiple copies or collate...
770 lppd
->Flags
&= ~PD_COLLATE
;
772 /* if the printer driver supports it... store info there
773 * otherwise no collate & multiple copies !
775 if (lpdm
->dmFields
& DM_COLLATE
)
777 (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
);
778 if (lpdm
->dmFields
& DM_COPIES
)
779 lpdm
->u1
.s1
.dmCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
781 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
782 lppd
->Flags
|= PD_COLLATE
;
784 lppd
->Flags
&= ~PD_COLLATE
;
785 lppd
->nCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
791 /************************************************************************
792 * PRINTDLG_SetUpPaperComboBox
794 * Initialize either the papersize or inputslot combos of the Printer Setup
795 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
796 * We also try to re-select the old selection.
798 static BOOL
PRINTDLG_SetUpPaperComboBoxA(HWND hDlg
,
809 WORD oldWord
= 0, newWord
= 0; /* DMPAPER_ and DMBIN_ start at 1 */
811 int fwCapability_Names
;
812 int fwCapability_Words
;
814 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName
,PortName
,nIDComboBox
);
816 /* query the dialog box for the current selected value */
817 Sel
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETCURSEL
, 0, 0);
819 /* we enter here only if a different printer is selected after
820 * the Print Setup dialog is opened. The current settings are
821 * stored into the newly selected printer.
823 oldWord
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
,
825 if(oldWord
>= DMPAPER_USER
) /* DMPAPER_USER == DMBIN_USER */
826 oldWord
= 0; /* There's no point in trying to keep custom
827 paper / bin sizes across printers */
831 newWord
= (nIDComboBox
== cmb2
) ? dm
->u1
.s1
.dmPaperSize
: dm
->u1
.s1
.dmDefaultSource
;
833 if (nIDComboBox
== cmb2
) {
835 fwCapability_Names
= DC_PAPERNAMES
;
836 fwCapability_Words
= DC_PAPERS
;
840 fwCapability_Names
= DC_BINNAMES
;
841 fwCapability_Words
= DC_BINS
;
844 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
845 fwCapability_Names
, NULL
, dm
);
846 if (NrOfEntries
== 0)
847 WARN("no Name Entries found!\n");
848 else if (NrOfEntries
< 0)
851 if(DeviceCapabilitiesA(PrinterName
, PortName
, fwCapability_Words
, NULL
, dm
)
853 ERR("Number of caps is different\n");
857 Names
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(char)*NamesSize
);
858 Words
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WORD
));
859 DeviceCapabilitiesA(PrinterName
, PortName
, fwCapability_Names
, Names
, dm
);
860 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
861 fwCapability_Words
, (LPSTR
)Words
, dm
);
863 /* reset any current content in the combobox */
864 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_RESETCONTENT
, 0, 0);
866 /* store new content */
867 for (i
= 0; i
< NrOfEntries
; i
++) {
868 DWORD pos
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_ADDSTRING
, 0,
869 (LPARAM
)(&Names
[i
*NamesSize
]) );
870 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_SETITEMDATA
, pos
,
874 /* Look for old selection or the new default.
875 Can't do this is previous loop since item order will change as more items are added */
877 old_Sel
= NrOfEntries
;
878 for (i
= 0; i
< NrOfEntries
; i
++) {
879 if(SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) ==
884 if(SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) == newWord
)
888 if(old_Sel
< NrOfEntries
)
892 if(nIDComboBox
== cmb2
)
893 dm
->u1
.s1
.dmPaperSize
= oldWord
;
895 dm
->u1
.s1
.dmDefaultSource
= oldWord
;
900 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_SETCURSEL
, Sel
, 0);
902 HeapFree(GetProcessHeap(),0,Words
);
903 HeapFree(GetProcessHeap(),0,Names
);
907 static BOOL
PRINTDLG_SetUpPaperComboBoxW(HWND hDlg
,
909 const WCHAR
* PrinterName
,
910 const WCHAR
* PortName
,
918 WORD oldWord
= 0, newWord
= 0; /* DMPAPER_ and DMBIN_ start at 1 */
920 int fwCapability_Names
;
921 int fwCapability_Words
;
923 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName
),debugstr_w(PortName
),nIDComboBox
);
925 /* query the dialog box for the current selected value */
926 Sel
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETCURSEL
, 0, 0);
928 /* we enter here only if a different printer is selected after
929 * the Print Setup dialog is opened. The current settings are
930 * stored into the newly selected printer.
932 oldWord
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETITEMDATA
,
935 if(oldWord
>= DMPAPER_USER
) /* DMPAPER_USER == DMBIN_USER */
936 oldWord
= 0; /* There's no point in trying to keep custom
937 paper / bin sizes across printers */
941 newWord
= (nIDComboBox
== cmb2
) ? dm
->u1
.s1
.dmPaperSize
: dm
->u1
.s1
.dmDefaultSource
;
943 if (nIDComboBox
== cmb2
) {
945 fwCapability_Names
= DC_PAPERNAMES
;
946 fwCapability_Words
= DC_PAPERS
;
950 fwCapability_Names
= DC_BINNAMES
;
951 fwCapability_Words
= DC_BINS
;
954 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
955 fwCapability_Names
, NULL
, dm
);
956 if (NrOfEntries
== 0)
957 WARN("no Name Entries found!\n");
958 else if (NrOfEntries
< 0)
961 if(DeviceCapabilitiesW(PrinterName
, PortName
, fwCapability_Words
, NULL
, dm
)
963 ERR("Number of caps is different\n");
967 Names
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WCHAR
)*NamesSize
);
968 Words
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WORD
));
969 DeviceCapabilitiesW(PrinterName
, PortName
, fwCapability_Names
, Names
, dm
);
970 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
971 fwCapability_Words
, Words
, dm
);
973 /* reset any current content in the combobox */
974 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_RESETCONTENT
, 0, 0);
976 /* store new content */
977 for (i
= 0; i
< NrOfEntries
; i
++) {
978 DWORD pos
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_ADDSTRING
, 0,
979 (LPARAM
)(&Names
[i
*NamesSize
]) );
980 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_SETITEMDATA
, pos
,
984 /* Look for old selection or the new default.
985 Can't do this is previous loop since item order will change as more items are added */
987 old_Sel
= NrOfEntries
;
988 for (i
= 0; i
< NrOfEntries
; i
++) {
989 if(SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) ==
994 if(SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) == newWord
)
998 if(old_Sel
< NrOfEntries
)
1002 if(nIDComboBox
== cmb2
)
1003 dm
->u1
.s1
.dmPaperSize
= oldWord
;
1005 dm
->u1
.s1
.dmDefaultSource
= oldWord
;
1010 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_SETCURSEL
, Sel
, 0);
1012 HeapFree(GetProcessHeap(),0,Words
);
1013 HeapFree(GetProcessHeap(),0,Names
);
1018 /***********************************************************************
1019 * PRINTDLG_UpdatePrinterInfoTexts [internal]
1021 static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg
, const PRINTER_INFO_2A
*pi
)
1023 char StatusMsg
[256];
1024 char ResourceString
[256];
1027 /* Status Message */
1030 /* add all status messages */
1031 for (i
= 0; i
< 25; i
++) {
1032 if (pi
->Status
& (1<<i
)) {
1033 LoadStringA(COMDLG32_hInstance
, PD32_PRINTER_STATUS_PAUSED
+i
,
1034 ResourceString
, 255);
1035 strcat(StatusMsg
,ResourceString
);
1038 /* append "ready" */
1039 /* FIXME: status==ready must only be appended if really so.
1040 but how to detect? */
1041 LoadStringA(COMDLG32_hInstance
, PD32_PRINTER_STATUS_READY
,
1042 ResourceString
, 255);
1043 strcat(StatusMsg
,ResourceString
);
1044 SetDlgItemTextA(hDlg
, stc12
, StatusMsg
);
1046 /* set all other printer info texts */
1047 SetDlgItemTextA(hDlg
, stc11
, pi
->pDriverName
);
1049 if (pi
->pLocation
!= NULL
&& pi
->pLocation
[0] != '\0')
1050 SetDlgItemTextA(hDlg
, stc14
, pi
->pLocation
);
1052 SetDlgItemTextA(hDlg
, stc14
, pi
->pPortName
);
1053 SetDlgItemTextA(hDlg
, stc13
, pi
->pComment
? pi
->pComment
: "");
1057 static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg
, const PRINTER_INFO_2W
*pi
)
1059 WCHAR StatusMsg
[256];
1060 WCHAR ResourceString
[256];
1061 static const WCHAR emptyW
[] = {0};
1064 /* Status Message */
1067 /* add all status messages */
1068 for (i
= 0; i
< 25; i
++) {
1069 if (pi
->Status
& (1<<i
)) {
1070 LoadStringW(COMDLG32_hInstance
, PD32_PRINTER_STATUS_PAUSED
+i
,
1071 ResourceString
, 255);
1072 lstrcatW(StatusMsg
,ResourceString
);
1075 /* append "ready" */
1076 /* FIXME: status==ready must only be appended if really so.
1077 but how to detect? */
1078 LoadStringW(COMDLG32_hInstance
, PD32_PRINTER_STATUS_READY
,
1079 ResourceString
, 255);
1080 lstrcatW(StatusMsg
,ResourceString
);
1081 SetDlgItemTextW(hDlg
, stc12
, StatusMsg
);
1083 /* set all other printer info texts */
1084 SetDlgItemTextW(hDlg
, stc11
, pi
->pDriverName
);
1085 if (pi
->pLocation
!= NULL
&& pi
->pLocation
[0] != '\0')
1086 SetDlgItemTextW(hDlg
, stc14
, pi
->pLocation
);
1088 SetDlgItemTextW(hDlg
, stc14
, pi
->pPortName
);
1089 SetDlgItemTextW(hDlg
, stc13
, pi
->pComment
? pi
->pComment
: emptyW
);
1093 /*******************************************************************
1095 * PRINTDLG_ChangePrinter
1098 static BOOL
PRINTDLG_ChangePrinterA(HWND hDlg
, char *name
, PRINT_PTRA
*PrintStructures
)
1100 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1101 LPDEVMODEA lpdm
= NULL
;
1106 HeapFree(GetProcessHeap(),0, PrintStructures
->lpPrinterInfo
);
1107 HeapFree(GetProcessHeap(),0, PrintStructures
->lpDriverInfo
);
1108 if(!OpenPrinterA(name
, &hprn
, NULL
)) {
1109 ERR("Can't open printer %s\n", name
);
1112 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
1113 PrintStructures
->lpPrinterInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
1114 GetPrinterA(hprn
, 2, (LPBYTE
)PrintStructures
->lpPrinterInfo
, needed
,
1116 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
1117 PrintStructures
->lpDriverInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
1118 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)PrintStructures
->lpDriverInfo
,
1120 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures
->lpPrinterInfo
->pPrinterName
);
1125 PRINTDLG_UpdatePrinterInfoTextsA(hDlg
, PrintStructures
->lpPrinterInfo
);
1127 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
1128 PrintStructures
->lpDevMode
= NULL
;
1130 dmSize
= DocumentPropertiesA(0, 0, name
, NULL
, NULL
, 0);
1132 ERR("DocumentProperties fails on %s\n", debugstr_a(name
));
1135 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(), 0, dmSize
);
1136 dmSize
= DocumentPropertiesA(0, 0, name
, PrintStructures
->lpDevMode
, NULL
,
1138 if(lppd
->hDevMode
&& (lpdm
= GlobalLock(lppd
->hDevMode
)) &&
1139 !lstrcmpA( (LPSTR
) lpdm
->dmDeviceName
,
1140 (LPSTR
) PrintStructures
->lpDevMode
->dmDeviceName
)) {
1141 /* Supplied devicemode matches current printer so try to use it */
1142 DocumentPropertiesA(0, 0, name
, PrintStructures
->lpDevMode
, lpdm
,
1143 DM_OUT_BUFFER
| DM_IN_BUFFER
);
1146 GlobalUnlock(lppd
->hDevMode
);
1148 lpdm
= PrintStructures
->lpDevMode
; /* use this as a shortcut */
1150 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
1151 /* Print range (All/Range/Selection) */
1152 if(lppd
->nFromPage
!= 0xffff)
1153 SetDlgItemInt(hDlg
, edt1
, lppd
->nFromPage
, FALSE
);
1154 if(lppd
->nToPage
!= 0xffff)
1155 SetDlgItemInt(hDlg
, edt2
, lppd
->nToPage
, FALSE
);
1157 CheckRadioButton(hDlg
, rad1
, rad3
, rad1
); /* default */
1158 if (lppd
->Flags
& PD_NOSELECTION
)
1159 EnableWindow(GetDlgItem(hDlg
, rad2
), FALSE
);
1161 if (lppd
->Flags
& PD_SELECTION
)
1162 CheckRadioButton(hDlg
, rad1
, rad3
, rad2
);
1163 if (lppd
->Flags
& PD_NOPAGENUMS
) {
1164 EnableWindow(GetDlgItem(hDlg
, rad3
), FALSE
);
1165 EnableWindow(GetDlgItem(hDlg
, stc2
),FALSE
);
1166 EnableWindow(GetDlgItem(hDlg
, edt1
), FALSE
);
1167 EnableWindow(GetDlgItem(hDlg
, stc3
),FALSE
);
1168 EnableWindow(GetDlgItem(hDlg
, edt2
), FALSE
);
1170 if (lppd
->Flags
& PD_PAGENUMS
)
1171 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1175 if (lppd
->Flags
& PD_COLLATE
) {
1176 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1177 (LPARAM
)PrintStructures
->hCollateIcon
);
1178 CheckDlgButton(hDlg
, chx2
, 1);
1180 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1181 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1182 CheckDlgButton(hDlg
, chx2
, 0);
1185 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1186 /* if printer doesn't support it: no Collate */
1187 if (!(lpdm
->dmFields
& DM_COLLATE
)) {
1188 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1189 EnableWindow(GetDlgItem(hDlg
, ico3
), FALSE
);
1196 if (lppd
->hDevMode
== 0)
1197 copies
= lppd
->nCopies
;
1199 copies
= lpdm
->u1
.s1
.dmCopies
;
1200 if(copies
== 0) copies
= 1;
1201 else if(copies
< 0) copies
= MAX_COPIES
;
1202 SetDlgItemInt(hDlg
, edt3
, copies
, FALSE
);
1205 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1206 /* if printer doesn't support it: no nCopies */
1207 if (!(lpdm
->dmFields
& DM_COPIES
)) {
1208 EnableWindow(GetDlgItem(hDlg
, edt3
), FALSE
);
1209 EnableWindow(GetDlgItem(hDlg
, stc5
), FALSE
);
1214 CheckDlgButton(hDlg
, chx1
, (lppd
->Flags
& PD_PRINTTOFILE
) ? 1 : 0);
1215 if (lppd
->Flags
& PD_DISABLEPRINTTOFILE
)
1216 EnableWindow(GetDlgItem(hDlg
, chx1
), FALSE
);
1217 if (lppd
->Flags
& PD_HIDEPRINTTOFILE
)
1218 ShowWindow(GetDlgItem(hDlg
, chx1
), SW_HIDE
);
1220 /* Fill print quality combo, PrintDlg16 */
1221 if(GetDlgItem(hDlg
, cmb1
))
1223 DWORD numResolutions
= DeviceCapabilitiesA(PrintStructures
->lpPrinterInfo
->pPrinterName
,
1224 PrintStructures
->lpPrinterInfo
->pPortName
,
1225 DC_ENUMRESOLUTIONS
, NULL
, lpdm
);
1227 if(numResolutions
!= -1)
1229 HWND hQuality
= GetDlgItem(hDlg
, cmb1
);
1234 HDC hPrinterDC
= CreateDCA(PrintStructures
->lpPrinterInfo
->pDriverName
,
1235 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1238 Resolutions
= HeapAlloc(GetProcessHeap(), 0, numResolutions
*sizeof(LONG
)*2);
1239 DeviceCapabilitiesA(PrintStructures
->lpPrinterInfo
->pPrinterName
,
1240 PrintStructures
->lpPrinterInfo
->pPortName
,
1241 DC_ENUMRESOLUTIONS
, (LPSTR
)Resolutions
, lpdm
);
1243 dpiX
= GetDeviceCaps(hPrinterDC
, LOGPIXELSX
);
1244 dpiY
= GetDeviceCaps(hPrinterDC
, LOGPIXELSY
);
1245 DeleteDC(hPrinterDC
);
1247 SendMessageA(hQuality
, CB_RESETCONTENT
, 0, 0);
1248 for(i
= 0; i
< (numResolutions
* 2); i
+= 2)
1250 BOOL IsDefault
= FALSE
;
1253 if(Resolutions
[i
] == Resolutions
[i
+1])
1255 if(dpiX
== Resolutions
[i
])
1257 sprintf(buf
, "%d dpi", Resolutions
[i
]);
1260 if(dpiX
== Resolutions
[i
] && dpiY
== Resolutions
[i
+1])
1262 sprintf(buf
, "%d dpi x %d dpi", Resolutions
[i
], Resolutions
[i
+1]);
1265 Index
= SendMessageA(hQuality
, CB_ADDSTRING
, 0, (LPARAM
)buf
);
1268 SendMessageA(hQuality
, CB_SETCURSEL
, Index
, 0);
1270 SendMessageA(hQuality
, CB_SETITEMDATA
, Index
, MAKELONG(dpiX
,dpiY
));
1272 HeapFree(GetProcessHeap(), 0, Resolutions
);
1275 } else { /* PD_PRINTSETUP */
1276 BOOL bPortrait
= (lpdm
->u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
);
1278 PRINTDLG_SetUpPaperComboBoxA(hDlg
, cmb2
,
1279 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1280 PrintStructures
->lpPrinterInfo
->pPortName
,
1282 PRINTDLG_SetUpPaperComboBoxA(hDlg
, cmb3
,
1283 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1284 PrintStructures
->lpPrinterInfo
->pPortName
,
1286 CheckRadioButton(hDlg
, rad1
, rad2
, bPortrait
? rad1
: rad2
);
1287 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1288 (LPARAM
)(bPortrait
? PrintStructures
->hPortraitIcon
:
1289 PrintStructures
->hLandscapeIcon
));
1294 if ((lppd
->Flags
& PD_SHOWHELP
)==0) {
1295 /* hide if PD_SHOWHELP not specified */
1296 ShowWindow(GetDlgItem(hDlg
, pshHelp
), SW_HIDE
);
1301 static BOOL
PRINTDLG_ChangePrinterW(HWND hDlg
, WCHAR
*name
,
1302 PRINT_PTRW
*PrintStructures
)
1304 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1305 LPDEVMODEW lpdm
= NULL
;
1310 HeapFree(GetProcessHeap(),0, PrintStructures
->lpPrinterInfo
);
1311 HeapFree(GetProcessHeap(),0, PrintStructures
->lpDriverInfo
);
1312 if(!OpenPrinterW(name
, &hprn
, NULL
)) {
1313 ERR("Can't open printer %s\n", debugstr_w(name
));
1316 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
1317 PrintStructures
->lpPrinterInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
1318 GetPrinterW(hprn
, 2, (LPBYTE
)PrintStructures
->lpPrinterInfo
, needed
,
1320 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
1321 PrintStructures
->lpDriverInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
1322 if (!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)PrintStructures
->lpDriverInfo
,
1324 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures
->lpPrinterInfo
->pPrinterName
));
1329 PRINTDLG_UpdatePrinterInfoTextsW(hDlg
, PrintStructures
->lpPrinterInfo
);
1331 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
1332 PrintStructures
->lpDevMode
= NULL
;
1334 dmSize
= DocumentPropertiesW(0, 0, name
, NULL
, NULL
, 0);
1336 ERR("DocumentProperties fails on %s\n", debugstr_w(name
));
1339 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(), 0, dmSize
);
1340 dmSize
= DocumentPropertiesW(0, 0, name
, PrintStructures
->lpDevMode
, NULL
,
1342 if(lppd
->hDevMode
&& (lpdm
= GlobalLock(lppd
->hDevMode
)) &&
1343 !lstrcmpW(lpdm
->dmDeviceName
,
1344 PrintStructures
->lpDevMode
->dmDeviceName
)) {
1345 /* Supplied devicemode matches current printer so try to use it */
1346 DocumentPropertiesW(0, 0, name
, PrintStructures
->lpDevMode
, lpdm
,
1347 DM_OUT_BUFFER
| DM_IN_BUFFER
);
1350 GlobalUnlock(lppd
->hDevMode
);
1352 lpdm
= PrintStructures
->lpDevMode
; /* use this as a shortcut */
1354 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
1355 /* Print range (All/Range/Selection) */
1356 if(lppd
->nFromPage
!= 0xffff)
1357 SetDlgItemInt(hDlg
, edt1
, lppd
->nFromPage
, FALSE
);
1358 if(lppd
->nToPage
!= 0xffff)
1359 SetDlgItemInt(hDlg
, edt2
, lppd
->nToPage
, FALSE
);
1361 CheckRadioButton(hDlg
, rad1
, rad3
, rad1
); /* default */
1362 if (lppd
->Flags
& PD_NOSELECTION
)
1363 EnableWindow(GetDlgItem(hDlg
, rad2
), FALSE
);
1365 if (lppd
->Flags
& PD_SELECTION
)
1366 CheckRadioButton(hDlg
, rad1
, rad3
, rad2
);
1367 if (lppd
->Flags
& PD_NOPAGENUMS
) {
1368 EnableWindow(GetDlgItem(hDlg
, rad3
), FALSE
);
1369 EnableWindow(GetDlgItem(hDlg
, stc2
),FALSE
);
1370 EnableWindow(GetDlgItem(hDlg
, edt1
), FALSE
);
1371 EnableWindow(GetDlgItem(hDlg
, stc3
),FALSE
);
1372 EnableWindow(GetDlgItem(hDlg
, edt2
), FALSE
);
1374 if (lppd
->Flags
& PD_PAGENUMS
)
1375 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1379 if (lppd
->Flags
& PD_COLLATE
) {
1380 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1381 (LPARAM
)PrintStructures
->hCollateIcon
);
1382 CheckDlgButton(hDlg
, chx2
, 1);
1384 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1385 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1386 CheckDlgButton(hDlg
, chx2
, 0);
1389 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1390 /* if printer doesn't support it: no Collate */
1391 if (!(lpdm
->dmFields
& DM_COLLATE
)) {
1392 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1393 EnableWindow(GetDlgItem(hDlg
, ico3
), FALSE
);
1400 if (lppd
->hDevMode
== 0)
1401 copies
= lppd
->nCopies
;
1403 copies
= lpdm
->u1
.s1
.dmCopies
;
1404 if(copies
== 0) copies
= 1;
1405 else if(copies
< 0) copies
= MAX_COPIES
;
1406 SetDlgItemInt(hDlg
, edt3
, copies
, FALSE
);
1409 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1410 /* if printer doesn't support it: no nCopies */
1411 if (!(lpdm
->dmFields
& DM_COPIES
)) {
1412 EnableWindow(GetDlgItem(hDlg
, edt3
), FALSE
);
1413 EnableWindow(GetDlgItem(hDlg
, stc5
), FALSE
);
1418 CheckDlgButton(hDlg
, chx1
, (lppd
->Flags
& PD_PRINTTOFILE
) ? 1 : 0);
1419 if (lppd
->Flags
& PD_DISABLEPRINTTOFILE
)
1420 EnableWindow(GetDlgItem(hDlg
, chx1
), FALSE
);
1421 if (lppd
->Flags
& PD_HIDEPRINTTOFILE
)
1422 ShowWindow(GetDlgItem(hDlg
, chx1
), SW_HIDE
);
1424 } else { /* PD_PRINTSETUP */
1425 BOOL bPortrait
= (lpdm
->u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
);
1427 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb2
,
1428 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1429 PrintStructures
->lpPrinterInfo
->pPortName
,
1431 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb3
,
1432 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1433 PrintStructures
->lpPrinterInfo
->pPortName
,
1435 CheckRadioButton(hDlg
, rad1
, rad2
, bPortrait
? rad1
: rad2
);
1436 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1437 (LPARAM
)(bPortrait
? PrintStructures
->hPortraitIcon
:
1438 PrintStructures
->hLandscapeIcon
));
1443 if ((lppd
->Flags
& PD_SHOWHELP
)==0) {
1444 /* hide if PD_SHOWHELP not specified */
1445 ShowWindow(GetDlgItem(hDlg
, pshHelp
), SW_HIDE
);
1450 /***********************************************************************
1451 * check_printer_setup [internal]
1453 static LRESULT
check_printer_setup(HWND hDlg
)
1456 WCHAR resourcestr
[256],resultstr
[256];
1458 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
1461 EnumPrintersW(PRINTER_ENUM_CONNECTIONS
, NULL
, 2, NULL
, 0, &needed
, &num
);
1467 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEVICES
,resultstr
, 255);
1468 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
,resourcestr
, 255);
1469 MessageBoxW(hDlg
, resultstr
, resourcestr
,MB_OK
| MB_ICONWARNING
);
1474 /***********************************************************************
1475 * PRINTDLG_WMInitDialog [internal]
1477 static LRESULT
PRINTDLG_WMInitDialog(HWND hDlg
,
1478 PRINT_PTRA
* PrintStructures
)
1480 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1484 UINT comboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1486 /* load Collate ICONs */
1487 /* We load these with LoadImage because they are not a standard
1488 size and we don't want them rescaled */
1489 PrintStructures
->hCollateIcon
=
1490 LoadImageA(COMDLG32_hInstance
, "PD32_COLLATE", IMAGE_ICON
, 0, 0, 0);
1491 PrintStructures
->hNoCollateIcon
=
1492 LoadImageA(COMDLG32_hInstance
, "PD32_NOCOLLATE", IMAGE_ICON
, 0, 0, 0);
1494 /* These can be done with LoadIcon */
1495 PrintStructures
->hPortraitIcon
=
1496 LoadIconA(COMDLG32_hInstance
, "PD32_PORTRAIT");
1497 PrintStructures
->hLandscapeIcon
=
1498 LoadIconA(COMDLG32_hInstance
, "PD32_LANDSCAPE");
1500 /* display the collate/no_collate icon */
1501 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1502 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1504 if(PrintStructures
->hCollateIcon
== 0 ||
1505 PrintStructures
->hNoCollateIcon
== 0 ||
1506 PrintStructures
->hPortraitIcon
== 0 ||
1507 PrintStructures
->hLandscapeIcon
== 0) {
1508 ERR("no icon in resource file\n");
1509 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1510 EndDialog(hDlg
, FALSE
);
1514 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1515 * must be registered and the Help button must be shown.
1517 if (lppd
->Flags
& PD_SHOWHELP
) {
1518 if((PrintStructures
->HelpMessageID
=
1519 RegisterWindowMessageA(HELPMSGSTRINGA
)) == 0) {
1520 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL
);
1524 PrintStructures
->HelpMessageID
= 0;
1526 if(!(lppd
->Flags
&PD_PRINTSETUP
)) {
1527 PrintStructures
->hwndUpDown
=
1528 CreateUpDownControl(WS_CHILD
| WS_VISIBLE
| WS_BORDER
|
1529 UDS_NOTHOUSANDS
| UDS_ARROWKEYS
|
1530 UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, 0, 0, 0, 0,
1531 hDlg
, UPDOWN_ID
, COMDLG32_hInstance
,
1532 GetDlgItem(hDlg
, edt3
), MAX_COPIES
, 1, 1);
1535 /* FIXME: I allow more freedom than either Win95 or WinNT,
1536 * which do not agree on what errors should be thrown or not
1537 * in case nToPage or nFromPage is out-of-range.
1539 if (lppd
->nMaxPage
< lppd
->nMinPage
)
1540 lppd
->nMaxPage
= lppd
->nMinPage
;
1541 if (lppd
->nMinPage
== lppd
->nMaxPage
)
1542 lppd
->Flags
|= PD_NOPAGENUMS
;
1543 if (lppd
->nToPage
< lppd
->nMinPage
)
1544 lppd
->nToPage
= lppd
->nMinPage
;
1545 if (lppd
->nToPage
> lppd
->nMaxPage
)
1546 lppd
->nToPage
= lppd
->nMaxPage
;
1547 if (lppd
->nFromPage
< lppd
->nMinPage
)
1548 lppd
->nFromPage
= lppd
->nMinPage
;
1549 if (lppd
->nFromPage
> lppd
->nMaxPage
)
1550 lppd
->nFromPage
= lppd
->nMaxPage
;
1552 /* if we have the combo box, fill it */
1553 if (GetDlgItem(hDlg
,comboID
)) {
1556 pdn
= GlobalLock(lppd
->hDevNames
);
1557 pdm
= GlobalLock(lppd
->hDevMode
);
1559 name
= (char*)pdn
+ pdn
->wDeviceOffset
;
1561 name
= (char*)pdm
->dmDeviceName
;
1562 PRINTDLG_SetUpPrinterListComboA(hDlg
, comboID
, name
);
1563 if(pdm
) GlobalUnlock(lppd
->hDevMode
);
1564 if(pdn
) GlobalUnlock(lppd
->hDevNames
);
1566 /* Now find selected printer and update rest of dlg */
1567 name
= HeapAlloc(GetProcessHeap(),0,256);
1568 if (GetDlgItemTextA(hDlg
, comboID
, name
, 255))
1569 PRINTDLG_ChangePrinterA(hDlg
, name
, PrintStructures
);
1570 HeapFree(GetProcessHeap(),0,name
);
1572 /* else use default printer */
1574 DWORD dwBufLen
= ARRAY_SIZE(name
);
1575 BOOL ret
= GetDefaultPrinterA(name
, &dwBufLen
);
1578 PRINTDLG_ChangePrinterA(hDlg
, name
, PrintStructures
);
1580 FIXME("No default printer found, expect problems!\n");
1585 static LRESULT
PRINTDLG_WMInitDialogW(HWND hDlg
,
1586 PRINT_PTRW
* PrintStructures
)
1588 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1592 UINT comboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1594 /* load Collate ICONs */
1595 /* We load these with LoadImage because they are not a standard
1596 size and we don't want them rescaled */
1597 PrintStructures
->hCollateIcon
=
1598 LoadImageW(COMDLG32_hInstance
, pd32_collateW
, IMAGE_ICON
, 0, 0, 0);
1599 PrintStructures
->hNoCollateIcon
=
1600 LoadImageW(COMDLG32_hInstance
, pd32_nocollateW
, IMAGE_ICON
, 0, 0, 0);
1602 /* These can be done with LoadIcon */
1603 PrintStructures
->hPortraitIcon
=
1604 LoadIconW(COMDLG32_hInstance
, pd32_portraitW
);
1605 PrintStructures
->hLandscapeIcon
=
1606 LoadIconW(COMDLG32_hInstance
, pd32_landscapeW
);
1608 /* display the collate/no_collate icon */
1609 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1610 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1612 if(PrintStructures
->hCollateIcon
== 0 ||
1613 PrintStructures
->hNoCollateIcon
== 0 ||
1614 PrintStructures
->hPortraitIcon
== 0 ||
1615 PrintStructures
->hLandscapeIcon
== 0) {
1616 ERR("no icon in resource file\n");
1617 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1618 EndDialog(hDlg
, FALSE
);
1622 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1623 * must be registered and the Help button must be shown.
1625 if (lppd
->Flags
& PD_SHOWHELP
) {
1626 if((PrintStructures
->HelpMessageID
=
1627 RegisterWindowMessageW(HELPMSGSTRINGW
)) == 0) {
1628 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL
);
1632 PrintStructures
->HelpMessageID
= 0;
1634 if(!(lppd
->Flags
&PD_PRINTSETUP
)) {
1635 PrintStructures
->hwndUpDown
=
1636 CreateUpDownControl(WS_CHILD
| WS_VISIBLE
| WS_BORDER
|
1637 UDS_NOTHOUSANDS
| UDS_ARROWKEYS
|
1638 UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, 0, 0, 0, 0,
1639 hDlg
, UPDOWN_ID
, COMDLG32_hInstance
,
1640 GetDlgItem(hDlg
, edt3
), MAX_COPIES
, 1, 1);
1643 /* FIXME: I allow more freedom than either Win95 or WinNT,
1644 * which do not agree to what errors should be thrown or not
1645 * in case nToPage or nFromPage is out-of-range.
1647 if (lppd
->nMaxPage
< lppd
->nMinPage
)
1648 lppd
->nMaxPage
= lppd
->nMinPage
;
1649 if (lppd
->nMinPage
== lppd
->nMaxPage
)
1650 lppd
->Flags
|= PD_NOPAGENUMS
;
1651 if (lppd
->nToPage
< lppd
->nMinPage
)
1652 lppd
->nToPage
= lppd
->nMinPage
;
1653 if (lppd
->nToPage
> lppd
->nMaxPage
)
1654 lppd
->nToPage
= lppd
->nMaxPage
;
1655 if (lppd
->nFromPage
< lppd
->nMinPage
)
1656 lppd
->nFromPage
= lppd
->nMinPage
;
1657 if (lppd
->nFromPage
> lppd
->nMaxPage
)
1658 lppd
->nFromPage
= lppd
->nMaxPage
;
1660 /* if we have the combo box, fill it */
1661 if (GetDlgItem(hDlg
,comboID
)) {
1664 pdn
= GlobalLock(lppd
->hDevNames
);
1665 pdm
= GlobalLock(lppd
->hDevMode
);
1667 name
= (WCHAR
*)pdn
+ pdn
->wDeviceOffset
;
1669 name
= pdm
->dmDeviceName
;
1670 PRINTDLG_SetUpPrinterListComboW(hDlg
, comboID
, name
);
1671 if(pdm
) GlobalUnlock(lppd
->hDevMode
);
1672 if(pdn
) GlobalUnlock(lppd
->hDevNames
);
1674 /* Now find selected printer and update rest of dlg */
1675 /* ansi is ok here */
1676 name
= HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR
));
1677 if (GetDlgItemTextW(hDlg
, comboID
, name
, 255))
1678 PRINTDLG_ChangePrinterW(hDlg
, name
, PrintStructures
);
1679 HeapFree(GetProcessHeap(),0,name
);
1681 /* else use default printer */
1683 DWORD dwBufLen
= ARRAY_SIZE(name
);
1684 BOOL ret
= GetDefaultPrinterW(name
, &dwBufLen
);
1687 PRINTDLG_ChangePrinterW(hDlg
, name
, PrintStructures
);
1689 FIXME("No default printer found, expect problems!\n");
1694 /***********************************************************************
1695 * PRINTDLG_WMCommand [internal]
1697 static LRESULT
PRINTDLG_WMCommandA(HWND hDlg
, WPARAM wParam
,
1698 PRINT_PTRA
* PrintStructures
)
1700 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1701 UINT PrinterComboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1702 LPDEVMODEA lpdm
= PrintStructures
->lpDevMode
;
1704 switch (LOWORD(wParam
)) {
1706 TRACE(" OK button was hit\n");
1707 if (!PRINTDLG_UpdatePrintDlgA(hDlg
, PrintStructures
)) {
1708 FIXME("Update printdlg was not successful!\n");
1711 EndDialog(hDlg
, TRUE
);
1715 TRACE(" CANCEL button was hit\n");
1716 EndDialog(hDlg
, FALSE
);
1720 TRACE(" HELP button was hit\n");
1721 SendMessageA(lppd
->hwndOwner
, PrintStructures
->HelpMessageID
,
1722 (WPARAM
) hDlg
, (LPARAM
) lppd
);
1725 case chx2
: /* collate pages checkbox */
1726 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
1727 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1728 (LPARAM
)PrintStructures
->hCollateIcon
);
1730 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1731 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1733 case edt1
: /* from page nr editbox */
1734 case edt2
: /* to page nr editbox */
1735 if (HIWORD(wParam
)==EN_CHANGE
) {
1738 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
1739 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
1740 if (nFromPage
!= lppd
->nFromPage
|| nToPage
!= lppd
->nToPage
)
1741 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1746 if(HIWORD(wParam
) == EN_CHANGE
) {
1747 INT copies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
1749 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1751 EnableWindow(GetDlgItem(hDlg
, chx2
), TRUE
);
1755 case psh2
: /* Properties button */
1758 char PrinterName
[256];
1760 GetDlgItemTextA(hDlg
, PrinterComboID
, PrinterName
, 255);
1761 if (!OpenPrinterA(PrinterName
, &hPrinter
, NULL
)) {
1762 FIXME(" Call to OpenPrinter did not succeed!\n");
1765 DocumentPropertiesA(hDlg
, hPrinter
, PrinterName
,
1766 PrintStructures
->lpDevMode
,
1767 PrintStructures
->lpDevMode
,
1768 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
1769 ClosePrinter(hPrinter
);
1773 case rad1
: /* Paperorientation */
1774 if (lppd
->Flags
& PD_PRINTSETUP
)
1776 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1777 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1778 (LPARAM
)(PrintStructures
->hPortraitIcon
));
1782 case rad2
: /* Paperorientation */
1783 if (lppd
->Flags
& PD_PRINTSETUP
)
1785 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1786 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1787 (LPARAM
)(PrintStructures
->hLandscapeIcon
));
1791 case cmb1
: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT16 */
1792 if (PrinterComboID
!= LOWORD(wParam
)) {
1796 case cmb4
: /* Printer combobox */
1797 if (HIWORD(wParam
)==CBN_SELCHANGE
) {
1799 INT index
= SendDlgItemMessageW(hDlg
, LOWORD(wParam
), CB_GETCURSEL
, 0, 0);
1800 INT length
= SendDlgItemMessageW(hDlg
, LOWORD(wParam
), CB_GETLBTEXTLEN
, index
, 0);
1801 PrinterName
= HeapAlloc(GetProcessHeap(),0,length
+1);
1802 SendDlgItemMessageA(hDlg
, LOWORD(wParam
), CB_GETLBTEXT
, index
, (LPARAM
)PrinterName
);
1803 PRINTDLG_ChangePrinterA(hDlg
, PrinterName
, PrintStructures
);
1804 HeapFree(GetProcessHeap(),0,PrinterName
);
1808 case cmb2
: /* Papersize */
1810 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
1812 lpdm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageA(hDlg
, cmb2
,
1815 GetDlgItemTextA(hDlg
, cmb2
, (char *)lpdm
->dmFormName
, CCHFORMNAME
);
1820 case cmb3
: /* Bin */
1822 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
1824 lpdm
->u1
.s1
.dmDefaultSource
= SendDlgItemMessageA(hDlg
, cmb3
,
1825 CB_GETITEMDATA
, Sel
,
1830 if(lppd
->Flags
& PD_PRINTSETUP
) {
1831 switch (LOWORD(wParam
)) {
1832 case rad1
: /* orientation */
1834 if (IsDlgButtonChecked(hDlg
, rad1
) == BST_CHECKED
) {
1835 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_PORTRAIT
) {
1836 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1837 SendDlgItemMessageA(hDlg
, stc10
, STM_SETIMAGE
, IMAGE_ICON
,
1838 (LPARAM
)PrintStructures
->hPortraitIcon
);
1839 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1840 (LPARAM
)PrintStructures
->hPortraitIcon
);
1843 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_LANDSCAPE
) {
1844 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1845 SendDlgItemMessageA(hDlg
, stc10
, STM_SETIMAGE
, IMAGE_ICON
,
1846 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1847 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1848 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1857 static LRESULT
PRINTDLG_WMCommandW(HWND hDlg
, WPARAM wParam
,
1858 PRINT_PTRW
* PrintStructures
)
1860 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1861 UINT PrinterComboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1862 LPDEVMODEW lpdm
= PrintStructures
->lpDevMode
;
1864 switch (LOWORD(wParam
)) {
1866 TRACE(" OK button was hit\n");
1867 if (!PRINTDLG_UpdatePrintDlgW(hDlg
, PrintStructures
)) {
1868 FIXME("Update printdlg was not successful!\n");
1871 EndDialog(hDlg
, TRUE
);
1875 TRACE(" CANCEL button was hit\n");
1876 EndDialog(hDlg
, FALSE
);
1880 TRACE(" HELP button was hit\n");
1881 SendMessageW(lppd
->hwndOwner
, PrintStructures
->HelpMessageID
,
1882 (WPARAM
) hDlg
, (LPARAM
) lppd
);
1885 case chx2
: /* collate pages checkbox */
1886 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
1887 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1888 (LPARAM
)PrintStructures
->hCollateIcon
);
1890 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1891 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1893 case edt1
: /* from page nr editbox */
1894 case edt2
: /* to page nr editbox */
1895 if (HIWORD(wParam
)==EN_CHANGE
) {
1898 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
1899 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
1900 if (nFromPage
!= lppd
->nFromPage
|| nToPage
!= lppd
->nToPage
)
1901 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1906 if(HIWORD(wParam
) == EN_CHANGE
) {
1907 INT copies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
1909 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1911 EnableWindow(GetDlgItem(hDlg
, chx2
), TRUE
);
1915 case psh2
: /* Properties button */
1918 WCHAR PrinterName
[256];
1920 if (!GetDlgItemTextW(hDlg
, PrinterComboID
, PrinterName
, 255)) break;
1921 if (!OpenPrinterW(PrinterName
, &hPrinter
, NULL
)) {
1922 FIXME(" Call to OpenPrinter did not succeed!\n");
1925 DocumentPropertiesW(hDlg
, hPrinter
, PrinterName
,
1926 PrintStructures
->lpDevMode
,
1927 PrintStructures
->lpDevMode
,
1928 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
1929 ClosePrinter(hPrinter
);
1933 case rad1
: /* Paperorientation */
1934 if (lppd
->Flags
& PD_PRINTSETUP
)
1936 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1937 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1938 (LPARAM
)(PrintStructures
->hPortraitIcon
));
1942 case rad2
: /* Paperorientation */
1943 if (lppd
->Flags
& PD_PRINTSETUP
)
1945 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1946 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1947 (LPARAM
)(PrintStructures
->hLandscapeIcon
));
1951 case cmb1
: /* Printer Combobox in PRINT SETUP */
1953 case cmb4
: /* Printer combobox */
1954 if (HIWORD(wParam
)==CBN_SELCHANGE
) {
1956 INT index
= SendDlgItemMessageW(hDlg
, LOWORD(wParam
), CB_GETCURSEL
, 0, 0);
1957 INT length
= SendDlgItemMessageW(hDlg
, LOWORD(wParam
), CB_GETLBTEXTLEN
, index
, 0);
1959 PrinterName
= HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*(length
+1));
1960 SendDlgItemMessageW(hDlg
, LOWORD(wParam
), CB_GETLBTEXT
, index
, (LPARAM
)PrinterName
);
1961 PRINTDLG_ChangePrinterW(hDlg
, PrinterName
, PrintStructures
);
1962 HeapFree(GetProcessHeap(),0,PrinterName
);
1966 case cmb2
: /* Papersize */
1968 DWORD Sel
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
1970 lpdm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageW(hDlg
, cmb2
,
1973 GetDlgItemTextW(hDlg
, cmb2
, lpdm
->dmFormName
, CCHFORMNAME
);
1978 case cmb3
: /* Bin */
1980 DWORD Sel
= SendDlgItemMessageW(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
1982 lpdm
->u1
.s1
.dmDefaultSource
= SendDlgItemMessageW(hDlg
, cmb3
,
1983 CB_GETITEMDATA
, Sel
,
1988 if(lppd
->Flags
& PD_PRINTSETUP
) {
1989 switch (LOWORD(wParam
)) {
1990 case rad1
: /* orientation */
1992 if (IsDlgButtonChecked(hDlg
, rad1
) == BST_CHECKED
) {
1993 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_PORTRAIT
) {
1994 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1995 SendDlgItemMessageW(hDlg
, stc10
, STM_SETIMAGE
, IMAGE_ICON
,
1996 (LPARAM
)PrintStructures
->hPortraitIcon
);
1997 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1998 (LPARAM
)PrintStructures
->hPortraitIcon
);
2001 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_LANDSCAPE
) {
2002 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
2003 SendDlgItemMessageW(hDlg
, stc10
, STM_SETIMAGE
, IMAGE_ICON
,
2004 (LPARAM
)PrintStructures
->hLandscapeIcon
);
2005 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
2006 (LPARAM
)PrintStructures
->hLandscapeIcon
);
2015 /***********************************************************************
2016 * PrintDlgProcA [internal]
2018 static INT_PTR CALLBACK
PrintDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
2021 PRINT_PTRA
* PrintStructures
;
2022 INT_PTR res
= FALSE
;
2024 if (uMsg
!=WM_INITDIALOG
) {
2025 PrintStructures
= GetPropW(hDlg
, printdlg_prop
);
2026 if (!PrintStructures
)
2029 PrintStructures
= (PRINT_PTRA
*) lParam
;
2030 SetPropW(hDlg
, printdlg_prop
, PrintStructures
);
2031 if(!check_printer_setup(hDlg
))
2033 EndDialog(hDlg
,FALSE
);
2036 res
= PRINTDLG_WMInitDialog(hDlg
, PrintStructures
);
2038 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
)
2039 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(
2040 hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->lpPrintDlg
2045 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
) {
2046 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
,uMsg
,wParam
,
2053 return PRINTDLG_WMCommandA(hDlg
, wParam
, PrintStructures
);
2056 DestroyIcon(PrintStructures
->hCollateIcon
);
2057 DestroyIcon(PrintStructures
->hNoCollateIcon
);
2058 DestroyIcon(PrintStructures
->hPortraitIcon
);
2059 DestroyIcon(PrintStructures
->hLandscapeIcon
);
2060 if(PrintStructures
->hwndUpDown
)
2061 DestroyWindow(PrintStructures
->hwndUpDown
);
2067 static INT_PTR CALLBACK
PrintDlgProcW(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
2070 PRINT_PTRW
* PrintStructures
;
2071 INT_PTR res
= FALSE
;
2073 if (uMsg
!=WM_INITDIALOG
) {
2074 PrintStructures
= GetPropW(hDlg
, printdlg_prop
);
2075 if (!PrintStructures
)
2078 PrintStructures
= (PRINT_PTRW
*) lParam
;
2079 SetPropW(hDlg
, printdlg_prop
, PrintStructures
);
2080 if(!check_printer_setup(hDlg
))
2082 EndDialog(hDlg
,FALSE
);
2085 res
= PRINTDLG_WMInitDialogW(hDlg
, PrintStructures
);
2087 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
)
2088 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->lpPrintDlg
);
2092 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
) {
2093 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
,uMsg
,wParam
, lParam
);
2099 return PRINTDLG_WMCommandW(hDlg
, wParam
, PrintStructures
);
2102 DestroyIcon(PrintStructures
->hCollateIcon
);
2103 DestroyIcon(PrintStructures
->hNoCollateIcon
);
2104 DestroyIcon(PrintStructures
->hPortraitIcon
);
2105 DestroyIcon(PrintStructures
->hLandscapeIcon
);
2106 if(PrintStructures
->hwndUpDown
)
2107 DestroyWindow(PrintStructures
->hwndUpDown
);
2113 /************************************************************
2115 * PRINTDLG_GetDlgTemplate
2118 static HGLOBAL
PRINTDLG_GetDlgTemplateA(const PRINTDLGA
*lppd
)
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
= FindResourceA(lppd
->hInstance
,
2128 lppd
->lpSetupTemplateName
, (LPSTR
)RT_DIALOG
);
2129 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
2131 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32_SETUP",
2133 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
2136 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
2137 hDlgTmpl
= lppd
->hPrintTemplate
;
2138 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
2139 hResInfo
= FindResourceA(lppd
->hInstance
,
2140 lppd
->lpPrintTemplateName
,
2142 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
2144 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32",
2146 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
2152 static HGLOBAL
PRINTDLG_GetDlgTemplateW(const PRINTDLGW
*lppd
)
2156 static const WCHAR xpsetup
[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
2157 static const WCHAR xprint
[] = { 'P','R','I','N','T','3','2',0};
2159 if (lppd
->Flags
& PD_PRINTSETUP
) {
2160 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
2161 hDlgTmpl
= lppd
->hSetupTemplate
;
2162 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
2163 hResInfo
= FindResourceW(lppd
->hInstance
,
2164 lppd
->lpSetupTemplateName
, (LPWSTR
)RT_DIALOG
);
2165 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
2167 hResInfo
= FindResourceW(COMDLG32_hInstance
, xpsetup
, (LPWSTR
)RT_DIALOG
);
2168 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
2171 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
2172 hDlgTmpl
= lppd
->hPrintTemplate
;
2173 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
2174 hResInfo
= FindResourceW(lppd
->hInstance
,
2175 lppd
->lpPrintTemplateName
,
2177 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
2179 hResInfo
= FindResourceW(COMDLG32_hInstance
, xprint
, (LPWSTR
)RT_DIALOG
);
2180 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
2186 /***********************************************************************
2191 static BOOL
PRINTDLG_CreateDCA(LPPRINTDLGA lppd
)
2193 DEVNAMES
*pdn
= GlobalLock(lppd
->hDevNames
);
2194 DEVMODEA
*pdm
= GlobalLock(lppd
->hDevMode
);
2196 if(lppd
->Flags
& PD_RETURNDC
) {
2197 lppd
->hDC
= CreateDCA((char*)pdn
+ pdn
->wDriverOffset
,
2198 (char*)pdn
+ pdn
->wDeviceOffset
,
2199 (char*)pdn
+ pdn
->wOutputOffset
,
2201 } else if(lppd
->Flags
& PD_RETURNIC
) {
2202 lppd
->hDC
= CreateICA((char*)pdn
+ pdn
->wDriverOffset
,
2203 (char*)pdn
+ pdn
->wDeviceOffset
,
2204 (char*)pdn
+ pdn
->wOutputOffset
,
2207 GlobalUnlock(lppd
->hDevNames
);
2208 GlobalUnlock(lppd
->hDevMode
);
2209 return lppd
->hDC
!= NULL
;
2212 static BOOL
PRINTDLG_CreateDCW(LPPRINTDLGW lppd
)
2214 DEVNAMES
*pdn
= GlobalLock(lppd
->hDevNames
);
2215 DEVMODEW
*pdm
= GlobalLock(lppd
->hDevMode
);
2217 if(lppd
->Flags
& PD_RETURNDC
) {
2218 lppd
->hDC
= CreateDCW((WCHAR
*)pdn
+ pdn
->wDriverOffset
,
2219 (WCHAR
*)pdn
+ pdn
->wDeviceOffset
,
2220 (WCHAR
*)pdn
+ pdn
->wOutputOffset
,
2222 } else if(lppd
->Flags
& PD_RETURNIC
) {
2223 lppd
->hDC
= CreateICW((WCHAR
*)pdn
+ pdn
->wDriverOffset
,
2224 (WCHAR
*)pdn
+ pdn
->wDeviceOffset
,
2225 (WCHAR
*)pdn
+ pdn
->wOutputOffset
,
2228 GlobalUnlock(lppd
->hDevNames
);
2229 GlobalUnlock(lppd
->hDevMode
);
2230 return lppd
->hDC
!= NULL
;
2233 /***********************************************************************
2234 * PrintDlgA (COMDLG32.@)
2236 * Displays the PRINT dialog box, which enables the user to specify
2237 * specific properties of the print job.
2240 * lppd [IO] ptr to PRINTDLG32 struct
2243 * nonzero if the user pressed the OK button
2244 * zero if the user cancelled the window or an error occurred
2248 * * The Collate Icons do not display, even though they are in the code.
2249 * * The Properties Button(s) should call DocumentPropertiesA().
2252 BOOL WINAPI
PrintDlgA(LPPRINTDLGA lppd
)
2260 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
2264 if(TRACE_ON(commdlg
)) {
2265 char flagstr
[1000] = "";
2266 const struct pd_flags
*pflag
= pd_flags
;
2267 for( ; pflag
->name
; pflag
++) {
2268 if(lppd
->Flags
& pflag
->flag
)
2269 strcat(flagstr
, pflag
->name
);
2271 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2272 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2273 "flags %08x (%s)\n",
2274 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
2275 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
2276 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
2279 if(lppd
->lStructSize
!= sizeof(PRINTDLGA
)) {
2280 WARN("structure size failure!!!\n");
2281 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
2285 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
2286 PRINTER_INFO_2A
*pbuf
;
2287 DRIVER_INFO_3A
*dbuf
;
2291 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
2292 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2293 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2296 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
2297 WARN("Can't find default printer\n");
2298 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
2302 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
2303 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
2304 GetPrinterA(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
2306 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
2307 dbuf
= HeapAlloc(GetProcessHeap(),0,needed
);
2308 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
2309 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2310 GetLastError(),pbuf
->pPrinterName
);
2311 HeapFree(GetProcessHeap(), 0, dbuf
);
2312 HeapFree(GetProcessHeap(), 0, pbuf
);
2313 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2318 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
2322 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
2323 pbuf
->pDevMode
->dmDriverExtra
);
2324 ptr
= GlobalLock(lppd
->hDevMode
);
2325 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
2326 pbuf
->pDevMode
->dmDriverExtra
);
2327 GlobalUnlock(lppd
->hDevMode
);
2328 HeapFree(GetProcessHeap(), 0, pbuf
);
2329 HeapFree(GetProcessHeap(), 0, dbuf
);
2333 PRINT_PTRA
*PrintStructures
;
2335 /* load Dialog resources,
2336 * depending on Flags indicates Print32 or Print32_setup dialog
2338 hDlgTmpl
= PRINTDLG_GetDlgTemplateA(lppd
);
2340 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2343 ptr
= LockResource( hDlgTmpl
);
2345 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2349 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2350 sizeof(PRINT_PTRA
));
2351 PrintStructures
->lpPrintDlg
= lppd
;
2353 /* and create & process the dialog .
2354 * -1 is failure, 0 is broken hwnd, everything else is ok.
2356 hInst
= COMDLG32_hInstance
;
2357 if (lppd
->Flags
& (PD_ENABLESETUPTEMPLATE
| PD_ENABLEPRINTTEMPLATE
)) hInst
= lppd
->hInstance
;
2358 bRet
= (0<DialogBoxIndirectParamA(hInst
, ptr
, lppd
->hwndOwner
,
2360 (LPARAM
)PrintStructures
));
2363 DEVMODEA
*lpdm
= PrintStructures
->lpDevMode
, *lpdmReturn
;
2364 PRINTER_INFO_2A
*pi
= PrintStructures
->lpPrinterInfo
;
2365 DRIVER_INFO_3A
*di
= PrintStructures
->lpDriverInfo
;
2367 if (lppd
->hDevMode
== 0) {
2368 TRACE(" No hDevMode yet... Need to create my own\n");
2369 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
,
2370 lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2372 lppd
->hDevMode
= GlobalReAlloc(lppd
->hDevMode
,
2373 lpdm
->dmSize
+ lpdm
->dmDriverExtra
,
2376 lpdmReturn
= GlobalLock(lppd
->hDevMode
);
2377 memcpy(lpdmReturn
, lpdm
, lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2379 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
2384 GlobalUnlock(lppd
->hDevMode
);
2386 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
2387 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpPrinterInfo
);
2388 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDriverInfo
);
2389 HeapFree(GetProcessHeap(), 0, PrintStructures
);
2391 if(bRet
&& (lppd
->Flags
& PD_RETURNDC
|| lppd
->Flags
& PD_RETURNIC
))
2392 bRet
= PRINTDLG_CreateDCA(lppd
);
2394 TRACE("exit! (%d)\n", bRet
);
2398 /***********************************************************************
2399 * PrintDlgW (COMDLG32.@)
2403 BOOL WINAPI
PrintDlgW(LPPRINTDLGW lppd
)
2411 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
2415 if(TRACE_ON(commdlg
)) {
2416 char flagstr
[1000] = "";
2417 const struct pd_flags
*pflag
= pd_flags
;
2418 for( ; pflag
->name
; pflag
++) {
2419 if(lppd
->Flags
& pflag
->flag
)
2420 strcat(flagstr
, pflag
->name
);
2422 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2423 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2424 "flags %08x (%s)\n",
2425 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
2426 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
2427 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
2430 if(lppd
->lStructSize
!= sizeof(PRINTDLGW
)) {
2431 WARN("structure size failure!!!\n");
2432 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
2436 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
2437 PRINTER_INFO_2W
*pbuf
;
2438 DRIVER_INFO_3W
*dbuf
;
2442 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
2443 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2444 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2447 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
2448 WARN("Can't find default printer\n");
2449 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
2453 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
2454 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
2455 GetPrinterW(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
2457 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
2458 dbuf
= HeapAlloc(GetProcessHeap(),0,needed
);
2459 if (!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
2460 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2461 GetLastError(),debugstr_w(pbuf
->pPrinterName
));
2462 HeapFree(GetProcessHeap(), 0, dbuf
);
2463 HeapFree(GetProcessHeap(), 0, pbuf
);
2464 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2469 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
2473 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
2474 pbuf
->pDevMode
->dmDriverExtra
);
2475 ptr
= GlobalLock(lppd
->hDevMode
);
2476 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
2477 pbuf
->pDevMode
->dmDriverExtra
);
2478 GlobalUnlock(lppd
->hDevMode
);
2479 HeapFree(GetProcessHeap(), 0, pbuf
);
2480 HeapFree(GetProcessHeap(), 0, dbuf
);
2484 PRINT_PTRW
*PrintStructures
;
2486 /* load Dialog resources,
2487 * depending on Flags indicates Print32 or Print32_setup dialog
2489 hDlgTmpl
= PRINTDLG_GetDlgTemplateW(lppd
);
2491 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2494 ptr
= LockResource( hDlgTmpl
);
2496 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2500 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2501 sizeof(PRINT_PTRW
));
2502 PrintStructures
->lpPrintDlg
= lppd
;
2504 /* and create & process the dialog .
2505 * -1 is failure, 0 is broken hwnd, everything else is ok.
2507 hInst
= COMDLG32_hInstance
;
2508 if (lppd
->Flags
& (PD_ENABLESETUPTEMPLATE
| PD_ENABLEPRINTTEMPLATE
)) hInst
= lppd
->hInstance
;
2509 bRet
= (0<DialogBoxIndirectParamW(hInst
, ptr
, lppd
->hwndOwner
,
2511 (LPARAM
)PrintStructures
));
2514 DEVMODEW
*lpdm
= PrintStructures
->lpDevMode
, *lpdmReturn
;
2515 PRINTER_INFO_2W
*pi
= PrintStructures
->lpPrinterInfo
;
2516 DRIVER_INFO_3W
*di
= PrintStructures
->lpDriverInfo
;
2518 if (lppd
->hDevMode
== 0) {
2519 TRACE(" No hDevMode yet... Need to create my own\n");
2520 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
,
2521 lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2524 if((locks
= (GlobalFlags(lppd
->hDevMode
) & GMEM_LOCKCOUNT
))) {
2525 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks
);
2527 GlobalUnlock(lppd
->hDevMode
);
2528 TRACE("Now got %d locks\n", locks
);
2531 lppd
->hDevMode
= GlobalReAlloc(lppd
->hDevMode
,
2532 lpdm
->dmSize
+ lpdm
->dmDriverExtra
,
2535 lpdmReturn
= GlobalLock(lppd
->hDevMode
);
2536 memcpy(lpdmReturn
, lpdm
, lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2538 if (lppd
->hDevNames
!= 0) {
2540 if((locks
= (GlobalFlags(lppd
->hDevNames
) & GMEM_LOCKCOUNT
))) {
2541 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks
);
2543 GlobalUnlock(lppd
->hDevNames
);
2546 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
2551 GlobalUnlock(lppd
->hDevMode
);
2553 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
2554 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpPrinterInfo
);
2555 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDriverInfo
);
2556 HeapFree(GetProcessHeap(), 0, PrintStructures
);
2558 if(bRet
&& (lppd
->Flags
& PD_RETURNDC
|| lppd
->Flags
& PD_RETURNIC
))
2559 bRet
= PRINTDLG_CreateDCW(lppd
);
2561 TRACE("exit! (%d)\n", bRet
);
2565 /***********************************************************************
2570 * cmb1 - printer select (not in standard dialog template)
2572 * cmb3 - source (tray?)
2573 * edt4 - border left
2575 * edt6 - border right
2576 * edt7 - border bottom
2577 * psh3 - "Printer..."
2585 LPPAGESETUPDLGA dlga
;
2586 LPPAGESETUPDLGW dlgw
;
2588 HWND hDlg
; /* Page Setup dialog handle */
2589 RECT rtDrawRect
; /* Drawing rect for page */
2592 static inline DWORD
pagesetup_get_flags(const pagesetup_data
*data
)
2594 return data
->u
.dlgw
->Flags
;
2597 static inline BOOL
is_metric(const pagesetup_data
*data
)
2599 return pagesetup_get_flags(data
) & PSD_INHUNDREDTHSOFMILLIMETERS
;
2602 static inline LONG
tenths_mm_to_size(const pagesetup_data
*data
, LONG size
)
2604 if (is_metric(data
))
2607 return 10 * size
* 100 / 254;
2610 static inline LONG
thousandths_inch_to_size(const pagesetup_data
*data
, LONG size
)
2612 if (is_metric(data
))
2613 return size
* 254 / 100;
2618 static WCHAR
get_decimal_sep(void)
2624 WCHAR buf
[] = {'.', 0};
2625 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SDECIMAL
, buf
, ARRAY_SIZE(buf
));
2631 static void size2str(const pagesetup_data
*data
, DWORD size
, LPWSTR strout
)
2633 static const WCHAR integer_fmt
[] = {'%','d',0};
2634 static const WCHAR hundredths_fmt
[] = {'%','d','%','c','%','0','2','d',0};
2635 static const WCHAR thousandths_fmt
[] = {'%','d','%','c','%','0','3','d',0};
2637 /* FIXME use LOCALE_SDECIMAL when the edit parsing code can cope */
2639 if (is_metric(data
))
2642 wsprintfW(strout
, hundredths_fmt
, size
/ 100, get_decimal_sep(), size
% 100);
2644 wsprintfW(strout
, integer_fmt
, size
/ 100);
2649 wsprintfW(strout
, thousandths_fmt
, size
/ 1000, get_decimal_sep(), size
% 1000);
2651 wsprintfW(strout
, integer_fmt
, size
/ 1000);
2656 static inline BOOL
is_default_metric(void)
2659 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_IMEASURE
| LOCALE_RETURN_NUMBER
,
2660 (LPWSTR
)&system
, sizeof(system
));
2664 /**********************************************
2666 * Cyclically permute the four members of rc
2667 * If sense is TRUE l -> t -> r -> b
2668 * otherwise l <- t <- r <- b
2670 static inline void rotate_rect(RECT
*rc
, BOOL sense
)
2676 rc
->bottom
= rc
->right
;
2677 rc
->right
= rc
->top
;
2685 rc
->top
= rc
->right
;
2686 rc
->right
= rc
->bottom
;
2691 static void pagesetup_set_orientation(pagesetup_data
*data
, WORD orient
)
2693 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2695 assert(orient
== DMORIENT_PORTRAIT
|| orient
== DMORIENT_LANDSCAPE
);
2698 dm
->u1
.s1
.dmOrientation
= orient
;
2701 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2702 dmA
->u1
.s1
.dmOrientation
= orient
;
2704 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2707 static WORD
pagesetup_get_orientation(const pagesetup_data
*data
)
2709 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2713 orient
= dm
->u1
.s1
.dmOrientation
;
2716 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2717 orient
= dmA
->u1
.s1
.dmOrientation
;
2719 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2723 static void pagesetup_set_papersize(pagesetup_data
*data
, WORD paper
)
2725 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2728 dm
->u1
.s1
.dmPaperSize
= paper
;
2731 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2732 dmA
->u1
.s1
.dmPaperSize
= paper
;
2734 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2737 static WORD
pagesetup_get_papersize(const pagesetup_data
*data
)
2739 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2743 paper
= dm
->u1
.s1
.dmPaperSize
;
2746 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2747 paper
= dmA
->u1
.s1
.dmPaperSize
;
2749 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2753 static void pagesetup_set_defaultsource(pagesetup_data
*data
, WORD source
)
2755 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2758 dm
->u1
.s1
.dmDefaultSource
= source
;
2761 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2762 dmA
->u1
.s1
.dmDefaultSource
= source
;
2764 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2769 devnames_driver_name
,
2770 devnames_device_name
,
2771 devnames_output_name
2775 static inline WORD
get_devname_offset(const DEVNAMES
*dn
, devnames_name which
)
2779 case devnames_driver_name
: return dn
->wDriverOffset
;
2780 case devnames_device_name
: return dn
->wDeviceOffset
;
2781 case devnames_output_name
: return dn
->wOutputOffset
;
2783 ERR("Shouldn't be here\n");
2787 static WCHAR
*pagesetup_get_a_devname(const pagesetup_data
*data
, devnames_name which
)
2792 dn
= GlobalLock(data
->u
.dlgw
->hDevNames
);
2794 name
= strdupW((WCHAR
*)dn
+ get_devname_offset(dn
, which
));
2797 int len
= MultiByteToWideChar(CP_ACP
, 0, (char*)dn
+ get_devname_offset(dn
, which
), -1, NULL
, 0);
2798 name
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
2799 MultiByteToWideChar(CP_ACP
, 0, (char*)dn
+ get_devname_offset(dn
, which
), -1, name
, len
);
2801 GlobalUnlock(data
->u
.dlgw
->hDevNames
);
2805 static WCHAR
*pagesetup_get_drvname(const pagesetup_data
*data
)
2807 return pagesetup_get_a_devname(data
, devnames_driver_name
);
2810 static WCHAR
*pagesetup_get_devname(const pagesetup_data
*data
)
2812 return pagesetup_get_a_devname(data
, devnames_device_name
);
2815 static WCHAR
*pagesetup_get_portname(const pagesetup_data
*data
)
2817 return pagesetup_get_a_devname(data
, devnames_output_name
);
2820 static void pagesetup_release_a_devname(const pagesetup_data
*data
, WCHAR
*name
)
2822 HeapFree(GetProcessHeap(), 0, name
);
2825 static void pagesetup_set_devnames(pagesetup_data
*data
, LPCWSTR drv
, LPCWSTR devname
, LPCWSTR port
)
2829 DWORD len
= sizeof(DEVNAMES
), drv_len
, dev_len
, port_len
;
2833 drv_len
= (lstrlenW(drv
) + 1) * sizeof(WCHAR
);
2834 dev_len
= (lstrlenW(devname
) + 1) * sizeof(WCHAR
);
2835 port_len
= (lstrlenW(port
) + 1) * sizeof(WCHAR
);
2839 drv_len
= WideCharToMultiByte(CP_ACP
, 0, drv
, -1, NULL
, 0, NULL
, NULL
);
2840 dev_len
= WideCharToMultiByte(CP_ACP
, 0, devname
, -1, NULL
, 0, NULL
, NULL
);
2841 port_len
= WideCharToMultiByte(CP_ACP
, 0, port
, -1, NULL
, 0, NULL
, NULL
);
2843 len
+= drv_len
+ dev_len
+ port_len
;
2845 if(data
->u
.dlgw
->hDevNames
)
2846 data
->u
.dlgw
->hDevNames
= GlobalReAlloc(data
->u
.dlgw
->hDevNames
, len
, GMEM_MOVEABLE
);
2848 data
->u
.dlgw
->hDevNames
= GlobalAlloc(GMEM_MOVEABLE
, len
);
2850 dn
= GlobalLock(data
->u
.dlgw
->hDevNames
);
2854 WCHAR
*ptr
= (WCHAR
*)(dn
+ 1);
2855 len
= sizeof(DEVNAMES
) / sizeof(WCHAR
);
2856 dn
->wDriverOffset
= len
;
2858 ptr
+= drv_len
/ sizeof(WCHAR
);
2859 len
+= drv_len
/ sizeof(WCHAR
);
2860 dn
->wDeviceOffset
= len
;
2861 lstrcpyW(ptr
, devname
);
2862 ptr
+= dev_len
/ sizeof(WCHAR
);
2863 len
+= dev_len
/ sizeof(WCHAR
);
2864 dn
->wOutputOffset
= len
;
2865 lstrcpyW(ptr
, port
);
2869 char *ptr
= (char *)(dn
+ 1);
2870 len
= sizeof(DEVNAMES
);
2871 dn
->wDriverOffset
= len
;
2872 WideCharToMultiByte(CP_ACP
, 0, drv
, -1, ptr
, drv_len
, NULL
, NULL
);
2875 dn
->wDeviceOffset
= len
;
2876 WideCharToMultiByte(CP_ACP
, 0, devname
, -1, ptr
, dev_len
, NULL
, NULL
);
2879 dn
->wOutputOffset
= len
;
2880 WideCharToMultiByte(CP_ACP
, 0, port
, -1, ptr
, port_len
, NULL
, NULL
);
2884 len
= ARRAY_SIZE(def
);
2885 GetDefaultPrinterW(def
, &len
);
2886 if(!lstrcmpW(def
, devname
))
2889 GlobalUnlock(data
->u
.dlgw
->hDevNames
);
2892 static DEVMODEW
*pagesetup_get_devmode(const pagesetup_data
*data
)
2894 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2899 /* We make a copy even in the unicode case because the ptr
2900 may get passed back to us in pagesetup_set_devmode. */
2901 ret
= HeapAlloc(GetProcessHeap(), 0, dm
->dmSize
+ dm
->dmDriverExtra
);
2902 memcpy(ret
, dm
, dm
->dmSize
+ dm
->dmDriverExtra
);
2905 ret
= GdiConvertToDevmodeW((DEVMODEA
*)dm
);
2907 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2911 static void pagesetup_release_devmode(const pagesetup_data
*data
, DEVMODEW
*dm
)
2913 HeapFree(GetProcessHeap(), 0, dm
);
2916 static void pagesetup_set_devmode(pagesetup_data
*data
, DEVMODEW
*dm
)
2918 DEVMODEA
*dmA
= NULL
;
2924 size
= dm
->dmSize
+ dm
->dmDriverExtra
;
2929 dmA
= convert_to_devmodeA(dm
);
2930 size
= dmA
->dmSize
+ dmA
->dmDriverExtra
;
2934 if(data
->u
.dlgw
->hDevMode
)
2935 data
->u
.dlgw
->hDevMode
= GlobalReAlloc(data
->u
.dlgw
->hDevMode
, size
,
2938 data
->u
.dlgw
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, size
);
2940 dst
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2941 memcpy(dst
, src
, size
);
2942 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2943 HeapFree(GetProcessHeap(), 0, dmA
);
2946 static inline POINT
*pagesetup_get_papersize_pt(const pagesetup_data
*data
)
2948 return &data
->u
.dlgw
->ptPaperSize
;
2951 static inline RECT
*pagesetup_get_margin_rect(const pagesetup_data
*data
)
2953 return &data
->u
.dlgw
->rtMargin
;
2962 static inline LPPAGESETUPHOOK
pagesetup_get_hook(const pagesetup_data
*data
, hook_type which
)
2966 case page_setup_hook
: return data
->u
.dlgw
->lpfnPageSetupHook
;
2967 case page_paint_hook
: return data
->u
.dlgw
->lpfnPagePaintHook
;
2972 /* This should only be used in calls to hook procs so we return the ptr
2973 already cast to LPARAM */
2974 static inline LPARAM
pagesetup_get_dlg_struct(const pagesetup_data
*data
)
2976 return (LPARAM
)data
->u
.dlgw
;
2979 static inline void swap_point(POINT
*pt
)
2986 static BOOL
pagesetup_update_papersize(pagesetup_data
*data
)
2989 LPWSTR devname
, portname
;
2991 WORD
*words
= NULL
, paperword
;
2992 POINT
*points
= NULL
;
2993 BOOL retval
= FALSE
;
2995 dm
= pagesetup_get_devmode(data
);
2996 devname
= pagesetup_get_devname(data
);
2997 portname
= pagesetup_get_portname(data
);
2999 num
= DeviceCapabilitiesW(devname
, portname
, DC_PAPERS
, NULL
, dm
);
3002 FIXME("No papernames found for %s/%s\n", debugstr_w(devname
), debugstr_w(portname
));
3006 words
= HeapAlloc(GetProcessHeap(), 0, num
* sizeof(WORD
));
3007 points
= HeapAlloc(GetProcessHeap(), 0, num
* sizeof(POINT
));
3009 if (num
!= DeviceCapabilitiesW(devname
, portname
, DC_PAPERS
, (LPWSTR
)words
, dm
))
3011 FIXME("Number of returned words is not %d\n", num
);
3015 if (num
!= DeviceCapabilitiesW(devname
, portname
, DC_PAPERSIZE
, (LPWSTR
)points
, dm
))
3017 FIXME("Number of returned sizes is not %d\n", num
);
3021 paperword
= pagesetup_get_papersize(data
);
3023 for (i
= 0; i
< num
; i
++)
3024 if (words
[i
] == paperword
)
3029 FIXME("Papersize %d not found in list?\n", paperword
);
3033 /* this is _10ths_ of a millimeter */
3034 pagesetup_get_papersize_pt(data
)->x
= tenths_mm_to_size(data
, points
[i
].x
);
3035 pagesetup_get_papersize_pt(data
)->y
= tenths_mm_to_size(data
, points
[i
].y
);
3037 if(pagesetup_get_orientation(data
) == DMORIENT_LANDSCAPE
)
3038 swap_point(pagesetup_get_papersize_pt(data
));
3043 HeapFree(GetProcessHeap(), 0, words
);
3044 HeapFree(GetProcessHeap(), 0, points
);
3045 pagesetup_release_a_devname(data
, portname
);
3046 pagesetup_release_a_devname(data
, devname
);
3047 pagesetup_release_devmode(data
, dm
);
3052 /**********************************************************************************************
3053 * pagesetup_change_printer
3055 * Redefines hDevMode and hDevNames HANDLES and initialises it.
3058 static BOOL
pagesetup_change_printer(LPWSTR name
, pagesetup_data
*data
)
3062 PRINTER_INFO_2W
*prn_info
= NULL
;
3063 DRIVER_INFO_3W
*drv_info
= NULL
;
3064 DEVMODEW
*dm
= NULL
;
3065 BOOL retval
= FALSE
;
3067 if(!OpenPrinterW(name
, &hprn
, NULL
))
3069 ERR("Can't open printer %s\n", debugstr_w(name
));
3073 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
3074 prn_info
= HeapAlloc(GetProcessHeap(), 0, needed
);
3075 GetPrinterW(hprn
, 2, (LPBYTE
)prn_info
, needed
, &needed
);
3076 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
3077 drv_info
= HeapAlloc(GetProcessHeap(), 0, needed
);
3078 if(!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)drv_info
, needed
, &needed
))
3080 ERR("GetPrinterDriverA failed for %s, fix your config!\n", debugstr_w(prn_info
->pPrinterName
));
3085 needed
= DocumentPropertiesW(0, 0, name
, NULL
, NULL
, 0);
3088 ERR("DocumentProperties fails on %s\n", debugstr_w(name
));
3092 dm
= HeapAlloc(GetProcessHeap(), 0, needed
);
3093 DocumentPropertiesW(0, 0, name
, dm
, NULL
, DM_OUT_BUFFER
);
3095 pagesetup_set_devmode(data
, dm
);
3096 pagesetup_set_devnames(data
, drv_info
->pDriverPath
, prn_info
->pPrinterName
,
3097 prn_info
->pPortName
);
3101 HeapFree(GetProcessHeap(), 0, dm
);
3102 HeapFree(GetProcessHeap(), 0, prn_info
);
3103 HeapFree(GetProcessHeap(), 0, drv_info
);
3107 /****************************************************************************************
3108 * pagesetup_init_combos
3110 * Fills Printers, Paper and Source combos
3113 static void pagesetup_init_combos(HWND hDlg
, pagesetup_data
*data
)
3116 LPWSTR devname
, portname
;
3118 dm
= pagesetup_get_devmode(data
);
3119 devname
= pagesetup_get_devname(data
);
3120 portname
= pagesetup_get_portname(data
);
3122 PRINTDLG_SetUpPrinterListComboW(hDlg
, cmb1
, devname
);
3123 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb2
, devname
, portname
, dm
);
3124 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb3
, devname
, portname
, dm
);
3126 pagesetup_release_a_devname(data
, portname
);
3127 pagesetup_release_a_devname(data
, devname
);
3128 pagesetup_release_devmode(data
, dm
);
3132 /****************************************************************************************
3133 * pagesetup_change_printer_dialog
3135 * Pops up another dialog that lets the user pick another printer.
3137 * For now we display the PrintDlg, this should display a striped down version of it.
3139 static void pagesetup_change_printer_dialog(HWND hDlg
, pagesetup_data
*data
)
3142 LPWSTR drvname
, devname
, portname
;
3143 DEVMODEW
*tmp_dm
, *dm
;
3145 memset(&prnt
, 0, sizeof(prnt
));
3146 prnt
.lStructSize
= sizeof(prnt
);
3148 prnt
.hwndOwner
= hDlg
;
3150 drvname
= pagesetup_get_drvname(data
);
3151 devname
= pagesetup_get_devname(data
);
3152 portname
= pagesetup_get_portname(data
);
3154 PRINTDLG_CreateDevNamesW(&prnt
.hDevNames
, drvname
, devname
, portname
);
3155 pagesetup_release_a_devname(data
, portname
);
3156 pagesetup_release_a_devname(data
, devname
);
3157 pagesetup_release_a_devname(data
, drvname
);
3159 tmp_dm
= pagesetup_get_devmode(data
);
3160 prnt
.hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, tmp_dm
->dmSize
+ tmp_dm
->dmDriverExtra
);
3161 dm
= GlobalLock(prnt
.hDevMode
);
3162 memcpy(dm
, tmp_dm
, tmp_dm
->dmSize
+ tmp_dm
->dmDriverExtra
);
3163 GlobalUnlock(prnt
.hDevMode
);
3164 pagesetup_release_devmode(data
, tmp_dm
);
3166 if (PrintDlgW(&prnt
))
3168 DEVMODEW
*dm
= GlobalLock(prnt
.hDevMode
);
3169 DEVNAMES
*dn
= GlobalLock(prnt
.hDevNames
);
3171 pagesetup_set_devnames(data
, (WCHAR
*)dn
+ dn
->wDriverOffset
,
3172 (WCHAR
*)dn
+ dn
->wDeviceOffset
, (WCHAR
*)dn
+ dn
->wOutputOffset
);
3173 pagesetup_set_devmode(data
, dm
);
3174 GlobalUnlock(prnt
.hDevNames
);
3175 GlobalUnlock(prnt
.hDevMode
);
3176 pagesetup_init_combos(hDlg
, data
);
3179 GlobalFree(prnt
.hDevMode
);
3180 GlobalFree(prnt
.hDevNames
);
3184 /******************************************************************************************
3185 * pagesetup_change_preview
3187 * Changes paper preview size / position
3190 static void pagesetup_change_preview(const pagesetup_data
*data
)
3192 LONG width
, height
, x
, y
;
3194 const int shadow
= 4;
3196 if(pagesetup_get_orientation(data
) == DMORIENT_LANDSCAPE
)
3198 width
= data
->rtDrawRect
.right
- data
->rtDrawRect
.left
;
3199 height
= pagesetup_get_papersize_pt(data
)->y
* width
/ pagesetup_get_papersize_pt(data
)->x
;
3203 height
= data
->rtDrawRect
.bottom
- data
->rtDrawRect
.top
;
3204 width
= pagesetup_get_papersize_pt(data
)->x
* height
/ pagesetup_get_papersize_pt(data
)->y
;
3206 x
= (data
->rtDrawRect
.right
+ data
->rtDrawRect
.left
- width
) / 2;
3207 y
= (data
->rtDrawRect
.bottom
+ data
->rtDrawRect
.top
- height
) / 2;
3208 TRACE("draw rect %s x=%d, y=%d, w=%d, h=%d\n",
3209 wine_dbgstr_rect(&data
->rtDrawRect
), x
, y
, width
, height
);
3211 MoveWindow(GetDlgItem(data
->hDlg
, rct2
), x
+ width
, y
+ shadow
, shadow
, height
, FALSE
);
3212 MoveWindow(GetDlgItem(data
->hDlg
, rct3
), x
+ shadow
, y
+ height
, width
, shadow
, FALSE
);
3213 MoveWindow(GetDlgItem(data
->hDlg
, rct1
), x
, y
, width
, height
, FALSE
);
3215 tmp
= data
->rtDrawRect
;
3216 tmp
.right
+= shadow
;
3217 tmp
.bottom
+= shadow
;
3218 InvalidateRect(data
->hDlg
, &tmp
, TRUE
);
3221 static inline LONG
*element_from_margin_id(RECT
*rc
, WORD id
)
3225 case edt4
: return &rc
->left
;
3226 case edt5
: return &rc
->top
;
3227 case edt6
: return &rc
->right
;
3228 case edt7
: return &rc
->bottom
;
3233 static void update_margin_edits(HWND hDlg
, const pagesetup_data
*data
, WORD id
)
3238 for(idx
= edt4
; idx
<= edt7
; idx
++)
3240 if(id
== 0 || id
== idx
)
3242 size2str(data
, *element_from_margin_id(pagesetup_get_margin_rect(data
), idx
), str
);
3243 SetDlgItemTextW(hDlg
, idx
, str
);
3248 static void margin_edit_notification(HWND hDlg
, const pagesetup_data
*data
, WORD msg
, WORD id
)
3256 LONG
*value
= element_from_margin_id(pagesetup_get_margin_rect(data
), id
);
3258 if (GetDlgItemTextW(hDlg
, id
, buf
, ARRAY_SIZE(buf
)) != 0)
3261 WCHAR decimal
= get_decimal_sep();
3263 val
= wcstol(buf
, &end
, 10);
3264 if(end
!= buf
|| *end
== decimal
)
3266 int mult
= is_metric(data
) ? 100 : 1000;
3275 val
+= (*end
- '0') * mult
;
3287 update_margin_edits(hDlg
, data
, id
);
3292 static void set_margin_groupbox_title(HWND hDlg
, const pagesetup_data
*data
)
3296 if(LoadStringW(COMDLG32_hInstance
, is_metric(data
) ? PD32_MARGINS_IN_MILLIMETERS
: PD32_MARGINS_IN_INCHES
,
3297 title
, ARRAY_SIZE(title
)))
3298 SetDlgItemTextW(hDlg
, grp4
, title
);
3301 static void pagesetup_update_orientation_buttons(HWND hDlg
, const pagesetup_data
*data
)
3303 if (pagesetup_get_orientation(data
) == DMORIENT_LANDSCAPE
)
3304 CheckRadioButton(hDlg
, rad1
, rad2
, rad2
);
3306 CheckRadioButton(hDlg
, rad1
, rad2
, rad1
);
3309 /****************************************************************************************
3310 * pagesetup_printer_properties
3312 * Handle invocation of the 'Properties' button (not present in the default template).
3314 static void pagesetup_printer_properties(HWND hDlg
, pagesetup_data
*data
)
3322 devname
= pagesetup_get_devname(data
);
3324 if (!OpenPrinterW(devname
, &hprn
, NULL
))
3326 FIXME("Call to OpenPrinter did not succeed!\n");
3327 pagesetup_release_a_devname(data
, devname
);
3331 dm
= pagesetup_get_devmode(data
);
3332 DocumentPropertiesW(hDlg
, hprn
, devname
, dm
, dm
, DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
3333 pagesetup_set_devmode(data
, dm
);
3334 pagesetup_release_devmode(data
, dm
);
3335 pagesetup_release_a_devname(data
, devname
);
3338 /* Changing paper */
3339 pagesetup_update_papersize(data
);
3340 pagesetup_update_orientation_buttons(hDlg
, data
);
3342 /* Changing paper preview */
3343 pagesetup_change_preview(data
);
3345 /* Selecting paper in combo */
3346 count
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCOUNT
, 0, 0);
3349 WORD paperword
= pagesetup_get_papersize(data
);
3350 for(i
= 0; i
< count
; i
++)
3352 if(SendDlgItemMessageW(hDlg
, cmb2
, CB_GETITEMDATA
, i
, 0) == paperword
) {
3353 SendDlgItemMessageW(hDlg
, cmb2
, CB_SETCURSEL
, i
, 0);
3360 /********************************************************************************
3361 * pagesetup_wm_command
3362 * process WM_COMMAND message for PageSetupDlg
3365 * hDlg [in] Main dialog HANDLE
3366 * wParam [in] WM_COMMAND wParam
3367 * lParam [in] WM_COMMAND lParam
3368 * pda [in/out] ptr to PageSetupDataA
3371 static BOOL
pagesetup_wm_command(HWND hDlg
, WPARAM wParam
, LPARAM lParam
, pagesetup_data
*data
)
3373 WORD msg
= HIWORD(wParam
);
3374 WORD id
= LOWORD(wParam
);
3376 TRACE("loword (lparam) %d, wparam 0x%lx, lparam %08lx\n",
3377 LOWORD(lParam
),wParam
,lParam
);
3380 EndDialog(hDlg
, TRUE
);
3384 EndDialog(hDlg
, FALSE
);
3387 case psh3
: /* Printer... */
3388 pagesetup_change_printer_dialog(hDlg
, data
);
3391 case rad1
: /* Portrait */
3392 case rad2
: /* Landscape */
3393 if((id
== rad1
&& pagesetup_get_orientation(data
) == DMORIENT_LANDSCAPE
) ||
3394 (id
== rad2
&& pagesetup_get_orientation(data
) == DMORIENT_PORTRAIT
))
3396 pagesetup_set_orientation(data
, (id
== rad1
) ? DMORIENT_PORTRAIT
: DMORIENT_LANDSCAPE
);
3397 pagesetup_update_papersize(data
);
3398 rotate_rect(pagesetup_get_margin_rect(data
), (id
== rad2
));
3399 update_margin_edits(hDlg
, data
, 0);
3400 pagesetup_change_preview(data
);
3403 case cmb1
: /* Printer combo */
3404 if(msg
== CBN_SELCHANGE
)
3407 INT index
= SendDlgItemMessageW(hDlg
, id
, CB_GETCURSEL
, 0, 0);
3408 INT length
= SendDlgItemMessageW(hDlg
, id
, CB_GETLBTEXTLEN
, index
, 0);
3409 name
= HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*(length
+1));
3410 SendDlgItemMessageW(hDlg
, id
, CB_GETLBTEXT
, index
, (LPARAM
)name
);
3411 pagesetup_change_printer(name
, data
);
3412 pagesetup_init_combos(hDlg
, data
);
3413 HeapFree(GetProcessHeap(),0,name
);
3416 case cmb2
: /* Paper combo */
3417 if(msg
== CBN_SELCHANGE
)
3419 DWORD paperword
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETITEMDATA
,
3420 SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0), 0);
3421 if (paperword
!= CB_ERR
)
3423 pagesetup_set_papersize(data
, paperword
);
3424 pagesetup_update_papersize(data
);
3425 pagesetup_change_preview(data
);
3427 FIXME("could not get dialog text for papersize cmbbox?\n");
3430 case cmb3
: /* Paper Source */
3431 if(msg
== CBN_SELCHANGE
)
3433 WORD source
= SendDlgItemMessageW(hDlg
, cmb3
, CB_GETITEMDATA
,
3434 SendDlgItemMessageW(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0), 0);
3435 pagesetup_set_defaultsource(data
, source
);
3438 case psh2
: /* Printer Properties button */
3439 pagesetup_printer_properties(hDlg
, data
);
3445 margin_edit_notification(hDlg
, data
, msg
, id
);
3448 InvalidateRect(GetDlgItem(hDlg
, rct1
), NULL
, TRUE
);
3452 /***********************************************************************
3453 * default_page_paint_hook
3454 * Default hook paint procedure that receives WM_PSD_* messages from the dialog box
3455 * whenever the sample page is redrawn.
3457 static UINT_PTR
default_page_paint_hook(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
,
3458 const pagesetup_data
*data
)
3460 LPRECT lprc
= (LPRECT
) lParam
;
3461 HDC hdc
= (HDC
) wParam
;
3464 HFONT hfont
, holdfont
;
3466 TRACE("uMsg: WM_USER+%d\n",uMsg
-WM_USER
);
3467 /* Call user paint hook if enable */
3468 if (pagesetup_get_flags(data
) & PSD_ENABLEPAGEPAINTHOOK
)
3469 if (pagesetup_get_hook(data
, page_paint_hook
)(hwndDlg
, uMsg
, wParam
, lParam
))
3473 /* LPPAGESETUPDLG in lParam */
3474 case WM_PSD_PAGESETUPDLG
:
3475 /* Inform about the sample page rectangle */
3476 case WM_PSD_FULLPAGERECT
:
3477 /* Inform about the margin rectangle */
3478 case WM_PSD_MINMARGINRECT
:
3481 /* Draw dashed rectangle showing margins */
3482 case WM_PSD_MARGINRECT
:
3483 hpen
= CreatePen(PS_DASH
, 1, GetSysColor(COLOR_3DSHADOW
));
3484 holdpen
= SelectObject(hdc
, hpen
);
3485 Rectangle(hdc
, lprc
->left
, lprc
->top
, lprc
->right
, lprc
->bottom
);
3486 DeleteObject(SelectObject(hdc
, holdpen
));
3488 /* Draw the fake document */
3489 case WM_PSD_GREEKTEXTRECT
:
3490 /* select a nice scalable font, because we want the text really small */
3491 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, sizeof(lf
), &lf
, 0);
3492 lf
.lfHeight
= 6; /* value chosen based on visual effect */
3493 hfont
= CreateFontIndirectW(&lf
);
3494 holdfont
= SelectObject(hdc
, hfont
);
3496 /* if text not loaded, then do so now */
3497 if (wszFakeDocumentText
[0] == '\0')
3498 LoadStringW(COMDLG32_hInstance
,
3500 wszFakeDocumentText
,
3501 ARRAY_SIZE(wszFakeDocumentText
));
3503 oldbkmode
= SetBkMode(hdc
, TRANSPARENT
);
3504 DrawTextW(hdc
, wszFakeDocumentText
, -1, lprc
, DT_TOP
|DT_LEFT
|DT_NOPREFIX
|DT_WORDBREAK
);
3505 SetBkMode(hdc
, oldbkmode
);
3507 DeleteObject(SelectObject(hdc
, holdfont
));
3510 /* Envelope stamp */
3511 case WM_PSD_ENVSTAMPRECT
:
3512 /* Return address */
3513 case WM_PSD_YAFULLPAGERECT
:
3514 FIXME("envelope/stamp is not implemented\n");
3517 FIXME("Unknown message %x\n",uMsg
);
3523 /***********************************************************************
3525 * The main paint procedure for the PageSetupDlg function.
3526 * The Page Setup dialog box includes an image of a sample page that shows how
3527 * the user's selections affect the appearance of the printed output.
3528 * The image consists of a rectangle that represents the selected paper
3529 * or envelope type, with a dotted-line rectangle representing
3530 * the current margins, and partial (Greek text) characters
3531 * to show how text looks on the printed page.
3533 * The following messages in the order sends to user hook procedure:
3534 * WM_PSD_PAGESETUPDLG Draw the contents of the sample page
3535 * WM_PSD_FULLPAGERECT Inform about the bounding rectangle
3536 * WM_PSD_MINMARGINRECT Inform about the margin rectangle (min margin?)
3537 * WM_PSD_MARGINRECT Draw the margin rectangle
3538 * WM_PSD_GREEKTEXTRECT Draw the Greek text inside the margin rectangle
3539 * If any of first three messages returns TRUE, painting done.
3542 * hWnd [in] Handle to the Page Setup dialog box
3543 * uMsg [in] Received message
3546 * WM_PSD_ENVSTAMPRECT Draw in the envelope-stamp rectangle (for envelopes only)
3547 * WM_PSD_YAFULLPAGERECT Draw the return address portion (for envelopes and other paper sizes)
3550 * FALSE if all done correctly
3555 static LRESULT CALLBACK
3556 PRINTDLG_PagePaintProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3559 RECT rcClient
, rcMargin
;
3562 HBRUSH hbrush
, holdbrush
;
3563 pagesetup_data
*data
;
3564 int papersize
=0, orientation
=0; /* FIXME: set these values for the user paint hook */
3565 double scalx
, scaly
;
3567 if (uMsg
!= WM_PAINT
)
3568 return CallWindowProcA(lpfnStaticWndProc
, hWnd
, uMsg
, wParam
, lParam
);
3570 /* Processing WM_PAINT message */
3571 data
= GetPropW(hWnd
, pagesetupdlg_prop
);
3573 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3576 if (default_page_paint_hook(hWnd
, WM_PSD_PAGESETUPDLG
, MAKELONG(papersize
, orientation
),
3577 pagesetup_get_dlg_struct(data
), data
))
3580 hdc
= BeginPaint(hWnd
, &ps
);
3581 GetClientRect(hWnd
, &rcClient
);
3583 scalx
= rcClient
.right
/ (double)pagesetup_get_papersize_pt(data
)->x
;
3584 scaly
= rcClient
.bottom
/ (double)pagesetup_get_papersize_pt(data
)->y
;
3585 rcMargin
= rcClient
;
3587 rcMargin
.left
+= pagesetup_get_margin_rect(data
)->left
* scalx
;
3588 rcMargin
.top
+= pagesetup_get_margin_rect(data
)->top
* scaly
;
3589 rcMargin
.right
-= pagesetup_get_margin_rect(data
)->right
* scalx
;
3590 rcMargin
.bottom
-= pagesetup_get_margin_rect(data
)->bottom
* scaly
;
3592 /* if the space is too small then we make sure to not draw anything */
3593 rcMargin
.left
= min(rcMargin
.left
, rcMargin
.right
);
3594 rcMargin
.top
= min(rcMargin
.top
, rcMargin
.bottom
);
3596 if (!default_page_paint_hook(hWnd
, WM_PSD_FULLPAGERECT
, (WPARAM
)hdc
, (LPARAM
)&rcClient
, data
) &&
3597 !default_page_paint_hook(hWnd
, WM_PSD_MINMARGINRECT
, (WPARAM
)hdc
, (LPARAM
)&rcMargin
, data
) )
3599 /* fill background */
3600 hbrush
= GetSysColorBrush(COLOR_3DHIGHLIGHT
);
3601 FillRect(hdc
, &rcClient
, hbrush
);
3602 holdbrush
= SelectObject(hdc
, hbrush
);
3604 hpen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DSHADOW
));
3605 holdpen
= SelectObject(hdc
, hpen
);
3607 /* paint left edge */
3608 MoveToEx(hdc
, rcClient
.left
, rcClient
.top
, NULL
);
3609 LineTo(hdc
, rcClient
.left
, rcClient
.bottom
-1);
3611 /* paint top edge */
3612 MoveToEx(hdc
, rcClient
.left
, rcClient
.top
, NULL
);
3613 LineTo(hdc
, rcClient
.right
, rcClient
.top
);
3615 hpen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DDKSHADOW
));
3616 DeleteObject(SelectObject(hdc
, hpen
));
3618 /* paint right edge */
3619 MoveToEx(hdc
, rcClient
.right
-1, rcClient
.top
, NULL
);
3620 LineTo(hdc
, rcClient
.right
-1, rcClient
.bottom
);
3622 /* paint bottom edge */
3623 MoveToEx(hdc
, rcClient
.left
, rcClient
.bottom
-1, NULL
);
3624 LineTo(hdc
, rcClient
.right
, rcClient
.bottom
-1);
3626 DeleteObject(SelectObject(hdc
, holdpen
));
3627 DeleteObject(SelectObject(hdc
, holdbrush
));
3629 default_page_paint_hook(hWnd
, WM_PSD_MARGINRECT
, (WPARAM
)hdc
, (LPARAM
)&rcMargin
, data
);
3631 /* give text a bit of a space from the frame */
3632 InflateRect(&rcMargin
, -2, -2);
3634 /* if the space is too small then we make sure to not draw anything */
3635 rcMargin
.left
= min(rcMargin
.left
, rcMargin
.right
);
3636 rcMargin
.top
= min(rcMargin
.top
, rcMargin
.bottom
);
3638 default_page_paint_hook(hWnd
, WM_PSD_GREEKTEXTRECT
, (WPARAM
)hdc
, (LPARAM
)&rcMargin
, data
);
3641 EndPaint(hWnd
, &ps
);
3645 /*******************************************************
3646 * The margin edit controls are subclassed to filter
3647 * anything other than numbers and the decimal separator.
3649 static LRESULT CALLBACK
pagesetup_margin_editproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3653 WCHAR decimal
= get_decimal_sep();
3654 WCHAR wc
= (WCHAR
)wparam
;
3655 if(!iswdigit(wc
) && wc
!= decimal
&& wc
!= VK_BACK
) return 0;
3657 return CallWindowProcW(edit_wndproc
, hwnd
, msg
, wparam
, lparam
);
3660 static void subclass_margin_edits(HWND hDlg
)
3665 for(id
= edt4
; id
<= edt7
; id
++)
3667 old_proc
= (WNDPROC
)SetWindowLongPtrW(GetDlgItem(hDlg
, id
),
3669 (ULONG_PTR
)pagesetup_margin_editproc
);
3670 InterlockedCompareExchangePointer((void**)&edit_wndproc
, old_proc
, NULL
);
3674 /***********************************************************************
3675 * pagesetup_dlg_proc
3677 * Message handler for PageSetupDlg
3679 static INT_PTR CALLBACK
pagesetup_dlg_proc(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3681 pagesetup_data
*data
;
3682 INT_PTR res
= FALSE
;
3685 if (uMsg
== WM_INITDIALOG
) { /*Init dialog*/
3686 data
= (pagesetup_data
*)lParam
;
3689 hDrawWnd
= GetDlgItem(hDlg
, rct1
);
3690 TRACE("set property to %p\n", data
);
3691 SetPropW(hDlg
, pagesetupdlg_prop
, data
);
3692 SetPropW(hDrawWnd
, pagesetupdlg_prop
, data
);
3693 GetWindowRect(hDrawWnd
, &data
->rtDrawRect
); /* Calculating rect in client coordinates where paper draws */
3694 MapWindowPoints( 0, hDlg
, (LPPOINT
)&data
->rtDrawRect
, 2 );
3695 lpfnStaticWndProc
= (WNDPROC
)SetWindowLongPtrW(
3698 (ULONG_PTR
)PRINTDLG_PagePaintProc
);
3700 /* FIXME: Paint hook. Must it be at begin of initialization or at end? */
3702 if (pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPHOOK
)
3704 if (!pagesetup_get_hook(data
, page_setup_hook
)(hDlg
, uMsg
, wParam
,
3705 pagesetup_get_dlg_struct(data
)))
3706 FIXME("Setup page hook failed?\n");
3709 /* if printer button disabled */
3710 if (pagesetup_get_flags(data
) & PSD_DISABLEPRINTER
)
3711 EnableWindow(GetDlgItem(hDlg
, psh3
), FALSE
);
3712 /* if margin edit boxes disabled */
3713 if (pagesetup_get_flags(data
) & PSD_DISABLEMARGINS
)
3715 EnableWindow(GetDlgItem(hDlg
, edt4
), FALSE
);
3716 EnableWindow(GetDlgItem(hDlg
, edt5
), FALSE
);
3717 EnableWindow(GetDlgItem(hDlg
, edt6
), FALSE
);
3718 EnableWindow(GetDlgItem(hDlg
, edt7
), FALSE
);
3721 /* Set orientation radiobuttons properly */
3722 pagesetup_update_orientation_buttons(hDlg
, data
);
3724 /* if orientation disabled */
3725 if (pagesetup_get_flags(data
) & PSD_DISABLEORIENTATION
)
3727 EnableWindow(GetDlgItem(hDlg
,rad1
),FALSE
);
3728 EnableWindow(GetDlgItem(hDlg
,rad2
),FALSE
);
3731 /* We fill them out enabled or not */
3732 if (!(pagesetup_get_flags(data
) & PSD_MARGINS
))
3734 /* default is 1 inch */
3735 LONG size
= thousandths_inch_to_size(data
, 1000);
3736 SetRect(pagesetup_get_margin_rect(data
), size
, size
, size
, size
);
3738 update_margin_edits(hDlg
, data
, 0);
3739 subclass_margin_edits(hDlg
);
3740 set_margin_groupbox_title(hDlg
, data
);
3742 /* if paper disabled */
3743 if (pagesetup_get_flags(data
) & PSD_DISABLEPAPER
)
3745 EnableWindow(GetDlgItem(hDlg
,cmb2
),FALSE
);
3746 EnableWindow(GetDlgItem(hDlg
,cmb3
),FALSE
);
3749 /* filling combos: printer, paper, source. selecting current printer (from DEVMODEA) */
3750 pagesetup_init_combos(hDlg
, data
);
3751 pagesetup_update_papersize(data
);
3752 pagesetup_set_defaultsource(data
, DMBIN_FORMSOURCE
); /* FIXME: This is the auto select bin. Is this correct? */
3754 /* Drawing paper prev */
3755 pagesetup_change_preview(data
);
3758 data
= GetPropW(hDlg
, pagesetupdlg_prop
);
3761 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3764 if (pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPHOOK
)
3766 res
= pagesetup_get_hook(data
, page_setup_hook
)(hDlg
, uMsg
, wParam
, lParam
);
3767 if (res
) return res
;
3772 return pagesetup_wm_command(hDlg
, wParam
, lParam
, data
);
3777 static WCHAR
*get_default_printer(void)
3782 GetDefaultPrinterW(NULL
, &len
);
3785 name
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3786 GetDefaultPrinterW(name
, &len
);
3791 static void pagesetup_dump_dlg_struct(const pagesetup_data
*data
)
3793 if(TRACE_ON(commdlg
))
3795 char flagstr
[1000] = "";
3796 const struct pd_flags
*pflag
= psd_flags
;
3797 for( ; pflag
->name
; pflag
++)
3799 if(pagesetup_get_flags(data
) & pflag
->flag
)
3801 strcat(flagstr
, pflag
->name
);
3802 strcat(flagstr
, "|");
3805 TRACE("%s: (%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3806 "hinst %p, flags %08x (%s)\n",
3807 data
->unicode
? "unicode" : "ansi",
3808 data
->u
.dlgw
, data
->u
.dlgw
->hwndOwner
, data
->u
.dlgw
->hDevMode
,
3809 data
->u
.dlgw
->hDevNames
, data
->u
.dlgw
->hInstance
,
3810 pagesetup_get_flags(data
), flagstr
);
3814 static void *pagesetup_get_template(pagesetup_data
*data
)
3817 HGLOBAL tmpl_handle
;
3819 if(pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPTEMPLATEHANDLE
)
3821 tmpl_handle
= data
->u
.dlgw
->hPageSetupTemplate
;
3823 else if(pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPTEMPLATE
)
3826 res
= FindResourceW(data
->u
.dlgw
->hInstance
,
3827 data
->u
.dlgw
->lpPageSetupTemplateName
, (LPWSTR
)RT_DIALOG
);
3829 res
= FindResourceA(data
->u
.dlga
->hInstance
,
3830 data
->u
.dlga
->lpPageSetupTemplateName
, (LPSTR
)RT_DIALOG
);
3831 tmpl_handle
= LoadResource(data
->u
.dlgw
->hInstance
, res
);
3835 res
= FindResourceW(COMDLG32_hInstance
, MAKEINTRESOURCEW(PAGESETUPDLGORD
),
3837 tmpl_handle
= LoadResource(COMDLG32_hInstance
, res
);
3839 return LockResource(tmpl_handle
);
3842 static BOOL
pagesetup_common(pagesetup_data
*data
)
3847 if(!pagesetup_get_dlg_struct(data
))
3849 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
3853 pagesetup_dump_dlg_struct(data
);
3855 if(data
->u
.dlgw
->lStructSize
!= sizeof(PAGESETUPDLGW
))
3857 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
3861 if ((pagesetup_get_flags(data
) & PSD_ENABLEPAGEPAINTHOOK
) &&
3862 (pagesetup_get_hook(data
, page_paint_hook
) == NULL
))
3864 COMDLG32_SetCommDlgExtendedError(CDERR_NOHOOK
);
3868 if(!(pagesetup_get_flags(data
) & (PSD_INTHOUSANDTHSOFINCHES
| PSD_INHUNDREDTHSOFMILLIMETERS
)))
3869 data
->u
.dlgw
->Flags
|= is_default_metric() ?
3870 PSD_INHUNDREDTHSOFMILLIMETERS
: PSD_INTHOUSANDTHSOFINCHES
;
3872 if (!data
->u
.dlgw
->hDevMode
|| !data
->u
.dlgw
->hDevNames
)
3874 WCHAR
*def
= get_default_printer();
3877 if (!(pagesetup_get_flags(data
) & PSD_NOWARNING
))
3880 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEFAULT_PRINTER
, errstr
, 255);
3881 MessageBoxW(data
->u
.dlgw
->hwndOwner
, errstr
, 0, MB_OK
| MB_ICONERROR
);
3883 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
3886 pagesetup_change_printer(def
, data
);
3887 HeapFree(GetProcessHeap(), 0, def
);
3890 if (pagesetup_get_flags(data
) & PSD_RETURNDEFAULT
)
3892 pagesetup_update_papersize(data
);
3896 tmpl
= pagesetup_get_template(data
);
3898 ret
= DialogBoxIndirectParamW(data
->u
.dlgw
->hInstance
, tmpl
,
3899 data
->u
.dlgw
->hwndOwner
,
3900 pagesetup_dlg_proc
, (LPARAM
)data
) > 0;
3904 /***********************************************************************
3905 * PageSetupDlgA (COMDLG32.@)
3907 * Displays the PAGE SETUP dialog box, which enables the user to specify
3908 * specific properties of a printed page such as
3909 * size, source, orientation and the width of the page margins.
3912 * setupdlg [IO] PAGESETUPDLGA struct
3915 * TRUE if the user pressed the OK button
3916 * FALSE if the user cancelled the window or an error occurred
3919 * The values of hDevMode and hDevNames are filled on output and can be
3920 * changed in PAGESETUPDLG when they are passed in PageSetupDlg.
3923 BOOL WINAPI
PageSetupDlgA(LPPAGESETUPDLGA setupdlg
)
3925 pagesetup_data data
;
3927 data
.unicode
= FALSE
;
3928 data
.u
.dlga
= setupdlg
;
3930 return pagesetup_common(&data
);
3933 /***********************************************************************
3934 * PageSetupDlgW (COMDLG32.@)
3936 * See PageSetupDlgA.
3938 BOOL WINAPI
PageSetupDlgW(LPPAGESETUPDLGW setupdlg
)
3940 pagesetup_data data
;
3942 data
.unicode
= TRUE
;
3943 data
.u
.dlgw
= setupdlg
;
3945 return pagesetup_common(&data
);
3948 static void pdlgex_to_pdlg(const PRINTDLGEXW
*pdlgex
, PRINTDLGW
*pdlg
)
3950 pdlg
->lStructSize
= sizeof(*pdlg
);
3951 pdlg
->hwndOwner
= pdlgex
->hwndOwner
;
3952 pdlg
->hDevMode
= pdlgex
->hDevMode
;
3953 pdlg
->hDevNames
= pdlgex
->hDevNames
;
3954 pdlg
->hDC
= pdlgex
->hDC
;
3955 pdlg
->Flags
= pdlgex
->Flags
;
3956 if ((pdlgex
->Flags
& PD_NOPAGENUMS
) || !pdlgex
->nPageRanges
|| !pdlgex
->lpPageRanges
)
3958 pdlg
->nFromPage
= 0;
3959 pdlg
->nToPage
= 65534;
3963 pdlg
->nFromPage
= pdlgex
->lpPageRanges
[0].nFromPage
;
3964 pdlg
->nToPage
= pdlgex
->lpPageRanges
[0].nToPage
;
3966 pdlg
->nMinPage
= pdlgex
->nMinPage
;
3967 pdlg
->nMaxPage
= pdlgex
->nMaxPage
;
3968 pdlg
->nCopies
= pdlgex
->nCopies
;
3969 pdlg
->hInstance
= pdlgex
->hInstance
;
3970 pdlg
->lCustData
= 0;
3971 pdlg
->lpfnPrintHook
= NULL
;
3972 pdlg
->lpfnSetupHook
= NULL
;
3973 pdlg
->lpPrintTemplateName
= pdlgex
->lpPrintTemplateName
;
3974 pdlg
->lpSetupTemplateName
= NULL
;
3975 pdlg
->hPrintTemplate
= NULL
;
3976 pdlg
->hSetupTemplate
= NULL
;
3979 /* Only copy fields that are supposed to be changed. */
3980 static void pdlg_to_pdlgex(const PRINTDLGW
*pdlg
, PRINTDLGEXW
*pdlgex
)
3982 pdlgex
->hDevMode
= pdlg
->hDevMode
;
3983 pdlgex
->hDevNames
= pdlg
->hDevNames
;
3984 pdlgex
->hDC
= pdlg
->hDC
;
3985 if (!(pdlgex
->Flags
& PD_NOPAGENUMS
) && pdlgex
->nPageRanges
&& pdlgex
->lpPageRanges
)
3987 pdlgex
->lpPageRanges
[0].nFromPage
= pdlg
->nFromPage
;
3988 pdlgex
->lpPageRanges
[0].nToPage
= pdlg
->nToPage
;
3990 pdlgex
->nMinPage
= pdlg
->nMinPage
;
3991 pdlgex
->nMaxPage
= pdlg
->nMaxPage
;
3992 pdlgex
->nCopies
= pdlg
->nCopies
;
3995 struct callback_data
3997 IPrintDialogCallback
*callback
;
3998 IObjectWithSite
*object
;
4001 static UINT_PTR CALLBACK
pdlgex_hook_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
4003 if (msg
== WM_INITDIALOG
)
4005 PRINTDLGW
*pd
= (PRINTDLGW
*)lp
;
4006 struct callback_data
*cb
= (struct callback_data
*)pd
->lCustData
;
4010 cb
->callback
->lpVtbl
->SelectionChange(cb
->callback
);
4011 cb
->callback
->lpVtbl
->InitDone(cb
->callback
);
4016 /* FIXME: store interface pointer somewhere in window properties and call it
4018 cb->callback->lpVtbl->HandleMessage(cb->callback, hwnd, msg, wp, lp, &hres);
4025 /***********************************************************************
4026 * PrintDlgExA (COMDLG32.@)
4034 HRESULT WINAPI
PrintDlgExA(LPPRINTDLGEXA lppd
)
4036 PRINTER_INFO_2A
*pbuf
;
4037 DRIVER_INFO_3A
*dbuf
;
4042 if ((lppd
== NULL
) || (lppd
->lStructSize
!= sizeof(PRINTDLGEXA
)))
4043 return E_INVALIDARG
;
4045 if (!IsWindow(lppd
->hwndOwner
))
4048 if (lppd
->nStartPage
!= START_PAGE_GENERAL
)
4050 if (!lppd
->nPropertyPages
)
4051 return E_INVALIDARG
;
4053 FIXME("custom property sheets (%d at %p) not supported\n", lppd
->nPropertyPages
, lppd
->lphPropertyPages
);
4056 /* Use PD_NOPAGENUMS or set nMaxPageRanges and lpPageRanges */
4057 if (!(lppd
->Flags
& PD_NOPAGENUMS
) && (!lppd
->nMaxPageRanges
|| !lppd
->lpPageRanges
))
4059 return E_INVALIDARG
;
4062 if (lppd
->Flags
& PD_RETURNDEFAULT
)
4064 if (lppd
->hDevMode
|| lppd
->hDevNames
)
4066 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
4067 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
4068 return E_INVALIDARG
;
4070 if (!PRINTDLG_OpenDefaultPrinter(&hprn
))
4072 WARN("Can't find default printer\n");
4073 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
4077 pbuf
= get_printer_infoA(hprn
);
4084 dbuf
= get_driver_infoA(hprn
);
4087 HeapFree(GetProcessHeap(), 0, pbuf
);
4088 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
4092 dm
= pbuf
->pDevMode
;
4097 struct callback_data cb_data
= { 0 };
4099 FIXME("(%p) semi-stub\n", lppd
);
4101 if (lppd
->lpCallback
)
4103 IUnknown_QueryInterface((IUnknown
*)lppd
->lpCallback
, &IID_IPrintDialogCallback
, (void **)&cb_data
.callback
);
4104 IUnknown_QueryInterface((IUnknown
*)lppd
->lpCallback
, &IID_IObjectWithSite
, (void **)&cb_data
.object
);
4108 * PRINTDLGEXA/W and PRINTDLGA/W layout is the same for A and W variants.
4110 pdlgex_to_pdlg((const PRINTDLGEXW
*)lppd
, (PRINTDLGW
*)&pdlg
);
4111 pdlg
.Flags
|= PD_ENABLEPRINTHOOK
;
4112 pdlg
.lpfnPrintHook
= pdlgex_hook_proc
;
4113 pdlg
.lCustData
= (LPARAM
)&cb_data
;
4115 if (PrintDlgA(&pdlg
))
4117 pdlg_to_pdlgex((const PRINTDLGW
*)&pdlg
, (PRINTDLGEXW
*)lppd
);
4118 lppd
->dwResultAction
= PD_RESULT_PRINT
;
4121 lppd
->dwResultAction
= PD_RESULT_CANCEL
;
4123 if (cb_data
.callback
)
4124 cb_data
.callback
->lpVtbl
->Release(cb_data
.callback
);
4126 cb_data
.object
->lpVtbl
->Release(cb_data
.object
);
4133 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
), dbuf
->pDriverPath
, pbuf
->pPrinterName
, pbuf
->pPortName
);
4134 if (!lppd
->hDevNames
)
4137 lppd
->hDevMode
= update_devmode_handleA(lppd
->hDevMode
, dm
);
4138 if (hr
== S_OK
&& lppd
->hDevMode
) {
4139 if (lppd
->Flags
& PD_RETURNDC
) {
4140 lppd
->hDC
= CreateDCA(dbuf
->pDriverPath
, pbuf
->pPrinterName
, pbuf
->pPortName
, dm
);
4144 else if (lppd
->Flags
& PD_RETURNIC
) {
4145 lppd
->hDC
= CreateICA(dbuf
->pDriverPath
, pbuf
->pPrinterName
, pbuf
->pPortName
, dm
);
4153 HeapFree(GetProcessHeap(), 0, pbuf
);
4154 HeapFree(GetProcessHeap(), 0, dbuf
);
4159 /***********************************************************************
4160 * PrintDlgExW (COMDLG32.@)
4162 * Display the property sheet style PRINT dialog box
4165 * lppd [IO] ptr to PRINTDLGEX struct
4169 * Failure: One of the following COM error codes:
4170 * E_OUTOFMEMORY Insufficient memory.
4171 * E_INVALIDARG One or more arguments are invalid.
4172 * E_POINTER Invalid pointer.
4173 * E_HANDLE Invalid handle.
4174 * E_FAIL Unspecified error.
4177 * This Dialog enables the user to specify specific properties of the print job.
4178 * The property sheet can also have additional application-specific and
4179 * driver-specific property pages.
4182 * Not fully implemented
4185 HRESULT WINAPI
PrintDlgExW(LPPRINTDLGEXW lppd
)
4187 PRINTER_INFO_2W
*pbuf
;
4188 DRIVER_INFO_3W
*dbuf
;
4193 if ((lppd
== NULL
) || (lppd
->lStructSize
!= sizeof(PRINTDLGEXW
))) {
4194 return E_INVALIDARG
;
4197 if (!IsWindow(lppd
->hwndOwner
)) {
4201 if (lppd
->nStartPage
!= START_PAGE_GENERAL
)
4203 if (!lppd
->nPropertyPages
)
4204 return E_INVALIDARG
;
4206 FIXME("custom property sheets (%d at %p) not supported\n", lppd
->nPropertyPages
, lppd
->lphPropertyPages
);
4209 /* Use PD_NOPAGENUMS or set nMaxPageRanges and lpPageRanges */
4210 if (!(lppd
->Flags
& PD_NOPAGENUMS
) && (!lppd
->nMaxPageRanges
|| !lppd
->lpPageRanges
))
4212 return E_INVALIDARG
;
4215 if (lppd
->Flags
& PD_RETURNDEFAULT
) {
4217 if (lppd
->hDevMode
|| lppd
->hDevNames
) {
4218 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
4219 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
4220 return E_INVALIDARG
;
4222 if (!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
4223 WARN("Can't find default printer\n");
4224 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
4228 pbuf
= get_printer_infoW(hprn
);
4235 dbuf
= get_driver_infoW(hprn
);
4238 HeapFree(GetProcessHeap(), 0, pbuf
);
4239 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
4243 dm
= pbuf
->pDevMode
;
4248 struct callback_data cb_data
= { 0 };
4250 FIXME("(%p) semi-stub\n", lppd
);
4252 if (lppd
->lpCallback
)
4254 IUnknown_QueryInterface((IUnknown
*)lppd
->lpCallback
, &IID_IPrintDialogCallback
, (void **)&cb_data
.callback
);
4255 IUnknown_QueryInterface((IUnknown
*)lppd
->lpCallback
, &IID_IObjectWithSite
, (void **)&cb_data
.object
);
4258 pdlgex_to_pdlg(lppd
, &pdlg
);
4259 pdlg
.Flags
|= PD_ENABLEPRINTHOOK
;
4260 pdlg
.lpfnPrintHook
= pdlgex_hook_proc
;
4261 pdlg
.lCustData
= (LPARAM
)&cb_data
;
4263 if (PrintDlgW(&pdlg
))
4265 pdlg_to_pdlgex(&pdlg
, lppd
);
4266 lppd
->dwResultAction
= PD_RESULT_PRINT
;
4269 lppd
->dwResultAction
= PD_RESULT_CANCEL
;
4271 if (cb_data
.callback
)
4272 cb_data
.callback
->lpVtbl
->Release(cb_data
.callback
);
4274 cb_data
.object
->lpVtbl
->Release(cb_data
.object
);
4281 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
), dbuf
->pDriverPath
, pbuf
->pPrinterName
, pbuf
->pPortName
);
4282 if (!lppd
->hDevNames
)
4285 lppd
->hDevMode
= update_devmode_handleW(lppd
->hDevMode
, dm
);
4286 if (hr
== S_OK
&& lppd
->hDevMode
) {
4287 if (lppd
->Flags
& PD_RETURNDC
) {
4288 lppd
->hDC
= CreateDCW(dbuf
->pDriverPath
, pbuf
->pPrinterName
, pbuf
->pPortName
, dm
);
4292 else if (lppd
->Flags
& PD_RETURNIC
) {
4293 lppd
->hDC
= CreateICW(dbuf
->pDriverPath
, pbuf
->pPrinterName
, pbuf
->pPortName
, dm
);
4301 HeapFree(GetProcessHeap(), 0, pbuf
);
4302 HeapFree(GetProcessHeap(), 0, dbuf
);