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
);
56 if (Property
->Atom
== Atom
)
60 temp
= ListEntry
->Flink
;
61 ListEntry
= SharedPtrToUser(temp
);
68 UserGetProp(HWND hWnd
, ATOM Atom
)
71 Prop
= IntGetProp(hWnd
, Atom
);
72 return Prop
? Prop
->Data
: NULL
;
75 /* FUNCTIONS *****************************************************************/
81 EnumPropsA(HWND hWnd
, PROPENUMPROCA lpEnumFunc
)
90 SetLastError(ERROR_INVALID_PARAMETER
);
94 Status
= NtUserBuildPropList(hWnd
, NULL
, 0, &Count
);
95 if(!NT_SUCCESS(Status
))
97 if(Status
== STATUS_INVALID_HANDLE
)
98 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
100 SetLastError(RtlNtStatusToDosError(Status
));
106 pli
= RtlAllocateHeap(GetProcessHeap(), 0, Count
);
109 SetLastError(ERROR_OUTOFMEMORY
);
113 Status
= NtUserBuildPropList(hWnd
, (LPVOID
)pli
, Count
, &Count
);
114 if(!NT_SUCCESS(Status
))
116 RtlFreeHeap(GetProcessHeap(), 0, pli
);
117 if(Status
== STATUS_INVALID_HANDLE
)
118 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
120 SetLastError(RtlNtStatusToDosError(Status
));
125 for(; Count
> 0; Count
--, i
++)
127 char str
[ATOM_BUFFER_SIZE
];
129 if(!GlobalGetAtomNameA(i
->Atom
, str
, ATOM_BUFFER_SIZE
))
132 ret
= lpEnumFunc(hWnd
, str
, i
->Data
);
137 RtlFreeHeap(GetProcessHeap(), 0, pli
);
148 EnumPropsExA(HWND hWnd
, PROPENUMPROCEXA lpEnumFunc
, LPARAM lParam
)
150 PPROPLISTITEM pli
, i
;
157 SetLastError(ERROR_INVALID_PARAMETER
);
161 Status
= NtUserBuildPropList(hWnd
, NULL
, 0, &Count
);
162 if(!NT_SUCCESS(Status
))
164 if(Status
== STATUS_INVALID_HANDLE
)
165 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
167 SetLastError(RtlNtStatusToDosError(Status
));
173 pli
= RtlAllocateHeap(GetProcessHeap(), 0, Count
);
176 SetLastError(ERROR_OUTOFMEMORY
);
180 Status
= NtUserBuildPropList(hWnd
, (LPVOID
)pli
, Count
, &Count
);
181 if(!NT_SUCCESS(Status
))
183 RtlFreeHeap(GetProcessHeap(), 0, pli
);
184 if(Status
== STATUS_INVALID_HANDLE
)
185 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
187 SetLastError(RtlNtStatusToDosError(Status
));
192 for(; Count
> 0; Count
--, i
++)
194 char str
[ATOM_BUFFER_SIZE
];
196 if(!GlobalGetAtomNameA(i
->Atom
, str
, ATOM_BUFFER_SIZE
))
199 ret
= lpEnumFunc(hWnd
, str
, i
->Data
, lParam
);
204 RtlFreeHeap(GetProcessHeap(), 0, pli
);
215 EnumPropsExW(HWND hWnd
, PROPENUMPROCEXW lpEnumFunc
, LPARAM lParam
)
217 PPROPLISTITEM pli
, i
;
224 SetLastError(ERROR_INVALID_PARAMETER
);
228 Status
= NtUserBuildPropList(hWnd
, NULL
, 0, &Count
);
229 if(!NT_SUCCESS(Status
))
231 if(Status
== STATUS_INVALID_HANDLE
)
232 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
234 SetLastError(RtlNtStatusToDosError(Status
));
240 pli
= RtlAllocateHeap(GetProcessHeap(), 0, Count
);
243 SetLastError(ERROR_OUTOFMEMORY
);
247 Status
= NtUserBuildPropList(hWnd
, (LPVOID
)pli
, Count
, &Count
);
248 if(!NT_SUCCESS(Status
))
250 RtlFreeHeap(GetProcessHeap(), 0, pli
);
251 if(Status
== STATUS_INVALID_HANDLE
)
252 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
254 SetLastError(RtlNtStatusToDosError(Status
));
259 for(; Count
> 0; Count
--, i
++)
261 WCHAR str
[ATOM_BUFFER_SIZE
];
263 if(!GlobalGetAtomNameW(i
->Atom
, str
, ATOM_BUFFER_SIZE
))
266 ret
= lpEnumFunc(hWnd
, str
, i
->Data
, lParam
);
271 RtlFreeHeap(GetProcessHeap(), 0, pli
);
282 EnumPropsW(HWND hWnd
, PROPENUMPROCW lpEnumFunc
)
284 PPROPLISTITEM pli
, i
;
291 SetLastError(ERROR_INVALID_PARAMETER
);
295 Status
= NtUserBuildPropList(hWnd
, NULL
, 0, &Count
);
296 if(!NT_SUCCESS(Status
))
298 if(Status
== STATUS_INVALID_HANDLE
)
299 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
301 SetLastError(RtlNtStatusToDosError(Status
));
307 pli
= RtlAllocateHeap(GetProcessHeap(), 0, Count
);
310 SetLastError(ERROR_OUTOFMEMORY
);
314 Status
= NtUserBuildPropList(hWnd
, (LPVOID
)pli
, Count
, &Count
);
315 if(!NT_SUCCESS(Status
))
317 RtlFreeHeap(GetProcessHeap(), 0, pli
);
318 if(Status
== STATUS_INVALID_HANDLE
)
319 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
321 SetLastError(RtlNtStatusToDosError(Status
));
326 for(; Count
> 0; Count
--, i
++)
328 WCHAR str
[ATOM_BUFFER_SIZE
];
330 if(!GlobalGetAtomNameW(i
->Atom
, str
, ATOM_BUFFER_SIZE
))
333 ret
= lpEnumFunc(hWnd
, str
, i
->Data
);
338 RtlFreeHeap(GetProcessHeap(), 0, pli
);
349 GetPropA(HWND hWnd
, LPCSTR lpString
)
352 UNICODE_STRING UString
;
354 if (HIWORD(lpString
))
356 RtlCreateUnicodeStringFromAsciiz(&UString
, (LPSTR
)lpString
);
357 lpWString
= UString
.Buffer
;
358 if (lpWString
== NULL
)
362 Ret
= GetPropW(hWnd
, lpWString
);
363 RtlFreeUnicodeString(&UString
);
367 Ret
= GetPropW(hWnd
, (LPWSTR
)lpString
);
377 GetPropW(HWND hWnd
, LPCWSTR lpString
)
382 if (HIWORD(lpString
))
384 Atom
= GlobalFindAtomW(lpString
);
388 Atom
= LOWORD((DWORD_PTR
)lpString
);
390 Prop
= IntGetProp(hWnd
, Atom
);
391 if (Prop
!= NULL
) Data
= Prop
->Data
;
400 RemovePropA(HWND hWnd
, LPCSTR lpString
)
403 UNICODE_STRING UString
;
406 if (HIWORD(lpString
))
408 RtlCreateUnicodeStringFromAsciiz(&UString
, (LPSTR
)lpString
);
409 lpWString
= UString
.Buffer
;
410 if (lpWString
== NULL
)
414 Ret
= RemovePropW(hWnd
, lpWString
);
415 RtlFreeUnicodeString(&UString
);
419 Ret
= RemovePropW(hWnd
, (LPCWSTR
)lpString
);
429 RemovePropW(HWND hWnd
,
433 if (HIWORD(lpString
))
435 Atom
= GlobalFindAtomW(lpString
);
439 Atom
= LOWORD((DWORD_PTR
)lpString
);
441 return(NtUserRemoveProp(hWnd
, Atom
));
449 SetPropA(HWND hWnd
, LPCSTR lpString
, HANDLE hData
)
452 UNICODE_STRING UString
;
455 if (HIWORD(lpString
))
457 RtlCreateUnicodeStringFromAsciiz(&UString
, (LPSTR
)lpString
);
458 lpWString
= UString
.Buffer
;
459 if (lpWString
== NULL
)
463 Ret
= SetPropW(hWnd
, lpWString
, hData
);
464 RtlFreeUnicodeString(&UString
);
468 Ret
= SetPropW(hWnd
, (LPWSTR
)lpString
, hData
);
478 SetPropW(HWND hWnd
, LPCWSTR lpString
, HANDLE hData
)
481 if (HIWORD(lpString
))
483 Atom
= GlobalAddAtomW(lpString
);
487 Atom
= LOWORD((DWORD_PTR
)lpString
);
490 return(NtUserSetProp(hWnd
, Atom
, hData
));