- Remove a mislaid artifact.
[reactos.git] / reactos / win32ss / user / user32 / windows / prop.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /*
20 * PROJECT: ReactOS user32.dll
21 * FILE: user/user32/windows/prop.c
22 * PURPOSE: Window Property
23 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
24 * UPDATE HISTORY:
25 * 09-05-2001 CSH Created
26 */
27
28 /* INCLUDES ******************************************************************/
29
30 #include <user32.h>
31
32 #include <wine/debug.h>
33
34 WINE_DEFAULT_DEBUG_CHANNEL(user32);
35
36 #define ATOM_BUFFER_SIZE 256
37
38 /* INTERNAL FUNCTIONS ********************************************************/
39
40 HANDLE
41 FASTCALL
42 IntGetProp(HWND hWnd, ATOM Atom)
43 {
44 PLIST_ENTRY ListEntry, temp;
45 PPROPERTY Property;
46 PWND pWnd;
47 int i;
48
49 pWnd = ValidateHwnd(hWnd);
50 if (!pWnd) return NULL;
51
52 ListEntry = SharedPtrToUser(pWnd->PropListHead.Flink);
53 for (i = 0; i < pWnd->PropListItems; i++ )
54 {
55 Property = CONTAINING_RECORD(ListEntry, PROPERTY, PropListEntry);
56 if (Property->Atom == Atom)
57 {
58 return(Property);
59 }
60 temp = ListEntry->Flink;
61 ListEntry = SharedPtrToUser(temp);
62 }
63 return NULL;
64 }
65
66 HANDLE
67 FASTCALL
68 UserGetProp(HWND hWnd, ATOM Atom)
69 {
70 PPROPERTY Prop;
71 Prop = IntGetProp(hWnd, Atom);
72 return Prop ? Prop->Data : NULL;
73 }
74
75 /* FUNCTIONS *****************************************************************/
76
77 /*
78 * @implemented
79 */
80 int WINAPI
81 EnumPropsA(HWND hWnd, PROPENUMPROCA lpEnumFunc)
82 {
83 PPROPLISTITEM pli, i;
84 NTSTATUS Status;
85 DWORD Count;
86 int ret = -1;
87
88 if(!lpEnumFunc)
89 {
90 SetLastError(ERROR_INVALID_PARAMETER);
91 return ret;
92 }
93
94 Status = NtUserBuildPropList(hWnd, NULL, 0, &Count);
95 if(!NT_SUCCESS(Status))
96 {
97 if(Status == STATUS_INVALID_HANDLE)
98 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
99 else
100 SetLastError(RtlNtStatusToDosError(Status));
101 return ret;
102 }
103
104 if(Count > 0)
105 {
106 pli = RtlAllocateHeap(GetProcessHeap(), 0, Count);
107 if (pli == NULL)
108 {
109 SetLastError(ERROR_OUTOFMEMORY);
110 return -1;
111 }
112
113 Status = NtUserBuildPropList(hWnd, (LPVOID)pli, Count, &Count);
114 if(!NT_SUCCESS(Status))
115 {
116 RtlFreeHeap(GetProcessHeap(), 0, pli);
117 if(Status == STATUS_INVALID_HANDLE)
118 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
119 else
120 SetLastError(RtlNtStatusToDosError(Status));
121 return ret;
122 }
123
124 i = pli;
125 for(; Count > 0; Count--, i++)
126 {
127 char str[ATOM_BUFFER_SIZE];
128
129 if(!GlobalGetAtomNameA(i->Atom, str, ATOM_BUFFER_SIZE))
130 continue;
131
132 ret = lpEnumFunc(hWnd, str, i->Data);
133 if(!ret)
134 break;
135 }
136
137 RtlFreeHeap(GetProcessHeap(), 0, pli);
138 }
139
140 return ret;
141 }
142
143
144 /*
145 * @implemented
146 */
147 int WINAPI
148 EnumPropsExA(HWND hWnd, PROPENUMPROCEXA lpEnumFunc, LPARAM lParam)
149 {
150 PPROPLISTITEM pli, i;
151 NTSTATUS Status;
152 DWORD Count;
153 int ret = -1;
154
155 if(!lpEnumFunc)
156 {
157 SetLastError(ERROR_INVALID_PARAMETER);
158 return ret;
159 }
160
161 Status = NtUserBuildPropList(hWnd, NULL, 0, &Count);
162 if(!NT_SUCCESS(Status))
163 {
164 if(Status == STATUS_INVALID_HANDLE)
165 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
166 else
167 SetLastError(RtlNtStatusToDosError(Status));
168 return ret;
169 }
170
171 if(Count > 0)
172 {
173 pli = RtlAllocateHeap(GetProcessHeap(), 0, Count);
174 if (pli == NULL)
175 {
176 SetLastError(ERROR_OUTOFMEMORY);
177 return -1;
178 }
179
180 Status = NtUserBuildPropList(hWnd, (LPVOID)pli, Count, &Count);
181 if(!NT_SUCCESS(Status))
182 {
183 RtlFreeHeap(GetProcessHeap(), 0, pli);
184 if(Status == STATUS_INVALID_HANDLE)
185 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
186 else
187 SetLastError(RtlNtStatusToDosError(Status));
188 return ret;
189 }
190
191 i = pli;
192 for(; Count > 0; Count--, i++)
193 {
194 char str[ATOM_BUFFER_SIZE];
195
196 if(!GlobalGetAtomNameA(i->Atom, str, ATOM_BUFFER_SIZE))
197 continue;
198
199 ret = lpEnumFunc(hWnd, str, i->Data, lParam);
200 if(!ret)
201 break;
202 }
203
204 RtlFreeHeap(GetProcessHeap(), 0, pli);
205 }
206
207 return ret;
208 }
209
210
211 /*
212 * @implemented
213 */
214 int WINAPI
215 EnumPropsExW(HWND hWnd, PROPENUMPROCEXW lpEnumFunc, LPARAM lParam)
216 {
217 PPROPLISTITEM pli, i;
218 NTSTATUS Status;
219 DWORD Count;
220 int ret = -1;
221
222 if(!lpEnumFunc)
223 {
224 SetLastError(ERROR_INVALID_PARAMETER);
225 return ret;
226 }
227
228 Status = NtUserBuildPropList(hWnd, NULL, 0, &Count);
229 if(!NT_SUCCESS(Status))
230 {
231 if(Status == STATUS_INVALID_HANDLE)
232 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
233 else
234 SetLastError(RtlNtStatusToDosError(Status));
235 return ret;
236 }
237
238 if(Count > 0)
239 {
240 pli = RtlAllocateHeap(GetProcessHeap(), 0, Count);
241 if (pli == NULL)
242 {
243 SetLastError(ERROR_OUTOFMEMORY);
244 return -1;
245 }
246
247 Status = NtUserBuildPropList(hWnd, (LPVOID)pli, Count, &Count);
248 if(!NT_SUCCESS(Status))
249 {
250 RtlFreeHeap(GetProcessHeap(), 0, pli);
251 if(Status == STATUS_INVALID_HANDLE)
252 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
253 else
254 SetLastError(RtlNtStatusToDosError(Status));
255 return ret;
256 }
257
258 i = pli;
259 for(; Count > 0; Count--, i++)
260 {
261 WCHAR str[ATOM_BUFFER_SIZE];
262
263 if(!GlobalGetAtomNameW(i->Atom, str, ATOM_BUFFER_SIZE))
264 continue;
265
266 ret = lpEnumFunc(hWnd, str, i->Data, lParam);
267 if(!ret)
268 break;
269 }
270
271 RtlFreeHeap(GetProcessHeap(), 0, pli);
272 }
273
274 return ret;
275 }
276
277
278 /*
279 * @implemented
280 */
281 int WINAPI
282 EnumPropsW(HWND hWnd, PROPENUMPROCW lpEnumFunc)
283 {
284 PPROPLISTITEM pli, i;
285 NTSTATUS Status;
286 DWORD Count;
287 int ret = -1;
288
289 if(!lpEnumFunc)
290 {
291 SetLastError(ERROR_INVALID_PARAMETER);
292 return ret;
293 }
294
295 Status = NtUserBuildPropList(hWnd, NULL, 0, &Count);
296 if(!NT_SUCCESS(Status))
297 {
298 if(Status == STATUS_INVALID_HANDLE)
299 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
300 else
301 SetLastError(RtlNtStatusToDosError(Status));
302 return ret;
303 }
304
305 if(Count > 0)
306 {
307 pli = RtlAllocateHeap(GetProcessHeap(), 0, Count);
308 if (pli == NULL)
309 {
310 SetLastError(ERROR_OUTOFMEMORY);
311 return -1;
312 }
313
314 Status = NtUserBuildPropList(hWnd, (LPVOID)pli, Count, &Count);
315 if(!NT_SUCCESS(Status))
316 {
317 RtlFreeHeap(GetProcessHeap(), 0, pli);
318 if(Status == STATUS_INVALID_HANDLE)
319 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
320 else
321 SetLastError(RtlNtStatusToDosError(Status));
322 return ret;
323 }
324
325 i = pli;
326 for(; Count > 0; Count--, i++)
327 {
328 WCHAR str[ATOM_BUFFER_SIZE];
329
330 if(!GlobalGetAtomNameW(i->Atom, str, ATOM_BUFFER_SIZE))
331 continue;
332
333 ret = lpEnumFunc(hWnd, str, i->Data);
334 if(!ret)
335 break;
336 }
337
338 RtlFreeHeap(GetProcessHeap(), 0, pli);
339 }
340
341 return ret;
342 }
343
344
345 /*
346 * @implemented
347 */
348 HANDLE WINAPI
349 GetPropA(HWND hWnd, LPCSTR lpString)
350 {
351 PWSTR lpWString;
352 UNICODE_STRING UString;
353 HANDLE Ret;
354 if (HIWORD(lpString))
355 {
356 RtlCreateUnicodeStringFromAsciiz(&UString, (LPSTR)lpString);
357 lpWString = UString.Buffer;
358 if (lpWString == NULL)
359 {
360 return(FALSE);
361 }
362 Ret = GetPropW(hWnd, lpWString);
363 RtlFreeUnicodeString(&UString);
364 }
365 else
366 {
367 Ret = GetPropW(hWnd, (LPWSTR)lpString);
368 }
369 return(Ret);
370 }
371
372
373 /*
374 * @implemented
375 */
376 HANDLE WINAPI
377 GetPropW(HWND hWnd, LPCWSTR lpString)
378 {
379 ATOM Atom;
380 HANDLE Data = NULL;
381 PPROPERTY Prop;
382 if (HIWORD(lpString))
383 {
384 Atom = GlobalFindAtomW(lpString);
385 }
386 else
387 {
388 Atom = LOWORD((DWORD_PTR)lpString);
389 }
390 Prop = IntGetProp(hWnd, Atom);
391 if (Prop != NULL) Data = Prop->Data;
392 return Data;
393 }
394
395
396 /*
397 * @implemented
398 */
399 HANDLE WINAPI
400 RemovePropA(HWND hWnd, LPCSTR lpString)
401 {
402 PWSTR lpWString;
403 UNICODE_STRING UString;
404 HANDLE Ret;
405
406 if (HIWORD(lpString))
407 {
408 RtlCreateUnicodeStringFromAsciiz(&UString, (LPSTR)lpString);
409 lpWString = UString.Buffer;
410 if (lpWString == NULL)
411 {
412 return(FALSE);
413 }
414 Ret = RemovePropW(hWnd, lpWString);
415 RtlFreeUnicodeString(&UString);
416 }
417 else
418 {
419 Ret = RemovePropW(hWnd, (LPCWSTR)lpString);
420 }
421 return(Ret);
422 }
423
424
425 /*
426 * @implemented
427 */
428 HANDLE WINAPI
429 RemovePropW(HWND hWnd,
430 LPCWSTR lpString)
431 {
432 ATOM Atom;
433 if (HIWORD(lpString))
434 {
435 Atom = GlobalFindAtomW(lpString);
436 }
437 else
438 {
439 Atom = LOWORD((DWORD_PTR)lpString);
440 }
441 return(NtUserRemoveProp(hWnd, Atom));
442 }
443
444
445 /*
446 * @implemented
447 */
448 BOOL WINAPI
449 SetPropA(HWND hWnd, LPCSTR lpString, HANDLE hData)
450 {
451 PWSTR lpWString;
452 UNICODE_STRING UString;
453 BOOL Ret;
454
455 if (HIWORD(lpString))
456 {
457 RtlCreateUnicodeStringFromAsciiz(&UString, (LPSTR)lpString);
458 lpWString = UString.Buffer;
459 if (lpWString == NULL)
460 {
461 return(FALSE);
462 }
463 Ret = SetPropW(hWnd, lpWString, hData);
464 RtlFreeUnicodeString(&UString);
465 }
466 else
467 {
468 Ret = SetPropW(hWnd, (LPWSTR)lpString, hData);
469 }
470 return(Ret);
471 }
472
473
474 /*
475 * @implemented
476 */
477 BOOL WINAPI
478 SetPropW(HWND hWnd, LPCWSTR lpString, HANDLE hData)
479 {
480 ATOM Atom;
481 if (HIWORD(lpString))
482 {
483 Atom = GlobalAddAtomW(lpString);
484 }
485 else
486 {
487 Atom = LOWORD((DWORD_PTR)lpString);
488 }
489
490 return(NtUserSetProp(hWnd, Atom, hData));
491 }