source: trunk/src/comdlg32/printdlg.c@ 10593

Last change on this file since 10593 was 10593, checked in by sandervl, 21 years ago

drawSingleLinePoint: wrong pen style checks

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