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
->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
->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
->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
->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
->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
->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
->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
->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
->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
->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
;
2346 static HGLOBAL
PRINTDLG_GetPGSTemplateA(const PAGESETUPDLGA
*lppd
)
2351 if(lppd
->Flags
& PSD_ENABLEPAGESETUPTEMPLATEHANDLE
) {
2352 hDlgTmpl
= lppd
->hPageSetupTemplate
;
2353 } else if(lppd
->Flags
& PSD_ENABLEPAGESETUPTEMPLATE
) {
2354 hResInfo
= FindResourceA(lppd
->hInstance
,
2355 lppd
->lpPageSetupTemplateName
, (LPSTR
)RT_DIALOG
);
2356 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
2358 hResInfo
= FindResourceA(COMDLG32_hInstance
,(LPCSTR
)PAGESETUPDLGORD
,(LPSTR
)RT_DIALOG
);
2359 hDlgTmpl
= LoadResource(COMDLG32_hInstance
,hResInfo
);
2364 static HGLOBAL
PRINTDLG_GetPGSTemplateW(const PAGESETUPDLGW
*lppd
)
2369 if(lppd
->Flags
& PSD_ENABLEPAGESETUPTEMPLATEHANDLE
) {
2370 hDlgTmpl
= lppd
->hPageSetupTemplate
;
2371 } else if(lppd
->Flags
& PSD_ENABLEPAGESETUPTEMPLATE
) {
2372 hResInfo
= FindResourceW(lppd
->hInstance
,
2373 lppd
->lpPageSetupTemplateName
, (LPWSTR
)RT_DIALOG
);
2374 hDlgTmpl
= LoadResource(lppd
->hInstance
, hResInfo
);
2376 hResInfo
= FindResourceW(COMDLG32_hInstance
,(LPCWSTR
)PAGESETUPDLGORD
,(LPWSTR
)RT_DIALOG
);
2377 hDlgTmpl
= LoadResource(COMDLG32_hInstance
,hResInfo
);
2383 _c_10mm2size(PAGESETUPDLGA
*dlga
,DWORD size
) {
2384 if (dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
)
2385 return 10*size
*100/254;
2386 /* If we don't have a flag, we can choose one. Use millimeters
2387 * to avoid confusing me
2389 dlga
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
2395 _c_inch2size(PAGESETUPDLGA
*dlga
,DWORD size
) {
2396 if (dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
)
2398 if (dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
)
2399 return (size
*254)/100;
2400 /* if we don't have a flag, we can choose one. Use millimeters
2401 * to avoid confusing me
2403 dlga
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
2404 return (size
*254)/100;
2408 _c_size2strA(PageSetupDataA
*pda
,DWORD size
,LPSTR strout
) {
2409 strcpy(strout
,"<undef>");
2410 if (pda
->dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
) {
2411 sprintf(strout
,"%d",(size
)/100);
2414 if (pda
->dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
) {
2415 sprintf(strout
,"%din",(size
)/1000);
2418 pda
->dlga
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
2419 sprintf(strout
,"%d",(size
)/100);
2423 _c_size2strW(PageSetupDataW
*pda
,DWORD size
,LPWSTR strout
) {
2424 static const char mm_fmt
[] = "%.2f mm";
2425 static const char in_fmt
[] = "%.2f in";
2427 if (pda
->dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
) {
2428 sprintf(buf
, mm_fmt
, (size
* 1.0) / 100.0);
2429 } else if (pda
->dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
) {
2430 sprintf(buf
, in_fmt
, (size
* 1.0) / 1000.0);
2432 pda
->dlga
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
2433 sprintf(buf
, mm_fmt
, (size
* 1.0) / 100.0);
2436 MultiByteToWideChar(CP_ACP
, 0, buf
, -1, strout
, 20);
2440 _c_str2sizeA(const PAGESETUPDLGA
*dlga
, LPCSTR strin
) {
2445 if (!sscanf(strin
,"%f%s",&val
,rest
))
2448 if (!strcmp(rest
,"in") || !strcmp(rest
,"inch")) {
2449 if (dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
)
2452 return val
*25.4*100;
2454 if (!strcmp(rest
,"cm")) { rest
[0]='m'; val
= val
*10.0; }
2455 if (!strcmp(rest
,"m")) { strcpy(rest
,"mm"); val
= val
*1000.0; }
2457 if (!strcmp(rest
,"mm")) {
2458 if (dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
)
2461 return 1000.0*val
/25.4;
2463 if (rest
[0]=='\0') {
2464 /* use application supplied default */
2465 if (dlga
->Flags
& PSD_INHUNDREDTHSOFMILLIMETERS
) {
2469 if (dlga
->Flags
& PSD_INTHOUSANDTHSOFINCHES
) {
2474 ERR("Did not find a conversion for type '%s'!\n",rest
);
2480 _c_str2sizeW(const PAGESETUPDLGW
*dlga
, LPCWSTR strin
) {
2483 /* this W -> A transition is OK */
2484 /* we need a unicode version of sscanf to avoid it */
2485 WideCharToMultiByte(CP_ACP
, 0, strin
, -1, buf
, sizeof(buf
), NULL
, NULL
);
2486 return _c_str2sizeA((const PAGESETUPDLGA
*)dlga
, buf
);
2490 /****************************************************************************
2491 * PRINTDLG_PS_UpdateDlgStructA
2493 * Updates pda->dlga structure
2494 * Function calls when user presses OK button
2497 * hDlg [in] main window dialog HANDLE
2498 * pda [in/out] ptr to PageSetupDataA structure
2504 PRINTDLG_PS_UpdateDlgStructA(HWND hDlg
, PageSetupDataA
*pda
) {
2509 memcpy(pda
->dlga
, &pda
->curdlg
, sizeof(pda
->curdlg
));
2510 pda
->dlga
->hDevMode
= pda
->pdlg
.hDevMode
;
2511 pda
->dlga
->hDevNames
= pda
->pdlg
.hDevNames
;
2513 dn
= GlobalLock(pda
->pdlg
.hDevNames
);
2514 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2516 /* Save paper orientation into device context */
2517 if(pda
->curdlg
.ptPaperSize
.x
> pda
->curdlg
.ptPaperSize
.y
)
2518 dm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
2520 dm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
2522 /* Save paper size into the device context */
2523 paperword
= SendDlgItemMessageA(hDlg
,cmb2
,CB_GETITEMDATA
,
2524 SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0), 0);
2525 if (paperword
!= CB_ERR
)
2526 dm
->u1
.s1
.dmPaperSize
= paperword
;
2528 FIXME("could not get dialog text for papersize cmbbox?\n");
2530 /* Save paper source into the device context */
2531 paperword
= SendDlgItemMessageA(hDlg
,cmb1
,CB_GETITEMDATA
,
2532 SendDlgItemMessageA(hDlg
, cmb1
, CB_GETCURSEL
, 0, 0), 0);
2533 if (paperword
!= CB_ERR
)
2534 dm
->dmDefaultSource
= paperword
;
2536 FIXME("could not get dialog text for papersize cmbbox?\n");
2538 GlobalUnlock(pda
->pdlg
.hDevNames
);
2539 GlobalUnlock(pda
->pdlg
.hDevMode
);
2545 PRINTDLG_PS_UpdateDlgStructW(HWND hDlg
, PageSetupDataW
*pda
) {
2548 LPWSTR devname
,portname
;
2549 WCHAR papername
[64];
2552 dn
= GlobalLock(pda
->pdlg
.hDevNames
);
2553 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2554 devname
= ((WCHAR
*)dn
)+dn
->wDeviceOffset
;
2555 portname
= ((WCHAR
*)dn
)+dn
->wOutputOffset
;
2557 /* Save paper size into device context */
2558 PRINTDLG_SetUpPaperComboBoxW(hDlg
,cmb2
,devname
,portname
,dm
);
2559 /* Save paper source into device context */
2560 PRINTDLG_SetUpPaperComboBoxW(hDlg
,cmb3
,devname
,portname
,dm
);
2562 if (GetDlgItemTextW(hDlg
,cmb2
,papername
,sizeof(papername
))>0) {
2563 PRINTDLG_PaperSizeW(&(pda
->pdlg
),papername
,&(pda
->dlga
->ptPaperSize
));
2564 pda
->dlga
->ptPaperSize
.x
= _c_10mm2size((LPPAGESETUPDLGA
)pda
->dlga
,pda
->dlga
->ptPaperSize
.x
);
2565 pda
->dlga
->ptPaperSize
.y
= _c_10mm2size((LPPAGESETUPDLGA
)pda
->dlga
,pda
->dlga
->ptPaperSize
.y
);
2567 FIXME("could not get dialog text for papersize cmbbox?\n");
2568 #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); }
2569 GETVAL(edt4
,pda
->dlga
->rtMargin
.left
);
2570 GETVAL(edt5
,pda
->dlga
->rtMargin
.top
);
2571 GETVAL(edt6
,pda
->dlga
->rtMargin
.right
);
2572 GETVAL(edt7
,pda
->dlga
->rtMargin
.bottom
);
2575 /* If we are in landscape, swap x and y of page size */
2576 if (IsDlgButtonChecked(hDlg
, rad2
)) {
2578 tmp
= pda
->dlga
->ptPaperSize
.x
;
2579 pda
->dlga
->ptPaperSize
.x
= pda
->dlga
->ptPaperSize
.y
;
2580 pda
->dlga
->ptPaperSize
.y
= tmp
;
2583 /* Save orientation */
2584 if (pda
->dlga
->ptPaperSize
.x
> pda
->dlga
->ptPaperSize
.y
)
2585 dm
->u1
.s1
.dmOrientation
= DMORIENT_LANDSCAPE
;
2587 dm
->u1
.s1
.dmOrientation
= DMORIENT_PORTRAIT
;
2589 GlobalUnlock(pda
->pdlg
.hDevNames
);
2590 GlobalUnlock(pda
->pdlg
.hDevMode
);
2594 /**********************************************************************************************
2595 * PRINTDLG_PS_ChangeActivePrinerA
2597 * Redefines hDevMode and hDevNames HANDLES and initialises it.
2600 * name [in] Name of a printer for activation
2601 * pda [in/out] ptr to PageSetupDataA structure
2608 PRINTDLG_PS_ChangeActivePrinterA(LPSTR name
, PageSetupDataA
*pda
){
2611 LPPRINTER_INFO_2A lpPrinterInfo
;
2612 LPDRIVER_INFO_3A lpDriverInfo
;
2613 DEVMODEA
*pDevMode
, *dm
;
2615 if(!OpenPrinterA(name
, &hprn
, NULL
)){
2616 ERR("Can't open printer %s\n", name
);
2619 GetPrinterA(hprn
, 2, NULL
, 0, &needed
);
2620 lpPrinterInfo
= HeapAlloc(GetProcessHeap(), 0, needed
);
2621 GetPrinterA(hprn
, 2, (LPBYTE
)lpPrinterInfo
, needed
, &needed
);
2622 GetPrinterDriverA(hprn
, NULL
, 3, NULL
, 0, &needed
);
2623 lpDriverInfo
= HeapAlloc(GetProcessHeap(), 0, needed
);
2624 if(!GetPrinterDriverA(hprn
, NULL
, 3, (LPBYTE
)lpDriverInfo
, needed
, &needed
)) {
2625 ERR("GetPrinterDriverA failed for %s, fix your config!\n", lpPrinterInfo
->pPrinterName
);
2626 HeapFree(GetProcessHeap(), 0, lpDriverInfo
);
2627 HeapFree(GetProcessHeap(), 0, lpPrinterInfo
);
2632 needed
= DocumentPropertiesA(0, 0, name
, NULL
, NULL
, 0);
2634 ERR("DocumentProperties fails on %s\n", debugstr_a(name
));
2635 HeapFree(GetProcessHeap(), 0, lpDriverInfo
);
2636 HeapFree(GetProcessHeap(), 0, lpPrinterInfo
);
2639 pDevMode
= HeapAlloc(GetProcessHeap(), 0, needed
);
2640 DocumentPropertiesA(0, 0, name
, pDevMode
, NULL
, DM_OUT_BUFFER
);
2642 pda
->pdlg
.hDevMode
= GlobalReAlloc(pda
->pdlg
.hDevMode
,
2643 pDevMode
->dmSize
+ pDevMode
->dmDriverExtra
,
2645 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2646 memcpy(dm
, pDevMode
, pDevMode
->dmSize
+ pDevMode
->dmDriverExtra
);
2648 PRINTDLG_CreateDevNames(&(pda
->pdlg
.hDevNames
),
2649 lpDriverInfo
->pDriverPath
,
2650 lpPrinterInfo
->pPrinterName
,
2651 lpPrinterInfo
->pPortName
);
2653 GlobalUnlock(pda
->pdlg
.hDevMode
);
2654 HeapFree(GetProcessHeap(), 0, pDevMode
);
2655 HeapFree(GetProcessHeap(), 0, lpPrinterInfo
);
2656 HeapFree(GetProcessHeap(), 0, lpDriverInfo
);
2660 /****************************************************************************************
2661 * PRINTDLG_PS_ChangePrinterA
2663 * Fills Printers, Paper and Source combo
2669 PRINTDLG_PS_ChangePrinterA(HWND hDlg
, PageSetupDataA
*pda
) {
2672 LPSTR devname
,portname
;
2674 dn
= GlobalLock(pda
->pdlg
.hDevNames
);
2675 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2676 devname
= ((char*)dn
)+dn
->wDeviceOffset
;
2677 portname
= ((char*)dn
)+dn
->wOutputOffset
;
2678 PRINTDLG_SetUpPrinterListComboA(hDlg
, cmb1
, devname
);
2679 PRINTDLG_SetUpPaperComboBoxA(hDlg
,cmb2
,devname
,portname
,dm
);
2680 PRINTDLG_SetUpPaperComboBoxA(hDlg
,cmb3
,devname
,portname
,dm
);
2681 GlobalUnlock(pda
->pdlg
.hDevNames
);
2682 GlobalUnlock(pda
->pdlg
.hDevMode
);
2687 PRINTDLG_PS_ChangePrinterW(HWND hDlg
, PageSetupDataW
*pda
) {
2690 LPWSTR devname
,portname
;
2692 dn
= GlobalLock(pda
->pdlg
.hDevNames
);
2693 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2694 devname
= ((WCHAR
*)dn
)+dn
->wDeviceOffset
;
2695 portname
= ((WCHAR
*)dn
)+dn
->wOutputOffset
;
2696 PRINTDLG_SetUpPaperComboBoxW(hDlg
,cmb2
,devname
,portname
,dm
);
2697 PRINTDLG_SetUpPaperComboBoxW(hDlg
,cmb3
,devname
,portname
,dm
);
2698 GlobalUnlock(pda
->pdlg
.hDevNames
);
2699 GlobalUnlock(pda
->pdlg
.hDevMode
);
2703 /******************************************************************************************
2704 * PRINTDLG_PS_ChangePaperPrev
2706 * Changes paper preview size / position
2709 * pda [i] Pointer for current PageSetupDataA structure
2715 PRINTDLG_PS_ChangePaperPrev(const PageSetupDataA
*pda
)
2717 LONG width
, height
, x
, y
;
2720 if(pda
->curdlg
.ptPaperSize
.x
> pda
->curdlg
.ptPaperSize
.y
) {
2721 width
= pda
->rtDrawRect
.right
- pda
->rtDrawRect
.left
;
2722 height
= pda
->curdlg
.ptPaperSize
.y
* width
/ pda
->curdlg
.ptPaperSize
.x
;
2724 height
= pda
->rtDrawRect
.bottom
- pda
->rtDrawRect
.top
;
2725 width
= pda
->curdlg
.ptPaperSize
.x
* height
/ pda
->curdlg
.ptPaperSize
.y
;
2727 x
= (pda
->rtDrawRect
.right
+ pda
->rtDrawRect
.left
- width
) / 2;
2728 y
= (pda
->rtDrawRect
.bottom
+ pda
->rtDrawRect
.top
- height
) / 2;
2729 TRACE("rtDrawRect(%d, %d, %d, %d) x=%d, y=%d, w=%d, h=%d\n",
2730 pda
->rtDrawRect
.left
, pda
->rtDrawRect
.top
, pda
->rtDrawRect
.right
, pda
->rtDrawRect
.bottom
,
2731 x
, y
, width
, height
);
2734 MoveWindow(GetDlgItem(pda
->hDlg
, rct2
), x
+width
, y
+SHADOW
, SHADOW
, height
, FALSE
);
2735 MoveWindow(GetDlgItem(pda
->hDlg
, rct3
), x
+SHADOW
, y
+height
, width
, SHADOW
, FALSE
);
2736 MoveWindow(GetDlgItem(pda
->hDlg
, rct1
), x
, y
, width
, height
, FALSE
);
2737 memcpy(&rtTmp
, &pda
->rtDrawRect
, sizeof(RECT
));
2738 rtTmp
.right
+= SHADOW
;
2739 rtTmp
.bottom
+= SHADOW
;
2742 InvalidateRect(pda
->hDlg
, &rtTmp
, TRUE
);
2746 #define GETVAL(idc,val) \
2747 if(msg == EN_CHANGE){ \
2748 if (GetDlgItemTextA(hDlg,idc,buf,sizeof(buf)) > 0)\
2749 val = _c_str2sizeA(pda->dlga,buf); \
2751 FIXME("could not get dlgitemtexta for %x\n",id); \
2754 /********************************************************************************
2755 * PRINTDLG_PS_WMCommandA
2756 * process WM_COMMAND message for PageSetupDlgA
2759 * hDlg [in] Main dialog HANDLE
2760 * wParam [in] WM_COMMAND wParam
2761 * lParam [in] WM_COMMAND lParam
2762 * pda [in/out] ptr to PageSetupDataA
2766 PRINTDLG_PS_WMCommandA(
2767 HWND hDlg
, WPARAM wParam
, LPARAM lParam
, PageSetupDataA
*pda
2769 WORD msg
= HIWORD(wParam
);
2770 WORD id
= LOWORD(wParam
);
2773 TRACE("loword (lparam) %d, wparam 0x%lx, lparam %08lx\n",
2774 LOWORD(lParam
),wParam
,lParam
);
2777 if (!PRINTDLG_PS_UpdateDlgStructA(hDlg
, pda
))
2779 EndDialog(hDlg
, TRUE
);
2783 EndDialog(hDlg
, FALSE
);
2787 pda
->pdlg
.Flags
= 0;
2788 pda
->pdlg
.hwndOwner
= hDlg
;
2789 if (PrintDlgA(&(pda
->pdlg
)))
2790 PRINTDLG_PS_ChangePrinterA(hDlg
,pda
);
2794 if (pda
->curdlg
.ptPaperSize
.x
> pda
->curdlg
.ptPaperSize
.y
){
2795 DWORD tmp
= pda
->curdlg
.ptPaperSize
.x
;
2796 pda
->curdlg
.ptPaperSize
.x
= pda
->curdlg
.ptPaperSize
.y
;
2797 pda
->curdlg
.ptPaperSize
.y
= tmp
;
2799 PRINTDLG_PS_ChangePaperPrev(pda
);
2802 if (pda
->curdlg
.ptPaperSize
.y
> pda
->curdlg
.ptPaperSize
.x
){
2803 DWORD tmp
= pda
->curdlg
.ptPaperSize
.x
;
2804 pda
->curdlg
.ptPaperSize
.x
= pda
->curdlg
.ptPaperSize
.y
;
2805 pda
->curdlg
.ptPaperSize
.y
= tmp
;
2807 PRINTDLG_PS_ChangePaperPrev(pda
);
2809 case cmb1
: /* Printer combo */
2810 if(msg
== CBN_SELCHANGE
){
2811 char crPrinterName
[256];
2812 GetDlgItemTextA(hDlg
, id
, crPrinterName
, 255);
2813 PRINTDLG_PS_ChangeActivePrinterA(crPrinterName
, pda
);
2814 PRINTDLG_PS_ChangePrinterA(hDlg
, pda
);
2817 case cmb2
: /* Paper combo */
2818 if(msg
== CBN_SELCHANGE
){
2819 DWORD paperword
= SendDlgItemMessageA(hDlg
,cmb2
,CB_GETITEMDATA
,
2820 SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCURSEL
, 0, 0), 0);
2821 if (paperword
!= CB_ERR
) {
2822 PRINTDLG_PaperSizeA(&(pda
->pdlg
), paperword
,&(pda
->curdlg
.ptPaperSize
));
2823 pda
->curdlg
.ptPaperSize
.x
= _c_10mm2size(pda
->dlga
,pda
->curdlg
.ptPaperSize
.x
);
2824 pda
->curdlg
.ptPaperSize
.y
= _c_10mm2size(pda
->dlga
,pda
->curdlg
.ptPaperSize
.y
);
2826 if (IsDlgButtonChecked(hDlg
, rad2
)) {
2827 DWORD tmp
= pda
->curdlg
.ptPaperSize
.x
;
2828 pda
->curdlg
.ptPaperSize
.x
= pda
->curdlg
.ptPaperSize
.y
;
2829 pda
->curdlg
.ptPaperSize
.y
= tmp
;
2831 PRINTDLG_PS_ChangePaperPrev(pda
);
2833 FIXME("could not get dialog text for papersize cmbbox?\n");
2837 if(msg
== CBN_SELCHANGE
){
2838 DEVMODEA
*dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2839 dm
->dmDefaultSource
= SendDlgItemMessageA(hDlg
, cmb3
,CB_GETITEMDATA
,
2840 SendDlgItemMessageA(hDlg
, cmb3
, CB_GETCURSEL
, 0, 0), 0);
2841 GlobalUnlock(pda
->pdlg
.hDevMode
);
2844 case psh2
: /* Printer Properties button */
2847 char PrinterName
[256];
2852 GetDlgItemTextA(hDlg
, cmb1
, PrinterName
, 255);
2853 if (!OpenPrinterA(PrinterName
, &hPrinter
, NULL
)) {
2854 FIXME("Call to OpenPrinter did not succeed!\n");
2857 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
2858 DocumentPropertiesA(hDlg
, hPrinter
, PrinterName
, dm
, dm
,
2859 DM_IN_BUFFER
| DM_OUT_BUFFER
| DM_IN_PROMPT
);
2860 ClosePrinter(hPrinter
);
2861 /* Changing paper */
2862 PRINTDLG_PaperSizeA(&(pda
->pdlg
), dm
->u1
.s1
.dmPaperSize
, &(pda
->curdlg
.ptPaperSize
));
2863 pda
->curdlg
.ptPaperSize
.x
= _c_10mm2size(pda
->dlga
, pda
->curdlg
.ptPaperSize
.x
);
2864 pda
->curdlg
.ptPaperSize
.y
= _c_10mm2size(pda
->dlga
, pda
->curdlg
.ptPaperSize
.y
);
2865 if (dm
->u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
){
2866 DWORD tmp
= pda
->curdlg
.ptPaperSize
.x
;
2867 pda
->curdlg
.ptPaperSize
.x
= pda
->curdlg
.ptPaperSize
.y
;
2868 pda
->curdlg
.ptPaperSize
.y
= tmp
;
2869 CheckRadioButton(hDlg
, rad1
, rad2
, rad2
);
2872 CheckRadioButton(hDlg
, rad1
, rad2
, rad1
);
2873 /* Changing paper preview */
2874 PRINTDLG_PS_ChangePaperPrev(pda
);
2875 /* Selecting paper in combo */
2876 count
= SendDlgItemMessageA(hDlg
, cmb2
, CB_GETCOUNT
, 0, 0);
2877 if(count
!= CB_ERR
){
2878 for(i
=0; i
<count
; ++i
){
2879 if(SendDlgItemMessageA(hDlg
, cmb2
, CB_GETITEMDATA
, i
, 0) == dm
->u1
.s1
.dmPaperSize
) {
2880 SendDlgItemMessageA(hDlg
, cmb2
, CB_SETCURSEL
, i
, 0);
2886 GlobalUnlock(pda
->pdlg
.hDevMode
);
2890 GETVAL(id
, pda
->curdlg
.rtMargin
.left
);
2893 GETVAL(id
, pda
->curdlg
.rtMargin
.right
);
2896 GETVAL(id
, pda
->curdlg
.rtMargin
.top
);
2899 GETVAL(id
, pda
->curdlg
.rtMargin
.bottom
);
2902 InvalidateRect(GetDlgItem(hDlg
, rct1
), NULL
, TRUE
);
2908 PRINTDLG_PS_WMCommandW(
2909 HWND hDlg
, WPARAM wParam
, LPARAM lParam
, PageSetupDataW
*pda
2911 TRACE("loword (lparam) %d, wparam 0x%lx, lparam %08lx\n",
2912 LOWORD(lParam
),wParam
,lParam
);
2913 switch (LOWORD(wParam
)) {
2915 if (!PRINTDLG_PS_UpdateDlgStructW(hDlg
, pda
))
2917 EndDialog(hDlg
, TRUE
);
2921 EndDialog(hDlg
, FALSE
);
2925 pda
->pdlg
.Flags
= 0;
2926 pda
->pdlg
.hwndOwner
= hDlg
;
2927 if (PrintDlgW(&(pda
->pdlg
)))
2928 PRINTDLG_PS_ChangePrinterW(hDlg
,pda
);
2936 /***********************************************************************
2937 * DefaultPagePaintHook
2938 * Default hook paint procedure that receives WM_PSD_* messages from the dialog box
2939 * whenever the sample page is redrawn.
2943 PRINTDLG_DefaultPagePaintHook(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
,
2944 const PageSetupDataA
*pda
)
2946 LPRECT lprc
= (LPRECT
) lParam
;
2947 HDC hdc
= (HDC
) wParam
;
2950 HFONT hfont
, holdfont
;
2952 TRACE("uMsg: WM_USER+%d\n",uMsg
-WM_USER
);
2953 /* Call user paint hook if enable */
2954 if (pda
->dlga
->Flags
& PSD_ENABLEPAGEPAINTHOOK
)
2955 if (pda
->dlga
->lpfnPagePaintHook(hwndDlg
, uMsg
, wParam
, lParam
))
2959 /* LPPAGESETUPDLG in lParam */
2960 case WM_PSD_PAGESETUPDLG
:
2961 /* Inform about the sample page rectangle */
2962 case WM_PSD_FULLPAGERECT
:
2963 /* Inform about the margin rectangle */
2964 case WM_PSD_MINMARGINRECT
:
2967 /* Draw dashed rectangle showing margins */
2968 case WM_PSD_MARGINRECT
:
2969 hpen
= CreatePen(PS_DASH
, 1, GetSysColor(COLOR_3DSHADOW
));
2970 holdpen
= SelectObject(hdc
, hpen
);
2971 Rectangle(hdc
, lprc
->left
, lprc
->top
, lprc
->right
, lprc
->bottom
);
2972 DeleteObject(SelectObject(hdc
, holdpen
));
2974 /* Draw the fake document */
2975 case WM_PSD_GREEKTEXTRECT
:
2976 /* select a nice scalable font, because we want the text really small */
2977 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, sizeof(lf
), &lf
, 0);
2978 lf
.lfHeight
= 6; /* value chosen based on visual effect */
2979 hfont
= CreateFontIndirectW(&lf
);
2980 holdfont
= SelectObject(hdc
, hfont
);
2982 /* if text not loaded, then do so now */
2983 if (wszFakeDocumentText
[0] == '\0')
2984 LoadStringW(COMDLG32_hInstance
,
2986 wszFakeDocumentText
,
2987 sizeof(wszFakeDocumentText
)/sizeof(wszFakeDocumentText
[0]));
2989 oldbkmode
= SetBkMode(hdc
, TRANSPARENT
);
2990 DrawTextW(hdc
, wszFakeDocumentText
, -1, lprc
, DT_TOP
|DT_LEFT
|DT_NOPREFIX
|DT_WORDBREAK
);
2991 SetBkMode(hdc
, oldbkmode
);
2993 DeleteObject(SelectObject(hdc
, holdfont
));
2996 /* Envelope stamp */
2997 case WM_PSD_ENVSTAMPRECT
:
2998 /* Return address */
2999 case WM_PSD_YAFULLPAGERECT
:
3000 FIXME("envelope/stamp is not implemented\n");
3003 FIXME("Unknown message %x\n",uMsg
);
3009 /***********************************************************************
3011 * The main paint procedure for the PageSetupDlg function.
3012 * The Page Setup dialog box includes an image of a sample page that shows how
3013 * the user's selections affect the appearance of the printed output.
3014 * The image consists of a rectangle that represents the selected paper
3015 * or envelope type, with a dotted-line rectangle representing
3016 * the current margins, and partial (Greek text) characters
3017 * to show how text looks on the printed page.
3019 * The following messages in the order sends to user hook procedure:
3020 * WM_PSD_PAGESETUPDLG Draw the contents of the sample page
3021 * WM_PSD_FULLPAGERECT Inform about the bounding rectangle
3022 * WM_PSD_MINMARGINRECT Inform about the margin rectangle (min margin?)
3023 * WM_PSD_MARGINRECT Draw the margin rectangle
3024 * WM_PSD_GREEKTEXTRECT Draw the Greek text inside the margin rectangle
3025 * If any of first three messages returns TRUE, painting done.
3028 * hWnd [in] Handle to the Page Setup dialog box
3029 * uMsg [in] Received message
3032 * WM_PSD_ENVSTAMPRECT Draw in the envelope-stamp rectangle (for envelopes only)
3033 * WM_PSD_YAFULLPAGERECT Draw the return address portion (for envelopes and other paper sizes)
3036 * FALSE if all done correctly
3041 static LRESULT CALLBACK
3042 PRINTDLG_PagePaintProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3045 RECT rcClient
, rcMargin
;
3048 HBRUSH hbrush
, holdbrush
;
3049 PageSetupDataA
*pda
;
3050 int papersize
=0, orientation
=0; /* FIXME: set this values for user paint hook */
3051 double scalx
, scaly
;
3052 #define CALLPAINTHOOK(msg,lprc) PRINTDLG_DefaultPagePaintHook( hWnd, msg, (WPARAM)hdc, (LPARAM)lprc, pda)
3054 if (uMsg
!= WM_PAINT
)
3055 return CallWindowProcA(lpfnStaticWndProc
, hWnd
, uMsg
, wParam
, lParam
);
3057 /* Processing WM_PAINT message */
3058 pda
= (PageSetupDataA
*)GetPropA(hWnd
, "__WINE_PAGESETUPDLGDATA");
3060 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3063 if (PRINTDLG_DefaultPagePaintHook(hWnd
, WM_PSD_PAGESETUPDLG
, MAKELONG(papersize
, orientation
), (LPARAM
)pda
->dlga
, pda
))
3066 hdc
= BeginPaint(hWnd
, &ps
);
3067 GetClientRect(hWnd
, &rcClient
);
3069 scalx
= rcClient
.right
/ (double)pda
->curdlg
.ptPaperSize
.x
;
3070 scaly
= rcClient
.bottom
/ (double)pda
->curdlg
.ptPaperSize
.y
;
3071 rcMargin
= rcClient
;
3073 rcMargin
.left
+= (LONG
)pda
->curdlg
.rtMargin
.left
* scalx
;
3074 rcMargin
.top
+= (LONG
)pda
->curdlg
.rtMargin
.top
* scalx
;
3075 rcMargin
.right
-= (LONG
)pda
->curdlg
.rtMargin
.right
* scaly
;
3076 rcMargin
.bottom
-= (LONG
)pda
->curdlg
.rtMargin
.bottom
* scaly
;
3078 /* if the space is too small then we make sure to not draw anything */
3079 rcMargin
.left
= min(rcMargin
.left
, rcMargin
.right
);
3080 rcMargin
.top
= min(rcMargin
.top
, rcMargin
.bottom
);
3082 if (!CALLPAINTHOOK(WM_PSD_FULLPAGERECT
, &rcClient
) &&
3083 !CALLPAINTHOOK(WM_PSD_MINMARGINRECT
, &rcMargin
) )
3085 /* fill background */
3086 hbrush
= GetSysColorBrush(COLOR_3DHIGHLIGHT
);
3087 FillRect(hdc
, &rcClient
, hbrush
);
3088 holdbrush
= SelectObject(hdc
, hbrush
);
3090 hpen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DSHADOW
));
3091 holdpen
= SelectObject(hdc
, hpen
);
3093 /* paint left edge */
3094 MoveToEx(hdc
, rcClient
.left
, rcClient
.top
, NULL
);
3095 LineTo(hdc
, rcClient
.left
, rcClient
.bottom
-1);
3097 /* paint top edge */
3098 MoveToEx(hdc
, rcClient
.left
, rcClient
.top
, NULL
);
3099 LineTo(hdc
, rcClient
.right
, rcClient
.top
);
3101 hpen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DDKSHADOW
));
3102 DeleteObject(SelectObject(hdc
, hpen
));
3104 /* paint right edge */
3105 MoveToEx(hdc
, rcClient
.right
-1, rcClient
.top
, NULL
);
3106 LineTo(hdc
, rcClient
.right
-1, rcClient
.bottom
);
3108 /* paint bottom edge */
3109 MoveToEx(hdc
, rcClient
.left
, rcClient
.bottom
-1, NULL
);
3110 LineTo(hdc
, rcClient
.right
, rcClient
.bottom
-1);
3112 DeleteObject(SelectObject(hdc
, holdpen
));
3113 DeleteObject(SelectObject(hdc
, holdbrush
));
3115 CALLPAINTHOOK(WM_PSD_MARGINRECT
, &rcMargin
);
3117 /* give text a bit of a space from the frame */
3120 rcMargin
.right
-= 2;
3121 rcMargin
.bottom
-= 2;
3123 /* if the space is too small then we make sure to not draw anything */
3124 rcMargin
.left
= min(rcMargin
.left
, rcMargin
.right
);
3125 rcMargin
.top
= min(rcMargin
.top
, rcMargin
.bottom
);
3127 CALLPAINTHOOK(WM_PSD_GREEKTEXTRECT
, &rcMargin
);
3130 EndPaint(hWnd
, &ps
);
3132 #undef CALLPAINTHOOK
3135 /***********************************************************************
3136 * PRINTDLG_PageDlgProcA
3137 * Message handler for PageSetupDlgA
3139 static INT_PTR CALLBACK
3140 PRINTDLG_PageDlgProcA(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3143 PageSetupDataA
*pda
;
3144 INT_PTR res
= FALSE
;
3147 if (uMsg
== WM_INITDIALOG
) { /*Init dialog*/
3148 pda
= (PageSetupDataA
*)lParam
;
3149 pda
->hDlg
= hDlg
; /* saving handle to main window to PageSetupDataA structure */
3150 memcpy(&pda
->curdlg
, pda
->dlga
, sizeof(pda
->curdlg
));
3152 hDrawWnd
= GetDlgItem(hDlg
, rct1
);
3153 TRACE("set property to %p\n", pda
);
3154 SetPropA(hDlg
, "__WINE_PAGESETUPDLGDATA", pda
);
3155 SetPropA(hDrawWnd
, "__WINE_PAGESETUPDLGDATA", pda
);
3156 GetWindowRect(hDrawWnd
, &pda
->rtDrawRect
); /* Calculating rect in client coordinates where paper draws */
3157 ScreenToClient(hDlg
, (LPPOINT
)&pda
->rtDrawRect
);
3158 ScreenToClient(hDlg
, (LPPOINT
)(&pda
->rtDrawRect
.right
));
3159 lpfnStaticWndProc
= (WNDPROC
)SetWindowLongPtrW(
3162 (ULONG_PTR
)PRINTDLG_PagePaintProc
);
3164 /* FIXME: Paint hook. Must it be at begin of initializtion or at end? */
3166 if (pda
->dlga
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
3167 if (!pda
->dlga
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,(LPARAM
)pda
->dlga
))
3168 FIXME("Setup page hook failed?\n");
3171 /* if printer button disabled */
3172 if (pda
->dlga
->Flags
& PSD_DISABLEPRINTER
)
3173 EnableWindow(GetDlgItem(hDlg
, psh3
), FALSE
);
3174 /* if margin edit boxes disabled */
3175 if (pda
->dlga
->Flags
& PSD_DISABLEMARGINS
) {
3176 EnableWindow(GetDlgItem(hDlg
, edt4
), FALSE
);
3177 EnableWindow(GetDlgItem(hDlg
, edt5
), FALSE
);
3178 EnableWindow(GetDlgItem(hDlg
, edt6
), FALSE
);
3179 EnableWindow(GetDlgItem(hDlg
, edt7
), FALSE
);
3181 /* Set orientation radiobutton properly */
3182 if(pda
->dlga
->hDevMode
)
3184 dm
= GlobalLock(pda
->dlga
->hDevMode
);
3185 if (dm
->u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
)
3186 CheckRadioButton(hDlg
, rad1
, rad2
, rad2
);
3187 else /* this is default if papersize is not set */
3188 CheckRadioButton(hDlg
, rad1
, rad2
, rad1
);
3189 GlobalUnlock(pda
->dlga
->hDevMode
);
3192 /* if orientation disabled */
3193 if (pda
->dlga
->Flags
& PSD_DISABLEORIENTATION
) {
3194 EnableWindow(GetDlgItem(hDlg
,rad1
),FALSE
);
3195 EnableWindow(GetDlgItem(hDlg
,rad2
),FALSE
);
3197 /* We fill them out enabled or not */
3198 if (pda
->dlga
->Flags
& PSD_MARGINS
) {
3200 _c_size2strA(pda
,pda
->dlga
->rtMargin
.left
,str
);
3201 SetDlgItemTextA(hDlg
,edt4
,str
);
3202 _c_size2strA(pda
,pda
->dlga
->rtMargin
.top
,str
);
3203 SetDlgItemTextA(hDlg
,edt5
,str
);
3204 _c_size2strA(pda
,pda
->dlga
->rtMargin
.right
,str
);
3205 SetDlgItemTextA(hDlg
,edt6
,str
);
3206 _c_size2strA(pda
,pda
->dlga
->rtMargin
.bottom
,str
);
3207 SetDlgItemTextA(hDlg
,edt7
,str
);
3209 /* default is 1 inch */
3210 DWORD size
= _c_inch2size(pda
->dlga
,1000);
3212 _c_size2strA(pda
,size
,str
);
3213 SetDlgItemTextA(hDlg
,edt4
,str
);
3214 SetDlgItemTextA(hDlg
,edt5
,str
);
3215 SetDlgItemTextA(hDlg
,edt6
,str
);
3216 SetDlgItemTextA(hDlg
,edt7
,str
);
3217 pda
->curdlg
.rtMargin
.left
= size
;
3218 pda
->curdlg
.rtMargin
.top
= size
;
3219 pda
->curdlg
.rtMargin
.right
= size
;
3220 pda
->curdlg
.rtMargin
.bottom
= size
;
3222 /* if paper disabled */
3223 if (pda
->dlga
->Flags
& PSD_DISABLEPAPER
) {
3224 EnableWindow(GetDlgItem(hDlg
,cmb2
),FALSE
);
3225 EnableWindow(GetDlgItem(hDlg
,cmb3
),FALSE
);
3227 /* filling combos: printer, paper, source. selecting current printer (from DEVMODEA) */
3228 PRINTDLG_PS_ChangePrinterA(hDlg
, pda
);
3229 dm
= GlobalLock(pda
->pdlg
.hDevMode
);
3231 dm
->dmDefaultSource
= 15; /*FIXME: Automatic select. Does it always 15 at start? */
3232 PRINTDLG_PaperSizeA(&(pda
->pdlg
), dm
->u1
.s1
.dmPaperSize
, &pda
->curdlg
.ptPaperSize
);
3233 GlobalUnlock(pda
->pdlg
.hDevMode
);
3234 pda
->curdlg
.ptPaperSize
.x
= _c_10mm2size(pda
->dlga
, pda
->curdlg
.ptPaperSize
.x
);
3235 pda
->curdlg
.ptPaperSize
.y
= _c_10mm2size(pda
->dlga
, pda
->curdlg
.ptPaperSize
.y
);
3236 if (IsDlgButtonChecked(hDlg
, rad2
) == BST_CHECKED
) { /* Landscape orientation */
3237 DWORD tmp
= pda
->curdlg
.ptPaperSize
.y
;
3238 pda
->curdlg
.ptPaperSize
.y
= pda
->curdlg
.ptPaperSize
.x
;
3239 pda
->curdlg
.ptPaperSize
.x
= tmp
;
3242 WARN("GlobalLock(pda->pdlg.hDevMode) fail? hDevMode=%p\n", pda
->pdlg
.hDevMode
);
3243 /* Drawing paper prev */
3244 PRINTDLG_PS_ChangePaperPrev(pda
);
3247 pda
= (PageSetupDataA
*)GetPropA(hDlg
,"__WINE_PAGESETUPDLGDATA");
3249 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3252 if (pda
->dlga
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
3253 res
= pda
->dlga
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,lParam
);
3254 if (res
) return res
;
3259 return PRINTDLG_PS_WMCommandA(hDlg
, wParam
, lParam
, pda
);
3264 static INT_PTR CALLBACK
3265 PageDlgProcW(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3267 static const WCHAR __WINE_PAGESETUPDLGDATA
[] =
3268 { '_', '_', 'W', 'I', 'N', 'E', '_', 'P', 'A', 'G', 'E',
3269 'S', 'E', 'T', 'U', 'P', 'D', 'L', 'G', 'D', 'A', 'T', 'A', 0 };
3270 PageSetupDataW
*pda
;
3274 if (uMsg
==WM_INITDIALOG
) {
3276 pda
= (PageSetupDataW
*)lParam
;
3277 SetPropW(hDlg
, __WINE_PAGESETUPDLGDATA
, pda
);
3278 if (pda
->dlga
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
3279 res
= pda
->dlga
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,(LPARAM
)pda
->dlga
);
3281 FIXME("Setup page hook failed?\n");
3286 if (pda
->dlga
->Flags
& PSD_ENABLEPAGEPAINTHOOK
) {
3287 FIXME("PagePaintHook not yet implemented!\n");
3289 if (pda
->dlga
->Flags
& PSD_DISABLEPRINTER
)
3290 EnableWindow(GetDlgItem(hDlg
, psh3
), FALSE
);
3291 if (pda
->dlga
->Flags
& PSD_DISABLEMARGINS
) {
3292 EnableWindow(GetDlgItem(hDlg
, edt4
), FALSE
);
3293 EnableWindow(GetDlgItem(hDlg
, edt5
), FALSE
);
3294 EnableWindow(GetDlgItem(hDlg
, edt6
), FALSE
);
3295 EnableWindow(GetDlgItem(hDlg
, edt7
), FALSE
);
3298 if(pda
->dlga
->hDevMode
)
3300 dm
= GlobalLock(pda
->dlga
->hDevMode
);
3301 /* Landscape orientation */
3302 if (dm
->u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
)
3303 CheckRadioButton(hDlg
, rad1
, rad2
, rad2
);
3304 else /* this is default if papersize is not set */
3305 CheckRadioButton(hDlg
, rad1
, rad2
, rad1
);
3306 GlobalUnlock(pda
->dlga
->hDevMode
);
3309 if (pda
->dlga
->Flags
& PSD_DISABLEORIENTATION
) {
3310 EnableWindow(GetDlgItem(hDlg
,rad1
),FALSE
);
3311 EnableWindow(GetDlgItem(hDlg
,rad2
),FALSE
);
3313 /* We fill them out enabled or not */
3314 if (pda
->dlga
->Flags
& PSD_MARGINS
) {
3316 _c_size2strW(pda
,pda
->dlga
->rtMargin
.left
,str
);
3317 SetDlgItemTextW(hDlg
,edt4
,str
);
3318 _c_size2strW(pda
,pda
->dlga
->rtMargin
.top
,str
);
3319 SetDlgItemTextW(hDlg
,edt5
,str
);
3320 _c_size2strW(pda
,pda
->dlga
->rtMargin
.right
,str
);
3321 SetDlgItemTextW(hDlg
,edt6
,str
);
3322 _c_size2strW(pda
,pda
->dlga
->rtMargin
.bottom
,str
);
3323 SetDlgItemTextW(hDlg
,edt7
,str
);
3325 /* default is 1 inch */
3326 DWORD size
= _c_inch2size((LPPAGESETUPDLGA
)pda
->dlga
,1000);
3328 _c_size2strW(pda
,size
,str
);
3329 SetDlgItemTextW(hDlg
,edt4
,str
);
3330 SetDlgItemTextW(hDlg
,edt5
,str
);
3331 SetDlgItemTextW(hDlg
,edt6
,str
);
3332 SetDlgItemTextW(hDlg
,edt7
,str
);
3334 PRINTDLG_PS_ChangePrinterW(hDlg
,pda
);
3335 if (pda
->dlga
->Flags
& PSD_DISABLEPAPER
) {
3336 EnableWindow(GetDlgItem(hDlg
,cmb2
),FALSE
);
3337 EnableWindow(GetDlgItem(hDlg
,cmb3
),FALSE
);
3342 pda
= (PageSetupDataW
*)GetPropW(hDlg
, __WINE_PAGESETUPDLGDATA
);
3344 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3347 if (pda
->dlga
->Flags
& PSD_ENABLEPAGESETUPHOOK
) {
3348 res
= pda
->dlga
->lpfnPageSetupHook(hDlg
,uMsg
,wParam
,lParam
);
3349 if (res
) return res
;
3354 return PRINTDLG_PS_WMCommandW(hDlg
, wParam
, lParam
, pda
);
3359 /***********************************************************************
3360 * PageSetupDlgA (COMDLG32.@)
3362 * Displays the PAGE SETUP dialog box, which enables the user to specify
3363 * specific properties of a printed page such as
3364 * size, source, orientation and the width of the page margins.
3367 * setupdlg [IO] PAGESETUPDLGA struct
3370 * TRUE if the user pressed the OK button
3371 * FALSE if the user cancelled the window or an error occurred
3374 * The values of hDevMode and hDevNames are filled on output and can be
3375 * changed in PAGESETUPDLG when they are passed in PageSetupDlg.
3379 BOOL WINAPI
PageSetupDlgA(LPPAGESETUPDLGA setupdlg
) {
3383 PageSetupDataA
*pda
;
3386 if (setupdlg
== NULL
) {
3387 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
3392 if(TRACE_ON(commdlg
)) {
3393 char flagstr
[1000] = "";
3394 const struct pd_flags
*pflag
= psd_flags
;
3395 for( ; pflag
->name
; pflag
++) {
3396 if(setupdlg
->Flags
& pflag
->flag
) {
3397 strcat(flagstr
, pflag
->name
);
3398 strcat(flagstr
, "|");
3401 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3402 "hinst %p, flags %08x (%s)\n",
3403 setupdlg
, setupdlg
->hwndOwner
, setupdlg
->hDevMode
,
3404 setupdlg
->hDevNames
,
3405 setupdlg
->hInstance
, setupdlg
->Flags
, flagstr
);
3408 /* Checking setupdlg structure */
3409 if(setupdlg
->lStructSize
!= sizeof(PAGESETUPDLGA
)) {
3410 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE
);
3413 if ((setupdlg
->Flags
& PSD_ENABLEPAGEPAINTHOOK
) &&
3414 (setupdlg
->lpfnPagePaintHook
== NULL
)) {
3415 COMDLG32_SetCommDlgExtendedError(CDERR_NOHOOK
);
3419 /* Initialize default printer struct. If no printer device info is specified
3420 retrieve the default printer data. */
3421 memset(&pdlg
,0,sizeof(pdlg
));
3422 pdlg
.lStructSize
= sizeof(pdlg
);
3423 if (setupdlg
->hDevMode
&& setupdlg
->hDevNames
) {
3424 pdlg
.hDevMode
= setupdlg
->hDevMode
;
3425 pdlg
.hDevNames
= setupdlg
->hDevNames
;
3427 pdlg
.Flags
= PD_RETURNDEFAULT
;
3428 bRet
= PrintDlgA(&pdlg
);
3430 if (!(setupdlg
->Flags
& PSD_NOWARNING
)) {
3432 LoadStringA(COMDLG32_hInstance
, PD32_NO_DEFAULT_PRINTER
, errstr
, 255);
3433 MessageBoxA(setupdlg
->hwndOwner
, errstr
, 0, MB_OK
| MB_ICONERROR
);
3439 /* short cut exit, just return default values */
3440 if (setupdlg
->Flags
& PSD_RETURNDEFAULT
) {
3443 setupdlg
->hDevMode
= pdlg
.hDevMode
;
3444 setupdlg
->hDevNames
= pdlg
.hDevNames
;
3445 dm
= GlobalLock(pdlg
.hDevMode
);
3446 PRINTDLG_PaperSizeA(&pdlg
, dm
->u1
.s1
.dmPaperSize
, &setupdlg
->ptPaperSize
);
3447 GlobalUnlock(pdlg
.hDevMode
);
3448 setupdlg
->ptPaperSize
.x
=_c_10mm2size(setupdlg
,setupdlg
->ptPaperSize
.x
);
3449 setupdlg
->ptPaperSize
.y
=_c_10mm2size(setupdlg
,setupdlg
->ptPaperSize
.y
);
3453 /* get dialog template */
3454 hDlgTmpl
= PRINTDLG_GetPGSTemplateA(setupdlg
);
3456 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
3459 ptr
= LockResource( hDlgTmpl
);
3461 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
3465 pda
= HeapAlloc(GetProcessHeap(),0,sizeof(*pda
));
3466 pda
->dlga
= setupdlg
;
3467 memcpy(&pda
->pdlg
,&pdlg
,sizeof(pdlg
));
3469 bRet
= (0<DialogBoxIndirectParamA(
3470 setupdlg
->hInstance
,
3472 setupdlg
->hwndOwner
,
3473 PRINTDLG_PageDlgProcA
,
3477 HeapFree(GetProcessHeap(),0,pda
);
3480 /***********************************************************************
3481 * PageSetupDlgW (COMDLG32.@)
3483 * See PageSetupDlgA.
3485 BOOL WINAPI
PageSetupDlgW(LPPAGESETUPDLGW setupdlg
) {
3489 PageSetupDataW
*pdw
;
3492 FIXME("Unicode implementation is not done yet\n");
3494 if (setupdlg
== NULL
) {
3495 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION
);
3499 if(TRACE_ON(commdlg
)) {
3500 char flagstr
[1000] = "";
3501 const struct pd_flags
*pflag
= psd_flags
;
3502 for( ; pflag
->name
; pflag
++) {
3503 if(setupdlg
->Flags
& pflag
->flag
) {
3504 strcat(flagstr
, pflag
->name
);
3505 strcat(flagstr
, "|");
3508 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3509 "hinst %p, flags %08x (%s)\n",
3510 setupdlg
, setupdlg
->hwndOwner
, setupdlg
->hDevMode
,
3511 setupdlg
->hDevNames
,
3512 setupdlg
->hInstance
, setupdlg
->Flags
, flagstr
);
3515 /* Initialize default printer struct. If no printer device info is specified
3516 retrieve the default printer data. */
3517 memset(&pdlg
,0,sizeof(pdlg
));
3518 pdlg
.lStructSize
= sizeof(pdlg
);
3519 if (setupdlg
->hDevMode
&& setupdlg
->hDevNames
) {
3520 pdlg
.hDevMode
= setupdlg
->hDevMode
;
3521 pdlg
.hDevNames
= setupdlg
->hDevNames
;
3523 pdlg
.Flags
= PD_RETURNDEFAULT
;
3524 bRet
= PrintDlgW(&pdlg
);
3526 if (!(setupdlg
->Flags
& PSD_NOWARNING
)) {
3528 LoadStringW(COMDLG32_hInstance
, PD32_NO_DEFAULT_PRINTER
, errstr
, 255);
3529 MessageBoxW(setupdlg
->hwndOwner
, errstr
, 0, MB_OK
| MB_ICONERROR
);
3535 /* short cut exit, just return default values */
3536 if (setupdlg
->Flags
& PSD_RETURNDEFAULT
) {
3537 static const WCHAR a4
[] = {'A','4',0};
3538 setupdlg
->hDevMode
= pdlg
.hDevMode
;
3539 setupdlg
->hDevNames
= pdlg
.hDevNames
;
3540 /* FIXME: Just return "A4" for now. */
3541 PRINTDLG_PaperSizeW(&pdlg
,a4
,&setupdlg
->ptPaperSize
);
3542 setupdlg
->ptPaperSize
.x
=_c_10mm2size((LPPAGESETUPDLGA
)setupdlg
,setupdlg
->ptPaperSize
.x
);
3543 setupdlg
->ptPaperSize
.y
=_c_10mm2size((LPPAGESETUPDLGA
)setupdlg
,setupdlg
->ptPaperSize
.y
);
3546 hDlgTmpl
= PRINTDLG_GetPGSTemplateW(setupdlg
);
3548 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
3551 ptr
= LockResource( hDlgTmpl
);
3553 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
3556 pdw
= HeapAlloc(GetProcessHeap(),0,sizeof(*pdw
));
3557 pdw
->dlga
= setupdlg
;
3558 memcpy(&pdw
->pdlg
,&pdlg
,sizeof(pdlg
));
3560 bRet
= (0<DialogBoxIndirectParamW(
3561 setupdlg
->hInstance
,
3563 setupdlg
->hwndOwner
,
3570 /***********************************************************************
3571 * PrintDlgExA (COMDLG32.@)
3579 HRESULT WINAPI
PrintDlgExA(LPPRINTDLGEXA lppd
)
3582 FIXME("(%p) stub\n", lppd
);
3583 if ((lppd
== NULL
) || (lppd
->lStructSize
!= sizeof(PRINTDLGEXA
))) {
3584 return E_INVALIDARG
;
3587 if (!IsWindow(lppd
->hwndOwner
)) {
3594 /***********************************************************************
3595 * PrintDlgExW (COMDLG32.@)
3597 * Display the property sheet style PRINT dialog box
3600 * lppd [IO] ptr to PRINTDLGEX struct
3604 * Failure: One of the following COM error codes:
3605 * E_OUTOFMEMORY Insufficient memory.
3606 * E_INVALIDARG One or more arguments are invalid.
3607 * E_POINTER Invalid pointer.
3608 * E_HANDLE Invalid handle.
3609 * E_FAIL Unspecified error.
3612 * This Dialog enables the user to specify specific properties of the print job.
3613 * The property sheet can also have additional application-specific and
3614 * driver-specific property pages.
3620 HRESULT WINAPI
PrintDlgExW(LPPRINTDLGEXW lppd
)
3623 FIXME("(%p) stub\n", lppd
);
3624 if ((lppd
== NULL
) || (lppd
->lStructSize
!= sizeof(PRINTDLGEXW
))) {
3625 return E_INVALIDARG
;
3628 if (!IsWindow(lppd
->hwndOwner
)) {