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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 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 lppd
->Flags
|= PD_PRINTTOFILE
;
329 pi
->pPortName
= "FILE:";
332 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
) { /* Collate */
333 FIXME("Collate lppd not yet implemented as output\n");
336 /* set PD_Collate and nCopies */
337 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
338 /* The application doesn't support multiple copies or collate...
340 lppd
->Flags
&= ~PD_COLLATE
;
342 /* if the printer driver supports it... store info there
343 * otherwise no collate & multiple copies !
345 if (lpdm
->dmFields
& DM_COLLATE
)
347 (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
);
348 if (lpdm
->dmFields
& DM_COPIES
)
349 lpdm
->dmCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
351 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
352 lppd
->Flags
|= PD_COLLATE
;
354 lppd
->Flags
&= ~PD_COLLATE
;
355 lppd
->nCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
361 static BOOL
PRINTDLG_UpdatePrintDlgW(HWND hDlg
,
362 PRINT_PTRW
* PrintStructures
)
364 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
365 PDEVMODEW lpdm
= PrintStructures
->lpDevMode
;
366 LPPRINTER_INFO_2W pi
= PrintStructures
->lpPrinterInfo
;
370 FIXME("No lpdm ptr?\n");
375 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
376 /* check whether nFromPage and nToPage are within range defined by
377 * nMinPage and nMaxPage
379 if (IsDlgButtonChecked(hDlg
, rad3
) == BST_CHECKED
) { /* Pages */
382 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
383 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
384 if (nFromPage
< lppd
->nMinPage
|| nFromPage
> lppd
->nMaxPage
||
385 nToPage
< lppd
->nMinPage
|| nToPage
> lppd
->nMaxPage
) {
386 WCHAR resourcestr
[256];
387 WCHAR resultstr
[256];
388 LoadStringW(COMDLG32_hInstance
, PD32_INVALID_PAGE_RANGE
,
390 wsprintfW(resultstr
,resourcestr
, lppd
->nMinPage
, lppd
->nMaxPage
);
391 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
,
393 MessageBoxW(hDlg
, resultstr
, resourcestr
,
394 MB_OK
| MB_ICONWARNING
);
397 lppd
->nFromPage
= nFromPage
;
398 lppd
->nToPage
= nToPage
;
401 if (IsDlgButtonChecked(hDlg
, chx1
) == BST_CHECKED
) {/* Print to file */
402 static WCHAR file
[] = {'F','I','L','E',':',0};
403 lppd
->Flags
|= PD_PRINTTOFILE
;
404 pi
->pPortName
= file
;
407 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
) { /* Collate */
408 FIXME("Collate lppd not yet implemented as output\n");
411 /* set PD_Collate and nCopies */
412 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
413 /* The application doesn't support multiple copies or collate...
415 lppd
->Flags
&= ~PD_COLLATE
;
417 /* if the printer driver supports it... store info there
418 * otherwise no collate & multiple copies !
420 if (lpdm
->dmFields
& DM_COLLATE
)
422 (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
);
423 if (lpdm
->dmFields
& DM_COPIES
)
424 lpdm
->dmCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
426 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
427 lppd
->Flags
|= PD_COLLATE
;
429 lppd
->Flags
&= ~PD_COLLATE
;
430 lppd
->nCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
436 static BOOL
PRINTDLG_PaperSizeA(
437 PRINTDLGA
*pdlga
,const WORD PaperSize
,LPPOINT size
441 LPSTR devname
,portname
;
445 POINT
*points
= NULL
;
448 dn
= GlobalLock(pdlga
->hDevNames
);
449 dm
= GlobalLock(pdlga
->hDevMode
);
450 devname
= ((char*)dn
)+dn
->wDeviceOffset
;
451 portname
= ((char*)dn
)+dn
->wOutputOffset
;
454 NrOfEntries
= DeviceCapabilitiesA(devname
,portname
,DC_PAPERNAMES
,NULL
,dm
);
456 FIXME("No papernames found for %s/%s\n",devname
,portname
);
459 if (NrOfEntries
== -1) {
460 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
464 Words
= HeapAlloc(GetProcessHeap(),0,NrOfEntries
*sizeof(WORD
));
465 if (NrOfEntries
!= (ret
=DeviceCapabilitiesA(devname
,portname
,DC_PAPERS
,(LPSTR
)Words
,dm
))) {
466 FIXME("Number of returned vals %d is not %d\n",NrOfEntries
,ret
);
469 for (i
=0;i
<NrOfEntries
;i
++)
470 if (Words
[i
] == PaperSize
)
472 HeapFree(GetProcessHeap(),0,Words
);
473 if (i
== NrOfEntries
) {
474 FIXME("Papersize %d not found in list?\n",PaperSize
);
477 points
= HeapAlloc(GetProcessHeap(),0,sizeof(points
[0])*NrOfEntries
);
478 if (NrOfEntries
!=(ret
=DeviceCapabilitiesA(devname
,portname
,DC_PAPERSIZE
,(LPSTR
)points
,dm
))) {
479 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries
,ret
);
482 /* this is _10ths_ of a millimeter */
487 GlobalUnlock(pdlga
->hDevNames
);
488 GlobalUnlock(pdlga
->hDevMode
);
489 HeapFree(GetProcessHeap(),0,Words
);
490 HeapFree(GetProcessHeap(),0,points
);
494 static BOOL
PRINTDLG_PaperSizeW(
495 PRINTDLGW
*pdlga
,const WCHAR
*PaperSize
,LPPOINT size
499 LPWSTR devname
,portname
;
503 POINT
*points
= NULL
;
506 dn
= GlobalLock(pdlga
->hDevNames
);
507 dm
= GlobalLock(pdlga
->hDevMode
);
508 devname
= ((WCHAR
*)dn
)+dn
->wDeviceOffset
;
509 portname
= ((WCHAR
*)dn
)+dn
->wOutputOffset
;
512 NrOfEntries
= DeviceCapabilitiesW(devname
,portname
,DC_PAPERNAMES
,NULL
,dm
);
514 FIXME("No papernames found for %s/%s\n",debugstr_w(devname
),debugstr_w(portname
));
517 if (NrOfEntries
== -1) {
518 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
522 Names
= HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*NrOfEntries
*64);
523 if (NrOfEntries
!= (ret
=DeviceCapabilitiesW(devname
,portname
,DC_PAPERNAMES
,Names
,dm
))) {
524 FIXME("Number of returned vals %d is not %d\n",NrOfEntries
,ret
);
527 for (i
=0;i
<NrOfEntries
;i
++)
528 if (!lstrcmpW(PaperSize
,Names
+(64*i
)))
530 HeapFree(GetProcessHeap(),0,Names
);
531 if (i
==NrOfEntries
) {
532 FIXME("Papersize %s not found in list?\n",debugstr_w(PaperSize
));
535 points
= HeapAlloc(GetProcessHeap(),0,sizeof(points
[0])*NrOfEntries
);
536 if (NrOfEntries
!=(ret
=DeviceCapabilitiesW(devname
,portname
,DC_PAPERSIZE
,(LPWSTR
)points
,dm
))) {
537 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries
,ret
);
540 /* this is _10ths_ of a millimeter */
545 GlobalUnlock(pdlga
->hDevNames
);
546 GlobalUnlock(pdlga
->hDevMode
);
547 HeapFree(GetProcessHeap(),0,Names
);
548 HeapFree(GetProcessHeap(),0,points
);
553 /************************************************************************
554 * PRINTDLG_SetUpPaperComboBox
556 * Initialize either the papersize or inputslot combos of the Printer Setup
557 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
558 * We also try to re-select the old selection.
560 static BOOL
PRINTDLG_SetUpPaperComboBoxA(HWND hDlg
,
573 int fwCapability_Names
;
574 int fwCapability_Words
;
576 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName
,PortName
,nIDComboBox
);
578 /* query the dialog box for the current selected value */
579 Sel
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETCURSEL
, 0, 0);
581 /* we enter here only if a different printer is selected after
582 * the Print Setup dialog is opened. The current settings are
583 * stored into the newly selected printer.
585 oldWord
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
,
588 if (nIDComboBox
== cmb2
)
589 dm
->u1
.s1
.dmPaperSize
= oldWord
;
591 dm
->dmDefaultSource
= oldWord
;
595 /* we enter here only when the Print setup dialog is initially
596 * opened. In this case the settings are restored from when
597 * the dialog was last closed.
600 if (nIDComboBox
== cmb2
)
601 oldWord
= dm
->u1
.s1
.dmPaperSize
;
603 oldWord
= dm
->dmDefaultSource
;
607 if (nIDComboBox
== cmb2
) {
609 fwCapability_Names
= DC_PAPERNAMES
;
610 fwCapability_Words
= DC_PAPERS
;
614 fwCapability_Names
= DC_BINNAMES
;
615 fwCapability_Words
= DC_BINS
;
618 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
619 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
621 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
622 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
623 fwCapability_Names
, NULL
, dm
);
624 if (NrOfEntries
== 0)
625 WARN("no Name Entries found!\n");
626 else if (NrOfEntries
< 0)
629 if(DeviceCapabilitiesA(PrinterName
, PortName
, fwCapability_Words
, NULL
, dm
)
631 ERR("Number of caps is different\n");
635 Names
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(char)*NamesSize
);
636 Words
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WORD
));
637 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
638 fwCapability_Names
, Names
, dm
);
639 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
640 fwCapability_Words
, (LPSTR
)Words
, dm
);
642 /* reset any current content in the combobox */
643 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_RESETCONTENT
, 0, 0);
645 /* store new content */
646 for (i
= 0; i
< NrOfEntries
; i
++) {
647 DWORD pos
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_ADDSTRING
, 0,
648 (LPARAM
)(&Names
[i
*NamesSize
]) );
649 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_SETITEMDATA
, pos
,
653 /* Look for old selection - can't do this is previous loop since
654 item order will change as more items are added */
656 for (i
= 0; i
< NrOfEntries
; i
++) {
657 if(SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) ==
663 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_SETCURSEL
, Sel
, 0);
665 HeapFree(GetProcessHeap(),0,Words
);
666 HeapFree(GetProcessHeap(),0,Names
);
670 static BOOL
PRINTDLG_SetUpPaperComboBoxW(HWND hDlg
,
683 int fwCapability_Names
;
684 int fwCapability_Words
;
686 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName
),debugstr_w(PortName
),nIDComboBox
);
688 /* query the dialog box for the current selected value */
689 Sel
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETCURSEL
, 0, 0);
691 /* we enter here only if a different printer is selected after
692 * the Print Setup dialog is opened. The current settings are
693 * stored into the newly selected printer.
695 oldWord
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETITEMDATA
,
698 if (nIDComboBox
== cmb2
)
699 dm
->u1
.s1
.dmPaperSize
= oldWord
;
701 dm
->dmDefaultSource
= oldWord
;
705 /* we enter here only when the Print setup dialog is initially
706 * opened. In this case the settings are restored from when
707 * the dialog was last closed.
710 if (nIDComboBox
== cmb2
)
711 oldWord
= dm
->u1
.s1
.dmPaperSize
;
713 oldWord
= dm
->dmDefaultSource
;
717 if (nIDComboBox
== cmb2
) {
719 fwCapability_Names
= DC_PAPERNAMES
;
720 fwCapability_Words
= DC_PAPERS
;
724 fwCapability_Names
= DC_BINNAMES
;
725 fwCapability_Words
= DC_BINS
;
728 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
729 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
731 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
732 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
733 fwCapability_Names
, NULL
, dm
);
734 if (NrOfEntries
== 0)
735 WARN("no Name Entries found!\n");
736 else if (NrOfEntries
< 0)
739 if(DeviceCapabilitiesW(PrinterName
, PortName
, fwCapability_Words
, NULL
, dm
)
741 ERR("Number of caps is different\n");
745 Names
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WCHAR
)*NamesSize
);
746 Words
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WORD
));
747 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
748 fwCapability_Names
, Names
, dm
);
749 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
750 fwCapability_Words
, (LPWSTR
)Words
, dm
);
752 /* reset any current content in the combobox */
753 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_RESETCONTENT
, 0, 0);
755 /* store new content */
756 for (i
= 0; i
< NrOfEntries
; i
++) {
757 DWORD pos
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_ADDSTRING
, 0,
758 (LPARAM
)(&Names
[i
*NamesSize
]) );
759 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_SETITEMDATA
, pos
,
763 /* Look for old selection - can't do this is previous loop since
764 item order will change as more items are added */
766 for (i
= 0; i
< NrOfEntries
; i
++) {
767 if(SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) ==
773 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_SETCURSEL
, Sel
, 0);
775 HeapFree(GetProcessHeap(),0,Words
);
776 HeapFree(GetProcessHeap(),0,Names
);
781 /***********************************************************************
782 * PRINTDLG_UpdatePrinterInfoTexts [internal]
784 static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg
, LPPRINTER_INFO_2A pi
)
787 char ResourceString
[256];
793 /* add all status messages */
794 for (i
= 0; i
< 25; i
++) {
795 if (pi
->Status
& (1<<i
)) {
796 LoadStringA(COMDLG32_hInstance
, PD32_PRINTER_STATUS_PAUSED
+i
,
797 ResourceString
, 255);
798 strcat(StatusMsg
,ResourceString
);
802 /* FIXME: status==ready must only be appended if really so.
803 but how to detect? */
804 LoadStringA(COMDLG32_hInstance
, PD32_PRINTER_STATUS_READY
,
805 ResourceString
, 255);
806 strcat(StatusMsg
,ResourceString
);
807 SetDlgItemTextA(hDlg
, stc12
, StatusMsg
);
809 /* set all other printer info texts */
810 SetDlgItemTextA(hDlg
, stc11
, pi
->pDriverName
);
812 if (pi
->pLocation
!= NULL
&& pi
->pLocation
[0] != '\0')
813 SetDlgItemTextA(hDlg
, stc14
, pi
->pLocation
);
815 SetDlgItemTextA(hDlg
, stc14
, pi
->pPortName
);
816 SetDlgItemTextA(hDlg
, stc13
, pi
->pComment
? pi
->pComment
: "");
820 static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg
, LPPRINTER_INFO_2W pi
)
822 WCHAR StatusMsg
[256];
823 WCHAR ResourceString
[256];
824 static const WCHAR emptyW
[] = {0};
830 /* add all status messages */
831 for (i
= 0; i
< 25; i
++) {
832 if (pi
->Status
& (1<<i
)) {
833 LoadStringW(COMDLG32_hInstance
, PD32_PRINTER_STATUS_PAUSED
+i
,
834 ResourceString
, 255);
835 lstrcatW(StatusMsg
,ResourceString
);
839 /* FIXME: status==ready must only be appended if really so.
840 but how to detect? */
841 LoadStringW(COMDLG32_hInstance
, PD32_PRINTER_STATUS_READY
,
842 ResourceString
, 255);
843 lstrcatW(StatusMsg
,ResourceString
);
844 SetDlgItemTextW(hDlg
, stc12
, StatusMsg
);
846 /* set all other printer info texts */
847 SetDlgItemTextW(hDlg
, stc11
, pi
->pDriverName
);
848 if (pi
->pLocation
!= NULL
&& pi
->pLocation
[0] != '\0')
849 SetDlgItemTextW(hDlg
, stc14
, pi
->pLocation
);
851 SetDlgItemTextW(hDlg
, stc14
, pi
->pPortName
);
852 SetDlgItemTextW(hDlg
, stc13
, pi
->pComment
? pi
->pComment
: emptyW
);
856 /*******************************************************************
858 * PRINTDLG_ChangePrinter
861 BOOL
PRINTDLG_ChangePrinterA(HWND hDlg
, char *name
,
862 PRINT_PTRA
*PrintStructures
)
864 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
865 LPDEVMODEA lpdm
= NULL
;
870 HeapFree(GetProcessHeap(),0, PrintStructures
->lpPrinterInfo
);
871 HeapFree(GetProcessHeap(),0, PrintStructures
->lpDriverInfo
);
872 if(!OpenPrinterA(name
, &hprn
, NULL
)) {
873 ERR("Can't open printer %s\n", name
);
876 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
877 PrintStructures
->lpPrinterInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
878 GetPrinterA(hprn
, 2, (LPBYTE
)PrintStructures
->lpPrinterInfo
, needed
,
880 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
881 PrintStructures
->lpDriverInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
882 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)PrintStructures
->lpDriverInfo
,
884 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures
->lpPrinterInfo
->pPrinterName
);
889 PRINTDLG_UpdatePrinterInfoTextsA(hDlg
, PrintStructures
->lpPrinterInfo
);
891 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
892 PrintStructures
->lpDevMode
= NULL
;
894 dmSize
= DocumentPropertiesA(0, 0, name
, NULL
, NULL
, 0);
896 ERR("DocumentProperties fails on %s\n", debugstr_a(name
));
899 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(), 0, dmSize
);
900 dmSize
= DocumentPropertiesA(0, 0, name
, PrintStructures
->lpDevMode
, NULL
,
902 if(lppd
->hDevMode
&& (lpdm
= GlobalLock(lppd
->hDevMode
)) &&
903 !lstrcmpA( (LPSTR
) lpdm
->dmDeviceName
,
904 (LPSTR
) PrintStructures
->lpDevMode
->dmDeviceName
)) {
905 /* Supplied devicemode matches current printer so try to use it */
906 DocumentPropertiesA(0, 0, name
, PrintStructures
->lpDevMode
, lpdm
,
907 DM_OUT_BUFFER
| DM_IN_BUFFER
);
910 GlobalUnlock(lppd
->hDevMode
);
912 lpdm
= PrintStructures
->lpDevMode
; /* use this as a shortcut */
914 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
915 /* Print range (All/Range/Selection) */
916 SetDlgItemInt(hDlg
, edt1
, lppd
->nFromPage
, FALSE
);
917 SetDlgItemInt(hDlg
, edt2
, lppd
->nToPage
, FALSE
);
918 CheckRadioButton(hDlg
, rad1
, rad3
, rad1
); /* default */
919 if (lppd
->Flags
& PD_NOSELECTION
)
920 EnableWindow(GetDlgItem(hDlg
, rad2
), FALSE
);
922 if (lppd
->Flags
& PD_SELECTION
)
923 CheckRadioButton(hDlg
, rad1
, rad3
, rad2
);
924 if (lppd
->Flags
& PD_NOPAGENUMS
) {
925 EnableWindow(GetDlgItem(hDlg
, rad3
), FALSE
);
926 EnableWindow(GetDlgItem(hDlg
, stc2
),FALSE
);
927 EnableWindow(GetDlgItem(hDlg
, edt1
), FALSE
);
928 EnableWindow(GetDlgItem(hDlg
, stc3
),FALSE
);
929 EnableWindow(GetDlgItem(hDlg
, edt2
), FALSE
);
931 if (lppd
->Flags
& PD_PAGENUMS
)
932 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
937 * FIXME: The ico3 is not displayed for some reason. I don't know why.
939 if (lppd
->Flags
& PD_COLLATE
) {
940 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
941 (LPARAM
)PrintStructures
->hCollateIcon
);
942 CheckDlgButton(hDlg
, chx2
, 1);
944 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
945 (LPARAM
)PrintStructures
->hNoCollateIcon
);
946 CheckDlgButton(hDlg
, chx2
, 0);
949 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
950 /* if printer doesn't support it: no Collate */
951 if (!(lpdm
->dmFields
& DM_COLLATE
)) {
952 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
953 EnableWindow(GetDlgItem(hDlg
, ico3
), FALSE
);
960 if (lppd
->hDevMode
== 0)
961 copies
= lppd
->nCopies
;
963 copies
= lpdm
->dmCopies
;
964 if(copies
== 0) copies
= 1;
965 else if(copies
< 0) copies
= MAX_COPIES
;
966 SetDlgItemInt(hDlg
, edt3
, copies
, FALSE
);
969 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
970 /* if printer doesn't support it: no nCopies */
971 if (!(lpdm
->dmFields
& DM_COPIES
)) {
972 EnableWindow(GetDlgItem(hDlg
, edt3
), FALSE
);
973 EnableWindow(GetDlgItem(hDlg
, stc5
), FALSE
);
978 CheckDlgButton(hDlg
, chx1
, (lppd
->Flags
& PD_PRINTTOFILE
) ? 1 : 0);
979 if (lppd
->Flags
& PD_DISABLEPRINTTOFILE
)
980 EnableWindow(GetDlgItem(hDlg
, chx1
), FALSE
);
981 if (lppd
->Flags
& PD_HIDEPRINTTOFILE
)
982 ShowWindow(GetDlgItem(hDlg
, chx1
), SW_HIDE
);
984 } else { /* PD_PRINTSETUP */
985 BOOL bPortrait
= (lpdm
->u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
);
987 PRINTDLG_SetUpPaperComboBoxA(hDlg
, cmb2
,
988 PrintStructures
->lpPrinterInfo
->pPrinterName
,
989 PrintStructures
->lpPrinterInfo
->pPortName
,
991 PRINTDLG_SetUpPaperComboBoxA(hDlg
, cmb3
,
992 PrintStructures
->lpPrinterInfo
->pPrinterName
,
993 PrintStructures
->lpPrinterInfo
->pPortName
,
995 CheckRadioButton(hDlg
, rad1
, rad2
, bPortrait
? rad1
: rad2
);
996 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
997 (LPARAM
)(bPortrait
? PrintStructures
->hPortraitIcon
:
998 PrintStructures
->hLandscapeIcon
));
1003 if ((lppd
->Flags
& PD_SHOWHELP
)==0) {
1004 /* hide if PD_SHOWHELP not specified */
1005 ShowWindow(GetDlgItem(hDlg
, pshHelp
), SW_HIDE
);
1010 static BOOL
PRINTDLG_ChangePrinterW(HWND hDlg
, WCHAR
*name
,
1011 PRINT_PTRW
*PrintStructures
)
1013 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1014 LPDEVMODEW lpdm
= NULL
;
1019 HeapFree(GetProcessHeap(),0, PrintStructures
->lpPrinterInfo
);
1020 HeapFree(GetProcessHeap(),0, PrintStructures
->lpDriverInfo
);
1021 if(!OpenPrinterW(name
, &hprn
, NULL
)) {
1022 ERR("Can't open printer %s\n", debugstr_w(name
));
1025 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
1026 PrintStructures
->lpPrinterInfo
= HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*needed
);
1027 GetPrinterW(hprn
, 2, (LPBYTE
)PrintStructures
->lpPrinterInfo
, needed
,
1029 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
1030 PrintStructures
->lpDriverInfo
= HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*needed
);
1031 if (!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)PrintStructures
->lpDriverInfo
,
1033 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures
->lpPrinterInfo
->pPrinterName
));
1038 PRINTDLG_UpdatePrinterInfoTextsW(hDlg
, PrintStructures
->lpPrinterInfo
);
1040 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
1041 PrintStructures
->lpDevMode
= NULL
;
1043 dmSize
= DocumentPropertiesW(0, 0, name
, NULL
, NULL
, 0);
1045 ERR("DocumentProperties fails on %s\n", debugstr_w(name
));
1048 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(), 0, dmSize
);
1049 dmSize
= DocumentPropertiesW(0, 0, name
, PrintStructures
->lpDevMode
, NULL
,
1051 if(lppd
->hDevMode
&& (lpdm
= GlobalLock(lppd
->hDevMode
)) &&
1052 !lstrcmpW(lpdm
->dmDeviceName
,
1053 PrintStructures
->lpDevMode
->dmDeviceName
)) {
1054 /* Supplied devicemode matches current printer so try to use it */
1055 DocumentPropertiesW(0, 0, name
, PrintStructures
->lpDevMode
, lpdm
,
1056 DM_OUT_BUFFER
| DM_IN_BUFFER
);
1059 GlobalUnlock(lppd
->hDevMode
);
1061 lpdm
= PrintStructures
->lpDevMode
; /* use this as a shortcut */
1063 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
1064 /* Print range (All/Range/Selection) */
1065 SetDlgItemInt(hDlg
, edt1
, lppd
->nFromPage
, FALSE
);
1066 SetDlgItemInt(hDlg
, edt2
, lppd
->nToPage
, FALSE
);
1067 CheckRadioButton(hDlg
, rad1
, rad3
, rad1
); /* default */
1068 if (lppd
->Flags
& PD_NOSELECTION
)
1069 EnableWindow(GetDlgItem(hDlg
, rad2
), FALSE
);
1071 if (lppd
->Flags
& PD_SELECTION
)
1072 CheckRadioButton(hDlg
, rad1
, rad3
, rad2
);
1073 if (lppd
->Flags
& PD_NOPAGENUMS
) {
1074 EnableWindow(GetDlgItem(hDlg
, rad3
), FALSE
);
1075 EnableWindow(GetDlgItem(hDlg
, stc2
),FALSE
);
1076 EnableWindow(GetDlgItem(hDlg
, edt1
), FALSE
);
1077 EnableWindow(GetDlgItem(hDlg
, stc3
),FALSE
);
1078 EnableWindow(GetDlgItem(hDlg
, edt2
), FALSE
);
1080 if (lppd
->Flags
& PD_PAGENUMS
)
1081 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1086 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1088 if (lppd
->Flags
& PD_COLLATE
) {
1089 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1090 (LPARAM
)PrintStructures
->hCollateIcon
);
1091 CheckDlgButton(hDlg
, chx2
, 1);
1093 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1094 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1095 CheckDlgButton(hDlg
, chx2
, 0);
1098 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1099 /* if printer doesn't support it: no Collate */
1100 if (!(lpdm
->dmFields
& DM_COLLATE
)) {
1101 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1102 EnableWindow(GetDlgItem(hDlg
, ico3
), FALSE
);
1109 if (lppd
->hDevMode
== 0)
1110 copies
= lppd
->nCopies
;
1112 copies
= lpdm
->dmCopies
;
1113 if(copies
== 0) copies
= 1;
1114 else if(copies
< 0) copies
= MAX_COPIES
;
1115 SetDlgItemInt(hDlg
, edt3
, copies
, FALSE
);
1118 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1119 /* if printer doesn't support it: no nCopies */
1120 if (!(lpdm
->dmFields
& DM_COPIES
)) {
1121 EnableWindow(GetDlgItem(hDlg
, edt3
), FALSE
);
1122 EnableWindow(GetDlgItem(hDlg
, stc5
), FALSE
);
1127 CheckDlgButton(hDlg
, chx1
, (lppd
->Flags
& PD_PRINTTOFILE
) ? 1 : 0);
1128 if (lppd
->Flags
& PD_DISABLEPRINTTOFILE
)
1129 EnableWindow(GetDlgItem(hDlg
, chx1
), FALSE
);
1130 if (lppd
->Flags
& PD_HIDEPRINTTOFILE
)
1131 ShowWindow(GetDlgItem(hDlg
, chx1
), SW_HIDE
);
1133 } else { /* PD_PRINTSETUP */
1134 BOOL bPortrait
= (lpdm
->u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
);
1136 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb2
,
1137 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1138 PrintStructures
->lpPrinterInfo
->pPortName
,
1140 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb3
,
1141 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1142 PrintStructures
->lpPrinterInfo
->pPortName
,
1144 CheckRadioButton(hDlg
, rad1
, rad2
, bPortrait
? rad1
: rad2
);
1145 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1146 (LPARAM
)(bPortrait
? PrintStructures
->hPortraitIcon
:
1147 PrintStructures
->hLandscapeIcon
));
1152 if ((lppd
->Flags
& PD_SHOWHELP
)==0) {
1153 /* hide if PD_SHOWHELP not specified */
1154 ShowWindow(GetDlgItem(hDlg
, pshHelp
), SW_HIDE
);
1159 /***********************************************************************
1160 * check_printer_setup [internal]
1162 static LRESULT
check_printer_setup(HWND hDlg
)
1165 WCHAR resourcestr
[256],resultstr
[256];
1168 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
1171 EnumPrintersW(PRINTER_ENUM_CONNECTIONS
, NULL
, 2, NULL
, 0, &needed
, &num
);
1177 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEVICES
,resultstr
, 255);
1178 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
,resourcestr
, 255);
1179 res
= MessageBoxW(hDlg
, resultstr
, resourcestr
,MB_OK
| MB_ICONWARNING
);
1184 /***********************************************************************
1185 * PRINTDLG_WMInitDialog [internal]
1187 static LRESULT
PRINTDLG_WMInitDialog(HWND hDlg
, WPARAM wParam
,
1188 PRINT_PTRA
* PrintStructures
)
1190 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1194 UINT comboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1196 /* load Collate ICONs */
1197 /* We load these with LoadImage because they are not a standard
1198 size and we don't want them rescaled */
1199 PrintStructures
->hCollateIcon
=
1200 LoadImageA(COMDLG32_hInstance
, "PD32_COLLATE", IMAGE_ICON
, 0, 0, 0);
1201 PrintStructures
->hNoCollateIcon
=
1202 LoadImageA(COMDLG32_hInstance
, "PD32_NOCOLLATE", IMAGE_ICON
, 0, 0, 0);
1204 /* These can be done with LoadIcon */
1205 PrintStructures
->hPortraitIcon
=
1206 LoadIconA(COMDLG32_hInstance
, "PD32_PORTRAIT");
1207 PrintStructures
->hLandscapeIcon
=
1208 LoadIconA(COMDLG32_hInstance
, "PD32_LANDSCAPE");
1210 /* display the collate/no_collate icon */
1211 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1212 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1214 if(PrintStructures
->hCollateIcon
== 0 ||
1215 PrintStructures
->hNoCollateIcon
== 0 ||
1216 PrintStructures
->hPortraitIcon
== 0 ||
1217 PrintStructures
->hLandscapeIcon
== 0) {
1218 ERR("no icon in resourcefile\n");
1219 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1220 EndDialog(hDlg
, FALSE
);
1224 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1225 * must be registered and the Help button must be shown.
1227 if (lppd
->Flags
& PD_SHOWHELP
) {
1228 if((PrintStructures
->HelpMessageID
=
1229 RegisterWindowMessageA(HELPMSGSTRINGA
)) == 0) {
1230 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL
);
1234 PrintStructures
->HelpMessageID
= 0;
1236 if(!(lppd
->Flags
&PD_PRINTSETUP
)) {
1237 PrintStructures
->hwndUpDown
=
1238 CreateUpDownControl(WS_CHILD
| WS_VISIBLE
| WS_BORDER
|
1239 UDS_NOTHOUSANDS
| UDS_ARROWKEYS
|
1240 UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, 0, 0, 0, 0,
1241 hDlg
, UPDOWN_ID
, COMDLG32_hInstance
,
1242 GetDlgItem(hDlg
, edt3
), MAX_COPIES
, 1, 1);
1245 /* FIXME: I allow more freedom than either Win95 or WinNT,
1246 * which do not agree to what errors should be thrown or not
1247 * in case nToPage or nFromPage is out-of-range.
1249 if (lppd
->nMaxPage
< lppd
->nMinPage
)
1250 lppd
->nMaxPage
= lppd
->nMinPage
;
1251 if (lppd
->nMinPage
== lppd
->nMaxPage
)
1252 lppd
->Flags
|= PD_NOPAGENUMS
;
1253 if (lppd
->nToPage
< lppd
->nMinPage
)
1254 lppd
->nToPage
= lppd
->nMinPage
;
1255 if (lppd
->nToPage
> lppd
->nMaxPage
)
1256 lppd
->nToPage
= lppd
->nMaxPage
;
1257 if (lppd
->nFromPage
< lppd
->nMinPage
)
1258 lppd
->nFromPage
= lppd
->nMinPage
;
1259 if (lppd
->nFromPage
> lppd
->nMaxPage
)
1260 lppd
->nFromPage
= lppd
->nMaxPage
;
1262 /* if we have the combo box, fill it */
1263 if (GetDlgItem(hDlg
,comboID
)) {
1266 pdn
= GlobalLock(lppd
->hDevNames
);
1267 pdm
= GlobalLock(lppd
->hDevMode
);
1269 name
= (char*)pdn
+ pdn
->wDeviceOffset
;
1271 name
= (char*)pdm
->dmDeviceName
;
1272 PRINTDLG_SetUpPrinterListComboA(hDlg
, comboID
, name
);
1273 if(pdm
) GlobalUnlock(lppd
->hDevMode
);
1274 if(pdn
) GlobalUnlock(lppd
->hDevNames
);
1276 /* Now find selected printer and update rest of dlg */
1277 name
= HeapAlloc(GetProcessHeap(),0,256);
1278 if (GetDlgItemTextA(hDlg
, comboID
, name
, 255))
1279 PRINTDLG_ChangePrinterA(hDlg
, name
, PrintStructures
);
1280 HeapFree(GetProcessHeap(),0,name
);
1282 /* else use default printer */
1284 DWORD dwBufLen
= sizeof(name
);
1285 BOOL ret
= GetDefaultPrinterA(name
, &dwBufLen
);
1288 PRINTDLG_ChangePrinterA(hDlg
, name
, PrintStructures
);
1290 FIXME("No default printer found, expect problems!\n");
1295 static LRESULT
PRINTDLG_WMInitDialogW(HWND hDlg
, WPARAM wParam
,
1296 PRINT_PTRW
* PrintStructures
)
1298 static const WCHAR PD32_COLLATE
[] = { 'P', 'D', '3', '2', '_', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
1299 static const WCHAR PD32_NOCOLLATE
[] = { 'P', 'D', '3', '2', '_', 'N', 'O', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
1300 static const WCHAR PD32_PORTRAIT
[] = { 'P', 'D', '3', '2', '_', 'P', 'O', 'R', 'T', 'R', 'A', 'I', 'T', 0 };
1301 static const WCHAR PD32_LANDSCAPE
[] = { 'P', 'D', '3', '2', '_', 'L', 'A', 'N', 'D', 'S', 'C', 'A', 'P', 'E', 0 };
1302 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1306 UINT comboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1308 /* load Collate ICONs */
1309 /* We load these with LoadImage because they are not a standard
1310 size and we don't want them rescaled */
1311 PrintStructures
->hCollateIcon
=
1312 LoadImageW(COMDLG32_hInstance
, PD32_COLLATE
, IMAGE_ICON
, 0, 0, 0);
1313 PrintStructures
->hNoCollateIcon
=
1314 LoadImageW(COMDLG32_hInstance
, PD32_NOCOLLATE
, IMAGE_ICON
, 0, 0, 0);
1316 /* These can be done with LoadIcon */
1317 PrintStructures
->hPortraitIcon
=
1318 LoadIconW(COMDLG32_hInstance
, PD32_PORTRAIT
);
1319 PrintStructures
->hLandscapeIcon
=
1320 LoadIconW(COMDLG32_hInstance
, PD32_LANDSCAPE
);
1322 /* display the collate/no_collate icon */
1323 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1324 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1326 if(PrintStructures
->hCollateIcon
== 0 ||
1327 PrintStructures
->hNoCollateIcon
== 0 ||
1328 PrintStructures
->hPortraitIcon
== 0 ||
1329 PrintStructures
->hLandscapeIcon
== 0) {
1330 ERR("no icon in resourcefile\n");
1331 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1332 EndDialog(hDlg
, FALSE
);
1336 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1337 * must be registered and the Help button must be shown.
1339 if (lppd
->Flags
& PD_SHOWHELP
) {
1340 if((PrintStructures
->HelpMessageID
=
1341 RegisterWindowMessageW(HELPMSGSTRINGW
)) == 0) {
1342 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL
);
1346 PrintStructures
->HelpMessageID
= 0;
1348 if(!(lppd
->Flags
&PD_PRINTSETUP
)) {
1349 PrintStructures
->hwndUpDown
=
1350 CreateUpDownControl(WS_CHILD
| WS_VISIBLE
| WS_BORDER
|
1351 UDS_NOTHOUSANDS
| UDS_ARROWKEYS
|
1352 UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, 0, 0, 0, 0,
1353 hDlg
, UPDOWN_ID
, COMDLG32_hInstance
,
1354 GetDlgItem(hDlg
, edt3
), MAX_COPIES
, 1, 1);
1357 /* FIXME: I allow more freedom than either Win95 or WinNT,
1358 * which do not agree to what errors should be thrown or not
1359 * in case nToPage or nFromPage is out-of-range.
1361 if (lppd
->nMaxPage
< lppd
->nMinPage
)
1362 lppd
->nMaxPage
= lppd
->nMinPage
;
1363 if (lppd
->nMinPage
== lppd
->nMaxPage
)
1364 lppd
->Flags
|= PD_NOPAGENUMS
;
1365 if (lppd
->nToPage
< lppd
->nMinPage
)
1366 lppd
->nToPage
= lppd
->nMinPage
;
1367 if (lppd
->nToPage
> lppd
->nMaxPage
)
1368 lppd
->nToPage
= lppd
->nMaxPage
;
1369 if (lppd
->nFromPage
< lppd
->nMinPage
)
1370 lppd
->nFromPage
= lppd
->nMinPage
;
1371 if (lppd
->nFromPage
> lppd
->nMaxPage
)
1372 lppd
->nFromPage
= lppd
->nMaxPage
;
1374 /* if we have the combo box, fill it */
1375 if (GetDlgItem(hDlg
,comboID
)) {
1378 pdn
= GlobalLock(lppd
->hDevNames
);
1379 pdm
= GlobalLock(lppd
->hDevMode
);
1381 name
= (WCHAR
*)pdn
+ pdn
->wDeviceOffset
;
1383 name
= pdm
->dmDeviceName
;
1384 PRINTDLG_SetUpPrinterListComboW(hDlg
, comboID
, name
);
1385 if(pdm
) GlobalUnlock(lppd
->hDevMode
);
1386 if(pdn
) GlobalUnlock(lppd
->hDevNames
);
1388 /* Now find selected printer and update rest of dlg */
1389 /* ansi is ok here */
1390 name
= HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR
));
1391 if (GetDlgItemTextW(hDlg
, comboID
, name
, 255))
1392 PRINTDLG_ChangePrinterW(hDlg
, name
, PrintStructures
);
1393 HeapFree(GetProcessHeap(),0,name
);
1395 /* else use default printer */
1397 DWORD dwBufLen
= sizeof(name
) / sizeof(WCHAR
);
1398 BOOL ret
= GetDefaultPrinterW(name
, &dwBufLen
);
1401 PRINTDLG_ChangePrinterW(hDlg
, name
, PrintStructures
);
1403 FIXME("No default printer found, expect problems!\n");
1408 /***********************************************************************
1409 * PRINTDLG_WMCommand [internal]
1411 LRESULT
PRINTDLG_WMCommandA(HWND hDlg
, WPARAM wParam
,
1412 LPARAM lParam
, PRINT_PTRA
* PrintStructures
)
1414 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1415 UINT PrinterComboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1416 LPDEVMODEA lpdm
= PrintStructures
->lpDevMode
;
1418 switch (LOWORD(wParam
)) {
1420 TRACE(" OK button was hit\n");
1421 if (!PRINTDLG_UpdatePrintDlgA(hDlg
, PrintStructures
)) {
1422 FIXME("Update printdlg was not successful!\n");
1425 EndDialog(hDlg
, TRUE
);
1429 TRACE(" CANCEL button was hit\n");
1430 EndDialog(hDlg
, FALSE
);
1434 TRACE(" HELP button was hit\n");
1435 SendMessageA(lppd
->hwndOwner
, PrintStructures
->HelpMessageID
,
1436 (WPARAM
) hDlg
, (LPARAM
) lppd
);
1439 case chx2
: /* collate pages checkbox */
1440 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
1441 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1442 (LPARAM
)PrintStructures
->hCollateIcon
);
1444 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1445 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1447 case edt1
: /* from page nr editbox */
1448 case edt2
: /* to page nr editbox */
1449 if (HIWORD(wParam
)==EN_CHANGE
) {
1452 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
1453 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
1454 if (nFromPage
!= lppd
->nFromPage
|| nToPage
!= lppd
->nToPage
)
1455 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1460 if(HIWORD(wParam
) == EN_CHANGE
) {
1461 INT copies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
1463 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1465 EnableWindow(GetDlgItem(hDlg
, chx2
), TRUE
);
1470 case psh1
: /* Print Setup */
1474 if (!PrintStructures
->dlg
.lpPrintDlg16
) {
1475 FIXME("The 32bit print dialog does not have this button!?\n");
1479 memcpy(&pdlg
,PrintStructures
->dlg
.lpPrintDlg16
,sizeof(pdlg
));
1480 pdlg
.Flags
|= PD_PRINTSETUP
;
1481 pdlg
.hwndOwner
= HWND_16(hDlg
);
1482 if (!PrintDlg16(&pdlg
))
1487 case psh2
: /* Properties button */
1490 char PrinterName
[256];
1492 GetDlgItemTextA(hDlg
, PrinterComboID
, PrinterName
, 255);
1493 if (!OpenPrinterA(PrinterName
, &hPrinter
, NULL
)) {
1494 FIXME(" Call to OpenPrinter did not succeed!\n");
1497 DocumentPropertiesA(hDlg
, hPrinter
, PrinterName
,
1498 PrintStructures
->lpDevMode
,
1499 PrintStructures
->lpDevMode
,
1500 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
1501 ClosePrinter(hPrinter
);
1505 case rad1
: /* Paperorientation */
1506 if (lppd
->Flags
& PD_PRINTSETUP
)
1508 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1509 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1510 (LPARAM
)(PrintStructures
->hPortraitIcon
));
1514 case rad2
: /* Paperorientation */
1515 if (lppd
->Flags
& PD_PRINTSETUP
)
1517 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1518 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1519 (LPARAM
)(PrintStructures
->hLandscapeIcon
));
1523 case cmb1
: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1524 if (PrinterComboID
!= LOWORD(wParam
)) {
1525 FIXME("No handling for print quality combo box yet.\n");
1529 case cmb4
: /* Printer combobox */
1530 if (HIWORD(wParam
)==CBN_SELCHANGE
) {
1531 char PrinterName
[256];
1532 GetDlgItemTextA(hDlg
, LOWORD(wParam
), PrinterName
, 255);
1533 PRINTDLG_ChangePrinterA(hDlg
, PrinterName
, PrintStructures
);
1537 case cmb2
: /* Papersize */
1539 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
1541 lpdm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageA(hDlg
, cmb2
,
1547 case cmb3
: /* Bin */
1549 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
1551 lpdm
->dmDefaultSource
= SendDlgItemMessageA(hDlg
, cmb3
,
1552 CB_GETITEMDATA
, Sel
,
1557 if(lppd
->Flags
& PD_PRINTSETUP
) {
1558 switch (LOWORD(wParam
)) {
1559 case rad1
: /* orientation */
1561 if (IsDlgButtonChecked(hDlg
, rad1
) == BST_CHECKED
) {
1562 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_PORTRAIT
) {
1563 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1564 SendDlgItemMessageA(hDlg
, stc10
, STM_SETIMAGE
,
1566 (LPARAM
)PrintStructures
->hPortraitIcon
);
1567 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
,
1569 (LPARAM
)PrintStructures
->hPortraitIcon
);
1572 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_LANDSCAPE
) {
1573 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1574 SendDlgItemMessageA(hDlg
, stc10
, STM_SETIMAGE
,
1576 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1577 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
,
1579 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1588 static LRESULT
PRINTDLG_WMCommandW(HWND hDlg
, WPARAM wParam
,
1589 LPARAM lParam
, PRINT_PTRW
* PrintStructures
)
1591 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1592 UINT PrinterComboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1593 LPDEVMODEW lpdm
= PrintStructures
->lpDevMode
;
1595 switch (LOWORD(wParam
)) {
1597 TRACE(" OK button was hit\n");
1598 if (!PRINTDLG_UpdatePrintDlgW(hDlg
, PrintStructures
)) {
1599 FIXME("Update printdlg was not successful!\n");
1602 EndDialog(hDlg
, TRUE
);
1606 TRACE(" CANCEL button was hit\n");
1607 EndDialog(hDlg
, FALSE
);
1611 TRACE(" HELP button was hit\n");
1612 SendMessageW(lppd
->hwndOwner
, PrintStructures
->HelpMessageID
,
1613 (WPARAM
) hDlg
, (LPARAM
) lppd
);
1616 case chx2
: /* collate pages checkbox */
1617 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
1618 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1619 (LPARAM
)PrintStructures
->hCollateIcon
);
1621 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1622 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1624 case edt1
: /* from page nr editbox */
1625 case edt2
: /* to page nr editbox */
1626 if (HIWORD(wParam
)==EN_CHANGE
) {
1629 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
1630 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
1631 if (nFromPage
!= lppd
->nFromPage
|| nToPage
!= lppd
->nToPage
)
1632 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1637 if(HIWORD(wParam
) == EN_CHANGE
) {
1638 INT copies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
1640 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1642 EnableWindow(GetDlgItem(hDlg
, chx2
), TRUE
);
1646 case psh1
: /* Print Setup */
1648 ERR("psh1 is called from 16bit code only, we should not get here.\n");
1651 case psh2
: /* Properties button */
1654 WCHAR PrinterName
[256];
1656 if (!GetDlgItemTextW(hDlg
, PrinterComboID
, PrinterName
, 255)) break;
1657 if (!OpenPrinterW(PrinterName
, &hPrinter
, NULL
)) {
1658 FIXME(" Call to OpenPrinter did not succeed!\n");
1661 DocumentPropertiesW(hDlg
, hPrinter
, PrinterName
,
1662 PrintStructures
->lpDevMode
,
1663 PrintStructures
->lpDevMode
,
1664 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
1665 ClosePrinter(hPrinter
);
1669 case rad1
: /* Paperorientation */
1670 if (lppd
->Flags
& PD_PRINTSETUP
)
1672 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1673 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1674 (LPARAM
)(PrintStructures
->hPortraitIcon
));
1678 case rad2
: /* Paperorientation */
1679 if (lppd
->Flags
& PD_PRINTSETUP
)
1681 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1682 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1683 (LPARAM
)(PrintStructures
->hLandscapeIcon
));
1687 case cmb1
: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1688 if (PrinterComboID
!= LOWORD(wParam
)) {
1689 FIXME("No handling for print quality combo box yet.\n");
1693 case cmb4
: /* Printer combobox */
1694 if (HIWORD(wParam
)==CBN_SELCHANGE
) {
1695 WCHAR PrinterName
[256];
1696 GetDlgItemTextW(hDlg
, LOWORD(wParam
), PrinterName
, 255);
1697 PRINTDLG_ChangePrinterW(hDlg
, PrinterName
, PrintStructures
);
1701 case cmb2
: /* Papersize */
1703 DWORD Sel
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
1705 lpdm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageW(hDlg
, cmb2
,
1711 case cmb3
: /* Bin */
1713 DWORD Sel
= SendDlgItemMessageW(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
1715 lpdm
->dmDefaultSource
= SendDlgItemMessageW(hDlg
, cmb3
,
1716 CB_GETITEMDATA
, Sel
,
1721 if(lppd
->Flags
& PD_PRINTSETUP
) {
1722 switch (LOWORD(wParam
)) {
1723 case rad1
: /* orientation */
1725 if (IsDlgButtonChecked(hDlg
, rad1
) == BST_CHECKED
) {
1726 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_PORTRAIT
) {
1727 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1728 SendDlgItemMessageW(hDlg
, stc10
, STM_SETIMAGE
,
1730 (LPARAM
)PrintStructures
->hPortraitIcon
);
1731 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
,
1733 (LPARAM
)PrintStructures
->hPortraitIcon
);
1736 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_LANDSCAPE
) {
1737 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1738 SendDlgItemMessageW(hDlg
, stc10
, STM_SETIMAGE
,
1740 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1741 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
,
1743 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1752 /***********************************************************************
1753 * PrintDlgProcA [internal]
1755 static INT_PTR CALLBACK
PrintDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
1758 PRINT_PTRA
* PrintStructures
;
1759 INT_PTR res
= FALSE
;
1761 if (uMsg
!=WM_INITDIALOG
) {
1762 PrintStructures
= (PRINT_PTRA
*)GetPropA(hDlg
,"__WINE_PRINTDLGDATA");
1763 if (!PrintStructures
)
1766 PrintStructures
= (PRINT_PTRA
*) lParam
;
1767 SetPropA(hDlg
,"__WINE_PRINTDLGDATA",PrintStructures
);
1768 if(!check_printer_setup(hDlg
))
1770 EndDialog(hDlg
,FALSE
);
1773 res
= PRINTDLG_WMInitDialog(hDlg
, wParam
, PrintStructures
);
1775 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
)
1776 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(
1777 hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->lpPrintDlg
1782 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
) {
1783 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
,uMsg
,wParam
,
1790 return PRINTDLG_WMCommandA(hDlg
, wParam
, lParam
, PrintStructures
);
1793 DestroyIcon(PrintStructures
->hCollateIcon
);
1794 DestroyIcon(PrintStructures
->hNoCollateIcon
);
1795 DestroyIcon(PrintStructures
->hPortraitIcon
);
1796 DestroyIcon(PrintStructures
->hLandscapeIcon
);
1797 if(PrintStructures
->hwndUpDown
)
1798 DestroyWindow(PrintStructures
->hwndUpDown
);
1804 static INT_PTR CALLBACK
PrintDlgProcW(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
1807 static const WCHAR propW
[] = {'_','_','W','I','N','E','_','P','R','I','N','T','D','L','G','D','A','T','A',0};
1808 PRINT_PTRW
* PrintStructures
;
1809 INT_PTR res
= FALSE
;
1811 if (uMsg
!=WM_INITDIALOG
) {
1812 PrintStructures
= (PRINT_PTRW
*) GetPropW(hDlg
, propW
);
1813 if (!PrintStructures
)
1816 PrintStructures
= (PRINT_PTRW
*) lParam
;
1817 SetPropW(hDlg
, propW
, PrintStructures
);
1818 if(!check_printer_setup(hDlg
))
1820 EndDialog(hDlg
,FALSE
);
1823 res
= PRINTDLG_WMInitDialogW(hDlg
, wParam
, PrintStructures
);
1825 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
)
1826 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->lpPrintDlg
);
1830 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
) {
1831 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
,uMsg
,wParam
, lParam
);
1837 return PRINTDLG_WMCommandW(hDlg
, wParam
, lParam
, PrintStructures
);
1840 DestroyIcon(PrintStructures
->hCollateIcon
);
1841 DestroyIcon(PrintStructures
->hNoCollateIcon
);
1842 DestroyIcon(PrintStructures
->hPortraitIcon
);
1843 DestroyIcon(PrintStructures
->hLandscapeIcon
);
1844 if(PrintStructures
->hwndUpDown
)
1845 DestroyWindow(PrintStructures
->hwndUpDown
);
1851 /************************************************************
1853 * PRINTDLG_GetDlgTemplate
1856 static HGLOBAL
PRINTDLG_GetDlgTemplateA(PRINTDLGA
*lppd
)
1861 if (lppd
->Flags
& PD_PRINTSETUP
) {
1862 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
1863 hDlgTmpl
= lppd
->hSetupTemplate
;
1864 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
1865 hResInfo
= FindResourceA(lppd
->hInstance
,
1866 lppd
->lpSetupTemplateName
, (LPSTR
)RT_DIALOG
);
1867 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1869 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32_SETUP",
1871 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1874 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
1875 hDlgTmpl
= lppd
->hPrintTemplate
;
1876 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
1877 hResInfo
= FindResourceA(lppd
->hInstance
,
1878 lppd
->lpPrintTemplateName
,
1880 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1882 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32",
1884 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1890 static HGLOBAL
PRINTDLG_GetDlgTemplateW(PRINTDLGW
*lppd
)
1894 static const WCHAR xpsetup
[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
1895 static const WCHAR xprint
[] = { 'P','R','I','N','T','3','2',0};
1897 if (lppd
->Flags
& PD_PRINTSETUP
) {
1898 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
1899 hDlgTmpl
= lppd
->hSetupTemplate
;
1900 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
1901 hResInfo
= FindResourceW(lppd
->hInstance
,
1902 lppd
->lpSetupTemplateName
, (LPWSTR
)RT_DIALOG
);
1903 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1905 hResInfo
= FindResourceW(COMDLG32_hInstance
, xpsetup
, (LPWSTR
)RT_DIALOG
);
1906 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1909 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
1910 hDlgTmpl
= lppd
->hPrintTemplate
;
1911 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
1912 hResInfo
= FindResourceW(lppd
->hInstance
,
1913 lppd
->lpPrintTemplateName
,
1915 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1917 hResInfo
= FindResourceW(COMDLG32_hInstance
, xprint
, (LPWSTR
)RT_DIALOG
);
1918 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1924 /***********************************************************************
1929 static BOOL
PRINTDLG_CreateDCA(LPPRINTDLGA lppd
)
1931 DEVNAMES
*pdn
= GlobalLock(lppd
->hDevNames
);
1932 DEVMODEA
*pdm
= GlobalLock(lppd
->hDevMode
);
1934 if(lppd
->Flags
& PD_RETURNDC
) {
1935 lppd
->hDC
= CreateDCA((char*)pdn
+ pdn
->wDriverOffset
,
1936 (char*)pdn
+ pdn
->wDeviceOffset
,
1937 (char*)pdn
+ pdn
->wOutputOffset
,
1939 } else if(lppd
->Flags
& PD_RETURNIC
) {
1940 lppd
->hDC
= CreateICA((char*)pdn
+ pdn
->wDriverOffset
,
1941 (char*)pdn
+ pdn
->wDeviceOffset
,
1942 (char*)pdn
+ pdn
->wOutputOffset
,
1945 GlobalUnlock(lppd
->hDevNames
);
1946 GlobalUnlock(lppd
->hDevMode
);
1947 return lppd
->hDC
? TRUE
: FALSE
;
1950 static BOOL
PRINTDLG_CreateDCW(LPPRINTDLGW lppd
)
1952 DEVNAMES
*pdn
= GlobalLock(lppd
->hDevNames
);
1953 DEVMODEW
*pdm
= GlobalLock(lppd
->hDevMode
);
1955 if(lppd
->Flags
& PD_RETURNDC
) {
1956 lppd
->hDC
= CreateDCW((WCHAR
*)pdn
+ pdn
->wDriverOffset
,
1957 (WCHAR
*)pdn
+ pdn
->wDeviceOffset
,
1958 (WCHAR
*)pdn
+ pdn
->wOutputOffset
,
1960 } else if(lppd
->Flags
& PD_RETURNIC
) {
1961 lppd
->hDC
= CreateICW((WCHAR
*)pdn
+ pdn
->wDriverOffset
,
1962 (WCHAR
*)pdn
+ pdn
->wDeviceOffset
,
1963 (WCHAR
*)pdn
+ pdn
->wOutputOffset
,
1966 GlobalUnlock(lppd
->hDevNames
);
1967 GlobalUnlock(lppd
->hDevMode
);
1968 return lppd
->hDC
? TRUE
: FALSE
;
1971 /***********************************************************************
1972 * PrintDlgA (COMDLG32.@)
1974 * Displays the the PRINT dialog box, which enables the user to specify
1975 * specific properties of the print job.
1978 * lppd [IO] ptr to PRINTDLG32 struct
1981 * nonzero if the user pressed the OK button
1982 * zero if the user cancelled the window or an error occurred
1986 * * The Collate Icons do not display, even though they are in the code.
1987 * * The Properties Button(s) should call DocumentPropertiesA().
1990 BOOL WINAPI
PrintDlgA(LPPRINTDLGA lppd
)
1994 HINSTANCE hInst
= (HINSTANCE
)GetWindowLongPtrA( lppd
->hwndOwner
, GWLP_HINSTANCE
);
1996 if(TRACE_ON(commdlg
)) {
1997 char flagstr
[1000] = "";
1998 struct pd_flags
*pflag
= pd_flags
;
1999 for( ; pflag
->name
; pflag
++) {
2000 if(lppd
->Flags
& pflag
->flag
)
2001 strcat(flagstr
, pflag
->name
);
2003 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2004 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2005 "flags %08lx (%s)\n",
2006 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
2007 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
2008 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
2011 if(lppd
->lStructSize
!= sizeof(PRINTDLGA
)) {
2012 WARN("structure size failure !!!\n");
2013 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
2017 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
2018 PRINTER_INFO_2A
*pbuf
;
2019 DRIVER_INFO_3A
*dbuf
;
2023 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
2024 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2025 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2028 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
2029 WARN("Can't find default printer\n");
2030 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
2034 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
2035 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
2036 GetPrinterA(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
2038 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
2039 dbuf
= HeapAlloc(GetProcessHeap(),0,needed
);
2040 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
2041 ERR("GetPrinterDriverA failed, le %ld, fix your config for printer %s!\n",GetLastError(),pbuf
->pPrinterName
);
2042 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2047 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
2051 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
2052 pbuf
->pDevMode
->dmDriverExtra
);
2053 ptr
= GlobalLock(lppd
->hDevMode
);
2054 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
2055 pbuf
->pDevMode
->dmDriverExtra
);
2056 GlobalUnlock(lppd
->hDevMode
);
2057 HeapFree(GetProcessHeap(), 0, pbuf
);
2058 HeapFree(GetProcessHeap(), 0, dbuf
);
2062 PRINT_PTRA
*PrintStructures
;
2064 /* load Dialog resources,
2065 * depending on Flags indicates Print32 or Print32_setup dialog
2067 hDlgTmpl
= PRINTDLG_GetDlgTemplateA(lppd
);
2069 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2072 ptr
= LockResource( hDlgTmpl
);
2074 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2078 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2079 sizeof(PRINT_PTRA
));
2080 PrintStructures
->lpPrintDlg
= lppd
;
2082 /* and create & process the dialog .
2083 * -1 is failure, 0 is broken hwnd, everything else is ok.
2085 bRet
= (0<DialogBoxIndirectParamA(hInst
, ptr
, lppd
->hwndOwner
,
2087 (LPARAM
)PrintStructures
));
2090 DEVMODEA
*lpdm
= PrintStructures
->lpDevMode
, *lpdmReturn
;
2091 PRINTER_INFO_2A
*pi
= PrintStructures
->lpPrinterInfo
;
2092 DRIVER_INFO_3A
*di
= PrintStructures
->lpDriverInfo
;
2094 if (lppd
->hDevMode
== 0) {
2095 TRACE(" No hDevMode yet... Need to create my own\n");
2096 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
,
2097 lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2100 if((locks
= (GlobalFlags(lppd
->hDevMode
) & GMEM_LOCKCOUNT
))) {
2101 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks
);
2103 GlobalUnlock(lppd
->hDevMode
);
2104 TRACE("Now got %d locks\n", locks
);
2107 lppd
->hDevMode
= GlobalReAlloc(lppd
->hDevMode
,
2108 lpdm
->dmSize
+ lpdm
->dmDriverExtra
,
2111 lpdmReturn
= GlobalLock(lppd
->hDevMode
);
2112 memcpy(lpdmReturn
, lpdm
, lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2114 if (lppd
->hDevNames
!= 0) {
2116 if((locks
= (GlobalFlags(lppd
->hDevNames
) & GMEM_LOCKCOUNT
))) {
2117 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks
);
2119 GlobalUnlock(lppd
->hDevNames
);
2122 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
2127 GlobalUnlock(lppd
->hDevMode
);
2129 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
2130 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpPrinterInfo
);
2131 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDriverInfo
);
2132 HeapFree(GetProcessHeap(), 0, PrintStructures
);
2134 if(bRet
&& (lppd
->Flags
& PD_RETURNDC
|| lppd
->Flags
& PD_RETURNIC
))
2135 bRet
= PRINTDLG_CreateDCA(lppd
);
2137 TRACE("exit! (%d)\n", bRet
);
2141 /***********************************************************************
2142 * PrintDlgW (COMDLG32.@)
2146 BOOL WINAPI
PrintDlgW(
2147 LPPRINTDLGW lppd
/* [in/out] ptr to PRINTDLG32 struct */
2152 HINSTANCE hInst
= (HINSTANCE
)GetWindowLongPtrW( lppd
->hwndOwner
, GWLP_HINSTANCE
);
2154 if(TRACE_ON(commdlg
)) {
2155 char flagstr
[1000] = "";
2156 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 %08lx (%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 %ld, 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
,"%ld",(size
)/100);
2396 if (pda
->dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
) {
2397 sprintf(strout
,"%ldin",(size
)/1000);
2400 pda
->dlga
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
2401 sprintf(strout
,"%ld",(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
);
2499 if(pda
->curdlg
.ptPaperSize
.x
> pda
->curdlg
.ptPaperSize
.y
)
2500 dm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
2502 dm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
2504 paperword
= SendDlgItemMessageA(hDlg
,cmb2
,CB_GETITEMDATA
,
2505 SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0), 0);
2506 if (paperword
!= CB_ERR
)
2507 dm
->u1
.s1
.dmPaperSize
= paperword
;
2509 FIXME("could not get dialog text for papersize cmbbox?\n");
2511 GlobalUnlock(pda
->pdlg
.hDevNames
);
2512 GlobalUnlock(pda
->pdlg
.hDevMode
);
2518 PRINTDLG_PS_UpdateDlgStructW(HWND hDlg
, PageSetupDataW
*pda
) {
2521 LPWSTR devname
,portname
;
2522 WCHAR papername
[64];
2525 dn
= GlobalLock(pda
->pdlg
.hDevNames
);
2526 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2527 devname
= ((WCHAR
*)dn
)+dn
->wDeviceOffset
;
2528 portname
= ((WCHAR
*)dn
)+dn
->wOutputOffset
;
2529 PRINTDLG_SetUpPaperComboBoxW(hDlg
,cmb2
,devname
,portname
,dm
);
2530 PRINTDLG_SetUpPaperComboBoxW(hDlg
,cmb3
,devname
,portname
,dm
);
2532 if (GetDlgItemTextW(hDlg
,cmb2
,papername
,sizeof(papername
))>0) {
2533 PRINTDLG_PaperSizeW(&(pda
->pdlg
),papername
,&(pda
->dlga
->ptPaperSize
));
2534 pda
->dlga
->ptPaperSize
.x
= _c_10mm2size((LPPAGESETUPDLGA
)pda
->dlga
,pda
->dlga
->ptPaperSize
.x
);
2535 pda
->dlga
->ptPaperSize
.y
= _c_10mm2size((LPPAGESETUPDLGA
)pda
->dlga
,pda
->dlga
->ptPaperSize
.y
);
2537 FIXME("could not get dialog text for papersize cmbbox?\n");
2538 #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); }
2539 GETVAL(edt4
,pda
->dlga
->rtMargin
.left
);
2540 GETVAL(edt5
,pda
->dlga
->rtMargin
.top
);
2541 GETVAL(edt6
,pda
->dlga
->rtMargin
.right
);
2542 GETVAL(edt7
,pda
->dlga
->rtMargin
.bottom
);
2545 /* If we are in landscape, swap x and y of page size */
2546 if (IsDlgButtonChecked(hDlg
, rad2
)) {
2548 tmp
= pda
->dlga
->ptPaperSize
.x
;
2549 pda
->dlga
->ptPaperSize
.x
= pda
->dlga
->ptPaperSize
.y
;
2550 pda
->dlga
->ptPaperSize
.y
= tmp
;
2552 GlobalUnlock(pda
->pdlg
.hDevNames
);
2553 GlobalUnlock(pda
->pdlg
.hDevMode
);
2557 /**********************************************************************************************
2558 * PRINTDLG_PS_ChangeActivePrinerA
2560 * Redefines hDevMode and hDevNames HANDLES and initialises it.
2563 * name [in] Name of a printer for activation
2564 * pda [in/out] ptr to PageSetupDataA structure
2571 PRINTDLG_PS_ChangeActivePrinterA(LPSTR name
, PageSetupDataA
*pda
){
2574 LPPRINTER_INFO_2A lpPrinterInfo
;
2575 LPDRIVER_INFO_3A lpDriverInfo
;
2576 DEVMODEA
*pDevMode
, *dm
;
2578 if(!OpenPrinterA(name
, &hprn
, NULL
)){
2579 ERR("Can't open printer %s\n", name
);
2582 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
2583 lpPrinterInfo
= HeapAlloc(GetProcessHeap(), 0, needed
);
2584 GetPrinterA(hprn
, 2, (LPBYTE
)lpPrinterInfo
, needed
, &needed
);
2585 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
2586 lpDriverInfo
= HeapAlloc(GetProcessHeap(), 0, needed
);
2587 if(!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)lpDriverInfo
, needed
, &needed
)) {
2588 ERR("GetPrinterDriverA failed for %s, fix your config!\n", lpPrinterInfo
->pPrinterName
);
2593 needed
= DocumentPropertiesA(0, 0, name
, NULL
, NULL
, 0);
2595 ERR("DocumentProperties fails on %s\n", debugstr_a(name
));
2598 pDevMode
= HeapAlloc(GetProcessHeap(), 0, needed
);
2599 DocumentPropertiesA(0, 0, name
, pDevMode
, NULL
, DM_OUT_BUFFER
);
2601 pda
->pdlg
.hDevMode
= GlobalReAlloc(pda
->pdlg
.hDevMode
,
2602 pDevMode
->dmSize
+ pDevMode
->dmDriverExtra
,
2604 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2605 memcpy(dm
, pDevMode
, pDevMode
->dmSize
+ pDevMode
->dmDriverExtra
);
2607 PRINTDLG_CreateDevNames(&(pda
->pdlg
.hDevNames
),
2608 lpDriverInfo
->pDriverPath
,
2609 lpPrinterInfo
->pPrinterName
,
2610 lpPrinterInfo
->pPortName
);
2612 GlobalUnlock(pda
->pdlg
.hDevMode
);
2613 HeapFree(GetProcessHeap(), 0, pDevMode
);
2614 HeapFree(GetProcessHeap(), 0, lpPrinterInfo
);
2615 HeapFree(GetProcessHeap(), 0, lpDriverInfo
);
2619 /****************************************************************************************
2620 * PRINTDLG_PS_ChangePrinterA
2622 * Fills Printers, Paper and Source combo
2628 PRINTDLG_PS_ChangePrinterA(HWND hDlg
, PageSetupDataA
*pda
) {
2631 LPSTR devname
,portname
;
2633 dn
= GlobalLock(pda
->pdlg
.hDevNames
);
2634 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2635 devname
= ((char*)dn
)+dn
->wDeviceOffset
;
2636 portname
= ((char*)dn
)+dn
->wOutputOffset
;
2637 PRINTDLG_SetUpPrinterListComboA(hDlg
, cmb1
, devname
);
2638 PRINTDLG_SetUpPaperComboBoxA(hDlg
,cmb2
,devname
,portname
,dm
);
2639 PRINTDLG_SetUpPaperComboBoxA(hDlg
,cmb3
,devname
,portname
,dm
);
2640 GlobalUnlock(pda
->pdlg
.hDevNames
);
2641 GlobalUnlock(pda
->pdlg
.hDevMode
);
2646 PRINTDLG_PS_ChangePrinterW(HWND hDlg
, PageSetupDataW
*pda
) {
2649 LPWSTR devname
,portname
;
2651 dn
= GlobalLock(pda
->pdlg
.hDevNames
);
2652 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2653 devname
= ((WCHAR
*)dn
)+dn
->wDeviceOffset
;
2654 portname
= ((WCHAR
*)dn
)+dn
->wOutputOffset
;
2655 PRINTDLG_SetUpPaperComboBoxW(hDlg
,cmb2
,devname
,portname
,dm
);
2656 PRINTDLG_SetUpPaperComboBoxW(hDlg
,cmb3
,devname
,portname
,dm
);
2657 GlobalUnlock(pda
->pdlg
.hDevNames
);
2658 GlobalUnlock(pda
->pdlg
.hDevMode
);
2662 /******************************************************************************************
2663 * PRINTDLG_PS_ChangePaperPrev
2665 * Changes paper preview size / position
2668 * pda [i] Pointer for current PageSetupDataA structure
2674 PRINTDLG_PS_ChangePaperPrev(PageSetupDataA
*pda
)
2676 LONG width
, height
, x
, y
;
2679 if(pda
->curdlg
.ptPaperSize
.x
> pda
->curdlg
.ptPaperSize
.y
) {
2680 width
= pda
->rtDrawRect
.right
- pda
->rtDrawRect
.left
;
2681 height
= pda
->curdlg
.ptPaperSize
.y
* width
/ pda
->curdlg
.ptPaperSize
.x
;
2683 height
= pda
->rtDrawRect
.bottom
- pda
->rtDrawRect
.top
;
2684 width
= pda
->curdlg
.ptPaperSize
.x
* height
/ pda
->curdlg
.ptPaperSize
.y
;
2686 x
= (pda
->rtDrawRect
.right
+ pda
->rtDrawRect
.left
- width
) / 2;
2687 y
= (pda
->rtDrawRect
.bottom
+ pda
->rtDrawRect
.top
- height
) / 2;
2688 TRACE("rtDrawRect(%ld, %ld, %ld, %ld) x=%ld, y=%ld, w=%ld, h=%ld",
2689 pda
->rtDrawRect
.left
, pda
->rtDrawRect
.top
, pda
->rtDrawRect
.right
, pda
->rtDrawRect
.bottom
,
2690 x
, y
, width
, height
);
2693 MoveWindow(GetDlgItem(pda
->hDlg
, rct2
), x
+width
, y
+SHADOW
, SHADOW
, height
, FALSE
);
2694 MoveWindow(GetDlgItem(pda
->hDlg
, rct3
), x
+SHADOW
, y
+height
, width
, SHADOW
, FALSE
);
2695 MoveWindow(GetDlgItem(pda
->hDlg
, rct1
), x
, y
, width
, height
, FALSE
);
2696 memcpy(&rtTmp
, &pda
->rtDrawRect
, sizeof(RECT
));
2697 rtTmp
.right
+= SHADOW
;
2698 rtTmp
.bottom
+= SHADOW
;
2701 InvalidateRect(pda
->hDlg
, &rtTmp
, TRUE
);
2705 #define GETVAL(idc,val) \
2706 if(msg == EN_CHANGE){ \
2707 if (GetDlgItemTextA(hDlg,idc,buf,sizeof(buf)) > 0)\
2708 val = _c_str2sizeA(pda->dlga,buf); \
2710 FIXME("could not get dlgitemtexta for %x\n",id); \
2713 /********************************************************************************
2714 * PRINTDLG_PS_WMCommandA
2715 * process WM_COMMAND message for PageSetupDlgA
2718 * hDlg [in] Main dialog HANDLE
2719 * wParam [in] WM_COMMAND wParam
2720 * lParam [in] WM_COMMAND lParam
2721 * pda [in/out] ptr to PageSetupDataA
2725 PRINTDLG_PS_WMCommandA(
2726 HWND hDlg
, WPARAM wParam
, LPARAM lParam
, PageSetupDataA
*pda
2728 WORD msg
= HIWORD(wParam
);
2729 WORD id
= LOWORD(wParam
);
2732 TRACE("loword (lparam) %d, wparam 0x%x, lparam %08lx\n",
2733 LOWORD(lParam
),wParam
,lParam
);
2736 if (!PRINTDLG_PS_UpdateDlgStructA(hDlg
, pda
))
2738 EndDialog(hDlg
, TRUE
);
2742 EndDialog(hDlg
, FALSE
);
2746 pda
->pdlg
.Flags
= 0;
2747 pda
->pdlg
.hwndOwner
= hDlg
;
2748 if (PrintDlgA(&(pda
->pdlg
)))
2749 PRINTDLG_PS_ChangePrinterA(hDlg
,pda
);
2753 if (pda
->curdlg
.ptPaperSize
.x
> pda
->curdlg
.ptPaperSize
.y
){
2754 DWORD tmp
= pda
->curdlg
.ptPaperSize
.x
;
2755 pda
->curdlg
.ptPaperSize
.x
= pda
->curdlg
.ptPaperSize
.y
;
2756 pda
->curdlg
.ptPaperSize
.y
= tmp
;
2758 PRINTDLG_PS_ChangePaperPrev(pda
);
2761 if (pda
->curdlg
.ptPaperSize
.y
> pda
->curdlg
.ptPaperSize
.x
){
2762 DWORD tmp
= pda
->curdlg
.ptPaperSize
.x
;
2763 pda
->curdlg
.ptPaperSize
.x
= pda
->curdlg
.ptPaperSize
.y
;
2764 pda
->curdlg
.ptPaperSize
.y
= tmp
;
2766 PRINTDLG_PS_ChangePaperPrev(pda
);
2768 case cmb1
: /* Printer combo */
2769 if(msg
== CBN_SELCHANGE
){
2770 char crPrinterName
[256];
2771 GetDlgItemTextA(hDlg
, id
, crPrinterName
, 255);
2772 PRINTDLG_PS_ChangeActivePrinterA(crPrinterName
, pda
);
2773 PRINTDLG_PS_ChangePrinterA(hDlg
, pda
);
2776 case cmb2
: /* Paper combo */
2777 if(msg
== CBN_SELCHANGE
){
2778 DWORD paperword
= SendDlgItemMessageA(hDlg
,cmb2
,CB_GETITEMDATA
,
2779 SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0), 0);
2780 if (paperword
!= CB_ERR
) {
2781 PRINTDLG_PaperSizeA(&(pda
->pdlg
), paperword
,&(pda
->curdlg
.ptPaperSize
));
2782 pda
->curdlg
.ptPaperSize
.x
= _c_10mm2size(pda
->dlga
,pda
->curdlg
.ptPaperSize
.x
);
2783 pda
->curdlg
.ptPaperSize
.y
= _c_10mm2size(pda
->dlga
,pda
->curdlg
.ptPaperSize
.y
);
2785 if (IsDlgButtonChecked(hDlg
, rad2
)) {
2786 DWORD tmp
= pda
->curdlg
.ptPaperSize
.x
;
2787 pda
->curdlg
.ptPaperSize
.x
= pda
->curdlg
.ptPaperSize
.y
;
2788 pda
->curdlg
.ptPaperSize
.y
= tmp
;
2790 PRINTDLG_PS_ChangePaperPrev(pda
);
2792 FIXME("could not get dialog text for papersize cmbbox?\n");
2796 if(msg
== CBN_SELCHANGE
){
2797 DEVMODEA
*dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2798 dm
->dmDefaultSource
= SendDlgItemMessageA(hDlg
, cmb3
,CB_GETITEMDATA
,
2799 SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0), 0);
2800 GlobalUnlock(pda
->pdlg
.hDevMode
);
2803 case psh2
: /* Printer Properties button */
2806 char PrinterName
[256];
2811 GetDlgItemTextA(hDlg
, cmb1
, PrinterName
, 255);
2812 if (!OpenPrinterA(PrinterName
, &hPrinter
, NULL
)) {
2813 FIXME("Call to OpenPrinter did not succeed!\n");
2816 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2817 DocumentPropertiesA(hDlg
, hPrinter
, PrinterName
, dm
, dm
,
2818 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
2819 ClosePrinter(hPrinter
);
2820 /* Changing paper */
2821 PRINTDLG_PaperSizeA(&(pda
->pdlg
), dm
->u1
.s1
.dmPaperSize
, &(pda
->curdlg
.ptPaperSize
));
2822 pda
->curdlg
.ptPaperSize
.x
= _c_10mm2size(pda
->dlga
, pda
->curdlg
.ptPaperSize
.x
);
2823 pda
->curdlg
.ptPaperSize
.y
= _c_10mm2size(pda
->dlga
, pda
->curdlg
.ptPaperSize
.y
);
2824 if (dm
->u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
){
2825 DWORD tmp
= pda
->curdlg
.ptPaperSize
.x
;
2826 pda
->curdlg
.ptPaperSize
.x
= pda
->curdlg
.ptPaperSize
.y
;
2827 pda
->curdlg
.ptPaperSize
.y
= tmp
;
2828 CheckRadioButton(hDlg
, rad1
, rad2
, rad2
);
2831 CheckRadioButton(hDlg
, rad1
, rad2
, rad1
);
2832 /* Changing paper preview */
2833 PRINTDLG_PS_ChangePaperPrev(pda
);
2834 /* Selecting paper in combo */
2835 count
= SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCOUNT
, 0, 0);
2836 if(count
!= CB_ERR
){
2837 for(i
=0; i
<count
; ++i
){
2838 if(SendDlgItemMessageA(hDlg
, cmb2
, CB_GETITEMDATA
, i
, 0) == dm
->u1
.s1
.dmPaperSize
) {
2839 SendDlgItemMessageA(hDlg
, cmb2
, CB_SETCURSEL
, i
, 0);
2845 GlobalUnlock(pda
->pdlg
.hDevMode
);
2849 GETVAL(id
, pda
->curdlg
.rtMargin
.left
);
2852 GETVAL(id
, pda
->curdlg
.rtMargin
.right
);
2855 GETVAL(id
, pda
->curdlg
.rtMargin
.top
);
2858 GETVAL(id
, pda
->curdlg
.rtMargin
.bottom
);
2861 InvalidateRect(GetDlgItem(hDlg
, rct1
), NULL
, TRUE
);
2867 PRINTDLG_PS_WMCommandW(
2868 HWND hDlg
, WPARAM wParam
, LPARAM lParam
, PageSetupDataW
*pda
2870 TRACE("loword (lparam) %d, wparam 0x%x, lparam %08lx\n",
2871 LOWORD(lParam
),wParam
,lParam
);
2872 switch (LOWORD(wParam
)) {
2874 if (!PRINTDLG_PS_UpdateDlgStructW(hDlg
, pda
))
2876 EndDialog(hDlg
, TRUE
);
2880 EndDialog(hDlg
, FALSE
);
2884 pda
->pdlg
.Flags
= 0;
2885 pda
->pdlg
.hwndOwner
= hDlg
;
2886 if (PrintDlgW(&(pda
->pdlg
)))
2887 PRINTDLG_PS_ChangePrinterW(hDlg
,pda
);
2895 /***********************************************************************
2896 * DefaultPagePaintHook
2897 * Default hook paint procedure that receives WM_PSD_* messages from the dialog box
2898 * whenever the sample page is redrawn.
2902 PRINTDLG_DefaultPagePaintHook(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, PageSetupDataA
*pda
)
2904 LPRECT lprc
= (LPRECT
) lParam
;
2905 HDC hdc
= (HDC
) wParam
;
2908 HFONT hfont
, holdfont
;
2910 TRACE("uMsg: WM_USER+%d\n",uMsg
-WM_USER
);
2911 /* Call user paint hook if enable */
2912 if (pda
->dlga
->Flags
& PSD_ENABLEPAGEPAINTHOOK
)
2913 if (pda
->dlga
->lpfnPagePaintHook(hwndDlg
, uMsg
, wParam
, lParam
))
2917 /* LPPAGESETUPDLG in lParam */
2918 case WM_PSD_PAGESETUPDLG
:
2919 /* Inform about the sample page rectangle */
2920 case WM_PSD_FULLPAGERECT
:
2921 /* Inform about the margin rectangle */
2922 case WM_PSD_MINMARGINRECT
:
2925 /* Draw dashed rectangle showing margins */
2926 case WM_PSD_MARGINRECT
:
2927 hpen
= CreatePen(PS_DASH
, 1, GetSysColor(COLOR_3DSHADOW
));
2928 holdpen
= SelectObject(hdc
, hpen
);
2929 Rectangle(hdc
, lprc
->left
, lprc
->top
, lprc
->right
, lprc
->bottom
);
2930 DeleteObject(SelectObject(hdc
, holdpen
));
2932 /* Draw the fake document */
2933 case WM_PSD_GREEKTEXTRECT
:
2934 /* select a nice scalable font, because we want the text really small */
2935 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, sizeof(lf
), &lf
, 0);
2936 lf
.lfHeight
= 6; /* value chosen based on visual effect */
2937 hfont
= CreateFontIndirectW(&lf
);
2938 holdfont
= SelectObject(hdc
, hfont
);
2940 /* if text not loaded, then do so now */
2941 if (wszFakeDocumentText
[0] == '\0')
2942 LoadStringW(COMDLG32_hInstance
,
2944 wszFakeDocumentText
,
2945 sizeof(wszFakeDocumentText
)/sizeof(wszFakeDocumentText
[0]));
2947 oldbkmode
= SetBkMode(hdc
, TRANSPARENT
);
2948 DrawTextW(hdc
, wszFakeDocumentText
, -1, lprc
, DT_TOP
|DT_LEFT
|DT_NOPREFIX
|DT_WORDBREAK
);
2949 SetBkMode(hdc
, oldbkmode
);
2951 DeleteObject(SelectObject(hdc
, holdfont
));
2954 /* Envelope stamp */
2955 case WM_PSD_ENVSTAMPRECT
:
2956 /* Return address */
2957 case WM_PSD_YAFULLPAGERECT
:
2958 FIXME("envelope/stamp is not implemented\n");
2961 FIXME("Unknown message %x\n",uMsg
);
2967 /***********************************************************************
2969 * The main paint procedure for the PageSetupDlg function.
2970 * The Page Setup dialog box includes an image of a sample page that shows how
2971 * the user's selections affect the appearance of the printed output.
2972 * The image consists of a rectangle that represents the selected paper
2973 * or envelope type, with a dotted-line rectangle representing
2974 * the current margins, and partial (Greek text) characters
2975 * to show how text looks on the printed page.
2977 * The following messages in the order sends to user hook procedure:
2978 * WM_PSD_PAGESETUPDLG Draw the contents of the sample page
2979 * WM_PSD_FULLPAGERECT Inform about the bounding rectangle
2980 * WM_PSD_MINMARGINRECT Inform about the margin rectangle (min margin?)
2981 * WM_PSD_MARGINRECT Draw the margin rectangle
2982 * WM_PSD_GREEKTEXTRECT Draw the Greek text inside the margin rectangle
2983 * If any of first three messages returns TRUE, painting done.
2986 * hWnd [in] Handle to the Page Setup dialog box
2987 * uMsg [in] Received message
2990 * WM_PSD_ENVSTAMPRECT Draw in the envelope-stamp rectangle (for envelopes only)
2991 * WM_PSD_YAFULLPAGERECT Draw the return address portion (for envelopes and other paper sizes)
2994 * FALSE if all done correctly
2999 static LRESULT CALLBACK
3000 PRINTDLG_PagePaintProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3003 RECT rcClient
, rcMargin
;
3006 HBRUSH hbrush
, holdbrush
;
3007 PageSetupDataA
*pda
;
3008 int papersize
=0, orientation
=0; /* FIXME: set this values for user paint hook */
3009 double scalx
, scaly
;
3010 #define CALLPAINTHOOK(msg,lprc) PRINTDLG_DefaultPagePaintHook( hWnd, msg, (WPARAM)hdc, (LPARAM)lprc, pda)
3012 if (uMsg
!= WM_PAINT
)
3013 return CallWindowProcA(lpfnStaticWndProc
, hWnd
, uMsg
, wParam
, lParam
);
3015 /* Processing WM_PAINT message */
3016 pda
= (PageSetupDataA
*)GetPropA(hWnd
, "__WINE_PAGESETUPDLGDATA");
3018 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3021 if (PRINTDLG_DefaultPagePaintHook(hWnd
, WM_PSD_PAGESETUPDLG
, MAKELONG(papersize
, orientation
), (LPARAM
)pda
->dlga
, pda
))
3024 hdc
= BeginPaint(hWnd
, &ps
);
3025 GetClientRect(hWnd
, &rcClient
);
3027 scalx
= rcClient
.right
/ (double)pda
->curdlg
.ptPaperSize
.x
;
3028 scaly
= rcClient
.bottom
/ (double)pda
->curdlg
.ptPaperSize
.y
;
3029 rcMargin
= rcClient
;
3031 rcMargin
.left
+= (LONG
)pda
->curdlg
.rtMargin
.left
* scalx
;
3032 rcMargin
.top
+= (LONG
)pda
->curdlg
.rtMargin
.top
* scalx
;
3033 rcMargin
.right
-= (LONG
)pda
->curdlg
.rtMargin
.right
* scaly
;
3034 rcMargin
.bottom
-= (LONG
)pda
->curdlg
.rtMargin
.bottom
* scaly
;
3036 /* if the space is too small then we make sure to not draw anything */
3037 rcMargin
.left
= min(rcMargin
.left
, rcMargin
.right
);
3038 rcMargin
.top
= min(rcMargin
.top
, rcMargin
.bottom
);
3040 if (!CALLPAINTHOOK(WM_PSD_FULLPAGERECT
, &rcClient
) &&
3041 !CALLPAINTHOOK(WM_PSD_MINMARGINRECT
, &rcMargin
) )
3043 /* fill background */
3044 hbrush
= GetSysColorBrush(COLOR_3DHIGHLIGHT
);
3045 FillRect(hdc
, &rcClient
, hbrush
);
3046 holdbrush
= SelectObject(hdc
, hbrush
);
3048 hpen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DSHADOW
));
3049 holdpen
= SelectObject(hdc
, hpen
);
3051 /* paint left edge */
3052 MoveToEx(hdc
, rcClient
.left
, rcClient
.top
, NULL
);
3053 LineTo(hdc
, rcClient
.left
, rcClient
.bottom
-1);
3055 /* paint top edge */
3056 MoveToEx(hdc
, rcClient
.left
, rcClient
.top
, NULL
);
3057 LineTo(hdc
, rcClient
.right
, rcClient
.top
);
3059 hpen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DDKSHADOW
));
3060 DeleteObject(SelectObject(hdc
, hpen
));
3062 /* paint right edge */
3063 MoveToEx(hdc
, rcClient
.right
-1, rcClient
.top
, NULL
);
3064 LineTo(hdc
, rcClient
.right
-1, rcClient
.bottom
);
3066 /* paint bottom edge */
3067 MoveToEx(hdc
, rcClient
.left
, rcClient
.bottom
-1, NULL
);
3068 LineTo(hdc
, rcClient
.right
, rcClient
.bottom
-1);
3070 DeleteObject(SelectObject(hdc
, holdpen
));
3071 DeleteObject(SelectObject(hdc
, holdbrush
));
3073 CALLPAINTHOOK(WM_PSD_MARGINRECT
, &rcMargin
);
3075 /* give text a bit of a space from the frame */
3078 rcMargin
.right
-= 2;
3079 rcMargin
.bottom
-= 2;
3081 /* if the space is too small then we make sure to not draw anything */
3082 rcMargin
.left
= min(rcMargin
.left
, rcMargin
.right
);
3083 rcMargin
.top
= min(rcMargin
.top
, rcMargin
.bottom
);
3085 CALLPAINTHOOK(WM_PSD_GREEKTEXTRECT
, &rcMargin
);
3088 EndPaint(hWnd
, &ps
);
3090 #undef CALLPAINTHOOK
3093 /***********************************************************************
3094 * PRINTDLG_PageDlgProcA
3095 * Message handler for PageSetupDlgA
3097 static INT_PTR CALLBACK
3098 PRINTDLG_PageDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3101 PageSetupDataA
*pda
;
3102 INT_PTR res
= FALSE
;
3105 if (uMsg
== WM_INITDIALOG
) { /*Init dialog*/
3106 pda
= (PageSetupDataA
*)lParam
;
3107 pda
->hDlg
= hDlg
; /* saving handle to main window to PageSetupDataA structure */
3108 memcpy(&pda
->curdlg
, pda
->dlga
, sizeof(pda
->curdlg
));
3110 hDrawWnd
= GetDlgItem(hDlg
, rct1
);
3111 TRACE("set property to %p", pda
);
3112 SetPropA(hDlg
, "__WINE_PAGESETUPDLGDATA", pda
);
3113 SetPropA(hDrawWnd
, "__WINE_PAGESETUPDLGDATA", pda
);
3114 GetWindowRect(hDrawWnd
, &pda
->rtDrawRect
); /* Calculating rect in client coordinates where paper draws */
3115 ScreenToClient(hDlg
, (LPPOINT
)&pda
->rtDrawRect
);
3116 ScreenToClient(hDlg
, (LPPOINT
)(&pda
->rtDrawRect
.right
));
3117 lpfnStaticWndProc
= (WNDPROC
)SetWindowLongPtrW(
3120 (ULONG_PTR
)PRINTDLG_PagePaintProc
);
3122 /* FIXME: Paint hook. Must it be at begin of initializtion or at end? */
3124 if (pda
->dlga
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
3125 if (!pda
->dlga
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,(LPARAM
)pda
->dlga
))
3126 FIXME("Setup page hook failed?\n");
3129 /* if printer button disabled */
3130 if (pda
->dlga
->Flags
& PSD_DISABLEPRINTER
)
3131 EnableWindow(GetDlgItem(hDlg
, psh3
), FALSE
);
3132 /* if margin edit boxes disabled */
3133 if (pda
->dlga
->Flags
& PSD_DISABLEMARGINS
) {
3134 EnableWindow(GetDlgItem(hDlg
, edt4
), FALSE
);
3135 EnableWindow(GetDlgItem(hDlg
, edt5
), FALSE
);
3136 EnableWindow(GetDlgItem(hDlg
, edt6
), FALSE
);
3137 EnableWindow(GetDlgItem(hDlg
, edt7
), FALSE
);
3139 /* Set orientation radiobutton properly */
3140 dm
= GlobalLock(pda
->dlga
->hDevMode
);
3141 if (dm
->u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
)
3142 CheckRadioButton(hDlg
, rad1
, rad2
, rad2
);
3143 else /* this is default if papersize is not set */
3144 CheckRadioButton(hDlg
, rad1
, rad2
, rad1
);
3145 GlobalUnlock(pda
->dlga
->hDevMode
);
3147 /* if orientation disabled */
3148 if (pda
->dlga
->Flags
& PSD_DISABLEORIENTATION
) {
3149 EnableWindow(GetDlgItem(hDlg
,rad1
),FALSE
);
3150 EnableWindow(GetDlgItem(hDlg
,rad2
),FALSE
);
3152 /* We fill them out enabled or not */
3153 if (pda
->dlga
->Flags
& PSD_MARGINS
) {
3155 _c_size2strA(pda
,pda
->dlga
->rtMargin
.left
,str
);
3156 SetDlgItemTextA(hDlg
,edt4
,str
);
3157 _c_size2strA(pda
,pda
->dlga
->rtMargin
.top
,str
);
3158 SetDlgItemTextA(hDlg
,edt5
,str
);
3159 _c_size2strA(pda
,pda
->dlga
->rtMargin
.right
,str
);
3160 SetDlgItemTextA(hDlg
,edt6
,str
);
3161 _c_size2strA(pda
,pda
->dlga
->rtMargin
.bottom
,str
);
3162 SetDlgItemTextA(hDlg
,edt7
,str
);
3164 /* default is 1 inch */
3165 DWORD size
= _c_inch2size(pda
->dlga
,1000);
3167 _c_size2strA(pda
,size
,str
);
3168 SetDlgItemTextA(hDlg
,edt4
,str
);
3169 SetDlgItemTextA(hDlg
,edt5
,str
);
3170 SetDlgItemTextA(hDlg
,edt6
,str
);
3171 SetDlgItemTextA(hDlg
,edt7
,str
);
3172 pda
->curdlg
.rtMargin
.left
= size
;
3173 pda
->curdlg
.rtMargin
.top
= size
;
3174 pda
->curdlg
.rtMargin
.right
= size
;
3175 pda
->curdlg
.rtMargin
.bottom
= size
;
3177 /* if paper disabled */
3178 if (pda
->dlga
->Flags
& PSD_DISABLEPAPER
) {
3179 EnableWindow(GetDlgItem(hDlg
,cmb2
),FALSE
);
3180 EnableWindow(GetDlgItem(hDlg
,cmb3
),FALSE
);
3182 /* filling combos: printer, paper, source. selecting current printer (from DEVMODEA) */
3183 PRINTDLG_PS_ChangePrinterA(hDlg
, pda
);
3184 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
3186 dm
->dmDefaultSource
= 15; /*FIXME: Automatic select. Does it always 15 at start? */
3187 PRINTDLG_PaperSizeA(&(pda
->pdlg
), dm
->u1
.s1
.dmPaperSize
, &pda
->curdlg
.ptPaperSize
);
3188 GlobalUnlock(pda
->pdlg
.hDevMode
);
3189 pda
->curdlg
.ptPaperSize
.x
= _c_10mm2size(pda
->dlga
, pda
->curdlg
.ptPaperSize
.x
);
3190 pda
->curdlg
.ptPaperSize
.y
= _c_10mm2size(pda
->dlga
, pda
->curdlg
.ptPaperSize
.y
);
3191 if (IsDlgButtonChecked(hDlg
, rad2
) == BST_CHECKED
) { /* Landscape orientation */
3192 DWORD tmp
= pda
->curdlg
.ptPaperSize
.y
;
3193 pda
->curdlg
.ptPaperSize
.y
= pda
->curdlg
.ptPaperSize
.x
;
3194 pda
->curdlg
.ptPaperSize
.x
= tmp
;
3197 WARN("GlobalLock(pda->pdlg.hDevMode) fail? hDevMode=%p", pda
->pdlg
.hDevMode
);
3198 /* Drawing paper prev */
3199 PRINTDLG_PS_ChangePaperPrev(pda
);
3202 pda
= (PageSetupDataA
*)GetPropA(hDlg
,"__WINE_PAGESETUPDLGDATA");
3204 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3207 if (pda
->dlga
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
3208 res
= pda
->dlga
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,lParam
);
3209 if (res
) return res
;
3214 return PRINTDLG_PS_WMCommandA(hDlg
, wParam
, lParam
, pda
);
3219 static INT_PTR CALLBACK
3220 PageDlgProcW(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3222 static const WCHAR __WINE_PAGESETUPDLGDATA
[] =
3223 { '_', '_', 'W', 'I', 'N', 'E', '_', 'P', 'A', 'G', 'E',
3224 'S', 'E', 'T', 'U', 'P', 'D', 'L', 'G', 'D', 'A', 'T', 'A', 0 };
3225 PageSetupDataW
*pda
;
3228 if (uMsg
==WM_INITDIALOG
) {
3230 pda
= (PageSetupDataW
*)lParam
;
3231 SetPropW(hDlg
, __WINE_PAGESETUPDLGDATA
, pda
);
3232 if (pda
->dlga
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
3233 res
= pda
->dlga
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,(LPARAM
)pda
->dlga
);
3235 FIXME("Setup page hook failed?\n");
3240 if (pda
->dlga
->Flags
& PSD_ENABLEPAGEPAINTHOOK
) {
3241 FIXME("PagePaintHook not yet implemented!\n");
3243 if (pda
->dlga
->Flags
& PSD_DISABLEPRINTER
)
3244 EnableWindow(GetDlgItem(hDlg
, psh3
), FALSE
);
3245 if (pda
->dlga
->Flags
& PSD_DISABLEMARGINS
) {
3246 EnableWindow(GetDlgItem(hDlg
, edt4
), FALSE
);
3247 EnableWindow(GetDlgItem(hDlg
, edt5
), FALSE
);
3248 EnableWindow(GetDlgItem(hDlg
, edt6
), FALSE
);
3249 EnableWindow(GetDlgItem(hDlg
, edt7
), FALSE
);
3251 /* width larger as height -> landscape */
3252 if (pda
->dlga
->ptPaperSize
.x
> pda
->dlga
->ptPaperSize
.y
)
3253 CheckRadioButton(hDlg
, rad1
, rad2
, rad2
);
3254 else /* this is default if papersize is not set */
3255 CheckRadioButton(hDlg
, rad1
, rad2
, rad1
);
3256 if (pda
->dlga
->Flags
& PSD_DISABLEORIENTATION
) {
3257 EnableWindow(GetDlgItem(hDlg
,rad1
),FALSE
);
3258 EnableWindow(GetDlgItem(hDlg
,rad2
),FALSE
);
3260 /* We fill them out enabled or not */
3261 if (pda
->dlga
->Flags
& PSD_MARGINS
) {
3263 _c_size2strW(pda
,pda
->dlga
->rtMargin
.left
,str
);
3264 SetDlgItemTextW(hDlg
,edt4
,str
);
3265 _c_size2strW(pda
,pda
->dlga
->rtMargin
.top
,str
);
3266 SetDlgItemTextW(hDlg
,edt5
,str
);
3267 _c_size2strW(pda
,pda
->dlga
->rtMargin
.right
,str
);
3268 SetDlgItemTextW(hDlg
,edt6
,str
);
3269 _c_size2strW(pda
,pda
->dlga
->rtMargin
.bottom
,str
);
3270 SetDlgItemTextW(hDlg
,edt7
,str
);
3272 /* default is 1 inch */
3273 DWORD size
= _c_inch2size((LPPAGESETUPDLGA
)pda
->dlga
,1000);
3275 _c_size2strW(pda
,size
,str
);
3276 SetDlgItemTextW(hDlg
,edt4
,str
);
3277 SetDlgItemTextW(hDlg
,edt5
,str
);
3278 SetDlgItemTextW(hDlg
,edt6
,str
);
3279 SetDlgItemTextW(hDlg
,edt7
,str
);
3281 PRINTDLG_PS_ChangePrinterW(hDlg
,pda
);
3282 if (pda
->dlga
->Flags
& PSD_DISABLEPAPER
) {
3283 EnableWindow(GetDlgItem(hDlg
,cmb2
),FALSE
);
3284 EnableWindow(GetDlgItem(hDlg
,cmb3
),FALSE
);
3289 pda
= (PageSetupDataW
*)GetPropW(hDlg
, __WINE_PAGESETUPDLGDATA
);
3291 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3294 if (pda
->dlga
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
3295 res
= pda
->dlga
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,lParam
);
3296 if (res
) return res
;
3301 return PRINTDLG_PS_WMCommandW(hDlg
, wParam
, lParam
, pda
);
3306 /***********************************************************************
3307 * PageSetupDlgA (COMDLG32.@)
3309 * Displays the the PAGE SETUP dialog box, which enables the user to specify
3310 * specific properties of a printed page such as
3311 * size, source, orientation and the width of the page margins.
3314 * setupdlg [IO] PAGESETUPDLGA struct
3317 * TRUE if the user pressed the OK button
3318 * FALSE if the user cancelled the window or an error occurred
3321 * The values of hDevMode and hDevNames are filled on output and can be
3322 * changed in PAGESETUPDLG when they are passed in PageSetupDlg.
3326 BOOL WINAPI
PageSetupDlgA(LPPAGESETUPDLGA setupdlg
) {
3330 PageSetupDataA
*pda
;
3334 if(TRACE_ON(commdlg
)) {
3335 char flagstr
[1000] = "";
3336 struct pd_flags
*pflag
= psd_flags
;
3337 for( ; pflag
->name
; pflag
++) {
3338 if(setupdlg
->Flags
& pflag
->flag
) {
3339 strcat(flagstr
, pflag
->name
);
3340 strcat(flagstr
, "|");
3343 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3344 "hinst %p, flags %08lx (%s)\n",
3345 setupdlg
, setupdlg
->hwndOwner
, setupdlg
->hDevMode
,
3346 setupdlg
->hDevNames
,
3347 setupdlg
->hInstance
, setupdlg
->Flags
, flagstr
);
3349 /* Checking setupdlg structure */
3350 if (setupdlg
== NULL
) {
3351 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
3354 if(setupdlg
->lStructSize
!= sizeof(PAGESETUPDLGA
)) {
3355 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
3358 if ((setupdlg
->Flags
& PSD_ENABLEPAGEPAINTHOOK
) &&
3359 (setupdlg
->lpfnPagePaintHook
== NULL
)) {
3360 COMDLG32_SetCommDlgExtendedError(CDERR_NOHOOK
);
3364 /* First get default printer data, we need it right after that. */
3365 memset(&pdlg
,0,sizeof(pdlg
));
3366 pdlg
.lStructSize
= sizeof(pdlg
);
3367 pdlg
.Flags
= PD_RETURNDEFAULT
;
3368 bRet
= PrintDlgA(&pdlg
);
3370 if(!(setupdlg
->Flags
& PSD_NOWARNING
)){
3372 LoadStringA(COMDLG32_hInstance
, PD32_NO_DEFAULT_PRINTER
, errstr
, 255);
3373 MessageBoxA(setupdlg
->hwndOwner
, errstr
, 0, MB_OK
| MB_ICONERROR
);
3378 /* short cut exit, just return default values */
3379 if (setupdlg
->Flags
& PSD_RETURNDEFAULT
) {
3382 dm
= GlobalLock(pdlg
.hDevMode
);
3383 PRINTDLG_PaperSizeA(&pdlg
, dm
->u1
.s1
.dmPaperSize
, &setupdlg
->ptPaperSize
);
3384 GlobalUnlock(pdlg
.hDevMode
);
3385 setupdlg
->ptPaperSize
.x
=_c_10mm2size(setupdlg
,setupdlg
->ptPaperSize
.x
);
3386 setupdlg
->ptPaperSize
.y
=_c_10mm2size(setupdlg
,setupdlg
->ptPaperSize
.y
);
3390 /* get dialog template */
3391 hDlgTmpl
= PRINTDLG_GetPGSTemplateA(setupdlg
);
3393 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
3396 ptr
= LockResource( hDlgTmpl
);
3398 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
3402 pda
= HeapAlloc(GetProcessHeap(),0,sizeof(*pda
));
3403 pda
->dlga
= setupdlg
;
3404 memcpy(&pda
->pdlg
,&pdlg
,sizeof(pdlg
));
3406 bRet
= (0<DialogBoxIndirectParamA(
3407 setupdlg
->hInstance
,
3409 setupdlg
->hwndOwner
,
3410 PRINTDLG_PageDlgProcA
,
3414 HeapFree(GetProcessHeap(),0,pda
);
3417 /***********************************************************************
3418 * PageSetupDlgW (COMDLG32.@)
3420 * See PageSetupDlgA.
3422 BOOL WINAPI
PageSetupDlgW(LPPAGESETUPDLGW setupdlg
) {
3426 PageSetupDataW
*pdw
;
3429 FIXME("Unicode implementation is not done yet\n");
3430 if(TRACE_ON(commdlg
)) {
3431 char flagstr
[1000] = "";
3432 struct pd_flags
*pflag
= psd_flags
;
3433 for( ; pflag
->name
; pflag
++) {
3434 if(setupdlg
->Flags
& pflag
->flag
) {
3435 strcat(flagstr
, pflag
->name
);
3436 strcat(flagstr
, "|");
3439 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3440 "hinst %p, flags %08lx (%s)\n",
3441 setupdlg
, setupdlg
->hwndOwner
, setupdlg
->hDevMode
,
3442 setupdlg
->hDevNames
,
3443 setupdlg
->hInstance
, setupdlg
->Flags
, flagstr
);
3446 /* First get default printer data, we need it right after that. */
3447 memset(&pdlg
,0,sizeof(pdlg
));
3448 pdlg
.lStructSize
= sizeof(pdlg
);
3449 pdlg
.Flags
= PD_RETURNDEFAULT
;
3450 bRet
= PrintDlgW(&pdlg
);
3451 if (!bRet
) return FALSE
;
3453 /* short cut exit, just return default values */
3454 if (setupdlg
->Flags
& PSD_RETURNDEFAULT
) {
3455 static const WCHAR a4
[] = {'A','4',0};
3456 setupdlg
->hDevMode
= pdlg
.hDevMode
;
3457 setupdlg
->hDevNames
= pdlg
.hDevNames
;
3458 /* FIXME: Just return "A4" for now. */
3459 PRINTDLG_PaperSizeW(&pdlg
,a4
,&setupdlg
->ptPaperSize
);
3460 setupdlg
->ptPaperSize
.x
=_c_10mm2size((LPPAGESETUPDLGA
)setupdlg
,setupdlg
->ptPaperSize
.x
);
3461 setupdlg
->ptPaperSize
.y
=_c_10mm2size((LPPAGESETUPDLGA
)setupdlg
,setupdlg
->ptPaperSize
.y
);
3464 hDlgTmpl
= PRINTDLG_GetPGSTemplateW(setupdlg
);
3466 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
3469 ptr
= LockResource( hDlgTmpl
);
3471 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
3474 pdw
= HeapAlloc(GetProcessHeap(),0,sizeof(*pdw
));
3475 pdw
->dlga
= setupdlg
;
3476 memcpy(&pdw
->pdlg
,&pdlg
,sizeof(pdlg
));
3478 bRet
= (0<DialogBoxIndirectParamW(
3479 setupdlg
->hInstance
,
3481 setupdlg
->hwndOwner
,
3488 /***********************************************************************
3489 * PrintDlgExA (COMDLG32.@)
3496 HRESULT WINAPI
PrintDlgExA(LPPRINTDLGEXA lpPrintDlgExA
)
3502 /***********************************************************************
3503 * PrintDlgExW (COMDLG32.@)
3505 * Display the the PRINT dialog box, which enables the user to specify
3506 * specific properties of the print job. The property sheet can also have
3507 * additional application-specific and driver-specific property pages.
3510 * lppd [IO] ptr to PRINTDLGEX struct
3514 * Failure: One of the following COM error codes:
3515 * E_OUTOFMEMORY Insufficient memory.
3516 * E_INVALIDARG One or more arguments are invalid.
3517 * E_POINTER Invalid pointer.
3518 * E_HANDLE Invalid handle.
3519 * E_FAIL Unspecified error.
3524 HRESULT WINAPI
PrintDlgExW(LPPRINTDLGEXW lpPrintDlgExW
)