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