Changeset 295 for trunk/src/comctl32/comctl32undoc.c
- Timestamp:
- Jul 12, 1999, 5:58:51 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/comctl32/comctl32undoc.c
r164 r295 1 /* $Id: comctl32undoc.c,v 1. 7 1999-06-23 19:45:00 achimhaExp $ */1 /* $Id: comctl32undoc.c,v 1.8 1999-07-12 15:58:46 cbratschi Exp $ */ 2 2 /* 3 3 * Undocumented functions from COMCTL32.DLL … … 11 11 * 12 12 */ 13 14 /* CB: todo 15 - porting/implementing string functions 16 - DPA_LoadStream 17 - DPA_SaveStream 18 */ 13 19 14 20 #include "comctl32.h" … … 28 34 * dwFlags [I] flags 29 35 * pfnSort [I] pointer to sort function 30 * dwParam5 [I]36 * pfnMerge [I] pointer to merge function 31 37 * lParam [I] application specific value 32 38 * … … 37 43 BOOL WINAPI 38 44 DPA_Merge (const HDPA hdpa1, const HDPA hdpa2, DWORD dwFlags, 39 PFNDPACOMPARE pfnCompare, LPVOID pfnParam5, LPARAM lParam) 40 { 41 /* LPVOID *pWork1, *pWork2; */ 42 INT nCount1, nCount2; 45 PFNDPACOMPARE pfnCompare, PFNDPAMERGE pfnMerge, LPARAM lParam) 46 { 47 LPVOID pWork1, pWork2; 48 INT nResult; 49 INT nCount, nIndex; 50 INT nNewItems; 43 51 44 52 // TRACE (commctrl, "(%p %p %08lx %p %p %08lx): stub!\n", 45 // 53 // hdpa1, hdpa2, dwFlags, pfnCompare, pfnParam5, lParam); 46 54 47 55 if (IsBadWritePtr (hdpa1, sizeof(DPA))) 48 56 return FALSE; 49 57 50 58 if (IsBadWritePtr (hdpa2, sizeof(DPA))) 51 59 return FALSE; 52 60 53 61 if (IsBadCodePtr ((FARPROC)pfnCompare)) 54 55 56 if (IsBadCodePtr ((FARPROC)pfn Param5))57 62 return FALSE; 63 64 if (IsBadCodePtr ((FARPROC)pfnMerge)) 65 return FALSE; 58 66 59 67 if (dwFlags & DPAM_SORT) { 60 // TRACE (commctrl, "sorting dpa's!\n"); 61 DPA_Sort (hdpa1, pfnCompare, lParam); 62 DPA_Sort (hdpa2, pfnCompare, lParam); 63 } 64 65 if (hdpa2->nItemCount <= 0) 66 return TRUE; 67 68 nCount1 = hdpa1->nItemCount - 1; 69 70 nCount2 = hdpa2->nItemCount - 1; 71 72 // FIXME (commctrl, "nCount1=%d nCount2=%d\n", nCount1, nCount2); 73 // FIXME (commctrl, "semi stub!\n"); 68 // TRACE("sorting dpa's!\n"); 69 if (hdpa1->nItemCount > 0) 70 DPA_Sort (hdpa1, pfnCompare, lParam); 71 // TRACE ("dpa 1 sorted!\n"); 72 if (hdpa2->nItemCount > 0) 73 DPA_Sort (hdpa2, pfnCompare, lParam); 74 // TRACE ("dpa 2 sorted!\n"); 75 } 76 77 if (hdpa2->nItemCount < 1) 78 return TRUE; 79 80 // TRACE("hdpa1->nItemCount=%d hdpa2->nItemCount=%d\n", 81 // hdpa1->nItemCount, hdpa2->nItemCount); 82 83 84 /* preliminary hack - simply append the pointer list hdpa2 to hdpa1*/ 85 for (nCount = 0; nCount < hdpa2->nItemCount; nCount++) 86 DPA_InsertPtr (hdpa1, hdpa1->nItemCount + 1, hdpa2->ptrs[nCount]); 87 74 88 #if 0 75 76 do { 77 78 79 if (nResult == 0) { 80 81 } 82 else if (nResult > 0) { 83 84 } 85 else { 86 87 } 88 89 } 90 while (nCount2 >= 0); 91 89 /* incomplete implementation */ 90 91 pWork1 = &(hdpa1->ptrs[hdpa1->nItemCount - 1]); 92 pWork2 = &(hdpa2->ptrs[hdpa2->nItemCount - 1]); 93 94 nIndex = hdpa1->nItemCount - 1; 95 nCount = hdpa2->nItemCount - 1; 96 97 do 98 { 99 nResult = (pfnCompare)(pWork1, pWork2, lParam); 100 101 if (nResult == 0) 102 { 103 PVOID ptr; 104 105 ptr = (pfnMerge)(1, pWork1, pWork2, lParam); 106 if (!ptr) 107 return FALSE; 108 109 nCount--; 110 pWork2--; 111 pWork1 = ptr; 112 } 113 else if (nResult < 0) 114 { 115 if (!dwFlags & 8) 116 { 117 PVOID ptr; 118 119 ptr = DPA_DeletePtr (hdpa1, hdpa1->nItemCount - 1); 120 121 (pfnMerge)(2, ptr, NULL, lParam); 122 } 123 } 124 else 125 { 126 if (!dwFlags & 4) 127 { 128 PVOID ptr; 129 130 ptr = (pfnMerge)(3, pWork2, NULL, lParam); 131 if (!ptr) 132 return FALSE; 133 DPA_InsertPtr (hdpa1, nIndex, ptr); 134 } 135 nCount--; 136 pWork2--; 137 } 138 139 nIndex--; 140 pWork1--; 141 142 } 143 while (nCount >= 0); 92 144 #endif 93 94 145 95 146 return TRUE; … … 145 196 146 197 if (lpSrc) 147 198 lpDest = HeapReAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, lpSrc, dwSize); 148 199 else 149 200 lpDest = HeapAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, dwSize); 150 201 151 202 return lpDest; … … 210 261 } MRUINFO, *LPMRUINFO; 211 262 212 263 213 264 typedef struct tagMRU 214 265 { … … 223 274 LPVOID WINAPI 224 275 CreateMRUListLazyA (LPMRUINFO lpmi, DWORD dwParam2, 225 276 DWORD dwParam3, DWORD dwParam4); 226 277 227 278 … … 249 300 #if 0 250 301 if (!(hmru->dwParam1 & 1001)) { 251 252 253 302 RegSetValueExA (hmru->hKeyMRU, "MRUList", 0, REG_SZ, 303 hmru->lpszMRUString, 304 lstrlenA (hmru->lpszMRUString)); 254 305 } 255 306 … … 269 320 270 321 // FIXME (commctrl, "(%lx %lx %lx) empty stub!\n", 271 // 322 // dwParam1, dwParam2, dwParam3); 272 323 273 324 return 0; … … 280 331 281 332 // FIXME (commctrl, "(%lx %lx %lx %lx) empty stub!\n", 282 // 333 // dwParam1, dwParam2, dwParam3, dwParam4); 283 334 284 335 return TRUE; … … 304 355 305 356 if (lpmi) { 306 // 307 // 308 // 357 // FIXME (commctrl, "(%lx %lx %lx %lx \"%s\" %lx)\n", 358 // lpmi->dwParam1, lpmi->dwParam2, lpmi->dwParam3, 359 // (DWORD)lpmi->hkeyMain, lpmi->lpszSubKey, lpmi->dwParam6); 309 360 } 310 361 … … 338 389 339 390 if (!lpDest && lpSrc) 340 391 return lstrlenA (lpSrc); 341 392 342 393 if (nMaxLen == 0) 343 394 return 0; 344 395 345 396 if (lpSrc == NULL) { 346 347 397 lpDest[0] = '\0'; 398 return 0; 348 399 } 349 400 350 401 len = lstrlenA (lpSrc); 351 402 if (len >= nMaxLen) 352 403 len = nMaxLen - 1; 353 404 354 405 RtlMoveMemory (lpDest, lpSrc, len); … … 373 424 { 374 425 // TRACE (commctrl, "(%p %p)\n", lppDest, lpSrc); 375 426 376 427 if (lpSrc) { 377 378 379 380 381 428 LPSTR ptr = COMCTL32_ReAlloc (*lppDest, lstrlenA (lpSrc) + 1); 429 if (!ptr) 430 return FALSE; 431 lstrcpyA (ptr, lpSrc); 432 *lppDest = ptr; 382 433 } 383 434 else { 384 385 386 387 435 if (*lppDest) { 436 COMCTL32_Free (*lppDest); 437 *lppDest = NULL; 438 } 388 439 } 389 440 … … 411 462 412 463 if (!lpDest && lpSrc) 413 464 return lstrlenW (lpSrc); 414 465 415 466 if (nMaxLen == 0) 416 467 return 0; 417 468 418 469 if (lpSrc == NULL) { 419 420 470 lpDest[0] = L'\0'; 471 return 0; 421 472 } 422 473 423 474 len = lstrlenW (lpSrc); 424 475 if (len >= nMaxLen) 425 476 len = nMaxLen - 1; 426 477 427 478 RtlMoveMemory (lpDest, lpSrc, len*sizeof(WCHAR)); … … 446 497 { 447 498 // TRACE (commctrl, "(%p %p)\n", lppDest, lpSrc); 448 499 449 500 if (lpSrc) { 450 451 452 453 454 455 501 INT len = lstrlenW (lpSrc) + 1; 502 LPWSTR ptr = COMCTL32_ReAlloc (*lppDest, len * sizeof(WCHAR)); 503 if (!ptr) 504 return FALSE; 505 lstrcpyW (ptr, lpSrc); 506 *lppDest = ptr; 456 507 } 457 508 else { 458 459 460 461 509 if (*lppDest) { 510 COMCTL32_Free (*lppDest); 511 *lppDest = NULL; 512 } 462 513 } 463 514 … … 494 545 if (hdsa) 495 546 { 496 547 hdsa->nItemCount = 0; 497 548 hdsa->pData = NULL; 498 499 500 549 hdsa->nMaxCount = 0; 550 hdsa->nItemSize = nSize; 551 hdsa->nGrow = MAX(1, nGrow); 501 552 } 502 553 … … 522 573 523 574 if (!hdsa) 524 575 return FALSE; 525 576 526 577 if (hdsa->pData && (!COMCTL32_Free (hdsa->pData))) 527 578 return FALSE; 528 579 529 580 return COMCTL32_Free (hdsa); … … 532 583 533 584 /************************************************************************** 534 * DSA_GetItem [COMCTL32.322] 585 * DSA_GetItem [COMCTL32.322] 535 586 * 536 587 * PARAMS … … 550 601 551 602 // TRACE (commctrl, "(%p %d %p)\n", hdsa, nIndex, pDest); 552 603 553 604 if (!hdsa) 554 605 return FALSE; 555 606 if ((nIndex < 0) || (nIndex >= hdsa->nItemCount)) 556 607 return FALSE; 557 608 558 609 pSrc = (char *) hdsa->pData + (hdsa->nItemSize * nIndex); … … 564 615 565 616 /************************************************************************** 566 * DSA_GetItemPtr [COMCTL32.323] 617 * DSA_GetItemPtr [COMCTL32.323] 567 618 * 568 619 * Retrieves a pointer to the specified item. … … 585 636 586 637 if (!hdsa) 587 638 return NULL; 588 639 if ((nIndex < 0) || (nIndex >= hdsa->nItemCount)) 589 640 return NULL; 590 641 591 642 pSrc = (char *) hdsa->pData + (hdsa->nItemSize * nIndex); 592 643 593 644 // TRACE (commctrl, "-- ret=%p\n", pSrc); 594 645 … … 598 649 599 650 /************************************************************************** 600 * DSA_SetItem [COMCTL32.325] 651 * DSA_SetItem [COMCTL32.325] 601 652 * 602 653 * Sets the contents of an item in the array. … … 617 668 INT nSize, nNewItems; 618 669 LPVOID pDest, lpTemp; 619 670 620 671 // TRACE("(%p %d %p)\n", hdsa, nIndex, pSrc); 621 672 622 673 if ((!hdsa) || nIndex < 0) 623 624 674 return FALSE; 675 625 676 if (hdsa->nItemCount <= nIndex) { 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 } 677 /* within the old array */ 678 if (hdsa->nMaxCount > nIndex) { 679 /* within the allocated space, set a new boundary */ 680 hdsa->nItemCount = nIndex + 1; 681 } 682 else { 683 /* resize the block of memory */ 684 nNewItems = 685 hdsa->nGrow * ((INT)((nIndex - 1) / hdsa->nGrow) + 1); 686 nSize = hdsa->nItemSize * nNewItems; 687 688 lpTemp = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize); 689 if (!lpTemp) 690 return FALSE; 691 692 hdsa->nMaxCount = nNewItems; 693 hdsa->nItemCount = nIndex + 1; 694 hdsa->pData = lpTemp; 695 } 645 696 } 646 697 … … 648 699 pDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex); 649 700 // TRACE("-- move dest=%p src=%p size=%d\n", 650 // 701 // pDest, pSrc, hdsa->nItemSize); 651 702 memmove (pDest, pSrc, hdsa->nItemSize); 652 703 … … 656 707 657 708 /************************************************************************** 658 * DSA_InsertItem [COMCTL32.325] 709 * DSA_InsertItem [COMCTL32.325] 659 710 * 660 711 * PARAMS … … 674 725 LPVOID lpTemp, lpDest; 675 726 LPDWORD p; 676 727 677 728 // TRACE("(%p %d %p)\n", hdsa, nIndex, pSrc); 678 729 679 730 if ((!hdsa) || nIndex < 0) 680 731 return -1; 681 732 682 733 for (i = 0; i < hdsa->nItemSize; i += 4) { 683 684 // 685 // 686 // 687 // 688 } 689 734 p = *(DWORD**)((char *) pSrc + i); 735 // if (IsBadStringPtrA ((char*)p, 256)) 736 // TRACE("-- %d=%p\n", i, (DWORD*)p); 737 // else 738 // TRACE("-- %d=%p [%s]\n", i, p, debugstr_a((char*)p)); 739 } 740 690 741 /* when nIndex > nItemCount then append */ 691 742 if (nIndex >= hdsa->nItemCount) 692 743 nIndex = hdsa->nItemCount; 693 744 694 745 /* do we need to resize ? */ 695 746 if (hdsa->nItemCount >= hdsa->nMaxCount) { 696 697 698 699 700 701 702 703 704 hdsa->pData = lpTemp; 747 nNewItems = hdsa->nMaxCount + hdsa->nGrow; 748 nSize = hdsa->nItemSize * nNewItems; 749 750 lpTemp = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize); 751 if (!lpTemp) 752 return -1; 753 754 hdsa->nMaxCount = nNewItems; 755 hdsa->pData = lpTemp; 705 756 } 706 757 707 758 /* do we need to move elements ? */ 708 759 if (nIndex < hdsa->nItemCount) { 709 710 711 712 // 713 // 714 760 lpTemp = (char *) hdsa->pData + (hdsa->nItemSize * nIndex); 761 lpDest = (char *) lpTemp + hdsa->nItemSize; 762 nSize = (hdsa->nItemCount - nIndex) * hdsa->nItemSize; 763 // TRACE("-- move dest=%p src=%p size=%d\n", 764 // lpDest, lpTemp, nSize); 765 memmove (lpDest, lpTemp, nSize); 715 766 } 716 767 … … 719 770 lpDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex); 720 771 // TRACE("-- move dest=%p src=%p size=%d\n", 721 // 772 // lpDest, pSrc, hdsa->nItemSize); 722 773 memmove (lpDest, pSrc, hdsa->nItemSize); 723 774 … … 727 778 728 779 /************************************************************************** 729 * DSA_DeleteItem [COMCTL32.326] 780 * DSA_DeleteItem [COMCTL32.326] 730 781 * 731 782 * PARAMS … … 743 794 LPVOID lpDest,lpSrc; 744 795 INT nSize; 745 796 746 797 // TRACE (commctrl, "(%p %d)\n", hdsa, nIndex); 747 798 748 799 if (!hdsa) 749 800 return -1; 750 801 if (nIndex < 0 || nIndex >= hdsa->nItemCount) 751 802 return -1; 752 803 753 804 /* do we need to move ? */ 754 805 if (nIndex < hdsa->nItemCount - 1) { 755 756 757 758 // 759 // 760 761 } 762 806 lpDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex); 807 lpSrc = (char *) lpDest + hdsa->nItemSize; 808 nSize = hdsa->nItemSize * (hdsa->nItemCount - nIndex - 1); 809 // TRACE (commctrl, "-- move dest=%p src=%p size=%d\n", 810 // lpDest, lpSrc, nSize); 811 memmove (lpDest, lpSrc, nSize); 812 } 813 763 814 hdsa->nItemCount--; 764 815 765 816 /* free memory ? */ 766 817 if ((hdsa->nMaxCount - hdsa->nItemCount) >= hdsa->nGrow) { 767 768 769 770 771 772 773 774 818 nSize = hdsa->nItemSize * hdsa->nItemCount; 819 820 lpDest = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize); 821 if (!lpDest) 822 return -1; 823 824 hdsa->nMaxCount = hdsa->nItemCount; 825 hdsa->pData = lpDest; 775 826 } 776 827 … … 797 848 // TRACE (commctrl, "(%p)\n", hdsa); 798 849 799 if (!hdsa) 800 850 if (!hdsa) 851 return FALSE; 801 852 if (hdsa->pData && (!COMCTL32_Free (hdsa->pData))) 802 853 return FALSE; 803 854 804 855 hdsa->nItemCount = 0; … … 835 886 hdpa = (HDPA)COMCTL32_Alloc (sizeof(DPA)); 836 887 if (hdpa) { 837 838 839 840 841 888 hdpa->nGrow = MAX(8, nGrow); 889 hdpa->hHeap = COMCTL32_hHeap; 890 hdpa->nMaxCount = hdpa->nGrow * 2; 891 hdpa->ptrs = 892 (LPVOID*)COMCTL32_Alloc (hdpa->nMaxCount * sizeof(LPVOID)); 842 893 } 843 894 … … 865 916 866 917 if (!hdpa) 867 918 return FALSE; 868 919 869 920 if (hdpa->ptrs && (!HeapFree (hdpa->hHeap, 0, hdpa->ptrs))) 870 921 return FALSE; 871 922 872 923 return HeapFree (hdpa->hHeap, 0, hdpa); … … 894 945 895 946 if (!hdpa) 896 947 return FALSE; 897 948 898 949 hdpa->nGrow = MAX(8, nGrow); … … 929 980 930 981 if (!hdpa) 931 982 return NULL; 932 983 933 984 // TRACE (commctrl, "(%p %p)\n", hdpa, hdpaNew); 934 985 935 986 if (!hdpaNew) { 936 937 938 939 940 987 /* create a new DPA */ 988 hdpaTemp = (HDPA)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY, 989 sizeof(DPA)); 990 hdpaTemp->hHeap = hdpa->hHeap; 991 hdpaTemp->nGrow = hdpa->nGrow; 941 992 } 942 993 else 943 994 hdpaTemp = hdpaNew; 944 995 945 996 if (hdpaTemp->ptrs) { 946 947 948 949 950 997 /* remove old pointer array */ 998 HeapFree (hdpaTemp->hHeap, 0, hdpaTemp->ptrs); 999 hdpaTemp->ptrs = NULL; 1000 hdpaTemp->nItemCount = 0; 1001 hdpaTemp->nMaxCount = 0; 951 1002 } 952 1003 953 1004 /* create a new pointer array */ 954 1005 nNewItems = hdpaTemp->nGrow * 955 1006 ((INT)((hdpa->nItemCount - 1) / hdpaTemp->nGrow) + 1); 956 1007 nSize = nNewItems * sizeof(LPVOID); 957 1008 hdpaTemp->ptrs = 958 1009 (LPVOID*)HeapAlloc (hdpaTemp->hHeap, HEAP_ZERO_MEMORY, nSize); 959 1010 hdpaTemp->nMaxCount = nNewItems; 960 1011 … … 962 1013 hdpaTemp->nItemCount = hdpa->nItemCount; 963 1014 memmove (hdpaTemp->ptrs, hdpa->ptrs, 964 1015 hdpaTemp->nItemCount * sizeof(LPVOID)); 965 1016 966 1017 return hdpaTemp; … … 988 1039 989 1040 if (!hdpa) 990 1041 return NULL; 991 1042 if (!hdpa->ptrs) 992 1043 return NULL; 993 1044 if ((i < 0) || (i >= hdpa->nItemCount)) 994 1045 return NULL; 995 1046 996 1047 // TRACE (commctrl, "-- %p\n", hdpa->ptrs[i]); … … 1020 1071 1021 1072 if (!hdpa->ptrs) 1022 1073 return -1; 1023 1074 1024 1075 for (i = 0; i < hdpa->nItemCount; i++) { 1025 1026 1076 if (hdpa->ptrs[i] == p) 1077 return i; 1027 1078 } 1028 1079 … … 1055 1106 1056 1107 if ((!hdpa) || (i < 0)) 1057 1108 return -1; 1058 1109 1059 1110 if (!hdpa->ptrs) { 1060 1061 1062 1063 1064 1065 1111 hdpa->ptrs = 1112 (LPVOID*)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY, 1113 2 * hdpa->nGrow * sizeof(LPVOID)); 1114 if (!hdpa->ptrs) 1115 return -1; 1116 hdpa->nMaxCount = hdpa->nGrow * 2; 1066 1117 nIndex = 0; 1067 1118 } 1068 1119 else { 1069 1070 // 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 // 1085 1086 1087 // 1088 1089 1090 1091 // 1092 // 1093 1094 1095 1120 if (hdpa->nItemCount >= hdpa->nMaxCount) { 1121 // TRACE (commctrl, "-- resizing\n"); 1122 nNewItems = hdpa->nMaxCount + hdpa->nGrow; 1123 nSize = nNewItems * sizeof(LPVOID); 1124 1125 lpTemp = (LPVOID*)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY, 1126 hdpa->ptrs, nSize); 1127 if (!lpTemp) 1128 return -1; 1129 hdpa->nMaxCount = nNewItems; 1130 hdpa->ptrs = lpTemp; 1131 } 1132 1133 if (i >= hdpa->nItemCount) { 1134 nIndex = hdpa->nItemCount; 1135 // TRACE (commctrl, "-- appending at %d\n", nIndex); 1136 } 1137 else { 1138 // TRACE (commctrl, "-- inserting at %d\n", i); 1139 lpTemp = hdpa->ptrs + i; 1140 lpDest = lpTemp + 1; 1141 nSize = (hdpa->nItemCount - i) * sizeof(LPVOID); 1142 // TRACE (commctrl, "-- move dest=%p src=%p size=%x\n", 1143 // lpDest, lpTemp, nSize); 1144 memmove (lpDest, lpTemp, nSize); 1145 nIndex = i; 1146 } 1096 1147 } 1097 1148 … … 1123 1174 { 1124 1175 LPVOID *lpTemp; 1125 1176 1126 1177 // TRACE (commctrl, "(%p %d %p)\n", hdpa, i, p); 1127 1178 1128 1179 if ((!hdpa) || i < 0) 1129 1130 1180 return FALSE; 1181 1131 1182 if (hdpa->nItemCount <= i) { 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 hdpa->ptrs = lpTemp; 1150 } 1183 /* within the old array */ 1184 if (hdpa->nMaxCount > i) { 1185 /* within the allocated space, set a new boundary */ 1186 hdpa->nItemCount = i; 1187 } 1188 else { 1189 /* resize the block of memory */ 1190 INT nNewItems = 1191 hdpa->nGrow * ((INT)((i - 1) / hdpa->nGrow) + 1); 1192 INT nSize = nNewItems * sizeof(LPVOID); 1193 1194 lpTemp = (LPVOID*)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY, 1195 hdpa->ptrs, nSize); 1196 if (!lpTemp) 1197 return FALSE; 1198 1199 hdpa->nItemCount = nNewItems; 1200 hdpa->ptrs = lpTemp; 1201 } 1151 1202 } 1152 1203 … … 1177 1228 LPVOID *lpDest, *lpSrc, lpTemp = NULL; 1178 1229 INT nSize; 1179 1230 1180 1231 // TRACE (commctrl, "(%p %d)\n", hdpa, i); 1181 1232 1182 1233 if ((!hdpa) || i < 0 || i >= hdpa->nItemCount) 1183 1234 return NULL; 1184 1235 1185 1236 lpTemp = hdpa->ptrs[i]; … … 1187 1238 /* do we need to move ?*/ 1188 1239 if (i < hdpa->nItemCount - 1) { 1189 1190 1191 1192 // 1193 // 1194 1195 } 1196 1240 lpDest = hdpa->ptrs + i; 1241 lpSrc = lpDest + 1; 1242 nSize = (hdpa->nItemCount - i - 1) * sizeof(LPVOID); 1243 // TRACE (commctrl,"-- move dest=%p src=%p size=%x\n", 1244 // lpDest, lpSrc, nSize); 1245 memmove (lpDest, lpSrc, nSize); 1246 } 1247 1197 1248 hdpa->nItemCount --; 1198 1249 1199 1250 /* free memory ?*/ 1200 1251 if ((hdpa->nMaxCount - hdpa->nItemCount) >= hdpa->nGrow) { 1201 1202 1203 1204 1205 1206 1207 1208 1209 hdpa->ptrs = (LPVOID*)lpDest; 1252 INT nNewItems = MIN(hdpa->nGrow * 2, hdpa->nItemCount); 1253 nSize = nNewItems * sizeof(LPVOID); 1254 lpDest = (LPVOID)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY, 1255 hdpa->ptrs, nSize); 1256 if (!lpDest) 1257 return NULL; 1258 1259 hdpa->nMaxCount = nNewItems; 1260 hdpa->ptrs = (LPVOID*)lpDest; 1210 1261 } 1211 1262 … … 1232 1283 // TRACE (commctrl, "(%p)\n", hdpa); 1233 1284 1234 if (!hdpa) 1235 1285 if (!hdpa) 1286 return FALSE; 1236 1287 1237 1288 if (hdpa->ptrs && (!HeapFree (hdpa->hHeap, 0, hdpa->ptrs))) 1238 1289 return FALSE; 1239 1290 1240 1291 hdpa->nItemCount = 0; 1241 1292 hdpa->nMaxCount = hdpa->nGrow * 2; 1242 1293 hdpa->ptrs = (LPVOID*)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY, 1243 1294 hdpa->nMaxCount * sizeof(LPVOID)); 1244 1295 1245 1296 return TRUE; … … 1265 1316 static VOID 1266 1317 DPA_QuickSort (LPVOID *lpPtrs, INT l, INT r, 1267 1318 PFNDPACOMPARE pfnCompare, LPARAM lParam) 1268 1319 { 1269 1320 LPVOID t, v; … … 1271 1322 1272 1323 // TRACE (commctrl, "l=%i r=%i\n", l, r); 1273 1324 1274 1325 i = l; 1275 1326 j = r; 1276 1327 v = lpPtrs[(int)(l+r)/2]; 1277 1328 do { 1278 1279 1280 if (i <= j) 1281 1282 1283 1284 1285 1329 while ((pfnCompare)(lpPtrs[i], v, lParam) > 0) i++; 1330 while ((pfnCompare)(lpPtrs[j], v, lParam) < 0) j--; 1331 if (i <= j) 1332 { 1333 t = lpPtrs[i]; 1334 lpPtrs[i++] = lpPtrs[j]; 1335 lpPtrs[j--] = t; 1336 } 1286 1337 } while (i <= j); 1287 1338 if (l < j) DPA_QuickSort (lpPtrs, l, j, pfnCompare, lParam); … … 1309 1360 { 1310 1361 if (!hdpa || !pfnCompare) 1311 1362 return FALSE; 1312 1363 1313 1364 // TRACE (commctrl, "(%p %p 0x%lx)\n", hdpa, pfnCompare, lParam); 1314 1365 1315 1366 if ((hdpa->nItemCount > 1) && (hdpa->ptrs)) 1316 1317 1367 DPA_QuickSort (hdpa->ptrs, 0, hdpa->nItemCount - 1, 1368 pfnCompare, lParam); 1318 1369 1319 1370 return TRUE; … … 1346 1397 INT WINAPI 1347 1398 DPA_Search (const HDPA hdpa, LPVOID pFind, INT nStart, 1348 1399 PFNDPACOMPARE pfnCompare, LPARAM lParam, UINT uOptions) 1349 1400 { 1350 1401 if (!hdpa || !pfnCompare || !pFind) 1351 1402 return -1; 1352 1403 1353 1404 // TRACE (commctrl, "(%p %p %d %p 0x%08lx 0x%08x)\n", 1354 // 1405 // hdpa, pFind, nStart, pfnCompare, lParam, uOptions); 1355 1406 1356 1407 if (uOptions & DPAS_SORTED) { 1357 1358 1359 1360 1361 // 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 // 1375 1376 1377 1378 1379 1380 // 1381 1382 1383 1384 1385 // 1386 1387 1408 /* array is sorted --> use binary search */ 1409 INT l, r, x, n; 1410 LPVOID *lpPtr; 1411 1412 // TRACE (commctrl, "binary search\n"); 1413 1414 l = (nStart == -1) ? 0 : nStart; 1415 r = hdpa->nItemCount - 1; 1416 lpPtr = hdpa->ptrs; 1417 while (r >= l) { 1418 x = (l + r) / 2; 1419 n = (pfnCompare)(pFind, lpPtr[x], lParam); 1420 if (n < 0) 1421 r = x - 1; 1422 else 1423 l = x + 1; 1424 if (n == 0) { 1425 // TRACE (commctrl, "-- ret=%d\n", n); 1426 return n; 1427 } 1428 } 1429 1430 if (uOptions & DPAS_INSERTBEFORE) { 1431 // TRACE (commctrl, "-- ret=%d\n", r); 1432 return r; 1433 } 1434 1435 if (uOptions & DPAS_INSERTAFTER) { 1436 // TRACE (commctrl, "-- ret=%d\n", l); 1437 return l; 1438 } 1388 1439 } 1389 1440 else { 1390 1391 1392 1393 1394 // 1395 1396 1397 1398 1399 1400 // 1401 1402 1403 1441 /* array is not sorted --> use linear search */ 1442 LPVOID *lpPtr; 1443 INT nIndex; 1444 1445 // TRACE (commctrl, "linear search\n"); 1446 1447 nIndex = (nStart == -1)? 0 : nStart; 1448 lpPtr = hdpa->ptrs; 1449 for (; nIndex < hdpa->nItemCount; nIndex++) { 1450 if ((pfnCompare)(pFind, lpPtr[nIndex], lParam) == 0) { 1451 // TRACE (commctrl, "-- ret=%d\n", nIndex); 1452 return nIndex; 1453 } 1454 } 1404 1455 } 1405 1456 … … 1431 1482 1432 1483 if (hHeap) 1433 1484 hdpa = (HDPA)HeapAlloc (hHeap, HEAP_ZERO_MEMORY, sizeof(DPA)); 1434 1485 else 1435 1486 hdpa = (HDPA)COMCTL32_Alloc (sizeof(DPA)); 1436 1487 1437 1488 if (hdpa) { 1438 1439 1440 1441 1442 1443 1489 hdpa->nGrow = MIN(8, nGrow); 1490 hdpa->hHeap = hHeap ? hHeap : COMCTL32_hHeap; 1491 hdpa->nMaxCount = hdpa->nGrow * 2; 1492 hdpa->ptrs = 1493 (LPVOID*)HeapAlloc (hHeap, HEAP_ZERO_MEMORY, 1494 hdpa->nMaxCount * sizeof(LPVOID)); 1444 1495 } 1445 1496 … … 1476 1527 1477 1528 // TRACE (commctrl, "(0x%04x 0x%04x %d %p 0x%08lx)\n", 1478 // 1479 // 1529 // lpNotify->hwndFrom, lpNotify->hwndTo, uCode, lpHdr, 1530 // lpNotify->dwParam5); 1480 1531 1481 1532 if (!lpNotify->hwndTo) 1482 1533 return 0; 1483 1534 1484 1535 if (lpNotify->hwndFrom == -1) { 1485 1486 1536 lpNmh = lpHdr; 1537 idFrom = lpHdr->idFrom; 1487 1538 } 1488 1539 else { 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1540 if (lpNotify->hwndFrom) { 1541 HWND hwndParent = GetParent (lpNotify->hwndFrom); 1542 if (hwndParent) { 1543 hwndParent = GetWindow (lpNotify->hwndFrom, GW_OWNER); 1544 if (hwndParent) 1545 idFrom = GetDlgCtrlID (lpNotify->hwndFrom); 1546 } 1547 } 1548 1549 lpNmh = (lpHdr) ? lpHdr : &nmhdr; 1550 1551 lpNmh->hwndFrom = lpNotify->hwndFrom; 1552 lpNmh->idFrom = idFrom; 1553 lpNmh->code = uCode; 1503 1554 } 1504 1555 … … 1523 1574 LRESULT WINAPI 1524 1575 COMCTL32_SendNotify (HWND hwndFrom, HWND hwndTo, 1525 1576 UINT uCode, LPNMHDR lpHdr) 1526 1577 { 1527 1578 NOTIFYDATA notify; 1528 1579 1529 1580 // TRACE (commctrl, "(0x%04x 0x%04x %d %p)\n", 1530 // 1581 // hwndFrom, hwndTo, uCode, lpHdr); 1531 1582 1532 1583 notify.hwndFrom = hwndFrom; … … 1556 1607 LRESULT WINAPI 1557 1608 COMCTL32_SendNotifyEx (HWND hwndTo, HWND hwndFrom, UINT uCode, 1558 1609 LPNMHDR lpHdr, DWORD dwParam5) 1559 1610 { 1560 1611 NOTIFYDATA notify; … … 1562 1613 1563 1614 // TRACE (commctrl, "(0x%04x 0x%04x %d %p 0x%08lx)\n", 1564 // 1615 // hwndFrom, hwndTo, uCode, lpHdr, dwParam5); 1565 1616 1566 1617 hwndNotify = hwndTo; 1567 1618 if (!hwndTo) { 1568 1569 1570 1571 1572 1619 if (IsWindow (hwndFrom)) { 1620 hwndNotify = GetParent (hwndFrom); 1621 if (!hwndNotify) 1622 return 0; 1623 } 1573 1624 } 1574 1625 … … 1605 1656 1606 1657 if (*lpStr2 == 0) 1607 1658 return ((LPSTR)lpStr1); 1608 1659 len1 = 0; 1609 1660 while (lpStr1[len1] != 0) ++len1; … … 1611 1662 while (lpStr2[len2] != 0) ++len2; 1612 1663 if (len2 == 0) 1613 1664 return ((LPSTR)(lpStr1 + len1)); 1614 1665 first = tolower (*lpStr2); 1615 1666 while (len1 >= len2) { 1616 1617 1618 1619 1620 1621 1622 } 1623 1667 if (tolower(*lpStr1) == first) { 1668 for (i = 1; i < len2; ++i) 1669 if (tolower (lpStr1[i]) != tolower(lpStr2[i])) 1670 break; 1671 if (i >= len2) 1672 return ((LPSTR)lpStr1); 1673 } 1674 ++lpStr1; --len1; 1624 1675 } 1625 1676 return (NULL); … … 1641 1692 * 1642 1693 * Enumerates all items in a dynamic pointer array. 1643 *1644 * PARAMS1645 * hdpa [I] handle to the dynamic pointer array1646 * enumProc [I]1647 * lParam [I]1648 *1649 * RETURNS1650 * none1651 */1652 1653 VOID WINAPI1654 DPA_EnumCallback (const HDPA hdpa, DPAENUMPROC enumProc, LPARAM lParam)1655 {1656 INT i;1657 1658 // TRACE (commctrl, "(%p %p %08lx)\n", hdpa, enumProc, lParam);1659 1660 if (!hdpa)1661 return;1662 if (hdpa->nItemCount <= 0)1663 return;1664 1665 for (i = 0; i < hdpa->nItemCount; i++) {1666 if ((enumProc)(hdpa->ptrs[i], lParam) == 0)1667 return;1668 }1669 1670 return;1671 }1672 1673 1674 /**************************************************************************1675 * DPA_DestroyCallback [COMCTL32.386]1676 *1677 * Enumerates all items in a dynamic pointer array and destroys it.1678 1694 * 1679 1695 * PARAMS … … 1683 1699 * 1684 1700 * RETURNS 1701 * none 1702 */ 1703 1704 1705 VOID WINAPI 1706 DPA_EnumCallback (const HDPA hdpa, DPAENUMPROC enumProc, LPARAM lParam) 1707 { 1708 INT i; 1709 1710 // TRACE (commctrl, "(%p %p %08lx)\n", hdpa, enumProc, lParam); 1711 1712 if (!hdpa) 1713 return; 1714 if (hdpa->nItemCount <= 0) 1715 return; 1716 1717 for (i = 0; i < hdpa->nItemCount; i++) { 1718 if ((enumProc)(hdpa->ptrs[i], lParam) == 0) 1719 return; 1720 } 1721 1722 return; 1723 } 1724 1725 1726 /************************************************************************** 1727 * DPA_DestroyCallback [COMCTL32.386] 1728 * 1729 * Enumerates all items in a dynamic pointer array and destroys it. 1730 * 1731 * PARAMS 1732 * hdpa [I] handle to the dynamic pointer array 1733 * enumProc [I] 1734 * lParam [I] 1735 * 1736 * RETURNS 1685 1737 * Success: TRUE 1686 1738 * Failure: FALSE … … 1720 1772 1721 1773 if (!hdsa) 1722 1774 return; 1723 1775 if (hdsa->nItemCount <= 0) 1724 1776 return; 1725 1777 1726 1778 for (i = 0; i < hdsa->nItemCount; i++) { 1727 1728 1729 1779 LPVOID lpItem = DSA_GetItemPtr (hdsa, i); 1780 if ((enumProc)(lpItem, lParam) == 0) 1781 return; 1730 1782 } 1731 1783 … … 1796 1848 */ 1797 1849 LPSTR WINAPI COMCTL32_StrRChrA( LPCSTR lpStart, LPCSTR lpEnd, WORD wMatch) { 1798 // return lstrrchr(lpStart, lpEnd, wMatch); 1850 // return lstrrchr(lpStart, lpEnd, wMatch); 1799 1851 } 1800 1852 … … 1804 1856 */ 1805 1857 LPWSTR WINAPI COMCTL32_StrRChrW( LPCWSTR lpStart, LPCWSTR lpEnd, WORD wMatch) { 1806 // return lstrrchrw(lpStart, lpEnd, wMatch); 1858 // return lstrrchrw(lpStart, lpEnd, wMatch); 1807 1859 } 1808 1860 … … 1838 1890 // if( CRTDLL_wcschr(lpSet, *(WORD*)lpLoop)) 1839 1891 // return (INT)(lpLoop-lpStr); 1840 1892 1841 1893 // return (INT)(lpLoop-lpStr); 1842 1894 }
Note:
See TracChangeset
for help on using the changeset viewer.