3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
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.
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.
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.
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)
25 * 09-05-2001 CSH Created
28 /* INCLUDES ******************************************************************/
32 #include <wine/debug.h>
34 WINE_DEFAULT_DEBUG_CHANNEL(user32
);
36 #define ATOM_BUFFER_SIZE 256
38 /* INTERNAL FUNCTIONS ********************************************************/
42 IntGetProp(HWND hWnd
, ATOM Atom
)
44 PLIST_ENTRY ListEntry
, temp
;
49 pWnd
= ValidateHwnd(hWnd
);
50 if (!pWnd
) return NULL
;
52 ListEntry
= SharedPtrToUser(pWnd
->PropListHead
.Flink
);
53 for (i
= 0; i
< pWnd
->PropListItems
; i
++ )
55 Property
= CONTAINING_RECORD(ListEntry
, PROPERTY
, PropListEntry
);
57 if (Property
->Atom
== Atom
)
61 temp
= ListEntry
->Flink
;
62 ListEntry
= SharedPtrToUser(temp
);
69 UserGetProp(HWND hWnd
, ATOM Atom
)
72 Prop
= IntGetProp(hWnd
, Atom
);
73 return Prop
? Prop
->Data
: NULL
;
76 /* FUNCTIONS *****************************************************************/
82 EnumPropsA(HWND hWnd
, PROPENUMPROCA lpEnumFunc
)
91 SetLastError(ERROR_INVALID_PARAMETER
);
95 Status
= NtUserBuildPropList(hWnd
, NULL
, 0, &Count
);
96 if(!NT_SUCCESS(Status
))
98 if(Status
== STATUS_INVALID_HANDLE
)
99 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
101 SetLastError(RtlNtStatusToDosError(Status
));
107 pli
= RtlAllocateHeap(GetProcessHeap(), 0, Count
);
110 SetLastError(ERROR_OUTOFMEMORY
);
114 Status
= NtUserBuildPropList(hWnd
, (LPVOID
)pli
, Count
, &Count
);
115 if(!NT_SUCCESS(Status
))
117 RtlFreeHeap(GetProcessHeap(), 0, pli
);
118 if(Status
== STATUS_INVALID_HANDLE
)
119 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
121 SetLastError(RtlNtStatusToDosError(Status
));
126 for(; Count
> 0; Count
--, i
++)
128 char str
[ATOM_BUFFER_SIZE
];
130 if(!GlobalGetAtomNameA(i
->Atom
, str
, ATOM_BUFFER_SIZE
))
133 ret
= lpEnumFunc(hWnd
, str
, i
->Data
);
138 RtlFreeHeap(GetProcessHeap(), 0, pli
);
149 EnumPropsExA(HWND hWnd
, PROPENUMPROCEXA lpEnumFunc
, LPARAM lParam
)
151 PPROPLISTITEM pli
, i
;
158 SetLastError(ERROR_INVALID_PARAMETER
);
162 Status
= NtUserBuildPropList(hWnd
, NULL
, 0, &Count
);
163 if(!NT_SUCCESS(Status
))
165 if(Status
== STATUS_INVALID_HANDLE
)
166 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
168 SetLastError(RtlNtStatusToDosError(Status
));
174 pli
= RtlAllocateHeap(GetProcessHeap(), 0, Count
);
177 SetLastError(ERROR_OUTOFMEMORY
);
181 Status
= NtUserBuildPropList(hWnd
, (LPVOID
)pli
, Count
, &Count
);
182 if(!NT_SUCCESS(Status
))
184 RtlFreeHeap(GetProcessHeap(), 0, pli
);
185 if(Status
== STATUS_INVALID_HANDLE
)
186 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
188 SetLastError(RtlNtStatusToDosError(Status
));
193 for(; Count
> 0; Count
--, i
++)
195 char str
[ATOM_BUFFER_SIZE
];
197 if(!GlobalGetAtomNameA(i
->Atom
, str
, ATOM_BUFFER_SIZE
))
200 ret
= lpEnumFunc(hWnd
, str
, i
->Data
, lParam
);
205 RtlFreeHeap(GetProcessHeap(), 0, pli
);
216 EnumPropsExW(HWND hWnd
, PROPENUMPROCEXW lpEnumFunc
, LPARAM lParam
)
218 PPROPLISTITEM pli
, i
;
225 SetLastError(ERROR_INVALID_PARAMETER
);
229 Status
= NtUserBuildPropList(hWnd
, NULL
, 0, &Count
);
230 if(!NT_SUCCESS(Status
))
232 if(Status
== STATUS_INVALID_HANDLE
)
233 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
235 SetLastError(RtlNtStatusToDosError(Status
));
241 pli
= RtlAllocateHeap(GetProcessHeap(), 0, Count
);
244 SetLastError(ERROR_OUTOFMEMORY
);
248 Status
= NtUserBuildPropList(hWnd
, (LPVOID
)pli
, Count
, &Count
);
249 if(!NT_SUCCESS(Status
))
251 RtlFreeHeap(GetProcessHeap(), 0, pli
);
252 if(Status
== STATUS_INVALID_HANDLE
)
253 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
255 SetLastError(RtlNtStatusToDosError(Status
));
260 for(; Count
> 0; Count
--, i
++)
262 WCHAR str
[ATOM_BUFFER_SIZE
];
264 if(!GlobalGetAtomNameW(i
->Atom
, str
, ATOM_BUFFER_SIZE
))
267 ret
= lpEnumFunc(hWnd
, str
, i
->Data
, lParam
);
272 RtlFreeHeap(GetProcessHeap(), 0, pli
);
283 EnumPropsW(HWND hWnd
, PROPENUMPROCW lpEnumFunc
)
285 PPROPLISTITEM pli
, i
;
292 SetLastError(ERROR_INVALID_PARAMETER
);
296 Status
= NtUserBuildPropList(hWnd
, NULL
, 0, &Count
);
297 if(!NT_SUCCESS(Status
))
299 if(Status
== STATUS_INVALID_HANDLE
)
300 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
302 SetLastError(RtlNtStatusToDosError(Status
));
308 pli
= RtlAllocateHeap(GetProcessHeap(), 0, Count
);
311 SetLastError(ERROR_OUTOFMEMORY
);
315 Status
= NtUserBuildPropList(hWnd
, (LPVOID
)pli
, Count
, &Count
);
316 if(!NT_SUCCESS(Status
))
318 RtlFreeHeap(GetProcessHeap(), 0, pli
);
319 if(Status
== STATUS_INVALID_HANDLE
)
320 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
322 SetLastError(RtlNtStatusToDosError(Status
));
327 for(; Count
> 0; Count
--, i
++)
329 WCHAR str
[ATOM_BUFFER_SIZE
];
331 if(!GlobalGetAtomNameW(i
->Atom
, str
, ATOM_BUFFER_SIZE
))
334 ret
= lpEnumFunc(hWnd
, str
, i
->Data
);
339 RtlFreeHeap(GetProcessHeap(), 0, pli
);
350 GetPropA(HWND hWnd
, LPCSTR lpString
)
353 UNICODE_STRING UString
;
355 if (HIWORD(lpString
))
357 RtlCreateUnicodeStringFromAsciiz(&UString
, (LPSTR
)lpString
);
358 lpWString
= UString
.Buffer
;
359 if (lpWString
== NULL
)
363 Ret
= GetPropW(hWnd
, lpWString
);
364 RtlFreeUnicodeString(&UString
);
368 Ret
= GetPropW(hWnd
, (LPWSTR
)lpString
);
378 GetPropW(HWND hWnd
, LPCWSTR lpString
)
383 if (HIWORD(lpString
))
385 Atom
= GlobalFindAtomW(lpString
);
389 Atom
= LOWORD((DWORD_PTR
)lpString
);
391 Prop
= IntGetProp(hWnd
, Atom
);
392 if (Prop
!= NULL
) Data
= Prop
->Data
;
401 RemovePropA(HWND hWnd
, LPCSTR lpString
)
404 UNICODE_STRING UString
;
407 if (HIWORD(lpString
))
409 RtlCreateUnicodeStringFromAsciiz(&UString
, (LPSTR
)lpString
);
410 lpWString
= UString
.Buffer
;
411 if (lpWString
== NULL
)
415 Ret
= RemovePropW(hWnd
, lpWString
);
416 RtlFreeUnicodeString(&UString
);
420 Ret
= RemovePropW(hWnd
, (LPCWSTR
)lpString
);
430 RemovePropW(HWND hWnd
,
434 if (HIWORD(lpString
))
436 Atom
= GlobalFindAtomW(lpString
);
440 Atom
= LOWORD((DWORD_PTR
)lpString
);
442 return(NtUserRemoveProp(hWnd
, Atom
));
450 SetPropA(HWND hWnd
, LPCSTR lpString
, HANDLE hData
)
453 UNICODE_STRING UString
;
456 if (HIWORD(lpString
))
458 RtlCreateUnicodeStringFromAsciiz(&UString
, (LPSTR
)lpString
);
459 lpWString
= UString
.Buffer
;
460 if (lpWString
== NULL
)
464 Ret
= SetPropW(hWnd
, lpWString
, hData
);
465 RtlFreeUnicodeString(&UString
);
469 Ret
= SetPropW(hWnd
, (LPWSTR
)lpString
, hData
);
479 SetPropW(HWND hWnd
, LPCWSTR lpString
, HANDLE hData
)
482 if (HIWORD(lpString
))
484 Atom
= GlobalAddAtomW(lpString
);
488 Atom
= LOWORD((DWORD_PTR
)lpString
);
491 return(NtUserSetProp(hWnd
, Atom
, hData
));