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"
46 WINE_DEFAULT_DEBUG_CHANNEL(commdlg
);
51 /* Yes these constants are the same, but we're just copying win98 */
52 #define UPDOWN_ID 0x270f
53 #define MAX_COPIES 9999
56 static const struct pd_flags psd_flags
[] = {
57 {PSD_MINMARGINS
,"PSD_MINMARGINS"},
58 {PSD_MARGINS
,"PSD_MARGINS"},
59 {PSD_INTHOUSANDTHSOFINCHES
,"PSD_INTHOUSANDTHSOFINCHES"},
60 {PSD_INHUNDREDTHSOFMILLIMETERS
,"PSD_INHUNDREDTHSOFMILLIMETERS"},
61 {PSD_DISABLEMARGINS
,"PSD_DISABLEMARGINS"},
62 {PSD_DISABLEPRINTER
,"PSD_DISABLEPRINTER"},
63 {PSD_NOWARNING
,"PSD_NOWARNING"},
64 {PSD_DISABLEORIENTATION
,"PSD_DISABLEORIENTATION"},
65 {PSD_RETURNDEFAULT
,"PSD_RETURNDEFAULT"},
66 {PSD_DISABLEPAPER
,"PSD_DISABLEPAPER"},
67 {PSD_SHOWHELP
,"PSD_SHOWHELP"},
68 {PSD_ENABLEPAGESETUPHOOK
,"PSD_ENABLEPAGESETUPHOOK"},
69 {PSD_ENABLEPAGESETUPTEMPLATE
,"PSD_ENABLEPAGESETUPTEMPLATE"},
70 {PSD_ENABLEPAGESETUPTEMPLATEHANDLE
,"PSD_ENABLEPAGESETUPTEMPLATEHANDLE"},
71 {PSD_ENABLEPAGEPAINTHOOK
,"PSD_ENABLEPAGEPAINTHOOK"},
72 {PSD_DISABLEPAGEPAINTING
,"PSD_DISABLEPAGEPAINTING"},
76 /* address of wndproc for subclassed Static control */
77 static WNDPROC lpfnStaticWndProc
;
78 static WNDPROC edit_wndproc
;
79 /* the text of the fake document to render for the Page Setup dialog */
80 static WCHAR wszFakeDocumentText
[1024];
81 static const WCHAR pd32_collateW
[] = { 'P', 'D', '3', '2', '_', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
82 static const WCHAR pd32_nocollateW
[] = { 'P', 'D', '3', '2', '_', 'N', 'O', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
83 static const WCHAR pd32_portraitW
[] = { 'P', 'D', '3', '2', '_', 'P', 'O', 'R', 'T', 'R', 'A', 'I', 'T', 0 };
84 static const WCHAR pd32_landscapeW
[] = { 'P', 'D', '3', '2', '_', 'L', 'A', 'N', 'D', 'S', 'C', 'A', 'P', 'E', 0 };
85 static const WCHAR printdlg_prop
[] = {'_','_','W','I','N','E','_','P','R','I','N','T','D','L','G','D','A','T','A',0};
86 static const WCHAR pagesetupdlg_prop
[] = { '_', '_', 'W', 'I', 'N', 'E', '_', 'P', 'A', 'G', 'E',
87 'S', 'E', 'T', 'U', 'P', 'D', 'L', 'G', 'D', 'A', 'T', 'A', 0 };
90 static LPWSTR
strdupW(LPCWSTR p
)
96 len
= (strlenW(p
) + 1) * sizeof(WCHAR
);
97 ret
= HeapAlloc(GetProcessHeap(), 0, len
);
102 /***********************************************************
103 * convert_to_devmodeA
105 * Creates an ansi copy of supplied devmode
107 static DEVMODEA
*convert_to_devmodeA(const DEVMODEW
*dmW
)
112 if (!dmW
) return NULL
;
113 size
= dmW
->dmSize
- CCHDEVICENAME
-
114 ((dmW
->dmSize
> FIELD_OFFSET(DEVMODEW
, dmFormName
)) ? CCHFORMNAME
: 0);
116 dmA
= HeapAlloc(GetProcessHeap(), 0, size
+ dmW
->dmDriverExtra
);
117 if (!dmA
) return NULL
;
119 WideCharToMultiByte(CP_ACP
, 0, dmW
->dmDeviceName
, -1,
120 (LPSTR
)dmA
->dmDeviceName
, CCHDEVICENAME
, NULL
, NULL
);
122 if (FIELD_OFFSET(DEVMODEW
, dmFormName
) >= dmW
->dmSize
)
124 memcpy(&dmA
->dmSpecVersion
, &dmW
->dmSpecVersion
,
125 dmW
->dmSize
- FIELD_OFFSET(DEVMODEW
, dmSpecVersion
));
129 memcpy(&dmA
->dmSpecVersion
, &dmW
->dmSpecVersion
,
130 FIELD_OFFSET(DEVMODEW
, dmFormName
) - FIELD_OFFSET(DEVMODEW
, dmSpecVersion
));
131 WideCharToMultiByte(CP_ACP
, 0, dmW
->dmFormName
, -1,
132 (LPSTR
)dmA
->dmFormName
, CCHFORMNAME
, NULL
, NULL
);
134 memcpy(&dmA
->dmLogPixels
, &dmW
->dmLogPixels
, dmW
->dmSize
- FIELD_OFFSET(DEVMODEW
, dmLogPixels
));
138 memcpy((char *)dmA
+ dmA
->dmSize
, (const char *)dmW
+ dmW
->dmSize
, dmW
->dmDriverExtra
);
142 /***********************************************************************
143 * PRINTDLG_OpenDefaultPrinter
145 * Returns a winspool printer handle to the default printer in *hprn
146 * Caller must call ClosePrinter on the handle
148 * Returns TRUE on success else FALSE
150 BOOL
PRINTDLG_OpenDefaultPrinter(HANDLE
*hprn
)
153 DWORD dwBufLen
= sizeof(buf
) / sizeof(buf
[0]);
155 if(!GetDefaultPrinterW(buf
, &dwBufLen
))
157 res
= OpenPrinterW(buf
, hprn
, NULL
);
159 WARN("Could not open printer %s\n", debugstr_w(buf
));
163 /***********************************************************************
164 * PRINTDLG_SetUpPrinterListCombo
166 * Initializes printer list combox.
167 * hDlg: HWND of dialog
168 * id: Control id of combo
169 * name: Name of printer to select
171 * Initializes combo with list of available printers. Selects printer 'name'
172 * If name is NULL or does not exist select the default printer.
174 * Returns number of printers added to list.
176 INT
PRINTDLG_SetUpPrinterListComboA(HWND hDlg
, UINT id
, LPCSTR name
)
180 LPPRINTER_INFO_2A pi
;
181 EnumPrintersA(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
182 pi
= HeapAlloc(GetProcessHeap(), 0, needed
);
183 EnumPrintersA(PRINTER_ENUM_LOCAL
, NULL
, 2, (LPBYTE
)pi
, needed
, &needed
,
186 SendDlgItemMessageA(hDlg
, id
, CB_RESETCONTENT
, 0, 0);
188 for(i
= 0; i
< num
; i
++) {
189 SendDlgItemMessageA(hDlg
, id
, CB_ADDSTRING
, 0,
190 (LPARAM
)pi
[i
].pPrinterName
);
192 HeapFree(GetProcessHeap(), 0, pi
);
194 (i
= SendDlgItemMessageA(hDlg
, id
, CB_FINDSTRINGEXACT
, -1,
195 (LPARAM
)name
)) == CB_ERR
) {
198 DWORD dwBufLen
= sizeof(buf
);
200 WARN("Can't find %s in printer list so trying to find default\n",
202 if(!GetDefaultPrinterA(buf
, &dwBufLen
))
204 i
= SendDlgItemMessageA(hDlg
, id
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buf
);
206 FIXME("Can't find default printer in printer list\n");
208 SendDlgItemMessageA(hDlg
, id
, CB_SETCURSEL
, i
, 0);
212 static INT
PRINTDLG_SetUpPrinterListComboW(HWND hDlg
, UINT id
, LPCWSTR name
)
216 LPPRINTER_INFO_2W pi
;
217 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
218 pi
= HeapAlloc(GetProcessHeap(), 0, needed
);
219 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, (LPBYTE
)pi
, needed
, &needed
,
222 for(i
= 0; i
< num
; i
++) {
223 SendDlgItemMessageW(hDlg
, id
, CB_ADDSTRING
, 0,
224 (LPARAM
)pi
[i
].pPrinterName
);
226 HeapFree(GetProcessHeap(), 0, pi
);
228 (i
= SendDlgItemMessageW(hDlg
, id
, CB_FINDSTRINGEXACT
, -1,
229 (LPARAM
)name
)) == CB_ERR
) {
231 DWORD dwBufLen
= sizeof(buf
)/sizeof(buf
[0]);
233 WARN("Can't find %s in printer list so trying to find default\n",
235 if(!GetDefaultPrinterW(buf
, &dwBufLen
))
237 i
= SendDlgItemMessageW(hDlg
, id
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buf
);
239 TRACE("Can't find default printer in printer list\n");
241 SendDlgItemMessageW(hDlg
, id
, CB_SETCURSEL
, i
, 0);
245 /***********************************************************************
246 * PRINTDLG_CreateDevNames [internal]
249 * creates a DevNames structure.
251 * (NB. when we handle unicode the offsets will be in wchars).
253 static BOOL
PRINTDLG_CreateDevNames(HGLOBAL
*hmem
, const char* DeviceDriverName
,
254 const char* DeviceName
, const char* OutputPort
)
257 char* pDevNamesSpace
;
259 LPDEVNAMES lpDevNames
;
261 DWORD dwBufLen
= sizeof(buf
);
263 size
= strlen(DeviceDriverName
) + 1
264 + strlen(DeviceName
) + 1
265 + strlen(OutputPort
) + 1
269 *hmem
= GlobalReAlloc(*hmem
, size
, GMEM_MOVEABLE
);
271 *hmem
= GlobalAlloc(GMEM_MOVEABLE
, size
);
275 pDevNamesSpace
= GlobalLock(*hmem
);
276 lpDevNames
= (LPDEVNAMES
) pDevNamesSpace
;
278 pTempPtr
= pDevNamesSpace
+ sizeof(DEVNAMES
);
279 strcpy(pTempPtr
, DeviceDriverName
);
280 lpDevNames
->wDriverOffset
= pTempPtr
- pDevNamesSpace
;
282 pTempPtr
+= strlen(DeviceDriverName
) + 1;
283 strcpy(pTempPtr
, DeviceName
);
284 lpDevNames
->wDeviceOffset
= pTempPtr
- pDevNamesSpace
;
286 pTempPtr
+= strlen(DeviceName
) + 1;
287 strcpy(pTempPtr
, OutputPort
);
288 lpDevNames
->wOutputOffset
= pTempPtr
- pDevNamesSpace
;
290 GetDefaultPrinterA(buf
, &dwBufLen
);
291 lpDevNames
->wDefault
= (strcmp(buf
, DeviceName
) == 0) ? 1 : 0;
296 static BOOL
PRINTDLG_CreateDevNamesW(HGLOBAL
*hmem
, LPCWSTR DeviceDriverName
,
297 LPCWSTR DeviceName
, LPCWSTR OutputPort
)
300 LPWSTR pDevNamesSpace
;
302 LPDEVNAMES lpDevNames
;
304 DWORD dwBufLen
= sizeof(bufW
) / sizeof(WCHAR
);
306 size
= sizeof(WCHAR
)*lstrlenW(DeviceDriverName
) + 2
307 + sizeof(WCHAR
)*lstrlenW(DeviceName
) + 2
308 + sizeof(WCHAR
)*lstrlenW(OutputPort
) + 2
312 *hmem
= GlobalReAlloc(*hmem
, size
, GMEM_MOVEABLE
);
314 *hmem
= GlobalAlloc(GMEM_MOVEABLE
, size
);
318 pDevNamesSpace
= GlobalLock(*hmem
);
319 lpDevNames
= (LPDEVNAMES
) pDevNamesSpace
;
321 pTempPtr
= (LPWSTR
)((LPDEVNAMES
)pDevNamesSpace
+ 1);
322 lstrcpyW(pTempPtr
, DeviceDriverName
);
323 lpDevNames
->wDriverOffset
= pTempPtr
- pDevNamesSpace
;
325 pTempPtr
+= lstrlenW(DeviceDriverName
) + 1;
326 lstrcpyW(pTempPtr
, DeviceName
);
327 lpDevNames
->wDeviceOffset
= pTempPtr
- pDevNamesSpace
;
329 pTempPtr
+= lstrlenW(DeviceName
) + 1;
330 lstrcpyW(pTempPtr
, OutputPort
);
331 lpDevNames
->wOutputOffset
= pTempPtr
- pDevNamesSpace
;
333 GetDefaultPrinterW(bufW
, &dwBufLen
);
334 lpDevNames
->wDefault
= (lstrcmpW(bufW
, DeviceName
) == 0) ? 1 : 0;
339 /***********************************************************************
340 * PRINTDLG_UpdatePrintDlg [internal]
343 * updates the PrintDlg structure for return values.
346 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
347 * TRUE if successful.
349 static BOOL
PRINTDLG_UpdatePrintDlgA(HWND hDlg
,
350 PRINT_PTRA
* PrintStructures
)
352 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
353 PDEVMODEA lpdm
= PrintStructures
->lpDevMode
;
354 LPPRINTER_INFO_2A pi
= PrintStructures
->lpPrinterInfo
;
358 FIXME("No lpdm ptr?\n");
363 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
364 /* check whether nFromPage and nToPage are within range defined by
365 * nMinPage and nMaxPage
367 if (IsDlgButtonChecked(hDlg
, rad3
) == BST_CHECKED
) { /* Pages */
371 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
372 nToPage
= GetDlgItemInt(hDlg
, edt2
, &translated
, FALSE
);
374 /* if no ToPage value is entered, use the FromPage value */
375 if(!translated
) nToPage
= nFromPage
;
377 if (nFromPage
< lppd
->nMinPage
|| nFromPage
> lppd
->nMaxPage
||
378 nToPage
< lppd
->nMinPage
|| nToPage
> lppd
->nMaxPage
) {
379 WCHAR resourcestr
[256];
380 WCHAR resultstr
[256];
381 LoadStringW(COMDLG32_hInstance
, PD32_INVALID_PAGE_RANGE
, resourcestr
, 255);
382 wsprintfW(resultstr
,resourcestr
, lppd
->nMinPage
, lppd
->nMaxPage
);
383 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
, resourcestr
, 255);
384 MessageBoxW(hDlg
, resultstr
, resourcestr
, MB_OK
| MB_ICONWARNING
);
387 lppd
->nFromPage
= nFromPage
;
388 lppd
->nToPage
= nToPage
;
389 lppd
->Flags
|= PD_PAGENUMS
;
392 lppd
->Flags
&= ~PD_PAGENUMS
;
394 if (IsDlgButtonChecked(hDlg
, rad2
) == BST_CHECKED
) /* Selection */
395 lppd
->Flags
|= PD_SELECTION
;
397 lppd
->Flags
&= ~PD_SELECTION
;
399 if (IsDlgButtonChecked(hDlg
, chx1
) == BST_CHECKED
) {/* Print to file */
400 static char file
[] = "FILE:";
401 lppd
->Flags
|= PD_PRINTTOFILE
;
402 pi
->pPortName
= file
;
405 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
) { /* Collate */
406 FIXME("Collate lppd not yet implemented as output\n");
409 /* set PD_Collate and nCopies */
410 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
411 /* The application doesn't support multiple copies or collate...
413 lppd
->Flags
&= ~PD_COLLATE
;
415 /* if the printer driver supports it... store info there
416 * otherwise no collate & multiple copies !
418 if (lpdm
->dmFields
& DM_COLLATE
)
420 (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
);
421 if (lpdm
->dmFields
& DM_COPIES
)
422 lpdm
->u1
.s1
.dmCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
424 /* Application is responsible for multiple copies */
425 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
426 lppd
->Flags
|= PD_COLLATE
;
428 lppd
->Flags
&= ~PD_COLLATE
;
429 lppd
->nCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
430 /* multiple copies already included in the document. Driver must print only one copy */
431 lpdm
->u1
.s1
.dmCopies
= 1;
434 /* Print quality, PrintDlg16 */
435 if(GetDlgItem(hDlg
, cmb1
))
437 HWND hQuality
= GetDlgItem(hDlg
, cmb1
);
438 int Sel
= SendMessageA(hQuality
, CB_GETCURSEL
, 0, 0);
442 LONG dpi
= SendMessageA(hQuality
, CB_GETITEMDATA
, Sel
, 0);
443 lpdm
->dmFields
|= DM_PRINTQUALITY
| DM_YRESOLUTION
;
444 lpdm
->u1
.s1
.dmPrintQuality
= LOWORD(dpi
);
445 lpdm
->dmYResolution
= HIWORD(dpi
);
452 static BOOL
PRINTDLG_UpdatePrintDlgW(HWND hDlg
,
453 PRINT_PTRW
* PrintStructures
)
455 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
456 PDEVMODEW lpdm
= PrintStructures
->lpDevMode
;
457 LPPRINTER_INFO_2W pi
= PrintStructures
->lpPrinterInfo
;
461 FIXME("No lpdm ptr?\n");
466 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
467 /* check whether nFromPage and nToPage are within range defined by
468 * nMinPage and nMaxPage
470 if (IsDlgButtonChecked(hDlg
, rad3
) == BST_CHECKED
) { /* Pages */
474 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
475 nToPage
= GetDlgItemInt(hDlg
, edt2
, &translated
, FALSE
);
477 /* if no ToPage value is entered, use the FromPage value */
478 if(!translated
) nToPage
= nFromPage
;
480 if (nFromPage
< lppd
->nMinPage
|| nFromPage
> lppd
->nMaxPage
||
481 nToPage
< lppd
->nMinPage
|| nToPage
> lppd
->nMaxPage
) {
482 WCHAR resourcestr
[256];
483 WCHAR resultstr
[256];
484 LoadStringW(COMDLG32_hInstance
, PD32_INVALID_PAGE_RANGE
,
486 wsprintfW(resultstr
,resourcestr
, lppd
->nMinPage
, lppd
->nMaxPage
);
487 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
,
489 MessageBoxW(hDlg
, resultstr
, resourcestr
,
490 MB_OK
| MB_ICONWARNING
);
493 lppd
->nFromPage
= nFromPage
;
494 lppd
->nToPage
= nToPage
;
495 lppd
->Flags
|= PD_PAGENUMS
;
498 lppd
->Flags
&= ~PD_PAGENUMS
;
500 if (IsDlgButtonChecked(hDlg
, rad2
) == BST_CHECKED
) /* Selection */
501 lppd
->Flags
|= PD_SELECTION
;
503 lppd
->Flags
&= ~PD_SELECTION
;
505 if (IsDlgButtonChecked(hDlg
, chx1
) == BST_CHECKED
) {/* Print to file */
506 static WCHAR file
[] = {'F','I','L','E',':',0};
507 lppd
->Flags
|= PD_PRINTTOFILE
;
508 pi
->pPortName
= file
;
511 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
) { /* Collate */
512 FIXME("Collate lppd not yet implemented as output\n");
515 /* set PD_Collate and nCopies */
516 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
517 /* The application doesn't support multiple copies or collate...
519 lppd
->Flags
&= ~PD_COLLATE
;
521 /* if the printer driver supports it... store info there
522 * otherwise no collate & multiple copies !
524 if (lpdm
->dmFields
& DM_COLLATE
)
526 (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
);
527 if (lpdm
->dmFields
& DM_COPIES
)
528 lpdm
->u1
.s1
.dmCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
530 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
531 lppd
->Flags
|= PD_COLLATE
;
533 lppd
->Flags
&= ~PD_COLLATE
;
534 lppd
->nCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
540 /************************************************************************
541 * PRINTDLG_SetUpPaperComboBox
543 * Initialize either the papersize or inputslot combos of the Printer Setup
544 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
545 * We also try to re-select the old selection.
547 static BOOL
PRINTDLG_SetUpPaperComboBoxA(HWND hDlg
,
560 int fwCapability_Names
;
561 int fwCapability_Words
;
563 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName
,PortName
,nIDComboBox
);
565 /* query the dialog box for the current selected value */
566 Sel
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETCURSEL
, 0, 0);
568 /* we enter here only if a different printer is selected after
569 * the Print Setup dialog is opened. The current settings are
570 * stored into the newly selected printer.
572 oldWord
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
,
575 if (nIDComboBox
== cmb2
)
576 dm
->u1
.s1
.dmPaperSize
= oldWord
;
578 dm
->u1
.s1
.dmDefaultSource
= oldWord
;
582 /* we enter here only when the Print setup dialog is initially
583 * opened. In this case the settings are restored from when
584 * the dialog was last closed.
587 if (nIDComboBox
== cmb2
)
588 oldWord
= dm
->u1
.s1
.dmPaperSize
;
590 oldWord
= dm
->u1
.s1
.dmDefaultSource
;
594 if (nIDComboBox
== cmb2
) {
596 fwCapability_Names
= DC_PAPERNAMES
;
597 fwCapability_Words
= DC_PAPERS
;
601 fwCapability_Names
= DC_BINNAMES
;
602 fwCapability_Words
= DC_BINS
;
605 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
606 fwCapability_Names
, NULL
, dm
);
607 if (NrOfEntries
== 0)
608 WARN("no Name Entries found!\n");
609 else if (NrOfEntries
< 0)
612 if(DeviceCapabilitiesA(PrinterName
, PortName
, fwCapability_Words
, NULL
, dm
)
614 ERR("Number of caps is different\n");
618 Names
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(char)*NamesSize
);
619 Words
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WORD
));
620 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
621 fwCapability_Names
, Names
, dm
);
622 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
623 fwCapability_Words
, (LPSTR
)Words
, dm
);
625 /* reset any current content in the combobox */
626 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_RESETCONTENT
, 0, 0);
628 /* store new content */
629 for (i
= 0; i
< NrOfEntries
; i
++) {
630 DWORD pos
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_ADDSTRING
, 0,
631 (LPARAM
)(&Names
[i
*NamesSize
]) );
632 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_SETITEMDATA
, pos
,
636 /* Look for old selection - can't do this is previous loop since
637 item order will change as more items are added */
639 for (i
= 0; i
< NrOfEntries
; i
++) {
640 if(SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) ==
646 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_SETCURSEL
, Sel
, 0);
648 HeapFree(GetProcessHeap(),0,Words
);
649 HeapFree(GetProcessHeap(),0,Names
);
653 static BOOL
PRINTDLG_SetUpPaperComboBoxW(HWND hDlg
,
655 const WCHAR
* PrinterName
,
656 const WCHAR
* PortName
,
666 int fwCapability_Names
;
667 int fwCapability_Words
;
669 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName
),debugstr_w(PortName
),nIDComboBox
);
671 /* query the dialog box for the current selected value */
672 Sel
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETCURSEL
, 0, 0);
674 /* we enter here only if a different printer is selected after
675 * the Print Setup dialog is opened. The current settings are
676 * stored into the newly selected printer.
678 oldWord
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETITEMDATA
,
681 if (nIDComboBox
== cmb2
)
682 dm
->u1
.s1
.dmPaperSize
= oldWord
;
684 dm
->u1
.s1
.dmDefaultSource
= oldWord
;
688 /* we enter here only when the Print setup dialog is initially
689 * opened. In this case the settings are restored from when
690 * the dialog was last closed.
693 if (nIDComboBox
== cmb2
)
694 oldWord
= dm
->u1
.s1
.dmPaperSize
;
696 oldWord
= dm
->u1
.s1
.dmDefaultSource
;
700 if (nIDComboBox
== cmb2
) {
702 fwCapability_Names
= DC_PAPERNAMES
;
703 fwCapability_Words
= DC_PAPERS
;
707 fwCapability_Names
= DC_BINNAMES
;
708 fwCapability_Words
= DC_BINS
;
711 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
712 fwCapability_Names
, NULL
, dm
);
713 if (NrOfEntries
== 0)
714 WARN("no Name Entries found!\n");
715 else if (NrOfEntries
< 0)
718 if(DeviceCapabilitiesW(PrinterName
, PortName
, fwCapability_Words
, NULL
, dm
)
720 ERR("Number of caps is different\n");
724 Names
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WCHAR
)*NamesSize
);
725 Words
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WORD
));
726 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
727 fwCapability_Names
, Names
, dm
);
728 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
729 fwCapability_Words
, Words
, dm
);
731 /* reset any current content in the combobox */
732 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_RESETCONTENT
, 0, 0);
734 /* store new content */
735 for (i
= 0; i
< NrOfEntries
; i
++) {
736 DWORD pos
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_ADDSTRING
, 0,
737 (LPARAM
)(&Names
[i
*NamesSize
]) );
738 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_SETITEMDATA
, pos
,
742 /* Look for old selection - can't do this is previous loop since
743 item order will change as more items are added */
745 for (i
= 0; i
< NrOfEntries
; i
++) {
746 if(SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) ==
752 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_SETCURSEL
, Sel
, 0);
754 HeapFree(GetProcessHeap(),0,Words
);
755 HeapFree(GetProcessHeap(),0,Names
);
760 /***********************************************************************
761 * PRINTDLG_UpdatePrinterInfoTexts [internal]
763 static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg
, const PRINTER_INFO_2A
*pi
)
766 char ResourceString
[256];
772 /* add all status messages */
773 for (i
= 0; i
< 25; i
++) {
774 if (pi
->Status
& (1<<i
)) {
775 LoadStringA(COMDLG32_hInstance
, PD32_PRINTER_STATUS_PAUSED
+i
,
776 ResourceString
, 255);
777 strcat(StatusMsg
,ResourceString
);
781 /* FIXME: status==ready must only be appended if really so.
782 but how to detect? */
783 LoadStringA(COMDLG32_hInstance
, PD32_PRINTER_STATUS_READY
,
784 ResourceString
, 255);
785 strcat(StatusMsg
,ResourceString
);
786 SetDlgItemTextA(hDlg
, stc12
, StatusMsg
);
788 /* set all other printer info texts */
789 SetDlgItemTextA(hDlg
, stc11
, pi
->pDriverName
);
791 if (pi
->pLocation
!= NULL
&& pi
->pLocation
[0] != '\0')
792 SetDlgItemTextA(hDlg
, stc14
, pi
->pLocation
);
794 SetDlgItemTextA(hDlg
, stc14
, pi
->pPortName
);
795 SetDlgItemTextA(hDlg
, stc13
, pi
->pComment
? pi
->pComment
: "");
799 static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg
, const PRINTER_INFO_2W
*pi
)
801 WCHAR StatusMsg
[256];
802 WCHAR ResourceString
[256];
803 static const WCHAR emptyW
[] = {0};
809 /* add all status messages */
810 for (i
= 0; i
< 25; i
++) {
811 if (pi
->Status
& (1<<i
)) {
812 LoadStringW(COMDLG32_hInstance
, PD32_PRINTER_STATUS_PAUSED
+i
,
813 ResourceString
, 255);
814 lstrcatW(StatusMsg
,ResourceString
);
818 /* FIXME: status==ready must only be appended if really so.
819 but how to detect? */
820 LoadStringW(COMDLG32_hInstance
, PD32_PRINTER_STATUS_READY
,
821 ResourceString
, 255);
822 lstrcatW(StatusMsg
,ResourceString
);
823 SetDlgItemTextW(hDlg
, stc12
, StatusMsg
);
825 /* set all other printer info texts */
826 SetDlgItemTextW(hDlg
, stc11
, pi
->pDriverName
);
827 if (pi
->pLocation
!= NULL
&& pi
->pLocation
[0] != '\0')
828 SetDlgItemTextW(hDlg
, stc14
, pi
->pLocation
);
830 SetDlgItemTextW(hDlg
, stc14
, pi
->pPortName
);
831 SetDlgItemTextW(hDlg
, stc13
, pi
->pComment
? pi
->pComment
: emptyW
);
835 /*******************************************************************
837 * PRINTDLG_ChangePrinter
840 BOOL
PRINTDLG_ChangePrinterA(HWND hDlg
, char *name
,
841 PRINT_PTRA
*PrintStructures
)
843 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
844 LPDEVMODEA lpdm
= NULL
;
849 HeapFree(GetProcessHeap(),0, PrintStructures
->lpPrinterInfo
);
850 HeapFree(GetProcessHeap(),0, PrintStructures
->lpDriverInfo
);
851 if(!OpenPrinterA(name
, &hprn
, NULL
)) {
852 ERR("Can't open printer %s\n", name
);
855 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
856 PrintStructures
->lpPrinterInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
857 GetPrinterA(hprn
, 2, (LPBYTE
)PrintStructures
->lpPrinterInfo
, needed
,
859 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
860 PrintStructures
->lpDriverInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
861 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)PrintStructures
->lpDriverInfo
,
863 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures
->lpPrinterInfo
->pPrinterName
);
868 PRINTDLG_UpdatePrinterInfoTextsA(hDlg
, PrintStructures
->lpPrinterInfo
);
870 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
871 PrintStructures
->lpDevMode
= NULL
;
873 dmSize
= DocumentPropertiesA(0, 0, name
, NULL
, NULL
, 0);
875 ERR("DocumentProperties fails on %s\n", debugstr_a(name
));
878 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(), 0, dmSize
);
879 dmSize
= DocumentPropertiesA(0, 0, name
, PrintStructures
->lpDevMode
, NULL
,
881 if(lppd
->hDevMode
&& (lpdm
= GlobalLock(lppd
->hDevMode
)) &&
882 !lstrcmpA( (LPSTR
) lpdm
->dmDeviceName
,
883 (LPSTR
) PrintStructures
->lpDevMode
->dmDeviceName
)) {
884 /* Supplied devicemode matches current printer so try to use it */
885 DocumentPropertiesA(0, 0, name
, PrintStructures
->lpDevMode
, lpdm
,
886 DM_OUT_BUFFER
| DM_IN_BUFFER
);
889 GlobalUnlock(lppd
->hDevMode
);
891 lpdm
= PrintStructures
->lpDevMode
; /* use this as a shortcut */
893 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
894 /* Print range (All/Range/Selection) */
895 if(lppd
->nFromPage
!= 0xffff)
896 SetDlgItemInt(hDlg
, edt1
, lppd
->nFromPage
, FALSE
);
897 if(lppd
->nToPage
!= 0xffff)
898 SetDlgItemInt(hDlg
, edt2
, lppd
->nToPage
, FALSE
);
900 CheckRadioButton(hDlg
, rad1
, rad3
, rad1
); /* default */
901 if (lppd
->Flags
& PD_NOSELECTION
)
902 EnableWindow(GetDlgItem(hDlg
, rad2
), FALSE
);
904 if (lppd
->Flags
& PD_SELECTION
)
905 CheckRadioButton(hDlg
, rad1
, rad3
, rad2
);
906 if (lppd
->Flags
& PD_NOPAGENUMS
) {
907 EnableWindow(GetDlgItem(hDlg
, rad3
), FALSE
);
908 EnableWindow(GetDlgItem(hDlg
, stc2
),FALSE
);
909 EnableWindow(GetDlgItem(hDlg
, edt1
), FALSE
);
910 EnableWindow(GetDlgItem(hDlg
, stc3
),FALSE
);
911 EnableWindow(GetDlgItem(hDlg
, edt2
), FALSE
);
913 if (lppd
->Flags
& PD_PAGENUMS
)
914 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
919 * FIXME: The ico3 is not displayed for some reason. I don't know why.
921 if (lppd
->Flags
& PD_COLLATE
) {
922 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
923 (LPARAM
)PrintStructures
->hCollateIcon
);
924 CheckDlgButton(hDlg
, chx2
, 1);
926 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
927 (LPARAM
)PrintStructures
->hNoCollateIcon
);
928 CheckDlgButton(hDlg
, chx2
, 0);
931 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
932 /* if printer doesn't support it: no Collate */
933 if (!(lpdm
->dmFields
& DM_COLLATE
)) {
934 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
935 EnableWindow(GetDlgItem(hDlg
, ico3
), FALSE
);
942 if (lppd
->hDevMode
== 0)
943 copies
= lppd
->nCopies
;
945 copies
= lpdm
->u1
.s1
.dmCopies
;
946 if(copies
== 0) copies
= 1;
947 else if(copies
< 0) copies
= MAX_COPIES
;
948 SetDlgItemInt(hDlg
, edt3
, copies
, FALSE
);
951 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
952 /* if printer doesn't support it: no nCopies */
953 if (!(lpdm
->dmFields
& DM_COPIES
)) {
954 EnableWindow(GetDlgItem(hDlg
, edt3
), FALSE
);
955 EnableWindow(GetDlgItem(hDlg
, stc5
), FALSE
);
960 CheckDlgButton(hDlg
, chx1
, (lppd
->Flags
& PD_PRINTTOFILE
) ? 1 : 0);
961 if (lppd
->Flags
& PD_DISABLEPRINTTOFILE
)
962 EnableWindow(GetDlgItem(hDlg
, chx1
), FALSE
);
963 if (lppd
->Flags
& PD_HIDEPRINTTOFILE
)
964 ShowWindow(GetDlgItem(hDlg
, chx1
), SW_HIDE
);
966 /* Fill print quality combo, PrintDlg16 */
967 if(GetDlgItem(hDlg
, cmb1
))
969 DWORD numResolutions
= DeviceCapabilitiesA(PrintStructures
->lpPrinterInfo
->pPrinterName
,
970 PrintStructures
->lpPrinterInfo
->pPortName
,
971 DC_ENUMRESOLUTIONS
, NULL
, lpdm
);
973 if(numResolutions
!= -1)
975 HWND hQuality
= GetDlgItem(hDlg
, cmb1
);
980 HDC hPrinterDC
= CreateDCA(PrintStructures
->lpPrinterInfo
->pDriverName
,
981 PrintStructures
->lpPrinterInfo
->pPrinterName
,
984 Resolutions
= HeapAlloc(GetProcessHeap(), 0, numResolutions
*sizeof(LONG
)*2);
985 DeviceCapabilitiesA(PrintStructures
->lpPrinterInfo
->pPrinterName
,
986 PrintStructures
->lpPrinterInfo
->pPortName
,
987 DC_ENUMRESOLUTIONS
, (LPSTR
)Resolutions
, lpdm
);
989 dpiX
= GetDeviceCaps(hPrinterDC
, LOGPIXELSX
);
990 dpiY
= GetDeviceCaps(hPrinterDC
, LOGPIXELSY
);
991 DeleteDC(hPrinterDC
);
993 SendMessageA(hQuality
, CB_RESETCONTENT
, 0, 0);
994 for(i
= 0; i
< (numResolutions
* 2); i
+= 2)
996 BOOL IsDefault
= FALSE
;
999 if(Resolutions
[i
] == Resolutions
[i
+1])
1001 if(dpiX
== Resolutions
[i
])
1003 sprintf(buf
, "%d dpi", Resolutions
[i
]);
1006 if(dpiX
== Resolutions
[i
] && dpiY
== Resolutions
[i
+1])
1008 sprintf(buf
, "%d dpi x %d dpi", Resolutions
[i
], Resolutions
[i
+1]);
1011 Index
= SendMessageA(hQuality
, CB_ADDSTRING
, 0, (LPARAM
)buf
);
1014 SendMessageA(hQuality
, CB_SETCURSEL
, Index
, 0);
1016 SendMessageA(hQuality
, CB_SETITEMDATA
, Index
, MAKELONG(dpiX
,dpiY
));
1018 HeapFree(GetProcessHeap(), 0, Resolutions
);
1021 } else { /* PD_PRINTSETUP */
1022 BOOL bPortrait
= (lpdm
->u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
);
1024 PRINTDLG_SetUpPaperComboBoxA(hDlg
, cmb2
,
1025 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1026 PrintStructures
->lpPrinterInfo
->pPortName
,
1028 PRINTDLG_SetUpPaperComboBoxA(hDlg
, cmb3
,
1029 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1030 PrintStructures
->lpPrinterInfo
->pPortName
,
1032 CheckRadioButton(hDlg
, rad1
, rad2
, bPortrait
? rad1
: rad2
);
1033 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1034 (LPARAM
)(bPortrait
? PrintStructures
->hPortraitIcon
:
1035 PrintStructures
->hLandscapeIcon
));
1040 if ((lppd
->Flags
& PD_SHOWHELP
)==0) {
1041 /* hide if PD_SHOWHELP not specified */
1042 ShowWindow(GetDlgItem(hDlg
, pshHelp
), SW_HIDE
);
1047 static BOOL
PRINTDLG_ChangePrinterW(HWND hDlg
, WCHAR
*name
,
1048 PRINT_PTRW
*PrintStructures
)
1050 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1051 LPDEVMODEW lpdm
= NULL
;
1056 HeapFree(GetProcessHeap(),0, PrintStructures
->lpPrinterInfo
);
1057 HeapFree(GetProcessHeap(),0, PrintStructures
->lpDriverInfo
);
1058 if(!OpenPrinterW(name
, &hprn
, NULL
)) {
1059 ERR("Can't open printer %s\n", debugstr_w(name
));
1062 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
1063 PrintStructures
->lpPrinterInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
1064 GetPrinterW(hprn
, 2, (LPBYTE
)PrintStructures
->lpPrinterInfo
, needed
,
1066 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
1067 PrintStructures
->lpDriverInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
1068 if (!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)PrintStructures
->lpDriverInfo
,
1070 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures
->lpPrinterInfo
->pPrinterName
));
1075 PRINTDLG_UpdatePrinterInfoTextsW(hDlg
, PrintStructures
->lpPrinterInfo
);
1077 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
1078 PrintStructures
->lpDevMode
= NULL
;
1080 dmSize
= DocumentPropertiesW(0, 0, name
, NULL
, NULL
, 0);
1082 ERR("DocumentProperties fails on %s\n", debugstr_w(name
));
1085 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(), 0, dmSize
);
1086 dmSize
= DocumentPropertiesW(0, 0, name
, PrintStructures
->lpDevMode
, NULL
,
1088 if(lppd
->hDevMode
&& (lpdm
= GlobalLock(lppd
->hDevMode
)) &&
1089 !lstrcmpW(lpdm
->dmDeviceName
,
1090 PrintStructures
->lpDevMode
->dmDeviceName
)) {
1091 /* Supplied devicemode matches current printer so try to use it */
1092 DocumentPropertiesW(0, 0, name
, PrintStructures
->lpDevMode
, lpdm
,
1093 DM_OUT_BUFFER
| DM_IN_BUFFER
);
1096 GlobalUnlock(lppd
->hDevMode
);
1098 lpdm
= PrintStructures
->lpDevMode
; /* use this as a shortcut */
1100 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
1101 /* Print range (All/Range/Selection) */
1102 if(lppd
->nFromPage
!= 0xffff)
1103 SetDlgItemInt(hDlg
, edt1
, lppd
->nFromPage
, FALSE
);
1104 if(lppd
->nToPage
!= 0xffff)
1105 SetDlgItemInt(hDlg
, edt2
, lppd
->nToPage
, FALSE
);
1107 CheckRadioButton(hDlg
, rad1
, rad3
, rad1
); /* default */
1108 if (lppd
->Flags
& PD_NOSELECTION
)
1109 EnableWindow(GetDlgItem(hDlg
, rad2
), FALSE
);
1111 if (lppd
->Flags
& PD_SELECTION
)
1112 CheckRadioButton(hDlg
, rad1
, rad3
, rad2
);
1113 if (lppd
->Flags
& PD_NOPAGENUMS
) {
1114 EnableWindow(GetDlgItem(hDlg
, rad3
), FALSE
);
1115 EnableWindow(GetDlgItem(hDlg
, stc2
),FALSE
);
1116 EnableWindow(GetDlgItem(hDlg
, edt1
), FALSE
);
1117 EnableWindow(GetDlgItem(hDlg
, stc3
),FALSE
);
1118 EnableWindow(GetDlgItem(hDlg
, edt2
), FALSE
);
1120 if (lppd
->Flags
& PD_PAGENUMS
)
1121 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1126 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1128 if (lppd
->Flags
& PD_COLLATE
) {
1129 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1130 (LPARAM
)PrintStructures
->hCollateIcon
);
1131 CheckDlgButton(hDlg
, chx2
, 1);
1133 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1134 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1135 CheckDlgButton(hDlg
, chx2
, 0);
1138 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1139 /* if printer doesn't support it: no Collate */
1140 if (!(lpdm
->dmFields
& DM_COLLATE
)) {
1141 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1142 EnableWindow(GetDlgItem(hDlg
, ico3
), FALSE
);
1149 if (lppd
->hDevMode
== 0)
1150 copies
= lppd
->nCopies
;
1152 copies
= lpdm
->u1
.s1
.dmCopies
;
1153 if(copies
== 0) copies
= 1;
1154 else if(copies
< 0) copies
= MAX_COPIES
;
1155 SetDlgItemInt(hDlg
, edt3
, copies
, FALSE
);
1158 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1159 /* if printer doesn't support it: no nCopies */
1160 if (!(lpdm
->dmFields
& DM_COPIES
)) {
1161 EnableWindow(GetDlgItem(hDlg
, edt3
), FALSE
);
1162 EnableWindow(GetDlgItem(hDlg
, stc5
), FALSE
);
1167 CheckDlgButton(hDlg
, chx1
, (lppd
->Flags
& PD_PRINTTOFILE
) ? 1 : 0);
1168 if (lppd
->Flags
& PD_DISABLEPRINTTOFILE
)
1169 EnableWindow(GetDlgItem(hDlg
, chx1
), FALSE
);
1170 if (lppd
->Flags
& PD_HIDEPRINTTOFILE
)
1171 ShowWindow(GetDlgItem(hDlg
, chx1
), SW_HIDE
);
1173 } else { /* PD_PRINTSETUP */
1174 BOOL bPortrait
= (lpdm
->u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
);
1176 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb2
,
1177 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1178 PrintStructures
->lpPrinterInfo
->pPortName
,
1180 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb3
,
1181 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1182 PrintStructures
->lpPrinterInfo
->pPortName
,
1184 CheckRadioButton(hDlg
, rad1
, rad2
, bPortrait
? rad1
: rad2
);
1185 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1186 (LPARAM
)(bPortrait
? PrintStructures
->hPortraitIcon
:
1187 PrintStructures
->hLandscapeIcon
));
1192 if ((lppd
->Flags
& PD_SHOWHELP
)==0) {
1193 /* hide if PD_SHOWHELP not specified */
1194 ShowWindow(GetDlgItem(hDlg
, pshHelp
), SW_HIDE
);
1199 /***********************************************************************
1200 * check_printer_setup [internal]
1202 static LRESULT
check_printer_setup(HWND hDlg
)
1205 WCHAR resourcestr
[256],resultstr
[256];
1207 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
1210 EnumPrintersW(PRINTER_ENUM_CONNECTIONS
, NULL
, 2, NULL
, 0, &needed
, &num
);
1216 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEVICES
,resultstr
, 255);
1217 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
,resourcestr
, 255);
1218 MessageBoxW(hDlg
, resultstr
, resourcestr
,MB_OK
| MB_ICONWARNING
);
1223 /***********************************************************************
1224 * PRINTDLG_WMInitDialog [internal]
1226 static LRESULT
PRINTDLG_WMInitDialog(HWND hDlg
, WPARAM wParam
,
1227 PRINT_PTRA
* PrintStructures
)
1229 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1233 UINT comboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1235 /* load Collate ICONs */
1236 /* We load these with LoadImage because they are not a standard
1237 size and we don't want them rescaled */
1238 PrintStructures
->hCollateIcon
=
1239 LoadImageA(COMDLG32_hInstance
, "PD32_COLLATE", IMAGE_ICON
, 0, 0, 0);
1240 PrintStructures
->hNoCollateIcon
=
1241 LoadImageA(COMDLG32_hInstance
, "PD32_NOCOLLATE", IMAGE_ICON
, 0, 0, 0);
1243 /* These can be done with LoadIcon */
1244 PrintStructures
->hPortraitIcon
=
1245 LoadIconA(COMDLG32_hInstance
, "PD32_PORTRAIT");
1246 PrintStructures
->hLandscapeIcon
=
1247 LoadIconA(COMDLG32_hInstance
, "PD32_LANDSCAPE");
1249 /* display the collate/no_collate icon */
1250 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1251 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1253 if(PrintStructures
->hCollateIcon
== 0 ||
1254 PrintStructures
->hNoCollateIcon
== 0 ||
1255 PrintStructures
->hPortraitIcon
== 0 ||
1256 PrintStructures
->hLandscapeIcon
== 0) {
1257 ERR("no icon in resourcefile\n");
1258 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1259 EndDialog(hDlg
, FALSE
);
1263 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1264 * must be registered and the Help button must be shown.
1266 if (lppd
->Flags
& PD_SHOWHELP
) {
1267 if((PrintStructures
->HelpMessageID
=
1268 RegisterWindowMessageA(HELPMSGSTRINGA
)) == 0) {
1269 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL
);
1273 PrintStructures
->HelpMessageID
= 0;
1275 if(!(lppd
->Flags
&PD_PRINTSETUP
)) {
1276 PrintStructures
->hwndUpDown
=
1277 CreateUpDownControl(WS_CHILD
| WS_VISIBLE
| WS_BORDER
|
1278 UDS_NOTHOUSANDS
| UDS_ARROWKEYS
|
1279 UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, 0, 0, 0, 0,
1280 hDlg
, UPDOWN_ID
, COMDLG32_hInstance
,
1281 GetDlgItem(hDlg
, edt3
), MAX_COPIES
, 1, 1);
1284 /* FIXME: I allow more freedom than either Win95 or WinNT,
1285 * which do not agree to what errors should be thrown or not
1286 * in case nToPage or nFromPage is out-of-range.
1288 if (lppd
->nMaxPage
< lppd
->nMinPage
)
1289 lppd
->nMaxPage
= lppd
->nMinPage
;
1290 if (lppd
->nMinPage
== lppd
->nMaxPage
)
1291 lppd
->Flags
|= PD_NOPAGENUMS
;
1292 if (lppd
->nToPage
< lppd
->nMinPage
)
1293 lppd
->nToPage
= lppd
->nMinPage
;
1294 if (lppd
->nToPage
> lppd
->nMaxPage
)
1295 lppd
->nToPage
= lppd
->nMaxPage
;
1296 if (lppd
->nFromPage
< lppd
->nMinPage
)
1297 lppd
->nFromPage
= lppd
->nMinPage
;
1298 if (lppd
->nFromPage
> lppd
->nMaxPage
)
1299 lppd
->nFromPage
= lppd
->nMaxPage
;
1301 /* if we have the combo box, fill it */
1302 if (GetDlgItem(hDlg
,comboID
)) {
1305 pdn
= GlobalLock(lppd
->hDevNames
);
1306 pdm
= GlobalLock(lppd
->hDevMode
);
1308 name
= (char*)pdn
+ pdn
->wDeviceOffset
;
1310 name
= (char*)pdm
->dmDeviceName
;
1311 PRINTDLG_SetUpPrinterListComboA(hDlg
, comboID
, name
);
1312 if(pdm
) GlobalUnlock(lppd
->hDevMode
);
1313 if(pdn
) GlobalUnlock(lppd
->hDevNames
);
1315 /* Now find selected printer and update rest of dlg */
1316 name
= HeapAlloc(GetProcessHeap(),0,256);
1317 if (GetDlgItemTextA(hDlg
, comboID
, name
, 255))
1318 PRINTDLG_ChangePrinterA(hDlg
, name
, PrintStructures
);
1319 HeapFree(GetProcessHeap(),0,name
);
1321 /* else use default printer */
1323 DWORD dwBufLen
= sizeof(name
);
1324 BOOL ret
= GetDefaultPrinterA(name
, &dwBufLen
);
1327 PRINTDLG_ChangePrinterA(hDlg
, name
, PrintStructures
);
1329 FIXME("No default printer found, expect problems!\n");
1334 static LRESULT
PRINTDLG_WMInitDialogW(HWND hDlg
, WPARAM wParam
,
1335 PRINT_PTRW
* PrintStructures
)
1337 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1341 UINT comboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1343 /* load Collate ICONs */
1344 /* We load these with LoadImage because they are not a standard
1345 size and we don't want them rescaled */
1346 PrintStructures
->hCollateIcon
=
1347 LoadImageW(COMDLG32_hInstance
, pd32_collateW
, IMAGE_ICON
, 0, 0, 0);
1348 PrintStructures
->hNoCollateIcon
=
1349 LoadImageW(COMDLG32_hInstance
, pd32_nocollateW
, IMAGE_ICON
, 0, 0, 0);
1351 /* These can be done with LoadIcon */
1352 PrintStructures
->hPortraitIcon
=
1353 LoadIconW(COMDLG32_hInstance
, pd32_portraitW
);
1354 PrintStructures
->hLandscapeIcon
=
1355 LoadIconW(COMDLG32_hInstance
, pd32_landscapeW
);
1357 /* display the collate/no_collate icon */
1358 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1359 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1361 if(PrintStructures
->hCollateIcon
== 0 ||
1362 PrintStructures
->hNoCollateIcon
== 0 ||
1363 PrintStructures
->hPortraitIcon
== 0 ||
1364 PrintStructures
->hLandscapeIcon
== 0) {
1365 ERR("no icon in resourcefile\n");
1366 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1367 EndDialog(hDlg
, FALSE
);
1371 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1372 * must be registered and the Help button must be shown.
1374 if (lppd
->Flags
& PD_SHOWHELP
) {
1375 if((PrintStructures
->HelpMessageID
=
1376 RegisterWindowMessageW(HELPMSGSTRINGW
)) == 0) {
1377 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL
);
1381 PrintStructures
->HelpMessageID
= 0;
1383 if(!(lppd
->Flags
&PD_PRINTSETUP
)) {
1384 PrintStructures
->hwndUpDown
=
1385 CreateUpDownControl(WS_CHILD
| WS_VISIBLE
| WS_BORDER
|
1386 UDS_NOTHOUSANDS
| UDS_ARROWKEYS
|
1387 UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, 0, 0, 0, 0,
1388 hDlg
, UPDOWN_ID
, COMDLG32_hInstance
,
1389 GetDlgItem(hDlg
, edt3
), MAX_COPIES
, 1, 1);
1392 /* FIXME: I allow more freedom than either Win95 or WinNT,
1393 * which do not agree to what errors should be thrown or not
1394 * in case nToPage or nFromPage is out-of-range.
1396 if (lppd
->nMaxPage
< lppd
->nMinPage
)
1397 lppd
->nMaxPage
= lppd
->nMinPage
;
1398 if (lppd
->nMinPage
== lppd
->nMaxPage
)
1399 lppd
->Flags
|= PD_NOPAGENUMS
;
1400 if (lppd
->nToPage
< lppd
->nMinPage
)
1401 lppd
->nToPage
= lppd
->nMinPage
;
1402 if (lppd
->nToPage
> lppd
->nMaxPage
)
1403 lppd
->nToPage
= lppd
->nMaxPage
;
1404 if (lppd
->nFromPage
< lppd
->nMinPage
)
1405 lppd
->nFromPage
= lppd
->nMinPage
;
1406 if (lppd
->nFromPage
> lppd
->nMaxPage
)
1407 lppd
->nFromPage
= lppd
->nMaxPage
;
1409 /* if we have the combo box, fill it */
1410 if (GetDlgItem(hDlg
,comboID
)) {
1413 pdn
= GlobalLock(lppd
->hDevNames
);
1414 pdm
= GlobalLock(lppd
->hDevMode
);
1416 name
= (WCHAR
*)pdn
+ pdn
->wDeviceOffset
;
1418 name
= pdm
->dmDeviceName
;
1419 PRINTDLG_SetUpPrinterListComboW(hDlg
, comboID
, name
);
1420 if(pdm
) GlobalUnlock(lppd
->hDevMode
);
1421 if(pdn
) GlobalUnlock(lppd
->hDevNames
);
1423 /* Now find selected printer and update rest of dlg */
1424 /* ansi is ok here */
1425 name
= HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR
));
1426 if (GetDlgItemTextW(hDlg
, comboID
, name
, 255))
1427 PRINTDLG_ChangePrinterW(hDlg
, name
, PrintStructures
);
1428 HeapFree(GetProcessHeap(),0,name
);
1430 /* else use default printer */
1432 DWORD dwBufLen
= sizeof(name
) / sizeof(WCHAR
);
1433 BOOL ret
= GetDefaultPrinterW(name
, &dwBufLen
);
1436 PRINTDLG_ChangePrinterW(hDlg
, name
, PrintStructures
);
1438 FIXME("No default printer found, expect problems!\n");
1443 /***********************************************************************
1444 * PRINTDLG_WMCommand [internal]
1446 LRESULT
PRINTDLG_WMCommandA(HWND hDlg
, WPARAM wParam
,
1447 LPARAM lParam
, PRINT_PTRA
* PrintStructures
)
1449 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1450 UINT PrinterComboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1451 LPDEVMODEA lpdm
= PrintStructures
->lpDevMode
;
1453 switch (LOWORD(wParam
)) {
1455 TRACE(" OK button was hit\n");
1456 if (!PRINTDLG_UpdatePrintDlgA(hDlg
, PrintStructures
)) {
1457 FIXME("Update printdlg was not successful!\n");
1460 EndDialog(hDlg
, TRUE
);
1464 TRACE(" CANCEL button was hit\n");
1465 EndDialog(hDlg
, FALSE
);
1469 TRACE(" HELP button was hit\n");
1470 SendMessageA(lppd
->hwndOwner
, PrintStructures
->HelpMessageID
,
1471 (WPARAM
) hDlg
, (LPARAM
) lppd
);
1474 case chx2
: /* collate pages checkbox */
1475 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
1476 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1477 (LPARAM
)PrintStructures
->hCollateIcon
);
1479 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1480 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1482 case edt1
: /* from page nr editbox */
1483 case edt2
: /* to page nr editbox */
1484 if (HIWORD(wParam
)==EN_CHANGE
) {
1487 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
1488 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
1489 if (nFromPage
!= lppd
->nFromPage
|| nToPage
!= lppd
->nToPage
)
1490 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1495 if(HIWORD(wParam
) == EN_CHANGE
) {
1496 INT copies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
1498 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1500 EnableWindow(GetDlgItem(hDlg
, chx2
), TRUE
);
1505 case psh1
: /* Print Setup */
1509 if (!PrintStructures
->dlg
.lpPrintDlg16
) {
1510 FIXME("The 32bit print dialog does not have this button!?\n");
1514 memcpy(&pdlg
,PrintStructures
->dlg
.lpPrintDlg16
,sizeof(pdlg
));
1515 pdlg
.Flags
|= PD_PRINTSETUP
;
1516 pdlg
.hwndOwner
= HWND_16(hDlg
);
1517 if (!PrintDlg16(&pdlg
))
1522 case psh2
: /* Properties button */
1525 char PrinterName
[256];
1527 GetDlgItemTextA(hDlg
, PrinterComboID
, PrinterName
, 255);
1528 if (!OpenPrinterA(PrinterName
, &hPrinter
, NULL
)) {
1529 FIXME(" Call to OpenPrinter did not succeed!\n");
1532 DocumentPropertiesA(hDlg
, hPrinter
, PrinterName
,
1533 PrintStructures
->lpDevMode
,
1534 PrintStructures
->lpDevMode
,
1535 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
1536 ClosePrinter(hPrinter
);
1540 case rad1
: /* Paperorientation */
1541 if (lppd
->Flags
& PD_PRINTSETUP
)
1543 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1544 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1545 (LPARAM
)(PrintStructures
->hPortraitIcon
));
1549 case rad2
: /* Paperorientation */
1550 if (lppd
->Flags
& PD_PRINTSETUP
)
1552 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1553 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1554 (LPARAM
)(PrintStructures
->hLandscapeIcon
));
1558 case cmb1
: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT16 */
1559 if (PrinterComboID
!= LOWORD(wParam
)) {
1563 case cmb4
: /* Printer combobox */
1564 if (HIWORD(wParam
)==CBN_SELCHANGE
) {
1565 char PrinterName
[256];
1566 GetDlgItemTextA(hDlg
, LOWORD(wParam
), PrinterName
, 255);
1567 PRINTDLG_ChangePrinterA(hDlg
, PrinterName
, PrintStructures
);
1571 case cmb2
: /* Papersize */
1573 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
1575 lpdm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageA(hDlg
, cmb2
,
1581 case cmb3
: /* Bin */
1583 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
1585 lpdm
->u1
.s1
.dmDefaultSource
= SendDlgItemMessageA(hDlg
, cmb3
,
1586 CB_GETITEMDATA
, Sel
,
1591 if(lppd
->Flags
& PD_PRINTSETUP
) {
1592 switch (LOWORD(wParam
)) {
1593 case rad1
: /* orientation */
1595 if (IsDlgButtonChecked(hDlg
, rad1
) == BST_CHECKED
) {
1596 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_PORTRAIT
) {
1597 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1598 SendDlgItemMessageA(hDlg
, stc10
, STM_SETIMAGE
,
1600 (LPARAM
)PrintStructures
->hPortraitIcon
);
1601 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
,
1603 (LPARAM
)PrintStructures
->hPortraitIcon
);
1606 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_LANDSCAPE
) {
1607 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1608 SendDlgItemMessageA(hDlg
, stc10
, STM_SETIMAGE
,
1610 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1611 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
,
1613 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1622 static LRESULT
PRINTDLG_WMCommandW(HWND hDlg
, WPARAM wParam
,
1623 LPARAM lParam
, PRINT_PTRW
* PrintStructures
)
1625 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1626 UINT PrinterComboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1627 LPDEVMODEW lpdm
= PrintStructures
->lpDevMode
;
1629 switch (LOWORD(wParam
)) {
1631 TRACE(" OK button was hit\n");
1632 if (!PRINTDLG_UpdatePrintDlgW(hDlg
, PrintStructures
)) {
1633 FIXME("Update printdlg was not successful!\n");
1636 EndDialog(hDlg
, TRUE
);
1640 TRACE(" CANCEL button was hit\n");
1641 EndDialog(hDlg
, FALSE
);
1645 TRACE(" HELP button was hit\n");
1646 SendMessageW(lppd
->hwndOwner
, PrintStructures
->HelpMessageID
,
1647 (WPARAM
) hDlg
, (LPARAM
) lppd
);
1650 case chx2
: /* collate pages checkbox */
1651 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
1652 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1653 (LPARAM
)PrintStructures
->hCollateIcon
);
1655 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1656 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1658 case edt1
: /* from page nr editbox */
1659 case edt2
: /* to page nr editbox */
1660 if (HIWORD(wParam
)==EN_CHANGE
) {
1663 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
1664 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
1665 if (nFromPage
!= lppd
->nFromPage
|| nToPage
!= lppd
->nToPage
)
1666 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1671 if(HIWORD(wParam
) == EN_CHANGE
) {
1672 INT copies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
1674 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1676 EnableWindow(GetDlgItem(hDlg
, chx2
), TRUE
);
1680 case psh1
: /* Print Setup */
1682 ERR("psh1 is called from 16bit code only, we should not get here.\n");
1685 case psh2
: /* Properties button */
1688 WCHAR PrinterName
[256];
1690 if (!GetDlgItemTextW(hDlg
, PrinterComboID
, PrinterName
, 255)) break;
1691 if (!OpenPrinterW(PrinterName
, &hPrinter
, NULL
)) {
1692 FIXME(" Call to OpenPrinter did not succeed!\n");
1695 DocumentPropertiesW(hDlg
, hPrinter
, PrinterName
,
1696 PrintStructures
->lpDevMode
,
1697 PrintStructures
->lpDevMode
,
1698 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
1699 ClosePrinter(hPrinter
);
1703 case rad1
: /* Paperorientation */
1704 if (lppd
->Flags
& PD_PRINTSETUP
)
1706 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1707 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1708 (LPARAM
)(PrintStructures
->hPortraitIcon
));
1712 case rad2
: /* Paperorientation */
1713 if (lppd
->Flags
& PD_PRINTSETUP
)
1715 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1716 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1717 (LPARAM
)(PrintStructures
->hLandscapeIcon
));
1721 case cmb1
: /* Printer Combobox in PRINT SETUP */
1723 case cmb4
: /* Printer combobox */
1724 if (HIWORD(wParam
)==CBN_SELCHANGE
) {
1725 WCHAR PrinterName
[256];
1726 GetDlgItemTextW(hDlg
, LOWORD(wParam
), PrinterName
, 255);
1727 PRINTDLG_ChangePrinterW(hDlg
, PrinterName
, PrintStructures
);
1731 case cmb2
: /* Papersize */
1733 DWORD Sel
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
1735 lpdm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageW(hDlg
, cmb2
,
1741 case cmb3
: /* Bin */
1743 DWORD Sel
= SendDlgItemMessageW(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
1745 lpdm
->u1
.s1
.dmDefaultSource
= SendDlgItemMessageW(hDlg
, cmb3
,
1746 CB_GETITEMDATA
, Sel
,
1751 if(lppd
->Flags
& PD_PRINTSETUP
) {
1752 switch (LOWORD(wParam
)) {
1753 case rad1
: /* orientation */
1755 if (IsDlgButtonChecked(hDlg
, rad1
) == BST_CHECKED
) {
1756 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_PORTRAIT
) {
1757 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1758 SendDlgItemMessageW(hDlg
, stc10
, STM_SETIMAGE
,
1760 (LPARAM
)PrintStructures
->hPortraitIcon
);
1761 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
,
1763 (LPARAM
)PrintStructures
->hPortraitIcon
);
1766 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_LANDSCAPE
) {
1767 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1768 SendDlgItemMessageW(hDlg
, stc10
, STM_SETIMAGE
,
1770 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1771 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
,
1773 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1782 /***********************************************************************
1783 * PrintDlgProcA [internal]
1785 static INT_PTR CALLBACK
PrintDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
1788 PRINT_PTRA
* PrintStructures
;
1789 INT_PTR res
= FALSE
;
1791 if (uMsg
!=WM_INITDIALOG
) {
1792 PrintStructures
= GetPropW(hDlg
, printdlg_prop
);
1793 if (!PrintStructures
)
1796 PrintStructures
= (PRINT_PTRA
*) lParam
;
1797 SetPropW(hDlg
, printdlg_prop
, PrintStructures
);
1798 if(!check_printer_setup(hDlg
))
1800 EndDialog(hDlg
,FALSE
);
1803 res
= PRINTDLG_WMInitDialog(hDlg
, wParam
, PrintStructures
);
1805 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
)
1806 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(
1807 hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->lpPrintDlg
1812 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
) {
1813 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
,uMsg
,wParam
,
1820 return PRINTDLG_WMCommandA(hDlg
, wParam
, lParam
, PrintStructures
);
1823 DestroyIcon(PrintStructures
->hCollateIcon
);
1824 DestroyIcon(PrintStructures
->hNoCollateIcon
);
1825 DestroyIcon(PrintStructures
->hPortraitIcon
);
1826 DestroyIcon(PrintStructures
->hLandscapeIcon
);
1827 if(PrintStructures
->hwndUpDown
)
1828 DestroyWindow(PrintStructures
->hwndUpDown
);
1834 static INT_PTR CALLBACK
PrintDlgProcW(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
1837 PRINT_PTRW
* PrintStructures
;
1838 INT_PTR res
= FALSE
;
1840 if (uMsg
!=WM_INITDIALOG
) {
1841 PrintStructures
= GetPropW(hDlg
, printdlg_prop
);
1842 if (!PrintStructures
)
1845 PrintStructures
= (PRINT_PTRW
*) lParam
;
1846 SetPropW(hDlg
, printdlg_prop
, PrintStructures
);
1847 if(!check_printer_setup(hDlg
))
1849 EndDialog(hDlg
,FALSE
);
1852 res
= PRINTDLG_WMInitDialogW(hDlg
, wParam
, PrintStructures
);
1854 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
)
1855 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->lpPrintDlg
);
1859 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
) {
1860 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
,uMsg
,wParam
, lParam
);
1866 return PRINTDLG_WMCommandW(hDlg
, wParam
, lParam
, PrintStructures
);
1869 DestroyIcon(PrintStructures
->hCollateIcon
);
1870 DestroyIcon(PrintStructures
->hNoCollateIcon
);
1871 DestroyIcon(PrintStructures
->hPortraitIcon
);
1872 DestroyIcon(PrintStructures
->hLandscapeIcon
);
1873 if(PrintStructures
->hwndUpDown
)
1874 DestroyWindow(PrintStructures
->hwndUpDown
);
1880 /************************************************************
1882 * PRINTDLG_GetDlgTemplate
1885 static HGLOBAL
PRINTDLG_GetDlgTemplateA(const PRINTDLGA
*lppd
)
1890 if (lppd
->Flags
& PD_PRINTSETUP
) {
1891 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
1892 hDlgTmpl
= lppd
->hSetupTemplate
;
1893 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
1894 hResInfo
= FindResourceA(lppd
->hInstance
,
1895 lppd
->lpSetupTemplateName
, (LPSTR
)RT_DIALOG
);
1896 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1898 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32_SETUP",
1900 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1903 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
1904 hDlgTmpl
= lppd
->hPrintTemplate
;
1905 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
1906 hResInfo
= FindResourceA(lppd
->hInstance
,
1907 lppd
->lpPrintTemplateName
,
1909 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1911 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32",
1913 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1919 static HGLOBAL
PRINTDLG_GetDlgTemplateW(const PRINTDLGW
*lppd
)
1923 static const WCHAR xpsetup
[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
1924 static const WCHAR xprint
[] = { 'P','R','I','N','T','3','2',0};
1926 if (lppd
->Flags
& PD_PRINTSETUP
) {
1927 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
1928 hDlgTmpl
= lppd
->hSetupTemplate
;
1929 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
1930 hResInfo
= FindResourceW(lppd
->hInstance
,
1931 lppd
->lpSetupTemplateName
, (LPWSTR
)RT_DIALOG
);
1932 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1934 hResInfo
= FindResourceW(COMDLG32_hInstance
, xpsetup
, (LPWSTR
)RT_DIALOG
);
1935 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1938 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
1939 hDlgTmpl
= lppd
->hPrintTemplate
;
1940 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
1941 hResInfo
= FindResourceW(lppd
->hInstance
,
1942 lppd
->lpPrintTemplateName
,
1944 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1946 hResInfo
= FindResourceW(COMDLG32_hInstance
, xprint
, (LPWSTR
)RT_DIALOG
);
1947 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1953 /***********************************************************************
1958 static BOOL
PRINTDLG_CreateDCA(LPPRINTDLGA lppd
)
1960 DEVNAMES
*pdn
= GlobalLock(lppd
->hDevNames
);
1961 DEVMODEA
*pdm
= GlobalLock(lppd
->hDevMode
);
1963 if(lppd
->Flags
& PD_RETURNDC
) {
1964 lppd
->hDC
= CreateDCA((char*)pdn
+ pdn
->wDriverOffset
,
1965 (char*)pdn
+ pdn
->wDeviceOffset
,
1966 (char*)pdn
+ pdn
->wOutputOffset
,
1968 } else if(lppd
->Flags
& PD_RETURNIC
) {
1969 lppd
->hDC
= CreateICA((char*)pdn
+ pdn
->wDriverOffset
,
1970 (char*)pdn
+ pdn
->wDeviceOffset
,
1971 (char*)pdn
+ pdn
->wOutputOffset
,
1974 GlobalUnlock(lppd
->hDevNames
);
1975 GlobalUnlock(lppd
->hDevMode
);
1976 return lppd
->hDC
? TRUE
: FALSE
;
1979 static BOOL
PRINTDLG_CreateDCW(LPPRINTDLGW lppd
)
1981 DEVNAMES
*pdn
= GlobalLock(lppd
->hDevNames
);
1982 DEVMODEW
*pdm
= GlobalLock(lppd
->hDevMode
);
1984 if(lppd
->Flags
& PD_RETURNDC
) {
1985 lppd
->hDC
= CreateDCW((WCHAR
*)pdn
+ pdn
->wDriverOffset
,
1986 (WCHAR
*)pdn
+ pdn
->wDeviceOffset
,
1987 (WCHAR
*)pdn
+ pdn
->wOutputOffset
,
1989 } else if(lppd
->Flags
& PD_RETURNIC
) {
1990 lppd
->hDC
= CreateICW((WCHAR
*)pdn
+ pdn
->wDriverOffset
,
1991 (WCHAR
*)pdn
+ pdn
->wDeviceOffset
,
1992 (WCHAR
*)pdn
+ pdn
->wOutputOffset
,
1995 GlobalUnlock(lppd
->hDevNames
);
1996 GlobalUnlock(lppd
->hDevMode
);
1997 return lppd
->hDC
? TRUE
: FALSE
;
2000 /***********************************************************************
2001 * PrintDlgA (COMDLG32.@)
2003 * Displays the PRINT dialog box, which enables the user to specify
2004 * specific properties of the print job.
2007 * lppd [IO] ptr to PRINTDLG32 struct
2010 * nonzero if the user pressed the OK button
2011 * zero if the user cancelled the window or an error occurred
2015 * * The Collate Icons do not display, even though they are in the code.
2016 * * The Properties Button(s) should call DocumentPropertiesA().
2019 BOOL WINAPI
PrintDlgA(LPPRINTDLGA lppd
)
2027 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
2031 hInst
= (HINSTANCE
)GetWindowLongPtrA( lppd
->hwndOwner
, GWLP_HINSTANCE
);
2032 if(TRACE_ON(commdlg
)) {
2033 char flagstr
[1000] = "";
2034 const struct pd_flags
*pflag
= pd_flags
;
2035 for( ; pflag
->name
; pflag
++) {
2036 if(lppd
->Flags
& pflag
->flag
)
2037 strcat(flagstr
, pflag
->name
);
2039 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2040 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2041 "flags %08x (%s)\n",
2042 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
2043 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
2044 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
2047 if(lppd
->lStructSize
!= sizeof(PRINTDLGA
)) {
2048 WARN("structure size failure !!!\n");
2049 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
2053 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
2054 PRINTER_INFO_2A
*pbuf
;
2055 DRIVER_INFO_3A
*dbuf
;
2059 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
2060 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2061 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2064 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
2065 WARN("Can't find default printer\n");
2066 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
2070 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
2071 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
2072 GetPrinterA(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
2074 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
2075 dbuf
= HeapAlloc(GetProcessHeap(),0,needed
);
2076 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
2077 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2078 GetLastError(),pbuf
->pPrinterName
);
2079 HeapFree(GetProcessHeap(), 0, dbuf
);
2080 HeapFree(GetProcessHeap(), 0, pbuf
);
2081 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2086 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
2090 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
2091 pbuf
->pDevMode
->dmDriverExtra
);
2092 ptr
= GlobalLock(lppd
->hDevMode
);
2093 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
2094 pbuf
->pDevMode
->dmDriverExtra
);
2095 GlobalUnlock(lppd
->hDevMode
);
2096 HeapFree(GetProcessHeap(), 0, pbuf
);
2097 HeapFree(GetProcessHeap(), 0, dbuf
);
2101 PRINT_PTRA
*PrintStructures
;
2103 /* load Dialog resources,
2104 * depending on Flags indicates Print32 or Print32_setup dialog
2106 hDlgTmpl
= PRINTDLG_GetDlgTemplateA(lppd
);
2108 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2111 ptr
= LockResource( hDlgTmpl
);
2113 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2117 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2118 sizeof(PRINT_PTRA
));
2119 PrintStructures
->lpPrintDlg
= lppd
;
2121 /* and create & process the dialog .
2122 * -1 is failure, 0 is broken hwnd, everything else is ok.
2124 bRet
= (0<DialogBoxIndirectParamA(hInst
, ptr
, lppd
->hwndOwner
,
2126 (LPARAM
)PrintStructures
));
2129 DEVMODEA
*lpdm
= PrintStructures
->lpDevMode
, *lpdmReturn
;
2130 PRINTER_INFO_2A
*pi
= PrintStructures
->lpPrinterInfo
;
2131 DRIVER_INFO_3A
*di
= PrintStructures
->lpDriverInfo
;
2133 if (lppd
->hDevMode
== 0) {
2134 TRACE(" No hDevMode yet... Need to create my own\n");
2135 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
,
2136 lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2138 lppd
->hDevMode
= GlobalReAlloc(lppd
->hDevMode
,
2139 lpdm
->dmSize
+ lpdm
->dmDriverExtra
,
2142 lpdmReturn
= GlobalLock(lppd
->hDevMode
);
2143 memcpy(lpdmReturn
, lpdm
, lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2145 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
2150 GlobalUnlock(lppd
->hDevMode
);
2152 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
2153 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpPrinterInfo
);
2154 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDriverInfo
);
2155 HeapFree(GetProcessHeap(), 0, PrintStructures
);
2157 if(bRet
&& (lppd
->Flags
& PD_RETURNDC
|| lppd
->Flags
& PD_RETURNIC
))
2158 bRet
= PRINTDLG_CreateDCA(lppd
);
2160 TRACE("exit! (%d)\n", bRet
);
2164 /***********************************************************************
2165 * PrintDlgW (COMDLG32.@)
2169 BOOL WINAPI
PrintDlgW(LPPRINTDLGW lppd
)
2177 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
2181 hInst
= (HINSTANCE
)GetWindowLongPtrW( lppd
->hwndOwner
, GWLP_HINSTANCE
);
2182 if(TRACE_ON(commdlg
)) {
2183 char flagstr
[1000] = "";
2184 const struct pd_flags
*pflag
= pd_flags
;
2185 for( ; pflag
->name
; pflag
++) {
2186 if(lppd
->Flags
& pflag
->flag
)
2187 strcat(flagstr
, pflag
->name
);
2189 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2190 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2191 "flags %08x (%s)\n",
2192 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
2193 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
2194 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
2197 if(lppd
->lStructSize
!= sizeof(PRINTDLGW
)) {
2198 WARN("structure size failure !!!\n");
2199 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
2203 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
2204 PRINTER_INFO_2W
*pbuf
;
2205 DRIVER_INFO_3W
*dbuf
;
2209 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
2210 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2211 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2214 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
2215 WARN("Can't find default printer\n");
2216 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
2220 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
2221 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
2222 GetPrinterW(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
2224 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
2225 dbuf
= HeapAlloc(GetProcessHeap(),0,needed
);
2226 if (!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
2227 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2228 GetLastError(),debugstr_w(pbuf
->pPrinterName
));
2229 HeapFree(GetProcessHeap(), 0, dbuf
);
2230 HeapFree(GetProcessHeap(), 0, pbuf
);
2231 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2236 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
2240 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
2241 pbuf
->pDevMode
->dmDriverExtra
);
2242 ptr
= GlobalLock(lppd
->hDevMode
);
2243 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
2244 pbuf
->pDevMode
->dmDriverExtra
);
2245 GlobalUnlock(lppd
->hDevMode
);
2246 HeapFree(GetProcessHeap(), 0, pbuf
);
2247 HeapFree(GetProcessHeap(), 0, dbuf
);
2251 PRINT_PTRW
*PrintStructures
;
2253 /* load Dialog resources,
2254 * depending on Flags indicates Print32 or Print32_setup dialog
2256 hDlgTmpl
= PRINTDLG_GetDlgTemplateW(lppd
);
2258 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2261 ptr
= LockResource( hDlgTmpl
);
2263 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2267 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2268 sizeof(PRINT_PTRW
));
2269 PrintStructures
->lpPrintDlg
= lppd
;
2271 /* and create & process the dialog .
2272 * -1 is failure, 0 is broken hwnd, everything else is ok.
2274 bRet
= (0<DialogBoxIndirectParamW(hInst
, ptr
, lppd
->hwndOwner
,
2276 (LPARAM
)PrintStructures
));
2279 DEVMODEW
*lpdm
= PrintStructures
->lpDevMode
, *lpdmReturn
;
2280 PRINTER_INFO_2W
*pi
= PrintStructures
->lpPrinterInfo
;
2281 DRIVER_INFO_3W
*di
= PrintStructures
->lpDriverInfo
;
2283 if (lppd
->hDevMode
== 0) {
2284 TRACE(" No hDevMode yet... Need to create my own\n");
2285 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
,
2286 lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2289 if((locks
= (GlobalFlags(lppd
->hDevMode
) & GMEM_LOCKCOUNT
))) {
2290 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks
);
2292 GlobalUnlock(lppd
->hDevMode
);
2293 TRACE("Now got %d locks\n", locks
);
2296 lppd
->hDevMode
= GlobalReAlloc(lppd
->hDevMode
,
2297 lpdm
->dmSize
+ lpdm
->dmDriverExtra
,
2300 lpdmReturn
= GlobalLock(lppd
->hDevMode
);
2301 memcpy(lpdmReturn
, lpdm
, lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2303 if (lppd
->hDevNames
!= 0) {
2305 if((locks
= (GlobalFlags(lppd
->hDevNames
) & GMEM_LOCKCOUNT
))) {
2306 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks
);
2308 GlobalUnlock(lppd
->hDevNames
);
2311 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
2316 GlobalUnlock(lppd
->hDevMode
);
2318 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
2319 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpPrinterInfo
);
2320 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDriverInfo
);
2321 HeapFree(GetProcessHeap(), 0, PrintStructures
);
2323 if(bRet
&& (lppd
->Flags
& PD_RETURNDC
|| lppd
->Flags
& PD_RETURNIC
))
2324 bRet
= PRINTDLG_CreateDCW(lppd
);
2326 TRACE("exit! (%d)\n", bRet
);
2330 /***********************************************************************
2335 * cmb1 - printer select (not in standard dialog template)
2337 * cmb3 - source (tray?)
2338 * edt4 - border left
2340 * edt6 - border right
2341 * edt7 - border bottom
2342 * psh3 - "Printer..."
2350 LPPAGESETUPDLGA dlga
;
2351 LPPAGESETUPDLGW dlgw
;
2353 HWND hDlg
; /* Page Setup dialog handle */
2354 RECT rtDrawRect
; /* Drawing rect for page */
2357 static inline DWORD
pagesetup_get_flags(const pagesetup_data
*data
)
2359 return data
->u
.dlgw
->Flags
;
2362 static inline BOOL
is_metric(const pagesetup_data
*data
)
2364 return pagesetup_get_flags(data
) & PSD_INHUNDREDTHSOFMILLIMETERS
;
2367 static inline LONG
tenths_mm_to_size(pagesetup_data
*data
, LONG size
)
2369 if (is_metric(data
))
2372 return 10 * size
* 100 / 254;
2375 static inline LONG
thousandths_inch_to_size(pagesetup_data
*data
, LONG size
)
2377 if (is_metric(data
))
2378 return size
* 254 / 100;
2383 static WCHAR
get_decimal_sep(void)
2389 WCHAR buf
[2] = {'.',0};
2390 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SDECIMAL
, buf
, sizeof(buf
) / sizeof(buf
[0]));
2396 static void size2str(const pagesetup_data
*data
, DWORD size
, LPWSTR strout
)
2398 WCHAR integer_fmt
[] = {'%','d',0};
2399 WCHAR hundredths_fmt
[] = {'%','d','%','c','%','0','2','d',0};
2400 WCHAR thousandths_fmt
[] = {'%','d','%','c','%','0','3','d',0};
2402 /* FIXME use LOCALE_SDECIMAL when the edit parsing code can cope */
2404 if (is_metric(data
))
2407 wsprintfW(strout
, hundredths_fmt
, size
/ 100, get_decimal_sep(), size
% 100);
2409 wsprintfW(strout
, integer_fmt
, size
/ 100);
2414 wsprintfW(strout
, thousandths_fmt
, size
/ 1000, get_decimal_sep(), size
% 1000);
2416 wsprintfW(strout
, integer_fmt
, size
/ 1000);
2421 static inline BOOL
is_default_metric(void)
2424 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_IMEASURE
| LOCALE_RETURN_NUMBER
,
2425 (LPWSTR
)&system
, sizeof(system
));
2429 /**********************************************
2431 * Cyclically permute the four members of rc
2432 * If sense is TRUE l -> t -> r -> b
2433 * otherwise l <- t <- r <- b
2435 static inline void rotate_rect(RECT
*rc
, BOOL sense
)
2441 rc
->bottom
= rc
->right
;
2442 rc
->right
= rc
->top
;
2450 rc
->top
= rc
->right
;
2451 rc
->right
= rc
->bottom
;
2456 static void pagesetup_set_orientation(pagesetup_data
*data
, WORD orient
)
2458 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2460 assert(orient
== DMORIENT_PORTRAIT
|| orient
== DMORIENT_LANDSCAPE
);
2463 dm
->u1
.s1
.dmOrientation
= orient
;
2466 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2467 dmA
->u1
.s1
.dmOrientation
= orient
;
2469 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2472 static WORD
pagesetup_get_orientation(const pagesetup_data
*data
)
2474 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2478 orient
= dm
->u1
.s1
.dmOrientation
;
2481 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2482 orient
= dmA
->u1
.s1
.dmOrientation
;
2484 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2488 static void pagesetup_set_papersize(pagesetup_data
*data
, WORD paper
)
2490 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2493 dm
->u1
.s1
.dmPaperSize
= paper
;
2496 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2497 dmA
->u1
.s1
.dmPaperSize
= paper
;
2499 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2502 static WORD
pagesetup_get_papersize(const pagesetup_data
*data
)
2504 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2508 paper
= dm
->u1
.s1
.dmPaperSize
;
2511 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2512 paper
= dmA
->u1
.s1
.dmPaperSize
;
2514 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2518 static void pagesetup_set_defaultsource(pagesetup_data
*data
, WORD source
)
2520 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2523 dm
->u1
.s1
.dmDefaultSource
= source
;
2526 DEVMODEA
*dmA
= (DEVMODEA
*)dm
;
2527 dmA
->u1
.s1
.dmDefaultSource
= source
;
2529 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2534 devnames_driver_name
,
2535 devnames_device_name
,
2536 devnames_output_name
2540 static inline WORD
get_devname_offset(DEVNAMES
*dn
, devnames_name which
)
2544 case devnames_driver_name
: return dn
->wDriverOffset
;
2545 case devnames_device_name
: return dn
->wDeviceOffset
;
2546 case devnames_output_name
: return dn
->wOutputOffset
;
2548 ERR("Souldn't be here\n");
2552 static WCHAR
*pagesetup_get_a_devname(const pagesetup_data
*data
, devnames_name which
)
2557 dn
= GlobalLock(data
->u
.dlgw
->hDevNames
);
2559 name
= strdupW((WCHAR
*)dn
+ get_devname_offset(dn
, which
));
2562 int len
= MultiByteToWideChar(CP_ACP
, 0, (char*)dn
+ get_devname_offset(dn
, which
), -1, NULL
, 0);
2563 name
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
2564 MultiByteToWideChar(CP_ACP
, 0, (char*)dn
+ get_devname_offset(dn
, which
), -1, name
, len
);
2566 GlobalUnlock(data
->u
.dlgw
->hDevNames
);
2570 static WCHAR
*pagesetup_get_drvname(const pagesetup_data
*data
)
2572 return pagesetup_get_a_devname(data
, devnames_driver_name
);
2575 static WCHAR
*pagesetup_get_devname(const pagesetup_data
*data
)
2577 return pagesetup_get_a_devname(data
, devnames_device_name
);
2580 static WCHAR
*pagesetup_get_portname(const pagesetup_data
*data
)
2582 return pagesetup_get_a_devname(data
, devnames_output_name
);
2585 static void pagesetup_release_a_devname(const pagesetup_data
*data
, WCHAR
*name
)
2587 HeapFree(GetProcessHeap(), 0, name
);
2590 static void pagesetup_set_devnames(pagesetup_data
*data
, LPCWSTR drv
, LPCWSTR devname
, LPCWSTR port
)
2594 DWORD len
= sizeof(DEVNAMES
), drv_len
, dev_len
, port_len
;
2598 drv_len
= (strlenW(drv
) + 1) * sizeof(WCHAR
);
2599 dev_len
= (strlenW(devname
) + 1) * sizeof(WCHAR
);
2600 port_len
= (strlenW(port
) + 1) * sizeof(WCHAR
);
2604 drv_len
= WideCharToMultiByte(CP_ACP
, 0, drv
, -1, NULL
, 0, NULL
, NULL
);
2605 dev_len
= WideCharToMultiByte(CP_ACP
, 0, devname
, -1, NULL
, 0, NULL
, NULL
);
2606 port_len
= WideCharToMultiByte(CP_ACP
, 0, port
, -1, NULL
, 0, NULL
, NULL
);
2608 len
+= drv_len
+ dev_len
+ port_len
;
2610 if(data
->u
.dlgw
->hDevNames
)
2611 data
->u
.dlgw
->hDevNames
= GlobalReAlloc(data
->u
.dlgw
->hDevNames
, len
, GMEM_MOVEABLE
);
2613 data
->u
.dlgw
->hDevNames
= GlobalAlloc(GMEM_MOVEABLE
, len
);
2615 dn
= GlobalLock(data
->u
.dlgw
->hDevNames
);
2619 WCHAR
*ptr
= (WCHAR
*)(dn
+ 1);
2620 len
= sizeof(DEVNAMES
) / sizeof(WCHAR
);
2621 dn
->wDriverOffset
= len
;
2623 ptr
+= drv_len
/ sizeof(WCHAR
);
2624 len
+= drv_len
/ sizeof(WCHAR
);
2625 dn
->wDeviceOffset
= len
;
2626 strcpyW(ptr
, devname
);
2627 ptr
+= dev_len
/ sizeof(WCHAR
);
2628 len
+= dev_len
/ sizeof(WCHAR
);
2629 dn
->wOutputOffset
= len
;
2634 char *ptr
= (char *)(dn
+ 1);
2635 len
= sizeof(DEVNAMES
);
2636 dn
->wDriverOffset
= len
;
2637 WideCharToMultiByte(CP_ACP
, 0, drv
, -1, ptr
, drv_len
, NULL
, NULL
);
2640 dn
->wDeviceOffset
= len
;
2641 WideCharToMultiByte(CP_ACP
, 0, devname
, -1, ptr
, dev_len
, NULL
, NULL
);
2644 dn
->wOutputOffset
= len
;
2645 WideCharToMultiByte(CP_ACP
, 0, port
, -1, ptr
, port_len
, NULL
, NULL
);
2649 len
= sizeof(def
) / sizeof(def
[0]);
2650 GetDefaultPrinterW(def
, &len
);
2651 if(!lstrcmpW(def
, devname
))
2654 GlobalUnlock(data
->u
.dlgw
->hDevNames
);
2657 static DEVMODEW
*pagesetup_get_devmode(const pagesetup_data
*data
)
2659 DEVMODEW
*dm
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2664 /* We make a copy even in the unicode case because the ptr
2665 may get passed back to us in pagesetup_set_devmode. */
2666 ret
= HeapAlloc(GetProcessHeap(), 0, dm
->dmSize
+ dm
->dmDriverExtra
);
2667 memcpy(ret
, dm
, dm
->dmSize
+ dm
->dmDriverExtra
);
2670 ret
= GdiConvertToDevmodeW((DEVMODEA
*)dm
);
2672 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2676 static void pagesetup_release_devmode(const pagesetup_data
*data
, DEVMODEW
*dm
)
2678 HeapFree(GetProcessHeap(), 0, dm
);
2681 static void pagesetup_set_devmode(pagesetup_data
*data
, DEVMODEW
*dm
)
2683 DEVMODEA
*dmA
= NULL
;
2689 size
= dm
->dmSize
+ dm
->dmDriverExtra
;
2694 dmA
= convert_to_devmodeA(dm
);
2695 size
= dmA
->dmSize
+ dmA
->dmDriverExtra
;
2699 if(data
->u
.dlgw
->hDevMode
)
2700 data
->u
.dlgw
->hDevMode
= GlobalReAlloc(data
->u
.dlgw
->hDevMode
, size
,
2703 data
->u
.dlgw
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, size
);
2705 dst
= GlobalLock(data
->u
.dlgw
->hDevMode
);
2706 memcpy(dst
, src
, size
);
2707 GlobalUnlock(data
->u
.dlgw
->hDevMode
);
2708 HeapFree(GetProcessHeap(), 0, dmA
);
2711 static inline POINT
*pagesetup_get_papersize_pt(const pagesetup_data
*data
)
2713 return &data
->u
.dlgw
->ptPaperSize
;
2716 static inline RECT
*pagesetup_get_margin_rect(const pagesetup_data
*data
)
2718 return &data
->u
.dlgw
->rtMargin
;
2727 static inline LPPAGESETUPHOOK
pagesetup_get_hook(const pagesetup_data
*data
, hook_type which
)
2731 case page_setup_hook
: return data
->u
.dlgw
->lpfnPageSetupHook
;
2732 case page_paint_hook
: return data
->u
.dlgw
->lpfnPagePaintHook
;
2737 /* This should only be used in calls to hook procs so we return the ptr
2738 already cast to LPARAM */
2739 static inline LPARAM
pagesetup_get_dlg_struct(const pagesetup_data
*data
)
2741 return (LPARAM
)data
->u
.dlgw
;
2744 static inline void swap_point(POINT
*pt
)
2751 static BOOL
pagesetup_update_papersize(pagesetup_data
*data
)
2754 LPWSTR devname
, portname
;
2756 WORD
*words
= NULL
, paperword
;
2757 POINT
*points
= NULL
;
2758 BOOL retval
= FALSE
;
2760 dm
= pagesetup_get_devmode(data
);
2761 devname
= pagesetup_get_devname(data
);
2762 portname
= pagesetup_get_portname(data
);
2764 num
= DeviceCapabilitiesW(devname
, portname
, DC_PAPERS
, NULL
, dm
);
2767 FIXME("No papernames found for %s/%s\n", debugstr_w(devname
), debugstr_w(portname
));
2771 words
= HeapAlloc(GetProcessHeap(), 0, num
* sizeof(WORD
));
2772 points
= HeapAlloc(GetProcessHeap(), 0, num
* sizeof(POINT
));
2774 if (num
!= DeviceCapabilitiesW(devname
, portname
, DC_PAPERS
, (LPWSTR
)words
, dm
))
2776 FIXME("Number of returned words is not %d\n", num
);
2780 if (num
!= DeviceCapabilitiesW(devname
, portname
, DC_PAPERSIZE
, (LPWSTR
)points
, dm
))
2782 FIXME("Number of returned sizes is not %d\n", num
);
2786 paperword
= pagesetup_get_papersize(data
);
2788 for (i
= 0; i
< num
; i
++)
2789 if (words
[i
] == paperword
)
2794 FIXME("Papersize %d not found in list?\n", paperword
);
2798 /* this is _10ths_ of a millimeter */
2799 pagesetup_get_papersize_pt(data
)->x
= tenths_mm_to_size(data
, points
[i
].x
);
2800 pagesetup_get_papersize_pt(data
)->y
= tenths_mm_to_size(data
, points
[i
].y
);
2802 if(pagesetup_get_orientation(data
) == DMORIENT_LANDSCAPE
)
2803 swap_point(pagesetup_get_papersize_pt(data
));
2808 HeapFree(GetProcessHeap(), 0, words
);
2809 HeapFree(GetProcessHeap(), 0, points
);
2810 pagesetup_release_a_devname(data
, portname
);
2811 pagesetup_release_a_devname(data
, devname
);
2812 pagesetup_release_devmode(data
, dm
);
2817 /**********************************************************************************************
2818 * pagesetup_change_printer
2820 * Redefines hDevMode and hDevNames HANDLES and initialises it.
2823 static BOOL
pagesetup_change_printer(LPWSTR name
, pagesetup_data
*data
)
2827 PRINTER_INFO_2W
*prn_info
= NULL
;
2828 DRIVER_INFO_3W
*drv_info
= NULL
;
2829 DEVMODEW
*dm
= NULL
;
2830 BOOL retval
= FALSE
;
2832 if(!OpenPrinterW(name
, &hprn
, NULL
))
2834 ERR("Can't open printer %s\n", debugstr_w(name
));
2838 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
2839 prn_info
= HeapAlloc(GetProcessHeap(), 0, needed
);
2840 GetPrinterW(hprn
, 2, (LPBYTE
)prn_info
, needed
, &needed
);
2841 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
2842 drv_info
= HeapAlloc(GetProcessHeap(), 0, needed
);
2843 if(!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)drv_info
, needed
, &needed
))
2845 ERR("GetPrinterDriverA failed for %s, fix your config!\n", debugstr_w(prn_info
->pPrinterName
));
2850 needed
= DocumentPropertiesW(0, 0, name
, NULL
, NULL
, 0);
2853 ERR("DocumentProperties fails on %s\n", debugstr_w(name
));
2857 dm
= HeapAlloc(GetProcessHeap(), 0, needed
);
2858 DocumentPropertiesW(0, 0, name
, dm
, NULL
, DM_OUT_BUFFER
);
2860 pagesetup_set_devmode(data
, dm
);
2861 pagesetup_set_devnames(data
, drv_info
->pDriverPath
, prn_info
->pPrinterName
,
2862 prn_info
->pPortName
);
2866 HeapFree(GetProcessHeap(), 0, dm
);
2867 HeapFree(GetProcessHeap(), 0, prn_info
);
2868 HeapFree(GetProcessHeap(), 0, drv_info
);
2872 /****************************************************************************************
2873 * pagesetup_init_combos
2875 * Fills Printers, Paper and Source combos
2878 static void pagesetup_init_combos(HWND hDlg
, pagesetup_data
*data
)
2881 LPWSTR devname
, portname
;
2883 dm
= pagesetup_get_devmode(data
);
2884 devname
= pagesetup_get_devname(data
);
2885 portname
= pagesetup_get_portname(data
);
2887 PRINTDLG_SetUpPrinterListComboW(hDlg
, cmb1
, devname
);
2888 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb2
, devname
, portname
, dm
);
2889 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb3
, devname
, portname
, dm
);
2891 pagesetup_release_a_devname(data
, portname
);
2892 pagesetup_release_a_devname(data
, devname
);
2893 pagesetup_release_devmode(data
, dm
);
2897 /****************************************************************************************
2898 * pagesetup_change_printer_dialog
2900 * Pops up another dialog that lets the user pick another printer.
2902 * For now we display the PrintDlg, this should display a striped down version of it.
2904 static void pagesetup_change_printer_dialog(HWND hDlg
, pagesetup_data
*data
)
2907 LPWSTR drvname
, devname
, portname
;
2908 DEVMODEW
*tmp_dm
, *dm
;
2910 memset(&prnt
, 0, sizeof(prnt
));
2911 prnt
.lStructSize
= sizeof(prnt
);
2913 prnt
.hwndOwner
= hDlg
;
2915 drvname
= pagesetup_get_drvname(data
);
2916 devname
= pagesetup_get_devname(data
);
2917 portname
= pagesetup_get_portname(data
);
2919 PRINTDLG_CreateDevNamesW(&prnt
.hDevNames
, drvname
, devname
, portname
);
2920 pagesetup_release_a_devname(data
, portname
);
2921 pagesetup_release_a_devname(data
, devname
);
2922 pagesetup_release_a_devname(data
, drvname
);
2924 tmp_dm
= pagesetup_get_devmode(data
);
2925 prnt
.hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, tmp_dm
->dmSize
+ tmp_dm
->dmDriverExtra
);
2926 dm
= GlobalLock(prnt
.hDevMode
);
2927 memcpy(dm
, tmp_dm
, tmp_dm
->dmSize
+ tmp_dm
->dmDriverExtra
);
2928 GlobalUnlock(prnt
.hDevMode
);
2929 pagesetup_release_devmode(data
, tmp_dm
);
2931 if (PrintDlgW(&prnt
))
2933 DEVMODEW
*dm
= GlobalLock(prnt
.hDevMode
);
2934 DEVNAMES
*dn
= GlobalLock(prnt
.hDevNames
);
2936 pagesetup_set_devnames(data
, (WCHAR
*)dn
+ dn
->wDriverOffset
,
2937 (WCHAR
*)dn
+ dn
->wDeviceOffset
, (WCHAR
*)dn
+ dn
->wOutputOffset
);
2938 pagesetup_set_devmode(data
, dm
);
2939 GlobalUnlock(prnt
.hDevNames
);
2940 GlobalUnlock(prnt
.hDevMode
);
2941 pagesetup_init_combos(hDlg
, data
);
2944 GlobalFree(prnt
.hDevMode
);
2945 GlobalFree(prnt
.hDevNames
);
2949 /******************************************************************************************
2950 * pagesetup_change_preview
2952 * Changes paper preview size / position
2955 static void pagesetup_change_preview(const pagesetup_data
*data
)
2957 LONG width
, height
, x
, y
;
2959 const int shadow
= 4;
2961 if(pagesetup_get_orientation(data
) == DMORIENT_LANDSCAPE
)
2963 width
= data
->rtDrawRect
.right
- data
->rtDrawRect
.left
;
2964 height
= pagesetup_get_papersize_pt(data
)->y
* width
/ pagesetup_get_papersize_pt(data
)->x
;
2968 height
= data
->rtDrawRect
.bottom
- data
->rtDrawRect
.top
;
2969 width
= pagesetup_get_papersize_pt(data
)->x
* height
/ pagesetup_get_papersize_pt(data
)->y
;
2971 x
= (data
->rtDrawRect
.right
+ data
->rtDrawRect
.left
- width
) / 2;
2972 y
= (data
->rtDrawRect
.bottom
+ data
->rtDrawRect
.top
- height
) / 2;
2973 TRACE("draw rect %s x=%d, y=%d, w=%d, h=%d\n",
2974 wine_dbgstr_rect(&data
->rtDrawRect
), x
, y
, width
, height
);
2976 MoveWindow(GetDlgItem(data
->hDlg
, rct2
), x
+ width
, y
+ shadow
, shadow
, height
, FALSE
);
2977 MoveWindow(GetDlgItem(data
->hDlg
, rct3
), x
+ shadow
, y
+ height
, width
, shadow
, FALSE
);
2978 MoveWindow(GetDlgItem(data
->hDlg
, rct1
), x
, y
, width
, height
, FALSE
);
2980 tmp
= data
->rtDrawRect
;
2981 tmp
.right
+= shadow
;
2982 tmp
.bottom
+= shadow
;
2983 InvalidateRect(data
->hDlg
, &tmp
, TRUE
);
2986 static inline LONG
*element_from_margin_id(RECT
*rc
, WORD id
)
2990 case edt4
: return &rc
->left
;
2991 case edt5
: return &rc
->top
;
2992 case edt6
: return &rc
->right
;
2993 case edt7
: return &rc
->bottom
;
2998 static void update_margin_edits(HWND hDlg
, const pagesetup_data
*data
, WORD id
)
3003 for(idx
= edt4
; idx
<= edt7
; idx
++)
3005 if(id
== 0 || id
== idx
)
3007 size2str(data
, *element_from_margin_id(pagesetup_get_margin_rect(data
), idx
), str
);
3008 SetDlgItemTextW(hDlg
, idx
, str
);
3013 static void margin_edit_notification(HWND hDlg
, pagesetup_data
*data
, WORD msg
, WORD id
)
3021 LONG
*value
= element_from_margin_id(pagesetup_get_margin_rect(data
), id
);
3023 if (GetDlgItemTextW(hDlg
, id
, buf
, sizeof(buf
) / sizeof(buf
[0])) != 0)
3026 WCHAR decimal
= get_decimal_sep();
3028 val
= strtolW(buf
, &end
, 10);
3029 if(end
!= buf
|| *end
== decimal
)
3031 int mult
= is_metric(data
) ? 100 : 1000;
3040 val
+= (*end
- '0') * mult
;
3052 update_margin_edits(hDlg
, data
, id
);
3057 static void set_margin_groupbox_title(HWND hDlg
, const pagesetup_data
*data
)
3061 if(LoadStringW(COMDLG32_hInstance
, is_metric(data
) ? PD32_MARGINS_IN_MILLIMETERS
: PD32_MARGINS_IN_INCHES
,
3062 title
, sizeof(title
)/sizeof(title
[0])))
3063 SetDlgItemTextW(hDlg
, grp4
, title
);
3066 static void pagesetup_update_orientation_buttons(HWND hDlg
, const pagesetup_data
*data
)
3068 if (pagesetup_get_orientation(data
) == DMORIENT_LANDSCAPE
)
3069 CheckRadioButton(hDlg
, rad1
, rad2
, rad2
);
3071 CheckRadioButton(hDlg
, rad1
, rad2
, rad1
);
3074 /****************************************************************************************
3075 * pagesetup_printer_properties
3077 * Handle invocation of the 'Properties' button (not present in the default template).
3079 static void pagesetup_printer_properties(HWND hDlg
, pagesetup_data
*data
)
3087 devname
= pagesetup_get_devname(data
);
3089 if (!OpenPrinterW(devname
, &hprn
, NULL
))
3091 FIXME("Call to OpenPrinter did not succeed!\n");
3092 pagesetup_release_a_devname(data
, devname
);
3096 dm
= pagesetup_get_devmode(data
);
3097 DocumentPropertiesW(hDlg
, hprn
, devname
, dm
, dm
, DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
3098 pagesetup_set_devmode(data
, dm
);
3099 pagesetup_release_devmode(data
, dm
);
3100 pagesetup_release_a_devname(data
, devname
);
3103 /* Changing paper */
3104 pagesetup_update_papersize(data
);
3105 pagesetup_update_orientation_buttons(hDlg
, data
);
3107 /* Changing paper preview */
3108 pagesetup_change_preview(data
);
3110 /* Selecting paper in combo */
3111 count
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCOUNT
, 0, 0);
3114 WORD paperword
= pagesetup_get_papersize(data
);
3115 for(i
= 0; i
< count
; i
++)
3117 if(SendDlgItemMessageW(hDlg
, cmb2
, CB_GETITEMDATA
, i
, 0) == paperword
) {
3118 SendDlgItemMessageW(hDlg
, cmb2
, CB_SETCURSEL
, i
, 0);
3125 /********************************************************************************
3126 * pagesetup_wm_command
3127 * process WM_COMMAND message for PageSetupDlg
3130 * hDlg [in] Main dialog HANDLE
3131 * wParam [in] WM_COMMAND wParam
3132 * lParam [in] WM_COMMAND lParam
3133 * pda [in/out] ptr to PageSetupDataA
3136 static BOOL
pagesetup_wm_command(HWND hDlg
, WPARAM wParam
, LPARAM lParam
, pagesetup_data
*data
)
3138 WORD msg
= HIWORD(wParam
);
3139 WORD id
= LOWORD(wParam
);
3141 TRACE("loword (lparam) %d, wparam 0x%lx, lparam %08lx\n",
3142 LOWORD(lParam
),wParam
,lParam
);
3145 EndDialog(hDlg
, TRUE
);
3149 EndDialog(hDlg
, FALSE
);
3152 case psh3
: /* Printer... */
3153 pagesetup_change_printer_dialog(hDlg
, data
);
3156 case rad1
: /* Portrait */
3157 case rad2
: /* Landscape */
3158 if((id
== rad1
&& pagesetup_get_orientation(data
) == DMORIENT_LANDSCAPE
) ||
3159 (id
== rad2
&& pagesetup_get_orientation(data
) == DMORIENT_PORTRAIT
))
3161 pagesetup_set_orientation(data
, (id
== rad1
) ? DMORIENT_PORTRAIT
: DMORIENT_LANDSCAPE
);
3162 pagesetup_update_papersize(data
);
3163 rotate_rect(pagesetup_get_margin_rect(data
), (id
== rad2
));
3164 update_margin_edits(hDlg
, data
, 0);
3165 pagesetup_change_preview(data
);
3168 case cmb1
: /* Printer combo */
3169 if(msg
== CBN_SELCHANGE
)
3172 GetDlgItemTextW(hDlg
, id
, name
, sizeof(name
) / sizeof(name
[0]));
3173 pagesetup_change_printer(name
, data
);
3174 pagesetup_init_combos(hDlg
, data
);
3177 case cmb2
: /* Paper combo */
3178 if(msg
== CBN_SELCHANGE
)
3180 DWORD paperword
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETITEMDATA
,
3181 SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0), 0);
3182 if (paperword
!= CB_ERR
)
3184 pagesetup_set_papersize(data
, paperword
);
3185 pagesetup_update_papersize(data
);
3186 pagesetup_change_preview(data
);
3188 FIXME("could not get dialog text for papersize cmbbox?\n");
3191 case cmb3
: /* Paper Source */
3192 if(msg
== CBN_SELCHANGE
)
3194 WORD source
= SendDlgItemMessageW(hDlg
, cmb3
, CB_GETITEMDATA
,
3195 SendDlgItemMessageW(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0), 0);
3196 pagesetup_set_defaultsource(data
, source
);
3199 case psh2
: /* Printer Properties button */
3200 pagesetup_printer_properties(hDlg
, data
);
3206 margin_edit_notification(hDlg
, data
, msg
, id
);
3209 InvalidateRect(GetDlgItem(hDlg
, rct1
), NULL
, TRUE
);
3213 /***********************************************************************
3214 * default_page_paint_hook
3215 * Default hook paint procedure that receives WM_PSD_* messages from the dialog box
3216 * whenever the sample page is redrawn.
3218 static UINT_PTR
default_page_paint_hook(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
,
3219 const pagesetup_data
*data
)
3221 LPRECT lprc
= (LPRECT
) lParam
;
3222 HDC hdc
= (HDC
) wParam
;
3225 HFONT hfont
, holdfont
;
3227 TRACE("uMsg: WM_USER+%d\n",uMsg
-WM_USER
);
3228 /* Call user paint hook if enable */
3229 if (pagesetup_get_flags(data
) & PSD_ENABLEPAGEPAINTHOOK
)
3230 if (pagesetup_get_hook(data
, page_paint_hook
)(hwndDlg
, uMsg
, wParam
, lParam
))
3234 /* LPPAGESETUPDLG in lParam */
3235 case WM_PSD_PAGESETUPDLG
:
3236 /* Inform about the sample page rectangle */
3237 case WM_PSD_FULLPAGERECT
:
3238 /* Inform about the margin rectangle */
3239 case WM_PSD_MINMARGINRECT
:
3242 /* Draw dashed rectangle showing margins */
3243 case WM_PSD_MARGINRECT
:
3244 hpen
= CreatePen(PS_DASH
, 1, GetSysColor(COLOR_3DSHADOW
));
3245 holdpen
= SelectObject(hdc
, hpen
);
3246 Rectangle(hdc
, lprc
->left
, lprc
->top
, lprc
->right
, lprc
->bottom
);
3247 DeleteObject(SelectObject(hdc
, holdpen
));
3249 /* Draw the fake document */
3250 case WM_PSD_GREEKTEXTRECT
:
3251 /* select a nice scalable font, because we want the text really small */
3252 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, sizeof(lf
), &lf
, 0);
3253 lf
.lfHeight
= 6; /* value chosen based on visual effect */
3254 hfont
= CreateFontIndirectW(&lf
);
3255 holdfont
= SelectObject(hdc
, hfont
);
3257 /* if text not loaded, then do so now */
3258 if (wszFakeDocumentText
[0] == '\0')
3259 LoadStringW(COMDLG32_hInstance
,
3261 wszFakeDocumentText
,
3262 sizeof(wszFakeDocumentText
)/sizeof(wszFakeDocumentText
[0]));
3264 oldbkmode
= SetBkMode(hdc
, TRANSPARENT
);
3265 DrawTextW(hdc
, wszFakeDocumentText
, -1, lprc
, DT_TOP
|DT_LEFT
|DT_NOPREFIX
|DT_WORDBREAK
);
3266 SetBkMode(hdc
, oldbkmode
);
3268 DeleteObject(SelectObject(hdc
, holdfont
));
3271 /* Envelope stamp */
3272 case WM_PSD_ENVSTAMPRECT
:
3273 /* Return address */
3274 case WM_PSD_YAFULLPAGERECT
:
3275 FIXME("envelope/stamp is not implemented\n");
3278 FIXME("Unknown message %x\n",uMsg
);
3284 /***********************************************************************
3286 * The main paint procedure for the PageSetupDlg function.
3287 * The Page Setup dialog box includes an image of a sample page that shows how
3288 * the user's selections affect the appearance of the printed output.
3289 * The image consists of a rectangle that represents the selected paper
3290 * or envelope type, with a dotted-line rectangle representing
3291 * the current margins, and partial (Greek text) characters
3292 * to show how text looks on the printed page.
3294 * The following messages in the order sends to user hook procedure:
3295 * WM_PSD_PAGESETUPDLG Draw the contents of the sample page
3296 * WM_PSD_FULLPAGERECT Inform about the bounding rectangle
3297 * WM_PSD_MINMARGINRECT Inform about the margin rectangle (min margin?)
3298 * WM_PSD_MARGINRECT Draw the margin rectangle
3299 * WM_PSD_GREEKTEXTRECT Draw the Greek text inside the margin rectangle
3300 * If any of first three messages returns TRUE, painting done.
3303 * hWnd [in] Handle to the Page Setup dialog box
3304 * uMsg [in] Received message
3307 * WM_PSD_ENVSTAMPRECT Draw in the envelope-stamp rectangle (for envelopes only)
3308 * WM_PSD_YAFULLPAGERECT Draw the return address portion (for envelopes and other paper sizes)
3311 * FALSE if all done correctly
3316 static LRESULT CALLBACK
3317 PRINTDLG_PagePaintProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3320 RECT rcClient
, rcMargin
;
3323 HBRUSH hbrush
, holdbrush
;
3324 pagesetup_data
*data
;
3325 int papersize
=0, orientation
=0; /* FIXME: set this values for user paint hook */
3326 double scalx
, scaly
;
3328 if (uMsg
!= WM_PAINT
)
3329 return CallWindowProcA(lpfnStaticWndProc
, hWnd
, uMsg
, wParam
, lParam
);
3331 /* Processing WM_PAINT message */
3332 data
= GetPropW(hWnd
, pagesetupdlg_prop
);
3334 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3337 if (default_page_paint_hook(hWnd
, WM_PSD_PAGESETUPDLG
, MAKELONG(papersize
, orientation
),
3338 pagesetup_get_dlg_struct(data
), data
))
3341 hdc
= BeginPaint(hWnd
, &ps
);
3342 GetClientRect(hWnd
, &rcClient
);
3344 scalx
= rcClient
.right
/ (double)pagesetup_get_papersize_pt(data
)->x
;
3345 scaly
= rcClient
.bottom
/ (double)pagesetup_get_papersize_pt(data
)->y
;
3346 rcMargin
= rcClient
;
3348 rcMargin
.left
+= pagesetup_get_margin_rect(data
)->left
* scalx
;
3349 rcMargin
.top
+= pagesetup_get_margin_rect(data
)->top
* scaly
;
3350 rcMargin
.right
-= pagesetup_get_margin_rect(data
)->right
* scalx
;
3351 rcMargin
.bottom
-= pagesetup_get_margin_rect(data
)->bottom
* scaly
;
3353 /* if the space is too small then we make sure to not draw anything */
3354 rcMargin
.left
= min(rcMargin
.left
, rcMargin
.right
);
3355 rcMargin
.top
= min(rcMargin
.top
, rcMargin
.bottom
);
3357 if (!default_page_paint_hook(hWnd
, WM_PSD_FULLPAGERECT
, (WPARAM
)hdc
, (LPARAM
)&rcClient
, data
) &&
3358 !default_page_paint_hook(hWnd
, WM_PSD_MINMARGINRECT
, (WPARAM
)hdc
, (LPARAM
)&rcMargin
, data
) )
3360 /* fill background */
3361 hbrush
= GetSysColorBrush(COLOR_3DHIGHLIGHT
);
3362 FillRect(hdc
, &rcClient
, hbrush
);
3363 holdbrush
= SelectObject(hdc
, hbrush
);
3365 hpen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DSHADOW
));
3366 holdpen
= SelectObject(hdc
, hpen
);
3368 /* paint left edge */
3369 MoveToEx(hdc
, rcClient
.left
, rcClient
.top
, NULL
);
3370 LineTo(hdc
, rcClient
.left
, rcClient
.bottom
-1);
3372 /* paint top edge */
3373 MoveToEx(hdc
, rcClient
.left
, rcClient
.top
, NULL
);
3374 LineTo(hdc
, rcClient
.right
, rcClient
.top
);
3376 hpen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DDKSHADOW
));
3377 DeleteObject(SelectObject(hdc
, hpen
));
3379 /* paint right edge */
3380 MoveToEx(hdc
, rcClient
.right
-1, rcClient
.top
, NULL
);
3381 LineTo(hdc
, rcClient
.right
-1, rcClient
.bottom
);
3383 /* paint bottom edge */
3384 MoveToEx(hdc
, rcClient
.left
, rcClient
.bottom
-1, NULL
);
3385 LineTo(hdc
, rcClient
.right
, rcClient
.bottom
-1);
3387 DeleteObject(SelectObject(hdc
, holdpen
));
3388 DeleteObject(SelectObject(hdc
, holdbrush
));
3390 default_page_paint_hook(hWnd
, WM_PSD_MARGINRECT
, (WPARAM
)hdc
, (LPARAM
)&rcMargin
, data
);
3392 /* give text a bit of a space from the frame */
3395 rcMargin
.right
-= 2;
3396 rcMargin
.bottom
-= 2;
3398 /* if the space is too small then we make sure to not draw anything */
3399 rcMargin
.left
= min(rcMargin
.left
, rcMargin
.right
);
3400 rcMargin
.top
= min(rcMargin
.top
, rcMargin
.bottom
);
3402 default_page_paint_hook(hWnd
, WM_PSD_GREEKTEXTRECT
, (WPARAM
)hdc
, (LPARAM
)&rcMargin
, data
);
3405 EndPaint(hWnd
, &ps
);
3409 /*******************************************************
3410 * The margin edit controls are subclassed to filter
3411 * anything other than numbers and the decimal separator.
3413 static LRESULT CALLBACK
pagesetup_margin_editproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3418 WCHAR decimal
= get_decimal_sep();
3419 WCHAR wc
= (WCHAR
)wparam
;
3420 if(!isdigitW(wc
) && wc
!= decimal
&& wc
!= VK_BACK
) return 0;
3422 return CallWindowProcW(edit_wndproc
, hwnd
, msg
, wparam
, lparam
);
3425 static void subclass_margin_edits(HWND hDlg
)
3430 for(id
= edt4
; id
<= edt7
; id
++)
3432 old_proc
= (WNDPROC
)SetWindowLongPtrW(GetDlgItem(hDlg
, id
),
3434 (ULONG_PTR
)pagesetup_margin_editproc
);
3435 InterlockedCompareExchangePointer((void**)&edit_wndproc
, old_proc
, NULL
);
3439 /***********************************************************************
3440 * pagesetup_dlg_proc
3442 * Message handler for PageSetupDlg
3444 static INT_PTR CALLBACK
pagesetup_dlg_proc(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3446 pagesetup_data
*data
;
3447 INT_PTR res
= FALSE
;
3450 if (uMsg
== WM_INITDIALOG
) { /*Init dialog*/
3451 data
= (pagesetup_data
*)lParam
;
3454 hDrawWnd
= GetDlgItem(hDlg
, rct1
);
3455 TRACE("set property to %p\n", data
);
3456 SetPropW(hDlg
, pagesetupdlg_prop
, data
);
3457 SetPropW(hDrawWnd
, pagesetupdlg_prop
, data
);
3458 GetWindowRect(hDrawWnd
, &data
->rtDrawRect
); /* Calculating rect in client coordinates where paper draws */
3459 ScreenToClient(hDlg
, (LPPOINT
)&data
->rtDrawRect
);
3460 ScreenToClient(hDlg
, (LPPOINT
)(&data
->rtDrawRect
.right
));
3461 lpfnStaticWndProc
= (WNDPROC
)SetWindowLongPtrW(
3464 (ULONG_PTR
)PRINTDLG_PagePaintProc
);
3466 /* FIXME: Paint hook. Must it be at begin of initialization or at end? */
3468 if (pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPHOOK
)
3470 if (!pagesetup_get_hook(data
, page_setup_hook
)(hDlg
, uMsg
, wParam
,
3471 pagesetup_get_dlg_struct(data
)))
3472 FIXME("Setup page hook failed?\n");
3475 /* if printer button disabled */
3476 if (pagesetup_get_flags(data
) & PSD_DISABLEPRINTER
)
3477 EnableWindow(GetDlgItem(hDlg
, psh3
), FALSE
);
3478 /* if margin edit boxes disabled */
3479 if (pagesetup_get_flags(data
) & PSD_DISABLEMARGINS
)
3481 EnableWindow(GetDlgItem(hDlg
, edt4
), FALSE
);
3482 EnableWindow(GetDlgItem(hDlg
, edt5
), FALSE
);
3483 EnableWindow(GetDlgItem(hDlg
, edt6
), FALSE
);
3484 EnableWindow(GetDlgItem(hDlg
, edt7
), FALSE
);
3487 /* Set orientation radiobuttons properly */
3488 pagesetup_update_orientation_buttons(hDlg
, data
);
3490 /* if orientation disabled */
3491 if (pagesetup_get_flags(data
) & PSD_DISABLEORIENTATION
)
3493 EnableWindow(GetDlgItem(hDlg
,rad1
),FALSE
);
3494 EnableWindow(GetDlgItem(hDlg
,rad2
),FALSE
);
3497 /* We fill them out enabled or not */
3498 if (!(pagesetup_get_flags(data
) & PSD_MARGINS
))
3500 /* default is 1 inch */
3501 LONG size
= thousandths_inch_to_size(data
, 1000);
3502 SetRect(pagesetup_get_margin_rect(data
), size
, size
, size
, size
);
3504 update_margin_edits(hDlg
, data
, 0);
3505 subclass_margin_edits(hDlg
);
3506 set_margin_groupbox_title(hDlg
, data
);
3508 /* if paper disabled */
3509 if (pagesetup_get_flags(data
) & PSD_DISABLEPAPER
)
3511 EnableWindow(GetDlgItem(hDlg
,cmb2
),FALSE
);
3512 EnableWindow(GetDlgItem(hDlg
,cmb3
),FALSE
);
3515 /* filling combos: printer, paper, source. selecting current printer (from DEVMODEA) */
3516 pagesetup_init_combos(hDlg
, data
);
3517 pagesetup_update_papersize(data
);
3518 pagesetup_set_defaultsource(data
, DMBIN_FORMSOURCE
); /* FIXME: This is the auto select bin. Is this correct? */
3520 /* Drawing paper prev */
3521 pagesetup_change_preview(data
);
3524 data
= GetPropW(hDlg
, pagesetupdlg_prop
);
3527 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3530 if (pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPHOOK
)
3532 res
= pagesetup_get_hook(data
, page_setup_hook
)(hDlg
, uMsg
, wParam
, lParam
);
3533 if (res
) return res
;
3538 return pagesetup_wm_command(hDlg
, wParam
, lParam
, data
);
3543 static WCHAR
*get_default_printer(void)
3548 GetDefaultPrinterW(NULL
, &len
);
3551 name
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3552 GetDefaultPrinterW(name
, &len
);
3557 static void pagesetup_dump_dlg_struct(pagesetup_data
*data
)
3559 if(TRACE_ON(commdlg
))
3561 char flagstr
[1000] = "";
3562 const struct pd_flags
*pflag
= psd_flags
;
3563 for( ; pflag
->name
; pflag
++)
3565 if(pagesetup_get_flags(data
) & pflag
->flag
)
3567 strcat(flagstr
, pflag
->name
);
3568 strcat(flagstr
, "|");
3571 TRACE("%s: (%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3572 "hinst %p, flags %08x (%s)\n",
3573 data
->unicode
? "unicode" : "ansi",
3574 data
->u
.dlgw
, data
->u
.dlgw
->hwndOwner
, data
->u
.dlgw
->hDevMode
,
3575 data
->u
.dlgw
->hDevNames
, data
->u
.dlgw
->hInstance
,
3576 pagesetup_get_flags(data
), flagstr
);
3580 static void *pagesetup_get_template(pagesetup_data
*data
)
3583 HGLOBAL tmpl_handle
;
3585 if(pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPTEMPLATEHANDLE
)
3587 tmpl_handle
= data
->u
.dlgw
->hPageSetupTemplate
;
3589 else if(pagesetup_get_flags(data
) & PSD_ENABLEPAGESETUPTEMPLATE
)
3592 res
= FindResourceW(data
->u
.dlgw
->hInstance
,
3593 data
->u
.dlgw
->lpPageSetupTemplateName
, MAKEINTRESOURCEW(RT_DIALOG
));
3595 res
= FindResourceA(data
->u
.dlga
->hInstance
,
3596 data
->u
.dlga
->lpPageSetupTemplateName
, MAKEINTRESOURCEA(RT_DIALOG
));
3597 tmpl_handle
= LoadResource(data
->u
.dlgw
->hInstance
, res
);
3601 res
= FindResourceW(COMDLG32_hInstance
, MAKEINTRESOURCEW(PAGESETUPDLGORD
),
3602 MAKEINTRESOURCEW(RT_DIALOG
));
3603 tmpl_handle
= LoadResource(COMDLG32_hInstance
, res
);
3605 return LockResource(tmpl_handle
);
3608 static BOOL
pagesetup_common(pagesetup_data
*data
)
3613 if(!pagesetup_get_dlg_struct(data
))
3615 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
3619 pagesetup_dump_dlg_struct(data
);
3621 if(data
->u
.dlgw
->lStructSize
!= sizeof(PAGESETUPDLGW
))
3623 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
3627 if ((pagesetup_get_flags(data
) & PSD_ENABLEPAGEPAINTHOOK
) &&
3628 (pagesetup_get_hook(data
, page_paint_hook
) == NULL
))
3630 COMDLG32_SetCommDlgExtendedError(CDERR_NOHOOK
);
3634 if(!(pagesetup_get_flags(data
) & (PSD_INTHOUSANDTHSOFINCHES
| PSD_INHUNDREDTHSOFMILLIMETERS
)))
3635 data
->u
.dlgw
->Flags
|= is_default_metric() ?
3636 PSD_INHUNDREDTHSOFMILLIMETERS
: PSD_INTHOUSANDTHSOFINCHES
;
3638 if (!data
->u
.dlgw
->hDevMode
|| !data
->u
.dlgw
->hDevNames
)
3640 WCHAR
*def
= get_default_printer();
3643 if (!(pagesetup_get_flags(data
) & PSD_NOWARNING
))
3646 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEFAULT_PRINTER
, errstr
, 255);
3647 MessageBoxW(data
->u
.dlgw
->hwndOwner
, errstr
, 0, MB_OK
| MB_ICONERROR
);
3649 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
3652 pagesetup_change_printer(def
, data
);
3653 HeapFree(GetProcessHeap(), 0, def
);
3656 if (pagesetup_get_flags(data
) & PSD_RETURNDEFAULT
)
3658 pagesetup_update_papersize(data
);
3662 tmpl
= pagesetup_get_template(data
);
3664 ret
= DialogBoxIndirectParamW(data
->u
.dlgw
->hInstance
, tmpl
,
3665 data
->u
.dlgw
->hwndOwner
,
3666 pagesetup_dlg_proc
, (LPARAM
)data
) > 0;
3670 /***********************************************************************
3671 * PageSetupDlgA (COMDLG32.@)
3673 * Displays the PAGE SETUP dialog box, which enables the user to specify
3674 * specific properties of a printed page such as
3675 * size, source, orientation and the width of the page margins.
3678 * setupdlg [IO] PAGESETUPDLGA struct
3681 * TRUE if the user pressed the OK button
3682 * FALSE if the user cancelled the window or an error occurred
3685 * The values of hDevMode and hDevNames are filled on output and can be
3686 * changed in PAGESETUPDLG when they are passed in PageSetupDlg.
3689 BOOL WINAPI
PageSetupDlgA(LPPAGESETUPDLGA setupdlg
)
3691 pagesetup_data data
;
3693 data
.unicode
= FALSE
;
3694 data
.u
.dlga
= setupdlg
;
3696 return pagesetup_common(&data
);
3699 /***********************************************************************
3700 * PageSetupDlgW (COMDLG32.@)
3702 * See PageSetupDlgA.
3704 BOOL WINAPI
PageSetupDlgW(LPPAGESETUPDLGW setupdlg
)
3706 pagesetup_data data
;
3708 data
.unicode
= TRUE
;
3709 data
.u
.dlgw
= setupdlg
;
3711 return pagesetup_common(&data
);
3714 /***********************************************************************
3715 * PrintDlgExA (COMDLG32.@)
3723 HRESULT WINAPI
PrintDlgExA(LPPRINTDLGEXA lppd
)
3726 FIXME("(%p) stub\n", lppd
);
3727 if ((lppd
== NULL
) || (lppd
->lStructSize
!= sizeof(PRINTDLGEXA
))) {
3728 return E_INVALIDARG
;
3731 if (!IsWindow(lppd
->hwndOwner
)) {
3738 /***********************************************************************
3739 * PrintDlgExW (COMDLG32.@)
3741 * Display the property sheet style PRINT dialog box
3744 * lppd [IO] ptr to PRINTDLGEX struct
3748 * Failure: One of the following COM error codes:
3749 * E_OUTOFMEMORY Insufficient memory.
3750 * E_INVALIDARG One or more arguments are invalid.
3751 * E_POINTER Invalid pointer.
3752 * E_HANDLE Invalid handle.
3753 * E_FAIL Unspecified error.
3756 * This Dialog enables the user to specify specific properties of the print job.
3757 * The property sheet can also have additional application-specific and
3758 * driver-specific property pages.
3761 * Not fully implemented
3764 HRESULT WINAPI
PrintDlgExW(LPPRINTDLGEXW lppd
)
3769 FIXME("(%p) not fully implemented\n", lppd
);
3771 if ((lppd
== NULL
) || (lppd
->lStructSize
!= sizeof(PRINTDLGEXW
))) {
3772 return E_INVALIDARG
;
3775 if (!IsWindow(lppd
->hwndOwner
)) {
3779 if (lppd
->Flags
& PD_RETURNDEFAULT
) {
3780 PRINTER_INFO_2W
*pbuf
;
3781 DRIVER_INFO_2W
*dbuf
;
3783 DWORD needed
= 1024;
3786 if (lppd
->hDevMode
|| lppd
->hDevNames
) {
3787 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
3788 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
3789 return E_INVALIDARG
;
3791 if (!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
3792 WARN("Can't find default printer\n");
3793 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
3797 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
3798 bRet
= GetPrinterW(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
3799 if (!bRet
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
3800 HeapFree(GetProcessHeap(), 0, pbuf
);
3801 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
3802 bRet
= GetPrinterW(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
3805 HeapFree(GetProcessHeap(), 0, pbuf
);
3811 dbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
3812 bRet
= GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
);
3813 if (!bRet
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
3814 HeapFree(GetProcessHeap(), 0, dbuf
);
3815 dbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
3816 bRet
= GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
);
3819 ERR("GetPrinterDriverW failed, last error %d, fix your config for printer %s!\n",
3820 GetLastError(), debugstr_w(pbuf
->pPrinterName
));
3821 HeapFree(GetProcessHeap(), 0, dbuf
);
3822 HeapFree(GetProcessHeap(), 0, pbuf
);
3823 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
3829 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
3833 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
3834 pbuf
->pDevMode
->dmDriverExtra
);
3835 if (lppd
->hDevMode
) {
3836 ptr
= GlobalLock(lppd
->hDevMode
);
3838 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
3839 pbuf
->pDevMode
->dmDriverExtra
);
3840 GlobalUnlock(lppd
->hDevMode
);
3844 HeapFree(GetProcessHeap(), 0, pbuf
);
3845 HeapFree(GetProcessHeap(), 0, dbuf
);