ea5d34e5624d94c607fd748ab8834d6bd2510f9a
[reactos.git] / reactos / dll / win32 / comdlg32 / printdlg.c
1 /*
2 * COMMDLG - Print Dialog
3 *
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
6 * Copyright 1999 Klaas van Gend
7 * Copyright 2000 Huw D M Davies
8 *
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.
13 *
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.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23 #include <ctype.h>
24 #include <stdlib.h>
25 #include <stdarg.h>
26 #include <stdio.h>
27 #include <string.h>
28
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"
37
38 #include "wine/debug.h"
39
40 #include "commdlg.h"
41 #include "dlgs.h"
42 #include "cderr.h"
43
44 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
45
46 #include "cdlg.h"
47 #include "printdlg.h"
48
49 /* Yes these constants are the same, but we're just copying win98 */
50 #define UPDOWN_ID 0x270f
51 #define MAX_COPIES 9999
52
53 /* Debugging info */
54 static const struct pd_flags psd_flags[] = {
55 {PSD_MINMARGINS,"PSD_MINMARGINS"},
56 {PSD_MARGINS,"PSD_MARGINS"},
57 {PSD_INTHOUSANDTHSOFINCHES,"PSD_INTHOUSANDTHSOFINCHES"},
58 {PSD_INHUNDREDTHSOFMILLIMETERS,"PSD_INHUNDREDTHSOFMILLIMETERS"},
59 {PSD_DISABLEMARGINS,"PSD_DISABLEMARGINS"},
60 {PSD_DISABLEPRINTER,"PSD_DISABLEPRINTER"},
61 {PSD_NOWARNING,"PSD_NOWARNING"},
62 {PSD_DISABLEORIENTATION,"PSD_DISABLEORIENTATION"},
63 {PSD_RETURNDEFAULT,"PSD_RETURNDEFAULT"},
64 {PSD_DISABLEPAPER,"PSD_DISABLEPAPER"},
65 {PSD_SHOWHELP,"PSD_SHOWHELP"},
66 {PSD_ENABLEPAGESETUPHOOK,"PSD_ENABLEPAGESETUPHOOK"},
67 {PSD_ENABLEPAGESETUPTEMPLATE,"PSD_ENABLEPAGESETUPTEMPLATE"},
68 {PSD_ENABLEPAGESETUPTEMPLATEHANDLE,"PSD_ENABLEPAGESETUPTEMPLATEHANDLE"},
69 {PSD_ENABLEPAGEPAINTHOOK,"PSD_ENABLEPAGEPAINTHOOK"},
70 {PSD_DISABLEPAGEPAINTING,"PSD_DISABLEPAGEPAINTING"},
71 {-1, NULL}
72 };
73
74 /* address of wndproc for subclassed Static control */
75 static WNDPROC lpfnStaticWndProc;
76 /* the text of the fake document to render for the Page Setup dialog */
77 static WCHAR wszFakeDocumentText[1024];
78
79 /***********************************************************************
80 * PRINTDLG_OpenDefaultPrinter
81 *
82 * Returns a winspool printer handle to the default printer in *hprn
83 * Caller must call ClosePrinter on the handle
84 *
85 * Returns TRUE on success else FALSE
86 */
87 BOOL PRINTDLG_OpenDefaultPrinter(HANDLE *hprn)
88 {
89 WCHAR buf[260];
90 DWORD dwBufLen = sizeof(buf) / sizeof(buf[0]);
91 BOOL res;
92 if(!GetDefaultPrinterW(buf, &dwBufLen))
93 return FALSE;
94 res = OpenPrinterW(buf, hprn, NULL);
95 if (!res)
96 WARN("Could not open printer %s\n", debugstr_w(buf));
97 return res;
98 }
99
100 /***********************************************************************
101 * PRINTDLG_SetUpPrinterListCombo
102 *
103 * Initializes printer list combox.
104 * hDlg: HWND of dialog
105 * id: Control id of combo
106 * name: Name of printer to select
107 *
108 * Initializes combo with list of available printers. Selects printer 'name'
109 * If name is NULL or does not exist select the default printer.
110 *
111 * Returns number of printers added to list.
112 */
113 INT PRINTDLG_SetUpPrinterListComboA(HWND hDlg, UINT id, LPCSTR name)
114 {
115 DWORD needed, num;
116 INT i;
117 LPPRINTER_INFO_2A pi;
118 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
119 pi = HeapAlloc(GetProcessHeap(), 0, needed);
120 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
121 &num);
122
123 SendDlgItemMessageA(hDlg, id, CB_RESETCONTENT, 0, 0);
124
125 for(i = 0; i < num; i++) {
126 SendDlgItemMessageA(hDlg, id, CB_ADDSTRING, 0,
127 (LPARAM)pi[i].pPrinterName );
128 }
129 HeapFree(GetProcessHeap(), 0, pi);
130 if(!name ||
131 (i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1,
132 (LPARAM)name)) == CB_ERR) {
133
134 char buf[260];
135 DWORD dwBufLen = sizeof(buf);
136 if (name != NULL)
137 WARN("Can't find %s in printer list so trying to find default\n",
138 debugstr_a(name));
139 if(!GetDefaultPrinterA(buf, &dwBufLen))
140 return num;
141 i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
142 if(i == CB_ERR)
143 FIXME("Can't find default printer in printer list\n");
144 }
145 SendDlgItemMessageA(hDlg, id, CB_SETCURSEL, i, 0);
146 return num;
147 }
148
149 static INT PRINTDLG_SetUpPrinterListComboW(HWND hDlg, UINT id, LPCWSTR name)
150 {
151 DWORD needed, num;
152 INT i;
153 LPPRINTER_INFO_2W pi;
154 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
155 pi = HeapAlloc(GetProcessHeap(), 0, needed);
156 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
157 &num);
158
159 for(i = 0; i < num; i++) {
160 SendDlgItemMessageW(hDlg, id, CB_ADDSTRING, 0,
161 (LPARAM)pi[i].pPrinterName );
162 }
163 HeapFree(GetProcessHeap(), 0, pi);
164 if(!name ||
165 (i = SendDlgItemMessageW(hDlg, id, CB_FINDSTRINGEXACT, -1,
166 (LPARAM)name)) == CB_ERR) {
167 WCHAR buf[260];
168 DWORD dwBufLen = sizeof(buf)/sizeof(buf[0]);
169 if (name != NULL)
170 WARN("Can't find %s in printer list so trying to find default\n",
171 debugstr_w(name));
172 if(!GetDefaultPrinterW(buf, &dwBufLen))
173 return num;
174 i = SendDlgItemMessageW(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
175 if(i == CB_ERR)
176 TRACE("Can't find default printer in printer list\n");
177 }
178 SendDlgItemMessageW(hDlg, id, CB_SETCURSEL, i, 0);
179 return num;
180 }
181
182 /***********************************************************************
183 * PRINTDLG_CreateDevNames [internal]
184 *
185 *
186 * creates a DevNames structure.
187 *
188 * (NB. when we handle unicode the offsets will be in wchars).
189 */
190 static BOOL PRINTDLG_CreateDevNames(HGLOBAL *hmem, const char* DeviceDriverName,
191 const char* DeviceName, const char* OutputPort)
192 {
193 long size;
194 char* pDevNamesSpace;
195 char* pTempPtr;
196 LPDEVNAMES lpDevNames;
197 char buf[260];
198 DWORD dwBufLen = sizeof(buf);
199
200 size = strlen(DeviceDriverName) + 1
201 + strlen(DeviceName) + 1
202 + strlen(OutputPort) + 1
203 + sizeof(DEVNAMES);
204
205 if(*hmem)
206 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
207 else
208 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
209 if (*hmem == 0)
210 return FALSE;
211
212 pDevNamesSpace = GlobalLock(*hmem);
213 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
214
215 pTempPtr = pDevNamesSpace + sizeof(DEVNAMES);
216 strcpy(pTempPtr, DeviceDriverName);
217 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
218
219 pTempPtr += strlen(DeviceDriverName) + 1;
220 strcpy(pTempPtr, DeviceName);
221 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
222
223 pTempPtr += strlen(DeviceName) + 1;
224 strcpy(pTempPtr, OutputPort);
225 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
226
227 GetDefaultPrinterA(buf, &dwBufLen);
228 lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
229 GlobalUnlock(*hmem);
230 return TRUE;
231 }
232
233 static BOOL PRINTDLG_CreateDevNamesW(HGLOBAL *hmem, LPCWSTR DeviceDriverName,
234 LPCWSTR DeviceName, LPCWSTR OutputPort)
235 {
236 long size;
237 LPWSTR pDevNamesSpace;
238 LPWSTR pTempPtr;
239 LPDEVNAMES lpDevNames;
240 WCHAR bufW[260];
241 DWORD dwBufLen = sizeof(bufW) / sizeof(WCHAR);
242
243 size = sizeof(WCHAR)*lstrlenW(DeviceDriverName) + 2
244 + sizeof(WCHAR)*lstrlenW(DeviceName) + 2
245 + sizeof(WCHAR)*lstrlenW(OutputPort) + 2
246 + sizeof(DEVNAMES);
247
248 if(*hmem)
249 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
250 else
251 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
252 if (*hmem == 0)
253 return FALSE;
254
255 pDevNamesSpace = GlobalLock(*hmem);
256 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
257
258 pTempPtr = (LPWSTR)((LPDEVNAMES)pDevNamesSpace + 1);
259 lstrcpyW(pTempPtr, DeviceDriverName);
260 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
261
262 pTempPtr += lstrlenW(DeviceDriverName) + 1;
263 lstrcpyW(pTempPtr, DeviceName);
264 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
265
266 pTempPtr += lstrlenW(DeviceName) + 1;
267 lstrcpyW(pTempPtr, OutputPort);
268 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
269
270 GetDefaultPrinterW(bufW, &dwBufLen);
271 lpDevNames->wDefault = (lstrcmpW(bufW, DeviceName) == 0) ? 1 : 0;
272 GlobalUnlock(*hmem);
273 return TRUE;
274 }
275
276 /***********************************************************************
277 * PRINTDLG_UpdatePrintDlg [internal]
278 *
279 *
280 * updates the PrintDlg structure for return values.
281 *
282 * RETURNS
283 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
284 * TRUE if successful.
285 */
286 static BOOL PRINTDLG_UpdatePrintDlgA(HWND hDlg,
287 PRINT_PTRA* PrintStructures)
288 {
289 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
290 PDEVMODEA lpdm = PrintStructures->lpDevMode;
291 LPPRINTER_INFO_2A pi = PrintStructures->lpPrinterInfo;
292
293
294 if(!lpdm) {
295 FIXME("No lpdm ptr?\n");
296 return FALSE;
297 }
298
299
300 if(!(lppd->Flags & PD_PRINTSETUP)) {
301 /* check whether nFromPage and nToPage are within range defined by
302 * nMinPage and nMaxPage
303 */
304 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
305 WORD nToPage;
306 WORD nFromPage;
307 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
308 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
309 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
310 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
311 WCHAR resourcestr[256];
312 WCHAR resultstr[256];
313 LoadStringW(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE, resourcestr, 255);
314 wsprintfW(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
315 LoadStringW(COMDLG32_hInstance, PD32_PRINT_TITLE, resourcestr, 255);
316 MessageBoxW(hDlg, resultstr, resourcestr, MB_OK | MB_ICONWARNING);
317 return FALSE;
318 }
319 lppd->nFromPage = nFromPage;
320 lppd->nToPage = nToPage;
321 lppd->Flags |= PD_PAGENUMS;
322 }
323 else
324 lppd->Flags &= ~PD_PAGENUMS;
325
326 if (IsDlgButtonChecked(hDlg, rad2) == BST_CHECKED) /* Selection */
327 lppd->Flags |= PD_SELECTION;
328 else
329 lppd->Flags &= ~PD_SELECTION;
330
331 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
332 static char file[] = "FILE:";
333 lppd->Flags |= PD_PRINTTOFILE;
334 pi->pPortName = file;
335 }
336
337 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
338 FIXME("Collate lppd not yet implemented as output\n");
339 }
340
341 /* set PD_Collate and nCopies */
342 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
343 /* The application doesn't support multiple copies or collate...
344 */
345 lppd->Flags &= ~PD_COLLATE;
346 lppd->nCopies = 1;
347 /* if the printer driver supports it... store info there
348 * otherwise no collate & multiple copies !
349 */
350 if (lpdm->dmFields & DM_COLLATE)
351 lpdm->dmCollate =
352 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
353 if (lpdm->dmFields & DM_COPIES)
354 lpdm->u1.s1.dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
355 } else {
356 /* Application is responsible for multiple copies */
357 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
358 lppd->Flags |= PD_COLLATE;
359 else
360 lppd->Flags &= ~PD_COLLATE;
361 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
362 /* multiple copies already included in the document. Driver must print only one copy */
363 lpdm->u1.s1.dmCopies = 1;
364 }
365
366 /* Print quality, PrintDlg16 */
367 if(GetDlgItem(hDlg, cmb1))
368 {
369 HWND hQuality = GetDlgItem(hDlg, cmb1);
370 int Sel = SendMessageA(hQuality, CB_GETCURSEL, 0, 0);
371
372 if(Sel != CB_ERR)
373 {
374 LONG dpi = SendMessageA(hQuality, CB_GETITEMDATA, Sel, 0);
375 lpdm->dmFields |= DM_PRINTQUALITY | DM_YRESOLUTION;
376 lpdm->u1.s1.dmPrintQuality = LOWORD(dpi);
377 lpdm->dmYResolution = HIWORD(dpi);
378 }
379 }
380 }
381 return TRUE;
382 }
383
384 static BOOL PRINTDLG_UpdatePrintDlgW(HWND hDlg,
385 PRINT_PTRW* PrintStructures)
386 {
387 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
388 PDEVMODEW lpdm = PrintStructures->lpDevMode;
389 LPPRINTER_INFO_2W pi = PrintStructures->lpPrinterInfo;
390
391
392 if(!lpdm) {
393 FIXME("No lpdm ptr?\n");
394 return FALSE;
395 }
396
397
398 if(!(lppd->Flags & PD_PRINTSETUP)) {
399 /* check whether nFromPage and nToPage are within range defined by
400 * nMinPage and nMaxPage
401 */
402 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
403 WORD nToPage;
404 WORD nFromPage;
405 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
406 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
407 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
408 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
409 WCHAR resourcestr[256];
410 WCHAR resultstr[256];
411 LoadStringW(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
412 resourcestr, 255);
413 wsprintfW(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
414 LoadStringW(COMDLG32_hInstance, PD32_PRINT_TITLE,
415 resourcestr, 255);
416 MessageBoxW(hDlg, resultstr, resourcestr,
417 MB_OK | MB_ICONWARNING);
418 return FALSE;
419 }
420 lppd->nFromPage = nFromPage;
421 lppd->nToPage = nToPage;
422 lppd->Flags |= PD_PAGENUMS;
423 }
424 else
425 lppd->Flags &= ~PD_PAGENUMS;
426
427 if (IsDlgButtonChecked(hDlg, rad2) == BST_CHECKED) /* Selection */
428 lppd->Flags |= PD_SELECTION;
429 else
430 lppd->Flags &= ~PD_SELECTION;
431
432 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
433 static WCHAR file[] = {'F','I','L','E',':',0};
434 lppd->Flags |= PD_PRINTTOFILE;
435 pi->pPortName = file;
436 }
437
438 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
439 FIXME("Collate lppd not yet implemented as output\n");
440 }
441
442 /* set PD_Collate and nCopies */
443 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
444 /* The application doesn't support multiple copies or collate...
445 */
446 lppd->Flags &= ~PD_COLLATE;
447 lppd->nCopies = 1;
448 /* if the printer driver supports it... store info there
449 * otherwise no collate & multiple copies !
450 */
451 if (lpdm->dmFields & DM_COLLATE)
452 lpdm->dmCollate =
453 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
454 if (lpdm->dmFields & DM_COPIES)
455 lpdm->u1.s1.dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
456 } else {
457 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
458 lppd->Flags |= PD_COLLATE;
459 else
460 lppd->Flags &= ~PD_COLLATE;
461 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
462 }
463 }
464 return TRUE;
465 }
466
467 static BOOL PRINTDLG_PaperSizeA(
468 PRINTDLGA *pdlga,const WORD PaperSize,LPPOINT size
469 ) {
470 DEVNAMES *dn;
471 DEVMODEA *dm;
472 LPSTR devname,portname;
473 int i;
474 INT NrOfEntries,ret;
475 WORD *Words = NULL;
476 POINT *points = NULL;
477 BOOL retval = FALSE;
478
479 dn = GlobalLock(pdlga->hDevNames);
480 dm = GlobalLock(pdlga->hDevMode);
481 devname = ((char*)dn)+dn->wDeviceOffset;
482 portname = ((char*)dn)+dn->wOutputOffset;
483
484
485 NrOfEntries = DeviceCapabilitiesA(devname,portname,DC_PAPERNAMES,NULL,dm);
486 if (!NrOfEntries) {
487 FIXME("No papernames found for %s/%s\n",devname,portname);
488 goto out;
489 }
490 if (NrOfEntries == -1) {
491 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
492 goto out;
493 }
494
495 Words = HeapAlloc(GetProcessHeap(),0,NrOfEntries*sizeof(WORD));
496 if (NrOfEntries != (ret=DeviceCapabilitiesA(devname,portname,DC_PAPERS,(LPSTR)Words,dm))) {
497 FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
498 goto out;
499 }
500 for (i=0;i<NrOfEntries;i++)
501 if (Words[i] == PaperSize)
502 break;
503 if (i == NrOfEntries) {
504 FIXME("Papersize %d not found in list?\n",PaperSize);
505 goto out;
506 }
507 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
508 if (NrOfEntries!=(ret=DeviceCapabilitiesA(devname,portname,DC_PAPERSIZE,(LPSTR)points,dm))) {
509 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
510 goto out;
511 }
512 /* this is _10ths_ of a millimeter */
513 size->x=points[i].x;
514 size->y=points[i].y;
515 retval = TRUE;
516 out:
517 GlobalUnlock(pdlga->hDevNames);
518 GlobalUnlock(pdlga->hDevMode);
519 HeapFree(GetProcessHeap(),0,Words);
520 HeapFree(GetProcessHeap(),0,points);
521 return retval;
522 }
523
524 static BOOL PRINTDLG_PaperSizeW(
525 PRINTDLGW *pdlga,const WCHAR *PaperSize,LPPOINT size
526 ) {
527 DEVNAMES *dn;
528 DEVMODEW *dm;
529 LPWSTR devname,portname;
530 int i;
531 INT NrOfEntries,ret;
532 WCHAR *Names = NULL;
533 POINT *points = NULL;
534 BOOL retval = FALSE;
535
536 dn = GlobalLock(pdlga->hDevNames);
537 dm = GlobalLock(pdlga->hDevMode);
538 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
539 portname = ((WCHAR*)dn)+dn->wOutputOffset;
540
541
542 NrOfEntries = DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,NULL,dm);
543 if (!NrOfEntries) {
544 FIXME("No papernames found for %s/%s\n",debugstr_w(devname),debugstr_w(portname));
545 goto out;
546 }
547 if (NrOfEntries == -1) {
548 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
549 goto out;
550 }
551
552 Names = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*NrOfEntries*64);
553 if (NrOfEntries != (ret=DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,Names,dm))) {
554 FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
555 goto out;
556 }
557 for (i=0;i<NrOfEntries;i++)
558 if (!lstrcmpW(PaperSize,Names+(64*i)))
559 break;
560 if (i==NrOfEntries) {
561 FIXME("Papersize %s not found in list?\n",debugstr_w(PaperSize));
562 goto out;
563 }
564 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
565 if (NrOfEntries!=(ret=DeviceCapabilitiesW(devname,portname,DC_PAPERSIZE,(LPWSTR)points,dm))) {
566 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
567 goto out;
568 }
569 /* this is _10ths_ of a millimeter */
570 size->x=points[i].x;
571 size->y=points[i].y;
572 retval = TRUE;
573 out:
574 GlobalUnlock(pdlga->hDevNames);
575 GlobalUnlock(pdlga->hDevMode);
576 HeapFree(GetProcessHeap(),0,Names);
577 HeapFree(GetProcessHeap(),0,points);
578 return retval;
579 }
580
581
582 /************************************************************************
583 * PRINTDLG_SetUpPaperComboBox
584 *
585 * Initialize either the papersize or inputslot combos of the Printer Setup
586 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
587 * We also try to re-select the old selection.
588 */
589 static BOOL PRINTDLG_SetUpPaperComboBoxA(HWND hDlg,
590 int nIDComboBox,
591 char* PrinterName,
592 char* PortName,
593 LPDEVMODEA dm)
594 {
595 int i;
596 int NrOfEntries;
597 char* Names;
598 WORD* Words;
599 DWORD Sel;
600 WORD oldWord = 0;
601 int NamesSize;
602 int fwCapability_Names;
603 int fwCapability_Words;
604
605 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName,PortName,nIDComboBox);
606
607 /* query the dialog box for the current selected value */
608 Sel = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
609 if(Sel != CB_ERR) {
610 /* we enter here only if a different printer is selected after
611 * the Print Setup dialog is opened. The current settings are
612 * stored into the newly selected printer.
613 */
614 oldWord = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA,
615 Sel, 0);
616 if (dm) {
617 if (nIDComboBox == cmb2)
618 dm->u1.s1.dmPaperSize = oldWord;
619 else
620 dm->u1.s1.dmDefaultSource = oldWord;
621 }
622 }
623 else {
624 /* we enter here only when the Print setup dialog is initially
625 * opened. In this case the settings are restored from when
626 * the dialog was last closed.
627 */
628 if (dm) {
629 if (nIDComboBox == cmb2)
630 oldWord = dm->u1.s1.dmPaperSize;
631 else
632 oldWord = dm->u1.s1.dmDefaultSource;
633 }
634 }
635
636 if (nIDComboBox == cmb2) {
637 NamesSize = 64;
638 fwCapability_Names = DC_PAPERNAMES;
639 fwCapability_Words = DC_PAPERS;
640 } else {
641 nIDComboBox = cmb3;
642 NamesSize = 24;
643 fwCapability_Names = DC_BINNAMES;
644 fwCapability_Words = DC_BINS;
645 }
646
647 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
648 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
649 */
650 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
651 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
652 fwCapability_Names, NULL, dm);
653 if (NrOfEntries == 0)
654 WARN("no Name Entries found!\n");
655 else if (NrOfEntries < 0)
656 return FALSE;
657
658 if(DeviceCapabilitiesA(PrinterName, PortName, fwCapability_Words, NULL, dm)
659 != NrOfEntries) {
660 ERR("Number of caps is different\n");
661 NrOfEntries = 0;
662 }
663
664 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(char)*NamesSize);
665 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
666 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
667 fwCapability_Names, Names, dm);
668 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
669 fwCapability_Words, (LPSTR)Words, dm);
670
671 /* reset any current content in the combobox */
672 SendDlgItemMessageA(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
673
674 /* store new content */
675 for (i = 0; i < NrOfEntries; i++) {
676 DWORD pos = SendDlgItemMessageA(hDlg, nIDComboBox, CB_ADDSTRING, 0,
677 (LPARAM)(&Names[i*NamesSize]) );
678 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
679 Words[i]);
680 }
681
682 /* Look for old selection - can't do this is previous loop since
683 item order will change as more items are added */
684 Sel = 0;
685 for (i = 0; i < NrOfEntries; i++) {
686 if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
687 oldWord) {
688 Sel = i;
689 break;
690 }
691 }
692 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
693
694 HeapFree(GetProcessHeap(),0,Words);
695 HeapFree(GetProcessHeap(),0,Names);
696 return TRUE;
697 }
698
699 static BOOL PRINTDLG_SetUpPaperComboBoxW(HWND hDlg,
700 int nIDComboBox,
701 const WCHAR* PrinterName,
702 const WCHAR* PortName,
703 LPDEVMODEW dm)
704 {
705 int i;
706 int NrOfEntries;
707 WCHAR* Names;
708 WORD* Words;
709 DWORD Sel;
710 WORD oldWord = 0;
711 int NamesSize;
712 int fwCapability_Names;
713 int fwCapability_Words;
714
715 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName),debugstr_w(PortName),nIDComboBox);
716
717 /* query the dialog box for the current selected value */
718 Sel = SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
719 if(Sel != CB_ERR) {
720 /* we enter here only if a different printer is selected after
721 * the Print Setup dialog is opened. The current settings are
722 * stored into the newly selected printer.
723 */
724 oldWord = SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETITEMDATA,
725 Sel, 0);
726 if (dm) {
727 if (nIDComboBox == cmb2)
728 dm->u1.s1.dmPaperSize = oldWord;
729 else
730 dm->u1.s1.dmDefaultSource = oldWord;
731 }
732 }
733 else {
734 /* we enter here only when the Print setup dialog is initially
735 * opened. In this case the settings are restored from when
736 * the dialog was last closed.
737 */
738 if (dm) {
739 if (nIDComboBox == cmb2)
740 oldWord = dm->u1.s1.dmPaperSize;
741 else
742 oldWord = dm->u1.s1.dmDefaultSource;
743 }
744 }
745
746 if (nIDComboBox == cmb2) {
747 NamesSize = 64;
748 fwCapability_Names = DC_PAPERNAMES;
749 fwCapability_Words = DC_PAPERS;
750 } else {
751 nIDComboBox = cmb3;
752 NamesSize = 24;
753 fwCapability_Names = DC_BINNAMES;
754 fwCapability_Words = DC_BINS;
755 }
756
757 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
758 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
759 */
760 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
761 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
762 fwCapability_Names, NULL, dm);
763 if (NrOfEntries == 0)
764 WARN("no Name Entries found!\n");
765 else if (NrOfEntries < 0)
766 return FALSE;
767
768 if(DeviceCapabilitiesW(PrinterName, PortName, fwCapability_Words, NULL, dm)
769 != NrOfEntries) {
770 ERR("Number of caps is different\n");
771 NrOfEntries = 0;
772 }
773
774 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WCHAR)*NamesSize);
775 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
776 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
777 fwCapability_Names, Names, dm);
778 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
779 fwCapability_Words, (LPWSTR)Words, dm);
780
781 /* reset any current content in the combobox */
782 SendDlgItemMessageW(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
783
784 /* store new content */
785 for (i = 0; i < NrOfEntries; i++) {
786 DWORD pos = SendDlgItemMessageW(hDlg, nIDComboBox, CB_ADDSTRING, 0,
787 (LPARAM)(&Names[i*NamesSize]) );
788 SendDlgItemMessageW(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
789 Words[i]);
790 }
791
792 /* Look for old selection - can't do this is previous loop since
793 item order will change as more items are added */
794 Sel = 0;
795 for (i = 0; i < NrOfEntries; i++) {
796 if(SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
797 oldWord) {
798 Sel = i;
799 break;
800 }
801 }
802 SendDlgItemMessageW(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
803
804 HeapFree(GetProcessHeap(),0,Words);
805 HeapFree(GetProcessHeap(),0,Names);
806 return TRUE;
807 }
808
809
810 /***********************************************************************
811 * PRINTDLG_UpdatePrinterInfoTexts [internal]
812 */
813 static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg, const PRINTER_INFO_2A *pi)
814 {
815 char StatusMsg[256];
816 char ResourceString[256];
817 int i;
818
819 /* Status Message */
820 StatusMsg[0]='\0';
821
822 /* add all status messages */
823 for (i = 0; i < 25; i++) {
824 if (pi->Status & (1<<i)) {
825 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
826 ResourceString, 255);
827 strcat(StatusMsg,ResourceString);
828 }
829 }
830 /* append "ready" */
831 /* FIXME: status==ready must only be appended if really so.
832 but how to detect? */
833 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
834 ResourceString, 255);
835 strcat(StatusMsg,ResourceString);
836 SetDlgItemTextA(hDlg, stc12, StatusMsg);
837
838 /* set all other printer info texts */
839 SetDlgItemTextA(hDlg, stc11, pi->pDriverName);
840
841 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
842 SetDlgItemTextA(hDlg, stc14, pi->pLocation);
843 else
844 SetDlgItemTextA(hDlg, stc14, pi->pPortName);
845 SetDlgItemTextA(hDlg, stc13, pi->pComment ? pi->pComment : "");
846 return;
847 }
848
849 static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg, const PRINTER_INFO_2W *pi)
850 {
851 WCHAR StatusMsg[256];
852 WCHAR ResourceString[256];
853 static const WCHAR emptyW[] = {0};
854 int i;
855
856 /* Status Message */
857 StatusMsg[0]='\0';
858
859 /* add all status messages */
860 for (i = 0; i < 25; i++) {
861 if (pi->Status & (1<<i)) {
862 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
863 ResourceString, 255);
864 lstrcatW(StatusMsg,ResourceString);
865 }
866 }
867 /* append "ready" */
868 /* FIXME: status==ready must only be appended if really so.
869 but how to detect? */
870 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
871 ResourceString, 255);
872 lstrcatW(StatusMsg,ResourceString);
873 SetDlgItemTextW(hDlg, stc12, StatusMsg);
874
875 /* set all other printer info texts */
876 SetDlgItemTextW(hDlg, stc11, pi->pDriverName);
877 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
878 SetDlgItemTextW(hDlg, stc14, pi->pLocation);
879 else
880 SetDlgItemTextW(hDlg, stc14, pi->pPortName);
881 SetDlgItemTextW(hDlg, stc13, pi->pComment ? pi->pComment : emptyW);
882 }
883
884
885 /*******************************************************************
886 *
887 * PRINTDLG_ChangePrinter
888 *
889 */
890 BOOL PRINTDLG_ChangePrinterA(HWND hDlg, char *name,
891 PRINT_PTRA *PrintStructures)
892 {
893 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
894 LPDEVMODEA lpdm = NULL;
895 LONG dmSize;
896 DWORD needed;
897 HANDLE hprn;
898
899 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
900 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
901 if(!OpenPrinterA(name, &hprn, NULL)) {
902 ERR("Can't open printer %s\n", name);
903 return FALSE;
904 }
905 GetPrinterA(hprn, 2, NULL, 0, &needed);
906 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,needed);
907 GetPrinterA(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
908 &needed);
909 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
910 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,needed);
911 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
912 needed, &needed)) {
913 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures->lpPrinterInfo->pPrinterName);
914 return FALSE;
915 }
916 ClosePrinter(hprn);
917
918 PRINTDLG_UpdatePrinterInfoTextsA(hDlg, PrintStructures->lpPrinterInfo);
919
920 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
921 PrintStructures->lpDevMode = NULL;
922
923 dmSize = DocumentPropertiesA(0, 0, name, NULL, NULL, 0);
924 if(dmSize == -1) {
925 ERR("DocumentProperties fails on %s\n", debugstr_a(name));
926 return FALSE;
927 }
928 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
929 dmSize = DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, NULL,
930 DM_OUT_BUFFER);
931 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
932 !lstrcmpA( (LPSTR) lpdm->dmDeviceName,
933 (LPSTR) PrintStructures->lpDevMode->dmDeviceName)) {
934 /* Supplied devicemode matches current printer so try to use it */
935 DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, lpdm,
936 DM_OUT_BUFFER | DM_IN_BUFFER);
937 }
938 if(lpdm)
939 GlobalUnlock(lppd->hDevMode);
940
941 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
942
943 if(!(lppd->Flags & PD_PRINTSETUP)) {
944 /* Print range (All/Range/Selection) */
945 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
946 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
947 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
948 if (lppd->Flags & PD_NOSELECTION)
949 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
950 else
951 if (lppd->Flags & PD_SELECTION)
952 CheckRadioButton(hDlg, rad1, rad3, rad2);
953 if (lppd->Flags & PD_NOPAGENUMS) {
954 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
955 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
956 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
957 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
958 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
959 } else {
960 if (lppd->Flags & PD_PAGENUMS)
961 CheckRadioButton(hDlg, rad1, rad3, rad3);
962 }
963
964 /* Collate pages
965 *
966 * FIXME: The ico3 is not displayed for some reason. I don't know why.
967 */
968 if (lppd->Flags & PD_COLLATE) {
969 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
970 (LPARAM)PrintStructures->hCollateIcon);
971 CheckDlgButton(hDlg, chx2, 1);
972 } else {
973 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
974 (LPARAM)PrintStructures->hNoCollateIcon);
975 CheckDlgButton(hDlg, chx2, 0);
976 }
977
978 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
979 /* if printer doesn't support it: no Collate */
980 if (!(lpdm->dmFields & DM_COLLATE)) {
981 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
982 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
983 }
984 }
985
986 /* nCopies */
987 {
988 INT copies;
989 if (lppd->hDevMode == 0)
990 copies = lppd->nCopies;
991 else
992 copies = lpdm->u1.s1.dmCopies;
993 if(copies == 0) copies = 1;
994 else if(copies < 0) copies = MAX_COPIES;
995 SetDlgItemInt(hDlg, edt3, copies, FALSE);
996 }
997
998 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
999 /* if printer doesn't support it: no nCopies */
1000 if (!(lpdm->dmFields & DM_COPIES)) {
1001 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
1002 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
1003 }
1004 }
1005
1006 /* print to file */
1007 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
1008 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
1009 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
1010 if (lppd->Flags & PD_HIDEPRINTTOFILE)
1011 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
1012
1013 /* Fill print quality combo, PrintDlg16 */
1014 if(GetDlgItem(hDlg, cmb1))
1015 {
1016 DWORD numResolutions = DeviceCapabilitiesA(PrintStructures->lpPrinterInfo->pPrinterName,
1017 PrintStructures->lpPrinterInfo->pPortName,
1018 DC_ENUMRESOLUTIONS, NULL, lpdm);
1019
1020 if(numResolutions != -1)
1021 {
1022 HWND hQuality = GetDlgItem(hDlg, cmb1);
1023 LONG* Resolutions;
1024 char buf[255];
1025 int i;
1026 int dpiX, dpiY;
1027 HDC hPrinterDC = CreateDCA(PrintStructures->lpPrinterInfo->pDriverName,
1028 PrintStructures->lpPrinterInfo->pPrinterName,
1029 0, lpdm);
1030
1031 Resolutions = HeapAlloc(GetProcessHeap(), 0, numResolutions*sizeof(LONG)*2);
1032 DeviceCapabilitiesA(PrintStructures->lpPrinterInfo->pPrinterName,
1033 PrintStructures->lpPrinterInfo->pPortName,
1034 DC_ENUMRESOLUTIONS, (LPSTR)Resolutions, lpdm);
1035
1036 dpiX = GetDeviceCaps(hPrinterDC, LOGPIXELSX);
1037 dpiY = GetDeviceCaps(hPrinterDC, LOGPIXELSY);
1038 DeleteDC(hPrinterDC);
1039
1040 SendMessageA(hQuality, CB_RESETCONTENT, 0, 0);
1041 for(i = 0; i < (numResolutions * 2); i += 2)
1042 {
1043 BOOL IsDefault = FALSE;
1044 LRESULT Index;
1045
1046 if(Resolutions[i] == Resolutions[i+1])
1047 {
1048 if(dpiX == Resolutions[i])
1049 IsDefault = TRUE;
1050 sprintf(buf, "%d dpi", Resolutions[i]);
1051 } else
1052 {
1053 if(dpiX == Resolutions[i] && dpiY == Resolutions[i+1])
1054 IsDefault = TRUE;
1055 sprintf(buf, "%d dpi x %d dpi", Resolutions[i], Resolutions[i+1]);
1056 }
1057
1058 Index = SendMessageA(hQuality, CB_ADDSTRING, 0, (LPARAM)buf);
1059
1060 if(IsDefault)
1061 SendMessageA(hQuality, CB_SETCURSEL, Index, 0);
1062
1063 SendMessageA(hQuality, CB_SETITEMDATA, Index, MAKELONG(dpiX,dpiY));
1064 }
1065 HeapFree(GetProcessHeap(), 0, Resolutions);
1066 }
1067 }
1068 } else { /* PD_PRINTSETUP */
1069 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
1070
1071 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb2,
1072 PrintStructures->lpPrinterInfo->pPrinterName,
1073 PrintStructures->lpPrinterInfo->pPortName,
1074 lpdm);
1075 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb3,
1076 PrintStructures->lpPrinterInfo->pPrinterName,
1077 PrintStructures->lpPrinterInfo->pPortName,
1078 lpdm);
1079 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1080 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1081 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1082 PrintStructures->hLandscapeIcon));
1083
1084 }
1085
1086 /* help button */
1087 if ((lppd->Flags & PD_SHOWHELP)==0) {
1088 /* hide if PD_SHOWHELP not specified */
1089 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1090 }
1091 return TRUE;
1092 }
1093
1094 static BOOL PRINTDLG_ChangePrinterW(HWND hDlg, WCHAR *name,
1095 PRINT_PTRW *PrintStructures)
1096 {
1097 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1098 LPDEVMODEW lpdm = NULL;
1099 LONG dmSize;
1100 DWORD needed;
1101 HANDLE hprn;
1102
1103 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
1104 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
1105 if(!OpenPrinterW(name, &hprn, NULL)) {
1106 ERR("Can't open printer %s\n", debugstr_w(name));
1107 return FALSE;
1108 }
1109 GetPrinterW(hprn, 2, NULL, 0, &needed);
1110 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
1111 GetPrinterW(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
1112 &needed);
1113 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
1114 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
1115 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
1116 needed, &needed)) {
1117 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures->lpPrinterInfo->pPrinterName));
1118 return FALSE;
1119 }
1120 ClosePrinter(hprn);
1121
1122 PRINTDLG_UpdatePrinterInfoTextsW(hDlg, PrintStructures->lpPrinterInfo);
1123
1124 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
1125 PrintStructures->lpDevMode = NULL;
1126
1127 dmSize = DocumentPropertiesW(0, 0, name, NULL, NULL, 0);
1128 if(dmSize == -1) {
1129 ERR("DocumentProperties fails on %s\n", debugstr_w(name));
1130 return FALSE;
1131 }
1132 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
1133 dmSize = DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, NULL,
1134 DM_OUT_BUFFER);
1135 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
1136 !lstrcmpW(lpdm->dmDeviceName,
1137 PrintStructures->lpDevMode->dmDeviceName)) {
1138 /* Supplied devicemode matches current printer so try to use it */
1139 DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, lpdm,
1140 DM_OUT_BUFFER | DM_IN_BUFFER);
1141 }
1142 if(lpdm)
1143 GlobalUnlock(lppd->hDevMode);
1144
1145 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
1146
1147 if(!(lppd->Flags & PD_PRINTSETUP)) {
1148 /* Print range (All/Range/Selection) */
1149 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
1150 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
1151 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
1152 if (lppd->Flags & PD_NOSELECTION)
1153 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
1154 else
1155 if (lppd->Flags & PD_SELECTION)
1156 CheckRadioButton(hDlg, rad1, rad3, rad2);
1157 if (lppd->Flags & PD_NOPAGENUMS) {
1158 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
1159 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
1160 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
1161 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
1162 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
1163 } else {
1164 if (lppd->Flags & PD_PAGENUMS)
1165 CheckRadioButton(hDlg, rad1, rad3, rad3);
1166 }
1167
1168 /* Collate pages
1169 *
1170 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1171 */
1172 if (lppd->Flags & PD_COLLATE) {
1173 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1174 (LPARAM)PrintStructures->hCollateIcon);
1175 CheckDlgButton(hDlg, chx2, 1);
1176 } else {
1177 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1178 (LPARAM)PrintStructures->hNoCollateIcon);
1179 CheckDlgButton(hDlg, chx2, 0);
1180 }
1181
1182 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1183 /* if printer doesn't support it: no Collate */
1184 if (!(lpdm->dmFields & DM_COLLATE)) {
1185 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1186 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
1187 }
1188 }
1189
1190 /* nCopies */
1191 {
1192 INT copies;
1193 if (lppd->hDevMode == 0)
1194 copies = lppd->nCopies;
1195 else
1196 copies = lpdm->u1.s1.dmCopies;
1197 if(copies == 0) copies = 1;
1198 else if(copies < 0) copies = MAX_COPIES;
1199 SetDlgItemInt(hDlg, edt3, copies, FALSE);
1200 }
1201
1202 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1203 /* if printer doesn't support it: no nCopies */
1204 if (!(lpdm->dmFields & DM_COPIES)) {
1205 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
1206 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
1207 }
1208 }
1209
1210 /* print to file */
1211 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
1212 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
1213 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
1214 if (lppd->Flags & PD_HIDEPRINTTOFILE)
1215 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
1216
1217 } else { /* PD_PRINTSETUP */
1218 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
1219
1220 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb2,
1221 PrintStructures->lpPrinterInfo->pPrinterName,
1222 PrintStructures->lpPrinterInfo->pPortName,
1223 lpdm);
1224 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb3,
1225 PrintStructures->lpPrinterInfo->pPrinterName,
1226 PrintStructures->lpPrinterInfo->pPortName,
1227 lpdm);
1228 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1229 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1230 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1231 PrintStructures->hLandscapeIcon));
1232
1233 }
1234
1235 /* help button */
1236 if ((lppd->Flags & PD_SHOWHELP)==0) {
1237 /* hide if PD_SHOWHELP not specified */
1238 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1239 }
1240 return TRUE;
1241 }
1242
1243 /***********************************************************************
1244 * check_printer_setup [internal]
1245 */
1246 static LRESULT check_printer_setup(HWND hDlg)
1247 {
1248 DWORD needed,num;
1249 WCHAR resourcestr[256],resultstr[256];
1250 int res;
1251
1252 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
1253 if(needed == 0)
1254 {
1255 EnumPrintersW(PRINTER_ENUM_CONNECTIONS, NULL, 2, NULL, 0, &needed, &num);
1256 }
1257 if(needed > 0)
1258 return TRUE;
1259 else
1260 {
1261 LoadStringW(COMDLG32_hInstance, PD32_NO_DEVICES,resultstr, 255);
1262 LoadStringW(COMDLG32_hInstance, PD32_PRINT_TITLE,resourcestr, 255);
1263 res = MessageBoxW(hDlg, resultstr, resourcestr,MB_OK | MB_ICONWARNING);
1264 return FALSE;
1265 }
1266 }
1267
1268 /***********************************************************************
1269 * PRINTDLG_WMInitDialog [internal]
1270 */
1271 static LRESULT PRINTDLG_WMInitDialog(HWND hDlg, WPARAM wParam,
1272 PRINT_PTRA* PrintStructures)
1273 {
1274 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
1275 DEVNAMES *pdn;
1276 DEVMODEA *pdm;
1277 char *name = NULL;
1278 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1279
1280 /* load Collate ICONs */
1281 /* We load these with LoadImage because they are not a standard
1282 size and we don't want them rescaled */
1283 PrintStructures->hCollateIcon =
1284 LoadImageA(COMDLG32_hInstance, "PD32_COLLATE", IMAGE_ICON, 0, 0, 0);
1285 PrintStructures->hNoCollateIcon =
1286 LoadImageA(COMDLG32_hInstance, "PD32_NOCOLLATE", IMAGE_ICON, 0, 0, 0);
1287
1288 /* These can be done with LoadIcon */
1289 PrintStructures->hPortraitIcon =
1290 LoadIconA(COMDLG32_hInstance, "PD32_PORTRAIT");
1291 PrintStructures->hLandscapeIcon =
1292 LoadIconA(COMDLG32_hInstance, "PD32_LANDSCAPE");
1293
1294 /* display the collate/no_collate icon */
1295 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1296 (LPARAM)PrintStructures->hNoCollateIcon);
1297
1298 if(PrintStructures->hCollateIcon == 0 ||
1299 PrintStructures->hNoCollateIcon == 0 ||
1300 PrintStructures->hPortraitIcon == 0 ||
1301 PrintStructures->hLandscapeIcon == 0) {
1302 ERR("no icon in resourcefile\n");
1303 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1304 EndDialog(hDlg, FALSE);
1305 }
1306
1307 /*
1308 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1309 * must be registered and the Help button must be shown.
1310 */
1311 if (lppd->Flags & PD_SHOWHELP) {
1312 if((PrintStructures->HelpMessageID =
1313 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
1314 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1315 return FALSE;
1316 }
1317 } else
1318 PrintStructures->HelpMessageID = 0;
1319
1320 if(!(lppd->Flags &PD_PRINTSETUP)) {
1321 PrintStructures->hwndUpDown =
1322 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1323 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1324 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1325 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1326 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1327 }
1328
1329 /* FIXME: I allow more freedom than either Win95 or WinNT,
1330 * which do not agree to what errors should be thrown or not
1331 * in case nToPage or nFromPage is out-of-range.
1332 */
1333 if (lppd->nMaxPage < lppd->nMinPage)
1334 lppd->nMaxPage = lppd->nMinPage;
1335 if (lppd->nMinPage == lppd->nMaxPage)
1336 lppd->Flags |= PD_NOPAGENUMS;
1337 if (lppd->nToPage < lppd->nMinPage)
1338 lppd->nToPage = lppd->nMinPage;
1339 if (lppd->nToPage > lppd->nMaxPage)
1340 lppd->nToPage = lppd->nMaxPage;
1341 if (lppd->nFromPage < lppd->nMinPage)
1342 lppd->nFromPage = lppd->nMinPage;
1343 if (lppd->nFromPage > lppd->nMaxPage)
1344 lppd->nFromPage = lppd->nMaxPage;
1345
1346 /* if we have the combo box, fill it */
1347 if (GetDlgItem(hDlg,comboID)) {
1348 /* Fill Combobox
1349 */
1350 pdn = GlobalLock(lppd->hDevNames);
1351 pdm = GlobalLock(lppd->hDevMode);
1352 if(pdn)
1353 name = (char*)pdn + pdn->wDeviceOffset;
1354 else if(pdm)
1355 name = (char*)pdm->dmDeviceName;
1356 PRINTDLG_SetUpPrinterListComboA(hDlg, comboID, name);
1357 if(pdm) GlobalUnlock(lppd->hDevMode);
1358 if(pdn) GlobalUnlock(lppd->hDevNames);
1359
1360 /* Now find selected printer and update rest of dlg */
1361 name = HeapAlloc(GetProcessHeap(),0,256);
1362 if (GetDlgItemTextA(hDlg, comboID, name, 255))
1363 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1364 HeapFree(GetProcessHeap(),0,name);
1365 } else {
1366 /* else use default printer */
1367 char name[200];
1368 DWORD dwBufLen = sizeof(name);
1369 BOOL ret = GetDefaultPrinterA(name, &dwBufLen);
1370
1371 if (ret)
1372 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1373 else
1374 FIXME("No default printer found, expect problems!\n");
1375 }
1376 return TRUE;
1377 }
1378
1379 static LRESULT PRINTDLG_WMInitDialogW(HWND hDlg, WPARAM wParam,
1380 PRINT_PTRW* PrintStructures)
1381 {
1382 static const WCHAR PD32_COLLATE[] = { 'P', 'D', '3', '2', '_', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
1383 static const WCHAR PD32_NOCOLLATE[] = { 'P', 'D', '3', '2', '_', 'N', 'O', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
1384 static const WCHAR PD32_PORTRAIT[] = { 'P', 'D', '3', '2', '_', 'P', 'O', 'R', 'T', 'R', 'A', 'I', 'T', 0 };
1385 static const WCHAR PD32_LANDSCAPE[] = { 'P', 'D', '3', '2', '_', 'L', 'A', 'N', 'D', 'S', 'C', 'A', 'P', 'E', 0 };
1386 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1387 DEVNAMES *pdn;
1388 DEVMODEW *pdm;
1389 WCHAR *name = NULL;
1390 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1391
1392 /* load Collate ICONs */
1393 /* We load these with LoadImage because they are not a standard
1394 size and we don't want them rescaled */
1395 PrintStructures->hCollateIcon =
1396 LoadImageW(COMDLG32_hInstance, PD32_COLLATE, IMAGE_ICON, 0, 0, 0);
1397 PrintStructures->hNoCollateIcon =
1398 LoadImageW(COMDLG32_hInstance, PD32_NOCOLLATE, IMAGE_ICON, 0, 0, 0);
1399
1400 /* These can be done with LoadIcon */
1401 PrintStructures->hPortraitIcon =
1402 LoadIconW(COMDLG32_hInstance, PD32_PORTRAIT);
1403 PrintStructures->hLandscapeIcon =
1404 LoadIconW(COMDLG32_hInstance, PD32_LANDSCAPE);
1405
1406 /* display the collate/no_collate icon */
1407 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1408 (LPARAM)PrintStructures->hNoCollateIcon);
1409
1410 if(PrintStructures->hCollateIcon == 0 ||
1411 PrintStructures->hNoCollateIcon == 0 ||
1412 PrintStructures->hPortraitIcon == 0 ||
1413 PrintStructures->hLandscapeIcon == 0) {
1414 ERR("no icon in resourcefile\n");
1415 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1416 EndDialog(hDlg, FALSE);
1417 }
1418
1419 /*
1420 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1421 * must be registered and the Help button must be shown.
1422 */
1423 if (lppd->Flags & PD_SHOWHELP) {
1424 if((PrintStructures->HelpMessageID =
1425 RegisterWindowMessageW(HELPMSGSTRINGW)) == 0) {
1426 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1427 return FALSE;
1428 }
1429 } else
1430 PrintStructures->HelpMessageID = 0;
1431
1432 if(!(lppd->Flags &PD_PRINTSETUP)) {
1433 PrintStructures->hwndUpDown =
1434 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1435 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1436 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1437 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1438 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1439 }
1440
1441 /* FIXME: I allow more freedom than either Win95 or WinNT,
1442 * which do not agree to what errors should be thrown or not
1443 * in case nToPage or nFromPage is out-of-range.
1444 */
1445 if (lppd->nMaxPage < lppd->nMinPage)
1446 lppd->nMaxPage = lppd->nMinPage;
1447 if (lppd->nMinPage == lppd->nMaxPage)
1448 lppd->Flags |= PD_NOPAGENUMS;
1449 if (lppd->nToPage < lppd->nMinPage)
1450 lppd->nToPage = lppd->nMinPage;
1451 if (lppd->nToPage > lppd->nMaxPage)
1452 lppd->nToPage = lppd->nMaxPage;
1453 if (lppd->nFromPage < lppd->nMinPage)
1454 lppd->nFromPage = lppd->nMinPage;
1455 if (lppd->nFromPage > lppd->nMaxPage)
1456 lppd->nFromPage = lppd->nMaxPage;
1457
1458 /* if we have the combo box, fill it */
1459 if (GetDlgItem(hDlg,comboID)) {
1460 /* Fill Combobox
1461 */
1462 pdn = GlobalLock(lppd->hDevNames);
1463 pdm = GlobalLock(lppd->hDevMode);
1464 if(pdn)
1465 name = (WCHAR*)pdn + pdn->wDeviceOffset;
1466 else if(pdm)
1467 name = pdm->dmDeviceName;
1468 PRINTDLG_SetUpPrinterListComboW(hDlg, comboID, name);
1469 if(pdm) GlobalUnlock(lppd->hDevMode);
1470 if(pdn) GlobalUnlock(lppd->hDevNames);
1471
1472 /* Now find selected printer and update rest of dlg */
1473 /* ansi is ok here */
1474 name = HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR));
1475 if (GetDlgItemTextW(hDlg, comboID, name, 255))
1476 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1477 HeapFree(GetProcessHeap(),0,name);
1478 } else {
1479 /* else use default printer */
1480 WCHAR name[200];
1481 DWORD dwBufLen = sizeof(name) / sizeof(WCHAR);
1482 BOOL ret = GetDefaultPrinterW(name, &dwBufLen);
1483
1484 if (ret)
1485 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1486 else
1487 FIXME("No default printer found, expect problems!\n");
1488 }
1489 return TRUE;
1490 }
1491
1492 /***********************************************************************
1493 * PRINTDLG_WMCommand [internal]
1494 */
1495 LRESULT PRINTDLG_WMCommandA(HWND hDlg, WPARAM wParam,
1496 LPARAM lParam, PRINT_PTRA* PrintStructures)
1497 {
1498 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
1499 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1500 LPDEVMODEA lpdm = PrintStructures->lpDevMode;
1501
1502 switch (LOWORD(wParam)) {
1503 case IDOK:
1504 TRACE(" OK button was hit\n");
1505 if (!PRINTDLG_UpdatePrintDlgA(hDlg, PrintStructures)) {
1506 FIXME("Update printdlg was not successful!\n");
1507 return(FALSE);
1508 }
1509 EndDialog(hDlg, TRUE);
1510 return(TRUE);
1511
1512 case IDCANCEL:
1513 TRACE(" CANCEL button was hit\n");
1514 EndDialog(hDlg, FALSE);
1515 return(FALSE);
1516
1517 case pshHelp:
1518 TRACE(" HELP button was hit\n");
1519 SendMessageA(lppd->hwndOwner, PrintStructures->HelpMessageID,
1520 (WPARAM) hDlg, (LPARAM) lppd);
1521 break;
1522
1523 case chx2: /* collate pages checkbox */
1524 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1525 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1526 (LPARAM)PrintStructures->hCollateIcon);
1527 else
1528 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1529 (LPARAM)PrintStructures->hNoCollateIcon);
1530 break;
1531 case edt1: /* from page nr editbox */
1532 case edt2: /* to page nr editbox */
1533 if (HIWORD(wParam)==EN_CHANGE) {
1534 WORD nToPage;
1535 WORD nFromPage;
1536 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1537 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1538 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1539 CheckRadioButton(hDlg, rad1, rad3, rad3);
1540 }
1541 break;
1542
1543 case edt3:
1544 if(HIWORD(wParam) == EN_CHANGE) {
1545 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1546 if(copies <= 1)
1547 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1548 else
1549 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1550 }
1551 break;
1552
1553 #if 0
1554 case psh1: /* Print Setup */
1555 {
1556 PRINTDLG16 pdlg;
1557
1558 if (!PrintStructures->dlg.lpPrintDlg16) {
1559 FIXME("The 32bit print dialog does not have this button!?\n");
1560 break;
1561 }
1562
1563 memcpy(&pdlg,PrintStructures->dlg.lpPrintDlg16,sizeof(pdlg));
1564 pdlg.Flags |= PD_PRINTSETUP;
1565 pdlg.hwndOwner = HWND_16(hDlg);
1566 if (!PrintDlg16(&pdlg))
1567 break;
1568 }
1569 break;
1570 #endif
1571 case psh2: /* Properties button */
1572 {
1573 HANDLE hPrinter;
1574 char PrinterName[256];
1575
1576 GetDlgItemTextA(hDlg, PrinterComboID, PrinterName, 255);
1577 if (!OpenPrinterA(PrinterName, &hPrinter, NULL)) {
1578 FIXME(" Call to OpenPrinter did not succeed!\n");
1579 break;
1580 }
1581 DocumentPropertiesA(hDlg, hPrinter, PrinterName,
1582 PrintStructures->lpDevMode,
1583 PrintStructures->lpDevMode,
1584 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1585 ClosePrinter(hPrinter);
1586 break;
1587 }
1588
1589 case rad1: /* Paperorientation */
1590 if (lppd->Flags & PD_PRINTSETUP)
1591 {
1592 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1593 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1594 (LPARAM)(PrintStructures->hPortraitIcon));
1595 }
1596 break;
1597
1598 case rad2: /* Paperorientation */
1599 if (lppd->Flags & PD_PRINTSETUP)
1600 {
1601 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1602 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1603 (LPARAM)(PrintStructures->hLandscapeIcon));
1604 }
1605 break;
1606
1607 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT16 */
1608 if (PrinterComboID != LOWORD(wParam)) {
1609 break;
1610 }
1611 /* FALLTHROUGH */
1612 case cmb4: /* Printer combobox */
1613 if (HIWORD(wParam)==CBN_SELCHANGE) {
1614 char PrinterName[256];
1615 GetDlgItemTextA(hDlg, LOWORD(wParam), PrinterName, 255);
1616 PRINTDLG_ChangePrinterA(hDlg, PrinterName, PrintStructures);
1617 }
1618 break;
1619
1620 case cmb2: /* Papersize */
1621 {
1622 DWORD Sel = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1623 if(Sel != CB_ERR)
1624 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
1625 CB_GETITEMDATA,
1626 Sel, 0);
1627 }
1628 break;
1629
1630 case cmb3: /* Bin */
1631 {
1632 DWORD Sel = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1633 if(Sel != CB_ERR)
1634 lpdm->u1.s1.dmDefaultSource = SendDlgItemMessageA(hDlg, cmb3,
1635 CB_GETITEMDATA, Sel,
1636 0);
1637 }
1638 break;
1639 }
1640 if(lppd->Flags & PD_PRINTSETUP) {
1641 switch (LOWORD(wParam)) {
1642 case rad1: /* orientation */
1643 case rad2:
1644 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1645 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1646 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1647 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1648 (WPARAM)IMAGE_ICON,
1649 (LPARAM)PrintStructures->hPortraitIcon);
1650 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1651 (WPARAM)IMAGE_ICON,
1652 (LPARAM)PrintStructures->hPortraitIcon);
1653 }
1654 } else {
1655 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1656 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1657 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1658 (WPARAM)IMAGE_ICON,
1659 (LPARAM)PrintStructures->hLandscapeIcon);
1660 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1661 (WPARAM)IMAGE_ICON,
1662 (LPARAM)PrintStructures->hLandscapeIcon);
1663 }
1664 }
1665 break;
1666 }
1667 }
1668 return FALSE;
1669 }
1670
1671 static LRESULT PRINTDLG_WMCommandW(HWND hDlg, WPARAM wParam,
1672 LPARAM lParam, PRINT_PTRW* PrintStructures)
1673 {
1674 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1675 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1676 LPDEVMODEW lpdm = PrintStructures->lpDevMode;
1677
1678 switch (LOWORD(wParam)) {
1679 case IDOK:
1680 TRACE(" OK button was hit\n");
1681 if (!PRINTDLG_UpdatePrintDlgW(hDlg, PrintStructures)) {
1682 FIXME("Update printdlg was not successful!\n");
1683 return(FALSE);
1684 }
1685 EndDialog(hDlg, TRUE);
1686 return(TRUE);
1687
1688 case IDCANCEL:
1689 TRACE(" CANCEL button was hit\n");
1690 EndDialog(hDlg, FALSE);
1691 return(FALSE);
1692
1693 case pshHelp:
1694 TRACE(" HELP button was hit\n");
1695 SendMessageW(lppd->hwndOwner, PrintStructures->HelpMessageID,
1696 (WPARAM) hDlg, (LPARAM) lppd);
1697 break;
1698
1699 case chx2: /* collate pages checkbox */
1700 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1701 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1702 (LPARAM)PrintStructures->hCollateIcon);
1703 else
1704 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1705 (LPARAM)PrintStructures->hNoCollateIcon);
1706 break;
1707 case edt1: /* from page nr editbox */
1708 case edt2: /* to page nr editbox */
1709 if (HIWORD(wParam)==EN_CHANGE) {
1710 WORD nToPage;
1711 WORD nFromPage;
1712 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1713 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1714 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1715 CheckRadioButton(hDlg, rad1, rad3, rad3);
1716 }
1717 break;
1718
1719 case edt3:
1720 if(HIWORD(wParam) == EN_CHANGE) {
1721 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1722 if(copies <= 1)
1723 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1724 else
1725 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1726 }
1727 break;
1728
1729 case psh1: /* Print Setup */
1730 {
1731 ERR("psh1 is called from 16bit code only, we should not get here.\n");
1732 }
1733 break;
1734 case psh2: /* Properties button */
1735 {
1736 HANDLE hPrinter;
1737 WCHAR PrinterName[256];
1738
1739 if (!GetDlgItemTextW(hDlg, PrinterComboID, PrinterName, 255)) break;
1740 if (!OpenPrinterW(PrinterName, &hPrinter, NULL)) {
1741 FIXME(" Call to OpenPrinter did not succeed!\n");
1742 break;
1743 }
1744 DocumentPropertiesW(hDlg, hPrinter, PrinterName,
1745 PrintStructures->lpDevMode,
1746 PrintStructures->lpDevMode,
1747 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1748 ClosePrinter(hPrinter);
1749 break;
1750 }
1751
1752 case rad1: /* Paperorientation */
1753 if (lppd->Flags & PD_PRINTSETUP)
1754 {
1755 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1756 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1757 (LPARAM)(PrintStructures->hPortraitIcon));
1758 }
1759 break;
1760
1761 case rad2: /* Paperorientation */
1762 if (lppd->Flags & PD_PRINTSETUP)
1763 {
1764 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1765 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1766 (LPARAM)(PrintStructures->hLandscapeIcon));
1767 }
1768 break;
1769
1770 case cmb1: /* Printer Combobox in PRINT SETUP */
1771 /* FALLTHROUGH */
1772 case cmb4: /* Printer combobox */
1773 if (HIWORD(wParam)==CBN_SELCHANGE) {
1774 WCHAR PrinterName[256];
1775 GetDlgItemTextW(hDlg, LOWORD(wParam), PrinterName, 255);
1776 PRINTDLG_ChangePrinterW(hDlg, PrinterName, PrintStructures);
1777 }
1778 break;
1779
1780 case cmb2: /* Papersize */
1781 {
1782 DWORD Sel = SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1783 if(Sel != CB_ERR)
1784 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageW(hDlg, cmb2,
1785 CB_GETITEMDATA,
1786 Sel, 0);
1787 }
1788 break;
1789
1790 case cmb3: /* Bin */
1791 {
1792 DWORD Sel = SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1793 if(Sel != CB_ERR)
1794 lpdm->u1.s1.dmDefaultSource = SendDlgItemMessageW(hDlg, cmb3,
1795 CB_GETITEMDATA, Sel,
1796 0);
1797 }
1798 break;
1799 }
1800 if(lppd->Flags & PD_PRINTSETUP) {
1801 switch (LOWORD(wParam)) {
1802 case rad1: /* orientation */
1803 case rad2:
1804 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1805 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1806 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1807 SendDlgItemMessageW(hDlg, stc10, STM_SETIMAGE,
1808 (WPARAM)IMAGE_ICON,
1809 (LPARAM)PrintStructures->hPortraitIcon);
1810 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE,
1811 (WPARAM)IMAGE_ICON,
1812 (LPARAM)PrintStructures->hPortraitIcon);
1813 }
1814 } else {
1815 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1816 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1817 SendDlgItemMessageW(hDlg, stc10, STM_SETIMAGE,
1818 (WPARAM)IMAGE_ICON,
1819 (LPARAM)PrintStructures->hLandscapeIcon);
1820 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE,
1821 (WPARAM)IMAGE_ICON,
1822 (LPARAM)PrintStructures->hLandscapeIcon);
1823 }
1824 }
1825 break;
1826 }
1827 }
1828 return FALSE;
1829 }
1830
1831 /***********************************************************************
1832 * PrintDlgProcA [internal]
1833 */
1834 static INT_PTR CALLBACK PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
1835 LPARAM lParam)
1836 {
1837 PRINT_PTRA* PrintStructures;
1838 INT_PTR res = FALSE;
1839
1840 if (uMsg!=WM_INITDIALOG) {
1841 PrintStructures = (PRINT_PTRA*)GetPropA(hDlg,"__WINE_PRINTDLGDATA");
1842 if (!PrintStructures)
1843 return FALSE;
1844 } else {
1845 PrintStructures = (PRINT_PTRA*) lParam;
1846 SetPropA(hDlg,"__WINE_PRINTDLGDATA",PrintStructures);
1847 if(!check_printer_setup(hDlg))
1848 {
1849 EndDialog(hDlg,FALSE);
1850 return FALSE;
1851 }
1852 res = PRINTDLG_WMInitDialog(hDlg, wParam, PrintStructures);
1853
1854 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
1855 res = PrintStructures->lpPrintDlg->lpfnPrintHook(
1856 hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg
1857 );
1858 return res;
1859 }
1860
1861 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
1862 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam,
1863 lParam);
1864 if(res) return res;
1865 }
1866
1867 switch (uMsg) {
1868 case WM_COMMAND:
1869 return PRINTDLG_WMCommandA(hDlg, wParam, lParam, PrintStructures);
1870
1871 case WM_DESTROY:
1872 DestroyIcon(PrintStructures->hCollateIcon);
1873 DestroyIcon(PrintStructures->hNoCollateIcon);
1874 DestroyIcon(PrintStructures->hPortraitIcon);
1875 DestroyIcon(PrintStructures->hLandscapeIcon);
1876 if(PrintStructures->hwndUpDown)
1877 DestroyWindow(PrintStructures->hwndUpDown);
1878 return FALSE;
1879 }
1880 return res;
1881 }
1882
1883 static INT_PTR CALLBACK PrintDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
1884 LPARAM lParam)
1885 {
1886 static const WCHAR propW[] = {'_','_','W','I','N','E','_','P','R','I','N','T','D','L','G','D','A','T','A',0};
1887 PRINT_PTRW* PrintStructures;
1888 INT_PTR res = FALSE;
1889
1890 if (uMsg!=WM_INITDIALOG) {
1891 PrintStructures = (PRINT_PTRW*) GetPropW(hDlg, propW);
1892 if (!PrintStructures)
1893 return FALSE;
1894 } else {
1895 PrintStructures = (PRINT_PTRW*) lParam;
1896 SetPropW(hDlg, propW, PrintStructures);
1897 if(!check_printer_setup(hDlg))
1898 {
1899 EndDialog(hDlg,FALSE);
1900 return FALSE;
1901 }
1902 res = PRINTDLG_WMInitDialogW(hDlg, wParam, PrintStructures);
1903
1904 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
1905 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg);
1906 return res;
1907 }
1908
1909 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
1910 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam, lParam);
1911 if(res) return res;
1912 }
1913
1914 switch (uMsg) {
1915 case WM_COMMAND:
1916 return PRINTDLG_WMCommandW(hDlg, wParam, lParam, PrintStructures);
1917
1918 case WM_DESTROY:
1919 DestroyIcon(PrintStructures->hCollateIcon);
1920 DestroyIcon(PrintStructures->hNoCollateIcon);
1921 DestroyIcon(PrintStructures->hPortraitIcon);
1922 DestroyIcon(PrintStructures->hLandscapeIcon);
1923 if(PrintStructures->hwndUpDown)
1924 DestroyWindow(PrintStructures->hwndUpDown);
1925 return FALSE;
1926 }
1927 return res;
1928 }
1929
1930 /************************************************************
1931 *
1932 * PRINTDLG_GetDlgTemplate
1933 *
1934 */
1935 static HGLOBAL PRINTDLG_GetDlgTemplateA(const PRINTDLGA *lppd)
1936 {
1937 HRSRC hResInfo;
1938 HGLOBAL hDlgTmpl;
1939
1940 if (lppd->Flags & PD_PRINTSETUP) {
1941 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
1942 hDlgTmpl = lppd->hSetupTemplate;
1943 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
1944 hResInfo = FindResourceA(lppd->hInstance,
1945 lppd->lpSetupTemplateName, (LPSTR)RT_DIALOG);
1946 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1947 } else {
1948 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32_SETUP",
1949 (LPSTR)RT_DIALOG);
1950 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1951 }
1952 } else {
1953 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
1954 hDlgTmpl = lppd->hPrintTemplate;
1955 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
1956 hResInfo = FindResourceA(lppd->hInstance,
1957 lppd->lpPrintTemplateName,
1958 (LPSTR)RT_DIALOG);
1959 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1960 } else {
1961 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32",
1962 (LPSTR)RT_DIALOG);
1963 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1964 }
1965 }
1966 return hDlgTmpl;
1967 }
1968
1969 static HGLOBAL PRINTDLG_GetDlgTemplateW(const PRINTDLGW *lppd)
1970 {
1971 HRSRC hResInfo;
1972 HGLOBAL hDlgTmpl;
1973 static const WCHAR xpsetup[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
1974 static const WCHAR xprint[] = { 'P','R','I','N','T','3','2',0};
1975
1976 if (lppd->Flags & PD_PRINTSETUP) {
1977 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
1978 hDlgTmpl = lppd->hSetupTemplate;
1979 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
1980 hResInfo = FindResourceW(lppd->hInstance,
1981 lppd->lpSetupTemplateName, (LPWSTR)RT_DIALOG);
1982 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1983 } else {
1984 hResInfo = FindResourceW(COMDLG32_hInstance, xpsetup, (LPWSTR)RT_DIALOG);
1985 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1986 }
1987 } else {
1988 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
1989 hDlgTmpl = lppd->hPrintTemplate;
1990 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
1991 hResInfo = FindResourceW(lppd->hInstance,
1992 lppd->lpPrintTemplateName,
1993 (LPWSTR)RT_DIALOG);
1994 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1995 } else {
1996 hResInfo = FindResourceW(COMDLG32_hInstance, xprint, (LPWSTR)RT_DIALOG);
1997 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1998 }
1999 }
2000 return hDlgTmpl;
2001 }
2002
2003 /***********************************************************************
2004 *
2005 * PRINTDLG_CreateDC
2006 *
2007 */
2008 static BOOL PRINTDLG_CreateDCA(LPPRINTDLGA lppd)
2009 {
2010 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
2011 DEVMODEA *pdm = GlobalLock(lppd->hDevMode);
2012
2013 if(lppd->Flags & PD_RETURNDC) {
2014 lppd->hDC = CreateDCA((char*)pdn + pdn->wDriverOffset,
2015 (char*)pdn + pdn->wDeviceOffset,
2016 (char*)pdn + pdn->wOutputOffset,
2017 pdm );
2018 } else if(lppd->Flags & PD_RETURNIC) {
2019 lppd->hDC = CreateICA((char*)pdn + pdn->wDriverOffset,
2020 (char*)pdn + pdn->wDeviceOffset,
2021 (char*)pdn + pdn->wOutputOffset,
2022 pdm );
2023 }
2024 GlobalUnlock(lppd->hDevNames);
2025 GlobalUnlock(lppd->hDevMode);
2026 return lppd->hDC ? TRUE : FALSE;
2027 }
2028
2029 static BOOL PRINTDLG_CreateDCW(LPPRINTDLGW lppd)
2030 {
2031 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
2032 DEVMODEW *pdm = GlobalLock(lppd->hDevMode);
2033
2034 if(lppd->Flags & PD_RETURNDC) {
2035 lppd->hDC = CreateDCW((WCHAR*)pdn + pdn->wDriverOffset,
2036 (WCHAR*)pdn + pdn->wDeviceOffset,
2037 (WCHAR*)pdn + pdn->wOutputOffset,
2038 pdm );
2039 } else if(lppd->Flags & PD_RETURNIC) {
2040 lppd->hDC = CreateICW((WCHAR*)pdn + pdn->wDriverOffset,
2041 (WCHAR*)pdn + pdn->wDeviceOffset,
2042 (WCHAR*)pdn + pdn->wOutputOffset,
2043 pdm );
2044 }
2045 GlobalUnlock(lppd->hDevNames);
2046 GlobalUnlock(lppd->hDevMode);
2047 return lppd->hDC ? TRUE : FALSE;
2048 }
2049
2050 /***********************************************************************
2051 * PrintDlgA (COMDLG32.@)
2052 *
2053 * Displays the PRINT dialog box, which enables the user to specify
2054 * specific properties of the print job.
2055 *
2056 * PARAMS
2057 * lppd [IO] ptr to PRINTDLG32 struct
2058 *
2059 * RETURNS
2060 * nonzero if the user pressed the OK button
2061 * zero if the user cancelled the window or an error occurred
2062 *
2063 * BUGS
2064 * PrintDlg:
2065 * * The Collate Icons do not display, even though they are in the code.
2066 * * The Properties Button(s) should call DocumentPropertiesA().
2067 */
2068
2069 BOOL WINAPI PrintDlgA(LPPRINTDLGA lppd)
2070 {
2071 BOOL bRet = FALSE;
2072 LPVOID ptr;
2073 HINSTANCE hInst;
2074
2075 if (!lppd)
2076 {
2077 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION);
2078 return FALSE;
2079 }
2080
2081 hInst = (HINSTANCE)GetWindowLongPtrA( lppd->hwndOwner, GWLP_HINSTANCE );
2082 if(TRACE_ON(commdlg)) {
2083 char flagstr[1000] = "";
2084 const struct pd_flags *pflag = pd_flags;
2085 for( ; pflag->name; pflag++) {
2086 if(lppd->Flags & pflag->flag)
2087 strcat(flagstr, pflag->name);
2088 }
2089 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2090 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2091 "flags %08x (%s)\n",
2092 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2093 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2094 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2095 }
2096
2097 if(lppd->lStructSize != sizeof(PRINTDLGA)) {
2098 WARN("structure size failure !!!\n");
2099 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2100 return FALSE;
2101 }
2102
2103 if(lppd->Flags & PD_RETURNDEFAULT) {
2104 PRINTER_INFO_2A *pbuf;
2105 DRIVER_INFO_3A *dbuf;
2106 HANDLE hprn;
2107 DWORD needed;
2108
2109 if(lppd->hDevMode || lppd->hDevNames) {
2110 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2111 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2112 return FALSE;
2113 }
2114 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2115 WARN("Can't find default printer\n");
2116 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2117 return FALSE;
2118 }
2119
2120 GetPrinterA(hprn, 2, NULL, 0, &needed);
2121 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
2122 GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2123
2124 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
2125 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
2126 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2127 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2128 GetLastError(),pbuf->pPrinterName);
2129 HeapFree(GetProcessHeap(), 0, dbuf);
2130 HeapFree(GetProcessHeap(), 0, pbuf);
2131 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2132 return FALSE;
2133 }
2134 ClosePrinter(hprn);
2135
2136 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2137 dbuf->pDriverPath,
2138 pbuf->pPrinterName,
2139 pbuf->pPortName);
2140 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2141 pbuf->pDevMode->dmDriverExtra);
2142 ptr = GlobalLock(lppd->hDevMode);
2143 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2144 pbuf->pDevMode->dmDriverExtra);
2145 GlobalUnlock(lppd->hDevMode);
2146 HeapFree(GetProcessHeap(), 0, pbuf);
2147 HeapFree(GetProcessHeap(), 0, dbuf);
2148 bRet = TRUE;
2149 } else {
2150 HGLOBAL hDlgTmpl;
2151 PRINT_PTRA *PrintStructures;
2152
2153 /* load Dialog resources,
2154 * depending on Flags indicates Print32 or Print32_setup dialog
2155 */
2156 hDlgTmpl = PRINTDLG_GetDlgTemplateA(lppd);
2157 if (!hDlgTmpl) {
2158 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2159 return FALSE;
2160 }
2161 ptr = LockResource( hDlgTmpl );
2162 if (!ptr) {
2163 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2164 return FALSE;
2165 }
2166
2167 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2168 sizeof(PRINT_PTRA));
2169 PrintStructures->lpPrintDlg = lppd;
2170
2171 /* and create & process the dialog .
2172 * -1 is failure, 0 is broken hwnd, everything else is ok.
2173 */
2174 bRet = (0<DialogBoxIndirectParamA(hInst, ptr, lppd->hwndOwner,
2175 PrintDlgProcA,
2176 (LPARAM)PrintStructures));
2177
2178 if(bRet) {
2179 DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2180 PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
2181 DRIVER_INFO_3A *di = PrintStructures->lpDriverInfo;
2182
2183 if (lppd->hDevMode == 0) {
2184 TRACE(" No hDevMode yet... Need to create my own\n");
2185 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2186 lpdm->dmSize + lpdm->dmDriverExtra);
2187 } else {
2188 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2189 lpdm->dmSize + lpdm->dmDriverExtra,
2190 GMEM_MOVEABLE);
2191 }
2192 lpdmReturn = GlobalLock(lppd->hDevMode);
2193 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2194
2195 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2196 di->pDriverPath,
2197 pi->pPrinterName,
2198 pi->pPortName
2199 );
2200 GlobalUnlock(lppd->hDevMode);
2201 }
2202 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2203 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2204 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2205 HeapFree(GetProcessHeap(), 0, PrintStructures);
2206 }
2207 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2208 bRet = PRINTDLG_CreateDCA(lppd);
2209
2210 TRACE("exit! (%d)\n", bRet);
2211 return bRet;
2212 }
2213
2214 /***********************************************************************
2215 * PrintDlgW (COMDLG32.@)
2216 *
2217 * See PrintDlgA.
2218 */
2219 BOOL WINAPI PrintDlgW(LPPRINTDLGW lppd)
2220 {
2221 BOOL bRet = FALSE;
2222 LPVOID ptr;
2223 HINSTANCE hInst;
2224
2225 if (!lppd)
2226 {
2227 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION);
2228 return FALSE;
2229 }
2230
2231 hInst = (HINSTANCE)GetWindowLongPtrW( lppd->hwndOwner, GWLP_HINSTANCE );
2232 if(TRACE_ON(commdlg)) {
2233 char flagstr[1000] = "";
2234 const struct pd_flags *pflag = pd_flags;
2235 for( ; pflag->name; pflag++) {
2236 if(lppd->Flags & pflag->flag)
2237 strcat(flagstr, pflag->name);
2238 }
2239 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2240 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2241 "flags %08x (%s)\n",
2242 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2243 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2244 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2245 }
2246
2247 if(lppd->lStructSize != sizeof(PRINTDLGW)) {
2248 WARN("structure size failure !!!\n");
2249 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2250 return FALSE;
2251 }
2252
2253 if(lppd->Flags & PD_RETURNDEFAULT) {
2254 PRINTER_INFO_2W *pbuf;
2255 DRIVER_INFO_3W *dbuf;
2256 HANDLE hprn;
2257 DWORD needed;
2258
2259 if(lppd->hDevMode || lppd->hDevNames) {
2260 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2261 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2262 return FALSE;
2263 }
2264 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2265 WARN("Can't find default printer\n");
2266 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2267 return FALSE;
2268 }
2269
2270 GetPrinterW(hprn, 2, NULL, 0, &needed);
2271 pbuf = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*needed);
2272 GetPrinterW(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2273
2274 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
2275 dbuf = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
2276 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2277 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2278 GetLastError(),debugstr_w(pbuf->pPrinterName));
2279 HeapFree(GetProcessHeap(), 0, dbuf);
2280 HeapFree(GetProcessHeap(), 0, pbuf);
2281 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2282 return FALSE;
2283 }
2284 ClosePrinter(hprn);
2285
2286 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2287 dbuf->pDriverPath,
2288 pbuf->pPrinterName,
2289 pbuf->pPortName);
2290 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2291 pbuf->pDevMode->dmDriverExtra);
2292 ptr = GlobalLock(lppd->hDevMode);
2293 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2294 pbuf->pDevMode->dmDriverExtra);
2295 GlobalUnlock(lppd->hDevMode);
2296 HeapFree(GetProcessHeap(), 0, pbuf);
2297 HeapFree(GetProcessHeap(), 0, dbuf);
2298 bRet = TRUE;
2299 } else {
2300 HGLOBAL hDlgTmpl;
2301 PRINT_PTRW *PrintStructures;
2302
2303 /* load Dialog resources,
2304 * depending on Flags indicates Print32 or Print32_setup dialog
2305 */
2306 hDlgTmpl = PRINTDLG_GetDlgTemplateW(lppd);
2307 if (!hDlgTmpl) {
2308 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2309 return FALSE;
2310 }
2311 ptr = LockResource( hDlgTmpl );
2312 if (!ptr) {
2313 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2314 return FALSE;
2315 }
2316
2317 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2318 sizeof(PRINT_PTRW));
2319 PrintStructures->lpPrintDlg = lppd;
2320
2321 /* and create & process the dialog .
2322 * -1 is failure, 0 is broken hwnd, everything else is ok.
2323 */
2324 bRet = (0<DialogBoxIndirectParamW(hInst, ptr, lppd->hwndOwner,
2325 PrintDlgProcW,
2326 (LPARAM)PrintStructures));
2327
2328 if(bRet) {
2329 DEVMODEW *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2330 PRINTER_INFO_2W *pi = PrintStructures->lpPrinterInfo;
2331 DRIVER_INFO_3W *di = PrintStructures->lpDriverInfo;
2332
2333 if (lppd->hDevMode == 0) {
2334 TRACE(" No hDevMode yet... Need to create my own\n");
2335 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2336 lpdm->dmSize + lpdm->dmDriverExtra);
2337 } else {
2338 WORD locks;
2339 if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
2340 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2341 while(locks--) {
2342 GlobalUnlock(lppd->hDevMode);
2343 TRACE("Now got %d locks\n", locks);
2344 }
2345 }
2346 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2347 lpdm->dmSize + lpdm->dmDriverExtra,
2348 GMEM_MOVEABLE);
2349 }
2350 lpdmReturn = GlobalLock(lppd->hDevMode);
2351 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2352
2353 if (lppd->hDevNames != 0) {
2354 WORD locks;
2355 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
2356 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2357 while(locks--)
2358 GlobalUnlock(lppd->hDevNames);
2359 }
2360 }
2361 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2362 di->pDriverPath,
2363 pi->pPrinterName,
2364 pi->pPortName
2365 );
2366 GlobalUnlock(lppd->hDevMode);
2367 }
2368 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2369 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2370 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2371 HeapFree(GetProcessHeap(), 0, PrintStructures);
2372 }
2373 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2374 bRet = PRINTDLG_CreateDCW(lppd);
2375
2376 TRACE("exit! (%d)\n", bRet);
2377 return bRet;
2378 }
2379
2380 /***********************************************************************
2381 *
2382 * PageSetupDlg
2383 * rad1 - portrait
2384 * rad2 - landscape
2385 * cmb1 - printer select (not in standard dialog template)
2386 * cmb2 - paper size
2387 * cmb3 - source (tray?)
2388 * edt4 - border left
2389 * edt5 - border top
2390 * edt6 - border right
2391 * edt7 - border bottom
2392 * psh3 - "Printer..."
2393 */
2394
2395 typedef struct {
2396 LPPAGESETUPDLGA dlga; /* Handler to user defined struct */
2397 PRINTDLGA pdlg;
2398 HWND hDlg; /* Page Setup dialog handler */
2399 PAGESETUPDLGA curdlg; /* Stores the current dialog state */
2400 RECT rtDrawRect; /* Drawing rect for page */
2401 } PageSetupDataA;
2402
2403 typedef struct {
2404 LPPAGESETUPDLGW dlgw;
2405 PRINTDLGW pdlg;
2406 PAGESETUPDLGW curdlg; /* Current dialog state */
2407 } PageSetupDataW;
2408
2409
2410 static HGLOBAL PRINTDLG_GetPGSTemplateA(const PAGESETUPDLGA *lppd)
2411 {
2412 HRSRC hResInfo;
2413 HGLOBAL hDlgTmpl;
2414
2415 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2416 hDlgTmpl = lppd->hPageSetupTemplate;
2417 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2418 hResInfo = FindResourceA(lppd->hInstance,
2419 lppd->lpPageSetupTemplateName, (LPSTR)RT_DIALOG);
2420 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2421 } else {
2422 hResInfo = FindResourceA(COMDLG32_hInstance,(LPCSTR)PAGESETUPDLGORD,(LPSTR)RT_DIALOG);
2423 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2424 }
2425 return hDlgTmpl;
2426 }
2427
2428 static HGLOBAL PRINTDLG_GetPGSTemplateW(const PAGESETUPDLGW *lppd)
2429 {
2430 HRSRC hResInfo;
2431 HGLOBAL hDlgTmpl;
2432
2433 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2434 hDlgTmpl = lppd->hPageSetupTemplate;
2435 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2436 hResInfo = FindResourceW(lppd->hInstance,
2437 lppd->lpPageSetupTemplateName, (LPWSTR)RT_DIALOG);
2438 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2439 } else {
2440 hResInfo = FindResourceW(COMDLG32_hInstance,(LPCWSTR)PAGESETUPDLGORD,(LPWSTR)RT_DIALOG);
2441 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2442 }
2443 return hDlgTmpl;
2444 }
2445
2446 static DWORD
2447 _c_10mm2size(PAGESETUPDLGA *dlga,DWORD size) {
2448 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2449 return 10*size*100/254;
2450 /* If we don't have a flag, we can choose one. Use millimeters
2451 * to avoid confusing me
2452 */
2453 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2454 return 10*size;
2455 }
2456
2457
2458 static DWORD
2459 _c_inch2size(PAGESETUPDLGA *dlga,DWORD size) {
2460 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2461 return size;
2462 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
2463 return (size*254)/100;
2464 /* if we don't have a flag, we can choose one. Use millimeters
2465 * to avoid confusing me
2466 */
2467 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2468 return (size*254)/100;
2469 }
2470
2471 static void
2472 _c_size2strA(PageSetupDataA *pda,DWORD size,LPSTR strout) {
2473 strcpy(strout,"<undef>");
2474 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2475 sprintf(strout,"%d",(size)/100);
2476 return;
2477 }
2478 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2479 sprintf(strout,"%din",(size)/1000);
2480 return;
2481 }
2482 pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2483 sprintf(strout,"%d",(size)/100);
2484 return;
2485 }
2486 static void
2487 _c_size2strW(PageSetupDataW *pdw,DWORD size,LPWSTR strout) {
2488 static const char mm_fmt[] = "%.2f mm";
2489 static const char in_fmt[] = "%.2f in";
2490 char buf[20];
2491 if (pdw->dlgw->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2492 sprintf(buf, mm_fmt, (size * 1.0) / 100.0);
2493 } else if (pdw->dlgw->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2494 sprintf(buf, in_fmt, (size * 1.0) / 1000.0);
2495 } else {
2496 pdw->dlgw->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2497 sprintf(buf, mm_fmt, (size * 1.0) / 100.0);
2498 }
2499
2500 MultiByteToWideChar(CP_ACP, 0, buf, -1, strout, 20);
2501 }
2502
2503 static DWORD
2504 _c_str2sizeA(const PAGESETUPDLGA *dlga, LPCSTR strin) {
2505 float val;
2506 char rest[200];
2507
2508 rest[0]='\0';
2509 if (!sscanf(strin,"%f%s",&val,rest))
2510 return 0;
2511
2512 if (!strcmp(rest,"in") || !strcmp(rest,"inch")) {
2513 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2514 return 1000*val;
2515 else
2516 return val*25.4*100;
2517 }
2518 if (!strcmp(rest,"cm")) { rest[0]='m'; val = val*10.0; }
2519 if (!strcmp(rest,"m")) { strcpy(rest,"mm"); val = val*1000.0; }
2520
2521 if (!strcmp(rest,"mm")) {
2522 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
2523 return 100*val;
2524 else
2525 return 1000.0*val/25.4;
2526 }
2527 if (rest[0]=='\0') {
2528 /* use application supplied default */
2529 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2530 /* 100*mm */
2531 return 100.0*val;
2532 }
2533 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2534 /* 1000*inch */
2535 return 1000.0*val;
2536 }
2537 }
2538 ERR("Did not find a conversion for type '%s'!\n",rest);
2539 return 0;
2540 }
2541
2542
2543 static DWORD
2544 _c_str2sizeW(const PAGESETUPDLGW *dlga, LPCWSTR strin) {
2545 char buf[200];
2546
2547 /* this W -> A transition is OK */
2548 /* we need a unicode version of sscanf to avoid it */
2549 WideCharToMultiByte(CP_ACP, 0, strin, -1, buf, sizeof(buf), NULL, NULL);
2550 return _c_str2sizeA((const PAGESETUPDLGA *)dlga, buf);
2551 }
2552
2553
2554 /****************************************************************************
2555 * PRINTDLG_PS_UpdateDlgStructA
2556 *
2557 * Updates pda->dlga structure
2558 * Function calls when user presses OK button
2559 *
2560 * PARAMS
2561 * hDlg [in] main window dialog HANDLE
2562 * pda [in/out] ptr to PageSetupDataA structure
2563 *
2564 * RETURNS
2565 * TRUE
2566 */
2567 static BOOL
2568 PRINTDLG_PS_UpdateDlgStructA(HWND hDlg, PageSetupDataA *pda) {
2569 DEVNAMES *dn;
2570 DEVMODEA *dm;
2571 DWORD paperword;
2572
2573 memcpy(pda->dlga, &pda->curdlg, sizeof(pda->curdlg));
2574 pda->dlga->hDevMode = pda->pdlg.hDevMode;
2575 pda->dlga->hDevNames = pda->pdlg.hDevNames;
2576
2577 dn = GlobalLock(pda->pdlg.hDevNames);
2578 dm = GlobalLock(pda->pdlg.hDevMode);
2579
2580 /* Save paper orientation into device context */
2581 if(pda->curdlg.ptPaperSize.x > pda->curdlg.ptPaperSize.y)
2582 dm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
2583 else
2584 dm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
2585
2586 /* Save paper size into the device context */
2587 paperword = SendDlgItemMessageA(hDlg,cmb2,CB_GETITEMDATA,
2588 SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0), 0);
2589 if (paperword != CB_ERR)
2590 dm->u1.s1.dmPaperSize = paperword;
2591 else
2592 FIXME("could not get dialog text for papersize cmbbox?\n");
2593
2594 /* Save paper source into the device context */
2595 paperword = SendDlgItemMessageA(hDlg,cmb1,CB_GETITEMDATA,
2596 SendDlgItemMessageA(hDlg, cmb1, CB_GETCURSEL, 0, 0), 0);
2597 if (paperword != CB_ERR)
2598 dm->u1.s1.dmDefaultSource = paperword;
2599 else
2600 FIXME("could not get dialog text for papersize cmbbox?\n");
2601
2602 GlobalUnlock(pda->pdlg.hDevNames);
2603 GlobalUnlock(pda->pdlg.hDevMode);
2604
2605 return TRUE;
2606 }
2607
2608 static BOOL
2609 PRINTDLG_PS_UpdateDlgStructW(HWND hDlg, PageSetupDataW *pdw) {
2610 DEVNAMES *dn;
2611 DEVMODEW *dm;
2612 LPWSTR devname,portname;
2613 WCHAR papername[64];
2614 WCHAR buf[200];
2615
2616 dn = GlobalLock(pdw->pdlg.hDevNames);
2617 dm = GlobalLock(pdw->pdlg.hDevMode);
2618 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
2619 portname = ((WCHAR*)dn)+dn->wOutputOffset;
2620
2621 /* Save paper size into device context */
2622 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
2623 /* Save paper source into device context */
2624 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
2625
2626 if (GetDlgItemTextW(hDlg,cmb2,papername,sizeof(papername)/sizeof(papername[0]))>0) {
2627 PRINTDLG_PaperSizeW(&(pdw->pdlg),papername,&(pdw->dlgw->ptPaperSize));
2628 pdw->dlgw->ptPaperSize.x = _c_10mm2size((LPPAGESETUPDLGA)pdw->dlgw,pdw->dlgw->ptPaperSize.x);
2629 pdw->dlgw->ptPaperSize.y = _c_10mm2size((LPPAGESETUPDLGA)pdw->dlgw,pdw->dlgw->ptPaperSize.y);
2630 } else
2631 FIXME("could not get dialog text for papersize cmbbox?\n");
2632 #define GETVAL(id,val) if (GetDlgItemTextW(hDlg,id,buf,sizeof(buf)/sizeof(buf[0]))>0) { val = _c_str2sizeW(pdw->dlgw,buf); } else { FIXME("could not get dlgitemtextw for %x\n",id); }
2633 GETVAL(edt4,pdw->dlgw->rtMargin.left);
2634 GETVAL(edt5,pdw->dlgw->rtMargin.top);
2635 GETVAL(edt6,pdw->dlgw->rtMargin.right);
2636 GETVAL(edt7,pdw->dlgw->rtMargin.bottom);
2637 #undef GETVAL
2638
2639 /* If we are in landscape, swap x and y of page size */
2640 if (IsDlgButtonChecked(hDlg, rad2)) {
2641 DWORD tmp;
2642 tmp = pdw->dlgw->ptPaperSize.x;
2643 pdw->dlgw->ptPaperSize.x = pdw->dlgw->ptPaperSize.y;
2644 pdw->dlgw->ptPaperSize.y = tmp;
2645 }
2646
2647 /* Save orientation */
2648 if (pdw->dlgw->ptPaperSize.x > pdw->dlgw->ptPaperSize.y)
2649 dm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
2650 else
2651 dm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
2652
2653 GlobalUnlock(pdw->pdlg.hDevNames);
2654 GlobalUnlock(pdw->pdlg.hDevMode);
2655 return TRUE;
2656 }
2657
2658 /**********************************************************************************************
2659 * PRINTDLG_PS_ChangeActivePrinerA
2660 *
2661 * Redefines hDevMode and hDevNames HANDLES and initialises it.
2662 *
2663 * PARAMS
2664 * name [in] Name of a printer for activation
2665 * pda [in/out] ptr to PageSetupDataA structure
2666 *
2667 * RETURN
2668 * TRUE if success
2669 * FALSE if fail
2670 */
2671 static BOOL
2672 PRINTDLG_PS_ChangeActivePrinterA(LPSTR name, PageSetupDataA *pda){
2673 HANDLE hprn;
2674 DWORD needed;
2675 LPPRINTER_INFO_2A lpPrinterInfo;
2676 LPDRIVER_INFO_3A lpDriverInfo;
2677 DEVMODEA *pDevMode, *dm;
2678
2679 if(!OpenPrinterA(name, &hprn, NULL)){
2680 ERR("Can't open printer %s\n", name);
2681 return FALSE;
2682 }
2683 GetPrinterA(hprn, 2, NULL, 0, &needed);
2684 lpPrinterInfo = HeapAlloc(GetProcessHeap(), 0, needed);
2685 GetPrinterA(hprn, 2, (LPBYTE)lpPrinterInfo, needed, &needed);
2686 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
2687 lpDriverInfo = HeapAlloc(GetProcessHeap(), 0, needed);
2688 if(!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)lpDriverInfo, needed, &needed)) {
2689 ERR("GetPrinterDriverA failed for %s, fix your config!\n", lpPrinterInfo->pPrinterName);
2690 HeapFree(GetProcessHeap(), 0, lpDriverInfo);
2691 HeapFree(GetProcessHeap(), 0, lpPrinterInfo);
2692 return FALSE;
2693 }
2694 ClosePrinter(hprn);
2695
2696 needed = DocumentPropertiesA(0, 0, name, NULL, NULL, 0);
2697 if(needed == -1) {
2698 ERR("DocumentProperties fails on %s\n", debugstr_a(name));
2699 HeapFree(GetProcessHeap(), 0, lpDriverInfo);
2700 HeapFree(GetProcessHeap(), 0, lpPrinterInfo);
2701 return FALSE;
2702 }
2703 pDevMode = HeapAlloc(GetProcessHeap(), 0, needed);
2704 DocumentPropertiesA(0, 0, name, pDevMode, NULL, DM_OUT_BUFFER);
2705
2706 pda->pdlg.hDevMode = GlobalReAlloc(pda->pdlg.hDevMode,
2707 pDevMode->dmSize + pDevMode->dmDriverExtra,
2708 GMEM_MOVEABLE);
2709 dm = GlobalLock(pda->pdlg.hDevMode);
2710 memcpy(dm, pDevMode, pDevMode->dmSize + pDevMode->dmDriverExtra);
2711
2712 PRINTDLG_CreateDevNames(&(pda->pdlg.hDevNames),
2713 lpDriverInfo->pDriverPath,
2714 lpPrinterInfo->pPrinterName,
2715 lpPrinterInfo->pPortName);
2716
2717 GlobalUnlock(pda->pdlg.hDevMode);
2718 HeapFree(GetProcessHeap(), 0, pDevMode);
2719 HeapFree(GetProcessHeap(), 0, lpPrinterInfo);
2720 HeapFree(GetProcessHeap(), 0, lpDriverInfo);
2721 return TRUE;
2722 }
2723
2724 /****************************************************************************************
2725 * PRINTDLG_PS_ChangePrinterA
2726 *
2727 * Fills Printers, Paper and Source combo
2728 *
2729 * RETURNS
2730 * TRUE
2731 */
2732 static BOOL
2733 PRINTDLG_PS_ChangePrinterA(HWND hDlg, PageSetupDataA *pda) {
2734 DEVNAMES *dn;
2735 DEVMODEA *dm;
2736 LPSTR devname,portname;
2737
2738 dn = GlobalLock(pda->pdlg.hDevNames);
2739 dm = GlobalLock(pda->pdlg.hDevMode);
2740 devname = ((char*)dn)+dn->wDeviceOffset;
2741 portname = ((char*)dn)+dn->wOutputOffset;
2742 PRINTDLG_SetUpPrinterListComboA(hDlg, cmb1, devname);
2743 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb2,devname,portname,dm);
2744 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb3,devname,portname,dm);
2745 GlobalUnlock(pda->pdlg.hDevNames);
2746 GlobalUnlock(pda->pdlg.hDevMode);
2747 return TRUE;
2748 }
2749
2750 static void PRINTDLG_PS_SetOrientationW(HWND hDlg, PageSetupDataW* pdw)
2751 {
2752 WCHAR PaperName[64];
2753
2754 GetDlgItemTextW(hDlg, cmb2, PaperName, sizeof(PaperName)/sizeof(WCHAR));
2755 PRINTDLG_PaperSizeW(&pdw->pdlg, PaperName, &pdw->curdlg.ptPaperSize);
2756 pdw->curdlg.ptPaperSize.x = _c_10mm2size((LPPAGESETUPDLGA)pdw->dlgw, pdw->curdlg.ptPaperSize.x);
2757 pdw->curdlg.ptPaperSize.y = _c_10mm2size((LPPAGESETUPDLGA)pdw->dlgw, pdw->curdlg.ptPaperSize.y);
2758
2759 if(IsDlgButtonChecked(hDlg, rad2))
2760 {
2761 DWORD tmp = pdw->curdlg.ptPaperSize.x;
2762 pdw->curdlg.ptPaperSize.x = pdw->curdlg.ptPaperSize.y;
2763 pdw->curdlg.ptPaperSize.y = tmp;
2764 }
2765 }
2766
2767 static void PRINTDLG_PS_UpdatePrintDlgW(PageSetupDataW* pdw, HWND hDlg)
2768 {
2769 DEVMODEW* dm;
2770 DWORD sel;
2771
2772 dm = GlobalLock(pdw->pdlg.hDevMode);
2773
2774 if(!dm)
2775 return;
2776
2777 if(pdw->curdlg.ptPaperSize.y > pdw->curdlg.ptPaperSize.x)
2778 dm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
2779 else
2780 dm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
2781
2782 sel = SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0);
2783
2784 if(sel != CB_ERR)
2785 dm->u1.s1.dmPaperSize = SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, sel, 0);
2786
2787 GlobalUnlock(pdw->pdlg.hDevMode);
2788 }
2789
2790 static BOOL
2791 PRINTDLG_PS_ChangePrinterW(HWND hDlg, PageSetupDataW *pdw) {
2792 DEVNAMES *dn;
2793 DEVMODEW *dm;
2794 LPWSTR devname,portname;
2795
2796 dn = GlobalLock(pdw->pdlg.hDevNames);
2797 dm = GlobalLock(pdw->pdlg.hDevMode);
2798 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
2799 portname = ((WCHAR*)dn)+dn->wOutputOffset;
2800 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
2801 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
2802
2803 /* Landscape orientation */
2804 if (dm->u1.s1.dmOrientation == DMORIENT_LANDSCAPE)
2805 CheckRadioButton(hDlg, rad1, rad2, rad2);
2806 else /* this is default if papersize is not set */
2807 CheckRadioButton(hDlg, rad1, rad2, rad1);
2808
2809 GlobalUnlock(pdw->pdlg.hDevNames);
2810 GlobalUnlock(pdw->pdlg.hDevMode);
2811
2812 PRINTDLG_PS_SetOrientationW(hDlg, pdw);
2813
2814 return TRUE;
2815 }
2816
2817 /******************************************************************************************
2818 * PRINTDLG_PS_ChangePaperPrev
2819 *
2820 * Changes paper preview size / position
2821 *
2822 * PARAMS:
2823 * pda [i] Pointer for current PageSetupDataA structure
2824 *
2825 * RETURNS:
2826 * always - TRUE
2827 */
2828 static BOOL
2829 PRINTDLG_PS_ChangePaperPrev(const PageSetupDataA *pda)
2830 {
2831 LONG width, height, x, y;
2832 RECT rtTmp;
2833
2834 if(pda->curdlg.ptPaperSize.x > pda->curdlg.ptPaperSize.y) {
2835 width = pda->rtDrawRect.right - pda->rtDrawRect.left;
2836 height = pda->curdlg.ptPaperSize.y * width / pda->curdlg.ptPaperSize.x;
2837 } else {
2838 height = pda->rtDrawRect.bottom - pda->rtDrawRect.top;
2839 width = pda->curdlg.ptPaperSize.x * height / pda->curdlg.ptPaperSize.y;
2840 }
2841 x = (pda->rtDrawRect.right + pda->rtDrawRect.left - width) / 2;
2842 y = (pda->rtDrawRect.bottom + pda->rtDrawRect.top - height) / 2;
2843 TRACE("rtDrawRect(%d, %d, %d, %d) x=%d, y=%d, w=%d, h=%d\n",
2844 pda->rtDrawRect.left, pda->rtDrawRect.top, pda->rtDrawRect.right, pda->rtDrawRect.bottom,
2845 x, y, width, height);
2846
2847 #define SHADOW 4
2848 MoveWindow(GetDlgItem(pda->hDlg, rct2), x+width, y+SHADOW, SHADOW, height, FALSE);
2849 MoveWindow(GetDlgItem(pda->hDlg, rct3), x+SHADOW, y+height, width, SHADOW, FALSE);
2850 MoveWindow(GetDlgItem(pda->hDlg, rct1), x, y, width, height, FALSE);
2851 rtTmp = pda->rtDrawRect;
2852 rtTmp.right += SHADOW;
2853 rtTmp.bottom += SHADOW;
2854 #undef SHADOW
2855
2856 InvalidateRect(pda->hDlg, &rtTmp, TRUE);
2857 return TRUE;
2858 }
2859
2860 #define GETVAL(idc,val) \
2861 if(msg == EN_CHANGE){ \
2862 if (GetDlgItemTextA(hDlg,idc,buf,sizeof(buf)) > 0)\
2863 val = _c_str2sizeA(pda->dlga,buf); \
2864 else\
2865 FIXME("could not get dlgitemtexta for %x\n",id); \
2866 }
2867
2868 /********************************************************************************
2869 * PRINTDLG_PS_WMCommandA
2870 * process WM_COMMAND message for PageSetupDlgA
2871 *
2872 * PARAMS
2873 * hDlg [in] Main dialog HANDLE
2874 * wParam [in] WM_COMMAND wParam
2875 * lParam [in] WM_COMMAND lParam
2876 * pda [in/out] ptr to PageSetupDataA
2877 */
2878
2879 static BOOL
2880 PRINTDLG_PS_WMCommandA(
2881 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataA *pda
2882 ) {
2883 WORD msg = HIWORD(wParam);
2884 WORD id = LOWORD(wParam);
2885 char buf[200];
2886
2887 TRACE("loword (lparam) %d, wparam 0x%lx, lparam %08lx\n",
2888 LOWORD(lParam),wParam,lParam);
2889 switch (id) {
2890 case IDOK:
2891 if (!PRINTDLG_PS_UpdateDlgStructA(hDlg, pda))
2892 return(FALSE);
2893 EndDialog(hDlg, TRUE);
2894 return TRUE ;
2895
2896 case IDCANCEL:
2897 EndDialog(hDlg, FALSE);
2898 return FALSE ;
2899
2900 case psh3: {
2901 pda->pdlg.Flags = 0;
2902 pda->pdlg.hwndOwner = hDlg;
2903 if (PrintDlgA(&(pda->pdlg)))
2904 PRINTDLG_PS_ChangePrinterA(hDlg,pda);
2905 }
2906 return TRUE;
2907 case rad1:
2908 case rad2:
2909 if((id == rad1 && pda->curdlg.ptPaperSize.x > pda->curdlg.ptPaperSize.y) ||
2910 (id == rad2 && pda->curdlg.ptPaperSize.y > pda->curdlg.ptPaperSize.x))
2911 {
2912 char TmpText[25];
2913 char TmpText2[25];
2914 DWORD tmp = pda->curdlg.ptPaperSize.x;
2915
2916 pda->curdlg.ptPaperSize.x = pda->curdlg.ptPaperSize.y;
2917 pda->curdlg.ptPaperSize.y = tmp;
2918
2919 GetDlgItemTextA(hDlg, edt4, TmpText, sizeof(TmpText));
2920 GetDlgItemTextA(hDlg, edt5, TmpText2, sizeof(TmpText2));
2921 SetDlgItemTextA(hDlg, edt5, TmpText);
2922 SetDlgItemTextA(hDlg, edt4, TmpText2);
2923
2924 GetDlgItemTextA(hDlg, edt6, TmpText, sizeof(TmpText));
2925 GetDlgItemTextA(hDlg, edt7, TmpText2, sizeof(TmpText2));
2926 SetDlgItemTextA(hDlg, edt7, TmpText);
2927 SetDlgItemTextA(hDlg, edt6, TmpText2);
2928
2929 PRINTDLG_PS_ChangePaperPrev(pda);
2930 }
2931 break;
2932 case cmb1: /* Printer combo */
2933 if(msg == CBN_SELCHANGE){
2934 char crPrinterName[256];
2935 GetDlgItemTextA(hDlg, id, crPrinterName, 255);
2936 PRINTDLG_PS_ChangeActivePrinterA(crPrinterName, pda);
2937 PRINTDLG_PS_ChangePrinterA(hDlg, pda);
2938 }
2939 break;
2940 case cmb2: /* Paper combo */
2941 if(msg == CBN_SELCHANGE){
2942 DWORD paperword = SendDlgItemMessageA(hDlg,cmb2,CB_GETITEMDATA,
2943 SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0), 0);
2944 if (paperword != CB_ERR) {
2945 PRINTDLG_PaperSizeA(&(pda->pdlg), paperword,&(pda->curdlg.ptPaperSize));
2946 pda->curdlg.ptPaperSize.x = _c_10mm2size(pda->dlga,pda->curdlg.ptPaperSize.x);
2947 pda->curdlg.ptPaperSize.y = _c_10mm2size(pda->dlga,pda->curdlg.ptPaperSize.y);
2948
2949 if (IsDlgButtonChecked(hDlg, rad2)) {
2950 DWORD tmp = pda->curdlg.ptPaperSize.x;
2951 pda->curdlg.ptPaperSize.x = pda->curdlg.ptPaperSize.y;
2952 pda->curdlg.ptPaperSize.y = tmp;
2953 }
2954 PRINTDLG_PS_ChangePaperPrev(pda);
2955 } else
2956 FIXME("could not get dialog text for papersize cmbbox?\n");
2957 }
2958 break;
2959 case cmb3:
2960 if(msg == CBN_SELCHANGE){
2961 DEVMODEA *dm = GlobalLock(pda->pdlg.hDevMode);
2962 dm->u1.s1.dmDefaultSource = SendDlgItemMessageA(hDlg, cmb3,CB_GETITEMDATA,
2963 SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0), 0);
2964 GlobalUnlock(pda->pdlg.hDevMode);
2965 }
2966 break;
2967 case psh2: /* Printer Properties button */
2968 {
2969 HANDLE hPrinter;
2970 char PrinterName[256];
2971 DEVMODEA *dm;
2972 LRESULT count;
2973 int i;
2974
2975 GetDlgItemTextA(hDlg, cmb1, PrinterName, 255);
2976 if (!OpenPrinterA(PrinterName, &hPrinter, NULL)) {
2977 FIXME("Call to OpenPrinter did not succeed!\n");
2978 break;
2979 }
2980 dm = GlobalLock(pda->pdlg.hDevMode);
2981 DocumentPropertiesA(hDlg, hPrinter, PrinterName, dm, dm,
2982 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
2983 ClosePrinter(hPrinter);
2984 /* Changing paper */
2985 PRINTDLG_PaperSizeA(&(pda->pdlg), dm->u1.s1.dmPaperSize, &(pda->curdlg.ptPaperSize));
2986 pda->curdlg.ptPaperSize.x = _c_10mm2size(pda->dlga, pda->curdlg.ptPaperSize.x);
2987 pda->curdlg.ptPaperSize.y = _c_10mm2size(pda->dlga, pda->curdlg.ptPaperSize.y);
2988 if (dm->u1.s1.dmOrientation == DMORIENT_LANDSCAPE){
2989 DWORD tmp = pda->curdlg.ptPaperSize.x;
2990 pda->curdlg.ptPaperSize.x = pda->curdlg.ptPaperSize.y;
2991 pda->curdlg.ptPaperSize.y = tmp;
2992 CheckRadioButton(hDlg, rad1, rad2, rad2);
2993 }
2994 else
2995 CheckRadioButton(hDlg, rad1, rad2, rad1);
2996 /* Changing paper preview */
2997 PRINTDLG_PS_ChangePaperPrev(pda);
2998 /* Selecting paper in combo */
2999 count = SendDlgItemMessageA(hDlg, cmb2, CB_GETCOUNT, 0, 0);
3000 if(count != CB_ERR){
3001 for(i=0; i<count; ++i){
3002 if(SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, i, 0) == dm->u1.s1.dmPaperSize) {
3003 SendDlgItemMessageA(hDlg, cmb2, CB_SETCURSEL, i, 0);
3004 break;
3005 }
3006 }
3007 }
3008
3009 GlobalUnlock(pda->pdlg.hDevMode);
3010 break;
3011 }
3012 case edt4:
3013 GETVAL(id, pda->curdlg.rtMargin.left);
3014 break;
3015 case edt5:
3016 GETVAL(id, pda->curdlg.rtMargin.top);
3017 break;
3018 case edt6:
3019 GETVAL(id, pda->curdlg.rtMargin.right);
3020 break;
3021 case edt7:
3022 GETVAL(id, pda->curdlg.rtMargin.bottom);
3023 break;
3024 }
3025 InvalidateRect(GetDlgItem(hDlg, rct1), NULL, TRUE);
3026 return FALSE;
3027 }
3028 #undef GETVAL
3029
3030 static BOOL
3031 PRINTDLG_PS_WMCommandW(
3032 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataW *pdw
3033 ) {
3034 TRACE("loword (lparam) %d, wparam 0x%lx, lparam %08lx\n",
3035 LOWORD(lParam),wParam,lParam);
3036 switch (LOWORD(wParam)) {
3037 case IDOK:
3038 if (!PRINTDLG_PS_UpdateDlgStructW(hDlg, pdw))
3039 return(FALSE);
3040 EndDialog(hDlg, TRUE);
3041 return TRUE ;
3042
3043 case IDCANCEL:
3044 EndDialog(hDlg, FALSE);
3045 return FALSE ;
3046
3047 case rad1:
3048 case rad2:
3049 if((LOWORD(wParam) == rad1 && pdw->curdlg.ptPaperSize.x > pdw->curdlg.ptPaperSize.y) ||
3050 (LOWORD(wParam) == rad2 && pdw->curdlg.ptPaperSize.y > pdw->curdlg.ptPaperSize.x))
3051 {
3052 WCHAR tmpText[25];
3053 WCHAR tmpText2[25];
3054 DWORD tmp = pdw->curdlg.ptPaperSize.y;
3055
3056 pdw->curdlg.ptPaperSize.y = pdw->curdlg.ptPaperSize.x;
3057 pdw->curdlg.ptPaperSize.x = tmp;
3058
3059 GetDlgItemTextW(hDlg, edt4, tmpText, sizeof(tmpText)/sizeof(WCHAR));
3060 GetDlgItemTextW(hDlg, edt5, tmpText2, sizeof(tmpText2)/sizeof(WCHAR));
3061 SetDlgItemTextW(hDlg, edt5, tmpText);
3062 SetDlgItemTextW(hDlg, edt4, tmpText2);
3063
3064 GetDlgItemTextW(hDlg, edt6, tmpText, sizeof(tmpText)/sizeof(WCHAR));
3065 GetDlgItemTextW(hDlg, edt7, tmpText2, sizeof(tmpText2)/sizeof(WCHAR));
3066 SetDlgItemTextW(hDlg, edt7, tmpText);
3067 SetDlgItemTextW(hDlg, edt6, tmpText2);
3068 }
3069 break;
3070
3071 case psh3: {
3072 pdw->pdlg.Flags = 0;
3073 pdw->pdlg.hwndOwner = hDlg;
3074 PRINTDLG_PS_UpdatePrintDlgW(pdw, hDlg);
3075 if (PrintDlgW(&(pdw->pdlg)))
3076 PRINTDLG_PS_ChangePrinterW(hDlg,pdw);
3077 return TRUE;
3078 }
3079 }
3080 return FALSE;
3081 }
3082
3083
3084 /***********************************************************************
3085 * DefaultPagePaintHook
3086 * Default hook paint procedure that receives WM_PSD_* messages from the dialog box
3087 * whenever the sample page is redrawn.
3088 */
3089
3090 static UINT_PTR
3091 PRINTDLG_DefaultPagePaintHook(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam,
3092 const PageSetupDataA *pda)
3093 {
3094 LPRECT lprc = (LPRECT) lParam;
3095 HDC hdc = (HDC) wParam;
3096 HPEN hpen, holdpen;
3097 LOGFONTW lf;
3098 HFONT hfont, holdfont;
3099 INT oldbkmode;
3100 TRACE("uMsg: WM_USER+%d\n",uMsg-WM_USER);
3101 /* Call user paint hook if enable */
3102 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK)
3103 if (pda->dlga->lpfnPagePaintHook(hwndDlg, uMsg, wParam, lParam))
3104 return TRUE;
3105
3106 switch (uMsg) {
3107 /* LPPAGESETUPDLG in lParam */
3108 case WM_PSD_PAGESETUPDLG:
3109 /* Inform about the sample page rectangle */
3110 case WM_PSD_FULLPAGERECT:
3111 /* Inform about the margin rectangle */
3112 case WM_PSD_MINMARGINRECT:
3113 return FALSE;
3114
3115 /* Draw dashed rectangle showing margins */
3116 case WM_PSD_MARGINRECT:
3117 hpen = CreatePen(PS_DASH, 1, GetSysColor(COLOR_3DSHADOW));
3118 holdpen = SelectObject(hdc, hpen);
3119 Rectangle(hdc, lprc->left, lprc->top, lprc->right, lprc->bottom);
3120 DeleteObject(SelectObject(hdc, holdpen));
3121 return TRUE;
3122 /* Draw the fake document */
3123 case WM_PSD_GREEKTEXTRECT:
3124 /* select a nice scalable font, because we want the text really small */
3125 SystemParametersInfoW(SPI_GETICONTITLELOGFONT, sizeof(lf), &lf, 0);
3126 lf.lfHeight = 6; /* value chosen based on visual effect */
3127 hfont = CreateFontIndirectW(&lf);
3128 holdfont = SelectObject(hdc, hfont);
3129
3130 /* if text not loaded, then do so now */
3131 if (wszFakeDocumentText[0] == '\0')
3132 LoadStringW(COMDLG32_hInstance,
3133 IDS_FAKEDOCTEXT,
3134 wszFakeDocumentText,
3135 sizeof(wszFakeDocumentText)/sizeof(wszFakeDocumentText[0]));
3136
3137 oldbkmode = SetBkMode(hdc, TRANSPARENT);
3138 DrawTextW(hdc, wszFakeDocumentText, -1, lprc, DT_TOP|DT_LEFT|DT_NOPREFIX|DT_WORDBREAK);
3139 SetBkMode(hdc, oldbkmode);
3140
3141 DeleteObject(SelectObject(hdc, holdfont));
3142 return TRUE;
3143
3144 /* Envelope stamp */
3145 case WM_PSD_ENVSTAMPRECT:
3146 /* Return address */
3147 case WM_PSD_YAFULLPAGERECT:
3148 FIXME("envelope/stamp is not implemented\n");
3149 return FALSE;
3150 default:
3151 FIXME("Unknown message %x\n",uMsg);
3152 return FALSE;
3153 }
3154 return TRUE;
3155 }
3156
3157 /***********************************************************************
3158 * PagePaintProc
3159 * The main paint procedure for the PageSetupDlg function.
3160 * The Page Setup dialog box includes an image of a sample page that shows how
3161 * the user's selections affect the appearance of the printed output.
3162 * The image consists of a rectangle that represents the selected paper
3163 * or envelope type, with a dotted-line rectangle representing
3164 * the current margins, and partial (Greek text) characters
3165 * to show how text looks on the printed page.
3166 *
3167 * The following messages in the order sends to user hook procedure:
3168 * WM_PSD_PAGESETUPDLG Draw the contents of the sample page
3169 * WM_PSD_FULLPAGERECT Inform about the bounding rectangle
3170 * WM_PSD_MINMARGINRECT Inform about the margin rectangle (min margin?)
3171 * WM_PSD_MARGINRECT Draw the margin rectangle
3172 * WM_PSD_GREEKTEXTRECT Draw the Greek text inside the margin rectangle
3173 * If any of first three messages returns TRUE, painting done.
3174 *
3175 * PARAMS:
3176 * hWnd [in] Handle to the Page Setup dialog box
3177 * uMsg [in] Received message
3178 *
3179 * TODO:
3180 * WM_PSD_ENVSTAMPRECT Draw in the envelope-stamp rectangle (for envelopes only)
3181 * WM_PSD_YAFULLPAGERECT Draw the return address portion (for envelopes and other paper sizes)
3182 *
3183 * RETURNS:
3184 * FALSE if all done correctly
3185 *
3186 */
3187
3188
3189 static LRESULT CALLBACK
3190 PRINTDLG_PagePaintProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3191 {
3192 PAINTSTRUCT ps;
3193 RECT rcClient, rcMargin;
3194 HPEN hpen, holdpen;
3195 HDC hdc;
3196 HBRUSH hbrush, holdbrush;
3197 PageSetupDataA *pda;
3198 int papersize=0, orientation=0; /* FIXME: set this values for user paint hook */
3199 double scalx, scaly;
3200 #define CALLPAINTHOOK(msg,lprc) PRINTDLG_DefaultPagePaintHook( hWnd, msg, (WPARAM)hdc, (LPARAM)lprc, pda)
3201
3202 if (uMsg != WM_PAINT)
3203 return CallWindowProcA(lpfnStaticWndProc, hWnd, uMsg, wParam, lParam);
3204
3205 /* Processing WM_PAINT message */
3206 pda = (PageSetupDataA*)GetPropA(hWnd, "__WINE_PAGESETUPDLGDATA");
3207 if (!pda) {
3208 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3209 return FALSE;
3210 }
3211 if (PRINTDLG_DefaultPagePaintHook(hWnd, WM_PSD_PAGESETUPDLG, MAKELONG(papersize, orientation), (LPARAM)pda->dlga, pda))
3212 return FALSE;
3213
3214 hdc = BeginPaint(hWnd, &ps);
3215 GetClientRect(hWnd, &rcClient);
3216
3217 scalx = rcClient.right / (double)pda->curdlg.ptPaperSize.x;
3218 scaly = rcClient.bottom / (double)pda->curdlg.ptPaperSize.y;
3219 rcMargin = rcClient;
3220
3221 rcMargin.left += pda->curdlg.rtMargin.left * scalx;
3222 rcMargin.top += pda->curdlg.rtMargin.top * scalx;
3223 rcMargin.right -= pda->curdlg.rtMargin.right * scaly;
3224 rcMargin.bottom -= pda->curdlg.rtMargin.bottom * scaly;
3225
3226 /* if the space is too small then we make sure to not draw anything */
3227 rcMargin.left = min(rcMargin.left, rcMargin.right);
3228 rcMargin.top = min(rcMargin.top, rcMargin.bottom);
3229
3230 if (!CALLPAINTHOOK(WM_PSD_FULLPAGERECT, &rcClient) &&
3231 !CALLPAINTHOOK(WM_PSD_MINMARGINRECT, &rcMargin) )
3232 {
3233 /* fill background */
3234 hbrush = GetSysColorBrush(COLOR_3DHIGHLIGHT);
3235 FillRect(hdc, &rcClient, hbrush);
3236 holdbrush = SelectObject(hdc, hbrush);
3237
3238 hpen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW));
3239 holdpen = SelectObject(hdc, hpen);
3240
3241 /* paint left edge */
3242 MoveToEx(hdc, rcClient.left, rcClient.top, NULL);
3243 LineTo(hdc, rcClient.left, rcClient.bottom-1);
3244
3245 /* paint top edge */
3246 MoveToEx(hdc, rcClient.left, rcClient.top, NULL);
3247 LineTo(hdc, rcClient.right, rcClient.top);
3248
3249 hpen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DDKSHADOW));
3250 DeleteObject(SelectObject(hdc, hpen));
3251
3252 /* paint right edge */
3253 MoveToEx(hdc, rcClient.right-1, rcClient.top, NULL);
3254 LineTo(hdc, rcClient.right-1, rcClient.bottom);
3255
3256 /* paint bottom edge */
3257 MoveToEx(hdc, rcClient.left, rcClient.bottom-1, NULL);
3258 LineTo(hdc, rcClient.right, rcClient.bottom-1);
3259
3260 DeleteObject(SelectObject(hdc, holdpen));
3261 DeleteObject(SelectObject(hdc, holdbrush));
3262
3263 CALLPAINTHOOK(WM_PSD_MARGINRECT, &rcMargin);
3264
3265 /* give text a bit of a space from the frame */
3266 rcMargin.left += 2;
3267 rcMargin.top += 2;
3268 rcMargin.right -= 2;
3269 rcMargin.bottom -= 2;
3270
3271 /* if the space is too small then we make sure to not draw anything */
3272 rcMargin.left = min(rcMargin.left, rcMargin.right);
3273 rcMargin.top = min(rcMargin.top, rcMargin.bottom);
3274
3275 CALLPAINTHOOK(WM_PSD_GREEKTEXTRECT, &rcMargin);
3276 }
3277
3278 EndPaint(hWnd, &ps);
3279 return FALSE;
3280 #undef CALLPAINTHOOK
3281 }
3282
3283 /***********************************************************************
3284 * PRINTDLG_PageDlgProcA
3285 * Message handler for PageSetupDlgA
3286 */
3287 static INT_PTR CALLBACK
3288 PRINTDLG_PageDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
3289 {
3290 DEVMODEA *dm;
3291 PageSetupDataA *pda;
3292 INT_PTR res = FALSE;
3293 HWND hDrawWnd;
3294
3295 if (uMsg == WM_INITDIALOG) { /*Init dialog*/
3296 pda = (PageSetupDataA*)lParam;
3297 pda->hDlg = hDlg; /* saving handle to main window to PageSetupDataA structure */
3298 pda->curdlg = *pda->dlga;
3299
3300 hDrawWnd = GetDlgItem(hDlg, rct1);
3301 TRACE("set property to %p\n", pda);
3302 SetPropA(hDlg, "__WINE_PAGESETUPDLGDATA", pda);
3303 SetPropA(hDrawWnd, "__WINE_PAGESETUPDLGDATA", pda);
3304 GetWindowRect(hDrawWnd, &pda->rtDrawRect); /* Calculating rect in client coordinates where paper draws */
3305 ScreenToClient(hDlg, (LPPOINT)&pda->rtDrawRect);
3306 ScreenToClient(hDlg, (LPPOINT)(&pda->rtDrawRect.right));
3307 lpfnStaticWndProc = (WNDPROC)SetWindowLongPtrW(
3308 hDrawWnd,
3309 GWLP_WNDPROC,
3310 (ULONG_PTR)PRINTDLG_PagePaintProc);
3311
3312 /* FIXME: Paint hook. Must it be at begin of initialization or at end? */
3313 res = TRUE;
3314 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3315 if (!pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,(LPARAM)pda->dlga))
3316 FIXME("Setup page hook failed?\n");
3317 }
3318
3319 /* if printer button disabled */
3320 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
3321 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
3322 /* if margin edit boxes disabled */
3323 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
3324 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
3325 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
3326 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
3327 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
3328 }
3329 /* Set orientation radiobutton properly */
3330 if(pda->dlga->hDevMode)
3331 {
3332 dm = GlobalLock(pda->dlga->hDevMode);
3333 if (dm->u1.s1.dmOrientation == DMORIENT_LANDSCAPE)
3334 CheckRadioButton(hDlg, rad1, rad2, rad2);
3335 else /* this is default if papersize is not set */
3336 CheckRadioButton(hDlg, rad1, rad2, rad1);
3337 GlobalUnlock(pda->dlga->hDevMode);
3338 }
3339
3340 /* if orientation disabled */
3341 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
3342 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
3343 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
3344 }
3345 /* We fill them out enabled or not */
3346 if (pda->dlga->Flags & PSD_MARGINS) {
3347 char str[100];
3348 _c_size2strA(pda,pda->dlga->rtMargin.left,str);
3349 SetDlgItemTextA(hDlg,edt4,str);
3350 _c_size2strA(pda,pda->dlga->rtMargin.top,str);
3351 SetDlgItemTextA(hDlg,edt5,str);
3352 _c_size2strA(pda,pda->dlga->rtMargin.right,str);
3353 SetDlgItemTextA(hDlg,edt6,str);
3354 _c_size2strA(pda,pda->dlga->rtMargin.bottom,str);
3355 SetDlgItemTextA(hDlg,edt7,str);
3356 } else {
3357 /* default is 1 inch */
3358 DWORD size = _c_inch2size(pda->dlga,1000);
3359 char str[20];
3360 _c_size2strA(pda,size,str);
3361 SetDlgItemTextA(hDlg,edt4,str);
3362 SetDlgItemTextA(hDlg,edt5,str);
3363 SetDlgItemTextA(hDlg,edt6,str);
3364 SetDlgItemTextA(hDlg,edt7,str);
3365 pda->curdlg.rtMargin.left = size;
3366 pda->curdlg.rtMargin.top = size;
3367 pda->curdlg.rtMargin.right = size;
3368 pda->curdlg.rtMargin.bottom = size;
3369 }
3370 /* if paper disabled */
3371 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
3372 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
3373 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
3374 }
3375 /* filling combos: printer, paper, source. selecting current printer (from DEVMODEA) */
3376 PRINTDLG_PS_ChangePrinterA(hDlg, pda);
3377 dm = GlobalLock(pda->pdlg.hDevMode);
3378 if(dm){
3379 dm->u1.s1.dmDefaultSource = 15; /*FIXME: Automatic select. Does it always 15 at start? */
3380 PRINTDLG_PaperSizeA(&(pda->pdlg), dm->u1.s1.dmPaperSize, &pda->curdlg.ptPaperSize);
3381 GlobalUnlock(pda->pdlg.hDevMode);
3382 pda->curdlg.ptPaperSize.x = _c_10mm2size(pda->dlga, pda->curdlg.ptPaperSize.x);
3383 pda->curdlg.ptPaperSize.y = _c_10mm2size(pda->dlga, pda->curdlg.ptPaperSize.y);
3384 if (IsDlgButtonChecked(hDlg, rad2) == BST_CHECKED) { /* Landscape orientation */
3385 DWORD tmp = pda->curdlg.ptPaperSize.y;
3386 pda->curdlg.ptPaperSize.y = pda->curdlg.ptPaperSize.x;
3387 pda->curdlg.ptPaperSize.x = tmp;
3388 }
3389 } else
3390 WARN("GlobalLock(pda->pdlg.hDevMode) fail? hDevMode=%p\n", pda->pdlg.hDevMode);
3391 /* Drawing paper prev */
3392 PRINTDLG_PS_ChangePaperPrev(pda);
3393 return TRUE;
3394 } else {
3395 pda = (PageSetupDataA*)GetPropA(hDlg,"__WINE_PAGESETUPDLGDATA");
3396 if (!pda) {
3397 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3398 return FALSE;
3399 }
3400 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3401 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3402 if (res) return res;
3403 }
3404 }
3405 switch (uMsg) {
3406 case WM_COMMAND:
3407 return PRINTDLG_PS_WMCommandA(hDlg, wParam, lParam, pda);
3408 }
3409 return FALSE;
3410 }
3411
3412 static INT_PTR CALLBACK
3413 PageDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
3414 {
3415 static const WCHAR __WINE_PAGESETUPDLGDATA[] =
3416 { '_', '_', 'W', 'I', 'N', 'E', '_', 'P', 'A', 'G', 'E',
3417 'S', 'E', 'T', 'U', 'P', 'D', 'L', 'G', 'D', 'A', 'T', 'A', 0 };
3418 PageSetupDataW *pdw;
3419 BOOL res = FALSE;
3420
3421 if (uMsg==WM_INITDIALOG) {
3422 res = TRUE;
3423 pdw = (PageSetupDataW*)lParam;
3424 pdw->curdlg = *pdw->dlgw;
3425 SetPropW(hDlg, __WINE_PAGESETUPDLGDATA, pdw);
3426 if (pdw->dlgw->Flags & PSD_ENABLEPAGESETUPHOOK) {
3427 res = pdw->dlgw->lpfnPageSetupHook(hDlg,uMsg,wParam,(LPARAM)pdw->dlgw);
3428 if (!res) {
3429 FIXME("Setup page hook failed?\n");
3430 res = TRUE;
3431 }
3432 }
3433
3434 if (pdw->dlgw->Flags & PSD_ENABLEPAGEPAINTHOOK) {
3435 FIXME("PagePaintHook not yet implemented!\n");
3436 }
3437 if (pdw->dlgw->Flags & PSD_DISABLEPRINTER)
3438 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
3439 if (pdw->dlgw->Flags & PSD_DISABLEMARGINS) {
3440 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
3441 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
3442 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
3443 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
3444 }
3445
3446 PRINTDLG_PS_ChangePrinterW(hDlg,pdw);
3447
3448 if (pdw->dlgw->Flags & PSD_DISABLEORIENTATION) {
3449 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
3450 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
3451 }
3452 /* We fill them out enabled or not */
3453 if (pdw->dlgw->Flags & PSD_MARGINS) {
3454 WCHAR str[100];
3455 _c_size2strW(pdw,pdw->dlgw->rtMargin.left,str);
3456 SetDlgItemTextW(hDlg,edt4,str);
3457 _c_size2strW(pdw,pdw->dlgw->rtMargin.top,str);
3458 SetDlgItemTextW(hDlg,edt5,str);
3459 _c_size2strW(pdw,pdw->dlgw->rtMargin.right,str);
3460 SetDlgItemTextW(hDlg,edt6,str);
3461 _c_size2strW(pdw,pdw->dlgw->rtMargin.bottom,str);
3462 SetDlgItemTextW(hDlg,edt7,str);
3463 } else {
3464 /* default is 1 inch */
3465 DWORD size = _c_inch2size((LPPAGESETUPDLGA)pdw->dlgw,1000);
3466 WCHAR str[20];
3467 _c_size2strW(pdw,size,str);
3468 SetDlgItemTextW(hDlg,edt4,str);
3469 SetDlgItemTextW(hDlg,edt5,str);
3470 SetDlgItemTextW(hDlg,edt6,str);
3471 SetDlgItemTextW(hDlg,edt7,str);
3472 }
3473
3474 if (pdw->dlgw->Flags & PSD_DISABLEPAPER) {
3475 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
3476 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
3477 }
3478
3479 return TRUE;
3480 } else {
3481 pdw = (PageSetupDataW*)GetPropW(hDlg, __WINE_PAGESETUPDLGDATA);
3482 if (!pdw) {
3483 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3484 return FALSE;
3485 }
3486 if (pdw->dlgw->Flags & PSD_ENABLEPAGESETUPHOOK) {
3487 res = pdw->dlgw->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3488 if (res) return res;
3489 }
3490 }
3491 switch (uMsg) {
3492 case WM_COMMAND:
3493 return PRINTDLG_PS_WMCommandW(hDlg, wParam, lParam, pdw);
3494 }
3495 return FALSE;
3496 }
3497
3498 /***********************************************************************
3499 * PageSetupDlgA (COMDLG32.@)
3500 *
3501 * Displays the PAGE SETUP dialog box, which enables the user to specify
3502 * specific properties of a printed page such as
3503 * size, source, orientation and the width of the page margins.
3504 *
3505 * PARAMS
3506 * setupdlg [IO] PAGESETUPDLGA struct
3507 *
3508 * RETURNS
3509 * TRUE if the user pressed the OK button
3510 * FALSE if the user cancelled the window or an error occurred
3511 *
3512 * NOTES
3513 * The values of hDevMode and hDevNames are filled on output and can be
3514 * changed in PAGESETUPDLG when they are passed in PageSetupDlg.
3515 *
3516 */
3517
3518 BOOL WINAPI PageSetupDlgA(LPPAGESETUPDLGA setupdlg) {
3519 HGLOBAL hDlgTmpl;
3520 LPVOID ptr;
3521 BOOL bRet;
3522 PageSetupDataA *pda;
3523 PRINTDLGA pdlg;
3524
3525 if (setupdlg == NULL) {
3526 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION);
3527 return FALSE;
3528 }
3529
3530 /* TRACE */
3531 if(TRACE_ON(commdlg)) {
3532 char flagstr[1000] = "";
3533 const struct pd_flags *pflag = psd_flags;
3534 for( ; pflag->name; pflag++) {
3535 if(setupdlg->Flags & pflag->flag) {
3536 strcat(flagstr, pflag->name);
3537 strcat(flagstr, "|");
3538 }
3539 }
3540 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3541 "hinst %p, flags %08x (%s)\n",
3542 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
3543 setupdlg->hDevNames,
3544 setupdlg->hInstance, setupdlg->Flags, flagstr);
3545 }
3546
3547 /* Checking setupdlg structure */
3548 if(setupdlg->lStructSize != sizeof(PAGESETUPDLGA)) {
3549 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
3550 return FALSE;
3551 }
3552 if ((setupdlg->Flags & PSD_ENABLEPAGEPAINTHOOK) &&
3553 (setupdlg->lpfnPagePaintHook == NULL)) {
3554 COMDLG32_SetCommDlgExtendedError(CDERR_NOHOOK);
3555 return FALSE;
3556 }
3557
3558 /* Initialize default printer struct. If no printer device info is specified
3559 retrieve the default printer data. */
3560 memset(&pdlg,0,sizeof(pdlg));
3561 pdlg.lStructSize = sizeof(pdlg);
3562 if (setupdlg->hDevMode && setupdlg->hDevNames) {
3563 pdlg.hDevMode = setupdlg->hDevMode;
3564 pdlg.hDevNames = setupdlg->hDevNames;
3565 } else {
3566 pdlg.Flags = PD_RETURNDEFAULT;
3567 bRet = PrintDlgA(&pdlg);
3568 if (!bRet){
3569 if (!(setupdlg->Flags & PSD_NOWARNING)) {
3570 WCHAR errstr[256];
3571 LoadStringW(COMDLG32_hInstance, PD32_NO_DEFAULT_PRINTER, errstr, 255);
3572 MessageBoxW(setupdlg->hwndOwner, errstr, 0, MB_OK | MB_ICONERROR);
3573 }
3574 return FALSE;
3575 }
3576 }
3577
3578 /* short cut exit, just return default values */
3579 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
3580 DEVMODEA *dm;
3581
3582 setupdlg->hDevMode = pdlg.hDevMode;
3583 setupdlg->hDevNames = pdlg.hDevNames;
3584 dm = GlobalLock(pdlg.hDevMode);
3585 PRINTDLG_PaperSizeA(&pdlg, dm->u1.s1.dmPaperSize, &setupdlg->ptPaperSize);
3586 GlobalUnlock(pdlg.hDevMode);
3587 setupdlg->ptPaperSize.x=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.x);
3588 setupdlg->ptPaperSize.y=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.y);
3589 return TRUE;
3590 }
3591
3592 /* get dialog template */
3593 hDlgTmpl = PRINTDLG_GetPGSTemplateA(setupdlg);
3594 if (!hDlgTmpl) {
3595 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3596 return FALSE;
3597 }
3598 ptr = LockResource( hDlgTmpl );
3599 if (!ptr) {
3600 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3601 return FALSE;
3602 }
3603
3604 pda = HeapAlloc(GetProcessHeap(),0,sizeof(*pda));
3605 pda->dlga = setupdlg;
3606 pda->pdlg = pdlg;
3607
3608 bRet = (0<DialogBoxIndirectParamA(
3609 setupdlg->hInstance,
3610 ptr,
3611 setupdlg->hwndOwner,
3612 PRINTDLG_PageDlgProcA,
3613 (LPARAM)pda)
3614 );
3615
3616 HeapFree(GetProcessHeap(),0,pda);
3617 return bRet;
3618 }
3619 /***********************************************************************
3620 * PageSetupDlgW (COMDLG32.@)
3621 *
3622 * See PageSetupDlgA.
3623 */
3624 BOOL WINAPI PageSetupDlgW(LPPAGESETUPDLGW setupdlg) {
3625 HGLOBAL hDlgTmpl;
3626 LPVOID ptr;
3627 BOOL bRet;
3628 PageSetupDataW *pdw;
3629 PRINTDLGW pdlg;
3630
3631 FIXME("Unicode implementation is not done yet\n");
3632
3633 if (setupdlg == NULL) {
3634 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION);
3635 return FALSE;
3636 }
3637
3638 if(TRACE_ON(commdlg)) {
3639 char flagstr[1000] = "";
3640 const struct pd_flags *pflag = psd_flags;
3641 for( ; pflag->name; pflag++) {
3642 if(setupdlg->Flags & pflag->flag) {
3643 strcat(flagstr, pflag->name);
3644 strcat(flagstr, "|");
3645 }
3646 }
3647 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3648 "hinst %p, flags %08x (%s)\n",
3649 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
3650 setupdlg->hDevNames,
3651 setupdlg->hInstance, setupdlg->Flags, flagstr);
3652 }
3653
3654 /* Initialize default printer struct. If no printer device info is specified
3655 retrieve the default printer data. */
3656 memset(&pdlg,0,sizeof(pdlg));
3657 pdlg.lStructSize = sizeof(pdlg);
3658 if (setupdlg->hDevMode && setupdlg->hDevNames) {
3659 pdlg.hDevMode = setupdlg->hDevMode;
3660 pdlg.hDevNames = setupdlg->hDevNames;
3661 } else {
3662 pdlg.Flags = PD_RETURNDEFAULT;
3663 bRet = PrintDlgW(&pdlg);
3664 if (!bRet){
3665 if (!(setupdlg->Flags & PSD_NOWARNING)) {
3666 WCHAR errstr[256];
3667 LoadStringW(COMDLG32_hInstance, PD32_NO_DEFAULT_PRINTER, errstr, 255);
3668 MessageBoxW(setupdlg->hwndOwner, errstr, 0, MB_OK | MB_ICONERROR);
3669 }
3670 return FALSE;
3671 }
3672 }
3673
3674 /* short cut exit, just return default values */
3675 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
3676 static const WCHAR a4[] = {'A','4',0};
3677 setupdlg->hDevMode = pdlg.hDevMode;
3678 setupdlg->hDevNames = pdlg.hDevNames;
3679 /* FIXME: Just return "A4" for now. */
3680 PRINTDLG_PaperSizeW(&pdlg,a4,&setupdlg->ptPaperSize);
3681 setupdlg->ptPaperSize.x=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.x);
3682 setupdlg->ptPaperSize.y=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.y);
3683 return TRUE;
3684 }
3685 hDlgTmpl = PRINTDLG_GetPGSTemplateW(setupdlg);
3686 if (!hDlgTmpl) {
3687 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3688 return FALSE;
3689 }
3690 ptr = LockResource( hDlgTmpl );
3691 if (!ptr) {
3692 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3693 return FALSE;
3694 }
3695 pdw = HeapAlloc(GetProcessHeap(),0,sizeof(*pdw));
3696 pdw->dlgw = setupdlg;
3697 pdw->pdlg = pdlg;
3698
3699 bRet = (0<DialogBoxIndirectParamW(
3700 setupdlg->hInstance,
3701 ptr,
3702 setupdlg->hwndOwner,
3703 PageDlgProcW,
3704 (LPARAM)pdw)
3705 );
3706 return bRet;
3707 }
3708
3709 /***********************************************************************
3710 * PrintDlgExA (COMDLG32.@)
3711 *
3712 * See PrintDlgExW.
3713 *
3714 * BUGS
3715 * Only a Stub
3716 *
3717 */
3718 HRESULT WINAPI PrintDlgExA(LPPRINTDLGEXA lppd)
3719 {
3720
3721 FIXME("(%p) stub\n", lppd);
3722 if ((lppd == NULL) || (lppd->lStructSize != sizeof(PRINTDLGEXA))) {
3723 return E_INVALIDARG;
3724 }
3725
3726 if (!IsWindow(lppd->hwndOwner)) {
3727 return E_HANDLE;
3728 }
3729
3730 return E_NOTIMPL;
3731 }
3732
3733 /***********************************************************************
3734 * PrintDlgExW (COMDLG32.@)
3735 *
3736 * Display the property sheet style PRINT dialog box
3737 *
3738 * PARAMS
3739 * lppd [IO] ptr to PRINTDLGEX struct
3740 *
3741 * RETURNS
3742 * Success: S_OK
3743 * Failure: One of the following COM error codes:
3744 * E_OUTOFMEMORY Insufficient memory.
3745 * E_INVALIDARG One or more arguments are invalid.
3746 * E_POINTER Invalid pointer.
3747 * E_HANDLE Invalid handle.
3748 * E_FAIL Unspecified error.
3749 *
3750 * NOTES
3751 * This Dialog enables the user to specify specific properties of the print job.
3752 * The property sheet can also have additional application-specific and
3753 * driver-specific property pages.
3754 *
3755 * BUGS
3756 * Only a Stub
3757 *
3758 */
3759 HRESULT WINAPI PrintDlgExW(LPPRINTDLGEXW lppd)
3760 {
3761
3762 FIXME("(%p) stub\n", lppd);
3763 if ((lppd == NULL) || (lppd->lStructSize != sizeof(PRINTDLGEXW))) {
3764 return E_INVALIDARG;
3765 }
3766
3767 if (!IsWindow(lppd->hwndOwner)) {
3768 return E_HANDLE;
3769 }
3770
3771 return E_NOTIMPL;
3772 }