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
29 #define NONAMELESSUNION
30 #define NONAMELESSSTRUCT
38 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(commdlg
);
49 /* Yes these constants are the same, but we're just copying win98 */
50 #define UPDOWN_ID 0x270f
51 #define MAX_COPIES 9999
54 static const struct pd_flags psd_flags
[] = {
55 {PSD_MINMARGINS
,"PSD_MINMARGINS"},
56 {PSD_MARGINS
,"PSD_MARGINS"},
57 {PSD_INTHOUSANDTHSOFINCHES
,"PSD_INTHOUSANDTHSOFINCHES"},
58 {PSD_INHUNDREDTHSOFMILLIMETERS
,"PSD_INHUNDREDTHSOFMILLIMETERS"},
59 {PSD_DISABLEMARGINS
,"PSD_DISABLEMARGINS"},
60 {PSD_DISABLEPRINTER
,"PSD_DISABLEPRINTER"},
61 {PSD_NOWARNING
,"PSD_NOWARNING"},
62 {PSD_DISABLEORIENTATION
,"PSD_DISABLEORIENTATION"},
63 {PSD_RETURNDEFAULT
,"PSD_RETURNDEFAULT"},
64 {PSD_DISABLEPAPER
,"PSD_DISABLEPAPER"},
65 {PSD_SHOWHELP
,"PSD_SHOWHELP"},
66 {PSD_ENABLEPAGESETUPHOOK
,"PSD_ENABLEPAGESETUPHOOK"},
67 {PSD_ENABLEPAGESETUPTEMPLATE
,"PSD_ENABLEPAGESETUPTEMPLATE"},
68 {PSD_ENABLEPAGESETUPTEMPLATEHANDLE
,"PSD_ENABLEPAGESETUPTEMPLATEHANDLE"},
69 {PSD_ENABLEPAGEPAINTHOOK
,"PSD_ENABLEPAGEPAINTHOOK"},
70 {PSD_DISABLEPAGEPAINTING
,"PSD_DISABLEPAGEPAINTING"},
74 /* address of wndproc for subclassed Static control */
75 static WNDPROC lpfnStaticWndProc
;
76 /* the text of the fake document to render for the Page Setup dialog */
77 static WCHAR wszFakeDocumentText
[1024];
78 static const WCHAR pd32_collateW
[] = { 'P', 'D', '3', '2', '_', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
79 static const WCHAR pd32_nocollateW
[] = { 'P', 'D', '3', '2', '_', 'N', 'O', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
80 static const WCHAR pd32_portraitW
[] = { 'P', 'D', '3', '2', '_', 'P', 'O', 'R', 'T', 'R', 'A', 'I', 'T', 0 };
81 static const WCHAR pd32_landscapeW
[] = { 'P', 'D', '3', '2', '_', 'L', 'A', 'N', 'D', 'S', 'C', 'A', 'P', 'E', 0 };
82 static const WCHAR printdlg_prop
[] = {'_','_','W','I','N','E','_','P','R','I','N','T','D','L','G','D','A','T','A',0};
83 static const WCHAR pagesetupdlg_prop
[] = { '_', '_', 'W', 'I', 'N', 'E', '_', 'P', 'A', 'G', 'E',
84 'S', 'E', 'T', 'U', 'P', 'D', 'L', 'G', 'D', 'A', 'T', 'A', 0 };
86 /***********************************************************************
87 * PRINTDLG_OpenDefaultPrinter
89 * Returns a winspool printer handle to the default printer in *hprn
90 * Caller must call ClosePrinter on the handle
92 * Returns TRUE on success else FALSE
94 BOOL
PRINTDLG_OpenDefaultPrinter(HANDLE
*hprn
)
97 DWORD dwBufLen
= sizeof(buf
) / sizeof(buf
[0]);
99 if(!GetDefaultPrinterW(buf
, &dwBufLen
))
101 res
= OpenPrinterW(buf
, hprn
, NULL
);
103 WARN("Could not open printer %s\n", debugstr_w(buf
));
107 /***********************************************************************
108 * PRINTDLG_SetUpPrinterListCombo
110 * Initializes printer list combox.
111 * hDlg: HWND of dialog
112 * id: Control id of combo
113 * name: Name of printer to select
115 * Initializes combo with list of available printers. Selects printer 'name'
116 * If name is NULL or does not exist select the default printer.
118 * Returns number of printers added to list.
120 INT
PRINTDLG_SetUpPrinterListComboA(HWND hDlg
, UINT id
, LPCSTR name
)
124 LPPRINTER_INFO_2A pi
;
125 EnumPrintersA(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
126 pi
= HeapAlloc(GetProcessHeap(), 0, needed
);
127 EnumPrintersA(PRINTER_ENUM_LOCAL
, NULL
, 2, (LPBYTE
)pi
, needed
, &needed
,
130 SendDlgItemMessageA(hDlg
, id
, CB_RESETCONTENT
, 0, 0);
132 for(i
= 0; i
< num
; i
++) {
133 SendDlgItemMessageA(hDlg
, id
, CB_ADDSTRING
, 0,
134 (LPARAM
)pi
[i
].pPrinterName
);
136 HeapFree(GetProcessHeap(), 0, pi
);
138 (i
= SendDlgItemMessageA(hDlg
, id
, CB_FINDSTRINGEXACT
, -1,
139 (LPARAM
)name
)) == CB_ERR
) {
142 DWORD dwBufLen
= sizeof(buf
);
144 WARN("Can't find %s in printer list so trying to find default\n",
146 if(!GetDefaultPrinterA(buf
, &dwBufLen
))
148 i
= SendDlgItemMessageA(hDlg
, id
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buf
);
150 FIXME("Can't find default printer in printer list\n");
152 SendDlgItemMessageA(hDlg
, id
, CB_SETCURSEL
, i
, 0);
156 static INT
PRINTDLG_SetUpPrinterListComboW(HWND hDlg
, UINT id
, LPCWSTR name
)
160 LPPRINTER_INFO_2W pi
;
161 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
162 pi
= HeapAlloc(GetProcessHeap(), 0, needed
);
163 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, (LPBYTE
)pi
, needed
, &needed
,
166 for(i
= 0; i
< num
; i
++) {
167 SendDlgItemMessageW(hDlg
, id
, CB_ADDSTRING
, 0,
168 (LPARAM
)pi
[i
].pPrinterName
);
170 HeapFree(GetProcessHeap(), 0, pi
);
172 (i
= SendDlgItemMessageW(hDlg
, id
, CB_FINDSTRINGEXACT
, -1,
173 (LPARAM
)name
)) == CB_ERR
) {
175 DWORD dwBufLen
= sizeof(buf
)/sizeof(buf
[0]);
177 WARN("Can't find %s in printer list so trying to find default\n",
179 if(!GetDefaultPrinterW(buf
, &dwBufLen
))
181 i
= SendDlgItemMessageW(hDlg
, id
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buf
);
183 TRACE("Can't find default printer in printer list\n");
185 SendDlgItemMessageW(hDlg
, id
, CB_SETCURSEL
, i
, 0);
189 /***********************************************************************
190 * PRINTDLG_CreateDevNames [internal]
193 * creates a DevNames structure.
195 * (NB. when we handle unicode the offsets will be in wchars).
197 static BOOL
PRINTDLG_CreateDevNames(HGLOBAL
*hmem
, const char* DeviceDriverName
,
198 const char* DeviceName
, const char* OutputPort
)
201 char* pDevNamesSpace
;
203 LPDEVNAMES lpDevNames
;
205 DWORD dwBufLen
= sizeof(buf
);
207 size
= strlen(DeviceDriverName
) + 1
208 + strlen(DeviceName
) + 1
209 + strlen(OutputPort
) + 1
213 *hmem
= GlobalReAlloc(*hmem
, size
, GMEM_MOVEABLE
);
215 *hmem
= GlobalAlloc(GMEM_MOVEABLE
, size
);
219 pDevNamesSpace
= GlobalLock(*hmem
);
220 lpDevNames
= (LPDEVNAMES
) pDevNamesSpace
;
222 pTempPtr
= pDevNamesSpace
+ sizeof(DEVNAMES
);
223 strcpy(pTempPtr
, DeviceDriverName
);
224 lpDevNames
->wDriverOffset
= pTempPtr
- pDevNamesSpace
;
226 pTempPtr
+= strlen(DeviceDriverName
) + 1;
227 strcpy(pTempPtr
, DeviceName
);
228 lpDevNames
->wDeviceOffset
= pTempPtr
- pDevNamesSpace
;
230 pTempPtr
+= strlen(DeviceName
) + 1;
231 strcpy(pTempPtr
, OutputPort
);
232 lpDevNames
->wOutputOffset
= pTempPtr
- pDevNamesSpace
;
234 GetDefaultPrinterA(buf
, &dwBufLen
);
235 lpDevNames
->wDefault
= (strcmp(buf
, DeviceName
) == 0) ? 1 : 0;
240 static BOOL
PRINTDLG_CreateDevNamesW(HGLOBAL
*hmem
, LPCWSTR DeviceDriverName
,
241 LPCWSTR DeviceName
, LPCWSTR OutputPort
)
244 LPWSTR pDevNamesSpace
;
246 LPDEVNAMES lpDevNames
;
248 DWORD dwBufLen
= sizeof(bufW
) / sizeof(WCHAR
);
250 size
= sizeof(WCHAR
)*lstrlenW(DeviceDriverName
) + 2
251 + sizeof(WCHAR
)*lstrlenW(DeviceName
) + 2
252 + sizeof(WCHAR
)*lstrlenW(OutputPort
) + 2
256 *hmem
= GlobalReAlloc(*hmem
, size
, GMEM_MOVEABLE
);
258 *hmem
= GlobalAlloc(GMEM_MOVEABLE
, size
);
262 pDevNamesSpace
= GlobalLock(*hmem
);
263 lpDevNames
= (LPDEVNAMES
) pDevNamesSpace
;
265 pTempPtr
= (LPWSTR
)((LPDEVNAMES
)pDevNamesSpace
+ 1);
266 lstrcpyW(pTempPtr
, DeviceDriverName
);
267 lpDevNames
->wDriverOffset
= pTempPtr
- pDevNamesSpace
;
269 pTempPtr
+= lstrlenW(DeviceDriverName
) + 1;
270 lstrcpyW(pTempPtr
, DeviceName
);
271 lpDevNames
->wDeviceOffset
= pTempPtr
- pDevNamesSpace
;
273 pTempPtr
+= lstrlenW(DeviceName
) + 1;
274 lstrcpyW(pTempPtr
, OutputPort
);
275 lpDevNames
->wOutputOffset
= pTempPtr
- pDevNamesSpace
;
277 GetDefaultPrinterW(bufW
, &dwBufLen
);
278 lpDevNames
->wDefault
= (lstrcmpW(bufW
, DeviceName
) == 0) ? 1 : 0;
283 /***********************************************************************
284 * PRINTDLG_UpdatePrintDlg [internal]
287 * updates the PrintDlg structure for return values.
290 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
291 * TRUE if successful.
293 static BOOL
PRINTDLG_UpdatePrintDlgA(HWND hDlg
,
294 PRINT_PTRA
* PrintStructures
)
296 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
297 PDEVMODEA lpdm
= PrintStructures
->lpDevMode
;
298 LPPRINTER_INFO_2A pi
= PrintStructures
->lpPrinterInfo
;
302 FIXME("No lpdm ptr?\n");
307 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
308 /* check whether nFromPage and nToPage are within range defined by
309 * nMinPage and nMaxPage
311 if (IsDlgButtonChecked(hDlg
, rad3
) == BST_CHECKED
) { /* Pages */
315 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
316 nToPage
= GetDlgItemInt(hDlg
, edt2
, &translated
, FALSE
);
318 /* if no ToPage value is entered, use the FromPage value */
319 if(!translated
) nToPage
= nFromPage
;
321 if (nFromPage
< lppd
->nMinPage
|| nFromPage
> lppd
->nMaxPage
||
322 nToPage
< lppd
->nMinPage
|| nToPage
> lppd
->nMaxPage
) {
323 WCHAR resourcestr
[256];
324 WCHAR resultstr
[256];
325 LoadStringW(COMDLG32_hInstance
, PD32_INVALID_PAGE_RANGE
, resourcestr
, 255);
326 wsprintfW(resultstr
,resourcestr
, lppd
->nMinPage
, lppd
->nMaxPage
);
327 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
, resourcestr
, 255);
328 MessageBoxW(hDlg
, resultstr
, resourcestr
, MB_OK
| MB_ICONWARNING
);
331 lppd
->nFromPage
= nFromPage
;
332 lppd
->nToPage
= nToPage
;
333 lppd
->Flags
|= PD_PAGENUMS
;
336 lppd
->Flags
&= ~PD_PAGENUMS
;
338 if (IsDlgButtonChecked(hDlg
, rad2
) == BST_CHECKED
) /* Selection */
339 lppd
->Flags
|= PD_SELECTION
;
341 lppd
->Flags
&= ~PD_SELECTION
;
343 if (IsDlgButtonChecked(hDlg
, chx1
) == BST_CHECKED
) {/* Print to file */
344 static char file
[] = "FILE:";
345 lppd
->Flags
|= PD_PRINTTOFILE
;
346 pi
->pPortName
= file
;
349 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
) { /* Collate */
350 FIXME("Collate lppd not yet implemented as output\n");
353 /* set PD_Collate and nCopies */
354 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
355 /* The application doesn't support multiple copies or collate...
357 lppd
->Flags
&= ~PD_COLLATE
;
359 /* if the printer driver supports it... store info there
360 * otherwise no collate & multiple copies !
362 if (lpdm
->dmFields
& DM_COLLATE
)
364 (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
);
365 if (lpdm
->dmFields
& DM_COPIES
)
366 lpdm
->u1
.s1
.dmCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
368 /* Application is responsible for multiple copies */
369 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
370 lppd
->Flags
|= PD_COLLATE
;
372 lppd
->Flags
&= ~PD_COLLATE
;
373 lppd
->nCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
374 /* multiple copies already included in the document. Driver must print only one copy */
375 lpdm
->u1
.s1
.dmCopies
= 1;
378 /* Print quality, PrintDlg16 */
379 if(GetDlgItem(hDlg
, cmb1
))
381 HWND hQuality
= GetDlgItem(hDlg
, cmb1
);
382 int Sel
= SendMessageA(hQuality
, CB_GETCURSEL
, 0, 0);
386 LONG dpi
= SendMessageA(hQuality
, CB_GETITEMDATA
, Sel
, 0);
387 lpdm
->dmFields
|= DM_PRINTQUALITY
| DM_YRESOLUTION
;
388 lpdm
->u1
.s1
.dmPrintQuality
= LOWORD(dpi
);
389 lpdm
->dmYResolution
= HIWORD(dpi
);
396 static BOOL
PRINTDLG_UpdatePrintDlgW(HWND hDlg
,
397 PRINT_PTRW
* PrintStructures
)
399 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
400 PDEVMODEW lpdm
= PrintStructures
->lpDevMode
;
401 LPPRINTER_INFO_2W pi
= PrintStructures
->lpPrinterInfo
;
405 FIXME("No lpdm ptr?\n");
410 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
411 /* check whether nFromPage and nToPage are within range defined by
412 * nMinPage and nMaxPage
414 if (IsDlgButtonChecked(hDlg
, rad3
) == BST_CHECKED
) { /* Pages */
418 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
419 nToPage
= GetDlgItemInt(hDlg
, edt2
, &translated
, FALSE
);
421 /* if no ToPage value is entered, use the FromPage value */
422 if(!translated
) nToPage
= nFromPage
;
424 if (nFromPage
< lppd
->nMinPage
|| nFromPage
> lppd
->nMaxPage
||
425 nToPage
< lppd
->nMinPage
|| nToPage
> lppd
->nMaxPage
) {
426 WCHAR resourcestr
[256];
427 WCHAR resultstr
[256];
428 LoadStringW(COMDLG32_hInstance
, PD32_INVALID_PAGE_RANGE
,
430 wsprintfW(resultstr
,resourcestr
, lppd
->nMinPage
, lppd
->nMaxPage
);
431 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
,
433 MessageBoxW(hDlg
, resultstr
, resourcestr
,
434 MB_OK
| MB_ICONWARNING
);
437 lppd
->nFromPage
= nFromPage
;
438 lppd
->nToPage
= nToPage
;
439 lppd
->Flags
|= PD_PAGENUMS
;
442 lppd
->Flags
&= ~PD_PAGENUMS
;
444 if (IsDlgButtonChecked(hDlg
, rad2
) == BST_CHECKED
) /* Selection */
445 lppd
->Flags
|= PD_SELECTION
;
447 lppd
->Flags
&= ~PD_SELECTION
;
449 if (IsDlgButtonChecked(hDlg
, chx1
) == BST_CHECKED
) {/* Print to file */
450 static WCHAR file
[] = {'F','I','L','E',':',0};
451 lppd
->Flags
|= PD_PRINTTOFILE
;
452 pi
->pPortName
= file
;
455 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
) { /* Collate */
456 FIXME("Collate lppd not yet implemented as output\n");
459 /* set PD_Collate and nCopies */
460 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
461 /* The application doesn't support multiple copies or collate...
463 lppd
->Flags
&= ~PD_COLLATE
;
465 /* if the printer driver supports it... store info there
466 * otherwise no collate & multiple copies !
468 if (lpdm
->dmFields
& DM_COLLATE
)
470 (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
);
471 if (lpdm
->dmFields
& DM_COPIES
)
472 lpdm
->u1
.s1
.dmCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
474 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
475 lppd
->Flags
|= PD_COLLATE
;
477 lppd
->Flags
&= ~PD_COLLATE
;
478 lppd
->nCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
484 static BOOL
PRINTDLG_PaperSizeW(
485 PRINTDLGW
*pdlga
,const WCHAR
*PaperSize
,LPPOINT size
489 LPWSTR devname
,portname
;
493 POINT
*points
= NULL
;
496 dn
= GlobalLock(pdlga
->hDevNames
);
497 dm
= GlobalLock(pdlga
->hDevMode
);
498 devname
= ((WCHAR
*)dn
)+dn
->wDeviceOffset
;
499 portname
= ((WCHAR
*)dn
)+dn
->wOutputOffset
;
502 NrOfEntries
= DeviceCapabilitiesW(devname
,portname
,DC_PAPERNAMES
,NULL
,dm
);
504 FIXME("No papernames found for %s/%s\n",debugstr_w(devname
),debugstr_w(portname
));
507 if (NrOfEntries
== -1) {
508 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
512 Names
= HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*NrOfEntries
*64);
513 if (NrOfEntries
!= (ret
=DeviceCapabilitiesW(devname
,portname
,DC_PAPERNAMES
,Names
,dm
))) {
514 FIXME("Number of returned vals %d is not %d\n",NrOfEntries
,ret
);
517 for (i
=0;i
<NrOfEntries
;i
++)
518 if (!lstrcmpW(PaperSize
,Names
+(64*i
)))
520 if (i
==NrOfEntries
) {
521 FIXME("Papersize %s not found in list?\n",debugstr_w(PaperSize
));
524 points
= HeapAlloc(GetProcessHeap(),0,sizeof(points
[0])*NrOfEntries
);
525 if (NrOfEntries
!=(ret
=DeviceCapabilitiesW(devname
,portname
,DC_PAPERSIZE
,(LPWSTR
)points
,dm
))) {
526 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries
,ret
);
529 /* this is _10ths_ of a millimeter */
534 GlobalUnlock(pdlga
->hDevNames
);
535 GlobalUnlock(pdlga
->hDevMode
);
536 HeapFree(GetProcessHeap(),0,Names
);
537 HeapFree(GetProcessHeap(),0,points
);
542 /************************************************************************
543 * PRINTDLG_SetUpPaperComboBox
545 * Initialize either the papersize or inputslot combos of the Printer Setup
546 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
547 * We also try to re-select the old selection.
549 static BOOL
PRINTDLG_SetUpPaperComboBoxA(HWND hDlg
,
562 int fwCapability_Names
;
563 int fwCapability_Words
;
565 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName
,PortName
,nIDComboBox
);
567 /* query the dialog box for the current selected value */
568 Sel
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETCURSEL
, 0, 0);
570 /* we enter here only if a different printer is selected after
571 * the Print Setup dialog is opened. The current settings are
572 * stored into the newly selected printer.
574 oldWord
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
,
577 if (nIDComboBox
== cmb2
)
578 dm
->u1
.s1
.dmPaperSize
= oldWord
;
580 dm
->u1
.s1
.dmDefaultSource
= oldWord
;
584 /* we enter here only when the Print setup dialog is initially
585 * opened. In this case the settings are restored from when
586 * the dialog was last closed.
589 if (nIDComboBox
== cmb2
)
590 oldWord
= dm
->u1
.s1
.dmPaperSize
;
592 oldWord
= dm
->u1
.s1
.dmDefaultSource
;
596 if (nIDComboBox
== cmb2
) {
598 fwCapability_Names
= DC_PAPERNAMES
;
599 fwCapability_Words
= DC_PAPERS
;
603 fwCapability_Names
= DC_BINNAMES
;
604 fwCapability_Words
= DC_BINS
;
607 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
608 fwCapability_Names
, NULL
, dm
);
609 if (NrOfEntries
== 0)
610 WARN("no Name Entries found!\n");
611 else if (NrOfEntries
< 0)
614 if(DeviceCapabilitiesA(PrinterName
, PortName
, fwCapability_Words
, NULL
, dm
)
616 ERR("Number of caps is different\n");
620 Names
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(char)*NamesSize
);
621 Words
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WORD
));
622 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
623 fwCapability_Names
, Names
, dm
);
624 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
625 fwCapability_Words
, (LPSTR
)Words
, dm
);
627 /* reset any current content in the combobox */
628 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_RESETCONTENT
, 0, 0);
630 /* store new content */
631 for (i
= 0; i
< NrOfEntries
; i
++) {
632 DWORD pos
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_ADDSTRING
, 0,
633 (LPARAM
)(&Names
[i
*NamesSize
]) );
634 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_SETITEMDATA
, pos
,
638 /* Look for old selection - can't do this is previous loop since
639 item order will change as more items are added */
641 for (i
= 0; i
< NrOfEntries
; i
++) {
642 if(SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) ==
648 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_SETCURSEL
, Sel
, 0);
650 HeapFree(GetProcessHeap(),0,Words
);
651 HeapFree(GetProcessHeap(),0,Names
);
655 static BOOL
PRINTDLG_SetUpPaperComboBoxW(HWND hDlg
,
657 const WCHAR
* PrinterName
,
658 const WCHAR
* PortName
,
668 int fwCapability_Names
;
669 int fwCapability_Words
;
671 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName
),debugstr_w(PortName
),nIDComboBox
);
673 /* query the dialog box for the current selected value */
674 Sel
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETCURSEL
, 0, 0);
676 /* we enter here only if a different printer is selected after
677 * the Print Setup dialog is opened. The current settings are
678 * stored into the newly selected printer.
680 oldWord
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETITEMDATA
,
683 if (nIDComboBox
== cmb2
)
684 dm
->u1
.s1
.dmPaperSize
= oldWord
;
686 dm
->u1
.s1
.dmDefaultSource
= oldWord
;
690 /* we enter here only when the Print setup dialog is initially
691 * opened. In this case the settings are restored from when
692 * the dialog was last closed.
695 if (nIDComboBox
== cmb2
)
696 oldWord
= dm
->u1
.s1
.dmPaperSize
;
698 oldWord
= dm
->u1
.s1
.dmDefaultSource
;
702 if (nIDComboBox
== cmb2
) {
704 fwCapability_Names
= DC_PAPERNAMES
;
705 fwCapability_Words
= DC_PAPERS
;
709 fwCapability_Names
= DC_BINNAMES
;
710 fwCapability_Words
= DC_BINS
;
713 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
714 fwCapability_Names
, NULL
, dm
);
715 if (NrOfEntries
== 0)
716 WARN("no Name Entries found!\n");
717 else if (NrOfEntries
< 0)
720 if(DeviceCapabilitiesW(PrinterName
, PortName
, fwCapability_Words
, NULL
, dm
)
722 ERR("Number of caps is different\n");
726 Names
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WCHAR
)*NamesSize
);
727 Words
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WORD
));
728 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
729 fwCapability_Names
, Names
, dm
);
730 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
731 fwCapability_Words
, Words
, dm
);
733 /* reset any current content in the combobox */
734 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_RESETCONTENT
, 0, 0);
736 /* store new content */
737 for (i
= 0; i
< NrOfEntries
; i
++) {
738 DWORD pos
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_ADDSTRING
, 0,
739 (LPARAM
)(&Names
[i
*NamesSize
]) );
740 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_SETITEMDATA
, pos
,
744 /* Look for old selection - can't do this is previous loop since
745 item order will change as more items are added */
747 for (i
= 0; i
< NrOfEntries
; i
++) {
748 if(SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) ==
754 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_SETCURSEL
, Sel
, 0);
756 HeapFree(GetProcessHeap(),0,Words
);
757 HeapFree(GetProcessHeap(),0,Names
);
762 /***********************************************************************
763 * PRINTDLG_UpdatePrinterInfoTexts [internal]
765 static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg
, const PRINTER_INFO_2A
*pi
)
768 char ResourceString
[256];
774 /* add all status messages */
775 for (i
= 0; i
< 25; i
++) {
776 if (pi
->Status
& (1<<i
)) {
777 LoadStringA(COMDLG32_hInstance
, PD32_PRINTER_STATUS_PAUSED
+i
,
778 ResourceString
, 255);
779 strcat(StatusMsg
,ResourceString
);
783 /* FIXME: status==ready must only be appended if really so.
784 but how to detect? */
785 LoadStringA(COMDLG32_hInstance
, PD32_PRINTER_STATUS_READY
,
786 ResourceString
, 255);
787 strcat(StatusMsg
,ResourceString
);
788 SetDlgItemTextA(hDlg
, stc12
, StatusMsg
);
790 /* set all other printer info texts */
791 SetDlgItemTextA(hDlg
, stc11
, pi
->pDriverName
);
793 if (pi
->pLocation
!= NULL
&& pi
->pLocation
[0] != '\0')
794 SetDlgItemTextA(hDlg
, stc14
, pi
->pLocation
);
796 SetDlgItemTextA(hDlg
, stc14
, pi
->pPortName
);
797 SetDlgItemTextA(hDlg
, stc13
, pi
->pComment
? pi
->pComment
: "");
801 static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg
, const PRINTER_INFO_2W
*pi
)
803 WCHAR StatusMsg
[256];
804 WCHAR ResourceString
[256];
805 static const WCHAR emptyW
[] = {0};
811 /* add all status messages */
812 for (i
= 0; i
< 25; i
++) {
813 if (pi
->Status
& (1<<i
)) {
814 LoadStringW(COMDLG32_hInstance
, PD32_PRINTER_STATUS_PAUSED
+i
,
815 ResourceString
, 255);
816 lstrcatW(StatusMsg
,ResourceString
);
820 /* FIXME: status==ready must only be appended if really so.
821 but how to detect? */
822 LoadStringW(COMDLG32_hInstance
, PD32_PRINTER_STATUS_READY
,
823 ResourceString
, 255);
824 lstrcatW(StatusMsg
,ResourceString
);
825 SetDlgItemTextW(hDlg
, stc12
, StatusMsg
);
827 /* set all other printer info texts */
828 SetDlgItemTextW(hDlg
, stc11
, pi
->pDriverName
);
829 if (pi
->pLocation
!= NULL
&& pi
->pLocation
[0] != '\0')
830 SetDlgItemTextW(hDlg
, stc14
, pi
->pLocation
);
832 SetDlgItemTextW(hDlg
, stc14
, pi
->pPortName
);
833 SetDlgItemTextW(hDlg
, stc13
, pi
->pComment
? pi
->pComment
: emptyW
);
837 /*******************************************************************
839 * PRINTDLG_ChangePrinter
842 BOOL
PRINTDLG_ChangePrinterA(HWND hDlg
, char *name
,
843 PRINT_PTRA
*PrintStructures
)
845 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
846 LPDEVMODEA lpdm
= NULL
;
851 HeapFree(GetProcessHeap(),0, PrintStructures
->lpPrinterInfo
);
852 HeapFree(GetProcessHeap(),0, PrintStructures
->lpDriverInfo
);
853 if(!OpenPrinterA(name
, &hprn
, NULL
)) {
854 ERR("Can't open printer %s\n", name
);
857 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
858 PrintStructures
->lpPrinterInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
859 GetPrinterA(hprn
, 2, (LPBYTE
)PrintStructures
->lpPrinterInfo
, needed
,
861 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
862 PrintStructures
->lpDriverInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
863 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)PrintStructures
->lpDriverInfo
,
865 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures
->lpPrinterInfo
->pPrinterName
);
870 PRINTDLG_UpdatePrinterInfoTextsA(hDlg
, PrintStructures
->lpPrinterInfo
);
872 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
873 PrintStructures
->lpDevMode
= NULL
;
875 dmSize
= DocumentPropertiesA(0, 0, name
, NULL
, NULL
, 0);
877 ERR("DocumentProperties fails on %s\n", debugstr_a(name
));
880 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(), 0, dmSize
);
881 dmSize
= DocumentPropertiesA(0, 0, name
, PrintStructures
->lpDevMode
, NULL
,
883 if(lppd
->hDevMode
&& (lpdm
= GlobalLock(lppd
->hDevMode
)) &&
884 !lstrcmpA( (LPSTR
) lpdm
->dmDeviceName
,
885 (LPSTR
) PrintStructures
->lpDevMode
->dmDeviceName
)) {
886 /* Supplied devicemode matches current printer so try to use it */
887 DocumentPropertiesA(0, 0, name
, PrintStructures
->lpDevMode
, lpdm
,
888 DM_OUT_BUFFER
| DM_IN_BUFFER
);
891 GlobalUnlock(lppd
->hDevMode
);
893 lpdm
= PrintStructures
->lpDevMode
; /* use this as a shortcut */
895 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
896 /* Print range (All/Range/Selection) */
897 if(lppd
->nFromPage
!= 0xffff)
898 SetDlgItemInt(hDlg
, edt1
, lppd
->nFromPage
, FALSE
);
899 if(lppd
->nToPage
!= 0xffff)
900 SetDlgItemInt(hDlg
, edt2
, lppd
->nToPage
, FALSE
);
902 CheckRadioButton(hDlg
, rad1
, rad3
, rad1
); /* default */
903 if (lppd
->Flags
& PD_NOSELECTION
)
904 EnableWindow(GetDlgItem(hDlg
, rad2
), FALSE
);
906 if (lppd
->Flags
& PD_SELECTION
)
907 CheckRadioButton(hDlg
, rad1
, rad3
, rad2
);
908 if (lppd
->Flags
& PD_NOPAGENUMS
) {
909 EnableWindow(GetDlgItem(hDlg
, rad3
), FALSE
);
910 EnableWindow(GetDlgItem(hDlg
, stc2
),FALSE
);
911 EnableWindow(GetDlgItem(hDlg
, edt1
), FALSE
);
912 EnableWindow(GetDlgItem(hDlg
, stc3
),FALSE
);
913 EnableWindow(GetDlgItem(hDlg
, edt2
), FALSE
);
915 if (lppd
->Flags
& PD_PAGENUMS
)
916 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
921 * FIXME: The ico3 is not displayed for some reason. I don't know why.
923 if (lppd
->Flags
& PD_COLLATE
) {
924 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
925 (LPARAM
)PrintStructures
->hCollateIcon
);
926 CheckDlgButton(hDlg
, chx2
, 1);
928 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
929 (LPARAM
)PrintStructures
->hNoCollateIcon
);
930 CheckDlgButton(hDlg
, chx2
, 0);
933 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
934 /* if printer doesn't support it: no Collate */
935 if (!(lpdm
->dmFields
& DM_COLLATE
)) {
936 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
937 EnableWindow(GetDlgItem(hDlg
, ico3
), FALSE
);
944 if (lppd
->hDevMode
== 0)
945 copies
= lppd
->nCopies
;
947 copies
= lpdm
->u1
.s1
.dmCopies
;
948 if(copies
== 0) copies
= 1;
949 else if(copies
< 0) copies
= MAX_COPIES
;
950 SetDlgItemInt(hDlg
, edt3
, copies
, FALSE
);
953 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
954 /* if printer doesn't support it: no nCopies */
955 if (!(lpdm
->dmFields
& DM_COPIES
)) {
956 EnableWindow(GetDlgItem(hDlg
, edt3
), FALSE
);
957 EnableWindow(GetDlgItem(hDlg
, stc5
), FALSE
);
962 CheckDlgButton(hDlg
, chx1
, (lppd
->Flags
& PD_PRINTTOFILE
) ? 1 : 0);
963 if (lppd
->Flags
& PD_DISABLEPRINTTOFILE
)
964 EnableWindow(GetDlgItem(hDlg
, chx1
), FALSE
);
965 if (lppd
->Flags
& PD_HIDEPRINTTOFILE
)
966 ShowWindow(GetDlgItem(hDlg
, chx1
), SW_HIDE
);
968 /* Fill print quality combo, PrintDlg16 */
969 if(GetDlgItem(hDlg
, cmb1
))
971 DWORD numResolutions
= DeviceCapabilitiesA(PrintStructures
->lpPrinterInfo
->pPrinterName
,
972 PrintStructures
->lpPrinterInfo
->pPortName
,
973 DC_ENUMRESOLUTIONS
, NULL
, lpdm
);
975 if(numResolutions
!= -1)
977 HWND hQuality
= GetDlgItem(hDlg
, cmb1
);
982 HDC hPrinterDC
= CreateDCA(PrintStructures
->lpPrinterInfo
->pDriverName
,
983 PrintStructures
->lpPrinterInfo
->pPrinterName
,
986 Resolutions
= HeapAlloc(GetProcessHeap(), 0, numResolutions
*sizeof(LONG
)*2);
987 DeviceCapabilitiesA(PrintStructures
->lpPrinterInfo
->pPrinterName
,
988 PrintStructures
->lpPrinterInfo
->pPortName
,
989 DC_ENUMRESOLUTIONS
, (LPSTR
)Resolutions
, lpdm
);
991 dpiX
= GetDeviceCaps(hPrinterDC
, LOGPIXELSX
);
992 dpiY
= GetDeviceCaps(hPrinterDC
, LOGPIXELSY
);
993 DeleteDC(hPrinterDC
);
995 SendMessageA(hQuality
, CB_RESETCONTENT
, 0, 0);
996 for(i
= 0; i
< (numResolutions
* 2); i
+= 2)
998 BOOL IsDefault
= FALSE
;
1001 if(Resolutions
[i
] == Resolutions
[i
+1])
1003 if(dpiX
== Resolutions
[i
])
1005 sprintf(buf
, "%d dpi", Resolutions
[i
]);
1008 if(dpiX
== Resolutions
[i
] && dpiY
== Resolutions
[i
+1])
1010 sprintf(buf
, "%d dpi x %d dpi", Resolutions
[i
], Resolutions
[i
+1]);
1013 Index
= SendMessageA(hQuality
, CB_ADDSTRING
, 0, (LPARAM
)buf
);
1016 SendMessageA(hQuality
, CB_SETCURSEL
, Index
, 0);
1018 SendMessageA(hQuality
, CB_SETITEMDATA
, Index
, MAKELONG(dpiX
,dpiY
));
1020 HeapFree(GetProcessHeap(), 0, Resolutions
);
1023 } else { /* PD_PRINTSETUP */
1024 BOOL bPortrait
= (lpdm
->u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
);
1026 PRINTDLG_SetUpPaperComboBoxA(hDlg
, cmb2
,
1027 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1028 PrintStructures
->lpPrinterInfo
->pPortName
,
1030 PRINTDLG_SetUpPaperComboBoxA(hDlg
, cmb3
,
1031 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1032 PrintStructures
->lpPrinterInfo
->pPortName
,
1034 CheckRadioButton(hDlg
, rad1
, rad2
, bPortrait
? rad1
: rad2
);
1035 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1036 (LPARAM
)(bPortrait
? PrintStructures
->hPortraitIcon
:
1037 PrintStructures
->hLandscapeIcon
));
1042 if ((lppd
->Flags
& PD_SHOWHELP
)==0) {
1043 /* hide if PD_SHOWHELP not specified */
1044 ShowWindow(GetDlgItem(hDlg
, pshHelp
), SW_HIDE
);
1049 static BOOL
PRINTDLG_ChangePrinterW(HWND hDlg
, WCHAR
*name
,
1050 PRINT_PTRW
*PrintStructures
)
1052 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1053 LPDEVMODEW lpdm
= NULL
;
1058 HeapFree(GetProcessHeap(),0, PrintStructures
->lpPrinterInfo
);
1059 HeapFree(GetProcessHeap(),0, PrintStructures
->lpDriverInfo
);
1060 if(!OpenPrinterW(name
, &hprn
, NULL
)) {
1061 ERR("Can't open printer %s\n", debugstr_w(name
));
1064 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
1065 PrintStructures
->lpPrinterInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
1066 GetPrinterW(hprn
, 2, (LPBYTE
)PrintStructures
->lpPrinterInfo
, needed
,
1068 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
1069 PrintStructures
->lpDriverInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
1070 if (!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)PrintStructures
->lpDriverInfo
,
1072 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures
->lpPrinterInfo
->pPrinterName
));
1077 PRINTDLG_UpdatePrinterInfoTextsW(hDlg
, PrintStructures
->lpPrinterInfo
);
1079 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
1080 PrintStructures
->lpDevMode
= NULL
;
1082 dmSize
= DocumentPropertiesW(0, 0, name
, NULL
, NULL
, 0);
1084 ERR("DocumentProperties fails on %s\n", debugstr_w(name
));
1087 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(), 0, dmSize
);
1088 dmSize
= DocumentPropertiesW(0, 0, name
, PrintStructures
->lpDevMode
, NULL
,
1090 if(lppd
->hDevMode
&& (lpdm
= GlobalLock(lppd
->hDevMode
)) &&
1091 !lstrcmpW(lpdm
->dmDeviceName
,
1092 PrintStructures
->lpDevMode
->dmDeviceName
)) {
1093 /* Supplied devicemode matches current printer so try to use it */
1094 DocumentPropertiesW(0, 0, name
, PrintStructures
->lpDevMode
, lpdm
,
1095 DM_OUT_BUFFER
| DM_IN_BUFFER
);
1098 GlobalUnlock(lppd
->hDevMode
);
1100 lpdm
= PrintStructures
->lpDevMode
; /* use this as a shortcut */
1102 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
1103 /* Print range (All/Range/Selection) */
1104 if(lppd
->nFromPage
!= 0xffff)
1105 SetDlgItemInt(hDlg
, edt1
, lppd
->nFromPage
, FALSE
);
1106 if(lppd
->nToPage
!= 0xffff)
1107 SetDlgItemInt(hDlg
, edt2
, lppd
->nToPage
, FALSE
);
1109 CheckRadioButton(hDlg
, rad1
, rad3
, rad1
); /* default */
1110 if (lppd
->Flags
& PD_NOSELECTION
)
1111 EnableWindow(GetDlgItem(hDlg
, rad2
), FALSE
);
1113 if (lppd
->Flags
& PD_SELECTION
)
1114 CheckRadioButton(hDlg
, rad1
, rad3
, rad2
);
1115 if (lppd
->Flags
& PD_NOPAGENUMS
) {
1116 EnableWindow(GetDlgItem(hDlg
, rad3
), FALSE
);
1117 EnableWindow(GetDlgItem(hDlg
, stc2
),FALSE
);
1118 EnableWindow(GetDlgItem(hDlg
, edt1
), FALSE
);
1119 EnableWindow(GetDlgItem(hDlg
, stc3
),FALSE
);
1120 EnableWindow(GetDlgItem(hDlg
, edt2
), FALSE
);
1122 if (lppd
->Flags
& PD_PAGENUMS
)
1123 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1128 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1130 if (lppd
->Flags
& PD_COLLATE
) {
1131 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1132 (LPARAM
)PrintStructures
->hCollateIcon
);
1133 CheckDlgButton(hDlg
, chx2
, 1);
1135 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1136 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1137 CheckDlgButton(hDlg
, chx2
, 0);
1140 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1141 /* if printer doesn't support it: no Collate */
1142 if (!(lpdm
->dmFields
& DM_COLLATE
)) {
1143 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1144 EnableWindow(GetDlgItem(hDlg
, ico3
), FALSE
);
1151 if (lppd
->hDevMode
== 0)
1152 copies
= lppd
->nCopies
;
1154 copies
= lpdm
->u1
.s1
.dmCopies
;
1155 if(copies
== 0) copies
= 1;
1156 else if(copies
< 0) copies
= MAX_COPIES
;
1157 SetDlgItemInt(hDlg
, edt3
, copies
, FALSE
);
1160 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1161 /* if printer doesn't support it: no nCopies */
1162 if (!(lpdm
->dmFields
& DM_COPIES
)) {
1163 EnableWindow(GetDlgItem(hDlg
, edt3
), FALSE
);
1164 EnableWindow(GetDlgItem(hDlg
, stc5
), FALSE
);
1169 CheckDlgButton(hDlg
, chx1
, (lppd
->Flags
& PD_PRINTTOFILE
) ? 1 : 0);
1170 if (lppd
->Flags
& PD_DISABLEPRINTTOFILE
)
1171 EnableWindow(GetDlgItem(hDlg
, chx1
), FALSE
);
1172 if (lppd
->Flags
& PD_HIDEPRINTTOFILE
)
1173 ShowWindow(GetDlgItem(hDlg
, chx1
), SW_HIDE
);
1175 } else { /* PD_PRINTSETUP */
1176 BOOL bPortrait
= (lpdm
->u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
);
1178 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb2
,
1179 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1180 PrintStructures
->lpPrinterInfo
->pPortName
,
1182 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb3
,
1183 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1184 PrintStructures
->lpPrinterInfo
->pPortName
,
1186 CheckRadioButton(hDlg
, rad1
, rad2
, bPortrait
? rad1
: rad2
);
1187 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1188 (LPARAM
)(bPortrait
? PrintStructures
->hPortraitIcon
:
1189 PrintStructures
->hLandscapeIcon
));
1194 if ((lppd
->Flags
& PD_SHOWHELP
)==0) {
1195 /* hide if PD_SHOWHELP not specified */
1196 ShowWindow(GetDlgItem(hDlg
, pshHelp
), SW_HIDE
);
1201 /***********************************************************************
1202 * check_printer_setup [internal]
1204 static LRESULT
check_printer_setup(HWND hDlg
)
1207 WCHAR resourcestr
[256],resultstr
[256];
1209 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
1212 EnumPrintersW(PRINTER_ENUM_CONNECTIONS
, NULL
, 2, NULL
, 0, &needed
, &num
);
1218 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEVICES
,resultstr
, 255);
1219 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
,resourcestr
, 255);
1220 MessageBoxW(hDlg
, resultstr
, resourcestr
,MB_OK
| MB_ICONWARNING
);
1225 /***********************************************************************
1226 * PRINTDLG_WMInitDialog [internal]
1228 static LRESULT
PRINTDLG_WMInitDialog(HWND hDlg
, WPARAM wParam
,
1229 PRINT_PTRA
* PrintStructures
)
1231 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1235 UINT comboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1237 /* load Collate ICONs */
1238 /* We load these with LoadImage because they are not a standard
1239 size and we don't want them rescaled */
1240 PrintStructures
->hCollateIcon
=
1241 LoadImageA(COMDLG32_hInstance
, "PD32_COLLATE", IMAGE_ICON
, 0, 0, 0);
1242 PrintStructures
->hNoCollateIcon
=
1243 LoadImageA(COMDLG32_hInstance
, "PD32_NOCOLLATE", IMAGE_ICON
, 0, 0, 0);
1245 /* These can be done with LoadIcon */
1246 PrintStructures
->hPortraitIcon
=
1247 LoadIconA(COMDLG32_hInstance
, "PD32_PORTRAIT");
1248 PrintStructures
->hLandscapeIcon
=
1249 LoadIconA(COMDLG32_hInstance
, "PD32_LANDSCAPE");
1251 /* display the collate/no_collate icon */
1252 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1253 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1255 if(PrintStructures
->hCollateIcon
== 0 ||
1256 PrintStructures
->hNoCollateIcon
== 0 ||
1257 PrintStructures
->hPortraitIcon
== 0 ||
1258 PrintStructures
->hLandscapeIcon
== 0) {
1259 ERR("no icon in resourcefile\n");
1260 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1261 EndDialog(hDlg
, FALSE
);
1265 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1266 * must be registered and the Help button must be shown.
1268 if (lppd
->Flags
& PD_SHOWHELP
) {
1269 if((PrintStructures
->HelpMessageID
=
1270 RegisterWindowMessageA(HELPMSGSTRINGA
)) == 0) {
1271 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL
);
1275 PrintStructures
->HelpMessageID
= 0;
1277 if(!(lppd
->Flags
&PD_PRINTSETUP
)) {
1278 PrintStructures
->hwndUpDown
=
1279 CreateUpDownControl(WS_CHILD
| WS_VISIBLE
| WS_BORDER
|
1280 UDS_NOTHOUSANDS
| UDS_ARROWKEYS
|
1281 UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, 0, 0, 0, 0,
1282 hDlg
, UPDOWN_ID
, COMDLG32_hInstance
,
1283 GetDlgItem(hDlg
, edt3
), MAX_COPIES
, 1, 1);
1286 /* FIXME: I allow more freedom than either Win95 or WinNT,
1287 * which do not agree to what errors should be thrown or not
1288 * in case nToPage or nFromPage is out-of-range.
1290 if (lppd
->nMaxPage
< lppd
->nMinPage
)
1291 lppd
->nMaxPage
= lppd
->nMinPage
;
1292 if (lppd
->nMinPage
== lppd
->nMaxPage
)
1293 lppd
->Flags
|= PD_NOPAGENUMS
;
1294 if (lppd
->nToPage
< lppd
->nMinPage
)
1295 lppd
->nToPage
= lppd
->nMinPage
;
1296 if (lppd
->nToPage
> lppd
->nMaxPage
)
1297 lppd
->nToPage
= lppd
->nMaxPage
;
1298 if (lppd
->nFromPage
< lppd
->nMinPage
)
1299 lppd
->nFromPage
= lppd
->nMinPage
;
1300 if (lppd
->nFromPage
> lppd
->nMaxPage
)
1301 lppd
->nFromPage
= lppd
->nMaxPage
;
1303 /* if we have the combo box, fill it */
1304 if (GetDlgItem(hDlg
,comboID
)) {
1307 pdn
= GlobalLock(lppd
->hDevNames
);
1308 pdm
= GlobalLock(lppd
->hDevMode
);
1310 name
= (char*)pdn
+ pdn
->wDeviceOffset
;
1312 name
= (char*)pdm
->dmDeviceName
;
1313 PRINTDLG_SetUpPrinterListComboA(hDlg
, comboID
, name
);
1314 if(pdm
) GlobalUnlock(lppd
->hDevMode
);
1315 if(pdn
) GlobalUnlock(lppd
->hDevNames
);
1317 /* Now find selected printer and update rest of dlg */
1318 name
= HeapAlloc(GetProcessHeap(),0,256);
1319 if (GetDlgItemTextA(hDlg
, comboID
, name
, 255))
1320 PRINTDLG_ChangePrinterA(hDlg
, name
, PrintStructures
);
1321 HeapFree(GetProcessHeap(),0,name
);
1323 /* else use default printer */
1325 DWORD dwBufLen
= sizeof(name
);
1326 BOOL ret
= GetDefaultPrinterA(name
, &dwBufLen
);
1329 PRINTDLG_ChangePrinterA(hDlg
, name
, PrintStructures
);
1331 FIXME("No default printer found, expect problems!\n");
1336 static LRESULT
PRINTDLG_WMInitDialogW(HWND hDlg
, WPARAM wParam
,
1337 PRINT_PTRW
* PrintStructures
)
1339 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1343 UINT comboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1345 /* load Collate ICONs */
1346 /* We load these with LoadImage because they are not a standard
1347 size and we don't want them rescaled */
1348 PrintStructures
->hCollateIcon
=
1349 LoadImageW(COMDLG32_hInstance
, pd32_collateW
, IMAGE_ICON
, 0, 0, 0);
1350 PrintStructures
->hNoCollateIcon
=
1351 LoadImageW(COMDLG32_hInstance
, pd32_nocollateW
, IMAGE_ICON
, 0, 0, 0);
1353 /* These can be done with LoadIcon */
1354 PrintStructures
->hPortraitIcon
=
1355 LoadIconW(COMDLG32_hInstance
, pd32_portraitW
);
1356 PrintStructures
->hLandscapeIcon
=
1357 LoadIconW(COMDLG32_hInstance
, pd32_landscapeW
);
1359 /* display the collate/no_collate icon */
1360 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1361 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1363 if(PrintStructures
->hCollateIcon
== 0 ||
1364 PrintStructures
->hNoCollateIcon
== 0 ||
1365 PrintStructures
->hPortraitIcon
== 0 ||
1366 PrintStructures
->hLandscapeIcon
== 0) {
1367 ERR("no icon in resourcefile\n");
1368 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1369 EndDialog(hDlg
, FALSE
);
1373 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1374 * must be registered and the Help button must be shown.
1376 if (lppd
->Flags
& PD_SHOWHELP
) {
1377 if((PrintStructures
->HelpMessageID
=
1378 RegisterWindowMessageW(HELPMSGSTRINGW
)) == 0) {
1379 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL
);
1383 PrintStructures
->HelpMessageID
= 0;
1385 if(!(lppd
->Flags
&PD_PRINTSETUP
)) {
1386 PrintStructures
->hwndUpDown
=
1387 CreateUpDownControl(WS_CHILD
| WS_VISIBLE
| WS_BORDER
|
1388 UDS_NOTHOUSANDS
| UDS_ARROWKEYS
|
1389 UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, 0, 0, 0, 0,
1390 hDlg
, UPDOWN_ID
, COMDLG32_hInstance
,
1391 GetDlgItem(hDlg
, edt3
), MAX_COPIES
, 1, 1);
1394 /* FIXME: I allow more freedom than either Win95 or WinNT,
1395 * which do not agree to what errors should be thrown or not
1396 * in case nToPage or nFromPage is out-of-range.
1398 if (lppd
->nMaxPage
< lppd
->nMinPage
)
1399 lppd
->nMaxPage
= lppd
->nMinPage
;
1400 if (lppd
->nMinPage
== lppd
->nMaxPage
)
1401 lppd
->Flags
|= PD_NOPAGENUMS
;
1402 if (lppd
->nToPage
< lppd
->nMinPage
)
1403 lppd
->nToPage
= lppd
->nMinPage
;
1404 if (lppd
->nToPage
> lppd
->nMaxPage
)
1405 lppd
->nToPage
= lppd
->nMaxPage
;
1406 if (lppd
->nFromPage
< lppd
->nMinPage
)
1407 lppd
->nFromPage
= lppd
->nMinPage
;
1408 if (lppd
->nFromPage
> lppd
->nMaxPage
)
1409 lppd
->nFromPage
= lppd
->nMaxPage
;
1411 /* if we have the combo box, fill it */
1412 if (GetDlgItem(hDlg
,comboID
)) {
1415 pdn
= GlobalLock(lppd
->hDevNames
);
1416 pdm
= GlobalLock(lppd
->hDevMode
);
1418 name
= (WCHAR
*)pdn
+ pdn
->wDeviceOffset
;
1420 name
= pdm
->dmDeviceName
;
1421 PRINTDLG_SetUpPrinterListComboW(hDlg
, comboID
, name
);
1422 if(pdm
) GlobalUnlock(lppd
->hDevMode
);
1423 if(pdn
) GlobalUnlock(lppd
->hDevNames
);
1425 /* Now find selected printer and update rest of dlg */
1426 /* ansi is ok here */
1427 name
= HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR
));
1428 if (GetDlgItemTextW(hDlg
, comboID
, name
, 255))
1429 PRINTDLG_ChangePrinterW(hDlg
, name
, PrintStructures
);
1430 HeapFree(GetProcessHeap(),0,name
);
1432 /* else use default printer */
1434 DWORD dwBufLen
= sizeof(name
) / sizeof(WCHAR
);
1435 BOOL ret
= GetDefaultPrinterW(name
, &dwBufLen
);
1438 PRINTDLG_ChangePrinterW(hDlg
, name
, PrintStructures
);
1440 FIXME("No default printer found, expect problems!\n");
1445 /***********************************************************************
1446 * PRINTDLG_WMCommand [internal]
1448 LRESULT
PRINTDLG_WMCommandA(HWND hDlg
, WPARAM wParam
,
1449 LPARAM lParam
, PRINT_PTRA
* PrintStructures
)
1451 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1452 UINT PrinterComboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1453 LPDEVMODEA lpdm
= PrintStructures
->lpDevMode
;
1455 switch (LOWORD(wParam
)) {
1457 TRACE(" OK button was hit\n");
1458 if (!PRINTDLG_UpdatePrintDlgA(hDlg
, PrintStructures
)) {
1459 FIXME("Update printdlg was not successful!\n");
1462 EndDialog(hDlg
, TRUE
);
1466 TRACE(" CANCEL button was hit\n");
1467 EndDialog(hDlg
, FALSE
);
1471 TRACE(" HELP button was hit\n");
1472 SendMessageA(lppd
->hwndOwner
, PrintStructures
->HelpMessageID
,
1473 (WPARAM
) hDlg
, (LPARAM
) lppd
);
1476 case chx2
: /* collate pages checkbox */
1477 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
1478 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1479 (LPARAM
)PrintStructures
->hCollateIcon
);
1481 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1482 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1484 case edt1
: /* from page nr editbox */
1485 case edt2
: /* to page nr editbox */
1486 if (HIWORD(wParam
)==EN_CHANGE
) {
1489 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
1490 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
1491 if (nFromPage
!= lppd
->nFromPage
|| nToPage
!= lppd
->nToPage
)
1492 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1497 if(HIWORD(wParam
) == EN_CHANGE
) {
1498 INT copies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
1500 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1502 EnableWindow(GetDlgItem(hDlg
, chx2
), TRUE
);
1507 case psh1
: /* Print Setup */
1511 if (!PrintStructures
->dlg
.lpPrintDlg16
) {
1512 FIXME("The 32bit print dialog does not have this button!?\n");
1516 memcpy(&pdlg
,PrintStructures
->dlg
.lpPrintDlg16
,sizeof(pdlg
));
1517 pdlg
.Flags
|= PD_PRINTSETUP
;
1518 pdlg
.hwndOwner
= HWND_16(hDlg
);
1519 if (!PrintDlg16(&pdlg
))
1524 case psh2
: /* Properties button */
1527 char PrinterName
[256];
1529 GetDlgItemTextA(hDlg
, PrinterComboID
, PrinterName
, 255);
1530 if (!OpenPrinterA(PrinterName
, &hPrinter
, NULL
)) {
1531 FIXME(" Call to OpenPrinter did not succeed!\n");
1534 DocumentPropertiesA(hDlg
, hPrinter
, PrinterName
,
1535 PrintStructures
->lpDevMode
,
1536 PrintStructures
->lpDevMode
,
1537 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
1538 ClosePrinter(hPrinter
);
1542 case rad1
: /* Paperorientation */
1543 if (lppd
->Flags
& PD_PRINTSETUP
)
1545 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1546 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1547 (LPARAM
)(PrintStructures
->hPortraitIcon
));
1551 case rad2
: /* Paperorientation */
1552 if (lppd
->Flags
& PD_PRINTSETUP
)
1554 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1555 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1556 (LPARAM
)(PrintStructures
->hLandscapeIcon
));
1560 case cmb1
: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT16 */
1561 if (PrinterComboID
!= LOWORD(wParam
)) {
1565 case cmb4
: /* Printer combobox */
1566 if (HIWORD(wParam
)==CBN_SELCHANGE
) {
1567 char PrinterName
[256];
1568 GetDlgItemTextA(hDlg
, LOWORD(wParam
), PrinterName
, 255);
1569 PRINTDLG_ChangePrinterA(hDlg
, PrinterName
, PrintStructures
);
1573 case cmb2
: /* Papersize */
1575 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
1577 lpdm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageA(hDlg
, cmb2
,
1583 case cmb3
: /* Bin */
1585 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
1587 lpdm
->u1
.s1
.dmDefaultSource
= SendDlgItemMessageA(hDlg
, cmb3
,
1588 CB_GETITEMDATA
, Sel
,
1593 if(lppd
->Flags
& PD_PRINTSETUP
) {
1594 switch (LOWORD(wParam
)) {
1595 case rad1
: /* orientation */
1597 if (IsDlgButtonChecked(hDlg
, rad1
) == BST_CHECKED
) {
1598 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_PORTRAIT
) {
1599 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1600 SendDlgItemMessageA(hDlg
, stc10
, STM_SETIMAGE
,
1602 (LPARAM
)PrintStructures
->hPortraitIcon
);
1603 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
,
1605 (LPARAM
)PrintStructures
->hPortraitIcon
);
1608 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_LANDSCAPE
) {
1609 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1610 SendDlgItemMessageA(hDlg
, stc10
, STM_SETIMAGE
,
1612 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1613 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
,
1615 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1624 static LRESULT
PRINTDLG_WMCommandW(HWND hDlg
, WPARAM wParam
,
1625 LPARAM lParam
, PRINT_PTRW
* PrintStructures
)
1627 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1628 UINT PrinterComboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1629 LPDEVMODEW lpdm
= PrintStructures
->lpDevMode
;
1631 switch (LOWORD(wParam
)) {
1633 TRACE(" OK button was hit\n");
1634 if (!PRINTDLG_UpdatePrintDlgW(hDlg
, PrintStructures
)) {
1635 FIXME("Update printdlg was not successful!\n");
1638 EndDialog(hDlg
, TRUE
);
1642 TRACE(" CANCEL button was hit\n");
1643 EndDialog(hDlg
, FALSE
);
1647 TRACE(" HELP button was hit\n");
1648 SendMessageW(lppd
->hwndOwner
, PrintStructures
->HelpMessageID
,
1649 (WPARAM
) hDlg
, (LPARAM
) lppd
);
1652 case chx2
: /* collate pages checkbox */
1653 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
1654 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1655 (LPARAM
)PrintStructures
->hCollateIcon
);
1657 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1658 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1660 case edt1
: /* from page nr editbox */
1661 case edt2
: /* to page nr editbox */
1662 if (HIWORD(wParam
)==EN_CHANGE
) {
1665 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
1666 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
1667 if (nFromPage
!= lppd
->nFromPage
|| nToPage
!= lppd
->nToPage
)
1668 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1673 if(HIWORD(wParam
) == EN_CHANGE
) {
1674 INT copies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
1676 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1678 EnableWindow(GetDlgItem(hDlg
, chx2
), TRUE
);
1682 case psh1
: /* Print Setup */
1684 ERR("psh1 is called from 16bit code only, we should not get here.\n");
1687 case psh2
: /* Properties button */
1690 WCHAR PrinterName
[256];
1692 if (!GetDlgItemTextW(hDlg
, PrinterComboID
, PrinterName
, 255)) break;
1693 if (!OpenPrinterW(PrinterName
, &hPrinter
, NULL
)) {
1694 FIXME(" Call to OpenPrinter did not succeed!\n");
1697 DocumentPropertiesW(hDlg
, hPrinter
, PrinterName
,
1698 PrintStructures
->lpDevMode
,
1699 PrintStructures
->lpDevMode
,
1700 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
1701 ClosePrinter(hPrinter
);
1705 case rad1
: /* Paperorientation */
1706 if (lppd
->Flags
& PD_PRINTSETUP
)
1708 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1709 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1710 (LPARAM
)(PrintStructures
->hPortraitIcon
));
1714 case rad2
: /* Paperorientation */
1715 if (lppd
->Flags
& PD_PRINTSETUP
)
1717 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1718 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1719 (LPARAM
)(PrintStructures
->hLandscapeIcon
));
1723 case cmb1
: /* Printer Combobox in PRINT SETUP */
1725 case cmb4
: /* Printer combobox */
1726 if (HIWORD(wParam
)==CBN_SELCHANGE
) {
1727 WCHAR PrinterName
[256];
1728 GetDlgItemTextW(hDlg
, LOWORD(wParam
), PrinterName
, 255);
1729 PRINTDLG_ChangePrinterW(hDlg
, PrinterName
, PrintStructures
);
1733 case cmb2
: /* Papersize */
1735 DWORD Sel
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
1737 lpdm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageW(hDlg
, cmb2
,
1743 case cmb3
: /* Bin */
1745 DWORD Sel
= SendDlgItemMessageW(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
1747 lpdm
->u1
.s1
.dmDefaultSource
= SendDlgItemMessageW(hDlg
, cmb3
,
1748 CB_GETITEMDATA
, Sel
,
1753 if(lppd
->Flags
& PD_PRINTSETUP
) {
1754 switch (LOWORD(wParam
)) {
1755 case rad1
: /* orientation */
1757 if (IsDlgButtonChecked(hDlg
, rad1
) == BST_CHECKED
) {
1758 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_PORTRAIT
) {
1759 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1760 SendDlgItemMessageW(hDlg
, stc10
, STM_SETIMAGE
,
1762 (LPARAM
)PrintStructures
->hPortraitIcon
);
1763 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
,
1765 (LPARAM
)PrintStructures
->hPortraitIcon
);
1768 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_LANDSCAPE
) {
1769 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1770 SendDlgItemMessageW(hDlg
, stc10
, STM_SETIMAGE
,
1772 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1773 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
,
1775 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1784 /***********************************************************************
1785 * PrintDlgProcA [internal]
1787 static INT_PTR CALLBACK
PrintDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
1790 PRINT_PTRA
* PrintStructures
;
1791 INT_PTR res
= FALSE
;
1793 if (uMsg
!=WM_INITDIALOG
) {
1794 PrintStructures
= GetPropW(hDlg
, printdlg_prop
);
1795 if (!PrintStructures
)
1798 PrintStructures
= (PRINT_PTRA
*) lParam
;
1799 SetPropW(hDlg
, printdlg_prop
, PrintStructures
);
1800 if(!check_printer_setup(hDlg
))
1802 EndDialog(hDlg
,FALSE
);
1805 res
= PRINTDLG_WMInitDialog(hDlg
, wParam
, PrintStructures
);
1807 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
)
1808 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(
1809 hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->lpPrintDlg
1814 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
) {
1815 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
,uMsg
,wParam
,
1822 return PRINTDLG_WMCommandA(hDlg
, wParam
, lParam
, PrintStructures
);
1825 DestroyIcon(PrintStructures
->hCollateIcon
);
1826 DestroyIcon(PrintStructures
->hNoCollateIcon
);
1827 DestroyIcon(PrintStructures
->hPortraitIcon
);
1828 DestroyIcon(PrintStructures
->hLandscapeIcon
);
1829 if(PrintStructures
->hwndUpDown
)
1830 DestroyWindow(PrintStructures
->hwndUpDown
);
1836 static INT_PTR CALLBACK
PrintDlgProcW(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
1839 PRINT_PTRW
* PrintStructures
;
1840 INT_PTR res
= FALSE
;
1842 if (uMsg
!=WM_INITDIALOG
) {
1843 PrintStructures
= GetPropW(hDlg
, printdlg_prop
);
1844 if (!PrintStructures
)
1847 PrintStructures
= (PRINT_PTRW
*) lParam
;
1848 SetPropW(hDlg
, printdlg_prop
, PrintStructures
);
1849 if(!check_printer_setup(hDlg
))
1851 EndDialog(hDlg
,FALSE
);
1854 res
= PRINTDLG_WMInitDialogW(hDlg
, wParam
, PrintStructures
);
1856 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
)
1857 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->lpPrintDlg
);
1861 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
) {
1862 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
,uMsg
,wParam
, lParam
);
1868 return PRINTDLG_WMCommandW(hDlg
, wParam
, lParam
, PrintStructures
);
1871 DestroyIcon(PrintStructures
->hCollateIcon
);
1872 DestroyIcon(PrintStructures
->hNoCollateIcon
);
1873 DestroyIcon(PrintStructures
->hPortraitIcon
);
1874 DestroyIcon(PrintStructures
->hLandscapeIcon
);
1875 if(PrintStructures
->hwndUpDown
)
1876 DestroyWindow(PrintStructures
->hwndUpDown
);
1882 /************************************************************
1884 * PRINTDLG_GetDlgTemplate
1887 static HGLOBAL
PRINTDLG_GetDlgTemplateA(const PRINTDLGA
*lppd
)
1892 if (lppd
->Flags
& PD_PRINTSETUP
) {
1893 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
1894 hDlgTmpl
= lppd
->hSetupTemplate
;
1895 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
1896 hResInfo
= FindResourceA(lppd
->hInstance
,
1897 lppd
->lpSetupTemplateName
, (LPSTR
)RT_DIALOG
);
1898 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1900 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32_SETUP",
1902 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1905 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
1906 hDlgTmpl
= lppd
->hPrintTemplate
;
1907 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
1908 hResInfo
= FindResourceA(lppd
->hInstance
,
1909 lppd
->lpPrintTemplateName
,
1911 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1913 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32",
1915 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1921 static HGLOBAL
PRINTDLG_GetDlgTemplateW(const PRINTDLGW
*lppd
)
1925 static const WCHAR xpsetup
[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
1926 static const WCHAR xprint
[] = { 'P','R','I','N','T','3','2',0};
1928 if (lppd
->Flags
& PD_PRINTSETUP
) {
1929 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
1930 hDlgTmpl
= lppd
->hSetupTemplate
;
1931 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
1932 hResInfo
= FindResourceW(lppd
->hInstance
,
1933 lppd
->lpSetupTemplateName
, (LPWSTR
)RT_DIALOG
);
1934 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1936 hResInfo
= FindResourceW(COMDLG32_hInstance
, xpsetup
, (LPWSTR
)RT_DIALOG
);
1937 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1940 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
1941 hDlgTmpl
= lppd
->hPrintTemplate
;
1942 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
1943 hResInfo
= FindResourceW(lppd
->hInstance
,
1944 lppd
->lpPrintTemplateName
,
1946 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1948 hResInfo
= FindResourceW(COMDLG32_hInstance
, xprint
, (LPWSTR
)RT_DIALOG
);
1949 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1955 /***********************************************************************
1960 static BOOL
PRINTDLG_CreateDCA(LPPRINTDLGA lppd
)
1962 DEVNAMES
*pdn
= GlobalLock(lppd
->hDevNames
);
1963 DEVMODEA
*pdm
= GlobalLock(lppd
->hDevMode
);
1965 if(lppd
->Flags
& PD_RETURNDC
) {
1966 lppd
->hDC
= CreateDCA((char*)pdn
+ pdn
->wDriverOffset
,
1967 (char*)pdn
+ pdn
->wDeviceOffset
,
1968 (char*)pdn
+ pdn
->wOutputOffset
,
1970 } else if(lppd
->Flags
& PD_RETURNIC
) {
1971 lppd
->hDC
= CreateICA((char*)pdn
+ pdn
->wDriverOffset
,
1972 (char*)pdn
+ pdn
->wDeviceOffset
,
1973 (char*)pdn
+ pdn
->wOutputOffset
,
1976 GlobalUnlock(lppd
->hDevNames
);
1977 GlobalUnlock(lppd
->hDevMode
);
1978 return lppd
->hDC
? TRUE
: FALSE
;
1981 static BOOL
PRINTDLG_CreateDCW(LPPRINTDLGW lppd
)
1983 DEVNAMES
*pdn
= GlobalLock(lppd
->hDevNames
);
1984 DEVMODEW
*pdm
= GlobalLock(lppd
->hDevMode
);
1986 if(lppd
->Flags
& PD_RETURNDC
) {
1987 lppd
->hDC
= CreateDCW((WCHAR
*)pdn
+ pdn
->wDriverOffset
,
1988 (WCHAR
*)pdn
+ pdn
->wDeviceOffset
,
1989 (WCHAR
*)pdn
+ pdn
->wOutputOffset
,
1991 } else if(lppd
->Flags
& PD_RETURNIC
) {
1992 lppd
->hDC
= CreateICW((WCHAR
*)pdn
+ pdn
->wDriverOffset
,
1993 (WCHAR
*)pdn
+ pdn
->wDeviceOffset
,
1994 (WCHAR
*)pdn
+ pdn
->wOutputOffset
,
1997 GlobalUnlock(lppd
->hDevNames
);
1998 GlobalUnlock(lppd
->hDevMode
);
1999 return lppd
->hDC
? TRUE
: FALSE
;
2002 /***********************************************************************
2003 * PrintDlgA (COMDLG32.@)
2005 * Displays the PRINT dialog box, which enables the user to specify
2006 * specific properties of the print job.
2009 * lppd [IO] ptr to PRINTDLG32 struct
2012 * nonzero if the user pressed the OK button
2013 * zero if the user cancelled the window or an error occurred
2017 * * The Collate Icons do not display, even though they are in the code.
2018 * * The Properties Button(s) should call DocumentPropertiesA().
2021 BOOL WINAPI
PrintDlgA(LPPRINTDLGA lppd
)
2029 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
2033 hInst
= (HINSTANCE
)GetWindowLongPtrA( lppd
->hwndOwner
, GWLP_HINSTANCE
);
2034 if(TRACE_ON(commdlg
)) {
2035 char flagstr
[1000] = "";
2036 const struct pd_flags
*pflag
= pd_flags
;
2037 for( ; pflag
->name
; pflag
++) {
2038 if(lppd
->Flags
& pflag
->flag
)
2039 strcat(flagstr
, pflag
->name
);
2041 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2042 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2043 "flags %08x (%s)\n",
2044 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
2045 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
2046 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
2049 if(lppd
->lStructSize
!= sizeof(PRINTDLGA
)) {
2050 WARN("structure size failure !!!\n");
2051 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
2055 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
2056 PRINTER_INFO_2A
*pbuf
;
2057 DRIVER_INFO_3A
*dbuf
;
2061 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
2062 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2063 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2066 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
2067 WARN("Can't find default printer\n");
2068 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
2072 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
2073 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
2074 GetPrinterA(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
2076 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
2077 dbuf
= HeapAlloc(GetProcessHeap(),0,needed
);
2078 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
2079 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2080 GetLastError(),pbuf
->pPrinterName
);
2081 HeapFree(GetProcessHeap(), 0, dbuf
);
2082 HeapFree(GetProcessHeap(), 0, pbuf
);
2083 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2088 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
2092 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
2093 pbuf
->pDevMode
->dmDriverExtra
);
2094 ptr
= GlobalLock(lppd
->hDevMode
);
2095 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
2096 pbuf
->pDevMode
->dmDriverExtra
);
2097 GlobalUnlock(lppd
->hDevMode
);
2098 HeapFree(GetProcessHeap(), 0, pbuf
);
2099 HeapFree(GetProcessHeap(), 0, dbuf
);
2103 PRINT_PTRA
*PrintStructures
;
2105 /* load Dialog resources,
2106 * depending on Flags indicates Print32 or Print32_setup dialog
2108 hDlgTmpl
= PRINTDLG_GetDlgTemplateA(lppd
);
2110 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2113 ptr
= LockResource( hDlgTmpl
);
2115 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2119 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2120 sizeof(PRINT_PTRA
));
2121 PrintStructures
->lpPrintDlg
= lppd
;
2123 /* and create & process the dialog .
2124 * -1 is failure, 0 is broken hwnd, everything else is ok.
2126 bRet
= (0<DialogBoxIndirectParamA(hInst
, ptr
, lppd
->hwndOwner
,
2128 (LPARAM
)PrintStructures
));
2131 DEVMODEA
*lpdm
= PrintStructures
->lpDevMode
, *lpdmReturn
;
2132 PRINTER_INFO_2A
*pi
= PrintStructures
->lpPrinterInfo
;
2133 DRIVER_INFO_3A
*di
= PrintStructures
->lpDriverInfo
;
2135 if (lppd
->hDevMode
== 0) {
2136 TRACE(" No hDevMode yet... Need to create my own\n");
2137 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
,
2138 lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2140 lppd
->hDevMode
= GlobalReAlloc(lppd
->hDevMode
,
2141 lpdm
->dmSize
+ lpdm
->dmDriverExtra
,
2144 lpdmReturn
= GlobalLock(lppd
->hDevMode
);
2145 memcpy(lpdmReturn
, lpdm
, lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2147 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
2152 GlobalUnlock(lppd
->hDevMode
);
2154 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
2155 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpPrinterInfo
);
2156 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDriverInfo
);
2157 HeapFree(GetProcessHeap(), 0, PrintStructures
);
2159 if(bRet
&& (lppd
->Flags
& PD_RETURNDC
|| lppd
->Flags
& PD_RETURNIC
))
2160 bRet
= PRINTDLG_CreateDCA(lppd
);
2162 TRACE("exit! (%d)\n", bRet
);
2166 /***********************************************************************
2167 * PrintDlgW (COMDLG32.@)
2171 BOOL WINAPI
PrintDlgW(LPPRINTDLGW lppd
)
2179 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
2183 hInst
= (HINSTANCE
)GetWindowLongPtrW( lppd
->hwndOwner
, GWLP_HINSTANCE
);
2184 if(TRACE_ON(commdlg
)) {
2185 char flagstr
[1000] = "";
2186 const struct pd_flags
*pflag
= pd_flags
;
2187 for( ; pflag
->name
; pflag
++) {
2188 if(lppd
->Flags
& pflag
->flag
)
2189 strcat(flagstr
, pflag
->name
);
2191 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2192 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2193 "flags %08x (%s)\n",
2194 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
2195 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
2196 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
2199 if(lppd
->lStructSize
!= sizeof(PRINTDLGW
)) {
2200 WARN("structure size failure !!!\n");
2201 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
2205 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
2206 PRINTER_INFO_2W
*pbuf
;
2207 DRIVER_INFO_3W
*dbuf
;
2211 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
2212 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2213 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2216 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
2217 WARN("Can't find default printer\n");
2218 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
2222 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
2223 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
2224 GetPrinterW(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
2226 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
2227 dbuf
= HeapAlloc(GetProcessHeap(),0,needed
);
2228 if (!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
2229 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2230 GetLastError(),debugstr_w(pbuf
->pPrinterName
));
2231 HeapFree(GetProcessHeap(), 0, dbuf
);
2232 HeapFree(GetProcessHeap(), 0, pbuf
);
2233 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2238 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
2242 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
2243 pbuf
->pDevMode
->dmDriverExtra
);
2244 ptr
= GlobalLock(lppd
->hDevMode
);
2245 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
2246 pbuf
->pDevMode
->dmDriverExtra
);
2247 GlobalUnlock(lppd
->hDevMode
);
2248 HeapFree(GetProcessHeap(), 0, pbuf
);
2249 HeapFree(GetProcessHeap(), 0, dbuf
);
2253 PRINT_PTRW
*PrintStructures
;
2255 /* load Dialog resources,
2256 * depending on Flags indicates Print32 or Print32_setup dialog
2258 hDlgTmpl
= PRINTDLG_GetDlgTemplateW(lppd
);
2260 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2263 ptr
= LockResource( hDlgTmpl
);
2265 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2269 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2270 sizeof(PRINT_PTRW
));
2271 PrintStructures
->lpPrintDlg
= lppd
;
2273 /* and create & process the dialog .
2274 * -1 is failure, 0 is broken hwnd, everything else is ok.
2276 bRet
= (0<DialogBoxIndirectParamW(hInst
, ptr
, lppd
->hwndOwner
,
2278 (LPARAM
)PrintStructures
));
2281 DEVMODEW
*lpdm
= PrintStructures
->lpDevMode
, *lpdmReturn
;
2282 PRINTER_INFO_2W
*pi
= PrintStructures
->lpPrinterInfo
;
2283 DRIVER_INFO_3W
*di
= PrintStructures
->lpDriverInfo
;
2285 if (lppd
->hDevMode
== 0) {
2286 TRACE(" No hDevMode yet... Need to create my own\n");
2287 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
,
2288 lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2291 if((locks
= (GlobalFlags(lppd
->hDevMode
) & GMEM_LOCKCOUNT
))) {
2292 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks
);
2294 GlobalUnlock(lppd
->hDevMode
);
2295 TRACE("Now got %d locks\n", locks
);
2298 lppd
->hDevMode
= GlobalReAlloc(lppd
->hDevMode
,
2299 lpdm
->dmSize
+ lpdm
->dmDriverExtra
,
2302 lpdmReturn
= GlobalLock(lppd
->hDevMode
);
2303 memcpy(lpdmReturn
, lpdm
, lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2305 if (lppd
->hDevNames
!= 0) {
2307 if((locks
= (GlobalFlags(lppd
->hDevNames
) & GMEM_LOCKCOUNT
))) {
2308 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks
);
2310 GlobalUnlock(lppd
->hDevNames
);
2313 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
2318 GlobalUnlock(lppd
->hDevMode
);
2320 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
2321 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpPrinterInfo
);
2322 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDriverInfo
);
2323 HeapFree(GetProcessHeap(), 0, PrintStructures
);
2325 if(bRet
&& (lppd
->Flags
& PD_RETURNDC
|| lppd
->Flags
& PD_RETURNIC
))
2326 bRet
= PRINTDLG_CreateDCW(lppd
);
2328 TRACE("exit! (%d)\n", bRet
);
2332 /***********************************************************************
2337 * cmb1 - printer select (not in standard dialog template)
2339 * cmb3 - source (tray?)
2340 * edt4 - border left
2342 * edt6 - border right
2343 * edt7 - border bottom
2344 * psh3 - "Printer..."
2348 LPPAGESETUPDLGA dlga
; /* Handler to user defined struct */
2349 HWND hDlg
; /* Page Setup dialog handler */
2350 RECT rtDrawRect
; /* Drawing rect for page */
2354 LPPAGESETUPDLGW dlgw
;
2356 PAGESETUPDLGW curdlg
; /* Current dialog state */
2360 static HGLOBAL
PRINTDLG_GetPGSTemplateA(const PAGESETUPDLGA
*lppd
)
2365 if(lppd
->Flags
& PSD_ENABLEPAGESETUPTEMPLATEHANDLE
) {
2366 hDlgTmpl
= lppd
->hPageSetupTemplate
;
2367 } else if(lppd
->Flags
& PSD_ENABLEPAGESETUPTEMPLATE
) {
2368 hResInfo
= FindResourceA(lppd
->hInstance
,
2369 lppd
->lpPageSetupTemplateName
, (LPSTR
)RT_DIALOG
);
2370 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
2372 hResInfo
= FindResourceA(COMDLG32_hInstance
,(LPCSTR
)PAGESETUPDLGORD
,(LPSTR
)RT_DIALOG
);
2373 hDlgTmpl
= LoadResource(COMDLG32_hInstance
,hResInfo
);
2378 static HGLOBAL
PRINTDLG_GetPGSTemplateW(const PAGESETUPDLGW
*lppd
)
2383 if(lppd
->Flags
& PSD_ENABLEPAGESETUPTEMPLATEHANDLE
) {
2384 hDlgTmpl
= lppd
->hPageSetupTemplate
;
2385 } else if(lppd
->Flags
& PSD_ENABLEPAGESETUPTEMPLATE
) {
2386 hResInfo
= FindResourceW(lppd
->hInstance
,
2387 lppd
->lpPageSetupTemplateName
, (LPWSTR
)RT_DIALOG
);
2388 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
2390 hResInfo
= FindResourceW(COMDLG32_hInstance
,(LPCWSTR
)PAGESETUPDLGORD
,(LPWSTR
)RT_DIALOG
);
2391 hDlgTmpl
= LoadResource(COMDLG32_hInstance
,hResInfo
);
2396 static inline BOOL
is_metric(const PageSetupDataA
*pda
)
2398 return pda
->dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
;
2402 _c_10mm2size(PAGESETUPDLGA
*dlga
,DWORD size
) {
2403 if (dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
)
2404 return 10*size
*100/254;
2410 _c_inch2size(PAGESETUPDLGA
*dlga
,DWORD size
) {
2411 if (dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
)
2414 return (size
*254)/100;
2417 static void size2str(const PageSetupDataA
*pda
, DWORD size
, LPWSTR strout
)
2419 static const WCHAR metric_format
[] = {'%','d',0};
2420 static const WCHAR imperial_format
[] = {'%','d','i','n',0};
2423 wsprintfW(strout
, metric_format
, size
/ 100);
2425 wsprintfW(strout
, imperial_format
, size
/ 1000);
2429 _c_size2strW(PageSetupDataW
*pdw
,DWORD size
,LPWSTR strout
) {
2430 static const char mm_fmt
[] = "%.2f mm";
2431 static const char in_fmt
[] = "%.2f in";
2433 if (pdw
->dlgw
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
) {
2434 sprintf(buf
, mm_fmt
, (size
* 1.0) / 100.0);
2435 } else if (pdw
->dlgw
->Flags
& PSD_INTHOUSANDTHSOFINCHES
) {
2436 sprintf(buf
, in_fmt
, (size
* 1.0) / 1000.0);
2438 pdw
->dlgw
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
2439 sprintf(buf
, mm_fmt
, (size
* 1.0) / 100.0);
2442 MultiByteToWideChar(CP_ACP
, 0, buf
, -1, strout
, 20);
2446 _c_str2sizeA(const PAGESETUPDLGA
*dlga
, LPCSTR strin
) {
2451 if (!sscanf(strin
,"%f%s",&val
,rest
))
2454 if (!strcmp(rest
,"in") || !strcmp(rest
,"inch")) {
2455 if (dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
)
2458 return val
*25.4*100;
2460 if (!strcmp(rest
,"cm")) { rest
[0]='m'; val
= val
*10.0; }
2461 if (!strcmp(rest
,"m")) { strcpy(rest
,"mm"); val
= val
*1000.0; }
2463 if (!strcmp(rest
,"mm")) {
2464 if (dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
)
2467 return 1000.0*val
/25.4;
2469 if (rest
[0]=='\0') {
2470 /* use application supplied default */
2471 if (dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
) {
2475 if (dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
) {
2480 ERR("Did not find a conversion for type '%s'!\n",rest
);
2486 _c_str2sizeW(const PAGESETUPDLGW
*dlga
, LPCWSTR strin
) {
2489 /* this W -> A transition is OK */
2490 /* we need a unicode version of sscanf to avoid it */
2491 WideCharToMultiByte(CP_ACP
, 0, strin
, -1, buf
, sizeof(buf
), NULL
, NULL
);
2492 return _c_str2sizeA((const PAGESETUPDLGA
*)dlga
, buf
);
2495 static inline BOOL
is_default_metric(void)
2498 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_IMEASURE
| LOCALE_RETURN_NUMBER
,
2499 (LPWSTR
)&system
, sizeof(system
));
2503 /**********************************************
2505 * Cyclically permute the four members of rc
2506 * If sense is TRUE l -> t -> r -> b
2507 * otherwise l <- t <- r <- b
2509 static inline void rotate_rect(RECT
*rc
, BOOL sense
)
2515 rc
->bottom
= rc
->right
;
2516 rc
->right
= rc
->top
;
2524 rc
->top
= rc
->right
;
2525 rc
->right
= rc
->bottom
;
2530 static BOOL
pagesetup_papersizeA(PAGESETUPDLGA
*dlg
, const WORD paperword
, LPPOINT size
)
2534 LPSTR devname
, portname
;
2537 POINT
*points
= NULL
;
2538 BOOL retval
= FALSE
;
2540 dn
= GlobalLock(dlg
->hDevNames
);
2541 dm
= GlobalLock(dlg
->hDevMode
);
2542 devname
= ((char*)dn
)+dn
->wDeviceOffset
;
2543 portname
= ((char*)dn
)+dn
->wOutputOffset
;
2545 num
= DeviceCapabilitiesA(devname
, portname
, DC_PAPERS
, NULL
, dm
);
2548 FIXME("No papernames found for %s/%s\n", devname
, portname
);
2552 words
= HeapAlloc(GetProcessHeap(), 0, num
* sizeof(WORD
));
2553 points
= HeapAlloc(GetProcessHeap(), 0, num
* sizeof(POINT
));
2555 if (num
!= DeviceCapabilitiesA(devname
, portname
, DC_PAPERS
, (LPSTR
)words
, dm
))
2557 FIXME("Number of returned words is not %d\n", num
);
2561 if (num
!= DeviceCapabilitiesA(devname
, portname
, DC_PAPERSIZE
, (LPSTR
)points
, dm
))
2563 FIXME("Number of returned sizes is not %d\n",num
);
2567 for (i
= 0; i
< num
; i
++)
2568 if (words
[i
] == paperword
)
2573 FIXME("Papersize %d not found in list?\n", paperword
);
2577 /* this is _10ths_ of a millimeter */
2578 size
->x
= _c_10mm2size(dlg
, points
[i
].x
);
2579 size
->y
= _c_10mm2size(dlg
, points
[i
].y
);
2583 HeapFree(GetProcessHeap(), 0, words
);
2584 HeapFree(GetProcessHeap(), 0, points
);
2585 GlobalUnlock(dlg
->hDevNames
);
2586 GlobalUnlock(dlg
->hDevMode
);
2591 PRINTDLG_PS_UpdateDlgStructW(HWND hDlg
, PageSetupDataW
*pdw
) {
2594 LPWSTR devname
,portname
;
2595 WCHAR papername
[64];
2598 dn
= GlobalLock(pdw
->pdlg
.hDevNames
);
2599 dm
= GlobalLock(pdw
->pdlg
.hDevMode
);
2600 devname
= ((WCHAR
*)dn
)+dn
->wDeviceOffset
;
2601 portname
= ((WCHAR
*)dn
)+dn
->wOutputOffset
;
2603 /* Save paper size into device context */
2604 PRINTDLG_SetUpPaperComboBoxW(hDlg
,cmb2
,devname
,portname
,dm
);
2605 /* Save paper source into device context */
2606 PRINTDLG_SetUpPaperComboBoxW(hDlg
,cmb3
,devname
,portname
,dm
);
2608 if (GetDlgItemTextW(hDlg
,cmb2
,papername
,sizeof(papername
)/sizeof(papername
[0]))>0) {
2609 PRINTDLG_PaperSizeW(&(pdw
->pdlg
),papername
,&(pdw
->dlgw
->ptPaperSize
));
2610 pdw
->dlgw
->ptPaperSize
.x
= _c_10mm2size((LPPAGESETUPDLGA
)pdw
->dlgw
,pdw
->dlgw
->ptPaperSize
.x
);
2611 pdw
->dlgw
->ptPaperSize
.y
= _c_10mm2size((LPPAGESETUPDLGA
)pdw
->dlgw
,pdw
->dlgw
->ptPaperSize
.y
);
2613 FIXME("could not get dialog text for papersize cmbbox?\n");
2614 #define GETVAL(id,val) if (GetDlgItemTextW(hDlg,id,buf,sizeof(buf)/sizeof(buf[0]))>0) { val = _c_str2sizeW(pdw->dlgw,buf); } else { FIXME("could not get dlgitemtextw for %x\n",id); }
2615 GETVAL(edt4
,pdw
->dlgw
->rtMargin
.left
);
2616 GETVAL(edt5
,pdw
->dlgw
->rtMargin
.top
);
2617 GETVAL(edt6
,pdw
->dlgw
->rtMargin
.right
);
2618 GETVAL(edt7
,pdw
->dlgw
->rtMargin
.bottom
);
2621 /* If we are in landscape, swap x and y of page size */
2622 if (IsDlgButtonChecked(hDlg
, rad2
)) {
2624 tmp
= pdw
->dlgw
->ptPaperSize
.x
;
2625 pdw
->dlgw
->ptPaperSize
.x
= pdw
->dlgw
->ptPaperSize
.y
;
2626 pdw
->dlgw
->ptPaperSize
.y
= tmp
;
2629 /* Save orientation */
2630 if (pdw
->dlgw
->ptPaperSize
.x
> pdw
->dlgw
->ptPaperSize
.y
)
2631 dm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
2633 dm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
2635 GlobalUnlock(pdw
->pdlg
.hDevNames
);
2636 GlobalUnlock(pdw
->pdlg
.hDevMode
);
2640 /**********************************************************************************************
2641 * PRINTDLG_PS_ChangeActivePrinerA
2643 * Redefines hDevMode and hDevNames HANDLES and initialises it.
2646 * name [in] Name of a printer for activation
2647 * pda [in/out] ptr to PageSetupDataA structure
2654 PRINTDLG_PS_ChangeActivePrinterA(LPSTR name
, PageSetupDataA
*pda
){
2657 LPPRINTER_INFO_2A lpPrinterInfo
;
2658 LPDRIVER_INFO_3A lpDriverInfo
;
2659 DEVMODEA
*pDevMode
, *dm
;
2661 if(!OpenPrinterA(name
, &hprn
, NULL
)){
2662 ERR("Can't open printer %s\n", name
);
2665 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
2666 lpPrinterInfo
= HeapAlloc(GetProcessHeap(), 0, needed
);
2667 GetPrinterA(hprn
, 2, (LPBYTE
)lpPrinterInfo
, needed
, &needed
);
2668 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
2669 lpDriverInfo
= HeapAlloc(GetProcessHeap(), 0, needed
);
2670 if(!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)lpDriverInfo
, needed
, &needed
)) {
2671 ERR("GetPrinterDriverA failed for %s, fix your config!\n", lpPrinterInfo
->pPrinterName
);
2672 HeapFree(GetProcessHeap(), 0, lpDriverInfo
);
2673 HeapFree(GetProcessHeap(), 0, lpPrinterInfo
);
2678 needed
= DocumentPropertiesA(0, 0, name
, NULL
, NULL
, 0);
2680 ERR("DocumentProperties fails on %s\n", debugstr_a(name
));
2681 HeapFree(GetProcessHeap(), 0, lpDriverInfo
);
2682 HeapFree(GetProcessHeap(), 0, lpPrinterInfo
);
2685 pDevMode
= HeapAlloc(GetProcessHeap(), 0, needed
);
2686 DocumentPropertiesA(0, 0, name
, pDevMode
, NULL
, DM_OUT_BUFFER
);
2688 pda
->dlga
->hDevMode
= GlobalReAlloc(pda
->dlga
->hDevMode
,
2689 pDevMode
->dmSize
+ pDevMode
->dmDriverExtra
,
2691 dm
= GlobalLock(pda
->dlga
->hDevMode
);
2692 memcpy(dm
, pDevMode
, pDevMode
->dmSize
+ pDevMode
->dmDriverExtra
);
2694 PRINTDLG_CreateDevNames(&(pda
->dlga
->hDevNames
),
2695 lpDriverInfo
->pDriverPath
,
2696 lpPrinterInfo
->pPrinterName
,
2697 lpPrinterInfo
->pPortName
);
2699 GlobalUnlock(pda
->dlga
->hDevMode
);
2700 HeapFree(GetProcessHeap(), 0, pDevMode
);
2701 HeapFree(GetProcessHeap(), 0, lpPrinterInfo
);
2702 HeapFree(GetProcessHeap(), 0, lpDriverInfo
);
2706 /****************************************************************************************
2707 * PRINTDLG_PS_ChangePrinterA
2709 * Fills Printers, Paper and Source combo
2715 PRINTDLG_PS_ChangePrinterA(HWND hDlg
, PageSetupDataA
*pda
) {
2718 LPSTR devname
,portname
;
2720 dn
= GlobalLock(pda
->dlga
->hDevNames
);
2721 dm
= GlobalLock(pda
->dlga
->hDevMode
);
2722 devname
= ((char*)dn
)+dn
->wDeviceOffset
;
2723 portname
= ((char*)dn
)+dn
->wOutputOffset
;
2724 PRINTDLG_SetUpPrinterListComboA(hDlg
, cmb1
, devname
);
2725 PRINTDLG_SetUpPaperComboBoxA(hDlg
,cmb2
,devname
,portname
,dm
);
2726 PRINTDLG_SetUpPaperComboBoxA(hDlg
,cmb3
,devname
,portname
,dm
);
2727 GlobalUnlock(pda
->dlga
->hDevNames
);
2728 GlobalUnlock(pda
->dlga
->hDevMode
);
2732 static void PRINTDLG_PS_SetOrientationW(HWND hDlg
, PageSetupDataW
* pdw
)
2734 WCHAR PaperName
[64];
2736 GetDlgItemTextW(hDlg
, cmb2
, PaperName
, sizeof(PaperName
)/sizeof(WCHAR
));
2737 PRINTDLG_PaperSizeW(&pdw
->pdlg
, PaperName
, &pdw
->curdlg
.ptPaperSize
);
2738 pdw
->curdlg
.ptPaperSize
.x
= _c_10mm2size((LPPAGESETUPDLGA
)pdw
->dlgw
, pdw
->curdlg
.ptPaperSize
.x
);
2739 pdw
->curdlg
.ptPaperSize
.y
= _c_10mm2size((LPPAGESETUPDLGA
)pdw
->dlgw
, pdw
->curdlg
.ptPaperSize
.y
);
2741 if(IsDlgButtonChecked(hDlg
, rad2
))
2743 DWORD tmp
= pdw
->curdlg
.ptPaperSize
.x
;
2744 pdw
->curdlg
.ptPaperSize
.x
= pdw
->curdlg
.ptPaperSize
.y
;
2745 pdw
->curdlg
.ptPaperSize
.y
= tmp
;
2749 static void PRINTDLG_PS_UpdatePrintDlgW(PageSetupDataW
* pdw
, HWND hDlg
)
2754 dm
= GlobalLock(pdw
->pdlg
.hDevMode
);
2759 if(pdw
->curdlg
.ptPaperSize
.y
> pdw
->curdlg
.ptPaperSize
.x
)
2760 dm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
2762 dm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
2764 sel
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
2767 dm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETITEMDATA
, sel
, 0);
2769 GlobalUnlock(pdw
->pdlg
.hDevMode
);
2773 PRINTDLG_PS_ChangePrinterW(HWND hDlg
, PageSetupDataW
*pdw
) {
2776 LPWSTR devname
,portname
;
2778 dn
= GlobalLock(pdw
->pdlg
.hDevNames
);
2779 dm
= GlobalLock(pdw
->pdlg
.hDevMode
);
2780 devname
= ((WCHAR
*)dn
)+dn
->wDeviceOffset
;
2781 portname
= ((WCHAR
*)dn
)+dn
->wOutputOffset
;
2782 PRINTDLG_SetUpPaperComboBoxW(hDlg
,cmb2
,devname
,portname
,dm
);
2783 PRINTDLG_SetUpPaperComboBoxW(hDlg
,cmb3
,devname
,portname
,dm
);
2785 /* Landscape orientation */
2786 if (dm
->u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
)
2787 CheckRadioButton(hDlg
, rad1
, rad2
, rad2
);
2788 else /* this is default if papersize is not set */
2789 CheckRadioButton(hDlg
, rad1
, rad2
, rad1
);
2791 GlobalUnlock(pdw
->pdlg
.hDevNames
);
2792 GlobalUnlock(pdw
->pdlg
.hDevMode
);
2794 PRINTDLG_PS_SetOrientationW(hDlg
, pdw
);
2799 /******************************************************************************************
2800 * PRINTDLG_PS_ChangePaperPrev
2802 * Changes paper preview size / position
2805 * pda [i] Pointer for current PageSetupDataA structure
2811 PRINTDLG_PS_ChangePaperPrev(const PageSetupDataA
*pda
)
2813 LONG width
, height
, x
, y
;
2816 if(pda
->dlga
->ptPaperSize
.x
> pda
->dlga
->ptPaperSize
.y
) {
2817 width
= pda
->rtDrawRect
.right
- pda
->rtDrawRect
.left
;
2818 height
= pda
->dlga
->ptPaperSize
.y
* width
/ pda
->dlga
->ptPaperSize
.x
;
2820 height
= pda
->rtDrawRect
.bottom
- pda
->rtDrawRect
.top
;
2821 width
= pda
->dlga
->ptPaperSize
.x
* height
/ pda
->dlga
->ptPaperSize
.y
;
2823 x
= (pda
->rtDrawRect
.right
+ pda
->rtDrawRect
.left
- width
) / 2;
2824 y
= (pda
->rtDrawRect
.bottom
+ pda
->rtDrawRect
.top
- height
) / 2;
2825 TRACE("rtDrawRect(%d, %d, %d, %d) x=%d, y=%d, w=%d, h=%d\n",
2826 pda
->rtDrawRect
.left
, pda
->rtDrawRect
.top
, pda
->rtDrawRect
.right
, pda
->rtDrawRect
.bottom
,
2827 x
, y
, width
, height
);
2830 MoveWindow(GetDlgItem(pda
->hDlg
, rct2
), x
+width
, y
+SHADOW
, SHADOW
, height
, FALSE
);
2831 MoveWindow(GetDlgItem(pda
->hDlg
, rct3
), x
+SHADOW
, y
+height
, width
, SHADOW
, FALSE
);
2832 MoveWindow(GetDlgItem(pda
->hDlg
, rct1
), x
, y
, width
, height
, FALSE
);
2833 rtTmp
= pda
->rtDrawRect
;
2834 rtTmp
.right
+= SHADOW
;
2835 rtTmp
.bottom
+= SHADOW
;
2838 InvalidateRect(pda
->hDlg
, &rtTmp
, TRUE
);
2842 #define GETVAL(idc,val) \
2843 if(msg == EN_CHANGE){ \
2844 if (GetDlgItemTextA(hDlg,idc,buf,sizeof(buf)) > 0)\
2845 val = _c_str2sizeA(pda->dlga,buf); \
2847 FIXME("could not get dlgitemtexta for %x\n",id); \
2850 static void update_margin_edits(HWND hDlg
, const PageSetupDataA
*pda
)
2854 size2str(pda
, pda
->dlga
->rtMargin
.left
, str
);
2855 SetDlgItemTextW(hDlg
, edt4
, str
);
2856 size2str(pda
, pda
->dlga
->rtMargin
.top
, str
);
2857 SetDlgItemTextW(hDlg
, edt5
, str
);
2858 size2str(pda
, pda
->dlga
->rtMargin
.right
, str
);
2859 SetDlgItemTextW(hDlg
, edt6
, str
);
2860 size2str(pda
, pda
->dlga
->rtMargin
.bottom
, str
);
2861 SetDlgItemTextW(hDlg
, edt7
, str
);
2864 /********************************************************************************
2865 * PRINTDLG_PS_WMCommandA
2866 * process WM_COMMAND message for PageSetupDlgA
2869 * hDlg [in] Main dialog HANDLE
2870 * wParam [in] WM_COMMAND wParam
2871 * lParam [in] WM_COMMAND lParam
2872 * pda [in/out] ptr to PageSetupDataA
2876 PRINTDLG_PS_WMCommandA(
2877 HWND hDlg
, WPARAM wParam
, LPARAM lParam
, PageSetupDataA
*pda
2879 WORD msg
= HIWORD(wParam
);
2880 WORD id
= LOWORD(wParam
);
2883 TRACE("loword (lparam) %d, wparam 0x%lx, lparam %08lx\n",
2884 LOWORD(lParam
),wParam
,lParam
);
2887 EndDialog(hDlg
, TRUE
);
2891 EndDialog(hDlg
, FALSE
);
2897 memset(&prnt
, 0, sizeof(prnt
));
2898 prnt
.lStructSize
= sizeof(prnt
);
2900 prnt
.hwndOwner
= hDlg
;
2901 prnt
.hDevNames
= pda
->dlga
->hDevNames
;
2902 prnt
.hDevMode
= pda
->dlga
->hDevMode
;
2903 if (PrintDlgA(&prnt
))
2905 pda
->dlga
->hDevNames
= prnt
.hDevNames
;
2906 pda
->dlga
->hDevMode
= prnt
.hDevMode
;
2907 PRINTDLG_PS_ChangePrinterA(hDlg
,pda
);
2913 if((id
== rad1
&& pda
->dlga
->ptPaperSize
.x
> pda
->dlga
->ptPaperSize
.y
) ||
2914 (id
== rad2
&& pda
->dlga
->ptPaperSize
.y
> pda
->dlga
->ptPaperSize
.x
))
2916 DWORD tmp
= pda
->dlga
->ptPaperSize
.x
;
2917 DEVMODEA
*dm
= GlobalLock(pda
->dlga
->hDevMode
);
2919 pda
->dlga
->ptPaperSize
.x
= pda
->dlga
->ptPaperSize
.y
;
2920 pda
->dlga
->ptPaperSize
.y
= tmp
;
2922 dm
->u1
.s1
.dmOrientation
= (id
== rad1
) ? DMORIENT_PORTRAIT
: DMORIENT_LANDSCAPE
;
2923 GlobalUnlock(pda
->dlga
->hDevMode
);
2925 rotate_rect(&pda
->dlga
->rtMargin
, (id
== rad2
));
2926 update_margin_edits(hDlg
, pda
);
2928 PRINTDLG_PS_ChangePaperPrev(pda
);
2931 case cmb1
: /* Printer combo */
2932 if(msg
== CBN_SELCHANGE
){
2933 char crPrinterName
[256];
2934 GetDlgItemTextA(hDlg
, id
, crPrinterName
, 255);
2935 PRINTDLG_PS_ChangeActivePrinterA(crPrinterName
, pda
);
2936 PRINTDLG_PS_ChangePrinterA(hDlg
, pda
);
2939 case cmb2
: /* Paper combo */
2940 if(msg
== CBN_SELCHANGE
){
2941 DWORD paperword
= SendDlgItemMessageA(hDlg
,cmb2
,CB_GETITEMDATA
,
2942 SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0), 0);
2943 if (paperword
!= CB_ERR
)
2945 DEVMODEA
*dm
= GlobalLock(pda
->dlga
->hDevMode
);
2946 dm
->u1
.s1
.dmPaperSize
= paperword
;
2947 GlobalUnlock(pda
->dlga
->hDevMode
);
2948 pagesetup_papersizeA(pda
->dlga
, paperword
, &(pda
->dlga
->ptPaperSize
));
2949 if (IsDlgButtonChecked(hDlg
, rad2
)) {
2950 DWORD tmp
= pda
->dlga
->ptPaperSize
.x
;
2951 pda
->dlga
->ptPaperSize
.x
= pda
->dlga
->ptPaperSize
.y
;
2952 pda
->dlga
->ptPaperSize
.y
= tmp
;
2954 PRINTDLG_PS_ChangePaperPrev(pda
);
2956 FIXME("could not get dialog text for papersize cmbbox?\n");
2960 if(msg
== CBN_SELCHANGE
){
2961 DEVMODEA
*dm
= GlobalLock(pda
->dlga
->hDevMode
);
2962 dm
->u1
.s1
.dmDefaultSource
= SendDlgItemMessageA(hDlg
, cmb3
,CB_GETITEMDATA
,
2963 SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0), 0);
2964 GlobalUnlock(pda
->dlga
->hDevMode
);
2967 case psh2
: /* Printer Properties button */
2970 char PrinterName
[256];
2975 GetDlgItemTextA(hDlg
, cmb1
, PrinterName
, 255);
2976 if (!OpenPrinterA(PrinterName
, &hPrinter
, NULL
)) {
2977 FIXME("Call to OpenPrinter did not succeed!\n");
2980 dm
= GlobalLock(pda
->dlga
->hDevMode
);
2981 DocumentPropertiesA(hDlg
, hPrinter
, PrinterName
, dm
, dm
,
2982 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
2983 ClosePrinter(hPrinter
);
2984 /* Changing paper */
2985 pagesetup_papersizeA(pda
->dlga
, dm
->u1
.s1
.dmPaperSize
, &(pda
->dlga
->ptPaperSize
));
2986 if (dm
->u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
){
2987 DWORD tmp
= pda
->dlga
->ptPaperSize
.x
;
2988 pda
->dlga
->ptPaperSize
.x
= pda
->dlga
->ptPaperSize
.y
;
2989 pda
->dlga
->ptPaperSize
.y
= tmp
;
2990 CheckRadioButton(hDlg
, rad1
, rad2
, rad2
);
2993 CheckRadioButton(hDlg
, rad1
, rad2
, rad1
);
2994 /* Changing paper preview */
2995 PRINTDLG_PS_ChangePaperPrev(pda
);
2996 /* Selecting paper in combo */
2997 count
= SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCOUNT
, 0, 0);
2998 if(count
!= CB_ERR
){
2999 for(i
=0; i
<count
; ++i
){
3000 if(SendDlgItemMessageA(hDlg
, cmb2
, CB_GETITEMDATA
, i
, 0) == dm
->u1
.s1
.dmPaperSize
) {
3001 SendDlgItemMessageA(hDlg
, cmb2
, CB_SETCURSEL
, i
, 0);
3007 GlobalUnlock(pda
->dlga
->hDevMode
);
3011 GETVAL(id
, pda
->dlga
->rtMargin
.left
);
3014 GETVAL(id
, pda
->dlga
->rtMargin
.top
);
3017 GETVAL(id
, pda
->dlga
->rtMargin
.right
);
3020 GETVAL(id
, pda
->dlga
->rtMargin
.bottom
);
3023 InvalidateRect(GetDlgItem(hDlg
, rct1
), NULL
, TRUE
);
3029 PRINTDLG_PS_WMCommandW(
3030 HWND hDlg
, WPARAM wParam
, LPARAM lParam
, PageSetupDataW
*pdw
3032 TRACE("loword (lparam) %d, wparam 0x%lx, lparam %08lx\n",
3033 LOWORD(lParam
),wParam
,lParam
);
3034 switch (LOWORD(wParam
)) {
3036 if (!PRINTDLG_PS_UpdateDlgStructW(hDlg
, pdw
))
3038 EndDialog(hDlg
, TRUE
);
3042 EndDialog(hDlg
, FALSE
);
3047 if((LOWORD(wParam
) == rad1
&& pdw
->curdlg
.ptPaperSize
.x
> pdw
->curdlg
.ptPaperSize
.y
) ||
3048 (LOWORD(wParam
) == rad2
&& pdw
->curdlg
.ptPaperSize
.y
> pdw
->curdlg
.ptPaperSize
.x
))
3052 DWORD tmp
= pdw
->curdlg
.ptPaperSize
.y
;
3054 pdw
->curdlg
.ptPaperSize
.y
= pdw
->curdlg
.ptPaperSize
.x
;
3055 pdw
->curdlg
.ptPaperSize
.x
= tmp
;
3057 GetDlgItemTextW(hDlg
, edt4
, tmpText
, sizeof(tmpText
)/sizeof(WCHAR
));
3058 GetDlgItemTextW(hDlg
, edt5
, tmpText2
, sizeof(tmpText2
)/sizeof(WCHAR
));
3059 SetDlgItemTextW(hDlg
, edt5
, tmpText
);
3060 SetDlgItemTextW(hDlg
, edt4
, tmpText2
);
3062 GetDlgItemTextW(hDlg
, edt6
, tmpText
, sizeof(tmpText
)/sizeof(WCHAR
));
3063 GetDlgItemTextW(hDlg
, edt7
, tmpText2
, sizeof(tmpText2
)/sizeof(WCHAR
));
3064 SetDlgItemTextW(hDlg
, edt7
, tmpText
);
3065 SetDlgItemTextW(hDlg
, edt6
, tmpText2
);
3070 pdw
->pdlg
.Flags
= 0;
3071 pdw
->pdlg
.hwndOwner
= hDlg
;
3072 PRINTDLG_PS_UpdatePrintDlgW(pdw
, hDlg
);
3073 if (PrintDlgW(&(pdw
->pdlg
)))
3074 PRINTDLG_PS_ChangePrinterW(hDlg
,pdw
);
3082 /***********************************************************************
3083 * DefaultPagePaintHook
3084 * Default hook paint procedure that receives WM_PSD_* messages from the dialog box
3085 * whenever the sample page is redrawn.
3089 PRINTDLG_DefaultPagePaintHook(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
,
3090 const PageSetupDataA
*pda
)
3092 LPRECT lprc
= (LPRECT
) lParam
;
3093 HDC hdc
= (HDC
) wParam
;
3096 HFONT hfont
, holdfont
;
3098 TRACE("uMsg: WM_USER+%d\n",uMsg
-WM_USER
);
3099 /* Call user paint hook if enable */
3100 if (pda
->dlga
->Flags
& PSD_ENABLEPAGEPAINTHOOK
)
3101 if (pda
->dlga
->lpfnPagePaintHook(hwndDlg
, uMsg
, wParam
, lParam
))
3105 /* LPPAGESETUPDLG in lParam */
3106 case WM_PSD_PAGESETUPDLG
:
3107 /* Inform about the sample page rectangle */
3108 case WM_PSD_FULLPAGERECT
:
3109 /* Inform about the margin rectangle */
3110 case WM_PSD_MINMARGINRECT
:
3113 /* Draw dashed rectangle showing margins */
3114 case WM_PSD_MARGINRECT
:
3115 hpen
= CreatePen(PS_DASH
, 1, GetSysColor(COLOR_3DSHADOW
));
3116 holdpen
= SelectObject(hdc
, hpen
);
3117 Rectangle(hdc
, lprc
->left
, lprc
->top
, lprc
->right
, lprc
->bottom
);
3118 DeleteObject(SelectObject(hdc
, holdpen
));
3120 /* Draw the fake document */
3121 case WM_PSD_GREEKTEXTRECT
:
3122 /* select a nice scalable font, because we want the text really small */
3123 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, sizeof(lf
), &lf
, 0);
3124 lf
.lfHeight
= 6; /* value chosen based on visual effect */
3125 hfont
= CreateFontIndirectW(&lf
);
3126 holdfont
= SelectObject(hdc
, hfont
);
3128 /* if text not loaded, then do so now */
3129 if (wszFakeDocumentText
[0] == '\0')
3130 LoadStringW(COMDLG32_hInstance
,
3132 wszFakeDocumentText
,
3133 sizeof(wszFakeDocumentText
)/sizeof(wszFakeDocumentText
[0]));
3135 oldbkmode
= SetBkMode(hdc
, TRANSPARENT
);
3136 DrawTextW(hdc
, wszFakeDocumentText
, -1, lprc
, DT_TOP
|DT_LEFT
|DT_NOPREFIX
|DT_WORDBREAK
);
3137 SetBkMode(hdc
, oldbkmode
);
3139 DeleteObject(SelectObject(hdc
, holdfont
));
3142 /* Envelope stamp */
3143 case WM_PSD_ENVSTAMPRECT
:
3144 /* Return address */
3145 case WM_PSD_YAFULLPAGERECT
:
3146 FIXME("envelope/stamp is not implemented\n");
3149 FIXME("Unknown message %x\n",uMsg
);
3155 /***********************************************************************
3157 * The main paint procedure for the PageSetupDlg function.
3158 * The Page Setup dialog box includes an image of a sample page that shows how
3159 * the user's selections affect the appearance of the printed output.
3160 * The image consists of a rectangle that represents the selected paper
3161 * or envelope type, with a dotted-line rectangle representing
3162 * the current margins, and partial (Greek text) characters
3163 * to show how text looks on the printed page.
3165 * The following messages in the order sends to user hook procedure:
3166 * WM_PSD_PAGESETUPDLG Draw the contents of the sample page
3167 * WM_PSD_FULLPAGERECT Inform about the bounding rectangle
3168 * WM_PSD_MINMARGINRECT Inform about the margin rectangle (min margin?)
3169 * WM_PSD_MARGINRECT Draw the margin rectangle
3170 * WM_PSD_GREEKTEXTRECT Draw the Greek text inside the margin rectangle
3171 * If any of first three messages returns TRUE, painting done.
3174 * hWnd [in] Handle to the Page Setup dialog box
3175 * uMsg [in] Received message
3178 * WM_PSD_ENVSTAMPRECT Draw in the envelope-stamp rectangle (for envelopes only)
3179 * WM_PSD_YAFULLPAGERECT Draw the return address portion (for envelopes and other paper sizes)
3182 * FALSE if all done correctly
3187 static LRESULT CALLBACK
3188 PRINTDLG_PagePaintProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3191 RECT rcClient
, rcMargin
;
3194 HBRUSH hbrush
, holdbrush
;
3195 PageSetupDataA
*pda
;
3196 int papersize
=0, orientation
=0; /* FIXME: set this values for user paint hook */
3197 double scalx
, scaly
;
3198 #define CALLPAINTHOOK(msg,lprc) PRINTDLG_DefaultPagePaintHook( hWnd, msg, (WPARAM)hdc, (LPARAM)lprc, pda)
3200 if (uMsg
!= WM_PAINT
)
3201 return CallWindowProcA(lpfnStaticWndProc
, hWnd
, uMsg
, wParam
, lParam
);
3203 /* Processing WM_PAINT message */
3204 pda
= GetPropW(hWnd
, pagesetupdlg_prop
);
3206 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3209 if (PRINTDLG_DefaultPagePaintHook(hWnd
, WM_PSD_PAGESETUPDLG
, MAKELONG(papersize
, orientation
), (LPARAM
)pda
->dlga
, pda
))
3212 hdc
= BeginPaint(hWnd
, &ps
);
3213 GetClientRect(hWnd
, &rcClient
);
3215 scalx
= rcClient
.right
/ (double)pda
->dlga
->ptPaperSize
.x
;
3216 scaly
= rcClient
.bottom
/ (double)pda
->dlga
->ptPaperSize
.y
;
3217 rcMargin
= rcClient
;
3219 rcMargin
.left
+= pda
->dlga
->rtMargin
.left
* scalx
;
3220 rcMargin
.top
+= pda
->dlga
->rtMargin
.top
* scalx
;
3221 rcMargin
.right
-= pda
->dlga
->rtMargin
.right
* scaly
;
3222 rcMargin
.bottom
-= pda
->dlga
->rtMargin
.bottom
* scaly
;
3224 /* if the space is too small then we make sure to not draw anything */
3225 rcMargin
.left
= min(rcMargin
.left
, rcMargin
.right
);
3226 rcMargin
.top
= min(rcMargin
.top
, rcMargin
.bottom
);
3228 if (!CALLPAINTHOOK(WM_PSD_FULLPAGERECT
, &rcClient
) &&
3229 !CALLPAINTHOOK(WM_PSD_MINMARGINRECT
, &rcMargin
) )
3231 /* fill background */
3232 hbrush
= GetSysColorBrush(COLOR_3DHIGHLIGHT
);
3233 FillRect(hdc
, &rcClient
, hbrush
);
3234 holdbrush
= SelectObject(hdc
, hbrush
);
3236 hpen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DSHADOW
));
3237 holdpen
= SelectObject(hdc
, hpen
);
3239 /* paint left edge */
3240 MoveToEx(hdc
, rcClient
.left
, rcClient
.top
, NULL
);
3241 LineTo(hdc
, rcClient
.left
, rcClient
.bottom
-1);
3243 /* paint top edge */
3244 MoveToEx(hdc
, rcClient
.left
, rcClient
.top
, NULL
);
3245 LineTo(hdc
, rcClient
.right
, rcClient
.top
);
3247 hpen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DDKSHADOW
));
3248 DeleteObject(SelectObject(hdc
, hpen
));
3250 /* paint right edge */
3251 MoveToEx(hdc
, rcClient
.right
-1, rcClient
.top
, NULL
);
3252 LineTo(hdc
, rcClient
.right
-1, rcClient
.bottom
);
3254 /* paint bottom edge */
3255 MoveToEx(hdc
, rcClient
.left
, rcClient
.bottom
-1, NULL
);
3256 LineTo(hdc
, rcClient
.right
, rcClient
.bottom
-1);
3258 DeleteObject(SelectObject(hdc
, holdpen
));
3259 DeleteObject(SelectObject(hdc
, holdbrush
));
3261 CALLPAINTHOOK(WM_PSD_MARGINRECT
, &rcMargin
);
3263 /* give text a bit of a space from the frame */
3266 rcMargin
.right
-= 2;
3267 rcMargin
.bottom
-= 2;
3269 /* if the space is too small then we make sure to not draw anything */
3270 rcMargin
.left
= min(rcMargin
.left
, rcMargin
.right
);
3271 rcMargin
.top
= min(rcMargin
.top
, rcMargin
.bottom
);
3273 CALLPAINTHOOK(WM_PSD_GREEKTEXTRECT
, &rcMargin
);
3276 EndPaint(hWnd
, &ps
);
3278 #undef CALLPAINTHOOK
3281 /***********************************************************************
3282 * PRINTDLG_PageDlgProcA
3283 * Message handler for PageSetupDlgA
3285 static INT_PTR CALLBACK
3286 PRINTDLG_PageDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3289 PageSetupDataA
*pda
;
3290 INT_PTR res
= FALSE
;
3293 if (uMsg
== WM_INITDIALOG
) { /*Init dialog*/
3294 pda
= (PageSetupDataA
*)lParam
;
3295 pda
->hDlg
= hDlg
; /* saving handle to main window to PageSetupDataA structure */
3297 hDrawWnd
= GetDlgItem(hDlg
, rct1
);
3298 TRACE("set property to %p\n", pda
);
3299 SetPropW(hDlg
, pagesetupdlg_prop
, pda
);
3300 SetPropW(hDrawWnd
, pagesetupdlg_prop
, pda
);
3301 GetWindowRect(hDrawWnd
, &pda
->rtDrawRect
); /* Calculating rect in client coordinates where paper draws */
3302 ScreenToClient(hDlg
, (LPPOINT
)&pda
->rtDrawRect
);
3303 ScreenToClient(hDlg
, (LPPOINT
)(&pda
->rtDrawRect
.right
));
3304 lpfnStaticWndProc
= (WNDPROC
)SetWindowLongPtrW(
3307 (ULONG_PTR
)PRINTDLG_PagePaintProc
);
3309 /* FIXME: Paint hook. Must it be at begin of initialization or at end? */
3311 if (pda
->dlga
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
3312 if (!pda
->dlga
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,(LPARAM
)pda
->dlga
))
3313 FIXME("Setup page hook failed?\n");
3316 /* if printer button disabled */
3317 if (pda
->dlga
->Flags
& PSD_DISABLEPRINTER
)
3318 EnableWindow(GetDlgItem(hDlg
, psh3
), FALSE
);
3319 /* if margin edit boxes disabled */
3320 if (pda
->dlga
->Flags
& PSD_DISABLEMARGINS
) {
3321 EnableWindow(GetDlgItem(hDlg
, edt4
), FALSE
);
3322 EnableWindow(GetDlgItem(hDlg
, edt5
), FALSE
);
3323 EnableWindow(GetDlgItem(hDlg
, edt6
), FALSE
);
3324 EnableWindow(GetDlgItem(hDlg
, edt7
), FALSE
);
3326 /* Set orientation radiobutton properly */
3327 if(pda
->dlga
->hDevMode
)
3329 dm
= GlobalLock(pda
->dlga
->hDevMode
);
3330 if (dm
->u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
)
3331 CheckRadioButton(hDlg
, rad1
, rad2
, rad2
);
3332 else /* this is default if papersize is not set */
3333 CheckRadioButton(hDlg
, rad1
, rad2
, rad1
);
3334 GlobalUnlock(pda
->dlga
->hDevMode
);
3337 /* if orientation disabled */
3338 if (pda
->dlga
->Flags
& PSD_DISABLEORIENTATION
) {
3339 EnableWindow(GetDlgItem(hDlg
,rad1
),FALSE
);
3340 EnableWindow(GetDlgItem(hDlg
,rad2
),FALSE
);
3343 /* We fill them out enabled or not */
3344 if (!(pda
->dlga
->Flags
& PSD_MARGINS
))
3346 /* default is 1 inch */
3347 DWORD size
= _c_inch2size(pda
->dlga
,1000);
3348 pda
->dlga
->rtMargin
.left
= size
;
3349 pda
->dlga
->rtMargin
.top
= size
;
3350 pda
->dlga
->rtMargin
.right
= size
;
3351 pda
->dlga
->rtMargin
.bottom
= size
;
3353 update_margin_edits(hDlg
, pda
);
3355 /* if paper disabled */
3356 if (pda
->dlga
->Flags
& PSD_DISABLEPAPER
) {
3357 EnableWindow(GetDlgItem(hDlg
,cmb2
),FALSE
);
3358 EnableWindow(GetDlgItem(hDlg
,cmb3
),FALSE
);
3360 /* filling combos: printer, paper, source. selecting current printer (from DEVMODEA) */
3361 PRINTDLG_PS_ChangePrinterA(hDlg
, pda
);
3362 dm
= GlobalLock(pda
->dlga
->hDevMode
);
3364 dm
->u1
.s1
.dmDefaultSource
= 15; /*FIXME: Automatic select. Does it always 15 at start? */
3365 pagesetup_papersizeA(pda
->dlga
, dm
->u1
.s1
.dmPaperSize
, &pda
->dlga
->ptPaperSize
);
3366 GlobalUnlock(pda
->dlga
->hDevMode
);
3367 if (IsDlgButtonChecked(hDlg
, rad2
) == BST_CHECKED
) { /* Landscape orientation */
3368 DWORD tmp
= pda
->dlga
->ptPaperSize
.y
;
3369 pda
->dlga
->ptPaperSize
.y
= pda
->dlga
->ptPaperSize
.x
;
3370 pda
->dlga
->ptPaperSize
.x
= tmp
;
3373 WARN("GlobalLock(pda->dlga->hDevMode) fail? hDevMode=%p\n", pda
->dlga
->hDevMode
);
3374 /* Drawing paper prev */
3375 PRINTDLG_PS_ChangePaperPrev(pda
);
3378 pda
= GetPropW(hDlg
, pagesetupdlg_prop
);
3380 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3383 if (pda
->dlga
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
3384 res
= pda
->dlga
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,lParam
);
3385 if (res
) return res
;
3390 return PRINTDLG_PS_WMCommandA(hDlg
, wParam
, lParam
, pda
);
3395 static INT_PTR CALLBACK
3396 PageDlgProcW(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3398 PageSetupDataW
*pdw
;
3401 if (uMsg
==WM_INITDIALOG
) {
3403 pdw
= (PageSetupDataW
*)lParam
;
3404 pdw
->curdlg
= *pdw
->dlgw
;
3405 SetPropW(hDlg
, pagesetupdlg_prop
, pdw
);
3406 if (pdw
->dlgw
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
3407 res
= pdw
->dlgw
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,(LPARAM
)pdw
->dlgw
);
3409 FIXME("Setup page hook failed?\n");
3414 if (pdw
->dlgw
->Flags
& PSD_ENABLEPAGEPAINTHOOK
) {
3415 FIXME("PagePaintHook not yet implemented!\n");
3417 if (pdw
->dlgw
->Flags
& PSD_DISABLEPRINTER
)
3418 EnableWindow(GetDlgItem(hDlg
, psh3
), FALSE
);
3419 if (pdw
->dlgw
->Flags
& PSD_DISABLEMARGINS
) {
3420 EnableWindow(GetDlgItem(hDlg
, edt4
), FALSE
);
3421 EnableWindow(GetDlgItem(hDlg
, edt5
), FALSE
);
3422 EnableWindow(GetDlgItem(hDlg
, edt6
), FALSE
);
3423 EnableWindow(GetDlgItem(hDlg
, edt7
), FALSE
);
3426 PRINTDLG_PS_ChangePrinterW(hDlg
,pdw
);
3428 if (pdw
->dlgw
->Flags
& PSD_DISABLEORIENTATION
) {
3429 EnableWindow(GetDlgItem(hDlg
,rad1
),FALSE
);
3430 EnableWindow(GetDlgItem(hDlg
,rad2
),FALSE
);
3432 /* We fill them out enabled or not */
3433 if (pdw
->dlgw
->Flags
& PSD_MARGINS
) {
3435 _c_size2strW(pdw
,pdw
->dlgw
->rtMargin
.left
,str
);
3436 SetDlgItemTextW(hDlg
,edt4
,str
);
3437 _c_size2strW(pdw
,pdw
->dlgw
->rtMargin
.top
,str
);
3438 SetDlgItemTextW(hDlg
,edt5
,str
);
3439 _c_size2strW(pdw
,pdw
->dlgw
->rtMargin
.right
,str
);
3440 SetDlgItemTextW(hDlg
,edt6
,str
);
3441 _c_size2strW(pdw
,pdw
->dlgw
->rtMargin
.bottom
,str
);
3442 SetDlgItemTextW(hDlg
,edt7
,str
);
3444 /* default is 1 inch */
3445 DWORD size
= _c_inch2size((LPPAGESETUPDLGA
)pdw
->dlgw
,1000);
3447 _c_size2strW(pdw
,size
,str
);
3448 SetDlgItemTextW(hDlg
,edt4
,str
);
3449 SetDlgItemTextW(hDlg
,edt5
,str
);
3450 SetDlgItemTextW(hDlg
,edt6
,str
);
3451 SetDlgItemTextW(hDlg
,edt7
,str
);
3454 if (pdw
->dlgw
->Flags
& PSD_DISABLEPAPER
) {
3455 EnableWindow(GetDlgItem(hDlg
,cmb2
),FALSE
);
3456 EnableWindow(GetDlgItem(hDlg
,cmb3
),FALSE
);
3461 pdw
= GetPropW(hDlg
, pagesetupdlg_prop
);
3463 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3466 if (pdw
->dlgw
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
3467 res
= pdw
->dlgw
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,lParam
);
3468 if (res
) return res
;
3473 return PRINTDLG_PS_WMCommandW(hDlg
, wParam
, lParam
, pdw
);
3478 /***********************************************************************
3479 * PageSetupDlgA (COMDLG32.@)
3481 * Displays the PAGE SETUP dialog box, which enables the user to specify
3482 * specific properties of a printed page such as
3483 * size, source, orientation and the width of the page margins.
3486 * setupdlg [IO] PAGESETUPDLGA struct
3489 * TRUE if the user pressed the OK button
3490 * FALSE if the user cancelled the window or an error occurred
3493 * The values of hDevMode and hDevNames are filled on output and can be
3494 * changed in PAGESETUPDLG when they are passed in PageSetupDlg.
3498 BOOL WINAPI
PageSetupDlgA(LPPAGESETUPDLGA setupdlg
) {
3502 PageSetupDataA
*pda
;
3504 if (setupdlg
== NULL
) {
3505 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
3510 if(TRACE_ON(commdlg
)) {
3511 char flagstr
[1000] = "";
3512 const struct pd_flags
*pflag
= psd_flags
;
3513 for( ; pflag
->name
; pflag
++) {
3514 if(setupdlg
->Flags
& pflag
->flag
) {
3515 strcat(flagstr
, pflag
->name
);
3516 strcat(flagstr
, "|");
3519 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3520 "hinst %p, flags %08x (%s)\n",
3521 setupdlg
, setupdlg
->hwndOwner
, setupdlg
->hDevMode
,
3522 setupdlg
->hDevNames
,
3523 setupdlg
->hInstance
, setupdlg
->Flags
, flagstr
);
3526 /* Checking setupdlg structure */
3527 if(setupdlg
->lStructSize
!= sizeof(PAGESETUPDLGA
)) {
3528 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
3531 if ((setupdlg
->Flags
& PSD_ENABLEPAGEPAINTHOOK
) &&
3532 (setupdlg
->lpfnPagePaintHook
== NULL
)) {
3533 COMDLG32_SetCommDlgExtendedError(CDERR_NOHOOK
);
3537 if(!(setupdlg
->Flags
& (PSD_INTHOUSANDTHSOFINCHES
| PSD_INHUNDREDTHSOFMILLIMETERS
)))
3538 setupdlg
->Flags
|= is_default_metric() ?
3539 PSD_INHUNDREDTHSOFMILLIMETERS
: PSD_INTHOUSANDTHSOFINCHES
;
3541 /* Initialize default printer struct. If no printer device info is specified
3542 retrieve the default printer data. */
3543 if (!setupdlg
->hDevMode
|| !setupdlg
->hDevNames
)
3546 memset(&pdlg
, 0, sizeof(pdlg
));
3547 pdlg
.lStructSize
= sizeof(pdlg
);
3548 pdlg
.Flags
= PD_RETURNDEFAULT
;
3549 bRet
= PrintDlgA(&pdlg
);
3552 if (!(setupdlg
->Flags
& PSD_NOWARNING
)) {
3554 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEFAULT_PRINTER
, errstr
, 255);
3555 MessageBoxW(setupdlg
->hwndOwner
, errstr
, 0, MB_OK
| MB_ICONERROR
);
3559 setupdlg
->hDevMode
= pdlg
.hDevMode
;
3560 setupdlg
->hDevNames
= pdlg
.hDevNames
;
3563 /* short cut exit, just return default values */
3564 if (setupdlg
->Flags
& PSD_RETURNDEFAULT
) {
3566 dm
= GlobalLock(setupdlg
->hDevMode
);
3567 pagesetup_papersizeA(setupdlg
, dm
->u1
.s1
.dmPaperSize
, &setupdlg
->ptPaperSize
);
3568 GlobalUnlock(setupdlg
->hDevMode
);
3572 /* get dialog template */
3573 hDlgTmpl
= PRINTDLG_GetPGSTemplateA(setupdlg
);
3575 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
3578 ptr
= LockResource( hDlgTmpl
);
3580 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
3584 pda
= HeapAlloc(GetProcessHeap(),0,sizeof(*pda
));
3585 pda
->dlga
= setupdlg
;
3587 bRet
= (0<DialogBoxIndirectParamW(
3588 setupdlg
->hInstance
,
3590 setupdlg
->hwndOwner
,
3591 PRINTDLG_PageDlgProcA
,
3595 HeapFree(GetProcessHeap(),0,pda
);
3598 /***********************************************************************
3599 * PageSetupDlgW (COMDLG32.@)
3601 * See PageSetupDlgA.
3603 BOOL WINAPI
PageSetupDlgW(LPPAGESETUPDLGW setupdlg
) {
3607 PageSetupDataW
*pdw
;
3610 FIXME("Unicode implementation is not done yet\n");
3612 if (setupdlg
== NULL
) {
3613 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
3617 if(TRACE_ON(commdlg
)) {
3618 char flagstr
[1000] = "";
3619 const struct pd_flags
*pflag
= psd_flags
;
3620 for( ; pflag
->name
; pflag
++) {
3621 if(setupdlg
->Flags
& pflag
->flag
) {
3622 strcat(flagstr
, pflag
->name
);
3623 strcat(flagstr
, "|");
3626 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3627 "hinst %p, flags %08x (%s)\n",
3628 setupdlg
, setupdlg
->hwndOwner
, setupdlg
->hDevMode
,
3629 setupdlg
->hDevNames
,
3630 setupdlg
->hInstance
, setupdlg
->Flags
, flagstr
);
3633 /* Initialize default printer struct. If no printer device info is specified
3634 retrieve the default printer data. */
3635 memset(&pdlg
,0,sizeof(pdlg
));
3636 pdlg
.lStructSize
= sizeof(pdlg
);
3637 if (setupdlg
->hDevMode
&& setupdlg
->hDevNames
) {
3638 pdlg
.hDevMode
= setupdlg
->hDevMode
;
3639 pdlg
.hDevNames
= setupdlg
->hDevNames
;
3641 pdlg
.Flags
= PD_RETURNDEFAULT
;
3642 bRet
= PrintDlgW(&pdlg
);
3644 if (!(setupdlg
->Flags
& PSD_NOWARNING
)) {
3646 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEFAULT_PRINTER
, errstr
, 255);
3647 MessageBoxW(setupdlg
->hwndOwner
, errstr
, 0, MB_OK
| MB_ICONERROR
);
3653 /* short cut exit, just return default values */
3654 if (setupdlg
->Flags
& PSD_RETURNDEFAULT
) {
3655 static const WCHAR a4
[] = {'A','4',0};
3656 setupdlg
->hDevMode
= pdlg
.hDevMode
;
3657 setupdlg
->hDevNames
= pdlg
.hDevNames
;
3658 /* FIXME: Just return "A4" for now. */
3659 PRINTDLG_PaperSizeW(&pdlg
,a4
,&setupdlg
->ptPaperSize
);
3660 setupdlg
->ptPaperSize
.x
=_c_10mm2size((LPPAGESETUPDLGA
)setupdlg
,setupdlg
->ptPaperSize
.x
);
3661 setupdlg
->ptPaperSize
.y
=_c_10mm2size((LPPAGESETUPDLGA
)setupdlg
,setupdlg
->ptPaperSize
.y
);
3664 hDlgTmpl
= PRINTDLG_GetPGSTemplateW(setupdlg
);
3666 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
3669 ptr
= LockResource( hDlgTmpl
);
3671 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
3674 pdw
= HeapAlloc(GetProcessHeap(),0,sizeof(*pdw
));
3675 pdw
->dlgw
= setupdlg
;
3678 bRet
= (0<DialogBoxIndirectParamW(
3679 setupdlg
->hInstance
,
3681 setupdlg
->hwndOwner
,
3688 /***********************************************************************
3689 * PrintDlgExA (COMDLG32.@)
3697 HRESULT WINAPI
PrintDlgExA(LPPRINTDLGEXA lppd
)
3700 FIXME("(%p) stub\n", lppd
);
3701 if ((lppd
== NULL
) || (lppd
->lStructSize
!= sizeof(PRINTDLGEXA
))) {
3702 return E_INVALIDARG
;
3705 if (!IsWindow(lppd
->hwndOwner
)) {
3712 /***********************************************************************
3713 * PrintDlgExW (COMDLG32.@)
3715 * Display the property sheet style PRINT dialog box
3718 * lppd [IO] ptr to PRINTDLGEX struct
3722 * Failure: One of the following COM error codes:
3723 * E_OUTOFMEMORY Insufficient memory.
3724 * E_INVALIDARG One or more arguments are invalid.
3725 * E_POINTER Invalid pointer.
3726 * E_HANDLE Invalid handle.
3727 * E_FAIL Unspecified error.
3730 * This Dialog enables the user to specify specific properties of the print job.
3731 * The property sheet can also have additional application-specific and
3732 * driver-specific property pages.
3735 * Not fully implemented
3738 HRESULT WINAPI
PrintDlgExW(LPPRINTDLGEXW lppd
)
3743 FIXME("(%p) not fully implemented\n", lppd
);
3745 if ((lppd
== NULL
) || (lppd
->lStructSize
!= sizeof(PRINTDLGEXW
))) {
3746 return E_INVALIDARG
;
3749 if (!IsWindow(lppd
->hwndOwner
)) {
3753 if (lppd
->Flags
& PD_RETURNDEFAULT
) {
3754 PRINTER_INFO_2W
*pbuf
;
3755 DRIVER_INFO_2W
*dbuf
;
3757 DWORD needed
= 1024;
3760 if (lppd
->hDevMode
|| lppd
->hDevNames
) {
3761 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
3762 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
3763 return E_INVALIDARG
;
3765 if (!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
3766 WARN("Can't find default printer\n");
3767 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
3771 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
3772 bRet
= GetPrinterW(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
3773 if (!bRet
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
3774 HeapFree(GetProcessHeap(), 0, pbuf
);
3775 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
3776 bRet
= GetPrinterW(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
3779 HeapFree(GetProcessHeap(), 0, pbuf
);
3785 dbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
3786 bRet
= GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
);
3787 if (!bRet
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
3788 HeapFree(GetProcessHeap(), 0, dbuf
);
3789 dbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
3790 bRet
= GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
);
3793 ERR("GetPrinterDriverW failed, last error %d, fix your config for printer %s!\n",
3794 GetLastError(), debugstr_w(pbuf
->pPrinterName
));
3795 HeapFree(GetProcessHeap(), 0, dbuf
);
3796 HeapFree(GetProcessHeap(), 0, pbuf
);
3797 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
3803 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
3807 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
3808 pbuf
->pDevMode
->dmDriverExtra
);
3809 if (lppd
->hDevMode
) {
3810 ptr
= GlobalLock(lppd
->hDevMode
);
3812 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
3813 pbuf
->pDevMode
->dmDriverExtra
);
3814 GlobalUnlock(lppd
->hDevMode
);
3818 HeapFree(GetProcessHeap(), 0, pbuf
);
3819 HeapFree(GetProcessHeap(), 0, dbuf
);