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];
79 /***********************************************************************
80 * PRINTDLG_OpenDefaultPrinter
82 * Returns a winspool printer handle to the default printer in *hprn
83 * Caller must call ClosePrinter on the handle
85 * Returns TRUE on success else FALSE
87 BOOL
PRINTDLG_OpenDefaultPrinter(HANDLE
*hprn
)
90 DWORD dwBufLen
= sizeof(buf
) / sizeof(buf
[0]);
92 if(!GetDefaultPrinterW(buf
, &dwBufLen
))
94 res
= OpenPrinterW(buf
, hprn
, NULL
);
96 WARN("Could not open printer %s\n", debugstr_w(buf
));
100 /***********************************************************************
101 * PRINTDLG_SetUpPrinterListCombo
103 * Initializes printer list combox.
104 * hDlg: HWND of dialog
105 * id: Control id of combo
106 * name: Name of printer to select
108 * Initializes combo with list of available printers. Selects printer 'name'
109 * If name is NULL or does not exist select the default printer.
111 * Returns number of printers added to list.
113 INT
PRINTDLG_SetUpPrinterListComboA(HWND hDlg
, UINT id
, LPCSTR name
)
117 LPPRINTER_INFO_2A pi
;
118 EnumPrintersA(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
119 pi
= HeapAlloc(GetProcessHeap(), 0, needed
);
120 EnumPrintersA(PRINTER_ENUM_LOCAL
, NULL
, 2, (LPBYTE
)pi
, needed
, &needed
,
123 SendDlgItemMessageA(hDlg
, id
, CB_RESETCONTENT
, 0, 0);
125 for(i
= 0; i
< num
; i
++) {
126 SendDlgItemMessageA(hDlg
, id
, CB_ADDSTRING
, 0,
127 (LPARAM
)pi
[i
].pPrinterName
);
129 HeapFree(GetProcessHeap(), 0, pi
);
131 (i
= SendDlgItemMessageA(hDlg
, id
, CB_FINDSTRINGEXACT
, -1,
132 (LPARAM
)name
)) == CB_ERR
) {
135 DWORD dwBufLen
= sizeof(buf
);
136 FIXME("Can't find '%s' in printer list so trying to find default\n",
138 if(!GetDefaultPrinterA(buf
, &dwBufLen
))
140 i
= SendDlgItemMessageA(hDlg
, id
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buf
);
142 FIXME("Can't find default printer in printer list\n");
144 SendDlgItemMessageA(hDlg
, id
, CB_SETCURSEL
, i
, 0);
148 static INT
PRINTDLG_SetUpPrinterListComboW(HWND hDlg
, UINT id
, LPCWSTR name
)
152 LPPRINTER_INFO_2W pi
;
153 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
154 pi
= HeapAlloc(GetProcessHeap(), 0, needed
);
155 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, (LPBYTE
)pi
, needed
, &needed
,
158 for(i
= 0; i
< num
; i
++) {
159 SendDlgItemMessageW(hDlg
, id
, CB_ADDSTRING
, 0,
160 (LPARAM
)pi
[i
].pPrinterName
);
162 HeapFree(GetProcessHeap(), 0, pi
);
164 (i
= SendDlgItemMessageW(hDlg
, id
, CB_FINDSTRINGEXACT
, -1,
165 (LPARAM
)name
)) == CB_ERR
) {
167 DWORD dwBufLen
= sizeof(buf
)/sizeof(buf
[0]);
168 TRACE("Can't find '%s' in printer list so trying to find default\n",
170 if(!GetDefaultPrinterW(buf
, &dwBufLen
))
172 i
= SendDlgItemMessageW(hDlg
, id
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buf
);
174 TRACE("Can't find default printer in printer list\n");
176 SendDlgItemMessageW(hDlg
, id
, CB_SETCURSEL
, i
, 0);
180 /***********************************************************************
181 * PRINTDLG_CreateDevNames [internal]
184 * creates a DevNames structure.
186 * (NB. when we handle unicode the offsets will be in wchars).
188 static BOOL
PRINTDLG_CreateDevNames(HGLOBAL
*hmem
, char* DeviceDriverName
,
189 char* DeviceName
, char* OutputPort
)
192 char* pDevNamesSpace
;
194 LPDEVNAMES lpDevNames
;
196 DWORD dwBufLen
= sizeof(buf
);
198 size
= strlen(DeviceDriverName
) + 1
199 + strlen(DeviceName
) + 1
200 + strlen(OutputPort
) + 1
204 *hmem
= GlobalReAlloc(*hmem
, size
, GMEM_MOVEABLE
);
206 *hmem
= GlobalAlloc(GMEM_MOVEABLE
, size
);
210 pDevNamesSpace
= GlobalLock(*hmem
);
211 lpDevNames
= (LPDEVNAMES
) pDevNamesSpace
;
213 pTempPtr
= pDevNamesSpace
+ sizeof(DEVNAMES
);
214 strcpy(pTempPtr
, DeviceDriverName
);
215 lpDevNames
->wDriverOffset
= pTempPtr
- pDevNamesSpace
;
217 pTempPtr
+= strlen(DeviceDriverName
) + 1;
218 strcpy(pTempPtr
, DeviceName
);
219 lpDevNames
->wDeviceOffset
= pTempPtr
- pDevNamesSpace
;
221 pTempPtr
+= strlen(DeviceName
) + 1;
222 strcpy(pTempPtr
, OutputPort
);
223 lpDevNames
->wOutputOffset
= pTempPtr
- pDevNamesSpace
;
225 GetDefaultPrinterA(buf
, &dwBufLen
);
226 lpDevNames
->wDefault
= (strcmp(buf
, DeviceName
) == 0) ? 1 : 0;
231 static BOOL
PRINTDLG_CreateDevNamesW(HGLOBAL
*hmem
, LPCWSTR DeviceDriverName
,
232 LPCWSTR DeviceName
, LPCWSTR OutputPort
)
235 LPWSTR pDevNamesSpace
;
237 LPDEVNAMES lpDevNames
;
239 DWORD dwBufLen
= sizeof(bufW
) / sizeof(WCHAR
);
241 size
= sizeof(WCHAR
)*lstrlenW(DeviceDriverName
) + 2
242 + sizeof(WCHAR
)*lstrlenW(DeviceName
) + 2
243 + sizeof(WCHAR
)*lstrlenW(OutputPort
) + 2
247 *hmem
= GlobalReAlloc(*hmem
, size
, GMEM_MOVEABLE
);
249 *hmem
= GlobalAlloc(GMEM_MOVEABLE
, size
);
253 pDevNamesSpace
= GlobalLock(*hmem
);
254 lpDevNames
= (LPDEVNAMES
) pDevNamesSpace
;
256 pTempPtr
= (LPWSTR
)((LPDEVNAMES
)pDevNamesSpace
+ 1);
257 lstrcpyW(pTempPtr
, DeviceDriverName
);
258 lpDevNames
->wDriverOffset
= pTempPtr
- pDevNamesSpace
;
260 pTempPtr
+= lstrlenW(DeviceDriverName
) + 1;
261 lstrcpyW(pTempPtr
, DeviceName
);
262 lpDevNames
->wDeviceOffset
= pTempPtr
- pDevNamesSpace
;
264 pTempPtr
+= lstrlenW(DeviceName
) + 1;
265 lstrcpyW(pTempPtr
, OutputPort
);
266 lpDevNames
->wOutputOffset
= pTempPtr
- pDevNamesSpace
;
268 GetDefaultPrinterW(bufW
, &dwBufLen
);
269 lpDevNames
->wDefault
= (lstrcmpW(bufW
, DeviceName
) == 0) ? 1 : 0;
274 /***********************************************************************
275 * PRINTDLG_UpdatePrintDlg [internal]
278 * updates the PrintDlg structure for return values.
281 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
282 * TRUE if successful.
284 static BOOL
PRINTDLG_UpdatePrintDlgA(HWND hDlg
,
285 PRINT_PTRA
* PrintStructures
)
287 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
288 PDEVMODEA lpdm
= PrintStructures
->lpDevMode
;
289 LPPRINTER_INFO_2A pi
= PrintStructures
->lpPrinterInfo
;
293 FIXME("No lpdm ptr?\n");
298 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
299 /* check whether nFromPage and nToPage are within range defined by
300 * nMinPage and nMaxPage
302 if (IsDlgButtonChecked(hDlg
, rad3
) == BST_CHECKED
) { /* Pages */
305 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
306 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
307 if (nFromPage
< lppd
->nMinPage
|| nFromPage
> lppd
->nMaxPage
||
308 nToPage
< lppd
->nMinPage
|| nToPage
> lppd
->nMaxPage
) {
309 char resourcestr
[256];
311 LoadStringA(COMDLG32_hInstance
, PD32_INVALID_PAGE_RANGE
,
313 sprintf(resultstr
,resourcestr
, lppd
->nMinPage
, lppd
->nMaxPage
);
314 LoadStringA(COMDLG32_hInstance
, PD32_PRINT_TITLE
,
316 MessageBoxA(hDlg
, resultstr
, resourcestr
,
317 MB_OK
| MB_ICONWARNING
);
320 lppd
->nFromPage
= nFromPage
;
321 lppd
->nToPage
= nToPage
;
322 lppd
->Flags
|= PD_PAGENUMS
;
325 lppd
->Flags
&= ~PD_PAGENUMS
;
327 if (IsDlgButtonChecked(hDlg
, chx1
) == BST_CHECKED
) {/* Print to file */
328 static char file
[] = "FILE:";
329 lppd
->Flags
|= PD_PRINTTOFILE
;
330 pi
->pPortName
= file
;
333 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
) { /* Collate */
334 FIXME("Collate lppd not yet implemented as output\n");
337 /* set PD_Collate and nCopies */
338 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
339 /* The application doesn't support multiple copies or collate...
341 lppd
->Flags
&= ~PD_COLLATE
;
343 /* if the printer driver supports it... store info there
344 * otherwise no collate & multiple copies !
346 if (lpdm
->dmFields
& DM_COLLATE
)
348 (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
);
349 if (lpdm
->dmFields
& DM_COPIES
)
350 lpdm
->dmCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
352 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
353 lppd
->Flags
|= PD_COLLATE
;
355 lppd
->Flags
&= ~PD_COLLATE
;
356 lppd
->nCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
362 static BOOL
PRINTDLG_UpdatePrintDlgW(HWND hDlg
,
363 PRINT_PTRW
* PrintStructures
)
365 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
366 PDEVMODEW lpdm
= PrintStructures
->lpDevMode
;
367 LPPRINTER_INFO_2W pi
= PrintStructures
->lpPrinterInfo
;
371 FIXME("No lpdm ptr?\n");
376 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
377 /* check whether nFromPage and nToPage are within range defined by
378 * nMinPage and nMaxPage
380 if (IsDlgButtonChecked(hDlg
, rad3
) == BST_CHECKED
) { /* Pages */
383 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
384 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
385 if (nFromPage
< lppd
->nMinPage
|| nFromPage
> lppd
->nMaxPage
||
386 nToPage
< lppd
->nMinPage
|| nToPage
> lppd
->nMaxPage
) {
387 WCHAR resourcestr
[256];
388 WCHAR resultstr
[256];
389 LoadStringW(COMDLG32_hInstance
, PD32_INVALID_PAGE_RANGE
,
391 wsprintfW(resultstr
,resourcestr
, lppd
->nMinPage
, lppd
->nMaxPage
);
392 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
,
394 MessageBoxW(hDlg
, resultstr
, resourcestr
,
395 MB_OK
| MB_ICONWARNING
);
398 lppd
->nFromPage
= nFromPage
;
399 lppd
->nToPage
= nToPage
;
400 lppd
->Flags
|= PD_PAGENUMS
;
403 lppd
->Flags
&= ~PD_PAGENUMS
;
405 if (IsDlgButtonChecked(hDlg
, chx1
) == BST_CHECKED
) {/* Print to file */
406 static WCHAR file
[] = {'F','I','L','E',':',0};
407 lppd
->Flags
|= PD_PRINTTOFILE
;
408 pi
->pPortName
= file
;
411 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
) { /* Collate */
412 FIXME("Collate lppd not yet implemented as output\n");
415 /* set PD_Collate and nCopies */
416 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
417 /* The application doesn't support multiple copies or collate...
419 lppd
->Flags
&= ~PD_COLLATE
;
421 /* if the printer driver supports it... store info there
422 * otherwise no collate & multiple copies !
424 if (lpdm
->dmFields
& DM_COLLATE
)
426 (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
);
427 if (lpdm
->dmFields
& DM_COPIES
)
428 lpdm
->dmCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
430 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
431 lppd
->Flags
|= PD_COLLATE
;
433 lppd
->Flags
&= ~PD_COLLATE
;
434 lppd
->nCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
440 static BOOL
PRINTDLG_PaperSizeA(
441 PRINTDLGA
*pdlga
,const WORD PaperSize
,LPPOINT size
445 LPSTR devname
,portname
;
449 POINT
*points
= NULL
;
452 dn
= GlobalLock(pdlga
->hDevNames
);
453 dm
= GlobalLock(pdlga
->hDevMode
);
454 devname
= ((char*)dn
)+dn
->wDeviceOffset
;
455 portname
= ((char*)dn
)+dn
->wOutputOffset
;
458 NrOfEntries
= DeviceCapabilitiesA(devname
,portname
,DC_PAPERNAMES
,NULL
,dm
);
460 FIXME("No papernames found for %s/%s\n",devname
,portname
);
463 if (NrOfEntries
== -1) {
464 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
468 Words
= HeapAlloc(GetProcessHeap(),0,NrOfEntries
*sizeof(WORD
));
469 if (NrOfEntries
!= (ret
=DeviceCapabilitiesA(devname
,portname
,DC_PAPERS
,(LPSTR
)Words
,dm
))) {
470 FIXME("Number of returned vals %d is not %d\n",NrOfEntries
,ret
);
473 for (i
=0;i
<NrOfEntries
;i
++)
474 if (Words
[i
] == PaperSize
)
476 HeapFree(GetProcessHeap(),0,Words
);
477 if (i
== NrOfEntries
) {
478 FIXME("Papersize %d not found in list?\n",PaperSize
);
481 points
= HeapAlloc(GetProcessHeap(),0,sizeof(points
[0])*NrOfEntries
);
482 if (NrOfEntries
!=(ret
=DeviceCapabilitiesA(devname
,portname
,DC_PAPERSIZE
,(LPSTR
)points
,dm
))) {
483 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries
,ret
);
486 /* this is _10ths_ of a millimeter */
491 GlobalUnlock(pdlga
->hDevNames
);
492 GlobalUnlock(pdlga
->hDevMode
);
493 HeapFree(GetProcessHeap(),0,Words
);
494 HeapFree(GetProcessHeap(),0,points
);
498 static BOOL
PRINTDLG_PaperSizeW(
499 PRINTDLGW
*pdlga
,const WCHAR
*PaperSize
,LPPOINT size
503 LPWSTR devname
,portname
;
507 POINT
*points
= NULL
;
510 dn
= GlobalLock(pdlga
->hDevNames
);
511 dm
= GlobalLock(pdlga
->hDevMode
);
512 devname
= ((WCHAR
*)dn
)+dn
->wDeviceOffset
;
513 portname
= ((WCHAR
*)dn
)+dn
->wOutputOffset
;
516 NrOfEntries
= DeviceCapabilitiesW(devname
,portname
,DC_PAPERNAMES
,NULL
,dm
);
518 FIXME("No papernames found for %s/%s\n",debugstr_w(devname
),debugstr_w(portname
));
521 if (NrOfEntries
== -1) {
522 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
526 Names
= HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*NrOfEntries
*64);
527 if (NrOfEntries
!= (ret
=DeviceCapabilitiesW(devname
,portname
,DC_PAPERNAMES
,Names
,dm
))) {
528 FIXME("Number of returned vals %d is not %d\n",NrOfEntries
,ret
);
531 for (i
=0;i
<NrOfEntries
;i
++)
532 if (!lstrcmpW(PaperSize
,Names
+(64*i
)))
534 HeapFree(GetProcessHeap(),0,Names
);
535 if (i
==NrOfEntries
) {
536 FIXME("Papersize %s not found in list?\n",debugstr_w(PaperSize
));
539 points
= HeapAlloc(GetProcessHeap(),0,sizeof(points
[0])*NrOfEntries
);
540 if (NrOfEntries
!=(ret
=DeviceCapabilitiesW(devname
,portname
,DC_PAPERSIZE
,(LPWSTR
)points
,dm
))) {
541 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries
,ret
);
544 /* this is _10ths_ of a millimeter */
549 GlobalUnlock(pdlga
->hDevNames
);
550 GlobalUnlock(pdlga
->hDevMode
);
551 HeapFree(GetProcessHeap(),0,Names
);
552 HeapFree(GetProcessHeap(),0,points
);
557 /************************************************************************
558 * PRINTDLG_SetUpPaperComboBox
560 * Initialize either the papersize or inputslot combos of the Printer Setup
561 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
562 * We also try to re-select the old selection.
564 static BOOL
PRINTDLG_SetUpPaperComboBoxA(HWND hDlg
,
577 int fwCapability_Names
;
578 int fwCapability_Words
;
580 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName
,PortName
,nIDComboBox
);
582 /* query the dialog box for the current selected value */
583 Sel
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETCURSEL
, 0, 0);
585 /* we enter here only if a different printer is selected after
586 * the Print Setup dialog is opened. The current settings are
587 * stored into the newly selected printer.
589 oldWord
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
,
592 if (nIDComboBox
== cmb2
)
593 dm
->u1
.s1
.dmPaperSize
= oldWord
;
595 dm
->dmDefaultSource
= oldWord
;
599 /* we enter here only when the Print setup dialog is initially
600 * opened. In this case the settings are restored from when
601 * the dialog was last closed.
604 if (nIDComboBox
== cmb2
)
605 oldWord
= dm
->u1
.s1
.dmPaperSize
;
607 oldWord
= dm
->dmDefaultSource
;
611 if (nIDComboBox
== cmb2
) {
613 fwCapability_Names
= DC_PAPERNAMES
;
614 fwCapability_Words
= DC_PAPERS
;
618 fwCapability_Names
= DC_BINNAMES
;
619 fwCapability_Words
= DC_BINS
;
622 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
623 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
625 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
626 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
627 fwCapability_Names
, NULL
, dm
);
628 if (NrOfEntries
== 0)
629 WARN("no Name Entries found!\n");
630 else if (NrOfEntries
< 0)
633 if(DeviceCapabilitiesA(PrinterName
, PortName
, fwCapability_Words
, NULL
, dm
)
635 ERR("Number of caps is different\n");
639 Names
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(char)*NamesSize
);
640 Words
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WORD
));
641 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
642 fwCapability_Names
, Names
, dm
);
643 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
644 fwCapability_Words
, (LPSTR
)Words
, dm
);
646 /* reset any current content in the combobox */
647 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_RESETCONTENT
, 0, 0);
649 /* store new content */
650 for (i
= 0; i
< NrOfEntries
; i
++) {
651 DWORD pos
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_ADDSTRING
, 0,
652 (LPARAM
)(&Names
[i
*NamesSize
]) );
653 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_SETITEMDATA
, pos
,
657 /* Look for old selection - can't do this is previous loop since
658 item order will change as more items are added */
660 for (i
= 0; i
< NrOfEntries
; i
++) {
661 if(SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) ==
667 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_SETCURSEL
, Sel
, 0);
669 HeapFree(GetProcessHeap(),0,Words
);
670 HeapFree(GetProcessHeap(),0,Names
);
674 static BOOL
PRINTDLG_SetUpPaperComboBoxW(HWND hDlg
,
687 int fwCapability_Names
;
688 int fwCapability_Words
;
690 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName
),debugstr_w(PortName
),nIDComboBox
);
692 /* query the dialog box for the current selected value */
693 Sel
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETCURSEL
, 0, 0);
695 /* we enter here only if a different printer is selected after
696 * the Print Setup dialog is opened. The current settings are
697 * stored into the newly selected printer.
699 oldWord
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETITEMDATA
,
702 if (nIDComboBox
== cmb2
)
703 dm
->u1
.s1
.dmPaperSize
= oldWord
;
705 dm
->dmDefaultSource
= oldWord
;
709 /* we enter here only when the Print setup dialog is initially
710 * opened. In this case the settings are restored from when
711 * the dialog was last closed.
714 if (nIDComboBox
== cmb2
)
715 oldWord
= dm
->u1
.s1
.dmPaperSize
;
717 oldWord
= dm
->dmDefaultSource
;
721 if (nIDComboBox
== cmb2
) {
723 fwCapability_Names
= DC_PAPERNAMES
;
724 fwCapability_Words
= DC_PAPERS
;
728 fwCapability_Names
= DC_BINNAMES
;
729 fwCapability_Words
= DC_BINS
;
732 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
733 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
735 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
736 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
737 fwCapability_Names
, NULL
, dm
);
738 if (NrOfEntries
== 0)
739 WARN("no Name Entries found!\n");
740 else if (NrOfEntries
< 0)
743 if(DeviceCapabilitiesW(PrinterName
, PortName
, fwCapability_Words
, NULL
, dm
)
745 ERR("Number of caps is different\n");
749 Names
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WCHAR
)*NamesSize
);
750 Words
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WORD
));
751 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
752 fwCapability_Names
, Names
, dm
);
753 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
754 fwCapability_Words
, (LPWSTR
)Words
, dm
);
756 /* reset any current content in the combobox */
757 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_RESETCONTENT
, 0, 0);
759 /* store new content */
760 for (i
= 0; i
< NrOfEntries
; i
++) {
761 DWORD pos
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_ADDSTRING
, 0,
762 (LPARAM
)(&Names
[i
*NamesSize
]) );
763 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_SETITEMDATA
, pos
,
767 /* Look for old selection - can't do this is previous loop since
768 item order will change as more items are added */
770 for (i
= 0; i
< NrOfEntries
; i
++) {
771 if(SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) ==
777 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_SETCURSEL
, Sel
, 0);
779 HeapFree(GetProcessHeap(),0,Words
);
780 HeapFree(GetProcessHeap(),0,Names
);
785 /***********************************************************************
786 * PRINTDLG_UpdatePrinterInfoTexts [internal]
788 static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg
, LPPRINTER_INFO_2A pi
)
791 char ResourceString
[256];
797 /* add all status messages */
798 for (i
= 0; i
< 25; i
++) {
799 if (pi
->Status
& (1<<i
)) {
800 LoadStringA(COMDLG32_hInstance
, PD32_PRINTER_STATUS_PAUSED
+i
,
801 ResourceString
, 255);
802 strcat(StatusMsg
,ResourceString
);
806 /* FIXME: status==ready must only be appended if really so.
807 but how to detect? */
808 LoadStringA(COMDLG32_hInstance
, PD32_PRINTER_STATUS_READY
,
809 ResourceString
, 255);
810 strcat(StatusMsg
,ResourceString
);
811 SetDlgItemTextA(hDlg
, stc12
, StatusMsg
);
813 /* set all other printer info texts */
814 SetDlgItemTextA(hDlg
, stc11
, pi
->pDriverName
);
816 if (pi
->pLocation
!= NULL
&& pi
->pLocation
[0] != '\0')
817 SetDlgItemTextA(hDlg
, stc14
, pi
->pLocation
);
819 SetDlgItemTextA(hDlg
, stc14
, pi
->pPortName
);
820 SetDlgItemTextA(hDlg
, stc13
, pi
->pComment
? pi
->pComment
: "");
824 static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg
, LPPRINTER_INFO_2W pi
)
826 WCHAR StatusMsg
[256];
827 WCHAR ResourceString
[256];
828 static const WCHAR emptyW
[] = {0};
834 /* add all status messages */
835 for (i
= 0; i
< 25; i
++) {
836 if (pi
->Status
& (1<<i
)) {
837 LoadStringW(COMDLG32_hInstance
, PD32_PRINTER_STATUS_PAUSED
+i
,
838 ResourceString
, 255);
839 lstrcatW(StatusMsg
,ResourceString
);
843 /* FIXME: status==ready must only be appended if really so.
844 but how to detect? */
845 LoadStringW(COMDLG32_hInstance
, PD32_PRINTER_STATUS_READY
,
846 ResourceString
, 255);
847 lstrcatW(StatusMsg
,ResourceString
);
848 SetDlgItemTextW(hDlg
, stc12
, StatusMsg
);
850 /* set all other printer info texts */
851 SetDlgItemTextW(hDlg
, stc11
, pi
->pDriverName
);
852 if (pi
->pLocation
!= NULL
&& pi
->pLocation
[0] != '\0')
853 SetDlgItemTextW(hDlg
, stc14
, pi
->pLocation
);
855 SetDlgItemTextW(hDlg
, stc14
, pi
->pPortName
);
856 SetDlgItemTextW(hDlg
, stc13
, pi
->pComment
? pi
->pComment
: emptyW
);
860 /*******************************************************************
862 * PRINTDLG_ChangePrinter
865 BOOL
PRINTDLG_ChangePrinterA(HWND hDlg
, char *name
,
866 PRINT_PTRA
*PrintStructures
)
868 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
869 LPDEVMODEA lpdm
= NULL
;
874 HeapFree(GetProcessHeap(),0, PrintStructures
->lpPrinterInfo
);
875 HeapFree(GetProcessHeap(),0, PrintStructures
->lpDriverInfo
);
876 if(!OpenPrinterA(name
, &hprn
, NULL
)) {
877 ERR("Can't open printer %s\n", name
);
880 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
881 PrintStructures
->lpPrinterInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
882 GetPrinterA(hprn
, 2, (LPBYTE
)PrintStructures
->lpPrinterInfo
, needed
,
884 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
885 PrintStructures
->lpDriverInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
886 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)PrintStructures
->lpDriverInfo
,
888 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures
->lpPrinterInfo
->pPrinterName
);
893 PRINTDLG_UpdatePrinterInfoTextsA(hDlg
, PrintStructures
->lpPrinterInfo
);
895 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
896 PrintStructures
->lpDevMode
= NULL
;
898 dmSize
= DocumentPropertiesA(0, 0, name
, NULL
, NULL
, 0);
900 ERR("DocumentProperties fails on %s\n", debugstr_a(name
));
903 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(), 0, dmSize
);
904 dmSize
= DocumentPropertiesA(0, 0, name
, PrintStructures
->lpDevMode
, NULL
,
906 if(lppd
->hDevMode
&& (lpdm
= GlobalLock(lppd
->hDevMode
)) &&
907 !lstrcmpA( (LPSTR
) lpdm
->dmDeviceName
,
908 (LPSTR
) PrintStructures
->lpDevMode
->dmDeviceName
)) {
909 /* Supplied devicemode matches current printer so try to use it */
910 DocumentPropertiesA(0, 0, name
, PrintStructures
->lpDevMode
, lpdm
,
911 DM_OUT_BUFFER
| DM_IN_BUFFER
);
914 GlobalUnlock(lppd
->hDevMode
);
916 lpdm
= PrintStructures
->lpDevMode
; /* use this as a shortcut */
918 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
919 /* Print range (All/Range/Selection) */
920 SetDlgItemInt(hDlg
, edt1
, lppd
->nFromPage
, FALSE
);
921 SetDlgItemInt(hDlg
, edt2
, lppd
->nToPage
, FALSE
);
922 CheckRadioButton(hDlg
, rad1
, rad3
, rad1
); /* default */
923 if (lppd
->Flags
& PD_NOSELECTION
)
924 EnableWindow(GetDlgItem(hDlg
, rad2
), FALSE
);
926 if (lppd
->Flags
& PD_SELECTION
)
927 CheckRadioButton(hDlg
, rad1
, rad3
, rad2
);
928 if (lppd
->Flags
& PD_NOPAGENUMS
) {
929 EnableWindow(GetDlgItem(hDlg
, rad3
), FALSE
);
930 EnableWindow(GetDlgItem(hDlg
, stc2
),FALSE
);
931 EnableWindow(GetDlgItem(hDlg
, edt1
), FALSE
);
932 EnableWindow(GetDlgItem(hDlg
, stc3
),FALSE
);
933 EnableWindow(GetDlgItem(hDlg
, edt2
), FALSE
);
935 if (lppd
->Flags
& PD_PAGENUMS
)
936 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
941 * FIXME: The ico3 is not displayed for some reason. I don't know why.
943 if (lppd
->Flags
& PD_COLLATE
) {
944 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
945 (LPARAM
)PrintStructures
->hCollateIcon
);
946 CheckDlgButton(hDlg
, chx2
, 1);
948 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
949 (LPARAM
)PrintStructures
->hNoCollateIcon
);
950 CheckDlgButton(hDlg
, chx2
, 0);
953 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
954 /* if printer doesn't support it: no Collate */
955 if (!(lpdm
->dmFields
& DM_COLLATE
)) {
956 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
957 EnableWindow(GetDlgItem(hDlg
, ico3
), FALSE
);
964 if (lppd
->hDevMode
== 0)
965 copies
= lppd
->nCopies
;
967 copies
= lpdm
->dmCopies
;
968 if(copies
== 0) copies
= 1;
969 else if(copies
< 0) copies
= MAX_COPIES
;
970 SetDlgItemInt(hDlg
, edt3
, copies
, FALSE
);
973 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
974 /* if printer doesn't support it: no nCopies */
975 if (!(lpdm
->dmFields
& DM_COPIES
)) {
976 EnableWindow(GetDlgItem(hDlg
, edt3
), FALSE
);
977 EnableWindow(GetDlgItem(hDlg
, stc5
), FALSE
);
982 CheckDlgButton(hDlg
, chx1
, (lppd
->Flags
& PD_PRINTTOFILE
) ? 1 : 0);
983 if (lppd
->Flags
& PD_DISABLEPRINTTOFILE
)
984 EnableWindow(GetDlgItem(hDlg
, chx1
), FALSE
);
985 if (lppd
->Flags
& PD_HIDEPRINTTOFILE
)
986 ShowWindow(GetDlgItem(hDlg
, chx1
), SW_HIDE
);
988 } else { /* PD_PRINTSETUP */
989 BOOL bPortrait
= (lpdm
->u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
);
991 PRINTDLG_SetUpPaperComboBoxA(hDlg
, cmb2
,
992 PrintStructures
->lpPrinterInfo
->pPrinterName
,
993 PrintStructures
->lpPrinterInfo
->pPortName
,
995 PRINTDLG_SetUpPaperComboBoxA(hDlg
, cmb3
,
996 PrintStructures
->lpPrinterInfo
->pPrinterName
,
997 PrintStructures
->lpPrinterInfo
->pPortName
,
999 CheckRadioButton(hDlg
, rad1
, rad2
, bPortrait
? rad1
: rad2
);
1000 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1001 (LPARAM
)(bPortrait
? PrintStructures
->hPortraitIcon
:
1002 PrintStructures
->hLandscapeIcon
));
1007 if ((lppd
->Flags
& PD_SHOWHELP
)==0) {
1008 /* hide if PD_SHOWHELP not specified */
1009 ShowWindow(GetDlgItem(hDlg
, pshHelp
), SW_HIDE
);
1014 static BOOL
PRINTDLG_ChangePrinterW(HWND hDlg
, WCHAR
*name
,
1015 PRINT_PTRW
*PrintStructures
)
1017 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1018 LPDEVMODEW lpdm
= NULL
;
1023 HeapFree(GetProcessHeap(),0, PrintStructures
->lpPrinterInfo
);
1024 HeapFree(GetProcessHeap(),0, PrintStructures
->lpDriverInfo
);
1025 if(!OpenPrinterW(name
, &hprn
, NULL
)) {
1026 ERR("Can't open printer %s\n", debugstr_w(name
));
1029 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
1030 PrintStructures
->lpPrinterInfo
= HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*needed
);
1031 GetPrinterW(hprn
, 2, (LPBYTE
)PrintStructures
->lpPrinterInfo
, needed
,
1033 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
1034 PrintStructures
->lpDriverInfo
= HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*needed
);
1035 if (!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)PrintStructures
->lpDriverInfo
,
1037 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures
->lpPrinterInfo
->pPrinterName
));
1042 PRINTDLG_UpdatePrinterInfoTextsW(hDlg
, PrintStructures
->lpPrinterInfo
);
1044 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
1045 PrintStructures
->lpDevMode
= NULL
;
1047 dmSize
= DocumentPropertiesW(0, 0, name
, NULL
, NULL
, 0);
1049 ERR("DocumentProperties fails on %s\n", debugstr_w(name
));
1052 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(), 0, dmSize
);
1053 dmSize
= DocumentPropertiesW(0, 0, name
, PrintStructures
->lpDevMode
, NULL
,
1055 if(lppd
->hDevMode
&& (lpdm
= GlobalLock(lppd
->hDevMode
)) &&
1056 !lstrcmpW(lpdm
->dmDeviceName
,
1057 PrintStructures
->lpDevMode
->dmDeviceName
)) {
1058 /* Supplied devicemode matches current printer so try to use it */
1059 DocumentPropertiesW(0, 0, name
, PrintStructures
->lpDevMode
, lpdm
,
1060 DM_OUT_BUFFER
| DM_IN_BUFFER
);
1063 GlobalUnlock(lppd
->hDevMode
);
1065 lpdm
= PrintStructures
->lpDevMode
; /* use this as a shortcut */
1067 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
1068 /* Print range (All/Range/Selection) */
1069 SetDlgItemInt(hDlg
, edt1
, lppd
->nFromPage
, FALSE
);
1070 SetDlgItemInt(hDlg
, edt2
, lppd
->nToPage
, FALSE
);
1071 CheckRadioButton(hDlg
, rad1
, rad3
, rad1
); /* default */
1072 if (lppd
->Flags
& PD_NOSELECTION
)
1073 EnableWindow(GetDlgItem(hDlg
, rad2
), FALSE
);
1075 if (lppd
->Flags
& PD_SELECTION
)
1076 CheckRadioButton(hDlg
, rad1
, rad3
, rad2
);
1077 if (lppd
->Flags
& PD_NOPAGENUMS
) {
1078 EnableWindow(GetDlgItem(hDlg
, rad3
), FALSE
);
1079 EnableWindow(GetDlgItem(hDlg
, stc2
),FALSE
);
1080 EnableWindow(GetDlgItem(hDlg
, edt1
), FALSE
);
1081 EnableWindow(GetDlgItem(hDlg
, stc3
),FALSE
);
1082 EnableWindow(GetDlgItem(hDlg
, edt2
), FALSE
);
1084 if (lppd
->Flags
& PD_PAGENUMS
)
1085 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1090 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1092 if (lppd
->Flags
& PD_COLLATE
) {
1093 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1094 (LPARAM
)PrintStructures
->hCollateIcon
);
1095 CheckDlgButton(hDlg
, chx2
, 1);
1097 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1098 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1099 CheckDlgButton(hDlg
, chx2
, 0);
1102 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1103 /* if printer doesn't support it: no Collate */
1104 if (!(lpdm
->dmFields
& DM_COLLATE
)) {
1105 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1106 EnableWindow(GetDlgItem(hDlg
, ico3
), FALSE
);
1113 if (lppd
->hDevMode
== 0)
1114 copies
= lppd
->nCopies
;
1116 copies
= lpdm
->dmCopies
;
1117 if(copies
== 0) copies
= 1;
1118 else if(copies
< 0) copies
= MAX_COPIES
;
1119 SetDlgItemInt(hDlg
, edt3
, copies
, FALSE
);
1122 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1123 /* if printer doesn't support it: no nCopies */
1124 if (!(lpdm
->dmFields
& DM_COPIES
)) {
1125 EnableWindow(GetDlgItem(hDlg
, edt3
), FALSE
);
1126 EnableWindow(GetDlgItem(hDlg
, stc5
), FALSE
);
1131 CheckDlgButton(hDlg
, chx1
, (lppd
->Flags
& PD_PRINTTOFILE
) ? 1 : 0);
1132 if (lppd
->Flags
& PD_DISABLEPRINTTOFILE
)
1133 EnableWindow(GetDlgItem(hDlg
, chx1
), FALSE
);
1134 if (lppd
->Flags
& PD_HIDEPRINTTOFILE
)
1135 ShowWindow(GetDlgItem(hDlg
, chx1
), SW_HIDE
);
1137 } else { /* PD_PRINTSETUP */
1138 BOOL bPortrait
= (lpdm
->u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
);
1140 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb2
,
1141 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1142 PrintStructures
->lpPrinterInfo
->pPortName
,
1144 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb3
,
1145 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1146 PrintStructures
->lpPrinterInfo
->pPortName
,
1148 CheckRadioButton(hDlg
, rad1
, rad2
, bPortrait
? rad1
: rad2
);
1149 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1150 (LPARAM
)(bPortrait
? PrintStructures
->hPortraitIcon
:
1151 PrintStructures
->hLandscapeIcon
));
1156 if ((lppd
->Flags
& PD_SHOWHELP
)==0) {
1157 /* hide if PD_SHOWHELP not specified */
1158 ShowWindow(GetDlgItem(hDlg
, pshHelp
), SW_HIDE
);
1163 /***********************************************************************
1164 * check_printer_setup [internal]
1166 static LRESULT
check_printer_setup(HWND hDlg
)
1169 WCHAR resourcestr
[256],resultstr
[256];
1172 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
1175 EnumPrintersW(PRINTER_ENUM_CONNECTIONS
, NULL
, 2, NULL
, 0, &needed
, &num
);
1181 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEVICES
,resultstr
, 255);
1182 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
,resourcestr
, 255);
1183 res
= MessageBoxW(hDlg
, resultstr
, resourcestr
,MB_OK
| MB_ICONWARNING
);
1188 /***********************************************************************
1189 * PRINTDLG_WMInitDialog [internal]
1191 static LRESULT
PRINTDLG_WMInitDialog(HWND hDlg
, WPARAM wParam
,
1192 PRINT_PTRA
* PrintStructures
)
1194 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1198 UINT comboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1200 /* load Collate ICONs */
1201 /* We load these with LoadImage because they are not a standard
1202 size and we don't want them rescaled */
1203 PrintStructures
->hCollateIcon
=
1204 LoadImageA(COMDLG32_hInstance
, "PD32_COLLATE", IMAGE_ICON
, 0, 0, 0);
1205 PrintStructures
->hNoCollateIcon
=
1206 LoadImageA(COMDLG32_hInstance
, "PD32_NOCOLLATE", IMAGE_ICON
, 0, 0, 0);
1208 /* These can be done with LoadIcon */
1209 PrintStructures
->hPortraitIcon
=
1210 LoadIconA(COMDLG32_hInstance
, "PD32_PORTRAIT");
1211 PrintStructures
->hLandscapeIcon
=
1212 LoadIconA(COMDLG32_hInstance
, "PD32_LANDSCAPE");
1214 /* display the collate/no_collate icon */
1215 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1216 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1218 if(PrintStructures
->hCollateIcon
== 0 ||
1219 PrintStructures
->hNoCollateIcon
== 0 ||
1220 PrintStructures
->hPortraitIcon
== 0 ||
1221 PrintStructures
->hLandscapeIcon
== 0) {
1222 ERR("no icon in resourcefile\n");
1223 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1224 EndDialog(hDlg
, FALSE
);
1228 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1229 * must be registered and the Help button must be shown.
1231 if (lppd
->Flags
& PD_SHOWHELP
) {
1232 if((PrintStructures
->HelpMessageID
=
1233 RegisterWindowMessageA(HELPMSGSTRINGA
)) == 0) {
1234 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL
);
1238 PrintStructures
->HelpMessageID
= 0;
1240 if(!(lppd
->Flags
&PD_PRINTSETUP
)) {
1241 PrintStructures
->hwndUpDown
=
1242 CreateUpDownControl(WS_CHILD
| WS_VISIBLE
| WS_BORDER
|
1243 UDS_NOTHOUSANDS
| UDS_ARROWKEYS
|
1244 UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, 0, 0, 0, 0,
1245 hDlg
, UPDOWN_ID
, COMDLG32_hInstance
,
1246 GetDlgItem(hDlg
, edt3
), MAX_COPIES
, 1, 1);
1249 /* FIXME: I allow more freedom than either Win95 or WinNT,
1250 * which do not agree to what errors should be thrown or not
1251 * in case nToPage or nFromPage is out-of-range.
1253 if (lppd
->nMaxPage
< lppd
->nMinPage
)
1254 lppd
->nMaxPage
= lppd
->nMinPage
;
1255 if (lppd
->nMinPage
== lppd
->nMaxPage
)
1256 lppd
->Flags
|= PD_NOPAGENUMS
;
1257 if (lppd
->nToPage
< lppd
->nMinPage
)
1258 lppd
->nToPage
= lppd
->nMinPage
;
1259 if (lppd
->nToPage
> lppd
->nMaxPage
)
1260 lppd
->nToPage
= lppd
->nMaxPage
;
1261 if (lppd
->nFromPage
< lppd
->nMinPage
)
1262 lppd
->nFromPage
= lppd
->nMinPage
;
1263 if (lppd
->nFromPage
> lppd
->nMaxPage
)
1264 lppd
->nFromPage
= lppd
->nMaxPage
;
1266 /* if we have the combo box, fill it */
1267 if (GetDlgItem(hDlg
,comboID
)) {
1270 pdn
= GlobalLock(lppd
->hDevNames
);
1271 pdm
= GlobalLock(lppd
->hDevMode
);
1273 name
= (char*)pdn
+ pdn
->wDeviceOffset
;
1275 name
= (char*)pdm
->dmDeviceName
;
1276 PRINTDLG_SetUpPrinterListComboA(hDlg
, comboID
, name
);
1277 if(pdm
) GlobalUnlock(lppd
->hDevMode
);
1278 if(pdn
) GlobalUnlock(lppd
->hDevNames
);
1280 /* Now find selected printer and update rest of dlg */
1281 name
= HeapAlloc(GetProcessHeap(),0,256);
1282 if (GetDlgItemTextA(hDlg
, comboID
, name
, 255))
1283 PRINTDLG_ChangePrinterA(hDlg
, name
, PrintStructures
);
1284 HeapFree(GetProcessHeap(),0,name
);
1286 /* else use default printer */
1288 DWORD dwBufLen
= sizeof(name
);
1289 BOOL ret
= GetDefaultPrinterA(name
, &dwBufLen
);
1292 PRINTDLG_ChangePrinterA(hDlg
, name
, PrintStructures
);
1294 FIXME("No default printer found, expect problems!\n");
1299 static LRESULT
PRINTDLG_WMInitDialogW(HWND hDlg
, WPARAM wParam
,
1300 PRINT_PTRW
* PrintStructures
)
1302 static const WCHAR PD32_COLLATE
[] = { 'P', 'D', '3', '2', '_', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
1303 static const WCHAR PD32_NOCOLLATE
[] = { 'P', 'D', '3', '2', '_', 'N', 'O', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
1304 static const WCHAR PD32_PORTRAIT
[] = { 'P', 'D', '3', '2', '_', 'P', 'O', 'R', 'T', 'R', 'A', 'I', 'T', 0 };
1305 static const WCHAR PD32_LANDSCAPE
[] = { 'P', 'D', '3', '2', '_', 'L', 'A', 'N', 'D', 'S', 'C', 'A', 'P', 'E', 0 };
1306 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1310 UINT comboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1312 /* load Collate ICONs */
1313 /* We load these with LoadImage because they are not a standard
1314 size and we don't want them rescaled */
1315 PrintStructures
->hCollateIcon
=
1316 LoadImageW(COMDLG32_hInstance
, PD32_COLLATE
, IMAGE_ICON
, 0, 0, 0);
1317 PrintStructures
->hNoCollateIcon
=
1318 LoadImageW(COMDLG32_hInstance
, PD32_NOCOLLATE
, IMAGE_ICON
, 0, 0, 0);
1320 /* These can be done with LoadIcon */
1321 PrintStructures
->hPortraitIcon
=
1322 LoadIconW(COMDLG32_hInstance
, PD32_PORTRAIT
);
1323 PrintStructures
->hLandscapeIcon
=
1324 LoadIconW(COMDLG32_hInstance
, PD32_LANDSCAPE
);
1326 /* display the collate/no_collate icon */
1327 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1328 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1330 if(PrintStructures
->hCollateIcon
== 0 ||
1331 PrintStructures
->hNoCollateIcon
== 0 ||
1332 PrintStructures
->hPortraitIcon
== 0 ||
1333 PrintStructures
->hLandscapeIcon
== 0) {
1334 ERR("no icon in resourcefile\n");
1335 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1336 EndDialog(hDlg
, FALSE
);
1340 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1341 * must be registered and the Help button must be shown.
1343 if (lppd
->Flags
& PD_SHOWHELP
) {
1344 if((PrintStructures
->HelpMessageID
=
1345 RegisterWindowMessageW(HELPMSGSTRINGW
)) == 0) {
1346 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL
);
1350 PrintStructures
->HelpMessageID
= 0;
1352 if(!(lppd
->Flags
&PD_PRINTSETUP
)) {
1353 PrintStructures
->hwndUpDown
=
1354 CreateUpDownControl(WS_CHILD
| WS_VISIBLE
| WS_BORDER
|
1355 UDS_NOTHOUSANDS
| UDS_ARROWKEYS
|
1356 UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, 0, 0, 0, 0,
1357 hDlg
, UPDOWN_ID
, COMDLG32_hInstance
,
1358 GetDlgItem(hDlg
, edt3
), MAX_COPIES
, 1, 1);
1361 /* FIXME: I allow more freedom than either Win95 or WinNT,
1362 * which do not agree to what errors should be thrown or not
1363 * in case nToPage or nFromPage is out-of-range.
1365 if (lppd
->nMaxPage
< lppd
->nMinPage
)
1366 lppd
->nMaxPage
= lppd
->nMinPage
;
1367 if (lppd
->nMinPage
== lppd
->nMaxPage
)
1368 lppd
->Flags
|= PD_NOPAGENUMS
;
1369 if (lppd
->nToPage
< lppd
->nMinPage
)
1370 lppd
->nToPage
= lppd
->nMinPage
;
1371 if (lppd
->nToPage
> lppd
->nMaxPage
)
1372 lppd
->nToPage
= lppd
->nMaxPage
;
1373 if (lppd
->nFromPage
< lppd
->nMinPage
)
1374 lppd
->nFromPage
= lppd
->nMinPage
;
1375 if (lppd
->nFromPage
> lppd
->nMaxPage
)
1376 lppd
->nFromPage
= lppd
->nMaxPage
;
1378 /* if we have the combo box, fill it */
1379 if (GetDlgItem(hDlg
,comboID
)) {
1382 pdn
= GlobalLock(lppd
->hDevNames
);
1383 pdm
= GlobalLock(lppd
->hDevMode
);
1385 name
= (WCHAR
*)pdn
+ pdn
->wDeviceOffset
;
1387 name
= pdm
->dmDeviceName
;
1388 PRINTDLG_SetUpPrinterListComboW(hDlg
, comboID
, name
);
1389 if(pdm
) GlobalUnlock(lppd
->hDevMode
);
1390 if(pdn
) GlobalUnlock(lppd
->hDevNames
);
1392 /* Now find selected printer and update rest of dlg */
1393 /* ansi is ok here */
1394 name
= HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR
));
1395 if (GetDlgItemTextW(hDlg
, comboID
, name
, 255))
1396 PRINTDLG_ChangePrinterW(hDlg
, name
, PrintStructures
);
1397 HeapFree(GetProcessHeap(),0,name
);
1399 /* else use default printer */
1401 DWORD dwBufLen
= sizeof(name
) / sizeof(WCHAR
);
1402 BOOL ret
= GetDefaultPrinterW(name
, &dwBufLen
);
1405 PRINTDLG_ChangePrinterW(hDlg
, name
, PrintStructures
);
1407 FIXME("No default printer found, expect problems!\n");
1412 /***********************************************************************
1413 * PRINTDLG_WMCommand [internal]
1415 LRESULT
PRINTDLG_WMCommandA(HWND hDlg
, WPARAM wParam
,
1416 LPARAM lParam
, PRINT_PTRA
* PrintStructures
)
1418 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1419 UINT PrinterComboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1420 LPDEVMODEA lpdm
= PrintStructures
->lpDevMode
;
1422 switch (LOWORD(wParam
)) {
1424 TRACE(" OK button was hit\n");
1425 if (!PRINTDLG_UpdatePrintDlgA(hDlg
, PrintStructures
)) {
1426 FIXME("Update printdlg was not successful!\n");
1429 EndDialog(hDlg
, TRUE
);
1433 TRACE(" CANCEL button was hit\n");
1434 EndDialog(hDlg
, FALSE
);
1438 TRACE(" HELP button was hit\n");
1439 SendMessageA(lppd
->hwndOwner
, PrintStructures
->HelpMessageID
,
1440 (WPARAM
) hDlg
, (LPARAM
) lppd
);
1443 case chx2
: /* collate pages checkbox */
1444 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
1445 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1446 (LPARAM
)PrintStructures
->hCollateIcon
);
1448 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1449 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1451 case edt1
: /* from page nr editbox */
1452 case edt2
: /* to page nr editbox */
1453 if (HIWORD(wParam
)==EN_CHANGE
) {
1456 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
1457 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
1458 if (nFromPage
!= lppd
->nFromPage
|| nToPage
!= lppd
->nToPage
)
1459 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1464 if(HIWORD(wParam
) == EN_CHANGE
) {
1465 INT copies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
1467 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1469 EnableWindow(GetDlgItem(hDlg
, chx2
), TRUE
);
1474 case psh1
: /* Print Setup */
1478 if (!PrintStructures
->dlg
.lpPrintDlg16
) {
1479 FIXME("The 32bit print dialog does not have this button!?\n");
1483 memcpy(&pdlg
,PrintStructures
->dlg
.lpPrintDlg16
,sizeof(pdlg
));
1484 pdlg
.Flags
|= PD_PRINTSETUP
;
1485 pdlg
.hwndOwner
= HWND_16(hDlg
);
1486 if (!PrintDlg16(&pdlg
))
1491 case psh2
: /* Properties button */
1494 char PrinterName
[256];
1496 GetDlgItemTextA(hDlg
, PrinterComboID
, PrinterName
, 255);
1497 if (!OpenPrinterA(PrinterName
, &hPrinter
, NULL
)) {
1498 FIXME(" Call to OpenPrinter did not succeed!\n");
1501 DocumentPropertiesA(hDlg
, hPrinter
, PrinterName
,
1502 PrintStructures
->lpDevMode
,
1503 PrintStructures
->lpDevMode
,
1504 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
1505 ClosePrinter(hPrinter
);
1509 case rad1
: /* Paperorientation */
1510 if (lppd
->Flags
& PD_PRINTSETUP
)
1512 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1513 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1514 (LPARAM
)(PrintStructures
->hPortraitIcon
));
1518 case rad2
: /* Paperorientation */
1519 if (lppd
->Flags
& PD_PRINTSETUP
)
1521 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1522 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1523 (LPARAM
)(PrintStructures
->hLandscapeIcon
));
1527 case cmb1
: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1528 if (PrinterComboID
!= LOWORD(wParam
)) {
1529 FIXME("No handling for print quality combo box yet.\n");
1533 case cmb4
: /* Printer combobox */
1534 if (HIWORD(wParam
)==CBN_SELCHANGE
) {
1535 char PrinterName
[256];
1536 GetDlgItemTextA(hDlg
, LOWORD(wParam
), PrinterName
, 255);
1537 PRINTDLG_ChangePrinterA(hDlg
, PrinterName
, PrintStructures
);
1541 case cmb2
: /* Papersize */
1543 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
1545 lpdm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageA(hDlg
, cmb2
,
1551 case cmb3
: /* Bin */
1553 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
1555 lpdm
->dmDefaultSource
= SendDlgItemMessageA(hDlg
, cmb3
,
1556 CB_GETITEMDATA
, Sel
,
1561 if(lppd
->Flags
& PD_PRINTSETUP
) {
1562 switch (LOWORD(wParam
)) {
1563 case rad1
: /* orientation */
1565 if (IsDlgButtonChecked(hDlg
, rad1
) == BST_CHECKED
) {
1566 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_PORTRAIT
) {
1567 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1568 SendDlgItemMessageA(hDlg
, stc10
, STM_SETIMAGE
,
1570 (LPARAM
)PrintStructures
->hPortraitIcon
);
1571 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
,
1573 (LPARAM
)PrintStructures
->hPortraitIcon
);
1576 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_LANDSCAPE
) {
1577 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1578 SendDlgItemMessageA(hDlg
, stc10
, STM_SETIMAGE
,
1580 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1581 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
,
1583 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1592 static LRESULT
PRINTDLG_WMCommandW(HWND hDlg
, WPARAM wParam
,
1593 LPARAM lParam
, PRINT_PTRW
* PrintStructures
)
1595 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1596 UINT PrinterComboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1597 LPDEVMODEW lpdm
= PrintStructures
->lpDevMode
;
1599 switch (LOWORD(wParam
)) {
1601 TRACE(" OK button was hit\n");
1602 if (!PRINTDLG_UpdatePrintDlgW(hDlg
, PrintStructures
)) {
1603 FIXME("Update printdlg was not successful!\n");
1606 EndDialog(hDlg
, TRUE
);
1610 TRACE(" CANCEL button was hit\n");
1611 EndDialog(hDlg
, FALSE
);
1615 TRACE(" HELP button was hit\n");
1616 SendMessageW(lppd
->hwndOwner
, PrintStructures
->HelpMessageID
,
1617 (WPARAM
) hDlg
, (LPARAM
) lppd
);
1620 case chx2
: /* collate pages checkbox */
1621 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
1622 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1623 (LPARAM
)PrintStructures
->hCollateIcon
);
1625 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1626 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1628 case edt1
: /* from page nr editbox */
1629 case edt2
: /* to page nr editbox */
1630 if (HIWORD(wParam
)==EN_CHANGE
) {
1633 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
1634 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
1635 if (nFromPage
!= lppd
->nFromPage
|| nToPage
!= lppd
->nToPage
)
1636 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1641 if(HIWORD(wParam
) == EN_CHANGE
) {
1642 INT copies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
1644 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1646 EnableWindow(GetDlgItem(hDlg
, chx2
), TRUE
);
1650 case psh1
: /* Print Setup */
1652 ERR("psh1 is called from 16bit code only, we should not get here.\n");
1655 case psh2
: /* Properties button */
1658 WCHAR PrinterName
[256];
1660 if (!GetDlgItemTextW(hDlg
, PrinterComboID
, PrinterName
, 255)) break;
1661 if (!OpenPrinterW(PrinterName
, &hPrinter
, NULL
)) {
1662 FIXME(" Call to OpenPrinter did not succeed!\n");
1665 DocumentPropertiesW(hDlg
, hPrinter
, PrinterName
,
1666 PrintStructures
->lpDevMode
,
1667 PrintStructures
->lpDevMode
,
1668 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
1669 ClosePrinter(hPrinter
);
1673 case rad1
: /* Paperorientation */
1674 if (lppd
->Flags
& PD_PRINTSETUP
)
1676 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1677 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1678 (LPARAM
)(PrintStructures
->hPortraitIcon
));
1682 case rad2
: /* Paperorientation */
1683 if (lppd
->Flags
& PD_PRINTSETUP
)
1685 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1686 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1687 (LPARAM
)(PrintStructures
->hLandscapeIcon
));
1691 case cmb1
: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1692 if (PrinterComboID
!= LOWORD(wParam
)) {
1693 FIXME("No handling for print quality combo box yet.\n");
1697 case cmb4
: /* Printer combobox */
1698 if (HIWORD(wParam
)==CBN_SELCHANGE
) {
1699 WCHAR PrinterName
[256];
1700 GetDlgItemTextW(hDlg
, LOWORD(wParam
), PrinterName
, 255);
1701 PRINTDLG_ChangePrinterW(hDlg
, PrinterName
, PrintStructures
);
1705 case cmb2
: /* Papersize */
1707 DWORD Sel
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
1709 lpdm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageW(hDlg
, cmb2
,
1715 case cmb3
: /* Bin */
1717 DWORD Sel
= SendDlgItemMessageW(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
1719 lpdm
->dmDefaultSource
= SendDlgItemMessageW(hDlg
, cmb3
,
1720 CB_GETITEMDATA
, Sel
,
1725 if(lppd
->Flags
& PD_PRINTSETUP
) {
1726 switch (LOWORD(wParam
)) {
1727 case rad1
: /* orientation */
1729 if (IsDlgButtonChecked(hDlg
, rad1
) == BST_CHECKED
) {
1730 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_PORTRAIT
) {
1731 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1732 SendDlgItemMessageW(hDlg
, stc10
, STM_SETIMAGE
,
1734 (LPARAM
)PrintStructures
->hPortraitIcon
);
1735 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
,
1737 (LPARAM
)PrintStructures
->hPortraitIcon
);
1740 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_LANDSCAPE
) {
1741 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1742 SendDlgItemMessageW(hDlg
, stc10
, STM_SETIMAGE
,
1744 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1745 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
,
1747 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1756 /***********************************************************************
1757 * PrintDlgProcA [internal]
1759 static INT_PTR CALLBACK
PrintDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
1762 PRINT_PTRA
* PrintStructures
;
1763 INT_PTR res
= FALSE
;
1765 if (uMsg
!=WM_INITDIALOG
) {
1766 PrintStructures
= (PRINT_PTRA
*)GetPropA(hDlg
,"__WINE_PRINTDLGDATA");
1767 if (!PrintStructures
)
1770 PrintStructures
= (PRINT_PTRA
*) lParam
;
1771 SetPropA(hDlg
,"__WINE_PRINTDLGDATA",PrintStructures
);
1772 if(!check_printer_setup(hDlg
))
1774 EndDialog(hDlg
,FALSE
);
1777 res
= PRINTDLG_WMInitDialog(hDlg
, wParam
, PrintStructures
);
1779 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
)
1780 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(
1781 hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->lpPrintDlg
1786 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
) {
1787 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
,uMsg
,wParam
,
1794 return PRINTDLG_WMCommandA(hDlg
, wParam
, lParam
, PrintStructures
);
1797 DestroyIcon(PrintStructures
->hCollateIcon
);
1798 DestroyIcon(PrintStructures
->hNoCollateIcon
);
1799 DestroyIcon(PrintStructures
->hPortraitIcon
);
1800 DestroyIcon(PrintStructures
->hLandscapeIcon
);
1801 if(PrintStructures
->hwndUpDown
)
1802 DestroyWindow(PrintStructures
->hwndUpDown
);
1808 static INT_PTR CALLBACK
PrintDlgProcW(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
1811 static const WCHAR propW
[] = {'_','_','W','I','N','E','_','P','R','I','N','T','D','L','G','D','A','T','A',0};
1812 PRINT_PTRW
* PrintStructures
;
1813 INT_PTR res
= FALSE
;
1815 if (uMsg
!=WM_INITDIALOG
) {
1816 PrintStructures
= (PRINT_PTRW
*) GetPropW(hDlg
, propW
);
1817 if (!PrintStructures
)
1820 PrintStructures
= (PRINT_PTRW
*) lParam
;
1821 SetPropW(hDlg
, propW
, PrintStructures
);
1822 if(!check_printer_setup(hDlg
))
1824 EndDialog(hDlg
,FALSE
);
1827 res
= PRINTDLG_WMInitDialogW(hDlg
, wParam
, PrintStructures
);
1829 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
)
1830 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->lpPrintDlg
);
1834 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
) {
1835 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
,uMsg
,wParam
, lParam
);
1841 return PRINTDLG_WMCommandW(hDlg
, wParam
, lParam
, PrintStructures
);
1844 DestroyIcon(PrintStructures
->hCollateIcon
);
1845 DestroyIcon(PrintStructures
->hNoCollateIcon
);
1846 DestroyIcon(PrintStructures
->hPortraitIcon
);
1847 DestroyIcon(PrintStructures
->hLandscapeIcon
);
1848 if(PrintStructures
->hwndUpDown
)
1849 DestroyWindow(PrintStructures
->hwndUpDown
);
1855 /************************************************************
1857 * PRINTDLG_GetDlgTemplate
1860 static HGLOBAL
PRINTDLG_GetDlgTemplateA(PRINTDLGA
*lppd
)
1865 if (lppd
->Flags
& PD_PRINTSETUP
) {
1866 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
1867 hDlgTmpl
= lppd
->hSetupTemplate
;
1868 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
1869 hResInfo
= FindResourceA(lppd
->hInstance
,
1870 lppd
->lpSetupTemplateName
, (LPSTR
)RT_DIALOG
);
1871 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1873 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32_SETUP",
1875 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1878 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
1879 hDlgTmpl
= lppd
->hPrintTemplate
;
1880 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
1881 hResInfo
= FindResourceA(lppd
->hInstance
,
1882 lppd
->lpPrintTemplateName
,
1884 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1886 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32",
1888 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1894 static HGLOBAL
PRINTDLG_GetDlgTemplateW(PRINTDLGW
*lppd
)
1898 static const WCHAR xpsetup
[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
1899 static const WCHAR xprint
[] = { 'P','R','I','N','T','3','2',0};
1901 if (lppd
->Flags
& PD_PRINTSETUP
) {
1902 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
1903 hDlgTmpl
= lppd
->hSetupTemplate
;
1904 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
1905 hResInfo
= FindResourceW(lppd
->hInstance
,
1906 lppd
->lpSetupTemplateName
, (LPWSTR
)RT_DIALOG
);
1907 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1909 hResInfo
= FindResourceW(COMDLG32_hInstance
, xpsetup
, (LPWSTR
)RT_DIALOG
);
1910 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1913 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
1914 hDlgTmpl
= lppd
->hPrintTemplate
;
1915 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
1916 hResInfo
= FindResourceW(lppd
->hInstance
,
1917 lppd
->lpPrintTemplateName
,
1919 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1921 hResInfo
= FindResourceW(COMDLG32_hInstance
, xprint
, (LPWSTR
)RT_DIALOG
);
1922 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1928 /***********************************************************************
1933 static BOOL
PRINTDLG_CreateDCA(LPPRINTDLGA lppd
)
1935 DEVNAMES
*pdn
= GlobalLock(lppd
->hDevNames
);
1936 DEVMODEA
*pdm
= GlobalLock(lppd
->hDevMode
);
1938 if(lppd
->Flags
& PD_RETURNDC
) {
1939 lppd
->hDC
= CreateDCA((char*)pdn
+ pdn
->wDriverOffset
,
1940 (char*)pdn
+ pdn
->wDeviceOffset
,
1941 (char*)pdn
+ pdn
->wOutputOffset
,
1943 } else if(lppd
->Flags
& PD_RETURNIC
) {
1944 lppd
->hDC
= CreateICA((char*)pdn
+ pdn
->wDriverOffset
,
1945 (char*)pdn
+ pdn
->wDeviceOffset
,
1946 (char*)pdn
+ pdn
->wOutputOffset
,
1949 GlobalUnlock(lppd
->hDevNames
);
1950 GlobalUnlock(lppd
->hDevMode
);
1951 return lppd
->hDC
? TRUE
: FALSE
;
1954 static BOOL
PRINTDLG_CreateDCW(LPPRINTDLGW lppd
)
1956 DEVNAMES
*pdn
= GlobalLock(lppd
->hDevNames
);
1957 DEVMODEW
*pdm
= GlobalLock(lppd
->hDevMode
);
1959 if(lppd
->Flags
& PD_RETURNDC
) {
1960 lppd
->hDC
= CreateDCW((WCHAR
*)pdn
+ pdn
->wDriverOffset
,
1961 (WCHAR
*)pdn
+ pdn
->wDeviceOffset
,
1962 (WCHAR
*)pdn
+ pdn
->wOutputOffset
,
1964 } else if(lppd
->Flags
& PD_RETURNIC
) {
1965 lppd
->hDC
= CreateICW((WCHAR
*)pdn
+ pdn
->wDriverOffset
,
1966 (WCHAR
*)pdn
+ pdn
->wDeviceOffset
,
1967 (WCHAR
*)pdn
+ pdn
->wOutputOffset
,
1970 GlobalUnlock(lppd
->hDevNames
);
1971 GlobalUnlock(lppd
->hDevMode
);
1972 return lppd
->hDC
? TRUE
: FALSE
;
1975 /***********************************************************************
1976 * PrintDlgA (COMDLG32.@)
1978 * Displays the the PRINT dialog box, which enables the user to specify
1979 * specific properties of the print job.
1982 * lppd [IO] ptr to PRINTDLG32 struct
1985 * nonzero if the user pressed the OK button
1986 * zero if the user cancelled the window or an error occurred
1990 * * The Collate Icons do not display, even though they are in the code.
1991 * * The Properties Button(s) should call DocumentPropertiesA().
1994 BOOL WINAPI
PrintDlgA(LPPRINTDLGA lppd
)
2002 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
2006 hInst
= (HINSTANCE
)GetWindowLongPtrA( lppd
->hwndOwner
, GWLP_HINSTANCE
);
2007 if(TRACE_ON(commdlg
)) {
2008 char flagstr
[1000] = "";
2009 const struct pd_flags
*pflag
= pd_flags
;
2010 for( ; pflag
->name
; pflag
++) {
2011 if(lppd
->Flags
& pflag
->flag
)
2012 strcat(flagstr
, pflag
->name
);
2014 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2015 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2016 "flags %08x (%s)\n",
2017 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
2018 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
2019 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
2022 if(lppd
->lStructSize
!= sizeof(PRINTDLGA
)) {
2023 WARN("structure size failure !!!\n");
2024 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
2028 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
2029 PRINTER_INFO_2A
*pbuf
;
2030 DRIVER_INFO_3A
*dbuf
;
2034 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
2035 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2036 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2039 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
2040 WARN("Can't find default printer\n");
2041 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
2045 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
2046 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
2047 GetPrinterA(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
2049 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
2050 dbuf
= HeapAlloc(GetProcessHeap(),0,needed
);
2051 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
2052 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",GetLastError(),pbuf
->pPrinterName
);
2053 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2058 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
2062 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
2063 pbuf
->pDevMode
->dmDriverExtra
);
2064 ptr
= GlobalLock(lppd
->hDevMode
);
2065 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
2066 pbuf
->pDevMode
->dmDriverExtra
);
2067 GlobalUnlock(lppd
->hDevMode
);
2068 HeapFree(GetProcessHeap(), 0, pbuf
);
2069 HeapFree(GetProcessHeap(), 0, dbuf
);
2073 PRINT_PTRA
*PrintStructures
;
2075 /* load Dialog resources,
2076 * depending on Flags indicates Print32 or Print32_setup dialog
2078 hDlgTmpl
= PRINTDLG_GetDlgTemplateA(lppd
);
2080 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2083 ptr
= LockResource( hDlgTmpl
);
2085 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2089 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2090 sizeof(PRINT_PTRA
));
2091 PrintStructures
->lpPrintDlg
= lppd
;
2093 /* and create & process the dialog .
2094 * -1 is failure, 0 is broken hwnd, everything else is ok.
2096 bRet
= (0<DialogBoxIndirectParamA(hInst
, ptr
, lppd
->hwndOwner
,
2098 (LPARAM
)PrintStructures
));
2101 DEVMODEA
*lpdm
= PrintStructures
->lpDevMode
, *lpdmReturn
;
2102 PRINTER_INFO_2A
*pi
= PrintStructures
->lpPrinterInfo
;
2103 DRIVER_INFO_3A
*di
= PrintStructures
->lpDriverInfo
;
2105 if (lppd
->hDevMode
== 0) {
2106 TRACE(" No hDevMode yet... Need to create my own\n");
2107 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
,
2108 lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2110 lppd
->hDevMode
= GlobalReAlloc(lppd
->hDevMode
,
2111 lpdm
->dmSize
+ lpdm
->dmDriverExtra
,
2114 lpdmReturn
= GlobalLock(lppd
->hDevMode
);
2115 memcpy(lpdmReturn
, lpdm
, lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2117 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
2122 GlobalUnlock(lppd
->hDevMode
);
2124 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
2125 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpPrinterInfo
);
2126 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDriverInfo
);
2127 HeapFree(GetProcessHeap(), 0, PrintStructures
);
2129 if(bRet
&& (lppd
->Flags
& PD_RETURNDC
|| lppd
->Flags
& PD_RETURNIC
))
2130 bRet
= PRINTDLG_CreateDCA(lppd
);
2132 TRACE("exit! (%d)\n", bRet
);
2136 /***********************************************************************
2137 * PrintDlgW (COMDLG32.@)
2141 BOOL WINAPI
PrintDlgW(LPPRINTDLGW lppd
)
2149 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
2153 hInst
= (HINSTANCE
)GetWindowLongPtrW( lppd
->hwndOwner
, GWLP_HINSTANCE
);
2154 if(TRACE_ON(commdlg
)) {
2155 char flagstr
[1000] = "";
2156 const struct pd_flags
*pflag
= pd_flags
;
2157 for( ; pflag
->name
; pflag
++) {
2158 if(lppd
->Flags
& pflag
->flag
)
2159 strcat(flagstr
, pflag
->name
);
2161 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2162 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2163 "flags %08x (%s)\n",
2164 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
2165 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
2166 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
2169 if(lppd
->lStructSize
!= sizeof(PRINTDLGW
)) {
2170 WARN("structure size failure !!!\n");
2171 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
2175 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
2176 PRINTER_INFO_2W
*pbuf
;
2177 DRIVER_INFO_3W
*dbuf
;
2181 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
2182 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2183 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2186 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
2187 WARN("Can't find default printer\n");
2188 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
2192 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
2193 pbuf
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*needed
);
2194 GetPrinterW(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
2196 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
2197 dbuf
= HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*needed
);
2198 if (!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
2199 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",GetLastError(),debugstr_w(pbuf
->pPrinterName
));
2200 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2205 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
2209 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
2210 pbuf
->pDevMode
->dmDriverExtra
);
2211 ptr
= GlobalLock(lppd
->hDevMode
);
2212 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
2213 pbuf
->pDevMode
->dmDriverExtra
);
2214 GlobalUnlock(lppd
->hDevMode
);
2215 HeapFree(GetProcessHeap(), 0, pbuf
);
2216 HeapFree(GetProcessHeap(), 0, dbuf
);
2220 PRINT_PTRW
*PrintStructures
;
2222 /* load Dialog resources,
2223 * depending on Flags indicates Print32 or Print32_setup dialog
2225 hDlgTmpl
= PRINTDLG_GetDlgTemplateW(lppd
);
2227 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2230 ptr
= LockResource( hDlgTmpl
);
2232 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2236 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2237 sizeof(PRINT_PTRW
));
2238 PrintStructures
->lpPrintDlg
= lppd
;
2240 /* and create & process the dialog .
2241 * -1 is failure, 0 is broken hwnd, everything else is ok.
2243 bRet
= (0<DialogBoxIndirectParamW(hInst
, ptr
, lppd
->hwndOwner
,
2245 (LPARAM
)PrintStructures
));
2248 DEVMODEW
*lpdm
= PrintStructures
->lpDevMode
, *lpdmReturn
;
2249 PRINTER_INFO_2W
*pi
= PrintStructures
->lpPrinterInfo
;
2250 DRIVER_INFO_3W
*di
= PrintStructures
->lpDriverInfo
;
2252 if (lppd
->hDevMode
== 0) {
2253 TRACE(" No hDevMode yet... Need to create my own\n");
2254 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
,
2255 lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2258 if((locks
= (GlobalFlags(lppd
->hDevMode
) & GMEM_LOCKCOUNT
))) {
2259 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks
);
2261 GlobalUnlock(lppd
->hDevMode
);
2262 TRACE("Now got %d locks\n", locks
);
2265 lppd
->hDevMode
= GlobalReAlloc(lppd
->hDevMode
,
2266 lpdm
->dmSize
+ lpdm
->dmDriverExtra
,
2269 lpdmReturn
= GlobalLock(lppd
->hDevMode
);
2270 memcpy(lpdmReturn
, lpdm
, lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2272 if (lppd
->hDevNames
!= 0) {
2274 if((locks
= (GlobalFlags(lppd
->hDevNames
) & GMEM_LOCKCOUNT
))) {
2275 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks
);
2277 GlobalUnlock(lppd
->hDevNames
);
2280 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
2285 GlobalUnlock(lppd
->hDevMode
);
2287 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
2288 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpPrinterInfo
);
2289 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDriverInfo
);
2290 HeapFree(GetProcessHeap(), 0, PrintStructures
);
2292 if(bRet
&& (lppd
->Flags
& PD_RETURNDC
|| lppd
->Flags
& PD_RETURNIC
))
2293 bRet
= PRINTDLG_CreateDCW(lppd
);
2295 TRACE("exit! (%d)\n", bRet
);
2299 /***********************************************************************
2304 * cmb1 - printer select (not in standart dialog template)
2306 * cmb3 - source (tray?)
2307 * edt4 - border left
2309 * edt6 - border right
2310 * edt7 - border bottom
2311 * psh3 - "Printer..."
2315 LPPAGESETUPDLGA dlga
; /* Handler to user defined struct */
2317 HWND hDlg
; /* Page Setup dialog handler */
2318 PAGESETUPDLGA curdlg
; /* Struct means cerrent dialog state */
2319 RECT rtDrawRect
; /* Drawing rect for page */
2323 LPPAGESETUPDLGW dlga
;
2328 static HGLOBAL
PRINTDLG_GetPGSTemplateA(PAGESETUPDLGA
*lppd
)
2333 if(lppd
->Flags
& PSD_ENABLEPAGESETUPTEMPLATEHANDLE
) {
2334 hDlgTmpl
= lppd
->hPageSetupTemplate
;
2335 } else if(lppd
->Flags
& PSD_ENABLEPAGESETUPTEMPLATE
) {
2336 hResInfo
= FindResourceA(lppd
->hInstance
,
2337 lppd
->lpPageSetupTemplateName
, (LPSTR
)RT_DIALOG
);
2338 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
2340 hResInfo
= FindResourceA(COMDLG32_hInstance
,(LPCSTR
)PAGESETUPDLGORD
,(LPSTR
)RT_DIALOG
);
2341 hDlgTmpl
= LoadResource(COMDLG32_hInstance
,hResInfo
);
2346 static HGLOBAL
PRINTDLG_GetPGSTemplateW(PAGESETUPDLGW
*lppd
)
2351 if(lppd
->Flags
& PSD_ENABLEPAGESETUPTEMPLATEHANDLE
) {
2352 hDlgTmpl
= lppd
->hPageSetupTemplate
;
2353 } else if(lppd
->Flags
& PSD_ENABLEPAGESETUPTEMPLATE
) {
2354 hResInfo
= FindResourceW(lppd
->hInstance
,
2355 lppd
->lpPageSetupTemplateName
, (LPWSTR
)RT_DIALOG
);
2356 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
2358 hResInfo
= FindResourceW(COMDLG32_hInstance
,(LPCWSTR
)PAGESETUPDLGORD
,(LPWSTR
)RT_DIALOG
);
2359 hDlgTmpl
= LoadResource(COMDLG32_hInstance
,hResInfo
);
2365 _c_10mm2size(PAGESETUPDLGA
*dlga
,DWORD size
) {
2366 if (dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
)
2367 return 10*size
*100/254;
2368 /* If we don't have a flag, we can choose one. Use millimeters
2369 * to avoid confusing me
2371 dlga
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
2377 _c_inch2size(PAGESETUPDLGA
*dlga
,DWORD size
) {
2378 if (dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
)
2380 if (dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
)
2381 return (size
*254)/100;
2382 /* if we don't have a flag, we can choose one. Use millimeters
2383 * to avoid confusing me
2385 dlga
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
2386 return (size
*254)/100;
2390 _c_size2strA(PageSetupDataA
*pda
,DWORD size
,LPSTR strout
) {
2391 strcpy(strout
,"<undef>");
2392 if (pda
->dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
) {
2393 sprintf(strout
,"%d",(size
)/100);
2396 if (pda
->dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
) {
2397 sprintf(strout
,"%din",(size
)/1000);
2400 pda
->dlga
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
2401 sprintf(strout
,"%d",(size
)/100);
2405 _c_size2strW(PageSetupDataW
*pda
,DWORD size
,LPWSTR strout
) {
2406 static const WCHAR UNDEF
[] = { '<', 'u', 'n', 'd', 'e', 'f', '>', 0 };
2407 static const WCHAR mm_fmt
[] = { '%', '.', '2', 'f', 'm', 'm', 0 };
2408 static const WCHAR in_fmt
[] = { '%', '.', '2', 'f', 'i', 'n', 0 };
2409 lstrcpyW(strout
, UNDEF
);
2410 if (pda
->dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
) {
2411 wsprintfW(strout
,mm_fmt
,(size
*1.0)/100.0);
2414 if (pda
->dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
) {
2415 wsprintfW(strout
,in_fmt
,(size
*1.0)/1000.0);
2418 pda
->dlga
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
2419 wsprintfW(strout
,mm_fmt
,(size
*1.0)/100.0);
2424 _c_str2sizeA(PAGESETUPDLGA
*dlga
,LPCSTR strin
) {
2429 if (!sscanf(strin
,"%f%s",&val
,rest
))
2432 if (!strcmp(rest
,"in") || !strcmp(rest
,"inch")) {
2433 if (dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
)
2436 return val
*25.4*100;
2438 if (!strcmp(rest
,"cm")) { rest
[0]='m'; val
= val
*10.0; }
2439 if (!strcmp(rest
,"m")) { strcpy(rest
,"mm"); val
= val
*1000.0; }
2441 if (!strcmp(rest
,"mm")) {
2442 if (dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
)
2445 return 1000.0*val
/25.4;
2447 if (rest
[0]=='\0') {
2448 /* use application supplied default */
2449 if (dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
) {
2453 if (dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
) {
2458 ERR("Did not find a conversion for type '%s'!\n",rest
);
2464 _c_str2sizeW(PAGESETUPDLGW
*dlga
, LPCWSTR strin
) {
2467 /* this W -> A transition is OK */
2468 /* we need a unicode version of sscanf to avoid it */
2469 WideCharToMultiByte(CP_ACP
, 0, strin
, -1, buf
, sizeof(buf
), NULL
, NULL
);
2470 return _c_str2sizeA((PAGESETUPDLGA
*)dlga
, buf
);
2474 /****************************************************************************
2475 * PRINTDLG_PS_UpdateDlgStructA
2477 * Updates pda->dlga structure
2478 * Function calls when user presses OK button
2481 * hDlg [in] main window dialog HANDLE
2482 * pda [in/out] ptr to PageSetupDataA structere
2488 PRINTDLG_PS_UpdateDlgStructA(HWND hDlg
, PageSetupDataA
*pda
) {
2493 memcpy(pda
->dlga
, &pda
->curdlg
, sizeof(pda
->curdlg
));
2494 pda
->dlga
->hDevMode
= pda
->pdlg
.hDevMode
;
2495 pda
->dlga
->hDevNames
= pda
->pdlg
.hDevNames
;
2497 dn
= GlobalLock(pda
->pdlg
.hDevNames
);
2498 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2500 /* Save paper orientation into device context */
2501 if(pda
->curdlg
.ptPaperSize
.x
> pda
->curdlg
.ptPaperSize
.y
)
2502 dm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
2504 dm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
2506 /* Save paper size into the device context */
2507 paperword
= SendDlgItemMessageA(hDlg
,cmb2
,CB_GETITEMDATA
,
2508 SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0), 0);
2509 if (paperword
!= CB_ERR
)
2510 dm
->u1
.s1
.dmPaperSize
= paperword
;
2512 FIXME("could not get dialog text for papersize cmbbox?\n");
2514 /* Save paper source into the device context */
2515 paperword
= SendDlgItemMessageA(hDlg
,cmb1
,CB_GETITEMDATA
,
2516 SendDlgItemMessageA(hDlg
, cmb1
, CB_GETCURSEL
, 0, 0), 0);
2517 if (paperword
!= CB_ERR
)
2518 dm
->dmDefaultSource
= paperword
;
2520 FIXME("could not get dialog text for papersize cmbbox?\n");
2522 GlobalUnlock(pda
->pdlg
.hDevNames
);
2523 GlobalUnlock(pda
->pdlg
.hDevMode
);
2529 PRINTDLG_PS_UpdateDlgStructW(HWND hDlg
, PageSetupDataW
*pda
) {
2532 LPWSTR devname
,portname
;
2533 WCHAR papername
[64];
2536 dn
= GlobalLock(pda
->pdlg
.hDevNames
);
2537 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2538 devname
= ((WCHAR
*)dn
)+dn
->wDeviceOffset
;
2539 portname
= ((WCHAR
*)dn
)+dn
->wOutputOffset
;
2541 /* Save paper size into device context */
2542 PRINTDLG_SetUpPaperComboBoxW(hDlg
,cmb2
,devname
,portname
,dm
);
2543 /* Save paper source into device context */
2544 PRINTDLG_SetUpPaperComboBoxW(hDlg
,cmb3
,devname
,portname
,dm
);
2546 if (GetDlgItemTextW(hDlg
,cmb2
,papername
,sizeof(papername
))>0) {
2547 PRINTDLG_PaperSizeW(&(pda
->pdlg
),papername
,&(pda
->dlga
->ptPaperSize
));
2548 pda
->dlga
->ptPaperSize
.x
= _c_10mm2size((LPPAGESETUPDLGA
)pda
->dlga
,pda
->dlga
->ptPaperSize
.x
);
2549 pda
->dlga
->ptPaperSize
.y
= _c_10mm2size((LPPAGESETUPDLGA
)pda
->dlga
,pda
->dlga
->ptPaperSize
.y
);
2551 FIXME("could not get dialog text for papersize cmbbox?\n");
2552 #define GETVAL(id,val) if (GetDlgItemTextW(hDlg,id,buf,sizeof(buf)/sizeof(buf[0]))>0) { val = _c_str2sizeW(pda->dlga,buf); } else { FIXME("could not get dlgitemtextw for %x\n",id); }
2553 GETVAL(edt4
,pda
->dlga
->rtMargin
.left
);
2554 GETVAL(edt5
,pda
->dlga
->rtMargin
.top
);
2555 GETVAL(edt6
,pda
->dlga
->rtMargin
.right
);
2556 GETVAL(edt7
,pda
->dlga
->rtMargin
.bottom
);
2559 /* If we are in landscape, swap x and y of page size */
2560 if (IsDlgButtonChecked(hDlg
, rad2
)) {
2562 tmp
= pda
->dlga
->ptPaperSize
.x
;
2563 pda
->dlga
->ptPaperSize
.x
= pda
->dlga
->ptPaperSize
.y
;
2564 pda
->dlga
->ptPaperSize
.y
= tmp
;
2566 GlobalUnlock(pda
->pdlg
.hDevNames
);
2567 GlobalUnlock(pda
->pdlg
.hDevMode
);
2571 /**********************************************************************************************
2572 * PRINTDLG_PS_ChangeActivePrinerA
2574 * Redefines hDevMode and hDevNames HANDLES and initialises it.
2577 * name [in] Name of a printer for activation
2578 * pda [in/out] ptr to PageSetupDataA structure
2585 PRINTDLG_PS_ChangeActivePrinterA(LPSTR name
, PageSetupDataA
*pda
){
2588 LPPRINTER_INFO_2A lpPrinterInfo
;
2589 LPDRIVER_INFO_3A lpDriverInfo
;
2590 DEVMODEA
*pDevMode
, *dm
;
2592 if(!OpenPrinterA(name
, &hprn
, NULL
)){
2593 ERR("Can't open printer %s\n", name
);
2596 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
2597 lpPrinterInfo
= HeapAlloc(GetProcessHeap(), 0, needed
);
2598 GetPrinterA(hprn
, 2, (LPBYTE
)lpPrinterInfo
, needed
, &needed
);
2599 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
2600 lpDriverInfo
= HeapAlloc(GetProcessHeap(), 0, needed
);
2601 if(!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)lpDriverInfo
, needed
, &needed
)) {
2602 ERR("GetPrinterDriverA failed for %s, fix your config!\n", lpPrinterInfo
->pPrinterName
);
2607 needed
= DocumentPropertiesA(0, 0, name
, NULL
, NULL
, 0);
2609 ERR("DocumentProperties fails on %s\n", debugstr_a(name
));
2612 pDevMode
= HeapAlloc(GetProcessHeap(), 0, needed
);
2613 DocumentPropertiesA(0, 0, name
, pDevMode
, NULL
, DM_OUT_BUFFER
);
2615 pda
->pdlg
.hDevMode
= GlobalReAlloc(pda
->pdlg
.hDevMode
,
2616 pDevMode
->dmSize
+ pDevMode
->dmDriverExtra
,
2618 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2619 memcpy(dm
, pDevMode
, pDevMode
->dmSize
+ pDevMode
->dmDriverExtra
);
2621 PRINTDLG_CreateDevNames(&(pda
->pdlg
.hDevNames
),
2622 lpDriverInfo
->pDriverPath
,
2623 lpPrinterInfo
->pPrinterName
,
2624 lpPrinterInfo
->pPortName
);
2626 GlobalUnlock(pda
->pdlg
.hDevMode
);
2627 HeapFree(GetProcessHeap(), 0, pDevMode
);
2628 HeapFree(GetProcessHeap(), 0, lpPrinterInfo
);
2629 HeapFree(GetProcessHeap(), 0, lpDriverInfo
);
2633 /****************************************************************************************
2634 * PRINTDLG_PS_ChangePrinterA
2636 * Fills Printers, Paper and Source combo
2642 PRINTDLG_PS_ChangePrinterA(HWND hDlg
, PageSetupDataA
*pda
) {
2645 LPSTR devname
,portname
;
2647 dn
= GlobalLock(pda
->pdlg
.hDevNames
);
2648 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2649 devname
= ((char*)dn
)+dn
->wDeviceOffset
;
2650 portname
= ((char*)dn
)+dn
->wOutputOffset
;
2651 PRINTDLG_SetUpPrinterListComboA(hDlg
, cmb1
, devname
);
2652 PRINTDLG_SetUpPaperComboBoxA(hDlg
,cmb2
,devname
,portname
,dm
);
2653 PRINTDLG_SetUpPaperComboBoxA(hDlg
,cmb3
,devname
,portname
,dm
);
2654 GlobalUnlock(pda
->pdlg
.hDevNames
);
2655 GlobalUnlock(pda
->pdlg
.hDevMode
);
2660 PRINTDLG_PS_ChangePrinterW(HWND hDlg
, PageSetupDataW
*pda
) {
2663 LPWSTR devname
,portname
;
2665 dn
= GlobalLock(pda
->pdlg
.hDevNames
);
2666 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2667 devname
= ((WCHAR
*)dn
)+dn
->wDeviceOffset
;
2668 portname
= ((WCHAR
*)dn
)+dn
->wOutputOffset
;
2669 PRINTDLG_SetUpPaperComboBoxW(hDlg
,cmb2
,devname
,portname
,dm
);
2670 PRINTDLG_SetUpPaperComboBoxW(hDlg
,cmb3
,devname
,portname
,dm
);
2671 GlobalUnlock(pda
->pdlg
.hDevNames
);
2672 GlobalUnlock(pda
->pdlg
.hDevMode
);
2676 /******************************************************************************************
2677 * PRINTDLG_PS_ChangePaperPrev
2679 * Changes paper preview size / position
2682 * pda [i] Pointer for current PageSetupDataA structure
2688 PRINTDLG_PS_ChangePaperPrev(PageSetupDataA
*pda
)
2690 LONG width
, height
, x
, y
;
2693 if(pda
->curdlg
.ptPaperSize
.x
> pda
->curdlg
.ptPaperSize
.y
) {
2694 width
= pda
->rtDrawRect
.right
- pda
->rtDrawRect
.left
;
2695 height
= pda
->curdlg
.ptPaperSize
.y
* width
/ pda
->curdlg
.ptPaperSize
.x
;
2697 height
= pda
->rtDrawRect
.bottom
- pda
->rtDrawRect
.top
;
2698 width
= pda
->curdlg
.ptPaperSize
.x
* height
/ pda
->curdlg
.ptPaperSize
.y
;
2700 x
= (pda
->rtDrawRect
.right
+ pda
->rtDrawRect
.left
- width
) / 2;
2701 y
= (pda
->rtDrawRect
.bottom
+ pda
->rtDrawRect
.top
- height
) / 2;
2702 TRACE("rtDrawRect(%d, %d, %d, %d) x=%d, y=%d, w=%d, h=%d\n",
2703 pda
->rtDrawRect
.left
, pda
->rtDrawRect
.top
, pda
->rtDrawRect
.right
, pda
->rtDrawRect
.bottom
,
2704 x
, y
, width
, height
);
2707 MoveWindow(GetDlgItem(pda
->hDlg
, rct2
), x
+width
, y
+SHADOW
, SHADOW
, height
, FALSE
);
2708 MoveWindow(GetDlgItem(pda
->hDlg
, rct3
), x
+SHADOW
, y
+height
, width
, SHADOW
, FALSE
);
2709 MoveWindow(GetDlgItem(pda
->hDlg
, rct1
), x
, y
, width
, height
, FALSE
);
2710 memcpy(&rtTmp
, &pda
->rtDrawRect
, sizeof(RECT
));
2711 rtTmp
.right
+= SHADOW
;
2712 rtTmp
.bottom
+= SHADOW
;
2715 InvalidateRect(pda
->hDlg
, &rtTmp
, TRUE
);
2719 #define GETVAL(idc,val) \
2720 if(msg == EN_CHANGE){ \
2721 if (GetDlgItemTextA(hDlg,idc,buf,sizeof(buf)) > 0)\
2722 val = _c_str2sizeA(pda->dlga,buf); \
2724 FIXME("could not get dlgitemtexta for %x\n",id); \
2727 /********************************************************************************
2728 * PRINTDLG_PS_WMCommandA
2729 * process WM_COMMAND message for PageSetupDlgA
2732 * hDlg [in] Main dialog HANDLE
2733 * wParam [in] WM_COMMAND wParam
2734 * lParam [in] WM_COMMAND lParam
2735 * pda [in/out] ptr to PageSetupDataA
2739 PRINTDLG_PS_WMCommandA(
2740 HWND hDlg
, WPARAM wParam
, LPARAM lParam
, PageSetupDataA
*pda
2742 WORD msg
= HIWORD(wParam
);
2743 WORD id
= LOWORD(wParam
);
2746 TRACE("loword (lparam) %d, wparam 0x%x, lparam %08lx\n",
2747 LOWORD(lParam
),wParam
,lParam
);
2750 if (!PRINTDLG_PS_UpdateDlgStructA(hDlg
, pda
))
2752 EndDialog(hDlg
, TRUE
);
2756 EndDialog(hDlg
, FALSE
);
2760 pda
->pdlg
.Flags
= 0;
2761 pda
->pdlg
.hwndOwner
= hDlg
;
2762 if (PrintDlgA(&(pda
->pdlg
)))
2763 PRINTDLG_PS_ChangePrinterA(hDlg
,pda
);
2767 if (pda
->curdlg
.ptPaperSize
.x
> pda
->curdlg
.ptPaperSize
.y
){
2768 DWORD tmp
= pda
->curdlg
.ptPaperSize
.x
;
2769 pda
->curdlg
.ptPaperSize
.x
= pda
->curdlg
.ptPaperSize
.y
;
2770 pda
->curdlg
.ptPaperSize
.y
= tmp
;
2772 PRINTDLG_PS_ChangePaperPrev(pda
);
2775 if (pda
->curdlg
.ptPaperSize
.y
> pda
->curdlg
.ptPaperSize
.x
){
2776 DWORD tmp
= pda
->curdlg
.ptPaperSize
.x
;
2777 pda
->curdlg
.ptPaperSize
.x
= pda
->curdlg
.ptPaperSize
.y
;
2778 pda
->curdlg
.ptPaperSize
.y
= tmp
;
2780 PRINTDLG_PS_ChangePaperPrev(pda
);
2782 case cmb1
: /* Printer combo */
2783 if(msg
== CBN_SELCHANGE
){
2784 char crPrinterName
[256];
2785 GetDlgItemTextA(hDlg
, id
, crPrinterName
, 255);
2786 PRINTDLG_PS_ChangeActivePrinterA(crPrinterName
, pda
);
2787 PRINTDLG_PS_ChangePrinterA(hDlg
, pda
);
2790 case cmb2
: /* Paper combo */
2791 if(msg
== CBN_SELCHANGE
){
2792 DWORD paperword
= SendDlgItemMessageA(hDlg
,cmb2
,CB_GETITEMDATA
,
2793 SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0), 0);
2794 if (paperword
!= CB_ERR
) {
2795 PRINTDLG_PaperSizeA(&(pda
->pdlg
), paperword
,&(pda
->curdlg
.ptPaperSize
));
2796 pda
->curdlg
.ptPaperSize
.x
= _c_10mm2size(pda
->dlga
,pda
->curdlg
.ptPaperSize
.x
);
2797 pda
->curdlg
.ptPaperSize
.y
= _c_10mm2size(pda
->dlga
,pda
->curdlg
.ptPaperSize
.y
);
2799 if (IsDlgButtonChecked(hDlg
, rad2
)) {
2800 DWORD tmp
= pda
->curdlg
.ptPaperSize
.x
;
2801 pda
->curdlg
.ptPaperSize
.x
= pda
->curdlg
.ptPaperSize
.y
;
2802 pda
->curdlg
.ptPaperSize
.y
= tmp
;
2804 PRINTDLG_PS_ChangePaperPrev(pda
);
2806 FIXME("could not get dialog text for papersize cmbbox?\n");
2810 if(msg
== CBN_SELCHANGE
){
2811 DEVMODEA
*dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2812 dm
->dmDefaultSource
= SendDlgItemMessageA(hDlg
, cmb3
,CB_GETITEMDATA
,
2813 SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0), 0);
2814 GlobalUnlock(pda
->pdlg
.hDevMode
);
2817 case psh2
: /* Printer Properties button */
2820 char PrinterName
[256];
2825 GetDlgItemTextA(hDlg
, cmb1
, PrinterName
, 255);
2826 if (!OpenPrinterA(PrinterName
, &hPrinter
, NULL
)) {
2827 FIXME("Call to OpenPrinter did not succeed!\n");
2830 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2831 DocumentPropertiesA(hDlg
, hPrinter
, PrinterName
, dm
, dm
,
2832 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
2833 ClosePrinter(hPrinter
);
2834 /* Changing paper */
2835 PRINTDLG_PaperSizeA(&(pda
->pdlg
), dm
->u1
.s1
.dmPaperSize
, &(pda
->curdlg
.ptPaperSize
));
2836 pda
->curdlg
.ptPaperSize
.x
= _c_10mm2size(pda
->dlga
, pda
->curdlg
.ptPaperSize
.x
);
2837 pda
->curdlg
.ptPaperSize
.y
= _c_10mm2size(pda
->dlga
, pda
->curdlg
.ptPaperSize
.y
);
2838 if (dm
->u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
){
2839 DWORD tmp
= pda
->curdlg
.ptPaperSize
.x
;
2840 pda
->curdlg
.ptPaperSize
.x
= pda
->curdlg
.ptPaperSize
.y
;
2841 pda
->curdlg
.ptPaperSize
.y
= tmp
;
2842 CheckRadioButton(hDlg
, rad1
, rad2
, rad2
);
2845 CheckRadioButton(hDlg
, rad1
, rad2
, rad1
);
2846 /* Changing paper preview */
2847 PRINTDLG_PS_ChangePaperPrev(pda
);
2848 /* Selecting paper in combo */
2849 count
= SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCOUNT
, 0, 0);
2850 if(count
!= CB_ERR
){
2851 for(i
=0; i
<count
; ++i
){
2852 if(SendDlgItemMessageA(hDlg
, cmb2
, CB_GETITEMDATA
, i
, 0) == dm
->u1
.s1
.dmPaperSize
) {
2853 SendDlgItemMessageA(hDlg
, cmb2
, CB_SETCURSEL
, i
, 0);
2859 GlobalUnlock(pda
->pdlg
.hDevMode
);
2863 GETVAL(id
, pda
->curdlg
.rtMargin
.left
);
2866 GETVAL(id
, pda
->curdlg
.rtMargin
.right
);
2869 GETVAL(id
, pda
->curdlg
.rtMargin
.top
);
2872 GETVAL(id
, pda
->curdlg
.rtMargin
.bottom
);
2875 InvalidateRect(GetDlgItem(hDlg
, rct1
), NULL
, TRUE
);
2881 PRINTDLG_PS_WMCommandW(
2882 HWND hDlg
, WPARAM wParam
, LPARAM lParam
, PageSetupDataW
*pda
2884 TRACE("loword (lparam) %d, wparam 0x%x, lparam %08lx\n",
2885 LOWORD(lParam
),wParam
,lParam
);
2886 switch (LOWORD(wParam
)) {
2888 if (!PRINTDLG_PS_UpdateDlgStructW(hDlg
, pda
))
2890 EndDialog(hDlg
, TRUE
);
2894 EndDialog(hDlg
, FALSE
);
2898 pda
->pdlg
.Flags
= 0;
2899 pda
->pdlg
.hwndOwner
= hDlg
;
2900 if (PrintDlgW(&(pda
->pdlg
)))
2901 PRINTDLG_PS_ChangePrinterW(hDlg
,pda
);
2909 /***********************************************************************
2910 * DefaultPagePaintHook
2911 * Default hook paint procedure that receives WM_PSD_* messages from the dialog box
2912 * whenever the sample page is redrawn.
2916 PRINTDLG_DefaultPagePaintHook(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, PageSetupDataA
*pda
)
2918 LPRECT lprc
= (LPRECT
) lParam
;
2919 HDC hdc
= (HDC
) wParam
;
2922 HFONT hfont
, holdfont
;
2924 TRACE("uMsg: WM_USER+%d\n",uMsg
-WM_USER
);
2925 /* Call user paint hook if enable */
2926 if (pda
->dlga
->Flags
& PSD_ENABLEPAGEPAINTHOOK
)
2927 if (pda
->dlga
->lpfnPagePaintHook(hwndDlg
, uMsg
, wParam
, lParam
))
2931 /* LPPAGESETUPDLG in lParam */
2932 case WM_PSD_PAGESETUPDLG
:
2933 /* Inform about the sample page rectangle */
2934 case WM_PSD_FULLPAGERECT
:
2935 /* Inform about the margin rectangle */
2936 case WM_PSD_MINMARGINRECT
:
2939 /* Draw dashed rectangle showing margins */
2940 case WM_PSD_MARGINRECT
:
2941 hpen
= CreatePen(PS_DASH
, 1, GetSysColor(COLOR_3DSHADOW
));
2942 holdpen
= SelectObject(hdc
, hpen
);
2943 Rectangle(hdc
, lprc
->left
, lprc
->top
, lprc
->right
, lprc
->bottom
);
2944 DeleteObject(SelectObject(hdc
, holdpen
));
2946 /* Draw the fake document */
2947 case WM_PSD_GREEKTEXTRECT
:
2948 /* select a nice scalable font, because we want the text really small */
2949 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, sizeof(lf
), &lf
, 0);
2950 lf
.lfHeight
= 6; /* value chosen based on visual effect */
2951 hfont
= CreateFontIndirectW(&lf
);
2952 holdfont
= SelectObject(hdc
, hfont
);
2954 /* if text not loaded, then do so now */
2955 if (wszFakeDocumentText
[0] == '\0')
2956 LoadStringW(COMDLG32_hInstance
,
2958 wszFakeDocumentText
,
2959 sizeof(wszFakeDocumentText
)/sizeof(wszFakeDocumentText
[0]));
2961 oldbkmode
= SetBkMode(hdc
, TRANSPARENT
);
2962 DrawTextW(hdc
, wszFakeDocumentText
, -1, lprc
, DT_TOP
|DT_LEFT
|DT_NOPREFIX
|DT_WORDBREAK
);
2963 SetBkMode(hdc
, oldbkmode
);
2965 DeleteObject(SelectObject(hdc
, holdfont
));
2968 /* Envelope stamp */
2969 case WM_PSD_ENVSTAMPRECT
:
2970 /* Return address */
2971 case WM_PSD_YAFULLPAGERECT
:
2972 FIXME("envelope/stamp is not implemented\n");
2975 FIXME("Unknown message %x\n",uMsg
);
2981 /***********************************************************************
2983 * The main paint procedure for the PageSetupDlg function.
2984 * The Page Setup dialog box includes an image of a sample page that shows how
2985 * the user's selections affect the appearance of the printed output.
2986 * The image consists of a rectangle that represents the selected paper
2987 * or envelope type, with a dotted-line rectangle representing
2988 * the current margins, and partial (Greek text) characters
2989 * to show how text looks on the printed page.
2991 * The following messages in the order sends to user hook procedure:
2992 * WM_PSD_PAGESETUPDLG Draw the contents of the sample page
2993 * WM_PSD_FULLPAGERECT Inform about the bounding rectangle
2994 * WM_PSD_MINMARGINRECT Inform about the margin rectangle (min margin?)
2995 * WM_PSD_MARGINRECT Draw the margin rectangle
2996 * WM_PSD_GREEKTEXTRECT Draw the Greek text inside the margin rectangle
2997 * If any of first three messages returns TRUE, painting done.
3000 * hWnd [in] Handle to the Page Setup dialog box
3001 * uMsg [in] Received message
3004 * WM_PSD_ENVSTAMPRECT Draw in the envelope-stamp rectangle (for envelopes only)
3005 * WM_PSD_YAFULLPAGERECT Draw the return address portion (for envelopes and other paper sizes)
3008 * FALSE if all done correctly
3013 static LRESULT CALLBACK
3014 PRINTDLG_PagePaintProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3017 RECT rcClient
, rcMargin
;
3020 HBRUSH hbrush
, holdbrush
;
3021 PageSetupDataA
*pda
;
3022 int papersize
=0, orientation
=0; /* FIXME: set this values for user paint hook */
3023 double scalx
, scaly
;
3024 #define CALLPAINTHOOK(msg,lprc) PRINTDLG_DefaultPagePaintHook( hWnd, msg, (WPARAM)hdc, (LPARAM)lprc, pda)
3026 if (uMsg
!= WM_PAINT
)
3027 return CallWindowProcA(lpfnStaticWndProc
, hWnd
, uMsg
, wParam
, lParam
);
3029 /* Processing WM_PAINT message */
3030 pda
= (PageSetupDataA
*)GetPropA(hWnd
, "__WINE_PAGESETUPDLGDATA");
3032 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3035 if (PRINTDLG_DefaultPagePaintHook(hWnd
, WM_PSD_PAGESETUPDLG
, MAKELONG(papersize
, orientation
), (LPARAM
)pda
->dlga
, pda
))
3038 hdc
= BeginPaint(hWnd
, &ps
);
3039 GetClientRect(hWnd
, &rcClient
);
3041 scalx
= rcClient
.right
/ (double)pda
->curdlg
.ptPaperSize
.x
;
3042 scaly
= rcClient
.bottom
/ (double)pda
->curdlg
.ptPaperSize
.y
;
3043 rcMargin
= rcClient
;
3045 rcMargin
.left
+= (LONG
)pda
->curdlg
.rtMargin
.left
* scalx
;
3046 rcMargin
.top
+= (LONG
)pda
->curdlg
.rtMargin
.top
* scalx
;
3047 rcMargin
.right
-= (LONG
)pda
->curdlg
.rtMargin
.right
* scaly
;
3048 rcMargin
.bottom
-= (LONG
)pda
->curdlg
.rtMargin
.bottom
* scaly
;
3050 /* if the space is too small then we make sure to not draw anything */
3051 rcMargin
.left
= min(rcMargin
.left
, rcMargin
.right
);
3052 rcMargin
.top
= min(rcMargin
.top
, rcMargin
.bottom
);
3054 if (!CALLPAINTHOOK(WM_PSD_FULLPAGERECT
, &rcClient
) &&
3055 !CALLPAINTHOOK(WM_PSD_MINMARGINRECT
, &rcMargin
) )
3057 /* fill background */
3058 hbrush
= GetSysColorBrush(COLOR_3DHIGHLIGHT
);
3059 FillRect(hdc
, &rcClient
, hbrush
);
3060 holdbrush
= SelectObject(hdc
, hbrush
);
3062 hpen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DSHADOW
));
3063 holdpen
= SelectObject(hdc
, hpen
);
3065 /* paint left edge */
3066 MoveToEx(hdc
, rcClient
.left
, rcClient
.top
, NULL
);
3067 LineTo(hdc
, rcClient
.left
, rcClient
.bottom
-1);
3069 /* paint top edge */
3070 MoveToEx(hdc
, rcClient
.left
, rcClient
.top
, NULL
);
3071 LineTo(hdc
, rcClient
.right
, rcClient
.top
);
3073 hpen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DDKSHADOW
));
3074 DeleteObject(SelectObject(hdc
, hpen
));
3076 /* paint right edge */
3077 MoveToEx(hdc
, rcClient
.right
-1, rcClient
.top
, NULL
);
3078 LineTo(hdc
, rcClient
.right
-1, rcClient
.bottom
);
3080 /* paint bottom edge */
3081 MoveToEx(hdc
, rcClient
.left
, rcClient
.bottom
-1, NULL
);
3082 LineTo(hdc
, rcClient
.right
, rcClient
.bottom
-1);
3084 DeleteObject(SelectObject(hdc
, holdpen
));
3085 DeleteObject(SelectObject(hdc
, holdbrush
));
3087 CALLPAINTHOOK(WM_PSD_MARGINRECT
, &rcMargin
);
3089 /* give text a bit of a space from the frame */
3092 rcMargin
.right
-= 2;
3093 rcMargin
.bottom
-= 2;
3095 /* if the space is too small then we make sure to not draw anything */
3096 rcMargin
.left
= min(rcMargin
.left
, rcMargin
.right
);
3097 rcMargin
.top
= min(rcMargin
.top
, rcMargin
.bottom
);
3099 CALLPAINTHOOK(WM_PSD_GREEKTEXTRECT
, &rcMargin
);
3102 EndPaint(hWnd
, &ps
);
3104 #undef CALLPAINTHOOK
3107 /***********************************************************************
3108 * PRINTDLG_PageDlgProcA
3109 * Message handler for PageSetupDlgA
3111 static INT_PTR CALLBACK
3112 PRINTDLG_PageDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3115 PageSetupDataA
*pda
;
3116 INT_PTR res
= FALSE
;
3119 if (uMsg
== WM_INITDIALOG
) { /*Init dialog*/
3120 pda
= (PageSetupDataA
*)lParam
;
3121 pda
->hDlg
= hDlg
; /* saving handle to main window to PageSetupDataA structure */
3122 memcpy(&pda
->curdlg
, pda
->dlga
, sizeof(pda
->curdlg
));
3124 hDrawWnd
= GetDlgItem(hDlg
, rct1
);
3125 TRACE("set property to %p\n", pda
);
3126 SetPropA(hDlg
, "__WINE_PAGESETUPDLGDATA", pda
);
3127 SetPropA(hDrawWnd
, "__WINE_PAGESETUPDLGDATA", pda
);
3128 GetWindowRect(hDrawWnd
, &pda
->rtDrawRect
); /* Calculating rect in client coordinates where paper draws */
3129 ScreenToClient(hDlg
, (LPPOINT
)&pda
->rtDrawRect
);
3130 ScreenToClient(hDlg
, (LPPOINT
)(&pda
->rtDrawRect
.right
));
3131 lpfnStaticWndProc
= (WNDPROC
)SetWindowLongPtrW(
3134 (ULONG_PTR
)PRINTDLG_PagePaintProc
);
3136 /* FIXME: Paint hook. Must it be at begin of initializtion or at end? */
3138 if (pda
->dlga
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
3139 if (!pda
->dlga
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,(LPARAM
)pda
->dlga
))
3140 FIXME("Setup page hook failed?\n");
3143 /* if printer button disabled */
3144 if (pda
->dlga
->Flags
& PSD_DISABLEPRINTER
)
3145 EnableWindow(GetDlgItem(hDlg
, psh3
), FALSE
);
3146 /* if margin edit boxes disabled */
3147 if (pda
->dlga
->Flags
& PSD_DISABLEMARGINS
) {
3148 EnableWindow(GetDlgItem(hDlg
, edt4
), FALSE
);
3149 EnableWindow(GetDlgItem(hDlg
, edt5
), FALSE
);
3150 EnableWindow(GetDlgItem(hDlg
, edt6
), FALSE
);
3151 EnableWindow(GetDlgItem(hDlg
, edt7
), FALSE
);
3153 /* Set orientation radiobutton properly */
3154 dm
= GlobalLock(pda
->dlga
->hDevMode
);
3155 if (dm
->u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
)
3156 CheckRadioButton(hDlg
, rad1
, rad2
, rad2
);
3157 else /* this is default if papersize is not set */
3158 CheckRadioButton(hDlg
, rad1
, rad2
, rad1
);
3159 GlobalUnlock(pda
->dlga
->hDevMode
);
3161 /* if orientation disabled */
3162 if (pda
->dlga
->Flags
& PSD_DISABLEORIENTATION
) {
3163 EnableWindow(GetDlgItem(hDlg
,rad1
),FALSE
);
3164 EnableWindow(GetDlgItem(hDlg
,rad2
),FALSE
);
3166 /* We fill them out enabled or not */
3167 if (pda
->dlga
->Flags
& PSD_MARGINS
) {
3169 _c_size2strA(pda
,pda
->dlga
->rtMargin
.left
,str
);
3170 SetDlgItemTextA(hDlg
,edt4
,str
);
3171 _c_size2strA(pda
,pda
->dlga
->rtMargin
.top
,str
);
3172 SetDlgItemTextA(hDlg
,edt5
,str
);
3173 _c_size2strA(pda
,pda
->dlga
->rtMargin
.right
,str
);
3174 SetDlgItemTextA(hDlg
,edt6
,str
);
3175 _c_size2strA(pda
,pda
->dlga
->rtMargin
.bottom
,str
);
3176 SetDlgItemTextA(hDlg
,edt7
,str
);
3178 /* default is 1 inch */
3179 DWORD size
= _c_inch2size(pda
->dlga
,1000);
3181 _c_size2strA(pda
,size
,str
);
3182 SetDlgItemTextA(hDlg
,edt4
,str
);
3183 SetDlgItemTextA(hDlg
,edt5
,str
);
3184 SetDlgItemTextA(hDlg
,edt6
,str
);
3185 SetDlgItemTextA(hDlg
,edt7
,str
);
3186 pda
->curdlg
.rtMargin
.left
= size
;
3187 pda
->curdlg
.rtMargin
.top
= size
;
3188 pda
->curdlg
.rtMargin
.right
= size
;
3189 pda
->curdlg
.rtMargin
.bottom
= size
;
3191 /* if paper disabled */
3192 if (pda
->dlga
->Flags
& PSD_DISABLEPAPER
) {
3193 EnableWindow(GetDlgItem(hDlg
,cmb2
),FALSE
);
3194 EnableWindow(GetDlgItem(hDlg
,cmb3
),FALSE
);
3196 /* filling combos: printer, paper, source. selecting current printer (from DEVMODEA) */
3197 PRINTDLG_PS_ChangePrinterA(hDlg
, pda
);
3198 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
3200 dm
->dmDefaultSource
= 15; /*FIXME: Automatic select. Does it always 15 at start? */
3201 PRINTDLG_PaperSizeA(&(pda
->pdlg
), dm
->u1
.s1
.dmPaperSize
, &pda
->curdlg
.ptPaperSize
);
3202 GlobalUnlock(pda
->pdlg
.hDevMode
);
3203 pda
->curdlg
.ptPaperSize
.x
= _c_10mm2size(pda
->dlga
, pda
->curdlg
.ptPaperSize
.x
);
3204 pda
->curdlg
.ptPaperSize
.y
= _c_10mm2size(pda
->dlga
, pda
->curdlg
.ptPaperSize
.y
);
3205 if (IsDlgButtonChecked(hDlg
, rad2
) == BST_CHECKED
) { /* Landscape orientation */
3206 DWORD tmp
= pda
->curdlg
.ptPaperSize
.y
;
3207 pda
->curdlg
.ptPaperSize
.y
= pda
->curdlg
.ptPaperSize
.x
;
3208 pda
->curdlg
.ptPaperSize
.x
= tmp
;
3211 WARN("GlobalLock(pda->pdlg.hDevMode) fail? hDevMode=%p\n", pda
->pdlg
.hDevMode
);
3212 /* Drawing paper prev */
3213 PRINTDLG_PS_ChangePaperPrev(pda
);
3216 pda
= (PageSetupDataA
*)GetPropA(hDlg
,"__WINE_PAGESETUPDLGDATA");
3218 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3221 if (pda
->dlga
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
3222 res
= pda
->dlga
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,lParam
);
3223 if (res
) return res
;
3228 return PRINTDLG_PS_WMCommandA(hDlg
, wParam
, lParam
, pda
);
3233 static INT_PTR CALLBACK
3234 PageDlgProcW(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3236 static const WCHAR __WINE_PAGESETUPDLGDATA
[] =
3237 { '_', '_', 'W', 'I', 'N', 'E', '_', 'P', 'A', 'G', 'E',
3238 'S', 'E', 'T', 'U', 'P', 'D', 'L', 'G', 'D', 'A', 'T', 'A', 0 };
3239 PageSetupDataW
*pda
;
3242 if (uMsg
==WM_INITDIALOG
) {
3244 pda
= (PageSetupDataW
*)lParam
;
3245 SetPropW(hDlg
, __WINE_PAGESETUPDLGDATA
, pda
);
3246 if (pda
->dlga
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
3247 res
= pda
->dlga
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,(LPARAM
)pda
->dlga
);
3249 FIXME("Setup page hook failed?\n");
3254 if (pda
->dlga
->Flags
& PSD_ENABLEPAGEPAINTHOOK
) {
3255 FIXME("PagePaintHook not yet implemented!\n");
3257 if (pda
->dlga
->Flags
& PSD_DISABLEPRINTER
)
3258 EnableWindow(GetDlgItem(hDlg
, psh3
), FALSE
);
3259 if (pda
->dlga
->Flags
& PSD_DISABLEMARGINS
) {
3260 EnableWindow(GetDlgItem(hDlg
, edt4
), FALSE
);
3261 EnableWindow(GetDlgItem(hDlg
, edt5
), FALSE
);
3262 EnableWindow(GetDlgItem(hDlg
, edt6
), FALSE
);
3263 EnableWindow(GetDlgItem(hDlg
, edt7
), FALSE
);
3265 /* width larger as height -> landscape */
3266 if (pda
->dlga
->ptPaperSize
.x
> pda
->dlga
->ptPaperSize
.y
)
3267 CheckRadioButton(hDlg
, rad1
, rad2
, rad2
);
3268 else /* this is default if papersize is not set */
3269 CheckRadioButton(hDlg
, rad1
, rad2
, rad1
);
3270 if (pda
->dlga
->Flags
& PSD_DISABLEORIENTATION
) {
3271 EnableWindow(GetDlgItem(hDlg
,rad1
),FALSE
);
3272 EnableWindow(GetDlgItem(hDlg
,rad2
),FALSE
);
3274 /* We fill them out enabled or not */
3275 if (pda
->dlga
->Flags
& PSD_MARGINS
) {
3277 _c_size2strW(pda
,pda
->dlga
->rtMargin
.left
,str
);
3278 SetDlgItemTextW(hDlg
,edt4
,str
);
3279 _c_size2strW(pda
,pda
->dlga
->rtMargin
.top
,str
);
3280 SetDlgItemTextW(hDlg
,edt5
,str
);
3281 _c_size2strW(pda
,pda
->dlga
->rtMargin
.right
,str
);
3282 SetDlgItemTextW(hDlg
,edt6
,str
);
3283 _c_size2strW(pda
,pda
->dlga
->rtMargin
.bottom
,str
);
3284 SetDlgItemTextW(hDlg
,edt7
,str
);
3286 /* default is 1 inch */
3287 DWORD size
= _c_inch2size((LPPAGESETUPDLGA
)pda
->dlga
,1000);
3289 _c_size2strW(pda
,size
,str
);
3290 SetDlgItemTextW(hDlg
,edt4
,str
);
3291 SetDlgItemTextW(hDlg
,edt5
,str
);
3292 SetDlgItemTextW(hDlg
,edt6
,str
);
3293 SetDlgItemTextW(hDlg
,edt7
,str
);
3295 PRINTDLG_PS_ChangePrinterW(hDlg
,pda
);
3296 if (pda
->dlga
->Flags
& PSD_DISABLEPAPER
) {
3297 EnableWindow(GetDlgItem(hDlg
,cmb2
),FALSE
);
3298 EnableWindow(GetDlgItem(hDlg
,cmb3
),FALSE
);
3303 pda
= (PageSetupDataW
*)GetPropW(hDlg
, __WINE_PAGESETUPDLGDATA
);
3305 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3308 if (pda
->dlga
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
3309 res
= pda
->dlga
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,lParam
);
3310 if (res
) return res
;
3315 return PRINTDLG_PS_WMCommandW(hDlg
, wParam
, lParam
, pda
);
3320 /***********************************************************************
3321 * PageSetupDlgA (COMDLG32.@)
3323 * Displays the the PAGE SETUP dialog box, which enables the user to specify
3324 * specific properties of a printed page such as
3325 * size, source, orientation and the width of the page margins.
3328 * setupdlg [IO] PAGESETUPDLGA struct
3331 * TRUE if the user pressed the OK button
3332 * FALSE if the user cancelled the window or an error occurred
3335 * The values of hDevMode and hDevNames are filled on output and can be
3336 * changed in PAGESETUPDLG when they are passed in PageSetupDlg.
3340 BOOL WINAPI
PageSetupDlgA(LPPAGESETUPDLGA setupdlg
) {
3344 PageSetupDataA
*pda
;
3348 if(TRACE_ON(commdlg
)) {
3349 char flagstr
[1000] = "";
3350 const struct pd_flags
*pflag
= psd_flags
;
3351 for( ; pflag
->name
; pflag
++) {
3352 if(setupdlg
->Flags
& pflag
->flag
) {
3353 strcat(flagstr
, pflag
->name
);
3354 strcat(flagstr
, "|");
3357 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3358 "hinst %p, flags %08x (%s)\n",
3359 setupdlg
, setupdlg
->hwndOwner
, setupdlg
->hDevMode
,
3360 setupdlg
->hDevNames
,
3361 setupdlg
->hInstance
, setupdlg
->Flags
, flagstr
);
3363 /* Checking setupdlg structure */
3364 if (setupdlg
== NULL
) {
3365 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
3368 if(setupdlg
->lStructSize
!= sizeof(PAGESETUPDLGA
)) {
3369 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
3372 if ((setupdlg
->Flags
& PSD_ENABLEPAGEPAINTHOOK
) &&
3373 (setupdlg
->lpfnPagePaintHook
== NULL
)) {
3374 COMDLG32_SetCommDlgExtendedError(CDERR_NOHOOK
);
3378 /* Initialize default printer struct. If no printer device info is specified
3379 retrieve the default printer data. */
3380 memset(&pdlg
,0,sizeof(pdlg
));
3381 pdlg
.lStructSize
= sizeof(pdlg
);
3382 if (setupdlg
->hDevMode
&& setupdlg
->hDevNames
) {
3383 pdlg
.hDevMode
= setupdlg
->hDevMode
;
3384 pdlg
.hDevNames
= setupdlg
->hDevNames
;
3386 pdlg
.Flags
= PD_RETURNDEFAULT
;
3387 bRet
= PrintDlgA(&pdlg
);
3389 if (!(setupdlg
->Flags
& PSD_NOWARNING
)) {
3391 LoadStringA(COMDLG32_hInstance
, PD32_NO_DEFAULT_PRINTER
, errstr
, 255);
3392 MessageBoxA(setupdlg
->hwndOwner
, errstr
, 0, MB_OK
| MB_ICONERROR
);
3398 /* short cut exit, just return default values */
3399 if (setupdlg
->Flags
& PSD_RETURNDEFAULT
) {
3402 dm
= GlobalLock(pdlg
.hDevMode
);
3403 PRINTDLG_PaperSizeA(&pdlg
, dm
->u1
.s1
.dmPaperSize
, &setupdlg
->ptPaperSize
);
3404 GlobalUnlock(pdlg
.hDevMode
);
3405 setupdlg
->ptPaperSize
.x
=_c_10mm2size(setupdlg
,setupdlg
->ptPaperSize
.x
);
3406 setupdlg
->ptPaperSize
.y
=_c_10mm2size(setupdlg
,setupdlg
->ptPaperSize
.y
);
3410 /* get dialog template */
3411 hDlgTmpl
= PRINTDLG_GetPGSTemplateA(setupdlg
);
3413 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
3416 ptr
= LockResource( hDlgTmpl
);
3418 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
3422 pda
= HeapAlloc(GetProcessHeap(),0,sizeof(*pda
));
3423 pda
->dlga
= setupdlg
;
3424 memcpy(&pda
->pdlg
,&pdlg
,sizeof(pdlg
));
3426 bRet
= (0<DialogBoxIndirectParamA(
3427 setupdlg
->hInstance
,
3429 setupdlg
->hwndOwner
,
3430 PRINTDLG_PageDlgProcA
,
3434 HeapFree(GetProcessHeap(),0,pda
);
3437 /***********************************************************************
3438 * PageSetupDlgW (COMDLG32.@)
3440 * See PageSetupDlgA.
3442 BOOL WINAPI
PageSetupDlgW(LPPAGESETUPDLGW setupdlg
) {
3446 PageSetupDataW
*pdw
;
3449 FIXME("Unicode implementation is not done yet\n");
3450 if(TRACE_ON(commdlg
)) {
3451 char flagstr
[1000] = "";
3452 const struct pd_flags
*pflag
= psd_flags
;
3453 for( ; pflag
->name
; pflag
++) {
3454 if(setupdlg
->Flags
& pflag
->flag
) {
3455 strcat(flagstr
, pflag
->name
);
3456 strcat(flagstr
, "|");
3459 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3460 "hinst %p, flags %08x (%s)\n",
3461 setupdlg
, setupdlg
->hwndOwner
, setupdlg
->hDevMode
,
3462 setupdlg
->hDevNames
,
3463 setupdlg
->hInstance
, setupdlg
->Flags
, flagstr
);
3466 /* Initialize default printer struct. If no printer device info is specified
3467 retrieve the default printer data. */
3468 memset(&pdlg
,0,sizeof(pdlg
));
3469 pdlg
.lStructSize
= sizeof(pdlg
);
3470 if (setupdlg
->hDevMode
&& setupdlg
->hDevNames
) {
3471 pdlg
.hDevMode
= setupdlg
->hDevMode
;
3472 pdlg
.hDevNames
= setupdlg
->hDevNames
;
3474 pdlg
.Flags
= PD_RETURNDEFAULT
;
3475 bRet
= PrintDlgW(&pdlg
);
3477 if (!(setupdlg
->Flags
& PSD_NOWARNING
)) {
3479 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEFAULT_PRINTER
, errstr
, 255);
3480 MessageBoxW(setupdlg
->hwndOwner
, errstr
, 0, MB_OK
| MB_ICONERROR
);
3486 /* short cut exit, just return default values */
3487 if (setupdlg
->Flags
& PSD_RETURNDEFAULT
) {
3488 static const WCHAR a4
[] = {'A','4',0};
3489 setupdlg
->hDevMode
= pdlg
.hDevMode
;
3490 setupdlg
->hDevNames
= pdlg
.hDevNames
;
3491 /* FIXME: Just return "A4" for now. */
3492 PRINTDLG_PaperSizeW(&pdlg
,a4
,&setupdlg
->ptPaperSize
);
3493 setupdlg
->ptPaperSize
.x
=_c_10mm2size((LPPAGESETUPDLGA
)setupdlg
,setupdlg
->ptPaperSize
.x
);
3494 setupdlg
->ptPaperSize
.y
=_c_10mm2size((LPPAGESETUPDLGA
)setupdlg
,setupdlg
->ptPaperSize
.y
);
3497 hDlgTmpl
= PRINTDLG_GetPGSTemplateW(setupdlg
);
3499 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
3502 ptr
= LockResource( hDlgTmpl
);
3504 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
3507 pdw
= HeapAlloc(GetProcessHeap(),0,sizeof(*pdw
));
3508 pdw
->dlga
= setupdlg
;
3509 memcpy(&pdw
->pdlg
,&pdlg
,sizeof(pdlg
));
3511 bRet
= (0<DialogBoxIndirectParamW(
3512 setupdlg
->hInstance
,
3514 setupdlg
->hwndOwner
,
3521 /***********************************************************************
3522 * PrintDlgExA (COMDLG32.@)
3529 HRESULT WINAPI
PrintDlgExA(LPPRINTDLGEXA lpPrintDlgExA
)
3535 /***********************************************************************
3536 * PrintDlgExW (COMDLG32.@)
3538 * Display the the PRINT dialog box, which enables the user to specify
3539 * specific properties of the print job. The property sheet can also have
3540 * additional application-specific and driver-specific property pages.
3543 * lppd [IO] ptr to PRINTDLGEX struct
3547 * Failure: One of the following COM error codes:
3548 * E_OUTOFMEMORY Insufficient memory.
3549 * E_INVALIDARG One or more arguments are invalid.
3550 * E_POINTER Invalid pointer.
3551 * E_HANDLE Invalid handle.
3552 * E_FAIL Unspecified error.
3557 HRESULT WINAPI
PrintDlgExW(LPPRINTDLGEXW lpPrintDlgExW
)