4 * Copyright 1995, 1996 Alexandre Julliard
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) */
21 /***********************************************************************
24 static PROPERTY
*PROP_FindProp( HWND32 hwnd
, LPCSTR str
)
28 WND
*pWnd
= WIN_FindWndPtr( hwnd
);
30 if (!pWnd
) return NULL
;
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
;
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
;
59 /***********************************************************************
62 HANDLE16 WINAPI
GetProp16( HWND16 hwnd
, LPCSTR str
)
64 return (HANDLE16
)GetProp32A( hwnd
, str
);
68 /***********************************************************************
69 * GetProp32A (USER32.281)
71 HANDLE32 WINAPI
GetProp32A( HWND32 hwnd
, LPCSTR str
)
73 PROPERTY
*prop
= PROP_FindProp( hwnd
, str
);
76 TRACE(prop
, "(%08x,'%s'): returning %08x\n",
77 hwnd
, str
, prop
? prop
->handle
: 0 );
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.282)
89 HANDLE32 WINAPI
GetProp32W( HWND32 hwnd
, LPCWSTR str
)
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
);
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.497)
114 BOOL32 WINAPI
SetProp32A( HWND32 hwnd
, LPCSTR str
, HANDLE32 handle
)
119 TRACE(prop
, "%04x '%s' %08x\n", hwnd
, str
, handle
);
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
);
135 prop
->next
= pWnd
->pProp
;
138 prop
->handle
= handle
;
143 /***********************************************************************
144 * SetProp32W (USER32.498)
146 BOOL32 WINAPI
SetProp32W( HWND32 hwnd
, LPCWSTR str
, HANDLE32 handle
)
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
);
160 /***********************************************************************
161 * RemoveProp16 (USER.24)
163 HANDLE16 WINAPI
RemoveProp16( HWND16 hwnd
, LPCSTR str
)
165 return (HANDLE16
)RemoveProp32A( hwnd
, str
);
169 /***********************************************************************
170 * RemoveProp32A (USER32.442)
172 HANDLE32 WINAPI
RemoveProp32A( HWND32 hwnd
, LPCSTR str
)
176 PROPERTY
**pprop
, *prop
;
177 WND
*pWnd
= WIN_FindWndPtr( hwnd
);
180 TRACE(prop
, "%04x '%s'\n", hwnd
, str
);
182 TRACE(prop
, "%04x #%04x\n", hwnd
, LOWORD(str
));
185 if (!pWnd
) return (HANDLE32
)0;
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;
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;
212 handle
= prop
->handle
;
214 SEGPTR_FREE(prop
->string
);
215 HeapFree( SystemHeap
, 0, prop
);
220 /***********************************************************************
221 * RemoveProp32W (USER32.443)
223 HANDLE32 WINAPI
RemoveProp32W( HWND32 hwnd
, LPCWSTR 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
);
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
)
249 SEGPTR_FREE( prop
->string
);
250 HeapFree( SystemHeap
, 0, prop
);
256 /***********************************************************************
257 * EnumProps16 (USER.27)
259 INT16 WINAPI
EnumProps16( HWND16 hwnd
, PROPENUMPROC16 func
)
261 PROPERTY
*prop
, *next
;
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. */
273 TRACE(prop
, " Callback: handle=%08x str='%s'\n",
274 prop
->handle
, prop
->string
);
275 ret
= func( hwnd
, SEGPTR_GET(prop
->string
), prop
->handle
);
282 /***********************************************************************
283 * EnumProps32A (USER32.186)
285 INT32 WINAPI
EnumProps32A( HWND32 hwnd
, PROPENUMPROC32A func
)
287 return EnumPropsEx32A( hwnd
, (PROPENUMPROCEX32A
)func
, 0 );
291 /***********************************************************************
292 * EnumProps32W (USER32.189)
294 INT32 WINAPI
EnumProps32W( HWND32 hwnd
, PROPENUMPROC32W func
)
296 return EnumPropsEx32W( hwnd
, (PROPENUMPROCEX32W
)func
, 0 );
300 /***********************************************************************
301 * EnumPropsEx32A (USER32.187)
303 INT32 WINAPI
EnumPropsEx32A(HWND32 hwnd
, PROPENUMPROCEX32A func
, LPARAM lParam
)
305 PROPERTY
*prop
, *next
;
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. */
318 TRACE(prop
, " Callback: handle=%08x str='%s'\n",
319 prop
->handle
, prop
->string
);
320 ret
= func( hwnd
, prop
->string
, prop
->handle
, lParam
);
327 /***********************************************************************
328 * EnumPropsEx32W (USER32.188)
330 INT32 WINAPI
EnumPropsEx32W(HWND32 hwnd
, PROPENUMPROCEX32W func
, LPARAM lParam
)
332 PROPERTY
*prop
, *next
;
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. */
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
);
354 ret
= func( hwnd
, (LPCWSTR
)(UINT32
)LOWORD( prop
->string
),
355 prop
->handle
, lParam
);