4 * Copyright 1995, 1996, 2001 Alexandre Julliard
11 #include "wine/winuser16.h"
12 #include "wine/server.h"
14 /* size of buffer needed to store an atom string */
15 #define ATOM_BUFFER_SIZE 256
17 /* ### start build ### */
18 extern WORD CALLBACK PROP_CallTo16_word_wlw(PROPENUMPROC16,WORD,LONG,WORD);
19 /* ### stop build ### */
21 /***********************************************************************
24 * Retrieve the list of properties of a given window.
25 * Returned buffer must be freed by caller.
27 static property_data_t *get_properties( HWND hwnd, int *count )
29 property_data_t *data;
35 if (!(data = HeapAlloc( GetProcessHeap(), 0, total * sizeof(*data) ))) break;
37 SERVER_START_REQ( get_window_properties )
40 wine_server_add_data( req, data, total * sizeof(*data) );
41 if (!wine_server_call( req )) res = reply->total;
44 if (res && res <= total)
49 HeapFree( GetProcessHeap(), 0, data );
50 total = res; /* restart with larger buffer */
56 /***********************************************************************
59 * relay to call the EnumProps callback function from EnumPropsEx
61 static BOOL CALLBACK EnumPropsA_relay( HWND hwnd, LPCSTR str, HANDLE handle, ULONG_PTR lparam )
63 PROPENUMPROCA func = (PROPENUMPROCA)lparam;
64 return func( hwnd, str, handle );
68 /***********************************************************************
71 * relay to call the EnumProps callback function from EnumPropsEx
73 static BOOL CALLBACK EnumPropsW_relay( HWND hwnd, LPCWSTR str, HANDLE handle, ULONG_PTR lparam )
75 PROPENUMPROCW func = (PROPENUMPROCW)lparam;
76 return func( hwnd, str, handle );
80 /***********************************************************************
81 * EnumPropsA (USER32.@)
83 INT WINAPI EnumPropsA( HWND hwnd, PROPENUMPROCA func )
85 return EnumPropsExA( hwnd, EnumPropsA_relay, (LPARAM)func );
89 /***********************************************************************
90 * EnumPropsW (USER32.@)
92 INT WINAPI EnumPropsW( HWND hwnd, PROPENUMPROCW func )
94 return EnumPropsExW( hwnd, EnumPropsW_relay, (LPARAM)func );
98 /***********************************************************************
101 HANDLE WINAPI GetPropA( HWND hwnd, LPCSTR str )
106 if (!HIWORD(str)) atom = LOWORD(str);
107 else if (!(atom = GlobalFindAtomA( str ))) return 0;
109 SERVER_START_REQ( get_window_property )
113 if (!wine_server_call_err( req )) ret = reply->handle;
120 /***********************************************************************
121 * GetPropW (USER32.@)
123 HANDLE WINAPI GetPropW( HWND hwnd, LPCWSTR str )
128 if (!HIWORD(str)) atom = LOWORD(str);
129 else if (!(atom = GlobalFindAtomW( str ))) return 0;
131 SERVER_START_REQ( get_window_property )
135 if (!wine_server_call_err( req )) ret = reply->handle;
142 /***********************************************************************
143 * SetPropA (USER32.@)
145 BOOL WINAPI SetPropA( HWND hwnd, LPCSTR str, HANDLE handle )
150 if (!HIWORD(str)) atom = LOWORD(str);
151 else if (!(atom = GlobalAddAtomA( str ))) return FALSE;
153 SERVER_START_REQ( set_window_property )
157 req->string = (HIWORD(str) != 0);
158 req->handle = handle;
159 ret = !wine_server_call_err( req );
163 if (HIWORD(str)) GlobalDeleteAtom( atom );
168 /***********************************************************************
169 * SetPropW (USER32.@)
171 BOOL WINAPI SetPropW( HWND hwnd, LPCWSTR str, HANDLE handle )
176 if (!HIWORD(str)) atom = LOWORD(str);
177 else if (!(atom = GlobalAddAtomW( str ))) return FALSE;
179 SERVER_START_REQ( set_window_property )
183 req->string = (HIWORD(str) != 0);
184 req->handle = handle;
185 ret = !wine_server_call_err( req );
189 if (HIWORD(str)) GlobalDeleteAtom( atom );
194 /***********************************************************************
195 * RemovePropA (USER32.@)
197 HANDLE WINAPI RemovePropA( HWND hwnd, LPCSTR str )
202 if (!HIWORD(str)) return RemovePropW( hwnd, MAKEINTATOMW(LOWORD(str)) );
204 if ((atom = GlobalAddAtomA( str )))
206 ret = RemovePropW( hwnd, MAKEINTATOMW(atom) );
207 GlobalDeleteAtom( atom );
213 /***********************************************************************
214 * RemovePropW (USER32.@)
216 HANDLE WINAPI RemovePropW( HWND hwnd, LPCWSTR str )
221 if (!HIWORD(str)) atom = LOWORD(str);
222 else if (!(atom = GlobalAddAtomW( str ))) return 0;
224 SERVER_START_REQ( remove_window_property )
228 if (!wine_server_call_err( req )) ret = reply->handle;
232 if (HIWORD(str)) GlobalDeleteAtom( atom );
237 /***********************************************************************
238 * EnumPropsExA (USER32.@)
240 INT WINAPI EnumPropsExA(HWND hwnd, PROPENUMPROCEXA func, LPARAM lParam)
242 int ret = -1, i, count;
243 property_data_t *list = get_properties( hwnd, &count );
247 for (i = 0; i < count; i++)
249 char string[ATOM_BUFFER_SIZE];
250 if (!GlobalGetAtomNameA( list[i].atom, string, ATOM_BUFFER_SIZE )) continue;
251 if (!(ret = func( hwnd, string, list[i].handle, lParam ))) break;
253 HeapFree( GetProcessHeap(), 0, list );
259 /***********************************************************************
260 * EnumPropsExW (USER32.@)
262 INT WINAPI EnumPropsExW(HWND hwnd, PROPENUMPROCEXW func, LPARAM lParam)
264 int ret = -1, i, count;
265 property_data_t *list = get_properties( hwnd, &count );
269 for (i = 0; i < count; i++)
271 WCHAR string[ATOM_BUFFER_SIZE];
272 if (!GlobalGetAtomNameW( list[i].atom, string, ATOM_BUFFER_SIZE )) continue;
273 if (!(ret = func( hwnd, string, list[i].handle, lParam ))) break;
275 HeapFree( GetProcessHeap(), 0, list );
281 /***********************************************************************
282 * EnumProps (USER.27)
284 INT16 WINAPI EnumProps16( HWND16 hwnd, PROPENUMPROC16 func )
286 int ret = -1, i, count;
287 property_data_t *list = get_properties( hwnd, &count );
291 char string[ATOM_BUFFER_SIZE];
292 SEGPTR segptr = MapLS( string );
293 for (i = 0; i < count; i++)
295 if (list[i].string) /* it was a string originally */
297 if (!GlobalGetAtomNameA( list[i].atom, string, ATOM_BUFFER_SIZE )) continue;
298 ret = PROP_CallTo16_word_wlw( func, hwnd, segptr, list[i].handle );
301 ret = PROP_CallTo16_word_wlw( func, hwnd, list[i].atom, list[i].handle );
305 HeapFree( GetProcessHeap(), 0, list );