Release 980329
[wine.git] / windows / property.c
blob9c3ac18c1f0cfa03a115773c8ace57b585fc2b1e
1 /*
2 * Window properties
4 * Copyright 1995, 1996 Alexandre Julliard
5 */
7 #include <string.h>
8 #include "win.h"
9 #include "heap.h"
10 #include "debug.h"
13 typedef struct tagPROPERTY
15 struct tagPROPERTY *next; /* Next property in window list */
16 HANDLE32 handle; /* User's data */
17 LPSTR string; /* Property string (or atom) */
18 } PROPERTY;
21 /***********************************************************************
22 * PROP_FindProp
24 static PROPERTY *PROP_FindProp( HWND32 hwnd, LPCSTR str )
26 ATOM atom;
27 PROPERTY *prop;
28 WND *pWnd = WIN_FindWndPtr( hwnd );
30 if (!pWnd) return NULL;
31 if (HIWORD(str))
33 atom = GlobalFindAtom32A( str );
34 for (prop = pWnd->pProp; prop; prop = prop->next)
36 if (HIWORD(prop->string))
38 if (!lstrcmpi32A( prop->string, str )) return prop;
40 else if (LOWORD(prop->string) == atom) return prop;
43 else /* atom */
45 atom = LOWORD(str);
46 for (prop = pWnd->pProp; (prop); prop = prop->next)
48 if (HIWORD(prop->string))
50 if (GlobalFindAtom32A( prop->string ) == atom) return prop;
52 else if (LOWORD(prop->string) == atom) return prop;
55 return NULL;
59 /***********************************************************************
60 * GetProp16 (USER.25)
62 HANDLE16 WINAPI GetProp16( HWND16 hwnd, LPCSTR str )
64 return (HANDLE16)GetProp32A( hwnd, str );
68 /***********************************************************************
69 * GetProp32A (USER32.280)
71 HANDLE32 WINAPI GetProp32A( HWND32 hwnd, LPCSTR str )
73 PROPERTY *prop = PROP_FindProp( hwnd, str );
75 if (HIWORD(str))
76 TRACE(prop, "(%08x,'%s'): returning %08x\n",
77 hwnd, str, prop ? prop->handle : 0 );
78 else
79 TRACE(prop, "(%08x,#%04x): returning %08x\n",
80 hwnd, LOWORD(str), prop ? prop->handle : 0 );
82 return prop ? prop->handle : 0;
86 /***********************************************************************
87 * GetProp32W (USER32.281)
89 HANDLE32 WINAPI GetProp32W( HWND32 hwnd, LPCWSTR str )
91 LPSTR strA;
92 HANDLE32 ret;
94 if (!HIWORD(str)) return GetProp32A( hwnd, (LPCSTR)(UINT32)LOWORD(str) );
95 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
96 ret = GetProp32A( hwnd, strA );
97 HeapFree( GetProcessHeap(), 0, strA );
98 return ret;
102 /***********************************************************************
103 * SetProp16 (USER.26)
105 BOOL16 WINAPI SetProp16( HWND16 hwnd, LPCSTR str, HANDLE16 handle )
107 return (BOOL16)SetProp32A( hwnd, str, handle );
111 /***********************************************************************
112 * SetProp32A (USER32.496)
114 BOOL32 WINAPI SetProp32A( HWND32 hwnd, LPCSTR str, HANDLE32 handle )
116 PROPERTY *prop;
118 if (HIWORD(str))
119 TRACE(prop, "%04x '%s' %08x\n", hwnd, str, handle );
120 else
121 TRACE(prop, "%04x #%04x %08x\n",
122 hwnd, LOWORD(str), handle );
124 if (!(prop = PROP_FindProp( hwnd, str )))
126 /* We need to create it */
127 WND *pWnd = WIN_FindWndPtr( hwnd );
128 if (!pWnd) return FALSE;
129 if (!(prop = HeapAlloc( SystemHeap, 0, sizeof(*prop) ))) return FALSE;
130 if (!(prop->string = SEGPTR_STRDUP(str)))
132 HeapFree( SystemHeap, 0, prop );
133 return FALSE;
135 prop->next = pWnd->pProp;
136 pWnd->pProp = prop;
138 prop->handle = handle;
139 return TRUE;
143 /***********************************************************************
144 * SetProp32W (USER32.497)
146 BOOL32 WINAPI SetProp32W( HWND32 hwnd, LPCWSTR str, HANDLE32 handle )
148 BOOL32 ret;
149 LPSTR strA;
151 if (!HIWORD(str))
152 return SetProp32A( hwnd, (LPCSTR)(UINT32)LOWORD(str), handle );
153 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
154 ret = SetProp32A( hwnd, strA, handle );
155 HeapFree( GetProcessHeap(), 0, strA );
156 return ret;
160 /***********************************************************************
161 * RemoveProp16 (USER.24)
163 HANDLE16 WINAPI RemoveProp16( HWND16 hwnd, LPCSTR str )
165 return (HANDLE16)RemoveProp32A( hwnd, str );
169 /***********************************************************************
170 * RemoveProp32A (USER32.441)
172 HANDLE32 WINAPI RemoveProp32A( HWND32 hwnd, LPCSTR str )
174 ATOM atom;
175 HANDLE32 handle;
176 PROPERTY **pprop, *prop;
177 WND *pWnd = WIN_FindWndPtr( hwnd );
179 if (HIWORD(str))
180 TRACE(prop, "%04x '%s'\n", hwnd, str );
181 else
182 TRACE(prop, "%04x #%04x\n", hwnd, LOWORD(str));
185 if (!pWnd) return NULL;
186 if (HIWORD(str))
188 atom = GlobalFindAtom32A( str );
189 for (pprop=(PROPERTY**)&pWnd->pProp; (*pprop); pprop = &(*pprop)->next)
191 if (HIWORD((*pprop)->string))
193 if (!lstrcmpi32A( (*pprop)->string, str )) break;
195 else if (LOWORD((*pprop)->string) == atom) break;
198 else /* atom */
200 atom = LOWORD(str);
201 for (pprop=(PROPERTY**)&pWnd->pProp; (*pprop); pprop = &(*pprop)->next)
203 if (HIWORD((*pprop)->string))
205 if (GlobalFindAtom32A( (*pprop)->string ) == atom) break;
207 else if (LOWORD((*pprop)->string) == atom) break;
210 if (!*pprop) return 0;
211 prop = *pprop;
212 handle = prop->handle;
213 *pprop = prop->next;
214 SEGPTR_FREE(prop->string);
215 HeapFree( SystemHeap, 0, prop );
216 return handle;
220 /***********************************************************************
221 * RemoveProp32W (USER32.442)
223 HANDLE32 WINAPI RemoveProp32W( HWND32 hwnd, LPCWSTR str )
225 LPSTR strA;
226 HANDLE32 ret;
228 if (!HIWORD(str))
229 return RemoveProp32A( hwnd, (LPCSTR)(UINT32)LOWORD(str) );
230 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
231 ret = RemoveProp32A( hwnd, strA );
232 HeapFree( GetProcessHeap(), 0, strA );
233 return ret;
237 /***********************************************************************
238 * PROPERTY_RemoveWindowProps
240 * Remove all properties of a window.
242 void PROPERTY_RemoveWindowProps( WND *pWnd )
244 PROPERTY *prop, *next;
246 for (prop = pWnd->pProp; (prop); prop = next)
248 next = prop->next;
249 SEGPTR_FREE( prop->string );
250 HeapFree( SystemHeap, 0, prop );
252 pWnd->pProp = NULL;
256 /***********************************************************************
257 * EnumProps16 (USER.27)
259 INT16 WINAPI EnumProps16( HWND16 hwnd, PROPENUMPROC16 func )
261 PROPERTY *prop, *next;
262 WND *pWnd;
263 INT16 ret = -1;
265 TRACE(prop, "%04x %08x\n", hwnd, (UINT32)func );
266 if (!(pWnd = WIN_FindWndPtr( hwnd ))) return -1;
267 for (prop = pWnd->pProp; (prop); prop = next)
269 /* Already get the next in case the callback */
270 /* function removes the current property. */
271 next = prop->next;
273 TRACE(prop, " Callback: handle=%08x str='%s'\n",
274 prop->handle, prop->string );
275 ret = func( hwnd, SEGPTR_GET(prop->string), prop->handle );
276 if (!ret) break;
278 return ret;
282 /***********************************************************************
283 * EnumProps32A (USER32.185)
285 INT32 WINAPI EnumProps32A( HWND32 hwnd, PROPENUMPROC32A func )
287 return EnumPropsEx32A( hwnd, (PROPENUMPROCEX32A)func, 0 );
291 /***********************************************************************
292 * EnumProps32W (USER32.188)
294 INT32 WINAPI EnumProps32W( HWND32 hwnd, PROPENUMPROC32W func )
296 return EnumPropsEx32W( hwnd, (PROPENUMPROCEX32W)func, 0 );
300 /***********************************************************************
301 * EnumPropsEx32A (USER32.186)
303 INT32 WINAPI EnumPropsEx32A(HWND32 hwnd, PROPENUMPROCEX32A func, LPARAM lParam)
305 PROPERTY *prop, *next;
306 WND *pWnd;
307 INT32 ret = -1;
309 TRACE(prop, "%04x %08x %08lx\n",
310 hwnd, (UINT32)func, lParam );
311 if (!(pWnd = WIN_FindWndPtr( hwnd ))) return -1;
312 for (prop = pWnd->pProp; (prop); prop = next)
314 /* Already get the next in case the callback */
315 /* function removes the current property. */
316 next = prop->next;
318 TRACE(prop, " Callback: handle=%08x str='%s'\n",
319 prop->handle, prop->string );
320 ret = func( hwnd, prop->string, prop->handle, lParam );
321 if (!ret) break;
323 return ret;
327 /***********************************************************************
328 * EnumPropsEx32W (USER32.187)
330 INT32 WINAPI EnumPropsEx32W(HWND32 hwnd, PROPENUMPROCEX32W func, LPARAM lParam)
332 PROPERTY *prop, *next;
333 WND *pWnd;
334 INT32 ret = -1;
336 TRACE(prop, "%04x %08x %08lx\n",
337 hwnd, (UINT32)func, lParam );
338 if (!(pWnd = WIN_FindWndPtr( hwnd ))) return -1;
339 for (prop = pWnd->pProp; (prop); prop = next)
341 /* Already get the next in case the callback */
342 /* function removes the current property. */
343 next = prop->next;
345 TRACE(prop, " Callback: handle=%08x str='%s'\n",
346 prop->handle, prop->string );
347 if (HIWORD(prop->string))
349 LPWSTR str = HEAP_strdupAtoW( GetProcessHeap(), 0, prop->string );
350 ret = func( hwnd, str, prop->handle, lParam );
351 HeapFree( GetProcessHeap(), 0, str );
353 else
354 ret = func( hwnd, (LPCWSTR)(UINT32)LOWORD( prop->string ),
355 prop->handle, lParam );
356 if (!ret) break;
358 return ret;