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
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #define NONAMELESSUNION
31 #define NONAMELESSSTRUCT
39 #include "wine/unicode.h"
40 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(commdlg
);
49 /* Yes these constants are the same, but we're just copying win98 */
50 #define UPDOWN_ID 0x270f
51 #define MAX_COPIES 9999
53 /* This PRINTDLGA internal structure stores
54 * pointers to several throughout useful structures.
60 LPPRINTDLGA lpPrintDlg
;
61 LPPRINTER_INFO_2A lpPrinterInfo
;
62 LPDRIVER_INFO_3A lpDriverInfo
;
64 HICON hCollateIcon
; /* PrintDlg only */
65 HICON hNoCollateIcon
; /* PrintDlg only */
66 HICON hPortraitIcon
; /* PrintSetupDlg only */
67 HICON hLandscapeIcon
; /* PrintSetupDlg only */
74 LPPRINTDLGW lpPrintDlg
;
75 LPPRINTER_INFO_2W lpPrinterInfo
;
76 LPDRIVER_INFO_3W lpDriverInfo
;
78 HICON hCollateIcon
; /* PrintDlg only */
79 HICON hNoCollateIcon
; /* PrintDlg only */
80 HICON hPortraitIcon
; /* PrintSetupDlg only */
81 HICON hLandscapeIcon
; /* PrintSetupDlg only */
92 static const struct pd_flags psd_flags
[] = {
93 {PSD_MINMARGINS
,"PSD_MINMARGINS"},
94 {PSD_MARGINS
,"PSD_MARGINS"},
95 {PSD_INTHOUSANDTHSOFINCHES
,"PSD_INTHOUSANDTHSOFINCHES"},
96 {PSD_INHUNDREDTHSOFMILLIMETERS
,"PSD_INHUNDREDTHSOFMILLIMETERS"},
97 {PSD_DISABLEMARGINS
,"PSD_DISABLEMARGINS"},
98 {PSD_DISABLEPRINTER
,"PSD_DISABLEPRINTER"},
99 {PSD_NOWARNING
,"PSD_NOWARNING"},
100 {PSD_DISABLEORIENTATION
,"PSD_DISABLEORIENTATION"},
101 {PSD_RETURNDEFAULT
,"PSD_RETURNDEFAULT"},
102 {PSD_DISABLEPAPER
,"PSD_DISABLEPAPER"},
103 {PSD_SHOWHELP
,"PSD_SHOWHELP"},
104 {PSD_ENABLEPAGESETUPHOOK
,"PSD_ENABLEPAGESETUPHOOK"},
105 {PSD_ENABLEPAGESETUPTEMPLATE
,"PSD_ENABLEPAGESETUPTEMPLATE"},
106 {PSD_ENABLEPAGESETUPTEMPLATEHANDLE
,"PSD_ENABLEPAGESETUPTEMPLATEHANDLE"},
107 {PSD_ENABLEPAGEPAINTHOOK
,"PSD_ENABLEPAGEPAINTHOOK"},
108 {PSD_DISABLEPAGEPAINTING
,"PSD_DISABLEPAGEPAINTING"},
112 static const struct pd_flags pd_flags
[] = {
113 {PD_SELECTION
, "PD_SELECTION "},
114 {PD_PAGENUMS
, "PD_PAGENUMS "},
115 {PD_NOSELECTION
, "PD_NOSELECTION "},
116 {PD_NOPAGENUMS
, "PD_NOPAGENUMS "},
117 {PD_COLLATE
, "PD_COLLATE "},
118 {PD_PRINTTOFILE
, "PD_PRINTTOFILE "},
119 {PD_PRINTSETUP
, "PD_PRINTSETUP "},
120 {PD_NOWARNING
, "PD_NOWARNING "},
121 {PD_RETURNDC
, "PD_RETURNDC "},
122 {PD_RETURNIC
, "PD_RETURNIC "},
123 {PD_RETURNDEFAULT
, "PD_RETURNDEFAULT "},
124 {PD_SHOWHELP
, "PD_SHOWHELP "},
125 {PD_ENABLEPRINTHOOK
, "PD_ENABLEPRINTHOOK "},
126 {PD_ENABLESETUPHOOK
, "PD_ENABLESETUPHOOK "},
127 {PD_ENABLEPRINTTEMPLATE
, "PD_ENABLEPRINTTEMPLATE "},
128 {PD_ENABLESETUPTEMPLATE
, "PD_ENABLESETUPTEMPLATE "},
129 {PD_ENABLEPRINTTEMPLATEHANDLE
, "PD_ENABLEPRINTTEMPLATEHANDLE "},
130 {PD_ENABLESETUPTEMPLATEHANDLE
, "PD_ENABLESETUPTEMPLATEHANDLE "},
131 {PD_USEDEVMODECOPIES
, "PD_USEDEVMODECOPIES[ANDCOLLATE] "},
132 {PD_DISABLEPRINTTOFILE
, "PD_DISABLEPRINTTOFILE "},
133 {PD_HIDEPRINTTOFILE
, "PD_HIDEPRINTTOFILE "},
134 {PD_NONETWORKBUTTON
, "PD_NONETWORKBUTTON "},
137 /* address of wndproc for subclassed Static control */
138 static WNDPROC lpfnStaticWndProc
;
139 static WNDPROC edit_wndproc
;
140 /* the text of the fake document to render for the Page Setup dialog */
141 static WCHAR wszFakeDocumentText
[1024];
142 static const WCHAR pd32_collateW
[] = { 'P', 'D', '3', '2', '_', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
143 static const WCHAR pd32_nocollateW
[] = { 'P', 'D', '3', '2', '_', 'N', 'O', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
144 static const WCHAR pd32_portraitW
[] = { 'P', 'D', '3', '2', '_', 'P', 'O', 'R', 'T', 'R', 'A', 'I', 'T', 0 };
145 static const WCHAR pd32_landscapeW
[] = { 'P', 'D', '3', '2', '_', 'L', 'A', 'N', 'D', 'S', 'C', 'A', 'P', 'E', 0 };
146 static const WCHAR printdlg_prop
[] = {'_','_','W','I','N','E','_','P','R','I','N','T','D','L','G','D','A','T','A',0};
147 static const WCHAR pagesetupdlg_prop
[] = { '_', '_', 'W', 'I', 'N', 'E', '_', 'P', 'A', 'G', 'E',
148 'S', 'E', 'T', 'U', 'P', 'D', 'L', 'G', 'D', 'A', 'T', 'A', 0 };
151 static LPWSTR
strdupW(LPCWSTR p
)
157 len
= (strlenW(p
) + 1) * sizeof(WCHAR
);
158 ret
= HeapAlloc(GetProcessHeap(), 0, len
);
163 /***********************************************************
164 * convert_to_devmodeA
166 * Creates an ansi copy of supplied devmode
168 static DEVMODEA
*convert_to_devmodeA(const DEVMODEW
*dmW
)
173 if (!dmW
) return NULL
;
174 size
= dmW
->dmSize
- CCHDEVICENAME
-
175 ((dmW
->dmSize
> FIELD_OFFSET(DEVMODEW
, dmFormName
)) ? CCHFORMNAME
: 0);
177 dmA
= HeapAlloc(GetProcessHeap(), 0, size
+ dmW
->dmDriverExtra
);
178 if (!dmA
) return NULL
;
180 WideCharToMultiByte(CP_ACP
, 0, dmW
->dmDeviceName
, -1,
181 (LPSTR
)dmA
->dmDeviceName
, CCHDEVICENAME
, NULL
, NULL
);
183 if (FIELD_OFFSET(DEVMODEW
, dmFormName
) >= dmW
->dmSize
)
185 memcpy(&dmA
->dmSpecVersion
, &dmW
->dmSpecVersion
,
186 dmW
->dmSize
- FIELD_OFFSET(DEVMODEW
, dmSpecVersion
));
190 memcpy(&dmA
->dmSpecVersion
, &dmW
->dmSpecVersion
,
191 FIELD_OFFSET(DEVMODEW
, dmFormName
) - FIELD_OFFSET(DEVMODEW
, dmSpecVersion
));
192 WideCharToMultiByte(CP_ACP
, 0, dmW
->dmFormName
, -1,
193 (LPSTR
)dmA
->dmFormName
, CCHFORMNAME
, NULL
, NULL
);
195 memcpy(&dmA
->dmLogPixels
, &dmW
->dmLogPixels
, dmW
->dmSize
- FIELD_OFFSET(DEVMODEW
, dmLogPixels
));
199 memcpy((char *)dmA
+ dmA
->dmSize
, (const char *)dmW
+ dmW
->dmSize
, dmW
->dmDriverExtra
);
203 /***********************************************************************
204 * PRINTDLG_OpenDefaultPrinter
206 * Returns a winspool printer handle to the default printer in *hprn
207 * Caller must call ClosePrinter on the handle
209 * Returns TRUE on success else FALSE
211 static BOOL
PRINTDLG_OpenDefaultPrinter(HANDLE
*hprn
)
214 DWORD dwBufLen
= sizeof(buf
) / sizeof(buf
[0]);
216 if(!GetDefaultPrinterW(buf
, &dwBufLen
))
218 res
= OpenPrinterW(buf
, hprn
, NULL
);
220 WARN("Could not open printer %s\n", debugstr_w(buf
));
224 /***********************************************************************
225 * PRINTDLG_SetUpPrinterListCombo
227 * Initializes printer list combox.
228 * hDlg: HWND of dialog
229 * id: Control id of combo
230 * name: Name of printer to select
232 * Initializes combo with list of available printers. Selects printer 'name'
233 * If name is NULL or does not exist select the default printer.
235 * Returns number of printers added to list.
237 static INT
PRINTDLG_SetUpPrinterListComboA(HWND hDlg
, UINT id
, LPCSTR name
)
241 LPPRINTER_INFO_2A pi
;
242 EnumPrintersA(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
243 pi
= HeapAlloc(GetProcessHeap(), 0, needed
);
244 EnumPrintersA(PRINTER_ENUM_LOCAL
, NULL
, 2, (LPBYTE
)pi
, needed
, &needed
,
247 SendDlgItemMessageA(hDlg
, id
, CB_RESETCONTENT
, 0, 0);
249 for(i
= 0; i
< num
; i
++) {
250 SendDlgItemMessageA(hDlg
, id
, CB_ADDSTRING
, 0,
251 (LPARAM
)pi
[i
].pPrinterName
);
253 HeapFree(GetProcessHeap(), 0, pi
);
255 (i
= SendDlgItemMessageA(hDlg
, id
, CB_FINDSTRINGEXACT
, -1,
256 (LPARAM
)name
)) == CB_ERR
) {
259 DWORD dwBufLen
= sizeof(buf
);
261 WARN("Can't find %s in printer list so trying to find default\n",
263 if(!GetDefaultPrinterA(buf
, &dwBufLen
))
265 i
= SendDlgItemMessageA(hDlg
, id
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buf
);
267 FIXME("Can't find default printer in printer list\n");
269 SendDlgItemMessageA(hDlg
, id
, CB_SETCURSEL
, i
, 0);
273 static INT
PRINTDLG_SetUpPrinterListComboW(HWND hDlg
, UINT id
, LPCWSTR name
)
277 LPPRINTER_INFO_2W pi
;
278 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
279 pi
= HeapAlloc(GetProcessHeap(), 0, needed
);
280 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, (LPBYTE
)pi
, needed
, &needed
,
283 for(i
= 0; i
< num
; i
++) {
284 SendDlgItemMessageW(hDlg
, id
, CB_ADDSTRING
, 0,
285 (LPARAM
)pi
[i
].pPrinterName
);
287 HeapFree(GetProcessHeap(), 0, pi
);
289 (i
= SendDlgItemMessageW(hDlg
, id
, CB_FINDSTRINGEXACT
, -1,
290 (LPARAM
)name
)) == CB_ERR
) {
292 DWORD dwBufLen
= sizeof(buf
)/sizeof(buf
[0]);
294 WARN("Can't find %s in printer list so trying to find default\n",
296 if(!GetDefaultPrinterW(buf
, &dwBufLen
))
298 i
= SendDlgItemMessageW(hDlg
, id
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buf
);
300 TRACE("Can't find default printer in printer list\n");
302 SendDlgItemMessageW(hDlg
, id
, CB_SETCURSEL
, i
, 0);
306 /***********************************************************************
307 * PRINTDLG_CreateDevNames [internal]
310 * creates a DevNames structure.
312 * (NB. when we handle unicode the offsets will be in wchars).
314 static BOOL
PRINTDLG_CreateDevNames(HGLOBAL
*hmem
, const char* DeviceDriverName
,
315 const char* DeviceName
, const char* OutputPort
)
318 char* pDevNamesSpace
;
320 LPDEVNAMES lpDevNames
;
322 DWORD dwBufLen
= sizeof(buf
);
324 size
= strlen(DeviceDriverName
) + 1
325 + strlen(DeviceName
) + 1
326 + strlen(OutputPort
) + 1
330 *hmem
= GlobalReAlloc(*hmem
, size
, GMEM_MOVEABLE
);
332 *hmem
= GlobalAlloc(GMEM_MOVEABLE
, size
);
336 pDevNamesSpace
= GlobalLock(*hmem
);
337 lpDevNames
= (LPDEVNAMES
) pDevNamesSpace
;
339 pTempPtr
= pDevNamesSpace
+ sizeof(DEVNAMES
);
340 strcpy(pTempPtr
, DeviceDriverName
);
341 lpDevNames
->wDriverOffset
= pTempPtr
- pDevNamesSpace
;
343 pTempPtr
+= strlen(DeviceDriverName
) + 1;
344 strcpy(pTempPtr
, DeviceName
);
345 lpDevNames
->wDeviceOffset
= pTempPtr
- pDevNamesSpace
;
347 pTempPtr
+= strlen(DeviceName
) + 1;
348 strcpy(pTempPtr
, OutputPort
);
349 lpDevNames
->wOutputOffset
= pTempPtr
- pDevNamesSpace
;
351 GetDefaultPrinterA(buf
, &dwBufLen
);
352 lpDevNames
->wDefault
= (strcmp(buf
, DeviceName
) == 0) ? 1 : 0;
357 static BOOL
PRINTDLG_CreateDevNamesW(HGLOBAL
*hmem
, LPCWSTR DeviceDriverName
,
358 LPCWSTR DeviceName
, LPCWSTR OutputPort
)
361 LPWSTR pDevNamesSpace
;
363 LPDEVNAMES lpDevNames
;
365 DWORD dwBufLen
= sizeof(bufW
) / sizeof(WCHAR
);
367 size
= sizeof(WCHAR
)*lstrlenW(DeviceDriverName
) + 2
368 + sizeof(WCHAR
)*lstrlenW(DeviceName
) + 2
369 + sizeof(WCHAR
)*lstrlenW(OutputPort
) + 2
373 *hmem
= GlobalReAlloc(*hmem
, size
, GMEM_MOVEABLE
);
375 *hmem
= GlobalAlloc(GMEM_MOVEABLE
, size
);
379 pDevNamesSpace
= GlobalLock(*hmem
);
380 lpDevNames
= (LPDEVNAMES
) pDevNamesSpace
;
382 pTempPtr
= (LPWSTR
)((LPDEVNAMES
)pDevNamesSpace
+ 1);
383 lstrcpyW(pTempPtr
, DeviceDriverName
);
384 lpDevNames
->wDriverOffset
= pTempPtr
- pDevNamesSpace
;
386 pTempPtr
+= lstrlenW(DeviceDriverName
) + 1;
387 lstrcpyW(pTempPtr
, DeviceName
);
388 lpDevNames
->wDeviceOffset
= pTempPtr
- pDevNamesSpace
;
390 pTempPtr
+= lstrlenW(DeviceName
) + 1;
391 lstrcpyW(pTempPtr
, OutputPort
);
392 lpDevNames
->wOutputOffset
= pTempPtr
- pDevNamesSpace
;
394 GetDefaultPrinterW(bufW
, &dwBufLen
);
395 lpDevNames
->wDefault
= (lstrcmpW(bufW
, DeviceName
) == 0) ? 1 : 0;
400 /***********************************************************************
401 * PRINTDLG_UpdatePrintDlg [internal]
404 * updates the PrintDlg structure for return values.
407 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
408 * TRUE if successful.
410 static BOOL
PRINTDLG_UpdatePrintDlgA(HWND hDlg
,
411 PRINT_PTRA
* PrintStructures
)
413 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
414 PDEVMODEA lpdm
= PrintStructures
->lpDevMode
;
415 LPPRINTER_INFO_2A pi
= PrintStructures
->lpPrinterInfo
;
419 FIXME("No lpdm ptr?\n");
424 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
425 /* check whether nFromPage and nToPage are within range defined by
426 * nMinPage and nMaxPage
428 if (IsDlgButtonChecked(hDlg
, rad3
) == BST_CHECKED
) { /* Pages */
432 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
433 nToPage
= GetDlgItemInt(hDlg
, edt2
, &translated
, FALSE
);
435 /* if no ToPage value is entered, use the FromPage value */
436 if(!translated
) nToPage
= nFromPage
;
438 if (nFromPage
< lppd
->nMinPage
|| nFromPage
> lppd
->nMaxPage
||
439 nToPage
< lppd
->nMinPage
|| nToPage
> lppd
->nMaxPage
) {
440 WCHAR resourcestr
[256];
441 WCHAR resultstr
[256];
442 LoadStringW(COMDLG32_hInstance
, PD32_INVALID_PAGE_RANGE
, resourcestr
, 255);
443 wsprintfW(resultstr
,resourcestr
, lppd
->nMinPage
, lppd
->nMaxPage
);
444 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
, resourcestr
, 255);
445 MessageBoxW(hDlg
, resultstr
, resourcestr
, MB_OK
| MB_ICONWARNING
);
448 lppd
->nFromPage
= nFromPage
;
449 lppd
->nToPage
= nToPage
;
450 lppd
->Flags
|= PD_PAGENUMS
;
453 lppd
->Flags
&= ~PD_PAGENUMS
;
455 if (IsDlgButtonChecked(hDlg
, rad2
) == BST_CHECKED
) /* Selection */
456 lppd
->Flags
|= PD_SELECTION
;
458 lppd
->Flags
&= ~PD_SELECTION
;
460 if (IsDlgButtonChecked(hDlg
, chx1
) == BST_CHECKED
) {/* Print to file */
461 static char file
[] = "FILE:";
462 lppd
->Flags
|= PD_PRINTTOFILE
;
463 pi
->pPortName
= file
;
466 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
) { /* Collate */
467 FIXME("Collate lppd not yet implemented as output\n");
470 /* set PD_Collate and nCopies */
471 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
472 /* The application doesn't support multiple copies or collate...
474 lppd
->Flags
&= ~PD_COLLATE
;
476 /* if the printer driver supports it... store info there
477 * otherwise no collate & multiple copies !
479 if (lpdm
->dmFields
& DM_COLLATE
)
481 (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
);
482 if (lpdm
->dmFields
& DM_COPIES
)
483 lpdm
->u1
.s1
.dmCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
485 /* Application is responsible for multiple copies */
486 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
487 lppd
->Flags
|= PD_COLLATE
;
489 lppd
->Flags
&= ~PD_COLLATE
;
490 lppd
->nCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
491 /* multiple copies already included in the document. Driver must print only one copy */
492 lpdm
->u1
.s1
.dmCopies
= 1;
495 /* Print quality, PrintDlg16 */
496 if(GetDlgItem(hDlg
, cmb1
))
498 HWND hQuality
= GetDlgItem(hDlg
, cmb1
);
499 int Sel
= SendMessageA(hQuality
, CB_GETCURSEL
, 0, 0);
503 LONG dpi
= SendMessageA(hQuality
, CB_GETITEMDATA
, Sel
, 0);
504 lpdm
->dmFields
|= DM_PRINTQUALITY
| DM_YRESOLUTION
;
505 lpdm
->u1
.s1
.dmPrintQuality
= LOWORD(dpi
);
506 lpdm
->dmYResolution
= HIWORD(dpi
);
513 static BOOL
PRINTDLG_UpdatePrintDlgW(HWND hDlg
,
514 PRINT_PTRW
* PrintStructures
)
516 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
517 PDEVMODEW lpdm
= PrintStructures
->lpDevMode
;
518 LPPRINTER_INFO_2W pi
= PrintStructures
->lpPrinterInfo
;
522 FIXME("No lpdm ptr?\n");
527 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
528 /* check whether nFromPage and nToPage are within range defined by
529 * nMinPage and nMaxPage
531 if (IsDlgButtonChecked(hDlg
, rad3
) == BST_CHECKED
) { /* Pages */
535 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
536 nToPage
= GetDlgItemInt(hDlg
, edt2
, &translated
, FALSE
);
538 /* if no ToPage value is entered, use the FromPage value */
539 if(!translated
) nToPage
= nFromPage
;
541 if (nFromPage
< lppd
->nMinPage
|| nFromPage
> lppd
->nMaxPage
||
542 nToPage
< lppd
->nMinPage
|| nToPage
> lppd
->nMaxPage
) {
543 WCHAR resourcestr
[256];
544 WCHAR resultstr
[256];
545 LoadStringW(COMDLG32_hInstance
, PD32_INVALID_PAGE_RANGE
,
547 wsprintfW(resultstr
,resourcestr
, lppd
->nMinPage
, lppd
->nMaxPage
);
548 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
,
550 MessageBoxW(hDlg
, resultstr
, resourcestr
,
551 MB_OK
| MB_ICONWARNING
);
554 lppd
->nFromPage
= nFromPage
;
555 lppd
->nToPage
= nToPage
;
556 lppd
->Flags
|= PD_PAGENUMS
;
559 lppd
->Flags
&= ~PD_PAGENUMS
;
561 if (IsDlgButtonChecked(hDlg
, rad2
) == BST_CHECKED
) /* Selection */
562 lppd
->Flags
|= PD_SELECTION
;
564 lppd
->Flags
&= ~PD_SELECTION
;
566 if (IsDlgButtonChecked(hDlg
, chx1
) == BST_CHECKED
) {/* Print to file */
567 static WCHAR file
[] = {'F','I','L','E',':',0};
568 lppd
->Flags
|= PD_PRINTTOFILE
;
569 pi
->pPortName
= file
;
572 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
) { /* Collate */
573 FIXME("Collate lppd not yet implemented as output\n");
576 /* set PD_Collate and nCopies */
577 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
578 /* The application doesn't support multiple copies or collate...
580 lppd
->Flags
&= ~PD_COLLATE
;
582 /* if the printer driver supports it... store info there
583 * otherwise no collate & multiple copies !
585 if (lpdm
->dmFields
& DM_COLLATE
)
587 (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
);
588 if (lpdm
->dmFields
& DM_COPIES
)
589 lpdm
->u1
.s1
.dmCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
591 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
592 lppd
->Flags
|= PD_COLLATE
;
594 lppd
->Flags
&= ~PD_COLLATE
;
595 lppd
->nCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
601 /************************************************************************
602 * PRINTDLG_SetUpPaperComboBox
604 * Initialize either the papersize or inputslot combos of the Printer Setup
605 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
606 * We also try to re-select the old selection.
608 static BOOL
PRINTDLG_SetUpPaperComboBoxA(HWND hDlg
,
621 int fwCapability_Names
;
622 int fwCapability_Words
;
624 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName
,PortName
,nIDComboBox
);
626 /* query the dialog box for the current selected value */
627 Sel
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETCURSEL
, 0, 0);
629 /* we enter here only if a different printer is selected after
630 * the Print Setup dialog is opened. The current settings are
631 * stored into the newly selected printer.
633 oldWord
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
,
636 if (nIDComboBox
== cmb2
)
637 dm
->u1
.s1
.dmPaperSize
= oldWord
;
639 dm
->u1
.s1
.dmDefaultSource
= oldWord
;
643 /* we enter here only when the Print setup dialog is initially
644 * opened. In this case the settings are restored from when
645 * the dialog was last closed.
648 if (nIDComboBox
== cmb2
)
649 oldWord
= dm
->u1
.s1
.dmPaperSize
;
651 oldWord
= dm
->u1
.s1
.dmDefaultSource
;
655 if (nIDComboBox
== cmb2
) {
657 fwCapability_Names
= DC_PAPERNAMES
;
658 fwCapability_Words
= DC_PAPERS
;
662 fwCapability_Names
= DC_BINNAMES
;
663 fwCapability_Words
= DC_BINS
;
666 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
667 fwCapability_Names
, NULL
, dm
);
668 if (NrOfEntries
== 0)
669 WARN("no Name Entries found!\n");
670 else if (NrOfEntries
< 0)
673 if(DeviceCapabilitiesA(PrinterName
, PortName
, fwCapability_Words
, NULL
, dm
)
675 ERR("Number of caps is different\n");
679 Names
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(char)*NamesSize
);
680 Words
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WORD
));
681 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
682 fwCapability_Names
, Names
, dm
);
683 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
684 fwCapability_Words
, (LPSTR
)Words
, dm
);
686 /* reset any current content in the combobox */
687 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_RESETCONTENT
, 0, 0);
689 /* store new content */
690 for (i
= 0; i
< NrOfEntries
; i
++) {
691 DWORD pos
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_ADDSTRING
, 0,
692 (LPARAM
)(&Names
[i
*NamesSize
]) );
693 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_SETITEMDATA
, pos
,
697 /* Look for old selection - can't do this is previous loop since
698 item order will change as more items are added */
700 for (i
= 0; i
< NrOfEntries
; i
++) {
701 if(SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) ==
707 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_SETCURSEL
, Sel
, 0);
709 HeapFree(GetProcessHeap(),0,Words
);
710 HeapFree(GetProcessHeap(),0,Names
);
714 static BOOL
PRINTDLG_SetUpPaperComboBoxW(HWND hDlg
,
716 const WCHAR
* PrinterName
,
717 const WCHAR
* PortName
,
727 int fwCapability_Names
;
728 int fwCapability_Words
;
730 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName
),debugstr_w(PortName
),nIDComboBox
);
732 /* query the dialog box for the current selected value */
733 Sel
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETCURSEL
, 0, 0);
735 /* we enter here only if a different printer is selected after
736 * the Print Setup dialog is opened. The current settings are
737 * stored into the newly selected printer.
739 oldWord
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETITEMDATA
,
742 if (nIDComboBox
== cmb2
)
743 dm
->u1
.s1
.dmPaperSize
= oldWord
;
745 dm
->u1
.s1
.dmDefaultSource
= oldWord
;
749 /* we enter here only when the Print setup dialog is initially
750 * opened. In this case the settings are restored from when
751 * the dialog was last closed.
754 if (nIDComboBox
== cmb2
)
755 oldWord
= dm
->u1
.s1
.dmPaperSize
;
757 oldWord
= dm
->u1
.s1
.dmDefaultSource
;
761 if (nIDComboBox
== cmb2
) {
763 fwCapability_Names
= DC_PAPERNAMES
;
764 fwCapability_Words
= DC_PAPERS
;
768 fwCapability_Names
= DC_BINNAMES
;
769 fwCapability_Words
= DC_BINS
;
772 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
773 fwCapability_Names
, NULL
, dm
);
774 if (NrOfEntries
== 0)
775 WARN("no Name Entries found!\n");
776 else if (NrOfEntries
< 0)
779 if(DeviceCapabilitiesW(PrinterName
, PortName
, fwCapability_Words
, NULL
, dm
)
781 ERR("Number of caps is different\n");
785 Names
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WCHAR
)*NamesSize
);
786 Words
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WORD
));
787 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
788 fwCapability_Names
, Names
, dm
);
789 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
790 fwCapability_Words
, Words
, dm
);
792 /* reset any current content in the combobox */
793 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_RESETCONTENT
, 0, 0);
795 /* store new content */
796 for (i
= 0; i
< NrOfEntries
; i
++) {
797 DWORD pos
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_ADDSTRING
, 0,
798 (LPARAM
)(&Names
[i
*NamesSize
]) );
799 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_SETITEMDATA
, pos
,
803 /* Look for old selection - can't do this is previous loop since
804 item order will change as more items are added */
806 for (i
= 0; i
< NrOfEntries
; i
++) {
807 if(SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) ==
813 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_SETCURSEL
, Sel
, 0);
815 HeapFree(GetProcessHeap(),0,Words
);
816 HeapFree(GetProcessHeap(),0,Names
);
821 /***********************************************************************
822 * PRINTDLG_UpdatePrinterInfoTexts [internal]
824 static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg
, const PRINTER_INFO_2A
*pi
)
827 char ResourceString
[256];
833 /* add all status messages */
834 for (i
= 0; i
< 25; i
++) {
835 if (pi
->Status
& (1<<i
)) {
836 LoadStringA(COMDLG32_hInstance
, PD32_PRINTER_STATUS_PAUSED
+i
,
837 ResourceString
, 255);
838 strcat(StatusMsg
,ResourceString
);
842 /* FIXME: status==ready must only be appended if really so.
843 but how to detect? */
844 LoadStringA(COMDLG32_hInstance
, PD32_PRINTER_STATUS_READY
,
845 ResourceString
, 255);
846 strcat(StatusMsg
,ResourceString
);
847 SetDlgItemTextA(hDlg
, stc12
, StatusMsg
);
849 /* set all other printer info texts */
850 SetDlgItemTextA(hDlg
, stc11
, pi
->pDriverName
);
852 if (pi
->pLocation
!= NULL
&& pi
->pLocation
[0] != '\0')
853 SetDlgItemTextA(hDlg
, stc14
, pi
->pLocation
);
855 SetDlgItemTextA(hDlg
, stc14
, pi
->pPortName
);
856 SetDlgItemTextA(hDlg
, stc13
, pi
->pComment
? pi
->pComment
: "");
860 static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg
, const PRINTER_INFO_2W
*pi
)
862 WCHAR StatusMsg
[256];
863 WCHAR ResourceString
[256];
864 static const WCHAR emptyW
[] = {0};
870 /* add all status messages */
871 for (i
= 0; i
< 25; i
++) {
872 if (pi
->Status
& (1<<i
)) {
873 LoadStringW(COMDLG32_hInstance
, PD32_PRINTER_STATUS_PAUSED
+i
,
874 ResourceString
, 255);
875 lstrcatW(StatusMsg
,ResourceString
);
879 /* FIXME: status==ready must only be appended if really so.
880 but how to detect? */
881 LoadStringW(COMDLG32_hInstance
, PD32_PRINTER_STATUS_READY
,
882 ResourceString
, 255);
883 lstrcatW(StatusMsg
,ResourceString
);
884 SetDlgItemTextW(hDlg
, stc12
, StatusMsg
);
886 /* set all other printer info texts */
887 SetDlgItemTextW(hDlg
, stc11
, pi
->pDriverName
);
888 if (pi
->pLocation
!= NULL
&& pi
->pLocation
[0] != '\0')
889 SetDlgItemTextW(hDlg
, stc14
, pi
->pLocation
);
891 SetDlgItemTextW(hDlg
, stc14
, pi
->pPortName
);
892 SetDlgItemTextW(hDlg
, stc13
, pi
->pComment
? pi
->pComment
: emptyW
);
896 /*******************************************************************
898 * PRINTDLG_ChangePrinter
901 static BOOL
PRINTDLG_ChangePrinterA(HWND hDlg
, char *name
, PRINT_PTRA
*PrintStructures
)
903 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
904 LPDEVMODEA lpdm
= NULL
;
909 HeapFree(GetProcessHeap(),0, PrintStructures
->lpPrinterInfo
);
910 HeapFree(GetProcessHeap(),0, PrintStructures
->lpDriverInfo
);
911 if(!OpenPrinterA(name
, &hprn
, NULL
)) {
912 ERR("Can't open printer %s\n", name
);
915 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
916 PrintStructures
->lpPrinterInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
917 GetPrinterA(hprn
, 2, (LPBYTE
)PrintStructures
->lpPrinterInfo
, needed
,
919 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
920 PrintStructures
->lpDriverInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
921 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)PrintStructures
->lpDriverInfo
,
923 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures
->lpPrinterInfo
->pPrinterName
);
928 PRINTDLG_UpdatePrinterInfoTextsA(hDlg
, PrintStructures
->lpPrinterInfo
);
930 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
931 PrintStructures
->lpDevMode
= NULL
;
933 dmSize
= DocumentPropertiesA(0, 0, name
, NULL
, NULL
, 0);
935 ERR("DocumentProperties fails on %s\n", debugstr_a(name
));
938 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(), 0, dmSize
);
939 dmSize
= DocumentPropertiesA(0, 0, name
, PrintStructures
->lpDevMode
, NULL
,
941 if(lppd
->hDevMode
&& (lpdm
= GlobalLock(lppd
->hDevMode
)) &&
942 !lstrcmpA( (LPSTR
) lpdm
->dmDeviceName
,
943 (LPSTR
) PrintStructures
->lpDevMode
->dmDeviceName
)) {
944 /* Supplied devicemode matches current printer so try to use it */
945 DocumentPropertiesA(0, 0, name
, PrintStructures
->lpDevMode
, lpdm
,
946 DM_OUT_BUFFER
| DM_IN_BUFFER
);
949 GlobalUnlock(lppd
->hDevMode
);
951 lpdm
= PrintStructures
->lpDevMode
; /* use this as a shortcut */
953 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
954 /* Print range (All/Range/Selection) */
955 if(lppd
->nFromPage
!= 0xffff)
956 SetDlgItemInt(hDlg
, edt1
, lppd
->nFromPage
, FALSE
);
957 if(lppd
->nToPage
!= 0xffff)
958 SetDlgItemInt(hDlg
, edt2
, lppd
->nToPage
, FALSE
);
960 CheckRadioButton(hDlg
, rad1
, rad3
, rad1
); /* default */
961 if (lppd
->Flags
& PD_NOSELECTION
)
962 EnableWindow(GetDlgItem(hDlg
, rad2
), FALSE
);
964 if (lppd
->Flags
& PD_SELECTION
)
965 CheckRadioButton(hDlg
, rad1
, rad3
, rad2
);
966 if (lppd
->Flags
& PD_NOPAGENUMS
) {
967 EnableWindow(GetDlgItem(hDlg
, rad3
), FALSE
);
968 EnableWindow(GetDlgItem(hDlg
, stc2
),FALSE
);
969 EnableWindow(GetDlgItem(hDlg
, edt1
), FALSE
);
970 EnableWindow(GetDlgItem(hDlg
, stc3
),FALSE
);
971 EnableWindow(GetDlgItem(hDlg
, edt2
), FALSE
);
973 if (lppd
->Flags
& PD_PAGENUMS
)
974 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
979 * FIXME: The ico3 is not displayed for some reason. I don't know why.
981 if (lppd
->Flags
& PD_COLLATE
) {
982 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
983 (LPARAM
)PrintStructures
->hCollateIcon
);
984 CheckDlgButton(hDlg
, chx2
, 1);
986 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
987 (LPARAM
)PrintStructures
->hNoCollateIcon
);
988 CheckDlgButton(hDlg
, chx2
, 0);
991 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
992 /* if printer doesn't support it: no Collate */
993 if (!(lpdm
->dmFields
& DM_COLLATE
)) {
994 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
995 EnableWindow(GetDlgItem(hDlg
, ico3
), FALSE
);
1002 if (lppd
->hDevMode
== 0)
1003 copies
= lppd
->nCopies
;
1005 copies
= lpdm
->u1
.s1
.dmCopies
;
1006 if(copies
== 0) copies
= 1;
1007 else if(copies
< 0) copies
= MAX_COPIES
;
1008 SetDlgItemInt(hDlg
, edt3
, copies
, FALSE
);
1011 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1012 /* if printer doesn't support it: no nCopies */
1013 if (!(lpdm
->dmFields
& DM_COPIES
)) {
1014 EnableWindow(GetDlgItem(hDlg
, edt3
), FALSE
);
1015 EnableWindow(GetDlgItem(hDlg
, stc5
), FALSE
);
1020 CheckDlgButton(hDlg
, chx1
, (lppd
->Flags
& PD_PRINTTOFILE
) ? 1 : 0);
1021 if (lppd
->Flags
& PD_DISABLEPRINTTOFILE
)
1022 EnableWindow(GetDlgItem(hDlg
, chx1
), FALSE
);
1023 if (lppd
->Flags
& PD_HIDEPRINTTOFILE
)
1024 ShowWindow(GetDlgItem(hDlg
, chx1
), SW_HIDE
);
1026 /* Fill print quality combo, PrintDlg16 */
1027 if(GetDlgItem(hDlg
, cmb1
))
1029 DWORD numResolutions
= DeviceCapabilitiesA(PrintStructures
->lpPrinterInfo
->pPrinterName
,
1030 PrintStructures
->lpPrinterInfo
->pPortName
,
1031 DC_ENUMRESOLUTIONS
, NULL
, lpdm
);
1033 if(numResolutions
!= -1)
1035 HWND hQuality
= GetDlgItem(hDlg
, cmb1
);
1040 HDC hPrinterDC
= CreateDCA(PrintStructures
->lpPrinterInfo
->pDriverName
,
1041 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1044 Resolutions
= HeapAlloc(GetProcessHeap(), 0, numResolutions
*sizeof(LONG
)*2);
1045 DeviceCapabilitiesA(PrintStructures
->lpPrinterInfo
->pPrinterName
,
1046 PrintStructures
->lpPrinterInfo
->pPortName
,
1047 DC_ENUMRESOLUTIONS
, (LPSTR
)Resolutions
, lpdm
);
1049 dpiX
= GetDeviceCaps(hPrinterDC
, LOGPIXELSX
);
1050 dpiY
= GetDeviceCaps(hPrinterDC
, LOGPIXELSY
);
1051 DeleteDC(hPrinterDC
);
1053 SendMessageA(hQuality
, CB_RESETCONTENT
, 0, 0);
1054 for(i
= 0; i
< (numResolutions
* 2); i
+= 2)
1056 BOOL IsDefault
= FALSE
;
1059 if(Resolutions
[i
] == Resolutions
[i
+1])
1061 if(dpiX
== Resolutions
[i
])
1063 sprintf(buf
, "%d dpi", Resolutions
[i
]);
1066 if(dpiX
== Resolutions
[i
] && dpiY
== Resolutions
[i
+1])
1068 sprintf(buf
, "%d dpi x %d dpi", Resolutions
[i
], Resolutions
[i
+1]);
1071 Index
= SendMessageA(hQuality
, CB_ADDSTRING
, 0, (LPARAM
)buf
);
1074 SendMessageA(hQuality
, CB_SETCURSEL
, Index
, 0);
1076 SendMessageA(hQuality
, CB_SETITEMDATA
, Index
, MAKELONG(dpiX
,dpiY
));
1078 HeapFree(GetProcessHeap(), 0, Resolutions
);
1081 } else { /* PD_PRINTSETUP */
1082 BOOL bPortrait
= (lpdm
->u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
);
1084 PRINTDLG_SetUpPaperComboBoxA(hDlg
, cmb2
,
1085 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1086 PrintStructures
->lpPrinterInfo
->pPortName
,
1088 PRINTDLG_SetUpPaperComboBoxA(hDlg
, cmb3
,
1089 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1090 PrintStructures
->lpPrinterInfo
->pPortName
,
1092 CheckRadioButton(hDlg
, rad1
, rad2
, bPortrait
? rad1
: rad2
);
1093 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1094 (LPARAM
)(bPortrait
? PrintStructures
->hPortraitIcon
:
1095 PrintStructures
->hLandscapeIcon
));
1100 if ((lppd
->Flags
& PD_SHOWHELP
)==0) {
1101 /* hide if PD_SHOWHELP not specified */
1102 ShowWindow(GetDlgItem(hDlg
, pshHelp
), SW_HIDE
);
1107 static BOOL
PRINTDLG_ChangePrinterW(HWND hDlg
, WCHAR
*name
,
1108 PRINT_PTRW
*PrintStructures
)
1110 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1111 LPDEVMODEW lpdm
= NULL
;
1116 HeapFree(GetProcessHeap(),0, PrintStructures
->lpPrinterInfo
);
1117 HeapFree(GetProcessHeap(),0, PrintStructures
->lpDriverInfo
);
1118 if(!OpenPrinterW(name
, &hprn
, NULL
)) {
1119 ERR("Can't open printer %s\n", debugstr_w(name
));
1122 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
1123 PrintStructures
->lpPrinterInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
1124 GetPrinterW(hprn
, 2, (LPBYTE
)PrintStructures
->lpPrinterInfo
, needed
,
1126 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
1127 PrintStructures
->lpDriverInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
1128 if (!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)PrintStructures
->lpDriverInfo
,
1130 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures
->lpPrinterInfo
->pPrinterName
));
1135 PRINTDLG_UpdatePrinterInfoTextsW(hDlg
, PrintStructures
->lpPrinterInfo
);
1137 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
1138 PrintStructures
->lpDevMode
= NULL
;
1140 dmSize
= DocumentPropertiesW(0, 0, name
, NULL
, NULL
, 0);
1142 ERR("DocumentProperties fails on %s\n", debugstr_w(name
));
1145 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(), 0, dmSize
);
1146 dmSize
= DocumentPropertiesW(0, 0, name
, PrintStructures
->lpDevMode
, NULL
,
1148 if(lppd
->hDevMode
&& (lpdm
= GlobalLock(lppd
->hDevMode
)) &&
1149 !lstrcmpW(lpdm
->dmDeviceName
,
1150 PrintStructures
->lpDevMode
->dmDeviceName
)) {
1151 /* Supplied devicemode matches current printer so try to use it */
1152 DocumentPropertiesW(0, 0, name
, PrintStructures
->lpDevMode
, lpdm
,
1153 DM_OUT_BUFFER
| DM_IN_BUFFER
);
1156 GlobalUnlock(lppd
->hDevMode
);
1158 lpdm
= PrintStructures
->lpDevMode
; /* use this as a shortcut */
1160 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
1161 /* Print range (All/Range/Selection) */
1162 if(lppd
->nFromPage
!= 0xffff)
1163 SetDlgItemInt(hDlg
, edt1
, lppd
->nFromPage
, FALSE
);
1164 if(lppd
->nToPage
!= 0xffff)
1165 SetDlgItemInt(hDlg
, edt2
, lppd
->nToPage
, FALSE
);
1167 CheckRadioButton(hDlg
, rad1
, rad3
, rad1
); /* default */
1168 if (lppd
->Flags
& PD_NOSELECTION
)
1169 EnableWindow(GetDlgItem(hDlg
, rad2
), FALSE
);
1171 if (lppd
->Flags
& PD_SELECTION
)
1172 CheckRadioButton(hDlg
, rad1
, rad3
, rad2
);
1173 if (lppd
->Flags
& PD_NOPAGENUMS
) {
1174 EnableWindow(GetDlgItem(hDlg
, rad3
), FALSE
);
1175 EnableWindow(GetDlgItem(hDlg
, stc2
),FALSE
);
1176 EnableWindow(GetDlgItem(hDlg
, edt1
), FALSE
);
1177 EnableWindow(GetDlgItem(hDlg
, stc3
),FALSE
);
1178 EnableWindow(GetDlgItem(hDlg
, edt2
), FALSE
);
1180 if (lppd
->Flags
& PD_PAGENUMS
)
1181 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1186 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1188 if (lppd
->Flags
& PD_COLLATE
) {
1189 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1190 (LPARAM
)PrintStructures
->hCollateIcon
);
1191 CheckDlgButton(hDlg
, chx2
, 1);
1193 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1194 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1195 CheckDlgButton(hDlg
, chx2
, 0);
1198 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1199 /* if printer doesn't support it: no Collate */
1200 if (!(lpdm
->dmFields
& DM_COLLATE
)) {
1201 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1202 EnableWindow(GetDlgItem(hDlg
, ico3
), FALSE
);
1209 if (lppd
->hDevMode
== 0)
1210 copies
= lppd
->nCopies
;
1212 copies
= lpdm
->u1
.s1
.dmCopies
;
1213 if(copies
== 0) copies
= 1;
1214 else if(copies
< 0) copies
= MAX_COPIES
;
1215 SetDlgItemInt(hDlg
, edt3
, copies
, FALSE
);
1218 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1219 /* if printer doesn't support it: no nCopies */
1220 if (!(lpdm
->dmFields
& DM_COPIES
)) {
1221 EnableWindow(GetDlgItem(hDlg
, edt3
), FALSE
);
1222 EnableWindow(GetDlgItem(hDlg
, stc5
), FALSE
);
1227 CheckDlgButton(hDlg
, chx1
, (lppd
->Flags
& PD_PRINTTOFILE
) ? 1 : 0);
1228 if (lppd
->Flags
& PD_DISABLEPRINTTOFILE
)
1229 EnableWindow(GetDlgItem(hDlg
, chx1
), FALSE
);
1230 if (lppd
->Flags
& PD_HIDEPRINTTOFILE
)
1231 ShowWindow(GetDlgItem(hDlg
, chx1
), SW_HIDE
);
1233 } else { /* PD_PRINTSETUP */
1234 BOOL bPortrait
= (lpdm
->u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
);
1236 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb2
,
1237 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1238 PrintStructures
->lpPrinterInfo
->pPortName
,
1240 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb3
,
1241 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1242 PrintStructures
->lpPrinterInfo
->pPortName
,
1244 CheckRadioButton(hDlg
, rad1
, rad2
, bPortrait
? rad1
: rad2
);
1245 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1246 (LPARAM
)(bPortrait
? PrintStructures
->hPortraitIcon
:
1247 PrintStructures
->hLandscapeIcon
));
1252 if ((lppd
->Flags
& PD_SHOWHELP
)==0) {
1253 /* hide if PD_SHOWHELP not specified */
1254 ShowWindow(GetDlgItem(hDlg
, pshHelp
), SW_HIDE
);
1259 /***********************************************************************
1260 * check_printer_setup [internal]
1262 static LRESULT
check_printer_setup(HWND hDlg
)
1265 WCHAR resourcestr
[256],resultstr
[256];
1267 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
1270 EnumPrintersW(PRINTER_ENUM_CONNECTIONS
, NULL
, 2, NULL
, 0, &needed
, &num
);
1276 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEVICES
,resultstr
, 255);
1277 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
,resourcestr
, 255);
1278 MessageBoxW(hDlg
, resultstr
, resourcestr
,MB_OK
| MB_ICONWARNING
);
1283 /***********************************************************************
1284 * PRINTDLG_WMInitDialog [internal]
1286 static LRESULT
PRINTDLG_WMInitDialog(HWND hDlg
,
1287 PRINT_PTRA
* PrintStructures
)
1289 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1293 UINT comboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1295 /* load Collate ICONs */
1296 /* We load these with LoadImage because they are not a standard
1297 size and we don't want them rescaled */
1298 PrintStructures
->hCollateIcon
=
1299 LoadImageA(COMDLG32_hInstance
, "PD32_COLLATE", IMAGE_ICON
, 0, 0, 0);
1300 PrintStructures
->hNoCollateIcon
=
1301 LoadImageA(COMDLG32_hInstance
, "PD32_NOCOLLATE", IMAGE_ICON
, 0, 0, 0);
1303 /* These can be done with LoadIcon */
1304 PrintStructures
->hPortraitIcon
=
1305 LoadIconA(COMDLG32_hInstance
, "PD32_PORTRAIT");
1306 PrintStructures
->hLandscapeIcon
=
1307 LoadIconA(COMDLG32_hInstance
, "PD32_LANDSCAPE");
1309 /* display the collate/no_collate icon */
1310 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1311 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1313 if(PrintStructures
->hCollateIcon
== 0 ||
1314 PrintStructures
->hNoCollateIcon
== 0 ||
1315 PrintStructures
->hPortraitIcon
== 0 ||
1316 PrintStructures
->hLandscapeIcon
== 0) {
1317 ERR("no icon in resourcefile\n");
1318 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1319 EndDialog(hDlg
, FALSE
);
1323 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1324 * must be registered and the Help button must be shown.
1326 if (lppd
->Flags
& PD_SHOWHELP
) {
1327 if((PrintStructures
->HelpMessageID
=
1328 RegisterWindowMessageA(HELPMSGSTRINGA
)) == 0) {
1329 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL
);
1333 PrintStructures
->HelpMessageID
= 0;
1335 if(!(lppd
->Flags
&PD_PRINTSETUP
)) {
1336 PrintStructures
->hwndUpDown
=
1337 CreateUpDownControl(WS_CHILD
| WS_VISIBLE
| WS_BORDER
|
1338 UDS_NOTHOUSANDS
| UDS_ARROWKEYS
|
1339 UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, 0, 0, 0, 0,
1340 hDlg
, UPDOWN_ID
, COMDLG32_hInstance
,
1341 GetDlgItem(hDlg
, edt3
), MAX_COPIES
, 1, 1);
1344 /* FIXME: I allow more freedom than either Win95 or WinNT,
1345 * which do not agree to what errors should be thrown or not
1346 * in case nToPage or nFromPage is out-of-range.
1348 if (lppd
->nMaxPage
< lppd
->nMinPage
)
1349 lppd
->nMaxPage
= lppd
->nMinPage
;
1350 if (lppd
->nMinPage
== lppd
->nMaxPage
)
1351 lppd
->Flags
|= PD_NOPAGENUMS
;
1352 if (lppd
->nToPage
< lppd
->nMinPage
)
1353 lppd
->nToPage
= lppd
->nMinPage
;
1354 if (lppd
->nToPage
> lppd
->nMaxPage
)
1355 lppd
->nToPage
= lppd
->nMaxPage
;
1356 if (lppd
->nFromPage
< lppd
->nMinPage
)
1357 lppd
->nFromPage
= lppd
->nMinPage
;
1358 if (lppd
->nFromPage
> lppd
->nMaxPage
)
1359 lppd
->nFromPage
= lppd
->nMaxPage
;
1361 /* if we have the combo box, fill it */
1362 if (GetDlgItem(hDlg
,comboID
)) {
1365 pdn
= GlobalLock(lppd
->hDevNames
);
1366 pdm
= GlobalLock(lppd
->hDevMode
);
1368 name
= (char*)pdn
+ pdn
->wDeviceOffset
;
1370 name
= (char*)pdm
->dmDeviceName
;
1371 PRINTDLG_SetUpPrinterListComboA(hDlg
, comboID
, name
);
1372 if(pdm
) GlobalUnlock(lppd
->hDevMode
);
1373 if(pdn
) GlobalUnlock(lppd
->hDevNames
);
1375 /* Now find selected printer and update rest of dlg */
1376 name
= HeapAlloc(GetProcessHeap(),0,256);
1377 if (GetDlgItemTextA(hDlg
, comboID
, name
, 255))
1378 PRINTDLG_ChangePrinterA(hDlg
, name
, PrintStructures
);
1379 HeapFree(GetProcessHeap(),0,name
);
1381 /* else use default printer */
1383 DWORD dwBufLen
= sizeof(name
);
1384 BOOL ret
= GetDefaultPrinterA(name
, &dwBufLen
);
1387 PRINTDLG_ChangePrinterA(hDlg
, name
, PrintStructures
);
1389 FIXME("No default printer found, expect problems!\n");
1394 static LRESULT
PRINTDLG_WMInitDialogW(HWND hDlg
,
1395 PRINT_PTRW
* PrintStructures
)
1397 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1401 UINT comboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1403 /* load Collate ICONs */
1404 /* We load these with LoadImage because they are not a standard
1405 size and we don't want them rescaled */
1406 PrintStructures
->hCollateIcon
=
1407 LoadImageW(COMDLG32_hInstance
, pd32_collateW
, IMAGE_ICON
, 0, 0, 0);
1408 PrintStructures
->hNoCollateIcon
=
1409 LoadImageW(COMDLG32_hInstance
, pd32_nocollateW
, IMAGE_ICON
, 0, 0, 0);
1411 /* These can be done with LoadIcon */
1412 PrintStructures
->hPortraitIcon
=
1413 LoadIconW(COMDLG32_hInstance
, pd32_portraitW
);
1414 PrintStructures
->hLandscapeIcon
=
1415 LoadIconW(COMDLG32_hInstance
, pd32_landscapeW
);
1417 /* display the collate/no_collate icon */
1418 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1419 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1421 if(PrintStructures
->hCollateIcon
== 0 ||
1422 PrintStructures
->hNoCollateIcon
== 0 ||
1423 PrintStructures
->hPortraitIcon
== 0 ||
1424 PrintStructures
->hLandscapeIcon
== 0) {
1425 ERR("no icon in resourcefile\n");
1426 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1427 EndDialog(hDlg
, FALSE
);
1431 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1432 * must be registered and the Help button must be shown.
1434 if (lppd
->Flags
& PD_SHOWHELP
) {
1435 if((PrintStructures
->HelpMessageID
=
1436 RegisterWindowMessageW(HELPMSGSTRINGW
)) == 0) {
1437 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL
);
1441 PrintStructures
->HelpMessageID
= 0;
1443 if(!(lppd
->Flags
&PD_PRINTSETUP
)) {
1444 PrintStructures
->hwndUpDown
=
1445 CreateUpDownControl(WS_CHILD
| WS_VISIBLE
| WS_BORDER
|
1446 UDS_NOTHOUSANDS
| UDS_ARROWKEYS
|
1447 UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, 0, 0, 0, 0,
1448 hDlg
, UPDOWN_ID
, COMDLG32_hInstance
,
1449 GetDlgItem(hDlg
, edt3
), MAX_COPIES
, 1, 1);
1452 /* FIXME: I allow more freedom than either Win95 or WinNT,
1453 * which do not agree to what errors should be thrown or not
1454 * in case nToPage or nFromPage is out-of-range.
1456 if (lppd
->nMaxPage
< lppd
->nMinPage
)
1457 lppd
->nMaxPage
= lppd
->nMinPage
;
1458 if (lppd
->nMinPage
== lppd
->nMaxPage
)
1459 lppd
->Flags
|= PD_NOPAGENUMS
;
1460 if (lppd
->nToPage
< lppd
->nMinPage
)
1461 lppd
->nToPage
= lppd
->nMinPage
;
1462 if (lppd
->nToPage
> lppd
->nMaxPage
)
1463 lppd
->nToPage
= lppd
->nMaxPage
;
1464 if (lppd
->nFromPage
< lppd
->nMinPage
)
1465 lppd
->nFromPage
= lppd
->nMinPage
;
1466 if (lppd
->nFromPage
> lppd
->nMaxPage
)
1467 lppd
->nFromPage
= lppd
->nMaxPage
;
1469 /* if we have the combo box, fill it */
1470 if (GetDlgItem(hDlg
,comboID
)) {
1473 pdn
= GlobalLock(lppd
->hDevNames
);
1474 pdm
= GlobalLock(lppd
->hDevMode
);
1476 name
= (WCHAR
*)pdn
+ pdn
->wDeviceOffset
;
1478 name
= pdm
->dmDeviceName
;
1479 PRINTDLG_SetUpPrinterListComboW(hDlg
, comboID
, name
);
1480 if(pdm
) GlobalUnlock(lppd
->hDevMode
);
1481 if(pdn
) GlobalUnlock(lppd
->hDevNames
);
1483 /* Now find selected printer and update rest of dlg */
1484 /* ansi is ok here */
1485 name
= HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR
));
1486 if (GetDlgItemTextW(hDlg
, comboID
, name
, 255))
1487 PRINTDLG_ChangePrinterW(hDlg
, name
, PrintStructures
);
1488 HeapFree(GetProcessHeap(),0,name
);
1490 /* else use default printer */
1492 DWORD dwBufLen
= sizeof(name
) / sizeof(WCHAR
);
1493 BOOL ret
= GetDefaultPrinterW(name
, &dwBufLen
);
1496 PRINTDLG_ChangePrinterW(hDlg
, name
, PrintStructures
);
1498 FIXME("No default printer found, expect problems!\n");
1503 /***********************************************************************
1504 * PRINTDLG_WMCommand [internal]
1506 static LRESULT
PRINTDLG_WMCommandA(HWND hDlg
, WPARAM wParam
,
1507 LPARAM lParam
, PRINT_PTRA
* PrintStructures
)
1509 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1510 UINT PrinterComboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1511 LPDEVMODEA lpdm
= PrintStructures
->lpDevMode
;
1513 switch (LOWORD(wParam
)) {
1515 TRACE(" OK button was hit\n");
1516 if (!PRINTDLG_UpdatePrintDlgA(hDlg
, PrintStructures
)) {
1517 FIXME("Update printdlg was not successful!\n");
1520 EndDialog(hDlg
, TRUE
);
1524 TRACE(" CANCEL button was hit\n");
1525 EndDialog(hDlg
, FALSE
);
1529 TRACE(" HELP button was hit\n");
1530 SendMessageA(lppd
->hwndOwner
, PrintStructures
->HelpMessageID
,
1531 (WPARAM
) hDlg
, (LPARAM
) lppd
);
1534 case chx2
: /* collate pages checkbox */
1535 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
1536 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1537 (LPARAM
)PrintStructures
->hCollateIcon
);
1539 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1540 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1542 case edt1
: /* from page nr editbox */
1543 case edt2
: /* to page nr editbox */
1544 if (HIWORD(wParam
)==EN_CHANGE
) {
1547 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
1548 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
1549 if (nFromPage
!= lppd
->nFromPage
|| nToPage
!= lppd
->nToPage
)
1550 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1555 if(HIWORD(wParam
) == EN_CHANGE
) {
1556 INT copies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
1558 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1560 EnableWindow(GetDlgItem(hDlg
, chx2
), TRUE
);
1564 case psh2
: /* Properties button */
1567 char PrinterName
[256];
1569 GetDlgItemTextA(hDlg
, PrinterComboID
, PrinterName
, 255);
1570 if (!OpenPrinterA(PrinterName
, &hPrinter
, NULL
)) {
1571 FIXME(" Call to OpenPrinter did not succeed!\n");
1574 DocumentPropertiesA(hDlg
, hPrinter
, PrinterName
,
1575 PrintStructures
->lpDevMode
,
1576 PrintStructures
->lpDevMode
,
1577 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
1578 ClosePrinter(hPrinter
);
1582 case rad1
: /* Paperorientation */
1583 if (lppd
->Flags
& PD_PRINTSETUP
)
1585 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1586 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1587 (LPARAM
)(PrintStructures
->hPortraitIcon
));
1591 case rad2
: /* Paperorientation */
1592 if (lppd
->Flags
& PD_PRINTSETUP
)
1594 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1595 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1596 (LPARAM
)(PrintStructures
->hLandscapeIcon
));
1600 case cmb1
: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT16 */
1601 if (PrinterComboID
!= LOWORD(wParam
)) {
1605 case cmb4
: /* Printer combobox */
1606 if (HIWORD(wParam
)==CBN_SELCHANGE
) {
1607 char PrinterName
[256];
1608 GetDlgItemTextA(hDlg
, LOWORD(wParam
), PrinterName
, 255);
1609 PRINTDLG_ChangePrinterA(hDlg
, PrinterName
, PrintStructures
);
1613 case cmb2
: /* Papersize */
1615 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
1617 lpdm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageA(hDlg
, cmb2
,
1623 case cmb3
: /* Bin */
1625 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
1627 lpdm
->u1
.s1
.dmDefaultSource
= SendDlgItemMessageA(hDlg
, cmb3
,
1628 CB_GETITEMDATA
, Sel
,
1633 if(lppd
->Flags
& PD_PRINTSETUP
) {
1634 switch (LOWORD(wParam
)) {
1635 case rad1
: /* orientation */
1637 if (IsDlgButtonChecked(hDlg
, rad1
) == BST_CHECKED
) {
1638 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_PORTRAIT
) {
1639 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1640 SendDlgItemMessageA(hDlg
, stc10
, STM_SETIMAGE
, IMAGE_ICON
,
1641 (LPARAM
)PrintStructures
->hPortraitIcon
);
1642 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1643 (LPARAM
)PrintStructures
->hPortraitIcon
);
1646 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_LANDSCAPE
) {
1647 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1648 SendDlgItemMessageA(hDlg
, stc10
, STM_SETIMAGE
, IMAGE_ICON
,
1649 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1650 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1651 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1660 static LRESULT
PRINTDLG_WMCommandW(HWND hDlg
, WPARAM wParam
,
1661 LPARAM lParam
, PRINT_PTRW
* PrintStructures
)
1663 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1664 UINT PrinterComboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1665 LPDEVMODEW lpdm
= PrintStructures
->lpDevMode
;
1667 switch (LOWORD(wParam
)) {
1669 TRACE(" OK button was hit\n");
1670 if (!PRINTDLG_UpdatePrintDlgW(hDlg
, PrintStructures
)) {
1671 FIXME("Update printdlg was not successful!\n");
1674 EndDialog(hDlg
, TRUE
);
1678 TRACE(" CANCEL button was hit\n");
1679 EndDialog(hDlg
, FALSE
);
1683 TRACE(" HELP button was hit\n");
1684 SendMessageW(lppd
->hwndOwner
, PrintStructures
->HelpMessageID
,
1685 (WPARAM
) hDlg
, (LPARAM
) lppd
);
1688 case chx2
: /* collate pages checkbox */
1689 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
1690 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1691 (LPARAM
)PrintStructures
->hCollateIcon
);
1693 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, IMAGE_ICON
,
1694 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1696 case edt1
: /* from page nr editbox */
1697 case edt2
: /* to page nr editbox */
1698 if (HIWORD(wParam
)==EN_CHANGE
) {
1701 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
1702 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
1703 if (nFromPage
!= lppd
->nFromPage
|| nToPage
!= lppd
->nToPage
)
1704 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1709 if(HIWORD(wParam
) == EN_CHANGE
) {
1710 INT copies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
1712 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1714 EnableWindow(GetDlgItem(hDlg
, chx2
), TRUE
);
1718 case psh2
: /* Properties button */
1721 WCHAR PrinterName
[256];
1723 if (!GetDlgItemTextW(hDlg
, PrinterComboID
, PrinterName
, 255)) break;
1724 if (!OpenPrinterW(PrinterName
, &hPrinter
, NULL
)) {
1725 FIXME(" Call to OpenPrinter did not succeed!\n");
1728 DocumentPropertiesW(hDlg
, hPrinter
, PrinterName
,
1729 PrintStructures
->lpDevMode
,
1730 PrintStructures
->lpDevMode
,
1731 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
1732 ClosePrinter(hPrinter
);
1736 case rad1
: /* Paperorientation */
1737 if (lppd
->Flags
& PD_PRINTSETUP
)
1739 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1740 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1741 (LPARAM
)(PrintStructures
->hPortraitIcon
));
1745 case rad2
: /* Paperorientation */
1746 if (lppd
->Flags
& PD_PRINTSETUP
)
1748 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1749 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1750 (LPARAM
)(PrintStructures
->hLandscapeIcon
));
1754 case cmb1
: /* Printer Combobox in PRINT SETUP */
1756 case cmb4
: /* Printer combobox */
1757 if (HIWORD(wParam
)==CBN_SELCHANGE
) {
1758 WCHAR PrinterName
[256];
1759 GetDlgItemTextW(hDlg
, LOWORD(wParam
), PrinterName
, 255);
1760 PRINTDLG_ChangePrinterW(hDlg
, PrinterName
, PrintStructures
);
1764 case cmb2
: /* Papersize */
1766 DWORD Sel
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
1768 lpdm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageW(hDlg
, cmb2
,
1774 case cmb3
: /* Bin */
1776 DWORD Sel
= SendDlgItemMessageW(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
1778 lpdm
->u1
.s1
.dmDefaultSource
= SendDlgItemMessageW(hDlg
, cmb3
,
1779 CB_GETITEMDATA
, Sel
,
1784 if(lppd
->Flags
& PD_PRINTSETUP
) {
1785 switch (LOWORD(wParam
)) {
1786 case rad1
: /* orientation */
1788 if (IsDlgButtonChecked(hDlg
, rad1
) == BST_CHECKED
) {
1789 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_PORTRAIT
) {
1790 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1791 SendDlgItemMessageW(hDlg
, stc10
, STM_SETIMAGE
, IMAGE_ICON
,
1792 (LPARAM
)PrintStructures
->hPortraitIcon
);
1793 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1794 (LPARAM
)PrintStructures
->hPortraitIcon
);
1797 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_LANDSCAPE
) {
1798 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1799 SendDlgItemMessageW(hDlg
, stc10
, STM_SETIMAGE
, IMAGE_ICON
,
1800 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1801 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, IMAGE_ICON
,
1802 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1811 /***********************************************************************
1812 * PrintDlgProcA [internal]
1814 static INT_PTR CALLBACK
PrintDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
1817 PRINT_PTRA
* PrintStructures
;
1818 INT_PTR res
= FALSE
;
1820 if (uMsg
!=WM_INITDIALOG
) {
1821 PrintStructures
= GetPropW(hDlg
, printdlg_prop
);
1822 if (!PrintStructures
)
1825 PrintStructures
= (PRINT_PTRA
*) lParam
;
1826 SetPropW(hDlg
, printdlg_prop
, PrintStructures
);
1827 if(!check_printer_setup(hDlg
))
1829 EndDialog(hDlg
,FALSE
);
1832 res
= PRINTDLG_WMInitDialog(hDlg
, PrintStructures
);
1834 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
)
1835 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(
1836 hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->lpPrintDlg
1841 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
) {
1842 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
,uMsg
,wParam
,
1849 return PRINTDLG_WMCommandA(hDlg
, wParam
, lParam
, PrintStructures
);
1852 DestroyIcon(PrintStructures
->hCollateIcon
);
1853 DestroyIcon(PrintStructures
->hNoCollateIcon
);
1854 DestroyIcon(PrintStructures
->hPortraitIcon
);
1855 DestroyIcon(PrintStructures
->hLandscapeIcon
);
1856 if(PrintStructures
->hwndUpDown
)
1857 DestroyWindow(PrintStructures
->hwndUpDown
);
1863 static INT_PTR CALLBACK
PrintDlgProcW(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
1866 PRINT_PTRW
* PrintStructures
;
1867 INT_PTR res
= FALSE
;
1869 if (uMsg
!=WM_INITDIALOG
) {
1870 PrintStructures
= GetPropW(hDlg
, printdlg_prop
);
1871 if (!PrintStructures
)
1874 PrintStructures
= (PRINT_PTRW
*) lParam
;
1875 SetPropW(hDlg
, printdlg_prop
, PrintStructures
);
1876 if(!check_printer_setup(hDlg
))
1878 EndDialog(hDlg
,FALSE
);
1881 res
= PRINTDLG_WMInitDialogW(hDlg
, PrintStructures
);
1883 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
)
1884 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->lpPrintDlg
);
1888 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
) {
1889 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
,uMsg
,wParam
, lParam
);
1895 return PRINTDLG_WMCommandW(hDlg
, wParam
, lParam
, PrintStructures
);
1898 DestroyIcon(PrintStructures
->hCollateIcon
);
1899 DestroyIcon(PrintStructures
->hNoCollateIcon
);
1900 DestroyIcon(PrintStructures
->hPortraitIcon
);
1901 DestroyIcon(PrintStructures
->hLandscapeIcon
);
1902 if(PrintStructures
->hwndUpDown
)
1903 DestroyWindow(PrintStructures
->hwndUpDown
);
1909 /************************************************************
1911 * PRINTDLG_GetDlgTemplate
1914 static HGLOBAL
PRINTDLG_GetDlgTemplateA(const PRINTDLGA
*lppd
)
1919 if (lppd
->Flags
& PD_PRINTSETUP
) {
1920 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
1921 hDlgTmpl
= lppd
->hSetupTemplate
;
1922 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
1923 hResInfo
= FindResourceA(lppd
->hInstance
,
1924 lppd
->lpSetupTemplateName
, (LPSTR
)RT_DIALOG
);
1925 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1927 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32_SETUP",
1929 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1932 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
1933 hDlgTmpl
= lppd
->hPrintTemplate
;
1934 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
1935 hResInfo
= FindResourceA(lppd
->hInstance
,
1936 lppd
->lpPrintTemplateName
,
1938 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1940 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32",
1942 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1948 static HGLOBAL
PRINTDLG_GetDlgTemplateW(const PRINTDLGW
*lppd
)
1952 static const WCHAR xpsetup
[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
1953 static const WCHAR xprint
[] = { 'P','R','I','N','T','3','2',0};
1955 if (lppd
->Flags
& PD_PRINTSETUP
) {
1956 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
1957 hDlgTmpl
= lppd
->hSetupTemplate
;
1958 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
1959 hResInfo
= FindResourceW(lppd
->hInstance
,
1960 lppd
->lpSetupTemplateName
, (LPWSTR
)RT_DIALOG
);
1961 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1963 hResInfo
= FindResourceW(COMDLG32_hInstance
, xpsetup
, (LPWSTR
)RT_DIALOG
);
1964 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1967 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
1968 hDlgTmpl
= lppd
->hPrintTemplate
;
1969 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
1970 hResInfo
= FindResourceW(lppd
->hInstance
,
1971 lppd
->lpPrintTemplateName
,
1973 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1975 hResInfo
= FindResourceW(COMDLG32_hInstance
, xprint
, (LPWSTR
)RT_DIALOG
);
1976 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1982 /***********************************************************************
1987 static BOOL
PRINTDLG_CreateDCA(LPPRINTDLGA lppd
)
1989 DEVNAMES
*pdn
= GlobalLock(lppd
->hDevNames
);
1990 DEVMODEA
*pdm
= GlobalLock(lppd
->hDevMode
);
1992 if(lppd
->Flags
& PD_RETURNDC
) {
1993 lppd
->hDC
= CreateDCA((char*)pdn
+ pdn
->wDriverOffset
,
1994 (char*)pdn
+ pdn
->wDeviceOffset
,
1995 (char*)pdn
+ pdn
->wOutputOffset
,
1997 } else if(lppd
->Flags
& PD_RETURNIC
) {
1998 lppd
->hDC
= CreateICA((char*)pdn
+ pdn
->wDriverOffset
,
1999 (char*)pdn
+ pdn
->wDeviceOffset
,
2000 (char*)pdn
+ pdn
->wOutputOffset
,
2003 GlobalUnlock(lppd
->hDevNames
);
2004 GlobalUnlock(lppd
->hDevMode
);
2005 return lppd
->hDC
? TRUE
: FALSE
;
2008 static BOOL
PRINTDLG_CreateDCW(LPPRINTDLGW lppd
)
2010 DEVNAMES
*pdn
= GlobalLock(lppd
->hDevNames
);
2011 DEVMODEW
*pdm
= GlobalLock(lppd
->hDevMode
);
2013 if(lppd
->Flags
& PD_RETURNDC
) {
2014 lppd
->hDC
= CreateDCW((WCHAR
*)pdn
+ pdn
->wDriverOffset
,
2015 (WCHAR
*)pdn
+ pdn
->wDeviceOffset
,
2016 (WCHAR
*)pdn
+ pdn
->wOutputOffset
,
2018 } else if(lppd
->Flags
& PD_RETURNIC
) {
2019 lppd
->hDC
= CreateICW((WCHAR
*)pdn
+ pdn
->wDriverOffset
,
2020 (WCHAR
*)pdn
+ pdn
->wDeviceOffset
,
2021 (WCHAR
*)pdn
+ pdn
->wOutputOffset
,
2024 GlobalUnlock(lppd
->hDevNames
);
2025 GlobalUnlock(lppd
->hDevMode
);
2026 return lppd
->hDC
? TRUE
: FALSE
;
2029 /***********************************************************************
2030 * PrintDlgA (COMDLG32.@)
2032 * Displays the PRINT dialog box, which enables the user to specify
2033 * specific properties of the print job.
2036 * lppd [IO] ptr to PRINTDLG32 struct
2039 * nonzero if the user pressed the OK button
2040 * zero if the user cancelled the window or an error occurred
2044 * * The Collate Icons do not display, even though they are in the code.
2045 * * The Properties Button(s) should call DocumentPropertiesA().
2048 BOOL WINAPI
PrintDlgA(LPPRINTDLGA lppd
)
2056 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
2060 if(TRACE_ON(commdlg
)) {
2061 char flagstr
[1000] = "";
2062 const struct pd_flags
*pflag
= pd_flags
;
2063 for( ; pflag
->name
; pflag
++) {
2064 if(lppd
->Flags
& pflag
->flag
)
2065 strcat(flagstr
, pflag
->name
);
2067 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2068 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2069 "flags %08x (%s)\n",
2070 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
2071 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
2072 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
2075 if(lppd
->lStructSize
!= sizeof(PRINTDLGA
)) {
2076 WARN("structure size failure !!!\n");
2077 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
2081 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
2082 PRINTER_INFO_2A
*pbuf
;
2083 DRIVER_INFO_3A
*dbuf
;
2087 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
2088 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2089 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2092 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
2093 WARN("Can't find default printer\n");
2094 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
2098 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
2099 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
2100 GetPrinterA(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
2102 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
2103 dbuf
= HeapAlloc(GetProcessHeap(),0,needed
);
2104 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
2105 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2106 GetLastError(),pbuf
->pPrinterName
);
2107 HeapFree(GetProcessHeap(), 0, dbuf
);
2108 HeapFree(GetProcessHeap(), 0, pbuf
);
2109 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2114 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
2118 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
2119 pbuf
->pDevMode
->dmDriverExtra
);
2120 ptr
= GlobalLock(lppd
->hDevMode
);
2121 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
2122 pbuf
->pDevMode
->dmDriverExtra
);
2123 GlobalUnlock(lppd
->hDevMode
);
2124 HeapFree(GetProcessHeap(), 0, pbuf
);
2125 HeapFree(GetProcessHeap(), 0, dbuf
);
2129 PRINT_PTRA
*PrintStructures
;
2131 /* load Dialog resources,
2132 * depending on Flags indicates Print32 or Print32_setup dialog
2134 hDlgTmpl
= PRINTDLG_GetDlgTemplateA(lppd
);
2136 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2139 ptr
= LockResource( hDlgTmpl
);
2141 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2145 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2146 sizeof(PRINT_PTRA
));
2147 PrintStructures
->lpPrintDlg
= lppd
;
2149 /* and create & process the dialog .
2150 * -1 is failure, 0 is broken hwnd, everything else is ok.
2152 hInst
= COMDLG32_hInstance
;
2153 if (lppd
->Flags
& (PD_ENABLESETUPTEMPLATE
| PD_ENABLEPRINTTEMPLATE
)) hInst
= lppd
->hInstance
;
2154 bRet
= (0<DialogBoxIndirectParamA(hInst
, ptr
, lppd
->hwndOwner
,
2156 (LPARAM
)PrintStructures
));
2159 DEVMODEA
*lpdm
= PrintStructures
->lpDevMode
, *lpdmReturn
;
2160 PRINTER_INFO_2A
*pi
= PrintStructures
->lpPrinterInfo
;
2161 DRIVER_INFO_3A
*di
= PrintStructures
->lpDriverInfo
;
2163 if (lppd
->hDevMode
== 0) {
2164 TRACE(" No hDevMode yet... Need to create my own\n");
2165 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
,
2166 lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2168 lppd
->hDevMode
= GlobalReAlloc(lppd
->hDevMode
,
2169 lpdm
->dmSize
+ lpdm
->dmDriverExtra
,
2172 lpdmReturn
= GlobalLock(lppd
->hDevMode
);
2173 memcpy(lpdmReturn
, lpdm
, lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2175 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
2180 GlobalUnlock(lppd
->hDevMode
);
2182 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
2183 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpPrinterInfo
);
2184 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDriverInfo
);
2185 HeapFree(GetProcessHeap(), 0, PrintStructures
);
2187 if(bRet
&& (lppd
->Flags
& PD_RETURNDC
|| lppd
->Flags
& PD_RETURNIC
))
2188 bRet
= PRINTDLG_CreateDCA(lppd
);
2190 TRACE("exit! (%d)\n", bRet
);
2194 /***********************************************************************
2195 * PrintDlgW (COMDLG32.@)
2199 BOOL WINAPI
PrintDlgW(LPPRINTDLGW lppd
)
2207 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
2211 if(TRACE_ON(commdlg
)) {
2212 char flagstr
[1000] = "";
2213 const struct pd_flags
*pflag
= pd_flags
;
2214 for( ; pflag
->name
; pflag
++) {
2215 if(lppd
->Flags
& pflag
->flag
)
2216 strcat(flagstr
, pflag
->name
);
2218 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2219 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2220 "flags %08x (%s)\n",
2221 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
2222 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
2223 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
2226 if(lppd
->lStructSize
!= sizeof(PRINTDLGW
)) {
2227 WARN("structure size failure !!!\n");
2228 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
2232 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
2233 PRINTER_INFO_2W
*pbuf
;
2234 DRIVER_INFO_3W
*dbuf
;
2238 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
2239 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2240 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2243 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
2244 WARN("Can't find default printer\n");
2245 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
2249 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
2250 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
2251 GetPrinterW(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
2253 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
2254 dbuf
= HeapAlloc(GetProcessHeap(),0,needed
);
2255 if (!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
2256 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2257 GetLastError(),debugstr_w(pbuf
->pPrinterName
));
2258 HeapFree(GetProcessHeap(), 0, dbuf
);
2259 HeapFree(GetProcessHeap(), 0, pbuf
);
2260 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2265 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
2269 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
2270 pbuf
->pDevMode
->dmDriverExtra
);
2271 ptr
= GlobalLock(lppd
->hDevMode
);
2272 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
2273 pbuf
->pDevMode
->dmDriverExtra
);
2274 GlobalUnlock(lppd
->hDevMode
);
2275 HeapFree(GetProcessHeap(), 0, pbuf
);
2276 HeapFree(GetProcessHeap(), 0, dbuf
);
2280 PRINT_PTRW
*PrintStructures
;
2282 /* load Dialog resources,
2283 * depending on Flags indicates Print32 or Print32_setup dialog
2285 hDlgTmpl
= PRINTDLG_GetDlgTemplateW(lppd
);
2287 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2290 ptr
= LockResource( hDlgTmpl
);
2292 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2296 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2297 sizeof(PRINT_PTRW
));
2298 PrintStructures
->lpPrintDlg
= lppd
;
2300 /* and create & process the dialog .
2301 * -1 is failure, 0 is broken hwnd, everything else is ok.
2303 hInst
= COMDLG32_hInstance
;
2304 if (lppd
->Flags
& (PD_ENABLESETUPTEMPLATE
| PD_ENABLEPRINTTEMPLATE
)) hInst
= lppd
->hInstance
;
2305 bRet
= (0<DialogBoxIndirectParamW(hInst
, ptr
, lppd
->hwndOwner
,
2307 (LPARAM
)PrintStructures
));
2310 DEVMODEW
*lpdm
= PrintStructures
->lpDevMode
, *lpdmReturn
;
2311 PRINTER_INFO_2W
*pi
= PrintStructures
->lpPrinterInfo
;
2312 DRIVER_INFO_3W
*di
= PrintStructures
->lpDriverInfo
;
2314 if (lppd
->hDevMode
== 0) {
2315 TRACE(" No hDevMode yet... Need to create my own\n");
2316 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
,
2317 lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2320 if((locks
= (GlobalFlags(lppd
->hDevMode
) & GMEM_LOCKCOUNT
))) {
2321 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks
);
2323 GlobalUnlock(lppd
->hDevMode
);
2324 TRACE("Now got %d locks\n", locks
);
2327 lppd
->hDevMode
= GlobalReAlloc(lppd
->hDevMode
,
2328 lpdm
->dmSize
+ lpdm
->dmDriverExtra
,
2331 lpdmReturn
= GlobalLock(lppd
->hDevMode
);
2332 memcpy(lpdmReturn
, lpdm
, lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2334 if (lppd
->hDevNames
!= 0) {
2336 if((locks
= (GlobalFlags(lppd
->hDevNames
) & GMEM_LOCKCOUNT
))) {
2337 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks
);
2339 GlobalUnlock(lppd
->hDevNames
);
2342 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
2347 GlobalUnlock(lppd
->hDevMode
);
2349 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
2350 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpPrinterInfo
);
2351 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDriverInfo
);
2352 HeapFree(GetProcessHeap(), 0, PrintStructures
);
2354 if(bRet
&& (lppd
->Flags
& PD_RETURNDC
|| lppd
->Flags
& PD_RETURNIC
))
2355 bRet
= PRINTDLG_CreateDCW(lppd
);
2357 TRACE("exit! (%d)\n", bRet
);
2361 /***********************************************************************
2366 * cmb1 - printer select (not in standard dialog template)
2368 * cmb3 - source (tray?)
2369 * edt4 - border left
2371 * edt6 - border right
2372 * edt7 - border bottom
2373 * psh3 - "Printer..."
2381 LPPAGESETUPDLGA dlga
;
2382 LPPAGESETUPDLGW dlgw
;
2384 HWND hDlg
; /* Page Setup dialog handle */
2385 RECT rtDrawRect
; /* Drawing rect for page */
2388 static inline DWORD
pagesetup_get_flags(const pagesetup_data
*data
)
2390 return data
->u
.dlgw
->Flags
;
2393 static inline BOOL
is_metric(const pagesetup_data
*data
)
2395 return pagesetup_get_flags(data
) & PSD_INHUNDREDTHSOFMILLIMETERS
;
2398 static inline LONG
tenths_mm_to_size(const pagesetup_data
*data
, LONG size
)
2400 if (is_metric(data
))
2403 return 10 * size
* 100 / 254;
2406 static inline LONG
thousandths_inch_to_size(const pagesetup_data
*data
, LONG size
)
2408 if (is_metric(data
))
2409 return size
* 254 / 100;
2414 static WCHAR
get_decimal_sep(void)
2420 WCHAR buf
[2] = {'.',0};
2421 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SDECIMAL
, buf
, sizeof(buf
) / sizeof(buf
[0]));
2427 static void size2str(const pagesetup_data
*data
, DWORD size
, LPWSTR strout
)
2429 WCHAR integer_fmt
[] = {'%','d',0};
2430 WCHAR hundredths_fmt
[] = {'%','d','%','c','%','0','2','d',0};
2431 WCHAR thousandths_fmt
[] = {'%','d','%','c','%','0','3','d',0};
2433 /* FIXME use LOCALE_SDECIMAL when the edit parsing code can cope */
2435 if (is_metric(data
))
2438 wsprintfW(strout
, hundredths_fmt
, size
/ 100, get_decimal_sep(), size
% 100);
2440 wsprintfW(strout
, integer_fmt
, size
/ 100);
2445 wsprintfW(strout
, thousandths_fmt
, size
/ 1000, get_decimal_sep(), size
% 1000);
2447 wsprintfW(strout
, integer_fmt
, size
/ 1000);
2452 static inline BOOL
is_default_metric(void)
2455 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_IMEASURE
| LOCALE_RETURN_NUMBER
,
2456 (LPWSTR
)&system
, sizeof(system
));
2460 /**********************************************
2462 * Cyclically permute the four members of rc
2463 * If sense is TRUE l -> t -> r -> b
2464 * otherwise l <- t <- r <- b
2466 static inline void rotate_rect(RECT
*rc
, BOOL sense
)
2472 rc
->bottom
= rc
->right
;
2473 rc
->right
= rc
->top
;
2481 rc
->top
= rc
->right
;
2482 rc
->right
= rc
->bottom
;
2487 static void pagesetup_set_orientation(pagesetup_data
*data
, WORD orient
)
2489 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2491 assert(orient
== DMORIENT_PORTRAIT
|| orient
== DMORIENT_LANDSCAPE
);
2494 dm
->u1
.s1
.dmOrientation
= orient
;
2497 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2498 dmA
->u1
.s1
.dmOrientation
= orient
;
2500 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2503 static WORD
pagesetup_get_orientation(const pagesetup_data
*data
)
2505 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2509 orient
= dm
->u1
.s1
.dmOrientation
;
2512 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2513 orient
= dmA
->u1
.s1
.dmOrientation
;
2515 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2519 static void pagesetup_set_papersize(pagesetup_data
*data
, WORD paper
)
2521 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2524 dm
->u1
.s1
.dmPaperSize
= paper
;
2527 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2528 dmA
->u1
.s1
.dmPaperSize
= paper
;
2530 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2533 static WORD
pagesetup_get_papersize(const pagesetup_data
*data
)
2535 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2539 paper
= dm
->u1
.s1
.dmPaperSize
;
2542 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2543 paper
= dmA
->u1
.s1
.dmPaperSize
;
2545 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2549 static void pagesetup_set_defaultsource(pagesetup_data
*data
, WORD source
)
2551 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2554 dm
->u1
.s1
.dmDefaultSource
= source
;
2557 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2558 dmA
->u1
.s1
.dmDefaultSource
= source
;
2560 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2565 devnames_driver_name
,
2566 devnames_device_name
,
2567 devnames_output_name
2571 static inline WORD
get_devname_offset(const DEVNAMES
*dn
, devnames_name which
)
2575 case devnames_driver_name
: return dn
->wDriverOffset
;
2576 case devnames_device_name
: return dn
->wDeviceOffset
;
2577 case devnames_output_name
: return dn
->wOutputOffset
;
2579 ERR("Souldn't be here\n");
2583 static WCHAR
*pagesetup_get_a_devname(const pagesetup_data
*data
, devnames_name which
)
2588 dn
= GlobalLock(data
->u
.dlgw
->hDevNames
);
2590 name
= strdupW((WCHAR
*)dn
+ get_devname_offset(dn
, which
));
2593 int len
= MultiByteToWideChar(CP_ACP
, 0, (char*)dn
+ get_devname_offset(dn
, which
), -1, NULL
, 0);
2594 name
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
2595 MultiByteToWideChar(CP_ACP
, 0, (char*)dn
+ get_devname_offset(dn
, which
), -1, name
, len
);
2597 GlobalUnlock(data
->u
.dlgw
->hDevNames
);
2601 static WCHAR
*pagesetup_get_drvname(const pagesetup_data
*data
)
2603 return pagesetup_get_a_devname(data
, devnames_driver_name
);
2606 static WCHAR
*pagesetup_get_devname(const pagesetup_data
*data
)
2608 return pagesetup_get_a_devname(data
, devnames_device_name
);
2611 static WCHAR
*pagesetup_get_portname(const pagesetup_data
*data
)
2613 return pagesetup_get_a_devname(data
, devnames_output_name
);
2616 static void pagesetup_release_a_devname(const pagesetup_data
*data
, WCHAR
*name
)
2618 HeapFree(GetProcessHeap(), 0, name
);
2621 static void pagesetup_set_devnames(pagesetup_data
*data
, LPCWSTR drv
, LPCWSTR devname
, LPCWSTR port
)
2625 DWORD len
= sizeof(DEVNAMES
), drv_len
, dev_len
, port_len
;
2629 drv_len
= (strlenW(drv
) + 1) * sizeof(WCHAR
);
2630 dev_len
= (strlenW(devname
) + 1) * sizeof(WCHAR
);
2631 port_len
= (strlenW(port
) + 1) * sizeof(WCHAR
);
2635 drv_len
= WideCharToMultiByte(CP_ACP
, 0, drv
, -1, NULL
, 0, NULL
, NULL
);
2636 dev_len
= WideCharToMultiByte(CP_ACP
, 0, devname
, -1, NULL
, 0, NULL
, NULL
);
2637 port_len
= WideCharToMultiByte(CP_ACP
, 0, port
, -1, NULL
, 0, NULL
, NULL
);
2639 len
+= drv_len
+ dev_len
+ port_len
;
2641 if(data
->u
.dlgw
->hDevNames
)
2642 data
->u
.dlgw
->hDevNames
= GlobalReAlloc(data
->u
.dlgw
->hDevNames
, len
, GMEM_MOVEABLE
);
2644 data
->u
.dlgw
->hDevNames
= GlobalAlloc(GMEM_MOVEABLE
, len
);
2646 dn
= GlobalLock(data
->u
.dlgw
->hDevNames
);
2650 WCHAR
*ptr
= (WCHAR
*)(dn
+ 1);
2651 len
= sizeof(DEVNAMES
) / sizeof(WCHAR
);
2652 dn
->wDriverOffset
= len
;
2654 ptr
+= drv_len
/ sizeof(WCHAR
);
2655 len
+= drv_len
/ sizeof(WCHAR
);
2656 dn
->wDeviceOffset
= len
;
2657 strcpyW(ptr
, devname
);
2658 ptr
+= dev_len
/ sizeof(WCHAR
);
2659 len
+= dev_len
/ sizeof(WCHAR
);
2660 dn
->wOutputOffset
= len
;
2665 char *ptr
= (char *)(dn
+ 1);
2666 len
= sizeof(DEVNAMES
);
2667 dn
->wDriverOffset
= len
;
2668 WideCharToMultiByte(CP_ACP
, 0, drv
, -1, ptr
, drv_len
, NULL
, NULL
);
2671 dn
->wDeviceOffset
= len
;
2672 WideCharToMultiByte(CP_ACP
, 0, devname
, -1, ptr
, dev_len
, NULL
, NULL
);
2675 dn
->wOutputOffset
= len
;
2676 WideCharToMultiByte(CP_ACP
, 0, port
, -1, ptr
, port_len
, NULL
, NULL
);
2680 len
= sizeof(def
) / sizeof(def
[0]);
2681 GetDefaultPrinterW(def
, &len
);
2682 if(!lstrcmpW(def
, devname
))
2685 GlobalUnlock(data
->u
.dlgw
->hDevNames
);
2688 static DEVMODEW
*pagesetup_get_devmode(const pagesetup_data
*data
)
2690 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2695 /* We make a copy even in the unicode case because the ptr
2696 may get passed back to us in pagesetup_set_devmode. */
2697 ret
= HeapAlloc(GetProcessHeap(), 0, dm
->dmSize
+ dm
->dmDriverExtra
);
2698 memcpy(ret
, dm
, dm
->dmSize
+ dm
->dmDriverExtra
);
2701 ret
= GdiConvertToDevmodeW((DEVMODEA
*)dm
);
2703 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2707 static void pagesetup_release_devmode(const pagesetup_data
*data
, DEVMODEW
*dm
)
2709 HeapFree(GetProcessHeap(), 0, dm
);
2712 static void pagesetup_set_devmode(pagesetup_data
*data
, DEVMODEW
*dm
)
2714 DEVMODEA
*dmA
= NULL
;
2720 size
= dm
->dmSize
+ dm
->dmDriverExtra
;
2725 dmA
= convert_to_devmodeA(dm
);
2726 size
= dmA
->dmSize
+ dmA
->dmDriverExtra
;
2730 if(data
->u
.dlgw
->hDevMode
)
2731 data
->u
.dlgw
->hDevMode
= GlobalReAlloc(data
->u
.dlgw
->hDevMode
, size
,
2734 data
->u
.dlgw
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, size
);
2736 dst
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2737 memcpy(dst
, src
, size
);
2738 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2739 HeapFree(GetProcessHeap(), 0, dmA
);
2742 static inline POINT
*pagesetup_get_papersize_pt(const pagesetup_data
*data
)
2744 return &data
->u
.dlgw
->ptPaperSize
;
2747 static inline RECT
*pagesetup_get_margin_rect(const pagesetup_data
*data
)
2749 return &data
->u
.dlgw
->rtMargin
;
2758 static inline LPPAGESETUPHOOK
pagesetup_get_hook(const pagesetup_data
*data
, hook_type which
)
2762 case page_setup_hook
: return data
->u
.dlgw
->lpfnPageSetupHook
;
2763 case page_paint_hook
: return data
->u
.dlgw
->lpfnPagePaintHook
;
2768 /* This should only be used in calls to hook procs so we return the ptr
2769 already cast to LPARAM */
2770 static inline LPARAM
pagesetup_get_dlg_struct(const pagesetup_data
*data
)
2772 return (LPARAM
)data
->u
.dlgw
;
2775 static inline void swap_point(POINT
*pt
)
2782 static BOOL
pagesetup_update_papersize(pagesetup_data
*data
)
2785 LPWSTR devname
, portname
;
2787 WORD
*words
= NULL
, paperword
;
2788 POINT
*points
= NULL
;
2789 BOOL retval
= FALSE
;
2791 dm
= pagesetup_get_devmode(data
);
2792 devname
= pagesetup_get_devname(data
);
2793 portname
= pagesetup_get_portname(data
);
2795 num
= DeviceCapabilitiesW(devname
, portname
, DC_PAPERS
, NULL
, dm
);
2798 FIXME("No papernames found for %s/%s\n", debugstr_w(devname
), debugstr_w(portname
));
2802 words
= HeapAlloc(GetProcessHeap(), 0, num
* sizeof(WORD
));
2803 points
= HeapAlloc(GetProcessHeap(), 0, num
* sizeof(POINT
));
2805 if (num
!= DeviceCapabilitiesW(devname
, portname
, DC_PAPERS
, (LPWSTR
)words
, dm
))
2807 FIXME("Number of returned words is not %d\n", num
);
2811 if (num
!= DeviceCapabilitiesW(devname
, portname
, DC_PAPERSIZE
, (LPWSTR
)points
, dm
))
2813 FIXME("Number of returned sizes is not %d\n", num
);
2817 paperword
= pagesetup_get_papersize(data
);
2819 for (i
= 0; i
< num
; i
++)
2820 if (words
[i
] == paperword
)
2825 FIXME("Papersize %d not found in list?\n", paperword
);
2829 /* this is _10ths_ of a millimeter */
2830 pagesetup_get_papersize_pt(data
)->x
= tenths_mm_to_size(data
, points
[i
].x
);
2831 pagesetup_get_papersize_pt(data
)->y
= tenths_mm_to_size(data
, points
[i
].y
);
2833 if(pagesetup_get_orientation(data
) == DMORIENT_LANDSCAPE
)
2834 swap_point(pagesetup_get_papersize_pt(data
));
2839 HeapFree(GetProcessHeap(), 0, words
);
2840 HeapFree(GetProcessHeap(), 0, points
);
2841 pagesetup_release_a_devname(data
, portname
);
2842 pagesetup_release_a_devname(data
, devname
);
2843 pagesetup_release_devmode(data
, dm
);
2848 /**********************************************************************************************
2849 * pagesetup_change_printer
2851 * Redefines hDevMode and hDevNames HANDLES and initialises it.
2854 static BOOL
pagesetup_change_printer(LPWSTR name
, pagesetup_data
*data
)
2858 PRINTER_INFO_2W
*prn_info
= NULL
;
2859 DRIVER_INFO_3W
*drv_info
= NULL
;
2860 DEVMODEW
*dm
= NULL
;
2861 BOOL retval
= FALSE
;
2863 if(!OpenPrinterW(name
, &hprn
, NULL
))
2865 ERR("Can't open printer %s\n", debugstr_w(name
));
2869 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
2870 prn_info
= HeapAlloc(GetProcessHeap(), 0, needed
);
2871 GetPrinterW(hprn
, 2, (LPBYTE
)prn_info
, needed
, &needed
);
2872 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
2873 drv_info
= HeapAlloc(GetProcessHeap(), 0, needed
);
2874 if(!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)drv_info
, needed
, &needed
))
2876 ERR("GetPrinterDriverA failed for %s, fix your config!\n", debugstr_w(prn_info
->pPrinterName
));
2881 needed
= DocumentPropertiesW(0, 0, name
, NULL
, NULL
, 0);
2884 ERR("DocumentProperties fails on %s\n", debugstr_w(name
));
2888 dm
= HeapAlloc(GetProcessHeap(), 0, needed
);
2889 DocumentPropertiesW(0, 0, name
, dm
, NULL
, DM_OUT_BUFFER
);
2891 pagesetup_set_devmode(data
, dm
);
2892 pagesetup_set_devnames(data
, drv_info
->pDriverPath
, prn_info
->pPrinterName
,
2893 prn_info
->pPortName
);
2897 HeapFree(GetProcessHeap(), 0, dm
);
2898 HeapFree(GetProcessHeap(), 0, prn_info
);
2899 HeapFree(GetProcessHeap(), 0, drv_info
);
2903 /****************************************************************************************
2904 * pagesetup_init_combos
2906 * Fills Printers, Paper and Source combos
2909 static void pagesetup_init_combos(HWND hDlg
, pagesetup_data
*data
)
2912 LPWSTR devname
, portname
;
2914 dm
= pagesetup_get_devmode(data
);
2915 devname
= pagesetup_get_devname(data
);
2916 portname
= pagesetup_get_portname(data
);
2918 PRINTDLG_SetUpPrinterListComboW(hDlg
, cmb1
, devname
);
2919 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb2
, devname
, portname
, dm
);
2920 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb3
, devname
, portname
, dm
);
2922 pagesetup_release_a_devname(data
, portname
);
2923 pagesetup_release_a_devname(data
, devname
);
2924 pagesetup_release_devmode(data
, dm
);
2928 /****************************************************************************************
2929 * pagesetup_change_printer_dialog
2931 * Pops up another dialog that lets the user pick another printer.
2933 * For now we display the PrintDlg, this should display a striped down version of it.
2935 static void pagesetup_change_printer_dialog(HWND hDlg
, pagesetup_data
*data
)
2938 LPWSTR drvname
, devname
, portname
;
2939 DEVMODEW
*tmp_dm
, *dm
;
2941 memset(&prnt
, 0, sizeof(prnt
));
2942 prnt
.lStructSize
= sizeof(prnt
);
2944 prnt
.hwndOwner
= hDlg
;
2946 drvname
= pagesetup_get_drvname(data
);
2947 devname
= pagesetup_get_devname(data
);
2948 portname
= pagesetup_get_portname(data
);
2950 PRINTDLG_CreateDevNamesW(&prnt
.hDevNames
, drvname
, devname
, portname
);
2951 pagesetup_release_a_devname(data
, portname
);
2952 pagesetup_release_a_devname(data
, devname
);
2953 pagesetup_release_a_devname(data
, drvname
);
2955 tmp_dm
= pagesetup_get_devmode(data
);
2956 prnt
.hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, tmp_dm
->dmSize
+ tmp_dm
->dmDriverExtra
);
2957 dm
= GlobalLock(prnt
.hDevMode
);
2958 memcpy(dm
, tmp_dm
, tmp_dm
->dmSize
+ tmp_dm
->dmDriverExtra
);
2959 GlobalUnlock(prnt
.hDevMode
);
2960 pagesetup_release_devmode(data
, tmp_dm
);
2962 if (PrintDlgW(&prnt
))
2964 DEVMODEW
*dm
= GlobalLock(prnt
.hDevMode
);
2965 DEVNAMES
*dn
= GlobalLock(prnt
.hDevNames
);
2967 pagesetup_set_devnames(data
, (WCHAR
*)dn
+ dn
->wDriverOffset
,
2968 (WCHAR
*)dn
+ dn
->wDeviceOffset
, (WCHAR
*)dn
+ dn
->wOutputOffset
);
2969 pagesetup_set_devmode(data
, dm
);
2970 GlobalUnlock(prnt
.hDevNames
);
2971 GlobalUnlock(prnt
.hDevMode
);
2972 pagesetup_init_combos(hDlg
, data
);
2975 GlobalFree(prnt
.hDevMode
);
2976 GlobalFree(prnt
.hDevNames
);
2980 /******************************************************************************************
2981 * pagesetup_change_preview
2983 * Changes paper preview size / position
2986 static void pagesetup_change_preview(const pagesetup_data
*data
)
2988 LONG width
, height
, x
, y
;
2990 const int shadow
= 4;
2992 if(pagesetup_get_orientation(data
) == DMORIENT_LANDSCAPE
)
2994 width
= data
->rtDrawRect
.right
- data
->rtDrawRect
.left
;
2995 height
= pagesetup_get_papersize_pt(data
)->y
* width
/ pagesetup_get_papersize_pt(data
)->x
;
2999 height
= data
->rtDrawRect
.bottom
- data
->rtDrawRect
.top
;
3000 width
= pagesetup_get_papersize_pt(data
)->x
* height
/ pagesetup_get_papersize_pt(data
)->y
;
3002 x
= (data
->rtDrawRect
.right
+ data
->rtDrawRect
.left
- width
) / 2;
3003 y
= (data
->rtDrawRect
.bottom
+ data
->rtDrawRect
.top
- height
) / 2;
3004 TRACE("draw rect %s x=%d, y=%d, w=%d, h=%d\n",
3005 wine_dbgstr_rect(&data
->rtDrawRect
), x
, y
, width
, height
);
3007 MoveWindow(GetDlgItem(data
->hDlg
, rct2
), x
+ width
, y
+ shadow
, shadow
, height
, FALSE
);
3008 MoveWindow(GetDlgItem(data
->hDlg
, rct3
), x
+ shadow
, y
+ height
, width
, shadow
, FALSE
);
3009 MoveWindow(GetDlgItem(data
->hDlg
, rct1
), x
, y
, width
, height
, FALSE
);
3011 tmp
= data
->rtDrawRect
;
3012 tmp
.right
+= shadow
;
3013 tmp
.bottom
+= shadow
;
3014 InvalidateRect(data
->hDlg
, &tmp
, TRUE
);
3017 static inline LONG
*element_from_margin_id(RECT
*rc
, WORD id
)
3021 case edt4
: return &rc
->left
;
3022 case edt5
: return &rc
->top
;
3023 case edt6
: return &rc
->right
;
3024 case edt7
: return &rc
->bottom
;
3029 static void update_margin_edits(HWND hDlg
, const pagesetup_data
*data
, WORD id
)
3034 for(idx
= edt4
; idx
<= edt7
; idx
++)
3036 if(id
== 0 || id
== idx
)
3038 size2str(data
, *element_from_margin_id(pagesetup_get_margin_rect(data
), idx
), str
);
3039 SetDlgItemTextW(hDlg
, idx
, str
);
3044 static void margin_edit_notification(HWND hDlg
, const pagesetup_data
*data
, WORD msg
, WORD id
)
3052 LONG
*value
= element_from_margin_id(pagesetup_get_margin_rect(data
), id
);
3054 if (GetDlgItemTextW(hDlg
, id
, buf
, sizeof(buf
) / sizeof(buf
[0])) != 0)
3057 WCHAR decimal
= get_decimal_sep();
3059 val
= strtolW(buf
, &end
, 10);
3060 if(end
!= buf
|| *end
== decimal
)
3062 int mult
= is_metric(data
) ? 100 : 1000;
3071 val
+= (*end
- '0') * mult
;
3083 update_margin_edits(hDlg
, data
, id
);
3088 static void set_margin_groupbox_title(HWND hDlg
, const pagesetup_data
*data
)
3092 if(LoadStringW(COMDLG32_hInstance
, is_metric(data
) ? PD32_MARGINS_IN_MILLIMETERS
: PD32_MARGINS_IN_INCHES
,
3093 title
, sizeof(title
)/sizeof(title
[0])))
3094 SetDlgItemTextW(hDlg
, grp4
, title
);
3097 static void pagesetup_update_orientation_buttons(HWND hDlg
, const pagesetup_data
*data
)
3099 if (pagesetup_get_orientation(data
) == DMORIENT_LANDSCAPE
)
3100 CheckRadioButton(hDlg
, rad1
, rad2
, rad2
);
3102 CheckRadioButton(hDlg
, rad1
, rad2
, rad1
);
3105 /****************************************************************************************
3106 * pagesetup_printer_properties
3108 * Handle invocation of the 'Properties' button (not present in the default template).
3110 static void pagesetup_printer_properties(HWND hDlg
, pagesetup_data
*data
)
3118 devname
= pagesetup_get_devname(data
);
3120 if (!OpenPrinterW(devname
, &hprn
, NULL
))
3122 FIXME("Call to OpenPrinter did not succeed!\n");
3123 pagesetup_release_a_devname(data
, devname
);
3127 dm
= pagesetup_get_devmode(data
);
3128 DocumentPropertiesW(hDlg
, hprn
, devname
, dm
, dm
, DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
3129 pagesetup_set_devmode(data
, dm
);
3130 pagesetup_release_devmode(data
, dm
);
3131 pagesetup_release_a_devname(data
, devname
);
3134 /* Changing paper */
3135 pagesetup_update_papersize(data
);
3136 pagesetup_update_orientation_buttons(hDlg
, data
);
3138 /* Changing paper preview */
3139 pagesetup_change_preview(data
);
3141 /* Selecting paper in combo */
3142 count
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCOUNT
, 0, 0);
3145 WORD paperword
= pagesetup_get_papersize(data
);
3146 for(i
= 0; i
< count
; i
++)
3148 if(SendDlgItemMessageW(hDlg
, cmb2
, CB_GETITEMDATA
, i
, 0) == paperword
) {
3149 SendDlgItemMessageW(hDlg
, cmb2
, CB_SETCURSEL
, i
, 0);
3156 /********************************************************************************
3157 * pagesetup_wm_command
3158 * process WM_COMMAND message for PageSetupDlg
3161 * hDlg [in] Main dialog HANDLE
3162 * wParam [in] WM_COMMAND wParam
3163 * lParam [in] WM_COMMAND lParam
3164 * pda [in/out] ptr to PageSetupDataA
3167 static BOOL
pagesetup_wm_command(HWND hDlg
, WPARAM wParam
, LPARAM lParam
, pagesetup_data
*data
)
3169 WORD msg
= HIWORD(wParam
);
3170 WORD id
= LOWORD(wParam
);
3172 TRACE("loword (lparam) %d, wparam 0x%lx, lparam %08lx\n",
3173 LOWORD(lParam
),wParam
,lParam
);
3176 EndDialog(hDlg
, TRUE
);
3180 EndDialog(hDlg
, FALSE
);
3183 case psh3
: /* Printer... */
3184 pagesetup_change_printer_dialog(hDlg
, data
);
3187 case rad1
: /* Portrait */
3188 case rad2
: /* Landscape */
3189 if((id
== rad1
&& pagesetup_get_orientation(data
) == DMORIENT_LANDSCAPE
) ||
3190 (id
== rad2
&& pagesetup_get_orientation(data
) == DMORIENT_PORTRAIT
))
3192 pagesetup_set_orientation(data
, (id
== rad1
) ? DMORIENT_PORTRAIT
: DMORIENT_LANDSCAPE
);
3193 pagesetup_update_papersize(data
);
3194 rotate_rect(pagesetup_get_margin_rect(data
), (id
== rad2
));
3195 update_margin_edits(hDlg
, data
, 0);
3196 pagesetup_change_preview(data
);
3199 case cmb1
: /* Printer combo */
3200 if(msg
== CBN_SELCHANGE
)
3203 GetDlgItemTextW(hDlg
, id
, name
, sizeof(name
) / sizeof(name
[0]));
3204 pagesetup_change_printer(name
, data
);
3205 pagesetup_init_combos(hDlg
, data
);
3208 case cmb2
: /* Paper combo */
3209 if(msg
== CBN_SELCHANGE
)
3211 DWORD paperword
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETITEMDATA
,
3212 SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0), 0);
3213 if (paperword
!= CB_ERR
)
3215 pagesetup_set_papersize(data
, paperword
);
3216 pagesetup_update_papersize(data
);
3217 pagesetup_change_preview(data
);
3219 FIXME("could not get dialog text for papersize cmbbox?\n");
3222 case cmb3
: /* Paper Source */
3223 if(msg
== CBN_SELCHANGE
)
3225 WORD source
= SendDlgItemMessageW(hDlg
, cmb3
, CB_GETITEMDATA
,
3226 SendDlgItemMessageW(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0), 0);
3227 pagesetup_set_defaultsource(data
, source
);
3230 case psh2
: /* Printer Properties button */
3231 pagesetup_printer_properties(hDlg
, data
);
3237 margin_edit_notification(hDlg
, data
, msg
, id
);
3240 InvalidateRect(GetDlgItem(hDlg
, rct1
), NULL
, TRUE
);
3244 /***********************************************************************
3245 * default_page_paint_hook
3246 * Default hook paint procedure that receives WM_PSD_* messages from the dialog box
3247 * whenever the sample page is redrawn.
3249 static UINT_PTR
default_page_paint_hook(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
,
3250 const pagesetup_data
*data
)
3252 LPRECT lprc
= (LPRECT
) lParam
;
3253 HDC hdc
= (HDC
) wParam
;
3256 HFONT hfont
, holdfont
;
3258 TRACE("uMsg: WM_USER+%d\n",uMsg
-WM_USER
);
3259 /* Call user paint hook if enable */
3260 if (pagesetup_get_flags(data
) & PSD_ENABLEPAGEPAINTHOOK
)
3261 if (pagesetup_get_hook(data
, page_paint_hook
)(hwndDlg
, uMsg
, wParam
, lParam
))
3265 /* LPPAGESETUPDLG in lParam */
3266 case WM_PSD_PAGESETUPDLG
:
3267 /* Inform about the sample page rectangle */
3268 case WM_PSD_FULLPAGERECT
:
3269 /* Inform about the margin rectangle */
3270 case WM_PSD_MINMARGINRECT
:
3273 /* Draw dashed rectangle showing margins */
3274 case WM_PSD_MARGINRECT
:
3275 hpen
= CreatePen(PS_DASH
, 1, GetSysColor(COLOR_3DSHADOW
));
3276 holdpen
= SelectObject(hdc
, hpen
);
3277 Rectangle(hdc
, lprc
->left
, lprc
->top
, lprc
->right
, lprc
->bottom
);
3278 DeleteObject(SelectObject(hdc
, holdpen
));
3280 /* Draw the fake document */
3281 case WM_PSD_GREEKTEXTRECT
:
3282 /* select a nice scalable font, because we want the text really small */
3283 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, sizeof(lf
), &lf
, 0);
3284 lf
.lfHeight
= 6; /* value chosen based on visual effect */
3285 hfont
= CreateFontIndirectW(&lf
);
3286 holdfont
= SelectObject(hdc
, hfont
);
3288 /* if text not loaded, then do so now */
3289 if (wszFakeDocumentText
[0] == '\0')
3290 LoadStringW(COMDLG32_hInstance
,
3292 wszFakeDocumentText
,
3293 sizeof(wszFakeDocumentText
)/sizeof(wszFakeDocumentText
[0]));
3295 oldbkmode
= SetBkMode(hdc
, TRANSPARENT
);
3296 DrawTextW(hdc
, wszFakeDocumentText
, -1, lprc
, DT_TOP
|DT_LEFT
|DT_NOPREFIX
|DT_WORDBREAK
);
3297 SetBkMode(hdc
, oldbkmode
);
3299 DeleteObject(SelectObject(hdc
, holdfont
));
3302 /* Envelope stamp */
3303 case WM_PSD_ENVSTAMPRECT
:
3304 /* Return address */
3305 case WM_PSD_YAFULLPAGERECT
:
3306 FIXME("envelope/stamp is not implemented\n");
3309 FIXME("Unknown message %x\n",uMsg
);
3315 /***********************************************************************
3317 * The main paint procedure for the PageSetupDlg function.
3318 * The Page Setup dialog box includes an image of a sample page that shows how
3319 * the user's selections affect the appearance of the printed output.
3320 * The image consists of a rectangle that represents the selected paper
3321 * or envelope type, with a dotted-line rectangle representing
3322 * the current margins, and partial (Greek text) characters
3323 * to show how text looks on the printed page.
3325 * The following messages in the order sends to user hook procedure:
3326 * WM_PSD_PAGESETUPDLG Draw the contents of the sample page
3327 * WM_PSD_FULLPAGERECT Inform about the bounding rectangle
3328 * WM_PSD_MINMARGINRECT Inform about the margin rectangle (min margin?)
3329 * WM_PSD_MARGINRECT Draw the margin rectangle
3330 * WM_PSD_GREEKTEXTRECT Draw the Greek text inside the margin rectangle
3331 * If any of first three messages returns TRUE, painting done.
3334 * hWnd [in] Handle to the Page Setup dialog box
3335 * uMsg [in] Received message
3338 * WM_PSD_ENVSTAMPRECT Draw in the envelope-stamp rectangle (for envelopes only)
3339 * WM_PSD_YAFULLPAGERECT Draw the return address portion (for envelopes and other paper sizes)
3342 * FALSE if all done correctly
3347 static LRESULT CALLBACK
3348 PRINTDLG_PagePaintProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3351 RECT rcClient
, rcMargin
;
3354 HBRUSH hbrush
, holdbrush
;
3355 pagesetup_data
*data
;
3356 int papersize
=0, orientation
=0; /* FIXME: set this values for user paint hook */
3357 double scalx
, scaly
;
3359 if (uMsg
!= WM_PAINT
)
3360 return CallWindowProcA(lpfnStaticWndProc
, hWnd
, uMsg
, wParam
, lParam
);
3362 /* Processing WM_PAINT message */
3363 data
= GetPropW(hWnd
, pagesetupdlg_prop
);
3365 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3368 if (default_page_paint_hook(hWnd
, WM_PSD_PAGESETUPDLG
, MAKELONG(papersize
, orientation
),
3369 pagesetup_get_dlg_struct(data
), data
))
3372 hdc
= BeginPaint(hWnd
, &ps
);
3373 GetClientRect(hWnd
, &rcClient
);
3375 scalx
= rcClient
.right
/ (double)pagesetup_get_papersize_pt(data
)->x
;
3376 scaly
= rcClient
.bottom
/ (double)pagesetup_get_papersize_pt(data
)->y
;
3377 rcMargin
= rcClient
;
3379 rcMargin
.left
+= pagesetup_get_margin_rect(data
)->left
* scalx
;
3380 rcMargin
.top
+= pagesetup_get_margin_rect(data
)->top
* scaly
;
3381 rcMargin
.right
-= pagesetup_get_margin_rect(data
)->right
* scalx
;
3382 rcMargin
.bottom
-= pagesetup_get_margin_rect(data
)->bottom
* scaly
;
3384 /* if the space is too small then we make sure to not draw anything */
3385 rcMargin
.left
= min(rcMargin
.left
, rcMargin
.right
);
3386 rcMargin
.top
= min(rcMargin
.top
, rcMargin
.bottom
);
3388 if (!default_page_paint_hook(hWnd
, WM_PSD_FULLPAGERECT
, (WPARAM
)hdc
, (LPARAM
)&rcClient
, data
) &&
3389 !default_page_paint_hook(hWnd
, WM_PSD_MINMARGINRECT
, (WPARAM
)hdc
, (LPARAM
)&rcMargin
, data
) )
3391 /* fill background */
3392 hbrush
= GetSysColorBrush(COLOR_3DHIGHLIGHT
);
3393 FillRect(hdc
, &rcClient
, hbrush
);
3394 holdbrush
= SelectObject(hdc
, hbrush
);
3396 hpen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DSHADOW
));
3397 holdpen
= SelectObject(hdc
, hpen
);
3399 /* paint left edge */
3400 MoveToEx(hdc
, rcClient
.left
, rcClient
.top
, NULL
);
3401 LineTo(hdc
, rcClient
.left
, rcClient
.bottom
-1);
3403 /* paint top edge */
3404 MoveToEx(hdc
, rcClient
.left
, rcClient
.top
, NULL
);
3405 LineTo(hdc
, rcClient
.right
, rcClient
.top
);
3407 hpen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DDKSHADOW
));
3408 DeleteObject(SelectObject(hdc
, hpen
));
3410 /* paint right edge */
3411 MoveToEx(hdc
, rcClient
.right
-1, rcClient
.top
, NULL
);
3412 LineTo(hdc
, rcClient
.right
-1, rcClient
.bottom
);
3414 /* paint bottom edge */
3415 MoveToEx(hdc
, rcClient
.left
, rcClient
.bottom
-1, NULL
);
3416 LineTo(hdc
, rcClient
.right
, rcClient
.bottom
-1);
3418 DeleteObject(SelectObject(hdc
, holdpen
));
3419 DeleteObject(SelectObject(hdc
, holdbrush
));
3421 default_page_paint_hook(hWnd
, WM_PSD_MARGINRECT
, (WPARAM
)hdc
, (LPARAM
)&rcMargin
, data
);
3423 /* give text a bit of a space from the frame */
3426 rcMargin
.right
-= 2;
3427 rcMargin
.bottom
-= 2;
3429 /* if the space is too small then we make sure to not draw anything */
3430 rcMargin
.left
= min(rcMargin
.left
, rcMargin
.right
);
3431 rcMargin
.top
= min(rcMargin
.top
, rcMargin
.bottom
);
3433 default_page_paint_hook(hWnd
, WM_PSD_GREEKTEXTRECT
, (WPARAM
)hdc
, (LPARAM
)&rcMargin
, data
);
3436 EndPaint(hWnd
, &ps
);
3440 /*******************************************************
3441 * The margin edit controls are subclassed to filter
3442 * anything other than numbers and the decimal separator.
3444 static LRESULT CALLBACK
pagesetup_margin_editproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3448 WCHAR decimal
= get_decimal_sep();
3449 WCHAR wc
= (WCHAR
)wparam
;
3450 if(!isdigitW(wc
) && wc
!= decimal
&& wc
!= VK_BACK
) return 0;
3452 return CallWindowProcW(edit_wndproc
, hwnd
, msg
, wparam
, lparam
);
3455 static void subclass_margin_edits(HWND hDlg
)
3460 for(id
= edt4
; id
<= edt7
; id
++)
3462 old_proc
= (WNDPROC
)SetWindowLongPtrW(GetDlgItem(hDlg
, id
),
3464 (ULONG_PTR
)pagesetup_margin_editproc
);
3465 InterlockedCompareExchangePointer((void**)&edit_wndproc
, old_proc
, NULL
);
3469 /***********************************************************************
3470 * pagesetup_dlg_proc
3472 * Message handler for PageSetupDlg
3474 static INT_PTR CALLBACK
pagesetup_dlg_proc(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3476 pagesetup_data
*data
;
3477 INT_PTR res
= FALSE
;
3480 if (uMsg
== WM_INITDIALOG
) { /*Init dialog*/
3481 data
= (pagesetup_data
*)lParam
;
3484 hDrawWnd
= GetDlgItem(hDlg
, rct1
);
3485 TRACE("set property to %p\n", data
);
3486 SetPropW(hDlg
, pagesetupdlg_prop
, data
);
3487 SetPropW(hDrawWnd
, pagesetupdlg_prop
, data
);
3488 GetWindowRect(hDrawWnd
, &data
->rtDrawRect
); /* Calculating rect in client coordinates where paper draws */
3489 ScreenToClient(hDlg
, (LPPOINT
)&data
->rtDrawRect
);
3490 ScreenToClient(hDlg
, (LPPOINT
)(&data
->rtDrawRect
.right
));
3491 lpfnStaticWndProc
= (WNDPROC
)SetWindowLongPtrW(
3494 (ULONG_PTR
)PRINTDLG_PagePaintProc
);
3496 /* FIXME: Paint hook. Must it be at begin of initialization or at end? */
3498 if (pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPHOOK
)
3500 if (!pagesetup_get_hook(data
, page_setup_hook
)(hDlg
, uMsg
, wParam
,
3501 pagesetup_get_dlg_struct(data
)))
3502 FIXME("Setup page hook failed?\n");
3505 /* if printer button disabled */
3506 if (pagesetup_get_flags(data
) & PSD_DISABLEPRINTER
)
3507 EnableWindow(GetDlgItem(hDlg
, psh3
), FALSE
);
3508 /* if margin edit boxes disabled */
3509 if (pagesetup_get_flags(data
) & PSD_DISABLEMARGINS
)
3511 EnableWindow(GetDlgItem(hDlg
, edt4
), FALSE
);
3512 EnableWindow(GetDlgItem(hDlg
, edt5
), FALSE
);
3513 EnableWindow(GetDlgItem(hDlg
, edt6
), FALSE
);
3514 EnableWindow(GetDlgItem(hDlg
, edt7
), FALSE
);
3517 /* Set orientation radiobuttons properly */
3518 pagesetup_update_orientation_buttons(hDlg
, data
);
3520 /* if orientation disabled */
3521 if (pagesetup_get_flags(data
) & PSD_DISABLEORIENTATION
)
3523 EnableWindow(GetDlgItem(hDlg
,rad1
),FALSE
);
3524 EnableWindow(GetDlgItem(hDlg
,rad2
),FALSE
);
3527 /* We fill them out enabled or not */
3528 if (!(pagesetup_get_flags(data
) & PSD_MARGINS
))
3530 /* default is 1 inch */
3531 LONG size
= thousandths_inch_to_size(data
, 1000);
3532 SetRect(pagesetup_get_margin_rect(data
), size
, size
, size
, size
);
3534 update_margin_edits(hDlg
, data
, 0);
3535 subclass_margin_edits(hDlg
);
3536 set_margin_groupbox_title(hDlg
, data
);
3538 /* if paper disabled */
3539 if (pagesetup_get_flags(data
) & PSD_DISABLEPAPER
)
3541 EnableWindow(GetDlgItem(hDlg
,cmb2
),FALSE
);
3542 EnableWindow(GetDlgItem(hDlg
,cmb3
),FALSE
);
3545 /* filling combos: printer, paper, source. selecting current printer (from DEVMODEA) */
3546 pagesetup_init_combos(hDlg
, data
);
3547 pagesetup_update_papersize(data
);
3548 pagesetup_set_defaultsource(data
, DMBIN_FORMSOURCE
); /* FIXME: This is the auto select bin. Is this correct? */
3550 /* Drawing paper prev */
3551 pagesetup_change_preview(data
);
3554 data
= GetPropW(hDlg
, pagesetupdlg_prop
);
3557 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3560 if (pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPHOOK
)
3562 res
= pagesetup_get_hook(data
, page_setup_hook
)(hDlg
, uMsg
, wParam
, lParam
);
3563 if (res
) return res
;
3568 return pagesetup_wm_command(hDlg
, wParam
, lParam
, data
);
3573 static WCHAR
*get_default_printer(void)
3578 GetDefaultPrinterW(NULL
, &len
);
3581 name
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3582 GetDefaultPrinterW(name
, &len
);
3587 static void pagesetup_dump_dlg_struct(pagesetup_data
*data
)
3589 if(TRACE_ON(commdlg
))
3591 char flagstr
[1000] = "";
3592 const struct pd_flags
*pflag
= psd_flags
;
3593 for( ; pflag
->name
; pflag
++)
3595 if(pagesetup_get_flags(data
) & pflag
->flag
)
3597 strcat(flagstr
, pflag
->name
);
3598 strcat(flagstr
, "|");
3601 TRACE("%s: (%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3602 "hinst %p, flags %08x (%s)\n",
3603 data
->unicode
? "unicode" : "ansi",
3604 data
->u
.dlgw
, data
->u
.dlgw
->hwndOwner
, data
->u
.dlgw
->hDevMode
,
3605 data
->u
.dlgw
->hDevNames
, data
->u
.dlgw
->hInstance
,
3606 pagesetup_get_flags(data
), flagstr
);
3610 static void *pagesetup_get_template(pagesetup_data
*data
)
3613 HGLOBAL tmpl_handle
;
3615 if(pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPTEMPLATEHANDLE
)
3617 tmpl_handle
= data
->u
.dlgw
->hPageSetupTemplate
;
3619 else if(pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPTEMPLATE
)
3622 res
= FindResourceW(data
->u
.dlgw
->hInstance
,
3623 data
->u
.dlgw
->lpPageSetupTemplateName
, MAKEINTRESOURCEW(RT_DIALOG
));
3625 res
= FindResourceA(data
->u
.dlga
->hInstance
,
3626 data
->u
.dlga
->lpPageSetupTemplateName
, MAKEINTRESOURCEA(RT_DIALOG
));
3627 tmpl_handle
= LoadResource(data
->u
.dlgw
->hInstance
, res
);
3631 res
= FindResourceW(COMDLG32_hInstance
, MAKEINTRESOURCEW(PAGESETUPDLGORD
),
3632 MAKEINTRESOURCEW(RT_DIALOG
));
3633 tmpl_handle
= LoadResource(COMDLG32_hInstance
, res
);
3635 return LockResource(tmpl_handle
);
3638 static BOOL
pagesetup_common(pagesetup_data
*data
)
3643 if(!pagesetup_get_dlg_struct(data
))
3645 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
3649 pagesetup_dump_dlg_struct(data
);
3651 if(data
->u
.dlgw
->lStructSize
!= sizeof(PAGESETUPDLGW
))
3653 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
3657 if ((pagesetup_get_flags(data
) & PSD_ENABLEPAGEPAINTHOOK
) &&
3658 (pagesetup_get_hook(data
, page_paint_hook
) == NULL
))
3660 COMDLG32_SetCommDlgExtendedError(CDERR_NOHOOK
);
3664 if(!(pagesetup_get_flags(data
) & (PSD_INTHOUSANDTHSOFINCHES
| PSD_INHUNDREDTHSOFMILLIMETERS
)))
3665 data
->u
.dlgw
->Flags
|= is_default_metric() ?
3666 PSD_INHUNDREDTHSOFMILLIMETERS
: PSD_INTHOUSANDTHSOFINCHES
;
3668 if (!data
->u
.dlgw
->hDevMode
|| !data
->u
.dlgw
->hDevNames
)
3670 WCHAR
*def
= get_default_printer();
3673 if (!(pagesetup_get_flags(data
) & PSD_NOWARNING
))
3676 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEFAULT_PRINTER
, errstr
, 255);
3677 MessageBoxW(data
->u
.dlgw
->hwndOwner
, errstr
, 0, MB_OK
| MB_ICONERROR
);
3679 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
3682 pagesetup_change_printer(def
, data
);
3683 HeapFree(GetProcessHeap(), 0, def
);
3686 if (pagesetup_get_flags(data
) & PSD_RETURNDEFAULT
)
3688 pagesetup_update_papersize(data
);
3692 tmpl
= pagesetup_get_template(data
);
3694 ret
= DialogBoxIndirectParamW(data
->u
.dlgw
->hInstance
, tmpl
,
3695 data
->u
.dlgw
->hwndOwner
,
3696 pagesetup_dlg_proc
, (LPARAM
)data
) > 0;
3700 /***********************************************************************
3701 * PageSetupDlgA (COMDLG32.@)
3703 * Displays the PAGE SETUP dialog box, which enables the user to specify
3704 * specific properties of a printed page such as
3705 * size, source, orientation and the width of the page margins.
3708 * setupdlg [IO] PAGESETUPDLGA struct
3711 * TRUE if the user pressed the OK button
3712 * FALSE if the user cancelled the window or an error occurred
3715 * The values of hDevMode and hDevNames are filled on output and can be
3716 * changed in PAGESETUPDLG when they are passed in PageSetupDlg.
3719 BOOL WINAPI
PageSetupDlgA(LPPAGESETUPDLGA setupdlg
)
3721 pagesetup_data data
;
3723 data
.unicode
= FALSE
;
3724 data
.u
.dlga
= setupdlg
;
3726 return pagesetup_common(&data
);
3729 /***********************************************************************
3730 * PageSetupDlgW (COMDLG32.@)
3732 * See PageSetupDlgA.
3734 BOOL WINAPI
PageSetupDlgW(LPPAGESETUPDLGW setupdlg
)
3736 pagesetup_data data
;
3738 data
.unicode
= TRUE
;
3739 data
.u
.dlgw
= setupdlg
;
3741 return pagesetup_common(&data
);
3744 /***********************************************************************
3745 * PrintDlgExA (COMDLG32.@)
3753 HRESULT WINAPI
PrintDlgExA(LPPRINTDLGEXA lppd
)
3756 FIXME("(%p) stub\n", lppd
);
3757 if ((lppd
== NULL
) || (lppd
->lStructSize
!= sizeof(PRINTDLGEXA
))) {
3758 return E_INVALIDARG
;
3761 if (!IsWindow(lppd
->hwndOwner
)) {
3768 /***********************************************************************
3769 * PrintDlgExW (COMDLG32.@)
3771 * Display the property sheet style PRINT dialog box
3774 * lppd [IO] ptr to PRINTDLGEX struct
3778 * Failure: One of the following COM error codes:
3779 * E_OUTOFMEMORY Insufficient memory.
3780 * E_INVALIDARG One or more arguments are invalid.
3781 * E_POINTER Invalid pointer.
3782 * E_HANDLE Invalid handle.
3783 * E_FAIL Unspecified error.
3786 * This Dialog enables the user to specify specific properties of the print job.
3787 * The property sheet can also have additional application-specific and
3788 * driver-specific property pages.
3791 * Not fully implemented
3794 HRESULT WINAPI
PrintDlgExW(LPPRINTDLGEXW lppd
)
3799 FIXME("(%p) not fully implemented\n", lppd
);
3801 if ((lppd
== NULL
) || (lppd
->lStructSize
!= sizeof(PRINTDLGEXW
))) {
3802 return E_INVALIDARG
;
3805 if (!IsWindow(lppd
->hwndOwner
)) {
3809 if (lppd
->Flags
& PD_RETURNDEFAULT
) {
3810 PRINTER_INFO_2W
*pbuf
;
3811 DRIVER_INFO_2W
*dbuf
;
3813 DWORD needed
= 1024;
3816 if (lppd
->hDevMode
|| lppd
->hDevNames
) {
3817 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
3818 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
3819 return E_INVALIDARG
;
3821 if (!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
3822 WARN("Can't find default printer\n");
3823 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
3827 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
3828 bRet
= GetPrinterW(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
3829 if (!bRet
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
3830 HeapFree(GetProcessHeap(), 0, pbuf
);
3831 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
3832 bRet
= GetPrinterW(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
3835 HeapFree(GetProcessHeap(), 0, pbuf
);
3841 dbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
3842 bRet
= GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
);
3843 if (!bRet
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
3844 HeapFree(GetProcessHeap(), 0, dbuf
);
3845 dbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
3846 bRet
= GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
);
3849 ERR("GetPrinterDriverW failed, last error %d, fix your config for printer %s!\n",
3850 GetLastError(), debugstr_w(pbuf
->pPrinterName
));
3851 HeapFree(GetProcessHeap(), 0, dbuf
);
3852 HeapFree(GetProcessHeap(), 0, pbuf
);
3853 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
3859 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
3863 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
3864 pbuf
->pDevMode
->dmDriverExtra
);
3865 if (lppd
->hDevMode
) {
3866 ptr
= GlobalLock(lppd
->hDevMode
);
3868 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
3869 pbuf
->pDevMode
->dmDriverExtra
);
3870 GlobalUnlock(lppd
->hDevMode
);
3874 HeapFree(GetProcessHeap(), 0, pbuf
);
3875 HeapFree(GetProcessHeap(), 0, dbuf
);