Cleaned up the code so it would be easier to parse with the new C
[wine] / include / 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 "windef.h"
25 #include "wine/winbase16.h"
26 #include "winnls.h"
27
28 typedef enum
29 {
30     WIN_PROC_INVALID,
31     WIN_PROC_16,
32     WIN_PROC_32A,
33     WIN_PROC_32W
34 } WINDOWPROCTYPE;
35
36 typedef enum
37 {
38     WIN_PROC_CLASS,
39     WIN_PROC_WINDOW,
40     WIN_PROC_TIMER
41 } WINDOWPROCUSER;
42
43 typedef void *HWINDOWPROC;  /* Really a pointer to a WINDOWPROC */
44
45 typedef struct
46 {
47     WPARAM16    wParam;
48     LPARAM      lParam;
49     LRESULT     lResult;
50 } MSGPARAM16;
51
52 typedef struct
53 {
54     WPARAM    wParam;
55     LPARAM      lParam;
56     LRESULT     lResult;
57 } MSGPARAM;
58
59 extern BOOL WINPROC_Init(void);
60 extern WNDPROC16 WINPROC_GetProc( HWINDOWPROC proc, WINDOWPROCTYPE type );
61 extern BOOL WINPROC_SetProc( HWINDOWPROC *pFirst, WNDPROC16 func,
62                                WINDOWPROCTYPE type, WINDOWPROCUSER user );
63 extern void WINPROC_FreeProc( HWINDOWPROC proc, WINDOWPROCUSER user );
64 extern WINDOWPROCTYPE WINPROC_GetProcType( HWINDOWPROC proc );
65
66 extern INT WINPROC_MapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM *pwparam,
67                                      LPARAM *plparam );
68 extern INT WINPROC_MapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM *pwparam,
69                                      LPARAM *plparam );
70 extern INT WINPROC_MapMsg16To32A( HWND hwnd, UINT16 msg16, WPARAM16 wParam16,
71                                     UINT *pmsg32, WPARAM *pwparam32,
72                                     LPARAM *plparam );
73 extern INT WINPROC_MapMsg16To32W( HWND hwnd, UINT16 msg16, WPARAM16 wParam16,
74                                     UINT *pmsg32, WPARAM *pwparam32,
75                                     LPARAM *plparam );
76 extern INT WINPROC_MapMsg32ATo16( HWND hwnd, UINT msg32,
77                                     WPARAM wParam32, UINT16 *pmsg16,
78                                     WPARAM16 *pwparam16, LPARAM *plparam );
79 extern INT WINPROC_MapMsg32WTo16( HWND hwnd, UINT msg32,
80                                     WPARAM wParam32, UINT16 *pmsg16,
81                                     WPARAM16 *pwparam16, LPARAM *plparam );
82 extern LRESULT WINPROC_UnmapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM wParam,
83                                          LPARAM lParam, LRESULT result );
84 extern void WINPROC_UnmapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM wParam,
85                                       LPARAM lParam );
86 extern LRESULT WINPROC_UnmapMsg16To32A( HWND hwnd, UINT msg, WPARAM wParam,
87                                         LPARAM lParam, LRESULT result );
88 extern LRESULT WINPROC_UnmapMsg16To32W( HWND hwnd, UINT msg, WPARAM wParam,
89                                         LPARAM lParam, LRESULT result );
90 extern void WINPROC_UnmapMsg32ATo16( HWND hwnd, UINT msg, WPARAM wParam,
91                                      LPARAM lParam, MSGPARAM16* pm16 );
92 extern void WINPROC_UnmapMsg32WTo16( HWND hwnd, UINT msg, WPARAM wParam,
93                                      LPARAM lParam, MSGPARAM16* pm16 );
94
95 /* map a Unicode string to a 16-bit pointer */
96 inline static SEGPTR map_str_32W_to_16( LPCWSTR str )
97 {
98     LPSTR ret;
99     INT len;
100
101     if (!HIWORD(str)) return (SEGPTR)LOWORD(str);
102     len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
103     if ((ret = HeapAlloc( GetProcessHeap(), 0, len )))
104         WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
105     return MapLS(ret);
106 }
107
108 /* unmap a Unicode string that was converted to a 16-bit pointer */
109 inline static void unmap_str_32W_to_16( SEGPTR str )
110 {
111     if (!HIWORD(str)) return;
112     HeapFree( GetProcessHeap(), 0, MapSL(str) );
113     UnMapLS( str );
114 }
115
116 /* map a 16-bit pointer to a Unicode string */
117 inline static LPWSTR map_str_16_to_32W( SEGPTR str )
118 {
119     LPWSTR ret;
120     INT len;
121
122     if (!HIWORD(str)) return (LPWSTR)(ULONG_PTR)LOWORD(str);
123     len = MultiByteToWideChar( CP_ACP, 0, MapSL(str), -1, NULL, 0 );
124     if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
125         MultiByteToWideChar( CP_ACP, 0, MapSL(str), -1, ret, len );
126     return ret;
127 }
128
129 /* unmap a 16-bit pointer that was converted to a Unicode string */
130 inline static void unmap_str_16_to_32W( LPCWSTR str )
131 {
132     if (HIWORD(str)) HeapFree( GetProcessHeap(), 0, (void *)str );
133 }
134
135 #endif  /* __WINE_WINPROC_H */