Release 960811
[wine/hacks.git] / windows / property.c
blob4b0796b88c688307a847c907c4b74380049d6081
1 /*
2 * Window properties
4 * Copyright 1995, 1996 Alexandre Julliard
5 */
7 #define NO_TRANSITION_TYPES /* This file is Win32-clean */
8 #include <stdlib.h>
9 #include <string.h>
10 #include "win.h"
11 #include "heap.h"
12 #include "string32.h"
13 #include "stddebug.h"
14 #include "debug.h"
17 typedef struct tagPROPERTY
19 struct tagPROPERTY *next; /* Next property in window list */
20 HANDLE32 handle; /* User's data */
21 LPSTR string; /* Property string (or atom) */
22 } PROPERTY;
25 /***********************************************************************
26 * PROP_FindProp
28 static PROPERTY *PROP_FindProp( HWND32 hwnd, LPCSTR str )
30 PROPERTY *prop;
31 WND *pWnd = WIN_FindWndPtr( hwnd );
33 if (!pWnd) return NULL;
34 if (HIWORD(str))
36 for (prop = pWnd->pProp; prop; prop = prop->next)
37 if (HIWORD(prop->string) && !lstrcmpi32A( prop->string, str ))
38 return prop;
40 else /* atom */
42 for (prop = pWnd->pProp; (prop); prop = prop->next)
43 if (!HIWORD(prop->string) && (LOWORD(prop->string) == LOWORD(str)))
44 return prop;
46 return NULL;
50 /***********************************************************************
51 * GetProp16 (USER.25)
53 HANDLE16 GetProp16( HWND16 hwnd, LPCSTR str )
55 return (HANDLE16)GetProp32A( hwnd, str );
59 /***********************************************************************
60 * GetProp32A (USER32.280)
62 HANDLE32 GetProp32A( HWND32 hwnd, LPCSTR str )
64 PROPERTY *prop = PROP_FindProp( hwnd, str );
66 dprintf_prop( stddeb, "GetProp(%08x,'%s'): returning %08x\n",
67 hwnd, str, prop ? prop->handle : 0 );
68 return prop ? prop->handle : 0;
72 /***********************************************************************
73 * GetProp32W (USER32.281)
75 HANDLE32 GetProp32W( HWND32 hwnd, LPCWSTR str )
77 LPSTR strA;
78 HANDLE32 ret;
80 if (!HIWORD(str)) return GetProp32A( hwnd, (LPCSTR)(UINT32)LOWORD(str) );
81 strA = STRING32_DupUniToAnsi( str );
82 ret = GetProp32A( hwnd, strA );
83 free( strA );
84 return ret;
88 /***********************************************************************
89 * SetProp16 (USER.26)
91 BOOL16 SetProp16( HWND16 hwnd, LPCSTR str, HANDLE16 handle )
93 return (BOOL16)SetProp32A( hwnd, str, handle );
97 /***********************************************************************
98 * SetProp32A (USER32.496)
100 BOOL32 SetProp32A( HWND32 hwnd, LPCSTR str, HANDLE32 handle )
102 PROPERTY *prop;
104 dprintf_prop( stddeb, "SetProp: %04x '%s' %08x\n", hwnd, str, handle );
105 if (!(prop = PROP_FindProp( hwnd, str )))
107 /* We need to create it */
108 WND *pWnd = WIN_FindWndPtr( hwnd );
109 if (!pWnd) return FALSE;
110 if (!(prop = HeapAlloc( SystemHeap, 0, sizeof(*prop) ))) return FALSE;
111 if (!(prop->string = SEGPTR_STRDUP(str)))
113 HeapFree( SystemHeap, 0, prop );
114 return FALSE;
116 prop->next = pWnd->pProp;
117 pWnd->pProp = prop;
119 prop->handle = handle;
120 return TRUE;
124 /***********************************************************************
125 * SetProp32W (USER32.497)
127 BOOL32 SetProp32W( HWND32 hwnd, LPCWSTR str, HANDLE32 handle )
129 BOOL32 ret;
130 LPSTR strA;
132 if (!HIWORD(str))
133 return SetProp32A( hwnd, (LPCSTR)(UINT32)LOWORD(str), handle );
134 strA = STRING32_DupUniToAnsi( str );
135 ret = SetProp32A( hwnd, strA, handle );
136 free( strA );
137 return ret;
141 /***********************************************************************
142 * RemoveProp16 (USER.24)
144 HANDLE16 RemoveProp16( HWND16 hwnd, LPCSTR str )
146 return (HANDLE16)RemoveProp32A( hwnd, str );
150 /***********************************************************************
151 * RemoveProp32A (USER32.441)
153 HANDLE32 RemoveProp32A( HWND32 hwnd, LPCSTR str )
155 HANDLE32 handle;
156 PROPERTY **pprop, *prop;
157 WND *pWnd = WIN_FindWndPtr( hwnd );
159 dprintf_prop( stddeb, "RemoveProp: %04x '%s'\n", hwnd, str );
160 if (!pWnd) return NULL;
161 if (HIWORD(str))
163 for (pprop=(PROPERTY**)&pWnd->pProp; (*pprop); pprop = &(*pprop)->next)
164 if (HIWORD((*pprop)->string) &&
165 !lstrcmpi32A( (*pprop)->string, str )) break;
167 else /* atom */
169 for (pprop=(PROPERTY**)&pWnd->pProp; (*pprop); pprop = &(*pprop)->next)
170 if (!HIWORD((*pprop)->string) &&
171 (LOWORD((*pprop)->string) == LOWORD(str))) break;
173 if (!*pprop) return 0;
174 prop = *pprop;
175 handle = prop->handle;
176 *pprop = prop->next;
177 SEGPTR_FREE(prop->string);
178 HeapFree( SystemHeap, 0, prop );
179 return handle;
183 /***********************************************************************
184 * RemoveProp32W (USER32.442)
186 HANDLE32 RemoveProp32W( HWND32 hwnd, LPCWSTR str )
188 LPSTR strA;
189 HANDLE32 ret;
191 if (!HIWORD(str))
192 return RemoveProp32A( hwnd, (LPCSTR)(UINT32)LOWORD(str) );
193 strA = STRING32_DupUniToAnsi( str );
194 ret = RemoveProp32A( hwnd, strA );
195 free( strA );
196 return ret;
200 /***********************************************************************
201 * PROPERTY_RemoveWindowProps
203 * Remove all properties of a window.
205 void PROPERTY_RemoveWindowProps( WND *pWnd )
207 PROPERTY *prop, *next;
209 for (prop = pWnd->pProp; (prop); prop = next)
211 next = prop->next;
212 SEGPTR_FREE( prop->string );
213 HeapFree( SystemHeap, 0, prop );
215 pWnd->pProp = NULL;
219 /***********************************************************************
220 * EnumProps16 (USER.27)
222 INT16 EnumProps16( HWND16 hwnd, PROPENUMPROC16 func )
224 PROPERTY *prop, *next;
225 WND *pWnd;
226 INT16 ret = -1;
228 dprintf_prop( stddeb, "EnumProps: %04x %08x\n", hwnd, (UINT32)func );
229 if (!(pWnd = WIN_FindWndPtr( hwnd ))) return -1;
230 for (prop = pWnd->pProp; (prop); prop = next)
232 /* Already get the next in case the callback */
233 /* function removes the current property. */
234 next = prop->next;
236 dprintf_prop( stddeb, " Callback: handle=%08x str='%s'\n",
237 prop->handle, prop->string );
238 ret = func( hwnd, SEGPTR_GET(prop->string), prop->handle );
239 if (!ret) break;
241 return ret;
245 /***********************************************************************
246 * EnumProps32A (USER32.185)
248 INT32 EnumProps32A( HWND32 hwnd, PROPENUMPROC32A func )
250 return EnumPropsEx32A( hwnd, (PROPENUMPROCEX32A)func, 0 );
254 /***********************************************************************
255 * EnumProps32W (USER32.188)
257 INT32 EnumProps32W( HWND32 hwnd, PROPENUMPROC32W func )
259 return EnumPropsEx32W( hwnd, (PROPENUMPROCEX32W)func, 0 );
263 /***********************************************************************
264 * EnumPropsEx32A (USER32.186)
266 INT32 EnumPropsEx32A( HWND32 hwnd, PROPENUMPROCEX32A func, LPARAM lParam )
268 PROPERTY *prop, *next;
269 WND *pWnd;
270 INT32 ret = -1;
272 dprintf_prop( stddeb, "EnumPropsEx32A: %04x %08x %08lx\n",
273 hwnd, (UINT32)func, lParam );
274 if (!(pWnd = WIN_FindWndPtr( hwnd ))) return -1;
275 for (prop = pWnd->pProp; (prop); prop = next)
277 /* Already get the next in case the callback */
278 /* function removes the current property. */
279 next = prop->next;
281 dprintf_prop( stddeb, " Callback: handle=%08x str='%s'\n",
282 prop->handle, prop->string );
283 ret = func( hwnd, prop->string, prop->handle, lParam );
284 if (!ret) break;
286 return ret;
290 /***********************************************************************
291 * EnumPropsEx32W (USER32.187)
293 INT32 EnumPropsEx32W( HWND32 hwnd, PROPENUMPROCEX32W func, LPARAM lParam )
295 PROPERTY *prop, *next;
296 WND *pWnd;
297 INT32 ret = -1;
299 dprintf_prop( stddeb, "EnumPropsEx32W: %04x %08x %08lx\n",
300 hwnd, (UINT32)func, lParam );
301 if (!(pWnd = WIN_FindWndPtr( hwnd ))) return -1;
302 for (prop = pWnd->pProp; (prop); prop = next)
304 /* Already get the next in case the callback */
305 /* function removes the current property. */
306 next = prop->next;
308 dprintf_prop( stddeb, " Callback: handle=%08x str='%s'\n",
309 prop->handle, prop->string );
310 if (HIWORD(prop->string))
312 LPWSTR str = STRING32_DupAnsiToUni( prop->string );
313 ret = func( hwnd, str, prop->handle, lParam );
314 free( str );
316 else
317 ret = func( hwnd, (LPCWSTR)(UINT32)LOWORD( prop->string ),
318 prop->handle, lParam );
319 if (!ret) break;
321 return ret;