6ba07a31b4b3f6434605e1aed57ed573b8ce7b81
[reactos.git] / reactos / lib / 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 /* $Id$
20 *
21 * PROJECT: ReactOS user32.dll
22 * FILE: lib/user32/windows/input.c
23 * PURPOSE: Input
24 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
25 * UPDATE HISTORY:
26 * 09-05-2001 CSH Created
27 */
28
29 /* INCLUDES ******************************************************************/
30
31 #include <user32.h>
32
33 typedef struct _PROPLISTITEM
34 {
35 ATOM Atom;
36 HANDLE Data;
37 } PROPLISTITEM, *PPROPLISTITEM;
38
39 #define ATOM_BUFFER_SIZE 256
40
41 /* FUNCTIONS *****************************************************************/
42
43 /*
44 * @implemented
45 */
46 int STDCALL
47 EnumPropsA(HWND hWnd, PROPENUMPROCA lpEnumFunc)
48 {
49 PPROPLISTITEM pli, i;
50 NTSTATUS Status;
51 DWORD Count;
52 int ret = -1;
53
54 if(!lpEnumFunc)
55 {
56 SetLastError(ERROR_INVALID_PARAMETER);
57 return ret;
58 }
59
60 Status = NtUserBuildPropList(hWnd, NULL, 0, &Count);
61 if(!NT_SUCCESS(Status))
62 {
63 if(Status == STATUS_INVALID_HANDLE)
64 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
65 else
66 SetLastError(RtlNtStatusToDosError(Status));
67 return ret;
68 }
69
70 if(Count > 0)
71 {
72 pli = RtlAllocateHeap(GetProcessHeap(), 0, Count);
73
74 Status = NtUserBuildPropList(hWnd, (LPVOID)pli, Count, &Count);
75 if(!NT_SUCCESS(Status))
76 {
77 RtlFreeHeap(GetProcessHeap(), 0, pli);
78 if(Status == STATUS_INVALID_HANDLE)
79 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
80 else
81 SetLastError(RtlNtStatusToDosError(Status));
82 return ret;
83 }
84
85 i = pli;
86 for(; Count > 0; Count--, i++)
87 {
88 char str[ATOM_BUFFER_SIZE];
89
90 if(!GlobalGetAtomNameA(i->Atom, str, ATOM_BUFFER_SIZE))
91 continue;
92
93 ret = lpEnumFunc(hWnd, str, i->Data);
94 if(!ret)
95 break;
96 }
97
98 RtlFreeHeap(GetProcessHeap(), 0, pli);
99 }
100
101 return ret;
102 }
103
104
105 /*
106 * @implemented
107 */
108 int STDCALL
109 EnumPropsExA(HWND hWnd, PROPENUMPROCEXA lpEnumFunc, LPARAM lParam)
110 {
111 PPROPLISTITEM pli, i;
112 NTSTATUS Status;
113 DWORD Count;
114 int ret = -1;
115
116 if(!lpEnumFunc)
117 {
118 SetLastError(ERROR_INVALID_PARAMETER);
119 return ret;
120 }
121
122 Status = NtUserBuildPropList(hWnd, NULL, 0, &Count);
123 if(!NT_SUCCESS(Status))
124 {
125 if(Status == STATUS_INVALID_HANDLE)
126 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
127 else
128 SetLastError(RtlNtStatusToDosError(Status));
129 return ret;
130 }
131
132 if(Count > 0)
133 {
134 pli = RtlAllocateHeap(GetProcessHeap(), 0, Count);
135
136 Status = NtUserBuildPropList(hWnd, (LPVOID)pli, Count, &Count);
137 if(!NT_SUCCESS(Status))
138 {
139 RtlFreeHeap(GetProcessHeap(), 0, pli);
140 if(Status == STATUS_INVALID_HANDLE)
141 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
142 else
143 SetLastError(RtlNtStatusToDosError(Status));
144 return ret;
145 }
146
147 i = pli;
148 for(; Count > 0; Count--, i++)
149 {
150 char str[ATOM_BUFFER_SIZE];
151
152 if(!GlobalGetAtomNameA(i->Atom, str, ATOM_BUFFER_SIZE))
153 continue;
154
155 ret = lpEnumFunc(hWnd, str, i->Data, lParam);
156 if(!ret)
157 break;
158 }
159
160 RtlFreeHeap(GetProcessHeap(), 0, pli);
161 }
162
163 return ret;
164 }
165
166
167 /*
168 * @implemented
169 */
170 int STDCALL
171 EnumPropsExW(HWND hWnd, PROPENUMPROCEXW lpEnumFunc, LPARAM lParam)
172 {
173 PPROPLISTITEM pli, i;
174 NTSTATUS Status;
175 DWORD Count;
176 int ret = -1;
177
178 if(!lpEnumFunc)
179 {
180 SetLastError(ERROR_INVALID_PARAMETER);
181 return ret;
182 }
183
184 Status = NtUserBuildPropList(hWnd, NULL, 0, &Count);
185 if(!NT_SUCCESS(Status))
186 {
187 if(Status == STATUS_INVALID_HANDLE)
188 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
189 else
190 SetLastError(RtlNtStatusToDosError(Status));
191 return ret;
192 }
193
194 if(Count > 0)
195 {
196 pli = RtlAllocateHeap(GetProcessHeap(), 0, Count);
197
198 Status = NtUserBuildPropList(hWnd, (LPVOID)pli, Count, &Count);
199 if(!NT_SUCCESS(Status))
200 {
201 RtlFreeHeap(GetProcessHeap(), 0, pli);
202 if(Status == STATUS_INVALID_HANDLE)
203 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
204 else
205 SetLastError(RtlNtStatusToDosError(Status));
206 return ret;
207 }
208
209 i = pli;
210 for(; Count > 0; Count--, i++)
211 {
212 WCHAR str[ATOM_BUFFER_SIZE];
213
214 if(!GlobalGetAtomNameW(i->Atom, str, ATOM_BUFFER_SIZE))
215 continue;
216
217 ret = lpEnumFunc(hWnd, str, i->Data, lParam);
218 if(!ret)
219 break;
220 }
221
222 RtlFreeHeap(GetProcessHeap(), 0, pli);
223 }
224
225 return ret;
226 }
227
228
229 /*
230 * @implemented
231 */
232 int STDCALL
233 EnumPropsW(HWND hWnd, PROPENUMPROCW lpEnumFunc)
234 {
235 PPROPLISTITEM pli, i;
236 NTSTATUS Status;
237 DWORD Count;
238 int ret = -1;
239
240 if(!lpEnumFunc)
241 {
242 SetLastError(ERROR_INVALID_PARAMETER);
243 return ret;
244 }
245
246 Status = NtUserBuildPropList(hWnd, NULL, 0, &Count);
247 if(!NT_SUCCESS(Status))
248 {
249 if(Status == STATUS_INVALID_HANDLE)
250 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
251 else
252 SetLastError(RtlNtStatusToDosError(Status));
253 return ret;
254 }
255
256 if(Count > 0)
257 {
258 pli = RtlAllocateHeap(GetProcessHeap(), 0, Count);
259
260 Status = NtUserBuildPropList(hWnd, (LPVOID)pli, Count, &Count);
261 if(!NT_SUCCESS(Status))
262 {
263 RtlFreeHeap(GetProcessHeap(), 0, pli);
264 if(Status == STATUS_INVALID_HANDLE)
265 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
266 else
267 SetLastError(RtlNtStatusToDosError(Status));
268 return ret;
269 }
270
271 i = pli;
272 for(; Count > 0; Count--, i++)
273 {
274 WCHAR str[ATOM_BUFFER_SIZE];
275
276 if(!GlobalGetAtomNameW(i->Atom, str, ATOM_BUFFER_SIZE))
277 continue;
278
279 ret = lpEnumFunc(hWnd, str, i->Data);
280 if(!ret)
281 break;
282 }
283
284 RtlFreeHeap(GetProcessHeap(), 0, pli);
285 }
286
287 return ret;
288 }
289
290
291 /*
292 * @implemented
293 */
294 HANDLE STDCALL
295 GetPropA(HWND hWnd, LPCSTR lpString)
296 {
297 PWSTR lpWString;
298 UNICODE_STRING UString;
299 HANDLE Ret;
300 if (HIWORD(lpString))
301 {
302 RtlCreateUnicodeStringFromAsciiz(&UString, (LPSTR)lpString);
303 lpWString = UString.Buffer;
304 if (lpWString == NULL)
305 {
306 return(FALSE);
307 }
308 Ret = GetPropW(hWnd, lpWString);
309 RtlFreeUnicodeString(&UString);
310 }
311 else
312 {
313 Ret = GetPropW(hWnd, (LPWSTR)lpString);
314 }
315 return(Ret);
316 }
317
318
319 /*
320 * @implemented
321 */
322 HANDLE STDCALL
323 GetPropW(HWND hWnd, LPCWSTR lpString)
324 {
325 ATOM Atom;
326 if (HIWORD(lpString))
327 {
328 Atom = GlobalFindAtomW(lpString);
329 }
330 else
331 {
332 Atom = LOWORD((DWORD)lpString);
333 }
334 return(NtUserGetProp(hWnd, Atom));
335 }
336
337
338 /*
339 * @implemented
340 */
341 HANDLE STDCALL
342 RemovePropA(HWND hWnd, LPCSTR lpString)
343 {
344 PWSTR lpWString;
345 UNICODE_STRING UString;
346 HANDLE Ret;
347
348 if (HIWORD(lpString))
349 {
350 RtlCreateUnicodeStringFromAsciiz(&UString, (LPSTR)lpString);
351 lpWString = UString.Buffer;
352 if (lpWString == NULL)
353 {
354 return(FALSE);
355 }
356 Ret = RemovePropW(hWnd, lpWString);
357 RtlFreeUnicodeString(&UString);
358 }
359 else
360 {
361 Ret = RemovePropW(hWnd, (LPCWSTR)lpString);
362 }
363 return(Ret);
364 }
365
366
367 /*
368 * @implemented
369 */
370 HANDLE STDCALL
371 RemovePropW(HWND hWnd,
372 LPCWSTR lpString)
373 {
374 ATOM Atom;
375 if (HIWORD(lpString))
376 {
377 Atom = GlobalFindAtomW(lpString);
378 }
379 else
380 {
381 Atom = LOWORD((DWORD)lpString);
382 }
383 return(NtUserRemoveProp(hWnd, Atom));
384 }
385
386
387 /*
388 * @implemented
389 */
390 BOOL STDCALL
391 SetPropA(HWND hWnd, LPCSTR lpString, HANDLE hData)
392 {
393 PWSTR lpWString;
394 UNICODE_STRING UString;
395 BOOL Ret;
396
397 if (HIWORD(lpString))
398 {
399 RtlCreateUnicodeStringFromAsciiz(&UString, (LPSTR)lpString);
400 lpWString = UString.Buffer;
401 if (lpWString == NULL)
402 {
403 return(FALSE);
404 }
405 Ret = SetPropW(hWnd, lpWString, hData);
406 RtlFreeUnicodeString(&UString);
407 }
408 else
409 {
410 Ret = SetPropW(hWnd, (LPWSTR)lpString, hData);
411 }
412 return(Ret);
413 }
414
415
416 /*
417 * @implemented
418 */
419 BOOL STDCALL
420 SetPropW(HWND hWnd, LPCWSTR lpString, HANDLE hData)
421 {
422 ATOM Atom;
423 if (HIWORD(lpString))
424 {
425 Atom = GlobalAddAtomW(lpString);
426 }
427 else
428 {
429 Atom = LOWORD((DWORD)lpString);
430 }
431
432 return(NtUserSetProp(hWnd, Atom, hData));
433 }