Move the name directive from the .spec file to the Makefile.
[wine/gsoc_dplay.git] / dlls / user / property.c
blob972066e1a85c9aec5cb9f8564eed72ef91537faa
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 "wine/winuser16.h"
26 #include "wine/server.h"
27 #include "win.h"
29 /* size of buffer needed to store an atom string */
30 #define ATOM_BUFFER_SIZE 256
32 /* ### start build ### */
33 extern WORD CALLBACK PROP_CallTo16_word_wlw(PROPENUMPROC16,WORD,LONG,WORD);
34 /* ### stop build ### */
36 /***********************************************************************
37 * get_properties
39 * Retrieve the list of properties of a given window.
40 * Returned buffer must be freed by caller.
42 static property_data_t *get_properties( HWND hwnd, int *count )
44 property_data_t *data;
45 int total = 32;
47 while (total)
49 int res = 0;
50 if (!(data = HeapAlloc( GetProcessHeap(), 0, total * sizeof(*data) ))) break;
51 *count = 0;
52 SERVER_START_REQ( get_window_properties )
54 req->window = hwnd;
55 wine_server_add_data( req, data, total * sizeof(*data) );
56 if (!wine_server_call( req )) res = reply->total;
58 SERVER_END_REQ;
59 if (res && res <= total)
61 *count = res;
62 return data;
64 HeapFree( GetProcessHeap(), 0, data );
65 total = res; /* restart with larger buffer */
67 return NULL;
71 /***********************************************************************
72 * EnumPropsA_relay
74 * relay to call the EnumProps callback function from EnumPropsEx
76 static BOOL CALLBACK EnumPropsA_relay( HWND hwnd, LPCSTR str, HANDLE handle, ULONG_PTR lparam )
78 PROPENUMPROCA func = (PROPENUMPROCA)lparam;
79 return func( hwnd, str, handle );
83 /***********************************************************************
84 * EnumPropsW_relay
86 * relay to call the EnumProps callback function from EnumPropsEx
88 static BOOL CALLBACK EnumPropsW_relay( HWND hwnd, LPCWSTR str, HANDLE handle, ULONG_PTR lparam )
90 PROPENUMPROCW func = (PROPENUMPROCW)lparam;
91 return func( hwnd, str, handle );
95 /***********************************************************************
96 * EnumPropsA (USER32.@)
98 INT WINAPI EnumPropsA( HWND hwnd, PROPENUMPROCA func )
100 return EnumPropsExA( hwnd, EnumPropsA_relay, (LPARAM)func );
104 /***********************************************************************
105 * EnumPropsW (USER32.@)
107 INT WINAPI EnumPropsW( HWND hwnd, PROPENUMPROCW func )
109 return EnumPropsExW( hwnd, EnumPropsW_relay, (LPARAM)func );
113 /***********************************************************************
114 * GetPropA (USER32.@)
116 HANDLE WINAPI GetPropA( HWND hwnd, LPCSTR str )
118 ATOM atom;
119 HANDLE ret = 0;
121 if (!HIWORD(str)) atom = LOWORD(str);
122 else if (!(atom = GlobalFindAtomA( str ))) return 0;
124 SERVER_START_REQ( get_window_property )
126 req->window = hwnd;
127 req->atom = atom;
128 if (!wine_server_call_err( req )) ret = reply->handle;
130 SERVER_END_REQ;
131 return ret;
135 /***********************************************************************
136 * GetPropW (USER32.@)
138 HANDLE WINAPI GetPropW( HWND hwnd, LPCWSTR str )
140 ATOM atom;
141 HANDLE ret = 0;
143 if (!HIWORD(str)) atom = LOWORD(str);
144 else if (!(atom = GlobalFindAtomW( str ))) return 0;
146 SERVER_START_REQ( get_window_property )
148 req->window = hwnd;
149 req->atom = atom;
150 if (!wine_server_call_err( req )) ret = reply->handle;
152 SERVER_END_REQ;
153 return ret;
157 /***********************************************************************
158 * SetPropA (USER32.@)
160 BOOL WINAPI SetPropA( HWND hwnd, LPCSTR str, HANDLE handle )
162 ATOM atom;
163 BOOL ret;
165 if (!HIWORD(str)) atom = LOWORD(str);
166 else if (!(atom = GlobalAddAtomA( str ))) return FALSE;
168 SERVER_START_REQ( set_window_property )
170 req->window = hwnd;
171 req->atom = atom;
172 req->string = (HIWORD(str) != 0);
173 req->handle = handle;
174 ret = !wine_server_call_err( req );
176 SERVER_END_REQ;
178 if (HIWORD(str)) GlobalDeleteAtom( atom );
179 return ret;
183 /***********************************************************************
184 * SetPropW (USER32.@)
186 BOOL WINAPI SetPropW( HWND hwnd, LPCWSTR str, HANDLE handle )
188 ATOM atom;
189 BOOL ret;
191 if (!HIWORD(str)) atom = LOWORD(str);
192 else if (!(atom = GlobalAddAtomW( str ))) return FALSE;
194 SERVER_START_REQ( set_window_property )
196 req->window = hwnd;
197 req->atom = atom;
198 req->string = (HIWORD(str) != 0);
199 req->handle = handle;
200 ret = !wine_server_call_err( req );
202 SERVER_END_REQ;
204 if (HIWORD(str)) GlobalDeleteAtom( atom );
205 return ret;
209 /***********************************************************************
210 * RemovePropA (USER32.@)
212 HANDLE WINAPI RemovePropA( HWND hwnd, LPCSTR str )
214 ATOM atom;
215 HANDLE ret = 0;
217 if (!HIWORD(str)) return RemovePropW( hwnd, MAKEINTATOMW(LOWORD(str)) );
219 if ((atom = GlobalAddAtomA( str )))
221 ret = RemovePropW( hwnd, MAKEINTATOMW(atom) );
222 GlobalDeleteAtom( atom );
224 return ret;
228 /***********************************************************************
229 * RemovePropW (USER32.@)
231 HANDLE WINAPI RemovePropW( HWND hwnd, LPCWSTR str )
233 ATOM atom;
234 HANDLE ret = 0;
236 if (!HIWORD(str)) atom = LOWORD(str);
237 else if (!(atom = GlobalAddAtomW( str ))) return 0;
239 SERVER_START_REQ( remove_window_property )
241 req->window = hwnd;
242 req->atom = atom;
243 if (!wine_server_call_err( req )) ret = reply->handle;
245 SERVER_END_REQ;
247 if (HIWORD(str)) GlobalDeleteAtom( atom );
248 return ret;
252 /***********************************************************************
253 * EnumPropsExA (USER32.@)
255 INT WINAPI EnumPropsExA(HWND hwnd, PROPENUMPROCEXA func, LPARAM lParam)
257 int ret = -1, i, count;
258 property_data_t *list = get_properties( hwnd, &count );
260 if (list)
262 for (i = 0; i < count; i++)
264 char string[ATOM_BUFFER_SIZE];
265 if (!GlobalGetAtomNameA( list[i].atom, string, ATOM_BUFFER_SIZE )) continue;
266 if (!(ret = func( hwnd, string, list[i].handle, lParam ))) break;
268 HeapFree( GetProcessHeap(), 0, list );
270 return ret;
274 /***********************************************************************
275 * EnumPropsExW (USER32.@)
277 INT WINAPI EnumPropsExW(HWND hwnd, PROPENUMPROCEXW func, LPARAM lParam)
279 int ret = -1, i, count;
280 property_data_t *list = get_properties( hwnd, &count );
282 if (list)
284 for (i = 0; i < count; i++)
286 WCHAR string[ATOM_BUFFER_SIZE];
287 if (!GlobalGetAtomNameW( list[i].atom, string, ATOM_BUFFER_SIZE )) continue;
288 if (!(ret = func( hwnd, string, list[i].handle, lParam ))) break;
290 HeapFree( GetProcessHeap(), 0, list );
292 return ret;
296 /***********************************************************************
297 * EnumProps (USER.27)
299 INT16 WINAPI EnumProps16( HWND16 hwnd, PROPENUMPROC16 func )
301 int ret = -1, i, count;
302 property_data_t *list = get_properties( HWND_32(hwnd), &count );
304 if (list)
306 char string[ATOM_BUFFER_SIZE];
307 SEGPTR segptr = MapLS( string );
308 for (i = 0; i < count; i++)
310 if (list[i].string) /* it was a string originally */
312 if (!GlobalGetAtomNameA( list[i].atom, string, ATOM_BUFFER_SIZE )) continue;
313 ret = PROP_CallTo16_word_wlw( func, hwnd, segptr, list[i].handle );
315 else
316 ret = PROP_CallTo16_word_wlw( func, hwnd, list[i].atom, list[i].handle );
317 if (!ret) break;
319 UnMapLS( segptr );
320 HeapFree( GetProcessHeap(), 0, list );
322 return ret;