Release 960928
[wine/multimedia.git] / windows / property.c
blob876bd58da7599bf291ab79d9748a7f57b0c3cb53
1 /*
2 * Window properties
4 * Copyright 1995, 1996 Alexandre Julliard
5 */
7 #define NO_TRANSITION_TYPES /* This file is Win32-clean */
8 #include <stdlib.h>
9 #include <string.h>
10 #include "win.h"
11 #include "heap.h"
12 #include "string32.h"
13 #include "stddebug.h"
14 #include "debug.h"
17 typedef struct tagPROPERTY
19 struct tagPROPERTY *next; /* Next property in window list */
20 HANDLE32 handle; /* User's data */
21 LPSTR string; /* Property string (or atom) */
22 } PROPERTY;
25 /***********************************************************************
26 * PROP_FindProp
28 static PROPERTY *PROP_FindProp( HWND32 hwnd, LPCSTR str )
30 PROPERTY *prop;
31 WND *pWnd = WIN_FindWndPtr( hwnd );
33 if (!pWnd) return NULL;
34 if (HIWORD(str))
36 for (prop = pWnd->pProp; prop; prop = prop->next)
37 if (HIWORD(prop->string) && !lstrcmpi32A( prop->string, str ))
38 return prop;
40 else /* atom */
42 for (prop = pWnd->pProp; (prop); prop = prop->next)
43 if (!HIWORD(prop->string) && (LOWORD(prop->string) == LOWORD(str)))
44 return prop;
46 return NULL;
50 /***********************************************************************
51 * GetProp16 (USER.25)
53 HANDLE16 GetProp16( HWND16 hwnd, LPCSTR str )
55 return (HANDLE16)GetProp32A( hwnd, str );
59 /***********************************************************************
60 * GetProp32A (USER32.280)
62 HANDLE32 GetProp32A( HWND32 hwnd, LPCSTR str )
64 PROPERTY *prop = PROP_FindProp( hwnd, str );
66 if (HIWORD(str))
67 dprintf_prop( stddeb, "GetProp(%08x,'%s'): returning %08x\n",
68 hwnd, str, prop ? prop->handle : 0 );
69 else
70 dprintf_prop( stddeb, "GetProp(%08x,#%04x): returning %08x\n",
71 hwnd, LOWORD(str), prop ? prop->handle : 0 );
73 return prop ? prop->handle : 0;
77 /***********************************************************************
78 * GetProp32W (USER32.281)
80 HANDLE32 GetProp32W( HWND32 hwnd, LPCWSTR str )
82 LPSTR strA;
83 HANDLE32 ret;
85 if (!HIWORD(str)) return GetProp32A( hwnd, (LPCSTR)(UINT32)LOWORD(str) );
86 strA = STRING32_DupUniToAnsi( str );
87 ret = GetProp32A( hwnd, strA );
88 free( strA );
89 return ret;
93 /***********************************************************************
94 * SetProp16 (USER.26)
96 BOOL16 SetProp16( HWND16 hwnd, LPCSTR str, HANDLE16 handle )
98 return (BOOL16)SetProp32A( hwnd, str, handle );
102 /***********************************************************************
103 * SetProp32A (USER32.496)
105 BOOL32 SetProp32A( HWND32 hwnd, LPCSTR str, HANDLE32 handle )
107 PROPERTY *prop;
109 if (HIWORD(str))
110 dprintf_prop( stddeb, "SetProp: %04x '%s' %08x\n", hwnd, str, handle );
111 else
112 dprintf_prop( stddeb, "SetProp: %04x #%04x %08x\n",
113 hwnd, LOWORD(str), handle );
115 if (!(prop = PROP_FindProp( hwnd, str )))
117 /* We need to create it */
118 WND *pWnd = WIN_FindWndPtr( hwnd );
119 if (!pWnd) return FALSE;
120 if (!(prop = HeapAlloc( SystemHeap, 0, sizeof(*prop) ))) return FALSE;
121 if (!(prop->string = SEGPTR_STRDUP(str)))
123 HeapFree( SystemHeap, 0, prop );
124 return FALSE;
126 prop->next = pWnd->pProp;
127 pWnd->pProp = prop;
129 prop->handle = handle;
130 return TRUE;
134 /***********************************************************************
135 * SetProp32W (USER32.497)
137 BOOL32 SetProp32W( HWND32 hwnd, LPCWSTR str, HANDLE32 handle )
139 BOOL32 ret;
140 LPSTR strA;
142 if (!HIWORD(str))
143 return SetProp32A( hwnd, (LPCSTR)(UINT32)LOWORD(str), handle );
144 strA = STRING32_DupUniToAnsi( str );
145 ret = SetProp32A( hwnd, strA, handle );
146 free( strA );
147 return ret;
151 /***********************************************************************
152 * RemoveProp16 (USER.24)
154 HANDLE16 RemoveProp16( HWND16 hwnd, LPCSTR str )
156 return (HANDLE16)RemoveProp32A( hwnd, str );
160 /***********************************************************************
161 * RemoveProp32A (USER32.441)
163 HANDLE32 RemoveProp32A( HWND32 hwnd, LPCSTR str )
165 HANDLE32 handle;
166 PROPERTY **pprop, *prop;
167 WND *pWnd = WIN_FindWndPtr( hwnd );
169 if (HIWORD(str))
170 dprintf_prop( stddeb, "RemoveProp: %04x '%s'\n", hwnd, str );
171 else
172 dprintf_prop( stddeb, "RemoveProp: %04x #%04x\n", hwnd, LOWORD(str));
175 if (!pWnd) return NULL;
176 if (HIWORD(str))
178 for (pprop=(PROPERTY**)&pWnd->pProp; (*pprop); pprop = &(*pprop)->next)
179 if (HIWORD((*pprop)->string) &&
180 !lstrcmpi32A( (*pprop)->string, str )) break;
182 else /* atom */
184 for (pprop=(PROPERTY**)&pWnd->pProp; (*pprop); pprop = &(*pprop)->next)
185 if (!HIWORD((*pprop)->string) &&
186 (LOWORD((*pprop)->string) == LOWORD(str))) break;
188 if (!*pprop) return 0;
189 prop = *pprop;
190 handle = prop->handle;
191 *pprop = prop->next;
192 SEGPTR_FREE(prop->string);
193 HeapFree( SystemHeap, 0, prop );
194 return handle;
198 /***********************************************************************
199 * RemoveProp32W (USER32.442)
201 HANDLE32 RemoveProp32W( HWND32 hwnd, LPCWSTR str )
203 LPSTR strA;
204 HANDLE32 ret;
206 if (!HIWORD(str))
207 return RemoveProp32A( hwnd, (LPCSTR)(UINT32)LOWORD(str) );
208 strA = STRING32_DupUniToAnsi( str );
209 ret = RemoveProp32A( hwnd, strA );
210 free( strA );
211 return ret;
215 /***********************************************************************
216 * PROPERTY_RemoveWindowProps
218 * Remove all properties of a window.
220 void PROPERTY_RemoveWindowProps( WND *pWnd )
222 PROPERTY *prop, *next;
224 for (prop = pWnd->pProp; (prop); prop = next)
226 next = prop->next;
227 SEGPTR_FREE( prop->string );
228 HeapFree( SystemHeap, 0, prop );
230 pWnd->pProp = NULL;
234 /***********************************************************************
235 * EnumProps16 (USER.27)
237 INT16 EnumProps16( HWND16 hwnd, PROPENUMPROC16 func )
239 PROPERTY *prop, *next;
240 WND *pWnd;
241 INT16 ret = -1;
243 dprintf_prop( stddeb, "EnumProps: %04x %08x\n", hwnd, (UINT32)func );
244 if (!(pWnd = WIN_FindWndPtr( hwnd ))) return -1;
245 for (prop = pWnd->pProp; (prop); prop = next)
247 /* Already get the next in case the callback */
248 /* function removes the current property. */
249 next = prop->next;
251 dprintf_prop( stddeb, " Callback: handle=%08x str='%s'\n",
252 prop->handle, prop->string );
253 ret = func( hwnd, SEGPTR_GET(prop->string), prop->handle );
254 if (!ret) break;
256 return ret;
260 /***********************************************************************
261 * EnumProps32A (USER32.185)
263 INT32 EnumProps32A( HWND32 hwnd, PROPENUMPROC32A func )
265 return EnumPropsEx32A( hwnd, (PROPENUMPROCEX32A)func, 0 );
269 /***********************************************************************
270 * EnumProps32W (USER32.188)
272 INT32 EnumProps32W( HWND32 hwnd, PROPENUMPROC32W func )
274 return EnumPropsEx32W( hwnd, (PROPENUMPROCEX32W)func, 0 );
278 /***********************************************************************
279 * EnumPropsEx32A (USER32.186)
281 INT32 EnumPropsEx32A( HWND32 hwnd, PROPENUMPROCEX32A func, LPARAM lParam )
283 PROPERTY *prop, *next;
284 WND *pWnd;
285 INT32 ret = -1;
287 dprintf_prop( stddeb, "EnumPropsEx32A: %04x %08x %08lx\n",
288 hwnd, (UINT32)func, lParam );
289 if (!(pWnd = WIN_FindWndPtr( hwnd ))) return -1;
290 for (prop = pWnd->pProp; (prop); prop = next)
292 /* Already get the next in case the callback */
293 /* function removes the current property. */
294 next = prop->next;
296 dprintf_prop( stddeb, " Callback: handle=%08x str='%s'\n",
297 prop->handle, prop->string );
298 ret = func( hwnd, prop->string, prop->handle, lParam );
299 if (!ret) break;
301 return ret;
305 /***********************************************************************
306 * EnumPropsEx32W (USER32.187)
308 INT32 EnumPropsEx32W( HWND32 hwnd, PROPENUMPROCEX32W func, LPARAM lParam )
310 PROPERTY *prop, *next;
311 WND *pWnd;
312 INT32 ret = -1;
314 dprintf_prop( stddeb, "EnumPropsEx32W: %04x %08x %08lx\n",
315 hwnd, (UINT32)func, lParam );
316 if (!(pWnd = WIN_FindWndPtr( hwnd ))) return -1;
317 for (prop = pWnd->pProp; (prop); prop = next)
319 /* Already get the next in case the callback */
320 /* function removes the current property. */
321 next = prop->next;
323 dprintf_prop( stddeb, " Callback: handle=%08x str='%s'\n",
324 prop->handle, prop->string );
325 if (HIWORD(prop->string))
327 LPWSTR str = STRING32_DupAnsiToUni( prop->string );
328 ret = func( hwnd, str, prop->handle, lParam );
329 free( str );
331 else
332 ret = func( hwnd, (LPCWSTR)(UINT32)LOWORD( prop->string ),
333 prop->handle, lParam );
334 if (!ret) break;
336 return ret;