ole32: Fix memory leaks in the storage test.
[wine] / dlls / user32 / user_private.h
1 /*
2  * USER private definitions
3  *
4  * Copyright 1993 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #ifndef __WINE_USER_PRIVATE_H
22 #define __WINE_USER_PRIVATE_H
23
24 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "winuser.h"
29 #include "winreg.h"
30 #include "winternl.h"
31 #include "wine/windef16.h"
32
33 extern WORD USER_HeapSel DECLSPEC_HIDDEN;
34
35 #define GET_WORD(ptr)  (*(const WORD *)(ptr))
36 #define GET_DWORD(ptr) (*(const DWORD *)(ptr))
37
38 #define WM_SYSTIMER         0x0118
39 #define WM_POPUPSYSTEMMENU  0x0313
40
41 /* internal messages codes */
42 enum wine_internal_message
43 {
44     WM_WINE_DESTROYWINDOW = 0x80000000,
45     WM_WINE_SETWINDOWPOS,
46     WM_WINE_SHOWWINDOW,
47     WM_WINE_SETPARENT,
48     WM_WINE_SETWINDOWLONG,
49     WM_WINE_ENABLEWINDOW,
50     WM_WINE_SETACTIVEWINDOW,
51     WM_WINE_KEYBOARD_LL_HOOK,
52     WM_WINE_MOUSE_LL_HOOK,
53     WM_WINE_FIRST_DRIVER_MSG = 0x80001000,  /* range of messages reserved for the USER driver */
54     WM_WINE_LAST_DRIVER_MSG = 0x80001fff
55 };
56
57 struct tagCURSORICONINFO;
58
59 typedef struct tagUSER_DRIVER {
60     /* keyboard functions */
61     HKL    (CDECL *pActivateKeyboardLayout)(HKL, UINT);
62     void   (CDECL *pBeep)(void);
63     SHORT  (CDECL *pGetAsyncKeyState)(INT);
64     INT    (CDECL *pGetKeyNameText)(LONG, LPWSTR, INT);
65     HKL    (CDECL *pGetKeyboardLayout)(DWORD);
66     BOOL   (CDECL *pGetKeyboardLayoutName)(LPWSTR);
67     HKL    (CDECL *pLoadKeyboardLayout)(LPCWSTR, UINT);
68     UINT   (CDECL *pMapVirtualKeyEx)(UINT, UINT, HKL);
69     UINT   (CDECL *pSendInput)(UINT, LPINPUT, int);
70     INT    (CDECL *pToUnicodeEx)(UINT, UINT, const BYTE *, LPWSTR, int, UINT, HKL);
71     BOOL   (CDECL *pUnloadKeyboardLayout)(HKL);
72     SHORT  (CDECL *pVkKeyScanEx)(WCHAR, HKL);
73     /* mouse functions */
74     void   (CDECL *pSetCursor)(struct tagCURSORICONINFO *);
75     BOOL   (CDECL *pGetCursorPos)(LPPOINT);
76     BOOL   (CDECL *pSetCursorPos)(INT,INT);
77     BOOL   (CDECL *pClipCursor)(LPCRECT);
78     /* screen saver functions */
79     BOOL   (CDECL *pGetScreenSaveActive)(void);
80     void   (CDECL *pSetScreenSaveActive)(BOOL);
81     /* clipboard functions */
82     INT    (CDECL *pAcquireClipboard)(HWND);                     /* Acquire selection */
83     BOOL   (CDECL *pCountClipboardFormats)(void);                /* Count available clipboard formats */
84     void   (CDECL *pEmptyClipboard)(BOOL);                       /* Empty clipboard data */
85     void   (CDECL *pEndClipboardUpdate)(void);                   /* End clipboard update */
86     UINT   (CDECL *pEnumClipboardFormats)(UINT);                 /* Enumerate clipboard formats */
87     BOOL   (CDECL *pGetClipboardData)(UINT, HANDLE16*, HANDLE*); /* Get specified selection data */
88     INT    (CDECL *pGetClipboardFormatName)(UINT, LPWSTR, UINT); /* Get a clipboard format name */
89     BOOL   (CDECL *pIsClipboardFormatAvailable)(UINT);           /* Check if specified format is available */
90     UINT   (CDECL *pRegisterClipboardFormat)(LPCWSTR);           /* Register a clipboard format */
91     BOOL   (CDECL *pSetClipboardData)(UINT, HANDLE16, HANDLE, BOOL);   /* Set specified selection data */
92     /* display modes */
93     LONG   (CDECL *pChangeDisplaySettingsEx)(LPCWSTR,LPDEVMODEW,HWND,DWORD,LPVOID);
94     BOOL   (CDECL *pEnumDisplayMonitors)(HDC,LPRECT,MONITORENUMPROC,LPARAM);
95     BOOL   (CDECL *pEnumDisplaySettingsEx)(LPCWSTR,DWORD,LPDEVMODEW,DWORD);
96     BOOL   (CDECL *pGetMonitorInfo)(HMONITOR,MONITORINFO*);
97     /* windowing functions */
98     BOOL   (CDECL *pCreateDesktopWindow)(HWND);
99     BOOL   (CDECL *pCreateWindow)(HWND);
100     void   (CDECL *pDestroyWindow)(HWND);
101     void   (CDECL *pGetDC)(HDC,HWND,HWND,const RECT *,const RECT *,DWORD);
102     DWORD  (CDECL *pMsgWaitForMultipleObjectsEx)(DWORD,const HANDLE*,DWORD,DWORD,DWORD);
103     void   (CDECL *pReleaseDC)(HWND,HDC);
104     BOOL   (CDECL *pScrollDC)(HDC, INT, INT, const RECT *, const RECT *, HRGN, LPRECT);
105     void   (CDECL *pSetCapture)(HWND,UINT);
106     void   (CDECL *pSetFocus)(HWND);
107     void   (CDECL *pSetLayeredWindowAttributes)(HWND,COLORREF,BYTE,DWORD);
108     void   (CDECL *pSetParent)(HWND,HWND,HWND);
109     int    (CDECL *pSetWindowRgn)(HWND,HRGN,BOOL);
110     void   (CDECL *pSetWindowIcon)(HWND,UINT,HICON);
111     void   (CDECL *pSetWindowStyle)(HWND,INT,STYLESTRUCT*);
112     void   (CDECL *pSetWindowText)(HWND,LPCWSTR);
113     UINT   (CDECL *pShowWindow)(HWND,INT,RECT*,UINT);
114     LRESULT (CDECL *pSysCommand)(HWND,WPARAM,LPARAM);
115     LRESULT (CDECL *pWindowMessage)(HWND,UINT,WPARAM,LPARAM);
116     void   (CDECL *pWindowPosChanging)(HWND,HWND,UINT,const RECT *,const RECT *,RECT *);
117     void   (CDECL *pWindowPosChanged)(HWND,HWND,UINT,const RECT *,const RECT *,const RECT *,const RECT *);
118 } USER_DRIVER;
119
120 extern const USER_DRIVER *USER_Driver DECLSPEC_HIDDEN;
121
122 extern void USER_unload_driver(void) DECLSPEC_HIDDEN;
123
124 struct received_message_info;
125 struct hook16_queue_info;
126
127 enum user_obj_type
128 {
129     USER_WINDOW = 1,  /* window */
130     USER_MENU,        /* menu */
131     USER_ACCEL,       /* accelerator */
132     USER_DWP          /* DeferWindowPos structure */
133 };
134
135 struct user_object
136 {
137     HANDLE             handle;
138     enum user_obj_type type;
139 };
140
141 #define OBJ_OTHER_PROCESS ((void *)1)  /* returned by get_user_handle_ptr on unknown handles */
142
143 HANDLE alloc_user_handle( struct user_object *ptr, enum user_obj_type type ) DECLSPEC_HIDDEN;
144 void *get_user_handle_ptr( HANDLE handle, enum user_obj_type type ) DECLSPEC_HIDDEN;
145 void release_user_handle_ptr( void *ptr ) DECLSPEC_HIDDEN;
146 void *free_user_handle( HANDLE handle, enum user_obj_type type ) DECLSPEC_HIDDEN;
147
148 /* type of message-sending functions that need special WM_CHAR handling */
149 enum wm_char_mapping
150 {
151     WMCHAR_MAP_POSTMESSAGE,
152     WMCHAR_MAP_SENDMESSAGE,
153     WMCHAR_MAP_SENDMESSAGETIMEOUT,
154     WMCHAR_MAP_RECVMESSAGE,
155     WMCHAR_MAP_DISPATCHMESSAGE,
156     WMCHAR_MAP_CALLWINDOWPROC,
157     WMCHAR_MAP_COUNT,
158     WMCHAR_MAP_NOMAPPING = WMCHAR_MAP_COUNT
159 };
160
161 /* data to store state for A/W mappings of WM_CHAR */
162 struct wm_char_mapping_data
163 {
164     BYTE lead_byte[WMCHAR_MAP_COUNT];
165     MSG  get_msg;
166 };
167
168 /* this is the structure stored in TEB->Win32ClientInfo */
169 /* no attempt is made to keep the layout compatible with the Windows one */
170 struct user_thread_info
171 {
172     HANDLE                        server_queue;           /* Handle to server-side queue */
173     DWORD                         recursion_count;        /* SendMessage recursion counter */
174     BOOL                          hook_unicode;           /* Is current hook unicode? */
175     HHOOK                         hook;                   /* Current hook */
176     struct received_message_info *receive_info;           /* Message being currently received */
177     struct hook16_queue_info     *hook16_info;            /* Opaque pointer for 16-bit hook support */
178     struct wm_char_mapping_data  *wmchar_data;            /* Data for WM_CHAR mappings */
179     DWORD                         GetMessageTimeVal;      /* Value for GetMessageTime */
180     DWORD                         GetMessagePosVal;       /* Value for GetMessagePos */
181     ULONG_PTR                     GetMessageExtraInfoVal; /* Value for GetMessageExtraInfo */
182     HCURSOR                       cursor;                 /* Current cursor */
183     INT                           cursor_count;           /* Cursor show count */
184     UINT                          active_hooks;           /* Bitmap of active hooks */
185     HWND                          top_window;             /* Desktop window */
186     HWND                          msg_window;             /* HWND_MESSAGE parent window */
187
188     ULONG                         pad[9];                 /* Available for more data */
189 };
190
191 struct hook_extra_info
192 {
193     HHOOK handle;
194     LPARAM lparam;
195 };
196
197 static inline struct user_thread_info *get_user_thread_info(void)
198 {
199     return (struct user_thread_info *)NtCurrentTeb()->Win32ClientInfo;
200 }
201
202 /* check if hwnd is a broadcast magic handle */
203 static inline BOOL is_broadcast( HWND hwnd )
204 {
205     return (hwnd == HWND_BROADCAST || hwnd == HWND_TOPMOST);
206 }
207
208 extern HMODULE user32_module DECLSPEC_HIDDEN;
209 extern DWORD USER16_AlertableWait DECLSPEC_HIDDEN;
210 extern HBRUSH SYSCOLOR_55AABrush DECLSPEC_HIDDEN;
211
212 struct dce;
213
214 extern BOOL CLIPBOARD_ReleaseOwner(void) DECLSPEC_HIDDEN;
215 extern BOOL FOCUS_MouseActivate( HWND hwnd ) DECLSPEC_HIDDEN;
216 extern BOOL HOOK_IsHooked( INT id ) DECLSPEC_HIDDEN;
217 extern BOOL set_capture_window( HWND hwnd, UINT gui_flags, HWND *prev_ret );
218 extern void free_dce( struct dce *dce, HWND hwnd ) DECLSPEC_HIDDEN;
219 extern void invalidate_dce( HWND hwnd, const RECT *rect ) DECLSPEC_HIDDEN;
220 extern void erase_now( HWND hwnd, UINT rdw_flags ) DECLSPEC_HIDDEN;
221 extern void *get_hook_proc( void *proc, const WCHAR *module );
222 extern LRESULT call_current_hook( HHOOK hhook, INT code, WPARAM wparam, LPARAM lparam ) DECLSPEC_HIDDEN;
223 extern BOOL map_wparam_AtoW( UINT message, WPARAM *wparam, enum wm_char_mapping mapping ) DECLSPEC_HIDDEN;
224 extern LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
225                                                UINT msg, WPARAM wparam, LPARAM lparam,
226                                                UINT flags, UINT timeout, PDWORD_PTR res_ptr ) DECLSPEC_HIDDEN;
227 extern HPEN SYSCOLOR_GetPen( INT index ) DECLSPEC_HIDDEN;
228 extern void SYSPARAMS_Init(void) DECLSPEC_HIDDEN;
229 extern void USER_CheckNotLock(void) DECLSPEC_HIDDEN;
230 extern BOOL USER_IsExitingThread( DWORD tid ) DECLSPEC_HIDDEN;
231
232 extern BOOL USER_SetWindowPos( WINDOWPOS * winpos ) DECLSPEC_HIDDEN;
233
234 typedef LRESULT (*winproc_callback_t)( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
235                                        LRESULT *result, void *arg );
236 typedef LRESULT (*winproc_callback16_t)( HWND16 hwnd, UINT16 msg, WPARAM16 wp, LPARAM lp,
237                                          LRESULT *result, void *arg );
238
239 extern WNDPROC16 WINPROC_GetProc16( WNDPROC proc, BOOL unicode ) DECLSPEC_HIDDEN;
240 extern WNDPROC WINPROC_AllocProc16( WNDPROC16 func ) DECLSPEC_HIDDEN;
241 extern WNDPROC WINPROC_GetProc( WNDPROC proc, BOOL unicode ) DECLSPEC_HIDDEN;
242 extern WNDPROC WINPROC_AllocProc( WNDPROC funcA, WNDPROC funcW ) DECLSPEC_HIDDEN;
243 extern BOOL WINPROC_IsUnicode( WNDPROC proc, BOOL def_val ) DECLSPEC_HIDDEN;
244
245 extern LRESULT WINPROC_CallProcAtoW( winproc_callback_t callback, HWND hwnd, UINT msg,
246                                      WPARAM wParam, LPARAM lParam, LRESULT *result, void *arg,
247                                      enum wm_char_mapping mapping ) DECLSPEC_HIDDEN;
248 extern LRESULT WINPROC_CallProc16To32A( winproc_callback_t callback, HWND16 hwnd, UINT16 msg,
249                                         WPARAM16 wParam, LPARAM lParam, LRESULT *result, void *arg ) DECLSPEC_HIDDEN;
250 extern LRESULT WINPROC_CallProc32ATo16( winproc_callback16_t callback, HWND hwnd, UINT msg,
251                                         WPARAM wParam, LPARAM lParam, LRESULT *result, void *arg ) DECLSPEC_HIDDEN;
252
253 extern INT_PTR WINPROC_CallDlgProcA( DLGPROC func, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ) DECLSPEC_HIDDEN;
254 extern INT_PTR WINPROC_CallDlgProcW( DLGPROC func, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ) DECLSPEC_HIDDEN;
255 extern BOOL WINPROC_call_window( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
256                                  LRESULT *result, BOOL unicode, enum wm_char_mapping mapping ) DECLSPEC_HIDDEN;
257
258 /* message spy definitions */
259
260 #define SPY_DISPATCHMESSAGE16     0x0100
261 #define SPY_DISPATCHMESSAGE       0x0101
262 #define SPY_SENDMESSAGE16         0x0102
263 #define SPY_SENDMESSAGE           0x0103
264 #define SPY_DEFWNDPROC16          0x0104
265 #define SPY_DEFWNDPROC            0x0105
266
267 #define SPY_RESULT_OK16           0x0000
268 #define SPY_RESULT_OK             0x0001
269 #define SPY_RESULT_INVALIDHWND16  0x0002
270 #define SPY_RESULT_INVALIDHWND    0x0003
271 #define SPY_RESULT_DEFWND16       0x0004
272 #define SPY_RESULT_DEFWND         0x0005
273
274 extern const char *SPY_GetClassLongOffsetName( INT offset ) DECLSPEC_HIDDEN;
275 extern const char *SPY_GetMsgName( UINT msg, HWND hWnd ) DECLSPEC_HIDDEN;
276 extern const char *SPY_GetVKeyName(WPARAM wParam) DECLSPEC_HIDDEN;
277 extern void SPY_EnterMessage( INT iFlag, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ) DECLSPEC_HIDDEN;
278 extern void SPY_ExitMessage( INT iFlag, HWND hwnd, UINT msg,
279                              LRESULT lReturn, WPARAM wParam, LPARAM lParam ) DECLSPEC_HIDDEN;
280 extern int SPY_Init(void) DECLSPEC_HIDDEN;
281
282 /* HANDLE16 <-> HANDLE conversions */
283 #define HCURSOR_16(h32)    (LOWORD(h32))
284 #define HICON_16(h32)      (LOWORD(h32))
285 #define HINSTANCE_16(h32)  (LOWORD(h32))
286
287 #define HCURSOR_32(h16)    ((HCURSOR)(ULONG_PTR)(h16))
288 #define HICON_32(h16)      ((HICON)(ULONG_PTR)(h16))
289 #define HINSTANCE_32(h16)  ((HINSTANCE)(ULONG_PTR)(h16))
290 #define HMODULE_32(h16)    ((HMODULE)(ULONG_PTR)(h16))
291
292 #include "pshpack1.h"
293
294 typedef struct
295 {
296     BYTE   bWidth;
297     BYTE   bHeight;
298     BYTE   bColorCount;
299     BYTE   bReserved;
300 } ICONRESDIR;
301
302 typedef struct
303 {
304     WORD   wWidth;
305     WORD   wHeight;
306 } CURSORDIR;
307
308 typedef struct
309 {   union
310     { ICONRESDIR icon;
311       CURSORDIR  cursor;
312     } ResInfo;
313     WORD   wPlanes;
314     WORD   wBitCount;
315     DWORD  dwBytesInRes;
316     WORD   wResId;
317 } CURSORICONDIRENTRY;
318
319 typedef struct
320 {
321     WORD                idReserved;
322     WORD                idType;
323     WORD                idCount;
324     CURSORICONDIRENTRY  idEntries[1];
325 } CURSORICONDIR;
326
327 #include "poppack.h"
328
329 extern void CURSORICON_FreeModuleIcons( HMODULE16 hModule ) DECLSPEC_HIDDEN;
330 extern BOOL get_icon_size( HICON handle, SIZE *size ) DECLSPEC_HIDDEN;
331
332 /* Mingw's assert() imports MessageBoxA and gets confused by user32 exporting it */
333 #ifdef __MINGW32__
334 #undef assert
335 #define assert(expr) ((void)0)
336 #endif
337
338 #endif /* __WINE_USER_PRIVATE_H */