user: Use a winproc callback instead of a message map/unmap in SendMessageTimeoutA.
[wine] / dlls / user / winproc.h
1 /*
2  * Window procedure callbacks definitions
3  *
4  * Copyright 1996 Alexandre Julliard
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #ifndef __WINE_WINPROC_H
22 #define __WINE_WINPROC_H
23
24 #include <stdarg.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wine/winbase16.h"
29 #include "winnls.h"
30
31 typedef struct
32 {
33     WPARAM16    wParam;
34     LPARAM      lParam;
35     LRESULT     lResult;
36 } MSGPARAM16;
37
38 typedef struct
39 {
40     WPARAM    wParam;
41     LPARAM      lParam;
42     LRESULT     lResult;
43 } MSGPARAM;
44
45 struct tagWINDOWPROC;
46
47 typedef LRESULT (*winproc_callback_t)( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
48                                        LRESULT *result, void *arg );
49 typedef LRESULT (*winproc_callback16_t)( HWND16 hwnd, UINT16 msg, WPARAM16 wp, LPARAM lp,
50                                          LRESULT *result, void *arg );
51
52 extern WNDPROC16 WINPROC_GetProc16( WNDPROC proc, BOOL unicode );
53 extern WNDPROC WINPROC_AllocProc16( WNDPROC16 func );
54 extern WNDPROC WINPROC_GetProc( WNDPROC proc, BOOL unicode );
55 extern WNDPROC WINPROC_AllocProc( WNDPROC funcA, WNDPROC funcW );
56 extern BOOL WINPROC_IsUnicode( WNDPROC proc, BOOL def_val );
57
58 extern LRESULT WINPROC_CallProcAtoW( winproc_callback_t callback, HWND hwnd, UINT msg,
59                                      WPARAM wParam, LPARAM lParam, LRESULT *result, void *arg );
60
61 extern INT WINPROC_MapMsg16To32A( HWND hwnd, UINT16 msg16, WPARAM16 wParam16,
62                                     UINT *pmsg32, WPARAM *pwparam32,
63                                     LPARAM *plparam );
64 extern INT WINPROC_MapMsg16To32W( HWND hwnd, UINT16 msg16, WPARAM16 wParam16,
65                                     UINT *pmsg32, WPARAM *pwparam32,
66                                     LPARAM *plparam );
67 extern INT WINPROC_MapMsg32ATo16( HWND hwnd, UINT msg32,
68                                     WPARAM wParam32, UINT16 *pmsg16,
69                                     WPARAM16 *pwparam16, LPARAM *plparam );
70 extern INT WINPROC_MapMsg32WTo16( HWND hwnd, UINT msg32,
71                                     WPARAM wParam32, UINT16 *pmsg16,
72                                     WPARAM16 *pwparam16, LPARAM *plparam );
73 extern LRESULT WINPROC_UnmapMsg16To32A( HWND hwnd, UINT msg, WPARAM wParam,
74                                         LPARAM lParam, LRESULT result );
75 extern LRESULT WINPROC_UnmapMsg16To32W( HWND hwnd, UINT msg, WPARAM wParam,
76                                         LPARAM lParam, LRESULT result,
77                                         WNDPROC dispatch );
78 extern void WINPROC_UnmapMsg32ATo16( HWND hwnd, UINT msg, WPARAM wParam,
79                                      LPARAM lParam, MSGPARAM16* pm16 );
80 extern void WINPROC_UnmapMsg32WTo16( HWND hwnd, UINT msg, WPARAM wParam,
81                                      LPARAM lParam, MSGPARAM16* pm16 );
82
83 extern INT_PTR WINPROC_CallDlgProc16( DLGPROC16 func, HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam );
84 extern INT_PTR WINPROC_CallDlgProcA( DLGPROC func, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
85 extern INT_PTR WINPROC_CallDlgProcW( DLGPROC func, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
86
87 /* map a Unicode string to a 16-bit pointer */
88 inline static SEGPTR map_str_32W_to_16( LPCWSTR str )
89 {
90     LPSTR ret;
91     INT len;
92
93     if (!HIWORD(str)) return (SEGPTR)LOWORD(str);
94     len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
95     if ((ret = HeapAlloc( GetProcessHeap(), 0, len )))
96         WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
97     return MapLS(ret);
98 }
99
100 /* unmap a Unicode string that was converted to a 16-bit pointer */
101 inline static void unmap_str_32W_to_16( SEGPTR str )
102 {
103     if (!HIWORD(str)) return;
104     HeapFree( GetProcessHeap(), 0, MapSL(str) );
105     UnMapLS( str );
106 }
107
108 /* map a 16-bit pointer to a Unicode string */
109 inline static LPWSTR map_str_16_to_32W( SEGPTR str )
110 {
111     LPWSTR ret;
112     INT len;
113
114     if (!HIWORD(str)) return (LPWSTR)(ULONG_PTR)LOWORD(str);
115     len = MultiByteToWideChar( CP_ACP, 0, MapSL(str), -1, NULL, 0 );
116     if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
117         MultiByteToWideChar( CP_ACP, 0, MapSL(str), -1, ret, len );
118     return ret;
119 }
120
121 /* unmap a 16-bit pointer that was converted to a Unicode string */
122 inline static void unmap_str_16_to_32W( LPCWSTR str )
123 {
124     if (HIWORD(str)) HeapFree( GetProcessHeap(), 0, (void *)str );
125 }
126
127
128 /* Class functions */
129 struct tagCLASS;  /* opaque structure */
130 struct tagWND;
131 extern void CLASS_RegisterBuiltinClasses(void);
132 extern void CLASS_AddWindow( struct tagCLASS *class, struct tagWND *win, BOOL unicode );
133 extern void CLASS_FreeModuleClasses( HMODULE16 hModule );
134
135 #endif  /* __WINE_WINPROC_H */