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 printdlg_prop
[] = L
"__WINE_PRINTDLGDATA";
145 static const WCHAR pagesetupdlg_prop
[] = L
"__WINE_PAGESETUPDLGDATA";
148 static LPWSTR
strdupW(LPCWSTR p
)
154 len
= (lstrlenW(p
) + 1) * sizeof(WCHAR
);
155 ret
= HeapAlloc(GetProcessHeap(), 0, len
);
160 /***********************************************************************
161 * get_driver_info [internal]
163 * get DRIVER_INFO_3W for the current printer handle,
164 * alloc the buffer, when needed
166 static DRIVER_INFO_3W
* get_driver_infoW(HANDLE hprn
)
168 DRIVER_INFO_3W
*di3
= NULL
;
172 res
= GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
173 if (!res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
174 di3
= HeapAlloc(GetProcessHeap(), 0, needed
);
175 res
= GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)di3
, needed
, &needed
);
181 TRACE("GetPrinterDriverW failed with %u\n", GetLastError());
182 HeapFree(GetProcessHeap(), 0, di3
);
186 static DRIVER_INFO_3A
* get_driver_infoA(HANDLE hprn
)
188 DRIVER_INFO_3A
*di3
= NULL
;
192 res
= GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
193 if (!res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
194 di3
= HeapAlloc(GetProcessHeap(), 0, needed
);
195 res
= GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)di3
, needed
, &needed
);
201 TRACE("GetPrinterDriverA failed with %u\n", GetLastError());
202 HeapFree(GetProcessHeap(), 0, di3
);
207 /***********************************************************************
208 * get_printer_info [internal]
210 * get PRINTER_INFO_2W for the current printer handle,
211 * alloc the buffer, when needed
213 static PRINTER_INFO_2W
* get_printer_infoW(HANDLE hprn
)
215 PRINTER_INFO_2W
*pi2
= NULL
;
219 res
= GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
220 if (!res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
221 pi2
= HeapAlloc(GetProcessHeap(), 0, needed
);
222 res
= GetPrinterW(hprn
, 2, (LPBYTE
)pi2
, needed
, &needed
);
228 TRACE("GetPrinterW failed with %u\n", GetLastError());
229 HeapFree(GetProcessHeap(), 0, pi2
);
233 static PRINTER_INFO_2A
* get_printer_infoA(HANDLE hprn
)
235 PRINTER_INFO_2A
*pi2
= NULL
;
239 res
= GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
240 if (!res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
241 pi2
= HeapAlloc(GetProcessHeap(), 0, needed
);
242 res
= GetPrinterA(hprn
, 2, (LPBYTE
)pi2
, needed
, &needed
);
248 TRACE("GetPrinterA failed with %u\n", GetLastError());
249 HeapFree(GetProcessHeap(), 0, pi2
);
254 /***********************************************************************
255 * update_devmode_handle [internal]
257 * update a devmode handle for the given DEVMODE, alloc the buffer, when needed
259 static HGLOBAL
update_devmode_handleW(HGLOBAL hdm
, DEVMODEW
*dm
)
261 SIZE_T size
= GlobalSize(hdm
);
264 /* Increase / alloc the global memory block, when needed */
265 if ((dm
->dmSize
+ dm
->dmDriverExtra
) > size
) {
267 hdm
= GlobalReAlloc(hdm
, dm
->dmSize
+ dm
->dmDriverExtra
, 0);
269 hdm
= GlobalAlloc(GMEM_MOVEABLE
, dm
->dmSize
+ dm
->dmDriverExtra
);
273 ptr
= GlobalLock(hdm
);
275 memcpy(ptr
, dm
, dm
->dmSize
+ dm
->dmDriverExtra
);
287 static HGLOBAL
update_devmode_handleA(HGLOBAL hdm
, DEVMODEA
*dm
)
289 SIZE_T size
= GlobalSize(hdm
);
292 /* Increase / alloc the global memory block, when needed */
293 if ((dm
->dmSize
+ dm
->dmDriverExtra
) > size
) {
295 hdm
= GlobalReAlloc(hdm
, dm
->dmSize
+ dm
->dmDriverExtra
, 0);
297 hdm
= GlobalAlloc(GMEM_MOVEABLE
, dm
->dmSize
+ dm
->dmDriverExtra
);
301 ptr
= GlobalLock(hdm
);
303 memcpy(ptr
, dm
, dm
->dmSize
+ dm
->dmDriverExtra
);
315 /***********************************************************
316 * convert_to_devmodeA
318 * Creates an ansi copy of supplied devmode
320 static DEVMODEA
*convert_to_devmodeA(const DEVMODEW
*dmW
)
325 if (!dmW
) return NULL
;
326 size
= dmW
->dmSize
- CCHDEVICENAME
-
327 ((dmW
->dmSize
> FIELD_OFFSET(DEVMODEW
, dmFormName
)) ? CCHFORMNAME
: 0);
329 dmA
= HeapAlloc(GetProcessHeap(), 0, size
+ dmW
->dmDriverExtra
);
330 if (!dmA
) return NULL
;
332 WideCharToMultiByte(CP_ACP
, 0, dmW
->dmDeviceName
, -1,
333 (LPSTR
)dmA
->dmDeviceName
, CCHDEVICENAME
, NULL
, NULL
);
335 if (FIELD_OFFSET(DEVMODEW
, dmFormName
) >= dmW
->dmSize
)
337 memcpy(&dmA
->dmSpecVersion
, &dmW
->dmSpecVersion
,
338 dmW
->dmSize
- FIELD_OFFSET(DEVMODEW
, dmSpecVersion
));
342 memcpy(&dmA
->dmSpecVersion
, &dmW
->dmSpecVersion
,
343 FIELD_OFFSET(DEVMODEW
, dmFormName
) - FIELD_OFFSET(DEVMODEW
, dmSpecVersion
));
344 WideCharToMultiByte(CP_ACP
, 0, dmW
->dmFormName
, -1,
345 (LPSTR
)dmA
->dmFormName
, CCHFORMNAME
, NULL
, NULL
);
347 memcpy(&dmA
->dmLogPixels
, &dmW
->dmLogPixels
, dmW
->dmSize
- FIELD_OFFSET(DEVMODEW
, dmLogPixels
));
351 memcpy((char *)dmA
+ dmA
->dmSize
, (const char *)dmW
+ dmW
->dmSize
, dmW
->dmDriverExtra
);
355 /***********************************************************************
356 * PRINTDLG_OpenDefaultPrinter
358 * Returns a winspool printer handle to the default printer in *hprn
359 * Caller must call ClosePrinter on the handle
361 * Returns TRUE on success else FALSE
363 static BOOL
PRINTDLG_OpenDefaultPrinter(HANDLE
*hprn
)
366 DWORD dwBufLen
= ARRAY_SIZE(buf
);
368 if(!GetDefaultPrinterW(buf
, &dwBufLen
))
370 res
= OpenPrinterW(buf
, hprn
, NULL
);
372 WARN("Could not open printer %s\n", debugstr_w(buf
));
376 /***********************************************************************
377 * PRINTDLG_SetUpPrinterListCombo
379 * Initializes printer list combox.
380 * hDlg: HWND of dialog
381 * id: Control id of combo
382 * name: Name of printer to select
384 * Initializes combo with list of available printers. Selects printer 'name'
385 * If name is NULL or does not exist select the default printer.
387 * Returns number of printers added to list.
389 static INT
PRINTDLG_SetUpPrinterListComboA(HWND hDlg
, UINT id
, LPCSTR name
)
393 LPPRINTER_INFO_2A pi
;
394 EnumPrintersA(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
395 pi
= HeapAlloc(GetProcessHeap(), 0, needed
);
396 EnumPrintersA(PRINTER_ENUM_LOCAL
, NULL
, 2, (LPBYTE
)pi
, needed
, &needed
,
399 SendDlgItemMessageA(hDlg
, id
, CB_RESETCONTENT
, 0, 0);
401 for(i
= 0; i
< num
; i
++) {
402 SendDlgItemMessageA(hDlg
, id
, CB_ADDSTRING
, 0,
403 (LPARAM
)pi
[i
].pPrinterName
);
405 HeapFree(GetProcessHeap(), 0, pi
);
407 (i
= SendDlgItemMessageA(hDlg
, id
, CB_FINDSTRINGEXACT
, -1,
408 (LPARAM
)name
)) == CB_ERR
) {
411 DWORD dwBufLen
= ARRAY_SIZE(buf
);
413 WARN("Can't find %s in printer list so trying to find default\n",
415 if(!GetDefaultPrinterA(buf
, &dwBufLen
))
417 i
= SendDlgItemMessageA(hDlg
, id
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buf
);
419 FIXME("Can't find default printer in printer list\n");
421 SendDlgItemMessageA(hDlg
, id
, CB_SETCURSEL
, i
, 0);
425 static INT
PRINTDLG_SetUpPrinterListComboW(HWND hDlg
, UINT id
, LPCWSTR name
)
429 LPPRINTER_INFO_2W pi
;
430 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
431 pi
= HeapAlloc(GetProcessHeap(), 0, needed
);
432 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, (LPBYTE
)pi
, needed
, &needed
,
435 for(i
= 0; i
< num
; i
++) {
436 SendDlgItemMessageW(hDlg
, id
, CB_ADDSTRING
, 0,
437 (LPARAM
)pi
[i
].pPrinterName
);
439 HeapFree(GetProcessHeap(), 0, pi
);
441 (i
= SendDlgItemMessageW(hDlg
, id
, CB_FINDSTRINGEXACT
, -1,
442 (LPARAM
)name
)) == CB_ERR
) {
444 DWORD dwBufLen
= ARRAY_SIZE(buf
);
446 WARN("Can't find %s in printer list so trying to find default\n",
448 if(!GetDefaultPrinterW(buf
, &dwBufLen
))
450 i
= SendDlgItemMessageW(hDlg
, id
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buf
);
452 TRACE("Can't find default printer in printer list\n");
454 SendDlgItemMessageW(hDlg
, id
, CB_SETCURSEL
, i
, 0);
458 /***********************************************************************
459 * PRINTDLG_CreateDevNames [internal]
462 * creates a DevNames structure.
464 * (NB. when we handle unicode the offsets will be in wchars).
466 static BOOL
PRINTDLG_CreateDevNames(HGLOBAL
*hmem
, const char* DeviceDriverName
,
467 const char* DeviceName
, const char* OutputPort
)
470 char* pDevNamesSpace
;
472 LPDEVNAMES lpDevNames
;
474 DWORD dwBufLen
= ARRAY_SIZE(buf
);
477 p
= strrchr( DeviceDriverName
, '\\' );
478 if (p
) DeviceDriverName
= p
+ 1;
480 size
= strlen(DeviceDriverName
) + 1
481 + strlen(DeviceName
) + 1
482 + strlen(OutputPort
) + 1
486 *hmem
= GlobalReAlloc(*hmem
, size
, GMEM_MOVEABLE
);
488 *hmem
= GlobalAlloc(GMEM_MOVEABLE
, size
);
492 pDevNamesSpace
= GlobalLock(*hmem
);
493 lpDevNames
= (LPDEVNAMES
) pDevNamesSpace
;
495 pTempPtr
= pDevNamesSpace
+ sizeof(DEVNAMES
);
496 strcpy(pTempPtr
, DeviceDriverName
);
497 lpDevNames
->wDriverOffset
= pTempPtr
- pDevNamesSpace
;
499 pTempPtr
+= strlen(DeviceDriverName
) + 1;
500 strcpy(pTempPtr
, DeviceName
);
501 lpDevNames
->wDeviceOffset
= pTempPtr
- pDevNamesSpace
;
503 pTempPtr
+= strlen(DeviceName
) + 1;
504 strcpy(pTempPtr
, OutputPort
);
505 lpDevNames
->wOutputOffset
= pTempPtr
- pDevNamesSpace
;
507 GetDefaultPrinterA(buf
, &dwBufLen
);
508 lpDevNames
->wDefault
= (strcmp(buf
, DeviceName
) == 0) ? 1 : 0;
513 static BOOL
PRINTDLG_CreateDevNamesW(HGLOBAL
*hmem
, LPCWSTR DeviceDriverName
,
514 LPCWSTR DeviceName
, LPCWSTR OutputPort
)
517 LPWSTR pDevNamesSpace
;
519 LPDEVNAMES lpDevNames
;
521 DWORD dwBufLen
= ARRAY_SIZE(bufW
);
524 p
= wcsrchr( DeviceDriverName
, '\\' );
525 if (p
) DeviceDriverName
= p
+ 1;
527 size
= sizeof(WCHAR
)*lstrlenW(DeviceDriverName
) + 2
528 + sizeof(WCHAR
)*lstrlenW(DeviceName
) + 2
529 + sizeof(WCHAR
)*lstrlenW(OutputPort
) + 2
533 *hmem
= GlobalReAlloc(*hmem
, size
, GMEM_MOVEABLE
);
535 *hmem
= GlobalAlloc(GMEM_MOVEABLE
, size
);
539 pDevNamesSpace
= GlobalLock(*hmem
);
540 lpDevNames
= (LPDEVNAMES
) pDevNamesSpace
;
542 pTempPtr
= (LPWSTR
)((LPDEVNAMES
)pDevNamesSpace
+ 1);
543 lstrcpyW(pTempPtr
, DeviceDriverName
);
544 lpDevNames
->wDriverOffset
= pTempPtr
- pDevNamesSpace
;
546 pTempPtr
+= lstrlenW(DeviceDriverName
) + 1;
547 lstrcpyW(pTempPtr
, DeviceName
);
548 lpDevNames
->wDeviceOffset
= pTempPtr
- pDevNamesSpace
;
550 pTempPtr
+= lstrlenW(DeviceName
) + 1;
551 lstrcpyW(pTempPtr
, OutputPort
);
552 lpDevNames
->wOutputOffset
= pTempPtr
- pDevNamesSpace
;
554 GetDefaultPrinterW(bufW
, &dwBufLen
);
555 lpDevNames
->wDefault
= (lstrcmpW(bufW
, DeviceName
) == 0) ? 1 : 0;
560 /***********************************************************************
561 * PRINTDLG_UpdatePrintDlg [internal]
564 * updates the PrintDlg structure for return values.
567 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
568 * TRUE if successful.
570 static BOOL
PRINTDLG_UpdatePrintDlgA(HWND hDlg
,
571 PRINT_PTRA
* PrintStructures
)
573 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
574 PDEVMODEA lpdm
= PrintStructures
->lpDevMode
;
575 LPPRINTER_INFO_2A pi
= PrintStructures
->lpPrinterInfo
;
579 FIXME("No lpdm ptr?\n");
584 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
585 /* check whether nFromPage and nToPage are within range defined by
586 * nMinPage and nMaxPage
588 if (IsDlgButtonChecked(hDlg
, rad3
) == BST_CHECKED
) { /* Pages */
592 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
593 nToPage
= GetDlgItemInt(hDlg
, edt2
, &translated
, FALSE
);
595 /* if no ToPage value is entered, use the FromPage value */
596 if(!translated
) nToPage
= nFromPage
;
598 if (nFromPage
< lppd
->nMinPage
|| nFromPage
> lppd
->nMaxPage
||
599 nToPage
< lppd
->nMinPage
|| nToPage
> lppd
->nMaxPage
) {
600 WCHAR resourcestr
[256];
601 WCHAR resultstr
[256];
602 LoadStringW(COMDLG32_hInstance
, PD32_INVALID_PAGE_RANGE
, resourcestr
, 255);
603 wsprintfW(resultstr
,resourcestr
, lppd
->nMinPage
, lppd
->nMaxPage
);
604 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
, resourcestr
, 255);
605 MessageBoxW(hDlg
, resultstr
, resourcestr
, MB_OK
| MB_ICONWARNING
);
608 lppd
->nFromPage
= nFromPage
;
609 lppd
->nToPage
= nToPage
;
610 lppd
->Flags
|= PD_PAGENUMS
;
613 lppd
->Flags
&= ~PD_PAGENUMS
;
615 if (IsDlgButtonChecked(hDlg
, rad2
) == BST_CHECKED
) /* Selection */
616 lppd
->Flags
|= PD_SELECTION
;
618 lppd
->Flags
&= ~PD_SELECTION
;
620 if (IsDlgButtonChecked(hDlg
, chx1
) == BST_CHECKED
) {/* Print to file */
621 static char file
[] = "FILE:";
622 lppd
->Flags
|= PD_PRINTTOFILE
;
623 pi
->pPortName
= file
;
626 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
) { /* Collate */
627 FIXME("Collate lppd not yet implemented as output\n");
630 /* set PD_Collate and nCopies */
631 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
632 /* The application doesn't support multiple copies or collate...
634 lppd
->Flags
&= ~PD_COLLATE
;
636 /* if the printer driver supports it... store info there
637 * otherwise no collate & multiple copies !
639 if (lpdm
->dmFields
& DM_COLLATE
)
641 (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
);
642 if (lpdm
->dmFields
& DM_COPIES
)
643 lpdm
->u1
.s1
.dmCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
645 /* Application is responsible for multiple copies */
646 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
647 lppd
->Flags
|= PD_COLLATE
;
649 lppd
->Flags
&= ~PD_COLLATE
;
650 lppd
->nCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
651 /* multiple copies already included in the document. Driver must print only one copy */
652 lpdm
->u1
.s1
.dmCopies
= 1;
655 /* Print quality, PrintDlg16 */
656 if(GetDlgItem(hDlg
, cmb1
))
658 HWND hQuality
= GetDlgItem(hDlg
, cmb1
);
659 int Sel
= SendMessageA(hQuality
, CB_GETCURSEL
, 0, 0);
663 LONG dpi
= SendMessageA(hQuality
, CB_GETITEMDATA
, Sel
, 0);
664 lpdm
->dmFields
|= DM_PRINTQUALITY
| DM_YRESOLUTION
;
665 lpdm
->u1
.s1
.dmPrintQuality
= LOWORD(dpi
);
666 lpdm
->dmYResolution
= HIWORD(dpi
);
673 static BOOL
PRINTDLG_UpdatePrintDlgW(HWND hDlg
,
674 PRINT_PTRW
* PrintStructures
)
676 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
677 PDEVMODEW lpdm
= PrintStructures
->lpDevMode
;
678 LPPRINTER_INFO_2W pi
= PrintStructures
->lpPrinterInfo
;
682 FIXME("No lpdm ptr?\n");
687 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
688 /* check whether nFromPage and nToPage are within range defined by
689 * nMinPage and nMaxPage
691 if (IsDlgButtonChecked(hDlg
, rad3
) == BST_CHECKED
) { /* Pages */
695 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
696 nToPage
= GetDlgItemInt(hDlg
, edt2
, &translated
, FALSE
);
698 /* if no ToPage value is entered, use the FromPage value */
699 if(!translated
) nToPage
= nFromPage
;
701 if (nFromPage
< lppd
->nMinPage
|| nFromPage
> lppd
->nMaxPage
||
702 nToPage
< lppd
->nMinPage
|| nToPage
> lppd
->nMaxPage
) {
703 WCHAR resourcestr
[256];
704 WCHAR resultstr
[256];
706 LoadStringW(COMDLG32_hInstance
, PD32_INVALID_PAGE_RANGE
,
708 args
[0] = lppd
->nMinPage
;
709 args
[1] = lppd
->nMaxPage
;
710 FormatMessageW(FORMAT_MESSAGE_FROM_STRING
|FORMAT_MESSAGE_ARGUMENT_ARRAY
,
711 resourcestr
, 0, 0, resultstr
,
712 ARRAY_SIZE(resultstr
),
713 (__ms_va_list
*)args
);
714 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
,
716 MessageBoxW(hDlg
, resultstr
, resourcestr
,
717 MB_OK
| MB_ICONWARNING
);
720 lppd
->nFromPage
= nFromPage
;
721 lppd
->nToPage
= nToPage
;
722 lppd
->Flags
|= PD_PAGENUMS
;
725 lppd
->Flags
&= ~PD_PAGENUMS
;
727 if (IsDlgButtonChecked(hDlg
, rad2
) == BST_CHECKED
) /* Selection */
728 lppd
->Flags
|= PD_SELECTION
;
730 lppd
->Flags
&= ~PD_SELECTION
;
732 if (IsDlgButtonChecked(hDlg
, chx1
) == BST_CHECKED
) {/* Print to file */
733 static WCHAR file
[] = L
"FILE:";
734 lppd
->Flags
|= PD_PRINTTOFILE
;
735 pi
->pPortName
= file
;
738 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
) { /* Collate */
739 FIXME("Collate lppd not yet implemented as output\n");
742 /* set PD_Collate and nCopies */
743 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
744 /* The application doesn't support multiple copies or collate...
746 lppd
->Flags
&= ~PD_COLLATE
;
748 /* if the printer driver supports it... store info there
749 * otherwise no collate & multiple copies !
751 if (lpdm
->dmFields
& DM_COLLATE
)
753 (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
);
754 if (lpdm
->dmFields
& DM_COPIES
)
755 lpdm
->u1
.s1
.dmCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
757 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
758 lppd
->Flags
|= PD_COLLATE
;
760 lppd
->Flags
&= ~PD_COLLATE
;
761 lppd
->nCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
767 /************************************************************************
768 * PRINTDLG_SetUpPaperComboBox
770 * Initialize either the papersize or inputslot combos of the Printer Setup
771 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
772 * We also try to re-select the old selection.
774 static BOOL
PRINTDLG_SetUpPaperComboBoxA(HWND hDlg
,
785 WORD oldWord
= 0, newWord
= 0; /* DMPAPER_ and DMBIN_ start at 1 */
787 int fwCapability_Names
;
788 int fwCapability_Words
;
790 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName
,PortName
,nIDComboBox
);
792 /* query the dialog box for the current selected value */
793 Sel
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETCURSEL
, 0, 0);
795 /* we enter here only if a different printer is selected after
796 * the Print Setup dialog is opened. The current settings are
797 * stored into the newly selected printer.
799 oldWord
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
,
801 if(oldWord
>= DMPAPER_USER
) /* DMPAPER_USER == DMBIN_USER */
802 oldWord
= 0; /* There's no point in trying to keep custom
803 paper / bin sizes across printers */
807 newWord
= (nIDComboBox
== cmb2
) ? dm
->u1
.s1
.dmPaperSize
: dm
->u1
.s1
.dmDefaultSource
;
809 if (nIDComboBox
== cmb2
) {
811 fwCapability_Names
= DC_PAPERNAMES
;
812 fwCapability_Words
= DC_PAPERS
;
816 fwCapability_Names
= DC_BINNAMES
;
817 fwCapability_Words
= DC_BINS
;
820 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
821 fwCapability_Names
, NULL
, dm
);
822 if (NrOfEntries
== 0)
823 WARN("no Name Entries found!\n");
824 else if (NrOfEntries
< 0)
827 if(DeviceCapabilitiesA(PrinterName
, PortName
, fwCapability_Words
, NULL
, dm
)
829 ERR("Number of caps is different\n");
833 Names
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(char)*NamesSize
);
834 Words
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WORD
));
835 DeviceCapabilitiesA(PrinterName
, PortName
, fwCapability_Names
, Names
, dm
);
836 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
837 fwCapability_Words
, (LPSTR
)Words
, dm
);
839 /* reset any current content in the combobox */
840 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_RESETCONTENT
, 0, 0);
842 /* store new content */
843 for (i
= 0; i
< NrOfEntries
; i
++) {
844 DWORD pos
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_ADDSTRING
, 0,
845 (LPARAM
)(&Names
[i
*NamesSize
]) );
846 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_SETITEMDATA
, pos
,
850 /* Look for old selection or the new default.
851 Can't do this is previous loop since item order will change as more items are added */
853 old_Sel
= NrOfEntries
;
854 for (i
= 0; i
< NrOfEntries
; i
++) {
855 if(SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) ==
860 if(SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) == newWord
)
864 if(old_Sel
< NrOfEntries
)
868 if(nIDComboBox
== cmb2
)
869 dm
->u1
.s1
.dmPaperSize
= oldWord
;
871 dm
->u1
.s1
.dmDefaultSource
= oldWord
;
876 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_SETCURSEL
, Sel
, 0);
878 HeapFree(GetProcessHeap(),0,Words
);
879 HeapFree(GetProcessHeap(),0,Names
);
883 static BOOL
PRINTDLG_SetUpPaperComboBoxW(HWND hDlg
,
885 const WCHAR
* PrinterName
,
886 const WCHAR
* PortName
,
894 WORD oldWord
= 0, newWord
= 0; /* DMPAPER_ and DMBIN_ start at 1 */
896 int fwCapability_Names
;
897 int fwCapability_Words
;
899 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName
),debugstr_w(PortName
),nIDComboBox
);
901 /* query the dialog box for the current selected value */
902 Sel
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETCURSEL
, 0, 0);
904 /* we enter here only if a different printer is selected after
905 * the Print Setup dialog is opened. The current settings are
906 * stored into the newly selected printer.
908 oldWord
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETITEMDATA
,
911 if(oldWord
>= DMPAPER_USER
) /* DMPAPER_USER == DMBIN_USER */
912 oldWord
= 0; /* There's no point in trying to keep custom
913 paper / bin sizes across printers */
917 newWord
= (nIDComboBox
== cmb2
) ? dm
->u1
.s1
.dmPaperSize
: dm
->u1
.s1
.dmDefaultSource
;
919 if (nIDComboBox
== cmb2
) {
921 fwCapability_Names
= DC_PAPERNAMES
;
922 fwCapability_Words
= DC_PAPERS
;
926 fwCapability_Names
= DC_BINNAMES
;
927 fwCapability_Words
= DC_BINS
;
930 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
931 fwCapability_Names
, NULL
, dm
);
932 if (NrOfEntries
== 0)
933 WARN("no Name Entries found!\n");
934 else if (NrOfEntries
< 0)
937 if(DeviceCapabilitiesW(PrinterName
, PortName
, fwCapability_Words
, NULL
, dm
)
939 ERR("Number of caps is different\n");
943 Names
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WCHAR
)*NamesSize
);
944 Words
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WORD
));
945 DeviceCapabilitiesW(PrinterName
, PortName
, fwCapability_Names
, Names
, dm
);
946 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
947 fwCapability_Words
, Words
, dm
);
949 /* reset any current content in the combobox */
950 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_RESETCONTENT
, 0, 0);
952 /* store new content */
953 for (i
= 0; i
< NrOfEntries
; i
++) {
954 DWORD pos
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_ADDSTRING
, 0,
955 (LPARAM
)(&Names
[i
*NamesSize
]) );
956 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_SETITEMDATA
, pos
,
960 /* Look for old selection or the new default.
961 Can't do this is previous loop since item order will change as more items are added */
963 old_Sel
= NrOfEntries
;
964 for (i
= 0; i
< NrOfEntries
; i
++) {
965 if(SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) ==
970 if(SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) == newWord
)
974 if(old_Sel
< NrOfEntries
)
978 if(nIDComboBox
== cmb2
)
979 dm
->u1
.s1
.dmPaperSize
= oldWord
;
981 dm
->u1
.s1
.dmDefaultSource
= oldWord
;
986 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_SETCURSEL
, Sel
, 0);
988 HeapFree(GetProcessHeap(),0,Words
);
989 HeapFree(GetProcessHeap(),0,Names
);
994 /***********************************************************************
995 * PRINTDLG_UpdatePrinterInfoTexts [internal]
997 static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg
, const PRINTER_INFO_2A
*pi
)
1000 char ResourceString
[256];
1003 /* Status Message */
1006 /* add all status messages */
1007 for (i
= 0; i
< 25; i
++) {
1008 if (pi
->Status
& (1<<i
)) {
1009 LoadStringA(COMDLG32_hInstance
, PD32_PRINTER_STATUS_PAUSED
+i
,
1010 ResourceString
, 255);
1011 strcat(StatusMsg
,ResourceString
);
1014 /* append "ready" */
1015 /* FIXME: status==ready must only be appended if really so.
1016 but how to detect? */
1017 LoadStringA(COMDLG32_hInstance
, PD32_PRINTER_STATUS_READY
,
1018 ResourceString
, 255);
1019 strcat(StatusMsg
,ResourceString
);
1020 SetDlgItemTextA(hDlg
, stc12
, StatusMsg
);
1022 /* set all other printer info texts */
1023 SetDlgItemTextA(hDlg
, stc11
, pi
->pDriverName
);
1025 if (pi
->pLocation
!= NULL
&& pi
->pLocation
[0] != '\0')
1026 SetDlgItemTextA(hDlg
, stc14
, pi
->pLocation
);
1028 SetDlgItemTextA(hDlg
, stc14
, pi
->pPortName
);
1029 SetDlgItemTextA(hDlg
, stc13
, pi
->pComment
? pi
->pComment
: "");
1033 static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg
, const PRINTER_INFO_2W
*pi
)
1035 WCHAR StatusMsg
[256];
1036 WCHAR ResourceString
[256];
1039 /* Status Message */
1042 /* add all status messages */
1043 for (i
= 0; i
< 25; i
++) {
1044 if (pi
->Status
& (1<<i
)) {
1045 LoadStringW(COMDLG32_hInstance
, PD32_PRINTER_STATUS_PAUSED
+i
,
1046 ResourceString
, 255);
1047 lstrcatW(StatusMsg
,ResourceString
);
1050 /* append "ready" */
1051 /* FIXME: status==ready must only be appended if really so.
1052 but how to detect? */
1053 LoadStringW(COMDLG32_hInstance
, PD32_PRINTER_STATUS_READY
,
1054 ResourceString
, 255);
1055 lstrcatW(StatusMsg
,ResourceString
);
1056 SetDlgItemTextW(hDlg
, stc12
, StatusMsg
);
1058 /* set all other printer info texts */
1059 SetDlgItemTextW(hDlg
, stc11
, pi
->pDriverName
);
1060 if (pi
->pLocation
!= NULL
&& pi
->pLocation
[0] != '\0')
1061 SetDlgItemTextW(hDlg
, stc14
, pi
->pLocation
);
1063 SetDlgItemTextW(hDlg
, stc14
, pi
->pPortName
);
1064 SetDlgItemTextW(hDlg
, stc13
, pi
->pComment
? pi
->pComment
: L
"");
1068 /*******************************************************************
1070 * PRINTDLG_ChangePrinter
1073 static BOOL
PRINTDLG_ChangePrinterA(HWND hDlg
, char *name
, PRINT_PTRA
*PrintStructures
)
1075 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1076 LPDEVMODEA lpdm
= NULL
;
1081 HeapFree(GetProcessHeap(),0, PrintStructures
->lpPrinterInfo
);
1082 HeapFree(GetProcessHeap(),0, PrintStructures
->lpDriverInfo
);
1083 if(!OpenPrinterA(name
, &hprn
, NULL
)) {
1084 ERR("Can't open printer %s\n", name
);
1087 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
1088 PrintStructures
->lpPrinterInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
1089 GetPrinterA(hprn
, 2, (LPBYTE
)PrintStructures
->lpPrinterInfo
, needed
,
1091 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
1092 PrintStructures
->lpDriverInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
1093 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)PrintStructures
->lpDriverInfo
,
1095 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures
->lpPrinterInfo
->pPrinterName
);
1100 PRINTDLG_UpdatePrinterInfoTextsA(hDlg
, PrintStructures
->lpPrinterInfo
);
1102 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
1103 PrintStructures
->lpDevMode
= NULL
;
1105 dmSize
= DocumentPropertiesA(0, 0, name
, NULL
, NULL
, 0);
1107 ERR("DocumentProperties fails on %s\n", debugstr_a(name
));
1110 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(), 0, dmSize
);
1111 dmSize
= DocumentPropertiesA(0, 0, name
, PrintStructures
->lpDevMode
, NULL
,
1113 if(lppd
->hDevMode
&& (lpdm
= GlobalLock(lppd
->hDevMode
)) &&
1114 !lstrcmpA( (LPSTR
) lpdm
->dmDeviceName
,
1115 (LPSTR
) PrintStructures
->lpDevMode
->dmDeviceName
)) {
1116 /* Supplied devicemode matches current printer so try to use it */
1117 DocumentPropertiesA(0, 0, name
, PrintStructures
->lpDevMode
, lpdm
,
1118 DM_OUT_BUFFER
| DM_IN_BUFFER
);
1121 GlobalUnlock(lppd
->hDevMode
);
1123 lpdm
= PrintStructures
->lpDevMode
; /* use this as a shortcut */
1125 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
1126 /* Print range (All/Range/Selection) */
1127 if(lppd
->nFromPage
!= 0xffff)
1128 SetDlgItemInt(hDlg
, edt1
, lppd
->nFromPage
, FALSE
);
1129 if(lppd
->nToPage
!= 0xffff)
1130 SetDlgItemInt(hDlg
, edt2
, lppd
->nToPage
, FALSE
);
1132 CheckRadioButton(hDlg
, rad1
, rad3
, rad1
); /* default */
1133 if (lppd
->Flags
& PD_NOSELECTION
)
1134 EnableWindow(GetDlgItem(hDlg
, rad2
), FALSE
);
1136 if (lppd
->Flags
& PD_SELECTION
)
1137 CheckRadioButton(hDlg
, rad1
, rad3
, rad2
);
1138 if (lppd
->Flags
& PD_NOPAGENUMS
) {
1139 EnableWindow(GetDlgItem(hDlg
, rad3
), FALSE
);
1140 EnableWindow(GetDlgItem(hDlg
, stc2
),FALSE
);
1141 EnableWindow(GetDlgItem(hDlg
, edt1
), FALSE
);
1142 EnableWindow(GetDlgItem(hDlg
, stc3
),FALSE
);
1143 EnableWindow(GetDlgItem(hDlg
, edt2
), FALSE
);
1145 if (lppd
->Flags
& PD_PAGENUMS
)
1146 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1151 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1153 if (lppd
->Flags
& PD_COLLATE
) {
1154 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1155 (LPARAM
)PrintStructures
->hCollateIcon
);
1156 CheckDlgButton(hDlg
, chx2
, 1);
1158 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1159 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1160 CheckDlgButton(hDlg
, chx2
, 0);
1163 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1164 /* if printer doesn't support it: no Collate */
1165 if (!(lpdm
->dmFields
& DM_COLLATE
)) {
1166 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1167 EnableWindow(GetDlgItem(hDlg
, ico3
), FALSE
);
1174 if (lppd
->hDevMode
== 0)
1175 copies
= lppd
->nCopies
;
1177 copies
= lpdm
->u1
.s1
.dmCopies
;
1178 if(copies
== 0) copies
= 1;
1179 else if(copies
< 0) copies
= MAX_COPIES
;
1180 SetDlgItemInt(hDlg
, edt3
, copies
, FALSE
);
1183 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1184 /* if printer doesn't support it: no nCopies */
1185 if (!(lpdm
->dmFields
& DM_COPIES
)) {
1186 EnableWindow(GetDlgItem(hDlg
, edt3
), FALSE
);
1187 EnableWindow(GetDlgItem(hDlg
, stc5
), FALSE
);
1192 CheckDlgButton(hDlg
, chx1
, (lppd
->Flags
& PD_PRINTTOFILE
) ? 1 : 0);
1193 if (lppd
->Flags
& PD_DISABLEPRINTTOFILE
)
1194 EnableWindow(GetDlgItem(hDlg
, chx1
), FALSE
);
1195 if (lppd
->Flags
& PD_HIDEPRINTTOFILE
)
1196 ShowWindow(GetDlgItem(hDlg
, chx1
), SW_HIDE
);
1198 /* Fill print quality combo, PrintDlg16 */
1199 if(GetDlgItem(hDlg
, cmb1
))
1201 DWORD numResolutions
= DeviceCapabilitiesA(PrintStructures
->lpPrinterInfo
->pPrinterName
,
1202 PrintStructures
->lpPrinterInfo
->pPortName
,
1203 DC_ENUMRESOLUTIONS
, NULL
, lpdm
);
1205 if(numResolutions
!= -1)
1207 HWND hQuality
= GetDlgItem(hDlg
, cmb1
);
1212 HDC hPrinterDC
= CreateDCA(PrintStructures
->lpPrinterInfo
->pDriverName
,
1213 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1216 Resolutions
= HeapAlloc(GetProcessHeap(), 0, numResolutions
*sizeof(LONG
)*2);
1217 DeviceCapabilitiesA(PrintStructures
->lpPrinterInfo
->pPrinterName
,
1218 PrintStructures
->lpPrinterInfo
->pPortName
,
1219 DC_ENUMRESOLUTIONS
, (LPSTR
)Resolutions
, lpdm
);
1221 dpiX
= GetDeviceCaps(hPrinterDC
, LOGPIXELSX
);
1222 dpiY
= GetDeviceCaps(hPrinterDC
, LOGPIXELSY
);
1223 DeleteDC(hPrinterDC
);
1225 SendMessageA(hQuality
, CB_RESETCONTENT
, 0, 0);
1226 for(i
= 0; i
< (numResolutions
* 2); i
+= 2)
1228 BOOL IsDefault
= FALSE
;
1231 if(Resolutions
[i
] == Resolutions
[i
+1])
1233 if(dpiX
== Resolutions
[i
])
1235 sprintf(buf
, "%d dpi", Resolutions
[i
]);
1238 if(dpiX
== Resolutions
[i
] && dpiY
== Resolutions
[i
+1])
1240 sprintf(buf
, "%d dpi x %d dpi", Resolutions
[i
], Resolutions
[i
+1]);
1243 Index
= SendMessageA(hQuality
, CB_ADDSTRING
, 0, (LPARAM
)buf
);
1246 SendMessageA(hQuality
, CB_SETCURSEL
, Index
, 0);
1248 SendMessageA(hQuality
, CB_SETITEMDATA
, Index
, MAKELONG(dpiX
,dpiY
));
1250 HeapFree(GetProcessHeap(), 0, Resolutions
);
1253 } else { /* PD_PRINTSETUP */
1254 BOOL bPortrait
= (lpdm
->u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
);
1256 PRINTDLG_SetUpPaperComboBoxA(hDlg
, cmb2
,
1257 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1258 PrintStructures
->lpPrinterInfo
->pPortName
,
1260 PRINTDLG_SetUpPaperComboBoxA(hDlg
, cmb3
,
1261 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1262 PrintStructures
->lpPrinterInfo
->pPortName
,
1264 CheckRadioButton(hDlg
, rad1
, rad2
, bPortrait
? rad1
: rad2
);
1265 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1266 (LPARAM
)(bPortrait
? PrintStructures
->hPortraitIcon
:
1267 PrintStructures
->hLandscapeIcon
));
1272 if ((lppd
->Flags
& PD_SHOWHELP
)==0) {
1273 /* hide if PD_SHOWHELP not specified */
1274 ShowWindow(GetDlgItem(hDlg
, pshHelp
), SW_HIDE
);
1279 static BOOL
PRINTDLG_ChangePrinterW(HWND hDlg
, WCHAR
*name
,
1280 PRINT_PTRW
*PrintStructures
)
1282 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1283 LPDEVMODEW lpdm
= NULL
;
1288 HeapFree(GetProcessHeap(),0, PrintStructures
->lpPrinterInfo
);
1289 HeapFree(GetProcessHeap(),0, PrintStructures
->lpDriverInfo
);
1290 if(!OpenPrinterW(name
, &hprn
, NULL
)) {
1291 ERR("Can't open printer %s\n", debugstr_w(name
));
1294 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
1295 PrintStructures
->lpPrinterInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
1296 GetPrinterW(hprn
, 2, (LPBYTE
)PrintStructures
->lpPrinterInfo
, needed
,
1298 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
1299 PrintStructures
->lpDriverInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
1300 if (!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)PrintStructures
->lpDriverInfo
,
1302 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures
->lpPrinterInfo
->pPrinterName
));
1307 PRINTDLG_UpdatePrinterInfoTextsW(hDlg
, PrintStructures
->lpPrinterInfo
);
1309 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
1310 PrintStructures
->lpDevMode
= NULL
;
1312 dmSize
= DocumentPropertiesW(0, 0, name
, NULL
, NULL
, 0);
1314 ERR("DocumentProperties fails on %s\n", debugstr_w(name
));
1317 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(), 0, dmSize
);
1318 dmSize
= DocumentPropertiesW(0, 0, name
, PrintStructures
->lpDevMode
, NULL
,
1320 if(lppd
->hDevMode
&& (lpdm
= GlobalLock(lppd
->hDevMode
)) &&
1321 !lstrcmpW(lpdm
->dmDeviceName
,
1322 PrintStructures
->lpDevMode
->dmDeviceName
)) {
1323 /* Supplied devicemode matches current printer so try to use it */
1324 DocumentPropertiesW(0, 0, name
, PrintStructures
->lpDevMode
, lpdm
,
1325 DM_OUT_BUFFER
| DM_IN_BUFFER
);
1328 GlobalUnlock(lppd
->hDevMode
);
1330 lpdm
= PrintStructures
->lpDevMode
; /* use this as a shortcut */
1332 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
1333 /* Print range (All/Range/Selection) */
1334 if(lppd
->nFromPage
!= 0xffff)
1335 SetDlgItemInt(hDlg
, edt1
, lppd
->nFromPage
, FALSE
);
1336 if(lppd
->nToPage
!= 0xffff)
1337 SetDlgItemInt(hDlg
, edt2
, lppd
->nToPage
, FALSE
);
1339 CheckRadioButton(hDlg
, rad1
, rad3
, rad1
); /* default */
1340 if (lppd
->Flags
& PD_NOSELECTION
)
1341 EnableWindow(GetDlgItem(hDlg
, rad2
), FALSE
);
1343 if (lppd
->Flags
& PD_SELECTION
)
1344 CheckRadioButton(hDlg
, rad1
, rad3
, rad2
);
1345 if (lppd
->Flags
& PD_NOPAGENUMS
) {
1346 EnableWindow(GetDlgItem(hDlg
, rad3
), FALSE
);
1347 EnableWindow(GetDlgItem(hDlg
, stc2
),FALSE
);
1348 EnableWindow(GetDlgItem(hDlg
, edt1
), FALSE
);
1349 EnableWindow(GetDlgItem(hDlg
, stc3
),FALSE
);
1350 EnableWindow(GetDlgItem(hDlg
, edt2
), FALSE
);
1352 if (lppd
->Flags
& PD_PAGENUMS
)
1353 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1358 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1360 if (lppd
->Flags
& PD_COLLATE
) {
1361 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1362 (LPARAM
)PrintStructures
->hCollateIcon
);
1363 CheckDlgButton(hDlg
, chx2
, 1);
1365 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1366 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1367 CheckDlgButton(hDlg
, chx2
, 0);
1370 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1371 /* if printer doesn't support it: no Collate */
1372 if (!(lpdm
->dmFields
& DM_COLLATE
)) {
1373 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1374 EnableWindow(GetDlgItem(hDlg
, ico3
), FALSE
);
1381 if (lppd
->hDevMode
== 0)
1382 copies
= lppd
->nCopies
;
1384 copies
= lpdm
->u1
.s1
.dmCopies
;
1385 if(copies
== 0) copies
= 1;
1386 else if(copies
< 0) copies
= MAX_COPIES
;
1387 SetDlgItemInt(hDlg
, edt3
, copies
, FALSE
);
1390 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1391 /* if printer doesn't support it: no nCopies */
1392 if (!(lpdm
->dmFields
& DM_COPIES
)) {
1393 EnableWindow(GetDlgItem(hDlg
, edt3
), FALSE
);
1394 EnableWindow(GetDlgItem(hDlg
, stc5
), FALSE
);
1399 CheckDlgButton(hDlg
, chx1
, (lppd
->Flags
& PD_PRINTTOFILE
) ? 1 : 0);
1400 if (lppd
->Flags
& PD_DISABLEPRINTTOFILE
)
1401 EnableWindow(GetDlgItem(hDlg
, chx1
), FALSE
);
1402 if (lppd
->Flags
& PD_HIDEPRINTTOFILE
)
1403 ShowWindow(GetDlgItem(hDlg
, chx1
), SW_HIDE
);
1405 } else { /* PD_PRINTSETUP */
1406 BOOL bPortrait
= (lpdm
->u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
);
1408 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb2
,
1409 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1410 PrintStructures
->lpPrinterInfo
->pPortName
,
1412 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb3
,
1413 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1414 PrintStructures
->lpPrinterInfo
->pPortName
,
1416 CheckRadioButton(hDlg
, rad1
, rad2
, bPortrait
? rad1
: rad2
);
1417 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1418 (LPARAM
)(bPortrait
? PrintStructures
->hPortraitIcon
:
1419 PrintStructures
->hLandscapeIcon
));
1424 if ((lppd
->Flags
& PD_SHOWHELP
)==0) {
1425 /* hide if PD_SHOWHELP not specified */
1426 ShowWindow(GetDlgItem(hDlg
, pshHelp
), SW_HIDE
);
1431 /***********************************************************************
1432 * check_printer_setup [internal]
1434 static LRESULT
check_printer_setup(HWND hDlg
)
1437 WCHAR resourcestr
[256],resultstr
[256];
1439 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
1442 EnumPrintersW(PRINTER_ENUM_CONNECTIONS
, NULL
, 2, NULL
, 0, &needed
, &num
);
1448 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEVICES
,resultstr
, 255);
1449 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
,resourcestr
, 255);
1450 MessageBoxW(hDlg
, resultstr
, resourcestr
,MB_OK
| MB_ICONWARNING
);
1455 /***********************************************************************
1456 * PRINTDLG_WMInitDialog [internal]
1458 static LRESULT
PRINTDLG_WMInitDialog(HWND hDlg
,
1459 PRINT_PTRA
* PrintStructures
)
1461 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1465 UINT comboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1467 /* load Collate ICONs */
1468 /* We load these with LoadImage because they are not a standard
1469 size and we don't want them rescaled */
1470 PrintStructures
->hCollateIcon
=
1471 LoadImageA(COMDLG32_hInstance
, "PD32_COLLATE", IMAGE_ICON
, 0, 0, 0);
1472 PrintStructures
->hNoCollateIcon
=
1473 LoadImageA(COMDLG32_hInstance
, "PD32_NOCOLLATE", IMAGE_ICON
, 0, 0, 0);
1475 /* These can be done with LoadIcon */
1476 PrintStructures
->hPortraitIcon
=
1477 LoadIconA(COMDLG32_hInstance
, "PD32_PORTRAIT");
1478 PrintStructures
->hLandscapeIcon
=
1479 LoadIconA(COMDLG32_hInstance
, "PD32_LANDSCAPE");
1481 /* display the collate/no_collate icon */
1482 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1483 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1485 if(PrintStructures
->hCollateIcon
== 0 ||
1486 PrintStructures
->hNoCollateIcon
== 0 ||
1487 PrintStructures
->hPortraitIcon
== 0 ||
1488 PrintStructures
->hLandscapeIcon
== 0) {
1489 ERR("no icon in resource file\n");
1490 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1491 EndDialog(hDlg
, FALSE
);
1495 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1496 * must be registered and the Help button must be shown.
1498 if (lppd
->Flags
& PD_SHOWHELP
) {
1499 if((PrintStructures
->HelpMessageID
=
1500 RegisterWindowMessageA(HELPMSGSTRINGA
)) == 0) {
1501 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL
);
1505 PrintStructures
->HelpMessageID
= 0;
1507 if(!(lppd
->Flags
&PD_PRINTSETUP
)) {
1508 PrintStructures
->hwndUpDown
=
1509 CreateUpDownControl(WS_CHILD
| WS_VISIBLE
| WS_BORDER
|
1510 UDS_NOTHOUSANDS
| UDS_ARROWKEYS
|
1511 UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, 0, 0, 0, 0,
1512 hDlg
, UPDOWN_ID
, COMDLG32_hInstance
,
1513 GetDlgItem(hDlg
, edt3
), MAX_COPIES
, 1, 1);
1516 /* FIXME: I allow more freedom than either Win95 or WinNT,
1517 * which do not agree on what errors should be thrown or not
1518 * in case nToPage or nFromPage is out-of-range.
1520 if (lppd
->nMaxPage
< lppd
->nMinPage
)
1521 lppd
->nMaxPage
= lppd
->nMinPage
;
1522 if (lppd
->nMinPage
== lppd
->nMaxPage
)
1523 lppd
->Flags
|= PD_NOPAGENUMS
;
1524 if (lppd
->nToPage
< lppd
->nMinPage
)
1525 lppd
->nToPage
= lppd
->nMinPage
;
1526 if (lppd
->nToPage
> lppd
->nMaxPage
)
1527 lppd
->nToPage
= lppd
->nMaxPage
;
1528 if (lppd
->nFromPage
< lppd
->nMinPage
)
1529 lppd
->nFromPage
= lppd
->nMinPage
;
1530 if (lppd
->nFromPage
> lppd
->nMaxPage
)
1531 lppd
->nFromPage
= lppd
->nMaxPage
;
1533 /* if we have the combo box, fill it */
1534 if (GetDlgItem(hDlg
,comboID
)) {
1537 pdn
= GlobalLock(lppd
->hDevNames
);
1538 pdm
= GlobalLock(lppd
->hDevMode
);
1540 name
= (char*)pdn
+ pdn
->wDeviceOffset
;
1542 name
= (char*)pdm
->dmDeviceName
;
1543 PRINTDLG_SetUpPrinterListComboA(hDlg
, comboID
, name
);
1544 if(pdm
) GlobalUnlock(lppd
->hDevMode
);
1545 if(pdn
) GlobalUnlock(lppd
->hDevNames
);
1547 /* Now find selected printer and update rest of dlg */
1548 name
= HeapAlloc(GetProcessHeap(),0,256);
1549 if (GetDlgItemTextA(hDlg
, comboID
, name
, 255))
1550 PRINTDLG_ChangePrinterA(hDlg
, name
, PrintStructures
);
1551 HeapFree(GetProcessHeap(),0,name
);
1553 /* else use default printer */
1555 DWORD dwBufLen
= ARRAY_SIZE(name
);
1556 BOOL ret
= GetDefaultPrinterA(name
, &dwBufLen
);
1559 PRINTDLG_ChangePrinterA(hDlg
, name
, PrintStructures
);
1561 FIXME("No default printer found, expect problems!\n");
1566 static LRESULT
PRINTDLG_WMInitDialogW(HWND hDlg
,
1567 PRINT_PTRW
* PrintStructures
)
1569 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1573 UINT comboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1575 /* load Collate ICONs */
1576 /* We load these with LoadImage because they are not a standard
1577 size and we don't want them rescaled */
1578 PrintStructures
->hCollateIcon
=
1579 LoadImageW(COMDLG32_hInstance
, L
"PD32_COLLATE", IMAGE_ICON
, 0, 0, 0);
1580 PrintStructures
->hNoCollateIcon
=
1581 LoadImageW(COMDLG32_hInstance
, L
"PD32_NOCOLLATE", IMAGE_ICON
, 0, 0, 0);
1583 /* These can be done with LoadIcon */
1584 PrintStructures
->hPortraitIcon
=
1585 LoadIconW(COMDLG32_hInstance
, L
"PD32_PORTRAIT");
1586 PrintStructures
->hLandscapeIcon
=
1587 LoadIconW(COMDLG32_hInstance
, L
"PD32_LANDSCAPE");
1589 /* display the collate/no_collate icon */
1590 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1591 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1593 if(PrintStructures
->hCollateIcon
== 0 ||
1594 PrintStructures
->hNoCollateIcon
== 0 ||
1595 PrintStructures
->hPortraitIcon
== 0 ||
1596 PrintStructures
->hLandscapeIcon
== 0) {
1597 ERR("no icon in resource file\n");
1598 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1599 EndDialog(hDlg
, FALSE
);
1603 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1604 * must be registered and the Help button must be shown.
1606 if (lppd
->Flags
& PD_SHOWHELP
) {
1607 if((PrintStructures
->HelpMessageID
=
1608 RegisterWindowMessageW(HELPMSGSTRINGW
)) == 0) {
1609 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL
);
1613 PrintStructures
->HelpMessageID
= 0;
1615 if(!(lppd
->Flags
&PD_PRINTSETUP
)) {
1616 PrintStructures
->hwndUpDown
=
1617 CreateUpDownControl(WS_CHILD
| WS_VISIBLE
| WS_BORDER
|
1618 UDS_NOTHOUSANDS
| UDS_ARROWKEYS
|
1619 UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, 0, 0, 0, 0,
1620 hDlg
, UPDOWN_ID
, COMDLG32_hInstance
,
1621 GetDlgItem(hDlg
, edt3
), MAX_COPIES
, 1, 1);
1624 /* FIXME: I allow more freedom than either Win95 or WinNT,
1625 * which do not agree to what errors should be thrown or not
1626 * in case nToPage or nFromPage is out-of-range.
1628 if (lppd
->nMaxPage
< lppd
->nMinPage
)
1629 lppd
->nMaxPage
= lppd
->nMinPage
;
1630 if (lppd
->nMinPage
== lppd
->nMaxPage
)
1631 lppd
->Flags
|= PD_NOPAGENUMS
;
1632 if (lppd
->nToPage
< lppd
->nMinPage
)
1633 lppd
->nToPage
= lppd
->nMinPage
;
1634 if (lppd
->nToPage
> lppd
->nMaxPage
)
1635 lppd
->nToPage
= lppd
->nMaxPage
;
1636 if (lppd
->nFromPage
< lppd
->nMinPage
)
1637 lppd
->nFromPage
= lppd
->nMinPage
;
1638 if (lppd
->nFromPage
> lppd
->nMaxPage
)
1639 lppd
->nFromPage
= lppd
->nMaxPage
;
1641 /* if we have the combo box, fill it */
1642 if (GetDlgItem(hDlg
,comboID
)) {
1645 pdn
= GlobalLock(lppd
->hDevNames
);
1646 pdm
= GlobalLock(lppd
->hDevMode
);
1648 name
= (WCHAR
*)pdn
+ pdn
->wDeviceOffset
;
1650 name
= pdm
->dmDeviceName
;
1651 PRINTDLG_SetUpPrinterListComboW(hDlg
, comboID
, name
);
1652 if(pdm
) GlobalUnlock(lppd
->hDevMode
);
1653 if(pdn
) GlobalUnlock(lppd
->hDevNames
);
1655 /* Now find selected printer and update rest of dlg */
1656 /* ansi is ok here */
1657 name
= HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR
));
1658 if (GetDlgItemTextW(hDlg
, comboID
, name
, 255))
1659 PRINTDLG_ChangePrinterW(hDlg
, name
, PrintStructures
);
1660 HeapFree(GetProcessHeap(),0,name
);
1662 /* else use default printer */
1664 DWORD dwBufLen
= ARRAY_SIZE(name
);
1665 BOOL ret
= GetDefaultPrinterW(name
, &dwBufLen
);
1668 PRINTDLG_ChangePrinterW(hDlg
, name
, PrintStructures
);
1670 FIXME("No default printer found, expect problems!\n");
1675 /***********************************************************************
1676 * PRINTDLG_WMCommand [internal]
1678 static LRESULT
PRINTDLG_WMCommandA(HWND hDlg
, WPARAM wParam
,
1679 PRINT_PTRA
* PrintStructures
)
1681 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1682 UINT PrinterComboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1683 LPDEVMODEA lpdm
= PrintStructures
->lpDevMode
;
1685 switch (LOWORD(wParam
)) {
1687 TRACE(" OK button was hit\n");
1688 if (!PRINTDLG_UpdatePrintDlgA(hDlg
, PrintStructures
)) {
1689 FIXME("Update printdlg was not successful!\n");
1692 EndDialog(hDlg
, TRUE
);
1696 TRACE(" CANCEL button was hit\n");
1697 EndDialog(hDlg
, FALSE
);
1701 TRACE(" HELP button was hit\n");
1702 SendMessageA(lppd
->hwndOwner
, PrintStructures
->HelpMessageID
,
1703 (WPARAM
) hDlg
, (LPARAM
) lppd
);
1706 case chx2
: /* collate pages checkbox */
1707 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
1708 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1709 (LPARAM
)PrintStructures
->hCollateIcon
);
1711 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1712 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1714 case edt1
: /* from page nr editbox */
1715 case edt2
: /* to page nr editbox */
1716 if (HIWORD(wParam
)==EN_CHANGE
) {
1719 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
1720 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
1721 if (nFromPage
!= lppd
->nFromPage
|| nToPage
!= lppd
->nToPage
)
1722 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1727 if(HIWORD(wParam
) == EN_CHANGE
) {
1728 INT copies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
1730 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1732 EnableWindow(GetDlgItem(hDlg
, chx2
), TRUE
);
1736 case psh2
: /* Properties button */
1739 char PrinterName
[256];
1741 GetDlgItemTextA(hDlg
, PrinterComboID
, PrinterName
, 255);
1742 if (!OpenPrinterA(PrinterName
, &hPrinter
, NULL
)) {
1743 FIXME(" Call to OpenPrinter did not succeed!\n");
1746 DocumentPropertiesA(hDlg
, hPrinter
, PrinterName
,
1747 PrintStructures
->lpDevMode
,
1748 PrintStructures
->lpDevMode
,
1749 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
1750 ClosePrinter(hPrinter
);
1754 case rad1
: /* Paperorientation */
1755 if (lppd
->Flags
& PD_PRINTSETUP
)
1757 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1758 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1759 (LPARAM
)(PrintStructures
->hPortraitIcon
));
1763 case rad2
: /* Paperorientation */
1764 if (lppd
->Flags
& PD_PRINTSETUP
)
1766 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1767 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1768 (LPARAM
)(PrintStructures
->hLandscapeIcon
));
1772 case cmb1
: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT16 */
1773 if (PrinterComboID
!= LOWORD(wParam
)) {
1777 case cmb4
: /* Printer combobox */
1778 if (HIWORD(wParam
)==CBN_SELCHANGE
) {
1780 INT index
= SendDlgItemMessageW(hDlg
, LOWORD(wParam
), CB_GETCURSEL
, 0, 0);
1781 INT length
= SendDlgItemMessageW(hDlg
, LOWORD(wParam
), CB_GETLBTEXTLEN
, index
, 0);
1782 PrinterName
= HeapAlloc(GetProcessHeap(),0,length
+1);
1783 SendDlgItemMessageA(hDlg
, LOWORD(wParam
), CB_GETLBTEXT
, index
, (LPARAM
)PrinterName
);
1784 PRINTDLG_ChangePrinterA(hDlg
, PrinterName
, PrintStructures
);
1785 HeapFree(GetProcessHeap(),0,PrinterName
);
1789 case cmb2
: /* Papersize */
1791 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
1793 lpdm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageA(hDlg
, cmb2
,
1796 GetDlgItemTextA(hDlg
, cmb2
, (char *)lpdm
->dmFormName
, CCHFORMNAME
);
1801 case cmb3
: /* Bin */
1803 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
1805 lpdm
->u1
.s1
.dmDefaultSource
= SendDlgItemMessageA(hDlg
, cmb3
,
1806 CB_GETITEMDATA
, Sel
,
1811 if(lppd
->Flags
& PD_PRINTSETUP
) {
1812 switch (LOWORD(wParam
)) {
1813 case rad1
: /* orientation */
1815 if (IsDlgButtonChecked(hDlg
, rad1
) == BST_CHECKED
) {
1816 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_PORTRAIT
) {
1817 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1818 SendDlgItemMessageA(hDlg
, stc10
, STM_SETIMAGE
, IMAGE_ICON
,
1819 (LPARAM
)PrintStructures
->hPortraitIcon
);
1820 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1821 (LPARAM
)PrintStructures
->hPortraitIcon
);
1824 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_LANDSCAPE
) {
1825 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1826 SendDlgItemMessageA(hDlg
, stc10
, STM_SETIMAGE
, IMAGE_ICON
,
1827 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1828 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1829 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1838 static LRESULT
PRINTDLG_WMCommandW(HWND hDlg
, WPARAM wParam
,
1839 PRINT_PTRW
* PrintStructures
)
1841 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1842 UINT PrinterComboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1843 LPDEVMODEW lpdm
= PrintStructures
->lpDevMode
;
1845 switch (LOWORD(wParam
)) {
1847 TRACE(" OK button was hit\n");
1848 if (!PRINTDLG_UpdatePrintDlgW(hDlg
, PrintStructures
)) {
1849 FIXME("Update printdlg was not successful!\n");
1852 EndDialog(hDlg
, TRUE
);
1856 TRACE(" CANCEL button was hit\n");
1857 EndDialog(hDlg
, FALSE
);
1861 TRACE(" HELP button was hit\n");
1862 SendMessageW(lppd
->hwndOwner
, PrintStructures
->HelpMessageID
,
1863 (WPARAM
) hDlg
, (LPARAM
) lppd
);
1866 case chx2
: /* collate pages checkbox */
1867 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
1868 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1869 (LPARAM
)PrintStructures
->hCollateIcon
);
1871 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1872 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1874 case edt1
: /* from page nr editbox */
1875 case edt2
: /* to page nr editbox */
1876 if (HIWORD(wParam
)==EN_CHANGE
) {
1879 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
1880 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
1881 if (nFromPage
!= lppd
->nFromPage
|| nToPage
!= lppd
->nToPage
)
1882 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1887 if(HIWORD(wParam
) == EN_CHANGE
) {
1888 INT copies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
1890 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1892 EnableWindow(GetDlgItem(hDlg
, chx2
), TRUE
);
1896 case psh2
: /* Properties button */
1899 WCHAR PrinterName
[256];
1901 if (!GetDlgItemTextW(hDlg
, PrinterComboID
, PrinterName
, 255)) break;
1902 if (!OpenPrinterW(PrinterName
, &hPrinter
, NULL
)) {
1903 FIXME(" Call to OpenPrinter did not succeed!\n");
1906 DocumentPropertiesW(hDlg
, hPrinter
, PrinterName
,
1907 PrintStructures
->lpDevMode
,
1908 PrintStructures
->lpDevMode
,
1909 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
1910 ClosePrinter(hPrinter
);
1914 case rad1
: /* Paperorientation */
1915 if (lppd
->Flags
& PD_PRINTSETUP
)
1917 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1918 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1919 (LPARAM
)(PrintStructures
->hPortraitIcon
));
1923 case rad2
: /* Paperorientation */
1924 if (lppd
->Flags
& PD_PRINTSETUP
)
1926 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1927 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1928 (LPARAM
)(PrintStructures
->hLandscapeIcon
));
1932 case cmb1
: /* Printer Combobox in PRINT SETUP */
1934 case cmb4
: /* Printer combobox */
1935 if (HIWORD(wParam
)==CBN_SELCHANGE
) {
1937 INT index
= SendDlgItemMessageW(hDlg
, LOWORD(wParam
), CB_GETCURSEL
, 0, 0);
1938 INT length
= SendDlgItemMessageW(hDlg
, LOWORD(wParam
), CB_GETLBTEXTLEN
, index
, 0);
1940 PrinterName
= HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*(length
+1));
1941 SendDlgItemMessageW(hDlg
, LOWORD(wParam
), CB_GETLBTEXT
, index
, (LPARAM
)PrinterName
);
1942 PRINTDLG_ChangePrinterW(hDlg
, PrinterName
, PrintStructures
);
1943 HeapFree(GetProcessHeap(),0,PrinterName
);
1947 case cmb2
: /* Papersize */
1949 DWORD Sel
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
1951 lpdm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageW(hDlg
, cmb2
,
1954 GetDlgItemTextW(hDlg
, cmb2
, lpdm
->dmFormName
, CCHFORMNAME
);
1959 case cmb3
: /* Bin */
1961 DWORD Sel
= SendDlgItemMessageW(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
1963 lpdm
->u1
.s1
.dmDefaultSource
= SendDlgItemMessageW(hDlg
, cmb3
,
1964 CB_GETITEMDATA
, Sel
,
1969 if(lppd
->Flags
& PD_PRINTSETUP
) {
1970 switch (LOWORD(wParam
)) {
1971 case rad1
: /* orientation */
1973 if (IsDlgButtonChecked(hDlg
, rad1
) == BST_CHECKED
) {
1974 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_PORTRAIT
) {
1975 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1976 SendDlgItemMessageW(hDlg
, stc10
, STM_SETIMAGE
, IMAGE_ICON
,
1977 (LPARAM
)PrintStructures
->hPortraitIcon
);
1978 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1979 (LPARAM
)PrintStructures
->hPortraitIcon
);
1982 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_LANDSCAPE
) {
1983 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1984 SendDlgItemMessageW(hDlg
, stc10
, STM_SETIMAGE
, IMAGE_ICON
,
1985 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1986 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1987 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1996 /***********************************************************************
1997 * PrintDlgProcA [internal]
1999 static INT_PTR CALLBACK
PrintDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
2002 PRINT_PTRA
* PrintStructures
;
2003 INT_PTR res
= FALSE
;
2005 if (uMsg
!=WM_INITDIALOG
) {
2006 PrintStructures
= GetPropW(hDlg
, printdlg_prop
);
2007 if (!PrintStructures
)
2010 PrintStructures
= (PRINT_PTRA
*) lParam
;
2011 SetPropW(hDlg
, printdlg_prop
, PrintStructures
);
2012 if(!check_printer_setup(hDlg
))
2014 EndDialog(hDlg
,FALSE
);
2017 res
= PRINTDLG_WMInitDialog(hDlg
, PrintStructures
);
2019 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
)
2020 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(
2021 hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->lpPrintDlg
2026 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
) {
2027 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
,uMsg
,wParam
,
2034 return PRINTDLG_WMCommandA(hDlg
, wParam
, PrintStructures
);
2037 DestroyIcon(PrintStructures
->hCollateIcon
);
2038 DestroyIcon(PrintStructures
->hNoCollateIcon
);
2039 DestroyIcon(PrintStructures
->hPortraitIcon
);
2040 DestroyIcon(PrintStructures
->hLandscapeIcon
);
2041 if(PrintStructures
->hwndUpDown
)
2042 DestroyWindow(PrintStructures
->hwndUpDown
);
2048 static INT_PTR CALLBACK
PrintDlgProcW(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
2051 PRINT_PTRW
* PrintStructures
;
2052 INT_PTR res
= FALSE
;
2054 if (uMsg
!=WM_INITDIALOG
) {
2055 PrintStructures
= GetPropW(hDlg
, printdlg_prop
);
2056 if (!PrintStructures
)
2059 PrintStructures
= (PRINT_PTRW
*) lParam
;
2060 SetPropW(hDlg
, printdlg_prop
, PrintStructures
);
2061 if(!check_printer_setup(hDlg
))
2063 EndDialog(hDlg
,FALSE
);
2066 res
= PRINTDLG_WMInitDialogW(hDlg
, PrintStructures
);
2068 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
)
2069 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->lpPrintDlg
);
2073 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
) {
2074 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
,uMsg
,wParam
, lParam
);
2080 return PRINTDLG_WMCommandW(hDlg
, wParam
, PrintStructures
);
2083 DestroyIcon(PrintStructures
->hCollateIcon
);
2084 DestroyIcon(PrintStructures
->hNoCollateIcon
);
2085 DestroyIcon(PrintStructures
->hPortraitIcon
);
2086 DestroyIcon(PrintStructures
->hLandscapeIcon
);
2087 if(PrintStructures
->hwndUpDown
)
2088 DestroyWindow(PrintStructures
->hwndUpDown
);
2094 /************************************************************
2096 * PRINTDLG_GetDlgTemplate
2099 static HGLOBAL
PRINTDLG_GetDlgTemplateA(const PRINTDLGA
*lppd
)
2104 if (lppd
->Flags
& PD_PRINTSETUP
) {
2105 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
2106 hDlgTmpl
= lppd
->hSetupTemplate
;
2107 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
2108 hResInfo
= FindResourceA(lppd
->hInstance
,
2109 lppd
->lpSetupTemplateName
, (LPSTR
)RT_DIALOG
);
2110 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
2112 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32_SETUP",
2114 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
2117 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
2118 hDlgTmpl
= lppd
->hPrintTemplate
;
2119 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
2120 hResInfo
= FindResourceA(lppd
->hInstance
,
2121 lppd
->lpPrintTemplateName
,
2123 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
2125 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32",
2127 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
2133 static HGLOBAL
PRINTDLG_GetDlgTemplateW(const PRINTDLGW
*lppd
)
2138 if (lppd
->Flags
& PD_PRINTSETUP
) {
2139 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
2140 hDlgTmpl
= lppd
->hSetupTemplate
;
2141 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
2142 hResInfo
= FindResourceW(lppd
->hInstance
,
2143 lppd
->lpSetupTemplateName
, (LPWSTR
)RT_DIALOG
);
2144 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
2146 hResInfo
= FindResourceW(COMDLG32_hInstance
, L
"PRINT32_SETUP", (LPWSTR
)RT_DIALOG
);
2147 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
2150 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
2151 hDlgTmpl
= lppd
->hPrintTemplate
;
2152 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
2153 hResInfo
= FindResourceW(lppd
->hInstance
,
2154 lppd
->lpPrintTemplateName
,
2156 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
2158 hResInfo
= FindResourceW(COMDLG32_hInstance
, L
"PRINT32", (LPWSTR
)RT_DIALOG
);
2159 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
2165 /***********************************************************************
2170 static BOOL
PRINTDLG_CreateDCA(LPPRINTDLGA lppd
)
2172 DEVNAMES
*pdn
= GlobalLock(lppd
->hDevNames
);
2173 DEVMODEA
*pdm
= GlobalLock(lppd
->hDevMode
);
2175 if(lppd
->Flags
& PD_RETURNDC
) {
2176 lppd
->hDC
= CreateDCA((char*)pdn
+ pdn
->wDriverOffset
,
2177 (char*)pdn
+ pdn
->wDeviceOffset
,
2178 (char*)pdn
+ pdn
->wOutputOffset
,
2180 } else if(lppd
->Flags
& PD_RETURNIC
) {
2181 lppd
->hDC
= CreateICA((char*)pdn
+ pdn
->wDriverOffset
,
2182 (char*)pdn
+ pdn
->wDeviceOffset
,
2183 (char*)pdn
+ pdn
->wOutputOffset
,
2186 GlobalUnlock(lppd
->hDevNames
);
2187 GlobalUnlock(lppd
->hDevMode
);
2188 return lppd
->hDC
!= NULL
;
2191 static BOOL
PRINTDLG_CreateDCW(LPPRINTDLGW lppd
)
2193 DEVNAMES
*pdn
= GlobalLock(lppd
->hDevNames
);
2194 DEVMODEW
*pdm
= GlobalLock(lppd
->hDevMode
);
2196 if(lppd
->Flags
& PD_RETURNDC
) {
2197 lppd
->hDC
= CreateDCW((WCHAR
*)pdn
+ pdn
->wDriverOffset
,
2198 (WCHAR
*)pdn
+ pdn
->wDeviceOffset
,
2199 (WCHAR
*)pdn
+ pdn
->wOutputOffset
,
2201 } else if(lppd
->Flags
& PD_RETURNIC
) {
2202 lppd
->hDC
= CreateICW((WCHAR
*)pdn
+ pdn
->wDriverOffset
,
2203 (WCHAR
*)pdn
+ pdn
->wDeviceOffset
,
2204 (WCHAR
*)pdn
+ pdn
->wOutputOffset
,
2207 GlobalUnlock(lppd
->hDevNames
);
2208 GlobalUnlock(lppd
->hDevMode
);
2209 return lppd
->hDC
!= NULL
;
2212 /***********************************************************************
2213 * PrintDlgA (COMDLG32.@)
2215 * Displays the PRINT dialog box, which enables the user to specify
2216 * specific properties of the print job.
2219 * lppd [IO] ptr to PRINTDLG32 struct
2222 * nonzero if the user pressed the OK button
2223 * zero if the user cancelled the window or an error occurred
2227 * * The Collate Icons do not display, even though they are in the code.
2228 * * The Properties Button(s) should call DocumentPropertiesA().
2231 BOOL WINAPI
PrintDlgA(LPPRINTDLGA lppd
)
2239 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
2243 if(TRACE_ON(commdlg
)) {
2244 char flagstr
[1000] = "";
2245 const struct pd_flags
*pflag
= pd_flags
;
2246 for( ; pflag
->name
; pflag
++) {
2247 if(lppd
->Flags
& pflag
->flag
)
2248 strcat(flagstr
, pflag
->name
);
2250 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2251 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2252 "flags %08x (%s)\n",
2253 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
2254 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
2255 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
2258 if(lppd
->lStructSize
!= sizeof(PRINTDLGA
)) {
2259 WARN("structure size failure!!!\n");
2260 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
2264 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
2265 PRINTER_INFO_2A
*pbuf
;
2266 DRIVER_INFO_3A
*dbuf
;
2270 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
2271 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2272 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2275 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
2276 WARN("Can't find default printer\n");
2277 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
2281 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
2282 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
2283 GetPrinterA(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
2285 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
2286 dbuf
= HeapAlloc(GetProcessHeap(),0,needed
);
2287 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
2288 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2289 GetLastError(),pbuf
->pPrinterName
);
2290 HeapFree(GetProcessHeap(), 0, dbuf
);
2291 HeapFree(GetProcessHeap(), 0, pbuf
);
2292 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2297 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
2301 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
2302 pbuf
->pDevMode
->dmDriverExtra
);
2303 ptr
= GlobalLock(lppd
->hDevMode
);
2304 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
2305 pbuf
->pDevMode
->dmDriverExtra
);
2306 GlobalUnlock(lppd
->hDevMode
);
2307 HeapFree(GetProcessHeap(), 0, pbuf
);
2308 HeapFree(GetProcessHeap(), 0, dbuf
);
2312 PRINT_PTRA
*PrintStructures
;
2314 /* load Dialog resources,
2315 * depending on Flags indicates Print32 or Print32_setup dialog
2317 hDlgTmpl
= PRINTDLG_GetDlgTemplateA(lppd
);
2319 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2322 ptr
= LockResource( hDlgTmpl
);
2324 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2328 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2329 sizeof(PRINT_PTRA
));
2330 PrintStructures
->lpPrintDlg
= lppd
;
2332 /* and create & process the dialog .
2333 * -1 is failure, 0 is broken hwnd, everything else is ok.
2335 hInst
= COMDLG32_hInstance
;
2336 if (lppd
->Flags
& (PD_ENABLESETUPTEMPLATE
| PD_ENABLEPRINTTEMPLATE
)) hInst
= lppd
->hInstance
;
2337 bRet
= (0<DialogBoxIndirectParamA(hInst
, ptr
, lppd
->hwndOwner
,
2339 (LPARAM
)PrintStructures
));
2342 DEVMODEA
*lpdm
= PrintStructures
->lpDevMode
, *lpdmReturn
;
2343 PRINTER_INFO_2A
*pi
= PrintStructures
->lpPrinterInfo
;
2344 DRIVER_INFO_3A
*di
= PrintStructures
->lpDriverInfo
;
2346 if (lppd
->hDevMode
== 0) {
2347 TRACE(" No hDevMode yet... Need to create my own\n");
2348 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
,
2349 lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2351 lppd
->hDevMode
= GlobalReAlloc(lppd
->hDevMode
,
2352 lpdm
->dmSize
+ lpdm
->dmDriverExtra
,
2355 lpdmReturn
= GlobalLock(lppd
->hDevMode
);
2356 memcpy(lpdmReturn
, lpdm
, lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2358 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
2363 GlobalUnlock(lppd
->hDevMode
);
2365 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
2366 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpPrinterInfo
);
2367 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDriverInfo
);
2368 HeapFree(GetProcessHeap(), 0, PrintStructures
);
2370 if(bRet
&& (lppd
->Flags
& PD_RETURNDC
|| lppd
->Flags
& PD_RETURNIC
))
2371 bRet
= PRINTDLG_CreateDCA(lppd
);
2373 TRACE("exit! (%d)\n", bRet
);
2377 /***********************************************************************
2378 * PrintDlgW (COMDLG32.@)
2382 BOOL WINAPI
PrintDlgW(LPPRINTDLGW lppd
)
2390 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
2394 if(TRACE_ON(commdlg
)) {
2395 char flagstr
[1000] = "";
2396 const struct pd_flags
*pflag
= pd_flags
;
2397 for( ; pflag
->name
; pflag
++) {
2398 if(lppd
->Flags
& pflag
->flag
)
2399 strcat(flagstr
, pflag
->name
);
2401 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2402 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2403 "flags %08x (%s)\n",
2404 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
2405 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
2406 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
2409 if(lppd
->lStructSize
!= sizeof(PRINTDLGW
)) {
2410 WARN("structure size failure!!!\n");
2411 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
2415 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
2416 PRINTER_INFO_2W
*pbuf
;
2417 DRIVER_INFO_3W
*dbuf
;
2421 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
2422 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2423 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2426 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
2427 WARN("Can't find default printer\n");
2428 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
2432 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
2433 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
2434 GetPrinterW(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
2436 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
2437 dbuf
= HeapAlloc(GetProcessHeap(),0,needed
);
2438 if (!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
2439 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2440 GetLastError(),debugstr_w(pbuf
->pPrinterName
));
2441 HeapFree(GetProcessHeap(), 0, dbuf
);
2442 HeapFree(GetProcessHeap(), 0, pbuf
);
2443 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2448 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
2452 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
2453 pbuf
->pDevMode
->dmDriverExtra
);
2454 ptr
= GlobalLock(lppd
->hDevMode
);
2455 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
2456 pbuf
->pDevMode
->dmDriverExtra
);
2457 GlobalUnlock(lppd
->hDevMode
);
2458 HeapFree(GetProcessHeap(), 0, pbuf
);
2459 HeapFree(GetProcessHeap(), 0, dbuf
);
2463 PRINT_PTRW
*PrintStructures
;
2465 /* load Dialog resources,
2466 * depending on Flags indicates Print32 or Print32_setup dialog
2468 hDlgTmpl
= PRINTDLG_GetDlgTemplateW(lppd
);
2470 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2473 ptr
= LockResource( hDlgTmpl
);
2475 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2479 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2480 sizeof(PRINT_PTRW
));
2481 PrintStructures
->lpPrintDlg
= lppd
;
2483 /* and create & process the dialog .
2484 * -1 is failure, 0 is broken hwnd, everything else is ok.
2486 hInst
= COMDLG32_hInstance
;
2487 if (lppd
->Flags
& (PD_ENABLESETUPTEMPLATE
| PD_ENABLEPRINTTEMPLATE
)) hInst
= lppd
->hInstance
;
2488 bRet
= (0<DialogBoxIndirectParamW(hInst
, ptr
, lppd
->hwndOwner
,
2490 (LPARAM
)PrintStructures
));
2493 DEVMODEW
*lpdm
= PrintStructures
->lpDevMode
, *lpdmReturn
;
2494 PRINTER_INFO_2W
*pi
= PrintStructures
->lpPrinterInfo
;
2495 DRIVER_INFO_3W
*di
= PrintStructures
->lpDriverInfo
;
2497 if (lppd
->hDevMode
== 0) {
2498 TRACE(" No hDevMode yet... Need to create my own\n");
2499 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
,
2500 lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2503 if((locks
= (GlobalFlags(lppd
->hDevMode
) & GMEM_LOCKCOUNT
))) {
2504 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks
);
2506 GlobalUnlock(lppd
->hDevMode
);
2507 TRACE("Now got %d locks\n", locks
);
2510 lppd
->hDevMode
= GlobalReAlloc(lppd
->hDevMode
,
2511 lpdm
->dmSize
+ lpdm
->dmDriverExtra
,
2514 lpdmReturn
= GlobalLock(lppd
->hDevMode
);
2515 memcpy(lpdmReturn
, lpdm
, lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2517 if (lppd
->hDevNames
!= 0) {
2519 if((locks
= (GlobalFlags(lppd
->hDevNames
) & GMEM_LOCKCOUNT
))) {
2520 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks
);
2522 GlobalUnlock(lppd
->hDevNames
);
2525 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
2530 GlobalUnlock(lppd
->hDevMode
);
2532 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
2533 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpPrinterInfo
);
2534 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDriverInfo
);
2535 HeapFree(GetProcessHeap(), 0, PrintStructures
);
2537 if(bRet
&& (lppd
->Flags
& PD_RETURNDC
|| lppd
->Flags
& PD_RETURNIC
))
2538 bRet
= PRINTDLG_CreateDCW(lppd
);
2540 TRACE("exit! (%d)\n", bRet
);
2544 /***********************************************************************
2549 * cmb1 - printer select (not in standard dialog template)
2551 * cmb3 - source (tray?)
2552 * edt4 - border left
2554 * edt6 - border right
2555 * edt7 - border bottom
2556 * psh3 - "Printer..."
2564 LPPAGESETUPDLGA dlga
;
2565 LPPAGESETUPDLGW dlgw
;
2567 HWND hDlg
; /* Page Setup dialog handle */
2568 RECT rtDrawRect
; /* Drawing rect for page */
2571 static inline DWORD
pagesetup_get_flags(const pagesetup_data
*data
)
2573 return data
->u
.dlgw
->Flags
;
2576 static inline BOOL
is_metric(const pagesetup_data
*data
)
2578 return pagesetup_get_flags(data
) & PSD_INHUNDREDTHSOFMILLIMETERS
;
2581 static inline LONG
tenths_mm_to_size(const pagesetup_data
*data
, LONG size
)
2583 if (is_metric(data
))
2586 return 10 * size
* 100 / 254;
2589 static inline LONG
thousandths_inch_to_size(const pagesetup_data
*data
, LONG size
)
2591 if (is_metric(data
))
2592 return size
* 254 / 100;
2597 static WCHAR
get_decimal_sep(void)
2604 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SDECIMAL
, buf
, ARRAY_SIZE(buf
));
2610 static void size2str(const pagesetup_data
*data
, DWORD size
, LPWSTR strout
)
2612 /* FIXME use LOCALE_SDECIMAL when the edit parsing code can cope */
2614 if (is_metric(data
))
2617 wsprintfW(strout
, L
"%d%c%02d", size
/ 100, get_decimal_sep(), size
% 100);
2619 wsprintfW(strout
, L
"%d", size
/ 100);
2624 wsprintfW(strout
, L
"%d%c%03d", size
/ 1000, get_decimal_sep(), size
% 1000);
2626 wsprintfW(strout
, L
"%d", size
/ 1000);
2631 static inline BOOL
is_default_metric(void)
2634 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_IMEASURE
| LOCALE_RETURN_NUMBER
,
2635 (LPWSTR
)&system
, sizeof(system
));
2639 /**********************************************
2641 * Cyclically permute the four members of rc
2642 * If sense is TRUE l -> t -> r -> b
2643 * otherwise l <- t <- r <- b
2645 static inline void rotate_rect(RECT
*rc
, BOOL sense
)
2651 rc
->bottom
= rc
->right
;
2652 rc
->right
= rc
->top
;
2660 rc
->top
= rc
->right
;
2661 rc
->right
= rc
->bottom
;
2666 static void pagesetup_set_orientation(pagesetup_data
*data
, WORD orient
)
2668 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2670 assert(orient
== DMORIENT_PORTRAIT
|| orient
== DMORIENT_LANDSCAPE
);
2673 dm
->u1
.s1
.dmOrientation
= orient
;
2676 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2677 dmA
->u1
.s1
.dmOrientation
= orient
;
2679 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2682 static WORD
pagesetup_get_orientation(const pagesetup_data
*data
)
2684 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2688 orient
= dm
->u1
.s1
.dmOrientation
;
2691 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2692 orient
= dmA
->u1
.s1
.dmOrientation
;
2694 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2698 static void pagesetup_set_papersize(pagesetup_data
*data
, WORD paper
)
2700 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2703 dm
->u1
.s1
.dmPaperSize
= paper
;
2706 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2707 dmA
->u1
.s1
.dmPaperSize
= paper
;
2709 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2712 static WORD
pagesetup_get_papersize(const pagesetup_data
*data
)
2714 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2718 paper
= dm
->u1
.s1
.dmPaperSize
;
2721 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2722 paper
= dmA
->u1
.s1
.dmPaperSize
;
2724 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2728 static void pagesetup_set_defaultsource(pagesetup_data
*data
, WORD source
)
2730 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2733 dm
->u1
.s1
.dmDefaultSource
= source
;
2736 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2737 dmA
->u1
.s1
.dmDefaultSource
= source
;
2739 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2744 devnames_driver_name
,
2745 devnames_device_name
,
2746 devnames_output_name
2750 static inline WORD
get_devname_offset(const DEVNAMES
*dn
, devnames_name which
)
2754 case devnames_driver_name
: return dn
->wDriverOffset
;
2755 case devnames_device_name
: return dn
->wDeviceOffset
;
2756 case devnames_output_name
: return dn
->wOutputOffset
;
2758 ERR("Shouldn't be here\n");
2762 static WCHAR
*pagesetup_get_a_devname(const pagesetup_data
*data
, devnames_name which
)
2767 dn
= GlobalLock(data
->u
.dlgw
->hDevNames
);
2769 name
= strdupW((WCHAR
*)dn
+ get_devname_offset(dn
, which
));
2772 int len
= MultiByteToWideChar(CP_ACP
, 0, (char*)dn
+ get_devname_offset(dn
, which
), -1, NULL
, 0);
2773 name
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
2774 MultiByteToWideChar(CP_ACP
, 0, (char*)dn
+ get_devname_offset(dn
, which
), -1, name
, len
);
2776 GlobalUnlock(data
->u
.dlgw
->hDevNames
);
2780 static WCHAR
*pagesetup_get_drvname(const pagesetup_data
*data
)
2782 return pagesetup_get_a_devname(data
, devnames_driver_name
);
2785 static WCHAR
*pagesetup_get_devname(const pagesetup_data
*data
)
2787 return pagesetup_get_a_devname(data
, devnames_device_name
);
2790 static WCHAR
*pagesetup_get_portname(const pagesetup_data
*data
)
2792 return pagesetup_get_a_devname(data
, devnames_output_name
);
2795 static void pagesetup_release_a_devname(const pagesetup_data
*data
, WCHAR
*name
)
2797 HeapFree(GetProcessHeap(), 0, name
);
2800 static void pagesetup_set_devnames(pagesetup_data
*data
, LPCWSTR drv
, LPCWSTR devname
, LPCWSTR port
)
2804 DWORD len
= sizeof(DEVNAMES
), drv_len
, dev_len
, port_len
;
2808 drv_len
= (lstrlenW(drv
) + 1) * sizeof(WCHAR
);
2809 dev_len
= (lstrlenW(devname
) + 1) * sizeof(WCHAR
);
2810 port_len
= (lstrlenW(port
) + 1) * sizeof(WCHAR
);
2814 drv_len
= WideCharToMultiByte(CP_ACP
, 0, drv
, -1, NULL
, 0, NULL
, NULL
);
2815 dev_len
= WideCharToMultiByte(CP_ACP
, 0, devname
, -1, NULL
, 0, NULL
, NULL
);
2816 port_len
= WideCharToMultiByte(CP_ACP
, 0, port
, -1, NULL
, 0, NULL
, NULL
);
2818 len
+= drv_len
+ dev_len
+ port_len
;
2820 if(data
->u
.dlgw
->hDevNames
)
2821 data
->u
.dlgw
->hDevNames
= GlobalReAlloc(data
->u
.dlgw
->hDevNames
, len
, GMEM_MOVEABLE
);
2823 data
->u
.dlgw
->hDevNames
= GlobalAlloc(GMEM_MOVEABLE
, len
);
2825 dn
= GlobalLock(data
->u
.dlgw
->hDevNames
);
2829 WCHAR
*ptr
= (WCHAR
*)(dn
+ 1);
2830 len
= sizeof(DEVNAMES
) / sizeof(WCHAR
);
2831 dn
->wDriverOffset
= len
;
2833 ptr
+= drv_len
/ sizeof(WCHAR
);
2834 len
+= drv_len
/ sizeof(WCHAR
);
2835 dn
->wDeviceOffset
= len
;
2836 lstrcpyW(ptr
, devname
);
2837 ptr
+= dev_len
/ sizeof(WCHAR
);
2838 len
+= dev_len
/ sizeof(WCHAR
);
2839 dn
->wOutputOffset
= len
;
2840 lstrcpyW(ptr
, port
);
2844 char *ptr
= (char *)(dn
+ 1);
2845 len
= sizeof(DEVNAMES
);
2846 dn
->wDriverOffset
= len
;
2847 WideCharToMultiByte(CP_ACP
, 0, drv
, -1, ptr
, drv_len
, NULL
, NULL
);
2850 dn
->wDeviceOffset
= len
;
2851 WideCharToMultiByte(CP_ACP
, 0, devname
, -1, ptr
, dev_len
, NULL
, NULL
);
2854 dn
->wOutputOffset
= len
;
2855 WideCharToMultiByte(CP_ACP
, 0, port
, -1, ptr
, port_len
, NULL
, NULL
);
2859 len
= ARRAY_SIZE(def
);
2860 GetDefaultPrinterW(def
, &len
);
2861 if(!lstrcmpW(def
, devname
))
2864 GlobalUnlock(data
->u
.dlgw
->hDevNames
);
2867 static DEVMODEW
*pagesetup_get_devmode(const pagesetup_data
*data
)
2869 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2874 /* We make a copy even in the unicode case because the ptr
2875 may get passed back to us in pagesetup_set_devmode. */
2876 ret
= HeapAlloc(GetProcessHeap(), 0, dm
->dmSize
+ dm
->dmDriverExtra
);
2877 memcpy(ret
, dm
, dm
->dmSize
+ dm
->dmDriverExtra
);
2880 ret
= GdiConvertToDevmodeW((DEVMODEA
*)dm
);
2882 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2886 static void pagesetup_release_devmode(const pagesetup_data
*data
, DEVMODEW
*dm
)
2888 HeapFree(GetProcessHeap(), 0, dm
);
2891 static void pagesetup_set_devmode(pagesetup_data
*data
, DEVMODEW
*dm
)
2893 DEVMODEA
*dmA
= NULL
;
2899 size
= dm
->dmSize
+ dm
->dmDriverExtra
;
2904 dmA
= convert_to_devmodeA(dm
);
2905 size
= dmA
->dmSize
+ dmA
->dmDriverExtra
;
2909 if(data
->u
.dlgw
->hDevMode
)
2910 data
->u
.dlgw
->hDevMode
= GlobalReAlloc(data
->u
.dlgw
->hDevMode
, size
,
2913 data
->u
.dlgw
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, size
);
2915 dst
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2916 memcpy(dst
, src
, size
);
2917 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2918 HeapFree(GetProcessHeap(), 0, dmA
);
2921 static inline POINT
*pagesetup_get_papersize_pt(const pagesetup_data
*data
)
2923 return &data
->u
.dlgw
->ptPaperSize
;
2926 static inline RECT
*pagesetup_get_margin_rect(const pagesetup_data
*data
)
2928 return &data
->u
.dlgw
->rtMargin
;
2937 static inline LPPAGESETUPHOOK
pagesetup_get_hook(const pagesetup_data
*data
, hook_type which
)
2941 case page_setup_hook
: return data
->u
.dlgw
->lpfnPageSetupHook
;
2942 case page_paint_hook
: return data
->u
.dlgw
->lpfnPagePaintHook
;
2947 /* This should only be used in calls to hook procs so we return the ptr
2948 already cast to LPARAM */
2949 static inline LPARAM
pagesetup_get_dlg_struct(const pagesetup_data
*data
)
2951 return (LPARAM
)data
->u
.dlgw
;
2954 static inline void swap_point(POINT
*pt
)
2961 static BOOL
pagesetup_update_papersize(pagesetup_data
*data
)
2964 LPWSTR devname
, portname
;
2966 WORD
*words
= NULL
, paperword
;
2967 POINT
*points
= NULL
;
2968 BOOL retval
= FALSE
;
2970 dm
= pagesetup_get_devmode(data
);
2971 devname
= pagesetup_get_devname(data
);
2972 portname
= pagesetup_get_portname(data
);
2974 num
= DeviceCapabilitiesW(devname
, portname
, DC_PAPERS
, NULL
, dm
);
2977 FIXME("No papernames found for %s/%s\n", debugstr_w(devname
), debugstr_w(portname
));
2981 words
= HeapAlloc(GetProcessHeap(), 0, num
* sizeof(WORD
));
2982 points
= HeapAlloc(GetProcessHeap(), 0, num
* sizeof(POINT
));
2984 if (num
!= DeviceCapabilitiesW(devname
, portname
, DC_PAPERS
, (LPWSTR
)words
, dm
))
2986 FIXME("Number of returned words is not %d\n", num
);
2990 if (num
!= DeviceCapabilitiesW(devname
, portname
, DC_PAPERSIZE
, (LPWSTR
)points
, dm
))
2992 FIXME("Number of returned sizes is not %d\n", num
);
2996 paperword
= pagesetup_get_papersize(data
);
2998 for (i
= 0; i
< num
; i
++)
2999 if (words
[i
] == paperword
)
3004 FIXME("Papersize %d not found in list?\n", paperword
);
3008 /* this is _10ths_ of a millimeter */
3009 pagesetup_get_papersize_pt(data
)->x
= tenths_mm_to_size(data
, points
[i
].x
);
3010 pagesetup_get_papersize_pt(data
)->y
= tenths_mm_to_size(data
, points
[i
].y
);
3012 if(pagesetup_get_orientation(data
) == DMORIENT_LANDSCAPE
)
3013 swap_point(pagesetup_get_papersize_pt(data
));
3018 HeapFree(GetProcessHeap(), 0, words
);
3019 HeapFree(GetProcessHeap(), 0, points
);
3020 pagesetup_release_a_devname(data
, portname
);
3021 pagesetup_release_a_devname(data
, devname
);
3022 pagesetup_release_devmode(data
, dm
);
3027 /**********************************************************************************************
3028 * pagesetup_change_printer
3030 * Redefines hDevMode and hDevNames HANDLES and initialises it.
3033 static BOOL
pagesetup_change_printer(LPWSTR name
, pagesetup_data
*data
)
3037 PRINTER_INFO_2W
*prn_info
= NULL
;
3038 DRIVER_INFO_3W
*drv_info
= NULL
;
3039 DEVMODEW
*dm
= NULL
;
3040 BOOL retval
= FALSE
;
3042 if(!OpenPrinterW(name
, &hprn
, NULL
))
3044 ERR("Can't open printer %s\n", debugstr_w(name
));
3048 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
3049 prn_info
= HeapAlloc(GetProcessHeap(), 0, needed
);
3050 GetPrinterW(hprn
, 2, (LPBYTE
)prn_info
, needed
, &needed
);
3051 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
3052 drv_info
= HeapAlloc(GetProcessHeap(), 0, needed
);
3053 if(!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)drv_info
, needed
, &needed
))
3055 ERR("GetPrinterDriverA failed for %s, fix your config!\n", debugstr_w(prn_info
->pPrinterName
));
3060 needed
= DocumentPropertiesW(0, 0, name
, NULL
, NULL
, 0);
3063 ERR("DocumentProperties fails on %s\n", debugstr_w(name
));
3067 dm
= HeapAlloc(GetProcessHeap(), 0, needed
);
3068 DocumentPropertiesW(0, 0, name
, dm
, NULL
, DM_OUT_BUFFER
);
3070 pagesetup_set_devmode(data
, dm
);
3071 pagesetup_set_devnames(data
, drv_info
->pDriverPath
, prn_info
->pPrinterName
,
3072 prn_info
->pPortName
);
3076 HeapFree(GetProcessHeap(), 0, dm
);
3077 HeapFree(GetProcessHeap(), 0, prn_info
);
3078 HeapFree(GetProcessHeap(), 0, drv_info
);
3082 /****************************************************************************************
3083 * pagesetup_init_combos
3085 * Fills Printers, Paper and Source combos
3088 static void pagesetup_init_combos(HWND hDlg
, pagesetup_data
*data
)
3091 LPWSTR devname
, portname
;
3093 dm
= pagesetup_get_devmode(data
);
3094 devname
= pagesetup_get_devname(data
);
3095 portname
= pagesetup_get_portname(data
);
3097 PRINTDLG_SetUpPrinterListComboW(hDlg
, cmb1
, devname
);
3098 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb2
, devname
, portname
, dm
);
3099 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb3
, devname
, portname
, dm
);
3101 pagesetup_release_a_devname(data
, portname
);
3102 pagesetup_release_a_devname(data
, devname
);
3103 pagesetup_release_devmode(data
, dm
);
3107 /****************************************************************************************
3108 * pagesetup_change_printer_dialog
3110 * Pops up another dialog that lets the user pick another printer.
3112 * For now we display the PrintDlg, this should display a striped down version of it.
3114 static void pagesetup_change_printer_dialog(HWND hDlg
, pagesetup_data
*data
)
3117 LPWSTR drvname
, devname
, portname
;
3118 DEVMODEW
*tmp_dm
, *dm
;
3120 memset(&prnt
, 0, sizeof(prnt
));
3121 prnt
.lStructSize
= sizeof(prnt
);
3123 prnt
.hwndOwner
= hDlg
;
3125 drvname
= pagesetup_get_drvname(data
);
3126 devname
= pagesetup_get_devname(data
);
3127 portname
= pagesetup_get_portname(data
);
3129 PRINTDLG_CreateDevNamesW(&prnt
.hDevNames
, drvname
, devname
, portname
);
3130 pagesetup_release_a_devname(data
, portname
);
3131 pagesetup_release_a_devname(data
, devname
);
3132 pagesetup_release_a_devname(data
, drvname
);
3134 tmp_dm
= pagesetup_get_devmode(data
);
3135 prnt
.hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, tmp_dm
->dmSize
+ tmp_dm
->dmDriverExtra
);
3136 dm
= GlobalLock(prnt
.hDevMode
);
3137 memcpy(dm
, tmp_dm
, tmp_dm
->dmSize
+ tmp_dm
->dmDriverExtra
);
3138 GlobalUnlock(prnt
.hDevMode
);
3139 pagesetup_release_devmode(data
, tmp_dm
);
3141 if (PrintDlgW(&prnt
))
3143 DEVMODEW
*dm
= GlobalLock(prnt
.hDevMode
);
3144 DEVNAMES
*dn
= GlobalLock(prnt
.hDevNames
);
3146 pagesetup_set_devnames(data
, (WCHAR
*)dn
+ dn
->wDriverOffset
,
3147 (WCHAR
*)dn
+ dn
->wDeviceOffset
, (WCHAR
*)dn
+ dn
->wOutputOffset
);
3148 pagesetup_set_devmode(data
, dm
);
3149 GlobalUnlock(prnt
.hDevNames
);
3150 GlobalUnlock(prnt
.hDevMode
);
3151 pagesetup_init_combos(hDlg
, data
);
3154 GlobalFree(prnt
.hDevMode
);
3155 GlobalFree(prnt
.hDevNames
);
3159 /******************************************************************************************
3160 * pagesetup_change_preview
3162 * Changes paper preview size / position
3165 static void pagesetup_change_preview(const pagesetup_data
*data
)
3167 LONG width
, height
, x
, y
;
3169 const int shadow
= 4;
3171 if(pagesetup_get_orientation(data
) == DMORIENT_LANDSCAPE
)
3173 width
= data
->rtDrawRect
.right
- data
->rtDrawRect
.left
;
3174 height
= pagesetup_get_papersize_pt(data
)->y
* width
/ pagesetup_get_papersize_pt(data
)->x
;
3178 height
= data
->rtDrawRect
.bottom
- data
->rtDrawRect
.top
;
3179 width
= pagesetup_get_papersize_pt(data
)->x
* height
/ pagesetup_get_papersize_pt(data
)->y
;
3181 x
= (data
->rtDrawRect
.right
+ data
->rtDrawRect
.left
- width
) / 2;
3182 y
= (data
->rtDrawRect
.bottom
+ data
->rtDrawRect
.top
- height
) / 2;
3183 TRACE("draw rect %s x=%d, y=%d, w=%d, h=%d\n",
3184 wine_dbgstr_rect(&data
->rtDrawRect
), x
, y
, width
, height
);
3186 MoveWindow(GetDlgItem(data
->hDlg
, rct2
), x
+ width
, y
+ shadow
, shadow
, height
, FALSE
);
3187 MoveWindow(GetDlgItem(data
->hDlg
, rct3
), x
+ shadow
, y
+ height
, width
, shadow
, FALSE
);
3188 MoveWindow(GetDlgItem(data
->hDlg
, rct1
), x
, y
, width
, height
, FALSE
);
3190 tmp
= data
->rtDrawRect
;
3191 tmp
.right
+= shadow
;
3192 tmp
.bottom
+= shadow
;
3193 InvalidateRect(data
->hDlg
, &tmp
, TRUE
);
3196 static inline LONG
*element_from_margin_id(RECT
*rc
, WORD id
)
3200 case edt4
: return &rc
->left
;
3201 case edt5
: return &rc
->top
;
3202 case edt6
: return &rc
->right
;
3203 case edt7
: return &rc
->bottom
;
3208 static void update_margin_edits(HWND hDlg
, const pagesetup_data
*data
, WORD id
)
3213 for(idx
= edt4
; idx
<= edt7
; idx
++)
3215 if(id
== 0 || id
== idx
)
3217 size2str(data
, *element_from_margin_id(pagesetup_get_margin_rect(data
), idx
), str
);
3218 SetDlgItemTextW(hDlg
, idx
, str
);
3223 static void margin_edit_notification(HWND hDlg
, const pagesetup_data
*data
, WORD msg
, WORD id
)
3231 LONG
*value
= element_from_margin_id(pagesetup_get_margin_rect(data
), id
);
3233 if (GetDlgItemTextW(hDlg
, id
, buf
, ARRAY_SIZE(buf
)) != 0)
3236 WCHAR decimal
= get_decimal_sep();
3238 val
= wcstol(buf
, &end
, 10);
3239 if(end
!= buf
|| *end
== decimal
)
3241 int mult
= is_metric(data
) ? 100 : 1000;
3250 val
+= (*end
- '0') * mult
;
3262 update_margin_edits(hDlg
, data
, id
);
3267 static void set_margin_groupbox_title(HWND hDlg
, const pagesetup_data
*data
)
3271 if(LoadStringW(COMDLG32_hInstance
, is_metric(data
) ? PD32_MARGINS_IN_MILLIMETERS
: PD32_MARGINS_IN_INCHES
,
3272 title
, ARRAY_SIZE(title
)))
3273 SetDlgItemTextW(hDlg
, grp4
, title
);
3276 static void pagesetup_update_orientation_buttons(HWND hDlg
, const pagesetup_data
*data
)
3278 if (pagesetup_get_orientation(data
) == DMORIENT_LANDSCAPE
)
3279 CheckRadioButton(hDlg
, rad1
, rad2
, rad2
);
3281 CheckRadioButton(hDlg
, rad1
, rad2
, rad1
);
3284 /****************************************************************************************
3285 * pagesetup_printer_properties
3287 * Handle invocation of the 'Properties' button (not present in the default template).
3289 static void pagesetup_printer_properties(HWND hDlg
, pagesetup_data
*data
)
3297 devname
= pagesetup_get_devname(data
);
3299 if (!OpenPrinterW(devname
, &hprn
, NULL
))
3301 FIXME("Call to OpenPrinter did not succeed!\n");
3302 pagesetup_release_a_devname(data
, devname
);
3306 dm
= pagesetup_get_devmode(data
);
3307 DocumentPropertiesW(hDlg
, hprn
, devname
, dm
, dm
, DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
3308 pagesetup_set_devmode(data
, dm
);
3309 pagesetup_release_devmode(data
, dm
);
3310 pagesetup_release_a_devname(data
, devname
);
3313 /* Changing paper */
3314 pagesetup_update_papersize(data
);
3315 pagesetup_update_orientation_buttons(hDlg
, data
);
3317 /* Changing paper preview */
3318 pagesetup_change_preview(data
);
3320 /* Selecting paper in combo */
3321 count
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCOUNT
, 0, 0);
3324 WORD paperword
= pagesetup_get_papersize(data
);
3325 for(i
= 0; i
< count
; i
++)
3327 if(SendDlgItemMessageW(hDlg
, cmb2
, CB_GETITEMDATA
, i
, 0) == paperword
) {
3328 SendDlgItemMessageW(hDlg
, cmb2
, CB_SETCURSEL
, i
, 0);
3335 /********************************************************************************
3336 * pagesetup_wm_command
3337 * process WM_COMMAND message for PageSetupDlg
3340 * hDlg [in] Main dialog HANDLE
3341 * wParam [in] WM_COMMAND wParam
3342 * lParam [in] WM_COMMAND lParam
3343 * pda [in/out] ptr to PageSetupDataA
3346 static BOOL
pagesetup_wm_command(HWND hDlg
, WPARAM wParam
, LPARAM lParam
, pagesetup_data
*data
)
3348 WORD msg
= HIWORD(wParam
);
3349 WORD id
= LOWORD(wParam
);
3351 TRACE("loword (lparam) %d, wparam 0x%lx, lparam %08lx\n",
3352 LOWORD(lParam
),wParam
,lParam
);
3355 EndDialog(hDlg
, TRUE
);
3359 EndDialog(hDlg
, FALSE
);
3362 case psh3
: /* Printer... */
3363 pagesetup_change_printer_dialog(hDlg
, data
);
3366 case rad1
: /* Portrait */
3367 case rad2
: /* Landscape */
3368 if((id
== rad1
&& pagesetup_get_orientation(data
) == DMORIENT_LANDSCAPE
) ||
3369 (id
== rad2
&& pagesetup_get_orientation(data
) == DMORIENT_PORTRAIT
))
3371 pagesetup_set_orientation(data
, (id
== rad1
) ? DMORIENT_PORTRAIT
: DMORIENT_LANDSCAPE
);
3372 pagesetup_update_papersize(data
);
3373 rotate_rect(pagesetup_get_margin_rect(data
), (id
== rad2
));
3374 update_margin_edits(hDlg
, data
, 0);
3375 pagesetup_change_preview(data
);
3378 case cmb1
: /* Printer combo */
3379 if(msg
== CBN_SELCHANGE
)
3382 INT index
= SendDlgItemMessageW(hDlg
, id
, CB_GETCURSEL
, 0, 0);
3383 INT length
= SendDlgItemMessageW(hDlg
, id
, CB_GETLBTEXTLEN
, index
, 0);
3384 name
= HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*(length
+1));
3385 SendDlgItemMessageW(hDlg
, id
, CB_GETLBTEXT
, index
, (LPARAM
)name
);
3386 pagesetup_change_printer(name
, data
);
3387 pagesetup_init_combos(hDlg
, data
);
3388 HeapFree(GetProcessHeap(),0,name
);
3391 case cmb2
: /* Paper combo */
3392 if(msg
== CBN_SELCHANGE
)
3394 DWORD paperword
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETITEMDATA
,
3395 SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0), 0);
3396 if (paperword
!= CB_ERR
)
3398 pagesetup_set_papersize(data
, paperword
);
3399 pagesetup_update_papersize(data
);
3400 pagesetup_change_preview(data
);
3402 FIXME("could not get dialog text for papersize cmbbox?\n");
3405 case cmb3
: /* Paper Source */
3406 if(msg
== CBN_SELCHANGE
)
3408 WORD source
= SendDlgItemMessageW(hDlg
, cmb3
, CB_GETITEMDATA
,
3409 SendDlgItemMessageW(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0), 0);
3410 pagesetup_set_defaultsource(data
, source
);
3413 case psh2
: /* Printer Properties button */
3414 pagesetup_printer_properties(hDlg
, data
);
3420 margin_edit_notification(hDlg
, data
, msg
, id
);
3423 InvalidateRect(GetDlgItem(hDlg
, rct1
), NULL
, TRUE
);
3427 /***********************************************************************
3428 * default_page_paint_hook
3429 * Default hook paint procedure that receives WM_PSD_* messages from the dialog box
3430 * whenever the sample page is redrawn.
3432 static UINT_PTR
default_page_paint_hook(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
,
3433 const pagesetup_data
*data
)
3435 LPRECT lprc
= (LPRECT
) lParam
;
3436 HDC hdc
= (HDC
) wParam
;
3439 HFONT hfont
, holdfont
;
3441 TRACE("uMsg: WM_USER+%d\n",uMsg
-WM_USER
);
3442 /* Call user paint hook if enable */
3443 if (pagesetup_get_flags(data
) & PSD_ENABLEPAGEPAINTHOOK
)
3444 if (pagesetup_get_hook(data
, page_paint_hook
)(hwndDlg
, uMsg
, wParam
, lParam
))
3448 /* LPPAGESETUPDLG in lParam */
3449 case WM_PSD_PAGESETUPDLG
:
3450 /* Inform about the sample page rectangle */
3451 case WM_PSD_FULLPAGERECT
:
3452 /* Inform about the margin rectangle */
3453 case WM_PSD_MINMARGINRECT
:
3456 /* Draw dashed rectangle showing margins */
3457 case WM_PSD_MARGINRECT
:
3458 hpen
= CreatePen(PS_DASH
, 1, GetSysColor(COLOR_3DSHADOW
));
3459 holdpen
= SelectObject(hdc
, hpen
);
3460 Rectangle(hdc
, lprc
->left
, lprc
->top
, lprc
->right
, lprc
->bottom
);
3461 DeleteObject(SelectObject(hdc
, holdpen
));
3463 /* Draw the fake document */
3464 case WM_PSD_GREEKTEXTRECT
:
3465 /* select a nice scalable font, because we want the text really small */
3466 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, sizeof(lf
), &lf
, 0);
3467 lf
.lfHeight
= 6; /* value chosen based on visual effect */
3468 hfont
= CreateFontIndirectW(&lf
);
3469 holdfont
= SelectObject(hdc
, hfont
);
3471 /* if text not loaded, then do so now */
3472 if (wszFakeDocumentText
[0] == '\0')
3473 LoadStringW(COMDLG32_hInstance
,
3475 wszFakeDocumentText
,
3476 ARRAY_SIZE(wszFakeDocumentText
));
3478 oldbkmode
= SetBkMode(hdc
, TRANSPARENT
);
3479 DrawTextW(hdc
, wszFakeDocumentText
, -1, lprc
, DT_TOP
|DT_LEFT
|DT_NOPREFIX
|DT_WORDBREAK
);
3480 SetBkMode(hdc
, oldbkmode
);
3482 DeleteObject(SelectObject(hdc
, holdfont
));
3485 /* Envelope stamp */
3486 case WM_PSD_ENVSTAMPRECT
:
3487 /* Return address */
3488 case WM_PSD_YAFULLPAGERECT
:
3489 FIXME("envelope/stamp is not implemented\n");
3492 FIXME("Unknown message %x\n",uMsg
);
3498 /***********************************************************************
3500 * The main paint procedure for the PageSetupDlg function.
3501 * The Page Setup dialog box includes an image of a sample page that shows how
3502 * the user's selections affect the appearance of the printed output.
3503 * The image consists of a rectangle that represents the selected paper
3504 * or envelope type, with a dotted-line rectangle representing
3505 * the current margins, and partial (Greek text) characters
3506 * to show how text looks on the printed page.
3508 * The following messages in the order sends to user hook procedure:
3509 * WM_PSD_PAGESETUPDLG Draw the contents of the sample page
3510 * WM_PSD_FULLPAGERECT Inform about the bounding rectangle
3511 * WM_PSD_MINMARGINRECT Inform about the margin rectangle (min margin?)
3512 * WM_PSD_MARGINRECT Draw the margin rectangle
3513 * WM_PSD_GREEKTEXTRECT Draw the Greek text inside the margin rectangle
3514 * If any of first three messages returns TRUE, painting done.
3517 * hWnd [in] Handle to the Page Setup dialog box
3518 * uMsg [in] Received message
3521 * WM_PSD_ENVSTAMPRECT Draw in the envelope-stamp rectangle (for envelopes only)
3522 * WM_PSD_YAFULLPAGERECT Draw the return address portion (for envelopes and other paper sizes)
3525 * FALSE if all done correctly
3530 static LRESULT CALLBACK
3531 PRINTDLG_PagePaintProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3534 RECT rcClient
, rcMargin
;
3537 HBRUSH hbrush
, holdbrush
;
3538 pagesetup_data
*data
;
3539 int papersize
=0, orientation
=0; /* FIXME: set these values for the user paint hook */
3540 double scalx
, scaly
;
3542 if (uMsg
!= WM_PAINT
)
3543 return CallWindowProcA(lpfnStaticWndProc
, hWnd
, uMsg
, wParam
, lParam
);
3545 /* Processing WM_PAINT message */
3546 data
= GetPropW(hWnd
, pagesetupdlg_prop
);
3548 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3551 if (default_page_paint_hook(hWnd
, WM_PSD_PAGESETUPDLG
, MAKELONG(papersize
, orientation
),
3552 pagesetup_get_dlg_struct(data
), data
))
3555 hdc
= BeginPaint(hWnd
, &ps
);
3556 GetClientRect(hWnd
, &rcClient
);
3558 scalx
= rcClient
.right
/ (double)pagesetup_get_papersize_pt(data
)->x
;
3559 scaly
= rcClient
.bottom
/ (double)pagesetup_get_papersize_pt(data
)->y
;
3560 rcMargin
= rcClient
;
3562 rcMargin
.left
+= pagesetup_get_margin_rect(data
)->left
* scalx
;
3563 rcMargin
.top
+= pagesetup_get_margin_rect(data
)->top
* scaly
;
3564 rcMargin
.right
-= pagesetup_get_margin_rect(data
)->right
* scalx
;
3565 rcMargin
.bottom
-= pagesetup_get_margin_rect(data
)->bottom
* scaly
;
3567 /* if the space is too small then we make sure to not draw anything */
3568 rcMargin
.left
= min(rcMargin
.left
, rcMargin
.right
);
3569 rcMargin
.top
= min(rcMargin
.top
, rcMargin
.bottom
);
3571 if (!default_page_paint_hook(hWnd
, WM_PSD_FULLPAGERECT
, (WPARAM
)hdc
, (LPARAM
)&rcClient
, data
) &&
3572 !default_page_paint_hook(hWnd
, WM_PSD_MINMARGINRECT
, (WPARAM
)hdc
, (LPARAM
)&rcMargin
, data
) )
3574 /* fill background */
3575 hbrush
= GetSysColorBrush(COLOR_3DHIGHLIGHT
);
3576 FillRect(hdc
, &rcClient
, hbrush
);
3577 holdbrush
= SelectObject(hdc
, hbrush
);
3579 hpen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DSHADOW
));
3580 holdpen
= SelectObject(hdc
, hpen
);
3582 /* paint left edge */
3583 MoveToEx(hdc
, rcClient
.left
, rcClient
.top
, NULL
);
3584 LineTo(hdc
, rcClient
.left
, rcClient
.bottom
-1);
3586 /* paint top edge */
3587 MoveToEx(hdc
, rcClient
.left
, rcClient
.top
, NULL
);
3588 LineTo(hdc
, rcClient
.right
, rcClient
.top
);
3590 hpen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DDKSHADOW
));
3591 DeleteObject(SelectObject(hdc
, hpen
));
3593 /* paint right edge */
3594 MoveToEx(hdc
, rcClient
.right
-1, rcClient
.top
, NULL
);
3595 LineTo(hdc
, rcClient
.right
-1, rcClient
.bottom
);
3597 /* paint bottom edge */
3598 MoveToEx(hdc
, rcClient
.left
, rcClient
.bottom
-1, NULL
);
3599 LineTo(hdc
, rcClient
.right
, rcClient
.bottom
-1);
3601 DeleteObject(SelectObject(hdc
, holdpen
));
3602 DeleteObject(SelectObject(hdc
, holdbrush
));
3604 default_page_paint_hook(hWnd
, WM_PSD_MARGINRECT
, (WPARAM
)hdc
, (LPARAM
)&rcMargin
, data
);
3606 /* give text a bit of a space from the frame */
3607 InflateRect(&rcMargin
, -2, -2);
3609 /* if the space is too small then we make sure to not draw anything */
3610 rcMargin
.left
= min(rcMargin
.left
, rcMargin
.right
);
3611 rcMargin
.top
= min(rcMargin
.top
, rcMargin
.bottom
);
3613 default_page_paint_hook(hWnd
, WM_PSD_GREEKTEXTRECT
, (WPARAM
)hdc
, (LPARAM
)&rcMargin
, data
);
3616 EndPaint(hWnd
, &ps
);
3620 /*******************************************************
3621 * The margin edit controls are subclassed to filter
3622 * anything other than numbers and the decimal separator.
3624 static LRESULT CALLBACK
pagesetup_margin_editproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3628 WCHAR decimal
= get_decimal_sep();
3629 WCHAR wc
= (WCHAR
)wparam
;
3630 if(!iswdigit(wc
) && wc
!= decimal
&& wc
!= VK_BACK
) return 0;
3632 return CallWindowProcW(edit_wndproc
, hwnd
, msg
, wparam
, lparam
);
3635 static void subclass_margin_edits(HWND hDlg
)
3640 for(id
= edt4
; id
<= edt7
; id
++)
3642 old_proc
= (WNDPROC
)SetWindowLongPtrW(GetDlgItem(hDlg
, id
),
3644 (ULONG_PTR
)pagesetup_margin_editproc
);
3645 InterlockedCompareExchangePointer((void**)&edit_wndproc
, old_proc
, NULL
);
3649 /***********************************************************************
3650 * pagesetup_dlg_proc
3652 * Message handler for PageSetupDlg
3654 static INT_PTR CALLBACK
pagesetup_dlg_proc(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3656 pagesetup_data
*data
;
3657 INT_PTR res
= FALSE
;
3660 if (uMsg
== WM_INITDIALOG
) { /*Init dialog*/
3661 data
= (pagesetup_data
*)lParam
;
3664 hDrawWnd
= GetDlgItem(hDlg
, rct1
);
3665 TRACE("set property to %p\n", data
);
3666 SetPropW(hDlg
, pagesetupdlg_prop
, data
);
3667 SetPropW(hDrawWnd
, pagesetupdlg_prop
, data
);
3668 GetWindowRect(hDrawWnd
, &data
->rtDrawRect
); /* Calculating rect in client coordinates where paper draws */
3669 MapWindowPoints( 0, hDlg
, (LPPOINT
)&data
->rtDrawRect
, 2 );
3670 lpfnStaticWndProc
= (WNDPROC
)SetWindowLongPtrW(
3673 (ULONG_PTR
)PRINTDLG_PagePaintProc
);
3675 /* FIXME: Paint hook. Must it be at begin of initialization or at end? */
3677 if (pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPHOOK
)
3679 if (!pagesetup_get_hook(data
, page_setup_hook
)(hDlg
, uMsg
, wParam
,
3680 pagesetup_get_dlg_struct(data
)))
3681 FIXME("Setup page hook failed?\n");
3684 /* if printer button disabled */
3685 if (pagesetup_get_flags(data
) & PSD_DISABLEPRINTER
)
3686 EnableWindow(GetDlgItem(hDlg
, psh3
), FALSE
);
3687 /* if margin edit boxes disabled */
3688 if (pagesetup_get_flags(data
) & PSD_DISABLEMARGINS
)
3690 EnableWindow(GetDlgItem(hDlg
, edt4
), FALSE
);
3691 EnableWindow(GetDlgItem(hDlg
, edt5
), FALSE
);
3692 EnableWindow(GetDlgItem(hDlg
, edt6
), FALSE
);
3693 EnableWindow(GetDlgItem(hDlg
, edt7
), FALSE
);
3696 /* Set orientation radiobuttons properly */
3697 pagesetup_update_orientation_buttons(hDlg
, data
);
3699 /* if orientation disabled */
3700 if (pagesetup_get_flags(data
) & PSD_DISABLEORIENTATION
)
3702 EnableWindow(GetDlgItem(hDlg
,rad1
),FALSE
);
3703 EnableWindow(GetDlgItem(hDlg
,rad2
),FALSE
);
3706 /* We fill them out enabled or not */
3707 if (!(pagesetup_get_flags(data
) & PSD_MARGINS
))
3709 /* default is 1 inch */
3710 LONG size
= thousandths_inch_to_size(data
, 1000);
3711 SetRect(pagesetup_get_margin_rect(data
), size
, size
, size
, size
);
3713 update_margin_edits(hDlg
, data
, 0);
3714 subclass_margin_edits(hDlg
);
3715 set_margin_groupbox_title(hDlg
, data
);
3717 /* if paper disabled */
3718 if (pagesetup_get_flags(data
) & PSD_DISABLEPAPER
)
3720 EnableWindow(GetDlgItem(hDlg
,cmb2
),FALSE
);
3721 EnableWindow(GetDlgItem(hDlg
,cmb3
),FALSE
);
3724 /* filling combos: printer, paper, source. selecting current printer (from DEVMODEA) */
3725 pagesetup_init_combos(hDlg
, data
);
3726 pagesetup_update_papersize(data
);
3727 pagesetup_set_defaultsource(data
, DMBIN_FORMSOURCE
); /* FIXME: This is the auto select bin. Is this correct? */
3729 /* Drawing paper prev */
3730 pagesetup_change_preview(data
);
3733 data
= GetPropW(hDlg
, pagesetupdlg_prop
);
3736 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3739 if (pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPHOOK
)
3741 res
= pagesetup_get_hook(data
, page_setup_hook
)(hDlg
, uMsg
, wParam
, lParam
);
3742 if (res
) return res
;
3747 return pagesetup_wm_command(hDlg
, wParam
, lParam
, data
);
3752 static WCHAR
*get_default_printer(void)
3757 GetDefaultPrinterW(NULL
, &len
);
3760 name
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3761 GetDefaultPrinterW(name
, &len
);
3766 static void pagesetup_dump_dlg_struct(const pagesetup_data
*data
)
3768 if(TRACE_ON(commdlg
))
3770 char flagstr
[1000] = "";
3771 const struct pd_flags
*pflag
= psd_flags
;
3772 for( ; pflag
->name
; pflag
++)
3774 if(pagesetup_get_flags(data
) & pflag
->flag
)
3776 strcat(flagstr
, pflag
->name
);
3777 strcat(flagstr
, "|");
3780 TRACE("%s: (%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3781 "hinst %p, flags %08x (%s)\n",
3782 data
->unicode
? "unicode" : "ansi",
3783 data
->u
.dlgw
, data
->u
.dlgw
->hwndOwner
, data
->u
.dlgw
->hDevMode
,
3784 data
->u
.dlgw
->hDevNames
, data
->u
.dlgw
->hInstance
,
3785 pagesetup_get_flags(data
), flagstr
);
3789 static void *pagesetup_get_template(pagesetup_data
*data
)
3792 HGLOBAL tmpl_handle
;
3794 if(pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPTEMPLATEHANDLE
)
3796 tmpl_handle
= data
->u
.dlgw
->hPageSetupTemplate
;
3798 else if(pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPTEMPLATE
)
3801 res
= FindResourceW(data
->u
.dlgw
->hInstance
,
3802 data
->u
.dlgw
->lpPageSetupTemplateName
, (LPWSTR
)RT_DIALOG
);
3804 res
= FindResourceA(data
->u
.dlga
->hInstance
,
3805 data
->u
.dlga
->lpPageSetupTemplateName
, (LPSTR
)RT_DIALOG
);
3806 tmpl_handle
= LoadResource(data
->u
.dlgw
->hInstance
, res
);
3810 res
= FindResourceW(COMDLG32_hInstance
, MAKEINTRESOURCEW(PAGESETUPDLGORD
),
3812 tmpl_handle
= LoadResource(COMDLG32_hInstance
, res
);
3814 return LockResource(tmpl_handle
);
3817 static BOOL
pagesetup_common(pagesetup_data
*data
)
3822 if(!pagesetup_get_dlg_struct(data
))
3824 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
3828 pagesetup_dump_dlg_struct(data
);
3830 if(data
->u
.dlgw
->lStructSize
!= sizeof(PAGESETUPDLGW
))
3832 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
3836 if ((pagesetup_get_flags(data
) & PSD_ENABLEPAGEPAINTHOOK
) &&
3837 (pagesetup_get_hook(data
, page_paint_hook
) == NULL
))
3839 COMDLG32_SetCommDlgExtendedError(CDERR_NOHOOK
);
3843 if(!(pagesetup_get_flags(data
) & (PSD_INTHOUSANDTHSOFINCHES
| PSD_INHUNDREDTHSOFMILLIMETERS
)))
3844 data
->u
.dlgw
->Flags
|= is_default_metric() ?
3845 PSD_INHUNDREDTHSOFMILLIMETERS
: PSD_INTHOUSANDTHSOFINCHES
;
3847 if (!data
->u
.dlgw
->hDevMode
|| !data
->u
.dlgw
->hDevNames
)
3849 WCHAR
*def
= get_default_printer();
3852 if (!(pagesetup_get_flags(data
) & PSD_NOWARNING
))
3855 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEFAULT_PRINTER
, errstr
, 255);
3856 MessageBoxW(data
->u
.dlgw
->hwndOwner
, errstr
, 0, MB_OK
| MB_ICONERROR
);
3858 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
3861 pagesetup_change_printer(def
, data
);
3862 HeapFree(GetProcessHeap(), 0, def
);
3865 if (pagesetup_get_flags(data
) & PSD_RETURNDEFAULT
)
3867 pagesetup_update_papersize(data
);
3871 tmpl
= pagesetup_get_template(data
);
3873 ret
= DialogBoxIndirectParamW(data
->u
.dlgw
->hInstance
, tmpl
,
3874 data
->u
.dlgw
->hwndOwner
,
3875 pagesetup_dlg_proc
, (LPARAM
)data
) > 0;
3879 /***********************************************************************
3880 * PageSetupDlgA (COMDLG32.@)
3882 * Displays the PAGE SETUP dialog box, which enables the user to specify
3883 * specific properties of a printed page such as
3884 * size, source, orientation and the width of the page margins.
3887 * setupdlg [IO] PAGESETUPDLGA struct
3890 * TRUE if the user pressed the OK button
3891 * FALSE if the user cancelled the window or an error occurred
3894 * The values of hDevMode and hDevNames are filled on output and can be
3895 * changed in PAGESETUPDLG when they are passed in PageSetupDlg.
3898 BOOL WINAPI
PageSetupDlgA(LPPAGESETUPDLGA setupdlg
)
3900 pagesetup_data data
;
3902 data
.unicode
= FALSE
;
3903 data
.u
.dlga
= setupdlg
;
3905 return pagesetup_common(&data
);
3908 /***********************************************************************
3909 * PageSetupDlgW (COMDLG32.@)
3911 * See PageSetupDlgA.
3913 BOOL WINAPI
PageSetupDlgW(LPPAGESETUPDLGW setupdlg
)
3915 pagesetup_data data
;
3917 data
.unicode
= TRUE
;
3918 data
.u
.dlgw
= setupdlg
;
3920 return pagesetup_common(&data
);
3923 static void pdlgex_to_pdlg(const PRINTDLGEXW
*pdlgex
, PRINTDLGW
*pdlg
)
3925 pdlg
->lStructSize
= sizeof(*pdlg
);
3926 pdlg
->hwndOwner
= pdlgex
->hwndOwner
;
3927 pdlg
->hDevMode
= pdlgex
->hDevMode
;
3928 pdlg
->hDevNames
= pdlgex
->hDevNames
;
3929 pdlg
->hDC
= pdlgex
->hDC
;
3930 pdlg
->Flags
= pdlgex
->Flags
;
3931 if ((pdlgex
->Flags
& PD_NOPAGENUMS
) || !pdlgex
->nPageRanges
|| !pdlgex
->lpPageRanges
)
3933 pdlg
->nFromPage
= 0;
3934 pdlg
->nToPage
= 65534;
3938 pdlg
->nFromPage
= pdlgex
->lpPageRanges
[0].nFromPage
;
3939 pdlg
->nToPage
= pdlgex
->lpPageRanges
[0].nToPage
;
3941 pdlg
->nMinPage
= pdlgex
->nMinPage
;
3942 pdlg
->nMaxPage
= pdlgex
->nMaxPage
;
3943 pdlg
->nCopies
= pdlgex
->nCopies
;
3944 pdlg
->hInstance
= pdlgex
->hInstance
;
3945 pdlg
->lCustData
= 0;
3946 pdlg
->lpfnPrintHook
= NULL
;
3947 pdlg
->lpfnSetupHook
= NULL
;
3948 pdlg
->lpPrintTemplateName
= pdlgex
->lpPrintTemplateName
;
3949 pdlg
->lpSetupTemplateName
= NULL
;
3950 pdlg
->hPrintTemplate
= NULL
;
3951 pdlg
->hSetupTemplate
= NULL
;
3954 /* Only copy fields that are supposed to be changed. */
3955 static void pdlg_to_pdlgex(const PRINTDLGW
*pdlg
, PRINTDLGEXW
*pdlgex
)
3957 pdlgex
->hDevMode
= pdlg
->hDevMode
;
3958 pdlgex
->hDevNames
= pdlg
->hDevNames
;
3959 pdlgex
->hDC
= pdlg
->hDC
;
3960 if (!(pdlgex
->Flags
& PD_NOPAGENUMS
) && pdlgex
->nPageRanges
&& pdlgex
->lpPageRanges
)
3962 pdlgex
->lpPageRanges
[0].nFromPage
= pdlg
->nFromPage
;
3963 pdlgex
->lpPageRanges
[0].nToPage
= pdlg
->nToPage
;
3965 pdlgex
->nMinPage
= pdlg
->nMinPage
;
3966 pdlgex
->nMaxPage
= pdlg
->nMaxPage
;
3967 pdlgex
->nCopies
= pdlg
->nCopies
;
3970 struct callback_data
3972 IPrintDialogCallback
*callback
;
3973 IObjectWithSite
*object
;
3976 static UINT_PTR CALLBACK
pdlgex_hook_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
3978 if (msg
== WM_INITDIALOG
)
3980 PRINTDLGW
*pd
= (PRINTDLGW
*)lp
;
3981 struct callback_data
*cb
= (struct callback_data
*)pd
->lCustData
;
3985 cb
->callback
->lpVtbl
->SelectionChange(cb
->callback
);
3986 cb
->callback
->lpVtbl
->InitDone(cb
->callback
);
3991 /* FIXME: store interface pointer somewhere in window properties and call it
3993 cb->callback->lpVtbl->HandleMessage(cb->callback, hwnd, msg, wp, lp, &hres);
4000 /***********************************************************************
4001 * PrintDlgExA (COMDLG32.@)
4009 HRESULT WINAPI
PrintDlgExA(LPPRINTDLGEXA lppd
)
4011 PRINTER_INFO_2A
*pbuf
;
4012 DRIVER_INFO_3A
*dbuf
;
4017 if ((lppd
== NULL
) || (lppd
->lStructSize
!= sizeof(PRINTDLGEXA
)))
4018 return E_INVALIDARG
;
4020 if (!IsWindow(lppd
->hwndOwner
))
4023 if (lppd
->nStartPage
!= START_PAGE_GENERAL
)
4025 if (!lppd
->nPropertyPages
)
4026 return E_INVALIDARG
;
4028 FIXME("custom property sheets (%d at %p) not supported\n", lppd
->nPropertyPages
, lppd
->lphPropertyPages
);
4031 /* Use PD_NOPAGENUMS or set nMaxPageRanges and lpPageRanges */
4032 if (!(lppd
->Flags
& PD_NOPAGENUMS
) && (!lppd
->nMaxPageRanges
|| !lppd
->lpPageRanges
))
4034 return E_INVALIDARG
;
4037 if (lppd
->Flags
& PD_RETURNDEFAULT
)
4039 if (lppd
->hDevMode
|| lppd
->hDevNames
)
4041 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
4042 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
4043 return E_INVALIDARG
;
4045 if (!PRINTDLG_OpenDefaultPrinter(&hprn
))
4047 WARN("Can't find default printer\n");
4048 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
4052 pbuf
= get_printer_infoA(hprn
);
4059 dbuf
= get_driver_infoA(hprn
);
4062 HeapFree(GetProcessHeap(), 0, pbuf
);
4063 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
4067 dm
= pbuf
->pDevMode
;
4072 struct callback_data cb_data
= { 0 };
4074 FIXME("(%p) semi-stub\n", lppd
);
4076 if (lppd
->lpCallback
)
4078 IUnknown_QueryInterface((IUnknown
*)lppd
->lpCallback
, &IID_IPrintDialogCallback
, (void **)&cb_data
.callback
);
4079 IUnknown_QueryInterface((IUnknown
*)lppd
->lpCallback
, &IID_IObjectWithSite
, (void **)&cb_data
.object
);
4083 * PRINTDLGEXA/W and PRINTDLGA/W layout is the same for A and W variants.
4085 pdlgex_to_pdlg((const PRINTDLGEXW
*)lppd
, (PRINTDLGW
*)&pdlg
);
4086 pdlg
.Flags
|= PD_ENABLEPRINTHOOK
;
4087 pdlg
.lpfnPrintHook
= pdlgex_hook_proc
;
4088 pdlg
.lCustData
= (LPARAM
)&cb_data
;
4090 if (PrintDlgA(&pdlg
))
4092 pdlg_to_pdlgex((const PRINTDLGW
*)&pdlg
, (PRINTDLGEXW
*)lppd
);
4093 lppd
->dwResultAction
= PD_RESULT_PRINT
;
4096 lppd
->dwResultAction
= PD_RESULT_CANCEL
;
4098 if (cb_data
.callback
)
4099 cb_data
.callback
->lpVtbl
->Release(cb_data
.callback
);
4101 cb_data
.object
->lpVtbl
->Release(cb_data
.object
);
4108 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
), dbuf
->pDriverPath
, pbuf
->pPrinterName
, pbuf
->pPortName
);
4109 if (!lppd
->hDevNames
)
4112 lppd
->hDevMode
= update_devmode_handleA(lppd
->hDevMode
, dm
);
4113 if (hr
== S_OK
&& lppd
->hDevMode
) {
4114 if (lppd
->Flags
& PD_RETURNDC
) {
4115 lppd
->hDC
= CreateDCA(dbuf
->pDriverPath
, pbuf
->pPrinterName
, pbuf
->pPortName
, dm
);
4119 else if (lppd
->Flags
& PD_RETURNIC
) {
4120 lppd
->hDC
= CreateICA(dbuf
->pDriverPath
, pbuf
->pPrinterName
, pbuf
->pPortName
, dm
);
4128 HeapFree(GetProcessHeap(), 0, pbuf
);
4129 HeapFree(GetProcessHeap(), 0, dbuf
);
4134 /***********************************************************************
4135 * PrintDlgExW (COMDLG32.@)
4137 * Display the property sheet style PRINT dialog box
4140 * lppd [IO] ptr to PRINTDLGEX struct
4144 * Failure: One of the following COM error codes:
4145 * E_OUTOFMEMORY Insufficient memory.
4146 * E_INVALIDARG One or more arguments are invalid.
4147 * E_POINTER Invalid pointer.
4148 * E_HANDLE Invalid handle.
4149 * E_FAIL Unspecified error.
4152 * This Dialog enables the user to specify specific properties of the print job.
4153 * The property sheet can also have additional application-specific and
4154 * driver-specific property pages.
4157 * Not fully implemented
4160 HRESULT WINAPI
PrintDlgExW(LPPRINTDLGEXW lppd
)
4162 PRINTER_INFO_2W
*pbuf
;
4163 DRIVER_INFO_3W
*dbuf
;
4168 if ((lppd
== NULL
) || (lppd
->lStructSize
!= sizeof(PRINTDLGEXW
))) {
4169 return E_INVALIDARG
;
4172 if (!IsWindow(lppd
->hwndOwner
)) {
4176 if (lppd
->nStartPage
!= START_PAGE_GENERAL
)
4178 if (!lppd
->nPropertyPages
)
4179 return E_INVALIDARG
;
4181 FIXME("custom property sheets (%d at %p) not supported\n", lppd
->nPropertyPages
, lppd
->lphPropertyPages
);
4184 /* Use PD_NOPAGENUMS or set nMaxPageRanges and lpPageRanges */
4185 if (!(lppd
->Flags
& PD_NOPAGENUMS
) && (!lppd
->nMaxPageRanges
|| !lppd
->lpPageRanges
))
4187 return E_INVALIDARG
;
4190 if (lppd
->Flags
& PD_RETURNDEFAULT
) {
4192 if (lppd
->hDevMode
|| lppd
->hDevNames
) {
4193 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
4194 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
4195 return E_INVALIDARG
;
4197 if (!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
4198 WARN("Can't find default printer\n");
4199 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
4203 pbuf
= get_printer_infoW(hprn
);
4210 dbuf
= get_driver_infoW(hprn
);
4213 HeapFree(GetProcessHeap(), 0, pbuf
);
4214 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
4218 dm
= pbuf
->pDevMode
;
4223 struct callback_data cb_data
= { 0 };
4225 FIXME("(%p) semi-stub\n", lppd
);
4227 if (lppd
->lpCallback
)
4229 IUnknown_QueryInterface((IUnknown
*)lppd
->lpCallback
, &IID_IPrintDialogCallback
, (void **)&cb_data
.callback
);
4230 IUnknown_QueryInterface((IUnknown
*)lppd
->lpCallback
, &IID_IObjectWithSite
, (void **)&cb_data
.object
);
4233 pdlgex_to_pdlg(lppd
, &pdlg
);
4234 pdlg
.Flags
|= PD_ENABLEPRINTHOOK
;
4235 pdlg
.lpfnPrintHook
= pdlgex_hook_proc
;
4236 pdlg
.lCustData
= (LPARAM
)&cb_data
;
4238 if (PrintDlgW(&pdlg
))
4240 pdlg_to_pdlgex(&pdlg
, lppd
);
4241 lppd
->dwResultAction
= PD_RESULT_PRINT
;
4244 lppd
->dwResultAction
= PD_RESULT_CANCEL
;
4246 if (cb_data
.callback
)
4247 cb_data
.callback
->lpVtbl
->Release(cb_data
.callback
);
4249 cb_data
.object
->lpVtbl
->Release(cb_data
.object
);
4256 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
), dbuf
->pDriverPath
, pbuf
->pPrinterName
, pbuf
->pPortName
);
4257 if (!lppd
->hDevNames
)
4260 lppd
->hDevMode
= update_devmode_handleW(lppd
->hDevMode
, dm
);
4261 if (hr
== S_OK
&& lppd
->hDevMode
) {
4262 if (lppd
->Flags
& PD_RETURNDC
) {
4263 lppd
->hDC
= CreateDCW(dbuf
->pDriverPath
, pbuf
->pPrinterName
, pbuf
->pPortName
, dm
);
4267 else if (lppd
->Flags
& PD_RETURNIC
) {
4268 lppd
->hDC
= CreateICW(dbuf
->pDriverPath
, pbuf
->pPrinterName
, pbuf
->pPortName
, dm
);
4276 HeapFree(GetProcessHeap(), 0, pbuf
);
4277 HeapFree(GetProcessHeap(), 0, dbuf
);