dxdiagn: Mark internal symbols with hidden visibility.
[wine] / dlls / commdlg.dll16 / printdlg.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 #include "cdlg16.h"
44
45 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
46
47 static void global_handle_to_16( HGLOBAL16 *h16, HGLOBAL handle )
48 {
49     DWORD size;
50     HGLOBAL16 ret;
51
52     if (!handle) return;
53     size = GlobalSize( handle );
54     if (*h16) ret = GlobalReAlloc16( GMEM_MOVEABLE, *h16, size );
55     else ret = GlobalAlloc16( GMEM_MOVEABLE, size );
56     if (ret)
57     {
58         void *src = GlobalLock( handle );
59         void *dst = GlobalLock16( ret );
60         memcpy( dst, src, size );
61         GlobalUnlock( handle );
62         GlobalUnlock16( ret );
63         *h16 = ret;
64     }
65 }
66
67 static HGLOBAL global_handle_from_16( HGLOBAL16 handle )
68 {
69     DWORD size;
70     HGLOBAL ret;
71
72     if (!handle) return 0;
73     size = GlobalSize16( handle );
74     if ((ret = GlobalAlloc( GMEM_MOVEABLE, size )))
75     {
76         void *src = GlobalLock16( handle );
77         void *dst = GlobalLock( ret );
78         memcpy( dst, src, size );
79         GlobalUnlock16( handle );
80         GlobalUnlock( ret );
81     }
82     return ret;
83 }
84
85 /**********************************************************************
86  *
87  *      16 bit commdlg
88  */
89
90 /***********************************************************************
91  *           PrintDlg   (COMMDLG.20)
92  *
93  *  Displays the PRINT dialog box, which enables the user to specify
94  *  specific properties of the print job.
95  *
96  * RETURNS
97  *  nonzero if the user pressed the OK button
98  *  zero    if the user cancelled the window or an error occurred
99  *
100  * BUGS
101  *  * calls up to the 32-bit versions of the Dialogs, which look different
102  *  * Customizing is *not* implemented.
103  */
104
105 BOOL16 WINAPI PrintDlg16( LPPRINTDLG16 lppd )
106 {
107     PRINTDLGA pd32;
108     BOOL ret;
109
110     if (!lppd) return PrintDlgA(NULL); /* generate failure with CDERR_INITIALIZATION */
111
112     pd32.lStructSize = sizeof(pd32);
113     pd32.Flags       = lppd->Flags & ~(PD_ENABLEPRINTTEMPLATE | PD_ENABLEPRINTTEMPLATEHANDLE |
114                                        PD_ENABLESETUPTEMPLATE | PD_ENABLESETUPTEMPLATEHANDLE |
115                                        PD_ENABLEPRINTHOOK | PD_ENABLESETUPHOOK);
116     pd32.hwndOwner   = HWND_32(lppd->hwndOwner);
117     pd32.hDevMode    = global_handle_from_16( lppd->hDevMode );
118     pd32.hDevNames   = global_handle_from_16( lppd->hDevNames );
119     pd32.nFromPage   = lppd->nFromPage;
120     pd32.nToPage     = lppd->nToPage;
121     pd32.nMinPage    = lppd->nMinPage;
122     pd32.nMaxPage    = lppd->nMaxPage;
123     pd32.nCopies     = lppd->nCopies;
124
125     if (lppd->Flags & (PD_ENABLEPRINTTEMPLATE | PD_ENABLEPRINTTEMPLATEHANDLE |
126                        PD_ENABLESETUPTEMPLATE | PD_ENABLESETUPTEMPLATEHANDLE))
127         FIXME( "custom templates no longer supported, using default\n" );
128     if (lppd->Flags & PD_ENABLEPRINTHOOK)
129         FIXME( "custom print hook %p no longer supported\n", lppd->lpfnPrintHook );
130     if (lppd->Flags & PD_ENABLESETUPHOOK)
131         FIXME( "custom setup hook %p no longer supported\n", lppd->lpfnSetupHook );
132
133     /* Generate failure with CDERR_STRUCTSIZE, when needed */
134     if (lppd->lStructSize != sizeof(PRINTDLG16)) pd32.lStructSize--;
135
136     if ((ret = PrintDlgA( &pd32 )))
137     {
138         lppd->hDC = HDC_16( pd32.hDC );
139         global_handle_to_16( &lppd->hDevNames, pd32.hDevNames );
140         global_handle_to_16( &lppd->hDevMode, pd32.hDevMode );
141
142         lppd->nFromPage   = pd32.nFromPage;
143         lppd->nToPage     = pd32.nToPage;
144         lppd->nMinPage    = pd32.nMinPage;
145         lppd->nMaxPage    = pd32.nMaxPage;
146         lppd->nCopies     = pd32.nCopies;
147     }
148     GlobalFree( pd32.hDevNames );
149     GlobalFree( pd32.hDevMode );
150     return ret;
151 }
152
153 /***********************************************************************
154  *           PrintDlgProc   (COMMDLG.21)
155  */
156 BOOL16 CALLBACK PrintDlgProc16(HWND16 hDlg16, UINT16 uMsg, WPARAM16 wParam, LPARAM lParam)
157 {
158     FIXME( "%04x %04x %04x %08lx: stub\n", hDlg16, uMsg, wParam, lParam );
159     return FALSE;
160 }
161
162 /***********************************************************************
163  *           PrintSetupDlgProc   (COMMDLG.22)
164  */
165 BOOL16 CALLBACK PrintSetupDlgProc16(HWND16 hWnd16, UINT16 wMsg, WPARAM16 wParam,
166                                    LPARAM lParam)
167 {
168   HWND hWnd = HWND_32(hWnd16);
169   switch (wMsg)
170     {
171     case WM_INITDIALOG:
172       TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
173       ShowWindow(hWnd, SW_SHOWNORMAL);
174       return (TRUE);
175     case WM_COMMAND:
176       switch (wParam) {
177       case IDOK:
178         EndDialog(hWnd, TRUE);
179         return(TRUE);
180       case IDCANCEL:
181         EndDialog(hWnd, FALSE);
182         return(TRUE);
183       }
184       return(FALSE);
185     }
186   return FALSE;
187 }