4 * Copyright 1995, 1996 Alexandre Julliard
12 DEFAULT_DEBUG_CHANNEL(prop)
15 typedef struct tagPROPERTY
17 struct tagPROPERTY *next; /* Next property in window list */
18 HANDLE handle; /* User's data */
19 LPSTR string; /* Property string (or atom) */
23 /***********************************************************************
26 static PROPERTY *PROP_FindProp( HWND hwnd, LPCSTR str )
30 WND *pWnd = WIN_FindWndPtr( hwnd );
32 if (!pWnd) return NULL;
35 atom = GlobalFindAtomA( str );
36 for (prop = pWnd->pProp; prop; prop = prop->next)
38 if (HIWORD(prop->string))
40 if (!lstrcmpiA( prop->string, str )) goto END;
42 else if (LOWORD(prop->string) == atom) goto END;
48 for (prop = pWnd->pProp; (prop); prop = prop->next)
50 if (HIWORD(prop->string))
52 if (GlobalFindAtomA( prop->string ) == atom) goto END;
54 else if (LOWORD(prop->string) == atom) goto END;
59 WIN_ReleaseWndPtr(pWnd);
64 /***********************************************************************
67 HANDLE16 WINAPI GetProp16( HWND16 hwnd, LPCSTR str )
69 return (HANDLE16)GetPropA( hwnd, str );
73 /***********************************************************************
74 * GetProp32A (USER32.281)
76 HANDLE WINAPI GetPropA( HWND hwnd, LPCSTR str )
78 PROPERTY *prop = PROP_FindProp( hwnd, str );
81 TRACE(prop, "(%08x,'%s'): returning %08x\n",
82 hwnd, str, prop ? prop->handle : 0 );
84 TRACE(prop, "(%08x,#%04x): returning %08x\n",
85 hwnd, LOWORD(str), prop ? prop->handle : 0 );
87 return prop ? prop->handle : 0;
91 /***********************************************************************
92 * GetProp32W (USER32.282)
94 HANDLE WINAPI GetPropW( HWND hwnd, LPCWSTR str )
99 if (!HIWORD(str)) return GetPropA( hwnd, (LPCSTR)(UINT)LOWORD(str) );
100 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
101 ret = GetPropA( hwnd, strA );
102 HeapFree( GetProcessHeap(), 0, strA );
107 /***********************************************************************
108 * SetProp16 (USER.26)
110 BOOL16 WINAPI SetProp16( HWND16 hwnd, LPCSTR str, HANDLE16 handle )
112 return (BOOL16)SetPropA( hwnd, str, handle );
116 /***********************************************************************
117 * SetProp32A (USER32.497)
119 BOOL WINAPI SetPropA( HWND hwnd, LPCSTR str, HANDLE handle )
124 TRACE(prop, "%04x '%s' %08x\n", hwnd, str, handle );
126 TRACE(prop, "%04x #%04x %08x\n",
127 hwnd, LOWORD(str), handle );
129 if (!(prop = PROP_FindProp( hwnd, str )))
131 /* We need to create it */
132 WND *pWnd = WIN_FindWndPtr( hwnd );
133 if (!pWnd) return FALSE;
134 if (!(prop = HeapAlloc( SystemHeap, 0, sizeof(*prop) )))
136 WIN_ReleaseWndPtr(pWnd);
139 if (!(prop->string = SEGPTR_STRDUP(str)))
141 HeapFree( SystemHeap, 0, prop );
142 WIN_ReleaseWndPtr(pWnd);
146 prop->next = pWnd->pProp;
148 WIN_ReleaseWndPtr(pWnd);
150 prop->handle = handle;
155 /***********************************************************************
156 * SetProp32W (USER32.498)
158 BOOL WINAPI SetPropW( HWND hwnd, LPCWSTR str, HANDLE handle )
164 return SetPropA( hwnd, (LPCSTR)(UINT)LOWORD(str), handle );
165 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
166 ret = SetPropA( hwnd, strA, handle );
167 HeapFree( GetProcessHeap(), 0, strA );
172 /***********************************************************************
173 * RemoveProp16 (USER.24)
175 HANDLE16 WINAPI RemoveProp16( HWND16 hwnd, LPCSTR str )
177 return (HANDLE16)RemovePropA( hwnd, str );
181 /***********************************************************************
182 * RemoveProp32A (USER32.442)
184 HANDLE WINAPI RemovePropA( HWND hwnd, LPCSTR str )
188 PROPERTY **pprop, *prop;
189 WND *pWnd = WIN_FindWndPtr( hwnd );
192 TRACE(prop, "%04x '%s'\n", hwnd, str );
194 TRACE(prop, "%04x #%04x\n", hwnd, LOWORD(str));
197 if (!pWnd) return (HANDLE)0;
200 atom = GlobalFindAtomA( str );
201 for (pprop=(PROPERTY**)&pWnd->pProp; (*pprop); pprop = &(*pprop)->next)
203 if (HIWORD((*pprop)->string))
205 if (!lstrcmpiA( (*pprop)->string, str )) break;
207 else if (LOWORD((*pprop)->string) == atom) break;
213 for (pprop=(PROPERTY**)&pWnd->pProp; (*pprop); pprop = &(*pprop)->next)
215 if (HIWORD((*pprop)->string))
217 if (GlobalFindAtomA( (*pprop)->string ) == atom) break;
219 else if (LOWORD((*pprop)->string) == atom) break;
222 WIN_ReleaseWndPtr(pWnd);
223 if (!*pprop) return 0;
225 handle = prop->handle;
227 SEGPTR_FREE(prop->string);
228 HeapFree( SystemHeap, 0, prop );
233 /***********************************************************************
234 * RemoveProp32W (USER32.443)
236 HANDLE WINAPI RemovePropW( HWND hwnd, LPCWSTR str )
242 return RemovePropA( hwnd, (LPCSTR)(UINT)LOWORD(str) );
243 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
244 ret = RemovePropA( hwnd, strA );
245 HeapFree( GetProcessHeap(), 0, strA );
250 /***********************************************************************
251 * PROPERTY_RemoveWindowProps
253 * Remove all properties of a window.
255 void PROPERTY_RemoveWindowProps( WND *pWnd )
257 PROPERTY *prop, *next;
259 for (prop = pWnd->pProp; (prop); prop = next)
262 SEGPTR_FREE( prop->string );
263 HeapFree( SystemHeap, 0, prop );
269 /***********************************************************************
270 * EnumProps16 (USER.27)
272 INT16 WINAPI EnumProps16( HWND16 hwnd, PROPENUMPROC16 func )
274 PROPERTY *prop, *next;
278 TRACE(prop, "%04x %08x\n", hwnd, (UINT)func );
279 if (!(pWnd = WIN_FindWndPtr( hwnd ))) return -1;
280 for (prop = pWnd->pProp; (prop); prop = next)
282 /* Already get the next in case the callback */
283 /* function removes the current property. */
286 TRACE(prop, " Callback: handle=%08x str='%s'\n",
287 prop->handle, prop->string );
288 ret = func( hwnd, SEGPTR_GET(prop->string), prop->handle );
291 WIN_ReleaseWndPtr(pWnd);
296 /***********************************************************************
297 * EnumProps32A (USER32.186)
299 INT WINAPI EnumPropsA( HWND hwnd, PROPENUMPROCA func )
301 return EnumPropsExA( hwnd, (PROPENUMPROCEXA)func, 0 );
305 /***********************************************************************
306 * EnumProps32W (USER32.189)
308 INT WINAPI EnumPropsW( HWND hwnd, PROPENUMPROCW func )
310 return EnumPropsExW( hwnd, (PROPENUMPROCEXW)func, 0 );
314 /***********************************************************************
315 * EnumPropsEx32A (USER32.187)
317 INT WINAPI EnumPropsExA(HWND hwnd, PROPENUMPROCEXA func, LPARAM lParam)
319 PROPERTY *prop, *next;
323 TRACE(prop, "%04x %08x %08lx\n",
324 hwnd, (UINT)func, lParam );
325 if (!(pWnd = WIN_FindWndPtr( hwnd ))) return -1;
326 for (prop = pWnd->pProp; (prop); prop = next)
328 /* Already get the next in case the callback */
329 /* function removes the current property. */
332 TRACE(prop, " Callback: handle=%08x str='%s'\n",
333 prop->handle, prop->string );
334 ret = func( hwnd, prop->string, prop->handle, lParam );
337 WIN_ReleaseWndPtr(pWnd);
342 /***********************************************************************
343 * EnumPropsEx32W (USER32.188)
345 INT WINAPI EnumPropsExW(HWND hwnd, PROPENUMPROCEXW func, LPARAM lParam)
347 PROPERTY *prop, *next;
351 TRACE(prop, "%04x %08x %08lx\n",
352 hwnd, (UINT)func, lParam );
353 if (!(pWnd = WIN_FindWndPtr( hwnd ))) return -1;
354 for (prop = pWnd->pProp; (prop); prop = next)
356 /* Already get the next in case the callback */
357 /* function removes the current property. */
360 TRACE(prop, " Callback: handle=%08x str='%s'\n",
361 prop->handle, prop->string );
362 if (HIWORD(prop->string))
364 LPWSTR str = HEAP_strdupAtoW( GetProcessHeap(), 0, prop->string );
365 ret = func( hwnd, str, prop->handle, lParam );
366 HeapFree( GetProcessHeap(), 0, str );
369 ret = func( hwnd, (LPCWSTR)(UINT)LOWORD( prop->string ),
370 prop->handle, lParam );
373 WIN_ReleaseWndPtr(pWnd);