wgl: Replace glReadPixels in wglBindTexImage2D by the MUCH faster glCopyTexImage2D.
[wine] / dlls / comdlg32 / printdlg16.c
1 /*
2  * COMMDLG - Print Dialog
3  *
4  * Copyright 1994 Martin Ayotte
5  * Copyright 1996 Albrecht Kleine
6  * Copyright 1999 Klaas van Gend
7  * Copyright 2000 Huw D M Davies
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23
24 #include <ctype.h>
25 #include <stdlib.h>
26 #include <stdarg.h>
27 #include <stdio.h>
28 #include <string.h>
29
30 #define NONAMELESSUNION
31 #define NONAMELESSSTRUCT
32 #include "windef.h"
33 #include "winbase.h"
34 #include "wingdi.h"
35 #include "wine/wingdi16.h"
36 #include "winuser.h"
37 #include "wine/winuser16.h"
38 #include "commdlg.h"
39 #include "dlgs.h"
40 #include "wine/debug.h"
41 #include "cderr.h"
42 #include "winspool.h"
43
44 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
45
46 #include "cdlg.h"
47 #include "cdlg16.h"
48 #include "printdlg.h"
49
50 typedef struct
51 {
52     PRINT_PTRA   print32;
53     LPPRINTDLG16 lpPrintDlg16;
54 } PRINT_PTRA16;
55
56 /* Internal Functions */
57
58 static BOOL PRINTDLG_CreateDevNames16(HGLOBAL16 *hmem, const char* DeviceDriverName,
59                                       const char* DeviceName, const char* OutputPort)
60 {
61     long size;
62     char*   pDevNamesSpace;
63     char*   pTempPtr;
64     LPDEVNAMES lpDevNames;
65     char buf[260];
66     DWORD dwBufLen = sizeof(buf);
67
68     size = strlen(DeviceDriverName) + 1
69             + strlen(DeviceName) + 1
70             + strlen(OutputPort) + 1
71             + sizeof(DEVNAMES);
72
73     if(*hmem)
74         *hmem = GlobalReAlloc16(*hmem, size, GMEM_MOVEABLE);
75     else
76         *hmem = GlobalAlloc16(GMEM_MOVEABLE, size);
77     if (*hmem == 0)
78         return FALSE;
79
80     pDevNamesSpace = GlobalLock16(*hmem);
81     lpDevNames = (LPDEVNAMES) pDevNamesSpace;
82
83     pTempPtr = pDevNamesSpace + sizeof(DEVNAMES);
84     strcpy(pTempPtr, DeviceDriverName);
85     lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
86
87     pTempPtr += strlen(DeviceDriverName) + 1;
88     strcpy(pTempPtr, DeviceName);
89     lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
90
91     pTempPtr += strlen(DeviceName) + 1;
92     strcpy(pTempPtr, OutputPort);
93     lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
94
95     GetDefaultPrinterA(buf, &dwBufLen);
96     lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
97     GlobalUnlock16(*hmem);
98     return TRUE;
99 }
100
101
102 /***********************************************************************
103  *           PRINTDLG_WMInitDialog                      [internal]
104  */
105 static LRESULT PRINTDLG_WMInitDialog16(HWND hDlg, WPARAM wParam, PRINT_PTRA16* ptr16)
106 {
107     PRINT_PTRA *PrintStructures = &ptr16->print32;
108     LPPRINTDLG16 lppd = ptr16->lpPrintDlg16;
109     DEVNAMES *pdn;
110     DEVMODEA *pdm;
111     char *name = NULL;
112     UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
113
114     /* load Collate ICONs */
115     PrintStructures->hCollateIcon =
116       LoadIconA(COMDLG32_hInstance, "PD32_COLLATE");
117     PrintStructures->hNoCollateIcon =
118       LoadIconA(COMDLG32_hInstance, "PD32_NOCOLLATE");
119     if(PrintStructures->hCollateIcon == 0 ||
120        PrintStructures->hNoCollateIcon == 0) {
121         ERR("no icon in resourcefile\n");
122         COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
123         EndDialog(hDlg, FALSE);
124     }
125
126     /* load Paper Orientation ICON */
127     /* FIXME: not implemented yet */
128
129     /*
130      * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
131      * must be registered and the Help button must be shown.
132      */
133     if (lppd->Flags & PD_SHOWHELP) {
134         if((PrintStructures->HelpMessageID =
135             RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
136             COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
137             return FALSE;
138         }
139     } else
140         PrintStructures->HelpMessageID = 0;
141
142     if (!(lppd->Flags & PD_PRINTSETUP)) {
143         /* We have a print quality combo box. What shall we do? */
144         if (GetDlgItem(hDlg,cmb1)) {
145             char buf [20];
146
147             FIXME("Print quality only displaying currently.\n");
148
149             pdm = GlobalLock16(lppd->hDevMode);
150             if(pdm) {
151                 switch (pdm->dmPrintQuality) {
152                 case DMRES_HIGH         : strcpy(buf,"High");break;
153                 case DMRES_MEDIUM       : strcpy(buf,"Medium");break;
154                 case DMRES_LOW          : strcpy(buf,"Low");break;
155                 case DMRES_DRAFT        : strcpy(buf,"Draft");break;
156                 case 0                  : strcpy(buf,"Default");break;
157                 default                 : sprintf(buf,"%ddpi",pdm->dmPrintQuality);break;
158                 }
159                 GlobalUnlock16(lppd->hDevMode);
160             } else
161                 strcpy(buf,"Default");
162             SendDlgItemMessageA(hDlg,cmb1,CB_ADDSTRING,0,(LPARAM)buf);
163             SendDlgItemMessageA(hDlg,cmb1,CB_SETCURSEL,0,0);
164             EnableWindow(GetDlgItem(hDlg,cmb1),FALSE);
165         }
166     }
167
168     /* FIXME: I allow more freedom than either Win95 or WinNT,
169      *        which do not agree to what errors should be thrown or not
170      *        in case nToPage or nFromPage is out-of-range.
171      */
172     if (lppd->nMaxPage < lppd->nMinPage)
173         lppd->nMaxPage = lppd->nMinPage;
174     if (lppd->nMinPage == lppd->nMaxPage)
175         lppd->Flags |= PD_NOPAGENUMS;
176     if (lppd->nToPage < lppd->nMinPage)
177         lppd->nToPage = lppd->nMinPage;
178     if (lppd->nToPage > lppd->nMaxPage)
179         lppd->nToPage = lppd->nMaxPage;
180     if (lppd->nFromPage < lppd->nMinPage)
181         lppd->nFromPage = lppd->nMinPage;
182     if (lppd->nFromPage > lppd->nMaxPage)
183         lppd->nFromPage = lppd->nMaxPage;
184
185     /* If the printer combo box is in the dialog, fill it */
186     if (GetDlgItem(hDlg,comboID)) {
187         /* Fill Combobox
188          */
189         pdn = GlobalLock16(lppd->hDevNames);
190         pdm = GlobalLock16(lppd->hDevMode);
191         if(pdn)
192             name = (char*)pdn + pdn->wDeviceOffset;
193         else if(pdm)
194             name = (char*)pdm->dmDeviceName;
195         PRINTDLG_SetUpPrinterListComboA(hDlg, comboID, name);
196         if(pdm) GlobalUnlock16(lppd->hDevMode);
197         if(pdn) GlobalUnlock16(lppd->hDevNames);
198
199         /* Now find selected printer and update rest of dlg */
200         name = HeapAlloc(GetProcessHeap(),0,256);
201         if (GetDlgItemTextA(hDlg, comboID, name, 255))
202             PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
203     } else {
204         /* else just use default printer */
205         char name[200];
206         DWORD dwBufLen = sizeof(name);
207         BOOL ret = GetDefaultPrinterA(name, &dwBufLen);
208
209         if (ret)
210             PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
211         else
212             FIXME("No default printer found, expect problems!\n");
213     }
214     HeapFree(GetProcessHeap(),0,name);
215
216     return TRUE;
217 }
218
219 /************************************************************
220  *
221  *      PRINTDLG_Get16TemplateFrom32             [Internal]
222  *      Generates a 16 bits template from the Wine 32 bits resource
223  *
224  */
225 static HGLOBAL16 PRINTDLG_Get16TemplateFrom32(LPCSTR PrintResourceName)
226 {
227         HRSRC hResInfo;
228         HGLOBAL hDlgTmpl32;
229         LPCVOID template32;
230         DWORD size;
231         HGLOBAL16 hGlobal16;
232         LPVOID template;
233
234         if (!(hResInfo = FindResourceA(COMDLG32_hInstance,
235                PrintResourceName, (LPSTR)RT_DIALOG)))
236         {
237             COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
238             return 0;
239         }
240         if (!(hDlgTmpl32 = LoadResource(COMDLG32_hInstance, hResInfo )) ||
241             !(template32 = LockResource( hDlgTmpl32 )))
242         {
243             COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
244             return 0;
245         }
246         size = SizeofResource(COMDLG32_hInstance, hResInfo);
247         hGlobal16 = GlobalAlloc16(0, size);
248         if (!hGlobal16)
249         {
250             COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
251             ERR("alloc failure for %d bytes\n", size);
252             return 0;
253         }
254         template = GlobalLock16(hGlobal16);
255         if (!template)
256         {
257             COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE);
258             ERR("global lock failure for %x handle\n", hGlobal16);
259             GlobalFree16(hGlobal16);
260             return 0;
261         }
262         ConvertDialog32To16(template32, size, template);
263         GlobalUnlock16(hGlobal16);
264         return hGlobal16;
265 }
266
267 static BOOL PRINTDLG_CreateDC16(LPPRINTDLG16 lppd)
268 {
269     DEVNAMES *pdn = GlobalLock16(lppd->hDevNames);
270     DEVMODEA *pdm = GlobalLock16(lppd->hDevMode);
271
272     if(lppd->Flags & PD_RETURNDC) {
273         lppd->hDC = HDC_16(CreateDCA((char*)pdn + pdn->wDriverOffset,
274                               (char*)pdn + pdn->wDeviceOffset,
275                               (char*)pdn + pdn->wOutputOffset,
276                               pdm ));
277     } else if(lppd->Flags & PD_RETURNIC) {
278         lppd->hDC = HDC_16(CreateICA((char*)pdn + pdn->wDriverOffset,
279                               (char*)pdn + pdn->wDeviceOffset,
280                               (char*)pdn + pdn->wOutputOffset,
281                               pdm ));
282     }
283     GlobalUnlock16(lppd->hDevNames);
284     GlobalUnlock16(lppd->hDevMode);
285     return lppd->hDC ? TRUE : FALSE;
286 }
287
288 /************************************************************
289  *
290  *      PRINTDLG_GetDlgTemplate
291  *
292  */
293 static HGLOBAL16 PRINTDLG_GetDlgTemplate16(const PRINTDLG16 *lppd)
294 {
295     HGLOBAL16 hDlgTmpl, hResInfo;
296
297     if (lppd->Flags & PD_PRINTSETUP) {
298         if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
299             hDlgTmpl = lppd->hSetupTemplate;
300         } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
301             hResInfo = FindResource16(lppd->hInstance,
302                                      MapSL(lppd->lpSetupTemplateName), (LPSTR)RT_DIALOG);
303             hDlgTmpl = LoadResource16(lppd->hInstance, hResInfo);
304         } else {
305             hDlgTmpl = PRINTDLG_Get16TemplateFrom32("PRINT32_SETUP");
306         }
307     } else {
308         if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
309             hDlgTmpl = lppd->hPrintTemplate;
310         } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
311             hResInfo = FindResource16(lppd->hInstance,
312                                      MapSL(lppd->lpPrintTemplateName),
313                                      (LPSTR)RT_DIALOG);
314             hDlgTmpl = LoadResource16(lppd->hInstance, hResInfo);
315         } else {
316             hDlgTmpl = PRINTDLG_Get16TemplateFrom32("PRINT32");
317         }
318     }
319     return hDlgTmpl;
320 }
321
322 /**********************************************************************
323  *
324  *      16 bit commdlg
325  */
326
327 /***********************************************************************
328  *           PrintDlg   (COMMDLG.20)
329  *
330  *  Displays the the PRINT dialog box, which enables the user to specify
331  *  specific properties of the print job.
332  *
333  * RETURNS
334  *  nonzero if the user pressed the OK button
335  *  zero    if the user cancelled the window or an error occurred
336  *
337  * BUGS
338  *  * calls up to the 32-bit versions of the Dialogs, which look different
339  *  * Customizing is *not* implemented.
340  */
341
342 BOOL16 WINAPI PrintDlg16(
343               LPPRINTDLG16 lppd /* [in/out] ptr to PRINTDLG struct */
344 ) {
345     BOOL      bRet = FALSE;
346     LPVOID   ptr;
347     HINSTANCE16 hInst = GetWindowLongPtrW( HWND_32(lppd->hwndOwner), GWLP_HINSTANCE );
348
349     if(TRACE_ON(commdlg)) {
350         char flagstr[1000] = "";
351         const struct pd_flags *pflag = pd_flags;
352         for( ; pflag->name; pflag++) {
353             if(lppd->Flags & pflag->flag)
354                 strcat(flagstr, pflag->name);
355         }
356         TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
357               "pp. %d-%d, min p %d, max p %d, copies %d, hinst %08x\n"
358               "flags %08x (%s)\n",
359               lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
360               lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
361               lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
362     }
363
364     if(lppd->lStructSize != sizeof(PRINTDLG16)) {
365         ERR("structure size %d\n",lppd->lStructSize);
366         COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
367         return FALSE;
368     }
369
370     if(lppd->Flags & PD_RETURNDEFAULT) {
371         PRINTER_INFO_2A *pbuf;
372         DRIVER_INFO_3A  *dbuf;
373         HANDLE hprn;
374         DWORD needed;
375
376         if(lppd->hDevMode || lppd->hDevNames) {
377             WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
378             COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
379             return FALSE;
380         }
381         if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
382             WARN("Can't find default printer\n");
383             COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
384             return FALSE;
385         }
386
387         GetPrinterA(hprn, 2, NULL, 0, &needed);
388         pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
389         GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
390         GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
391         dbuf = HeapAlloc(GetProcessHeap(),0,needed);
392         if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
393             ERR("GetPrinterDriverA failed for %s, le %d, fix your config!\n",
394                     pbuf->pPrinterName,GetLastError());
395             HeapFree(GetProcessHeap(), 0, dbuf);
396             COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
397             return FALSE;
398         }
399         ClosePrinter(hprn);
400         PRINTDLG_CreateDevNames16(&(lppd->hDevNames),
401                                 dbuf->pDriverPath,
402                                 pbuf->pPrinterName,
403                                 pbuf->pPortName);
404         lppd->hDevMode = GlobalAlloc16(GMEM_MOVEABLE,pbuf->pDevMode->dmSize+
405                                      pbuf->pDevMode->dmDriverExtra);
406         ptr = GlobalLock16(lppd->hDevMode);
407         memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
408                pbuf->pDevMode->dmDriverExtra);
409         GlobalUnlock16(lppd->hDevMode);
410         HeapFree(GetProcessHeap(), 0, pbuf);
411         HeapFree(GetProcessHeap(), 0, dbuf);
412         bRet = TRUE;
413     } else {
414         HGLOBAL16 hDlgTmpl;
415         PRINT_PTRA *PrintStructures;
416         PRINT_PTRA16 *ptr16;
417
418     /* load Dialog resources,
419      * depending on Flags indicates Print32 or Print32_setup dialog
420      */
421         hDlgTmpl = PRINTDLG_GetDlgTemplate16(lppd);
422         if (!hDlgTmpl) {
423             COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
424             return FALSE;
425         }
426         ptr16 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PRINT_PTRA16));
427         ptr16->lpPrintDlg16 = lppd;
428         PrintStructures = &ptr16->print32;
429         PrintStructures->lpPrintDlg = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(PRINTDLGA));
430 #define CVAL(x) PrintStructures->lpPrintDlg->x = lppd->x;
431 #define MVAL(x) PrintStructures->lpPrintDlg->x = MapSL(lppd->x);
432         CVAL(Flags);
433         PrintStructures->lpPrintDlg->hwndOwner = HWND_32(lppd->hwndOwner);
434         PrintStructures->lpPrintDlg->hDC = HDC_32(lppd->hDC);
435         CVAL(nFromPage);CVAL(nToPage);CVAL(nMinPage);CVAL(nMaxPage);
436         CVAL(nCopies);
437         PrintStructures->lpPrintDlg->hInstance = HINSTANCE_32(lppd->hInstance);
438         CVAL(lCustData);
439         MVAL(lpPrintTemplateName);MVAL(lpSetupTemplateName);
440         /* Don't copy rest, it is 16 bit specific */
441 #undef MVAL
442 #undef CVAL
443
444         PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(),0,sizeof(DEVMODEA));
445
446         /* and create & process the dialog .
447          * -1 is failure, 0 is broken hwnd, everything else is ok.
448          */
449         bRet =  (0<DialogBoxIndirectParam16(
450                  hInst, hDlgTmpl, lppd->hwndOwner,
451                  (DLGPROC16)GetProcAddress16(GetModuleHandle16("COMMDLG"),(LPCSTR)21),
452                  (LPARAM)PrintStructures
453                 )
454         );
455         if (!PrintStructures->lpPrinterInfo) bRet = FALSE;
456         if(bRet) {
457             DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
458             PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
459             DRIVER_INFO_3A *di = PrintStructures->lpDriverInfo;
460
461             if (lppd->hDevMode == 0) {
462                 TRACE(" No hDevMode yet... Need to create my own\n");
463                 lppd->hDevMode = GlobalAlloc16(GMEM_MOVEABLE,
464                                         lpdm->dmSize + lpdm->dmDriverExtra);
465             } else {
466                 WORD locks;
467                 if((locks = (GlobalFlags16(lppd->hDevMode)&GMEM_LOCKCOUNT))) {
468                     WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
469                     while(locks--) {
470                         GlobalUnlock16(lppd->hDevMode);
471                         TRACE("Now got %d locks\n", locks);
472                     }
473                 }
474                 lppd->hDevMode = GlobalReAlloc16(lppd->hDevMode,
475                                                lpdm->dmSize + lpdm->dmDriverExtra,
476                                                GMEM_MOVEABLE);
477             }
478             lpdmReturn = GlobalLock16(lppd->hDevMode);
479             memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
480
481             if (lppd->hDevNames != 0) {
482                 WORD locks;
483                 if((locks = (GlobalFlags16(lppd->hDevNames)&GMEM_LOCKCOUNT))) {
484                     WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
485                     while(locks--)
486                         GlobalUnlock16(lppd->hDevNames);
487                 }
488             }
489             PRINTDLG_CreateDevNames16(&(lppd->hDevNames),
490                     di->pDriverPath,
491                     pi->pPrinterName,
492                     pi->pPortName
493             );
494             GlobalUnlock16(lppd->hDevMode);
495             /* Copy back the [out] integer parameters */
496 #define CVAL(x) lppd->x = PrintStructures->lpPrintDlg->x;
497             CVAL(Flags);
498             CVAL(nFromPage);
499             CVAL(nToPage);
500             CVAL(nCopies);
501 #undef CVAL
502
503         }
504         if (!(lppd->Flags & (PD_ENABLESETUPTEMPLATEHANDLE | PD_ENABLESETUPTEMPLATE)))
505             GlobalFree16(hDlgTmpl); /* created from the 32 bits resource */
506         HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
507         HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
508         HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
509         HeapFree(GetProcessHeap(), 0, PrintStructures);
510     }
511     if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
512         bRet = PRINTDLG_CreateDC16(lppd);
513
514     TRACE("exit! (%d)\n", bRet);
515     return bRet;
516 }
517
518 /***********************************************************************
519  *           PrintDlgProc   (COMMDLG.21)
520  */
521 BOOL16 CALLBACK PrintDlgProc16(HWND16 hDlg16, UINT16 uMsg, WPARAM16 wParam,
522                             LPARAM lParam)
523 {
524     HWND hDlg = HWND_32(hDlg16);
525     PRINT_PTRA16 *PrintStructures;
526     BOOL16 res = FALSE;
527
528     if (uMsg!=WM_INITDIALOG) {
529         PrintStructures = (PRINT_PTRA16*)GetPropA(hDlg,"__WINE_PRINTDLGDATA");
530         if (!PrintStructures)
531             return FALSE;
532     } else {
533         PrintStructures = (PRINT_PTRA16*) lParam;
534         SetPropA(hDlg,"__WINE_PRINTDLGDATA",PrintStructures);
535         res = PRINTDLG_WMInitDialog16(hDlg, wParam, PrintStructures);
536
537         if(PrintStructures->lpPrintDlg16->Flags & PD_ENABLEPRINTHOOK) {
538             res = CallWindowProc16(
539                 (WNDPROC16)PrintStructures->lpPrintDlg16->lpfnPrintHook,
540                 hDlg16, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg16
541             );
542         }
543         return res;
544     }
545
546     if(PrintStructures->lpPrintDlg16->Flags & PD_ENABLEPRINTHOOK) {
547         res = CallWindowProc16(
548                 (WNDPROC16)PrintStructures->lpPrintDlg16->lpfnPrintHook,
549                 hDlg16,uMsg, wParam, lParam
550         );
551         if(LOWORD(res)) return res;
552     }
553
554     switch (uMsg) {
555     case WM_COMMAND: {
556          /* We need to map those for the 32bit window procedure, compare
557           * with 32Ato16 mapper in winproc.c
558           */
559         return PRINTDLG_WMCommandA(
560                 hDlg,
561                 MAKEWPARAM(wParam,HIWORD(lParam)),
562                 LOWORD(lParam),
563                 &PrintStructures->print32
564         );
565     }
566     case WM_DESTROY:
567         DestroyIcon(PrintStructures->print32.hCollateIcon);
568         DestroyIcon(PrintStructures->print32.hNoCollateIcon);
569     /* FIXME: don't forget to delete the paper orientation icons here! */
570
571         return FALSE;
572     }
573     return res;
574 }
575
576 /***********************************************************************
577  *           PrintSetupDlgProc   (COMMDLG.22)
578  */
579 BOOL16 CALLBACK PrintSetupDlgProc16(HWND16 hWnd16, UINT16 wMsg, WPARAM16 wParam,
580                                    LPARAM lParam)
581 {
582   HWND hWnd = HWND_32(hWnd16);
583   switch (wMsg)
584     {
585     case WM_INITDIALOG:
586       TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
587       ShowWindow(hWnd, SW_SHOWNORMAL);
588       return (TRUE);
589     case WM_COMMAND:
590       switch (wParam) {
591       case IDOK:
592         EndDialog(hWnd, TRUE);
593         return(TRUE);
594       case IDCANCEL:
595         EndDialog(hWnd, FALSE);
596         return(TRUE);
597       }
598       return(FALSE);
599     }
600   return FALSE;
601 }