4 * Copyright 1995, 1996 Alexandre Julliard
13 typedef struct tagPROPERTY
15 struct tagPROPERTY
*next
; /* Next property in window list */
16 HANDLE handle
; /* User's data */
17 LPSTR string
; /* Property string (or atom) */
21 /***********************************************************************
24 static PROPERTY
*PROP_FindProp( HWND hwnd
, LPCSTR str
)
28 WND
*pWnd
= WIN_FindWndPtr( hwnd
);
30 if (!pWnd
) return NULL
;
33 atom
= GlobalFindAtomA( str
);
34 for (prop
= pWnd
->pProp
; prop
; prop
= prop
->next
)
36 if (HIWORD(prop
->string
))
38 if (!lstrcmpiA( 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 (GlobalFindAtomA( 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
)GetPropA( hwnd
, str
);
68 /***********************************************************************
69 * GetProp32A (USER32.281)
71 HANDLE WINAPI
GetPropA( HWND 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 HANDLE WINAPI
GetPropW( HWND hwnd
, LPCWSTR str
)
94 if (!HIWORD(str
)) return GetPropA( hwnd
, (LPCSTR
)(UINT
)LOWORD(str
) );
95 strA
= HEAP_strdupWtoA( GetProcessHeap(), 0, str
);
96 ret
= GetPropA( 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
)SetPropA( hwnd
, str
, handle
);
111 /***********************************************************************
112 * SetProp32A (USER32.497)
114 BOOL WINAPI
SetPropA( HWND hwnd
, LPCSTR str
, HANDLE 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 BOOL WINAPI
SetPropW( HWND hwnd
, LPCWSTR str
, HANDLE handle
)
152 return SetPropA( hwnd
, (LPCSTR
)(UINT
)LOWORD(str
), handle
);
153 strA
= HEAP_strdupWtoA( GetProcessHeap(), 0, str
);
154 ret
= SetPropA( hwnd
, strA
, handle
);
155 HeapFree( GetProcessHeap(), 0, strA
);
160 /***********************************************************************
161 * RemoveProp16 (USER.24)
163 HANDLE16 WINAPI
RemoveProp16( HWND16 hwnd
, LPCSTR str
)
165 return (HANDLE16
)RemovePropA( hwnd
, str
);
169 /***********************************************************************
170 * RemoveProp32A (USER32.442)
172 HANDLE WINAPI
RemovePropA( HWND 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 (HANDLE
)0;
188 atom
= GlobalFindAtomA( str
);
189 for (pprop
=(PROPERTY
**)&pWnd
->pProp
; (*pprop
); pprop
= &(*pprop
)->next
)
191 if (HIWORD((*pprop
)->string
))
193 if (!lstrcmpiA( (*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 (GlobalFindAtomA( (*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 HANDLE WINAPI
RemovePropW( HWND hwnd
, LPCWSTR str
)
229 return RemovePropA( hwnd
, (LPCSTR
)(UINT
)LOWORD(str
) );
230 strA
= HEAP_strdupWtoA( GetProcessHeap(), 0, str
);
231 ret
= RemovePropA( 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
, (UINT
)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 INT WINAPI
EnumPropsA( HWND hwnd
, PROPENUMPROCA func
)
287 return EnumPropsExA( hwnd
, (PROPENUMPROCEXA
)func
, 0 );
291 /***********************************************************************
292 * EnumProps32W (USER32.189)
294 INT WINAPI
EnumPropsW( HWND hwnd
, PROPENUMPROCW func
)
296 return EnumPropsExW( hwnd
, (PROPENUMPROCEXW
)func
, 0 );
300 /***********************************************************************
301 * EnumPropsEx32A (USER32.187)
303 INT WINAPI
EnumPropsExA(HWND hwnd
, PROPENUMPROCEXA func
, LPARAM lParam
)
305 PROPERTY
*prop
, *next
;
309 TRACE(prop
, "%04x %08x %08lx\n",
310 hwnd
, (UINT
)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 INT WINAPI
EnumPropsExW(HWND hwnd
, PROPENUMPROCEXW func
, LPARAM lParam
)
332 PROPERTY
*prop
, *next
;
336 TRACE(prop
, "%04x %08x %08lx\n",
337 hwnd
, (UINT
)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
)(UINT
)LOWORD( prop
->string
),
355 prop
->handle
, lParam
);