2 * COMMDLG - Print Dialog
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
6 * Copyright 1999 Klaas van Gend
7 * Copyright 2000 Huw D M Davies
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #define NONAMELESSUNION
30 #define NONAMELESSSTRUCT
38 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(commdlg
);
49 /* Yes these constants are the same, but we're just copying win98 */
50 #define UPDOWN_ID 0x270f
51 #define MAX_COPIES 9999
54 static const struct pd_flags psd_flags
[] = {
55 {PSD_MINMARGINS
,"PSD_MINMARGINS"},
56 {PSD_MARGINS
,"PSD_MARGINS"},
57 {PSD_INTHOUSANDTHSOFINCHES
,"PSD_INTHOUSANDTHSOFINCHES"},
58 {PSD_INHUNDREDTHSOFMILLIMETERS
,"PSD_INHUNDREDTHSOFMILLIMETERS"},
59 {PSD_DISABLEMARGINS
,"PSD_DISABLEMARGINS"},
60 {PSD_DISABLEPRINTER
,"PSD_DISABLEPRINTER"},
61 {PSD_NOWARNING
,"PSD_NOWARNING"},
62 {PSD_DISABLEORIENTATION
,"PSD_DISABLEORIENTATION"},
63 {PSD_RETURNDEFAULT
,"PSD_RETURNDEFAULT"},
64 {PSD_DISABLEPAPER
,"PSD_DISABLEPAPER"},
65 {PSD_SHOWHELP
,"PSD_SHOWHELP"},
66 {PSD_ENABLEPAGESETUPHOOK
,"PSD_ENABLEPAGESETUPHOOK"},
67 {PSD_ENABLEPAGESETUPTEMPLATE
,"PSD_ENABLEPAGESETUPTEMPLATE"},
68 {PSD_ENABLEPAGESETUPTEMPLATEHANDLE
,"PSD_ENABLEPAGESETUPTEMPLATEHANDLE"},
69 {PSD_ENABLEPAGEPAINTHOOK
,"PSD_ENABLEPAGEPAINTHOOK"},
70 {PSD_DISABLEPAGEPAINTING
,"PSD_DISABLEPAGEPAINTING"},
74 /* address of wndproc for subclassed Static control */
75 static WNDPROC lpfnStaticWndProc
;
76 /* the text of the fake document to render for the Page Setup dialog */
77 static WCHAR wszFakeDocumentText
[1024];
79 /***********************************************************************
80 * PRINTDLG_OpenDefaultPrinter
82 * Returns a winspool printer handle to the default printer in *hprn
83 * Caller must call ClosePrinter on the handle
85 * Returns TRUE on success else FALSE
87 BOOL
PRINTDLG_OpenDefaultPrinter(HANDLE
*hprn
)
90 DWORD dwBufLen
= sizeof(buf
) / sizeof(buf
[0]);
92 if(!GetDefaultPrinterW(buf
, &dwBufLen
))
94 res
= OpenPrinterW(buf
, hprn
, NULL
);
96 WARN("Could not open printer %s\n", debugstr_w(buf
));
100 /***********************************************************************
101 * PRINTDLG_SetUpPrinterListCombo
103 * Initializes printer list combox.
104 * hDlg: HWND of dialog
105 * id: Control id of combo
106 * name: Name of printer to select
108 * Initializes combo with list of available printers. Selects printer 'name'
109 * If name is NULL or does not exist select the default printer.
111 * Returns number of printers added to list.
113 INT
PRINTDLG_SetUpPrinterListComboA(HWND hDlg
, UINT id
, LPCSTR name
)
117 LPPRINTER_INFO_2A pi
;
118 EnumPrintersA(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
119 pi
= HeapAlloc(GetProcessHeap(), 0, needed
);
120 EnumPrintersA(PRINTER_ENUM_LOCAL
, NULL
, 2, (LPBYTE
)pi
, needed
, &needed
,
123 SendDlgItemMessageA(hDlg
, id
, CB_RESETCONTENT
, 0, 0);
125 for(i
= 0; i
< num
; i
++) {
126 SendDlgItemMessageA(hDlg
, id
, CB_ADDSTRING
, 0,
127 (LPARAM
)pi
[i
].pPrinterName
);
129 HeapFree(GetProcessHeap(), 0, pi
);
131 (i
= SendDlgItemMessageA(hDlg
, id
, CB_FINDSTRINGEXACT
, -1,
132 (LPARAM
)name
)) == CB_ERR
) {
135 DWORD dwBufLen
= sizeof(buf
);
137 WARN("Can't find %s in printer list so trying to find default\n",
139 if(!GetDefaultPrinterA(buf
, &dwBufLen
))
141 i
= SendDlgItemMessageA(hDlg
, id
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buf
);
143 FIXME("Can't find default printer in printer list\n");
145 SendDlgItemMessageA(hDlg
, id
, CB_SETCURSEL
, i
, 0);
149 static INT
PRINTDLG_SetUpPrinterListComboW(HWND hDlg
, UINT id
, LPCWSTR name
)
153 LPPRINTER_INFO_2W pi
;
154 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
155 pi
= HeapAlloc(GetProcessHeap(), 0, needed
);
156 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, (LPBYTE
)pi
, needed
, &needed
,
159 for(i
= 0; i
< num
; i
++) {
160 SendDlgItemMessageW(hDlg
, id
, CB_ADDSTRING
, 0,
161 (LPARAM
)pi
[i
].pPrinterName
);
163 HeapFree(GetProcessHeap(), 0, pi
);
165 (i
= SendDlgItemMessageW(hDlg
, id
, CB_FINDSTRINGEXACT
, -1,
166 (LPARAM
)name
)) == CB_ERR
) {
168 DWORD dwBufLen
= sizeof(buf
)/sizeof(buf
[0]);
170 WARN("Can't find %s in printer list so trying to find default\n",
172 if(!GetDefaultPrinterW(buf
, &dwBufLen
))
174 i
= SendDlgItemMessageW(hDlg
, id
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)buf
);
176 TRACE("Can't find default printer in printer list\n");
178 SendDlgItemMessageW(hDlg
, id
, CB_SETCURSEL
, i
, 0);
182 /***********************************************************************
183 * PRINTDLG_CreateDevNames [internal]
186 * creates a DevNames structure.
188 * (NB. when we handle unicode the offsets will be in wchars).
190 static BOOL
PRINTDLG_CreateDevNames(HGLOBAL
*hmem
, const char* DeviceDriverName
,
191 const char* DeviceName
, const char* OutputPort
)
194 char* pDevNamesSpace
;
196 LPDEVNAMES lpDevNames
;
198 DWORD dwBufLen
= sizeof(buf
);
200 size
= strlen(DeviceDriverName
) + 1
201 + strlen(DeviceName
) + 1
202 + strlen(OutputPort
) + 1
206 *hmem
= GlobalReAlloc(*hmem
, size
, GMEM_MOVEABLE
);
208 *hmem
= GlobalAlloc(GMEM_MOVEABLE
, size
);
212 pDevNamesSpace
= GlobalLock(*hmem
);
213 lpDevNames
= (LPDEVNAMES
) pDevNamesSpace
;
215 pTempPtr
= pDevNamesSpace
+ sizeof(DEVNAMES
);
216 strcpy(pTempPtr
, DeviceDriverName
);
217 lpDevNames
->wDriverOffset
= pTempPtr
- pDevNamesSpace
;
219 pTempPtr
+= strlen(DeviceDriverName
) + 1;
220 strcpy(pTempPtr
, DeviceName
);
221 lpDevNames
->wDeviceOffset
= pTempPtr
- pDevNamesSpace
;
223 pTempPtr
+= strlen(DeviceName
) + 1;
224 strcpy(pTempPtr
, OutputPort
);
225 lpDevNames
->wOutputOffset
= pTempPtr
- pDevNamesSpace
;
227 GetDefaultPrinterA(buf
, &dwBufLen
);
228 lpDevNames
->wDefault
= (strcmp(buf
, DeviceName
) == 0) ? 1 : 0;
233 static BOOL
PRINTDLG_CreateDevNamesW(HGLOBAL
*hmem
, LPCWSTR DeviceDriverName
,
234 LPCWSTR DeviceName
, LPCWSTR OutputPort
)
237 LPWSTR pDevNamesSpace
;
239 LPDEVNAMES lpDevNames
;
241 DWORD dwBufLen
= sizeof(bufW
) / sizeof(WCHAR
);
243 size
= sizeof(WCHAR
)*lstrlenW(DeviceDriverName
) + 2
244 + sizeof(WCHAR
)*lstrlenW(DeviceName
) + 2
245 + sizeof(WCHAR
)*lstrlenW(OutputPort
) + 2
249 *hmem
= GlobalReAlloc(*hmem
, size
, GMEM_MOVEABLE
);
251 *hmem
= GlobalAlloc(GMEM_MOVEABLE
, size
);
255 pDevNamesSpace
= GlobalLock(*hmem
);
256 lpDevNames
= (LPDEVNAMES
) pDevNamesSpace
;
258 pTempPtr
= (LPWSTR
)((LPDEVNAMES
)pDevNamesSpace
+ 1);
259 lstrcpyW(pTempPtr
, DeviceDriverName
);
260 lpDevNames
->wDriverOffset
= pTempPtr
- pDevNamesSpace
;
262 pTempPtr
+= lstrlenW(DeviceDriverName
) + 1;
263 lstrcpyW(pTempPtr
, DeviceName
);
264 lpDevNames
->wDeviceOffset
= pTempPtr
- pDevNamesSpace
;
266 pTempPtr
+= lstrlenW(DeviceName
) + 1;
267 lstrcpyW(pTempPtr
, OutputPort
);
268 lpDevNames
->wOutputOffset
= pTempPtr
- pDevNamesSpace
;
270 GetDefaultPrinterW(bufW
, &dwBufLen
);
271 lpDevNames
->wDefault
= (lstrcmpW(bufW
, DeviceName
) == 0) ? 1 : 0;
276 /***********************************************************************
277 * PRINTDLG_UpdatePrintDlg [internal]
280 * updates the PrintDlg structure for return values.
283 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
284 * TRUE if successful.
286 static BOOL
PRINTDLG_UpdatePrintDlgA(HWND hDlg
,
287 PRINT_PTRA
* PrintStructures
)
289 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
290 PDEVMODEA lpdm
= PrintStructures
->lpDevMode
;
291 LPPRINTER_INFO_2A pi
= PrintStructures
->lpPrinterInfo
;
295 FIXME("No lpdm ptr?\n");
300 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
301 /* check whether nFromPage and nToPage are within range defined by
302 * nMinPage and nMaxPage
304 if (IsDlgButtonChecked(hDlg
, rad3
) == BST_CHECKED
) { /* Pages */
307 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
308 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
309 if (nFromPage
< lppd
->nMinPage
|| nFromPage
> lppd
->nMaxPage
||
310 nToPage
< lppd
->nMinPage
|| nToPage
> lppd
->nMaxPage
) {
311 char resourcestr
[256];
313 LoadStringA(COMDLG32_hInstance
, PD32_INVALID_PAGE_RANGE
,
315 sprintf(resultstr
,resourcestr
, lppd
->nMinPage
, lppd
->nMaxPage
);
316 LoadStringA(COMDLG32_hInstance
, PD32_PRINT_TITLE
,
318 MessageBoxA(hDlg
, resultstr
, resourcestr
,
319 MB_OK
| MB_ICONWARNING
);
322 lppd
->nFromPage
= nFromPage
;
323 lppd
->nToPage
= nToPage
;
324 lppd
->Flags
|= PD_PAGENUMS
;
327 lppd
->Flags
&= ~PD_PAGENUMS
;
329 if (IsDlgButtonChecked(hDlg
, rad2
) == BST_CHECKED
) /* Selection */
330 lppd
->Flags
|= PD_SELECTION
;
332 lppd
->Flags
&= ~PD_SELECTION
;
334 if (IsDlgButtonChecked(hDlg
, chx1
) == BST_CHECKED
) {/* Print to file */
335 static char file
[] = "FILE:";
336 lppd
->Flags
|= PD_PRINTTOFILE
;
337 pi
->pPortName
= file
;
340 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
) { /* Collate */
341 FIXME("Collate lppd not yet implemented as output\n");
344 /* set PD_Collate and nCopies */
345 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
346 /* The application doesn't support multiple copies or collate...
348 lppd
->Flags
&= ~PD_COLLATE
;
350 /* if the printer driver supports it... store info there
351 * otherwise no collate & multiple copies !
353 if (lpdm
->dmFields
& DM_COLLATE
)
355 (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
);
356 if (lpdm
->dmFields
& DM_COPIES
)
357 lpdm
->u1
.s1
.dmCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
359 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
360 lppd
->Flags
|= PD_COLLATE
;
362 lppd
->Flags
&= ~PD_COLLATE
;
363 lppd
->nCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
369 static BOOL
PRINTDLG_UpdatePrintDlgW(HWND hDlg
,
370 PRINT_PTRW
* PrintStructures
)
372 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
373 PDEVMODEW lpdm
= PrintStructures
->lpDevMode
;
374 LPPRINTER_INFO_2W pi
= PrintStructures
->lpPrinterInfo
;
378 FIXME("No lpdm ptr?\n");
383 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
384 /* check whether nFromPage and nToPage are within range defined by
385 * nMinPage and nMaxPage
387 if (IsDlgButtonChecked(hDlg
, rad3
) == BST_CHECKED
) { /* Pages */
390 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
391 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
392 if (nFromPage
< lppd
->nMinPage
|| nFromPage
> lppd
->nMaxPage
||
393 nToPage
< lppd
->nMinPage
|| nToPage
> lppd
->nMaxPage
) {
394 WCHAR resourcestr
[256];
395 WCHAR resultstr
[256];
396 LoadStringW(COMDLG32_hInstance
, PD32_INVALID_PAGE_RANGE
,
398 wsprintfW(resultstr
,resourcestr
, lppd
->nMinPage
, lppd
->nMaxPage
);
399 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
,
401 MessageBoxW(hDlg
, resultstr
, resourcestr
,
402 MB_OK
| MB_ICONWARNING
);
405 lppd
->nFromPage
= nFromPage
;
406 lppd
->nToPage
= nToPage
;
407 lppd
->Flags
|= PD_PAGENUMS
;
410 lppd
->Flags
&= ~PD_PAGENUMS
;
412 if (IsDlgButtonChecked(hDlg
, rad2
) == BST_CHECKED
) /* Selection */
413 lppd
->Flags
|= PD_SELECTION
;
415 lppd
->Flags
&= ~PD_SELECTION
;
417 if (IsDlgButtonChecked(hDlg
, chx1
) == BST_CHECKED
) {/* Print to file */
418 static WCHAR file
[] = {'F','I','L','E',':',0};
419 lppd
->Flags
|= PD_PRINTTOFILE
;
420 pi
->pPortName
= file
;
423 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
) { /* Collate */
424 FIXME("Collate lppd not yet implemented as output\n");
427 /* set PD_Collate and nCopies */
428 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
429 /* The application doesn't support multiple copies or collate...
431 lppd
->Flags
&= ~PD_COLLATE
;
433 /* if the printer driver supports it... store info there
434 * otherwise no collate & multiple copies !
436 if (lpdm
->dmFields
& DM_COLLATE
)
438 (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
);
439 if (lpdm
->dmFields
& DM_COPIES
)
440 lpdm
->u1
.s1
.dmCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
442 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
443 lppd
->Flags
|= PD_COLLATE
;
445 lppd
->Flags
&= ~PD_COLLATE
;
446 lppd
->nCopies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
452 static BOOL
PRINTDLG_PaperSizeA(
453 PRINTDLGA
*pdlga
,const WORD PaperSize
,LPPOINT size
457 LPSTR devname
,portname
;
461 POINT
*points
= NULL
;
464 dn
= GlobalLock(pdlga
->hDevNames
);
465 dm
= GlobalLock(pdlga
->hDevMode
);
466 devname
= ((char*)dn
)+dn
->wDeviceOffset
;
467 portname
= ((char*)dn
)+dn
->wOutputOffset
;
470 NrOfEntries
= DeviceCapabilitiesA(devname
,portname
,DC_PAPERNAMES
,NULL
,dm
);
472 FIXME("No papernames found for %s/%s\n",devname
,portname
);
475 if (NrOfEntries
== -1) {
476 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
480 Words
= HeapAlloc(GetProcessHeap(),0,NrOfEntries
*sizeof(WORD
));
481 if (NrOfEntries
!= (ret
=DeviceCapabilitiesA(devname
,portname
,DC_PAPERS
,(LPSTR
)Words
,dm
))) {
482 FIXME("Number of returned vals %d is not %d\n",NrOfEntries
,ret
);
485 for (i
=0;i
<NrOfEntries
;i
++)
486 if (Words
[i
] == PaperSize
)
488 HeapFree(GetProcessHeap(),0,Words
);
489 if (i
== NrOfEntries
) {
490 FIXME("Papersize %d not found in list?\n",PaperSize
);
493 points
= HeapAlloc(GetProcessHeap(),0,sizeof(points
[0])*NrOfEntries
);
494 if (NrOfEntries
!=(ret
=DeviceCapabilitiesA(devname
,portname
,DC_PAPERSIZE
,(LPSTR
)points
,dm
))) {
495 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries
,ret
);
498 /* this is _10ths_ of a millimeter */
503 GlobalUnlock(pdlga
->hDevNames
);
504 GlobalUnlock(pdlga
->hDevMode
);
505 HeapFree(GetProcessHeap(),0,Words
);
506 HeapFree(GetProcessHeap(),0,points
);
510 static BOOL
PRINTDLG_PaperSizeW(
511 PRINTDLGW
*pdlga
,const WCHAR
*PaperSize
,LPPOINT size
515 LPWSTR devname
,portname
;
519 POINT
*points
= NULL
;
522 dn
= GlobalLock(pdlga
->hDevNames
);
523 dm
= GlobalLock(pdlga
->hDevMode
);
524 devname
= ((WCHAR
*)dn
)+dn
->wDeviceOffset
;
525 portname
= ((WCHAR
*)dn
)+dn
->wOutputOffset
;
528 NrOfEntries
= DeviceCapabilitiesW(devname
,portname
,DC_PAPERNAMES
,NULL
,dm
);
530 FIXME("No papernames found for %s/%s\n",debugstr_w(devname
),debugstr_w(portname
));
533 if (NrOfEntries
== -1) {
534 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
538 Names
= HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*NrOfEntries
*64);
539 if (NrOfEntries
!= (ret
=DeviceCapabilitiesW(devname
,portname
,DC_PAPERNAMES
,Names
,dm
))) {
540 FIXME("Number of returned vals %d is not %d\n",NrOfEntries
,ret
);
543 for (i
=0;i
<NrOfEntries
;i
++)
544 if (!lstrcmpW(PaperSize
,Names
+(64*i
)))
546 HeapFree(GetProcessHeap(),0,Names
);
547 if (i
==NrOfEntries
) {
548 FIXME("Papersize %s not found in list?\n",debugstr_w(PaperSize
));
551 points
= HeapAlloc(GetProcessHeap(),0,sizeof(points
[0])*NrOfEntries
);
552 if (NrOfEntries
!=(ret
=DeviceCapabilitiesW(devname
,portname
,DC_PAPERSIZE
,(LPWSTR
)points
,dm
))) {
553 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries
,ret
);
556 /* this is _10ths_ of a millimeter */
561 GlobalUnlock(pdlga
->hDevNames
);
562 GlobalUnlock(pdlga
->hDevMode
);
563 HeapFree(GetProcessHeap(),0,Names
);
564 HeapFree(GetProcessHeap(),0,points
);
569 /************************************************************************
570 * PRINTDLG_SetUpPaperComboBox
572 * Initialize either the papersize or inputslot combos of the Printer Setup
573 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
574 * We also try to re-select the old selection.
576 static BOOL
PRINTDLG_SetUpPaperComboBoxA(HWND hDlg
,
589 int fwCapability_Names
;
590 int fwCapability_Words
;
592 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName
,PortName
,nIDComboBox
);
594 /* query the dialog box for the current selected value */
595 Sel
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETCURSEL
, 0, 0);
597 /* we enter here only if a different printer is selected after
598 * the Print Setup dialog is opened. The current settings are
599 * stored into the newly selected printer.
601 oldWord
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
,
604 if (nIDComboBox
== cmb2
)
605 dm
->u1
.s1
.dmPaperSize
= oldWord
;
607 dm
->u1
.s1
.dmDefaultSource
= oldWord
;
611 /* we enter here only when the Print setup dialog is initially
612 * opened. In this case the settings are restored from when
613 * the dialog was last closed.
616 if (nIDComboBox
== cmb2
)
617 oldWord
= dm
->u1
.s1
.dmPaperSize
;
619 oldWord
= dm
->u1
.s1
.dmDefaultSource
;
623 if (nIDComboBox
== cmb2
) {
625 fwCapability_Names
= DC_PAPERNAMES
;
626 fwCapability_Words
= DC_PAPERS
;
630 fwCapability_Names
= DC_BINNAMES
;
631 fwCapability_Words
= DC_BINS
;
634 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
635 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
637 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
638 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
639 fwCapability_Names
, NULL
, dm
);
640 if (NrOfEntries
== 0)
641 WARN("no Name Entries found!\n");
642 else if (NrOfEntries
< 0)
645 if(DeviceCapabilitiesA(PrinterName
, PortName
, fwCapability_Words
, NULL
, dm
)
647 ERR("Number of caps is different\n");
651 Names
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(char)*NamesSize
);
652 Words
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WORD
));
653 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
654 fwCapability_Names
, Names
, dm
);
655 NrOfEntries
= DeviceCapabilitiesA(PrinterName
, PortName
,
656 fwCapability_Words
, (LPSTR
)Words
, dm
);
658 /* reset any current content in the combobox */
659 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_RESETCONTENT
, 0, 0);
661 /* store new content */
662 for (i
= 0; i
< NrOfEntries
; i
++) {
663 DWORD pos
= SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_ADDSTRING
, 0,
664 (LPARAM
)(&Names
[i
*NamesSize
]) );
665 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_SETITEMDATA
, pos
,
669 /* Look for old selection - can't do this is previous loop since
670 item order will change as more items are added */
672 for (i
= 0; i
< NrOfEntries
; i
++) {
673 if(SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) ==
679 SendDlgItemMessageA(hDlg
, nIDComboBox
, CB_SETCURSEL
, Sel
, 0);
681 HeapFree(GetProcessHeap(),0,Words
);
682 HeapFree(GetProcessHeap(),0,Names
);
686 static BOOL
PRINTDLG_SetUpPaperComboBoxW(HWND hDlg
,
688 const WCHAR
* PrinterName
,
689 const WCHAR
* PortName
,
699 int fwCapability_Names
;
700 int fwCapability_Words
;
702 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName
),debugstr_w(PortName
),nIDComboBox
);
704 /* query the dialog box for the current selected value */
705 Sel
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETCURSEL
, 0, 0);
707 /* we enter here only if a different printer is selected after
708 * the Print Setup dialog is opened. The current settings are
709 * stored into the newly selected printer.
711 oldWord
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETITEMDATA
,
714 if (nIDComboBox
== cmb2
)
715 dm
->u1
.s1
.dmPaperSize
= oldWord
;
717 dm
->u1
.s1
.dmDefaultSource
= oldWord
;
721 /* we enter here only when the Print setup dialog is initially
722 * opened. In this case the settings are restored from when
723 * the dialog was last closed.
726 if (nIDComboBox
== cmb2
)
727 oldWord
= dm
->u1
.s1
.dmPaperSize
;
729 oldWord
= dm
->u1
.s1
.dmDefaultSource
;
733 if (nIDComboBox
== cmb2
) {
735 fwCapability_Names
= DC_PAPERNAMES
;
736 fwCapability_Words
= DC_PAPERS
;
740 fwCapability_Names
= DC_BINNAMES
;
741 fwCapability_Words
= DC_BINS
;
744 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
745 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
747 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
748 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
749 fwCapability_Names
, NULL
, dm
);
750 if (NrOfEntries
== 0)
751 WARN("no Name Entries found!\n");
752 else if (NrOfEntries
< 0)
755 if(DeviceCapabilitiesW(PrinterName
, PortName
, fwCapability_Words
, NULL
, dm
)
757 ERR("Number of caps is different\n");
761 Names
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WCHAR
)*NamesSize
);
762 Words
= HeapAlloc(GetProcessHeap(),0, NrOfEntries
*sizeof(WORD
));
763 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
764 fwCapability_Names
, Names
, dm
);
765 NrOfEntries
= DeviceCapabilitiesW(PrinterName
, PortName
,
766 fwCapability_Words
, (LPWSTR
)Words
, dm
);
768 /* reset any current content in the combobox */
769 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_RESETCONTENT
, 0, 0);
771 /* store new content */
772 for (i
= 0; i
< NrOfEntries
; i
++) {
773 DWORD pos
= SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_ADDSTRING
, 0,
774 (LPARAM
)(&Names
[i
*NamesSize
]) );
775 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_SETITEMDATA
, pos
,
779 /* Look for old selection - can't do this is previous loop since
780 item order will change as more items are added */
782 for (i
= 0; i
< NrOfEntries
; i
++) {
783 if(SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_GETITEMDATA
, i
, 0) ==
789 SendDlgItemMessageW(hDlg
, nIDComboBox
, CB_SETCURSEL
, Sel
, 0);
791 HeapFree(GetProcessHeap(),0,Words
);
792 HeapFree(GetProcessHeap(),0,Names
);
797 /***********************************************************************
798 * PRINTDLG_UpdatePrinterInfoTexts [internal]
800 static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg
, const PRINTER_INFO_2A
*pi
)
803 char ResourceString
[256];
809 /* add all status messages */
810 for (i
= 0; i
< 25; i
++) {
811 if (pi
->Status
& (1<<i
)) {
812 LoadStringA(COMDLG32_hInstance
, PD32_PRINTER_STATUS_PAUSED
+i
,
813 ResourceString
, 255);
814 strcat(StatusMsg
,ResourceString
);
818 /* FIXME: status==ready must only be appended if really so.
819 but how to detect? */
820 LoadStringA(COMDLG32_hInstance
, PD32_PRINTER_STATUS_READY
,
821 ResourceString
, 255);
822 strcat(StatusMsg
,ResourceString
);
823 SetDlgItemTextA(hDlg
, stc12
, StatusMsg
);
825 /* set all other printer info texts */
826 SetDlgItemTextA(hDlg
, stc11
, pi
->pDriverName
);
828 if (pi
->pLocation
!= NULL
&& pi
->pLocation
[0] != '\0')
829 SetDlgItemTextA(hDlg
, stc14
, pi
->pLocation
);
831 SetDlgItemTextA(hDlg
, stc14
, pi
->pPortName
);
832 SetDlgItemTextA(hDlg
, stc13
, pi
->pComment
? pi
->pComment
: "");
836 static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg
, const PRINTER_INFO_2W
*pi
)
838 WCHAR StatusMsg
[256];
839 WCHAR ResourceString
[256];
840 static const WCHAR emptyW
[] = {0};
846 /* add all status messages */
847 for (i
= 0; i
< 25; i
++) {
848 if (pi
->Status
& (1<<i
)) {
849 LoadStringW(COMDLG32_hInstance
, PD32_PRINTER_STATUS_PAUSED
+i
,
850 ResourceString
, 255);
851 lstrcatW(StatusMsg
,ResourceString
);
855 /* FIXME: status==ready must only be appended if really so.
856 but how to detect? */
857 LoadStringW(COMDLG32_hInstance
, PD32_PRINTER_STATUS_READY
,
858 ResourceString
, 255);
859 lstrcatW(StatusMsg
,ResourceString
);
860 SetDlgItemTextW(hDlg
, stc12
, StatusMsg
);
862 /* set all other printer info texts */
863 SetDlgItemTextW(hDlg
, stc11
, pi
->pDriverName
);
864 if (pi
->pLocation
!= NULL
&& pi
->pLocation
[0] != '\0')
865 SetDlgItemTextW(hDlg
, stc14
, pi
->pLocation
);
867 SetDlgItemTextW(hDlg
, stc14
, pi
->pPortName
);
868 SetDlgItemTextW(hDlg
, stc13
, pi
->pComment
? pi
->pComment
: emptyW
);
872 /*******************************************************************
874 * PRINTDLG_ChangePrinter
877 BOOL
PRINTDLG_ChangePrinterA(HWND hDlg
, char *name
,
878 PRINT_PTRA
*PrintStructures
)
880 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
881 LPDEVMODEA lpdm
= NULL
;
886 HeapFree(GetProcessHeap(),0, PrintStructures
->lpPrinterInfo
);
887 HeapFree(GetProcessHeap(),0, PrintStructures
->lpDriverInfo
);
888 if(!OpenPrinterA(name
, &hprn
, NULL
)) {
889 ERR("Can't open printer %s\n", name
);
892 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
893 PrintStructures
->lpPrinterInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
894 GetPrinterA(hprn
, 2, (LPBYTE
)PrintStructures
->lpPrinterInfo
, needed
,
896 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
897 PrintStructures
->lpDriverInfo
= HeapAlloc(GetProcessHeap(),0,needed
);
898 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)PrintStructures
->lpDriverInfo
,
900 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures
->lpPrinterInfo
->pPrinterName
);
905 PRINTDLG_UpdatePrinterInfoTextsA(hDlg
, PrintStructures
->lpPrinterInfo
);
907 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
908 PrintStructures
->lpDevMode
= NULL
;
910 dmSize
= DocumentPropertiesA(0, 0, name
, NULL
, NULL
, 0);
912 ERR("DocumentProperties fails on %s\n", debugstr_a(name
));
915 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(), 0, dmSize
);
916 dmSize
= DocumentPropertiesA(0, 0, name
, PrintStructures
->lpDevMode
, NULL
,
918 if(lppd
->hDevMode
&& (lpdm
= GlobalLock(lppd
->hDevMode
)) &&
919 !lstrcmpA( (LPSTR
) lpdm
->dmDeviceName
,
920 (LPSTR
) PrintStructures
->lpDevMode
->dmDeviceName
)) {
921 /* Supplied devicemode matches current printer so try to use it */
922 DocumentPropertiesA(0, 0, name
, PrintStructures
->lpDevMode
, lpdm
,
923 DM_OUT_BUFFER
| DM_IN_BUFFER
);
926 GlobalUnlock(lppd
->hDevMode
);
928 lpdm
= PrintStructures
->lpDevMode
; /* use this as a shortcut */
930 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
931 /* Print range (All/Range/Selection) */
932 SetDlgItemInt(hDlg
, edt1
, lppd
->nFromPage
, FALSE
);
933 SetDlgItemInt(hDlg
, edt2
, lppd
->nToPage
, FALSE
);
934 CheckRadioButton(hDlg
, rad1
, rad3
, rad1
); /* default */
935 if (lppd
->Flags
& PD_NOSELECTION
)
936 EnableWindow(GetDlgItem(hDlg
, rad2
), FALSE
);
938 if (lppd
->Flags
& PD_SELECTION
)
939 CheckRadioButton(hDlg
, rad1
, rad3
, rad2
);
940 if (lppd
->Flags
& PD_NOPAGENUMS
) {
941 EnableWindow(GetDlgItem(hDlg
, rad3
), FALSE
);
942 EnableWindow(GetDlgItem(hDlg
, stc2
),FALSE
);
943 EnableWindow(GetDlgItem(hDlg
, edt1
), FALSE
);
944 EnableWindow(GetDlgItem(hDlg
, stc3
),FALSE
);
945 EnableWindow(GetDlgItem(hDlg
, edt2
), FALSE
);
947 if (lppd
->Flags
& PD_PAGENUMS
)
948 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
953 * FIXME: The ico3 is not displayed for some reason. I don't know why.
955 if (lppd
->Flags
& PD_COLLATE
) {
956 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
957 (LPARAM
)PrintStructures
->hCollateIcon
);
958 CheckDlgButton(hDlg
, chx2
, 1);
960 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
961 (LPARAM
)PrintStructures
->hNoCollateIcon
);
962 CheckDlgButton(hDlg
, chx2
, 0);
965 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
966 /* if printer doesn't support it: no Collate */
967 if (!(lpdm
->dmFields
& DM_COLLATE
)) {
968 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
969 EnableWindow(GetDlgItem(hDlg
, ico3
), FALSE
);
976 if (lppd
->hDevMode
== 0)
977 copies
= lppd
->nCopies
;
979 copies
= lpdm
->u1
.s1
.dmCopies
;
980 if(copies
== 0) copies
= 1;
981 else if(copies
< 0) copies
= MAX_COPIES
;
982 SetDlgItemInt(hDlg
, edt3
, copies
, FALSE
);
985 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
986 /* if printer doesn't support it: no nCopies */
987 if (!(lpdm
->dmFields
& DM_COPIES
)) {
988 EnableWindow(GetDlgItem(hDlg
, edt3
), FALSE
);
989 EnableWindow(GetDlgItem(hDlg
, stc5
), FALSE
);
994 CheckDlgButton(hDlg
, chx1
, (lppd
->Flags
& PD_PRINTTOFILE
) ? 1 : 0);
995 if (lppd
->Flags
& PD_DISABLEPRINTTOFILE
)
996 EnableWindow(GetDlgItem(hDlg
, chx1
), FALSE
);
997 if (lppd
->Flags
& PD_HIDEPRINTTOFILE
)
998 ShowWindow(GetDlgItem(hDlg
, chx1
), SW_HIDE
);
1000 } else { /* PD_PRINTSETUP */
1001 BOOL bPortrait
= (lpdm
->u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
);
1003 PRINTDLG_SetUpPaperComboBoxA(hDlg
, cmb2
,
1004 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1005 PrintStructures
->lpPrinterInfo
->pPortName
,
1007 PRINTDLG_SetUpPaperComboBoxA(hDlg
, cmb3
,
1008 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1009 PrintStructures
->lpPrinterInfo
->pPortName
,
1011 CheckRadioButton(hDlg
, rad1
, rad2
, bPortrait
? rad1
: rad2
);
1012 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1013 (LPARAM
)(bPortrait
? PrintStructures
->hPortraitIcon
:
1014 PrintStructures
->hLandscapeIcon
));
1019 if ((lppd
->Flags
& PD_SHOWHELP
)==0) {
1020 /* hide if PD_SHOWHELP not specified */
1021 ShowWindow(GetDlgItem(hDlg
, pshHelp
), SW_HIDE
);
1026 static BOOL
PRINTDLG_ChangePrinterW(HWND hDlg
, WCHAR
*name
,
1027 PRINT_PTRW
*PrintStructures
)
1029 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1030 LPDEVMODEW lpdm
= NULL
;
1035 HeapFree(GetProcessHeap(),0, PrintStructures
->lpPrinterInfo
);
1036 HeapFree(GetProcessHeap(),0, PrintStructures
->lpDriverInfo
);
1037 if(!OpenPrinterW(name
, &hprn
, NULL
)) {
1038 ERR("Can't open printer %s\n", debugstr_w(name
));
1041 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
1042 PrintStructures
->lpPrinterInfo
= HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*needed
);
1043 GetPrinterW(hprn
, 2, (LPBYTE
)PrintStructures
->lpPrinterInfo
, needed
,
1045 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
1046 PrintStructures
->lpDriverInfo
= HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*needed
);
1047 if (!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)PrintStructures
->lpDriverInfo
,
1049 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures
->lpPrinterInfo
->pPrinterName
));
1054 PRINTDLG_UpdatePrinterInfoTextsW(hDlg
, PrintStructures
->lpPrinterInfo
);
1056 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
1057 PrintStructures
->lpDevMode
= NULL
;
1059 dmSize
= DocumentPropertiesW(0, 0, name
, NULL
, NULL
, 0);
1061 ERR("DocumentProperties fails on %s\n", debugstr_w(name
));
1064 PrintStructures
->lpDevMode
= HeapAlloc(GetProcessHeap(), 0, dmSize
);
1065 dmSize
= DocumentPropertiesW(0, 0, name
, PrintStructures
->lpDevMode
, NULL
,
1067 if(lppd
->hDevMode
&& (lpdm
= GlobalLock(lppd
->hDevMode
)) &&
1068 !lstrcmpW(lpdm
->dmDeviceName
,
1069 PrintStructures
->lpDevMode
->dmDeviceName
)) {
1070 /* Supplied devicemode matches current printer so try to use it */
1071 DocumentPropertiesW(0, 0, name
, PrintStructures
->lpDevMode
, lpdm
,
1072 DM_OUT_BUFFER
| DM_IN_BUFFER
);
1075 GlobalUnlock(lppd
->hDevMode
);
1077 lpdm
= PrintStructures
->lpDevMode
; /* use this as a shortcut */
1079 if(!(lppd
->Flags
& PD_PRINTSETUP
)) {
1080 /* Print range (All/Range/Selection) */
1081 SetDlgItemInt(hDlg
, edt1
, lppd
->nFromPage
, FALSE
);
1082 SetDlgItemInt(hDlg
, edt2
, lppd
->nToPage
, FALSE
);
1083 CheckRadioButton(hDlg
, rad1
, rad3
, rad1
); /* default */
1084 if (lppd
->Flags
& PD_NOSELECTION
)
1085 EnableWindow(GetDlgItem(hDlg
, rad2
), FALSE
);
1087 if (lppd
->Flags
& PD_SELECTION
)
1088 CheckRadioButton(hDlg
, rad1
, rad3
, rad2
);
1089 if (lppd
->Flags
& PD_NOPAGENUMS
) {
1090 EnableWindow(GetDlgItem(hDlg
, rad3
), FALSE
);
1091 EnableWindow(GetDlgItem(hDlg
, stc2
),FALSE
);
1092 EnableWindow(GetDlgItem(hDlg
, edt1
), FALSE
);
1093 EnableWindow(GetDlgItem(hDlg
, stc3
),FALSE
);
1094 EnableWindow(GetDlgItem(hDlg
, edt2
), FALSE
);
1096 if (lppd
->Flags
& PD_PAGENUMS
)
1097 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1102 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1104 if (lppd
->Flags
& PD_COLLATE
) {
1105 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1106 (LPARAM
)PrintStructures
->hCollateIcon
);
1107 CheckDlgButton(hDlg
, chx2
, 1);
1109 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1110 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1111 CheckDlgButton(hDlg
, chx2
, 0);
1114 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1115 /* if printer doesn't support it: no Collate */
1116 if (!(lpdm
->dmFields
& DM_COLLATE
)) {
1117 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1118 EnableWindow(GetDlgItem(hDlg
, ico3
), FALSE
);
1125 if (lppd
->hDevMode
== 0)
1126 copies
= lppd
->nCopies
;
1128 copies
= lpdm
->u1
.s1
.dmCopies
;
1129 if(copies
== 0) copies
= 1;
1130 else if(copies
< 0) copies
= MAX_COPIES
;
1131 SetDlgItemInt(hDlg
, edt3
, copies
, FALSE
);
1134 if (lppd
->Flags
& PD_USEDEVMODECOPIESANDCOLLATE
) {
1135 /* if printer doesn't support it: no nCopies */
1136 if (!(lpdm
->dmFields
& DM_COPIES
)) {
1137 EnableWindow(GetDlgItem(hDlg
, edt3
), FALSE
);
1138 EnableWindow(GetDlgItem(hDlg
, stc5
), FALSE
);
1143 CheckDlgButton(hDlg
, chx1
, (lppd
->Flags
& PD_PRINTTOFILE
) ? 1 : 0);
1144 if (lppd
->Flags
& PD_DISABLEPRINTTOFILE
)
1145 EnableWindow(GetDlgItem(hDlg
, chx1
), FALSE
);
1146 if (lppd
->Flags
& PD_HIDEPRINTTOFILE
)
1147 ShowWindow(GetDlgItem(hDlg
, chx1
), SW_HIDE
);
1149 } else { /* PD_PRINTSETUP */
1150 BOOL bPortrait
= (lpdm
->u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
);
1152 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb2
,
1153 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1154 PrintStructures
->lpPrinterInfo
->pPortName
,
1156 PRINTDLG_SetUpPaperComboBoxW(hDlg
, cmb3
,
1157 PrintStructures
->lpPrinterInfo
->pPrinterName
,
1158 PrintStructures
->lpPrinterInfo
->pPortName
,
1160 CheckRadioButton(hDlg
, rad1
, rad2
, bPortrait
? rad1
: rad2
);
1161 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1162 (LPARAM
)(bPortrait
? PrintStructures
->hPortraitIcon
:
1163 PrintStructures
->hLandscapeIcon
));
1168 if ((lppd
->Flags
& PD_SHOWHELP
)==0) {
1169 /* hide if PD_SHOWHELP not specified */
1170 ShowWindow(GetDlgItem(hDlg
, pshHelp
), SW_HIDE
);
1175 /***********************************************************************
1176 * check_printer_setup [internal]
1178 static LRESULT
check_printer_setup(HWND hDlg
)
1181 WCHAR resourcestr
[256],resultstr
[256];
1184 EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &needed
, &num
);
1187 EnumPrintersW(PRINTER_ENUM_CONNECTIONS
, NULL
, 2, NULL
, 0, &needed
, &num
);
1193 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEVICES
,resultstr
, 255);
1194 LoadStringW(COMDLG32_hInstance
, PD32_PRINT_TITLE
,resourcestr
, 255);
1195 res
= MessageBoxW(hDlg
, resultstr
, resourcestr
,MB_OK
| MB_ICONWARNING
);
1200 /***********************************************************************
1201 * PRINTDLG_WMInitDialog [internal]
1203 static LRESULT
PRINTDLG_WMInitDialog(HWND hDlg
, WPARAM wParam
,
1204 PRINT_PTRA
* PrintStructures
)
1206 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1210 UINT comboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1212 /* load Collate ICONs */
1213 /* We load these with LoadImage because they are not a standard
1214 size and we don't want them rescaled */
1215 PrintStructures
->hCollateIcon
=
1216 LoadImageA(COMDLG32_hInstance
, "PD32_COLLATE", IMAGE_ICON
, 0, 0, 0);
1217 PrintStructures
->hNoCollateIcon
=
1218 LoadImageA(COMDLG32_hInstance
, "PD32_NOCOLLATE", IMAGE_ICON
, 0, 0, 0);
1220 /* These can be done with LoadIcon */
1221 PrintStructures
->hPortraitIcon
=
1222 LoadIconA(COMDLG32_hInstance
, "PD32_PORTRAIT");
1223 PrintStructures
->hLandscapeIcon
=
1224 LoadIconA(COMDLG32_hInstance
, "PD32_LANDSCAPE");
1226 /* display the collate/no_collate icon */
1227 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1228 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1230 if(PrintStructures
->hCollateIcon
== 0 ||
1231 PrintStructures
->hNoCollateIcon
== 0 ||
1232 PrintStructures
->hPortraitIcon
== 0 ||
1233 PrintStructures
->hLandscapeIcon
== 0) {
1234 ERR("no icon in resourcefile\n");
1235 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1236 EndDialog(hDlg
, FALSE
);
1240 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1241 * must be registered and the Help button must be shown.
1243 if (lppd
->Flags
& PD_SHOWHELP
) {
1244 if((PrintStructures
->HelpMessageID
=
1245 RegisterWindowMessageA(HELPMSGSTRINGA
)) == 0) {
1246 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL
);
1250 PrintStructures
->HelpMessageID
= 0;
1252 if(!(lppd
->Flags
&PD_PRINTSETUP
)) {
1253 PrintStructures
->hwndUpDown
=
1254 CreateUpDownControl(WS_CHILD
| WS_VISIBLE
| WS_BORDER
|
1255 UDS_NOTHOUSANDS
| UDS_ARROWKEYS
|
1256 UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, 0, 0, 0, 0,
1257 hDlg
, UPDOWN_ID
, COMDLG32_hInstance
,
1258 GetDlgItem(hDlg
, edt3
), MAX_COPIES
, 1, 1);
1261 /* FIXME: I allow more freedom than either Win95 or WinNT,
1262 * which do not agree to what errors should be thrown or not
1263 * in case nToPage or nFromPage is out-of-range.
1265 if (lppd
->nMaxPage
< lppd
->nMinPage
)
1266 lppd
->nMaxPage
= lppd
->nMinPage
;
1267 if (lppd
->nMinPage
== lppd
->nMaxPage
)
1268 lppd
->Flags
|= PD_NOPAGENUMS
;
1269 if (lppd
->nToPage
< lppd
->nMinPage
)
1270 lppd
->nToPage
= lppd
->nMinPage
;
1271 if (lppd
->nToPage
> lppd
->nMaxPage
)
1272 lppd
->nToPage
= lppd
->nMaxPage
;
1273 if (lppd
->nFromPage
< lppd
->nMinPage
)
1274 lppd
->nFromPage
= lppd
->nMinPage
;
1275 if (lppd
->nFromPage
> lppd
->nMaxPage
)
1276 lppd
->nFromPage
= lppd
->nMaxPage
;
1278 /* if we have the combo box, fill it */
1279 if (GetDlgItem(hDlg
,comboID
)) {
1282 pdn
= GlobalLock(lppd
->hDevNames
);
1283 pdm
= GlobalLock(lppd
->hDevMode
);
1285 name
= (char*)pdn
+ pdn
->wDeviceOffset
;
1287 name
= (char*)pdm
->dmDeviceName
;
1288 PRINTDLG_SetUpPrinterListComboA(hDlg
, comboID
, name
);
1289 if(pdm
) GlobalUnlock(lppd
->hDevMode
);
1290 if(pdn
) GlobalUnlock(lppd
->hDevNames
);
1292 /* Now find selected printer and update rest of dlg */
1293 name
= HeapAlloc(GetProcessHeap(),0,256);
1294 if (GetDlgItemTextA(hDlg
, comboID
, name
, 255))
1295 PRINTDLG_ChangePrinterA(hDlg
, name
, PrintStructures
);
1296 HeapFree(GetProcessHeap(),0,name
);
1298 /* else use default printer */
1300 DWORD dwBufLen
= sizeof(name
);
1301 BOOL ret
= GetDefaultPrinterA(name
, &dwBufLen
);
1304 PRINTDLG_ChangePrinterA(hDlg
, name
, PrintStructures
);
1306 FIXME("No default printer found, expect problems!\n");
1311 static LRESULT
PRINTDLG_WMInitDialogW(HWND hDlg
, WPARAM wParam
,
1312 PRINT_PTRW
* PrintStructures
)
1314 static const WCHAR PD32_COLLATE
[] = { 'P', 'D', '3', '2', '_', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
1315 static const WCHAR PD32_NOCOLLATE
[] = { 'P', 'D', '3', '2', '_', 'N', 'O', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
1316 static const WCHAR PD32_PORTRAIT
[] = { 'P', 'D', '3', '2', '_', 'P', 'O', 'R', 'T', 'R', 'A', 'I', 'T', 0 };
1317 static const WCHAR PD32_LANDSCAPE
[] = { 'P', 'D', '3', '2', '_', 'L', 'A', 'N', 'D', 'S', 'C', 'A', 'P', 'E', 0 };
1318 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1322 UINT comboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1324 /* load Collate ICONs */
1325 /* We load these with LoadImage because they are not a standard
1326 size and we don't want them rescaled */
1327 PrintStructures
->hCollateIcon
=
1328 LoadImageW(COMDLG32_hInstance
, PD32_COLLATE
, IMAGE_ICON
, 0, 0, 0);
1329 PrintStructures
->hNoCollateIcon
=
1330 LoadImageW(COMDLG32_hInstance
, PD32_NOCOLLATE
, IMAGE_ICON
, 0, 0, 0);
1332 /* These can be done with LoadIcon */
1333 PrintStructures
->hPortraitIcon
=
1334 LoadIconW(COMDLG32_hInstance
, PD32_PORTRAIT
);
1335 PrintStructures
->hLandscapeIcon
=
1336 LoadIconW(COMDLG32_hInstance
, PD32_LANDSCAPE
);
1338 /* display the collate/no_collate icon */
1339 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1340 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1342 if(PrintStructures
->hCollateIcon
== 0 ||
1343 PrintStructures
->hNoCollateIcon
== 0 ||
1344 PrintStructures
->hPortraitIcon
== 0 ||
1345 PrintStructures
->hLandscapeIcon
== 0) {
1346 ERR("no icon in resourcefile\n");
1347 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1348 EndDialog(hDlg
, FALSE
);
1352 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1353 * must be registered and the Help button must be shown.
1355 if (lppd
->Flags
& PD_SHOWHELP
) {
1356 if((PrintStructures
->HelpMessageID
=
1357 RegisterWindowMessageW(HELPMSGSTRINGW
)) == 0) {
1358 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL
);
1362 PrintStructures
->HelpMessageID
= 0;
1364 if(!(lppd
->Flags
&PD_PRINTSETUP
)) {
1365 PrintStructures
->hwndUpDown
=
1366 CreateUpDownControl(WS_CHILD
| WS_VISIBLE
| WS_BORDER
|
1367 UDS_NOTHOUSANDS
| UDS_ARROWKEYS
|
1368 UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, 0, 0, 0, 0,
1369 hDlg
, UPDOWN_ID
, COMDLG32_hInstance
,
1370 GetDlgItem(hDlg
, edt3
), MAX_COPIES
, 1, 1);
1373 /* FIXME: I allow more freedom than either Win95 or WinNT,
1374 * which do not agree to what errors should be thrown or not
1375 * in case nToPage or nFromPage is out-of-range.
1377 if (lppd
->nMaxPage
< lppd
->nMinPage
)
1378 lppd
->nMaxPage
= lppd
->nMinPage
;
1379 if (lppd
->nMinPage
== lppd
->nMaxPage
)
1380 lppd
->Flags
|= PD_NOPAGENUMS
;
1381 if (lppd
->nToPage
< lppd
->nMinPage
)
1382 lppd
->nToPage
= lppd
->nMinPage
;
1383 if (lppd
->nToPage
> lppd
->nMaxPage
)
1384 lppd
->nToPage
= lppd
->nMaxPage
;
1385 if (lppd
->nFromPage
< lppd
->nMinPage
)
1386 lppd
->nFromPage
= lppd
->nMinPage
;
1387 if (lppd
->nFromPage
> lppd
->nMaxPage
)
1388 lppd
->nFromPage
= lppd
->nMaxPage
;
1390 /* if we have the combo box, fill it */
1391 if (GetDlgItem(hDlg
,comboID
)) {
1394 pdn
= GlobalLock(lppd
->hDevNames
);
1395 pdm
= GlobalLock(lppd
->hDevMode
);
1397 name
= (WCHAR
*)pdn
+ pdn
->wDeviceOffset
;
1399 name
= pdm
->dmDeviceName
;
1400 PRINTDLG_SetUpPrinterListComboW(hDlg
, comboID
, name
);
1401 if(pdm
) GlobalUnlock(lppd
->hDevMode
);
1402 if(pdn
) GlobalUnlock(lppd
->hDevNames
);
1404 /* Now find selected printer and update rest of dlg */
1405 /* ansi is ok here */
1406 name
= HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR
));
1407 if (GetDlgItemTextW(hDlg
, comboID
, name
, 255))
1408 PRINTDLG_ChangePrinterW(hDlg
, name
, PrintStructures
);
1409 HeapFree(GetProcessHeap(),0,name
);
1411 /* else use default printer */
1413 DWORD dwBufLen
= sizeof(name
) / sizeof(WCHAR
);
1414 BOOL ret
= GetDefaultPrinterW(name
, &dwBufLen
);
1417 PRINTDLG_ChangePrinterW(hDlg
, name
, PrintStructures
);
1419 FIXME("No default printer found, expect problems!\n");
1424 /***********************************************************************
1425 * PRINTDLG_WMCommand [internal]
1427 LRESULT
PRINTDLG_WMCommandA(HWND hDlg
, WPARAM wParam
,
1428 LPARAM lParam
, PRINT_PTRA
* PrintStructures
)
1430 LPPRINTDLGA lppd
= PrintStructures
->lpPrintDlg
;
1431 UINT PrinterComboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1432 LPDEVMODEA lpdm
= PrintStructures
->lpDevMode
;
1434 switch (LOWORD(wParam
)) {
1436 TRACE(" OK button was hit\n");
1437 if (!PRINTDLG_UpdatePrintDlgA(hDlg
, PrintStructures
)) {
1438 FIXME("Update printdlg was not successful!\n");
1441 EndDialog(hDlg
, TRUE
);
1445 TRACE(" CANCEL button was hit\n");
1446 EndDialog(hDlg
, FALSE
);
1450 TRACE(" HELP button was hit\n");
1451 SendMessageA(lppd
->hwndOwner
, PrintStructures
->HelpMessageID
,
1452 (WPARAM
) hDlg
, (LPARAM
) lppd
);
1455 case chx2
: /* collate pages checkbox */
1456 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
1457 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1458 (LPARAM
)PrintStructures
->hCollateIcon
);
1460 SendDlgItemMessageA(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1461 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1463 case edt1
: /* from page nr editbox */
1464 case edt2
: /* to page nr editbox */
1465 if (HIWORD(wParam
)==EN_CHANGE
) {
1468 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
1469 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
1470 if (nFromPage
!= lppd
->nFromPage
|| nToPage
!= lppd
->nToPage
)
1471 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1476 if(HIWORD(wParam
) == EN_CHANGE
) {
1477 INT copies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
1479 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1481 EnableWindow(GetDlgItem(hDlg
, chx2
), TRUE
);
1486 case psh1
: /* Print Setup */
1490 if (!PrintStructures
->dlg
.lpPrintDlg16
) {
1491 FIXME("The 32bit print dialog does not have this button!?\n");
1495 memcpy(&pdlg
,PrintStructures
->dlg
.lpPrintDlg16
,sizeof(pdlg
));
1496 pdlg
.Flags
|= PD_PRINTSETUP
;
1497 pdlg
.hwndOwner
= HWND_16(hDlg
);
1498 if (!PrintDlg16(&pdlg
))
1503 case psh2
: /* Properties button */
1506 char PrinterName
[256];
1508 GetDlgItemTextA(hDlg
, PrinterComboID
, PrinterName
, 255);
1509 if (!OpenPrinterA(PrinterName
, &hPrinter
, NULL
)) {
1510 FIXME(" Call to OpenPrinter did not succeed!\n");
1513 DocumentPropertiesA(hDlg
, hPrinter
, PrinterName
,
1514 PrintStructures
->lpDevMode
,
1515 PrintStructures
->lpDevMode
,
1516 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
1517 ClosePrinter(hPrinter
);
1521 case rad1
: /* Paperorientation */
1522 if (lppd
->Flags
& PD_PRINTSETUP
)
1524 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1525 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1526 (LPARAM
)(PrintStructures
->hPortraitIcon
));
1530 case rad2
: /* Paperorientation */
1531 if (lppd
->Flags
& PD_PRINTSETUP
)
1533 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1534 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1535 (LPARAM
)(PrintStructures
->hLandscapeIcon
));
1539 case cmb1
: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1540 if (PrinterComboID
!= LOWORD(wParam
)) {
1541 FIXME("No handling for print quality combo box yet.\n");
1545 case cmb4
: /* Printer combobox */
1546 if (HIWORD(wParam
)==CBN_SELCHANGE
) {
1547 char PrinterName
[256];
1548 GetDlgItemTextA(hDlg
, LOWORD(wParam
), PrinterName
, 255);
1549 PRINTDLG_ChangePrinterA(hDlg
, PrinterName
, PrintStructures
);
1553 case cmb2
: /* Papersize */
1555 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
1557 lpdm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageA(hDlg
, cmb2
,
1563 case cmb3
: /* Bin */
1565 DWORD Sel
= SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
1567 lpdm
->u1
.s1
.dmDefaultSource
= SendDlgItemMessageA(hDlg
, cmb3
,
1568 CB_GETITEMDATA
, Sel
,
1573 if(lppd
->Flags
& PD_PRINTSETUP
) {
1574 switch (LOWORD(wParam
)) {
1575 case rad1
: /* orientation */
1577 if (IsDlgButtonChecked(hDlg
, rad1
) == BST_CHECKED
) {
1578 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_PORTRAIT
) {
1579 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1580 SendDlgItemMessageA(hDlg
, stc10
, STM_SETIMAGE
,
1582 (LPARAM
)PrintStructures
->hPortraitIcon
);
1583 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
,
1585 (LPARAM
)PrintStructures
->hPortraitIcon
);
1588 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_LANDSCAPE
) {
1589 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1590 SendDlgItemMessageA(hDlg
, stc10
, STM_SETIMAGE
,
1592 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1593 SendDlgItemMessageA(hDlg
, ico1
, STM_SETIMAGE
,
1595 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1604 static LRESULT
PRINTDLG_WMCommandW(HWND hDlg
, WPARAM wParam
,
1605 LPARAM lParam
, PRINT_PTRW
* PrintStructures
)
1607 LPPRINTDLGW lppd
= PrintStructures
->lpPrintDlg
;
1608 UINT PrinterComboID
= (lppd
->Flags
& PD_PRINTSETUP
) ? cmb1
: cmb4
;
1609 LPDEVMODEW lpdm
= PrintStructures
->lpDevMode
;
1611 switch (LOWORD(wParam
)) {
1613 TRACE(" OK button was hit\n");
1614 if (!PRINTDLG_UpdatePrintDlgW(hDlg
, PrintStructures
)) {
1615 FIXME("Update printdlg was not successful!\n");
1618 EndDialog(hDlg
, TRUE
);
1622 TRACE(" CANCEL button was hit\n");
1623 EndDialog(hDlg
, FALSE
);
1627 TRACE(" HELP button was hit\n");
1628 SendMessageW(lppd
->hwndOwner
, PrintStructures
->HelpMessageID
,
1629 (WPARAM
) hDlg
, (LPARAM
) lppd
);
1632 case chx2
: /* collate pages checkbox */
1633 if (IsDlgButtonChecked(hDlg
, chx2
) == BST_CHECKED
)
1634 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1635 (LPARAM
)PrintStructures
->hCollateIcon
);
1637 SendDlgItemMessageW(hDlg
, ico3
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1638 (LPARAM
)PrintStructures
->hNoCollateIcon
);
1640 case edt1
: /* from page nr editbox */
1641 case edt2
: /* to page nr editbox */
1642 if (HIWORD(wParam
)==EN_CHANGE
) {
1645 nFromPage
= GetDlgItemInt(hDlg
, edt1
, NULL
, FALSE
);
1646 nToPage
= GetDlgItemInt(hDlg
, edt2
, NULL
, FALSE
);
1647 if (nFromPage
!= lppd
->nFromPage
|| nToPage
!= lppd
->nToPage
)
1648 CheckRadioButton(hDlg
, rad1
, rad3
, rad3
);
1653 if(HIWORD(wParam
) == EN_CHANGE
) {
1654 INT copies
= GetDlgItemInt(hDlg
, edt3
, NULL
, FALSE
);
1656 EnableWindow(GetDlgItem(hDlg
, chx2
), FALSE
);
1658 EnableWindow(GetDlgItem(hDlg
, chx2
), TRUE
);
1662 case psh1
: /* Print Setup */
1664 ERR("psh1 is called from 16bit code only, we should not get here.\n");
1667 case psh2
: /* Properties button */
1670 WCHAR PrinterName
[256];
1672 if (!GetDlgItemTextW(hDlg
, PrinterComboID
, PrinterName
, 255)) break;
1673 if (!OpenPrinterW(PrinterName
, &hPrinter
, NULL
)) {
1674 FIXME(" Call to OpenPrinter did not succeed!\n");
1677 DocumentPropertiesW(hDlg
, hPrinter
, PrinterName
,
1678 PrintStructures
->lpDevMode
,
1679 PrintStructures
->lpDevMode
,
1680 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
1681 ClosePrinter(hPrinter
);
1685 case rad1
: /* Paperorientation */
1686 if (lppd
->Flags
& PD_PRINTSETUP
)
1688 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1689 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1690 (LPARAM
)(PrintStructures
->hPortraitIcon
));
1694 case rad2
: /* Paperorientation */
1695 if (lppd
->Flags
& PD_PRINTSETUP
)
1697 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1698 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
, (WPARAM
) IMAGE_ICON
,
1699 (LPARAM
)(PrintStructures
->hLandscapeIcon
));
1703 case cmb1
: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1704 if (PrinterComboID
!= LOWORD(wParam
)) {
1705 FIXME("No handling for print quality combo box yet.\n");
1709 case cmb4
: /* Printer combobox */
1710 if (HIWORD(wParam
)==CBN_SELCHANGE
) {
1711 WCHAR PrinterName
[256];
1712 GetDlgItemTextW(hDlg
, LOWORD(wParam
), PrinterName
, 255);
1713 PRINTDLG_ChangePrinterW(hDlg
, PrinterName
, PrintStructures
);
1717 case cmb2
: /* Papersize */
1719 DWORD Sel
= SendDlgItemMessageW(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0);
1721 lpdm
->u1
.s1
.dmPaperSize
= SendDlgItemMessageW(hDlg
, cmb2
,
1727 case cmb3
: /* Bin */
1729 DWORD Sel
= SendDlgItemMessageW(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0);
1731 lpdm
->u1
.s1
.dmDefaultSource
= SendDlgItemMessageW(hDlg
, cmb3
,
1732 CB_GETITEMDATA
, Sel
,
1737 if(lppd
->Flags
& PD_PRINTSETUP
) {
1738 switch (LOWORD(wParam
)) {
1739 case rad1
: /* orientation */
1741 if (IsDlgButtonChecked(hDlg
, rad1
) == BST_CHECKED
) {
1742 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_PORTRAIT
) {
1743 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
1744 SendDlgItemMessageW(hDlg
, stc10
, STM_SETIMAGE
,
1746 (LPARAM
)PrintStructures
->hPortraitIcon
);
1747 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
,
1749 (LPARAM
)PrintStructures
->hPortraitIcon
);
1752 if(lpdm
->u1
.s1
.dmOrientation
!= DMORIENT_LANDSCAPE
) {
1753 lpdm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
1754 SendDlgItemMessageW(hDlg
, stc10
, STM_SETIMAGE
,
1756 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1757 SendDlgItemMessageW(hDlg
, ico1
, STM_SETIMAGE
,
1759 (LPARAM
)PrintStructures
->hLandscapeIcon
);
1768 /***********************************************************************
1769 * PrintDlgProcA [internal]
1771 static INT_PTR CALLBACK
PrintDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
1774 PRINT_PTRA
* PrintStructures
;
1775 INT_PTR res
= FALSE
;
1777 if (uMsg
!=WM_INITDIALOG
) {
1778 PrintStructures
= (PRINT_PTRA
*)GetPropA(hDlg
,"__WINE_PRINTDLGDATA");
1779 if (!PrintStructures
)
1782 PrintStructures
= (PRINT_PTRA
*) lParam
;
1783 SetPropA(hDlg
,"__WINE_PRINTDLGDATA",PrintStructures
);
1784 if(!check_printer_setup(hDlg
))
1786 EndDialog(hDlg
,FALSE
);
1789 res
= PRINTDLG_WMInitDialog(hDlg
, wParam
, PrintStructures
);
1791 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
)
1792 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(
1793 hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->lpPrintDlg
1798 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
) {
1799 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
,uMsg
,wParam
,
1806 return PRINTDLG_WMCommandA(hDlg
, wParam
, lParam
, PrintStructures
);
1809 DestroyIcon(PrintStructures
->hCollateIcon
);
1810 DestroyIcon(PrintStructures
->hNoCollateIcon
);
1811 DestroyIcon(PrintStructures
->hPortraitIcon
);
1812 DestroyIcon(PrintStructures
->hLandscapeIcon
);
1813 if(PrintStructures
->hwndUpDown
)
1814 DestroyWindow(PrintStructures
->hwndUpDown
);
1820 static INT_PTR CALLBACK
PrintDlgProcW(HWND hDlg
, UINT uMsg
, WPARAM wParam
,
1823 static const WCHAR propW
[] = {'_','_','W','I','N','E','_','P','R','I','N','T','D','L','G','D','A','T','A',0};
1824 PRINT_PTRW
* PrintStructures
;
1825 INT_PTR res
= FALSE
;
1827 if (uMsg
!=WM_INITDIALOG
) {
1828 PrintStructures
= (PRINT_PTRW
*) GetPropW(hDlg
, propW
);
1829 if (!PrintStructures
)
1832 PrintStructures
= (PRINT_PTRW
*) lParam
;
1833 SetPropW(hDlg
, propW
, PrintStructures
);
1834 if(!check_printer_setup(hDlg
))
1836 EndDialog(hDlg
,FALSE
);
1839 res
= PRINTDLG_WMInitDialogW(hDlg
, wParam
, PrintStructures
);
1841 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
)
1842 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
, uMsg
, wParam
, (LPARAM
)PrintStructures
->lpPrintDlg
);
1846 if(PrintStructures
->lpPrintDlg
->Flags
& PD_ENABLEPRINTHOOK
) {
1847 res
= PrintStructures
->lpPrintDlg
->lpfnPrintHook(hDlg
,uMsg
,wParam
, lParam
);
1853 return PRINTDLG_WMCommandW(hDlg
, wParam
, lParam
, PrintStructures
);
1856 DestroyIcon(PrintStructures
->hCollateIcon
);
1857 DestroyIcon(PrintStructures
->hNoCollateIcon
);
1858 DestroyIcon(PrintStructures
->hPortraitIcon
);
1859 DestroyIcon(PrintStructures
->hLandscapeIcon
);
1860 if(PrintStructures
->hwndUpDown
)
1861 DestroyWindow(PrintStructures
->hwndUpDown
);
1867 /************************************************************
1869 * PRINTDLG_GetDlgTemplate
1872 static HGLOBAL
PRINTDLG_GetDlgTemplateA(const PRINTDLGA
*lppd
)
1877 if (lppd
->Flags
& PD_PRINTSETUP
) {
1878 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
1879 hDlgTmpl
= lppd
->hSetupTemplate
;
1880 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
1881 hResInfo
= FindResourceA(lppd
->hInstance
,
1882 lppd
->lpSetupTemplateName
, (LPSTR
)RT_DIALOG
);
1883 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1885 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32_SETUP",
1887 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1890 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
1891 hDlgTmpl
= lppd
->hPrintTemplate
;
1892 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
1893 hResInfo
= FindResourceA(lppd
->hInstance
,
1894 lppd
->lpPrintTemplateName
,
1896 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1898 hResInfo
= FindResourceA(COMDLG32_hInstance
, "PRINT32",
1900 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1906 static HGLOBAL
PRINTDLG_GetDlgTemplateW(const PRINTDLGW
*lppd
)
1910 static const WCHAR xpsetup
[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
1911 static const WCHAR xprint
[] = { 'P','R','I','N','T','3','2',0};
1913 if (lppd
->Flags
& PD_PRINTSETUP
) {
1914 if(lppd
->Flags
& PD_ENABLESETUPTEMPLATEHANDLE
) {
1915 hDlgTmpl
= lppd
->hSetupTemplate
;
1916 } else if(lppd
->Flags
& PD_ENABLESETUPTEMPLATE
) {
1917 hResInfo
= FindResourceW(lppd
->hInstance
,
1918 lppd
->lpSetupTemplateName
, (LPWSTR
)RT_DIALOG
);
1919 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1921 hResInfo
= FindResourceW(COMDLG32_hInstance
, xpsetup
, (LPWSTR
)RT_DIALOG
);
1922 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1925 if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATEHANDLE
) {
1926 hDlgTmpl
= lppd
->hPrintTemplate
;
1927 } else if(lppd
->Flags
& PD_ENABLEPRINTTEMPLATE
) {
1928 hResInfo
= FindResourceW(lppd
->hInstance
,
1929 lppd
->lpPrintTemplateName
,
1931 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
1933 hResInfo
= FindResourceW(COMDLG32_hInstance
, xprint
, (LPWSTR
)RT_DIALOG
);
1934 hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
);
1940 /***********************************************************************
1945 static BOOL
PRINTDLG_CreateDCA(LPPRINTDLGA lppd
)
1947 DEVNAMES
*pdn
= GlobalLock(lppd
->hDevNames
);
1948 DEVMODEA
*pdm
= GlobalLock(lppd
->hDevMode
);
1950 if(lppd
->Flags
& PD_RETURNDC
) {
1951 lppd
->hDC
= CreateDCA((char*)pdn
+ pdn
->wDriverOffset
,
1952 (char*)pdn
+ pdn
->wDeviceOffset
,
1953 (char*)pdn
+ pdn
->wOutputOffset
,
1955 } else if(lppd
->Flags
& PD_RETURNIC
) {
1956 lppd
->hDC
= CreateICA((char*)pdn
+ pdn
->wDriverOffset
,
1957 (char*)pdn
+ pdn
->wDeviceOffset
,
1958 (char*)pdn
+ pdn
->wOutputOffset
,
1961 GlobalUnlock(lppd
->hDevNames
);
1962 GlobalUnlock(lppd
->hDevMode
);
1963 return lppd
->hDC
? TRUE
: FALSE
;
1966 static BOOL
PRINTDLG_CreateDCW(LPPRINTDLGW lppd
)
1968 DEVNAMES
*pdn
= GlobalLock(lppd
->hDevNames
);
1969 DEVMODEW
*pdm
= GlobalLock(lppd
->hDevMode
);
1971 if(lppd
->Flags
& PD_RETURNDC
) {
1972 lppd
->hDC
= CreateDCW((WCHAR
*)pdn
+ pdn
->wDriverOffset
,
1973 (WCHAR
*)pdn
+ pdn
->wDeviceOffset
,
1974 (WCHAR
*)pdn
+ pdn
->wOutputOffset
,
1976 } else if(lppd
->Flags
& PD_RETURNIC
) {
1977 lppd
->hDC
= CreateICW((WCHAR
*)pdn
+ pdn
->wDriverOffset
,
1978 (WCHAR
*)pdn
+ pdn
->wDeviceOffset
,
1979 (WCHAR
*)pdn
+ pdn
->wOutputOffset
,
1982 GlobalUnlock(lppd
->hDevNames
);
1983 GlobalUnlock(lppd
->hDevMode
);
1984 return lppd
->hDC
? TRUE
: FALSE
;
1987 /***********************************************************************
1988 * PrintDlgA (COMDLG32.@)
1990 * Displays the PRINT dialog box, which enables the user to specify
1991 * specific properties of the print job.
1994 * lppd [IO] ptr to PRINTDLG32 struct
1997 * nonzero if the user pressed the OK button
1998 * zero if the user cancelled the window or an error occurred
2002 * * The Collate Icons do not display, even though they are in the code.
2003 * * The Properties Button(s) should call DocumentPropertiesA().
2006 BOOL WINAPI
PrintDlgA(LPPRINTDLGA lppd
)
2014 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
2018 hInst
= (HINSTANCE
)GetWindowLongPtrA( lppd
->hwndOwner
, GWLP_HINSTANCE
);
2019 if(TRACE_ON(commdlg
)) {
2020 char flagstr
[1000] = "";
2021 const struct pd_flags
*pflag
= pd_flags
;
2022 for( ; pflag
->name
; pflag
++) {
2023 if(lppd
->Flags
& pflag
->flag
)
2024 strcat(flagstr
, pflag
->name
);
2026 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2027 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2028 "flags %08x (%s)\n",
2029 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
2030 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
2031 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
2034 if(lppd
->lStructSize
!= sizeof(PRINTDLGA
)) {
2035 WARN("structure size failure !!!\n");
2036 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
2040 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
2041 PRINTER_INFO_2A
*pbuf
;
2042 DRIVER_INFO_3A
*dbuf
;
2046 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
2047 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2048 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2051 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
2052 WARN("Can't find default printer\n");
2053 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
2057 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
2058 pbuf
= HeapAlloc(GetProcessHeap(), 0, needed
);
2059 GetPrinterA(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
2061 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
2062 dbuf
= HeapAlloc(GetProcessHeap(),0,needed
);
2063 if (!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
2064 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2065 GetLastError(),pbuf
->pPrinterName
);
2066 HeapFree(GetProcessHeap(), 0, dbuf
);
2067 HeapFree(GetProcessHeap(), 0, pbuf
);
2068 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2073 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
2077 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
2078 pbuf
->pDevMode
->dmDriverExtra
);
2079 ptr
= GlobalLock(lppd
->hDevMode
);
2080 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
2081 pbuf
->pDevMode
->dmDriverExtra
);
2082 GlobalUnlock(lppd
->hDevMode
);
2083 HeapFree(GetProcessHeap(), 0, pbuf
);
2084 HeapFree(GetProcessHeap(), 0, dbuf
);
2088 PRINT_PTRA
*PrintStructures
;
2090 /* load Dialog resources,
2091 * depending on Flags indicates Print32 or Print32_setup dialog
2093 hDlgTmpl
= PRINTDLG_GetDlgTemplateA(lppd
);
2095 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2098 ptr
= LockResource( hDlgTmpl
);
2100 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2104 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2105 sizeof(PRINT_PTRA
));
2106 PrintStructures
->lpPrintDlg
= lppd
;
2108 /* and create & process the dialog .
2109 * -1 is failure, 0 is broken hwnd, everything else is ok.
2111 bRet
= (0<DialogBoxIndirectParamA(hInst
, ptr
, lppd
->hwndOwner
,
2113 (LPARAM
)PrintStructures
));
2116 DEVMODEA
*lpdm
= PrintStructures
->lpDevMode
, *lpdmReturn
;
2117 PRINTER_INFO_2A
*pi
= PrintStructures
->lpPrinterInfo
;
2118 DRIVER_INFO_3A
*di
= PrintStructures
->lpDriverInfo
;
2120 if (lppd
->hDevMode
== 0) {
2121 TRACE(" No hDevMode yet... Need to create my own\n");
2122 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
,
2123 lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2125 lppd
->hDevMode
= GlobalReAlloc(lppd
->hDevMode
,
2126 lpdm
->dmSize
+ lpdm
->dmDriverExtra
,
2129 lpdmReturn
= GlobalLock(lppd
->hDevMode
);
2130 memcpy(lpdmReturn
, lpdm
, lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2132 PRINTDLG_CreateDevNames(&(lppd
->hDevNames
),
2137 GlobalUnlock(lppd
->hDevMode
);
2139 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
2140 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpPrinterInfo
);
2141 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDriverInfo
);
2142 HeapFree(GetProcessHeap(), 0, PrintStructures
);
2144 if(bRet
&& (lppd
->Flags
& PD_RETURNDC
|| lppd
->Flags
& PD_RETURNIC
))
2145 bRet
= PRINTDLG_CreateDCA(lppd
);
2147 TRACE("exit! (%d)\n", bRet
);
2151 /***********************************************************************
2152 * PrintDlgW (COMDLG32.@)
2156 BOOL WINAPI
PrintDlgW(LPPRINTDLGW lppd
)
2164 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
2168 hInst
= (HINSTANCE
)GetWindowLongPtrW( lppd
->hwndOwner
, GWLP_HINSTANCE
);
2169 if(TRACE_ON(commdlg
)) {
2170 char flagstr
[1000] = "";
2171 const struct pd_flags
*pflag
= pd_flags
;
2172 for( ; pflag
->name
; pflag
++) {
2173 if(lppd
->Flags
& pflag
->flag
)
2174 strcat(flagstr
, pflag
->name
);
2176 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2177 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2178 "flags %08x (%s)\n",
2179 lppd
, lppd
->hwndOwner
, lppd
->hDevMode
, lppd
->hDevNames
,
2180 lppd
->nFromPage
, lppd
->nToPage
, lppd
->nMinPage
, lppd
->nMaxPage
,
2181 lppd
->nCopies
, lppd
->hInstance
, lppd
->Flags
, flagstr
);
2184 if(lppd
->lStructSize
!= sizeof(PRINTDLGW
)) {
2185 WARN("structure size failure !!!\n");
2186 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
2190 if(lppd
->Flags
& PD_RETURNDEFAULT
) {
2191 PRINTER_INFO_2W
*pbuf
;
2192 DRIVER_INFO_3W
*dbuf
;
2196 if(lppd
->hDevMode
|| lppd
->hDevNames
) {
2197 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2198 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2201 if(!PRINTDLG_OpenDefaultPrinter(&hprn
)) {
2202 WARN("Can't find default printer\n");
2203 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN
);
2207 GetPrinterW(hprn
, 2, NULL
, 0, &needed
);
2208 pbuf
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*needed
);
2209 GetPrinterW(hprn
, 2, (LPBYTE
)pbuf
, needed
, &needed
);
2211 GetPrinterDriverW(hprn
, NULL
, 3, NULL
, 0, &needed
);
2212 dbuf
= HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*needed
);
2213 if (!GetPrinterDriverW(hprn
, NULL
, 3, (LPBYTE
)dbuf
, needed
, &needed
)) {
2214 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2215 GetLastError(),debugstr_w(pbuf
->pPrinterName
));
2216 HeapFree(GetProcessHeap(), 0, dbuf
);
2217 HeapFree(GetProcessHeap(), 0, pbuf
);
2218 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE
);
2223 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
2227 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
, pbuf
->pDevMode
->dmSize
+
2228 pbuf
->pDevMode
->dmDriverExtra
);
2229 ptr
= GlobalLock(lppd
->hDevMode
);
2230 memcpy(ptr
, pbuf
->pDevMode
, pbuf
->pDevMode
->dmSize
+
2231 pbuf
->pDevMode
->dmDriverExtra
);
2232 GlobalUnlock(lppd
->hDevMode
);
2233 HeapFree(GetProcessHeap(), 0, pbuf
);
2234 HeapFree(GetProcessHeap(), 0, dbuf
);
2238 PRINT_PTRW
*PrintStructures
;
2240 /* load Dialog resources,
2241 * depending on Flags indicates Print32 or Print32_setup dialog
2243 hDlgTmpl
= PRINTDLG_GetDlgTemplateW(lppd
);
2245 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2248 ptr
= LockResource( hDlgTmpl
);
2250 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
2254 PrintStructures
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2255 sizeof(PRINT_PTRW
));
2256 PrintStructures
->lpPrintDlg
= lppd
;
2258 /* and create & process the dialog .
2259 * -1 is failure, 0 is broken hwnd, everything else is ok.
2261 bRet
= (0<DialogBoxIndirectParamW(hInst
, ptr
, lppd
->hwndOwner
,
2263 (LPARAM
)PrintStructures
));
2266 DEVMODEW
*lpdm
= PrintStructures
->lpDevMode
, *lpdmReturn
;
2267 PRINTER_INFO_2W
*pi
= PrintStructures
->lpPrinterInfo
;
2268 DRIVER_INFO_3W
*di
= PrintStructures
->lpDriverInfo
;
2270 if (lppd
->hDevMode
== 0) {
2271 TRACE(" No hDevMode yet... Need to create my own\n");
2272 lppd
->hDevMode
= GlobalAlloc(GMEM_MOVEABLE
,
2273 lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2276 if((locks
= (GlobalFlags(lppd
->hDevMode
) & GMEM_LOCKCOUNT
))) {
2277 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks
);
2279 GlobalUnlock(lppd
->hDevMode
);
2280 TRACE("Now got %d locks\n", locks
);
2283 lppd
->hDevMode
= GlobalReAlloc(lppd
->hDevMode
,
2284 lpdm
->dmSize
+ lpdm
->dmDriverExtra
,
2287 lpdmReturn
= GlobalLock(lppd
->hDevMode
);
2288 memcpy(lpdmReturn
, lpdm
, lpdm
->dmSize
+ lpdm
->dmDriverExtra
);
2290 if (lppd
->hDevNames
!= 0) {
2292 if((locks
= (GlobalFlags(lppd
->hDevNames
) & GMEM_LOCKCOUNT
))) {
2293 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks
);
2295 GlobalUnlock(lppd
->hDevNames
);
2298 PRINTDLG_CreateDevNamesW(&(lppd
->hDevNames
),
2303 GlobalUnlock(lppd
->hDevMode
);
2305 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDevMode
);
2306 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpPrinterInfo
);
2307 HeapFree(GetProcessHeap(), 0, PrintStructures
->lpDriverInfo
);
2308 HeapFree(GetProcessHeap(), 0, PrintStructures
);
2310 if(bRet
&& (lppd
->Flags
& PD_RETURNDC
|| lppd
->Flags
& PD_RETURNIC
))
2311 bRet
= PRINTDLG_CreateDCW(lppd
);
2313 TRACE("exit! (%d)\n", bRet
);
2317 /***********************************************************************
2322 * cmb1 - printer select (not in standard dialog template)
2324 * cmb3 - source (tray?)
2325 * edt4 - border left
2327 * edt6 - border right
2328 * edt7 - border bottom
2329 * psh3 - "Printer..."
2333 LPPAGESETUPDLGA dlga
; /* Handler to user defined struct */
2335 HWND hDlg
; /* Page Setup dialog handler */
2336 PAGESETUPDLGA curdlg
; /* Stores the current dialog state */
2337 RECT rtDrawRect
; /* Drawing rect for page */
2341 LPPAGESETUPDLGW dlga
;
2343 PAGESETUPDLGW curdlg
; /* Current dialog state */
2347 static HGLOBAL
PRINTDLG_GetPGSTemplateA(const PAGESETUPDLGA
*lppd
)
2352 if(lppd
->Flags
& PSD_ENABLEPAGESETUPTEMPLATEHANDLE
) {
2353 hDlgTmpl
= lppd
->hPageSetupTemplate
;
2354 } else if(lppd
->Flags
& PSD_ENABLEPAGESETUPTEMPLATE
) {
2355 hResInfo
= FindResourceA(lppd
->hInstance
,
2356 lppd
->lpPageSetupTemplateName
, (LPSTR
)RT_DIALOG
);
2357 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
2359 hResInfo
= FindResourceA(COMDLG32_hInstance
,(LPCSTR
)PAGESETUPDLGORD
,(LPSTR
)RT_DIALOG
);
2360 hDlgTmpl
= LoadResource(COMDLG32_hInstance
,hResInfo
);
2365 static HGLOBAL
PRINTDLG_GetPGSTemplateW(const PAGESETUPDLGW
*lppd
)
2370 if(lppd
->Flags
& PSD_ENABLEPAGESETUPTEMPLATEHANDLE
) {
2371 hDlgTmpl
= lppd
->hPageSetupTemplate
;
2372 } else if(lppd
->Flags
& PSD_ENABLEPAGESETUPTEMPLATE
) {
2373 hResInfo
= FindResourceW(lppd
->hInstance
,
2374 lppd
->lpPageSetupTemplateName
, (LPWSTR
)RT_DIALOG
);
2375 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
2377 hResInfo
= FindResourceW(COMDLG32_hInstance
,(LPCWSTR
)PAGESETUPDLGORD
,(LPWSTR
)RT_DIALOG
);
2378 hDlgTmpl
= LoadResource(COMDLG32_hInstance
,hResInfo
);
2384 _c_10mm2size(PAGESETUPDLGA
*dlga
,DWORD size
) {
2385 if (dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
)
2386 return 10*size
*100/254;
2387 /* If we don't have a flag, we can choose one. Use millimeters
2388 * to avoid confusing me
2390 dlga
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
2396 _c_inch2size(PAGESETUPDLGA
*dlga
,DWORD size
) {
2397 if (dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
)
2399 if (dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
)
2400 return (size
*254)/100;
2401 /* if we don't have a flag, we can choose one. Use millimeters
2402 * to avoid confusing me
2404 dlga
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
2405 return (size
*254)/100;
2409 _c_size2strA(PageSetupDataA
*pda
,DWORD size
,LPSTR strout
) {
2410 strcpy(strout
,"<undef>");
2411 if (pda
->dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
) {
2412 sprintf(strout
,"%d",(size
)/100);
2415 if (pda
->dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
) {
2416 sprintf(strout
,"%din",(size
)/1000);
2419 pda
->dlga
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
2420 sprintf(strout
,"%d",(size
)/100);
2424 _c_size2strW(PageSetupDataW
*pda
,DWORD size
,LPWSTR strout
) {
2425 static const char mm_fmt
[] = "%.2f mm";
2426 static const char in_fmt
[] = "%.2f in";
2428 if (pda
->dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
) {
2429 sprintf(buf
, mm_fmt
, (size
* 1.0) / 100.0);
2430 } else if (pda
->dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
) {
2431 sprintf(buf
, in_fmt
, (size
* 1.0) / 1000.0);
2433 pda
->dlga
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
2434 sprintf(buf
, mm_fmt
, (size
* 1.0) / 100.0);
2437 MultiByteToWideChar(CP_ACP
, 0, buf
, -1, strout
, 20);
2441 _c_str2sizeA(const PAGESETUPDLGA
*dlga
, LPCSTR strin
) {
2446 if (!sscanf(strin
,"%f%s",&val
,rest
))
2449 if (!strcmp(rest
,"in") || !strcmp(rest
,"inch")) {
2450 if (dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
)
2453 return val
*25.4*100;
2455 if (!strcmp(rest
,"cm")) { rest
[0]='m'; val
= val
*10.0; }
2456 if (!strcmp(rest
,"m")) { strcpy(rest
,"mm"); val
= val
*1000.0; }
2458 if (!strcmp(rest
,"mm")) {
2459 if (dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
)
2462 return 1000.0*val
/25.4;
2464 if (rest
[0]=='\0') {
2465 /* use application supplied default */
2466 if (dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
) {
2470 if (dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
) {
2475 ERR("Did not find a conversion for type '%s'!\n",rest
);
2481 _c_str2sizeW(const PAGESETUPDLGW
*dlga
, LPCWSTR strin
) {
2484 /* this W -> A transition is OK */
2485 /* we need a unicode version of sscanf to avoid it */
2486 WideCharToMultiByte(CP_ACP
, 0, strin
, -1, buf
, sizeof(buf
), NULL
, NULL
);
2487 return _c_str2sizeA((const PAGESETUPDLGA
*)dlga
, buf
);
2491 /****************************************************************************
2492 * PRINTDLG_PS_UpdateDlgStructA
2494 * Updates pda->dlga structure
2495 * Function calls when user presses OK button
2498 * hDlg [in] main window dialog HANDLE
2499 * pda [in/out] ptr to PageSetupDataA structure
2505 PRINTDLG_PS_UpdateDlgStructA(HWND hDlg
, PageSetupDataA
*pda
) {
2510 memcpy(pda
->dlga
, &pda
->curdlg
, sizeof(pda
->curdlg
));
2511 pda
->dlga
->hDevMode
= pda
->pdlg
.hDevMode
;
2512 pda
->dlga
->hDevNames
= pda
->pdlg
.hDevNames
;
2514 dn
= GlobalLock(pda
->pdlg
.hDevNames
);
2515 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2517 /* Save paper orientation into device context */
2518 if(pda
->curdlg
.ptPaperSize
.x
> pda
->curdlg
.ptPaperSize
.y
)
2519 dm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
2521 dm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
2523 /* Save paper size into the device context */
2524 paperword
= SendDlgItemMessageA(hDlg
,cmb2
,CB_GETITEMDATA
,
2525 SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0), 0);
2526 if (paperword
!= CB_ERR
)
2527 dm
->u1
.s1
.dmPaperSize
= paperword
;
2529 FIXME("could not get dialog text for papersize cmbbox?\n");
2531 /* Save paper source into the device context */
2532 paperword
= SendDlgItemMessageA(hDlg
,cmb1
,CB_GETITEMDATA
,
2533 SendDlgItemMessageA(hDlg
, cmb1
, CB_GETCURSEL
, 0, 0), 0);
2534 if (paperword
!= CB_ERR
)
2535 dm
->u1
.s1
.dmDefaultSource
= paperword
;
2537 FIXME("could not get dialog text for papersize cmbbox?\n");
2539 GlobalUnlock(pda
->pdlg
.hDevNames
);
2540 GlobalUnlock(pda
->pdlg
.hDevMode
);
2546 PRINTDLG_PS_UpdateDlgStructW(HWND hDlg
, PageSetupDataW
*pda
) {
2549 LPWSTR devname
,portname
;
2550 WCHAR papername
[64];
2553 dn
= GlobalLock(pda
->pdlg
.hDevNames
);
2554 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2555 devname
= ((WCHAR
*)dn
)+dn
->wDeviceOffset
;
2556 portname
= ((WCHAR
*)dn
)+dn
->wOutputOffset
;
2558 /* Save paper size into device context */
2559 PRINTDLG_SetUpPaperComboBoxW(hDlg
,cmb2
,devname
,portname
,dm
);
2560 /* Save paper source into device context */
2561 PRINTDLG_SetUpPaperComboBoxW(hDlg
,cmb3
,devname
,portname
,dm
);
2563 if (GetDlgItemTextW(hDlg
,cmb2
,papername
,sizeof(papername
))>0) {
2564 PRINTDLG_PaperSizeW(&(pda
->pdlg
),papername
,&(pda
->dlga
->ptPaperSize
));
2565 pda
->dlga
->ptPaperSize
.x
= _c_10mm2size((LPPAGESETUPDLGA
)pda
->dlga
,pda
->dlga
->ptPaperSize
.x
);
2566 pda
->dlga
->ptPaperSize
.y
= _c_10mm2size((LPPAGESETUPDLGA
)pda
->dlga
,pda
->dlga
->ptPaperSize
.y
);
2568 FIXME("could not get dialog text for papersize cmbbox?\n");
2569 #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); }
2570 GETVAL(edt4
,pda
->dlga
->rtMargin
.left
);
2571 GETVAL(edt5
,pda
->dlga
->rtMargin
.top
);
2572 GETVAL(edt6
,pda
->dlga
->rtMargin
.right
);
2573 GETVAL(edt7
,pda
->dlga
->rtMargin
.bottom
);
2576 /* If we are in landscape, swap x and y of page size */
2577 if (IsDlgButtonChecked(hDlg
, rad2
)) {
2579 tmp
= pda
->dlga
->ptPaperSize
.x
;
2580 pda
->dlga
->ptPaperSize
.x
= pda
->dlga
->ptPaperSize
.y
;
2581 pda
->dlga
->ptPaperSize
.y
= tmp
;
2584 /* Save orientation */
2585 if (pda
->dlga
->ptPaperSize
.x
> pda
->dlga
->ptPaperSize
.y
)
2586 dm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
2588 dm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
2590 GlobalUnlock(pda
->pdlg
.hDevNames
);
2591 GlobalUnlock(pda
->pdlg
.hDevMode
);
2595 /**********************************************************************************************
2596 * PRINTDLG_PS_ChangeActivePrinerA
2598 * Redefines hDevMode and hDevNames HANDLES and initialises it.
2601 * name [in] Name of a printer for activation
2602 * pda [in/out] ptr to PageSetupDataA structure
2609 PRINTDLG_PS_ChangeActivePrinterA(LPSTR name
, PageSetupDataA
*pda
){
2612 LPPRINTER_INFO_2A lpPrinterInfo
;
2613 LPDRIVER_INFO_3A lpDriverInfo
;
2614 DEVMODEA
*pDevMode
, *dm
;
2616 if(!OpenPrinterA(name
, &hprn
, NULL
)){
2617 ERR("Can't open printer %s\n", name
);
2620 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
2621 lpPrinterInfo
= HeapAlloc(GetProcessHeap(), 0, needed
);
2622 GetPrinterA(hprn
, 2, (LPBYTE
)lpPrinterInfo
, needed
, &needed
);
2623 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
2624 lpDriverInfo
= HeapAlloc(GetProcessHeap(), 0, needed
);
2625 if(!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)lpDriverInfo
, needed
, &needed
)) {
2626 ERR("GetPrinterDriverA failed for %s, fix your config!\n", lpPrinterInfo
->pPrinterName
);
2627 HeapFree(GetProcessHeap(), 0, lpDriverInfo
);
2628 HeapFree(GetProcessHeap(), 0, lpPrinterInfo
);
2633 needed
= DocumentPropertiesA(0, 0, name
, NULL
, NULL
, 0);
2635 ERR("DocumentProperties fails on %s\n", debugstr_a(name
));
2636 HeapFree(GetProcessHeap(), 0, lpDriverInfo
);
2637 HeapFree(GetProcessHeap(), 0, lpPrinterInfo
);
2640 pDevMode
= HeapAlloc(GetProcessHeap(), 0, needed
);
2641 DocumentPropertiesA(0, 0, name
, pDevMode
, NULL
, DM_OUT_BUFFER
);
2643 pda
->pdlg
.hDevMode
= GlobalReAlloc(pda
->pdlg
.hDevMode
,
2644 pDevMode
->dmSize
+ pDevMode
->dmDriverExtra
,
2646 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2647 memcpy(dm
, pDevMode
, pDevMode
->dmSize
+ pDevMode
->dmDriverExtra
);
2649 PRINTDLG_CreateDevNames(&(pda
->pdlg
.hDevNames
),
2650 lpDriverInfo
->pDriverPath
,
2651 lpPrinterInfo
->pPrinterName
,
2652 lpPrinterInfo
->pPortName
);
2654 GlobalUnlock(pda
->pdlg
.hDevMode
);
2655 HeapFree(GetProcessHeap(), 0, pDevMode
);
2656 HeapFree(GetProcessHeap(), 0, lpPrinterInfo
);
2657 HeapFree(GetProcessHeap(), 0, lpDriverInfo
);
2661 /****************************************************************************************
2662 * PRINTDLG_PS_ChangePrinterA
2664 * Fills Printers, Paper and Source combo
2670 PRINTDLG_PS_ChangePrinterA(HWND hDlg
, PageSetupDataA
*pda
) {
2673 LPSTR devname
,portname
;
2675 dn
= GlobalLock(pda
->pdlg
.hDevNames
);
2676 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2677 devname
= ((char*)dn
)+dn
->wDeviceOffset
;
2678 portname
= ((char*)dn
)+dn
->wOutputOffset
;
2679 PRINTDLG_SetUpPrinterListComboA(hDlg
, cmb1
, devname
);
2680 PRINTDLG_SetUpPaperComboBoxA(hDlg
,cmb2
,devname
,portname
,dm
);
2681 PRINTDLG_SetUpPaperComboBoxA(hDlg
,cmb3
,devname
,portname
,dm
);
2682 GlobalUnlock(pda
->pdlg
.hDevNames
);
2683 GlobalUnlock(pda
->pdlg
.hDevMode
);
2687 static void PRINTDLG_PS_SetOrientationW(HWND hDlg
, PageSetupDataW
* pda
)
2689 WCHAR PaperName
[64];
2691 GetDlgItemTextW(hDlg
, cmb2
, PaperName
, sizeof(PaperName
)/sizeof(WCHAR
));
2692 PRINTDLG_PaperSizeW(&pda
->pdlg
, PaperName
, &pda
->curdlg
.ptPaperSize
);
2693 pda
->curdlg
.ptPaperSize
.x
= _c_10mm2size((LPPAGESETUPDLGA
)pda
->dlga
, pda
->curdlg
.ptPaperSize
.x
);
2694 pda
->curdlg
.ptPaperSize
.y
= _c_10mm2size((LPPAGESETUPDLGA
)pda
->dlga
, pda
->curdlg
.ptPaperSize
.y
);
2696 if(IsDlgButtonChecked(hDlg
, rad2
))
2698 DWORD tmp
= pda
->curdlg
.ptPaperSize
.x
;
2699 pda
->curdlg
.ptPaperSize
.x
= pda
->curdlg
.ptPaperSize
.y
;
2700 pda
->curdlg
.ptPaperSize
.y
= tmp
;
2705 PRINTDLG_PS_ChangePrinterW(HWND hDlg
, PageSetupDataW
*pda
) {
2708 LPWSTR devname
,portname
;
2710 dn
= GlobalLock(pda
->pdlg
.hDevNames
);
2711 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2712 devname
= ((WCHAR
*)dn
)+dn
->wDeviceOffset
;
2713 portname
= ((WCHAR
*)dn
)+dn
->wOutputOffset
;
2714 PRINTDLG_SetUpPaperComboBoxW(hDlg
,cmb2
,devname
,portname
,dm
);
2715 PRINTDLG_SetUpPaperComboBoxW(hDlg
,cmb3
,devname
,portname
,dm
);
2717 /* Landscape orientation */
2718 if (dm
->u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
)
2719 CheckRadioButton(hDlg
, rad1
, rad2
, rad2
);
2720 else /* this is default if papersize is not set */
2721 CheckRadioButton(hDlg
, rad1
, rad2
, rad1
);
2723 GlobalUnlock(pda
->pdlg
.hDevNames
);
2724 GlobalUnlock(pda
->pdlg
.hDevMode
);
2726 PRINTDLG_PS_SetOrientationW(hDlg
, pda
);
2731 /******************************************************************************************
2732 * PRINTDLG_PS_ChangePaperPrev
2734 * Changes paper preview size / position
2737 * pda [i] Pointer for current PageSetupDataA structure
2743 PRINTDLG_PS_ChangePaperPrev(const PageSetupDataA
*pda
)
2745 LONG width
, height
, x
, y
;
2748 if(pda
->curdlg
.ptPaperSize
.x
> pda
->curdlg
.ptPaperSize
.y
) {
2749 width
= pda
->rtDrawRect
.right
- pda
->rtDrawRect
.left
;
2750 height
= pda
->curdlg
.ptPaperSize
.y
* width
/ pda
->curdlg
.ptPaperSize
.x
;
2752 height
= pda
->rtDrawRect
.bottom
- pda
->rtDrawRect
.top
;
2753 width
= pda
->curdlg
.ptPaperSize
.x
* height
/ pda
->curdlg
.ptPaperSize
.y
;
2755 x
= (pda
->rtDrawRect
.right
+ pda
->rtDrawRect
.left
- width
) / 2;
2756 y
= (pda
->rtDrawRect
.bottom
+ pda
->rtDrawRect
.top
- height
) / 2;
2757 TRACE("rtDrawRect(%d, %d, %d, %d) x=%d, y=%d, w=%d, h=%d\n",
2758 pda
->rtDrawRect
.left
, pda
->rtDrawRect
.top
, pda
->rtDrawRect
.right
, pda
->rtDrawRect
.bottom
,
2759 x
, y
, width
, height
);
2762 MoveWindow(GetDlgItem(pda
->hDlg
, rct2
), x
+width
, y
+SHADOW
, SHADOW
, height
, FALSE
);
2763 MoveWindow(GetDlgItem(pda
->hDlg
, rct3
), x
+SHADOW
, y
+height
, width
, SHADOW
, FALSE
);
2764 MoveWindow(GetDlgItem(pda
->hDlg
, rct1
), x
, y
, width
, height
, FALSE
);
2765 memcpy(&rtTmp
, &pda
->rtDrawRect
, sizeof(RECT
));
2766 rtTmp
.right
+= SHADOW
;
2767 rtTmp
.bottom
+= SHADOW
;
2770 InvalidateRect(pda
->hDlg
, &rtTmp
, TRUE
);
2774 #define GETVAL(idc,val) \
2775 if(msg == EN_CHANGE){ \
2776 if (GetDlgItemTextA(hDlg,idc,buf,sizeof(buf)) > 0)\
2777 val = _c_str2sizeA(pda->dlga,buf); \
2779 FIXME("could not get dlgitemtexta for %x\n",id); \
2782 /********************************************************************************
2783 * PRINTDLG_PS_WMCommandA
2784 * process WM_COMMAND message for PageSetupDlgA
2787 * hDlg [in] Main dialog HANDLE
2788 * wParam [in] WM_COMMAND wParam
2789 * lParam [in] WM_COMMAND lParam
2790 * pda [in/out] ptr to PageSetupDataA
2794 PRINTDLG_PS_WMCommandA(
2795 HWND hDlg
, WPARAM wParam
, LPARAM lParam
, PageSetupDataA
*pda
2797 WORD msg
= HIWORD(wParam
);
2798 WORD id
= LOWORD(wParam
);
2801 TRACE("loword (lparam) %d, wparam 0x%lx, lparam %08lx\n",
2802 LOWORD(lParam
),wParam
,lParam
);
2805 if (!PRINTDLG_PS_UpdateDlgStructA(hDlg
, pda
))
2807 EndDialog(hDlg
, TRUE
);
2811 EndDialog(hDlg
, FALSE
);
2815 pda
->pdlg
.Flags
= 0;
2816 pda
->pdlg
.hwndOwner
= hDlg
;
2817 if (PrintDlgA(&(pda
->pdlg
)))
2818 PRINTDLG_PS_ChangePrinterA(hDlg
,pda
);
2823 if((id
== rad1
&& pda
->curdlg
.ptPaperSize
.x
> pda
->curdlg
.ptPaperSize
.y
) ||
2824 (id
== rad2
&& pda
->curdlg
.ptPaperSize
.y
> pda
->curdlg
.ptPaperSize
.x
))
2828 DWORD tmp
= pda
->curdlg
.ptPaperSize
.x
;
2830 pda
->curdlg
.ptPaperSize
.x
= pda
->curdlg
.ptPaperSize
.y
;
2831 pda
->curdlg
.ptPaperSize
.y
= tmp
;
2833 GetDlgItemTextA(hDlg
, edt4
, TmpText
, sizeof(TmpText
));
2834 GetDlgItemTextA(hDlg
, edt5
, TmpText2
, sizeof(TmpText2
));
2835 SetDlgItemTextA(hDlg
, edt5
, TmpText
);
2836 SetDlgItemTextA(hDlg
, edt4
, TmpText2
);
2838 GetDlgItemTextA(hDlg
, edt6
, TmpText
, sizeof(TmpText
));
2839 GetDlgItemTextA(hDlg
, edt7
, TmpText2
, sizeof(TmpText2
));
2840 SetDlgItemTextA(hDlg
, edt7
, TmpText
);
2841 SetDlgItemTextA(hDlg
, edt6
, TmpText2
);
2843 PRINTDLG_PS_ChangePaperPrev(pda
);
2846 case cmb1
: /* Printer combo */
2847 if(msg
== CBN_SELCHANGE
){
2848 char crPrinterName
[256];
2849 GetDlgItemTextA(hDlg
, id
, crPrinterName
, 255);
2850 PRINTDLG_PS_ChangeActivePrinterA(crPrinterName
, pda
);
2851 PRINTDLG_PS_ChangePrinterA(hDlg
, pda
);
2854 case cmb2
: /* Paper combo */
2855 if(msg
== CBN_SELCHANGE
){
2856 DWORD paperword
= SendDlgItemMessageA(hDlg
,cmb2
,CB_GETITEMDATA
,
2857 SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0), 0);
2858 if (paperword
!= CB_ERR
) {
2859 PRINTDLG_PaperSizeA(&(pda
->pdlg
), paperword
,&(pda
->curdlg
.ptPaperSize
));
2860 pda
->curdlg
.ptPaperSize
.x
= _c_10mm2size(pda
->dlga
,pda
->curdlg
.ptPaperSize
.x
);
2861 pda
->curdlg
.ptPaperSize
.y
= _c_10mm2size(pda
->dlga
,pda
->curdlg
.ptPaperSize
.y
);
2863 if (IsDlgButtonChecked(hDlg
, rad2
)) {
2864 DWORD tmp
= pda
->curdlg
.ptPaperSize
.x
;
2865 pda
->curdlg
.ptPaperSize
.x
= pda
->curdlg
.ptPaperSize
.y
;
2866 pda
->curdlg
.ptPaperSize
.y
= tmp
;
2868 PRINTDLG_PS_ChangePaperPrev(pda
);
2870 FIXME("could not get dialog text for papersize cmbbox?\n");
2874 if(msg
== CBN_SELCHANGE
){
2875 DEVMODEA
*dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2876 dm
->u1
.s1
.dmDefaultSource
= SendDlgItemMessageA(hDlg
, cmb3
,CB_GETITEMDATA
,
2877 SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0), 0);
2878 GlobalUnlock(pda
->pdlg
.hDevMode
);
2881 case psh2
: /* Printer Properties button */
2884 char PrinterName
[256];
2889 GetDlgItemTextA(hDlg
, cmb1
, PrinterName
, 255);
2890 if (!OpenPrinterA(PrinterName
, &hPrinter
, NULL
)) {
2891 FIXME("Call to OpenPrinter did not succeed!\n");
2894 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2895 DocumentPropertiesA(hDlg
, hPrinter
, PrinterName
, dm
, dm
,
2896 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
2897 ClosePrinter(hPrinter
);
2898 /* Changing paper */
2899 PRINTDLG_PaperSizeA(&(pda
->pdlg
), dm
->u1
.s1
.dmPaperSize
, &(pda
->curdlg
.ptPaperSize
));
2900 pda
->curdlg
.ptPaperSize
.x
= _c_10mm2size(pda
->dlga
, pda
->curdlg
.ptPaperSize
.x
);
2901 pda
->curdlg
.ptPaperSize
.y
= _c_10mm2size(pda
->dlga
, pda
->curdlg
.ptPaperSize
.y
);
2902 if (dm
->u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
){
2903 DWORD tmp
= pda
->curdlg
.ptPaperSize
.x
;
2904 pda
->curdlg
.ptPaperSize
.x
= pda
->curdlg
.ptPaperSize
.y
;
2905 pda
->curdlg
.ptPaperSize
.y
= tmp
;
2906 CheckRadioButton(hDlg
, rad1
, rad2
, rad2
);
2909 CheckRadioButton(hDlg
, rad1
, rad2
, rad1
);
2910 /* Changing paper preview */
2911 PRINTDLG_PS_ChangePaperPrev(pda
);
2912 /* Selecting paper in combo */
2913 count
= SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCOUNT
, 0, 0);
2914 if(count
!= CB_ERR
){
2915 for(i
=0; i
<count
; ++i
){
2916 if(SendDlgItemMessageA(hDlg
, cmb2
, CB_GETITEMDATA
, i
, 0) == dm
->u1
.s1
.dmPaperSize
) {
2917 SendDlgItemMessageA(hDlg
, cmb2
, CB_SETCURSEL
, i
, 0);
2923 GlobalUnlock(pda
->pdlg
.hDevMode
);
2927 GETVAL(id
, pda
->curdlg
.rtMargin
.left
);
2930 GETVAL(id
, pda
->curdlg
.rtMargin
.top
);
2933 GETVAL(id
, pda
->curdlg
.rtMargin
.right
);
2936 GETVAL(id
, pda
->curdlg
.rtMargin
.bottom
);
2939 InvalidateRect(GetDlgItem(hDlg
, rct1
), NULL
, TRUE
);
2945 PRINTDLG_PS_WMCommandW(
2946 HWND hDlg
, WPARAM wParam
, LPARAM lParam
, PageSetupDataW
*pda
2948 TRACE("loword (lparam) %d, wparam 0x%lx, lparam %08lx\n",
2949 LOWORD(lParam
),wParam
,lParam
);
2950 switch (LOWORD(wParam
)) {
2952 if (!PRINTDLG_PS_UpdateDlgStructW(hDlg
, pda
))
2954 EndDialog(hDlg
, TRUE
);
2958 EndDialog(hDlg
, FALSE
);
2963 if((LOWORD(wParam
) == rad1
&& pda
->curdlg
.ptPaperSize
.x
> pda
->curdlg
.ptPaperSize
.y
) ||
2964 (LOWORD(wParam
) == rad2
&& pda
->curdlg
.ptPaperSize
.y
> pda
->curdlg
.ptPaperSize
.x
))
2968 DWORD tmp
= pda
->curdlg
.ptPaperSize
.y
;
2970 pda
->curdlg
.ptPaperSize
.y
= pda
->curdlg
.ptPaperSize
.x
;
2971 pda
->curdlg
.ptPaperSize
.x
= tmp
;
2973 GetDlgItemTextW(hDlg
, edt4
, tmpText
, sizeof(tmpText
)/sizeof(WCHAR
));
2974 GetDlgItemTextW(hDlg
, edt5
, tmpText2
, sizeof(tmpText2
)/sizeof(WCHAR
));
2975 SetDlgItemTextW(hDlg
, edt5
, tmpText
);
2976 SetDlgItemTextW(hDlg
, edt4
, tmpText2
);
2978 GetDlgItemTextW(hDlg
, edt6
, tmpText
, sizeof(tmpText
)/sizeof(WCHAR
));
2979 GetDlgItemTextW(hDlg
, edt7
, tmpText2
, sizeof(tmpText2
)/sizeof(WCHAR
));
2980 SetDlgItemTextW(hDlg
, edt7
, tmpText
);
2981 SetDlgItemTextW(hDlg
, edt6
, tmpText2
);
2986 pda
->pdlg
.Flags
= 0;
2987 pda
->pdlg
.hwndOwner
= hDlg
;
2988 if (PrintDlgW(&(pda
->pdlg
)))
2989 PRINTDLG_PS_ChangePrinterW(hDlg
,pda
);
2997 /***********************************************************************
2998 * DefaultPagePaintHook
2999 * Default hook paint procedure that receives WM_PSD_* messages from the dialog box
3000 * whenever the sample page is redrawn.
3004 PRINTDLG_DefaultPagePaintHook(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
,
3005 const PageSetupDataA
*pda
)
3007 LPRECT lprc
= (LPRECT
) lParam
;
3008 HDC hdc
= (HDC
) wParam
;
3011 HFONT hfont
, holdfont
;
3013 TRACE("uMsg: WM_USER+%d\n",uMsg
-WM_USER
);
3014 /* Call user paint hook if enable */
3015 if (pda
->dlga
->Flags
& PSD_ENABLEPAGEPAINTHOOK
)
3016 if (pda
->dlga
->lpfnPagePaintHook(hwndDlg
, uMsg
, wParam
, lParam
))
3020 /* LPPAGESETUPDLG in lParam */
3021 case WM_PSD_PAGESETUPDLG
:
3022 /* Inform about the sample page rectangle */
3023 case WM_PSD_FULLPAGERECT
:
3024 /* Inform about the margin rectangle */
3025 case WM_PSD_MINMARGINRECT
:
3028 /* Draw dashed rectangle showing margins */
3029 case WM_PSD_MARGINRECT
:
3030 hpen
= CreatePen(PS_DASH
, 1, GetSysColor(COLOR_3DSHADOW
));
3031 holdpen
= SelectObject(hdc
, hpen
);
3032 Rectangle(hdc
, lprc
->left
, lprc
->top
, lprc
->right
, lprc
->bottom
);
3033 DeleteObject(SelectObject(hdc
, holdpen
));
3035 /* Draw the fake document */
3036 case WM_PSD_GREEKTEXTRECT
:
3037 /* select a nice scalable font, because we want the text really small */
3038 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, sizeof(lf
), &lf
, 0);
3039 lf
.lfHeight
= 6; /* value chosen based on visual effect */
3040 hfont
= CreateFontIndirectW(&lf
);
3041 holdfont
= SelectObject(hdc
, hfont
);
3043 /* if text not loaded, then do so now */
3044 if (wszFakeDocumentText
[0] == '\0')
3045 LoadStringW(COMDLG32_hInstance
,
3047 wszFakeDocumentText
,
3048 sizeof(wszFakeDocumentText
)/sizeof(wszFakeDocumentText
[0]));
3050 oldbkmode
= SetBkMode(hdc
, TRANSPARENT
);
3051 DrawTextW(hdc
, wszFakeDocumentText
, -1, lprc
, DT_TOP
|DT_LEFT
|DT_NOPREFIX
|DT_WORDBREAK
);
3052 SetBkMode(hdc
, oldbkmode
);
3054 DeleteObject(SelectObject(hdc
, holdfont
));
3057 /* Envelope stamp */
3058 case WM_PSD_ENVSTAMPRECT
:
3059 /* Return address */
3060 case WM_PSD_YAFULLPAGERECT
:
3061 FIXME("envelope/stamp is not implemented\n");
3064 FIXME("Unknown message %x\n",uMsg
);
3070 /***********************************************************************
3072 * The main paint procedure for the PageSetupDlg function.
3073 * The Page Setup dialog box includes an image of a sample page that shows how
3074 * the user's selections affect the appearance of the printed output.
3075 * The image consists of a rectangle that represents the selected paper
3076 * or envelope type, with a dotted-line rectangle representing
3077 * the current margins, and partial (Greek text) characters
3078 * to show how text looks on the printed page.
3080 * The following messages in the order sends to user hook procedure:
3081 * WM_PSD_PAGESETUPDLG Draw the contents of the sample page
3082 * WM_PSD_FULLPAGERECT Inform about the bounding rectangle
3083 * WM_PSD_MINMARGINRECT Inform about the margin rectangle (min margin?)
3084 * WM_PSD_MARGINRECT Draw the margin rectangle
3085 * WM_PSD_GREEKTEXTRECT Draw the Greek text inside the margin rectangle
3086 * If any of first three messages returns TRUE, painting done.
3089 * hWnd [in] Handle to the Page Setup dialog box
3090 * uMsg [in] Received message
3093 * WM_PSD_ENVSTAMPRECT Draw in the envelope-stamp rectangle (for envelopes only)
3094 * WM_PSD_YAFULLPAGERECT Draw the return address portion (for envelopes and other paper sizes)
3097 * FALSE if all done correctly
3102 static LRESULT CALLBACK
3103 PRINTDLG_PagePaintProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3106 RECT rcClient
, rcMargin
;
3109 HBRUSH hbrush
, holdbrush
;
3110 PageSetupDataA
*pda
;
3111 int papersize
=0, orientation
=0; /* FIXME: set this values for user paint hook */
3112 double scalx
, scaly
;
3113 #define CALLPAINTHOOK(msg,lprc) PRINTDLG_DefaultPagePaintHook( hWnd, msg, (WPARAM)hdc, (LPARAM)lprc, pda)
3115 if (uMsg
!= WM_PAINT
)
3116 return CallWindowProcA(lpfnStaticWndProc
, hWnd
, uMsg
, wParam
, lParam
);
3118 /* Processing WM_PAINT message */
3119 pda
= (PageSetupDataA
*)GetPropA(hWnd
, "__WINE_PAGESETUPDLGDATA");
3121 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3124 if (PRINTDLG_DefaultPagePaintHook(hWnd
, WM_PSD_PAGESETUPDLG
, MAKELONG(papersize
, orientation
), (LPARAM
)pda
->dlga
, pda
))
3127 hdc
= BeginPaint(hWnd
, &ps
);
3128 GetClientRect(hWnd
, &rcClient
);
3130 scalx
= rcClient
.right
/ (double)pda
->curdlg
.ptPaperSize
.x
;
3131 scaly
= rcClient
.bottom
/ (double)pda
->curdlg
.ptPaperSize
.y
;
3132 rcMargin
= rcClient
;
3134 rcMargin
.left
+= pda
->curdlg
.rtMargin
.left
* scalx
;
3135 rcMargin
.top
+= pda
->curdlg
.rtMargin
.top
* scalx
;
3136 rcMargin
.right
-= pda
->curdlg
.rtMargin
.right
* scaly
;
3137 rcMargin
.bottom
-= pda
->curdlg
.rtMargin
.bottom
* scaly
;
3139 /* if the space is too small then we make sure to not draw anything */
3140 rcMargin
.left
= min(rcMargin
.left
, rcMargin
.right
);
3141 rcMargin
.top
= min(rcMargin
.top
, rcMargin
.bottom
);
3143 if (!CALLPAINTHOOK(WM_PSD_FULLPAGERECT
, &rcClient
) &&
3144 !CALLPAINTHOOK(WM_PSD_MINMARGINRECT
, &rcMargin
) )
3146 /* fill background */
3147 hbrush
= GetSysColorBrush(COLOR_3DHIGHLIGHT
);
3148 FillRect(hdc
, &rcClient
, hbrush
);
3149 holdbrush
= SelectObject(hdc
, hbrush
);
3151 hpen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DSHADOW
));
3152 holdpen
= SelectObject(hdc
, hpen
);
3154 /* paint left edge */
3155 MoveToEx(hdc
, rcClient
.left
, rcClient
.top
, NULL
);
3156 LineTo(hdc
, rcClient
.left
, rcClient
.bottom
-1);
3158 /* paint top edge */
3159 MoveToEx(hdc
, rcClient
.left
, rcClient
.top
, NULL
);
3160 LineTo(hdc
, rcClient
.right
, rcClient
.top
);
3162 hpen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DDKSHADOW
));
3163 DeleteObject(SelectObject(hdc
, hpen
));
3165 /* paint right edge */
3166 MoveToEx(hdc
, rcClient
.right
-1, rcClient
.top
, NULL
);
3167 LineTo(hdc
, rcClient
.right
-1, rcClient
.bottom
);
3169 /* paint bottom edge */
3170 MoveToEx(hdc
, rcClient
.left
, rcClient
.bottom
-1, NULL
);
3171 LineTo(hdc
, rcClient
.right
, rcClient
.bottom
-1);
3173 DeleteObject(SelectObject(hdc
, holdpen
));
3174 DeleteObject(SelectObject(hdc
, holdbrush
));
3176 CALLPAINTHOOK(WM_PSD_MARGINRECT
, &rcMargin
);
3178 /* give text a bit of a space from the frame */
3181 rcMargin
.right
-= 2;
3182 rcMargin
.bottom
-= 2;
3184 /* if the space is too small then we make sure to not draw anything */
3185 rcMargin
.left
= min(rcMargin
.left
, rcMargin
.right
);
3186 rcMargin
.top
= min(rcMargin
.top
, rcMargin
.bottom
);
3188 CALLPAINTHOOK(WM_PSD_GREEKTEXTRECT
, &rcMargin
);
3191 EndPaint(hWnd
, &ps
);
3193 #undef CALLPAINTHOOK
3196 /***********************************************************************
3197 * PRINTDLG_PageDlgProcA
3198 * Message handler for PageSetupDlgA
3200 static INT_PTR CALLBACK
3201 PRINTDLG_PageDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3204 PageSetupDataA
*pda
;
3205 INT_PTR res
= FALSE
;
3208 if (uMsg
== WM_INITDIALOG
) { /*Init dialog*/
3209 pda
= (PageSetupDataA
*)lParam
;
3210 pda
->hDlg
= hDlg
; /* saving handle to main window to PageSetupDataA structure */
3211 memcpy(&pda
->curdlg
, pda
->dlga
, sizeof(pda
->curdlg
));
3213 hDrawWnd
= GetDlgItem(hDlg
, rct1
);
3214 TRACE("set property to %p\n", pda
);
3215 SetPropA(hDlg
, "__WINE_PAGESETUPDLGDATA", pda
);
3216 SetPropA(hDrawWnd
, "__WINE_PAGESETUPDLGDATA", pda
);
3217 GetWindowRect(hDrawWnd
, &pda
->rtDrawRect
); /* Calculating rect in client coordinates where paper draws */
3218 ScreenToClient(hDlg
, (LPPOINT
)&pda
->rtDrawRect
);
3219 ScreenToClient(hDlg
, (LPPOINT
)(&pda
->rtDrawRect
.right
));
3220 lpfnStaticWndProc
= (WNDPROC
)SetWindowLongPtrW(
3223 (ULONG_PTR
)PRINTDLG_PagePaintProc
);
3225 /* FIXME: Paint hook. Must it be at begin of initializtion or at end? */
3227 if (pda
->dlga
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
3228 if (!pda
->dlga
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,(LPARAM
)pda
->dlga
))
3229 FIXME("Setup page hook failed?\n");
3232 /* if printer button disabled */
3233 if (pda
->dlga
->Flags
& PSD_DISABLEPRINTER
)
3234 EnableWindow(GetDlgItem(hDlg
, psh3
), FALSE
);
3235 /* if margin edit boxes disabled */
3236 if (pda
->dlga
->Flags
& PSD_DISABLEMARGINS
) {
3237 EnableWindow(GetDlgItem(hDlg
, edt4
), FALSE
);
3238 EnableWindow(GetDlgItem(hDlg
, edt5
), FALSE
);
3239 EnableWindow(GetDlgItem(hDlg
, edt6
), FALSE
);
3240 EnableWindow(GetDlgItem(hDlg
, edt7
), FALSE
);
3242 /* Set orientation radiobutton properly */
3243 if(pda
->dlga
->hDevMode
)
3245 dm
= GlobalLock(pda
->dlga
->hDevMode
);
3246 if (dm
->u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
)
3247 CheckRadioButton(hDlg
, rad1
, rad2
, rad2
);
3248 else /* this is default if papersize is not set */
3249 CheckRadioButton(hDlg
, rad1
, rad2
, rad1
);
3250 GlobalUnlock(pda
->dlga
->hDevMode
);
3253 /* if orientation disabled */
3254 if (pda
->dlga
->Flags
& PSD_DISABLEORIENTATION
) {
3255 EnableWindow(GetDlgItem(hDlg
,rad1
),FALSE
);
3256 EnableWindow(GetDlgItem(hDlg
,rad2
),FALSE
);
3258 /* We fill them out enabled or not */
3259 if (pda
->dlga
->Flags
& PSD_MARGINS
) {
3261 _c_size2strA(pda
,pda
->dlga
->rtMargin
.left
,str
);
3262 SetDlgItemTextA(hDlg
,edt4
,str
);
3263 _c_size2strA(pda
,pda
->dlga
->rtMargin
.top
,str
);
3264 SetDlgItemTextA(hDlg
,edt5
,str
);
3265 _c_size2strA(pda
,pda
->dlga
->rtMargin
.right
,str
);
3266 SetDlgItemTextA(hDlg
,edt6
,str
);
3267 _c_size2strA(pda
,pda
->dlga
->rtMargin
.bottom
,str
);
3268 SetDlgItemTextA(hDlg
,edt7
,str
);
3270 /* default is 1 inch */
3271 DWORD size
= _c_inch2size(pda
->dlga
,1000);
3273 _c_size2strA(pda
,size
,str
);
3274 SetDlgItemTextA(hDlg
,edt4
,str
);
3275 SetDlgItemTextA(hDlg
,edt5
,str
);
3276 SetDlgItemTextA(hDlg
,edt6
,str
);
3277 SetDlgItemTextA(hDlg
,edt7
,str
);
3278 pda
->curdlg
.rtMargin
.left
= size
;
3279 pda
->curdlg
.rtMargin
.top
= size
;
3280 pda
->curdlg
.rtMargin
.right
= size
;
3281 pda
->curdlg
.rtMargin
.bottom
= size
;
3283 /* if paper disabled */
3284 if (pda
->dlga
->Flags
& PSD_DISABLEPAPER
) {
3285 EnableWindow(GetDlgItem(hDlg
,cmb2
),FALSE
);
3286 EnableWindow(GetDlgItem(hDlg
,cmb3
),FALSE
);
3288 /* filling combos: printer, paper, source. selecting current printer (from DEVMODEA) */
3289 PRINTDLG_PS_ChangePrinterA(hDlg
, pda
);
3290 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
3292 dm
->u1
.s1
.dmDefaultSource
= 15; /*FIXME: Automatic select. Does it always 15 at start? */
3293 PRINTDLG_PaperSizeA(&(pda
->pdlg
), dm
->u1
.s1
.dmPaperSize
, &pda
->curdlg
.ptPaperSize
);
3294 GlobalUnlock(pda
->pdlg
.hDevMode
);
3295 pda
->curdlg
.ptPaperSize
.x
= _c_10mm2size(pda
->dlga
, pda
->curdlg
.ptPaperSize
.x
);
3296 pda
->curdlg
.ptPaperSize
.y
= _c_10mm2size(pda
->dlga
, pda
->curdlg
.ptPaperSize
.y
);
3297 if (IsDlgButtonChecked(hDlg
, rad2
) == BST_CHECKED
) { /* Landscape orientation */
3298 DWORD tmp
= pda
->curdlg
.ptPaperSize
.y
;
3299 pda
->curdlg
.ptPaperSize
.y
= pda
->curdlg
.ptPaperSize
.x
;
3300 pda
->curdlg
.ptPaperSize
.x
= tmp
;
3303 WARN("GlobalLock(pda->pdlg.hDevMode) fail? hDevMode=%p\n", pda
->pdlg
.hDevMode
);
3304 /* Drawing paper prev */
3305 PRINTDLG_PS_ChangePaperPrev(pda
);
3308 pda
= (PageSetupDataA
*)GetPropA(hDlg
,"__WINE_PAGESETUPDLGDATA");
3310 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3313 if (pda
->dlga
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
3314 res
= pda
->dlga
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,lParam
);
3315 if (res
) return res
;
3320 return PRINTDLG_PS_WMCommandA(hDlg
, wParam
, lParam
, pda
);
3325 static INT_PTR CALLBACK
3326 PageDlgProcW(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3328 static const WCHAR __WINE_PAGESETUPDLGDATA
[] =
3329 { '_', '_', 'W', 'I', 'N', 'E', '_', 'P', 'A', 'G', 'E',
3330 'S', 'E', 'T', 'U', 'P', 'D', 'L', 'G', 'D', 'A', 'T', 'A', 0 };
3331 PageSetupDataW
*pda
;
3334 if (uMsg
==WM_INITDIALOG
) {
3336 pda
= (PageSetupDataW
*)lParam
;
3337 memcpy(&pda
->curdlg
, pda
, sizeof(pda
->curdlg
));
3338 SetPropW(hDlg
, __WINE_PAGESETUPDLGDATA
, pda
);
3339 if (pda
->dlga
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
3340 res
= pda
->dlga
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,(LPARAM
)pda
->dlga
);
3342 FIXME("Setup page hook failed?\n");
3347 if (pda
->dlga
->Flags
& PSD_ENABLEPAGEPAINTHOOK
) {
3348 FIXME("PagePaintHook not yet implemented!\n");
3350 if (pda
->dlga
->Flags
& PSD_DISABLEPRINTER
)
3351 EnableWindow(GetDlgItem(hDlg
, psh3
), FALSE
);
3352 if (pda
->dlga
->Flags
& PSD_DISABLEMARGINS
) {
3353 EnableWindow(GetDlgItem(hDlg
, edt4
), FALSE
);
3354 EnableWindow(GetDlgItem(hDlg
, edt5
), FALSE
);
3355 EnableWindow(GetDlgItem(hDlg
, edt6
), FALSE
);
3356 EnableWindow(GetDlgItem(hDlg
, edt7
), FALSE
);
3359 PRINTDLG_PS_ChangePrinterW(hDlg
,pda
);
3361 if (pda
->dlga
->Flags
& PSD_DISABLEORIENTATION
) {
3362 EnableWindow(GetDlgItem(hDlg
,rad1
),FALSE
);
3363 EnableWindow(GetDlgItem(hDlg
,rad2
),FALSE
);
3365 /* We fill them out enabled or not */
3366 if (pda
->dlga
->Flags
& PSD_MARGINS
) {
3368 _c_size2strW(pda
,pda
->dlga
->rtMargin
.left
,str
);
3369 SetDlgItemTextW(hDlg
,edt4
,str
);
3370 _c_size2strW(pda
,pda
->dlga
->rtMargin
.top
,str
);
3371 SetDlgItemTextW(hDlg
,edt5
,str
);
3372 _c_size2strW(pda
,pda
->dlga
->rtMargin
.right
,str
);
3373 SetDlgItemTextW(hDlg
,edt6
,str
);
3374 _c_size2strW(pda
,pda
->dlga
->rtMargin
.bottom
,str
);
3375 SetDlgItemTextW(hDlg
,edt7
,str
);
3377 /* default is 1 inch */
3378 DWORD size
= _c_inch2size((LPPAGESETUPDLGA
)pda
->dlga
,1000);
3380 _c_size2strW(pda
,size
,str
);
3381 SetDlgItemTextW(hDlg
,edt4
,str
);
3382 SetDlgItemTextW(hDlg
,edt5
,str
);
3383 SetDlgItemTextW(hDlg
,edt6
,str
);
3384 SetDlgItemTextW(hDlg
,edt7
,str
);
3387 if (pda
->dlga
->Flags
& PSD_DISABLEPAPER
) {
3388 EnableWindow(GetDlgItem(hDlg
,cmb2
),FALSE
);
3389 EnableWindow(GetDlgItem(hDlg
,cmb3
),FALSE
);
3394 pda
= (PageSetupDataW
*)GetPropW(hDlg
, __WINE_PAGESETUPDLGDATA
);
3396 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3399 if (pda
->dlga
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
3400 res
= pda
->dlga
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,lParam
);
3401 if (res
) return res
;
3406 return PRINTDLG_PS_WMCommandW(hDlg
, wParam
, lParam
, pda
);
3411 /***********************************************************************
3412 * PageSetupDlgA (COMDLG32.@)
3414 * Displays the PAGE SETUP dialog box, which enables the user to specify
3415 * specific properties of a printed page such as
3416 * size, source, orientation and the width of the page margins.
3419 * setupdlg [IO] PAGESETUPDLGA struct
3422 * TRUE if the user pressed the OK button
3423 * FALSE if the user cancelled the window or an error occurred
3426 * The values of hDevMode and hDevNames are filled on output and can be
3427 * changed in PAGESETUPDLG when they are passed in PageSetupDlg.
3431 BOOL WINAPI
PageSetupDlgA(LPPAGESETUPDLGA setupdlg
) {
3435 PageSetupDataA
*pda
;
3438 if (setupdlg
== NULL
) {
3439 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
3444 if(TRACE_ON(commdlg
)) {
3445 char flagstr
[1000] = "";
3446 const struct pd_flags
*pflag
= psd_flags
;
3447 for( ; pflag
->name
; pflag
++) {
3448 if(setupdlg
->Flags
& pflag
->flag
) {
3449 strcat(flagstr
, pflag
->name
);
3450 strcat(flagstr
, "|");
3453 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3454 "hinst %p, flags %08x (%s)\n",
3455 setupdlg
, setupdlg
->hwndOwner
, setupdlg
->hDevMode
,
3456 setupdlg
->hDevNames
,
3457 setupdlg
->hInstance
, setupdlg
->Flags
, flagstr
);
3460 /* Checking setupdlg structure */
3461 if(setupdlg
->lStructSize
!= sizeof(PAGESETUPDLGA
)) {
3462 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
3465 if ((setupdlg
->Flags
& PSD_ENABLEPAGEPAINTHOOK
) &&
3466 (setupdlg
->lpfnPagePaintHook
== NULL
)) {
3467 COMDLG32_SetCommDlgExtendedError(CDERR_NOHOOK
);
3471 /* Initialize default printer struct. If no printer device info is specified
3472 retrieve the default printer data. */
3473 memset(&pdlg
,0,sizeof(pdlg
));
3474 pdlg
.lStructSize
= sizeof(pdlg
);
3475 if (setupdlg
->hDevMode
&& setupdlg
->hDevNames
) {
3476 pdlg
.hDevMode
= setupdlg
->hDevMode
;
3477 pdlg
.hDevNames
= setupdlg
->hDevNames
;
3479 pdlg
.Flags
= PD_RETURNDEFAULT
;
3480 bRet
= PrintDlgA(&pdlg
);
3482 if (!(setupdlg
->Flags
& PSD_NOWARNING
)) {
3484 LoadStringA(COMDLG32_hInstance
, PD32_NO_DEFAULT_PRINTER
, errstr
, 255);
3485 MessageBoxA(setupdlg
->hwndOwner
, errstr
, 0, MB_OK
| MB_ICONERROR
);
3491 /* short cut exit, just return default values */
3492 if (setupdlg
->Flags
& PSD_RETURNDEFAULT
) {
3495 setupdlg
->hDevMode
= pdlg
.hDevMode
;
3496 setupdlg
->hDevNames
= pdlg
.hDevNames
;
3497 dm
= GlobalLock(pdlg
.hDevMode
);
3498 PRINTDLG_PaperSizeA(&pdlg
, dm
->u1
.s1
.dmPaperSize
, &setupdlg
->ptPaperSize
);
3499 GlobalUnlock(pdlg
.hDevMode
);
3500 setupdlg
->ptPaperSize
.x
=_c_10mm2size(setupdlg
,setupdlg
->ptPaperSize
.x
);
3501 setupdlg
->ptPaperSize
.y
=_c_10mm2size(setupdlg
,setupdlg
->ptPaperSize
.y
);
3505 /* get dialog template */
3506 hDlgTmpl
= PRINTDLG_GetPGSTemplateA(setupdlg
);
3508 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
3511 ptr
= LockResource( hDlgTmpl
);
3513 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
3517 pda
= HeapAlloc(GetProcessHeap(),0,sizeof(*pda
));
3518 pda
->dlga
= setupdlg
;
3519 memcpy(&pda
->pdlg
,&pdlg
,sizeof(pdlg
));
3521 bRet
= (0<DialogBoxIndirectParamA(
3522 setupdlg
->hInstance
,
3524 setupdlg
->hwndOwner
,
3525 PRINTDLG_PageDlgProcA
,
3529 HeapFree(GetProcessHeap(),0,pda
);
3532 /***********************************************************************
3533 * PageSetupDlgW (COMDLG32.@)
3535 * See PageSetupDlgA.
3537 BOOL WINAPI
PageSetupDlgW(LPPAGESETUPDLGW setupdlg
) {
3541 PageSetupDataW
*pdw
;
3544 FIXME("Unicode implementation is not done yet\n");
3546 if (setupdlg
== NULL
) {
3547 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
3551 if(TRACE_ON(commdlg
)) {
3552 char flagstr
[1000] = "";
3553 const struct pd_flags
*pflag
= psd_flags
;
3554 for( ; pflag
->name
; pflag
++) {
3555 if(setupdlg
->Flags
& pflag
->flag
) {
3556 strcat(flagstr
, pflag
->name
);
3557 strcat(flagstr
, "|");
3560 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3561 "hinst %p, flags %08x (%s)\n",
3562 setupdlg
, setupdlg
->hwndOwner
, setupdlg
->hDevMode
,
3563 setupdlg
->hDevNames
,
3564 setupdlg
->hInstance
, setupdlg
->Flags
, flagstr
);
3567 /* Initialize default printer struct. If no printer device info is specified
3568 retrieve the default printer data. */
3569 memset(&pdlg
,0,sizeof(pdlg
));
3570 pdlg
.lStructSize
= sizeof(pdlg
);
3571 if (setupdlg
->hDevMode
&& setupdlg
->hDevNames
) {
3572 pdlg
.hDevMode
= setupdlg
->hDevMode
;
3573 pdlg
.hDevNames
= setupdlg
->hDevNames
;
3575 pdlg
.Flags
= PD_RETURNDEFAULT
;
3576 bRet
= PrintDlgW(&pdlg
);
3578 if (!(setupdlg
->Flags
& PSD_NOWARNING
)) {
3580 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEFAULT_PRINTER
, errstr
, 255);
3581 MessageBoxW(setupdlg
->hwndOwner
, errstr
, 0, MB_OK
| MB_ICONERROR
);
3587 /* short cut exit, just return default values */
3588 if (setupdlg
->Flags
& PSD_RETURNDEFAULT
) {
3589 static const WCHAR a4
[] = {'A','4',0};
3590 setupdlg
->hDevMode
= pdlg
.hDevMode
;
3591 setupdlg
->hDevNames
= pdlg
.hDevNames
;
3592 /* FIXME: Just return "A4" for now. */
3593 PRINTDLG_PaperSizeW(&pdlg
,a4
,&setupdlg
->ptPaperSize
);
3594 setupdlg
->ptPaperSize
.x
=_c_10mm2size((LPPAGESETUPDLGA
)setupdlg
,setupdlg
->ptPaperSize
.x
);
3595 setupdlg
->ptPaperSize
.y
=_c_10mm2size((LPPAGESETUPDLGA
)setupdlg
,setupdlg
->ptPaperSize
.y
);
3598 hDlgTmpl
= PRINTDLG_GetPGSTemplateW(setupdlg
);
3600 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
3603 ptr
= LockResource( hDlgTmpl
);
3605 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
3608 pdw
= HeapAlloc(GetProcessHeap(),0,sizeof(*pdw
));
3609 pdw
->dlga
= setupdlg
;
3610 memcpy(&pdw
->pdlg
,&pdlg
,sizeof(pdlg
));
3612 bRet
= (0<DialogBoxIndirectParamW(
3613 setupdlg
->hInstance
,
3615 setupdlg
->hwndOwner
,
3622 /***********************************************************************
3623 * PrintDlgExA (COMDLG32.@)
3631 HRESULT WINAPI
PrintDlgExA(LPPRINTDLGEXA lppd
)
3634 FIXME("(%p) stub\n", lppd
);
3635 if ((lppd
== NULL
) || (lppd
->lStructSize
!= sizeof(PRINTDLGEXA
))) {
3636 return E_INVALIDARG
;
3639 if (!IsWindow(lppd
->hwndOwner
)) {
3646 /***********************************************************************
3647 * PrintDlgExW (COMDLG32.@)
3649 * Display the property sheet style PRINT dialog box
3652 * lppd [IO] ptr to PRINTDLGEX struct
3656 * Failure: One of the following COM error codes:
3657 * E_OUTOFMEMORY Insufficient memory.
3658 * E_INVALIDARG One or more arguments are invalid.
3659 * E_POINTER Invalid pointer.
3660 * E_HANDLE Invalid handle.
3661 * E_FAIL Unspecified error.
3664 * This Dialog enables the user to specify specific properties of the print job.
3665 * The property sheet can also have additional application-specific and
3666 * driver-specific property pages.
3672 HRESULT WINAPI
PrintDlgExW(LPPRINTDLGEXW lppd
)
3675 FIXME("(%p) stub\n", lppd
);
3676 if ((lppd
== NULL
) || (lppd
->lStructSize
!= sizeof(PRINTDLGEXW
))) {
3677 return E_INVALIDARG
;
3680 if (!IsWindow(lppd
->hwndOwner
)) {