Spelling fix.
[wine/wine-kai.git] / dlls / user / property.c
blob469a24b50d61014812a3dc3267d038fc401b01b1
1 /*
2 * Window properties
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
21 #include <string.h>
23 #include "windef.h"
24 #include "wingdi.h"
25 #include "wownt32.h"
26 #include "wine/winuser16.h"
27 #include "wine/server.h"
28 #include "win.h"
30 /* size of buffer needed to store an atom string */
31 #define ATOM_BUFFER_SIZE 256
34 /***********************************************************************
35 * get_properties
37 * Retrieve the list of properties of a given window.
38 * Returned buffer must be freed by caller.
40 static property_data_t *get_properties( HWND hwnd, int *count )
42 property_data_t *data;
43 int total = 32;
45 while (total)
47 int res = 0;
48 if (!(data = HeapAlloc( GetProcessHeap(), 0, total * sizeof(*data) ))) break;
49 *count = 0;
50 SERVER_START_REQ( get_window_properties )
52 req->window = hwnd;
53 wine_server_add_data( req, data, total * sizeof(*data) );
54 if (!wine_server_call( req )) res = reply->total;
56 SERVER_END_REQ;
57 if (res && res <= total)
59 *count = res;
60 return data;
62 HeapFree( GetProcessHeap(), 0, data );
63 total = res; /* restart with larger buffer */
65 return NULL;
69 /***********************************************************************
70 * EnumPropsA_relay
72 * relay to call the EnumProps callback function from EnumPropsEx
74 static BOOL CALLBACK EnumPropsA_relay( HWND hwnd, LPCSTR str, HANDLE handle, ULONG_PTR lparam )
76 PROPENUMPROCA func = (PROPENUMPROCA)lparam;
77 return func( hwnd, str, handle );
81 /***********************************************************************
82 * EnumPropsW_relay
84 * relay to call the EnumProps callback function from EnumPropsEx
86 static BOOL CALLBACK EnumPropsW_relay( HWND hwnd, LPCWSTR str, HANDLE handle, ULONG_PTR lparam )
88 PROPENUMPROCW func = (PROPENUMPROCW)lparam;
89 return func( hwnd, str, handle );
93 /***********************************************************************
94 * EnumPropsA (USER32.@)
96 INT WINAPI EnumPropsA( HWND hwnd, PROPENUMPROCA func )
98 return EnumPropsExA( hwnd, EnumPropsA_relay, (LPARAM)func );
102 /***********************************************************************
103 * EnumPropsW (USER32.@)
105 INT WINAPI EnumPropsW( HWND hwnd, PROPENUMPROCW func )
107 return EnumPropsExW( hwnd, EnumPropsW_relay, (LPARAM)func );
111 /***********************************************************************
112 * GetPropA (USER32.@)
114 HANDLE WINAPI GetPropA( HWND hwnd, LPCSTR str )
116 ATOM atom;
117 HANDLE ret = 0;
119 if (!HIWORD(str)) atom = LOWORD(str);
120 else if (!(atom = GlobalFindAtomA( str ))) return 0;
122 SERVER_START_REQ( get_window_property )
124 req->window = hwnd;
125 req->atom = atom;
126 if (!wine_server_call_err( req )) ret = reply->handle;
128 SERVER_END_REQ;
129 return ret;
133 /***********************************************************************
134 * GetPropW (USER32.@)
136 HANDLE WINAPI GetPropW( HWND hwnd, LPCWSTR str )
138 ATOM atom;
139 HANDLE ret = 0;
141 if (!HIWORD(str)) atom = LOWORD(str);
142 else if (!(atom = GlobalFindAtomW( str ))) return 0;
144 SERVER_START_REQ( get_window_property )
146 req->window = hwnd;
147 req->atom = atom;
148 if (!wine_server_call_err( req )) ret = reply->handle;
150 SERVER_END_REQ;
151 return ret;
155 /***********************************************************************
156 * SetPropA (USER32.@)
158 BOOL WINAPI SetPropA( HWND hwnd, LPCSTR str, HANDLE handle )
160 ATOM atom;
161 BOOL ret;
163 if (!HIWORD(str)) atom = LOWORD(str);
164 else if (!(atom = GlobalAddAtomA( str ))) return FALSE;
166 SERVER_START_REQ( set_window_property )
168 req->window = hwnd;
169 req->atom = atom;
170 req->string = (HIWORD(str) != 0);
171 req->handle = handle;
172 ret = !wine_server_call_err( req );
174 SERVER_END_REQ;
176 if (HIWORD(str)) GlobalDeleteAtom( atom );
177 return ret;
181 /***********************************************************************
182 * SetPropW (USER32.@)
184 BOOL WINAPI SetPropW( HWND hwnd, LPCWSTR str, HANDLE handle )
186 ATOM atom;
187 BOOL ret;
189 if (!HIWORD(str)) atom = LOWORD(str);
190 else if (!(atom = GlobalAddAtomW( str ))) return FALSE;
192 SERVER_START_REQ( set_window_property )
194 req->window = hwnd;
195 req->atom = atom;
196 req->string = (HIWORD(str) != 0);
197 req->handle = handle;
198 ret = !wine_server_call_err( req );
200 SERVER_END_REQ;
202 if (HIWORD(str)) GlobalDeleteAtom( atom );
203 return ret;
207 /***********************************************************************
208 * RemovePropA (USER32.@)
210 HANDLE WINAPI RemovePropA( HWND hwnd, LPCSTR str )
212 ATOM atom;
213 HANDLE ret = 0;
215 if (!HIWORD(str)) return RemovePropW( hwnd, MAKEINTATOMW(LOWORD(str)) );
217 if ((atom = GlobalAddAtomA( str )))
219 ret = RemovePropW( hwnd, MAKEINTATOMW(atom) );
220 GlobalDeleteAtom( atom );
222 return ret;
226 /***********************************************************************
227 * RemovePropW (USER32.@)
229 HANDLE WINAPI RemovePropW( HWND hwnd, LPCWSTR str )
231 ATOM atom;
232 HANDLE ret = 0;
234 if (!HIWORD(str)) atom = LOWORD(str);
235 else if (!(atom = GlobalAddAtomW( str ))) return 0;
237 SERVER_START_REQ( remove_window_property )
239 req->window = hwnd;
240 req->atom = atom;
241 if (!wine_server_call_err( req )) ret = reply->handle;
243 SERVER_END_REQ;
245 if (HIWORD(str)) GlobalDeleteAtom( atom );
246 return ret;
250 /***********************************************************************
251 * EnumPropsExA (USER32.@)
253 INT WINAPI EnumPropsExA(HWND hwnd, PROPENUMPROCEXA func, LPARAM lParam)
255 int ret = -1, i, count;
256 property_data_t *list = get_properties( hwnd, &count );
258 if (list)
260 for (i = 0; i < count; i++)
262 char string[ATOM_BUFFER_SIZE];
263 if (!GlobalGetAtomNameA( list[i].atom, string, ATOM_BUFFER_SIZE )) continue;
264 if (!(ret = func( hwnd, string, list[i].handle, lParam ))) break;
266 HeapFree( GetProcessHeap(), 0, list );
268 return ret;
272 /***********************************************************************
273 * EnumPropsExW (USER32.@)
275 INT WINAPI EnumPropsExW(HWND hwnd, PROPENUMPROCEXW func, LPARAM lParam)
277 int ret = -1, i, count;
278 property_data_t *list = get_properties( hwnd, &count );
280 if (list)
282 for (i = 0; i < count; i++)
284 WCHAR string[ATOM_BUFFER_SIZE];
285 if (!GlobalGetAtomNameW( list[i].atom, string, ATOM_BUFFER_SIZE )) continue;
286 if (!(ret = func( hwnd, string, list[i].handle, lParam ))) break;
288 HeapFree( GetProcessHeap(), 0, list );
290 return ret;
294 /***********************************************************************
295 * EnumProps (USER.27)
297 INT16 WINAPI EnumProps16( HWND16 hwnd, PROPENUMPROC16 func )
299 int ret = -1, i, count;
300 property_data_t *list = get_properties( HWND_32(hwnd), &count );
302 if (list)
304 char string[ATOM_BUFFER_SIZE];
305 SEGPTR segptr = MapLS( string );
306 WORD args[4];
307 DWORD result;
309 for (i = 0; i < count; i++)
311 if (list[i].string) /* it was a string originally */
313 if (!GlobalGetAtomNameA( list[i].atom, string, ATOM_BUFFER_SIZE )) continue;
314 args[3] = hwnd;
315 args[2] = SELECTOROF(segptr);
316 args[1] = OFFSETOF(segptr);
317 args[0] = LOWORD(list[i].handle);
319 else
321 args[3] = hwnd;
322 args[2] = 0;
323 args[1] = list[i].atom;
324 args[0] = LOWORD(list[i].handle);
326 WOWCallback16Ex( (DWORD)func, WCB16_PASCAL, sizeof(args), args, &result );
327 if (!(ret = LOWORD(result))) break;
329 UnMapLS( segptr );
330 HeapFree( GetProcessHeap(), 0, list );
332 return ret;