4 * Copyright 1995, 1996, 2001 Alexandre Julliard
11 #include "wine/winuser16.h"
12 #include "wine/server.h"
15 /* size of buffer needed to store an atom string */
16 #define ATOM_BUFFER_SIZE 256
19 /***********************************************************************
22 * Retrieve the list of properties of a given window.
23 * Returned buffer must be freed by caller.
25 static property_data_t *get_properties( HWND hwnd, int *count )
27 property_data_t *ret = NULL;
29 SERVER_START_VAR_REQ( get_window_properties, REQUEST_MAX_VAR_SIZE )
34 size_t size = server_data_size(req);
37 property_data_t *data = server_data_ptr(req);
38 if ((ret = HeapAlloc( GetProcessHeap(), 0, size ))) memcpy( ret, data, size );
39 *count = size / sizeof(*data);
48 /***********************************************************************
51 * relay to call the EnumProps callback function from EnumPropsEx
53 static BOOL CALLBACK EnumPropsA_relay( HWND hwnd, LPCSTR str, HANDLE handle, ULONG_PTR lparam )
55 PROPENUMPROCA func = (PROPENUMPROCA)lparam;
56 return func( hwnd, str, handle );
60 /***********************************************************************
63 * relay to call the EnumProps callback function from EnumPropsEx
65 static BOOL CALLBACK EnumPropsW_relay( HWND hwnd, LPCWSTR str, HANDLE handle, ULONG_PTR lparam )
67 PROPENUMPROCW func = (PROPENUMPROCW)lparam;
68 return func( hwnd, str, handle );
72 /***********************************************************************
73 * EnumPropsA (USER32.@)
75 INT WINAPI EnumPropsA( HWND hwnd, PROPENUMPROCA func )
77 return EnumPropsExA( hwnd, EnumPropsA_relay, (LPARAM)func );
81 /***********************************************************************
82 * EnumPropsW (USER32.@)
84 INT WINAPI EnumPropsW( HWND hwnd, PROPENUMPROCW func )
86 return EnumPropsExW( hwnd, EnumPropsW_relay, (LPARAM)func );
90 /***********************************************************************
93 HANDLE WINAPI GetPropA( HWND hwnd, LPCSTR str )
98 if (!HIWORD(str)) atom = LOWORD(str);
99 else if (!(atom = GlobalFindAtomA( str ))) return 0;
101 SERVER_START_REQ( get_window_property )
105 if (!SERVER_CALL_ERR()) ret = req->handle;
112 /***********************************************************************
113 * GetPropW (USER32.@)
115 HANDLE WINAPI GetPropW( HWND hwnd, LPCWSTR str )
120 if (!HIWORD(str)) atom = LOWORD(str);
121 else if (!(atom = GlobalFindAtomW( str ))) return 0;
123 SERVER_START_REQ( get_window_property )
127 if (!SERVER_CALL_ERR()) ret = req->handle;
134 /***********************************************************************
135 * SetPropA (USER32.@)
137 BOOL WINAPI SetPropA( HWND hwnd, LPCSTR str, HANDLE handle )
142 if (!HIWORD(str)) atom = LOWORD(str);
143 else if (!(atom = GlobalAddAtomA( str ))) return FALSE;
145 SERVER_START_REQ( set_window_property )
149 req->string = (HIWORD(str) != 0);
150 req->handle = handle;
151 ret = !SERVER_CALL_ERR();
155 if (HIWORD(str)) GlobalDeleteAtom( atom );
160 /***********************************************************************
161 * SetPropW (USER32.@)
163 BOOL WINAPI SetPropW( HWND hwnd, LPCWSTR str, HANDLE handle )
168 if (!HIWORD(str)) atom = LOWORD(str);
169 else if (!(atom = GlobalAddAtomW( str ))) return FALSE;
171 SERVER_START_REQ( set_window_property )
175 req->string = (HIWORD(str) != 0);
176 req->handle = handle;
177 ret = !SERVER_CALL_ERR();
181 if (HIWORD(str)) GlobalDeleteAtom( atom );
186 /***********************************************************************
187 * RemovePropA (USER32.@)
189 HANDLE WINAPI RemovePropA( HWND hwnd, LPCSTR str )
194 if (!HIWORD(str)) return RemovePropW( hwnd, MAKEINTATOMW(LOWORD(str)) );
196 if ((atom = GlobalAddAtomA( str )))
198 ret = RemovePropW( hwnd, MAKEINTATOMW(atom) );
199 GlobalDeleteAtom( atom );
205 /***********************************************************************
206 * RemovePropW (USER32.@)
208 HANDLE WINAPI RemovePropW( HWND hwnd, LPCWSTR str )
213 if (!HIWORD(str)) atom = LOWORD(str);
214 else if (!(atom = GlobalAddAtomW( str ))) return 0;
216 SERVER_START_REQ( remove_window_property )
220 if (!SERVER_CALL_ERR()) ret = req->handle;
224 if (HIWORD(str)) GlobalDeleteAtom( atom );
229 /***********************************************************************
230 * EnumPropsExA (USER32.@)
232 INT WINAPI EnumPropsExA(HWND hwnd, PROPENUMPROCEXA func, LPARAM lParam)
234 int ret = -1, i, count;
235 property_data_t *list = get_properties( hwnd, &count );
239 for (i = 0; i < count; i++)
241 char string[ATOM_BUFFER_SIZE];
242 if (!GlobalGetAtomNameA( list[i].atom, string, ATOM_BUFFER_SIZE )) continue;
243 if (!(ret = func( hwnd, string, list[i].handle, lParam ))) break;
245 HeapFree( GetProcessHeap(), 0, list );
251 /***********************************************************************
252 * EnumPropsExW (USER32.@)
254 INT WINAPI EnumPropsExW(HWND hwnd, PROPENUMPROCEXW func, LPARAM lParam)
256 int ret = -1, i, count;
257 property_data_t *list = get_properties( hwnd, &count );
261 for (i = 0; i < count; i++)
263 WCHAR string[ATOM_BUFFER_SIZE];
264 if (!GlobalGetAtomNameW( list[i].atom, string, ATOM_BUFFER_SIZE )) continue;
265 if (!(ret = func( hwnd, string, list[i].handle, lParam ))) break;
267 HeapFree( GetProcessHeap(), 0, list );
273 /***********************************************************************
274 * EnumProps (USER.27)
276 INT16 WINAPI EnumProps16( HWND16 hwnd, PROPENUMPROC16 func )
278 int ret = -1, i, count;
279 property_data_t *list = get_properties( hwnd, &count );
283 char *string = SEGPTR_ALLOC( ATOM_BUFFER_SIZE );
284 for (i = 0; i < count; i++)
286 if (list[i].string) /* it was a string originally */
288 if (!GlobalGetAtomNameA( list[i].atom, string, ATOM_BUFFER_SIZE )) continue;
289 ret = func( hwnd, SEGPTR_GET(string), list[i].handle );
292 ret = func( hwnd, list[i].atom, list[i].handle );
295 SEGPTR_FREE( string );
296 HeapFree( GetProcessHeap(), 0, list );