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

Last change on this file since 6666 was 6645, checked in by bird, 24 years ago

Added $Id:$ keyword.

File size: 74.1 KB
Line 
1/* $Id: printdlg.c,v 1.2 2001-09-05 12:12:02 bird Exp $ */
2/*
3 * COMMDLG - Print Dialog
4 *
5 * Copyright 1994 Martin Ayotte
6 * Copyright 1996 Albrecht Kleine
7 * Copyright 1999 Klaas van Gend
8 * Copyright 2000 Huw D M Davies
9 */
10#include <ctype.h>
11#include <stdlib.h>
12#include <stdio.h>
13#include <string.h>
14#include "windef.h"
15#include "winbase.h"
16#include "wingdi.h"
17#include "wine/wingdi16.h"
18#include "winuser.h"
19#include "wine/winuser16.h"
20#include "commdlg.h"
21#include "dlgs.h"
22#include "debugtools.h"
23#include "cderr.h"
24#include "winspool.h"
25#include "winerror.h"
26
27DEFAULT_DEBUG_CHANNEL(commdlg);
28
29#include "cdlg.h"
30
31/* This PRINTDLGA internal structure stores
32 * pointers to several throughout useful structures.
33 *
34 */
35typedef struct
36{
37 LPDEVMODEA lpDevMode;
38 struct {
39 LPPRINTDLGA lpPrintDlg;
40 LPPRINTDLG16 lpPrintDlg16;
41 } dlg;
42 LPPRINTER_INFO_2A lpPrinterInfo;
43 LPDRIVER_INFO_3A lpDriverInfo;
44 UINT HelpMessageID;
45 HICON hCollateIcon; /* PrintDlg only */
46 HICON hNoCollateIcon; /* PrintDlg only */
47 HICON hPortraitIcon; /* PrintSetupDlg only */
48 HICON hLandscapeIcon; /* PrintSetupDlg only */
49 HWND hwndUpDown;
50} PRINT_PTRA;
51
52/* Debugging info */
53static struct pd_flags {
54 DWORD flag;
55 LPSTR name;
56} pd_flags[] = {
57 {PD_SELECTION, "PD_SELECTION "},
58 {PD_PAGENUMS, "PD_PAGENUMS "},
59 {PD_NOSELECTION, "PD_NOSELECTION "},
60 {PD_NOPAGENUMS, "PD_NOPAGENUMS "},
61 {PD_COLLATE, "PD_COLLATE "},
62 {PD_PRINTTOFILE, "PD_PRINTTOFILE "},
63 {PD_PRINTSETUP, "PD_PRINTSETUP "},
64 {PD_NOWARNING, "PD_NOWARNING "},
65 {PD_RETURNDC, "PD_RETURNDC "},
66 {PD_RETURNIC, "PD_RETURNIC "},
67 {PD_RETURNDEFAULT, "PD_RETURNDEFAULT "},
68 {PD_SHOWHELP, "PD_SHOWHELP "},
69 {PD_ENABLEPRINTHOOK, "PD_ENABLEPRINTHOOK "},
70 {PD_ENABLESETUPHOOK, "PD_ENABLESETUPHOOK "},
71 {PD_ENABLEPRINTTEMPLATE, "PD_ENABLEPRINTTEMPLATE "},
72 {PD_ENABLESETUPTEMPLATE, "PD_ENABLESETUPTEMPLATE "},
73 {PD_ENABLEPRINTTEMPLATEHANDLE, "PD_ENABLEPRINTTEMPLATEHANDLE "},
74 {PD_ENABLESETUPTEMPLATEHANDLE, "PD_ENABLESETUPTEMPLATEHANDLE "},
75 {PD_USEDEVMODECOPIES, "PD_USEDEVMODECOPIES[ANDCOLLATE] "},
76 {PD_DISABLEPRINTTOFILE, "PD_DISABLEPRINTTOFILE "},
77 {PD_HIDEPRINTTOFILE, "PD_HIDEPRINTTOFILE "},
78 {PD_NONETWORKBUTTON, "PD_NONETWORKBUTTON "},
79 {-1, NULL}
80};
81
82/* Debugging info */
83static struct pd_flags psd_flags[] = {
84 {PSD_MINMARGINS,"PSD_MINMARGINS"},
85 {PSD_MARGINS,"PSD_MARGINS"},
86 {PSD_INTHOUSANDTHSOFINCHES,"PSD_INTHOUSANDTHSOFINCHES"},
87 {PSD_INHUNDREDTHSOFMILLIMETERS,"PSD_INHUNDREDTHSOFMILLIMETERS"},
88 {PSD_DISABLEMARGINS,"PSD_DISABLEMARGINS"},
89 {PSD_DISABLEPRINTER,"PSD_DISABLEPRINTER"},
90 {PSD_NOWARNING,"PSD_NOWARNING"},
91 {PSD_DISABLEORIENTATION,"PSD_DISABLEORIENTATION"},
92 {PSD_RETURNDEFAULT,"PSD_RETURNDEFAULT"},
93 {PSD_DISABLEPAPER,"PSD_DISABLEPAPER"},
94 {PSD_SHOWHELP,"PSD_SHOWHELP"},
95 {PSD_ENABLEPAGESETUPHOOK,"PSD_ENABLEPAGESETUPHOOK"},
96 {PSD_ENABLEPAGESETUPTEMPLATE,"PSD_ENABLEPAGESETUPTEMPLATE"},
97 {PSD_ENABLEPAGESETUPTEMPLATEHANDLE,"PSD_ENABLEPAGESETUPTEMPLATEHANDLE"},
98 {PSD_ENABLEPAGEPAINTHOOK,"PSD_ENABLEPAGEPAINTHOOK"},
99 {PSD_DISABLEPAGEPAINTING,"PSD_DISABLEPAGEPAINTING"},
100 {-1, NULL}
101};
102
103/* Yes these constants are the same, but we're just copying win98 */
104#define UPDOWN_ID 0x270f
105#define MAX_COPIES 9999
106
107/***********************************************************************
108 * PRINTDLG_GetDefaultPrinterName
109 *
110 * Returns the default printer name in buf.
111 * Even under WinNT/2000 default printer is retrieved via GetProfileString -
112 * these entries are mapped somewhere in the registry rather than win.ini.
113 *
114 * Returns TRUE on success else FALSE
115 */
116static BOOL PRINTDLG_GetDefaultPrinterName(LPSTR buf, DWORD len)
117{
118 char *ptr;
119
120 if(!GetProfileStringA("windows", "device", "", buf, len)) {
121 TRACE("No profile entry for default printer found.\n");
122 return FALSE;
123 }
124 if((ptr = strchr(buf, ',')) == NULL) {
125 FIXME("bad format for default printer (%s)!\n",buf);
126 return FALSE;
127 }
128 *ptr = '\0';
129 return TRUE;
130}
131
132/***********************************************************************
133 * PRINTDLG_OpenDefaultPrinter
134 *
135 * Returns a winspool printer handle to the default printer in *hprn
136 * Caller must call ClosePrinter on the handle
137 *
138 * Returns TRUE on success else FALSE
139 */
140static BOOL PRINTDLG_OpenDefaultPrinter(HANDLE *hprn)
141{
142 char buf[260];
143 BOOL res;
144 if(!PRINTDLG_GetDefaultPrinterName(buf, sizeof(buf)))
145 return FALSE;
146 res = OpenPrinterA(buf, hprn, NULL);
147 if (!res)
148 FIXME("Could not open printer %s?!\n",buf);
149 return res;
150}
151
152/***********************************************************************
153 * PRINTDLG_SetUpPrinterListCombo
154 *
155 * Initializes printer list combox.
156 * hDlg: HWND of dialog
157 * id: Control id of combo
158 * name: Name of printer to select
159 *
160 * Initializes combo with list of available printers. Selects printer 'name'
161 * If name is NULL or does not exist select the default printer.
162 *
163 * Returns number of printers added to list.
164 */
165static INT PRINTDLG_SetUpPrinterListCombo(HWND hDlg, UINT id, LPCSTR name)
166{
167 DWORD needed, num;
168 INT i;
169 LPPRINTER_INFO_2A pi;
170 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
171 pi = HeapAlloc(GetProcessHeap(), 0, needed);
172 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
173 &num);
174
175 for(i = 0; i < num; i++) {
176 SendDlgItemMessageA(hDlg, id, CB_ADDSTRING, 0,
177 (LPARAM)pi[i].pPrinterName );
178 }
179 HeapFree(GetProcessHeap(), 0, pi);
180 if(!name ||
181 (i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1,
182 (LPARAM)name)) == CB_ERR) {
183
184 char buf[260];
185 FIXME("Can't find '%s' in printer list so trying to find default\n",
186 name);
187 if(!PRINTDLG_GetDefaultPrinterName(buf, sizeof(buf)))
188 return num;
189 i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
190 if(i == CB_ERR)
191 FIXME("Can't find default printer in printer list\n");
192 }
193 SendDlgItemMessageA(hDlg, id, CB_SETCURSEL, i, 0);
194 return num;
195}
196
197/***********************************************************************
198 * PRINTDLG_CreateDevNames [internal]
199 *
200 *
201 * creates a DevNames structure.
202 *
203 * (NB. when we handle unicode the offsets will be in wchars).
204 */
205static BOOL PRINTDLG_CreateDevNames(HGLOBAL *hmem, char* DeviceDriverName,
206 char* DeviceName, char* OutputPort)
207{
208 long size;
209 char* pDevNamesSpace;
210 char* pTempPtr;
211 LPDEVNAMES lpDevNames;
212 char buf[260];
213
214 size = strlen(DeviceDriverName) + 1
215 + strlen(DeviceName) + 1
216 + strlen(OutputPort) + 1
217 + sizeof(DEVNAMES);
218
219 if(*hmem)
220 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
221 else
222 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
223 if (*hmem == 0)
224 return FALSE;
225
226 pDevNamesSpace = GlobalLock(*hmem);
227 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
228
229 pTempPtr = pDevNamesSpace + sizeof(DEVNAMES);
230 strcpy(pTempPtr, DeviceDriverName);
231 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
232
233 pTempPtr += strlen(DeviceDriverName) + 1;
234 strcpy(pTempPtr, DeviceName);
235 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
236
237 pTempPtr += strlen(DeviceName) + 1;
238 strcpy(pTempPtr, OutputPort);
239 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
240
241 PRINTDLG_GetDefaultPrinterName(buf, sizeof(buf));
242 lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
243 GlobalUnlock(*hmem);
244 return TRUE;
245}
246#ifndef __WIN32OS2__
247static BOOL PRINTDLG_CreateDevNames16(HGLOBAL16 *hmem, char* DeviceDriverName,
248 char* DeviceName, char* OutputPort)
249{
250 long size;
251 char* pDevNamesSpace;
252 char* pTempPtr;
253 LPDEVNAMES lpDevNames;
254 char buf[260];
255
256 size = strlen(DeviceDriverName) + 1
257 + strlen(DeviceName) + 1
258 + strlen(OutputPort) + 1
259 + sizeof(DEVNAMES);
260
261 if(*hmem)
262 *hmem = GlobalReAlloc16(*hmem, size, GMEM_MOVEABLE);
263 else
264 *hmem = GlobalAlloc16(GMEM_MOVEABLE, size);
265 if (*hmem == 0)
266 return FALSE;
267
268 pDevNamesSpace = GlobalLock16(*hmem);
269 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
270
271 pTempPtr = pDevNamesSpace + sizeof(DEVNAMES);
272 strcpy(pTempPtr, DeviceDriverName);
273 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
274
275 pTempPtr += strlen(DeviceDriverName) + 1;
276 strcpy(pTempPtr, DeviceName);
277 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
278
279 pTempPtr += strlen(DeviceName) + 1;
280 strcpy(pTempPtr, OutputPort);
281 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
282
283 PRINTDLG_GetDefaultPrinterName(buf, sizeof(buf));
284 lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
285 GlobalUnlock16(*hmem);
286 return TRUE;
287}
288#endif
289
290/***********************************************************************
291 * PRINTDLG_UpdatePrintDlg [internal]
292 *
293 *
294 * updates the PrintDlg structure for returnvalues.
295 *
296 * RETURNS
297 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
298 * TRUE if succesful.
299 */
300static BOOL PRINTDLG_UpdatePrintDlg(HWND hDlg,
301 PRINT_PTRA* PrintStructures)
302{
303 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
304 PDEVMODEA lpdm = PrintStructures->lpDevMode;
305 LPPRINTER_INFO_2A pi = PrintStructures->lpPrinterInfo;
306
307
308 if(!lpdm) {
309 FIXME("No lpdm ptr?\n");
310 return FALSE;
311 }
312
313
314 if(!(lppd->Flags & PD_PRINTSETUP)) {
315 /* check whether nFromPage and nToPage are within range defined by
316 * nMinPage and nMaxPage
317 */
318 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
319 WORD nToPage;
320 WORD nFromPage;
321 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
322 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
323 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
324 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
325 char resourcestr[256];
326 char resultstr[256];
327 LoadStringA(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
328 resourcestr, 255);
329 sprintf(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
330 LoadStringA(COMDLG32_hInstance, PD32_PRINT_TITLE,
331 resourcestr, 255);
332 MessageBoxA(hDlg, resultstr, resourcestr,
333 MB_OK | MB_ICONWARNING);
334 return FALSE;
335 }
336 lppd->nFromPage = nFromPage;
337 lppd->nToPage = nToPage;
338 }
339
340 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
341 lppd->Flags |= PD_PRINTTOFILE;
342 pi->pPortName = "FILE:";
343 }
344
345 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
346 FIXME("Collate lppd not yet implemented as output\n");
347 }
348
349 /* set PD_Collate and nCopies */
350 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
351 /* The application doesn't support multiple copies or collate...
352 */
353 lppd->Flags &= ~PD_COLLATE;
354 lppd->nCopies = 1;
355 /* if the printer driver supports it... store info there
356 * otherwise no collate & multiple copies !
357 */
358 if (lpdm->dmFields & DM_COLLATE)
359 lpdm->dmCollate =
360 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
361 if (lpdm->dmFields & DM_COPIES)
362 lpdm->dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
363 } else {
364 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
365 lppd->Flags |= PD_COLLATE;
366 else
367 lppd->Flags &= ~PD_COLLATE;
368 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
369 }
370 }
371 return TRUE;
372}
373
374static BOOL PRINTDLG_PaperSize(
375 PRINTDLGA *pdlga,const char *PaperSize,LPPOINT size
376) {
377 DEVNAMES *dn;
378 DEVMODEA *dm;
379 LPSTR devname,portname;
380 int i;
381 DWORD NrOfEntries,ret;
382 char *Names = NULL;
383 POINT *points = NULL;
384 BOOL retval = FALSE;
385
386 dn = GlobalLock(pdlga->hDevNames);
387 dm = GlobalLock(pdlga->hDevMode);
388 devname = ((char*)dn)+dn->wDeviceOffset;
389 portname = ((char*)dn)+dn->wOutputOffset;
390
391
392 NrOfEntries = DeviceCapabilitiesA(devname,portname,DC_PAPERNAMES,NULL,dm);
393 if (!NrOfEntries) {
394 FIXME("No papernames found for %s/%s\n",devname,portname);
395 goto out;
396 }
397 Names = (char*)HeapAlloc(GetProcessHeap(),0,NrOfEntries*64);
398 if (NrOfEntries != (ret=DeviceCapabilitiesA(devname,portname,DC_PAPERNAMES,Names,dm))) {
399 FIXME("Number of returned vals %ld is not %ld\n",NrOfEntries,ret);
400 goto out;
401 }
402 for (i=0;i<NrOfEntries;i++)
403 if (!strcmp(PaperSize,Names+(64*i)))
404 break;
405 HeapFree(GetProcessHeap(),0,Names);
406 if (i==NrOfEntries) {
407 FIXME("Papersize %s not found in list?\n",PaperSize);
408 goto out;
409 }
410 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
411 if (NrOfEntries!=(ret=DeviceCapabilitiesA(devname,portname,DC_PAPERSIZE,(LPBYTE)points,dm))) {
412 FIXME("Number of returned sizes %ld is not %ld?\n",NrOfEntries,ret);
413 goto out;
414 }
415 /* this is _10ths_ of a millimeter */
416 size->x=points[i].x;
417 size->y=points[i].y;
418 FIXME("papersize is %ld x %ld\n",size->x,size->y);
419 retval = TRUE;
420out:
421 GlobalUnlock(pdlga->hDevNames);
422 GlobalUnlock(pdlga->hDevMode);
423 if (Names) HeapFree(GetProcessHeap(),0,Names);
424 if (points) HeapFree(GetProcessHeap(),0,points);
425 return retval;
426}
427
428
429/************************************************************************
430 * PRINTDLG_SetUpPaperComboBox
431 *
432 * Initialize either the papersize or inputslot combos of the Printer Setup
433 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
434 * We also try to re-select the old selection.
435 */
436static BOOL PRINTDLG_SetUpPaperComboBox(HWND hDlg,
437 int nIDComboBox,
438 char* PrinterName,
439 char* PortName,
440 LPDEVMODEA dm)
441{
442 int i;
443 DWORD NrOfEntries;
444 char* Names;
445 WORD* Words;
446 DWORD Sel;
447 WORD oldWord = 0;
448 int NamesSize;
449 int fwCapability_Names;
450 int fwCapability_Words;
451
452 TRACE(" Printer: %s, ComboID: %d\n",PrinterName,nIDComboBox);
453
454 /* query the dialog box for the current selected value */
455 Sel = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
456 if(Sel != CB_ERR) {
457 /* we enter here only if a different printer is selected after
458 * the Print Setup dialog is opened. The current settings are
459 * stored into the newly selected printer.
460 */
461 oldWord = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA,
462 Sel, 0);
463 if (dm) {
464 if (nIDComboBox == cmb2)
465#ifdef __WIN32OS2__
466 dm->dmPaperSize = oldWord;
467#else
468 dm->u1.s1.dmPaperSize = oldWord;
469#endif
470 else
471 dm->dmDefaultSource = oldWord;
472 }
473 }
474 else {
475 /* we enter here only when the Print setup dialog is initially
476 * opened. In this case the settings are restored from when
477 * the dialog was last closed.
478 */
479 if (dm) {
480 if (nIDComboBox == cmb2)
481#ifdef __WIN32OS2__
482 oldWord = dm->dmPaperSize;
483#else
484 oldWord = dm->u1.s1.dmPaperSize;
485#endif
486 else
487 oldWord = dm->dmDefaultSource;
488 }
489 }
490
491 if (nIDComboBox == cmb2) {
492 NamesSize = 64;
493 fwCapability_Names = DC_PAPERNAMES;
494 fwCapability_Words = DC_PAPERS;
495 } else {
496 nIDComboBox = cmb3;
497 NamesSize = 24;
498 fwCapability_Names = DC_BINNAMES;
499 fwCapability_Words = DC_BINS;
500 }
501
502 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
503 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
504 */
505 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
506 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
507 fwCapability_Names, NULL, dm);
508 if (NrOfEntries == 0)
509 WARN("no Name Entries found!\n");
510
511 if(DeviceCapabilitiesA(PrinterName, PortName, fwCapability_Words, NULL, dm)
512 != NrOfEntries) {
513 ERR("Number of caps is different\n");
514 NrOfEntries = 0;
515 }
516
517 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*NamesSize);
518 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
519 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
520 fwCapability_Names, Names, dm);
521 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
522 fwCapability_Words, (LPSTR)Words, dm);
523
524 /* reset any current content in the combobox */
525 SendDlgItemMessageA(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
526
527 /* store new content */
528 for (i = 0; i < NrOfEntries; i++) {
529 DWORD pos = SendDlgItemMessageA(hDlg, nIDComboBox, CB_ADDSTRING, 0,
530 (LPARAM)(&Names[i*NamesSize]) );
531 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
532 Words[i]);
533 }
534
535 /* Look for old selection - can't do this is previous loop since
536 item order will change as more items are added */
537 Sel = 0;
538 for (i = 0; i < NrOfEntries; i++) {
539 if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
540 oldWord) {
541 Sel = i;
542 break;
543 }
544 }
545 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
546
547 HeapFree(GetProcessHeap(),0,Words);
548 HeapFree(GetProcessHeap(),0,Names);
549 return TRUE;
550}
551
552/***********************************************************************
553 * PRINTDLG_UpdatePrinterInfoTexts [internal]
554 */
555static void PRINTDLG_UpdatePrinterInfoTexts(HWND hDlg, LPPRINTER_INFO_2A pi)
556{
557 char StatusMsg[256];
558 char ResourceString[256];
559 int i;
560
561 /* Status Message */
562 StatusMsg[0]='\0';
563
564 /* add all status messages */
565 for (i = 0; i < 25; i++) {
566 if (pi->Status & (1<<i)) {
567 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
568 ResourceString, 255);
569 strcat(StatusMsg,ResourceString);
570 }
571 }
572 /* append "ready" */
573 /* FIXME: status==ready must only be appended if really so.
574 but how to detect? */
575 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
576 ResourceString, 255);
577 strcat(StatusMsg,ResourceString);
578
579 SendDlgItemMessageA(hDlg, stc12, WM_SETTEXT, 0, (LPARAM)StatusMsg);
580
581 /* set all other printer info texts */
582 SendDlgItemMessageA(hDlg, stc11, WM_SETTEXT, 0, (LPARAM)pi->pDriverName);
583 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
584 SendDlgItemMessageA(hDlg, stc14, WM_SETTEXT, 0,(LPARAM)pi->pLocation);
585 else
586 SendDlgItemMessageA(hDlg, stc14, WM_SETTEXT, 0,(LPARAM)pi->pPortName);
587 SendDlgItemMessageA(hDlg, stc13, WM_SETTEXT, 0, (LPARAM)(pi->pComment ?
588 pi->pComment : ""));
589 return;
590}
591
592
593/*******************************************************************
594 *
595 * PRINTDLG_ChangePrinter
596 *
597 */
598static BOOL PRINTDLG_ChangePrinter(HWND hDlg, char *name,
599 PRINT_PTRA *PrintStructures)
600{
601 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
602 LPDEVMODEA lpdm = NULL;
603 LONG dmSize;
604 DWORD needed;
605 HANDLE hprn;
606
607 if(PrintStructures->lpPrinterInfo)
608 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
609 if(PrintStructures->lpDriverInfo)
610 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
611 if(!OpenPrinterA(name, &hprn, NULL)) {
612 ERR("Can't open printer %s\n", name);
613 return FALSE;
614 }
615 GetPrinterA(hprn, 2, NULL, 0, &needed);
616 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,needed);
617 GetPrinterA(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
618 &needed);
619 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
620 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,needed);
621 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
622 needed, &needed)) {
623 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures->lpPrinterInfo->pPrinterName);
624 return FALSE;
625 }
626 ClosePrinter(hprn);
627
628 PRINTDLG_UpdatePrinterInfoTexts(hDlg, PrintStructures->lpPrinterInfo);
629
630 if(PrintStructures->lpDevMode) {
631 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
632 PrintStructures->lpDevMode = NULL;
633 }
634
635 dmSize = DocumentPropertiesA(0, 0, name, NULL, NULL, 0);
636 if(dmSize == -1) {
637 ERR("DocumentProperties fails on %s\n", debugstr_a(name));
638 return FALSE;
639 }
640 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
641 dmSize = DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, NULL,
642 DM_OUT_BUFFER);
643 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
644 !strcmp(lpdm->dmDeviceName,
645 PrintStructures->lpDevMode->dmDeviceName)) {
646 /* Supplied devicemode matches current printer so try to use it */
647 DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, lpdm,
648 DM_OUT_BUFFER | DM_IN_BUFFER);
649 }
650 if(lpdm)
651 GlobalUnlock(lppd->hDevMode);
652
653 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
654
655 if(!(lppd->Flags & PD_PRINTSETUP)) {
656 /* Print range (All/Range/Selection) */
657 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
658 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
659 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
660 if (lppd->Flags & PD_NOSELECTION)
661 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
662 else
663 if (lppd->Flags & PD_SELECTION)
664 CheckRadioButton(hDlg, rad1, rad3, rad2);
665 if (lppd->Flags & PD_NOPAGENUMS) {
666 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
667 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
668 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
669 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
670 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
671 } else {
672 if (lppd->Flags & PD_PAGENUMS)
673 CheckRadioButton(hDlg, rad1, rad3, rad3);
674 }
675 /* "All xxx pages"... */
676 {
677 char resourcestr[64];
678 char result[64];
679 LoadStringA(COMDLG32_hInstance, PD32_PRINT_ALL_X_PAGES,
680 resourcestr, 49);
681 sprintf(result,resourcestr,lppd->nMaxPage - lppd->nMinPage + 1);
682 SendDlgItemMessageA(hDlg, rad1, WM_SETTEXT, 0, (LPARAM) result);
683 }
684
685 /* Collate pages
686 *
687 * FIXME: The ico3 is not displayed for some reason. I don't know why.
688 */
689 if (lppd->Flags & PD_COLLATE) {
690 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
691 (LPARAM)PrintStructures->hCollateIcon);
692 CheckDlgButton(hDlg, chx2, 1);
693 } else {
694 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
695 (LPARAM)PrintStructures->hNoCollateIcon);
696 CheckDlgButton(hDlg, chx2, 0);
697 }
698
699 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
700 /* if printer doesn't support it: no Collate */
701 if (!(lpdm->dmFields & DM_COLLATE)) {
702 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
703 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
704 }
705 }
706
707 /* nCopies */
708 {
709 INT copies;
710 if (lppd->hDevMode == 0)
711 copies = lppd->nCopies;
712 else
713 copies = lpdm->dmCopies;
714 if(copies == 0) copies = 1;
715 else if(copies < 0) copies = MAX_COPIES;
716 SetDlgItemInt(hDlg, edt3, copies, FALSE);
717 }
718
719 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
720 /* if printer doesn't support it: no nCopies */
721 if (!(lpdm->dmFields & DM_COPIES)) {
722 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
723 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
724 }
725 }
726
727 /* print to file */
728 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
729 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
730 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
731 if (lppd->Flags & PD_HIDEPRINTTOFILE)
732 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
733
734 } else { /* PD_PRINTSETUP */
735#ifdef __WIN32OS2__
736 BOOL bPortrait = (lpdm->dmOrientation == DMORIENT_PORTRAIT);
737#else
738 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
739#endif
740
741 PRINTDLG_SetUpPaperComboBox(hDlg, cmb2,
742 PrintStructures->lpPrinterInfo->pPrinterName,
743 PrintStructures->lpPrinterInfo->pPortName,
744 lpdm);
745 PRINTDLG_SetUpPaperComboBox(hDlg, cmb3,
746 PrintStructures->lpPrinterInfo->pPrinterName,
747 PrintStructures->lpPrinterInfo->pPortName,
748 lpdm);
749 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
750 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
751 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
752 PrintStructures->hLandscapeIcon));
753
754 }
755
756 /* help button */
757 if ((lppd->Flags & PD_SHOWHELP)==0) {
758 /* hide if PD_SHOWHELP not specified */
759 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
760 }
761 return TRUE;
762}
763
764/***********************************************************************
765 * PRINTDLG_WMInitDialog [internal]
766 */
767static LRESULT PRINTDLG_WMInitDialog(HWND hDlg, WPARAM wParam,
768 PRINT_PTRA* PrintStructures)
769{
770 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
771 DEVNAMES *pdn;
772 DEVMODEA *pdm;
773 char *name = NULL;
774 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
775
776 /* load Collate ICONs */
777 /* We load these with LoadImage becasue they are not a standard
778 size and we don't want them rescaled */
779 PrintStructures->hCollateIcon =
780 LoadImageA(COMDLG32_hInstance, "PD32_COLLATE", IMAGE_ICON, 0, 0, 0);
781 PrintStructures->hNoCollateIcon =
782 LoadImageA(COMDLG32_hInstance, "PD32_NOCOLLATE", IMAGE_ICON, 0, 0, 0);
783
784 /* These can be done with LoadIcon */
785 PrintStructures->hPortraitIcon =
786 LoadIconA(COMDLG32_hInstance, "PD32_PORTRAIT");
787 PrintStructures->hLandscapeIcon =
788 LoadIconA(COMDLG32_hInstance, "PD32_LANDSCAPE");
789
790 if(PrintStructures->hCollateIcon == 0 ||
791 PrintStructures->hNoCollateIcon == 0 ||
792 PrintStructures->hPortraitIcon == 0 ||
793 PrintStructures->hLandscapeIcon == 0) {
794 ERR("no icon in resourcefile\n");
795 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
796 EndDialog(hDlg, FALSE);
797 }
798
799 /*
800 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
801 * must be registered and the Help button must be shown.
802 */
803 if (lppd->Flags & PD_SHOWHELP) {
804 if((PrintStructures->HelpMessageID =
805 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
806 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
807 return FALSE;
808 }
809 } else
810 PrintStructures->HelpMessageID = 0;
811
812 if(!(lppd->Flags &PD_PRINTSETUP)) {
813 PrintStructures->hwndUpDown =
814 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
815 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
816 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
817 hDlg, UPDOWN_ID, COMDLG32_hInstance,
818 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
819 }
820
821 /* FIXME: I allow more freedom than either Win95 or WinNT,
822 * which do not agree to what errors should be thrown or not
823 * in case nToPage or nFromPage is out-of-range.
824 */
825 if (lppd->nMaxPage < lppd->nMinPage)
826 lppd->nMaxPage = lppd->nMinPage;
827 if (lppd->nMinPage == lppd->nMaxPage)
828 lppd->Flags |= PD_NOPAGENUMS;
829 if (lppd->nToPage < lppd->nMinPage)
830 lppd->nToPage = lppd->nMinPage;
831 if (lppd->nToPage > lppd->nMaxPage)
832 lppd->nToPage = lppd->nMaxPage;
833 if (lppd->nFromPage < lppd->nMinPage)
834 lppd->nFromPage = lppd->nMinPage;
835 if (lppd->nFromPage > lppd->nMaxPage)
836 lppd->nFromPage = lppd->nMaxPage;
837
838 /* if we have the combo box, fill it */
839 if (GetDlgItem(hDlg,comboID)) {
840 /* Fill Combobox
841 */
842 pdn = GlobalLock(lppd->hDevNames);
843 pdm = GlobalLock(lppd->hDevMode);
844 if(pdn)
845 name = (char*)pdn + pdn->wDeviceOffset;
846 else if(pdm)
847 name = pdm->dmDeviceName;
848 PRINTDLG_SetUpPrinterListCombo(hDlg, comboID, name);
849 if(pdm) GlobalUnlock(lppd->hDevMode);
850 if(pdn) GlobalUnlock(lppd->hDevNames);
851
852 /* Now find selected printer and update rest of dlg */
853 name = HeapAlloc(GetProcessHeap(),0,256);
854 if (GetDlgItemTextA(hDlg, comboID, name, 255))
855 PRINTDLG_ChangePrinter(hDlg, name, PrintStructures);
856 HeapFree(GetProcessHeap(),0,name);
857 } else {
858 /* else use default printer */
859 char name[200];
860 BOOL ret = PRINTDLG_GetDefaultPrinterName(name, sizeof(name));
861
862 if (ret)
863 PRINTDLG_ChangePrinter(hDlg, name, PrintStructures);
864 else
865 FIXME("No default printer found, expect problems!\n");
866 }
867 return TRUE;
868}
869
870#ifndef __WIN32OS2__
871/***********************************************************************
872 * PRINTDLG_WMInitDialog [internal]
873 */
874static LRESULT PRINTDLG_WMInitDialog16(HWND hDlg, WPARAM wParam,
875 PRINT_PTRA* PrintStructures)
876{
877 LPPRINTDLG16 lppd = PrintStructures->dlg.lpPrintDlg16;
878 DEVNAMES *pdn;
879 DEVMODEA *pdm;
880 char *name = NULL;
881 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
882
883 /* load Collate ICONs */
884 PrintStructures->hCollateIcon =
885 LoadIconA(COMDLG32_hInstance, "PD32_COLLATE");
886 PrintStructures->hNoCollateIcon =
887 LoadIconA(COMDLG32_hInstance, "PD32_NOCOLLATE");
888 if(PrintStructures->hCollateIcon == 0 ||
889 PrintStructures->hNoCollateIcon == 0) {
890 ERR("no icon in resourcefile\n");
891 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
892 EndDialog(hDlg, FALSE);
893 }
894
895 /* load Paper Orientation ICON */
896 /* FIXME: not implemented yet */
897
898 /*
899 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
900 * must be registered and the Help button must be shown.
901 */
902 if (lppd->Flags & PD_SHOWHELP) {
903 if((PrintStructures->HelpMessageID =
904 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
905 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
906 return FALSE;
907 }
908 } else
909 PrintStructures->HelpMessageID = 0;
910
911 if (!(lppd->Flags & PD_PRINTSETUP)) {
912 /* We have a print quality combo box. What shall we do? */
913 if (GetDlgItem(hDlg,cmb1)) {
914 char buf [20];
915
916 FIXME("Print quality only displaying currently.\n");
917
918 pdm = GlobalLock16(lppd->hDevMode);
919 if(pdm) {
920 switch (pdm->dmPrintQuality) {
921 case DMRES_HIGH : strcpy(buf,"High");break;
922 case DMRES_MEDIUM : strcpy(buf,"Medium");break;
923 case DMRES_LOW : strcpy(buf,"Low");break;
924 case DMRES_DRAFT : strcpy(buf,"Draft");break;
925 case 0 : strcpy(buf,"Default");break;
926 default : sprintf(buf,"%ddpi",pdm->dmPrintQuality);break;
927 }
928 GlobalUnlock16(lppd->hDevMode);
929 } else
930 strcpy(buf,"Default");
931 SendDlgItemMessageA(hDlg,cmb1,CB_ADDSTRING,0,(LPARAM)buf);
932 SendDlgItemMessageA(hDlg,cmb1,CB_SETCURSEL,0,0);
933 EnableWindow(GetDlgItem(hDlg,cmb1),FALSE);
934 }
935 }
936
937 /* FIXME: I allow more freedom than either Win95 or WinNT,
938 * which do not agree to what errors should be thrown or not
939 * in case nToPage or nFromPage is out-of-range.
940 */
941 if (lppd->nMaxPage < lppd->nMinPage)
942 lppd->nMaxPage = lppd->nMinPage;
943 if (lppd->nMinPage == lppd->nMaxPage)
944 lppd->Flags |= PD_NOPAGENUMS;
945 if (lppd->nToPage < lppd->nMinPage)
946 lppd->nToPage = lppd->nMinPage;
947 if (lppd->nToPage > lppd->nMaxPage)
948 lppd->nToPage = lppd->nMaxPage;
949 if (lppd->nFromPage < lppd->nMinPage)
950 lppd->nFromPage = lppd->nMinPage;
951 if (lppd->nFromPage > lppd->nMaxPage)
952 lppd->nFromPage = lppd->nMaxPage;
953
954 /* If the printer combo box is in the dialog, fill it */
955 if (GetDlgItem(hDlg,comboID)) {
956 /* Fill Combobox
957 */
958 pdn = GlobalLock16(lppd->hDevNames);
959 pdm = GlobalLock16(lppd->hDevMode);
960 if(pdn)
961 name = (char*)pdn + pdn->wDeviceOffset;
962 else if(pdm)
963 name = pdm->dmDeviceName;
964 PRINTDLG_SetUpPrinterListCombo(hDlg, comboID, name);
965 if(pdm) GlobalUnlock16(lppd->hDevMode);
966 if(pdn) GlobalUnlock16(lppd->hDevNames);
967
968 /* Now find selected printer and update rest of dlg */
969 name = HeapAlloc(GetProcessHeap(),0,256);
970 if (GetDlgItemTextA(hDlg, comboID, name, 255))
971 PRINTDLG_ChangePrinter(hDlg, name, PrintStructures);
972 } else {
973 /* else just use default printer */
974 char name[200];
975 BOOL ret = PRINTDLG_GetDefaultPrinterName(name, sizeof(name));
976
977 if (ret)
978 PRINTDLG_ChangePrinter(hDlg, name, PrintStructures);
979 else
980 FIXME("No default printer found, expect problems!\n");
981 }
982 HeapFree(GetProcessHeap(),0,name);
983
984 return TRUE;
985}
986#endif
987
988/***********************************************************************
989 * PRINTDLG_WMCommand [internal]
990 */
991static LRESULT PRINTDLG_WMCommand(HWND hDlg, WPARAM wParam,
992 LPARAM lParam, PRINT_PTRA* PrintStructures)
993{
994 LPPRINTDLGA lppd = PrintStructures->dlg.lpPrintDlg;
995 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
996 LPDEVMODEA lpdm = PrintStructures->lpDevMode;
997
998 switch (LOWORD(wParam)) {
999 case IDOK:
1000 TRACE(" OK button was hit\n");
1001 if (PRINTDLG_UpdatePrintDlg(hDlg, PrintStructures)!=TRUE) {
1002 FIXME("Update printdlg was not successful!\n");
1003 return(FALSE);
1004 }
1005 EndDialog(hDlg, TRUE);
1006 return(TRUE);
1007
1008 case IDCANCEL:
1009 TRACE(" CANCEL button was hit\n");
1010 EndDialog(hDlg, FALSE);
1011 return(FALSE);
1012
1013 case pshHelp:
1014 TRACE(" HELP button was hit\n");
1015 SendMessageA(lppd->hwndOwner, PrintStructures->HelpMessageID,
1016 (WPARAM) hDlg, (LPARAM) lppd);
1017 break;
1018
1019 case chx2: /* collate pages checkbox */
1020 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1021 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1022 (LPARAM)PrintStructures->hCollateIcon);
1023 else
1024 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1025 (LPARAM)PrintStructures->hNoCollateIcon);
1026 break;
1027 case edt1: /* from page nr editbox */
1028 case edt2: /* to page nr editbox */
1029 if (HIWORD(wParam)==EN_CHANGE) {
1030 WORD nToPage;
1031 WORD nFromPage;
1032 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1033 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1034 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1035 CheckRadioButton(hDlg, rad1, rad3, rad3);
1036 }
1037 break;
1038
1039 case edt3:
1040 if(HIWORD(wParam) == EN_CHANGE) {
1041 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1042 if(copies <= 1)
1043 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1044 else
1045 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1046 }
1047 break;
1048
1049#ifndef __WIN32OS2__
1050 case psh1: /* Print Setup */
1051 {
1052 PRINTDLG16 pdlg;
1053
1054 if (!PrintStructures->dlg.lpPrintDlg16) {
1055 FIXME("The 32bit print dialog does not have this button!?\n");
1056 break;
1057 }
1058
1059 memcpy(&pdlg,PrintStructures->dlg.lpPrintDlg16,sizeof(pdlg));
1060 pdlg.Flags |= PD_PRINTSETUP;
1061 pdlg.hwndOwner = hDlg;
1062 if (!PrintDlg16(&pdlg))
1063 break;
1064 }
1065 break;
1066#endif
1067
1068 case psh2: /* Properties button */
1069 {
1070 HANDLE hPrinter;
1071 char PrinterName[256];
1072
1073 GetDlgItemTextA(hDlg, PrinterComboID, PrinterName, 255);
1074 if (!OpenPrinterA(PrinterName, &hPrinter, NULL)) {
1075 FIXME(" Call to OpenPrinter did not succeed!\n");
1076 break;
1077 }
1078 DocumentPropertiesA(hDlg, hPrinter, PrinterName,
1079 PrintStructures->lpDevMode,
1080 PrintStructures->lpDevMode,
1081 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1082 ClosePrinter(hPrinter);
1083 break;
1084 }
1085
1086 case rad1: /* Paperorientation */
1087 if (lppd->Flags & PD_PRINTSETUP)
1088 {
1089#ifdef __WIN32OS2__
1090 lpdm->dmOrientation = DMORIENT_PORTRAIT;
1091#else
1092 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1093#endif
1094 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1095 (LPARAM)(PrintStructures->hPortraitIcon));
1096 }
1097 break;
1098
1099 case rad2: /* Paperorientation */
1100 if (lppd->Flags & PD_PRINTSETUP)
1101 {
1102#ifdef __WIN32OS2__
1103 lpdm->dmOrientation = DMORIENT_LANDSCAPE;
1104#else
1105 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1106#endif
1107 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1108 (LPARAM)(PrintStructures->hLandscapeIcon));
1109 }
1110 break;
1111
1112 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1113 if (PrinterComboID != wParam) {
1114 FIXME("No handling for print quality combo box yet.\n");
1115 break;
1116 }
1117 /* FALLTHROUGH */
1118 case cmb4: /* Printer combobox */
1119 if (HIWORD(wParam)==CBN_SELCHANGE) {
1120 char PrinterName[256];
1121 GetDlgItemTextA(hDlg, LOWORD(wParam), PrinterName, 255);
1122 PRINTDLG_ChangePrinter(hDlg, PrinterName, PrintStructures);
1123 }
1124 break;
1125
1126 case cmb2: /* Papersize */
1127 {
1128 DWORD Sel = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1129 if(Sel != CB_ERR)
1130#ifdef __WIN32OS2__
1131 lpdm->dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
1132#else
1133 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
1134#endif
1135 CB_GETITEMDATA,
1136 Sel, 0);
1137 }
1138 break;
1139
1140 case cmb3: /* Bin */
1141 {
1142 DWORD Sel = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1143 if(Sel != CB_ERR)
1144 lpdm->dmDefaultSource = SendDlgItemMessageA(hDlg, cmb3,
1145 CB_GETITEMDATA, Sel,
1146 0);
1147 }
1148 break;
1149 }
1150 if(lppd->Flags & PD_PRINTSETUP) {
1151 switch (LOWORD(wParam)) {
1152 case rad1: /* orientation */
1153 case rad2:
1154 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1155#ifdef __WIN32OS2__
1156 if(lpdm->dmOrientation != DMORIENT_PORTRAIT) {
1157 lpdm->dmOrientation = DMORIENT_PORTRAIT;
1158#else
1159 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1160 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1161#endif
1162 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1163 (WPARAM)IMAGE_ICON,
1164 (LPARAM)PrintStructures->hPortraitIcon);
1165 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1166 (WPARAM)IMAGE_ICON,
1167 (LPARAM)PrintStructures->hPortraitIcon);
1168 }
1169 } else {
1170#ifdef __WIN32OS2__
1171 if(lpdm->dmOrientation != DMORIENT_LANDSCAPE) {
1172 lpdm->dmOrientation = DMORIENT_LANDSCAPE;
1173#else
1174 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1175 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1176#endif
1177 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1178 (WPARAM)IMAGE_ICON,
1179 (LPARAM)PrintStructures->hLandscapeIcon);
1180 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1181 (WPARAM)IMAGE_ICON,
1182 (LPARAM)PrintStructures->hLandscapeIcon);
1183 }
1184 }
1185 break;
1186 }
1187 }
1188 return FALSE;
1189}
1190
1191/***********************************************************************
1192 * PrintDlgProcA [internal]
1193 */
1194#ifdef __WIN32OS2__
1195LRESULT WINAPI PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
1196 LPARAM lParam)
1197#else
1198BOOL WINAPI PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
1199 LPARAM lParam)
1200#endif
1201{
1202 PRINT_PTRA* PrintStructures;
1203 LRESULT res=FALSE;
1204
1205 if (uMsg!=WM_INITDIALOG) {
1206 PrintStructures = (PRINT_PTRA*) GetWindowLongA(hDlg, DWL_USER);
1207 if (!PrintStructures)
1208 return FALSE;
1209 } else {
1210 PrintStructures = (PRINT_PTRA*) lParam;
1211 SetWindowLongA(hDlg, DWL_USER, lParam);
1212 res = PRINTDLG_WMInitDialog(hDlg, wParam, PrintStructures);
1213
1214 if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
1215 res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(
1216 hDlg, uMsg, wParam, (LPARAM)PrintStructures->dlg.lpPrintDlg
1217 );
1218 return res;
1219 }
1220
1221 if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
1222 res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam,
1223 lParam);
1224 if(res) return res;
1225 }
1226
1227 switch (uMsg) {
1228 case WM_COMMAND:
1229 return PRINTDLG_WMCommand(hDlg, wParam, lParam, PrintStructures);
1230
1231 case WM_DESTROY:
1232 DestroyIcon(PrintStructures->hCollateIcon);
1233 DestroyIcon(PrintStructures->hNoCollateIcon);
1234 DestroyIcon(PrintStructures->hPortraitIcon);
1235 DestroyIcon(PrintStructures->hLandscapeIcon);
1236 if(PrintStructures->hwndUpDown)
1237 DestroyWindow(PrintStructures->hwndUpDown);
1238 return FALSE;
1239 }
1240 return res;
1241}
1242
1243
1244#ifndef __WIN32OS2__
1245/************************************************************
1246 *
1247 * PRINTDLG_Get16TemplateFrom32 [Internal]
1248 * Generates a 16 bits template from the Wine 32 bits resource
1249 *
1250 */
1251static HGLOBAL16 PRINTDLG_Get16TemplateFrom32(char *PrintResourceName)
1252{
1253 HANDLE hResInfo, hDlgTmpl32;
1254 LPCVOID template32;
1255 DWORD size;
1256 HGLOBAL16 hGlobal16;
1257 LPVOID template;
1258
1259 if (!(hResInfo = FindResourceA(COMMDLG_hInstance32,
1260 PrintResourceName, RT_DIALOGA)))
1261 {
1262 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
1263 return 0;
1264 }
1265 if (!(hDlgTmpl32 = LoadResource(COMMDLG_hInstance32, hResInfo )) ||
1266 !(template32 = LockResource( hDlgTmpl32 )))
1267 {
1268 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1269 return 0;
1270 }
1271 size = SizeofResource(COMMDLG_hInstance32, hResInfo);
1272 hGlobal16 = GlobalAlloc16(0, size);
1273 if (!hGlobal16)
1274 {
1275 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
1276 ERR("alloc failure for %ld bytes\n", size);
1277 return 0;
1278 }
1279 template = GlobalLock16(hGlobal16);
1280 if (!template)
1281 {
1282 COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE);
1283 ERR("global lock failure for %x handle\n", hGlobal16);
1284 GlobalFree16(hGlobal16);
1285 return 0;
1286 }
1287 ConvertDialog32To16((LPVOID)template32, size, (LPVOID)template);
1288 GlobalUnlock16(hGlobal16);
1289 return hGlobal16;
1290}
1291#endif
1292
1293/************************************************************
1294 *
1295 * PRINTDLG_GetDlgTemplate
1296 *
1297 */
1298static HGLOBAL PRINTDLG_GetDlgTemplate(PRINTDLGA *lppd)
1299{
1300 HGLOBAL hDlgTmpl, hResInfo;
1301
1302 if (lppd->Flags & PD_PRINTSETUP) {
1303 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
1304 hDlgTmpl = lppd->hSetupTemplate;
1305 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
1306 hResInfo = FindResourceA(lppd->hInstance,
1307 lppd->lpSetupTemplateName, RT_DIALOGA);
1308 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1309 } else {
1310 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32_SETUP",
1311 RT_DIALOGA);
1312 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1313 }
1314 } else {
1315 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
1316 hDlgTmpl = lppd->hPrintTemplate;
1317 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
1318 hResInfo = FindResourceA(lppd->hInstance,
1319 lppd->lpPrintTemplateName,
1320 RT_DIALOGA);
1321 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1322 } else {
1323 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32",
1324 RT_DIALOGA);
1325 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1326 }
1327 }
1328 return hDlgTmpl;
1329}
1330
1331
1332#ifndef __WIN32OS2__
1333/************************************************************
1334 *
1335 * PRINTDLG_GetDlgTemplate
1336 *
1337 */
1338static HGLOBAL16 PRINTDLG_GetDlgTemplate16(PRINTDLG16 *lppd)
1339{
1340 HGLOBAL16 hDlgTmpl, hResInfo;
1341
1342 if (lppd->Flags & PD_PRINTSETUP) {
1343 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
1344 hDlgTmpl = lppd->hSetupTemplate;
1345 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
1346 hResInfo = FindResource16(lppd->hInstance,
1347 MapSL(lppd->lpSetupTemplateName), RT_DIALOGA);
1348 hDlgTmpl = LoadResource16(lppd->hInstance, hResInfo);
1349 } else {
1350 hDlgTmpl = PRINTDLG_Get16TemplateFrom32("PRINT32_SETUP");
1351 }
1352 } else {
1353 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
1354 hDlgTmpl = lppd->hPrintTemplate;
1355 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
1356 hResInfo = FindResource16(lppd->hInstance,
1357 MapSL(lppd->lpPrintTemplateName),
1358 RT_DIALOGA);
1359 hDlgTmpl = LoadResource16(lppd->hInstance, hResInfo);
1360 } else {
1361 hDlgTmpl = PRINTDLG_Get16TemplateFrom32("PRINT32");
1362 }
1363 }
1364 return hDlgTmpl;
1365}
1366#endif
1367
1368/***********************************************************************
1369 *
1370 * PRINTDLG_CreateDC
1371 *
1372 */
1373static BOOL PRINTDLG_CreateDC(LPPRINTDLGA lppd)
1374{
1375 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
1376 DEVMODEA *pdm = GlobalLock(lppd->hDevMode);
1377
1378 if(lppd->Flags & PD_RETURNDC) {
1379 lppd->hDC = CreateDCA((char*)pdn + pdn->wDriverOffset,
1380 (char*)pdn + pdn->wDeviceOffset,
1381 (char*)pdn + pdn->wOutputOffset,
1382 pdm );
1383 } else if(lppd->Flags & PD_RETURNIC) {
1384 lppd->hDC = CreateICA((char*)pdn + pdn->wDriverOffset,
1385 (char*)pdn + pdn->wDeviceOffset,
1386 (char*)pdn + pdn->wOutputOffset,
1387 pdm );
1388 }
1389 GlobalUnlock(lppd->hDevNames);
1390 GlobalUnlock(lppd->hDevMode);
1391 return lppd->hDC ? TRUE : FALSE;
1392}
1393
1394#ifndef __WIN32OS2__
1395static BOOL PRINTDLG_CreateDC16(LPPRINTDLG16 lppd)
1396{
1397 DEVNAMES *pdn = GlobalLock16(lppd->hDevNames);
1398 DEVMODEA *pdm = GlobalLock16(lppd->hDevMode);
1399
1400 if(lppd->Flags & PD_RETURNDC) {
1401 lppd->hDC = CreateDCA((char*)pdn + pdn->wDriverOffset,
1402 (char*)pdn + pdn->wDeviceOffset,
1403 (char*)pdn + pdn->wOutputOffset,
1404 pdm );
1405 } else if(lppd->Flags & PD_RETURNIC) {
1406 lppd->hDC = CreateICA((char*)pdn + pdn->wDriverOffset,
1407 (char*)pdn + pdn->wDeviceOffset,
1408 (char*)pdn + pdn->wOutputOffset,
1409 pdm );
1410 }
1411 GlobalUnlock16(lppd->hDevNames);
1412 GlobalUnlock16(lppd->hDevMode);
1413 return lppd->hDC ? TRUE : FALSE;
1414}
1415#endif
1416
1417/***********************************************************************
1418 * PrintDlgA (COMDLG32.@)
1419 *
1420 * Displays the the PRINT dialog box, which enables the user to specify
1421 * specific properties of the print job.
1422 *
1423 * RETURNS
1424 * nonzero if the user pressed the OK button
1425 * zero if the user cancelled the window or an error occurred
1426 *
1427 * BUGS
1428 * PrintDlg:
1429 * * The Collate Icons do not display, even though they are in the code.
1430 * * The Properties Button(s) should call DocumentPropertiesA().
1431 * PrintSetupDlg:
1432 * * The Paper Orientation Icons are not implemented yet.
1433 * * The Properties Button(s) should call DocumentPropertiesA().
1434 * * Settings are not yet taken from a provided DevMode or
1435 * default printer settings.
1436 */
1437BOOL WINAPI PrintDlgA(
1438 LPPRINTDLGA lppd /* [in/out] ptr to PRINTDLG32 struct */
1439 )
1440{
1441 BOOL bRet = FALSE;
1442 LPVOID ptr;
1443 HINSTANCE hInst = GetWindowLongA( lppd->hwndOwner, GWL_HINSTANCE );
1444
1445#ifdef __WIN32OS2__
1446 dprintf(("PrintDlgA %x", lppd));
1447#endif
1448
1449 if(TRACE_ON(commdlg)) {
1450 char flagstr[1000] = "";
1451 struct pd_flags *pflag = pd_flags;
1452 for( ; pflag->name; pflag++) {
1453 if(lppd->Flags & pflag->flag)
1454 strcat(flagstr, pflag->name);
1455 }
1456 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
1457 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %08x\n"
1458 "flags %08lx (%s)\n",
1459 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
1460 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
1461 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
1462 }
1463
1464 if(lppd->lStructSize != sizeof(PRINTDLGA)) {
1465 WARN("structure size failure !!!\n");
1466 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
1467 return FALSE;
1468 }
1469
1470 if(lppd->Flags & PD_RETURNDEFAULT) {
1471 PRINTER_INFO_2A *pbuf;
1472 DRIVER_INFO_3A *dbuf;
1473 HANDLE hprn;
1474 DWORD needed;
1475
1476 if(lppd->hDevMode || lppd->hDevNames) {
1477 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
1478 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
1479 return FALSE;
1480 }
1481 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
1482 WARN("Can't find default printer\n");
1483 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
1484 return FALSE;
1485 }
1486
1487 GetPrinterA(hprn, 2, NULL, 0, &needed);
1488 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
1489 GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
1490
1491 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
1492 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
1493 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
1494 ERR("GetPrinterDriverA failed, le %ld, fix your config for printer %s!\n",GetLastError(),pbuf->pPrinterName);
1495 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
1496 return FALSE;
1497 }
1498 ClosePrinter(hprn);
1499
1500 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
1501 dbuf->pDriverPath,
1502 pbuf->pPrinterName,
1503 pbuf->pPortName);
1504 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
1505 pbuf->pDevMode->dmDriverExtra);
1506 ptr = GlobalLock(lppd->hDevMode);
1507 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
1508 pbuf->pDevMode->dmDriverExtra);
1509 GlobalUnlock(lppd->hDevMode);
1510 HeapFree(GetProcessHeap(), 0, pbuf);
1511 HeapFree(GetProcessHeap(), 0, dbuf);
1512 bRet = TRUE;
1513 } else {
1514 HGLOBAL hDlgTmpl;
1515 PRINT_PTRA *PrintStructures;
1516
1517 /* load Dialog resources,
1518 * depending on Flags indicates Print32 or Print32_setup dialog
1519 */
1520 hDlgTmpl = PRINTDLG_GetDlgTemplate(lppd);
1521 if (!hDlgTmpl) {
1522 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1523 return FALSE;
1524 }
1525 ptr = LockResource( hDlgTmpl );
1526 if (!ptr) {
1527 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1528 return FALSE;
1529 }
1530
1531 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
1532 sizeof(PRINT_PTRA));
1533 PrintStructures->dlg.lpPrintDlg = lppd;
1534
1535 /* and create & process the dialog .
1536 * -1 is failure, 0 is broken hwnd, everything else is ok.
1537 */
1538 bRet = (0<DialogBoxIndirectParamA(hInst, ptr, lppd->hwndOwner,
1539 PrintDlgProcA,
1540 (LPARAM)PrintStructures));
1541
1542 if(bRet) {
1543 DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
1544 PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
1545 DRIVER_INFO_3A *di = PrintStructures->lpDriverInfo;
1546
1547 if (lppd->hDevMode == 0) {
1548 TRACE(" No hDevMode yet... Need to create my own\n");
1549 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
1550 lpdm->dmSize + lpdm->dmDriverExtra);
1551 } else {
1552 WORD locks;
1553 if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
1554 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
1555 while(locks--) {
1556 GlobalUnlock(lppd->hDevMode);
1557 TRACE("Now got %d locks\n", locks);
1558 }
1559 }
1560 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
1561 lpdm->dmSize + lpdm->dmDriverExtra,
1562 GMEM_MOVEABLE);
1563 }
1564 lpdmReturn = GlobalLock(lppd->hDevMode);
1565 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
1566
1567 if (lppd->hDevNames != 0) {
1568 WORD locks;
1569 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
1570 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
1571 while(locks--)
1572 GlobalUnlock(lppd->hDevNames);
1573 }
1574 }
1575 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
1576 di->pDriverPath,
1577 pi->pPrinterName,
1578 pi->pPortName
1579 );
1580 GlobalUnlock(lppd->hDevMode);
1581 }
1582 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
1583 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
1584 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
1585 HeapFree(GetProcessHeap(), 0, PrintStructures);
1586 }
1587 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
1588 bRet = PRINTDLG_CreateDC(lppd);
1589
1590 TRACE("exit! (%d)\n", bRet);
1591 return bRet;
1592}
1593
1594#ifndef __WIN32OS2__
1595/***********************************************************************
1596 * PrintDlg (COMMDLG.20)
1597 *
1598 * Displays the the PRINT dialog box, which enables the user to specify
1599 * specific properties of the print job.
1600 *
1601 * RETURNS
1602 * nonzero if the user pressed the OK button
1603 * zero if the user cancelled the window or an error occurred
1604 *
1605 * BUGS
1606 * * calls up to the 32-bit versions of the Dialogs, which look different
1607 * * Customizing is *not* implemented.
1608 */
1609
1610BOOL16 WINAPI PrintDlg16(
1611 LPPRINTDLG16 lppd /* [in/out] ptr to PRINTDLG struct */
1612) {
1613 BOOL bRet = FALSE;
1614 LPVOID ptr;
1615 HINSTANCE hInst = GetWindowLongA( lppd->hwndOwner, GWL_HINSTANCE );
1616
1617 if(TRACE_ON(commdlg)) {
1618 char flagstr[1000] = "";
1619 struct pd_flags *pflag = pd_flags;
1620 for( ; pflag->name; pflag++) {
1621 if(lppd->Flags & pflag->flag)
1622 strcat(flagstr, pflag->name);
1623 }
1624 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
1625 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %08x\n"
1626 "flags %08lx (%s)\n",
1627 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
1628 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
1629 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
1630 }
1631
1632 if(lppd->lStructSize != sizeof(PRINTDLG16)) {
1633 ERR("structure size (%ld/%d)\n",lppd->lStructSize,sizeof(PRINTDLG16));
1634 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
1635 return FALSE;
1636 }
1637
1638 if(lppd->Flags & PD_RETURNDEFAULT) {
1639 PRINTER_INFO_2A *pbuf;
1640 DRIVER_INFO_3A *dbuf;
1641 HANDLE hprn;
1642 DWORD needed;
1643
1644 if(lppd->hDevMode || lppd->hDevNames) {
1645 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
1646 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
1647 return FALSE;
1648 }
1649 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
1650 WARN("Can't find default printer\n");
1651 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
1652 return FALSE;
1653 }
1654
1655 GetPrinterA(hprn, 2, NULL, 0, &needed);
1656 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
1657 GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
1658 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
1659 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
1660 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
1661 ERR("GetPrinterDriverA failed for %s, le %ld, fix your config!\n",
1662 pbuf->pPrinterName,GetLastError());
1663 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
1664 return FALSE;
1665 }
1666 ClosePrinter(hprn);
1667 PRINTDLG_CreateDevNames16(&(lppd->hDevNames),
1668 dbuf->pDriverPath,
1669 pbuf->pPrinterName,
1670 pbuf->pPortName);
1671 lppd->hDevMode = GlobalAlloc16(GMEM_MOVEABLE,pbuf->pDevMode->dmSize+
1672 pbuf->pDevMode->dmDriverExtra);
1673 ptr = GlobalLock16(lppd->hDevMode);
1674 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
1675 pbuf->pDevMode->dmDriverExtra);
1676 GlobalUnlock16(lppd->hDevMode);
1677 HeapFree(GetProcessHeap(), 0, pbuf);
1678 HeapFree(GetProcessHeap(), 0, dbuf);
1679 bRet = TRUE;
1680 } else {
1681 HGLOBAL hDlgTmpl;
1682 PRINT_PTRA *PrintStructures;
1683
1684 /* load Dialog resources,
1685 * depending on Flags indicates Print32 or Print32_setup dialog
1686 */
1687 hDlgTmpl = PRINTDLG_GetDlgTemplate16(lppd);
1688 if (!hDlgTmpl) {
1689 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1690 return FALSE;
1691 }
1692 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
1693 sizeof(PRINT_PTRA));
1694 PrintStructures->dlg.lpPrintDlg16 = lppd;
1695 PrintStructures->dlg.lpPrintDlg = (LPPRINTDLGA)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(PRINTDLGA));
1696#define CVAL(x) PrintStructures->dlg.lpPrintDlg->x = lppd->x;
1697#define MVAL(x) PrintStructures->dlg.lpPrintDlg->x = MapSL(lppd->x);
1698 CVAL(Flags);CVAL(hwndOwner);CVAL(hDC);
1699 CVAL(nFromPage);CVAL(nToPage);CVAL(nMinPage);CVAL(nMaxPage);
1700 CVAL(nCopies);CVAL(hInstance);CVAL(lCustData);
1701 MVAL(lpPrintTemplateName);MVAL(lpSetupTemplateName);
1702 /* Don't copy rest, it is 16 bit specific */
1703#undef MVAL
1704#undef CVAL
1705
1706 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(),0,sizeof(DEVMODEA));
1707
1708 /* and create & process the dialog .
1709 * -1 is failure, 0 is broken hwnd, everything else is ok.
1710 */
1711 bRet = (0<DialogBoxIndirectParam16(
1712 hInst, hDlgTmpl, lppd->hwndOwner,
1713 (DLGPROC16)GetProcAddress16(GetModuleHandle16("COMMDLG"),(LPCSTR)21),
1714 (LPARAM)PrintStructures
1715 )
1716 );
1717 if (!PrintStructures->lpPrinterInfo) bRet = FALSE;
1718 if(bRet) {
1719 DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
1720 PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
1721 DRIVER_INFO_3A *di = PrintStructures->lpDriverInfo;
1722
1723 if (lppd->hDevMode == 0) {
1724 TRACE(" No hDevMode yet... Need to create my own\n");
1725 lppd->hDevMode = GlobalAlloc16(GMEM_MOVEABLE,
1726 lpdm->dmSize + lpdm->dmDriverExtra);
1727 } else {
1728 WORD locks;
1729 if((locks = (GlobalFlags16(lppd->hDevMode)&GMEM_LOCKCOUNT))) {
1730 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
1731 while(locks--) {
1732 GlobalUnlock16(lppd->hDevMode);
1733 TRACE("Now got %d locks\n", locks);
1734 }
1735 }
1736 lppd->hDevMode = GlobalReAlloc16(lppd->hDevMode,
1737 lpdm->dmSize + lpdm->dmDriverExtra,
1738 GMEM_MOVEABLE);
1739 }
1740 lpdmReturn = GlobalLock16(lppd->hDevMode);
1741 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
1742
1743 if (lppd->hDevNames != 0) {
1744 WORD locks;
1745 if((locks = (GlobalFlags16(lppd->hDevNames)&GMEM_LOCKCOUNT))) {
1746 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
1747 while(locks--)
1748 GlobalUnlock16(lppd->hDevNames);
1749 }
1750 }
1751 PRINTDLG_CreateDevNames16(&(lppd->hDevNames),
1752 di->pDriverPath,
1753 pi->pPrinterName,
1754 pi->pPortName
1755 );
1756 GlobalUnlock16(lppd->hDevMode);
1757 }
1758 if (!(lppd->Flags & (PD_ENABLESETUPTEMPLATEHANDLE | PD_ENABLESETUPTEMPLATE)))
1759 GlobalFree16(hDlgTmpl); /* created from the 32 bits resource */
1760 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
1761 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
1762 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
1763 HeapFree(GetProcessHeap(), 0, PrintStructures);
1764 }
1765 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
1766 bRet = PRINTDLG_CreateDC16(lppd);
1767
1768 TRACE("exit! (%d)\n", bRet);
1769 return bRet;
1770}
1771#endif
1772
1773
1774/***********************************************************************
1775 * PrintDlgW (COMDLG32.@)
1776 */
1777BOOL WINAPI PrintDlgW( LPPRINTDLGW printdlg )
1778{
1779#ifdef __WIN32OS2__
1780 dprintf(("PrintDlgW %x NOT IMPLEMENTED", printdlg));
1781#endif
1782 FIXME("A really empty stub\n" );
1783 return FALSE;
1784}
1785
1786/***********************************************************************
1787 *
1788 * PageSetupDlg
1789 * rad1 - portrait
1790 * rad2 - landscape
1791 * cmb2 - paper size
1792 * cmb3 - source (tray?)
1793 * edt4 - border left
1794 * edt5 - border top
1795 * edt6 - border right
1796 * edt7 - border bottom
1797 * psh3 - "Printer..."
1798 */
1799
1800typedef struct {
1801 LPPAGESETUPDLGA dlga;
1802
1803 PRINTDLGA pdlg;
1804} PageSetupData;
1805
1806static HGLOBAL PRINTDLG_GetPGSTemplate(PAGESETUPDLGA *lppd)
1807{
1808 HGLOBAL hDlgTmpl, hResInfo;
1809
1810 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
1811 hDlgTmpl = lppd->hPageSetupTemplate;
1812 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
1813 hResInfo = FindResourceA(lppd->hInstance,
1814 lppd->lpPageSetupTemplateName, RT_DIALOGA);
1815 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1816 } else {
1817 hResInfo = FindResourceA(COMDLG32_hInstance,(LPCSTR)PAGESETUPDLGORD,RT_DIALOGA);
1818 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
1819 }
1820 return hDlgTmpl;
1821}
1822
1823static DWORD
1824_c_10mm2size(PAGESETUPDLGA *dlga,DWORD size) {
1825 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
1826 return 10*size*10/25.4;
1827 /* If we don't have a flag, we can choose one. Use millimeters
1828 * to avoid confusing me
1829 */
1830 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
1831 FIXME("returning %ld/100 mm \n",size);
1832 return 10*size;
1833}
1834
1835
1836static DWORD
1837_c_inch2size(PAGESETUPDLGA *dlga,DWORD size) {
1838 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
1839 return size;
1840 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
1841 return (size*254)/10;
1842 /* if we don't have a flag, we can choose one. Use millimeters
1843 * to avoid confusing me
1844 */
1845 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
1846 return (size*254)/10;
1847}
1848
1849static void
1850_c_size2str(PageSetupData *pda,DWORD size,LPSTR strout) {
1851 strcpy(strout,"<undef>");
1852 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
1853 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
1854 return;
1855 }
1856 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
1857 sprintf(strout,"%.2fin",(size*1.0)/1000.0);
1858 return;
1859 }
1860 pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
1861 sprintf(strout,"%.2fmm",(size*1.0)/100.0);
1862 return;
1863}
1864
1865static DWORD
1866_c_str2size(PageSetupData *pda,LPCSTR strin) {
1867 float val;
1868 char rest[200];
1869
1870 rest[0]='\0';
1871 if (!sscanf(strin,"%f%s",&val,rest))
1872 return 0;
1873
1874 if (!strcmp(rest,"in") || !strcmp(rest,"inch")) {
1875 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
1876 return 1000*val;
1877 else
1878 return val*25.4*100;
1879 }
1880 if (!strcmp(rest,"cm")) { rest[0]='m'; val = val*10.0; }
1881 if (!strcmp(rest,"m")) { strcpy(rest,"mm"); val = val*1000.0; }
1882
1883 if (!strcmp(rest,"mm")) {
1884 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
1885 return 100*val;
1886 else
1887 return 1000.0*val/25.4;
1888 }
1889 if (rest[0]=='\0') {
1890 /* use application supplied default */
1891 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
1892 /* 100*mm */
1893 return 100.0*val;
1894 }
1895 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
1896 /* 1000*inch */
1897 return 1000.0*val;
1898 }
1899 }
1900 ERR("Did not find a conversion for type '%s'!\n",rest);
1901 return 0;
1902}
1903
1904
1905/*
1906 * This is called on finish and will update the output fields of the
1907 * struct.
1908 */
1909static BOOL
1910PRINTDLG_PS_UpdateDlgStruct(HWND hDlg, PageSetupData *pda) {
1911 DEVNAMES *dn;
1912 DEVMODEA *dm;
1913 LPSTR devname,portname;
1914 char papername[64];
1915 char buf[200];
1916
1917 dn = GlobalLock(pda->pdlg.hDevNames);
1918 dm = GlobalLock(pda->pdlg.hDevMode);
1919 devname = ((char*)dn)+dn->wDeviceOffset;
1920 portname = ((char*)dn)+dn->wOutputOffset;
1921 PRINTDLG_SetUpPaperComboBox(hDlg,cmb2,devname,portname,dm);
1922 PRINTDLG_SetUpPaperComboBox(hDlg,cmb3,devname,portname,dm);
1923
1924 if (GetDlgItemTextA(hDlg,cmb2,papername,sizeof(papername))>0) {
1925 PRINTDLG_PaperSize(&(pda->pdlg),papername,&(pda->dlga->ptPaperSize));
1926 pda->dlga->ptPaperSize.x = _c_10mm2size(pda->dlga,pda->dlga->ptPaperSize.x);
1927 pda->dlga->ptPaperSize.y = _c_10mm2size(pda->dlga,pda->dlga->ptPaperSize.y);
1928 } else
1929 FIXME("could not get dialog text for papersize cmbbox?\n");
1930#define GETVAL(id,val) if (GetDlgItemTextA(hDlg,id,buf,sizeof(buf))>0) { val = _c_str2size(pda,buf); } else { FIXME("could not get dlgitemtexta for %x\n",id); }
1931 GETVAL(edt4,pda->dlga->rtMargin.left);
1932 GETVAL(edt5,pda->dlga->rtMargin.top);
1933 GETVAL(edt6,pda->dlga->rtMargin.right);
1934 GETVAL(edt7,pda->dlga->rtMargin.bottom);
1935#undef GETVAL
1936
1937 /* If we are in landscape, swap x and y of page size */
1938 if (IsDlgButtonChecked(hDlg, rad2)) {
1939 DWORD tmp;
1940 tmp = pda->dlga->ptPaperSize.x;
1941 pda->dlga->ptPaperSize.x = pda->dlga->ptPaperSize.y;
1942 pda->dlga->ptPaperSize.y = tmp;
1943 }
1944 GlobalUnlock(pda->pdlg.hDevNames);
1945 GlobalUnlock(pda->pdlg.hDevMode);
1946 return TRUE;
1947}
1948
1949/*
1950 * This is called after returning from PrintDlg().
1951 */
1952static BOOL
1953PRINTDLG_PS_ChangePrinter(HWND hDlg, PageSetupData *pda) {
1954 DEVNAMES *dn;
1955 DEVMODEA *dm;
1956 LPSTR devname,portname;
1957
1958 dn = GlobalLock(pda->pdlg.hDevNames);
1959 dm = GlobalLock(pda->pdlg.hDevMode);
1960 devname = ((char*)dn)+dn->wDeviceOffset;
1961 portname = ((char*)dn)+dn->wOutputOffset;
1962 PRINTDLG_SetUpPaperComboBox(hDlg,cmb2,devname,portname,dm);
1963 PRINTDLG_SetUpPaperComboBox(hDlg,cmb3,devname,portname,dm);
1964 GlobalUnlock(pda->pdlg.hDevNames);
1965 GlobalUnlock(pda->pdlg.hDevMode);
1966 return TRUE;
1967}
1968
1969static BOOL
1970PRINTDLG_PS_WMCommand(
1971 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupData *pda
1972) {
1973 switch (LOWORD(wParam)) {
1974 case IDOK:
1975 if (!PRINTDLG_PS_UpdateDlgStruct(hDlg, pda))
1976 return(FALSE);
1977 EndDialog(hDlg, TRUE);
1978 return TRUE ;
1979
1980 case IDCANCEL:
1981 EndDialog(hDlg, FALSE);
1982 return FALSE ;
1983
1984 case psh3: {
1985 pda->pdlg.Flags = 0;
1986 pda->pdlg.hwndOwner = hDlg;
1987 if (PrintDlgA(&(pda->pdlg)))
1988 PRINTDLG_PS_ChangePrinter(hDlg,pda);
1989 return TRUE;
1990 }
1991 }
1992 FIXME("loword (lparam) %d, wparam 0x%x, lparam %08lx, STUB mostly.\n",
1993 LOWORD(lParam),wParam,lParam
1994 );
1995 return FALSE;
1996}
1997
1998
1999static BOOL WINAPI
2000PageDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
2001{
2002 PageSetupData *pda;
2003 BOOL res = FALSE;
2004
2005 if (uMsg==WM_INITDIALOG) {
2006 res = TRUE;
2007 pda = (PageSetupData*)lParam;
2008 SetPropA(hDlg,"__WINE_PAGESETUPDLGDATA",lParam);
2009 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
2010 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
2011 if (!res) {
2012 FIXME("Setup page hook failed?\n");
2013 res = TRUE;
2014 }
2015 }
2016 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK) {
2017 FIXME("PagePaintHook not yet implemented!\n");
2018 }
2019 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
2020 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
2021 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
2022 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
2023 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
2024 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
2025 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
2026 }
2027 /* width larger as height -> landscape */
2028 if (pda->dlga->ptPaperSize.x > pda->dlga->ptPaperSize.y)
2029 CheckRadioButton(hDlg, rad1, rad2, rad2);
2030 else /* this is default if papersize is not set */
2031 CheckRadioButton(hDlg, rad1, rad2, rad1);
2032 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
2033 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
2034 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
2035 }
2036 /* We fill them out enabled or not */
2037 if (pda->dlga->Flags & PSD_MARGINS) {
2038 char str[100];
2039 _c_size2str(pda,pda->dlga->rtMargin.left,str);
2040 SetDlgItemTextA(hDlg,edt4,str);
2041 _c_size2str(pda,pda->dlga->rtMargin.top,str);
2042 SetDlgItemTextA(hDlg,edt5,str);
2043 _c_size2str(pda,pda->dlga->rtMargin.right,str);
2044 SetDlgItemTextA(hDlg,edt6,str);
2045 _c_size2str(pda,pda->dlga->rtMargin.bottom,str);
2046 SetDlgItemTextA(hDlg,edt7,str);
2047 } else {
2048 /* default is 1 inch */
2049 DWORD size = _c_inch2size(pda->dlga,1000);
2050 char str[20];
2051 _c_size2str(pda,size,str);
2052 SetDlgItemTextA(hDlg,edt4,str);
2053 SetDlgItemTextA(hDlg,edt5,str);
2054 SetDlgItemTextA(hDlg,edt6,str);
2055 SetDlgItemTextA(hDlg,edt7,str);
2056 }
2057 PRINTDLG_PS_ChangePrinter(hDlg,pda);
2058 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
2059 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
2060 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
2061 }
2062 return TRUE;
2063 } else {
2064 pda = (PageSetupData*)GetPropA(hDlg,"__WINE_PAGESETUPDLGDATA");
2065 if (!pda) {
2066 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
2067 return FALSE;
2068 }
2069 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
2070 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
2071 if (res) return res;
2072 }
2073 }
2074 switch (uMsg) {
2075 case WM_COMMAND:
2076 return PRINTDLG_PS_WMCommand(hDlg, wParam, lParam, pda);
2077 }
2078 return FALSE;
2079}
2080
2081/***********************************************************************
2082 * PageSetupDlgA (COMDLG32.@)
2083 */
2084BOOL WINAPI PageSetupDlgA(LPPAGESETUPDLGA setupdlg) {
2085 HGLOBAL hDlgTmpl;
2086 LPVOID ptr;
2087 BOOL bRet;
2088 PageSetupData *pda;
2089 PRINTDLGA pdlg;
2090
2091#ifdef __WIN32OS2__
2092 dprintf(("PageSetupDlgA %x", setupdlg));
2093#endif
2094
2095 if(TRACE_ON(commdlg)) {
2096 char flagstr[1000] = "";
2097 struct pd_flags *pflag = psd_flags;
2098 for( ; pflag->name; pflag++) {
2099 if(setupdlg->Flags & pflag->flag) {
2100 strcat(flagstr, pflag->name);
2101 strcat(flagstr, "|");
2102 }
2103 }
2104 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
2105 "hinst %08x, flags %08lx (%s)\n",
2106 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
2107 setupdlg->hDevNames,
2108 setupdlg->hInstance, setupdlg->Flags, flagstr);
2109 }
2110
2111 /* First get default printer data, we need it right after that. */
2112 memset(&pdlg,0,sizeof(pdlg));
2113 pdlg.lStructSize = sizeof(pdlg);
2114 pdlg.Flags = PD_RETURNDEFAULT;
2115 bRet = PrintDlgA(&pdlg);
2116 if (!bRet) return FALSE;
2117
2118 /* short cut exit, just return default values */
2119 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
2120 setupdlg->hDevMode = pdlg.hDevMode;
2121 setupdlg->hDevNames = pdlg.hDevNames;
2122 /* FIXME: Just return "A4" for now. */
2123 PRINTDLG_PaperSize(&pdlg,"A4",&setupdlg->ptPaperSize);
2124 setupdlg->ptPaperSize.x=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.x);
2125 setupdlg->ptPaperSize.y=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.y);
2126 return TRUE;
2127 }
2128 hDlgTmpl = PRINTDLG_GetPGSTemplate(setupdlg);
2129 if (!hDlgTmpl) {
2130 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2131 return FALSE;
2132 }
2133 ptr = LockResource( hDlgTmpl );
2134 if (!ptr) {
2135 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2136 return FALSE;
2137 }
2138 pda = HeapAlloc(GetProcessHeap(),0,sizeof(*pda));
2139 pda->dlga = setupdlg;
2140 memcpy(&pda->pdlg,&pdlg,sizeof(pdlg));
2141
2142 bRet = (0<DialogBoxIndirectParamA(
2143 setupdlg->hInstance,
2144 ptr,
2145 setupdlg->hwndOwner,
2146 PageDlgProcA,
2147 (LPARAM)pda)
2148 );
2149 return bRet;
2150}
2151/***********************************************************************
2152 * PageSetupDlgW (COMDLG32.@)
2153 */
2154BOOL WINAPI PageSetupDlgW(LPPAGESETUPDLGW setupdlg) {
2155#ifdef __WIN32OS2__
2156 dprintf(("PageSetupDlgA %x NOT IMPLEMENTED", setupdlg));
2157#endif
2158 FIXME("(%p), stub!\n",setupdlg);
2159 return FALSE;
2160}
2161
2162#ifndef __WIN32OS2__
2163/**********************************************************************
2164 *
2165 * 16 bit commdlg
2166 */
2167
2168/***********************************************************************
2169 * PrintDlgProc (COMMDLG.21)
2170 */
2171LRESULT WINAPI PrintDlgProc16(HWND16 hDlg, UINT16 uMsg, WPARAM16 wParam,
2172 LPARAM lParam)
2173{
2174 PRINT_PTRA* PrintStructures;
2175 LRESULT res=FALSE;
2176
2177 if (uMsg!=WM_INITDIALOG) {
2178 PrintStructures = (PRINT_PTRA*) GetWindowLongA(hDlg, DWL_USER);
2179 if (!PrintStructures)
2180 return FALSE;
2181 } else {
2182 PrintStructures = (PRINT_PTRA*) lParam;
2183 SetWindowLongA(hDlg, DWL_USER, lParam);
2184 res = PRINTDLG_WMInitDialog16(hDlg, wParam, PrintStructures);
2185
2186 if(PrintStructures->dlg.lpPrintDlg16->Flags & PD_ENABLEPRINTHOOK) {
2187 res = CallWindowProc16(
2188 (WNDPROC16)PrintStructures->dlg.lpPrintDlg16->lpfnPrintHook,
2189 hDlg, uMsg, wParam, (LPARAM)PrintStructures->dlg.lpPrintDlg16
2190 );
2191 }
2192 return res;
2193 }
2194
2195 if(PrintStructures->dlg.lpPrintDlg16->Flags & PD_ENABLEPRINTHOOK) {
2196 res = CallWindowProc16(
2197 (WNDPROC16)PrintStructures->dlg.lpPrintDlg16->lpfnPrintHook,
2198 hDlg,uMsg, wParam, lParam
2199 );
2200 if(LOWORD(res)) return res;
2201 }
2202
2203 switch (uMsg) {
2204 case WM_COMMAND: {
2205 /* We need to map those for the 32bit window procedure, compare
2206 * with 32Ato16 mapper in winproc.c
2207 */
2208 return PRINTDLG_WMCommand(
2209 hDlg,
2210 MAKEWPARAM(wParam,HIWORD(lParam)),
2211 LOWORD(lParam),
2212 PrintStructures
2213 );
2214 }
2215 case WM_DESTROY:
2216 DestroyIcon(PrintStructures->hCollateIcon);
2217 DestroyIcon(PrintStructures->hNoCollateIcon);
2218 /* FIXME: don't forget to delete the paper orientation icons here! */
2219
2220 return FALSE;
2221 }
2222 return res;
2223}
2224
2225
2226/***********************************************************************
2227 * PrintSetupDlgProc (COMMDLG.22)
2228 */
2229LRESULT WINAPI PrintSetupDlgProc16(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
2230 LPARAM lParam)
2231{
2232 switch (wMsg)
2233 {
2234 case WM_INITDIALOG:
2235 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
2236 ShowWindow(hWnd, SW_SHOWNORMAL);
2237 return (TRUE);
2238 case WM_COMMAND:
2239 switch (wParam) {
2240 case IDOK:
2241 EndDialog(hWnd, TRUE);
2242 return(TRUE);
2243 case IDCANCEL:
2244 EndDialog(hWnd, FALSE);
2245 return(TRUE);
2246 }
2247 return(FALSE);
2248 }
2249 return FALSE;
2250}
2251#endif
2252
2253/***********************************************************************
2254 * PrintDlgExA (COMDLG32.@)
2255 */
2256HRESULT WINAPI PrintDlgExA(LPVOID lpPrintDlgExA) /* [???] FIXME: LPPRINTDLGEXA */
2257{
2258 FIXME("stub\n");
2259 return E_NOTIMPL;
2260}
2261/***********************************************************************
2262 * PrintDlgExW (COMDLG32.@)
2263 */
2264HRESULT WINAPI PrintDlgExW(LPVOID lpPrintDlgExW) /* [???] FIXME: LPPRINTDLGEXW */
2265{
2266 FIXME("stub\n");
2267 return E_NOTIMPL;
2268}
Note: See TracBrowser for help on using the repository browser.