Added some defines concerning SChannel CSPs.
[wine/multimedia.git] / dlls / commdlg / printdlg.c
blob1ee53c4941d27c3a86fc0cb329ba2ed341a9b30c
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 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 /***********************************************************************
75 * PRINTDLG_OpenDefaultPrinter
77 * Returns a winspool printer handle to the default printer in *hprn
78 * Caller must call ClosePrinter on the handle
80 * Returns TRUE on success else FALSE
82 BOOL PRINTDLG_OpenDefaultPrinter(HANDLE *hprn)
84 char buf[260];
85 DWORD dwBufLen = sizeof(buf);
86 BOOL res;
87 if(!GetDefaultPrinterA(buf, &dwBufLen))
88 return FALSE;
89 res = OpenPrinterA(buf, hprn, NULL);
90 if (!res)
91 FIXME("Could not open printer %s?!\n",buf);
92 return res;
95 /***********************************************************************
96 * PRINTDLG_SetUpPrinterListCombo
98 * Initializes printer list combox.
99 * hDlg: HWND of dialog
100 * id: Control id of combo
101 * name: Name of printer to select
103 * Initializes combo with list of available printers. Selects printer 'name'
104 * If name is NULL or does not exist select the default printer.
106 * Returns number of printers added to list.
108 INT PRINTDLG_SetUpPrinterListComboA(HWND hDlg, UINT id, LPCSTR name)
110 DWORD needed, num;
111 INT i;
112 LPPRINTER_INFO_2A pi;
113 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
114 pi = HeapAlloc(GetProcessHeap(), 0, needed);
115 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
116 &num);
118 for(i = 0; i < num; i++) {
119 SendDlgItemMessageA(hDlg, id, CB_ADDSTRING, 0,
120 (LPARAM)pi[i].pPrinterName );
122 HeapFree(GetProcessHeap(), 0, pi);
123 if(!name ||
124 (i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1,
125 (LPARAM)name)) == CB_ERR) {
127 char buf[260];
128 DWORD dwBufLen = sizeof(buf);
129 FIXME("Can't find '%s' in printer list so trying to find default\n",
130 name);
131 if(!GetDefaultPrinterA(buf, &dwBufLen))
132 return num;
133 i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
134 if(i == CB_ERR)
135 FIXME("Can't find default printer in printer list\n");
137 SendDlgItemMessageA(hDlg, id, CB_SETCURSEL, i, 0);
138 return num;
141 static INT PRINTDLG_SetUpPrinterListComboW(HWND hDlg, UINT id, LPCWSTR name)
143 DWORD needed, num;
144 INT i;
145 LPPRINTER_INFO_2W pi;
146 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
147 pi = HeapAlloc(GetProcessHeap(), 0, needed);
148 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
149 &num);
151 for(i = 0; i < num; i++) {
152 SendDlgItemMessageW(hDlg, id, CB_ADDSTRING, 0,
153 (LPARAM)pi[i].pPrinterName );
155 HeapFree(GetProcessHeap(), 0, pi);
156 if(!name ||
157 (i = SendDlgItemMessageW(hDlg, id, CB_FINDSTRINGEXACT, -1,
158 (LPARAM)name)) == CB_ERR) {
159 WCHAR buf[260];
160 DWORD dwBufLen = sizeof(buf)/sizeof(buf[0]);
161 TRACE("Can't find '%s' in printer list so trying to find default\n",
162 debugstr_w(name));
163 if(!GetDefaultPrinterW(buf, &dwBufLen))
164 return num;
165 i = SendDlgItemMessageW(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
166 if(i == CB_ERR)
167 TRACE("Can't find default printer in printer list\n");
169 SendDlgItemMessageW(hDlg, id, CB_SETCURSEL, i, 0);
170 return num;
173 /***********************************************************************
174 * PRINTDLG_CreateDevNames [internal]
177 * creates a DevNames structure.
179 * (NB. when we handle unicode the offsets will be in wchars).
181 static BOOL PRINTDLG_CreateDevNames(HGLOBAL *hmem, char* DeviceDriverName,
182 char* DeviceName, char* OutputPort)
184 long size;
185 char* pDevNamesSpace;
186 char* pTempPtr;
187 LPDEVNAMES lpDevNames;
188 char buf[260];
189 DWORD dwBufLen = sizeof(buf);
191 size = strlen(DeviceDriverName) + 1
192 + strlen(DeviceName) + 1
193 + strlen(OutputPort) + 1
194 + sizeof(DEVNAMES);
196 if(*hmem)
197 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
198 else
199 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
200 if (*hmem == 0)
201 return FALSE;
203 pDevNamesSpace = GlobalLock(*hmem);
204 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
206 pTempPtr = pDevNamesSpace + sizeof(DEVNAMES);
207 strcpy(pTempPtr, DeviceDriverName);
208 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
210 pTempPtr += strlen(DeviceDriverName) + 1;
211 strcpy(pTempPtr, DeviceName);
212 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
214 pTempPtr += strlen(DeviceName) + 1;
215 strcpy(pTempPtr, OutputPort);
216 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
218 GetDefaultPrinterA(buf, &dwBufLen);
219 lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
220 GlobalUnlock(*hmem);
221 return TRUE;
224 static BOOL PRINTDLG_CreateDevNamesW(HGLOBAL *hmem, LPCWSTR DeviceDriverName,
225 LPCWSTR DeviceName, LPCWSTR OutputPort)
227 long size;
228 LPWSTR pDevNamesSpace;
229 LPWSTR pTempPtr;
230 LPDEVNAMES lpDevNames;
231 WCHAR bufW[260];
232 DWORD dwBufLen = sizeof(bufW) / sizeof(WCHAR);
234 size = sizeof(WCHAR)*lstrlenW(DeviceDriverName) + 2
235 + sizeof(WCHAR)*lstrlenW(DeviceName) + 2
236 + sizeof(WCHAR)*lstrlenW(OutputPort) + 2
237 + sizeof(DEVNAMES);
239 if(*hmem)
240 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
241 else
242 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
243 if (*hmem == 0)
244 return FALSE;
246 pDevNamesSpace = GlobalLock(*hmem);
247 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
249 pTempPtr = (LPWSTR)((LPDEVNAMES)pDevNamesSpace + 1);
250 lstrcpyW(pTempPtr, DeviceDriverName);
251 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
253 pTempPtr += lstrlenW(DeviceDriverName) + 1;
254 lstrcpyW(pTempPtr, DeviceName);
255 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
257 pTempPtr += lstrlenW(DeviceName) + 1;
258 lstrcpyW(pTempPtr, OutputPort);
259 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
261 GetDefaultPrinterW(bufW, &dwBufLen);
262 lpDevNames->wDefault = (lstrcmpW(bufW, DeviceName) == 0) ? 1 : 0;
263 GlobalUnlock(*hmem);
264 return TRUE;
267 /***********************************************************************
268 * PRINTDLG_UpdatePrintDlg [internal]
271 * updates the PrintDlg structure for return values.
273 * RETURNS
274 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
275 * TRUE if successful.
277 static BOOL PRINTDLG_UpdatePrintDlgA(HWND hDlg,
278 PRINT_PTRA* PrintStructures)
280 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
281 PDEVMODEA lpdm = PrintStructures->lpDevMode;
282 LPPRINTER_INFO_2A pi = PrintStructures->lpPrinterInfo;
285 if(!lpdm) {
286 FIXME("No lpdm ptr?\n");
287 return FALSE;
291 if(!(lppd->Flags & PD_PRINTSETUP)) {
292 /* check whether nFromPage and nToPage are within range defined by
293 * nMinPage and nMaxPage
295 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
296 WORD nToPage;
297 WORD nFromPage;
298 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
299 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
300 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
301 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
302 char resourcestr[256];
303 char resultstr[256];
304 LoadStringA(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
305 resourcestr, 255);
306 sprintf(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
307 LoadStringA(COMDLG32_hInstance, PD32_PRINT_TITLE,
308 resourcestr, 255);
309 MessageBoxA(hDlg, resultstr, resourcestr,
310 MB_OK | MB_ICONWARNING);
311 return FALSE;
313 lppd->nFromPage = nFromPage;
314 lppd->nToPage = nToPage;
315 lppd->Flags |= PD_PAGENUMS;
317 else
318 lppd->Flags &= ~PD_PAGENUMS;
320 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
321 lppd->Flags |= PD_PRINTTOFILE;
322 pi->pPortName = "FILE:";
325 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
326 FIXME("Collate lppd not yet implemented as output\n");
329 /* set PD_Collate and nCopies */
330 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
331 /* The application doesn't support multiple copies or collate...
333 lppd->Flags &= ~PD_COLLATE;
334 lppd->nCopies = 1;
335 /* if the printer driver supports it... store info there
336 * otherwise no collate & multiple copies !
338 if (lpdm->dmFields & DM_COLLATE)
339 lpdm->dmCollate =
340 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
341 if (lpdm->dmFields & DM_COPIES)
342 lpdm->dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
343 } else {
344 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
345 lppd->Flags |= PD_COLLATE;
346 else
347 lppd->Flags &= ~PD_COLLATE;
348 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
351 return TRUE;
354 static BOOL PRINTDLG_UpdatePrintDlgW(HWND hDlg,
355 PRINT_PTRW* PrintStructures)
357 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
358 PDEVMODEW lpdm = PrintStructures->lpDevMode;
359 LPPRINTER_INFO_2W pi = PrintStructures->lpPrinterInfo;
362 if(!lpdm) {
363 FIXME("No lpdm ptr?\n");
364 return FALSE;
368 if(!(lppd->Flags & PD_PRINTSETUP)) {
369 /* check whether nFromPage and nToPage are within range defined by
370 * nMinPage and nMaxPage
372 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
373 WORD nToPage;
374 WORD nFromPage;
375 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
376 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
377 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
378 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
379 WCHAR resourcestr[256];
380 WCHAR resultstr[256];
381 LoadStringW(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
382 resourcestr, 255);
383 wsprintfW(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
384 LoadStringW(COMDLG32_hInstance, PD32_PRINT_TITLE,
385 resourcestr, 255);
386 MessageBoxW(hDlg, resultstr, resourcestr,
387 MB_OK | MB_ICONWARNING);
388 return FALSE;
390 lppd->nFromPage = nFromPage;
391 lppd->nToPage = nToPage;
394 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
395 static WCHAR file[] = {'F','I','L','E',':',0};
396 lppd->Flags |= PD_PRINTTOFILE;
397 pi->pPortName = file;
400 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
401 FIXME("Collate lppd not yet implemented as output\n");
404 /* set PD_Collate and nCopies */
405 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
406 /* The application doesn't support multiple copies or collate...
408 lppd->Flags &= ~PD_COLLATE;
409 lppd->nCopies = 1;
410 /* if the printer driver supports it... store info there
411 * otherwise no collate & multiple copies !
413 if (lpdm->dmFields & DM_COLLATE)
414 lpdm->dmCollate =
415 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
416 if (lpdm->dmFields & DM_COPIES)
417 lpdm->dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
418 } else {
419 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
420 lppd->Flags |= PD_COLLATE;
421 else
422 lppd->Flags &= ~PD_COLLATE;
423 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
426 return TRUE;
429 static BOOL PRINTDLG_PaperSizeA(
430 PRINTDLGA *pdlga,const char *PaperSize,LPPOINT size
432 DEVNAMES *dn;
433 DEVMODEA *dm;
434 LPSTR devname,portname;
435 int i;
436 INT NrOfEntries,ret;
437 char *Names = NULL;
438 POINT *points = NULL;
439 BOOL retval = FALSE;
441 dn = GlobalLock(pdlga->hDevNames);
442 dm = GlobalLock(pdlga->hDevMode);
443 devname = ((char*)dn)+dn->wDeviceOffset;
444 portname = ((char*)dn)+dn->wOutputOffset;
447 NrOfEntries = DeviceCapabilitiesA(devname,portname,DC_PAPERNAMES,NULL,dm);
448 if (!NrOfEntries) {
449 FIXME("No papernames found for %s/%s\n",devname,portname);
450 goto out;
452 if (NrOfEntries == -1) {
453 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
454 goto out;
457 Names = (char*)HeapAlloc(GetProcessHeap(),0,NrOfEntries*64);
458 if (NrOfEntries != (ret=DeviceCapabilitiesA(devname,portname,DC_PAPERNAMES,Names,dm))) {
459 FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
460 goto out;
462 for (i=0;i<NrOfEntries;i++)
463 if (!strcmp(PaperSize,Names+(64*i)))
464 break;
465 HeapFree(GetProcessHeap(),0,Names);
466 if (i==NrOfEntries) {
467 FIXME("Papersize %s not found in list?\n",PaperSize);
468 goto out;
470 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
471 if (NrOfEntries!=(ret=DeviceCapabilitiesA(devname,portname,DC_PAPERSIZE,(LPBYTE)points,dm))) {
472 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
473 goto out;
475 /* this is _10ths_ of a millimeter */
476 size->x=points[i].x;
477 size->y=points[i].y;
478 retval = TRUE;
479 out:
480 GlobalUnlock(pdlga->hDevNames);
481 GlobalUnlock(pdlga->hDevMode);
482 HeapFree(GetProcessHeap(),0,Names);
483 HeapFree(GetProcessHeap(),0,points);
484 return retval;
487 static BOOL PRINTDLG_PaperSizeW(
488 PRINTDLGW *pdlga,const WCHAR *PaperSize,LPPOINT size
490 DEVNAMES *dn;
491 DEVMODEW *dm;
492 LPWSTR devname,portname;
493 int i;
494 INT NrOfEntries,ret;
495 WCHAR *Names = NULL;
496 POINT *points = NULL;
497 BOOL retval = FALSE;
499 dn = GlobalLock(pdlga->hDevNames);
500 dm = GlobalLock(pdlga->hDevMode);
501 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
502 portname = ((WCHAR*)dn)+dn->wOutputOffset;
505 NrOfEntries = DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,NULL,dm);
506 if (!NrOfEntries) {
507 FIXME("No papernames found for %s/%s\n",debugstr_w(devname),debugstr_w(portname));
508 goto out;
510 if (NrOfEntries == -1) {
511 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
512 goto out;
515 Names = (WCHAR*)HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*NrOfEntries*64);
516 if (NrOfEntries != (ret=DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,Names,dm))) {
517 FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
518 goto out;
520 for (i=0;i<NrOfEntries;i++)
521 if (!lstrcmpW(PaperSize,Names+(64*i)))
522 break;
523 HeapFree(GetProcessHeap(),0,Names);
524 if (i==NrOfEntries) {
525 FIXME("Papersize %s not found in list?\n",debugstr_w(PaperSize));
526 goto out;
528 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
529 if (NrOfEntries!=(ret=DeviceCapabilitiesW(devname,portname,DC_PAPERSIZE,(LPWSTR)points,dm))) {
530 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
531 goto out;
533 /* this is _10ths_ of a millimeter */
534 size->x=points[i].x;
535 size->y=points[i].y;
536 retval = TRUE;
537 out:
538 GlobalUnlock(pdlga->hDevNames);
539 GlobalUnlock(pdlga->hDevMode);
540 HeapFree(GetProcessHeap(),0,Names);
541 HeapFree(GetProcessHeap(),0,points);
542 return retval;
546 /************************************************************************
547 * PRINTDLG_SetUpPaperComboBox
549 * Initialize either the papersize or inputslot combos of the Printer Setup
550 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
551 * We also try to re-select the old selection.
553 static BOOL PRINTDLG_SetUpPaperComboBoxA(HWND hDlg,
554 int nIDComboBox,
555 char* PrinterName,
556 char* PortName,
557 LPDEVMODEA dm)
559 int i;
560 int NrOfEntries;
561 char* Names;
562 WORD* Words;
563 DWORD Sel;
564 WORD oldWord = 0;
565 int NamesSize;
566 int fwCapability_Names;
567 int fwCapability_Words;
569 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName,PortName,nIDComboBox);
571 /* query the dialog box for the current selected value */
572 Sel = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
573 if(Sel != CB_ERR) {
574 /* we enter here only if a different printer is selected after
575 * the Print Setup dialog is opened. The current settings are
576 * stored into the newly selected printer.
578 oldWord = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA,
579 Sel, 0);
580 if (dm) {
581 if (nIDComboBox == cmb2)
582 dm->u1.s1.dmPaperSize = oldWord;
583 else
584 dm->dmDefaultSource = oldWord;
587 else {
588 /* we enter here only when the Print setup dialog is initially
589 * opened. In this case the settings are restored from when
590 * the dialog was last closed.
592 if (dm) {
593 if (nIDComboBox == cmb2)
594 oldWord = dm->u1.s1.dmPaperSize;
595 else
596 oldWord = dm->dmDefaultSource;
600 if (nIDComboBox == cmb2) {
601 NamesSize = 64;
602 fwCapability_Names = DC_PAPERNAMES;
603 fwCapability_Words = DC_PAPERS;
604 } else {
605 nIDComboBox = cmb3;
606 NamesSize = 24;
607 fwCapability_Names = DC_BINNAMES;
608 fwCapability_Words = DC_BINS;
611 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
612 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
614 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
615 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
616 fwCapability_Names, NULL, dm);
617 if (NrOfEntries == 0)
618 WARN("no Name Entries found!\n");
619 else if (NrOfEntries < 0)
620 return FALSE;
622 if(DeviceCapabilitiesA(PrinterName, PortName, fwCapability_Words, NULL, dm)
623 != NrOfEntries) {
624 ERR("Number of caps is different\n");
625 NrOfEntries = 0;
628 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(char)*NamesSize);
629 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
630 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
631 fwCapability_Names, Names, dm);
632 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
633 fwCapability_Words, (LPSTR)Words, dm);
635 /* reset any current content in the combobox */
636 SendDlgItemMessageA(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
638 /* store new content */
639 for (i = 0; i < NrOfEntries; i++) {
640 DWORD pos = SendDlgItemMessageA(hDlg, nIDComboBox, CB_ADDSTRING, 0,
641 (LPARAM)(&Names[i*NamesSize]) );
642 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
643 Words[i]);
646 /* Look for old selection - can't do this is previous loop since
647 item order will change as more items are added */
648 Sel = 0;
649 for (i = 0; i < NrOfEntries; i++) {
650 if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
651 oldWord) {
652 Sel = i;
653 break;
656 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
658 HeapFree(GetProcessHeap(),0,Words);
659 HeapFree(GetProcessHeap(),0,Names);
660 return TRUE;
663 static BOOL PRINTDLG_SetUpPaperComboBoxW(HWND hDlg,
664 int nIDComboBox,
665 WCHAR* PrinterName,
666 WCHAR* PortName,
667 LPDEVMODEW dm)
669 int i;
670 int NrOfEntries;
671 WCHAR* Names;
672 WORD* Words;
673 DWORD Sel;
674 WORD oldWord = 0;
675 int NamesSize;
676 int fwCapability_Names;
677 int fwCapability_Words;
679 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName),debugstr_w(PortName),nIDComboBox);
681 /* query the dialog box for the current selected value */
682 Sel = SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
683 if(Sel != CB_ERR) {
684 /* we enter here only if a different printer is selected after
685 * the Print Setup dialog is opened. The current settings are
686 * stored into the newly selected printer.
688 oldWord = SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETITEMDATA,
689 Sel, 0);
690 if (dm) {
691 if (nIDComboBox == cmb2)
692 dm->u1.s1.dmPaperSize = oldWord;
693 else
694 dm->dmDefaultSource = oldWord;
697 else {
698 /* we enter here only when the Print setup dialog is initially
699 * opened. In this case the settings are restored from when
700 * the dialog was last closed.
702 if (dm) {
703 if (nIDComboBox == cmb2)
704 oldWord = dm->u1.s1.dmPaperSize;
705 else
706 oldWord = dm->dmDefaultSource;
710 if (nIDComboBox == cmb2) {
711 NamesSize = 64;
712 fwCapability_Names = DC_PAPERNAMES;
713 fwCapability_Words = DC_PAPERS;
714 } else {
715 nIDComboBox = cmb3;
716 NamesSize = 24;
717 fwCapability_Names = DC_BINNAMES;
718 fwCapability_Words = DC_BINS;
721 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
722 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
724 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
725 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
726 fwCapability_Names, NULL, dm);
727 if (NrOfEntries == 0)
728 WARN("no Name Entries found!\n");
729 else if (NrOfEntries < 0)
730 return FALSE;
732 if(DeviceCapabilitiesW(PrinterName, PortName, fwCapability_Words, NULL, dm)
733 != NrOfEntries) {
734 ERR("Number of caps is different\n");
735 NrOfEntries = 0;
738 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WCHAR)*NamesSize);
739 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
740 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
741 fwCapability_Names, Names, dm);
742 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
743 fwCapability_Words, (LPWSTR)Words, dm);
745 /* reset any current content in the combobox */
746 SendDlgItemMessageW(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
748 /* store new content */
749 for (i = 0; i < NrOfEntries; i++) {
750 DWORD pos = SendDlgItemMessageW(hDlg, nIDComboBox, CB_ADDSTRING, 0,
751 (LPARAM)(&Names[i*NamesSize]) );
752 SendDlgItemMessageW(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
753 Words[i]);
756 /* Look for old selection - can't do this is previous loop since
757 item order will change as more items are added */
758 Sel = 0;
759 for (i = 0; i < NrOfEntries; i++) {
760 if(SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
761 oldWord) {
762 Sel = i;
763 break;
766 SendDlgItemMessageW(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
768 HeapFree(GetProcessHeap(),0,Words);
769 HeapFree(GetProcessHeap(),0,Names);
770 return TRUE;
774 /***********************************************************************
775 * PRINTDLG_UpdatePrinterInfoTexts [internal]
777 static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg, LPPRINTER_INFO_2A pi)
779 char StatusMsg[256];
780 char ResourceString[256];
781 int i;
783 /* Status Message */
784 StatusMsg[0]='\0';
786 /* add all status messages */
787 for (i = 0; i < 25; i++) {
788 if (pi->Status & (1<<i)) {
789 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
790 ResourceString, 255);
791 strcat(StatusMsg,ResourceString);
794 /* append "ready" */
795 /* FIXME: status==ready must only be appended if really so.
796 but how to detect? */
797 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
798 ResourceString, 255);
799 strcat(StatusMsg,ResourceString);
800 SetDlgItemTextA(hDlg, stc12, StatusMsg);
802 /* set all other printer info texts */
803 SetDlgItemTextA(hDlg, stc11, pi->pDriverName);
805 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
806 SetDlgItemTextA(hDlg, stc14, pi->pLocation);
807 else
808 SetDlgItemTextA(hDlg, stc14, pi->pPortName);
809 SetDlgItemTextA(hDlg, stc13, pi->pComment ? pi->pComment : "");
810 return;
813 static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg, LPPRINTER_INFO_2W pi)
815 WCHAR StatusMsg[256];
816 WCHAR ResourceString[256];
817 static const WCHAR emptyW[] = {0};
818 int i;
820 /* Status Message */
821 StatusMsg[0]='\0';
823 /* add all status messages */
824 for (i = 0; i < 25; i++) {
825 if (pi->Status & (1<<i)) {
826 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
827 ResourceString, 255);
828 lstrcatW(StatusMsg,ResourceString);
831 /* append "ready" */
832 /* FIXME: status==ready must only be appended if really so.
833 but how to detect? */
834 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
835 ResourceString, 255);
836 lstrcatW(StatusMsg,ResourceString);
837 SetDlgItemTextW(hDlg, stc12, StatusMsg);
839 /* set all other printer info texts */
840 SetDlgItemTextW(hDlg, stc11, pi->pDriverName);
841 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
842 SetDlgItemTextW(hDlg, stc14, pi->pLocation);
843 else
844 SetDlgItemTextW(hDlg, stc14, pi->pPortName);
845 SetDlgItemTextW(hDlg, stc13, pi->pComment ? pi->pComment : emptyW);
849 /*******************************************************************
851 * PRINTDLG_ChangePrinter
854 BOOL PRINTDLG_ChangePrinterA(HWND hDlg, char *name,
855 PRINT_PTRA *PrintStructures)
857 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
858 LPDEVMODEA lpdm = NULL;
859 LONG dmSize;
860 DWORD needed;
861 HANDLE hprn;
863 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
864 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
865 if(!OpenPrinterA(name, &hprn, NULL)) {
866 ERR("Can't open printer %s\n", name);
867 return FALSE;
869 GetPrinterA(hprn, 2, NULL, 0, &needed);
870 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,needed);
871 GetPrinterA(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
872 &needed);
873 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
874 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,needed);
875 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
876 needed, &needed)) {
877 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures->lpPrinterInfo->pPrinterName);
878 return FALSE;
880 ClosePrinter(hprn);
882 PRINTDLG_UpdatePrinterInfoTextsA(hDlg, PrintStructures->lpPrinterInfo);
884 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
885 PrintStructures->lpDevMode = NULL;
887 dmSize = DocumentPropertiesA(0, 0, name, NULL, NULL, 0);
888 if(dmSize == -1) {
889 ERR("DocumentProperties fails on %s\n", debugstr_a(name));
890 return FALSE;
892 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
893 dmSize = DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, NULL,
894 DM_OUT_BUFFER);
895 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
896 !strcmp(lpdm->dmDeviceName,
897 PrintStructures->lpDevMode->dmDeviceName)) {
898 /* Supplied devicemode matches current printer so try to use it */
899 DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, lpdm,
900 DM_OUT_BUFFER | DM_IN_BUFFER);
902 if(lpdm)
903 GlobalUnlock(lppd->hDevMode);
905 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
907 if(!(lppd->Flags & PD_PRINTSETUP)) {
908 /* Print range (All/Range/Selection) */
909 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
910 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
911 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
912 if (lppd->Flags & PD_NOSELECTION)
913 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
914 else
915 if (lppd->Flags & PD_SELECTION)
916 CheckRadioButton(hDlg, rad1, rad3, rad2);
917 if (lppd->Flags & PD_NOPAGENUMS) {
918 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
919 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
920 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
921 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
922 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
923 } else {
924 if (lppd->Flags & PD_PAGENUMS)
925 CheckRadioButton(hDlg, rad1, rad3, rad3);
928 /* Collate pages
930 * FIXME: The ico3 is not displayed for some reason. I don't know why.
932 if (lppd->Flags & PD_COLLATE) {
933 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
934 (LPARAM)PrintStructures->hCollateIcon);
935 CheckDlgButton(hDlg, chx2, 1);
936 } else {
937 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
938 (LPARAM)PrintStructures->hNoCollateIcon);
939 CheckDlgButton(hDlg, chx2, 0);
942 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
943 /* if printer doesn't support it: no Collate */
944 if (!(lpdm->dmFields & DM_COLLATE)) {
945 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
946 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
950 /* nCopies */
952 INT copies;
953 if (lppd->hDevMode == 0)
954 copies = lppd->nCopies;
955 else
956 copies = lpdm->dmCopies;
957 if(copies == 0) copies = 1;
958 else if(copies < 0) copies = MAX_COPIES;
959 SetDlgItemInt(hDlg, edt3, copies, FALSE);
962 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
963 /* if printer doesn't support it: no nCopies */
964 if (!(lpdm->dmFields & DM_COPIES)) {
965 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
966 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
970 /* print to file */
971 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
972 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
973 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
974 if (lppd->Flags & PD_HIDEPRINTTOFILE)
975 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
977 } else { /* PD_PRINTSETUP */
978 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
980 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb2,
981 PrintStructures->lpPrinterInfo->pPrinterName,
982 PrintStructures->lpPrinterInfo->pPortName,
983 lpdm);
984 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb3,
985 PrintStructures->lpPrinterInfo->pPrinterName,
986 PrintStructures->lpPrinterInfo->pPortName,
987 lpdm);
988 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
989 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
990 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
991 PrintStructures->hLandscapeIcon));
995 /* help button */
996 if ((lppd->Flags & PD_SHOWHELP)==0) {
997 /* hide if PD_SHOWHELP not specified */
998 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1000 return TRUE;
1003 static BOOL PRINTDLG_ChangePrinterW(HWND hDlg, WCHAR *name,
1004 PRINT_PTRW *PrintStructures)
1006 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1007 LPDEVMODEW lpdm = NULL;
1008 LONG dmSize;
1009 DWORD needed;
1010 HANDLE hprn;
1012 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
1013 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
1014 if(!OpenPrinterW(name, &hprn, NULL)) {
1015 ERR("Can't open printer %s\n", debugstr_w(name));
1016 return FALSE;
1018 GetPrinterW(hprn, 2, NULL, 0, &needed);
1019 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
1020 GetPrinterW(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
1021 &needed);
1022 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
1023 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
1024 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
1025 needed, &needed)) {
1026 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures->lpPrinterInfo->pPrinterName));
1027 return FALSE;
1029 ClosePrinter(hprn);
1031 PRINTDLG_UpdatePrinterInfoTextsW(hDlg, PrintStructures->lpPrinterInfo);
1033 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
1034 PrintStructures->lpDevMode = NULL;
1036 dmSize = DocumentPropertiesW(0, 0, name, NULL, NULL, 0);
1037 if(dmSize == -1) {
1038 ERR("DocumentProperties fails on %s\n", debugstr_w(name));
1039 return FALSE;
1041 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
1042 dmSize = DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, NULL,
1043 DM_OUT_BUFFER);
1044 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
1045 !lstrcmpW(lpdm->dmDeviceName,
1046 PrintStructures->lpDevMode->dmDeviceName)) {
1047 /* Supplied devicemode matches current printer so try to use it */
1048 DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, lpdm,
1049 DM_OUT_BUFFER | DM_IN_BUFFER);
1051 if(lpdm)
1052 GlobalUnlock(lppd->hDevMode);
1054 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
1056 if(!(lppd->Flags & PD_PRINTSETUP)) {
1057 /* Print range (All/Range/Selection) */
1058 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
1059 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
1060 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
1061 if (lppd->Flags & PD_NOSELECTION)
1062 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
1063 else
1064 if (lppd->Flags & PD_SELECTION)
1065 CheckRadioButton(hDlg, rad1, rad3, rad2);
1066 if (lppd->Flags & PD_NOPAGENUMS) {
1067 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
1068 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
1069 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
1070 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
1071 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
1072 } else {
1073 if (lppd->Flags & PD_PAGENUMS)
1074 CheckRadioButton(hDlg, rad1, rad3, rad3);
1077 /* Collate pages
1079 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1081 if (lppd->Flags & PD_COLLATE) {
1082 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1083 (LPARAM)PrintStructures->hCollateIcon);
1084 CheckDlgButton(hDlg, chx2, 1);
1085 } else {
1086 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1087 (LPARAM)PrintStructures->hNoCollateIcon);
1088 CheckDlgButton(hDlg, chx2, 0);
1091 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1092 /* if printer doesn't support it: no Collate */
1093 if (!(lpdm->dmFields & DM_COLLATE)) {
1094 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1095 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
1099 /* nCopies */
1101 INT copies;
1102 if (lppd->hDevMode == 0)
1103 copies = lppd->nCopies;
1104 else
1105 copies = lpdm->dmCopies;
1106 if(copies == 0) copies = 1;
1107 else if(copies < 0) copies = MAX_COPIES;
1108 SetDlgItemInt(hDlg, edt3, copies, FALSE);
1111 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1112 /* if printer doesn't support it: no nCopies */
1113 if (!(lpdm->dmFields & DM_COPIES)) {
1114 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
1115 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
1119 /* print to file */
1120 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
1121 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
1122 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
1123 if (lppd->Flags & PD_HIDEPRINTTOFILE)
1124 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
1126 } else { /* PD_PRINTSETUP */
1127 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
1129 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb2,
1130 PrintStructures->lpPrinterInfo->pPrinterName,
1131 PrintStructures->lpPrinterInfo->pPortName,
1132 lpdm);
1133 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb3,
1134 PrintStructures->lpPrinterInfo->pPrinterName,
1135 PrintStructures->lpPrinterInfo->pPortName,
1136 lpdm);
1137 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1138 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1139 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1140 PrintStructures->hLandscapeIcon));
1144 /* help button */
1145 if ((lppd->Flags & PD_SHOWHELP)==0) {
1146 /* hide if PD_SHOWHELP not specified */
1147 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1149 return TRUE;
1152 /***********************************************************************
1153 * PRINTDLG_WMInitDialog [internal]
1155 static LRESULT PRINTDLG_WMInitDialog(HWND hDlg, WPARAM wParam,
1156 PRINT_PTRA* PrintStructures)
1158 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
1159 DEVNAMES *pdn;
1160 DEVMODEA *pdm;
1161 char *name = NULL;
1162 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1164 /* load Collate ICONs */
1165 /* We load these with LoadImage because they are not a standard
1166 size and we don't want them rescaled */
1167 PrintStructures->hCollateIcon =
1168 LoadImageA(COMDLG32_hInstance, "PD32_COLLATE", IMAGE_ICON, 0, 0, 0);
1169 PrintStructures->hNoCollateIcon =
1170 LoadImageA(COMDLG32_hInstance, "PD32_NOCOLLATE", IMAGE_ICON, 0, 0, 0);
1172 /* These can be done with LoadIcon */
1173 PrintStructures->hPortraitIcon =
1174 LoadIconA(COMDLG32_hInstance, "PD32_PORTRAIT");
1175 PrintStructures->hLandscapeIcon =
1176 LoadIconA(COMDLG32_hInstance, "PD32_LANDSCAPE");
1178 /* display the collate/no_collate icon */
1179 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1180 (LPARAM)PrintStructures->hNoCollateIcon);
1182 if(PrintStructures->hCollateIcon == 0 ||
1183 PrintStructures->hNoCollateIcon == 0 ||
1184 PrintStructures->hPortraitIcon == 0 ||
1185 PrintStructures->hLandscapeIcon == 0) {
1186 ERR("no icon in resourcefile\n");
1187 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1188 EndDialog(hDlg, FALSE);
1192 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1193 * must be registered and the Help button must be shown.
1195 if (lppd->Flags & PD_SHOWHELP) {
1196 if((PrintStructures->HelpMessageID =
1197 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
1198 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1199 return FALSE;
1201 } else
1202 PrintStructures->HelpMessageID = 0;
1204 if(!(lppd->Flags &PD_PRINTSETUP)) {
1205 PrintStructures->hwndUpDown =
1206 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1207 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1208 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1209 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1210 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1213 /* FIXME: I allow more freedom than either Win95 or WinNT,
1214 * which do not agree to what errors should be thrown or not
1215 * in case nToPage or nFromPage is out-of-range.
1217 if (lppd->nMaxPage < lppd->nMinPage)
1218 lppd->nMaxPage = lppd->nMinPage;
1219 if (lppd->nMinPage == lppd->nMaxPage)
1220 lppd->Flags |= PD_NOPAGENUMS;
1221 if (lppd->nToPage < lppd->nMinPage)
1222 lppd->nToPage = lppd->nMinPage;
1223 if (lppd->nToPage > lppd->nMaxPage)
1224 lppd->nToPage = lppd->nMaxPage;
1225 if (lppd->nFromPage < lppd->nMinPage)
1226 lppd->nFromPage = lppd->nMinPage;
1227 if (lppd->nFromPage > lppd->nMaxPage)
1228 lppd->nFromPage = lppd->nMaxPage;
1230 /* if we have the combo box, fill it */
1231 if (GetDlgItem(hDlg,comboID)) {
1232 /* Fill Combobox
1234 pdn = GlobalLock(lppd->hDevNames);
1235 pdm = GlobalLock(lppd->hDevMode);
1236 if(pdn)
1237 name = (char*)pdn + pdn->wDeviceOffset;
1238 else if(pdm)
1239 name = pdm->dmDeviceName;
1240 PRINTDLG_SetUpPrinterListComboA(hDlg, comboID, name);
1241 if(pdm) GlobalUnlock(lppd->hDevMode);
1242 if(pdn) GlobalUnlock(lppd->hDevNames);
1244 /* Now find selected printer and update rest of dlg */
1245 name = HeapAlloc(GetProcessHeap(),0,256);
1246 if (GetDlgItemTextA(hDlg, comboID, name, 255))
1247 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1248 HeapFree(GetProcessHeap(),0,name);
1249 } else {
1250 /* else use default printer */
1251 char name[200];
1252 DWORD dwBufLen = sizeof(name);
1253 BOOL ret = GetDefaultPrinterA(name, &dwBufLen);
1255 if (ret)
1256 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1257 else
1258 FIXME("No default printer found, expect problems!\n");
1260 return TRUE;
1263 static LRESULT PRINTDLG_WMInitDialogW(HWND hDlg, WPARAM wParam,
1264 PRINT_PTRW* PrintStructures)
1266 const static WCHAR PD32_COLLATE[] = { 'P', 'D', '3', '2', '_', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
1267 const static WCHAR PD32_NOCOLLATE[] = { 'P', 'D', '3', '2', '_', 'N', 'O', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
1268 const static WCHAR PD32_PORTRAIT[] = { 'P', 'D', '3', '2', '_', 'P', 'O', 'R', 'T', 'R', 'A', 'I', 'T', 0 };
1269 const static WCHAR PD32_LANDSCAPE[] = { 'P', 'D', '3', '2', '_', 'L', 'A', 'N', 'D', 'S', 'C', 'A', 'P', 'E', 0 };
1270 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1271 DEVNAMES *pdn;
1272 DEVMODEW *pdm;
1273 WCHAR *name = NULL;
1274 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1276 /* load Collate ICONs */
1277 /* We load these with LoadImage because they are not a standard
1278 size and we don't want them rescaled */
1279 PrintStructures->hCollateIcon =
1280 LoadImageW(COMDLG32_hInstance, PD32_COLLATE, IMAGE_ICON, 0, 0, 0);
1281 PrintStructures->hNoCollateIcon =
1282 LoadImageW(COMDLG32_hInstance, PD32_NOCOLLATE, IMAGE_ICON, 0, 0, 0);
1284 /* These can be done with LoadIcon */
1285 PrintStructures->hPortraitIcon =
1286 LoadIconW(COMDLG32_hInstance, PD32_PORTRAIT);
1287 PrintStructures->hLandscapeIcon =
1288 LoadIconW(COMDLG32_hInstance, PD32_LANDSCAPE);
1290 /* display the collate/no_collate icon */
1291 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1292 (LPARAM)PrintStructures->hNoCollateIcon);
1294 if(PrintStructures->hCollateIcon == 0 ||
1295 PrintStructures->hNoCollateIcon == 0 ||
1296 PrintStructures->hPortraitIcon == 0 ||
1297 PrintStructures->hLandscapeIcon == 0) {
1298 ERR("no icon in resourcefile\n");
1299 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1300 EndDialog(hDlg, FALSE);
1304 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1305 * must be registered and the Help button must be shown.
1307 if (lppd->Flags & PD_SHOWHELP) {
1308 if((PrintStructures->HelpMessageID =
1309 RegisterWindowMessageW(HELPMSGSTRINGW)) == 0) {
1310 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1311 return FALSE;
1313 } else
1314 PrintStructures->HelpMessageID = 0;
1316 if(!(lppd->Flags &PD_PRINTSETUP)) {
1317 PrintStructures->hwndUpDown =
1318 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1319 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1320 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1321 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1322 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1325 /* FIXME: I allow more freedom than either Win95 or WinNT,
1326 * which do not agree to what errors should be thrown or not
1327 * in case nToPage or nFromPage is out-of-range.
1329 if (lppd->nMaxPage < lppd->nMinPage)
1330 lppd->nMaxPage = lppd->nMinPage;
1331 if (lppd->nMinPage == lppd->nMaxPage)
1332 lppd->Flags |= PD_NOPAGENUMS;
1333 if (lppd->nToPage < lppd->nMinPage)
1334 lppd->nToPage = lppd->nMinPage;
1335 if (lppd->nToPage > lppd->nMaxPage)
1336 lppd->nToPage = lppd->nMaxPage;
1337 if (lppd->nFromPage < lppd->nMinPage)
1338 lppd->nFromPage = lppd->nMinPage;
1339 if (lppd->nFromPage > lppd->nMaxPage)
1340 lppd->nFromPage = lppd->nMaxPage;
1342 /* if we have the combo box, fill it */
1343 if (GetDlgItem(hDlg,comboID)) {
1344 /* Fill Combobox
1346 pdn = GlobalLock(lppd->hDevNames);
1347 pdm = GlobalLock(lppd->hDevMode);
1348 if(pdn)
1349 name = (WCHAR*)pdn + pdn->wDeviceOffset;
1350 else if(pdm)
1351 name = pdm->dmDeviceName;
1352 PRINTDLG_SetUpPrinterListComboW(hDlg, comboID, name);
1353 if(pdm) GlobalUnlock(lppd->hDevMode);
1354 if(pdn) GlobalUnlock(lppd->hDevNames);
1356 /* Now find selected printer and update rest of dlg */
1357 /* ansi is ok here */
1358 name = HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR));
1359 if (GetDlgItemTextW(hDlg, comboID, name, 255))
1360 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1361 HeapFree(GetProcessHeap(),0,name);
1362 } else {
1363 /* else use default printer */
1364 WCHAR name[200];
1365 DWORD dwBufLen = sizeof(name) / sizeof(WCHAR);
1366 BOOL ret = GetDefaultPrinterW(name, &dwBufLen);
1368 if (ret)
1369 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1370 else
1371 FIXME("No default printer found, expect problems!\n");
1373 return TRUE;
1376 /***********************************************************************
1377 * PRINTDLG_WMCommand [internal]
1379 LRESULT PRINTDLG_WMCommandA(HWND hDlg, WPARAM wParam,
1380 LPARAM lParam, PRINT_PTRA* PrintStructures)
1382 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
1383 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1384 LPDEVMODEA lpdm = PrintStructures->lpDevMode;
1386 switch (LOWORD(wParam)) {
1387 case IDOK:
1388 TRACE(" OK button was hit\n");
1389 if (!PRINTDLG_UpdatePrintDlgA(hDlg, PrintStructures)) {
1390 FIXME("Update printdlg was not successful!\n");
1391 return(FALSE);
1393 EndDialog(hDlg, TRUE);
1394 return(TRUE);
1396 case IDCANCEL:
1397 TRACE(" CANCEL button was hit\n");
1398 EndDialog(hDlg, FALSE);
1399 return(FALSE);
1401 case pshHelp:
1402 TRACE(" HELP button was hit\n");
1403 SendMessageA(lppd->hwndOwner, PrintStructures->HelpMessageID,
1404 (WPARAM) hDlg, (LPARAM) lppd);
1405 break;
1407 case chx2: /* collate pages checkbox */
1408 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1409 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1410 (LPARAM)PrintStructures->hCollateIcon);
1411 else
1412 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1413 (LPARAM)PrintStructures->hNoCollateIcon);
1414 break;
1415 case edt1: /* from page nr editbox */
1416 case edt2: /* to page nr editbox */
1417 if (HIWORD(wParam)==EN_CHANGE) {
1418 WORD nToPage;
1419 WORD nFromPage;
1420 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1421 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1422 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1423 CheckRadioButton(hDlg, rad1, rad3, rad3);
1425 break;
1427 case edt3:
1428 if(HIWORD(wParam) == EN_CHANGE) {
1429 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1430 if(copies <= 1)
1431 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1432 else
1433 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1435 break;
1437 #if 0
1438 case psh1: /* Print Setup */
1440 PRINTDLG16 pdlg;
1442 if (!PrintStructures->dlg.lpPrintDlg16) {
1443 FIXME("The 32bit print dialog does not have this button!?\n");
1444 break;
1447 memcpy(&pdlg,PrintStructures->dlg.lpPrintDlg16,sizeof(pdlg));
1448 pdlg.Flags |= PD_PRINTSETUP;
1449 pdlg.hwndOwner = HWND_16(hDlg);
1450 if (!PrintDlg16(&pdlg))
1451 break;
1453 break;
1454 #endif
1455 case psh2: /* Properties button */
1457 HANDLE hPrinter;
1458 char PrinterName[256];
1460 GetDlgItemTextA(hDlg, PrinterComboID, PrinterName, 255);
1461 if (!OpenPrinterA(PrinterName, &hPrinter, NULL)) {
1462 FIXME(" Call to OpenPrinter did not succeed!\n");
1463 break;
1465 DocumentPropertiesA(hDlg, hPrinter, PrinterName,
1466 PrintStructures->lpDevMode,
1467 PrintStructures->lpDevMode,
1468 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1469 ClosePrinter(hPrinter);
1470 break;
1473 case rad1: /* Paperorientation */
1474 if (lppd->Flags & PD_PRINTSETUP)
1476 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1477 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1478 (LPARAM)(PrintStructures->hPortraitIcon));
1480 break;
1482 case rad2: /* Paperorientation */
1483 if (lppd->Flags & PD_PRINTSETUP)
1485 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1486 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1487 (LPARAM)(PrintStructures->hLandscapeIcon));
1489 break;
1491 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1492 if (PrinterComboID != LOWORD(wParam)) {
1493 FIXME("No handling for print quality combo box yet.\n");
1494 break;
1496 /* FALLTHROUGH */
1497 case cmb4: /* Printer combobox */
1498 if (HIWORD(wParam)==CBN_SELCHANGE) {
1499 char PrinterName[256];
1500 GetDlgItemTextA(hDlg, LOWORD(wParam), PrinterName, 255);
1501 PRINTDLG_ChangePrinterA(hDlg, PrinterName, PrintStructures);
1503 break;
1505 case cmb2: /* Papersize */
1507 DWORD Sel = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1508 if(Sel != CB_ERR)
1509 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
1510 CB_GETITEMDATA,
1511 Sel, 0);
1513 break;
1515 case cmb3: /* Bin */
1517 DWORD Sel = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1518 if(Sel != CB_ERR)
1519 lpdm->dmDefaultSource = SendDlgItemMessageA(hDlg, cmb3,
1520 CB_GETITEMDATA, Sel,
1523 break;
1525 if(lppd->Flags & PD_PRINTSETUP) {
1526 switch (LOWORD(wParam)) {
1527 case rad1: /* orientation */
1528 case rad2:
1529 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1530 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1531 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1532 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1533 (WPARAM)IMAGE_ICON,
1534 (LPARAM)PrintStructures->hPortraitIcon);
1535 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1536 (WPARAM)IMAGE_ICON,
1537 (LPARAM)PrintStructures->hPortraitIcon);
1539 } else {
1540 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1541 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1542 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1543 (WPARAM)IMAGE_ICON,
1544 (LPARAM)PrintStructures->hLandscapeIcon);
1545 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1546 (WPARAM)IMAGE_ICON,
1547 (LPARAM)PrintStructures->hLandscapeIcon);
1550 break;
1553 return FALSE;
1556 static LRESULT PRINTDLG_WMCommandW(HWND hDlg, WPARAM wParam,
1557 LPARAM lParam, PRINT_PTRW* PrintStructures)
1559 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1560 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1561 LPDEVMODEW lpdm = PrintStructures->lpDevMode;
1563 switch (LOWORD(wParam)) {
1564 case IDOK:
1565 TRACE(" OK button was hit\n");
1566 if (!PRINTDLG_UpdatePrintDlgW(hDlg, PrintStructures)) {
1567 FIXME("Update printdlg was not successful!\n");
1568 return(FALSE);
1570 EndDialog(hDlg, TRUE);
1571 return(TRUE);
1573 case IDCANCEL:
1574 TRACE(" CANCEL button was hit\n");
1575 EndDialog(hDlg, FALSE);
1576 return(FALSE);
1578 case pshHelp:
1579 TRACE(" HELP button was hit\n");
1580 SendMessageW(lppd->hwndOwner, PrintStructures->HelpMessageID,
1581 (WPARAM) hDlg, (LPARAM) lppd);
1582 break;
1584 case chx2: /* collate pages checkbox */
1585 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1586 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1587 (LPARAM)PrintStructures->hCollateIcon);
1588 else
1589 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1590 (LPARAM)PrintStructures->hNoCollateIcon);
1591 break;
1592 case edt1: /* from page nr editbox */
1593 case edt2: /* to page nr editbox */
1594 if (HIWORD(wParam)==EN_CHANGE) {
1595 WORD nToPage;
1596 WORD nFromPage;
1597 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1598 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1599 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1600 CheckRadioButton(hDlg, rad1, rad3, rad3);
1602 break;
1604 case edt3:
1605 if(HIWORD(wParam) == EN_CHANGE) {
1606 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1607 if(copies <= 1)
1608 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1609 else
1610 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1612 break;
1614 case psh1: /* Print Setup */
1616 ERR("psh1 is called from 16bit code only, we should not get here.\n");
1618 break;
1619 case psh2: /* Properties button */
1621 HANDLE hPrinter;
1622 WCHAR PrinterName[256];
1624 if (!GetDlgItemTextW(hDlg, PrinterComboID, PrinterName, 255)) break;
1625 if (!OpenPrinterW(PrinterName, &hPrinter, NULL)) {
1626 FIXME(" Call to OpenPrinter did not succeed!\n");
1627 break;
1629 DocumentPropertiesW(hDlg, hPrinter, PrinterName,
1630 PrintStructures->lpDevMode,
1631 PrintStructures->lpDevMode,
1632 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1633 ClosePrinter(hPrinter);
1634 break;
1637 case rad1: /* Paperorientation */
1638 if (lppd->Flags & PD_PRINTSETUP)
1640 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1641 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1642 (LPARAM)(PrintStructures->hPortraitIcon));
1644 break;
1646 case rad2: /* Paperorientation */
1647 if (lppd->Flags & PD_PRINTSETUP)
1649 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1650 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1651 (LPARAM)(PrintStructures->hLandscapeIcon));
1653 break;
1655 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1656 if (PrinterComboID != LOWORD(wParam)) {
1657 FIXME("No handling for print quality combo box yet.\n");
1658 break;
1660 /* FALLTHROUGH */
1661 case cmb4: /* Printer combobox */
1662 if (HIWORD(wParam)==CBN_SELCHANGE) {
1663 WCHAR PrinterName[256];
1664 GetDlgItemTextW(hDlg, LOWORD(wParam), PrinterName, 255);
1665 PRINTDLG_ChangePrinterW(hDlg, PrinterName, PrintStructures);
1667 break;
1669 case cmb2: /* Papersize */
1671 DWORD Sel = SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1672 if(Sel != CB_ERR)
1673 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageW(hDlg, cmb2,
1674 CB_GETITEMDATA,
1675 Sel, 0);
1677 break;
1679 case cmb3: /* Bin */
1681 DWORD Sel = SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1682 if(Sel != CB_ERR)
1683 lpdm->dmDefaultSource = SendDlgItemMessageW(hDlg, cmb3,
1684 CB_GETITEMDATA, Sel,
1687 break;
1689 if(lppd->Flags & PD_PRINTSETUP) {
1690 switch (LOWORD(wParam)) {
1691 case rad1: /* orientation */
1692 case rad2:
1693 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1694 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1695 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1696 SendDlgItemMessageW(hDlg, stc10, STM_SETIMAGE,
1697 (WPARAM)IMAGE_ICON,
1698 (LPARAM)PrintStructures->hPortraitIcon);
1699 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE,
1700 (WPARAM)IMAGE_ICON,
1701 (LPARAM)PrintStructures->hPortraitIcon);
1703 } else {
1704 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1705 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1706 SendDlgItemMessageW(hDlg, stc10, STM_SETIMAGE,
1707 (WPARAM)IMAGE_ICON,
1708 (LPARAM)PrintStructures->hLandscapeIcon);
1709 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE,
1710 (WPARAM)IMAGE_ICON,
1711 (LPARAM)PrintStructures->hLandscapeIcon);
1714 break;
1717 return FALSE;
1720 /***********************************************************************
1721 * PrintDlgProcA [internal]
1723 static INT_PTR CALLBACK PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
1724 LPARAM lParam)
1726 PRINT_PTRA* PrintStructures;
1727 INT_PTR res = FALSE;
1729 if (uMsg!=WM_INITDIALOG) {
1730 PrintStructures = (PRINT_PTRA*)GetPropA(hDlg,"__WINE_PRINTDLGDATA");
1731 if (!PrintStructures)
1732 return FALSE;
1733 } else {
1734 PrintStructures = (PRINT_PTRA*) lParam;
1735 SetPropA(hDlg,"__WINE_PRINTDLGDATA",PrintStructures);
1736 res = PRINTDLG_WMInitDialog(hDlg, wParam, PrintStructures);
1738 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
1739 res = PrintStructures->lpPrintDlg->lpfnPrintHook(
1740 hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg
1742 return res;
1745 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
1746 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam,
1747 lParam);
1748 if(res) return res;
1751 switch (uMsg) {
1752 case WM_COMMAND:
1753 return PRINTDLG_WMCommandA(hDlg, wParam, lParam, PrintStructures);
1755 case WM_DESTROY:
1756 DestroyIcon(PrintStructures->hCollateIcon);
1757 DestroyIcon(PrintStructures->hNoCollateIcon);
1758 DestroyIcon(PrintStructures->hPortraitIcon);
1759 DestroyIcon(PrintStructures->hLandscapeIcon);
1760 if(PrintStructures->hwndUpDown)
1761 DestroyWindow(PrintStructures->hwndUpDown);
1762 return FALSE;
1764 return res;
1767 static INT_PTR CALLBACK PrintDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
1768 LPARAM lParam)
1770 static const WCHAR propW[] = {'_','_','W','I','N','E','_','P','R','I','N','T','D','L','G','D','A','T','A',0};
1771 PRINT_PTRW* PrintStructures;
1772 INT_PTR res = FALSE;
1774 if (uMsg!=WM_INITDIALOG) {
1775 PrintStructures = (PRINT_PTRW*) GetPropW(hDlg, propW);
1776 if (!PrintStructures)
1777 return FALSE;
1778 } else {
1779 PrintStructures = (PRINT_PTRW*) lParam;
1780 SetPropW(hDlg, propW, PrintStructures);
1781 res = PRINTDLG_WMInitDialogW(hDlg, wParam, PrintStructures);
1783 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
1784 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg);
1785 return res;
1788 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
1789 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam, lParam);
1790 if(res) return res;
1793 switch (uMsg) {
1794 case WM_COMMAND:
1795 return PRINTDLG_WMCommandW(hDlg, wParam, lParam, PrintStructures);
1797 case WM_DESTROY:
1798 DestroyIcon(PrintStructures->hCollateIcon);
1799 DestroyIcon(PrintStructures->hNoCollateIcon);
1800 DestroyIcon(PrintStructures->hPortraitIcon);
1801 DestroyIcon(PrintStructures->hLandscapeIcon);
1802 if(PrintStructures->hwndUpDown)
1803 DestroyWindow(PrintStructures->hwndUpDown);
1804 return FALSE;
1806 return res;
1809 /************************************************************
1811 * PRINTDLG_GetDlgTemplate
1814 static HGLOBAL PRINTDLG_GetDlgTemplateA(PRINTDLGA *lppd)
1816 HRSRC hResInfo;
1817 HGLOBAL hDlgTmpl;
1819 if (lppd->Flags & PD_PRINTSETUP) {
1820 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
1821 hDlgTmpl = lppd->hSetupTemplate;
1822 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
1823 hResInfo = FindResourceA(lppd->hInstance,
1824 lppd->lpSetupTemplateName, (LPSTR)RT_DIALOG);
1825 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1826 } else {
1827 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32_SETUP",
1828 (LPSTR)RT_DIALOG);
1829 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1831 } else {
1832 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
1833 hDlgTmpl = lppd->hPrintTemplate;
1834 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
1835 hResInfo = FindResourceA(lppd->hInstance,
1836 lppd->lpPrintTemplateName,
1837 (LPSTR)RT_DIALOG);
1838 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1839 } else {
1840 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32",
1841 (LPSTR)RT_DIALOG);
1842 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1845 return hDlgTmpl;
1848 static HGLOBAL PRINTDLG_GetDlgTemplateW(PRINTDLGW *lppd)
1850 HRSRC hResInfo;
1851 HGLOBAL hDlgTmpl;
1852 static const WCHAR xpsetup[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
1853 static const WCHAR xprint[] = { 'P','R','I','N','T','3','2',0};
1855 if (lppd->Flags & PD_PRINTSETUP) {
1856 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
1857 hDlgTmpl = lppd->hSetupTemplate;
1858 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
1859 hResInfo = FindResourceW(lppd->hInstance,
1860 lppd->lpSetupTemplateName, (LPWSTR)RT_DIALOG);
1861 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1862 } else {
1863 hResInfo = FindResourceW(COMDLG32_hInstance, xpsetup, (LPWSTR)RT_DIALOG);
1864 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1866 } else {
1867 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
1868 hDlgTmpl = lppd->hPrintTemplate;
1869 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
1870 hResInfo = FindResourceW(lppd->hInstance,
1871 lppd->lpPrintTemplateName,
1872 (LPWSTR)RT_DIALOG);
1873 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1874 } else {
1875 hResInfo = FindResourceW(COMDLG32_hInstance, xprint, (LPWSTR)RT_DIALOG);
1876 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1879 return hDlgTmpl;
1882 /***********************************************************************
1884 * PRINTDLG_CreateDC
1887 static BOOL PRINTDLG_CreateDCA(LPPRINTDLGA lppd)
1889 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
1890 DEVMODEA *pdm = GlobalLock(lppd->hDevMode);
1892 if(lppd->Flags & PD_RETURNDC) {
1893 lppd->hDC = CreateDCA((char*)pdn + pdn->wDriverOffset,
1894 (char*)pdn + pdn->wDeviceOffset,
1895 (char*)pdn + pdn->wOutputOffset,
1896 pdm );
1897 } else if(lppd->Flags & PD_RETURNIC) {
1898 lppd->hDC = CreateICA((char*)pdn + pdn->wDriverOffset,
1899 (char*)pdn + pdn->wDeviceOffset,
1900 (char*)pdn + pdn->wOutputOffset,
1901 pdm );
1903 GlobalUnlock(lppd->hDevNames);
1904 GlobalUnlock(lppd->hDevMode);
1905 return lppd->hDC ? TRUE : FALSE;
1908 static BOOL PRINTDLG_CreateDCW(LPPRINTDLGW lppd)
1910 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
1911 DEVMODEW *pdm = GlobalLock(lppd->hDevMode);
1913 if(lppd->Flags & PD_RETURNDC) {
1914 lppd->hDC = CreateDCW((WCHAR*)pdn + pdn->wDriverOffset,
1915 (WCHAR*)pdn + pdn->wDeviceOffset,
1916 (WCHAR*)pdn + pdn->wOutputOffset,
1917 pdm );
1918 } else if(lppd->Flags & PD_RETURNIC) {
1919 lppd->hDC = CreateICW((WCHAR*)pdn + pdn->wDriverOffset,
1920 (WCHAR*)pdn + pdn->wDeviceOffset,
1921 (WCHAR*)pdn + pdn->wOutputOffset,
1922 pdm );
1924 GlobalUnlock(lppd->hDevNames);
1925 GlobalUnlock(lppd->hDevMode);
1926 return lppd->hDC ? TRUE : FALSE;
1929 /***********************************************************************
1930 * PrintDlgA (COMDLG32.@)
1932 * Displays the the PRINT dialog box, which enables the user to specify
1933 * specific properties of the print job.
1935 * RETURNS
1936 * nonzero if the user pressed the OK button
1937 * zero if the user cancelled the window or an error occurred
1939 * BUGS
1940 * PrintDlg:
1941 * * The Collate Icons do not display, even though they are in the code.
1942 * * The Properties Button(s) should call DocumentPropertiesA().
1943 * PrintSetupDlg:
1944 * * The Paper Orientation Icons are not implemented yet.
1945 * * The Properties Button(s) should call DocumentPropertiesA().
1946 * * Settings are not yet taken from a provided DevMode or
1947 * default printer settings.
1950 BOOL WINAPI PrintDlgA(
1951 LPPRINTDLGA lppd /* [in/out] ptr to PRINTDLG32 struct */
1954 BOOL bRet = FALSE;
1955 LPVOID ptr;
1956 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrA( lppd->hwndOwner, GWLP_HINSTANCE );
1958 if(TRACE_ON(commdlg)) {
1959 char flagstr[1000] = "";
1960 struct pd_flags *pflag = pd_flags;
1961 for( ; pflag->name; pflag++) {
1962 if(lppd->Flags & pflag->flag)
1963 strcat(flagstr, pflag->name);
1965 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
1966 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
1967 "flags %08lx (%s)\n",
1968 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
1969 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
1970 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
1973 if(lppd->lStructSize != sizeof(PRINTDLGA)) {
1974 WARN("structure size failure !!!\n");
1975 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
1976 return FALSE;
1979 if(lppd->Flags & PD_RETURNDEFAULT) {
1980 PRINTER_INFO_2A *pbuf;
1981 DRIVER_INFO_3A *dbuf;
1982 HANDLE hprn;
1983 DWORD needed;
1985 if(lppd->hDevMode || lppd->hDevNames) {
1986 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
1987 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
1988 return FALSE;
1990 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
1991 WARN("Can't find default printer\n");
1992 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
1993 return FALSE;
1996 GetPrinterA(hprn, 2, NULL, 0, &needed);
1997 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
1998 GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2000 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
2001 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
2002 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2003 ERR("GetPrinterDriverA failed, le %ld, fix your config for printer %s!\n",GetLastError(),pbuf->pPrinterName);
2004 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2005 return FALSE;
2007 ClosePrinter(hprn);
2009 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2010 dbuf->pDriverPath,
2011 pbuf->pPrinterName,
2012 pbuf->pPortName);
2013 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2014 pbuf->pDevMode->dmDriverExtra);
2015 ptr = GlobalLock(lppd->hDevMode);
2016 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2017 pbuf->pDevMode->dmDriverExtra);
2018 GlobalUnlock(lppd->hDevMode);
2019 HeapFree(GetProcessHeap(), 0, pbuf);
2020 HeapFree(GetProcessHeap(), 0, dbuf);
2021 bRet = TRUE;
2022 } else {
2023 HGLOBAL hDlgTmpl;
2024 PRINT_PTRA *PrintStructures;
2026 /* load Dialog resources,
2027 * depending on Flags indicates Print32 or Print32_setup dialog
2029 hDlgTmpl = PRINTDLG_GetDlgTemplateA(lppd);
2030 if (!hDlgTmpl) {
2031 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2032 return FALSE;
2034 ptr = LockResource( hDlgTmpl );
2035 if (!ptr) {
2036 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2037 return FALSE;
2040 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2041 sizeof(PRINT_PTRA));
2042 PrintStructures->lpPrintDlg = lppd;
2044 /* and create & process the dialog .
2045 * -1 is failure, 0 is broken hwnd, everything else is ok.
2047 bRet = (0<DialogBoxIndirectParamA(hInst, ptr, lppd->hwndOwner,
2048 PrintDlgProcA,
2049 (LPARAM)PrintStructures));
2051 if(bRet) {
2052 DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2053 PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
2054 DRIVER_INFO_3A *di = PrintStructures->lpDriverInfo;
2056 if (lppd->hDevMode == 0) {
2057 TRACE(" No hDevMode yet... Need to create my own\n");
2058 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2059 lpdm->dmSize + lpdm->dmDriverExtra);
2060 } else {
2061 WORD locks;
2062 if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
2063 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2064 while(locks--) {
2065 GlobalUnlock(lppd->hDevMode);
2066 TRACE("Now got %d locks\n", locks);
2069 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2070 lpdm->dmSize + lpdm->dmDriverExtra,
2071 GMEM_MOVEABLE);
2073 lpdmReturn = GlobalLock(lppd->hDevMode);
2074 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2076 if (lppd->hDevNames != 0) {
2077 WORD locks;
2078 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
2079 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2080 while(locks--)
2081 GlobalUnlock(lppd->hDevNames);
2084 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2085 di->pDriverPath,
2086 pi->pPrinterName,
2087 pi->pPortName
2089 GlobalUnlock(lppd->hDevMode);
2091 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2092 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2093 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2094 HeapFree(GetProcessHeap(), 0, PrintStructures);
2096 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2097 bRet = PRINTDLG_CreateDCA(lppd);
2099 TRACE("exit! (%d)\n", bRet);
2100 return bRet;
2103 /***********************************************************************
2104 * PrintDlgW (COMDLG32.@)
2106 BOOL WINAPI PrintDlgW(
2107 LPPRINTDLGW lppd /* [in/out] ptr to PRINTDLG32 struct */
2110 BOOL bRet = FALSE;
2111 LPVOID ptr;
2112 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW( lppd->hwndOwner, GWLP_HINSTANCE );
2114 if(TRACE_ON(commdlg)) {
2115 char flagstr[1000] = "";
2116 struct pd_flags *pflag = pd_flags;
2117 for( ; pflag->name; pflag++) {
2118 if(lppd->Flags & pflag->flag)
2119 strcat(flagstr, pflag->name);
2121 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2122 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2123 "flags %08lx (%s)\n",
2124 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2125 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2126 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2129 if(lppd->lStructSize != sizeof(PRINTDLGW)) {
2130 WARN("structure size failure !!!\n");
2131 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2132 return FALSE;
2135 if(lppd->Flags & PD_RETURNDEFAULT) {
2136 PRINTER_INFO_2W *pbuf;
2137 DRIVER_INFO_3W *dbuf;
2138 HANDLE hprn;
2139 DWORD needed;
2141 if(lppd->hDevMode || lppd->hDevNames) {
2142 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2143 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2144 return FALSE;
2146 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2147 WARN("Can't find default printer\n");
2148 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2149 return FALSE;
2152 GetPrinterW(hprn, 2, NULL, 0, &needed);
2153 pbuf = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*needed);
2154 GetPrinterW(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2156 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
2157 dbuf = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
2158 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2159 ERR("GetPrinterDriverA failed, le %ld, fix your config for printer %s!\n",GetLastError(),debugstr_w(pbuf->pPrinterName));
2160 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2161 return FALSE;
2163 ClosePrinter(hprn);
2165 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2166 dbuf->pDriverPath,
2167 pbuf->pPrinterName,
2168 pbuf->pPortName);
2169 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2170 pbuf->pDevMode->dmDriverExtra);
2171 ptr = GlobalLock(lppd->hDevMode);
2172 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2173 pbuf->pDevMode->dmDriverExtra);
2174 GlobalUnlock(lppd->hDevMode);
2175 HeapFree(GetProcessHeap(), 0, pbuf);
2176 HeapFree(GetProcessHeap(), 0, dbuf);
2177 bRet = TRUE;
2178 } else {
2179 HGLOBAL hDlgTmpl;
2180 PRINT_PTRW *PrintStructures;
2182 /* load Dialog resources,
2183 * depending on Flags indicates Print32 or Print32_setup dialog
2185 hDlgTmpl = PRINTDLG_GetDlgTemplateW(lppd);
2186 if (!hDlgTmpl) {
2187 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2188 return FALSE;
2190 ptr = LockResource( hDlgTmpl );
2191 if (!ptr) {
2192 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2193 return FALSE;
2196 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2197 sizeof(PRINT_PTRW));
2198 PrintStructures->lpPrintDlg = lppd;
2200 /* and create & process the dialog .
2201 * -1 is failure, 0 is broken hwnd, everything else is ok.
2203 bRet = (0<DialogBoxIndirectParamW(hInst, ptr, lppd->hwndOwner,
2204 PrintDlgProcW,
2205 (LPARAM)PrintStructures));
2207 if(bRet) {
2208 DEVMODEW *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2209 PRINTER_INFO_2W *pi = PrintStructures->lpPrinterInfo;
2210 DRIVER_INFO_3W *di = PrintStructures->lpDriverInfo;
2212 if (lppd->hDevMode == 0) {
2213 TRACE(" No hDevMode yet... Need to create my own\n");
2214 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2215 lpdm->dmSize + lpdm->dmDriverExtra);
2216 } else {
2217 WORD locks;
2218 if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
2219 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2220 while(locks--) {
2221 GlobalUnlock(lppd->hDevMode);
2222 TRACE("Now got %d locks\n", locks);
2225 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2226 lpdm->dmSize + lpdm->dmDriverExtra,
2227 GMEM_MOVEABLE);
2229 lpdmReturn = GlobalLock(lppd->hDevMode);
2230 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2232 if (lppd->hDevNames != 0) {
2233 WORD locks;
2234 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
2235 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2236 while(locks--)
2237 GlobalUnlock(lppd->hDevNames);
2240 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2241 di->pDriverPath,
2242 pi->pPrinterName,
2243 pi->pPortName
2245 GlobalUnlock(lppd->hDevMode);
2247 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2248 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2249 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2250 HeapFree(GetProcessHeap(), 0, PrintStructures);
2252 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2253 bRet = PRINTDLG_CreateDCW(lppd);
2255 TRACE("exit! (%d)\n", bRet);
2256 return bRet;
2259 /***********************************************************************
2261 * PageSetupDlg
2262 * rad1 - portrait
2263 * rad2 - landscape
2264 * cmb2 - paper size
2265 * cmb3 - source (tray?)
2266 * edt4 - border left
2267 * edt5 - border top
2268 * edt6 - border right
2269 * edt7 - border bottom
2270 * psh3 - "Printer..."
2273 typedef struct {
2274 LPPAGESETUPDLGA dlga;
2275 PRINTDLGA pdlg;
2276 } PageSetupDataA;
2278 typedef struct {
2279 LPPAGESETUPDLGW dlga;
2280 PRINTDLGW pdlg;
2281 } PageSetupDataW;
2283 static HGLOBAL PRINTDLG_GetPGSTemplateA(PAGESETUPDLGA *lppd)
2285 HRSRC hResInfo;
2286 HGLOBAL hDlgTmpl;
2288 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2289 hDlgTmpl = lppd->hPageSetupTemplate;
2290 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2291 hResInfo = FindResourceA(lppd->hInstance,
2292 lppd->lpPageSetupTemplateName, (LPSTR)RT_DIALOG);
2293 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2294 } else {
2295 hResInfo = FindResourceA(COMDLG32_hInstance,(LPCSTR)PAGESETUPDLGORD,(LPSTR)RT_DIALOG);
2296 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2298 return hDlgTmpl;
2301 static HGLOBAL PRINTDLG_GetPGSTemplateW(PAGESETUPDLGW *lppd)
2303 HRSRC hResInfo;
2304 HGLOBAL hDlgTmpl;
2306 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2307 hDlgTmpl = lppd->hPageSetupTemplate;
2308 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2309 hResInfo = FindResourceW(lppd->hInstance,
2310 lppd->lpPageSetupTemplateName, (LPWSTR)RT_DIALOG);
2311 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2312 } else {
2313 hResInfo = FindResourceW(COMDLG32_hInstance,(LPCWSTR)PAGESETUPDLGORD,(LPWSTR)RT_DIALOG);
2314 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2316 return hDlgTmpl;
2319 static DWORD
2320 _c_10mm2size(PAGESETUPDLGA *dlga,DWORD size) {
2321 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2322 return 10*size*10/25.4;
2323 /* If we don't have a flag, we can choose one. Use millimeters
2324 * to avoid confusing me
2326 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2327 return 10*size;
2331 static DWORD
2332 _c_inch2size(PAGESETUPDLGA *dlga,DWORD size) {
2333 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2334 return size;
2335 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
2336 return (size*254)/10;
2337 /* if we don't have a flag, we can choose one. Use millimeters
2338 * to avoid confusing me
2340 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2341 return (size*254)/10;
2344 static void
2345 _c_size2strA(PageSetupDataA *pda,DWORD size,LPSTR strout) {
2346 strcpy(strout,"<undef>");
2347 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2348 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
2349 return;
2351 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2352 sprintf(strout,"%.2fin",(size*1.0)/1000.0);
2353 return;
2355 pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2356 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
2357 return;
2359 static void
2360 _c_size2strW(PageSetupDataW *pda,DWORD size,LPWSTR strout) {
2361 const static WCHAR UNDEF[] = { '<', 'u', 'n', 'd', 'e', 'f', '>', 0 };
2362 const static WCHAR mm_fmt[] = { '%', '.', '2', 'f', 'm', 'm', 0 };
2363 const static WCHAR in_fmt[] = { '%', '.', '2', 'f', 'i', 'n', 0 };
2364 lstrcpyW(strout, UNDEF);
2365 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2366 wsprintfW(strout,mm_fmt,(size*1.0)/100.0);
2367 return;
2369 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2370 wsprintfW(strout,in_fmt,(size*1.0)/1000.0);
2371 return;
2373 pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2374 wsprintfW(strout,mm_fmt,(size*1.0)/100.0);
2375 return;
2378 static DWORD
2379 _c_str2sizeA(PAGESETUPDLGA *dlga,LPCSTR strin) {
2380 float val;
2381 char rest[200];
2383 rest[0]='\0';
2384 if (!sscanf(strin,"%f%s",&val,rest))
2385 return 0;
2387 if (!strcmp(rest,"in") || !strcmp(rest,"inch")) {
2388 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2389 return 1000*val;
2390 else
2391 return val*25.4*100;
2393 if (!strcmp(rest,"cm")) { rest[0]='m'; val = val*10.0; }
2394 if (!strcmp(rest,"m")) { strcpy(rest,"mm"); val = val*1000.0; }
2396 if (!strcmp(rest,"mm")) {
2397 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
2398 return 100*val;
2399 else
2400 return 1000.0*val/25.4;
2402 if (rest[0]=='\0') {
2403 /* use application supplied default */
2404 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2405 /* 100*mm */
2406 return 100.0*val;
2408 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2409 /* 1000*inch */
2410 return 1000.0*val;
2413 ERR("Did not find a conversion for type '%s'!\n",rest);
2414 return 0;
2418 static DWORD
2419 _c_str2sizeW(PAGESETUPDLGW *dlga, LPCWSTR strin) {
2420 char buf[200];
2422 /* this W -> A transition is OK */
2423 /* we need a unicode version of sscanf to avoid it */
2424 WideCharToMultiByte(CP_ACP, 0, strin, -1, buf, sizeof(buf), NULL, NULL);
2425 return _c_str2sizeA((PAGESETUPDLGA *)dlga, buf);
2430 * This is called on finish and will update the output fields of the
2431 * struct.
2433 static BOOL
2434 PRINTDLG_PS_UpdateDlgStructA(HWND hDlg, PageSetupDataA *pda) {
2435 DEVNAMES *dn;
2436 DEVMODEA *dm;
2437 LPSTR devname,portname;
2438 char papername[64];
2439 char buf[200];
2441 dn = GlobalLock(pda->pdlg.hDevNames);
2442 dm = GlobalLock(pda->pdlg.hDevMode);
2443 devname = ((char*)dn)+dn->wDeviceOffset;
2444 portname = ((char*)dn)+dn->wOutputOffset;
2445 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb2,devname,portname,dm);
2446 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb3,devname,portname,dm);
2448 if (GetDlgItemTextA(hDlg,cmb2,papername,sizeof(papername))>0) {
2449 PRINTDLG_PaperSizeA(&(pda->pdlg),papername,&(pda->dlga->ptPaperSize));
2450 pda->dlga->ptPaperSize.x = _c_10mm2size(pda->dlga,pda->dlga->ptPaperSize.x);
2451 pda->dlga->ptPaperSize.y = _c_10mm2size(pda->dlga,pda->dlga->ptPaperSize.y);
2452 } else
2453 FIXME("could not get dialog text for papersize cmbbox?\n");
2454 #define GETVAL(id,val) if (GetDlgItemTextA(hDlg,id,buf,sizeof(buf))>0) { val = _c_str2sizeA(pda->dlga,buf); } else { FIXME("could not get dlgitemtexta for %x\n",id); }
2455 GETVAL(edt4,pda->dlga->rtMargin.left);
2456 GETVAL(edt5,pda->dlga->rtMargin.top);
2457 GETVAL(edt6,pda->dlga->rtMargin.right);
2458 GETVAL(edt7,pda->dlga->rtMargin.bottom);
2459 #undef GETVAL
2461 /* If we are in landscape, swap x and y of page size */
2462 if (IsDlgButtonChecked(hDlg, rad2)) {
2463 DWORD tmp;
2464 tmp = pda->dlga->ptPaperSize.x;
2465 pda->dlga->ptPaperSize.x = pda->dlga->ptPaperSize.y;
2466 pda->dlga->ptPaperSize.y = tmp;
2468 GlobalUnlock(pda->pdlg.hDevNames);
2469 GlobalUnlock(pda->pdlg.hDevMode);
2470 return TRUE;
2473 static BOOL
2474 PRINTDLG_PS_UpdateDlgStructW(HWND hDlg, PageSetupDataW *pda) {
2475 DEVNAMES *dn;
2476 DEVMODEW *dm;
2477 LPWSTR devname,portname;
2478 WCHAR papername[64];
2479 WCHAR buf[200];
2481 dn = GlobalLock(pda->pdlg.hDevNames);
2482 dm = GlobalLock(pda->pdlg.hDevMode);
2483 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
2484 portname = ((WCHAR*)dn)+dn->wOutputOffset;
2485 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
2486 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
2488 if (GetDlgItemTextW(hDlg,cmb2,papername,sizeof(papername))>0) {
2489 PRINTDLG_PaperSizeW(&(pda->pdlg),papername,&(pda->dlga->ptPaperSize));
2490 pda->dlga->ptPaperSize.x = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga,pda->dlga->ptPaperSize.x);
2491 pda->dlga->ptPaperSize.y = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga,pda->dlga->ptPaperSize.y);
2492 } else
2493 FIXME("could not get dialog text for papersize cmbbox?\n");
2494 #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); }
2495 GETVAL(edt4,pda->dlga->rtMargin.left);
2496 GETVAL(edt5,pda->dlga->rtMargin.top);
2497 GETVAL(edt6,pda->dlga->rtMargin.right);
2498 GETVAL(edt7,pda->dlga->rtMargin.bottom);
2499 #undef GETVAL
2501 /* If we are in landscape, swap x and y of page size */
2502 if (IsDlgButtonChecked(hDlg, rad2)) {
2503 DWORD tmp;
2504 tmp = pda->dlga->ptPaperSize.x;
2505 pda->dlga->ptPaperSize.x = pda->dlga->ptPaperSize.y;
2506 pda->dlga->ptPaperSize.y = tmp;
2508 GlobalUnlock(pda->pdlg.hDevNames);
2509 GlobalUnlock(pda->pdlg.hDevMode);
2510 return TRUE;
2514 * This is called after returning from PrintDlg().
2516 static BOOL
2517 PRINTDLG_PS_ChangePrinterA(HWND hDlg, PageSetupDataA *pda) {
2518 DEVNAMES *dn;
2519 DEVMODEA *dm;
2520 LPSTR devname,portname;
2522 dn = GlobalLock(pda->pdlg.hDevNames);
2523 dm = GlobalLock(pda->pdlg.hDevMode);
2524 devname = ((char*)dn)+dn->wDeviceOffset;
2525 portname = ((char*)dn)+dn->wOutputOffset;
2526 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb2,devname,portname,dm);
2527 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb3,devname,portname,dm);
2528 GlobalUnlock(pda->pdlg.hDevNames);
2529 GlobalUnlock(pda->pdlg.hDevMode);
2530 return TRUE;
2533 static BOOL
2534 PRINTDLG_PS_ChangePrinterW(HWND hDlg, PageSetupDataW *pda) {
2535 DEVNAMES *dn;
2536 DEVMODEW *dm;
2537 LPWSTR devname,portname;
2539 dn = GlobalLock(pda->pdlg.hDevNames);
2540 dm = GlobalLock(pda->pdlg.hDevMode);
2541 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
2542 portname = ((WCHAR*)dn)+dn->wOutputOffset;
2543 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
2544 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
2545 GlobalUnlock(pda->pdlg.hDevNames);
2546 GlobalUnlock(pda->pdlg.hDevMode);
2547 return TRUE;
2550 static BOOL
2551 PRINTDLG_PS_WMCommandA(
2552 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataA *pda
2554 switch (LOWORD(wParam)) {
2555 case IDOK:
2556 if (!PRINTDLG_PS_UpdateDlgStructA(hDlg, pda))
2557 return(FALSE);
2558 EndDialog(hDlg, TRUE);
2559 return TRUE ;
2561 case IDCANCEL:
2562 EndDialog(hDlg, FALSE);
2563 return FALSE ;
2565 case psh3: {
2566 pda->pdlg.Flags = 0;
2567 pda->pdlg.hwndOwner = hDlg;
2568 if (PrintDlgA(&(pda->pdlg)))
2569 PRINTDLG_PS_ChangePrinterA(hDlg,pda);
2570 return TRUE;
2573 FIXME("loword (lparam) %d, wparam 0x%x, lparam %08lx, STUB mostly.\n",
2574 LOWORD(lParam),wParam,lParam
2576 return FALSE;
2579 static BOOL
2580 PRINTDLG_PS_WMCommandW(
2581 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataW *pda
2583 switch (LOWORD(wParam)) {
2584 case IDOK:
2585 if (!PRINTDLG_PS_UpdateDlgStructW(hDlg, pda))
2586 return(FALSE);
2587 EndDialog(hDlg, TRUE);
2588 return TRUE ;
2590 case IDCANCEL:
2591 EndDialog(hDlg, FALSE);
2592 return FALSE ;
2594 case psh3: {
2595 pda->pdlg.Flags = 0;
2596 pda->pdlg.hwndOwner = hDlg;
2597 if (PrintDlgW(&(pda->pdlg)))
2598 PRINTDLG_PS_ChangePrinterW(hDlg,pda);
2599 return TRUE;
2602 FIXME("loword (lparam) %d, wparam 0x%x, lparam %08lx, STUB mostly.\n",
2603 LOWORD(lParam),wParam,lParam
2605 return FALSE;
2609 static INT_PTR CALLBACK
2610 PageDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
2612 PageSetupDataA *pda;
2613 INT_PTR res = FALSE;
2615 if (uMsg==WM_INITDIALOG) {
2616 res = TRUE;
2617 pda = (PageSetupDataA*)lParam;
2618 SetPropA(hDlg,"__WINE_PAGESETUPDLGDATA",pda);
2619 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
2620 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,(LPARAM)pda->dlga);
2621 if (!res) {
2622 FIXME("Setup page hook failed?\n");
2623 res = TRUE;
2626 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK) {
2627 FIXME("PagePaintHook not yet implemented!\n");
2629 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
2630 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
2631 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
2632 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
2633 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
2634 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
2635 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
2637 /* width larger as height -> landscape */
2638 if (pda->dlga->ptPaperSize.x > pda->dlga->ptPaperSize.y)
2639 CheckRadioButton(hDlg, rad1, rad2, rad2);
2640 else /* this is default if papersize is not set */
2641 CheckRadioButton(hDlg, rad1, rad2, rad1);
2642 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
2643 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
2644 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
2646 /* We fill them out enabled or not */
2647 if (pda->dlga->Flags & PSD_MARGINS) {
2648 char str[100];
2649 _c_size2strA(pda,pda->dlga->rtMargin.left,str);
2650 SetDlgItemTextA(hDlg,edt4,str);
2651 _c_size2strA(pda,pda->dlga->rtMargin.top,str);
2652 SetDlgItemTextA(hDlg,edt5,str);
2653 _c_size2strA(pda,pda->dlga->rtMargin.right,str);
2654 SetDlgItemTextA(hDlg,edt6,str);
2655 _c_size2strA(pda,pda->dlga->rtMargin.bottom,str);
2656 SetDlgItemTextA(hDlg,edt7,str);
2657 } else {
2658 /* default is 1 inch */
2659 DWORD size = _c_inch2size(pda->dlga,1000);
2660 char str[20];
2661 _c_size2strA(pda,size,str);
2662 SetDlgItemTextA(hDlg,edt4,str);
2663 SetDlgItemTextA(hDlg,edt5,str);
2664 SetDlgItemTextA(hDlg,edt6,str);
2665 SetDlgItemTextA(hDlg,edt7,str);
2667 PRINTDLG_PS_ChangePrinterA(hDlg,pda);
2668 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
2669 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
2670 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
2672 return TRUE;
2673 } else {
2674 pda = (PageSetupDataA*)GetPropA(hDlg,"__WINE_PAGESETUPDLGDATA");
2675 if (!pda) {
2676 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
2677 return FALSE;
2679 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
2680 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
2681 if (res) return res;
2684 switch (uMsg) {
2685 case WM_COMMAND:
2686 return PRINTDLG_PS_WMCommandA(hDlg, wParam, lParam, pda);
2688 return FALSE;
2691 static INT_PTR CALLBACK
2692 PageDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
2694 const static WCHAR __WINE_PAGESETUPDLGDATA[] =
2695 { '_', '_', 'W', 'I', 'N', 'E', '_', 'P', 'A', 'G', 'E',
2696 'S', 'E', 'T', 'U', 'P', 'D', 'L', 'G', 'D', 'A', 'T', 'A', 0 };
2697 PageSetupDataW *pda;
2698 BOOL res = FALSE;
2700 if (uMsg==WM_INITDIALOG) {
2701 res = TRUE;
2702 pda = (PageSetupDataW*)lParam;
2703 SetPropW(hDlg, __WINE_PAGESETUPDLGDATA, pda);
2704 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
2705 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,(LPARAM)pda->dlga);
2706 if (!res) {
2707 FIXME("Setup page hook failed?\n");
2708 res = TRUE;
2711 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK) {
2712 FIXME("PagePaintHook not yet implemented!\n");
2714 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
2715 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
2716 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
2717 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
2718 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
2719 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
2720 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
2722 /* width larger as height -> landscape */
2723 if (pda->dlga->ptPaperSize.x > pda->dlga->ptPaperSize.y)
2724 CheckRadioButton(hDlg, rad1, rad2, rad2);
2725 else /* this is default if papersize is not set */
2726 CheckRadioButton(hDlg, rad1, rad2, rad1);
2727 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
2728 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
2729 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
2731 /* We fill them out enabled or not */
2732 if (pda->dlga->Flags & PSD_MARGINS) {
2733 WCHAR str[100];
2734 _c_size2strW(pda,pda->dlga->rtMargin.left,str);
2735 SetDlgItemTextW(hDlg,edt4,str);
2736 _c_size2strW(pda,pda->dlga->rtMargin.top,str);
2737 SetDlgItemTextW(hDlg,edt5,str);
2738 _c_size2strW(pda,pda->dlga->rtMargin.right,str);
2739 SetDlgItemTextW(hDlg,edt6,str);
2740 _c_size2strW(pda,pda->dlga->rtMargin.bottom,str);
2741 SetDlgItemTextW(hDlg,edt7,str);
2742 } else {
2743 /* default is 1 inch */
2744 DWORD size = _c_inch2size((LPPAGESETUPDLGA)pda->dlga,1000);
2745 WCHAR str[20];
2746 _c_size2strW(pda,size,str);
2747 SetDlgItemTextW(hDlg,edt4,str);
2748 SetDlgItemTextW(hDlg,edt5,str);
2749 SetDlgItemTextW(hDlg,edt6,str);
2750 SetDlgItemTextW(hDlg,edt7,str);
2752 PRINTDLG_PS_ChangePrinterW(hDlg,pda);
2753 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
2754 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
2755 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
2757 return TRUE;
2758 } else {
2759 pda = (PageSetupDataW*)GetPropW(hDlg, __WINE_PAGESETUPDLGDATA);
2760 if (!pda) {
2761 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
2762 return FALSE;
2764 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
2765 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
2766 if (res) return res;
2769 switch (uMsg) {
2770 case WM_COMMAND:
2771 return PRINTDLG_PS_WMCommandW(hDlg, wParam, lParam, pda);
2773 return FALSE;
2776 /***********************************************************************
2777 * PageSetupDlgA (COMDLG32.@)
2779 BOOL WINAPI PageSetupDlgA(LPPAGESETUPDLGA setupdlg) {
2780 HGLOBAL hDlgTmpl;
2781 LPVOID ptr;
2782 BOOL bRet;
2783 PageSetupDataA *pda;
2784 PRINTDLGA pdlg;
2786 if(TRACE_ON(commdlg)) {
2787 char flagstr[1000] = "";
2788 struct pd_flags *pflag = psd_flags;
2789 for( ; pflag->name; pflag++) {
2790 if(setupdlg->Flags & pflag->flag) {
2791 strcat(flagstr, pflag->name);
2792 strcat(flagstr, "|");
2795 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2796 "hinst %p, flags %08lx (%s)\n",
2797 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
2798 setupdlg->hDevNames,
2799 setupdlg->hInstance, setupdlg->Flags, flagstr);
2802 /* First get default printer data, we need it right after that. */
2803 memset(&pdlg,0,sizeof(pdlg));
2804 pdlg.lStructSize = sizeof(pdlg);
2805 pdlg.Flags = PD_RETURNDEFAULT;
2806 bRet = PrintDlgA(&pdlg);
2807 if (!bRet) return FALSE;
2809 /* short cut exit, just return default values */
2810 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
2811 setupdlg->hDevMode = pdlg.hDevMode;
2812 setupdlg->hDevNames = pdlg.hDevNames;
2813 /* FIXME: Just return "A4" for now. */
2814 PRINTDLG_PaperSizeA(&pdlg,"A4",&setupdlg->ptPaperSize);
2815 setupdlg->ptPaperSize.x=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.x);
2816 setupdlg->ptPaperSize.y=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.y);
2817 return TRUE;
2819 hDlgTmpl = PRINTDLG_GetPGSTemplateA(setupdlg);
2820 if (!hDlgTmpl) {
2821 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2822 return FALSE;
2824 ptr = LockResource( hDlgTmpl );
2825 if (!ptr) {
2826 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2827 return FALSE;
2829 pda = HeapAlloc(GetProcessHeap(),0,sizeof(*pda));
2830 pda->dlga = setupdlg;
2831 memcpy(&pda->pdlg,&pdlg,sizeof(pdlg));
2833 bRet = (0<DialogBoxIndirectParamA(
2834 setupdlg->hInstance,
2835 ptr,
2836 setupdlg->hwndOwner,
2837 PageDlgProcA,
2838 (LPARAM)pda)
2840 return bRet;
2842 /***********************************************************************
2843 * PageSetupDlgW (COMDLG32.@)
2845 BOOL WINAPI PageSetupDlgW(LPPAGESETUPDLGW setupdlg) {
2846 HGLOBAL hDlgTmpl;
2847 LPVOID ptr;
2848 BOOL bRet;
2849 PageSetupDataW *pdw;
2850 PRINTDLGW pdlg;
2852 if(TRACE_ON(commdlg)) {
2853 char flagstr[1000] = "";
2854 struct pd_flags *pflag = psd_flags;
2855 for( ; pflag->name; pflag++) {
2856 if(setupdlg->Flags & pflag->flag) {
2857 strcat(flagstr, pflag->name);
2858 strcat(flagstr, "|");
2861 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2862 "hinst %p, flags %08lx (%s)\n",
2863 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
2864 setupdlg->hDevNames,
2865 setupdlg->hInstance, setupdlg->Flags, flagstr);
2868 /* First get default printer data, we need it right after that. */
2869 memset(&pdlg,0,sizeof(pdlg));
2870 pdlg.lStructSize = sizeof(pdlg);
2871 pdlg.Flags = PD_RETURNDEFAULT;
2872 bRet = PrintDlgW(&pdlg);
2873 if (!bRet) return FALSE;
2875 /* short cut exit, just return default values */
2876 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
2877 static const WCHAR a4[] = {'A','4',0};
2878 setupdlg->hDevMode = pdlg.hDevMode;
2879 setupdlg->hDevNames = pdlg.hDevNames;
2880 /* FIXME: Just return "A4" for now. */
2881 PRINTDLG_PaperSizeW(&pdlg,a4,&setupdlg->ptPaperSize);
2882 setupdlg->ptPaperSize.x=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.x);
2883 setupdlg->ptPaperSize.y=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.y);
2884 return TRUE;
2886 hDlgTmpl = PRINTDLG_GetPGSTemplateW(setupdlg);
2887 if (!hDlgTmpl) {
2888 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2889 return FALSE;
2891 ptr = LockResource( hDlgTmpl );
2892 if (!ptr) {
2893 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2894 return FALSE;
2896 pdw = HeapAlloc(GetProcessHeap(),0,sizeof(*pdw));
2897 pdw->dlga = setupdlg;
2898 memcpy(&pdw->pdlg,&pdlg,sizeof(pdlg));
2900 bRet = (0<DialogBoxIndirectParamW(
2901 setupdlg->hInstance,
2902 ptr,
2903 setupdlg->hwndOwner,
2904 PageDlgProcW,
2905 (LPARAM)pdw)
2907 return bRet;
2910 /***********************************************************************
2911 * PrintDlgExA (COMDLG32.@)
2913 HRESULT WINAPI PrintDlgExA(LPVOID lpPrintDlgExA) /* [???] FIXME: LPPRINTDLGEXA */
2915 FIXME("stub\n");
2916 return E_NOTIMPL;
2918 /***********************************************************************
2919 * PrintDlgExW (COMDLG32.@)
2921 HRESULT WINAPI PrintDlgExW(LPVOID lpPrintDlgExW) /* [???] FIXME: LPPRINTDLGEXW */
2923 FIXME("stub\n");
2924 return E_NOTIMPL;