localspl: Implement XcvDataPort.
[wine/multimedia.git] / dlls / comdlg32 / printdlg.c
blob85ffe00a40f957eb8333aa1237b94fb587f21e12
1 /*
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
23 #include <ctype.h>
24 #include <stdlib.h>
25 #include <stdarg.h>
26 #include <stdio.h>
27 #include <string.h>
29 #define NONAMELESSUNION
30 #define NONAMELESSSTRUCT
31 #include "windef.h"
32 #include "winbase.h"
33 #include "wingdi.h"
34 #include "winuser.h"
35 #include "winspool.h"
36 #include "winerror.h"
38 #include "wine/debug.h"
40 #include "commdlg.h"
41 #include "dlgs.h"
42 #include "cderr.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
46 #include "cdlg.h"
47 #include "printdlg.h"
49 /* Yes these constants are the same, but we're just copying win98 */
50 #define UPDOWN_ID 0x270f
51 #define MAX_COPIES 9999
53 /* Debugging info */
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"},
71 {-1, NULL}
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)
89 WCHAR buf[260];
90 DWORD dwBufLen = sizeof(buf) / sizeof(buf[0]);
91 BOOL res;
92 if(!GetDefaultPrinterW(buf, &dwBufLen))
93 return FALSE;
94 res = OpenPrinterW(buf, hprn, NULL);
95 if (!res)
96 WARN("Could not open printer %s\n", debugstr_w(buf));
97 return res;
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)
115 DWORD needed, num;
116 INT i;
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,
121 &num);
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);
130 if(!name ||
131 (i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1,
132 (LPARAM)name)) == CB_ERR) {
134 char buf[260];
135 DWORD dwBufLen = sizeof(buf);
136 FIXME("Can't find '%s' in printer list so trying to find default\n",
137 name);
138 if(!GetDefaultPrinterA(buf, &dwBufLen))
139 return num;
140 i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
141 if(i == CB_ERR)
142 FIXME("Can't find default printer in printer list\n");
144 SendDlgItemMessageA(hDlg, id, CB_SETCURSEL, i, 0);
145 return num;
148 static INT PRINTDLG_SetUpPrinterListComboW(HWND hDlg, UINT id, LPCWSTR name)
150 DWORD needed, num;
151 INT i;
152 LPPRINTER_INFO_2W pi;
153 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
154 pi = HeapAlloc(GetProcessHeap(), 0, needed);
155 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
156 &num);
158 for(i = 0; i < num; i++) {
159 SendDlgItemMessageW(hDlg, id, CB_ADDSTRING, 0,
160 (LPARAM)pi[i].pPrinterName );
162 HeapFree(GetProcessHeap(), 0, pi);
163 if(!name ||
164 (i = SendDlgItemMessageW(hDlg, id, CB_FINDSTRINGEXACT, -1,
165 (LPARAM)name)) == CB_ERR) {
166 WCHAR buf[260];
167 DWORD dwBufLen = sizeof(buf)/sizeof(buf[0]);
168 TRACE("Can't find '%s' in printer list so trying to find default\n",
169 debugstr_w(name));
170 if(!GetDefaultPrinterW(buf, &dwBufLen))
171 return num;
172 i = SendDlgItemMessageW(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
173 if(i == CB_ERR)
174 TRACE("Can't find default printer in printer list\n");
176 SendDlgItemMessageW(hDlg, id, CB_SETCURSEL, i, 0);
177 return num;
180 /***********************************************************************
181 * PRINTDLG_CreateDevNames [internal]
184 * creates a DevNames structure.
186 * (NB. when we handle unicode the offsets will be in wchars).
188 static BOOL PRINTDLG_CreateDevNames(HGLOBAL *hmem, char* DeviceDriverName,
189 char* DeviceName, char* OutputPort)
191 long size;
192 char* pDevNamesSpace;
193 char* pTempPtr;
194 LPDEVNAMES lpDevNames;
195 char buf[260];
196 DWORD dwBufLen = sizeof(buf);
198 size = strlen(DeviceDriverName) + 1
199 + strlen(DeviceName) + 1
200 + strlen(OutputPort) + 1
201 + sizeof(DEVNAMES);
203 if(*hmem)
204 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
205 else
206 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
207 if (*hmem == 0)
208 return FALSE;
210 pDevNamesSpace = GlobalLock(*hmem);
211 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
213 pTempPtr = pDevNamesSpace + sizeof(DEVNAMES);
214 strcpy(pTempPtr, DeviceDriverName);
215 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
217 pTempPtr += strlen(DeviceDriverName) + 1;
218 strcpy(pTempPtr, DeviceName);
219 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
221 pTempPtr += strlen(DeviceName) + 1;
222 strcpy(pTempPtr, OutputPort);
223 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
225 GetDefaultPrinterA(buf, &dwBufLen);
226 lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
227 GlobalUnlock(*hmem);
228 return TRUE;
231 static BOOL PRINTDLG_CreateDevNamesW(HGLOBAL *hmem, LPCWSTR DeviceDriverName,
232 LPCWSTR DeviceName, LPCWSTR OutputPort)
234 long size;
235 LPWSTR pDevNamesSpace;
236 LPWSTR pTempPtr;
237 LPDEVNAMES lpDevNames;
238 WCHAR bufW[260];
239 DWORD dwBufLen = sizeof(bufW) / sizeof(WCHAR);
241 size = sizeof(WCHAR)*lstrlenW(DeviceDriverName) + 2
242 + sizeof(WCHAR)*lstrlenW(DeviceName) + 2
243 + sizeof(WCHAR)*lstrlenW(OutputPort) + 2
244 + sizeof(DEVNAMES);
246 if(*hmem)
247 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
248 else
249 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
250 if (*hmem == 0)
251 return FALSE;
253 pDevNamesSpace = GlobalLock(*hmem);
254 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
256 pTempPtr = (LPWSTR)((LPDEVNAMES)pDevNamesSpace + 1);
257 lstrcpyW(pTempPtr, DeviceDriverName);
258 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
260 pTempPtr += lstrlenW(DeviceDriverName) + 1;
261 lstrcpyW(pTempPtr, DeviceName);
262 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
264 pTempPtr += lstrlenW(DeviceName) + 1;
265 lstrcpyW(pTempPtr, OutputPort);
266 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
268 GetDefaultPrinterW(bufW, &dwBufLen);
269 lpDevNames->wDefault = (lstrcmpW(bufW, DeviceName) == 0) ? 1 : 0;
270 GlobalUnlock(*hmem);
271 return TRUE;
274 /***********************************************************************
275 * PRINTDLG_UpdatePrintDlg [internal]
278 * updates the PrintDlg structure for return values.
280 * RETURNS
281 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
282 * TRUE if successful.
284 static BOOL PRINTDLG_UpdatePrintDlgA(HWND hDlg,
285 PRINT_PTRA* PrintStructures)
287 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
288 PDEVMODEA lpdm = PrintStructures->lpDevMode;
289 LPPRINTER_INFO_2A pi = PrintStructures->lpPrinterInfo;
292 if(!lpdm) {
293 FIXME("No lpdm ptr?\n");
294 return FALSE;
298 if(!(lppd->Flags & PD_PRINTSETUP)) {
299 /* check whether nFromPage and nToPage are within range defined by
300 * nMinPage and nMaxPage
302 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
303 WORD nToPage;
304 WORD nFromPage;
305 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
306 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
307 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
308 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
309 char resourcestr[256];
310 char resultstr[256];
311 LoadStringA(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
312 resourcestr, 255);
313 sprintf(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
314 LoadStringA(COMDLG32_hInstance, PD32_PRINT_TITLE,
315 resourcestr, 255);
316 MessageBoxA(hDlg, resultstr, resourcestr,
317 MB_OK | MB_ICONWARNING);
318 return FALSE;
320 lppd->nFromPage = nFromPage;
321 lppd->nToPage = nToPage;
322 lppd->Flags |= PD_PAGENUMS;
324 else
325 lppd->Flags &= ~PD_PAGENUMS;
327 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
328 static char file[] = "FILE:";
329 lppd->Flags |= PD_PRINTTOFILE;
330 pi->pPortName = file;
333 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
334 FIXME("Collate lppd not yet implemented as output\n");
337 /* set PD_Collate and nCopies */
338 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
339 /* The application doesn't support multiple copies or collate...
341 lppd->Flags &= ~PD_COLLATE;
342 lppd->nCopies = 1;
343 /* if the printer driver supports it... store info there
344 * otherwise no collate & multiple copies !
346 if (lpdm->dmFields & DM_COLLATE)
347 lpdm->dmCollate =
348 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
349 if (lpdm->dmFields & DM_COPIES)
350 lpdm->dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
351 } else {
352 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
353 lppd->Flags |= PD_COLLATE;
354 else
355 lppd->Flags &= ~PD_COLLATE;
356 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
359 return TRUE;
362 static BOOL PRINTDLG_UpdatePrintDlgW(HWND hDlg,
363 PRINT_PTRW* PrintStructures)
365 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
366 PDEVMODEW lpdm = PrintStructures->lpDevMode;
367 LPPRINTER_INFO_2W pi = PrintStructures->lpPrinterInfo;
370 if(!lpdm) {
371 FIXME("No lpdm ptr?\n");
372 return FALSE;
376 if(!(lppd->Flags & PD_PRINTSETUP)) {
377 /* check whether nFromPage and nToPage are within range defined by
378 * nMinPage and nMaxPage
380 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
381 WORD nToPage;
382 WORD nFromPage;
383 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
384 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
385 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
386 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
387 WCHAR resourcestr[256];
388 WCHAR resultstr[256];
389 LoadStringW(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
390 resourcestr, 255);
391 wsprintfW(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
392 LoadStringW(COMDLG32_hInstance, PD32_PRINT_TITLE,
393 resourcestr, 255);
394 MessageBoxW(hDlg, resultstr, resourcestr,
395 MB_OK | MB_ICONWARNING);
396 return FALSE;
398 lppd->nFromPage = nFromPage;
399 lppd->nToPage = nToPage;
400 lppd->Flags |= PD_PAGENUMS;
402 else
403 lppd->Flags &= ~PD_PAGENUMS;
405 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
406 static WCHAR file[] = {'F','I','L','E',':',0};
407 lppd->Flags |= PD_PRINTTOFILE;
408 pi->pPortName = file;
411 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
412 FIXME("Collate lppd not yet implemented as output\n");
415 /* set PD_Collate and nCopies */
416 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
417 /* The application doesn't support multiple copies or collate...
419 lppd->Flags &= ~PD_COLLATE;
420 lppd->nCopies = 1;
421 /* if the printer driver supports it... store info there
422 * otherwise no collate & multiple copies !
424 if (lpdm->dmFields & DM_COLLATE)
425 lpdm->dmCollate =
426 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
427 if (lpdm->dmFields & DM_COPIES)
428 lpdm->dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
429 } else {
430 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
431 lppd->Flags |= PD_COLLATE;
432 else
433 lppd->Flags &= ~PD_COLLATE;
434 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
437 return TRUE;
440 static BOOL PRINTDLG_PaperSizeA(
441 PRINTDLGA *pdlga,const WORD PaperSize,LPPOINT size
443 DEVNAMES *dn;
444 DEVMODEA *dm;
445 LPSTR devname,portname;
446 int i;
447 INT NrOfEntries,ret;
448 WORD *Words = NULL;
449 POINT *points = NULL;
450 BOOL retval = FALSE;
452 dn = GlobalLock(pdlga->hDevNames);
453 dm = GlobalLock(pdlga->hDevMode);
454 devname = ((char*)dn)+dn->wDeviceOffset;
455 portname = ((char*)dn)+dn->wOutputOffset;
458 NrOfEntries = DeviceCapabilitiesA(devname,portname,DC_PAPERNAMES,NULL,dm);
459 if (!NrOfEntries) {
460 FIXME("No papernames found for %s/%s\n",devname,portname);
461 goto out;
463 if (NrOfEntries == -1) {
464 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
465 goto out;
468 Words = HeapAlloc(GetProcessHeap(),0,NrOfEntries*sizeof(WORD));
469 if (NrOfEntries != (ret=DeviceCapabilitiesA(devname,portname,DC_PAPERS,(LPSTR)Words,dm))) {
470 FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
471 goto out;
473 for (i=0;i<NrOfEntries;i++)
474 if (Words[i] == PaperSize)
475 break;
476 HeapFree(GetProcessHeap(),0,Words);
477 if (i == NrOfEntries) {
478 FIXME("Papersize %d not found in list?\n",PaperSize);
479 goto out;
481 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
482 if (NrOfEntries!=(ret=DeviceCapabilitiesA(devname,portname,DC_PAPERSIZE,(LPSTR)points,dm))) {
483 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
484 goto out;
486 /* this is _10ths_ of a millimeter */
487 size->x=points[i].x;
488 size->y=points[i].y;
489 retval = TRUE;
490 out:
491 GlobalUnlock(pdlga->hDevNames);
492 GlobalUnlock(pdlga->hDevMode);
493 HeapFree(GetProcessHeap(),0,Words);
494 HeapFree(GetProcessHeap(),0,points);
495 return retval;
498 static BOOL PRINTDLG_PaperSizeW(
499 PRINTDLGW *pdlga,const WCHAR *PaperSize,LPPOINT size
501 DEVNAMES *dn;
502 DEVMODEW *dm;
503 LPWSTR devname,portname;
504 int i;
505 INT NrOfEntries,ret;
506 WCHAR *Names = NULL;
507 POINT *points = NULL;
508 BOOL retval = FALSE;
510 dn = GlobalLock(pdlga->hDevNames);
511 dm = GlobalLock(pdlga->hDevMode);
512 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
513 portname = ((WCHAR*)dn)+dn->wOutputOffset;
516 NrOfEntries = DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,NULL,dm);
517 if (!NrOfEntries) {
518 FIXME("No papernames found for %s/%s\n",debugstr_w(devname),debugstr_w(portname));
519 goto out;
521 if (NrOfEntries == -1) {
522 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
523 goto out;
526 Names = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*NrOfEntries*64);
527 if (NrOfEntries != (ret=DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,Names,dm))) {
528 FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
529 goto out;
531 for (i=0;i<NrOfEntries;i++)
532 if (!lstrcmpW(PaperSize,Names+(64*i)))
533 break;
534 HeapFree(GetProcessHeap(),0,Names);
535 if (i==NrOfEntries) {
536 FIXME("Papersize %s not found in list?\n",debugstr_w(PaperSize));
537 goto out;
539 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
540 if (NrOfEntries!=(ret=DeviceCapabilitiesW(devname,portname,DC_PAPERSIZE,(LPWSTR)points,dm))) {
541 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
542 goto out;
544 /* this is _10ths_ of a millimeter */
545 size->x=points[i].x;
546 size->y=points[i].y;
547 retval = TRUE;
548 out:
549 GlobalUnlock(pdlga->hDevNames);
550 GlobalUnlock(pdlga->hDevMode);
551 HeapFree(GetProcessHeap(),0,Names);
552 HeapFree(GetProcessHeap(),0,points);
553 return retval;
557 /************************************************************************
558 * PRINTDLG_SetUpPaperComboBox
560 * Initialize either the papersize or inputslot combos of the Printer Setup
561 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
562 * We also try to re-select the old selection.
564 static BOOL PRINTDLG_SetUpPaperComboBoxA(HWND hDlg,
565 int nIDComboBox,
566 char* PrinterName,
567 char* PortName,
568 LPDEVMODEA dm)
570 int i;
571 int NrOfEntries;
572 char* Names;
573 WORD* Words;
574 DWORD Sel;
575 WORD oldWord = 0;
576 int NamesSize;
577 int fwCapability_Names;
578 int fwCapability_Words;
580 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName,PortName,nIDComboBox);
582 /* query the dialog box for the current selected value */
583 Sel = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
584 if(Sel != CB_ERR) {
585 /* we enter here only if a different printer is selected after
586 * the Print Setup dialog is opened. The current settings are
587 * stored into the newly selected printer.
589 oldWord = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA,
590 Sel, 0);
591 if (dm) {
592 if (nIDComboBox == cmb2)
593 dm->u1.s1.dmPaperSize = oldWord;
594 else
595 dm->dmDefaultSource = oldWord;
598 else {
599 /* we enter here only when the Print setup dialog is initially
600 * opened. In this case the settings are restored from when
601 * the dialog was last closed.
603 if (dm) {
604 if (nIDComboBox == cmb2)
605 oldWord = dm->u1.s1.dmPaperSize;
606 else
607 oldWord = dm->dmDefaultSource;
611 if (nIDComboBox == cmb2) {
612 NamesSize = 64;
613 fwCapability_Names = DC_PAPERNAMES;
614 fwCapability_Words = DC_PAPERS;
615 } else {
616 nIDComboBox = cmb3;
617 NamesSize = 24;
618 fwCapability_Names = DC_BINNAMES;
619 fwCapability_Words = DC_BINS;
622 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
623 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
625 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
626 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
627 fwCapability_Names, NULL, dm);
628 if (NrOfEntries == 0)
629 WARN("no Name Entries found!\n");
630 else if (NrOfEntries < 0)
631 return FALSE;
633 if(DeviceCapabilitiesA(PrinterName, PortName, fwCapability_Words, NULL, dm)
634 != NrOfEntries) {
635 ERR("Number of caps is different\n");
636 NrOfEntries = 0;
639 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(char)*NamesSize);
640 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
641 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
642 fwCapability_Names, Names, dm);
643 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
644 fwCapability_Words, (LPSTR)Words, dm);
646 /* reset any current content in the combobox */
647 SendDlgItemMessageA(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
649 /* store new content */
650 for (i = 0; i < NrOfEntries; i++) {
651 DWORD pos = SendDlgItemMessageA(hDlg, nIDComboBox, CB_ADDSTRING, 0,
652 (LPARAM)(&Names[i*NamesSize]) );
653 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
654 Words[i]);
657 /* Look for old selection - can't do this is previous loop since
658 item order will change as more items are added */
659 Sel = 0;
660 for (i = 0; i < NrOfEntries; i++) {
661 if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
662 oldWord) {
663 Sel = i;
664 break;
667 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
669 HeapFree(GetProcessHeap(),0,Words);
670 HeapFree(GetProcessHeap(),0,Names);
671 return TRUE;
674 static BOOL PRINTDLG_SetUpPaperComboBoxW(HWND hDlg,
675 int nIDComboBox,
676 WCHAR* PrinterName,
677 WCHAR* PortName,
678 LPDEVMODEW dm)
680 int i;
681 int NrOfEntries;
682 WCHAR* Names;
683 WORD* Words;
684 DWORD Sel;
685 WORD oldWord = 0;
686 int NamesSize;
687 int fwCapability_Names;
688 int fwCapability_Words;
690 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName),debugstr_w(PortName),nIDComboBox);
692 /* query the dialog box for the current selected value */
693 Sel = SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
694 if(Sel != CB_ERR) {
695 /* we enter here only if a different printer is selected after
696 * the Print Setup dialog is opened. The current settings are
697 * stored into the newly selected printer.
699 oldWord = SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETITEMDATA,
700 Sel, 0);
701 if (dm) {
702 if (nIDComboBox == cmb2)
703 dm->u1.s1.dmPaperSize = oldWord;
704 else
705 dm->dmDefaultSource = oldWord;
708 else {
709 /* we enter here only when the Print setup dialog is initially
710 * opened. In this case the settings are restored from when
711 * the dialog was last closed.
713 if (dm) {
714 if (nIDComboBox == cmb2)
715 oldWord = dm->u1.s1.dmPaperSize;
716 else
717 oldWord = dm->dmDefaultSource;
721 if (nIDComboBox == cmb2) {
722 NamesSize = 64;
723 fwCapability_Names = DC_PAPERNAMES;
724 fwCapability_Words = DC_PAPERS;
725 } else {
726 nIDComboBox = cmb3;
727 NamesSize = 24;
728 fwCapability_Names = DC_BINNAMES;
729 fwCapability_Words = DC_BINS;
732 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
733 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
735 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
736 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
737 fwCapability_Names, NULL, dm);
738 if (NrOfEntries == 0)
739 WARN("no Name Entries found!\n");
740 else if (NrOfEntries < 0)
741 return FALSE;
743 if(DeviceCapabilitiesW(PrinterName, PortName, fwCapability_Words, NULL, dm)
744 != NrOfEntries) {
745 ERR("Number of caps is different\n");
746 NrOfEntries = 0;
749 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WCHAR)*NamesSize);
750 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
751 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
752 fwCapability_Names, Names, dm);
753 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
754 fwCapability_Words, (LPWSTR)Words, dm);
756 /* reset any current content in the combobox */
757 SendDlgItemMessageW(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
759 /* store new content */
760 for (i = 0; i < NrOfEntries; i++) {
761 DWORD pos = SendDlgItemMessageW(hDlg, nIDComboBox, CB_ADDSTRING, 0,
762 (LPARAM)(&Names[i*NamesSize]) );
763 SendDlgItemMessageW(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
764 Words[i]);
767 /* Look for old selection - can't do this is previous loop since
768 item order will change as more items are added */
769 Sel = 0;
770 for (i = 0; i < NrOfEntries; i++) {
771 if(SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
772 oldWord) {
773 Sel = i;
774 break;
777 SendDlgItemMessageW(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
779 HeapFree(GetProcessHeap(),0,Words);
780 HeapFree(GetProcessHeap(),0,Names);
781 return TRUE;
785 /***********************************************************************
786 * PRINTDLG_UpdatePrinterInfoTexts [internal]
788 static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg, LPPRINTER_INFO_2A pi)
790 char StatusMsg[256];
791 char ResourceString[256];
792 int i;
794 /* Status Message */
795 StatusMsg[0]='\0';
797 /* add all status messages */
798 for (i = 0; i < 25; i++) {
799 if (pi->Status & (1<<i)) {
800 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
801 ResourceString, 255);
802 strcat(StatusMsg,ResourceString);
805 /* append "ready" */
806 /* FIXME: status==ready must only be appended if really so.
807 but how to detect? */
808 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
809 ResourceString, 255);
810 strcat(StatusMsg,ResourceString);
811 SetDlgItemTextA(hDlg, stc12, StatusMsg);
813 /* set all other printer info texts */
814 SetDlgItemTextA(hDlg, stc11, pi->pDriverName);
816 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
817 SetDlgItemTextA(hDlg, stc14, pi->pLocation);
818 else
819 SetDlgItemTextA(hDlg, stc14, pi->pPortName);
820 SetDlgItemTextA(hDlg, stc13, pi->pComment ? pi->pComment : "");
821 return;
824 static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg, LPPRINTER_INFO_2W pi)
826 WCHAR StatusMsg[256];
827 WCHAR ResourceString[256];
828 static const WCHAR emptyW[] = {0};
829 int i;
831 /* Status Message */
832 StatusMsg[0]='\0';
834 /* add all status messages */
835 for (i = 0; i < 25; i++) {
836 if (pi->Status & (1<<i)) {
837 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
838 ResourceString, 255);
839 lstrcatW(StatusMsg,ResourceString);
842 /* append "ready" */
843 /* FIXME: status==ready must only be appended if really so.
844 but how to detect? */
845 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
846 ResourceString, 255);
847 lstrcatW(StatusMsg,ResourceString);
848 SetDlgItemTextW(hDlg, stc12, StatusMsg);
850 /* set all other printer info texts */
851 SetDlgItemTextW(hDlg, stc11, pi->pDriverName);
852 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
853 SetDlgItemTextW(hDlg, stc14, pi->pLocation);
854 else
855 SetDlgItemTextW(hDlg, stc14, pi->pPortName);
856 SetDlgItemTextW(hDlg, stc13, pi->pComment ? pi->pComment : emptyW);
860 /*******************************************************************
862 * PRINTDLG_ChangePrinter
865 BOOL PRINTDLG_ChangePrinterA(HWND hDlg, char *name,
866 PRINT_PTRA *PrintStructures)
868 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
869 LPDEVMODEA lpdm = NULL;
870 LONG dmSize;
871 DWORD needed;
872 HANDLE hprn;
874 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
875 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
876 if(!OpenPrinterA(name, &hprn, NULL)) {
877 ERR("Can't open printer %s\n", name);
878 return FALSE;
880 GetPrinterA(hprn, 2, NULL, 0, &needed);
881 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,needed);
882 GetPrinterA(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
883 &needed);
884 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
885 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,needed);
886 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
887 needed, &needed)) {
888 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures->lpPrinterInfo->pPrinterName);
889 return FALSE;
891 ClosePrinter(hprn);
893 PRINTDLG_UpdatePrinterInfoTextsA(hDlg, PrintStructures->lpPrinterInfo);
895 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
896 PrintStructures->lpDevMode = NULL;
898 dmSize = DocumentPropertiesA(0, 0, name, NULL, NULL, 0);
899 if(dmSize == -1) {
900 ERR("DocumentProperties fails on %s\n", debugstr_a(name));
901 return FALSE;
903 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
904 dmSize = DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, NULL,
905 DM_OUT_BUFFER);
906 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
907 !lstrcmpA( (LPSTR) lpdm->dmDeviceName,
908 (LPSTR) PrintStructures->lpDevMode->dmDeviceName)) {
909 /* Supplied devicemode matches current printer so try to use it */
910 DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, lpdm,
911 DM_OUT_BUFFER | DM_IN_BUFFER);
913 if(lpdm)
914 GlobalUnlock(lppd->hDevMode);
916 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
918 if(!(lppd->Flags & PD_PRINTSETUP)) {
919 /* Print range (All/Range/Selection) */
920 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
921 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
922 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
923 if (lppd->Flags & PD_NOSELECTION)
924 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
925 else
926 if (lppd->Flags & PD_SELECTION)
927 CheckRadioButton(hDlg, rad1, rad3, rad2);
928 if (lppd->Flags & PD_NOPAGENUMS) {
929 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
930 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
931 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
932 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
933 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
934 } else {
935 if (lppd->Flags & PD_PAGENUMS)
936 CheckRadioButton(hDlg, rad1, rad3, rad3);
939 /* Collate pages
941 * FIXME: The ico3 is not displayed for some reason. I don't know why.
943 if (lppd->Flags & PD_COLLATE) {
944 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
945 (LPARAM)PrintStructures->hCollateIcon);
946 CheckDlgButton(hDlg, chx2, 1);
947 } else {
948 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
949 (LPARAM)PrintStructures->hNoCollateIcon);
950 CheckDlgButton(hDlg, chx2, 0);
953 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
954 /* if printer doesn't support it: no Collate */
955 if (!(lpdm->dmFields & DM_COLLATE)) {
956 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
957 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
961 /* nCopies */
963 INT copies;
964 if (lppd->hDevMode == 0)
965 copies = lppd->nCopies;
966 else
967 copies = lpdm->dmCopies;
968 if(copies == 0) copies = 1;
969 else if(copies < 0) copies = MAX_COPIES;
970 SetDlgItemInt(hDlg, edt3, copies, FALSE);
973 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
974 /* if printer doesn't support it: no nCopies */
975 if (!(lpdm->dmFields & DM_COPIES)) {
976 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
977 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
981 /* print to file */
982 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
983 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
984 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
985 if (lppd->Flags & PD_HIDEPRINTTOFILE)
986 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
988 } else { /* PD_PRINTSETUP */
989 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
991 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb2,
992 PrintStructures->lpPrinterInfo->pPrinterName,
993 PrintStructures->lpPrinterInfo->pPortName,
994 lpdm);
995 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb3,
996 PrintStructures->lpPrinterInfo->pPrinterName,
997 PrintStructures->lpPrinterInfo->pPortName,
998 lpdm);
999 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1000 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1001 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1002 PrintStructures->hLandscapeIcon));
1006 /* help button */
1007 if ((lppd->Flags & PD_SHOWHELP)==0) {
1008 /* hide if PD_SHOWHELP not specified */
1009 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1011 return TRUE;
1014 static BOOL PRINTDLG_ChangePrinterW(HWND hDlg, WCHAR *name,
1015 PRINT_PTRW *PrintStructures)
1017 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1018 LPDEVMODEW lpdm = NULL;
1019 LONG dmSize;
1020 DWORD needed;
1021 HANDLE hprn;
1023 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
1024 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
1025 if(!OpenPrinterW(name, &hprn, NULL)) {
1026 ERR("Can't open printer %s\n", debugstr_w(name));
1027 return FALSE;
1029 GetPrinterW(hprn, 2, NULL, 0, &needed);
1030 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
1031 GetPrinterW(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
1032 &needed);
1033 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
1034 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
1035 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
1036 needed, &needed)) {
1037 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures->lpPrinterInfo->pPrinterName));
1038 return FALSE;
1040 ClosePrinter(hprn);
1042 PRINTDLG_UpdatePrinterInfoTextsW(hDlg, PrintStructures->lpPrinterInfo);
1044 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
1045 PrintStructures->lpDevMode = NULL;
1047 dmSize = DocumentPropertiesW(0, 0, name, NULL, NULL, 0);
1048 if(dmSize == -1) {
1049 ERR("DocumentProperties fails on %s\n", debugstr_w(name));
1050 return FALSE;
1052 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
1053 dmSize = DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, NULL,
1054 DM_OUT_BUFFER);
1055 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
1056 !lstrcmpW(lpdm->dmDeviceName,
1057 PrintStructures->lpDevMode->dmDeviceName)) {
1058 /* Supplied devicemode matches current printer so try to use it */
1059 DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, lpdm,
1060 DM_OUT_BUFFER | DM_IN_BUFFER);
1062 if(lpdm)
1063 GlobalUnlock(lppd->hDevMode);
1065 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
1067 if(!(lppd->Flags & PD_PRINTSETUP)) {
1068 /* Print range (All/Range/Selection) */
1069 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
1070 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
1071 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
1072 if (lppd->Flags & PD_NOSELECTION)
1073 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
1074 else
1075 if (lppd->Flags & PD_SELECTION)
1076 CheckRadioButton(hDlg, rad1, rad3, rad2);
1077 if (lppd->Flags & PD_NOPAGENUMS) {
1078 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
1079 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
1080 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
1081 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
1082 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
1083 } else {
1084 if (lppd->Flags & PD_PAGENUMS)
1085 CheckRadioButton(hDlg, rad1, rad3, rad3);
1088 /* Collate pages
1090 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1092 if (lppd->Flags & PD_COLLATE) {
1093 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1094 (LPARAM)PrintStructures->hCollateIcon);
1095 CheckDlgButton(hDlg, chx2, 1);
1096 } else {
1097 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1098 (LPARAM)PrintStructures->hNoCollateIcon);
1099 CheckDlgButton(hDlg, chx2, 0);
1102 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1103 /* if printer doesn't support it: no Collate */
1104 if (!(lpdm->dmFields & DM_COLLATE)) {
1105 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1106 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
1110 /* nCopies */
1112 INT copies;
1113 if (lppd->hDevMode == 0)
1114 copies = lppd->nCopies;
1115 else
1116 copies = lpdm->dmCopies;
1117 if(copies == 0) copies = 1;
1118 else if(copies < 0) copies = MAX_COPIES;
1119 SetDlgItemInt(hDlg, edt3, copies, FALSE);
1122 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1123 /* if printer doesn't support it: no nCopies */
1124 if (!(lpdm->dmFields & DM_COPIES)) {
1125 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
1126 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
1130 /* print to file */
1131 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
1132 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
1133 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
1134 if (lppd->Flags & PD_HIDEPRINTTOFILE)
1135 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
1137 } else { /* PD_PRINTSETUP */
1138 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
1140 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb2,
1141 PrintStructures->lpPrinterInfo->pPrinterName,
1142 PrintStructures->lpPrinterInfo->pPortName,
1143 lpdm);
1144 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb3,
1145 PrintStructures->lpPrinterInfo->pPrinterName,
1146 PrintStructures->lpPrinterInfo->pPortName,
1147 lpdm);
1148 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1149 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1150 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1151 PrintStructures->hLandscapeIcon));
1155 /* help button */
1156 if ((lppd->Flags & PD_SHOWHELP)==0) {
1157 /* hide if PD_SHOWHELP not specified */
1158 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1160 return TRUE;
1163 /***********************************************************************
1164 * check_printer_setup [internal]
1166 static LRESULT check_printer_setup(HWND hDlg)
1168 DWORD needed,num;
1169 WCHAR resourcestr[256],resultstr[256];
1170 int res;
1172 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
1173 if(needed == 0)
1175 EnumPrintersW(PRINTER_ENUM_CONNECTIONS, NULL, 2, NULL, 0, &needed, &num);
1177 if(needed > 0)
1178 return TRUE;
1179 else
1181 LoadStringW(COMDLG32_hInstance, PD32_NO_DEVICES,resultstr, 255);
1182 LoadStringW(COMDLG32_hInstance, PD32_PRINT_TITLE,resourcestr, 255);
1183 res = MessageBoxW(hDlg, resultstr, resourcestr,MB_OK | MB_ICONWARNING);
1184 return FALSE;
1188 /***********************************************************************
1189 * PRINTDLG_WMInitDialog [internal]
1191 static LRESULT PRINTDLG_WMInitDialog(HWND hDlg, WPARAM wParam,
1192 PRINT_PTRA* PrintStructures)
1194 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
1195 DEVNAMES *pdn;
1196 DEVMODEA *pdm;
1197 char *name = NULL;
1198 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1200 /* load Collate ICONs */
1201 /* We load these with LoadImage because they are not a standard
1202 size and we don't want them rescaled */
1203 PrintStructures->hCollateIcon =
1204 LoadImageA(COMDLG32_hInstance, "PD32_COLLATE", IMAGE_ICON, 0, 0, 0);
1205 PrintStructures->hNoCollateIcon =
1206 LoadImageA(COMDLG32_hInstance, "PD32_NOCOLLATE", IMAGE_ICON, 0, 0, 0);
1208 /* These can be done with LoadIcon */
1209 PrintStructures->hPortraitIcon =
1210 LoadIconA(COMDLG32_hInstance, "PD32_PORTRAIT");
1211 PrintStructures->hLandscapeIcon =
1212 LoadIconA(COMDLG32_hInstance, "PD32_LANDSCAPE");
1214 /* display the collate/no_collate icon */
1215 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1216 (LPARAM)PrintStructures->hNoCollateIcon);
1218 if(PrintStructures->hCollateIcon == 0 ||
1219 PrintStructures->hNoCollateIcon == 0 ||
1220 PrintStructures->hPortraitIcon == 0 ||
1221 PrintStructures->hLandscapeIcon == 0) {
1222 ERR("no icon in resourcefile\n");
1223 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1224 EndDialog(hDlg, FALSE);
1228 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1229 * must be registered and the Help button must be shown.
1231 if (lppd->Flags & PD_SHOWHELP) {
1232 if((PrintStructures->HelpMessageID =
1233 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
1234 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1235 return FALSE;
1237 } else
1238 PrintStructures->HelpMessageID = 0;
1240 if(!(lppd->Flags &PD_PRINTSETUP)) {
1241 PrintStructures->hwndUpDown =
1242 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1243 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1244 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1245 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1246 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1249 /* FIXME: I allow more freedom than either Win95 or WinNT,
1250 * which do not agree to what errors should be thrown or not
1251 * in case nToPage or nFromPage is out-of-range.
1253 if (lppd->nMaxPage < lppd->nMinPage)
1254 lppd->nMaxPage = lppd->nMinPage;
1255 if (lppd->nMinPage == lppd->nMaxPage)
1256 lppd->Flags |= PD_NOPAGENUMS;
1257 if (lppd->nToPage < lppd->nMinPage)
1258 lppd->nToPage = lppd->nMinPage;
1259 if (lppd->nToPage > lppd->nMaxPage)
1260 lppd->nToPage = lppd->nMaxPage;
1261 if (lppd->nFromPage < lppd->nMinPage)
1262 lppd->nFromPage = lppd->nMinPage;
1263 if (lppd->nFromPage > lppd->nMaxPage)
1264 lppd->nFromPage = lppd->nMaxPage;
1266 /* if we have the combo box, fill it */
1267 if (GetDlgItem(hDlg,comboID)) {
1268 /* Fill Combobox
1270 pdn = GlobalLock(lppd->hDevNames);
1271 pdm = GlobalLock(lppd->hDevMode);
1272 if(pdn)
1273 name = (char*)pdn + pdn->wDeviceOffset;
1274 else if(pdm)
1275 name = (char*)pdm->dmDeviceName;
1276 PRINTDLG_SetUpPrinterListComboA(hDlg, comboID, name);
1277 if(pdm) GlobalUnlock(lppd->hDevMode);
1278 if(pdn) GlobalUnlock(lppd->hDevNames);
1280 /* Now find selected printer and update rest of dlg */
1281 name = HeapAlloc(GetProcessHeap(),0,256);
1282 if (GetDlgItemTextA(hDlg, comboID, name, 255))
1283 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1284 HeapFree(GetProcessHeap(),0,name);
1285 } else {
1286 /* else use default printer */
1287 char name[200];
1288 DWORD dwBufLen = sizeof(name);
1289 BOOL ret = GetDefaultPrinterA(name, &dwBufLen);
1291 if (ret)
1292 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1293 else
1294 FIXME("No default printer found, expect problems!\n");
1296 return TRUE;
1299 static LRESULT PRINTDLG_WMInitDialogW(HWND hDlg, WPARAM wParam,
1300 PRINT_PTRW* PrintStructures)
1302 static const WCHAR PD32_COLLATE[] = { 'P', 'D', '3', '2', '_', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
1303 static const WCHAR PD32_NOCOLLATE[] = { 'P', 'D', '3', '2', '_', 'N', 'O', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
1304 static const WCHAR PD32_PORTRAIT[] = { 'P', 'D', '3', '2', '_', 'P', 'O', 'R', 'T', 'R', 'A', 'I', 'T', 0 };
1305 static const WCHAR PD32_LANDSCAPE[] = { 'P', 'D', '3', '2', '_', 'L', 'A', 'N', 'D', 'S', 'C', 'A', 'P', 'E', 0 };
1306 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1307 DEVNAMES *pdn;
1308 DEVMODEW *pdm;
1309 WCHAR *name = NULL;
1310 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1312 /* load Collate ICONs */
1313 /* We load these with LoadImage because they are not a standard
1314 size and we don't want them rescaled */
1315 PrintStructures->hCollateIcon =
1316 LoadImageW(COMDLG32_hInstance, PD32_COLLATE, IMAGE_ICON, 0, 0, 0);
1317 PrintStructures->hNoCollateIcon =
1318 LoadImageW(COMDLG32_hInstance, PD32_NOCOLLATE, IMAGE_ICON, 0, 0, 0);
1320 /* These can be done with LoadIcon */
1321 PrintStructures->hPortraitIcon =
1322 LoadIconW(COMDLG32_hInstance, PD32_PORTRAIT);
1323 PrintStructures->hLandscapeIcon =
1324 LoadIconW(COMDLG32_hInstance, PD32_LANDSCAPE);
1326 /* display the collate/no_collate icon */
1327 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1328 (LPARAM)PrintStructures->hNoCollateIcon);
1330 if(PrintStructures->hCollateIcon == 0 ||
1331 PrintStructures->hNoCollateIcon == 0 ||
1332 PrintStructures->hPortraitIcon == 0 ||
1333 PrintStructures->hLandscapeIcon == 0) {
1334 ERR("no icon in resourcefile\n");
1335 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1336 EndDialog(hDlg, FALSE);
1340 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1341 * must be registered and the Help button must be shown.
1343 if (lppd->Flags & PD_SHOWHELP) {
1344 if((PrintStructures->HelpMessageID =
1345 RegisterWindowMessageW(HELPMSGSTRINGW)) == 0) {
1346 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1347 return FALSE;
1349 } else
1350 PrintStructures->HelpMessageID = 0;
1352 if(!(lppd->Flags &PD_PRINTSETUP)) {
1353 PrintStructures->hwndUpDown =
1354 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1355 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1356 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1357 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1358 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1361 /* FIXME: I allow more freedom than either Win95 or WinNT,
1362 * which do not agree to what errors should be thrown or not
1363 * in case nToPage or nFromPage is out-of-range.
1365 if (lppd->nMaxPage < lppd->nMinPage)
1366 lppd->nMaxPage = lppd->nMinPage;
1367 if (lppd->nMinPage == lppd->nMaxPage)
1368 lppd->Flags |= PD_NOPAGENUMS;
1369 if (lppd->nToPage < lppd->nMinPage)
1370 lppd->nToPage = lppd->nMinPage;
1371 if (lppd->nToPage > lppd->nMaxPage)
1372 lppd->nToPage = lppd->nMaxPage;
1373 if (lppd->nFromPage < lppd->nMinPage)
1374 lppd->nFromPage = lppd->nMinPage;
1375 if (lppd->nFromPage > lppd->nMaxPage)
1376 lppd->nFromPage = lppd->nMaxPage;
1378 /* if we have the combo box, fill it */
1379 if (GetDlgItem(hDlg,comboID)) {
1380 /* Fill Combobox
1382 pdn = GlobalLock(lppd->hDevNames);
1383 pdm = GlobalLock(lppd->hDevMode);
1384 if(pdn)
1385 name = (WCHAR*)pdn + pdn->wDeviceOffset;
1386 else if(pdm)
1387 name = pdm->dmDeviceName;
1388 PRINTDLG_SetUpPrinterListComboW(hDlg, comboID, name);
1389 if(pdm) GlobalUnlock(lppd->hDevMode);
1390 if(pdn) GlobalUnlock(lppd->hDevNames);
1392 /* Now find selected printer and update rest of dlg */
1393 /* ansi is ok here */
1394 name = HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR));
1395 if (GetDlgItemTextW(hDlg, comboID, name, 255))
1396 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1397 HeapFree(GetProcessHeap(),0,name);
1398 } else {
1399 /* else use default printer */
1400 WCHAR name[200];
1401 DWORD dwBufLen = sizeof(name) / sizeof(WCHAR);
1402 BOOL ret = GetDefaultPrinterW(name, &dwBufLen);
1404 if (ret)
1405 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1406 else
1407 FIXME("No default printer found, expect problems!\n");
1409 return TRUE;
1412 /***********************************************************************
1413 * PRINTDLG_WMCommand [internal]
1415 LRESULT PRINTDLG_WMCommandA(HWND hDlg, WPARAM wParam,
1416 LPARAM lParam, PRINT_PTRA* PrintStructures)
1418 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
1419 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1420 LPDEVMODEA lpdm = PrintStructures->lpDevMode;
1422 switch (LOWORD(wParam)) {
1423 case IDOK:
1424 TRACE(" OK button was hit\n");
1425 if (!PRINTDLG_UpdatePrintDlgA(hDlg, PrintStructures)) {
1426 FIXME("Update printdlg was not successful!\n");
1427 return(FALSE);
1429 EndDialog(hDlg, TRUE);
1430 return(TRUE);
1432 case IDCANCEL:
1433 TRACE(" CANCEL button was hit\n");
1434 EndDialog(hDlg, FALSE);
1435 return(FALSE);
1437 case pshHelp:
1438 TRACE(" HELP button was hit\n");
1439 SendMessageA(lppd->hwndOwner, PrintStructures->HelpMessageID,
1440 (WPARAM) hDlg, (LPARAM) lppd);
1441 break;
1443 case chx2: /* collate pages checkbox */
1444 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1445 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1446 (LPARAM)PrintStructures->hCollateIcon);
1447 else
1448 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1449 (LPARAM)PrintStructures->hNoCollateIcon);
1450 break;
1451 case edt1: /* from page nr editbox */
1452 case edt2: /* to page nr editbox */
1453 if (HIWORD(wParam)==EN_CHANGE) {
1454 WORD nToPage;
1455 WORD nFromPage;
1456 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1457 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1458 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1459 CheckRadioButton(hDlg, rad1, rad3, rad3);
1461 break;
1463 case edt3:
1464 if(HIWORD(wParam) == EN_CHANGE) {
1465 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1466 if(copies <= 1)
1467 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1468 else
1469 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1471 break;
1473 #if 0
1474 case psh1: /* Print Setup */
1476 PRINTDLG16 pdlg;
1478 if (!PrintStructures->dlg.lpPrintDlg16) {
1479 FIXME("The 32bit print dialog does not have this button!?\n");
1480 break;
1483 memcpy(&pdlg,PrintStructures->dlg.lpPrintDlg16,sizeof(pdlg));
1484 pdlg.Flags |= PD_PRINTSETUP;
1485 pdlg.hwndOwner = HWND_16(hDlg);
1486 if (!PrintDlg16(&pdlg))
1487 break;
1489 break;
1490 #endif
1491 case psh2: /* Properties button */
1493 HANDLE hPrinter;
1494 char PrinterName[256];
1496 GetDlgItemTextA(hDlg, PrinterComboID, PrinterName, 255);
1497 if (!OpenPrinterA(PrinterName, &hPrinter, NULL)) {
1498 FIXME(" Call to OpenPrinter did not succeed!\n");
1499 break;
1501 DocumentPropertiesA(hDlg, hPrinter, PrinterName,
1502 PrintStructures->lpDevMode,
1503 PrintStructures->lpDevMode,
1504 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1505 ClosePrinter(hPrinter);
1506 break;
1509 case rad1: /* Paperorientation */
1510 if (lppd->Flags & PD_PRINTSETUP)
1512 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1513 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1514 (LPARAM)(PrintStructures->hPortraitIcon));
1516 break;
1518 case rad2: /* Paperorientation */
1519 if (lppd->Flags & PD_PRINTSETUP)
1521 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1522 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1523 (LPARAM)(PrintStructures->hLandscapeIcon));
1525 break;
1527 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1528 if (PrinterComboID != LOWORD(wParam)) {
1529 FIXME("No handling for print quality combo box yet.\n");
1530 break;
1532 /* FALLTHROUGH */
1533 case cmb4: /* Printer combobox */
1534 if (HIWORD(wParam)==CBN_SELCHANGE) {
1535 char PrinterName[256];
1536 GetDlgItemTextA(hDlg, LOWORD(wParam), PrinterName, 255);
1537 PRINTDLG_ChangePrinterA(hDlg, PrinterName, PrintStructures);
1539 break;
1541 case cmb2: /* Papersize */
1543 DWORD Sel = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1544 if(Sel != CB_ERR)
1545 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
1546 CB_GETITEMDATA,
1547 Sel, 0);
1549 break;
1551 case cmb3: /* Bin */
1553 DWORD Sel = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1554 if(Sel != CB_ERR)
1555 lpdm->dmDefaultSource = SendDlgItemMessageA(hDlg, cmb3,
1556 CB_GETITEMDATA, Sel,
1559 break;
1561 if(lppd->Flags & PD_PRINTSETUP) {
1562 switch (LOWORD(wParam)) {
1563 case rad1: /* orientation */
1564 case rad2:
1565 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1566 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1567 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1568 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1569 (WPARAM)IMAGE_ICON,
1570 (LPARAM)PrintStructures->hPortraitIcon);
1571 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1572 (WPARAM)IMAGE_ICON,
1573 (LPARAM)PrintStructures->hPortraitIcon);
1575 } else {
1576 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1577 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1578 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1579 (WPARAM)IMAGE_ICON,
1580 (LPARAM)PrintStructures->hLandscapeIcon);
1581 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1582 (WPARAM)IMAGE_ICON,
1583 (LPARAM)PrintStructures->hLandscapeIcon);
1586 break;
1589 return FALSE;
1592 static LRESULT PRINTDLG_WMCommandW(HWND hDlg, WPARAM wParam,
1593 LPARAM lParam, PRINT_PTRW* PrintStructures)
1595 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1596 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1597 LPDEVMODEW lpdm = PrintStructures->lpDevMode;
1599 switch (LOWORD(wParam)) {
1600 case IDOK:
1601 TRACE(" OK button was hit\n");
1602 if (!PRINTDLG_UpdatePrintDlgW(hDlg, PrintStructures)) {
1603 FIXME("Update printdlg was not successful!\n");
1604 return(FALSE);
1606 EndDialog(hDlg, TRUE);
1607 return(TRUE);
1609 case IDCANCEL:
1610 TRACE(" CANCEL button was hit\n");
1611 EndDialog(hDlg, FALSE);
1612 return(FALSE);
1614 case pshHelp:
1615 TRACE(" HELP button was hit\n");
1616 SendMessageW(lppd->hwndOwner, PrintStructures->HelpMessageID,
1617 (WPARAM) hDlg, (LPARAM) lppd);
1618 break;
1620 case chx2: /* collate pages checkbox */
1621 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1622 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1623 (LPARAM)PrintStructures->hCollateIcon);
1624 else
1625 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1626 (LPARAM)PrintStructures->hNoCollateIcon);
1627 break;
1628 case edt1: /* from page nr editbox */
1629 case edt2: /* to page nr editbox */
1630 if (HIWORD(wParam)==EN_CHANGE) {
1631 WORD nToPage;
1632 WORD nFromPage;
1633 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1634 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1635 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1636 CheckRadioButton(hDlg, rad1, rad3, rad3);
1638 break;
1640 case edt3:
1641 if(HIWORD(wParam) == EN_CHANGE) {
1642 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1643 if(copies <= 1)
1644 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1645 else
1646 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1648 break;
1650 case psh1: /* Print Setup */
1652 ERR("psh1 is called from 16bit code only, we should not get here.\n");
1654 break;
1655 case psh2: /* Properties button */
1657 HANDLE hPrinter;
1658 WCHAR PrinterName[256];
1660 if (!GetDlgItemTextW(hDlg, PrinterComboID, PrinterName, 255)) break;
1661 if (!OpenPrinterW(PrinterName, &hPrinter, NULL)) {
1662 FIXME(" Call to OpenPrinter did not succeed!\n");
1663 break;
1665 DocumentPropertiesW(hDlg, hPrinter, PrinterName,
1666 PrintStructures->lpDevMode,
1667 PrintStructures->lpDevMode,
1668 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1669 ClosePrinter(hPrinter);
1670 break;
1673 case rad1: /* Paperorientation */
1674 if (lppd->Flags & PD_PRINTSETUP)
1676 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1677 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1678 (LPARAM)(PrintStructures->hPortraitIcon));
1680 break;
1682 case rad2: /* Paperorientation */
1683 if (lppd->Flags & PD_PRINTSETUP)
1685 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1686 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1687 (LPARAM)(PrintStructures->hLandscapeIcon));
1689 break;
1691 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1692 if (PrinterComboID != LOWORD(wParam)) {
1693 FIXME("No handling for print quality combo box yet.\n");
1694 break;
1696 /* FALLTHROUGH */
1697 case cmb4: /* Printer combobox */
1698 if (HIWORD(wParam)==CBN_SELCHANGE) {
1699 WCHAR PrinterName[256];
1700 GetDlgItemTextW(hDlg, LOWORD(wParam), PrinterName, 255);
1701 PRINTDLG_ChangePrinterW(hDlg, PrinterName, PrintStructures);
1703 break;
1705 case cmb2: /* Papersize */
1707 DWORD Sel = SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1708 if(Sel != CB_ERR)
1709 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageW(hDlg, cmb2,
1710 CB_GETITEMDATA,
1711 Sel, 0);
1713 break;
1715 case cmb3: /* Bin */
1717 DWORD Sel = SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1718 if(Sel != CB_ERR)
1719 lpdm->dmDefaultSource = SendDlgItemMessageW(hDlg, cmb3,
1720 CB_GETITEMDATA, Sel,
1723 break;
1725 if(lppd->Flags & PD_PRINTSETUP) {
1726 switch (LOWORD(wParam)) {
1727 case rad1: /* orientation */
1728 case rad2:
1729 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1730 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1731 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1732 SendDlgItemMessageW(hDlg, stc10, STM_SETIMAGE,
1733 (WPARAM)IMAGE_ICON,
1734 (LPARAM)PrintStructures->hPortraitIcon);
1735 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE,
1736 (WPARAM)IMAGE_ICON,
1737 (LPARAM)PrintStructures->hPortraitIcon);
1739 } else {
1740 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1741 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1742 SendDlgItemMessageW(hDlg, stc10, STM_SETIMAGE,
1743 (WPARAM)IMAGE_ICON,
1744 (LPARAM)PrintStructures->hLandscapeIcon);
1745 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE,
1746 (WPARAM)IMAGE_ICON,
1747 (LPARAM)PrintStructures->hLandscapeIcon);
1750 break;
1753 return FALSE;
1756 /***********************************************************************
1757 * PrintDlgProcA [internal]
1759 static INT_PTR CALLBACK PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
1760 LPARAM lParam)
1762 PRINT_PTRA* PrintStructures;
1763 INT_PTR res = FALSE;
1765 if (uMsg!=WM_INITDIALOG) {
1766 PrintStructures = (PRINT_PTRA*)GetPropA(hDlg,"__WINE_PRINTDLGDATA");
1767 if (!PrintStructures)
1768 return FALSE;
1769 } else {
1770 PrintStructures = (PRINT_PTRA*) lParam;
1771 SetPropA(hDlg,"__WINE_PRINTDLGDATA",PrintStructures);
1772 if(!check_printer_setup(hDlg))
1774 EndDialog(hDlg,FALSE);
1775 return FALSE;
1777 res = PRINTDLG_WMInitDialog(hDlg, wParam, PrintStructures);
1779 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
1780 res = PrintStructures->lpPrintDlg->lpfnPrintHook(
1781 hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg
1783 return res;
1786 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
1787 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam,
1788 lParam);
1789 if(res) return res;
1792 switch (uMsg) {
1793 case WM_COMMAND:
1794 return PRINTDLG_WMCommandA(hDlg, wParam, lParam, PrintStructures);
1796 case WM_DESTROY:
1797 DestroyIcon(PrintStructures->hCollateIcon);
1798 DestroyIcon(PrintStructures->hNoCollateIcon);
1799 DestroyIcon(PrintStructures->hPortraitIcon);
1800 DestroyIcon(PrintStructures->hLandscapeIcon);
1801 if(PrintStructures->hwndUpDown)
1802 DestroyWindow(PrintStructures->hwndUpDown);
1803 return FALSE;
1805 return res;
1808 static INT_PTR CALLBACK PrintDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
1809 LPARAM lParam)
1811 static const WCHAR propW[] = {'_','_','W','I','N','E','_','P','R','I','N','T','D','L','G','D','A','T','A',0};
1812 PRINT_PTRW* PrintStructures;
1813 INT_PTR res = FALSE;
1815 if (uMsg!=WM_INITDIALOG) {
1816 PrintStructures = (PRINT_PTRW*) GetPropW(hDlg, propW);
1817 if (!PrintStructures)
1818 return FALSE;
1819 } else {
1820 PrintStructures = (PRINT_PTRW*) lParam;
1821 SetPropW(hDlg, propW, PrintStructures);
1822 if(!check_printer_setup(hDlg))
1824 EndDialog(hDlg,FALSE);
1825 return FALSE;
1827 res = PRINTDLG_WMInitDialogW(hDlg, wParam, PrintStructures);
1829 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
1830 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg);
1831 return res;
1834 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
1835 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam, lParam);
1836 if(res) return res;
1839 switch (uMsg) {
1840 case WM_COMMAND:
1841 return PRINTDLG_WMCommandW(hDlg, wParam, lParam, PrintStructures);
1843 case WM_DESTROY:
1844 DestroyIcon(PrintStructures->hCollateIcon);
1845 DestroyIcon(PrintStructures->hNoCollateIcon);
1846 DestroyIcon(PrintStructures->hPortraitIcon);
1847 DestroyIcon(PrintStructures->hLandscapeIcon);
1848 if(PrintStructures->hwndUpDown)
1849 DestroyWindow(PrintStructures->hwndUpDown);
1850 return FALSE;
1852 return res;
1855 /************************************************************
1857 * PRINTDLG_GetDlgTemplate
1860 static HGLOBAL PRINTDLG_GetDlgTemplateA(PRINTDLGA *lppd)
1862 HRSRC hResInfo;
1863 HGLOBAL hDlgTmpl;
1865 if (lppd->Flags & PD_PRINTSETUP) {
1866 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
1867 hDlgTmpl = lppd->hSetupTemplate;
1868 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
1869 hResInfo = FindResourceA(lppd->hInstance,
1870 lppd->lpSetupTemplateName, (LPSTR)RT_DIALOG);
1871 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1872 } else {
1873 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32_SETUP",
1874 (LPSTR)RT_DIALOG);
1875 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1877 } else {
1878 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
1879 hDlgTmpl = lppd->hPrintTemplate;
1880 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
1881 hResInfo = FindResourceA(lppd->hInstance,
1882 lppd->lpPrintTemplateName,
1883 (LPSTR)RT_DIALOG);
1884 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1885 } else {
1886 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32",
1887 (LPSTR)RT_DIALOG);
1888 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1891 return hDlgTmpl;
1894 static HGLOBAL PRINTDLG_GetDlgTemplateW(PRINTDLGW *lppd)
1896 HRSRC hResInfo;
1897 HGLOBAL hDlgTmpl;
1898 static const WCHAR xpsetup[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
1899 static const WCHAR xprint[] = { 'P','R','I','N','T','3','2',0};
1901 if (lppd->Flags & PD_PRINTSETUP) {
1902 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
1903 hDlgTmpl = lppd->hSetupTemplate;
1904 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
1905 hResInfo = FindResourceW(lppd->hInstance,
1906 lppd->lpSetupTemplateName, (LPWSTR)RT_DIALOG);
1907 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1908 } else {
1909 hResInfo = FindResourceW(COMDLG32_hInstance, xpsetup, (LPWSTR)RT_DIALOG);
1910 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1912 } else {
1913 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
1914 hDlgTmpl = lppd->hPrintTemplate;
1915 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
1916 hResInfo = FindResourceW(lppd->hInstance,
1917 lppd->lpPrintTemplateName,
1918 (LPWSTR)RT_DIALOG);
1919 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1920 } else {
1921 hResInfo = FindResourceW(COMDLG32_hInstance, xprint, (LPWSTR)RT_DIALOG);
1922 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1925 return hDlgTmpl;
1928 /***********************************************************************
1930 * PRINTDLG_CreateDC
1933 static BOOL PRINTDLG_CreateDCA(LPPRINTDLGA lppd)
1935 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
1936 DEVMODEA *pdm = GlobalLock(lppd->hDevMode);
1938 if(lppd->Flags & PD_RETURNDC) {
1939 lppd->hDC = CreateDCA((char*)pdn + pdn->wDriverOffset,
1940 (char*)pdn + pdn->wDeviceOffset,
1941 (char*)pdn + pdn->wOutputOffset,
1942 pdm );
1943 } else if(lppd->Flags & PD_RETURNIC) {
1944 lppd->hDC = CreateICA((char*)pdn + pdn->wDriverOffset,
1945 (char*)pdn + pdn->wDeviceOffset,
1946 (char*)pdn + pdn->wOutputOffset,
1947 pdm );
1949 GlobalUnlock(lppd->hDevNames);
1950 GlobalUnlock(lppd->hDevMode);
1951 return lppd->hDC ? TRUE : FALSE;
1954 static BOOL PRINTDLG_CreateDCW(LPPRINTDLGW lppd)
1956 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
1957 DEVMODEW *pdm = GlobalLock(lppd->hDevMode);
1959 if(lppd->Flags & PD_RETURNDC) {
1960 lppd->hDC = CreateDCW((WCHAR*)pdn + pdn->wDriverOffset,
1961 (WCHAR*)pdn + pdn->wDeviceOffset,
1962 (WCHAR*)pdn + pdn->wOutputOffset,
1963 pdm );
1964 } else if(lppd->Flags & PD_RETURNIC) {
1965 lppd->hDC = CreateICW((WCHAR*)pdn + pdn->wDriverOffset,
1966 (WCHAR*)pdn + pdn->wDeviceOffset,
1967 (WCHAR*)pdn + pdn->wOutputOffset,
1968 pdm );
1970 GlobalUnlock(lppd->hDevNames);
1971 GlobalUnlock(lppd->hDevMode);
1972 return lppd->hDC ? TRUE : FALSE;
1975 /***********************************************************************
1976 * PrintDlgA (COMDLG32.@)
1978 * Displays the the PRINT dialog box, which enables the user to specify
1979 * specific properties of the print job.
1981 * PARAMS
1982 * lppd [IO] ptr to PRINTDLG32 struct
1984 * RETURNS
1985 * nonzero if the user pressed the OK button
1986 * zero if the user cancelled the window or an error occurred
1988 * BUGS
1989 * PrintDlg:
1990 * * The Collate Icons do not display, even though they are in the code.
1991 * * The Properties Button(s) should call DocumentPropertiesA().
1994 BOOL WINAPI PrintDlgA(LPPRINTDLGA lppd)
1996 BOOL bRet = FALSE;
1997 LPVOID ptr;
1998 HINSTANCE hInst;
2000 if (!lppd)
2002 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION);
2003 return FALSE;
2006 hInst = (HINSTANCE)GetWindowLongPtrA( lppd->hwndOwner, GWLP_HINSTANCE );
2007 if(TRACE_ON(commdlg)) {
2008 char flagstr[1000] = "";
2009 const struct pd_flags *pflag = pd_flags;
2010 for( ; pflag->name; pflag++) {
2011 if(lppd->Flags & pflag->flag)
2012 strcat(flagstr, pflag->name);
2014 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2015 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2016 "flags %08x (%s)\n",
2017 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2018 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2019 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2022 if(lppd->lStructSize != sizeof(PRINTDLGA)) {
2023 WARN("structure size failure !!!\n");
2024 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2025 return FALSE;
2028 if(lppd->Flags & PD_RETURNDEFAULT) {
2029 PRINTER_INFO_2A *pbuf;
2030 DRIVER_INFO_3A *dbuf;
2031 HANDLE hprn;
2032 DWORD needed;
2034 if(lppd->hDevMode || lppd->hDevNames) {
2035 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2036 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2037 return FALSE;
2039 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2040 WARN("Can't find default printer\n");
2041 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2042 return FALSE;
2045 GetPrinterA(hprn, 2, NULL, 0, &needed);
2046 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
2047 GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2049 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
2050 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
2051 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2052 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",GetLastError(),pbuf->pPrinterName);
2053 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2054 return FALSE;
2056 ClosePrinter(hprn);
2058 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2059 dbuf->pDriverPath,
2060 pbuf->pPrinterName,
2061 pbuf->pPortName);
2062 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2063 pbuf->pDevMode->dmDriverExtra);
2064 ptr = GlobalLock(lppd->hDevMode);
2065 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2066 pbuf->pDevMode->dmDriverExtra);
2067 GlobalUnlock(lppd->hDevMode);
2068 HeapFree(GetProcessHeap(), 0, pbuf);
2069 HeapFree(GetProcessHeap(), 0, dbuf);
2070 bRet = TRUE;
2071 } else {
2072 HGLOBAL hDlgTmpl;
2073 PRINT_PTRA *PrintStructures;
2075 /* load Dialog resources,
2076 * depending on Flags indicates Print32 or Print32_setup dialog
2078 hDlgTmpl = PRINTDLG_GetDlgTemplateA(lppd);
2079 if (!hDlgTmpl) {
2080 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2081 return FALSE;
2083 ptr = LockResource( hDlgTmpl );
2084 if (!ptr) {
2085 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2086 return FALSE;
2089 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2090 sizeof(PRINT_PTRA));
2091 PrintStructures->lpPrintDlg = lppd;
2093 /* and create & process the dialog .
2094 * -1 is failure, 0 is broken hwnd, everything else is ok.
2096 bRet = (0<DialogBoxIndirectParamA(hInst, ptr, lppd->hwndOwner,
2097 PrintDlgProcA,
2098 (LPARAM)PrintStructures));
2100 if(bRet) {
2101 DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2102 PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
2103 DRIVER_INFO_3A *di = PrintStructures->lpDriverInfo;
2105 if (lppd->hDevMode == 0) {
2106 TRACE(" No hDevMode yet... Need to create my own\n");
2107 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2108 lpdm->dmSize + lpdm->dmDriverExtra);
2109 } else {
2110 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2111 lpdm->dmSize + lpdm->dmDriverExtra,
2112 GMEM_MOVEABLE);
2114 lpdmReturn = GlobalLock(lppd->hDevMode);
2115 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2117 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2118 di->pDriverPath,
2119 pi->pPrinterName,
2120 pi->pPortName
2122 GlobalUnlock(lppd->hDevMode);
2124 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2125 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2126 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2127 HeapFree(GetProcessHeap(), 0, PrintStructures);
2129 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2130 bRet = PRINTDLG_CreateDCA(lppd);
2132 TRACE("exit! (%d)\n", bRet);
2133 return bRet;
2136 /***********************************************************************
2137 * PrintDlgW (COMDLG32.@)
2139 * See PrintDlgA.
2141 BOOL WINAPI PrintDlgW(LPPRINTDLGW lppd)
2143 BOOL bRet = FALSE;
2144 LPVOID ptr;
2145 HINSTANCE hInst;
2147 if (!lppd)
2149 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION);
2150 return FALSE;
2153 hInst = (HINSTANCE)GetWindowLongPtrW( lppd->hwndOwner, GWLP_HINSTANCE );
2154 if(TRACE_ON(commdlg)) {
2155 char flagstr[1000] = "";
2156 const struct pd_flags *pflag = pd_flags;
2157 for( ; pflag->name; pflag++) {
2158 if(lppd->Flags & pflag->flag)
2159 strcat(flagstr, pflag->name);
2161 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2162 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2163 "flags %08x (%s)\n",
2164 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2165 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2166 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2169 if(lppd->lStructSize != sizeof(PRINTDLGW)) {
2170 WARN("structure size failure !!!\n");
2171 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2172 return FALSE;
2175 if(lppd->Flags & PD_RETURNDEFAULT) {
2176 PRINTER_INFO_2W *pbuf;
2177 DRIVER_INFO_3W *dbuf;
2178 HANDLE hprn;
2179 DWORD needed;
2181 if(lppd->hDevMode || lppd->hDevNames) {
2182 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2183 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2184 return FALSE;
2186 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2187 WARN("Can't find default printer\n");
2188 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2189 return FALSE;
2192 GetPrinterW(hprn, 2, NULL, 0, &needed);
2193 pbuf = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*needed);
2194 GetPrinterW(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2196 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
2197 dbuf = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
2198 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2199 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",GetLastError(),debugstr_w(pbuf->pPrinterName));
2200 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2201 return FALSE;
2203 ClosePrinter(hprn);
2205 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2206 dbuf->pDriverPath,
2207 pbuf->pPrinterName,
2208 pbuf->pPortName);
2209 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2210 pbuf->pDevMode->dmDriverExtra);
2211 ptr = GlobalLock(lppd->hDevMode);
2212 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2213 pbuf->pDevMode->dmDriverExtra);
2214 GlobalUnlock(lppd->hDevMode);
2215 HeapFree(GetProcessHeap(), 0, pbuf);
2216 HeapFree(GetProcessHeap(), 0, dbuf);
2217 bRet = TRUE;
2218 } else {
2219 HGLOBAL hDlgTmpl;
2220 PRINT_PTRW *PrintStructures;
2222 /* load Dialog resources,
2223 * depending on Flags indicates Print32 or Print32_setup dialog
2225 hDlgTmpl = PRINTDLG_GetDlgTemplateW(lppd);
2226 if (!hDlgTmpl) {
2227 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2228 return FALSE;
2230 ptr = LockResource( hDlgTmpl );
2231 if (!ptr) {
2232 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2233 return FALSE;
2236 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2237 sizeof(PRINT_PTRW));
2238 PrintStructures->lpPrintDlg = lppd;
2240 /* and create & process the dialog .
2241 * -1 is failure, 0 is broken hwnd, everything else is ok.
2243 bRet = (0<DialogBoxIndirectParamW(hInst, ptr, lppd->hwndOwner,
2244 PrintDlgProcW,
2245 (LPARAM)PrintStructures));
2247 if(bRet) {
2248 DEVMODEW *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2249 PRINTER_INFO_2W *pi = PrintStructures->lpPrinterInfo;
2250 DRIVER_INFO_3W *di = PrintStructures->lpDriverInfo;
2252 if (lppd->hDevMode == 0) {
2253 TRACE(" No hDevMode yet... Need to create my own\n");
2254 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2255 lpdm->dmSize + lpdm->dmDriverExtra);
2256 } else {
2257 WORD locks;
2258 if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
2259 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2260 while(locks--) {
2261 GlobalUnlock(lppd->hDevMode);
2262 TRACE("Now got %d locks\n", locks);
2265 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2266 lpdm->dmSize + lpdm->dmDriverExtra,
2267 GMEM_MOVEABLE);
2269 lpdmReturn = GlobalLock(lppd->hDevMode);
2270 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2272 if (lppd->hDevNames != 0) {
2273 WORD locks;
2274 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
2275 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2276 while(locks--)
2277 GlobalUnlock(lppd->hDevNames);
2280 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2281 di->pDriverPath,
2282 pi->pPrinterName,
2283 pi->pPortName
2285 GlobalUnlock(lppd->hDevMode);
2287 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2288 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2289 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2290 HeapFree(GetProcessHeap(), 0, PrintStructures);
2292 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2293 bRet = PRINTDLG_CreateDCW(lppd);
2295 TRACE("exit! (%d)\n", bRet);
2296 return bRet;
2299 /***********************************************************************
2301 * PageSetupDlg
2302 * rad1 - portrait
2303 * rad2 - landscape
2304 * cmb1 - printer select (not in standart dialog template)
2305 * cmb2 - paper size
2306 * cmb3 - source (tray?)
2307 * edt4 - border left
2308 * edt5 - border top
2309 * edt6 - border right
2310 * edt7 - border bottom
2311 * psh3 - "Printer..."
2314 typedef struct {
2315 LPPAGESETUPDLGA dlga; /* Handler to user defined struct */
2316 PRINTDLGA pdlg;
2317 HWND hDlg; /* Page Setup dialog handler */
2318 PAGESETUPDLGA curdlg; /* Struct means cerrent dialog state */
2319 RECT rtDrawRect; /* Drawing rect for page */
2320 } PageSetupDataA;
2322 typedef struct {
2323 LPPAGESETUPDLGW dlga;
2324 PRINTDLGW pdlg;
2325 } PageSetupDataW;
2328 static HGLOBAL PRINTDLG_GetPGSTemplateA(PAGESETUPDLGA *lppd)
2330 HRSRC hResInfo;
2331 HGLOBAL hDlgTmpl;
2333 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2334 hDlgTmpl = lppd->hPageSetupTemplate;
2335 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2336 hResInfo = FindResourceA(lppd->hInstance,
2337 lppd->lpPageSetupTemplateName, (LPSTR)RT_DIALOG);
2338 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2339 } else {
2340 hResInfo = FindResourceA(COMDLG32_hInstance,(LPCSTR)PAGESETUPDLGORD,(LPSTR)RT_DIALOG);
2341 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2343 return hDlgTmpl;
2346 static HGLOBAL PRINTDLG_GetPGSTemplateW(PAGESETUPDLGW *lppd)
2348 HRSRC hResInfo;
2349 HGLOBAL hDlgTmpl;
2351 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2352 hDlgTmpl = lppd->hPageSetupTemplate;
2353 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2354 hResInfo = FindResourceW(lppd->hInstance,
2355 lppd->lpPageSetupTemplateName, (LPWSTR)RT_DIALOG);
2356 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2357 } else {
2358 hResInfo = FindResourceW(COMDLG32_hInstance,(LPCWSTR)PAGESETUPDLGORD,(LPWSTR)RT_DIALOG);
2359 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2361 return hDlgTmpl;
2364 static DWORD
2365 _c_10mm2size(PAGESETUPDLGA *dlga,DWORD size) {
2366 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2367 return 10*size*100/254;
2368 /* If we don't have a flag, we can choose one. Use millimeters
2369 * to avoid confusing me
2371 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2372 return 10*size;
2376 static DWORD
2377 _c_inch2size(PAGESETUPDLGA *dlga,DWORD size) {
2378 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2379 return size;
2380 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
2381 return (size*254)/100;
2382 /* if we don't have a flag, we can choose one. Use millimeters
2383 * to avoid confusing me
2385 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2386 return (size*254)/100;
2389 static void
2390 _c_size2strA(PageSetupDataA *pda,DWORD size,LPSTR strout) {
2391 strcpy(strout,"<undef>");
2392 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2393 sprintf(strout,"%d",(size)/100);
2394 return;
2396 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2397 sprintf(strout,"%din",(size)/1000);
2398 return;
2400 pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2401 sprintf(strout,"%d",(size)/100);
2402 return;
2404 static void
2405 _c_size2strW(PageSetupDataW *pda,DWORD size,LPWSTR strout) {
2406 static const WCHAR UNDEF[] = { '<', 'u', 'n', 'd', 'e', 'f', '>', 0 };
2407 static const WCHAR mm_fmt[] = { '%', '.', '2', 'f', 'm', 'm', 0 };
2408 static const WCHAR in_fmt[] = { '%', '.', '2', 'f', 'i', 'n', 0 };
2409 lstrcpyW(strout, UNDEF);
2410 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2411 wsprintfW(strout,mm_fmt,(size*1.0)/100.0);
2412 return;
2414 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2415 wsprintfW(strout,in_fmt,(size*1.0)/1000.0);
2416 return;
2418 pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2419 wsprintfW(strout,mm_fmt,(size*1.0)/100.0);
2420 return;
2423 static DWORD
2424 _c_str2sizeA(PAGESETUPDLGA *dlga,LPCSTR strin) {
2425 float val;
2426 char rest[200];
2428 rest[0]='\0';
2429 if (!sscanf(strin,"%f%s",&val,rest))
2430 return 0;
2432 if (!strcmp(rest,"in") || !strcmp(rest,"inch")) {
2433 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2434 return 1000*val;
2435 else
2436 return val*25.4*100;
2438 if (!strcmp(rest,"cm")) { rest[0]='m'; val = val*10.0; }
2439 if (!strcmp(rest,"m")) { strcpy(rest,"mm"); val = val*1000.0; }
2441 if (!strcmp(rest,"mm")) {
2442 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
2443 return 100*val;
2444 else
2445 return 1000.0*val/25.4;
2447 if (rest[0]=='\0') {
2448 /* use application supplied default */
2449 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2450 /* 100*mm */
2451 return 100.0*val;
2453 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2454 /* 1000*inch */
2455 return 1000.0*val;
2458 ERR("Did not find a conversion for type '%s'!\n",rest);
2459 return 0;
2463 static DWORD
2464 _c_str2sizeW(PAGESETUPDLGW *dlga, LPCWSTR strin) {
2465 char buf[200];
2467 /* this W -> A transition is OK */
2468 /* we need a unicode version of sscanf to avoid it */
2469 WideCharToMultiByte(CP_ACP, 0, strin, -1, buf, sizeof(buf), NULL, NULL);
2470 return _c_str2sizeA((PAGESETUPDLGA *)dlga, buf);
2474 /****************************************************************************
2475 * PRINTDLG_PS_UpdateDlgStructA
2477 * Updates pda->dlga structure
2478 * Function calls when user presses OK button
2480 * PARAMS
2481 * hDlg [in] main window dialog HANDLE
2482 * pda [in/out] ptr to PageSetupDataA structere
2484 * RETURNS
2485 * TRUE
2487 static BOOL
2488 PRINTDLG_PS_UpdateDlgStructA(HWND hDlg, PageSetupDataA *pda) {
2489 DEVNAMES *dn;
2490 DEVMODEA *dm;
2491 DWORD paperword;
2493 memcpy(pda->dlga, &pda->curdlg, sizeof(pda->curdlg));
2494 pda->dlga->hDevMode = pda->pdlg.hDevMode;
2495 pda->dlga->hDevNames = pda->pdlg.hDevNames;
2497 dn = GlobalLock(pda->pdlg.hDevNames);
2498 dm = GlobalLock(pda->pdlg.hDevMode);
2500 /* Save paper orientation into device context */
2501 if(pda->curdlg.ptPaperSize.x > pda->curdlg.ptPaperSize.y)
2502 dm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
2503 else
2504 dm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
2506 /* Save paper size into the device context */
2507 paperword = SendDlgItemMessageA(hDlg,cmb2,CB_GETITEMDATA,
2508 SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0), 0);
2509 if (paperword != CB_ERR)
2510 dm->u1.s1.dmPaperSize = paperword;
2511 else
2512 FIXME("could not get dialog text for papersize cmbbox?\n");
2514 /* Save paper source into the device context */
2515 paperword = SendDlgItemMessageA(hDlg,cmb1,CB_GETITEMDATA,
2516 SendDlgItemMessageA(hDlg, cmb1, CB_GETCURSEL, 0, 0), 0);
2517 if (paperword != CB_ERR)
2518 dm->dmDefaultSource = paperword;
2519 else
2520 FIXME("could not get dialog text for papersize cmbbox?\n");
2522 GlobalUnlock(pda->pdlg.hDevNames);
2523 GlobalUnlock(pda->pdlg.hDevMode);
2525 return TRUE;
2528 static BOOL
2529 PRINTDLG_PS_UpdateDlgStructW(HWND hDlg, PageSetupDataW *pda) {
2530 DEVNAMES *dn;
2531 DEVMODEW *dm;
2532 LPWSTR devname,portname;
2533 WCHAR papername[64];
2534 WCHAR buf[200];
2536 dn = GlobalLock(pda->pdlg.hDevNames);
2537 dm = GlobalLock(pda->pdlg.hDevMode);
2538 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
2539 portname = ((WCHAR*)dn)+dn->wOutputOffset;
2541 /* Save paper size into device context */
2542 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
2543 /* Save paper source into device context */
2544 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
2546 if (GetDlgItemTextW(hDlg,cmb2,papername,sizeof(papername))>0) {
2547 PRINTDLG_PaperSizeW(&(pda->pdlg),papername,&(pda->dlga->ptPaperSize));
2548 pda->dlga->ptPaperSize.x = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga,pda->dlga->ptPaperSize.x);
2549 pda->dlga->ptPaperSize.y = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga,pda->dlga->ptPaperSize.y);
2550 } else
2551 FIXME("could not get dialog text for papersize cmbbox?\n");
2552 #define GETVAL(id,val) if (GetDlgItemTextW(hDlg,id,buf,sizeof(buf)/sizeof(buf[0]))>0) { val = _c_str2sizeW(pda->dlga,buf); } else { FIXME("could not get dlgitemtextw for %x\n",id); }
2553 GETVAL(edt4,pda->dlga->rtMargin.left);
2554 GETVAL(edt5,pda->dlga->rtMargin.top);
2555 GETVAL(edt6,pda->dlga->rtMargin.right);
2556 GETVAL(edt7,pda->dlga->rtMargin.bottom);
2557 #undef GETVAL
2559 /* If we are in landscape, swap x and y of page size */
2560 if (IsDlgButtonChecked(hDlg, rad2)) {
2561 DWORD tmp;
2562 tmp = pda->dlga->ptPaperSize.x;
2563 pda->dlga->ptPaperSize.x = pda->dlga->ptPaperSize.y;
2564 pda->dlga->ptPaperSize.y = tmp;
2566 GlobalUnlock(pda->pdlg.hDevNames);
2567 GlobalUnlock(pda->pdlg.hDevMode);
2568 return TRUE;
2571 /**********************************************************************************************
2572 * PRINTDLG_PS_ChangeActivePrinerA
2574 * Redefines hDevMode and hDevNames HANDLES and initialises it.
2576 * PARAMS
2577 * name [in] Name of a printer for activation
2578 * pda [in/out] ptr to PageSetupDataA structure
2580 * RETURN
2581 * TRUE if success
2582 * FALSE if fail
2584 static BOOL
2585 PRINTDLG_PS_ChangeActivePrinterA(LPSTR name, PageSetupDataA *pda){
2586 HANDLE hprn;
2587 DWORD needed;
2588 LPPRINTER_INFO_2A lpPrinterInfo;
2589 LPDRIVER_INFO_3A lpDriverInfo;
2590 DEVMODEA *pDevMode, *dm;
2592 if(!OpenPrinterA(name, &hprn, NULL)){
2593 ERR("Can't open printer %s\n", name);
2594 return FALSE;
2596 GetPrinterA(hprn, 2, NULL, 0, &needed);
2597 lpPrinterInfo = HeapAlloc(GetProcessHeap(), 0, needed);
2598 GetPrinterA(hprn, 2, (LPBYTE)lpPrinterInfo, needed, &needed);
2599 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
2600 lpDriverInfo = HeapAlloc(GetProcessHeap(), 0, needed);
2601 if(!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)lpDriverInfo, needed, &needed)) {
2602 ERR("GetPrinterDriverA failed for %s, fix your config!\n", lpPrinterInfo->pPrinterName);
2603 return FALSE;
2605 ClosePrinter(hprn);
2607 needed = DocumentPropertiesA(0, 0, name, NULL, NULL, 0);
2608 if(needed == -1) {
2609 ERR("DocumentProperties fails on %s\n", debugstr_a(name));
2610 return FALSE;
2612 pDevMode = HeapAlloc(GetProcessHeap(), 0, needed);
2613 DocumentPropertiesA(0, 0, name, pDevMode, NULL, DM_OUT_BUFFER);
2615 pda->pdlg.hDevMode = GlobalReAlloc(pda->pdlg.hDevMode,
2616 pDevMode->dmSize + pDevMode->dmDriverExtra,
2617 GMEM_MOVEABLE);
2618 dm = GlobalLock(pda->pdlg.hDevMode);
2619 memcpy(dm, pDevMode, pDevMode->dmSize + pDevMode->dmDriverExtra);
2621 PRINTDLG_CreateDevNames(&(pda->pdlg.hDevNames),
2622 lpDriverInfo->pDriverPath,
2623 lpPrinterInfo->pPrinterName,
2624 lpPrinterInfo->pPortName);
2626 GlobalUnlock(pda->pdlg.hDevMode);
2627 HeapFree(GetProcessHeap(), 0, pDevMode);
2628 HeapFree(GetProcessHeap(), 0, lpPrinterInfo);
2629 HeapFree(GetProcessHeap(), 0, lpDriverInfo);
2630 return TRUE;
2633 /****************************************************************************************
2634 * PRINTDLG_PS_ChangePrinterA
2636 * Fills Printers, Paper and Source combo
2638 * RETURNS
2639 * TRUE
2641 static BOOL
2642 PRINTDLG_PS_ChangePrinterA(HWND hDlg, PageSetupDataA *pda) {
2643 DEVNAMES *dn;
2644 DEVMODEA *dm;
2645 LPSTR devname,portname;
2647 dn = GlobalLock(pda->pdlg.hDevNames);
2648 dm = GlobalLock(pda->pdlg.hDevMode);
2649 devname = ((char*)dn)+dn->wDeviceOffset;
2650 portname = ((char*)dn)+dn->wOutputOffset;
2651 PRINTDLG_SetUpPrinterListComboA(hDlg, cmb1, devname);
2652 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb2,devname,portname,dm);
2653 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb3,devname,portname,dm);
2654 GlobalUnlock(pda->pdlg.hDevNames);
2655 GlobalUnlock(pda->pdlg.hDevMode);
2656 return TRUE;
2659 static BOOL
2660 PRINTDLG_PS_ChangePrinterW(HWND hDlg, PageSetupDataW *pda) {
2661 DEVNAMES *dn;
2662 DEVMODEW *dm;
2663 LPWSTR devname,portname;
2665 dn = GlobalLock(pda->pdlg.hDevNames);
2666 dm = GlobalLock(pda->pdlg.hDevMode);
2667 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
2668 portname = ((WCHAR*)dn)+dn->wOutputOffset;
2669 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
2670 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
2671 GlobalUnlock(pda->pdlg.hDevNames);
2672 GlobalUnlock(pda->pdlg.hDevMode);
2673 return TRUE;
2676 /******************************************************************************************
2677 * PRINTDLG_PS_ChangePaperPrev
2679 * Changes paper preview size / position
2681 * PARAMS:
2682 * pda [i] Pointer for current PageSetupDataA structure
2684 * RETURNS:
2685 * always - TRUE
2687 static BOOL
2688 PRINTDLG_PS_ChangePaperPrev(PageSetupDataA *pda)
2690 LONG width, height, x, y;
2691 RECT rtTmp;
2693 if(pda->curdlg.ptPaperSize.x > pda->curdlg.ptPaperSize.y) {
2694 width = pda->rtDrawRect.right - pda->rtDrawRect.left;
2695 height = pda->curdlg.ptPaperSize.y * width / pda->curdlg.ptPaperSize.x;
2696 } else {
2697 height = pda->rtDrawRect.bottom - pda->rtDrawRect.top;
2698 width = pda->curdlg.ptPaperSize.x * height / pda->curdlg.ptPaperSize.y;
2700 x = (pda->rtDrawRect.right + pda->rtDrawRect.left - width) / 2;
2701 y = (pda->rtDrawRect.bottom + pda->rtDrawRect.top - height) / 2;
2702 TRACE("rtDrawRect(%d, %d, %d, %d) x=%d, y=%d, w=%d, h=%d\n",
2703 pda->rtDrawRect.left, pda->rtDrawRect.top, pda->rtDrawRect.right, pda->rtDrawRect.bottom,
2704 x, y, width, height);
2706 #define SHADOW 4
2707 MoveWindow(GetDlgItem(pda->hDlg, rct2), x+width, y+SHADOW, SHADOW, height, FALSE);
2708 MoveWindow(GetDlgItem(pda->hDlg, rct3), x+SHADOW, y+height, width, SHADOW, FALSE);
2709 MoveWindow(GetDlgItem(pda->hDlg, rct1), x, y, width, height, FALSE);
2710 memcpy(&rtTmp, &pda->rtDrawRect, sizeof(RECT));
2711 rtTmp.right += SHADOW;
2712 rtTmp.bottom += SHADOW;
2713 #undef SHADOW
2715 InvalidateRect(pda->hDlg, &rtTmp, TRUE);
2716 return TRUE;
2719 #define GETVAL(idc,val) \
2720 if(msg == EN_CHANGE){ \
2721 if (GetDlgItemTextA(hDlg,idc,buf,sizeof(buf)) > 0)\
2722 val = _c_str2sizeA(pda->dlga,buf); \
2723 else\
2724 FIXME("could not get dlgitemtexta for %x\n",id); \
2727 /********************************************************************************
2728 * PRINTDLG_PS_WMCommandA
2729 * process WM_COMMAND message for PageSetupDlgA
2731 * PARAMS
2732 * hDlg [in] Main dialog HANDLE
2733 * wParam [in] WM_COMMAND wParam
2734 * lParam [in] WM_COMMAND lParam
2735 * pda [in/out] ptr to PageSetupDataA
2738 static BOOL
2739 PRINTDLG_PS_WMCommandA(
2740 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataA *pda
2742 WORD msg = HIWORD(wParam);
2743 WORD id = LOWORD(wParam);
2744 char buf[200];
2746 TRACE("loword (lparam) %d, wparam 0x%x, lparam %08lx\n",
2747 LOWORD(lParam),wParam,lParam);
2748 switch (id) {
2749 case IDOK:
2750 if (!PRINTDLG_PS_UpdateDlgStructA(hDlg, pda))
2751 return(FALSE);
2752 EndDialog(hDlg, TRUE);
2753 return TRUE ;
2755 case IDCANCEL:
2756 EndDialog(hDlg, FALSE);
2757 return FALSE ;
2759 case psh3: {
2760 pda->pdlg.Flags = 0;
2761 pda->pdlg.hwndOwner = hDlg;
2762 if (PrintDlgA(&(pda->pdlg)))
2763 PRINTDLG_PS_ChangePrinterA(hDlg,pda);
2765 return TRUE;
2766 case rad1:
2767 if (pda->curdlg.ptPaperSize.x > pda->curdlg.ptPaperSize.y){
2768 DWORD tmp = pda->curdlg.ptPaperSize.x;
2769 pda->curdlg.ptPaperSize.x = pda->curdlg.ptPaperSize.y;
2770 pda->curdlg.ptPaperSize.y = tmp;
2772 PRINTDLG_PS_ChangePaperPrev(pda);
2773 break;
2774 case rad2:
2775 if (pda->curdlg.ptPaperSize.y > pda->curdlg.ptPaperSize.x){
2776 DWORD tmp = pda->curdlg.ptPaperSize.x;
2777 pda->curdlg.ptPaperSize.x = pda->curdlg.ptPaperSize.y;
2778 pda->curdlg.ptPaperSize.y = tmp;
2780 PRINTDLG_PS_ChangePaperPrev(pda);
2781 break;
2782 case cmb1: /* Printer combo */
2783 if(msg == CBN_SELCHANGE){
2784 char crPrinterName[256];
2785 GetDlgItemTextA(hDlg, id, crPrinterName, 255);
2786 PRINTDLG_PS_ChangeActivePrinterA(crPrinterName, pda);
2787 PRINTDLG_PS_ChangePrinterA(hDlg, pda);
2789 break;
2790 case cmb2: /* Paper combo */
2791 if(msg == CBN_SELCHANGE){
2792 DWORD paperword = SendDlgItemMessageA(hDlg,cmb2,CB_GETITEMDATA,
2793 SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0), 0);
2794 if (paperword != CB_ERR) {
2795 PRINTDLG_PaperSizeA(&(pda->pdlg), paperword,&(pda->curdlg.ptPaperSize));
2796 pda->curdlg.ptPaperSize.x = _c_10mm2size(pda->dlga,pda->curdlg.ptPaperSize.x);
2797 pda->curdlg.ptPaperSize.y = _c_10mm2size(pda->dlga,pda->curdlg.ptPaperSize.y);
2799 if (IsDlgButtonChecked(hDlg, rad2)) {
2800 DWORD tmp = pda->curdlg.ptPaperSize.x;
2801 pda->curdlg.ptPaperSize.x = pda->curdlg.ptPaperSize.y;
2802 pda->curdlg.ptPaperSize.y = tmp;
2804 PRINTDLG_PS_ChangePaperPrev(pda);
2805 } else
2806 FIXME("could not get dialog text for papersize cmbbox?\n");
2808 break;
2809 case cmb3:
2810 if(msg == CBN_SELCHANGE){
2811 DEVMODEA *dm = GlobalLock(pda->pdlg.hDevMode);
2812 dm->dmDefaultSource = SendDlgItemMessageA(hDlg, cmb3,CB_GETITEMDATA,
2813 SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0), 0);
2814 GlobalUnlock(pda->pdlg.hDevMode);
2816 break;
2817 case psh2: /* Printer Properties button */
2819 HANDLE hPrinter;
2820 char PrinterName[256];
2821 DEVMODEA *dm;
2822 LRESULT count;
2823 int i;
2825 GetDlgItemTextA(hDlg, cmb1, PrinterName, 255);
2826 if (!OpenPrinterA(PrinterName, &hPrinter, NULL)) {
2827 FIXME("Call to OpenPrinter did not succeed!\n");
2828 break;
2830 dm = GlobalLock(pda->pdlg.hDevMode);
2831 DocumentPropertiesA(hDlg, hPrinter, PrinterName, dm, dm,
2832 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
2833 ClosePrinter(hPrinter);
2834 /* Changing paper */
2835 PRINTDLG_PaperSizeA(&(pda->pdlg), dm->u1.s1.dmPaperSize, &(pda->curdlg.ptPaperSize));
2836 pda->curdlg.ptPaperSize.x = _c_10mm2size(pda->dlga, pda->curdlg.ptPaperSize.x);
2837 pda->curdlg.ptPaperSize.y = _c_10mm2size(pda->dlga, pda->curdlg.ptPaperSize.y);
2838 if (dm->u1.s1.dmOrientation == DMORIENT_LANDSCAPE){
2839 DWORD tmp = pda->curdlg.ptPaperSize.x;
2840 pda->curdlg.ptPaperSize.x = pda->curdlg.ptPaperSize.y;
2841 pda->curdlg.ptPaperSize.y = tmp;
2842 CheckRadioButton(hDlg, rad1, rad2, rad2);
2844 else
2845 CheckRadioButton(hDlg, rad1, rad2, rad1);
2846 /* Changing paper preview */
2847 PRINTDLG_PS_ChangePaperPrev(pda);
2848 /* Selecting paper in combo */
2849 count = SendDlgItemMessageA(hDlg, cmb2, CB_GETCOUNT, 0, 0);
2850 if(count != CB_ERR){
2851 for(i=0; i<count; ++i){
2852 if(SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, i, 0) == dm->u1.s1.dmPaperSize) {
2853 SendDlgItemMessageA(hDlg, cmb2, CB_SETCURSEL, i, 0);
2854 break;
2859 GlobalUnlock(pda->pdlg.hDevMode);
2860 break;
2862 case edt4:
2863 GETVAL(id, pda->curdlg.rtMargin.left);
2864 break;
2865 case edt5:
2866 GETVAL(id, pda->curdlg.rtMargin.right);
2867 break;
2868 case edt6:
2869 GETVAL(id, pda->curdlg.rtMargin.top);
2870 break;
2871 case edt7:
2872 GETVAL(id, pda->curdlg.rtMargin.bottom);
2873 break;
2875 InvalidateRect(GetDlgItem(hDlg, rct1), NULL, TRUE);
2876 return FALSE;
2878 #undef GETVAL
2880 static BOOL
2881 PRINTDLG_PS_WMCommandW(
2882 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataW *pda
2884 TRACE("loword (lparam) %d, wparam 0x%x, lparam %08lx\n",
2885 LOWORD(lParam),wParam,lParam);
2886 switch (LOWORD(wParam)) {
2887 case IDOK:
2888 if (!PRINTDLG_PS_UpdateDlgStructW(hDlg, pda))
2889 return(FALSE);
2890 EndDialog(hDlg, TRUE);
2891 return TRUE ;
2893 case IDCANCEL:
2894 EndDialog(hDlg, FALSE);
2895 return FALSE ;
2897 case psh3: {
2898 pda->pdlg.Flags = 0;
2899 pda->pdlg.hwndOwner = hDlg;
2900 if (PrintDlgW(&(pda->pdlg)))
2901 PRINTDLG_PS_ChangePrinterW(hDlg,pda);
2902 return TRUE;
2905 return FALSE;
2909 /***********************************************************************
2910 * DefaultPagePaintHook
2911 * Default hook paint procedure that receives WM_PSD_* messages from the dialog box
2912 * whenever the sample page is redrawn.
2915 static UINT_PTR
2916 PRINTDLG_DefaultPagePaintHook(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam, PageSetupDataA *pda)
2918 LPRECT lprc = (LPRECT) lParam;
2919 HDC hdc = (HDC) wParam;
2920 HPEN hpen, holdpen;
2921 LOGFONTW lf;
2922 HFONT hfont, holdfont;
2923 INT oldbkmode;
2924 TRACE("uMsg: WM_USER+%d\n",uMsg-WM_USER);
2925 /* Call user paint hook if enable */
2926 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK)
2927 if (pda->dlga->lpfnPagePaintHook(hwndDlg, uMsg, wParam, lParam))
2928 return TRUE;
2930 switch (uMsg) {
2931 /* LPPAGESETUPDLG in lParam */
2932 case WM_PSD_PAGESETUPDLG:
2933 /* Inform about the sample page rectangle */
2934 case WM_PSD_FULLPAGERECT:
2935 /* Inform about the margin rectangle */
2936 case WM_PSD_MINMARGINRECT:
2937 return FALSE;
2939 /* Draw dashed rectangle showing margins */
2940 case WM_PSD_MARGINRECT:
2941 hpen = CreatePen(PS_DASH, 1, GetSysColor(COLOR_3DSHADOW));
2942 holdpen = SelectObject(hdc, hpen);
2943 Rectangle(hdc, lprc->left, lprc->top, lprc->right, lprc->bottom);
2944 DeleteObject(SelectObject(hdc, holdpen));
2945 return TRUE;
2946 /* Draw the fake document */
2947 case WM_PSD_GREEKTEXTRECT:
2948 /* select a nice scalable font, because we want the text really small */
2949 SystemParametersInfoW(SPI_GETICONTITLELOGFONT, sizeof(lf), &lf, 0);
2950 lf.lfHeight = 6; /* value chosen based on visual effect */
2951 hfont = CreateFontIndirectW(&lf);
2952 holdfont = SelectObject(hdc, hfont);
2954 /* if text not loaded, then do so now */
2955 if (wszFakeDocumentText[0] == '\0')
2956 LoadStringW(COMDLG32_hInstance,
2957 IDS_FAKEDOCTEXT,
2958 wszFakeDocumentText,
2959 sizeof(wszFakeDocumentText)/sizeof(wszFakeDocumentText[0]));
2961 oldbkmode = SetBkMode(hdc, TRANSPARENT);
2962 DrawTextW(hdc, wszFakeDocumentText, -1, lprc, DT_TOP|DT_LEFT|DT_NOPREFIX|DT_WORDBREAK);
2963 SetBkMode(hdc, oldbkmode);
2965 DeleteObject(SelectObject(hdc, holdfont));
2966 return TRUE;
2968 /* Envelope stamp */
2969 case WM_PSD_ENVSTAMPRECT:
2970 /* Return address */
2971 case WM_PSD_YAFULLPAGERECT:
2972 FIXME("envelope/stamp is not implemented\n");
2973 return FALSE;
2974 default:
2975 FIXME("Unknown message %x\n",uMsg);
2976 return FALSE;
2978 return TRUE;
2981 /***********************************************************************
2982 * PagePaintProc
2983 * The main paint procedure for the PageSetupDlg function.
2984 * The Page Setup dialog box includes an image of a sample page that shows how
2985 * the user's selections affect the appearance of the printed output.
2986 * The image consists of a rectangle that represents the selected paper
2987 * or envelope type, with a dotted-line rectangle representing
2988 * the current margins, and partial (Greek text) characters
2989 * to show how text looks on the printed page.
2991 * The following messages in the order sends to user hook procedure:
2992 * WM_PSD_PAGESETUPDLG Draw the contents of the sample page
2993 * WM_PSD_FULLPAGERECT Inform about the bounding rectangle
2994 * WM_PSD_MINMARGINRECT Inform about the margin rectangle (min margin?)
2995 * WM_PSD_MARGINRECT Draw the margin rectangle
2996 * WM_PSD_GREEKTEXTRECT Draw the Greek text inside the margin rectangle
2997 * If any of first three messages returns TRUE, painting done.
2999 * PARAMS:
3000 * hWnd [in] Handle to the Page Setup dialog box
3001 * uMsg [in] Received message
3003 * TODO:
3004 * WM_PSD_ENVSTAMPRECT Draw in the envelope-stamp rectangle (for envelopes only)
3005 * WM_PSD_YAFULLPAGERECT Draw the return address portion (for envelopes and other paper sizes)
3007 * RETURNS:
3008 * FALSE if all done correctly
3013 static LRESULT CALLBACK
3014 PRINTDLG_PagePaintProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3016 PAINTSTRUCT ps;
3017 RECT rcClient, rcMargin;
3018 HPEN hpen, holdpen;
3019 HDC hdc;
3020 HBRUSH hbrush, holdbrush;
3021 PageSetupDataA *pda;
3022 int papersize=0, orientation=0; /* FIXME: set this values for user paint hook */
3023 double scalx, scaly;
3024 #define CALLPAINTHOOK(msg,lprc) PRINTDLG_DefaultPagePaintHook( hWnd, msg, (WPARAM)hdc, (LPARAM)lprc, pda)
3026 if (uMsg != WM_PAINT)
3027 return CallWindowProcA(lpfnStaticWndProc, hWnd, uMsg, wParam, lParam);
3029 /* Processing WM_PAINT message */
3030 pda = (PageSetupDataA*)GetPropA(hWnd, "__WINE_PAGESETUPDLGDATA");
3031 if (!pda) {
3032 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3033 return FALSE;
3035 if (PRINTDLG_DefaultPagePaintHook(hWnd, WM_PSD_PAGESETUPDLG, MAKELONG(papersize, orientation), (LPARAM)pda->dlga, pda))
3036 return FALSE;
3038 hdc = BeginPaint(hWnd, &ps);
3039 GetClientRect(hWnd, &rcClient);
3041 scalx = rcClient.right / (double)pda->curdlg.ptPaperSize.x;
3042 scaly = rcClient.bottom / (double)pda->curdlg.ptPaperSize.y;
3043 rcMargin = rcClient;
3045 rcMargin.left += (LONG)pda->curdlg.rtMargin.left * scalx;
3046 rcMargin.top += (LONG)pda->curdlg.rtMargin.top * scalx;
3047 rcMargin.right -= (LONG)pda->curdlg.rtMargin.right * scaly;
3048 rcMargin.bottom -= (LONG)pda->curdlg.rtMargin.bottom * scaly;
3050 /* if the space is too small then we make sure to not draw anything */
3051 rcMargin.left = min(rcMargin.left, rcMargin.right);
3052 rcMargin.top = min(rcMargin.top, rcMargin.bottom);
3054 if (!CALLPAINTHOOK(WM_PSD_FULLPAGERECT, &rcClient) &&
3055 !CALLPAINTHOOK(WM_PSD_MINMARGINRECT, &rcMargin) )
3057 /* fill background */
3058 hbrush = GetSysColorBrush(COLOR_3DHIGHLIGHT);
3059 FillRect(hdc, &rcClient, hbrush);
3060 holdbrush = SelectObject(hdc, hbrush);
3062 hpen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW));
3063 holdpen = SelectObject(hdc, hpen);
3065 /* paint left edge */
3066 MoveToEx(hdc, rcClient.left, rcClient.top, NULL);
3067 LineTo(hdc, rcClient.left, rcClient.bottom-1);
3069 /* paint top edge */
3070 MoveToEx(hdc, rcClient.left, rcClient.top, NULL);
3071 LineTo(hdc, rcClient.right, rcClient.top);
3073 hpen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DDKSHADOW));
3074 DeleteObject(SelectObject(hdc, hpen));
3076 /* paint right edge */
3077 MoveToEx(hdc, rcClient.right-1, rcClient.top, NULL);
3078 LineTo(hdc, rcClient.right-1, rcClient.bottom);
3080 /* paint bottom edge */
3081 MoveToEx(hdc, rcClient.left, rcClient.bottom-1, NULL);
3082 LineTo(hdc, rcClient.right, rcClient.bottom-1);
3084 DeleteObject(SelectObject(hdc, holdpen));
3085 DeleteObject(SelectObject(hdc, holdbrush));
3087 CALLPAINTHOOK(WM_PSD_MARGINRECT, &rcMargin);
3089 /* give text a bit of a space from the frame */
3090 rcMargin.left += 2;
3091 rcMargin.top += 2;
3092 rcMargin.right -= 2;
3093 rcMargin.bottom -= 2;
3095 /* if the space is too small then we make sure to not draw anything */
3096 rcMargin.left = min(rcMargin.left, rcMargin.right);
3097 rcMargin.top = min(rcMargin.top, rcMargin.bottom);
3099 CALLPAINTHOOK(WM_PSD_GREEKTEXTRECT, &rcMargin);
3102 EndPaint(hWnd, &ps);
3103 return FALSE;
3104 #undef CALLPAINTHOOK
3107 /***********************************************************************
3108 * PRINTDLG_PageDlgProcA
3109 * Message handler for PageSetupDlgA
3111 static INT_PTR CALLBACK
3112 PRINTDLG_PageDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
3114 DEVMODEA *dm;
3115 PageSetupDataA *pda;
3116 INT_PTR res = FALSE;
3117 HWND hDrawWnd;
3119 if (uMsg == WM_INITDIALOG) { /*Init dialog*/
3120 pda = (PageSetupDataA*)lParam;
3121 pda->hDlg = hDlg; /* saving handle to main window to PageSetupDataA structure */
3122 memcpy(&pda->curdlg, pda->dlga, sizeof(pda->curdlg));
3124 hDrawWnd = GetDlgItem(hDlg, rct1);
3125 TRACE("set property to %p\n", pda);
3126 SetPropA(hDlg, "__WINE_PAGESETUPDLGDATA", pda);
3127 SetPropA(hDrawWnd, "__WINE_PAGESETUPDLGDATA", pda);
3128 GetWindowRect(hDrawWnd, &pda->rtDrawRect); /* Calculating rect in client coordinates where paper draws */
3129 ScreenToClient(hDlg, (LPPOINT)&pda->rtDrawRect);
3130 ScreenToClient(hDlg, (LPPOINT)(&pda->rtDrawRect.right));
3131 lpfnStaticWndProc = (WNDPROC)SetWindowLongPtrW(
3132 hDrawWnd,
3133 GWLP_WNDPROC,
3134 (ULONG_PTR)PRINTDLG_PagePaintProc);
3136 /* FIXME: Paint hook. Must it be at begin of initializtion or at end? */
3137 res = TRUE;
3138 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3139 if (!pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,(LPARAM)pda->dlga))
3140 FIXME("Setup page hook failed?\n");
3143 /* if printer button disabled */
3144 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
3145 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
3146 /* if margin edit boxes disabled */
3147 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
3148 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
3149 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
3150 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
3151 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
3153 /* Set orientation radiobutton properly */
3154 dm = GlobalLock(pda->dlga->hDevMode);
3155 if (dm->u1.s1.dmOrientation == DMORIENT_LANDSCAPE)
3156 CheckRadioButton(hDlg, rad1, rad2, rad2);
3157 else /* this is default if papersize is not set */
3158 CheckRadioButton(hDlg, rad1, rad2, rad1);
3159 GlobalUnlock(pda->dlga->hDevMode);
3161 /* if orientation disabled */
3162 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
3163 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
3164 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
3166 /* We fill them out enabled or not */
3167 if (pda->dlga->Flags & PSD_MARGINS) {
3168 char str[100];
3169 _c_size2strA(pda,pda->dlga->rtMargin.left,str);
3170 SetDlgItemTextA(hDlg,edt4,str);
3171 _c_size2strA(pda,pda->dlga->rtMargin.top,str);
3172 SetDlgItemTextA(hDlg,edt5,str);
3173 _c_size2strA(pda,pda->dlga->rtMargin.right,str);
3174 SetDlgItemTextA(hDlg,edt6,str);
3175 _c_size2strA(pda,pda->dlga->rtMargin.bottom,str);
3176 SetDlgItemTextA(hDlg,edt7,str);
3177 } else {
3178 /* default is 1 inch */
3179 DWORD size = _c_inch2size(pda->dlga,1000);
3180 char str[20];
3181 _c_size2strA(pda,size,str);
3182 SetDlgItemTextA(hDlg,edt4,str);
3183 SetDlgItemTextA(hDlg,edt5,str);
3184 SetDlgItemTextA(hDlg,edt6,str);
3185 SetDlgItemTextA(hDlg,edt7,str);
3186 pda->curdlg.rtMargin.left = size;
3187 pda->curdlg.rtMargin.top = size;
3188 pda->curdlg.rtMargin.right = size;
3189 pda->curdlg.rtMargin.bottom = size;
3191 /* if paper disabled */
3192 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
3193 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
3194 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
3196 /* filling combos: printer, paper, source. selecting current printer (from DEVMODEA) */
3197 PRINTDLG_PS_ChangePrinterA(hDlg, pda);
3198 dm = GlobalLock(pda->pdlg.hDevMode);
3199 if(dm){
3200 dm->dmDefaultSource = 15; /*FIXME: Automatic select. Does it always 15 at start? */
3201 PRINTDLG_PaperSizeA(&(pda->pdlg), dm->u1.s1.dmPaperSize, &pda->curdlg.ptPaperSize);
3202 GlobalUnlock(pda->pdlg.hDevMode);
3203 pda->curdlg.ptPaperSize.x = _c_10mm2size(pda->dlga, pda->curdlg.ptPaperSize.x);
3204 pda->curdlg.ptPaperSize.y = _c_10mm2size(pda->dlga, pda->curdlg.ptPaperSize.y);
3205 if (IsDlgButtonChecked(hDlg, rad2) == BST_CHECKED) { /* Landscape orientation */
3206 DWORD tmp = pda->curdlg.ptPaperSize.y;
3207 pda->curdlg.ptPaperSize.y = pda->curdlg.ptPaperSize.x;
3208 pda->curdlg.ptPaperSize.x = tmp;
3210 } else
3211 WARN("GlobalLock(pda->pdlg.hDevMode) fail? hDevMode=%p\n", pda->pdlg.hDevMode);
3212 /* Drawing paper prev */
3213 PRINTDLG_PS_ChangePaperPrev(pda);
3214 return TRUE;
3215 } else {
3216 pda = (PageSetupDataA*)GetPropA(hDlg,"__WINE_PAGESETUPDLGDATA");
3217 if (!pda) {
3218 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3219 return FALSE;
3221 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3222 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3223 if (res) return res;
3226 switch (uMsg) {
3227 case WM_COMMAND:
3228 return PRINTDLG_PS_WMCommandA(hDlg, wParam, lParam, pda);
3230 return FALSE;
3233 static INT_PTR CALLBACK
3234 PageDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
3236 static const WCHAR __WINE_PAGESETUPDLGDATA[] =
3237 { '_', '_', 'W', 'I', 'N', 'E', '_', 'P', 'A', 'G', 'E',
3238 'S', 'E', 'T', 'U', 'P', 'D', 'L', 'G', 'D', 'A', 'T', 'A', 0 };
3239 PageSetupDataW *pda;
3240 BOOL res = FALSE;
3242 if (uMsg==WM_INITDIALOG) {
3243 res = TRUE;
3244 pda = (PageSetupDataW*)lParam;
3245 SetPropW(hDlg, __WINE_PAGESETUPDLGDATA, pda);
3246 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3247 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,(LPARAM)pda->dlga);
3248 if (!res) {
3249 FIXME("Setup page hook failed?\n");
3250 res = TRUE;
3254 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK) {
3255 FIXME("PagePaintHook not yet implemented!\n");
3257 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
3258 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
3259 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
3260 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
3261 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
3262 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
3263 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
3265 /* width larger as height -> landscape */
3266 if (pda->dlga->ptPaperSize.x > pda->dlga->ptPaperSize.y)
3267 CheckRadioButton(hDlg, rad1, rad2, rad2);
3268 else /* this is default if papersize is not set */
3269 CheckRadioButton(hDlg, rad1, rad2, rad1);
3270 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
3271 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
3272 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
3274 /* We fill them out enabled or not */
3275 if (pda->dlga->Flags & PSD_MARGINS) {
3276 WCHAR str[100];
3277 _c_size2strW(pda,pda->dlga->rtMargin.left,str);
3278 SetDlgItemTextW(hDlg,edt4,str);
3279 _c_size2strW(pda,pda->dlga->rtMargin.top,str);
3280 SetDlgItemTextW(hDlg,edt5,str);
3281 _c_size2strW(pda,pda->dlga->rtMargin.right,str);
3282 SetDlgItemTextW(hDlg,edt6,str);
3283 _c_size2strW(pda,pda->dlga->rtMargin.bottom,str);
3284 SetDlgItemTextW(hDlg,edt7,str);
3285 } else {
3286 /* default is 1 inch */
3287 DWORD size = _c_inch2size((LPPAGESETUPDLGA)pda->dlga,1000);
3288 WCHAR str[20];
3289 _c_size2strW(pda,size,str);
3290 SetDlgItemTextW(hDlg,edt4,str);
3291 SetDlgItemTextW(hDlg,edt5,str);
3292 SetDlgItemTextW(hDlg,edt6,str);
3293 SetDlgItemTextW(hDlg,edt7,str);
3295 PRINTDLG_PS_ChangePrinterW(hDlg,pda);
3296 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
3297 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
3298 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
3301 return TRUE;
3302 } else {
3303 pda = (PageSetupDataW*)GetPropW(hDlg, __WINE_PAGESETUPDLGDATA);
3304 if (!pda) {
3305 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3306 return FALSE;
3308 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3309 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3310 if (res) return res;
3313 switch (uMsg) {
3314 case WM_COMMAND:
3315 return PRINTDLG_PS_WMCommandW(hDlg, wParam, lParam, pda);
3317 return FALSE;
3320 /***********************************************************************
3321 * PageSetupDlgA (COMDLG32.@)
3323 * Displays the the PAGE SETUP dialog box, which enables the user to specify
3324 * specific properties of a printed page such as
3325 * size, source, orientation and the width of the page margins.
3327 * PARAMS
3328 * setupdlg [IO] PAGESETUPDLGA struct
3330 * RETURNS
3331 * TRUE if the user pressed the OK button
3332 * FALSE if the user cancelled the window or an error occurred
3334 * NOTES
3335 * The values of hDevMode and hDevNames are filled on output and can be
3336 * changed in PAGESETUPDLG when they are passed in PageSetupDlg.
3340 BOOL WINAPI PageSetupDlgA(LPPAGESETUPDLGA setupdlg) {
3341 HGLOBAL hDlgTmpl;
3342 LPVOID ptr;
3343 BOOL bRet;
3344 PageSetupDataA *pda;
3345 PRINTDLGA pdlg;
3347 /* TRACE */
3348 if(TRACE_ON(commdlg)) {
3349 char flagstr[1000] = "";
3350 const struct pd_flags *pflag = psd_flags;
3351 for( ; pflag->name; pflag++) {
3352 if(setupdlg->Flags & pflag->flag) {
3353 strcat(flagstr, pflag->name);
3354 strcat(flagstr, "|");
3357 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3358 "hinst %p, flags %08x (%s)\n",
3359 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
3360 setupdlg->hDevNames,
3361 setupdlg->hInstance, setupdlg->Flags, flagstr);
3363 /* Checking setupdlg structure */
3364 if (setupdlg == NULL) {
3365 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION);
3366 return FALSE;
3368 if(setupdlg->lStructSize != sizeof(PAGESETUPDLGA)) {
3369 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
3370 return FALSE;
3372 if ((setupdlg->Flags & PSD_ENABLEPAGEPAINTHOOK) &&
3373 (setupdlg->lpfnPagePaintHook == NULL)) {
3374 COMDLG32_SetCommDlgExtendedError(CDERR_NOHOOK);
3375 return FALSE;
3378 /* Initialize default printer struct. If no printer device info is specified
3379 retrieve the default printer data. */
3380 memset(&pdlg,0,sizeof(pdlg));
3381 pdlg.lStructSize = sizeof(pdlg);
3382 if (setupdlg->hDevMode && setupdlg->hDevNames) {
3383 pdlg.hDevMode = setupdlg->hDevMode;
3384 pdlg.hDevNames = setupdlg->hDevNames;
3385 } else {
3386 pdlg.Flags = PD_RETURNDEFAULT;
3387 bRet = PrintDlgA(&pdlg);
3388 if (!bRet){
3389 if (!(setupdlg->Flags & PSD_NOWARNING)) {
3390 char errstr[256];
3391 LoadStringA(COMDLG32_hInstance, PD32_NO_DEFAULT_PRINTER, errstr, 255);
3392 MessageBoxA(setupdlg->hwndOwner, errstr, 0, MB_OK | MB_ICONERROR);
3394 return FALSE;
3398 /* short cut exit, just return default values */
3399 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
3400 DEVMODEA *dm;
3402 dm = GlobalLock(pdlg.hDevMode);
3403 PRINTDLG_PaperSizeA(&pdlg, dm->u1.s1.dmPaperSize, &setupdlg->ptPaperSize);
3404 GlobalUnlock(pdlg.hDevMode);
3405 setupdlg->ptPaperSize.x=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.x);
3406 setupdlg->ptPaperSize.y=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.y);
3407 return TRUE;
3410 /* get dialog template */
3411 hDlgTmpl = PRINTDLG_GetPGSTemplateA(setupdlg);
3412 if (!hDlgTmpl) {
3413 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3414 return FALSE;
3416 ptr = LockResource( hDlgTmpl );
3417 if (!ptr) {
3418 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3419 return FALSE;
3422 pda = HeapAlloc(GetProcessHeap(),0,sizeof(*pda));
3423 pda->dlga = setupdlg;
3424 memcpy(&pda->pdlg,&pdlg,sizeof(pdlg));
3426 bRet = (0<DialogBoxIndirectParamA(
3427 setupdlg->hInstance,
3428 ptr,
3429 setupdlg->hwndOwner,
3430 PRINTDLG_PageDlgProcA,
3431 (LPARAM)pda)
3434 HeapFree(GetProcessHeap(),0,pda);
3435 return bRet;
3437 /***********************************************************************
3438 * PageSetupDlgW (COMDLG32.@)
3440 * See PageSetupDlgA.
3442 BOOL WINAPI PageSetupDlgW(LPPAGESETUPDLGW setupdlg) {
3443 HGLOBAL hDlgTmpl;
3444 LPVOID ptr;
3445 BOOL bRet;
3446 PageSetupDataW *pdw;
3447 PRINTDLGW pdlg;
3449 FIXME("Unicode implementation is not done yet\n");
3450 if(TRACE_ON(commdlg)) {
3451 char flagstr[1000] = "";
3452 const struct pd_flags *pflag = psd_flags;
3453 for( ; pflag->name; pflag++) {
3454 if(setupdlg->Flags & pflag->flag) {
3455 strcat(flagstr, pflag->name);
3456 strcat(flagstr, "|");
3459 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3460 "hinst %p, flags %08x (%s)\n",
3461 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
3462 setupdlg->hDevNames,
3463 setupdlg->hInstance, setupdlg->Flags, flagstr);
3466 /* Initialize default printer struct. If no printer device info is specified
3467 retrieve the default printer data. */
3468 memset(&pdlg,0,sizeof(pdlg));
3469 pdlg.lStructSize = sizeof(pdlg);
3470 if (setupdlg->hDevMode && setupdlg->hDevNames) {
3471 pdlg.hDevMode = setupdlg->hDevMode;
3472 pdlg.hDevNames = setupdlg->hDevNames;
3473 } else {
3474 pdlg.Flags = PD_RETURNDEFAULT;
3475 bRet = PrintDlgW(&pdlg);
3476 if (!bRet){
3477 if (!(setupdlg->Flags & PSD_NOWARNING)) {
3478 WCHAR errstr[256];
3479 LoadStringW(COMDLG32_hInstance, PD32_NO_DEFAULT_PRINTER, errstr, 255);
3480 MessageBoxW(setupdlg->hwndOwner, errstr, 0, MB_OK | MB_ICONERROR);
3482 return FALSE;
3486 /* short cut exit, just return default values */
3487 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
3488 static const WCHAR a4[] = {'A','4',0};
3489 setupdlg->hDevMode = pdlg.hDevMode;
3490 setupdlg->hDevNames = pdlg.hDevNames;
3491 /* FIXME: Just return "A4" for now. */
3492 PRINTDLG_PaperSizeW(&pdlg,a4,&setupdlg->ptPaperSize);
3493 setupdlg->ptPaperSize.x=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.x);
3494 setupdlg->ptPaperSize.y=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.y);
3495 return TRUE;
3497 hDlgTmpl = PRINTDLG_GetPGSTemplateW(setupdlg);
3498 if (!hDlgTmpl) {
3499 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3500 return FALSE;
3502 ptr = LockResource( hDlgTmpl );
3503 if (!ptr) {
3504 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3505 return FALSE;
3507 pdw = HeapAlloc(GetProcessHeap(),0,sizeof(*pdw));
3508 pdw->dlga = setupdlg;
3509 memcpy(&pdw->pdlg,&pdlg,sizeof(pdlg));
3511 bRet = (0<DialogBoxIndirectParamW(
3512 setupdlg->hInstance,
3513 ptr,
3514 setupdlg->hwndOwner,
3515 PageDlgProcW,
3516 (LPARAM)pdw)
3518 return bRet;
3521 /***********************************************************************
3522 * PrintDlgExA (COMDLG32.@)
3524 * See PrintDlgExW.
3526 * FIXME
3527 * Stub
3529 HRESULT WINAPI PrintDlgExA(LPPRINTDLGEXA lpPrintDlgExA)
3531 FIXME("stub\n");
3532 return E_NOTIMPL;
3535 /***********************************************************************
3536 * PrintDlgExW (COMDLG32.@)
3538 * Display the the PRINT dialog box, which enables the user to specify
3539 * specific properties of the print job. The property sheet can also have
3540 * additional application-specific and driver-specific property pages.
3542 * PARAMS
3543 * lppd [IO] ptr to PRINTDLGEX struct
3545 * RETURNS
3546 * Success: S_OK
3547 * Failure: One of the following COM error codes:
3548 * E_OUTOFMEMORY Insufficient memory.
3549 * E_INVALIDARG One or more arguments are invalid.
3550 * E_POINTER Invalid pointer.
3551 * E_HANDLE Invalid handle.
3552 * E_FAIL Unspecified error.
3554 * FIXME
3555 * Stub
3557 HRESULT WINAPI PrintDlgExW(LPPRINTDLGEXW lpPrintDlgExW)
3559 FIXME("stub\n");
3560 return E_NOTIMPL;