2 * COMMDLG - Print Dialog
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
6 * Copyright 1999 Klaas van Gend
7 * Copyright 2000 Huw D M Davies
8 * Copyright 2010 Vitaly Perov
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #define NONAMELESSUNION
32 #define NONAMELESSSTRUCT
40 #include "wine/unicode.h"
41 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(commdlg
);
50 /* Yes these constants are the same, but we're just copying win98 */
51 #define UPDOWN_ID 0x270f
52 #define MAX_COPIES 9999
54 /* This PRINTDLGA internal structure stores
55 * pointers to several throughout useful structures.
61 LPPRINTDLGA lpPrintDlg
;
62 LPPRINTER_INFO_2A lpPrinterInfo
;
63 LPDRIVER_INFO_3A lpDriverInfo
;
65 HICON hCollateIcon
; /* PrintDlg only */
66 HICON hNoCollateIcon
; /* PrintDlg only */
67 HICON hPortraitIcon
; /* PrintSetupDlg only */
68 HICON hLandscapeIcon
; /* PrintSetupDlg only */
75 LPPRINTDLGW lpPrintDlg
;
76 LPPRINTER_INFO_2W lpPrinterInfo
;
77 LPDRIVER_INFO_3W lpDriverInfo
;
79 HICON hCollateIcon
; /* PrintDlg only */
80 HICON hNoCollateIcon
; /* PrintDlg only */
81 HICON hPortraitIcon
; /* PrintSetupDlg only */
82 HICON hLandscapeIcon
; /* PrintSetupDlg only */
93 static const struct pd_flags psd_flags
[] = {
94 {PSD_MINMARGINS
,"PSD_MINMARGINS"},
95 {PSD_MARGINS
,"PSD_MARGINS"},
96 {PSD_INTHOUSANDTHSOFINCHES
,"PSD_INTHOUSANDTHSOFINCHES"},
97 {PSD_INHUNDREDTHSOFMILLIMETERS
,"PSD_INHUNDREDTHSOFMILLIMETERS"},
98 {PSD_DISABLEMARGINS
,"PSD_DISABLEMARGINS"},
99 {PSD_DISABLEPRINTER
,"PSD_DISABLEPRINTER"},
100 {PSD_NOWARNING
,"PSD_NOWARNING"},
101 {PSD_DISABLEORIENTATION
,"PSD_DISABLEORIENTATION"},
102 {PSD_RETURNDEFAULT
,"PSD_RETURNDEFAULT"},
103 {PSD_DISABLEPAPER
,"PSD_DISABLEPAPER"},
104 {PSD_SHOWHELP
,"PSD_SHOWHELP"},
105 {PSD_ENABLEPAGESETUPHOOK
,"PSD_ENABLEPAGESETUPHOOK"},
106 {PSD_ENABLEPAGESETUPTEMPLATE
,"PSD_ENABLEPAGESETUPTEMPLATE"},
107 {PSD_ENABLEPAGESETUPTEMPLATEHANDLE
,"PSD_ENABLEPAGESETUPTEMPLATEHANDLE"},
108 {PSD_ENABLEPAGEPAINTHOOK
,"PSD_ENABLEPAGEPAINTHOOK"},
109 {PSD_DISABLEPAGEPAINTING
,"PSD_DISABLEPAGEPAINTING"},
113 static const struct pd_flags pd_flags
[] = {
114 {PD_SELECTION
, "PD_SELECTION "},
115 {PD_PAGENUMS
, "PD_PAGENUMS "},
116 {PD_NOSELECTION
, "PD_NOSELECTION "},
117 {PD_NOPAGENUMS
, "PD_NOPAGENUMS "},
118 {PD_COLLATE
, "PD_COLLATE "},
119 {PD_PRINTTOFILE
, "PD_PRINTTOFILE "},
120 {PD_PRINTSETUP
, "PD_PRINTSETUP "},
121 {PD_NOWARNING
, "PD_NOWARNING "},
122 {PD_RETURNDC
, "PD_RETURNDC "},
123 {PD_RETURNIC
, "PD_RETURNIC "},
124 {PD_RETURNDEFAULT
, "PD_RETURNDEFAULT "},
125 {PD_SHOWHELP
, "PD_SHOWHELP "},
126 {PD_ENABLEPRINTHOOK
, "PD_ENABLEPRINTHOOK "},
127 {PD_ENABLESETUPHOOK
, "PD_ENABLESETUPHOOK "},
128 {PD_ENABLEPRINTTEMPLATE
, "PD_ENABLEPRINTTEMPLATE "},
129 {PD_ENABLESETUPTEMPLATE
, "PD_ENABLESETUPTEMPLATE "},
130 {PD_ENABLEPRINTTEMPLATEHANDLE
, "PD_ENABLEPRINTTEMPLATEHANDLE "},
131 {PD_ENABLESETUPTEMPLATEHANDLE
, "PD_ENABLESETUPTEMPLATEHANDLE "},
132 {PD_USEDEVMODECOPIES
, "PD_USEDEVMODECOPIES[ANDCOLLATE] "},
133 {PD_DISABLEPRINTTOFILE
, "PD_DISABLEPRINTTOFILE "},
134 {PD_HIDEPRINTTOFILE
, "PD_HIDEPRINTTOFILE "},
135 {PD_NONETWORKBUTTON
, "PD_NONETWORKBUTTON "},
138 /* address of wndproc for subclassed Static control */
139 static WNDPROC lpfnStaticWndProc
;
140 static WNDPROC edit_wndproc
;
141 /* the text of the fake document to render for the Page Setup dialog */
142 static WCHAR wszFakeDocumentText
[1024];
143 static const WCHAR pd32_collateW
[] = { 'P', 'D', '3', '2', '_', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
144 static const WCHAR pd32_nocollateW
[] = { 'P', 'D', '3', '2', '_', 'N', 'O', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
145 static const WCHAR pd32_portraitW
[] = { 'P', 'D', '3', '2', '_', 'P', 'O', 'R', 'T', 'R', 'A', 'I', 'T', 0 };
146 static const WCHAR pd32_landscapeW
[] = { 'P', 'D', '3', '2', '_', 'L', 'A', 'N', 'D', 'S', 'C', 'A', 'P', 'E', 0 };
147 static const WCHAR printdlg_prop
[] = {'_','_','W','I','N','E','_','P','R','I','N','T','D','L','G','D','A','T','A',0};
148 static const WCHAR pagesetupdlg_prop
[] = { '_', '_', 'W', 'I', 'N', 'E', '_', 'P', 'A', 'G', 'E',
149 'S', 'E', 'T', 'U', 'P', 'D', 'L', 'G', 'D', 'A', 'T', 'A', 0 };
152 static LPWSTR
strdupW(LPCWSTR p
)
158 len
= (strlenW(p
) + 1) * sizeof(WCHAR
);
159 ret
= HeapAlloc(GetProcessHeap(), 0, len
);
164 /***********************************************************************
165 * get_driver_info [internal]
167 * get DRIVER_INFO_3W for the current printer handle,
168 * alloc the buffer, when needed
170 static DRIVER_INFO_3W
* get_driver_infoW(HANDLE hprn
)
172 DRIVER_INFO_3W
*di3
= NULL
;
176 res
= GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
177 if (!res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
178 di3
= HeapAlloc(GetProcessHeap(), 0, needed
);
179 res
= GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)di3
, needed
, &needed
);
185 TRACE("GetPrinterDriverW failed with %u\n", GetLastError());
186 HeapFree(GetProcessHeap(), 0, di3
);
190 static DRIVER_INFO_3A
* get_driver_infoA(HANDLE hprn
)
192 DRIVER_INFO_3A
*di3
= NULL
;
196 res
= GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
197 if (!res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
198 di3
= HeapAlloc(GetProcessHeap(), 0, needed
);
199 res
= GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)di3
, needed
, &needed
);
205 TRACE("GetPrinterDriverA failed with %u\n", GetLastError());
206 HeapFree(GetProcessHeap(), 0, di3
);
211 /***********************************************************************
212 * get_printer_info [internal]
214 * get PRINTER_INFO_2W for the current printer handle,
215 * alloc the buffer, when needed
217 static PRINTER_INFO_2W
* get_printer_infoW(HANDLE hprn
)
219 PRINTER_INFO_2W
*pi2
= NULL
;
223 res
= GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
224 if (!res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
225 pi2
= HeapAlloc(GetProcessHeap(), 0, needed
);
226 res
= GetPrinterW(hprn
, 2, (LPBYTE
)pi2
, needed
, &needed
);
232 TRACE("GetPrinterW failed with %u\n", GetLastError());
233 HeapFree(GetProcessHeap(), 0, pi2
);
237 static PRINTER_INFO_2A
* get_printer_infoA(HANDLE hprn
)
239 PRINTER_INFO_2A
*pi2
= NULL
;
243 res
= GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
244 if (!res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
245 pi2
= HeapAlloc(GetProcessHeap(), 0, needed
);
246 res
= GetPrinterA(hprn
, 2, (LPBYTE
)pi2
, needed
, &needed
);
252 TRACE("GetPrinterA failed with %u\n", GetLastError());
253 HeapFree(GetProcessHeap(), 0, pi2
);
258 /***********************************************************************
259 * update_devmode_handle [internal]
261 * update a devmode handle for the given DEVMODE, alloc the buffer, when needed
263 static HGLOBAL
update_devmode_handleW(HGLOBAL hdm
, DEVMODEW
*dm
)
265 SIZE_T size
= GlobalSize(hdm
);
268 /* Increase / alloc the global memory block, when needed */
269 if ((dm
->dmSize
+ dm
->dmDriverExtra
) > size
) {
271 hdm
= GlobalReAlloc(hdm
, dm
->dmSize
+ dm
->dmDriverExtra
, 0);
273 hdm
= GlobalAlloc(GMEM_MOVEABLE
, dm
->dmSize
+ dm
->dmDriverExtra
);
277 ptr
= GlobalLock(hdm
);
279 memcpy(ptr
, dm
, dm
->dmSize
+ dm
->dmDriverExtra
);
291 static HGLOBAL
update_devmode_handleA(HGLOBAL hdm
, DEVMODEA
*dm
)
293 SIZE_T size
= GlobalSize(hdm
);
296 /* Increase / alloc the global memory block, when needed */
297 if ((dm
->dmSize
+ dm
->dmDriverExtra
) > size
) {
299 hdm
= GlobalReAlloc(hdm
, dm
->dmSize
+ dm
->dmDriverExtra
, 0);
301 hdm
= GlobalAlloc(GMEM_MOVEABLE
, dm
->dmSize
+ dm
->dmDriverExtra
);
305 ptr
= GlobalLock(hdm
);
307 memcpy(ptr
, dm
, dm
->dmSize
+ dm
->dmDriverExtra
);
319 /***********************************************************
320 * convert_to_devmodeA
322 * Creates an ansi copy of supplied devmode
324 static DEVMODEA
*convert_to_devmodeA(const DEVMODEW
*dmW
)
329 if (!dmW
) return NULL
;
330 size
= dmW
->dmSize
- CCHDEVICENAME
-
331 ((dmW
->dmSize
> FIELD_OFFSET(DEVMODEW
, dmFormName
)) ? CCHFORMNAME
: 0);
333 dmA
= HeapAlloc(GetProcessHeap(), 0, size
+ dmW
->dmDriverExtra
);
334 if (!dmA
) return NULL
;
336 WideCharToMultiByte(CP_ACP
, 0, dmW
->dmDeviceName
, -1,
337 (LPSTR
)dmA
->dmDeviceName
, CCHDEVICENAME
, NULL
, NULL
);
339 if (FIELD_OFFSET(DEVMODEW
, dmFormName
) >= dmW
->dmSize
)
341 memcpy(&dmA
->dmSpecVersion
, &dmW
->dmSpecVersion
,
342 dmW
->dmSize
- FIELD_OFFSET(DEVMODEW
, dmSpecVersion
));
346 memcpy(&dmA
->dmSpecVersion
, &dmW
->dmSpecVersion
,
347 FIELD_OFFSET(DEVMODEW
, dmFormName
) - FIELD_OFFSET(DEVMODEW
, dmSpecVersion
));
348 WideCharToMultiByte(CP_ACP
, 0, dmW
->dmFormName
, -1,
349 (LPSTR
)dmA
->dmFormName
, CCHFORMNAME
, NULL
, NULL
);
351 memcpy(&dmA
->dmLogPixels
, &dmW
->dmLogPixels
, dmW
->dmSize
- FIELD_OFFSET(DEVMODEW
, dmLogPixels
));
355 memcpy((char *)dmA
+ dmA
->dmSize
, (const char *)dmW
+ dmW
->dmSize
, dmW
->dmDriverExtra
);
359 /***********************************************************************
360 * PRINTDLG_OpenDefaultPrinter
362 * Returns a winspool printer handle to the default printer in *hprn
363 * Caller must call ClosePrinter on the handle
365 * Returns TRUE on success else FALSE
367 static BOOL
PRINTDLG_OpenDefaultPrinter(HANDLE
*hprn
)
370 DWORD dwBufLen
= sizeof(buf
) / sizeof(buf
[0]);
372 if(!GetDefaultPrinterW(buf
, &dwBufLen
))
374 res
= OpenPrinterW(buf
, hprn
, NULL
);
376 WARN("Could not open printer %s\n", debugstr_w(buf
));
380 /***********************************************************************
381 * PRINTDLG_SetUpPrinterListCombo
383 * Initializes printer list combox.
384 * hDlg: HWND of dialog
385 * id: Control id of combo
386 * name: Name of printer to select
388 * Initializes combo with list of available printers. Selects printer 'name'
389 * If name is NULL or does not exist select the default printer.
391 * Returns number of printers added to list.
393 static INT
PRINTDLG_SetUpPrinterListComboA(HWND hDlg
, UINT id
, LPCSTR name
)
397 LPPRINTER_INFO_2A pi
;
398 EnumPrintersA(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
399 pi
= HeapAlloc(GetProcessHeap(), 0, needed
);
400 EnumPrintersA(PRINTER_ENUM_LOCAL
, NULL
, 2, (LPBYTE
)pi
, needed
, &needed
,
403 SendDlgItemMessageA(hDlg
, id
, CB_RESETCONTENT
, 0, 0);
405 for(i
= 0; i
< num
; i
++) {
406 SendDlgItemMessageA(hDlg
, id
, CB_ADDSTRING
, 0,
407 (LPARAM
)pi
[i
].pPrinterName
);
409 HeapFree(GetProcessHeap(), 0, pi
);
411 (i
= SendDlgItemMessageA(hDlg
, id
, CB_FINDSTRINGEXACT
, -1,
412 (LPARAM
)name
)) == CB_ERR
) {
415 DWORD dwBufLen
= sizeof(buf
);
417 WARN("Can't find %s in printer list so trying to find default\n",
419 if(!GetDefaultPrinterA(buf
, &dwBufLen
))
421 i
= SendDlgItemMessageA(hDlg
, id
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buf
);
423 FIXME("Can't find default printer in printer list\n");
425 SendDlgItemMessageA(hDlg
, id
, CB_SETCURSEL
, i
, 0);
429 static INT
PRINTDLG_SetUpPrinterListComboW(HWND hDlg
, UINT id
, LPCWSTR name
)
433 LPPRINTER_INFO_2W pi
;
434 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
435 pi
= HeapAlloc(GetProcessHeap(), 0, needed
);
436 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, (LPBYTE
)pi
, needed
, &needed
,
439 for(i
= 0; i
< num
; i
++) {
440 SendDlgItemMessageW(hDlg
, id
, CB_ADDSTRING
, 0,
441 (LPARAM
)pi
[i
].pPrinterName
);
443 HeapFree(GetProcessHeap(), 0, pi
);
445 (i
= SendDlgItemMessageW(hDlg
, id
, CB_FINDSTRINGEXACT
, -1,
446 (LPARAM
)name
)) == CB_ERR
) {
448 DWORD dwBufLen
= sizeof(buf
)/sizeof(buf
[0]);
450 WARN("Can't find %s in printer list so trying to find default\n",
452 if(!GetDefaultPrinterW(buf
, &dwBufLen
))
454 i
= SendDlgItemMessageW(hDlg
, id
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buf
);
456 TRACE("Can't find default printer in printer list\n");
458 SendDlgItemMessageW(hDlg
, id
, CB_SETCURSEL
, i
, 0);
462 /***********************************************************************
463 * PRINTDLG_CreateDevNames [internal]
466 * creates a DevNames structure.
468 * (NB. when we handle unicode the offsets will be in wchars).
470 static BOOL
PRINTDLG_CreateDevNames(HGLOBAL
*hmem
, const char* DeviceDriverName
,
471 const char* DeviceName
, const char* OutputPort
)
474 char* pDevNamesSpace
;
476 LPDEVNAMES lpDevNames
;
478 DWORD dwBufLen
= sizeof(buf
);
481 p
= strrchr( DeviceDriverName
, '\\' );
482 if (p
) DeviceDriverName
= p
+ 1;
484 size
= strlen(DeviceDriverName
) + 1
485 + strlen(DeviceName
) + 1
486 + strlen(OutputPort
) + 1
490 *hmem
= GlobalReAlloc(*hmem
, size
, GMEM_MOVEABLE
);
492 *hmem
= GlobalAlloc(GMEM_MOVEABLE
, size
);
496 pDevNamesSpace
= GlobalLock(*hmem
);
497 lpDevNames
= (LPDEVNAMES
) pDevNamesSpace
;
499 pTempPtr
= pDevNamesSpace
+ sizeof(DEVNAMES
);
500 strcpy(pTempPtr
, DeviceDriverName
);
501 lpDevNames
->wDriverOffset
= pTempPtr
- pDevNamesSpace
;
503 pTempPtr
+= strlen(DeviceDriverName
) + 1;
504 strcpy(pTempPtr
, DeviceName
);
505 lpDevNames
->wDeviceOffset
= pTempPtr
- pDevNamesSpace
;
507 pTempPtr
+= strlen(DeviceName
) + 1;
508 strcpy(pTempPtr
, OutputPort
);
509 lpDevNames
->wOutputOffset
= pTempPtr
- pDevNamesSpace
;
511 GetDefaultPrinterA(buf
, &dwBufLen
);
512 lpDevNames
->wDefault
= (strcmp(buf
, DeviceName
) == 0) ? 1 : 0;
517 static BOOL
PRINTDLG_CreateDevNamesW(HGLOBAL
*hmem
, LPCWSTR DeviceDriverName
,
518 LPCWSTR DeviceName
, LPCWSTR OutputPort
)
521 LPWSTR pDevNamesSpace
;
523 LPDEVNAMES lpDevNames
;
525 DWORD dwBufLen
= sizeof(bufW
) / sizeof(WCHAR
);
528 p
= strrchrW( DeviceDriverName
, '\\' );
529 if (p
) DeviceDriverName
= p
+ 1;
531 size
= sizeof(WCHAR
)*lstrlenW(DeviceDriverName
) + 2
532 + sizeof(WCHAR
)*lstrlenW(DeviceName
) + 2
533 + sizeof(WCHAR
)*lstrlenW(OutputPort
) + 2
537 *hmem
= GlobalReAlloc(*hmem
, size
, GMEM_MOVEABLE
);
539 *hmem
= GlobalAlloc(GMEM_MOVEABLE
, size
);
543 pDevNamesSpace
= GlobalLock(*hmem
);
544 lpDevNames
= (LPDEVNAMES
) pDevNamesSpace
;
546 pTempPtr
= (LPWSTR
)((LPDEVNAMES
)pDevNamesSpace
+ 1);
547 lstrcpyW(pTempPtr
, DeviceDriverName
);
548 lpDevNames
->wDriverOffset
= pTempPtr
- pDevNamesSpace
;
550 pTempPtr
+= lstrlenW(DeviceDriverName
) + 1;
551 lstrcpyW(pTempPtr
, DeviceName
);
552 lpDevNames
->wDeviceOffset
= pTempPtr
- pDevNamesSpace
;
554 pTempPtr
+= lstrlenW(DeviceName
) + 1;
555 lstrcpyW(pTempPtr
, OutputPort
);
556 lpDevNames
->wOutputOffset
= pTempPtr
- pDevNamesSpace
;
558 GetDefaultPrinterW(bufW
, &dwBufLen
);
559 lpDevNames
->wDefault
= (lstrcmpW(bufW
, DeviceName
) == 0) ? 1 : 0;
564 /***********************************************************************
565 * PRINTDLG_UpdatePrintDlg [internal]
568 * updates the PrintDlg structure for return values.
571 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
572 * TRUE if successful.
574 static BOOL
PRINTDLG_UpdatePrintDlgA(HWND hDlg
,
575 PRINT_PTRA
* PrintStructures
)
577 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
578 PDEVMODEA lpdm
= PrintStructures
->lpDevMode
;
579 LPPRINTER_INFO_2A pi
= PrintStructures
->lpPrinterInfo
;
583 FIXME("No lpdm ptr?\n");
588 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
589 /* check whether nFromPage and nToPage are within range defined by
590 * nMinPage and nMaxPage
592 if (IsDlgButtonChecked(hDlg
, rad3
) == BST_CHECKED
) { /* Pages */
596 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
597 nToPage
= GetDlgItemInt(hDlg
, edt2
, &translated
, FALSE
);
599 /* if no ToPage value is entered, use the FromPage value */
600 if(!translated
) nToPage
= nFromPage
;
602 if (nFromPage
< lppd
->nMinPage
|| nFromPage
> lppd
->nMaxPage
||
603 nToPage
< lppd
->nMinPage
|| nToPage
> lppd
->nMaxPage
) {
604 WCHAR resourcestr
[256];
605 WCHAR resultstr
[256];
606 LoadStringW(COMDLG32_hInstance
, PD32_INVALID_PAGE_RANGE
, resourcestr
, 255);
607 wsprintfW(resultstr
,resourcestr
, lppd
->nMinPage
, lppd
->nMaxPage
);
608 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
, resourcestr
, 255);
609 MessageBoxW(hDlg
, resultstr
, resourcestr
, MB_OK
| MB_ICONWARNING
);
612 lppd
->nFromPage
= nFromPage
;
613 lppd
->nToPage
= nToPage
;
614 lppd
->Flags
|= PD_PAGENUMS
;
617 lppd
->Flags
&= ~PD_PAGENUMS
;
619 if (IsDlgButtonChecked(hDlg
, rad2
) == BST_CHECKED
) /* Selection */
620 lppd
->Flags
|= PD_SELECTION
;
622 lppd
->Flags
&= ~PD_SELECTION
;
624 if (IsDlgButtonChecked(hDlg
, chx1
) == BST_CHECKED
) {/* Print to file */
625 static char file
[] = "FILE:";
626 lppd
->Flags
|= PD_PRINTTOFILE
;
627 pi
->pPortName
= file
;
630 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
) { /* Collate */
631 FIXME("Collate lppd not yet implemented as output\n");
634 /* set PD_Collate and nCopies */
635 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
636 /* The application doesn't support multiple copies or collate...
638 lppd
->Flags
&= ~PD_COLLATE
;
640 /* if the printer driver supports it... store info there
641 * otherwise no collate & multiple copies !
643 if (lpdm
->dmFields
& DM_COLLATE
)
645 (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
);
646 if (lpdm
->dmFields
& DM_COPIES
)
647 lpdm
->u1
.s1
.dmCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
649 /* Application is responsible for multiple copies */
650 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
651 lppd
->Flags
|= PD_COLLATE
;
653 lppd
->Flags
&= ~PD_COLLATE
;
654 lppd
->nCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
655 /* multiple copies already included in the document. Driver must print only one copy */
656 lpdm
->u1
.s1
.dmCopies
= 1;
659 /* Print quality, PrintDlg16 */
660 if(GetDlgItem(hDlg
, cmb1
))
662 HWND hQuality
= GetDlgItem(hDlg
, cmb1
);
663 int Sel
= SendMessageA(hQuality
, CB_GETCURSEL
, 0, 0);
667 LONG dpi
= SendMessageA(hQuality
, CB_GETITEMDATA
, Sel
, 0);
668 lpdm
->dmFields
|= DM_PRINTQUALITY
| DM_YRESOLUTION
;
669 lpdm
->u1
.s1
.dmPrintQuality
= LOWORD(dpi
);
670 lpdm
->dmYResolution
= HIWORD(dpi
);
677 static BOOL
PRINTDLG_UpdatePrintDlgW(HWND hDlg
,
678 PRINT_PTRW
* PrintStructures
)
680 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
681 PDEVMODEW lpdm
= PrintStructures
->lpDevMode
;
682 LPPRINTER_INFO_2W pi
= PrintStructures
->lpPrinterInfo
;
686 FIXME("No lpdm ptr?\n");
691 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
692 /* check whether nFromPage and nToPage are within range defined by
693 * nMinPage and nMaxPage
695 if (IsDlgButtonChecked(hDlg
, rad3
) == BST_CHECKED
) { /* Pages */
699 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
700 nToPage
= GetDlgItemInt(hDlg
, edt2
, &translated
, FALSE
);
702 /* if no ToPage value is entered, use the FromPage value */
703 if(!translated
) nToPage
= nFromPage
;
705 if (nFromPage
< lppd
->nMinPage
|| nFromPage
> lppd
->nMaxPage
||
706 nToPage
< lppd
->nMinPage
|| nToPage
> lppd
->nMaxPage
) {
707 WCHAR resourcestr
[256];
708 WCHAR resultstr
[256];
710 LoadStringW(COMDLG32_hInstance
, PD32_INVALID_PAGE_RANGE
,
712 args
[0] = lppd
->nMinPage
;
713 args
[1] = lppd
->nMaxPage
;
714 FormatMessageW(FORMAT_MESSAGE_FROM_STRING
|FORMAT_MESSAGE_ARGUMENT_ARRAY
,
715 resourcestr
, 0, 0, resultstr
,
716 sizeof(resultstr
)/sizeof(*resultstr
),
717 (__ms_va_list
*)args
);
718 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
,
720 MessageBoxW(hDlg
, resultstr
, resourcestr
,
721 MB_OK
| MB_ICONWARNING
);
724 lppd
->nFromPage
= nFromPage
;
725 lppd
->nToPage
= nToPage
;
726 lppd
->Flags
|= PD_PAGENUMS
;
729 lppd
->Flags
&= ~PD_PAGENUMS
;
731 if (IsDlgButtonChecked(hDlg
, rad2
) == BST_CHECKED
) /* Selection */
732 lppd
->Flags
|= PD_SELECTION
;
734 lppd
->Flags
&= ~PD_SELECTION
;
736 if (IsDlgButtonChecked(hDlg
, chx1
) == BST_CHECKED
) {/* Print to file */
737 static WCHAR file
[] = {'F','I','L','E',':',0};
738 lppd
->Flags
|= PD_PRINTTOFILE
;
739 pi
->pPortName
= file
;
742 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
) { /* Collate */
743 FIXME("Collate lppd not yet implemented as output\n");
746 /* set PD_Collate and nCopies */
747 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
748 /* The application doesn't support multiple copies or collate...
750 lppd
->Flags
&= ~PD_COLLATE
;
752 /* if the printer driver supports it... store info there
753 * otherwise no collate & multiple copies !
755 if (lpdm
->dmFields
& DM_COLLATE
)
757 (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
);
758 if (lpdm
->dmFields
& DM_COPIES
)
759 lpdm
->u1
.s1
.dmCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
761 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
762 lppd
->Flags
|= PD_COLLATE
;
764 lppd
->Flags
&= ~PD_COLLATE
;
765 lppd
->nCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
771 /************************************************************************
772 * PRINTDLG_SetUpPaperComboBox
774 * Initialize either the papersize or inputslot combos of the Printer Setup
775 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
776 * We also try to re-select the old selection.
778 static BOOL
PRINTDLG_SetUpPaperComboBoxA(HWND hDlg
,
789 WORD oldWord
= 0, newWord
= 0; /* DMPAPER_ and DMBIN_ start at 1 */
791 int fwCapability_Names
;
792 int fwCapability_Words
;
794 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName
,PortName
,nIDComboBox
);
796 /* query the dialog box for the current selected value */
797 Sel
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETCURSEL
, 0, 0);
799 /* we enter here only if a different printer is selected after
800 * the Print Setup dialog is opened. The current settings are
801 * stored into the newly selected printer.
803 oldWord
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
,
805 if(oldWord
>= DMPAPER_USER
) /* DMPAPER_USER == DMBIN_USER */
806 oldWord
= 0; /* There's no point in trying to keep custom
807 paper / bin sizes across printers */
811 newWord
= (nIDComboBox
== cmb2
) ? dm
->u1
.s1
.dmPaperSize
: dm
->u1
.s1
.dmDefaultSource
;
813 if (nIDComboBox
== cmb2
) {
815 fwCapability_Names
= DC_PAPERNAMES
;
816 fwCapability_Words
= DC_PAPERS
;
820 fwCapability_Names
= DC_BINNAMES
;
821 fwCapability_Words
= DC_BINS
;
824 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
825 fwCapability_Names
, NULL
, dm
);
826 if (NrOfEntries
== 0)
827 WARN("no Name Entries found!\n");
828 else if (NrOfEntries
< 0)
831 if(DeviceCapabilitiesA(PrinterName
, PortName
, fwCapability_Words
, NULL
, dm
)
833 ERR("Number of caps is different\n");
837 Names
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(char)*NamesSize
);
838 Words
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WORD
));
839 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
840 fwCapability_Names
, Names
, dm
);
841 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
842 fwCapability_Words
, (LPSTR
)Words
, dm
);
844 /* reset any current content in the combobox */
845 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_RESETCONTENT
, 0, 0);
847 /* store new content */
848 for (i
= 0; i
< NrOfEntries
; i
++) {
849 DWORD pos
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_ADDSTRING
, 0,
850 (LPARAM
)(&Names
[i
*NamesSize
]) );
851 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_SETITEMDATA
, pos
,
855 /* Look for old selection or the new default.
856 Can't do this is previous loop since item order will change as more items are added */
858 old_Sel
= NrOfEntries
;
859 for (i
= 0; i
< NrOfEntries
; i
++) {
860 if(SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) ==
865 if(SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) == newWord
)
869 if(old_Sel
< NrOfEntries
)
873 if(nIDComboBox
== cmb2
)
874 dm
->u1
.s1
.dmPaperSize
= oldWord
;
876 dm
->u1
.s1
.dmDefaultSource
= oldWord
;
881 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_SETCURSEL
, Sel
, 0);
883 HeapFree(GetProcessHeap(),0,Words
);
884 HeapFree(GetProcessHeap(),0,Names
);
888 static BOOL
PRINTDLG_SetUpPaperComboBoxW(HWND hDlg
,
890 const WCHAR
* PrinterName
,
891 const WCHAR
* PortName
,
899 WORD oldWord
= 0, newWord
= 0; /* DMPAPER_ and DMBIN_ start at 1 */
901 int fwCapability_Names
;
902 int fwCapability_Words
;
904 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName
),debugstr_w(PortName
),nIDComboBox
);
906 /* query the dialog box for the current selected value */
907 Sel
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETCURSEL
, 0, 0);
909 /* we enter here only if a different printer is selected after
910 * the Print Setup dialog is opened. The current settings are
911 * stored into the newly selected printer.
913 oldWord
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETITEMDATA
,
916 if(oldWord
>= DMPAPER_USER
) /* DMPAPER_USER == DMBIN_USER */
917 oldWord
= 0; /* There's no point in trying to keep custom
918 paper / bin sizes across printers */
922 newWord
= (nIDComboBox
== cmb2
) ? dm
->u1
.s1
.dmPaperSize
: dm
->u1
.s1
.dmDefaultSource
;
924 if (nIDComboBox
== cmb2
) {
926 fwCapability_Names
= DC_PAPERNAMES
;
927 fwCapability_Words
= DC_PAPERS
;
931 fwCapability_Names
= DC_BINNAMES
;
932 fwCapability_Words
= DC_BINS
;
935 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
936 fwCapability_Names
, NULL
, dm
);
937 if (NrOfEntries
== 0)
938 WARN("no Name Entries found!\n");
939 else if (NrOfEntries
< 0)
942 if(DeviceCapabilitiesW(PrinterName
, PortName
, fwCapability_Words
, NULL
, dm
)
944 ERR("Number of caps is different\n");
948 Names
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WCHAR
)*NamesSize
);
949 Words
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WORD
));
950 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
951 fwCapability_Names
, Names
, dm
);
952 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
953 fwCapability_Words
, Words
, dm
);
955 /* reset any current content in the combobox */
956 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_RESETCONTENT
, 0, 0);
958 /* store new content */
959 for (i
= 0; i
< NrOfEntries
; i
++) {
960 DWORD pos
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_ADDSTRING
, 0,
961 (LPARAM
)(&Names
[i
*NamesSize
]) );
962 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_SETITEMDATA
, pos
,
966 /* Look for old selection or the new default.
967 Can't do this is previous loop since item order will change as more items are added */
969 old_Sel
= NrOfEntries
;
970 for (i
= 0; i
< NrOfEntries
; i
++) {
971 if(SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) ==
976 if(SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) == newWord
)
980 if(old_Sel
< NrOfEntries
)
984 if(nIDComboBox
== cmb2
)
985 dm
->u1
.s1
.dmPaperSize
= oldWord
;
987 dm
->u1
.s1
.dmDefaultSource
= oldWord
;
992 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_SETCURSEL
, Sel
, 0);
994 HeapFree(GetProcessHeap(),0,Words
);
995 HeapFree(GetProcessHeap(),0,Names
);
1000 /***********************************************************************
1001 * PRINTDLG_UpdatePrinterInfoTexts [internal]
1003 static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg
, const PRINTER_INFO_2A
*pi
)
1005 char StatusMsg
[256];
1006 char ResourceString
[256];
1009 /* Status Message */
1012 /* add all status messages */
1013 for (i
= 0; i
< 25; i
++) {
1014 if (pi
->Status
& (1<<i
)) {
1015 LoadStringA(COMDLG32_hInstance
, PD32_PRINTER_STATUS_PAUSED
+i
,
1016 ResourceString
, 255);
1017 strcat(StatusMsg
,ResourceString
);
1020 /* append "ready" */
1021 /* FIXME: status==ready must only be appended if really so.
1022 but how to detect? */
1023 LoadStringA(COMDLG32_hInstance
, PD32_PRINTER_STATUS_READY
,
1024 ResourceString
, 255);
1025 strcat(StatusMsg
,ResourceString
);
1026 SetDlgItemTextA(hDlg
, stc12
, StatusMsg
);
1028 /* set all other printer info texts */
1029 SetDlgItemTextA(hDlg
, stc11
, pi
->pDriverName
);
1031 if (pi
->pLocation
!= NULL
&& pi
->pLocation
[0] != '\0')
1032 SetDlgItemTextA(hDlg
, stc14
, pi
->pLocation
);
1034 SetDlgItemTextA(hDlg
, stc14
, pi
->pPortName
);
1035 SetDlgItemTextA(hDlg
, stc13
, pi
->pComment
? pi
->pComment
: "");
1039 static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg
, const PRINTER_INFO_2W
*pi
)
1041 WCHAR StatusMsg
[256];
1042 WCHAR ResourceString
[256];
1043 static const WCHAR emptyW
[] = {0};
1046 /* Status Message */
1049 /* add all status messages */
1050 for (i
= 0; i
< 25; i
++) {
1051 if (pi
->Status
& (1<<i
)) {
1052 LoadStringW(COMDLG32_hInstance
, PD32_PRINTER_STATUS_PAUSED
+i
,
1053 ResourceString
, 255);
1054 lstrcatW(StatusMsg
,ResourceString
);
1057 /* append "ready" */
1058 /* FIXME: status==ready must only be appended if really so.
1059 but how to detect? */
1060 LoadStringW(COMDLG32_hInstance
, PD32_PRINTER_STATUS_READY
,
1061 ResourceString
, 255);
1062 lstrcatW(StatusMsg
,ResourceString
);
1063 SetDlgItemTextW(hDlg
, stc12
, StatusMsg
);
1065 /* set all other printer info texts */
1066 SetDlgItemTextW(hDlg
, stc11
, pi
->pDriverName
);
1067 if (pi
->pLocation
!= NULL
&& pi
->pLocation
[0] != '\0')
1068 SetDlgItemTextW(hDlg
, stc14
, pi
->pLocation
);
1070 SetDlgItemTextW(hDlg
, stc14
, pi
->pPortName
);
1071 SetDlgItemTextW(hDlg
, stc13
, pi
->pComment
? pi
->pComment
: emptyW
);
1075 /*******************************************************************
1077 * PRINTDLG_ChangePrinter
1080 static BOOL
PRINTDLG_ChangePrinterA(HWND hDlg
, char *name
, PRINT_PTRA
*PrintStructures
)
1082 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1083 LPDEVMODEA lpdm
= NULL
;
1088 HeapFree(GetProcessHeap(),0, PrintStructures
->lpPrinterInfo
);
1089 HeapFree(GetProcessHeap(),0, PrintStructures
->lpDriverInfo
);
1090 if(!OpenPrinterA(name
, &hprn
, NULL
)) {
1091 ERR("Can't open printer %s\n", name
);
1094 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
1095 PrintStructures
->lpPrinterInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
1096 GetPrinterA(hprn
, 2, (LPBYTE
)PrintStructures
->lpPrinterInfo
, needed
,
1098 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
1099 PrintStructures
->lpDriverInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
1100 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)PrintStructures
->lpDriverInfo
,
1102 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures
->lpPrinterInfo
->pPrinterName
);
1107 PRINTDLG_UpdatePrinterInfoTextsA(hDlg
, PrintStructures
->lpPrinterInfo
);
1109 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
1110 PrintStructures
->lpDevMode
= NULL
;
1112 dmSize
= DocumentPropertiesA(0, 0, name
, NULL
, NULL
, 0);
1114 ERR("DocumentProperties fails on %s\n", debugstr_a(name
));
1117 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(), 0, dmSize
);
1118 dmSize
= DocumentPropertiesA(0, 0, name
, PrintStructures
->lpDevMode
, NULL
,
1120 if(lppd
->hDevMode
&& (lpdm
= GlobalLock(lppd
->hDevMode
)) &&
1121 !lstrcmpA( (LPSTR
) lpdm
->dmDeviceName
,
1122 (LPSTR
) PrintStructures
->lpDevMode
->dmDeviceName
)) {
1123 /* Supplied devicemode matches current printer so try to use it */
1124 DocumentPropertiesA(0, 0, name
, PrintStructures
->lpDevMode
, lpdm
,
1125 DM_OUT_BUFFER
| DM_IN_BUFFER
);
1128 GlobalUnlock(lppd
->hDevMode
);
1130 lpdm
= PrintStructures
->lpDevMode
; /* use this as a shortcut */
1132 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
1133 /* Print range (All/Range/Selection) */
1134 if(lppd
->nFromPage
!= 0xffff)
1135 SetDlgItemInt(hDlg
, edt1
, lppd
->nFromPage
, FALSE
);
1136 if(lppd
->nToPage
!= 0xffff)
1137 SetDlgItemInt(hDlg
, edt2
, lppd
->nToPage
, FALSE
);
1139 CheckRadioButton(hDlg
, rad1
, rad3
, rad1
); /* default */
1140 if (lppd
->Flags
& PD_NOSELECTION
)
1141 EnableWindow(GetDlgItem(hDlg
, rad2
), FALSE
);
1143 if (lppd
->Flags
& PD_SELECTION
)
1144 CheckRadioButton(hDlg
, rad1
, rad3
, rad2
);
1145 if (lppd
->Flags
& PD_NOPAGENUMS
) {
1146 EnableWindow(GetDlgItem(hDlg
, rad3
), FALSE
);
1147 EnableWindow(GetDlgItem(hDlg
, stc2
),FALSE
);
1148 EnableWindow(GetDlgItem(hDlg
, edt1
), FALSE
);
1149 EnableWindow(GetDlgItem(hDlg
, stc3
),FALSE
);
1150 EnableWindow(GetDlgItem(hDlg
, edt2
), FALSE
);
1152 if (lppd
->Flags
& PD_PAGENUMS
)
1153 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1158 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1160 if (lppd
->Flags
& PD_COLLATE
) {
1161 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1162 (LPARAM
)PrintStructures
->hCollateIcon
);
1163 CheckDlgButton(hDlg
, chx2
, 1);
1165 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1166 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1167 CheckDlgButton(hDlg
, chx2
, 0);
1170 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1171 /* if printer doesn't support it: no Collate */
1172 if (!(lpdm
->dmFields
& DM_COLLATE
)) {
1173 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1174 EnableWindow(GetDlgItem(hDlg
, ico3
), FALSE
);
1181 if (lppd
->hDevMode
== 0)
1182 copies
= lppd
->nCopies
;
1184 copies
= lpdm
->u1
.s1
.dmCopies
;
1185 if(copies
== 0) copies
= 1;
1186 else if(copies
< 0) copies
= MAX_COPIES
;
1187 SetDlgItemInt(hDlg
, edt3
, copies
, FALSE
);
1190 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1191 /* if printer doesn't support it: no nCopies */
1192 if (!(lpdm
->dmFields
& DM_COPIES
)) {
1193 EnableWindow(GetDlgItem(hDlg
, edt3
), FALSE
);
1194 EnableWindow(GetDlgItem(hDlg
, stc5
), FALSE
);
1199 CheckDlgButton(hDlg
, chx1
, (lppd
->Flags
& PD_PRINTTOFILE
) ? 1 : 0);
1200 if (lppd
->Flags
& PD_DISABLEPRINTTOFILE
)
1201 EnableWindow(GetDlgItem(hDlg
, chx1
), FALSE
);
1202 if (lppd
->Flags
& PD_HIDEPRINTTOFILE
)
1203 ShowWindow(GetDlgItem(hDlg
, chx1
), SW_HIDE
);
1205 /* Fill print quality combo, PrintDlg16 */
1206 if(GetDlgItem(hDlg
, cmb1
))
1208 DWORD numResolutions
= DeviceCapabilitiesA(PrintStructures
->lpPrinterInfo
->pPrinterName
,
1209 PrintStructures
->lpPrinterInfo
->pPortName
,
1210 DC_ENUMRESOLUTIONS
, NULL
, lpdm
);
1212 if(numResolutions
!= -1)
1214 HWND hQuality
= GetDlgItem(hDlg
, cmb1
);
1219 HDC hPrinterDC
= CreateDCA(PrintStructures
->lpPrinterInfo
->pDriverName
,
1220 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1223 Resolutions
= HeapAlloc(GetProcessHeap(), 0, numResolutions
*sizeof(LONG
)*2);
1224 DeviceCapabilitiesA(PrintStructures
->lpPrinterInfo
->pPrinterName
,
1225 PrintStructures
->lpPrinterInfo
->pPortName
,
1226 DC_ENUMRESOLUTIONS
, (LPSTR
)Resolutions
, lpdm
);
1228 dpiX
= GetDeviceCaps(hPrinterDC
, LOGPIXELSX
);
1229 dpiY
= GetDeviceCaps(hPrinterDC
, LOGPIXELSY
);
1230 DeleteDC(hPrinterDC
);
1232 SendMessageA(hQuality
, CB_RESETCONTENT
, 0, 0);
1233 for(i
= 0; i
< (numResolutions
* 2); i
+= 2)
1235 BOOL IsDefault
= FALSE
;
1238 if(Resolutions
[i
] == Resolutions
[i
+1])
1240 if(dpiX
== Resolutions
[i
])
1242 sprintf(buf
, "%d dpi", Resolutions
[i
]);
1245 if(dpiX
== Resolutions
[i
] && dpiY
== Resolutions
[i
+1])
1247 sprintf(buf
, "%d dpi x %d dpi", Resolutions
[i
], Resolutions
[i
+1]);
1250 Index
= SendMessageA(hQuality
, CB_ADDSTRING
, 0, (LPARAM
)buf
);
1253 SendMessageA(hQuality
, CB_SETCURSEL
, Index
, 0);
1255 SendMessageA(hQuality
, CB_SETITEMDATA
, Index
, MAKELONG(dpiX
,dpiY
));
1257 HeapFree(GetProcessHeap(), 0, Resolutions
);
1260 } else { /* PD_PRINTSETUP */
1261 BOOL bPortrait
= (lpdm
->u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
);
1263 PRINTDLG_SetUpPaperComboBoxA(hDlg
, cmb2
,
1264 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1265 PrintStructures
->lpPrinterInfo
->pPortName
,
1267 PRINTDLG_SetUpPaperComboBoxA(hDlg
, cmb3
,
1268 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1269 PrintStructures
->lpPrinterInfo
->pPortName
,
1271 CheckRadioButton(hDlg
, rad1
, rad2
, bPortrait
? rad1
: rad2
);
1272 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1273 (LPARAM
)(bPortrait
? PrintStructures
->hPortraitIcon
:
1274 PrintStructures
->hLandscapeIcon
));
1279 if ((lppd
->Flags
& PD_SHOWHELP
)==0) {
1280 /* hide if PD_SHOWHELP not specified */
1281 ShowWindow(GetDlgItem(hDlg
, pshHelp
), SW_HIDE
);
1286 static BOOL
PRINTDLG_ChangePrinterW(HWND hDlg
, WCHAR
*name
,
1287 PRINT_PTRW
*PrintStructures
)
1289 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1290 LPDEVMODEW lpdm
= NULL
;
1295 HeapFree(GetProcessHeap(),0, PrintStructures
->lpPrinterInfo
);
1296 HeapFree(GetProcessHeap(),0, PrintStructures
->lpDriverInfo
);
1297 if(!OpenPrinterW(name
, &hprn
, NULL
)) {
1298 ERR("Can't open printer %s\n", debugstr_w(name
));
1301 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
1302 PrintStructures
->lpPrinterInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
1303 GetPrinterW(hprn
, 2, (LPBYTE
)PrintStructures
->lpPrinterInfo
, needed
,
1305 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
1306 PrintStructures
->lpDriverInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
1307 if (!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)PrintStructures
->lpDriverInfo
,
1309 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures
->lpPrinterInfo
->pPrinterName
));
1314 PRINTDLG_UpdatePrinterInfoTextsW(hDlg
, PrintStructures
->lpPrinterInfo
);
1316 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
1317 PrintStructures
->lpDevMode
= NULL
;
1319 dmSize
= DocumentPropertiesW(0, 0, name
, NULL
, NULL
, 0);
1321 ERR("DocumentProperties fails on %s\n", debugstr_w(name
));
1324 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(), 0, dmSize
);
1325 dmSize
= DocumentPropertiesW(0, 0, name
, PrintStructures
->lpDevMode
, NULL
,
1327 if(lppd
->hDevMode
&& (lpdm
= GlobalLock(lppd
->hDevMode
)) &&
1328 !lstrcmpW(lpdm
->dmDeviceName
,
1329 PrintStructures
->lpDevMode
->dmDeviceName
)) {
1330 /* Supplied devicemode matches current printer so try to use it */
1331 DocumentPropertiesW(0, 0, name
, PrintStructures
->lpDevMode
, lpdm
,
1332 DM_OUT_BUFFER
| DM_IN_BUFFER
);
1335 GlobalUnlock(lppd
->hDevMode
);
1337 lpdm
= PrintStructures
->lpDevMode
; /* use this as a shortcut */
1339 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
1340 /* Print range (All/Range/Selection) */
1341 if(lppd
->nFromPage
!= 0xffff)
1342 SetDlgItemInt(hDlg
, edt1
, lppd
->nFromPage
, FALSE
);
1343 if(lppd
->nToPage
!= 0xffff)
1344 SetDlgItemInt(hDlg
, edt2
, lppd
->nToPage
, FALSE
);
1346 CheckRadioButton(hDlg
, rad1
, rad3
, rad1
); /* default */
1347 if (lppd
->Flags
& PD_NOSELECTION
)
1348 EnableWindow(GetDlgItem(hDlg
, rad2
), FALSE
);
1350 if (lppd
->Flags
& PD_SELECTION
)
1351 CheckRadioButton(hDlg
, rad1
, rad3
, rad2
);
1352 if (lppd
->Flags
& PD_NOPAGENUMS
) {
1353 EnableWindow(GetDlgItem(hDlg
, rad3
), FALSE
);
1354 EnableWindow(GetDlgItem(hDlg
, stc2
),FALSE
);
1355 EnableWindow(GetDlgItem(hDlg
, edt1
), FALSE
);
1356 EnableWindow(GetDlgItem(hDlg
, stc3
),FALSE
);
1357 EnableWindow(GetDlgItem(hDlg
, edt2
), FALSE
);
1359 if (lppd
->Flags
& PD_PAGENUMS
)
1360 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1365 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1367 if (lppd
->Flags
& PD_COLLATE
) {
1368 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1369 (LPARAM
)PrintStructures
->hCollateIcon
);
1370 CheckDlgButton(hDlg
, chx2
, 1);
1372 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1373 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1374 CheckDlgButton(hDlg
, chx2
, 0);
1377 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1378 /* if printer doesn't support it: no Collate */
1379 if (!(lpdm
->dmFields
& DM_COLLATE
)) {
1380 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1381 EnableWindow(GetDlgItem(hDlg
, ico3
), FALSE
);
1388 if (lppd
->hDevMode
== 0)
1389 copies
= lppd
->nCopies
;
1391 copies
= lpdm
->u1
.s1
.dmCopies
;
1392 if(copies
== 0) copies
= 1;
1393 else if(copies
< 0) copies
= MAX_COPIES
;
1394 SetDlgItemInt(hDlg
, edt3
, copies
, FALSE
);
1397 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1398 /* if printer doesn't support it: no nCopies */
1399 if (!(lpdm
->dmFields
& DM_COPIES
)) {
1400 EnableWindow(GetDlgItem(hDlg
, edt3
), FALSE
);
1401 EnableWindow(GetDlgItem(hDlg
, stc5
), FALSE
);
1406 CheckDlgButton(hDlg
, chx1
, (lppd
->Flags
& PD_PRINTTOFILE
) ? 1 : 0);
1407 if (lppd
->Flags
& PD_DISABLEPRINTTOFILE
)
1408 EnableWindow(GetDlgItem(hDlg
, chx1
), FALSE
);
1409 if (lppd
->Flags
& PD_HIDEPRINTTOFILE
)
1410 ShowWindow(GetDlgItem(hDlg
, chx1
), SW_HIDE
);
1412 } else { /* PD_PRINTSETUP */
1413 BOOL bPortrait
= (lpdm
->u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
);
1415 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb2
,
1416 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1417 PrintStructures
->lpPrinterInfo
->pPortName
,
1419 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb3
,
1420 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1421 PrintStructures
->lpPrinterInfo
->pPortName
,
1423 CheckRadioButton(hDlg
, rad1
, rad2
, bPortrait
? rad1
: rad2
);
1424 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1425 (LPARAM
)(bPortrait
? PrintStructures
->hPortraitIcon
:
1426 PrintStructures
->hLandscapeIcon
));
1431 if ((lppd
->Flags
& PD_SHOWHELP
)==0) {
1432 /* hide if PD_SHOWHELP not specified */
1433 ShowWindow(GetDlgItem(hDlg
, pshHelp
), SW_HIDE
);
1438 /***********************************************************************
1439 * check_printer_setup [internal]
1441 static LRESULT
check_printer_setup(HWND hDlg
)
1444 WCHAR resourcestr
[256],resultstr
[256];
1446 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
1449 EnumPrintersW(PRINTER_ENUM_CONNECTIONS
, NULL
, 2, NULL
, 0, &needed
, &num
);
1455 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEVICES
,resultstr
, 255);
1456 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
,resourcestr
, 255);
1457 MessageBoxW(hDlg
, resultstr
, resourcestr
,MB_OK
| MB_ICONWARNING
);
1462 /***********************************************************************
1463 * PRINTDLG_WMInitDialog [internal]
1465 static LRESULT
PRINTDLG_WMInitDialog(HWND hDlg
,
1466 PRINT_PTRA
* PrintStructures
)
1468 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1472 UINT comboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1474 /* load Collate ICONs */
1475 /* We load these with LoadImage because they are not a standard
1476 size and we don't want them rescaled */
1477 PrintStructures
->hCollateIcon
=
1478 LoadImageA(COMDLG32_hInstance
, "PD32_COLLATE", IMAGE_ICON
, 0, 0, 0);
1479 PrintStructures
->hNoCollateIcon
=
1480 LoadImageA(COMDLG32_hInstance
, "PD32_NOCOLLATE", IMAGE_ICON
, 0, 0, 0);
1482 /* These can be done with LoadIcon */
1483 PrintStructures
->hPortraitIcon
=
1484 LoadIconA(COMDLG32_hInstance
, "PD32_PORTRAIT");
1485 PrintStructures
->hLandscapeIcon
=
1486 LoadIconA(COMDLG32_hInstance
, "PD32_LANDSCAPE");
1488 /* display the collate/no_collate icon */
1489 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1490 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1492 if(PrintStructures
->hCollateIcon
== 0 ||
1493 PrintStructures
->hNoCollateIcon
== 0 ||
1494 PrintStructures
->hPortraitIcon
== 0 ||
1495 PrintStructures
->hLandscapeIcon
== 0) {
1496 ERR("no icon in resourcefile\n");
1497 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1498 EndDialog(hDlg
, FALSE
);
1502 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1503 * must be registered and the Help button must be shown.
1505 if (lppd
->Flags
& PD_SHOWHELP
) {
1506 if((PrintStructures
->HelpMessageID
=
1507 RegisterWindowMessageA(HELPMSGSTRINGA
)) == 0) {
1508 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL
);
1512 PrintStructures
->HelpMessageID
= 0;
1514 if(!(lppd
->Flags
&PD_PRINTSETUP
)) {
1515 PrintStructures
->hwndUpDown
=
1516 CreateUpDownControl(WS_CHILD
| WS_VISIBLE
| WS_BORDER
|
1517 UDS_NOTHOUSANDS
| UDS_ARROWKEYS
|
1518 UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, 0, 0, 0, 0,
1519 hDlg
, UPDOWN_ID
, COMDLG32_hInstance
,
1520 GetDlgItem(hDlg
, edt3
), MAX_COPIES
, 1, 1);
1523 /* FIXME: I allow more freedom than either Win95 or WinNT,
1524 * which do not agree on what errors should be thrown or not
1525 * in case nToPage or nFromPage is out-of-range.
1527 if (lppd
->nMaxPage
< lppd
->nMinPage
)
1528 lppd
->nMaxPage
= lppd
->nMinPage
;
1529 if (lppd
->nMinPage
== lppd
->nMaxPage
)
1530 lppd
->Flags
|= PD_NOPAGENUMS
;
1531 if (lppd
->nToPage
< lppd
->nMinPage
)
1532 lppd
->nToPage
= lppd
->nMinPage
;
1533 if (lppd
->nToPage
> lppd
->nMaxPage
)
1534 lppd
->nToPage
= lppd
->nMaxPage
;
1535 if (lppd
->nFromPage
< lppd
->nMinPage
)
1536 lppd
->nFromPage
= lppd
->nMinPage
;
1537 if (lppd
->nFromPage
> lppd
->nMaxPage
)
1538 lppd
->nFromPage
= lppd
->nMaxPage
;
1540 /* if we have the combo box, fill it */
1541 if (GetDlgItem(hDlg
,comboID
)) {
1544 pdn
= GlobalLock(lppd
->hDevNames
);
1545 pdm
= GlobalLock(lppd
->hDevMode
);
1547 name
= (char*)pdn
+ pdn
->wDeviceOffset
;
1549 name
= (char*)pdm
->dmDeviceName
;
1550 PRINTDLG_SetUpPrinterListComboA(hDlg
, comboID
, name
);
1551 if(pdm
) GlobalUnlock(lppd
->hDevMode
);
1552 if(pdn
) GlobalUnlock(lppd
->hDevNames
);
1554 /* Now find selected printer and update rest of dlg */
1555 name
= HeapAlloc(GetProcessHeap(),0,256);
1556 if (GetDlgItemTextA(hDlg
, comboID
, name
, 255))
1557 PRINTDLG_ChangePrinterA(hDlg
, name
, PrintStructures
);
1558 HeapFree(GetProcessHeap(),0,name
);
1560 /* else use default printer */
1562 DWORD dwBufLen
= sizeof(name
);
1563 BOOL ret
= GetDefaultPrinterA(name
, &dwBufLen
);
1566 PRINTDLG_ChangePrinterA(hDlg
, name
, PrintStructures
);
1568 FIXME("No default printer found, expect problems!\n");
1573 static LRESULT
PRINTDLG_WMInitDialogW(HWND hDlg
,
1574 PRINT_PTRW
* PrintStructures
)
1576 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1580 UINT comboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1582 /* load Collate ICONs */
1583 /* We load these with LoadImage because they are not a standard
1584 size and we don't want them rescaled */
1585 PrintStructures
->hCollateIcon
=
1586 LoadImageW(COMDLG32_hInstance
, pd32_collateW
, IMAGE_ICON
, 0, 0, 0);
1587 PrintStructures
->hNoCollateIcon
=
1588 LoadImageW(COMDLG32_hInstance
, pd32_nocollateW
, IMAGE_ICON
, 0, 0, 0);
1590 /* These can be done with LoadIcon */
1591 PrintStructures
->hPortraitIcon
=
1592 LoadIconW(COMDLG32_hInstance
, pd32_portraitW
);
1593 PrintStructures
->hLandscapeIcon
=
1594 LoadIconW(COMDLG32_hInstance
, pd32_landscapeW
);
1596 /* display the collate/no_collate icon */
1597 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1598 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1600 if(PrintStructures
->hCollateIcon
== 0 ||
1601 PrintStructures
->hNoCollateIcon
== 0 ||
1602 PrintStructures
->hPortraitIcon
== 0 ||
1603 PrintStructures
->hLandscapeIcon
== 0) {
1604 ERR("no icon in resourcefile\n");
1605 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1606 EndDialog(hDlg
, FALSE
);
1610 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1611 * must be registered and the Help button must be shown.
1613 if (lppd
->Flags
& PD_SHOWHELP
) {
1614 if((PrintStructures
->HelpMessageID
=
1615 RegisterWindowMessageW(HELPMSGSTRINGW
)) == 0) {
1616 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL
);
1620 PrintStructures
->HelpMessageID
= 0;
1622 if(!(lppd
->Flags
&PD_PRINTSETUP
)) {
1623 PrintStructures
->hwndUpDown
=
1624 CreateUpDownControl(WS_CHILD
| WS_VISIBLE
| WS_BORDER
|
1625 UDS_NOTHOUSANDS
| UDS_ARROWKEYS
|
1626 UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, 0, 0, 0, 0,
1627 hDlg
, UPDOWN_ID
, COMDLG32_hInstance
,
1628 GetDlgItem(hDlg
, edt3
), MAX_COPIES
, 1, 1);
1631 /* FIXME: I allow more freedom than either Win95 or WinNT,
1632 * which do not agree to what errors should be thrown or not
1633 * in case nToPage or nFromPage is out-of-range.
1635 if (lppd
->nMaxPage
< lppd
->nMinPage
)
1636 lppd
->nMaxPage
= lppd
->nMinPage
;
1637 if (lppd
->nMinPage
== lppd
->nMaxPage
)
1638 lppd
->Flags
|= PD_NOPAGENUMS
;
1639 if (lppd
->nToPage
< lppd
->nMinPage
)
1640 lppd
->nToPage
= lppd
->nMinPage
;
1641 if (lppd
->nToPage
> lppd
->nMaxPage
)
1642 lppd
->nToPage
= lppd
->nMaxPage
;
1643 if (lppd
->nFromPage
< lppd
->nMinPage
)
1644 lppd
->nFromPage
= lppd
->nMinPage
;
1645 if (lppd
->nFromPage
> lppd
->nMaxPage
)
1646 lppd
->nFromPage
= lppd
->nMaxPage
;
1648 /* if we have the combo box, fill it */
1649 if (GetDlgItem(hDlg
,comboID
)) {
1652 pdn
= GlobalLock(lppd
->hDevNames
);
1653 pdm
= GlobalLock(lppd
->hDevMode
);
1655 name
= (WCHAR
*)pdn
+ pdn
->wDeviceOffset
;
1657 name
= pdm
->dmDeviceName
;
1658 PRINTDLG_SetUpPrinterListComboW(hDlg
, comboID
, name
);
1659 if(pdm
) GlobalUnlock(lppd
->hDevMode
);
1660 if(pdn
) GlobalUnlock(lppd
->hDevNames
);
1662 /* Now find selected printer and update rest of dlg */
1663 /* ansi is ok here */
1664 name
= HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR
));
1665 if (GetDlgItemTextW(hDlg
, comboID
, name
, 255))
1666 PRINTDLG_ChangePrinterW(hDlg
, name
, PrintStructures
);
1667 HeapFree(GetProcessHeap(),0,name
);
1669 /* else use default printer */
1671 DWORD dwBufLen
= sizeof(name
) / sizeof(WCHAR
);
1672 BOOL ret
= GetDefaultPrinterW(name
, &dwBufLen
);
1675 PRINTDLG_ChangePrinterW(hDlg
, name
, PrintStructures
);
1677 FIXME("No default printer found, expect problems!\n");
1682 /***********************************************************************
1683 * PRINTDLG_WMCommand [internal]
1685 static LRESULT
PRINTDLG_WMCommandA(HWND hDlg
, WPARAM wParam
,
1686 PRINT_PTRA
* PrintStructures
)
1688 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1689 UINT PrinterComboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1690 LPDEVMODEA lpdm
= PrintStructures
->lpDevMode
;
1692 switch (LOWORD(wParam
)) {
1694 TRACE(" OK button was hit\n");
1695 if (!PRINTDLG_UpdatePrintDlgA(hDlg
, PrintStructures
)) {
1696 FIXME("Update printdlg was not successful!\n");
1699 EndDialog(hDlg
, TRUE
);
1703 TRACE(" CANCEL button was hit\n");
1704 EndDialog(hDlg
, FALSE
);
1708 TRACE(" HELP button was hit\n");
1709 SendMessageA(lppd
->hwndOwner
, PrintStructures
->HelpMessageID
,
1710 (WPARAM
) hDlg
, (LPARAM
) lppd
);
1713 case chx2
: /* collate pages checkbox */
1714 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
1715 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1716 (LPARAM
)PrintStructures
->hCollateIcon
);
1718 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1719 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1721 case edt1
: /* from page nr editbox */
1722 case edt2
: /* to page nr editbox */
1723 if (HIWORD(wParam
)==EN_CHANGE
) {
1726 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
1727 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
1728 if (nFromPage
!= lppd
->nFromPage
|| nToPage
!= lppd
->nToPage
)
1729 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1734 if(HIWORD(wParam
) == EN_CHANGE
) {
1735 INT copies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
1737 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1739 EnableWindow(GetDlgItem(hDlg
, chx2
), TRUE
);
1743 case psh2
: /* Properties button */
1746 char PrinterName
[256];
1748 GetDlgItemTextA(hDlg
, PrinterComboID
, PrinterName
, 255);
1749 if (!OpenPrinterA(PrinterName
, &hPrinter
, NULL
)) {
1750 FIXME(" Call to OpenPrinter did not succeed!\n");
1753 DocumentPropertiesA(hDlg
, hPrinter
, PrinterName
,
1754 PrintStructures
->lpDevMode
,
1755 PrintStructures
->lpDevMode
,
1756 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
1757 ClosePrinter(hPrinter
);
1761 case rad1
: /* Paperorientation */
1762 if (lppd
->Flags
& PD_PRINTSETUP
)
1764 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1765 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1766 (LPARAM
)(PrintStructures
->hPortraitIcon
));
1770 case rad2
: /* Paperorientation */
1771 if (lppd
->Flags
& PD_PRINTSETUP
)
1773 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1774 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1775 (LPARAM
)(PrintStructures
->hLandscapeIcon
));
1779 case cmb1
: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT16 */
1780 if (PrinterComboID
!= LOWORD(wParam
)) {
1784 case cmb4
: /* Printer combobox */
1785 if (HIWORD(wParam
)==CBN_SELCHANGE
) {
1786 char PrinterName
[256];
1787 GetDlgItemTextA(hDlg
, LOWORD(wParam
), PrinterName
, 255);
1788 PRINTDLG_ChangePrinterA(hDlg
, PrinterName
, PrintStructures
);
1792 case cmb2
: /* Papersize */
1794 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
1796 lpdm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageA(hDlg
, cmb2
,
1802 case cmb3
: /* Bin */
1804 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
1806 lpdm
->u1
.s1
.dmDefaultSource
= SendDlgItemMessageA(hDlg
, cmb3
,
1807 CB_GETITEMDATA
, Sel
,
1812 if(lppd
->Flags
& PD_PRINTSETUP
) {
1813 switch (LOWORD(wParam
)) {
1814 case rad1
: /* orientation */
1816 if (IsDlgButtonChecked(hDlg
, rad1
) == BST_CHECKED
) {
1817 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_PORTRAIT
) {
1818 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1819 SendDlgItemMessageA(hDlg
, stc10
, STM_SETIMAGE
, IMAGE_ICON
,
1820 (LPARAM
)PrintStructures
->hPortraitIcon
);
1821 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1822 (LPARAM
)PrintStructures
->hPortraitIcon
);
1825 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_LANDSCAPE
) {
1826 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1827 SendDlgItemMessageA(hDlg
, stc10
, STM_SETIMAGE
, IMAGE_ICON
,
1828 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1829 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1830 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1839 static LRESULT
PRINTDLG_WMCommandW(HWND hDlg
, WPARAM wParam
,
1840 PRINT_PTRW
* PrintStructures
)
1842 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1843 UINT PrinterComboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1844 LPDEVMODEW lpdm
= PrintStructures
->lpDevMode
;
1846 switch (LOWORD(wParam
)) {
1848 TRACE(" OK button was hit\n");
1849 if (!PRINTDLG_UpdatePrintDlgW(hDlg
, PrintStructures
)) {
1850 FIXME("Update printdlg was not successful!\n");
1853 EndDialog(hDlg
, TRUE
);
1857 TRACE(" CANCEL button was hit\n");
1858 EndDialog(hDlg
, FALSE
);
1862 TRACE(" HELP button was hit\n");
1863 SendMessageW(lppd
->hwndOwner
, PrintStructures
->HelpMessageID
,
1864 (WPARAM
) hDlg
, (LPARAM
) lppd
);
1867 case chx2
: /* collate pages checkbox */
1868 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
1869 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1870 (LPARAM
)PrintStructures
->hCollateIcon
);
1872 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1873 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1875 case edt1
: /* from page nr editbox */
1876 case edt2
: /* to page nr editbox */
1877 if (HIWORD(wParam
)==EN_CHANGE
) {
1880 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
1881 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
1882 if (nFromPage
!= lppd
->nFromPage
|| nToPage
!= lppd
->nToPage
)
1883 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1888 if(HIWORD(wParam
) == EN_CHANGE
) {
1889 INT copies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
1891 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1893 EnableWindow(GetDlgItem(hDlg
, chx2
), TRUE
);
1897 case psh2
: /* Properties button */
1900 WCHAR PrinterName
[256];
1902 if (!GetDlgItemTextW(hDlg
, PrinterComboID
, PrinterName
, 255)) break;
1903 if (!OpenPrinterW(PrinterName
, &hPrinter
, NULL
)) {
1904 FIXME(" Call to OpenPrinter did not succeed!\n");
1907 DocumentPropertiesW(hDlg
, hPrinter
, PrinterName
,
1908 PrintStructures
->lpDevMode
,
1909 PrintStructures
->lpDevMode
,
1910 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
1911 ClosePrinter(hPrinter
);
1915 case rad1
: /* Paperorientation */
1916 if (lppd
->Flags
& PD_PRINTSETUP
)
1918 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1919 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1920 (LPARAM
)(PrintStructures
->hPortraitIcon
));
1924 case rad2
: /* Paperorientation */
1925 if (lppd
->Flags
& PD_PRINTSETUP
)
1927 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1928 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1929 (LPARAM
)(PrintStructures
->hLandscapeIcon
));
1933 case cmb1
: /* Printer Combobox in PRINT SETUP */
1935 case cmb4
: /* Printer combobox */
1936 if (HIWORD(wParam
)==CBN_SELCHANGE
) {
1937 WCHAR PrinterName
[256];
1938 GetDlgItemTextW(hDlg
, LOWORD(wParam
), PrinterName
, 255);
1939 PRINTDLG_ChangePrinterW(hDlg
, PrinterName
, PrintStructures
);
1943 case cmb2
: /* Papersize */
1945 DWORD Sel
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
1947 lpdm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageW(hDlg
, cmb2
,
1953 case cmb3
: /* Bin */
1955 DWORD Sel
= SendDlgItemMessageW(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
1957 lpdm
->u1
.s1
.dmDefaultSource
= SendDlgItemMessageW(hDlg
, cmb3
,
1958 CB_GETITEMDATA
, Sel
,
1963 if(lppd
->Flags
& PD_PRINTSETUP
) {
1964 switch (LOWORD(wParam
)) {
1965 case rad1
: /* orientation */
1967 if (IsDlgButtonChecked(hDlg
, rad1
) == BST_CHECKED
) {
1968 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_PORTRAIT
) {
1969 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1970 SendDlgItemMessageW(hDlg
, stc10
, STM_SETIMAGE
, IMAGE_ICON
,
1971 (LPARAM
)PrintStructures
->hPortraitIcon
);
1972 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1973 (LPARAM
)PrintStructures
->hPortraitIcon
);
1976 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_LANDSCAPE
) {
1977 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1978 SendDlgItemMessageW(hDlg
, stc10
, STM_SETIMAGE
, IMAGE_ICON
,
1979 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1980 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1981 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1990 /***********************************************************************
1991 * PrintDlgProcA [internal]
1993 static INT_PTR CALLBACK
PrintDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
1996 PRINT_PTRA
* PrintStructures
;
1997 INT_PTR res
= FALSE
;
1999 if (uMsg
!=WM_INITDIALOG
) {
2000 PrintStructures
= GetPropW(hDlg
, printdlg_prop
);
2001 if (!PrintStructures
)
2004 PrintStructures
= (PRINT_PTRA
*) lParam
;
2005 SetPropW(hDlg
, printdlg_prop
, PrintStructures
);
2006 if(!check_printer_setup(hDlg
))
2008 EndDialog(hDlg
,FALSE
);
2011 res
= PRINTDLG_WMInitDialog(hDlg
, PrintStructures
);
2013 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
)
2014 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(
2015 hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->lpPrintDlg
2020 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
) {
2021 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
,uMsg
,wParam
,
2028 return PRINTDLG_WMCommandA(hDlg
, wParam
, PrintStructures
);
2031 DestroyIcon(PrintStructures
->hCollateIcon
);
2032 DestroyIcon(PrintStructures
->hNoCollateIcon
);
2033 DestroyIcon(PrintStructures
->hPortraitIcon
);
2034 DestroyIcon(PrintStructures
->hLandscapeIcon
);
2035 if(PrintStructures
->hwndUpDown
)
2036 DestroyWindow(PrintStructures
->hwndUpDown
);
2042 static INT_PTR CALLBACK
PrintDlgProcW(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
2045 PRINT_PTRW
* PrintStructures
;
2046 INT_PTR res
= FALSE
;
2048 if (uMsg
!=WM_INITDIALOG
) {
2049 PrintStructures
= GetPropW(hDlg
, printdlg_prop
);
2050 if (!PrintStructures
)
2053 PrintStructures
= (PRINT_PTRW
*) lParam
;
2054 SetPropW(hDlg
, printdlg_prop
, PrintStructures
);
2055 if(!check_printer_setup(hDlg
))
2057 EndDialog(hDlg
,FALSE
);
2060 res
= PRINTDLG_WMInitDialogW(hDlg
, PrintStructures
);
2062 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
)
2063 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->lpPrintDlg
);
2067 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
) {
2068 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
,uMsg
,wParam
, lParam
);
2074 return PRINTDLG_WMCommandW(hDlg
, wParam
, PrintStructures
);
2077 DestroyIcon(PrintStructures
->hCollateIcon
);
2078 DestroyIcon(PrintStructures
->hNoCollateIcon
);
2079 DestroyIcon(PrintStructures
->hPortraitIcon
);
2080 DestroyIcon(PrintStructures
->hLandscapeIcon
);
2081 if(PrintStructures
->hwndUpDown
)
2082 DestroyWindow(PrintStructures
->hwndUpDown
);
2088 /************************************************************
2090 * PRINTDLG_GetDlgTemplate
2093 static HGLOBAL
PRINTDLG_GetDlgTemplateA(const PRINTDLGA
*lppd
)
2098 if (lppd
->Flags
& PD_PRINTSETUP
) {
2099 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
2100 hDlgTmpl
= lppd
->hSetupTemplate
;
2101 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
2102 hResInfo
= FindResourceA(lppd
->hInstance
,
2103 lppd
->lpSetupTemplateName
, (LPSTR
)RT_DIALOG
);
2104 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
2106 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32_SETUP",
2108 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
2111 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
2112 hDlgTmpl
= lppd
->hPrintTemplate
;
2113 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
2114 hResInfo
= FindResourceA(lppd
->hInstance
,
2115 lppd
->lpPrintTemplateName
,
2117 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
2119 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32",
2121 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
2127 static HGLOBAL
PRINTDLG_GetDlgTemplateW(const PRINTDLGW
*lppd
)
2131 static const WCHAR xpsetup
[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
2132 static const WCHAR xprint
[] = { 'P','R','I','N','T','3','2',0};
2134 if (lppd
->Flags
& PD_PRINTSETUP
) {
2135 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
2136 hDlgTmpl
= lppd
->hSetupTemplate
;
2137 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
2138 hResInfo
= FindResourceW(lppd
->hInstance
,
2139 lppd
->lpSetupTemplateName
, (LPWSTR
)RT_DIALOG
);
2140 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
2142 hResInfo
= FindResourceW(COMDLG32_hInstance
, xpsetup
, (LPWSTR
)RT_DIALOG
);
2143 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
2146 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
2147 hDlgTmpl
= lppd
->hPrintTemplate
;
2148 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
2149 hResInfo
= FindResourceW(lppd
->hInstance
,
2150 lppd
->lpPrintTemplateName
,
2152 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
2154 hResInfo
= FindResourceW(COMDLG32_hInstance
, xprint
, (LPWSTR
)RT_DIALOG
);
2155 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
2161 /***********************************************************************
2166 static BOOL
PRINTDLG_CreateDCA(LPPRINTDLGA lppd
)
2168 DEVNAMES
*pdn
= GlobalLock(lppd
->hDevNames
);
2169 DEVMODEA
*pdm
= GlobalLock(lppd
->hDevMode
);
2171 if(lppd
->Flags
& PD_RETURNDC
) {
2172 lppd
->hDC
= CreateDCA((char*)pdn
+ pdn
->wDriverOffset
,
2173 (char*)pdn
+ pdn
->wDeviceOffset
,
2174 (char*)pdn
+ pdn
->wOutputOffset
,
2176 } else if(lppd
->Flags
& PD_RETURNIC
) {
2177 lppd
->hDC
= CreateICA((char*)pdn
+ pdn
->wDriverOffset
,
2178 (char*)pdn
+ pdn
->wDeviceOffset
,
2179 (char*)pdn
+ pdn
->wOutputOffset
,
2182 GlobalUnlock(lppd
->hDevNames
);
2183 GlobalUnlock(lppd
->hDevMode
);
2184 return lppd
->hDC
? TRUE
: FALSE
;
2187 static BOOL
PRINTDLG_CreateDCW(LPPRINTDLGW lppd
)
2189 DEVNAMES
*pdn
= GlobalLock(lppd
->hDevNames
);
2190 DEVMODEW
*pdm
= GlobalLock(lppd
->hDevMode
);
2192 if(lppd
->Flags
& PD_RETURNDC
) {
2193 lppd
->hDC
= CreateDCW((WCHAR
*)pdn
+ pdn
->wDriverOffset
,
2194 (WCHAR
*)pdn
+ pdn
->wDeviceOffset
,
2195 (WCHAR
*)pdn
+ pdn
->wOutputOffset
,
2197 } else if(lppd
->Flags
& PD_RETURNIC
) {
2198 lppd
->hDC
= CreateICW((WCHAR
*)pdn
+ pdn
->wDriverOffset
,
2199 (WCHAR
*)pdn
+ pdn
->wDeviceOffset
,
2200 (WCHAR
*)pdn
+ pdn
->wOutputOffset
,
2203 GlobalUnlock(lppd
->hDevNames
);
2204 GlobalUnlock(lppd
->hDevMode
);
2205 return lppd
->hDC
? TRUE
: FALSE
;
2208 /***********************************************************************
2209 * PrintDlgA (COMDLG32.@)
2211 * Displays the PRINT dialog box, which enables the user to specify
2212 * specific properties of the print job.
2215 * lppd [IO] ptr to PRINTDLG32 struct
2218 * nonzero if the user pressed the OK button
2219 * zero if the user cancelled the window or an error occurred
2223 * * The Collate Icons do not display, even though they are in the code.
2224 * * The Properties Button(s) should call DocumentPropertiesA().
2227 BOOL WINAPI
PrintDlgA(LPPRINTDLGA lppd
)
2235 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
2239 if(TRACE_ON(commdlg
)) {
2240 char flagstr
[1000] = "";
2241 const struct pd_flags
*pflag
= pd_flags
;
2242 for( ; pflag
->name
; pflag
++) {
2243 if(lppd
->Flags
& pflag
->flag
)
2244 strcat(flagstr
, pflag
->name
);
2246 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2247 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2248 "flags %08x (%s)\n",
2249 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
2250 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
2251 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
2254 if(lppd
->lStructSize
!= sizeof(PRINTDLGA
)) {
2255 WARN("structure size failure !!!\n");
2256 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
2260 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
2261 PRINTER_INFO_2A
*pbuf
;
2262 DRIVER_INFO_3A
*dbuf
;
2266 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
2267 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2268 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2271 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
2272 WARN("Can't find default printer\n");
2273 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
2277 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
2278 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
2279 GetPrinterA(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
2281 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
2282 dbuf
= HeapAlloc(GetProcessHeap(),0,needed
);
2283 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
2284 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2285 GetLastError(),pbuf
->pPrinterName
);
2286 HeapFree(GetProcessHeap(), 0, dbuf
);
2287 HeapFree(GetProcessHeap(), 0, pbuf
);
2288 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2293 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
2297 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
2298 pbuf
->pDevMode
->dmDriverExtra
);
2299 ptr
= GlobalLock(lppd
->hDevMode
);
2300 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
2301 pbuf
->pDevMode
->dmDriverExtra
);
2302 GlobalUnlock(lppd
->hDevMode
);
2303 HeapFree(GetProcessHeap(), 0, pbuf
);
2304 HeapFree(GetProcessHeap(), 0, dbuf
);
2308 PRINT_PTRA
*PrintStructures
;
2310 /* load Dialog resources,
2311 * depending on Flags indicates Print32 or Print32_setup dialog
2313 hDlgTmpl
= PRINTDLG_GetDlgTemplateA(lppd
);
2315 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2318 ptr
= LockResource( hDlgTmpl
);
2320 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2324 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2325 sizeof(PRINT_PTRA
));
2326 PrintStructures
->lpPrintDlg
= lppd
;
2328 /* and create & process the dialog .
2329 * -1 is failure, 0 is broken hwnd, everything else is ok.
2331 hInst
= COMDLG32_hInstance
;
2332 if (lppd
->Flags
& (PD_ENABLESETUPTEMPLATE
| PD_ENABLEPRINTTEMPLATE
)) hInst
= lppd
->hInstance
;
2333 bRet
= (0<DialogBoxIndirectParamA(hInst
, ptr
, lppd
->hwndOwner
,
2335 (LPARAM
)PrintStructures
));
2338 DEVMODEA
*lpdm
= PrintStructures
->lpDevMode
, *lpdmReturn
;
2339 PRINTER_INFO_2A
*pi
= PrintStructures
->lpPrinterInfo
;
2340 DRIVER_INFO_3A
*di
= PrintStructures
->lpDriverInfo
;
2342 if (lppd
->hDevMode
== 0) {
2343 TRACE(" No hDevMode yet... Need to create my own\n");
2344 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
,
2345 lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2347 lppd
->hDevMode
= GlobalReAlloc(lppd
->hDevMode
,
2348 lpdm
->dmSize
+ lpdm
->dmDriverExtra
,
2351 lpdmReturn
= GlobalLock(lppd
->hDevMode
);
2352 memcpy(lpdmReturn
, lpdm
, lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2354 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
2359 GlobalUnlock(lppd
->hDevMode
);
2361 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
2362 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpPrinterInfo
);
2363 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDriverInfo
);
2364 HeapFree(GetProcessHeap(), 0, PrintStructures
);
2366 if(bRet
&& (lppd
->Flags
& PD_RETURNDC
|| lppd
->Flags
& PD_RETURNIC
))
2367 bRet
= PRINTDLG_CreateDCA(lppd
);
2369 TRACE("exit! (%d)\n", bRet
);
2373 /***********************************************************************
2374 * PrintDlgW (COMDLG32.@)
2378 BOOL WINAPI
PrintDlgW(LPPRINTDLGW lppd
)
2386 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
2390 if(TRACE_ON(commdlg
)) {
2391 char flagstr
[1000] = "";
2392 const struct pd_flags
*pflag
= pd_flags
;
2393 for( ; pflag
->name
; pflag
++) {
2394 if(lppd
->Flags
& pflag
->flag
)
2395 strcat(flagstr
, pflag
->name
);
2397 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2398 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2399 "flags %08x (%s)\n",
2400 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
2401 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
2402 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
2405 if(lppd
->lStructSize
!= sizeof(PRINTDLGW
)) {
2406 WARN("structure size failure !!!\n");
2407 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
2411 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
2412 PRINTER_INFO_2W
*pbuf
;
2413 DRIVER_INFO_3W
*dbuf
;
2417 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
2418 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2419 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2422 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
2423 WARN("Can't find default printer\n");
2424 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
2428 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
2429 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
2430 GetPrinterW(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
2432 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
2433 dbuf
= HeapAlloc(GetProcessHeap(),0,needed
);
2434 if (!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
2435 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2436 GetLastError(),debugstr_w(pbuf
->pPrinterName
));
2437 HeapFree(GetProcessHeap(), 0, dbuf
);
2438 HeapFree(GetProcessHeap(), 0, pbuf
);
2439 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2444 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
2448 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
2449 pbuf
->pDevMode
->dmDriverExtra
);
2450 ptr
= GlobalLock(lppd
->hDevMode
);
2451 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
2452 pbuf
->pDevMode
->dmDriverExtra
);
2453 GlobalUnlock(lppd
->hDevMode
);
2454 HeapFree(GetProcessHeap(), 0, pbuf
);
2455 HeapFree(GetProcessHeap(), 0, dbuf
);
2459 PRINT_PTRW
*PrintStructures
;
2461 /* load Dialog resources,
2462 * depending on Flags indicates Print32 or Print32_setup dialog
2464 hDlgTmpl
= PRINTDLG_GetDlgTemplateW(lppd
);
2466 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2469 ptr
= LockResource( hDlgTmpl
);
2471 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2475 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2476 sizeof(PRINT_PTRW
));
2477 PrintStructures
->lpPrintDlg
= lppd
;
2479 /* and create & process the dialog .
2480 * -1 is failure, 0 is broken hwnd, everything else is ok.
2482 hInst
= COMDLG32_hInstance
;
2483 if (lppd
->Flags
& (PD_ENABLESETUPTEMPLATE
| PD_ENABLEPRINTTEMPLATE
)) hInst
= lppd
->hInstance
;
2484 bRet
= (0<DialogBoxIndirectParamW(hInst
, ptr
, lppd
->hwndOwner
,
2486 (LPARAM
)PrintStructures
));
2489 DEVMODEW
*lpdm
= PrintStructures
->lpDevMode
, *lpdmReturn
;
2490 PRINTER_INFO_2W
*pi
= PrintStructures
->lpPrinterInfo
;
2491 DRIVER_INFO_3W
*di
= PrintStructures
->lpDriverInfo
;
2493 if (lppd
->hDevMode
== 0) {
2494 TRACE(" No hDevMode yet... Need to create my own\n");
2495 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
,
2496 lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2499 if((locks
= (GlobalFlags(lppd
->hDevMode
) & GMEM_LOCKCOUNT
))) {
2500 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks
);
2502 GlobalUnlock(lppd
->hDevMode
);
2503 TRACE("Now got %d locks\n", locks
);
2506 lppd
->hDevMode
= GlobalReAlloc(lppd
->hDevMode
,
2507 lpdm
->dmSize
+ lpdm
->dmDriverExtra
,
2510 lpdmReturn
= GlobalLock(lppd
->hDevMode
);
2511 memcpy(lpdmReturn
, lpdm
, lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2513 if (lppd
->hDevNames
!= 0) {
2515 if((locks
= (GlobalFlags(lppd
->hDevNames
) & GMEM_LOCKCOUNT
))) {
2516 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks
);
2518 GlobalUnlock(lppd
->hDevNames
);
2521 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
2526 GlobalUnlock(lppd
->hDevMode
);
2528 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
2529 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpPrinterInfo
);
2530 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDriverInfo
);
2531 HeapFree(GetProcessHeap(), 0, PrintStructures
);
2533 if(bRet
&& (lppd
->Flags
& PD_RETURNDC
|| lppd
->Flags
& PD_RETURNIC
))
2534 bRet
= PRINTDLG_CreateDCW(lppd
);
2536 TRACE("exit! (%d)\n", bRet
);
2540 /***********************************************************************
2545 * cmb1 - printer select (not in standard dialog template)
2547 * cmb3 - source (tray?)
2548 * edt4 - border left
2550 * edt6 - border right
2551 * edt7 - border bottom
2552 * psh3 - "Printer..."
2560 LPPAGESETUPDLGA dlga
;
2561 LPPAGESETUPDLGW dlgw
;
2563 HWND hDlg
; /* Page Setup dialog handle */
2564 RECT rtDrawRect
; /* Drawing rect for page */
2567 static inline DWORD
pagesetup_get_flags(const pagesetup_data
*data
)
2569 return data
->u
.dlgw
->Flags
;
2572 static inline BOOL
is_metric(const pagesetup_data
*data
)
2574 return pagesetup_get_flags(data
) & PSD_INHUNDREDTHSOFMILLIMETERS
;
2577 static inline LONG
tenths_mm_to_size(const pagesetup_data
*data
, LONG size
)
2579 if (is_metric(data
))
2582 return 10 * size
* 100 / 254;
2585 static inline LONG
thousandths_inch_to_size(const pagesetup_data
*data
, LONG size
)
2587 if (is_metric(data
))
2588 return size
* 254 / 100;
2593 static WCHAR
get_decimal_sep(void)
2599 WCHAR buf
[] = {'.', 0};
2600 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SDECIMAL
, buf
, sizeof(buf
) / sizeof(buf
[0]));
2606 static void size2str(const pagesetup_data
*data
, DWORD size
, LPWSTR strout
)
2608 WCHAR integer_fmt
[] = {'%','d',0};
2609 WCHAR hundredths_fmt
[] = {'%','d','%','c','%','0','2','d',0};
2610 WCHAR thousandths_fmt
[] = {'%','d','%','c','%','0','3','d',0};
2612 /* FIXME use LOCALE_SDECIMAL when the edit parsing code can cope */
2614 if (is_metric(data
))
2617 wsprintfW(strout
, hundredths_fmt
, size
/ 100, get_decimal_sep(), size
% 100);
2619 wsprintfW(strout
, integer_fmt
, size
/ 100);
2624 wsprintfW(strout
, thousandths_fmt
, size
/ 1000, get_decimal_sep(), size
% 1000);
2626 wsprintfW(strout
, integer_fmt
, 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
= (strlenW(drv
) + 1) * sizeof(WCHAR
);
2809 dev_len
= (strlenW(devname
) + 1) * sizeof(WCHAR
);
2810 port_len
= (strlenW(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 strcpyW(ptr
, devname
);
2837 ptr
+= dev_len
/ sizeof(WCHAR
);
2838 len
+= dev_len
/ sizeof(WCHAR
);
2839 dn
->wOutputOffset
= len
;
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
= sizeof(def
) / sizeof(def
[0]);
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
, sizeof(buf
) / sizeof(buf
[0])) != 0)
3236 WCHAR decimal
= get_decimal_sep();
3238 val
= strtolW(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
, sizeof(title
)/sizeof(title
[0])))
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 GetDlgItemTextW(hDlg
, id
, name
, sizeof(name
) / sizeof(name
[0]));
3383 pagesetup_change_printer(name
, data
);
3384 pagesetup_init_combos(hDlg
, data
);
3387 case cmb2
: /* Paper combo */
3388 if(msg
== CBN_SELCHANGE
)
3390 DWORD paperword
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETITEMDATA
,
3391 SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0), 0);
3392 if (paperword
!= CB_ERR
)
3394 pagesetup_set_papersize(data
, paperword
);
3395 pagesetup_update_papersize(data
);
3396 pagesetup_change_preview(data
);
3398 FIXME("could not get dialog text for papersize cmbbox?\n");
3401 case cmb3
: /* Paper Source */
3402 if(msg
== CBN_SELCHANGE
)
3404 WORD source
= SendDlgItemMessageW(hDlg
, cmb3
, CB_GETITEMDATA
,
3405 SendDlgItemMessageW(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0), 0);
3406 pagesetup_set_defaultsource(data
, source
);
3409 case psh2
: /* Printer Properties button */
3410 pagesetup_printer_properties(hDlg
, data
);
3416 margin_edit_notification(hDlg
, data
, msg
, id
);
3419 InvalidateRect(GetDlgItem(hDlg
, rct1
), NULL
, TRUE
);
3423 /***********************************************************************
3424 * default_page_paint_hook
3425 * Default hook paint procedure that receives WM_PSD_* messages from the dialog box
3426 * whenever the sample page is redrawn.
3428 static UINT_PTR
default_page_paint_hook(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
,
3429 const pagesetup_data
*data
)
3431 LPRECT lprc
= (LPRECT
) lParam
;
3432 HDC hdc
= (HDC
) wParam
;
3435 HFONT hfont
, holdfont
;
3437 TRACE("uMsg: WM_USER+%d\n",uMsg
-WM_USER
);
3438 /* Call user paint hook if enable */
3439 if (pagesetup_get_flags(data
) & PSD_ENABLEPAGEPAINTHOOK
)
3440 if (pagesetup_get_hook(data
, page_paint_hook
)(hwndDlg
, uMsg
, wParam
, lParam
))
3444 /* LPPAGESETUPDLG in lParam */
3445 case WM_PSD_PAGESETUPDLG
:
3446 /* Inform about the sample page rectangle */
3447 case WM_PSD_FULLPAGERECT
:
3448 /* Inform about the margin rectangle */
3449 case WM_PSD_MINMARGINRECT
:
3452 /* Draw dashed rectangle showing margins */
3453 case WM_PSD_MARGINRECT
:
3454 hpen
= CreatePen(PS_DASH
, 1, GetSysColor(COLOR_3DSHADOW
));
3455 holdpen
= SelectObject(hdc
, hpen
);
3456 Rectangle(hdc
, lprc
->left
, lprc
->top
, lprc
->right
, lprc
->bottom
);
3457 DeleteObject(SelectObject(hdc
, holdpen
));
3459 /* Draw the fake document */
3460 case WM_PSD_GREEKTEXTRECT
:
3461 /* select a nice scalable font, because we want the text really small */
3462 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, sizeof(lf
), &lf
, 0);
3463 lf
.lfHeight
= 6; /* value chosen based on visual effect */
3464 hfont
= CreateFontIndirectW(&lf
);
3465 holdfont
= SelectObject(hdc
, hfont
);
3467 /* if text not loaded, then do so now */
3468 if (wszFakeDocumentText
[0] == '\0')
3469 LoadStringW(COMDLG32_hInstance
,
3471 wszFakeDocumentText
,
3472 sizeof(wszFakeDocumentText
)/sizeof(wszFakeDocumentText
[0]));
3474 oldbkmode
= SetBkMode(hdc
, TRANSPARENT
);
3475 DrawTextW(hdc
, wszFakeDocumentText
, -1, lprc
, DT_TOP
|DT_LEFT
|DT_NOPREFIX
|DT_WORDBREAK
);
3476 SetBkMode(hdc
, oldbkmode
);
3478 DeleteObject(SelectObject(hdc
, holdfont
));
3481 /* Envelope stamp */
3482 case WM_PSD_ENVSTAMPRECT
:
3483 /* Return address */
3484 case WM_PSD_YAFULLPAGERECT
:
3485 FIXME("envelope/stamp is not implemented\n");
3488 FIXME("Unknown message %x\n",uMsg
);
3494 /***********************************************************************
3496 * The main paint procedure for the PageSetupDlg function.
3497 * The Page Setup dialog box includes an image of a sample page that shows how
3498 * the user's selections affect the appearance of the printed output.
3499 * The image consists of a rectangle that represents the selected paper
3500 * or envelope type, with a dotted-line rectangle representing
3501 * the current margins, and partial (Greek text) characters
3502 * to show how text looks on the printed page.
3504 * The following messages in the order sends to user hook procedure:
3505 * WM_PSD_PAGESETUPDLG Draw the contents of the sample page
3506 * WM_PSD_FULLPAGERECT Inform about the bounding rectangle
3507 * WM_PSD_MINMARGINRECT Inform about the margin rectangle (min margin?)
3508 * WM_PSD_MARGINRECT Draw the margin rectangle
3509 * WM_PSD_GREEKTEXTRECT Draw the Greek text inside the margin rectangle
3510 * If any of first three messages returns TRUE, painting done.
3513 * hWnd [in] Handle to the Page Setup dialog box
3514 * uMsg [in] Received message
3517 * WM_PSD_ENVSTAMPRECT Draw in the envelope-stamp rectangle (for envelopes only)
3518 * WM_PSD_YAFULLPAGERECT Draw the return address portion (for envelopes and other paper sizes)
3521 * FALSE if all done correctly
3526 static LRESULT CALLBACK
3527 PRINTDLG_PagePaintProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3530 RECT rcClient
, rcMargin
;
3533 HBRUSH hbrush
, holdbrush
;
3534 pagesetup_data
*data
;
3535 int papersize
=0, orientation
=0; /* FIXME: set these values for the user paint hook */
3536 double scalx
, scaly
;
3538 if (uMsg
!= WM_PAINT
)
3539 return CallWindowProcA(lpfnStaticWndProc
, hWnd
, uMsg
, wParam
, lParam
);
3541 /* Processing WM_PAINT message */
3542 data
= GetPropW(hWnd
, pagesetupdlg_prop
);
3544 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3547 if (default_page_paint_hook(hWnd
, WM_PSD_PAGESETUPDLG
, MAKELONG(papersize
, orientation
),
3548 pagesetup_get_dlg_struct(data
), data
))
3551 hdc
= BeginPaint(hWnd
, &ps
);
3552 GetClientRect(hWnd
, &rcClient
);
3554 scalx
= rcClient
.right
/ (double)pagesetup_get_papersize_pt(data
)->x
;
3555 scaly
= rcClient
.bottom
/ (double)pagesetup_get_papersize_pt(data
)->y
;
3556 rcMargin
= rcClient
;
3558 rcMargin
.left
+= pagesetup_get_margin_rect(data
)->left
* scalx
;
3559 rcMargin
.top
+= pagesetup_get_margin_rect(data
)->top
* scaly
;
3560 rcMargin
.right
-= pagesetup_get_margin_rect(data
)->right
* scalx
;
3561 rcMargin
.bottom
-= pagesetup_get_margin_rect(data
)->bottom
* scaly
;
3563 /* if the space is too small then we make sure to not draw anything */
3564 rcMargin
.left
= min(rcMargin
.left
, rcMargin
.right
);
3565 rcMargin
.top
= min(rcMargin
.top
, rcMargin
.bottom
);
3567 if (!default_page_paint_hook(hWnd
, WM_PSD_FULLPAGERECT
, (WPARAM
)hdc
, (LPARAM
)&rcClient
, data
) &&
3568 !default_page_paint_hook(hWnd
, WM_PSD_MINMARGINRECT
, (WPARAM
)hdc
, (LPARAM
)&rcMargin
, data
) )
3570 /* fill background */
3571 hbrush
= GetSysColorBrush(COLOR_3DHIGHLIGHT
);
3572 FillRect(hdc
, &rcClient
, hbrush
);
3573 holdbrush
= SelectObject(hdc
, hbrush
);
3575 hpen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DSHADOW
));
3576 holdpen
= SelectObject(hdc
, hpen
);
3578 /* paint left edge */
3579 MoveToEx(hdc
, rcClient
.left
, rcClient
.top
, NULL
);
3580 LineTo(hdc
, rcClient
.left
, rcClient
.bottom
-1);
3582 /* paint top edge */
3583 MoveToEx(hdc
, rcClient
.left
, rcClient
.top
, NULL
);
3584 LineTo(hdc
, rcClient
.right
, rcClient
.top
);
3586 hpen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DDKSHADOW
));
3587 DeleteObject(SelectObject(hdc
, hpen
));
3589 /* paint right edge */
3590 MoveToEx(hdc
, rcClient
.right
-1, rcClient
.top
, NULL
);
3591 LineTo(hdc
, rcClient
.right
-1, rcClient
.bottom
);
3593 /* paint bottom edge */
3594 MoveToEx(hdc
, rcClient
.left
, rcClient
.bottom
-1, NULL
);
3595 LineTo(hdc
, rcClient
.right
, rcClient
.bottom
-1);
3597 DeleteObject(SelectObject(hdc
, holdpen
));
3598 DeleteObject(SelectObject(hdc
, holdbrush
));
3600 default_page_paint_hook(hWnd
, WM_PSD_MARGINRECT
, (WPARAM
)hdc
, (LPARAM
)&rcMargin
, data
);
3602 /* give text a bit of a space from the frame */
3605 rcMargin
.right
-= 2;
3606 rcMargin
.bottom
-= 2;
3608 /* if the space is too small then we make sure to not draw anything */
3609 rcMargin
.left
= min(rcMargin
.left
, rcMargin
.right
);
3610 rcMargin
.top
= min(rcMargin
.top
, rcMargin
.bottom
);
3612 default_page_paint_hook(hWnd
, WM_PSD_GREEKTEXTRECT
, (WPARAM
)hdc
, (LPARAM
)&rcMargin
, data
);
3615 EndPaint(hWnd
, &ps
);
3619 /*******************************************************
3620 * The margin edit controls are subclassed to filter
3621 * anything other than numbers and the decimal separator.
3623 static LRESULT CALLBACK
pagesetup_margin_editproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3627 WCHAR decimal
= get_decimal_sep();
3628 WCHAR wc
= (WCHAR
)wparam
;
3629 if(!isdigitW(wc
) && wc
!= decimal
&& wc
!= VK_BACK
) return 0;
3631 return CallWindowProcW(edit_wndproc
, hwnd
, msg
, wparam
, lparam
);
3634 static void subclass_margin_edits(HWND hDlg
)
3639 for(id
= edt4
; id
<= edt7
; id
++)
3641 old_proc
= (WNDPROC
)SetWindowLongPtrW(GetDlgItem(hDlg
, id
),
3643 (ULONG_PTR
)pagesetup_margin_editproc
);
3644 InterlockedCompareExchangePointer((void**)&edit_wndproc
, old_proc
, NULL
);
3648 /***********************************************************************
3649 * pagesetup_dlg_proc
3651 * Message handler for PageSetupDlg
3653 static INT_PTR CALLBACK
pagesetup_dlg_proc(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3655 pagesetup_data
*data
;
3656 INT_PTR res
= FALSE
;
3659 if (uMsg
== WM_INITDIALOG
) { /*Init dialog*/
3660 data
= (pagesetup_data
*)lParam
;
3663 hDrawWnd
= GetDlgItem(hDlg
, rct1
);
3664 TRACE("set property to %p\n", data
);
3665 SetPropW(hDlg
, pagesetupdlg_prop
, data
);
3666 SetPropW(hDrawWnd
, pagesetupdlg_prop
, data
);
3667 GetWindowRect(hDrawWnd
, &data
->rtDrawRect
); /* Calculating rect in client coordinates where paper draws */
3668 MapWindowPoints( 0, hDlg
, (LPPOINT
)&data
->rtDrawRect
, 2 );
3669 lpfnStaticWndProc
= (WNDPROC
)SetWindowLongPtrW(
3672 (ULONG_PTR
)PRINTDLG_PagePaintProc
);
3674 /* FIXME: Paint hook. Must it be at begin of initialization or at end? */
3676 if (pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPHOOK
)
3678 if (!pagesetup_get_hook(data
, page_setup_hook
)(hDlg
, uMsg
, wParam
,
3679 pagesetup_get_dlg_struct(data
)))
3680 FIXME("Setup page hook failed?\n");
3683 /* if printer button disabled */
3684 if (pagesetup_get_flags(data
) & PSD_DISABLEPRINTER
)
3685 EnableWindow(GetDlgItem(hDlg
, psh3
), FALSE
);
3686 /* if margin edit boxes disabled */
3687 if (pagesetup_get_flags(data
) & PSD_DISABLEMARGINS
)
3689 EnableWindow(GetDlgItem(hDlg
, edt4
), FALSE
);
3690 EnableWindow(GetDlgItem(hDlg
, edt5
), FALSE
);
3691 EnableWindow(GetDlgItem(hDlg
, edt6
), FALSE
);
3692 EnableWindow(GetDlgItem(hDlg
, edt7
), FALSE
);
3695 /* Set orientation radiobuttons properly */
3696 pagesetup_update_orientation_buttons(hDlg
, data
);
3698 /* if orientation disabled */
3699 if (pagesetup_get_flags(data
) & PSD_DISABLEORIENTATION
)
3701 EnableWindow(GetDlgItem(hDlg
,rad1
),FALSE
);
3702 EnableWindow(GetDlgItem(hDlg
,rad2
),FALSE
);
3705 /* We fill them out enabled or not */
3706 if (!(pagesetup_get_flags(data
) & PSD_MARGINS
))
3708 /* default is 1 inch */
3709 LONG size
= thousandths_inch_to_size(data
, 1000);
3710 SetRect(pagesetup_get_margin_rect(data
), size
, size
, size
, size
);
3712 update_margin_edits(hDlg
, data
, 0);
3713 subclass_margin_edits(hDlg
);
3714 set_margin_groupbox_title(hDlg
, data
);
3716 /* if paper disabled */
3717 if (pagesetup_get_flags(data
) & PSD_DISABLEPAPER
)
3719 EnableWindow(GetDlgItem(hDlg
,cmb2
),FALSE
);
3720 EnableWindow(GetDlgItem(hDlg
,cmb3
),FALSE
);
3723 /* filling combos: printer, paper, source. selecting current printer (from DEVMODEA) */
3724 pagesetup_init_combos(hDlg
, data
);
3725 pagesetup_update_papersize(data
);
3726 pagesetup_set_defaultsource(data
, DMBIN_FORMSOURCE
); /* FIXME: This is the auto select bin. Is this correct? */
3728 /* Drawing paper prev */
3729 pagesetup_change_preview(data
);
3732 data
= GetPropW(hDlg
, pagesetupdlg_prop
);
3735 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3738 if (pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPHOOK
)
3740 res
= pagesetup_get_hook(data
, page_setup_hook
)(hDlg
, uMsg
, wParam
, lParam
);
3741 if (res
) return res
;
3746 return pagesetup_wm_command(hDlg
, wParam
, lParam
, data
);
3751 static WCHAR
*get_default_printer(void)
3756 GetDefaultPrinterW(NULL
, &len
);
3759 name
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3760 GetDefaultPrinterW(name
, &len
);
3765 static void pagesetup_dump_dlg_struct(const pagesetup_data
*data
)
3767 if(TRACE_ON(commdlg
))
3769 char flagstr
[1000] = "";
3770 const struct pd_flags
*pflag
= psd_flags
;
3771 for( ; pflag
->name
; pflag
++)
3773 if(pagesetup_get_flags(data
) & pflag
->flag
)
3775 strcat(flagstr
, pflag
->name
);
3776 strcat(flagstr
, "|");
3779 TRACE("%s: (%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3780 "hinst %p, flags %08x (%s)\n",
3781 data
->unicode
? "unicode" : "ansi",
3782 data
->u
.dlgw
, data
->u
.dlgw
->hwndOwner
, data
->u
.dlgw
->hDevMode
,
3783 data
->u
.dlgw
->hDevNames
, data
->u
.dlgw
->hInstance
,
3784 pagesetup_get_flags(data
), flagstr
);
3788 static void *pagesetup_get_template(pagesetup_data
*data
)
3791 HGLOBAL tmpl_handle
;
3793 if(pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPTEMPLATEHANDLE
)
3795 tmpl_handle
= data
->u
.dlgw
->hPageSetupTemplate
;
3797 else if(pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPTEMPLATE
)
3800 res
= FindResourceW(data
->u
.dlgw
->hInstance
,
3801 data
->u
.dlgw
->lpPageSetupTemplateName
, MAKEINTRESOURCEW(RT_DIALOG
));
3803 res
= FindResourceA(data
->u
.dlga
->hInstance
,
3804 data
->u
.dlga
->lpPageSetupTemplateName
, MAKEINTRESOURCEA(RT_DIALOG
));
3805 tmpl_handle
= LoadResource(data
->u
.dlgw
->hInstance
, res
);
3809 res
= FindResourceW(COMDLG32_hInstance
, MAKEINTRESOURCEW(PAGESETUPDLGORD
),
3810 MAKEINTRESOURCEW(RT_DIALOG
));
3811 tmpl_handle
= LoadResource(COMDLG32_hInstance
, res
);
3813 return LockResource(tmpl_handle
);
3816 static BOOL
pagesetup_common(pagesetup_data
*data
)
3821 if(!pagesetup_get_dlg_struct(data
))
3823 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
3827 pagesetup_dump_dlg_struct(data
);
3829 if(data
->u
.dlgw
->lStructSize
!= sizeof(PAGESETUPDLGW
))
3831 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
3835 if ((pagesetup_get_flags(data
) & PSD_ENABLEPAGEPAINTHOOK
) &&
3836 (pagesetup_get_hook(data
, page_paint_hook
) == NULL
))
3838 COMDLG32_SetCommDlgExtendedError(CDERR_NOHOOK
);
3842 if(!(pagesetup_get_flags(data
) & (PSD_INTHOUSANDTHSOFINCHES
| PSD_INHUNDREDTHSOFMILLIMETERS
)))
3843 data
->u
.dlgw
->Flags
|= is_default_metric() ?
3844 PSD_INHUNDREDTHSOFMILLIMETERS
: PSD_INTHOUSANDTHSOFINCHES
;
3846 if (!data
->u
.dlgw
->hDevMode
|| !data
->u
.dlgw
->hDevNames
)
3848 WCHAR
*def
= get_default_printer();
3851 if (!(pagesetup_get_flags(data
) & PSD_NOWARNING
))
3854 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEFAULT_PRINTER
, errstr
, 255);
3855 MessageBoxW(data
->u
.dlgw
->hwndOwner
, errstr
, 0, MB_OK
| MB_ICONERROR
);
3857 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
3860 pagesetup_change_printer(def
, data
);
3861 HeapFree(GetProcessHeap(), 0, def
);
3864 if (pagesetup_get_flags(data
) & PSD_RETURNDEFAULT
)
3866 pagesetup_update_papersize(data
);
3870 tmpl
= pagesetup_get_template(data
);
3872 ret
= DialogBoxIndirectParamW(data
->u
.dlgw
->hInstance
, tmpl
,
3873 data
->u
.dlgw
->hwndOwner
,
3874 pagesetup_dlg_proc
, (LPARAM
)data
) > 0;
3878 /***********************************************************************
3879 * PageSetupDlgA (COMDLG32.@)
3881 * Displays the PAGE SETUP dialog box, which enables the user to specify
3882 * specific properties of a printed page such as
3883 * size, source, orientation and the width of the page margins.
3886 * setupdlg [IO] PAGESETUPDLGA struct
3889 * TRUE if the user pressed the OK button
3890 * FALSE if the user cancelled the window or an error occurred
3893 * The values of hDevMode and hDevNames are filled on output and can be
3894 * changed in PAGESETUPDLG when they are passed in PageSetupDlg.
3897 BOOL WINAPI
PageSetupDlgA(LPPAGESETUPDLGA setupdlg
)
3899 pagesetup_data data
;
3901 data
.unicode
= FALSE
;
3902 data
.u
.dlga
= setupdlg
;
3904 return pagesetup_common(&data
);
3907 /***********************************************************************
3908 * PageSetupDlgW (COMDLG32.@)
3910 * See PageSetupDlgA.
3912 BOOL WINAPI
PageSetupDlgW(LPPAGESETUPDLGW setupdlg
)
3914 pagesetup_data data
;
3916 data
.unicode
= TRUE
;
3917 data
.u
.dlgw
= setupdlg
;
3919 return pagesetup_common(&data
);
3922 /***********************************************************************
3923 * PrintDlgExA (COMDLG32.@)
3931 HRESULT WINAPI
PrintDlgExA(LPPRINTDLGEXA lppd
)
3933 PRINTER_INFO_2A
*pbuf
;
3934 DRIVER_INFO_3A
*dbuf
;
3939 if ((lppd
== NULL
) || (lppd
->lStructSize
!= sizeof(PRINTDLGEXA
)))
3940 return E_INVALIDARG
;
3942 if (!IsWindow(lppd
->hwndOwner
))
3945 if (lppd
->nStartPage
!= START_PAGE_GENERAL
)
3947 if (!lppd
->nPropertyPages
)
3948 return E_INVALIDARG
;
3950 FIXME("custom property sheets (%d at %p) not supported\n", lppd
->nPropertyPages
, lppd
->lphPropertyPages
);
3953 /* Use PD_NOPAGENUMS or set nMaxPageRanges and lpPageRanges */
3954 if (!(lppd
->Flags
& PD_NOPAGENUMS
) && (!lppd
->nMaxPageRanges
|| !lppd
->lpPageRanges
))
3956 return E_INVALIDARG
;
3959 if (lppd
->Flags
& PD_RETURNDEFAULT
)
3961 if (lppd
->hDevMode
|| lppd
->hDevNames
)
3963 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
3964 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
3965 return E_INVALIDARG
;
3967 if (!PRINTDLG_OpenDefaultPrinter(&hprn
))
3969 WARN("Can't find default printer\n");
3970 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
3974 pbuf
= get_printer_infoA(hprn
);
3981 dbuf
= get_driver_infoA(hprn
);
3984 HeapFree(GetProcessHeap(), 0, pbuf
);
3985 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
3989 dm
= pbuf
->pDevMode
;
3993 FIXME("(%p) dialog not implemented\n", lppd
);
4000 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
), dbuf
->pDriverPath
, pbuf
->pPrinterName
, pbuf
->pPortName
);
4001 if (!lppd
->hDevNames
)
4004 lppd
->hDevMode
= update_devmode_handleA(lppd
->hDevMode
, dm
);
4005 if (!hr
&& lppd
->hDevMode
) {
4006 if (lppd
->Flags
& PD_RETURNDC
) {
4007 lppd
->hDC
= CreateDCA(dbuf
->pDriverPath
, pbuf
->pPrinterName
, pbuf
->pPortName
, dm
);
4011 else if (lppd
->Flags
& PD_RETURNIC
) {
4012 lppd
->hDC
= CreateICA(dbuf
->pDriverPath
, pbuf
->pPrinterName
, pbuf
->pPortName
, dm
);
4020 HeapFree(GetProcessHeap(), 0, pbuf
);
4021 HeapFree(GetProcessHeap(), 0, dbuf
);
4026 /***********************************************************************
4027 * PrintDlgExW (COMDLG32.@)
4029 * Display the property sheet style PRINT dialog box
4032 * lppd [IO] ptr to PRINTDLGEX struct
4036 * Failure: One of the following COM error codes:
4037 * E_OUTOFMEMORY Insufficient memory.
4038 * E_INVALIDARG One or more arguments are invalid.
4039 * E_POINTER Invalid pointer.
4040 * E_HANDLE Invalid handle.
4041 * E_FAIL Unspecified error.
4044 * This Dialog enables the user to specify specific properties of the print job.
4045 * The property sheet can also have additional application-specific and
4046 * driver-specific property pages.
4049 * Not fully implemented
4052 HRESULT WINAPI
PrintDlgExW(LPPRINTDLGEXW lppd
)
4054 PRINTER_INFO_2W
*pbuf
;
4055 DRIVER_INFO_3W
*dbuf
;
4060 if ((lppd
== NULL
) || (lppd
->lStructSize
!= sizeof(PRINTDLGEXW
))) {
4061 return E_INVALIDARG
;
4064 if (!IsWindow(lppd
->hwndOwner
)) {
4068 if (lppd
->nStartPage
!= START_PAGE_GENERAL
)
4070 if (!lppd
->nPropertyPages
)
4071 return E_INVALIDARG
;
4073 FIXME("custom property sheets (%d at %p) not supported\n", lppd
->nPropertyPages
, lppd
->lphPropertyPages
);
4076 /* Use PD_NOPAGENUMS or set nMaxPageRanges and lpPageRanges */
4077 if (!(lppd
->Flags
& PD_NOPAGENUMS
) && (!lppd
->nMaxPageRanges
|| !lppd
->lpPageRanges
))
4079 return E_INVALIDARG
;
4082 if (lppd
->Flags
& PD_RETURNDEFAULT
) {
4084 if (lppd
->hDevMode
|| lppd
->hDevNames
) {
4085 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
4086 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
4087 return E_INVALIDARG
;
4089 if (!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
4090 WARN("Can't find default printer\n");
4091 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
4095 pbuf
= get_printer_infoW(hprn
);
4102 dbuf
= get_driver_infoW(hprn
);
4105 HeapFree(GetProcessHeap(), 0, pbuf
);
4106 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
4110 dm
= pbuf
->pDevMode
;
4114 FIXME("(%p) dialog not implemented\n", lppd
);
4121 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
), dbuf
->pDriverPath
, pbuf
->pPrinterName
, pbuf
->pPortName
);
4122 if (!lppd
->hDevNames
)
4125 lppd
->hDevMode
= update_devmode_handleW(lppd
->hDevMode
, dm
);
4126 if (!hr
&& lppd
->hDevMode
) {
4127 if (lppd
->Flags
& PD_RETURNDC
) {
4128 lppd
->hDC
= CreateDCW(dbuf
->pDriverPath
, pbuf
->pPrinterName
, pbuf
->pPortName
, dm
);
4132 else if (lppd
->Flags
& PD_RETURNIC
) {
4133 lppd
->hDC
= CreateICW(dbuf
->pDriverPath
, pbuf
->pPrinterName
, pbuf
->pPortName
, dm
);
4141 HeapFree(GetProcessHeap(), 0, pbuf
);
4142 HeapFree(GetProcessHeap(), 0, dbuf
);