4 * Copyright 1995, 1996 Alexandre Julliard
11 #include "wine/winuser16.h"
14 #include "debugtools.h"
16 DEFAULT_DEBUG_CHANNEL(prop
);
19 typedef struct tagPROPERTY
21 struct tagPROPERTY
*next
; /* Next property in window list */
22 HANDLE handle
; /* User's data */
23 LPSTR string
; /* Property string (or atom) */
27 /***********************************************************************
30 static PROPERTY
*PROP_FindProp( HWND hwnd
, LPCSTR str
)
34 WND
*pWnd
= WIN_FindWndPtr( hwnd
);
36 if (!pWnd
) return NULL
;
39 atom
= GlobalFindAtomA( str
);
40 for (prop
= pWnd
->pProp
; prop
; prop
= prop
->next
)
42 if (HIWORD(prop
->string
))
44 if (!lstrcmpiA( prop
->string
, str
)) goto END
;
46 else if (LOWORD(prop
->string
) == atom
) goto END
;
52 for (prop
= pWnd
->pProp
; (prop
); prop
= prop
->next
)
54 if (HIWORD(prop
->string
))
56 if (GlobalFindAtomA( prop
->string
) == atom
) goto END
;
58 else if (LOWORD(prop
->string
) == atom
) goto END
;
63 WIN_ReleaseWndPtr(pWnd
);
68 /***********************************************************************
71 HANDLE16 WINAPI
GetProp16( HWND16 hwnd
, LPCSTR str
)
73 return (HANDLE16
)GetPropA( hwnd
, str
);
77 /***********************************************************************
80 HANDLE WINAPI
GetPropA( HWND hwnd
, LPCSTR str
)
82 PROPERTY
*prop
= PROP_FindProp( hwnd
, str
);
85 TRACE("(%08x,'%s'): returning %08x\n",
86 hwnd
, str
, prop
? prop
->handle
: 0 );
88 TRACE("(%08x,#%04x): returning %08x\n",
89 hwnd
, LOWORD(str
), prop
? prop
->handle
: 0 );
91 return prop
? prop
->handle
: 0;
95 /***********************************************************************
98 HANDLE WINAPI
GetPropW( HWND hwnd
, LPCWSTR str
)
103 if (!HIWORD(str
)) return GetPropA( hwnd
, (LPCSTR
)(UINT
)LOWORD(str
) );
104 strA
= HEAP_strdupWtoA( GetProcessHeap(), 0, str
);
105 ret
= GetPropA( hwnd
, strA
);
106 HeapFree( GetProcessHeap(), 0, strA
);
111 /***********************************************************************
114 BOOL16 WINAPI
SetProp16( HWND16 hwnd
, LPCSTR str
, HANDLE16 handle
)
116 return (BOOL16
)SetPropA( hwnd
, str
, handle
);
120 /***********************************************************************
121 * SetPropA (USER32.@)
123 BOOL WINAPI
SetPropA( HWND hwnd
, LPCSTR str
, HANDLE handle
)
128 TRACE("%04x '%s' %08x\n", hwnd
, str
, handle
);
130 TRACE("%04x #%04x %08x\n",
131 hwnd
, LOWORD(str
), handle
);
133 if (!(prop
= PROP_FindProp( hwnd
, str
)))
135 /* We need to create it */
136 WND
*pWnd
= WIN_FindWndPtr( hwnd
);
137 if (!pWnd
) return FALSE
;
138 if (!(prop
= HeapAlloc( SystemHeap
, 0, sizeof(*prop
) )))
140 WIN_ReleaseWndPtr(pWnd
);
143 if (!(prop
->string
= SEGPTR_STRDUP(str
)))
145 HeapFree( SystemHeap
, 0, prop
);
146 WIN_ReleaseWndPtr(pWnd
);
150 prop
->next
= pWnd
->pProp
;
152 WIN_ReleaseWndPtr(pWnd
);
154 prop
->handle
= handle
;
159 /***********************************************************************
160 * SetPropW (USER32.@)
162 BOOL WINAPI
SetPropW( HWND hwnd
, LPCWSTR str
, HANDLE handle
)
168 return SetPropA( hwnd
, (LPCSTR
)(UINT
)LOWORD(str
), handle
);
169 strA
= HEAP_strdupWtoA( GetProcessHeap(), 0, str
);
170 ret
= SetPropA( hwnd
, strA
, handle
);
171 HeapFree( GetProcessHeap(), 0, strA
);
176 /***********************************************************************
177 * RemoveProp (USER.24)
179 HANDLE16 WINAPI
RemoveProp16( HWND16 hwnd
, LPCSTR str
)
181 return (HANDLE16
)RemovePropA( hwnd
, str
);
185 /***********************************************************************
186 * RemovePropA (USER32.@)
188 HANDLE WINAPI
RemovePropA( HWND hwnd
, LPCSTR str
)
192 PROPERTY
**pprop
, *prop
;
193 WND
*pWnd
= WIN_FindWndPtr( hwnd
);
196 TRACE("%04x '%s'\n", hwnd
, str
);
198 TRACE("%04x #%04x\n", hwnd
, LOWORD(str
));
201 if (!pWnd
) return (HANDLE
)0;
204 atom
= GlobalFindAtomA( str
);
205 for (pprop
=(PROPERTY
**)&pWnd
->pProp
; (*pprop
); pprop
= &(*pprop
)->next
)
207 if (HIWORD((*pprop
)->string
))
209 if (!lstrcmpiA( (*pprop
)->string
, str
)) break;
211 else if (LOWORD((*pprop
)->string
) == atom
) break;
217 for (pprop
=(PROPERTY
**)&pWnd
->pProp
; (*pprop
); pprop
= &(*pprop
)->next
)
219 if (HIWORD((*pprop
)->string
))
221 if (GlobalFindAtomA( (*pprop
)->string
) == atom
) break;
223 else if (LOWORD((*pprop
)->string
) == atom
) break;
226 WIN_ReleaseWndPtr(pWnd
);
227 if (!*pprop
) return 0;
229 handle
= prop
->handle
;
231 SEGPTR_FREE(prop
->string
);
232 HeapFree( SystemHeap
, 0, prop
);
237 /***********************************************************************
238 * RemovePropW (USER32.@)
240 HANDLE WINAPI
RemovePropW( HWND hwnd
, LPCWSTR str
)
246 return RemovePropA( hwnd
, (LPCSTR
)(UINT
)LOWORD(str
) );
247 strA
= HEAP_strdupWtoA( GetProcessHeap(), 0, str
);
248 ret
= RemovePropA( hwnd
, strA
);
249 HeapFree( GetProcessHeap(), 0, strA
);
254 /***********************************************************************
255 * PROPERTY_RemoveWindowProps
257 * Remove all properties of a window.
259 void PROPERTY_RemoveWindowProps( WND
*pWnd
)
261 PROPERTY
*prop
, *next
;
263 for (prop
= pWnd
->pProp
; (prop
); prop
= next
)
266 SEGPTR_FREE( prop
->string
);
267 HeapFree( SystemHeap
, 0, prop
);
273 /***********************************************************************
274 * EnumProps (USER.27)
276 INT16 WINAPI
EnumProps16( HWND16 hwnd
, PROPENUMPROC16 func
)
278 PROPERTY
*prop
, *next
;
282 TRACE("%04x %08x\n", hwnd
, (UINT
)func
);
283 if (!(pWnd
= WIN_FindWndPtr( hwnd
))) return -1;
284 for (prop
= pWnd
->pProp
; (prop
); prop
= next
)
286 /* Already get the next in case the callback */
287 /* function removes the current property. */
290 TRACE(" Callback: handle=%08x str='%s'\n",
291 prop
->handle
, prop
->string
);
292 ret
= func( hwnd
, SEGPTR_GET(prop
->string
), prop
->handle
);
295 WIN_ReleaseWndPtr(pWnd
);
300 /***********************************************************************
301 * EnumPropsA (USER32.@)
303 INT WINAPI
EnumPropsA( HWND hwnd
, PROPENUMPROCA func
)
305 return EnumPropsExA( hwnd
, (PROPENUMPROCEXA
)func
, 0 );
309 /***********************************************************************
310 * EnumPropsW (USER32.@)
312 INT WINAPI
EnumPropsW( HWND hwnd
, PROPENUMPROCW func
)
314 return EnumPropsExW( hwnd
, (PROPENUMPROCEXW
)func
, 0 );
318 /***********************************************************************
319 * EnumPropsExA (USER32.@)
321 INT WINAPI
EnumPropsExA(HWND hwnd
, PROPENUMPROCEXA func
, LPARAM lParam
)
323 PROPERTY
*prop
, *next
;
327 TRACE("%04x %08x %08lx\n",
328 hwnd
, (UINT
)func
, lParam
);
329 if (!(pWnd
= WIN_FindWndPtr( hwnd
))) return -1;
330 for (prop
= pWnd
->pProp
; (prop
); prop
= next
)
332 /* Already get the next in case the callback */
333 /* function removes the current property. */
336 TRACE(" Callback: handle=%08x str='%s'\n",
337 prop
->handle
, prop
->string
);
338 ret
= func( hwnd
, prop
->string
, prop
->handle
, lParam
);
341 WIN_ReleaseWndPtr(pWnd
);
346 /***********************************************************************
347 * EnumPropsExW (USER32.@)
349 INT WINAPI
EnumPropsExW(HWND hwnd
, PROPENUMPROCEXW func
, LPARAM lParam
)
351 PROPERTY
*prop
, *next
;
355 TRACE("%04x %08x %08lx\n",
356 hwnd
, (UINT
)func
, lParam
);
357 if (!(pWnd
= WIN_FindWndPtr( hwnd
))) return -1;
358 for (prop
= pWnd
->pProp
; (prop
); prop
= next
)
360 /* Already get the next in case the callback */
361 /* function removes the current property. */
364 TRACE(" Callback: handle=%08x str='%s'\n",
365 prop
->handle
, prop
->string
);
366 if (HIWORD(prop
->string
))
368 LPWSTR str
= HEAP_strdupAtoW( GetProcessHeap(), 0, prop
->string
);
369 ret
= func( hwnd
, str
, prop
->handle
, lParam
);
370 HeapFree( GetProcessHeap(), 0, str
);
373 ret
= func( hwnd
, (LPCWSTR
)(UINT
)LOWORD( prop
->string
),
374 prop
->handle
, lParam
);
377 WIN_ReleaseWndPtr(pWnd
);