4 * Copyright 1995, 1996 Alexandre Julliard
9 #include "wine/winuser16.h"
12 #include "debugtools.h"
14 DEFAULT_DEBUG_CHANNEL(prop)
17 typedef struct tagPROPERTY
19 struct tagPROPERTY *next; /* Next property in window list */
20 HANDLE handle; /* User's data */
21 LPSTR string; /* Property string (or atom) */
25 /***********************************************************************
28 static PROPERTY *PROP_FindProp( HWND hwnd, LPCSTR str )
32 WND *pWnd = WIN_FindWndPtr( hwnd );
34 if (!pWnd) return NULL;
37 atom = GlobalFindAtomA( str );
38 for (prop = pWnd->pProp; prop; prop = prop->next)
40 if (HIWORD(prop->string))
42 if (!lstrcmpiA( prop->string, str )) goto END;
44 else if (LOWORD(prop->string) == atom) goto END;
50 for (prop = pWnd->pProp; (prop); prop = prop->next)
52 if (HIWORD(prop->string))
54 if (GlobalFindAtomA( prop->string ) == atom) goto END;
56 else if (LOWORD(prop->string) == atom) goto END;
61 WIN_ReleaseWndPtr(pWnd);
66 /***********************************************************************
69 HANDLE16 WINAPI GetProp16( HWND16 hwnd, LPCSTR str )
71 return (HANDLE16)GetPropA( hwnd, str );
75 /***********************************************************************
76 * GetProp32A (USER32.281)
78 HANDLE WINAPI GetPropA( HWND hwnd, LPCSTR str )
80 PROPERTY *prop = PROP_FindProp( hwnd, str );
83 TRACE("(%08x,'%s'): returning %08x\n",
84 hwnd, str, prop ? prop->handle : 0 );
86 TRACE("(%08x,#%04x): returning %08x\n",
87 hwnd, LOWORD(str), prop ? prop->handle : 0 );
89 return prop ? prop->handle : 0;
93 /***********************************************************************
94 * GetProp32W (USER32.282)
96 HANDLE WINAPI GetPropW( HWND hwnd, LPCWSTR str )
101 if (!HIWORD(str)) return GetPropA( hwnd, (LPCSTR)(UINT)LOWORD(str) );
102 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
103 ret = GetPropA( hwnd, strA );
104 HeapFree( GetProcessHeap(), 0, strA );
109 /***********************************************************************
110 * SetProp16 (USER.26)
112 BOOL16 WINAPI SetProp16( HWND16 hwnd, LPCSTR str, HANDLE16 handle )
114 return (BOOL16)SetPropA( hwnd, str, handle );
118 /***********************************************************************
119 * SetProp32A (USER32.497)
121 BOOL WINAPI SetPropA( HWND hwnd, LPCSTR str, HANDLE handle )
126 TRACE("%04x '%s' %08x\n", hwnd, str, handle );
128 TRACE("%04x #%04x %08x\n",
129 hwnd, LOWORD(str), handle );
131 if (!(prop = PROP_FindProp( hwnd, str )))
133 /* We need to create it */
134 WND *pWnd = WIN_FindWndPtr( hwnd );
135 if (!pWnd) return FALSE;
136 if (!(prop = HeapAlloc( SystemHeap, 0, sizeof(*prop) )))
138 WIN_ReleaseWndPtr(pWnd);
141 if (!(prop->string = SEGPTR_STRDUP(str)))
143 HeapFree( SystemHeap, 0, prop );
144 WIN_ReleaseWndPtr(pWnd);
148 prop->next = pWnd->pProp;
150 WIN_ReleaseWndPtr(pWnd);
152 prop->handle = handle;
157 /***********************************************************************
158 * SetProp32W (USER32.498)
160 BOOL WINAPI SetPropW( HWND hwnd, LPCWSTR str, HANDLE handle )
166 return SetPropA( hwnd, (LPCSTR)(UINT)LOWORD(str), handle );
167 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
168 ret = SetPropA( hwnd, strA, handle );
169 HeapFree( GetProcessHeap(), 0, strA );
174 /***********************************************************************
175 * RemoveProp16 (USER.24)
177 HANDLE16 WINAPI RemoveProp16( HWND16 hwnd, LPCSTR str )
179 return (HANDLE16)RemovePropA( hwnd, str );
183 /***********************************************************************
184 * RemoveProp32A (USER32.442)
186 HANDLE WINAPI RemovePropA( HWND hwnd, LPCSTR str )
190 PROPERTY **pprop, *prop;
191 WND *pWnd = WIN_FindWndPtr( hwnd );
194 TRACE("%04x '%s'\n", hwnd, str );
196 TRACE("%04x #%04x\n", hwnd, LOWORD(str));
199 if (!pWnd) return (HANDLE)0;
202 atom = GlobalFindAtomA( str );
203 for (pprop=(PROPERTY**)&pWnd->pProp; (*pprop); pprop = &(*pprop)->next)
205 if (HIWORD((*pprop)->string))
207 if (!lstrcmpiA( (*pprop)->string, str )) break;
209 else if (LOWORD((*pprop)->string) == atom) break;
215 for (pprop=(PROPERTY**)&pWnd->pProp; (*pprop); pprop = &(*pprop)->next)
217 if (HIWORD((*pprop)->string))
219 if (GlobalFindAtomA( (*pprop)->string ) == atom) break;
221 else if (LOWORD((*pprop)->string) == atom) break;
224 WIN_ReleaseWndPtr(pWnd);
225 if (!*pprop) return 0;
227 handle = prop->handle;
229 SEGPTR_FREE(prop->string);
230 HeapFree( SystemHeap, 0, prop );
235 /***********************************************************************
236 * RemoveProp32W (USER32.443)
238 HANDLE WINAPI RemovePropW( HWND hwnd, LPCWSTR str )
244 return RemovePropA( hwnd, (LPCSTR)(UINT)LOWORD(str) );
245 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
246 ret = RemovePropA( hwnd, strA );
247 HeapFree( GetProcessHeap(), 0, strA );
252 /***********************************************************************
253 * PROPERTY_RemoveWindowProps
255 * Remove all properties of a window.
257 void PROPERTY_RemoveWindowProps( WND *pWnd )
259 PROPERTY *prop, *next;
261 for (prop = pWnd->pProp; (prop); prop = next)
264 SEGPTR_FREE( prop->string );
265 HeapFree( SystemHeap, 0, prop );
271 /***********************************************************************
272 * EnumProps16 (USER.27)
274 INT16 WINAPI EnumProps16( HWND16 hwnd, PROPENUMPROC16 func )
276 PROPERTY *prop, *next;
280 TRACE("%04x %08x\n", hwnd, (UINT)func );
281 if (!(pWnd = WIN_FindWndPtr( hwnd ))) return -1;
282 for (prop = pWnd->pProp; (prop); prop = next)
284 /* Already get the next in case the callback */
285 /* function removes the current property. */
288 TRACE(" Callback: handle=%08x str='%s'\n",
289 prop->handle, prop->string );
290 ret = func( hwnd, SEGPTR_GET(prop->string), prop->handle );
293 WIN_ReleaseWndPtr(pWnd);
298 /***********************************************************************
299 * EnumProps32A (USER32.186)
301 INT WINAPI EnumPropsA( HWND hwnd, PROPENUMPROCA func )
303 return EnumPropsExA( hwnd, (PROPENUMPROCEXA)func, 0 );
307 /***********************************************************************
308 * EnumProps32W (USER32.189)
310 INT WINAPI EnumPropsW( HWND hwnd, PROPENUMPROCW func )
312 return EnumPropsExW( hwnd, (PROPENUMPROCEXW)func, 0 );
316 /***********************************************************************
317 * EnumPropsEx32A (USER32.187)
319 INT WINAPI EnumPropsExA(HWND hwnd, PROPENUMPROCEXA func, LPARAM lParam)
321 PROPERTY *prop, *next;
325 TRACE("%04x %08x %08lx\n",
326 hwnd, (UINT)func, lParam );
327 if (!(pWnd = WIN_FindWndPtr( hwnd ))) return -1;
328 for (prop = pWnd->pProp; (prop); prop = next)
330 /* Already get the next in case the callback */
331 /* function removes the current property. */
334 TRACE(" Callback: handle=%08x str='%s'\n",
335 prop->handle, prop->string );
336 ret = func( hwnd, prop->string, prop->handle, lParam );
339 WIN_ReleaseWndPtr(pWnd);
344 /***********************************************************************
345 * EnumPropsEx32W (USER32.188)
347 INT WINAPI EnumPropsExW(HWND hwnd, PROPENUMPROCEXW func, LPARAM lParam)
349 PROPERTY *prop, *next;
353 TRACE("%04x %08x %08lx\n",
354 hwnd, (UINT)func, lParam );
355 if (!(pWnd = WIN_FindWndPtr( hwnd ))) return -1;
356 for (prop = pWnd->pProp; (prop); prop = next)
358 /* Already get the next in case the callback */
359 /* function removes the current property. */
362 TRACE(" Callback: handle=%08x str='%s'\n",
363 prop->handle, prop->string );
364 if (HIWORD(prop->string))
366 LPWSTR str = HEAP_strdupAtoW( GetProcessHeap(), 0, prop->string );
367 ret = func( hwnd, str, prop->handle, lParam );
368 HeapFree( GetProcessHeap(), 0, str );
371 ret = func( hwnd, (LPCWSTR)(UINT)LOWORD( prop->string ),
372 prop->handle, lParam );
375 WIN_ReleaseWndPtr(pWnd);