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: win32ss/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 #define ATOM_BUFFER_SIZE 256 33 34 /* INTERNAL FUNCTIONS ********************************************************/ 35 36 HANDLE 37 FASTCALL 38 IntGetProp(HWND hWnd, ATOM Atom, BOOLEAN SystemProp) 39 { 40 PLIST_ENTRY ListEntry, temp; 41 PPROPERTY Property; 42 PWND pWnd; 43 int i; 44 WORD SystemFlag = SystemProp ? PROPERTY_FLAG_SYSTEM : 0; 45 46 pWnd = ValidateHwnd(hWnd); 47 if (!pWnd) return NULL; 48 49 ListEntry = SharedPtrToUser(pWnd->PropListHead.Flink); 50 for (i = 0; i < pWnd->PropListItems; i++ ) 51 { 52 Property = CONTAINING_RECORD(ListEntry, PROPERTY, PropListEntry); 53 if (Property->Atom == Atom && 54 (Property->fs & PROPERTY_FLAG_SYSTEM) == SystemFlag) 55 { 56 return(Property); 57 } 58 temp = ListEntry->Flink; 59 ListEntry = SharedPtrToUser(temp); 60 } 61 return NULL; 62 } 63 64 HANDLE 65 FASTCALL 66 UserGetProp(HWND hWnd, ATOM Atom, BOOLEAN SystemProp) 67 { 68 PPROPERTY Prop; 69 Prop = IntGetProp(hWnd, Atom, SystemProp); 70 return Prop ? Prop->Data : NULL; 71 } 72 73 /* FUNCTIONS *****************************************************************/ 74 75 /* 76 * @implemented 77 */ 78 int WINAPI 79 EnumPropsA(HWND hWnd, PROPENUMPROCA lpEnumFunc) 80 { 81 PPROPLISTITEM pli, i; 82 NTSTATUS Status; 83 DWORD Count; 84 int ret = -1; 85 86 if(!lpEnumFunc) 87 { 88 SetLastError(ERROR_INVALID_PARAMETER); 89 return ret; 90 } 91 92 Status = NtUserBuildPropList(hWnd, NULL, 0, &Count); 93 if(!NT_SUCCESS(Status)) 94 { 95 if(Status == STATUS_INVALID_HANDLE) 96 SetLastError(ERROR_INVALID_WINDOW_HANDLE); 97 else 98 SetLastError(RtlNtStatusToDosError(Status)); 99 return ret; 100 } 101 102 if(Count > 0) 103 { 104 pli = RtlAllocateHeap(GetProcessHeap(), 0, Count); 105 if (pli == NULL) 106 { 107 SetLastError(ERROR_OUTOFMEMORY); 108 return -1; 109 } 110 111 Status = NtUserBuildPropList(hWnd, (LPVOID)pli, Count, &Count); 112 if(!NT_SUCCESS(Status)) 113 { 114 RtlFreeHeap(GetProcessHeap(), 0, pli); 115 if(Status == STATUS_INVALID_HANDLE) 116 SetLastError(ERROR_INVALID_WINDOW_HANDLE); 117 else 118 SetLastError(RtlNtStatusToDosError(Status)); 119 return ret; 120 } 121 122 i = pli; 123 for(; Count > 0; Count--, i++) 124 { 125 char str[ATOM_BUFFER_SIZE]; 126 127 if(!GlobalGetAtomNameA(i->Atom, str, ATOM_BUFFER_SIZE)) 128 continue; 129 130 ret = lpEnumFunc(hWnd, str, i->Data); 131 if(!ret) 132 break; 133 } 134 135 RtlFreeHeap(GetProcessHeap(), 0, pli); 136 } 137 138 return ret; 139 } 140 141 142 /* 143 * @implemented 144 */ 145 int WINAPI 146 EnumPropsExA(HWND hWnd, PROPENUMPROCEXA lpEnumFunc, LPARAM lParam) 147 { 148 PPROPLISTITEM pli, i; 149 NTSTATUS Status; 150 DWORD Count; 151 int ret = -1; 152 153 if(!lpEnumFunc) 154 { 155 SetLastError(ERROR_INVALID_PARAMETER); 156 return ret; 157 } 158 159 Status = NtUserBuildPropList(hWnd, NULL, 0, &Count); 160 if(!NT_SUCCESS(Status)) 161 { 162 if(Status == STATUS_INVALID_HANDLE) 163 SetLastError(ERROR_INVALID_WINDOW_HANDLE); 164 else 165 SetLastError(RtlNtStatusToDosError(Status)); 166 return ret; 167 } 168 169 if(Count > 0) 170 { 171 pli = RtlAllocateHeap(GetProcessHeap(), 0, Count); 172 if (pli == NULL) 173 { 174 SetLastError(ERROR_OUTOFMEMORY); 175 return -1; 176 } 177 178 Status = NtUserBuildPropList(hWnd, (LPVOID)pli, Count, &Count); 179 if(!NT_SUCCESS(Status)) 180 { 181 RtlFreeHeap(GetProcessHeap(), 0, pli); 182 if(Status == STATUS_INVALID_HANDLE) 183 SetLastError(ERROR_INVALID_WINDOW_HANDLE); 184 else 185 SetLastError(RtlNtStatusToDosError(Status)); 186 return ret; 187 } 188 189 i = pli; 190 for(; Count > 0; Count--, i++) 191 { 192 char str[ATOM_BUFFER_SIZE]; 193 194 if(!GlobalGetAtomNameA(i->Atom, str, ATOM_BUFFER_SIZE)) 195 continue; 196 197 ret = lpEnumFunc(hWnd, str, i->Data, lParam); 198 if(!ret) 199 break; 200 } 201 202 RtlFreeHeap(GetProcessHeap(), 0, pli); 203 } 204 205 return ret; 206 } 207 208 209 /* 210 * @implemented 211 */ 212 int WINAPI 213 EnumPropsExW(HWND hWnd, PROPENUMPROCEXW lpEnumFunc, LPARAM lParam) 214 { 215 PPROPLISTITEM pli, i; 216 NTSTATUS Status; 217 DWORD Count; 218 int ret = -1; 219 220 if(!lpEnumFunc) 221 { 222 SetLastError(ERROR_INVALID_PARAMETER); 223 return ret; 224 } 225 226 Status = NtUserBuildPropList(hWnd, NULL, 0, &Count); 227 if(!NT_SUCCESS(Status)) 228 { 229 if(Status == STATUS_INVALID_HANDLE) 230 SetLastError(ERROR_INVALID_WINDOW_HANDLE); 231 else 232 SetLastError(RtlNtStatusToDosError(Status)); 233 return ret; 234 } 235 236 if(Count > 0) 237 { 238 pli = RtlAllocateHeap(GetProcessHeap(), 0, Count); 239 if (pli == NULL) 240 { 241 SetLastError(ERROR_OUTOFMEMORY); 242 return -1; 243 } 244 245 Status = NtUserBuildPropList(hWnd, (LPVOID)pli, Count, &Count); 246 if(!NT_SUCCESS(Status)) 247 { 248 RtlFreeHeap(GetProcessHeap(), 0, pli); 249 if(Status == STATUS_INVALID_HANDLE) 250 SetLastError(ERROR_INVALID_WINDOW_HANDLE); 251 else 252 SetLastError(RtlNtStatusToDosError(Status)); 253 return ret; 254 } 255 256 i = pli; 257 for(; Count > 0; Count--, i++) 258 { 259 WCHAR str[ATOM_BUFFER_SIZE]; 260 261 if(!GlobalGetAtomNameW(i->Atom, str, ATOM_BUFFER_SIZE)) 262 continue; 263 264 ret = lpEnumFunc(hWnd, str, i->Data, lParam); 265 if(!ret) 266 break; 267 } 268 269 RtlFreeHeap(GetProcessHeap(), 0, pli); 270 } 271 272 return ret; 273 } 274 275 276 /* 277 * @implemented 278 */ 279 int WINAPI 280 EnumPropsW(HWND hWnd, PROPENUMPROCW lpEnumFunc) 281 { 282 PPROPLISTITEM pli, i; 283 NTSTATUS Status; 284 DWORD Count; 285 int ret = -1; 286 287 if(!lpEnumFunc) 288 { 289 SetLastError(ERROR_INVALID_PARAMETER); 290 return ret; 291 } 292 293 Status = NtUserBuildPropList(hWnd, NULL, 0, &Count); 294 if(!NT_SUCCESS(Status)) 295 { 296 if(Status == STATUS_INVALID_HANDLE) 297 SetLastError(ERROR_INVALID_WINDOW_HANDLE); 298 else 299 SetLastError(RtlNtStatusToDosError(Status)); 300 return ret; 301 } 302 303 if(Count > 0) 304 { 305 pli = RtlAllocateHeap(GetProcessHeap(), 0, Count); 306 if (pli == NULL) 307 { 308 SetLastError(ERROR_OUTOFMEMORY); 309 return -1; 310 } 311 312 Status = NtUserBuildPropList(hWnd, (LPVOID)pli, Count, &Count); 313 if(!NT_SUCCESS(Status)) 314 { 315 RtlFreeHeap(GetProcessHeap(), 0, pli); 316 if(Status == STATUS_INVALID_HANDLE) 317 SetLastError(ERROR_INVALID_WINDOW_HANDLE); 318 else 319 SetLastError(RtlNtStatusToDosError(Status)); 320 return ret; 321 } 322 323 i = pli; 324 for(; Count > 0; Count--, i++) 325 { 326 WCHAR str[ATOM_BUFFER_SIZE]; 327 328 if(!GlobalGetAtomNameW(i->Atom, str, ATOM_BUFFER_SIZE)) 329 continue; 330 331 ret = lpEnumFunc(hWnd, str, i->Data); 332 if(!ret) 333 break; 334 } 335 336 RtlFreeHeap(GetProcessHeap(), 0, pli); 337 } 338 339 return ret; 340 } 341 342 343 /* 344 * @implemented 345 */ 346 HANDLE WINAPI 347 GetPropA(HWND hWnd, LPCSTR lpString) 348 { 349 PWSTR lpWString; 350 UNICODE_STRING UString; 351 HANDLE Ret; 352 if (HIWORD(lpString)) 353 { 354 RtlCreateUnicodeStringFromAsciiz(&UString, (LPSTR)lpString); 355 lpWString = UString.Buffer; 356 if (lpWString == NULL) 357 { 358 return(FALSE); 359 } 360 Ret = GetPropW(hWnd, lpWString); 361 RtlFreeUnicodeString(&UString); 362 } 363 else 364 { 365 Ret = GetPropW(hWnd, (LPWSTR)lpString); 366 } 367 return(Ret); 368 } 369 370 371 /* 372 * @implemented 373 */ 374 HANDLE WINAPI 375 GetPropW(HWND hWnd, LPCWSTR lpString) 376 { 377 ATOM Atom; 378 HANDLE Data = NULL; 379 PPROPERTY Prop; 380 if (HIWORD(lpString)) 381 { 382 Atom = GlobalFindAtomW(lpString); 383 } 384 else 385 { 386 Atom = LOWORD((DWORD_PTR)lpString); 387 } 388 Prop = IntGetProp(hWnd, Atom, FALSE); 389 if (Prop != NULL) Data = Prop->Data; 390 return Data; 391 } 392 393 394 /* 395 * @implemented 396 */ 397 HANDLE WINAPI 398 RemovePropA(HWND hWnd, LPCSTR lpString) 399 { 400 PWSTR lpWString; 401 UNICODE_STRING UString; 402 HANDLE Ret; 403 404 if (HIWORD(lpString)) 405 { 406 RtlCreateUnicodeStringFromAsciiz(&UString, (LPSTR)lpString); 407 lpWString = UString.Buffer; 408 if (lpWString == NULL) 409 { 410 return(FALSE); 411 } 412 Ret = RemovePropW(hWnd, lpWString); 413 RtlFreeUnicodeString(&UString); 414 } 415 else 416 { 417 Ret = RemovePropW(hWnd, (LPCWSTR)lpString); 418 } 419 return(Ret); 420 } 421 422 423 /* 424 * @implemented 425 */ 426 HANDLE WINAPI 427 RemovePropW(HWND hWnd, 428 LPCWSTR lpString) 429 { 430 ATOM Atom; 431 if (HIWORD(lpString)) 432 { 433 Atom = GlobalFindAtomW(lpString); 434 } 435 else 436 { 437 Atom = LOWORD((DWORD_PTR)lpString); 438 } 439 return(NtUserRemoveProp(hWnd, Atom)); 440 } 441 442 443 /* 444 * @implemented 445 */ 446 BOOL WINAPI 447 SetPropA(HWND hWnd, LPCSTR lpString, HANDLE hData) 448 { 449 PWSTR lpWString; 450 UNICODE_STRING UString; 451 BOOL Ret; 452 453 if (HIWORD(lpString)) 454 { 455 RtlCreateUnicodeStringFromAsciiz(&UString, (LPSTR)lpString); 456 lpWString = UString.Buffer; 457 if (lpWString == NULL) 458 { 459 return(FALSE); 460 } 461 Ret = SetPropW(hWnd, lpWString, hData); 462 RtlFreeUnicodeString(&UString); 463 } 464 else 465 { 466 Ret = SetPropW(hWnd, (LPWSTR)lpString, hData); 467 } 468 return(Ret); 469 } 470 471 472 /* 473 * @implemented 474 */ 475 BOOL WINAPI 476 SetPropW(HWND hWnd, LPCWSTR lpString, HANDLE hData) 477 { 478 ATOM Atom; 479 if (HIWORD(lpString)) 480 { 481 Atom = GlobalAddAtomW(lpString); 482 } 483 else 484 { 485 Atom = LOWORD((DWORD_PTR)lpString); 486 } 487 488 return(NtUserSetProp(hWnd, Atom, hData)); 489 } 490