4 * Copyright 1995, 1996, 2001 Alexandre Julliard
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.
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.
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
22 #include "wine/port.h"
31 #include "wine/winuser16.h"
32 #include "wine/server.h"
34 /* size of buffer needed to store an atom string */
35 #define ATOM_BUFFER_SIZE 256
38 /***********************************************************************
41 * Retrieve the list of properties of a given window.
42 * Returned buffer must be freed by caller.
44 static property_data_t *get_properties( HWND hwnd, int *count )
46 property_data_t *data;
52 if (!(data = HeapAlloc( GetProcessHeap(), 0, total * sizeof(*data) ))) break;
54 SERVER_START_REQ( get_window_properties )
57 wine_server_add_data( req, data, total * sizeof(*data) );
58 if (!wine_server_call( req )) res = reply->total;
61 if (res && res <= total)
66 HeapFree( GetProcessHeap(), 0, data );
67 total = res; /* restart with larger buffer */
73 /***********************************************************************
76 * relay to call the EnumProps callback function from EnumPropsEx
78 static BOOL CALLBACK EnumPropsA_relay( HWND hwnd, LPCSTR str, HANDLE handle, ULONG_PTR lparam )
80 PROPENUMPROCA func = (PROPENUMPROCA)lparam;
81 return func( hwnd, str, handle );
85 /***********************************************************************
88 * relay to call the EnumProps callback function from EnumPropsEx
90 static BOOL CALLBACK EnumPropsW_relay( HWND hwnd, LPCWSTR str, HANDLE handle, ULONG_PTR lparam )
92 PROPENUMPROCW func = (PROPENUMPROCW)lparam;
93 return func( hwnd, str, handle );
97 /***********************************************************************
98 * EnumPropsA (USER32.@)
100 INT WINAPI EnumPropsA( HWND hwnd, PROPENUMPROCA func )
102 return EnumPropsExA( hwnd, EnumPropsA_relay, (LPARAM)func );
106 /***********************************************************************
107 * EnumPropsW (USER32.@)
109 INT WINAPI EnumPropsW( HWND hwnd, PROPENUMPROCW func )
111 return EnumPropsExW( hwnd, EnumPropsW_relay, (LPARAM)func );
115 /***********************************************************************
116 * GetPropA (USER32.@)
118 HANDLE WINAPI GetPropA( HWND hwnd, LPCSTR str )
123 if (!HIWORD(str)) atom = LOWORD(str);
124 else if (!(atom = GlobalFindAtomA( str ))) return 0;
126 SERVER_START_REQ( get_window_property )
130 if (!wine_server_call_err( req )) ret = reply->handle;
137 /***********************************************************************
138 * GetPropW (USER32.@)
140 HANDLE WINAPI GetPropW( HWND hwnd, LPCWSTR str )
145 if (!HIWORD(str)) atom = LOWORD(str);
146 else if (!(atom = GlobalFindAtomW( str ))) return 0;
148 SERVER_START_REQ( get_window_property )
152 if (!wine_server_call_err( req )) ret = reply->handle;
159 /***********************************************************************
160 * SetPropA (USER32.@)
162 BOOL WINAPI SetPropA( HWND hwnd, LPCSTR str, HANDLE handle )
167 if (!HIWORD(str)) atom = LOWORD(str);
168 else if (!(atom = GlobalAddAtomA( str ))) return FALSE;
170 SERVER_START_REQ( set_window_property )
174 req->string = (HIWORD(str) != 0);
175 req->handle = handle;
176 ret = !wine_server_call_err( req );
180 if (HIWORD(str)) GlobalDeleteAtom( atom );
185 /***********************************************************************
186 * SetPropW (USER32.@)
188 BOOL WINAPI SetPropW( HWND hwnd, LPCWSTR str, HANDLE handle )
193 if (!HIWORD(str)) atom = LOWORD(str);
194 else if (!(atom = GlobalAddAtomW( str ))) return FALSE;
196 SERVER_START_REQ( set_window_property )
200 req->string = (HIWORD(str) != 0);
201 req->handle = handle;
202 ret = !wine_server_call_err( req );
206 if (HIWORD(str)) GlobalDeleteAtom( atom );
211 /***********************************************************************
212 * RemovePropA (USER32.@)
214 HANDLE WINAPI RemovePropA( HWND hwnd, LPCSTR str )
219 if (!HIWORD(str)) return RemovePropW( hwnd, MAKEINTATOMW(LOWORD(str)) );
221 if ((atom = GlobalAddAtomA( str )))
223 ret = RemovePropW( hwnd, MAKEINTATOMW(atom) );
224 GlobalDeleteAtom( atom );
230 /***********************************************************************
231 * RemovePropW (USER32.@)
233 HANDLE WINAPI RemovePropW( HWND hwnd, LPCWSTR str )
238 if (!HIWORD(str)) atom = LOWORD(str);
239 else if (!(atom = GlobalAddAtomW( str ))) return 0;
241 SERVER_START_REQ( remove_window_property )
245 if (!wine_server_call_err( req )) ret = reply->handle;
249 if (HIWORD(str)) GlobalDeleteAtom( atom );
254 /***********************************************************************
255 * EnumPropsExA (USER32.@)
257 INT WINAPI EnumPropsExA(HWND hwnd, PROPENUMPROCEXA func, LPARAM lParam)
259 int ret = -1, i, count;
260 property_data_t *list = get_properties( hwnd, &count );
264 for (i = 0; i < count; i++)
266 char string[ATOM_BUFFER_SIZE];
267 if (!GlobalGetAtomNameA( list[i].atom, string, ATOM_BUFFER_SIZE )) continue;
268 if (!(ret = func( hwnd, string, list[i].handle, lParam ))) break;
270 HeapFree( GetProcessHeap(), 0, list );
276 /***********************************************************************
277 * EnumPropsExW (USER32.@)
279 INT WINAPI EnumPropsExW(HWND hwnd, PROPENUMPROCEXW func, LPARAM lParam)
281 int ret = -1, i, count;
282 property_data_t *list = get_properties( hwnd, &count );
286 for (i = 0; i < count; i++)
288 WCHAR string[ATOM_BUFFER_SIZE];
289 if (!GlobalGetAtomNameW( list[i].atom, string, ATOM_BUFFER_SIZE )) continue;
290 if (!(ret = func( hwnd, string, list[i].handle, lParam ))) break;
292 HeapFree( GetProcessHeap(), 0, list );
298 /***********************************************************************
299 * EnumProps (USER.27)
301 INT16 WINAPI EnumProps16( HWND16 hwnd, PROPENUMPROC16 func )
303 int ret = -1, i, count;
304 property_data_t *list = get_properties( HWND_32(hwnd), &count );
308 char string[ATOM_BUFFER_SIZE];
309 SEGPTR segptr = MapLS( string );
313 for (i = 0; i < count; i++)
315 if (list[i].string) /* it was a string originally */
317 if (!GlobalGetAtomNameA( list[i].atom, string, ATOM_BUFFER_SIZE )) continue;
319 args[2] = SELECTOROF(segptr);
320 args[1] = OFFSETOF(segptr);
321 args[0] = LOWORD(list[i].handle);
327 args[1] = list[i].atom;
328 args[0] = LOWORD(list[i].handle);
330 WOWCallback16Ex( (DWORD)func, WCB16_PASCAL, sizeof(args), args, &result );
331 if (!(ret = LOWORD(result))) break;
334 HeapFree( GetProcessHeap(), 0, list );