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

Last change on this file since 6502 was 6335, checked in by sandervl, 24 years ago

added (inactive) Wine printer dialog code

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