Silence some warnings due to casts between pointer and integers of
[wine/multimedia.git] / dlls / user / property.c
blobde4e5d9e7ebccdab28ce87f4d94905c058796e92
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
33 /* ### start build ### */
34 extern WORD CALLBACK PROP_CallTo16_word_wlw(PROPENUMPROC16,WORD,LONG,WORD);
35 /* ### stop build ### */
37 /***********************************************************************
38 * get_properties
40 * Retrieve the list of properties of a given window.
41 * Returned buffer must be freed by caller.
43 static property_data_t *get_properties( HWND hwnd, int *count )
45 property_data_t *data;
46 int total = 32;
48 while (total)
50 int res = 0;
51 if (!(data = HeapAlloc( GetProcessHeap(), 0, total * sizeof(*data) ))) break;
52 *count = 0;
53 SERVER_START_REQ( get_window_properties )
55 req->window = hwnd;
56 wine_server_add_data( req, data, total * sizeof(*data) );
57 if (!wine_server_call( req )) res = reply->total;
59 SERVER_END_REQ;
60 if (res && res <= total)
62 *count = res;
63 return data;
65 HeapFree( GetProcessHeap(), 0, data );
66 total = res; /* restart with larger buffer */
68 return NULL;
72 /***********************************************************************
73 * EnumPropsA_relay
75 * relay to call the EnumProps callback function from EnumPropsEx
77 static BOOL CALLBACK EnumPropsA_relay( HWND hwnd, LPCSTR str, HANDLE handle, ULONG_PTR lparam )
79 PROPENUMPROCA func = (PROPENUMPROCA)lparam;
80 return func( hwnd, str, handle );
84 /***********************************************************************
85 * EnumPropsW_relay
87 * relay to call the EnumProps callback function from EnumPropsEx
89 static BOOL CALLBACK EnumPropsW_relay( HWND hwnd, LPCWSTR str, HANDLE handle, ULONG_PTR lparam )
91 PROPENUMPROCW func = (PROPENUMPROCW)lparam;
92 return func( hwnd, str, handle );
96 /***********************************************************************
97 * EnumPropsA (USER32.@)
99 INT WINAPI EnumPropsA( HWND hwnd, PROPENUMPROCA func )
101 return EnumPropsExA( hwnd, EnumPropsA_relay, (LPARAM)func );
105 /***********************************************************************
106 * EnumPropsW (USER32.@)
108 INT WINAPI EnumPropsW( HWND hwnd, PROPENUMPROCW func )
110 return EnumPropsExW( hwnd, EnumPropsW_relay, (LPARAM)func );
114 /***********************************************************************
115 * GetPropA (USER32.@)
117 HANDLE WINAPI GetPropA( HWND hwnd, LPCSTR str )
119 ATOM atom;
120 HANDLE ret = 0;
122 if (!HIWORD(str)) atom = LOWORD(str);
123 else if (!(atom = GlobalFindAtomA( str ))) return 0;
125 SERVER_START_REQ( get_window_property )
127 req->window = hwnd;
128 req->atom = atom;
129 if (!wine_server_call_err( req )) ret = reply->handle;
131 SERVER_END_REQ;
132 return ret;
136 /***********************************************************************
137 * GetPropW (USER32.@)
139 HANDLE WINAPI GetPropW( HWND hwnd, LPCWSTR str )
141 ATOM atom;
142 HANDLE ret = 0;
144 if (!HIWORD(str)) atom = LOWORD(str);
145 else if (!(atom = GlobalFindAtomW( str ))) return 0;
147 SERVER_START_REQ( get_window_property )
149 req->window = hwnd;
150 req->atom = atom;
151 if (!wine_server_call_err( req )) ret = reply->handle;
153 SERVER_END_REQ;
154 return ret;
158 /***********************************************************************
159 * SetPropA (USER32.@)
161 BOOL WINAPI SetPropA( HWND hwnd, LPCSTR str, HANDLE handle )
163 ATOM atom;
164 BOOL ret;
166 if (!HIWORD(str)) atom = LOWORD(str);
167 else if (!(atom = GlobalAddAtomA( str ))) return FALSE;
169 SERVER_START_REQ( set_window_property )
171 req->window = hwnd;
172 req->atom = atom;
173 req->string = (HIWORD(str) != 0);
174 req->handle = handle;
175 ret = !wine_server_call_err( req );
177 SERVER_END_REQ;
179 if (HIWORD(str)) GlobalDeleteAtom( atom );
180 return ret;
184 /***********************************************************************
185 * SetPropW (USER32.@)
187 BOOL WINAPI SetPropW( HWND hwnd, LPCWSTR str, HANDLE handle )
189 ATOM atom;
190 BOOL ret;
192 if (!HIWORD(str)) atom = LOWORD(str);
193 else if (!(atom = GlobalAddAtomW( str ))) return FALSE;
195 SERVER_START_REQ( set_window_property )
197 req->window = hwnd;
198 req->atom = atom;
199 req->string = (HIWORD(str) != 0);
200 req->handle = handle;
201 ret = !wine_server_call_err( req );
203 SERVER_END_REQ;
205 if (HIWORD(str)) GlobalDeleteAtom( atom );
206 return ret;
210 /***********************************************************************
211 * RemovePropA (USER32.@)
213 HANDLE WINAPI RemovePropA( HWND hwnd, LPCSTR str )
215 ATOM atom;
216 HANDLE ret = 0;
218 if (!HIWORD(str)) return RemovePropW( hwnd, MAKEINTATOMW(LOWORD(str)) );
220 if ((atom = GlobalAddAtomA( str )))
222 ret = RemovePropW( hwnd, MAKEINTATOMW(atom) );
223 GlobalDeleteAtom( atom );
225 return ret;
229 /***********************************************************************
230 * RemovePropW (USER32.@)
232 HANDLE WINAPI RemovePropW( HWND hwnd, LPCWSTR str )
234 ATOM atom;
235 HANDLE ret = 0;
237 if (!HIWORD(str)) atom = LOWORD(str);
238 else if (!(atom = GlobalAddAtomW( str ))) return 0;
240 SERVER_START_REQ( remove_window_property )
242 req->window = hwnd;
243 req->atom = atom;
244 if (!wine_server_call_err( req )) ret = reply->handle;
246 SERVER_END_REQ;
248 if (HIWORD(str)) GlobalDeleteAtom( atom );
249 return ret;
253 /***********************************************************************
254 * EnumPropsExA (USER32.@)
256 INT WINAPI EnumPropsExA(HWND hwnd, PROPENUMPROCEXA func, LPARAM lParam)
258 int ret = -1, i, count;
259 property_data_t *list = get_properties( hwnd, &count );
261 if (list)
263 for (i = 0; i < count; i++)
265 char string[ATOM_BUFFER_SIZE];
266 if (!GlobalGetAtomNameA( list[i].atom, string, ATOM_BUFFER_SIZE )) continue;
267 if (!(ret = func( hwnd, string, list[i].handle, lParam ))) break;
269 HeapFree( GetProcessHeap(), 0, list );
271 return ret;
275 /***********************************************************************
276 * EnumPropsExW (USER32.@)
278 INT WINAPI EnumPropsExW(HWND hwnd, PROPENUMPROCEXW func, LPARAM lParam)
280 int ret = -1, i, count;
281 property_data_t *list = get_properties( hwnd, &count );
283 if (list)
285 for (i = 0; i < count; i++)
287 WCHAR string[ATOM_BUFFER_SIZE];
288 if (!GlobalGetAtomNameW( list[i].atom, string, ATOM_BUFFER_SIZE )) continue;
289 if (!(ret = func( hwnd, string, list[i].handle, lParam ))) break;
291 HeapFree( GetProcessHeap(), 0, list );
293 return ret;
297 /***********************************************************************
298 * EnumProps (USER.27)
300 INT16 WINAPI EnumProps16( HWND16 hwnd, PROPENUMPROC16 func )
302 int ret = -1, i, count;
303 property_data_t *list = get_properties( HWND_32(hwnd), &count );
305 if (list)
307 char string[ATOM_BUFFER_SIZE];
308 SEGPTR segptr = MapLS( string );
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 ret = PROP_CallTo16_word_wlw( func, hwnd, segptr, list[i].handle );
316 else
317 ret = PROP_CallTo16_word_wlw( func, hwnd, list[i].atom, list[i].handle );
318 if (!ret) break;
320 UnMapLS( segptr );
321 HeapFree( GetProcessHeap(), 0, list );
323 return ret;