2 * Undocumented functions from COMCTL32.DLL
4 * Copyright 1998 Eric Kohl <ekohl@abo.rhein-zeitung.de>
5 * 1998 Juergen Schmied <j.schmied@metronet.de>
7 * All of these functions are UNDOCUMENTED!! And I mean UNDOCUMENTED!!!!
8 * Do NOT rely on names or contents of undocumented structures and types!!!
9 * These functions are used by EXPLORER.EXE, IEXPLORE.EXE and
10 * COMCTL32.DLL (internally).
13 * - Add more functions.
14 * - Write some documentation.
18 #include <stdlib.h> /* atoi */
23 #include "debugtools.h"
25 DEFAULT_DEBUG_CHANNEL(commctrl)
28 extern HANDLE COMCTL32_hHeap; /* handle to the private heap */
31 * We put some function prototypes here that don't seem to belong in
32 * any header file. When they find their place, we can remove them.
34 extern LPWSTR __cdecl CRTDLL_wcschr(LPCWSTR, WCHAR);
35 extern LPSTR WINAPI lstrrchr(LPCSTR, LPCSTR, WORD);
36 extern LPWSTR WINAPI lstrrchrw(LPCWSTR, LPCWSTR, WORD);
37 extern LPWSTR WINAPI strstrw(LPCWSTR, LPCWSTR);
40 /**************************************************************************
41 * DPA_Merge [COMCTL32.11]
44 * hdpa1 [I] handle to a dynamic pointer array
45 * hdpa2 [I] handle to a dynamic pointer array
47 * pfnSort [I] pointer to sort function
49 * lParam [I] application specific value
52 * No more information available yet!
56 DPA_Merge (const HDPA hdpa1, const HDPA hdpa2, DWORD dwFlags,
57 PFNDPACOMPARE pfnCompare, LPVOID pfnParam5, LPARAM lParam)
59 /* LPVOID *pWork1, *pWork2; */
62 TRACE("(%p %p %08lx %p %p %08lx): stub!\n",
63 hdpa1, hdpa2, dwFlags, pfnCompare, pfnParam5, lParam);
65 if (IsBadWritePtr (hdpa1, sizeof(DPA)))
68 if (IsBadWritePtr (hdpa2, sizeof(DPA)))
71 if (IsBadCodePtr ((FARPROC)pfnCompare))
74 if (IsBadCodePtr ((FARPROC)pfnParam5))
77 if (dwFlags & DPAM_SORT) {
78 TRACE("sorting dpa's!\n");
79 DPA_Sort (hdpa1, pfnCompare, lParam);
80 DPA_Sort (hdpa2, pfnCompare, lParam);
83 if (hdpa2->nItemCount <= 0)
86 nCount1 = hdpa1->nItemCount - 1;
88 nCount2 = hdpa2->nItemCount - 1;
90 FIXME("nCount1=%d nCount2=%d\n", nCount1, nCount2);
91 FIXME("semi stub!\n");
100 else if (nResult > 0) {
108 while (nCount2 >= 0);
117 /**************************************************************************
118 * Alloc [COMCTL32.71]
120 * Allocates memory block from the dll's private heap
123 * dwSize [I] size of the allocated memory block
126 * Success: pointer to allocated memory block
131 COMCTL32_Alloc (DWORD dwSize)
135 TRACE("(0x%lx)\n", dwSize);
137 lpPtr = HeapAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, dwSize);
139 TRACE("-- ret=%p\n", lpPtr);
145 /**************************************************************************
146 * ReAlloc [COMCTL32.72]
148 * Changes the size of an allocated memory block or allocates a memory
149 * block using the dll's private heap.
152 * lpSrc [I] pointer to memory block which will be resized
153 * dwSize [I] new size of the memory block.
156 * Success: pointer to the resized memory block
160 * If lpSrc is a NULL-pointer, then COMCTL32_ReAlloc allocates a memory
161 * block like COMCTL32_Alloc.
165 COMCTL32_ReAlloc (LPVOID lpSrc, DWORD dwSize)
169 TRACE("(%p 0x%08lx)\n", lpSrc, dwSize);
172 lpDest = HeapReAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, lpSrc, dwSize);
174 lpDest = HeapAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, dwSize);
176 TRACE("-- ret=%p\n", lpDest);
182 /**************************************************************************
185 * Frees an allocated memory block from the dll's private heap.
188 * lpMem [I] pointer to memory block which will be freed
196 COMCTL32_Free (LPVOID lpMem)
198 TRACE("(%p)\n", lpMem);
200 return HeapFree (COMCTL32_hHeap, 0, lpMem);
204 /**************************************************************************
205 * GetSize [COMCTL32.74]
207 * Retrieves the size of the specified memory block from the dll's
211 * lpMem [I] pointer to an allocated memory block
214 * Success: size of the specified memory block
219 COMCTL32_GetSize (LPVOID lpMem)
221 TRACE("(%p)\n", lpMem);
223 return HeapSize (COMCTL32_hHeap, 0, lpMem);
227 /**************************************************************************
228 * The MRU-API is a set of functions to manipulate MRU(Most Recently Used)
234 typedef struct tagMRUINFO
242 } MRUINFO, *LPMRUINFO;
245 typedef struct tagMRU
247 DWORD dwParam1; /* some kind of flag */
256 CreateMRUListLazyA (LPMRUINFO lpmi, DWORD dwParam2,
257 DWORD dwParam3, DWORD dwParam4);
260 /**************************************************************************
261 * CreateMRUListA [COMCTL32.151]
270 CreateMRUListA (LPMRUINFO lpmi)
272 return CreateMRUListLazyA (lpmi, 0, 0, 0);
277 FreeMRUListA (HMRU hmru)
279 FIXME("(%p) empty stub!\n", hmru);
282 if (!(hmru->dwParam1 & 1001)) {
283 RegSetValueExA (hmru->hKeyMRU, "MRUList", 0, REG_SZ,
285 lstrlenA (hmru->lpszMRUString));
289 RegClosKey (hmru->hkeyMRU
290 COMCTL32_Free32 (hmru->lpszMRUString);
293 return COMCTL32_Free (hmru);
299 AddMRUData (DWORD dwParam1, DWORD dwParam2, DWORD dwParam3)
302 FIXME("(%lx %lx %lx) empty stub!\n",
303 dwParam1, dwParam2, dwParam3);
310 FindMRUData (DWORD dwParam1, DWORD dwParam2, DWORD dwParam3, DWORD dwParam4)
313 FIXME("(%lx %lx %lx %lx) empty stub!\n",
314 dwParam1, dwParam2, dwParam3, dwParam4);
321 CreateMRUListLazyA (LPMRUINFO lpmi, DWORD dwParam2, DWORD dwParam3, DWORD dwParam4)
330 * DWORD dwDisposition; */
332 /* internal variables */
335 FIXME("(%p) empty stub!\n", lpmi);
338 FIXME("(%lx %lx %lx %lx \"%s\" %lx)\n",
339 lpmi->dwParam1, lpmi->dwParam2, lpmi->dwParam3,
340 (DWORD)lpmi->hkeyMain, lpmi->lpszSubKey, lpmi->dwParam6);
343 /* dummy pointer creation */
344 ptr = COMCTL32_Alloc (32);
346 FIXME("-- ret = %p\n", ptr);
354 /**************************************************************************
355 * Str_GetPtrA [COMCTL32.233]
366 Str_GetPtrA (LPCSTR lpSrc, LPSTR lpDest, INT nMaxLen)
370 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
372 if (!lpDest && lpSrc)
373 return lstrlenA (lpSrc);
383 len = lstrlenA (lpSrc);
387 RtlMoveMemory (lpDest, lpSrc, len);
394 /**************************************************************************
395 * Str_SetPtrA [COMCTL32.234]
405 Str_SetPtrA (LPSTR *lppDest, LPCSTR lpSrc)
407 TRACE("(%p %p)\n", lppDest, lpSrc);
410 LPSTR ptr = COMCTL32_ReAlloc (*lppDest, lstrlenA (lpSrc) + 1);
413 lstrcpyA (ptr, lpSrc);
418 COMCTL32_Free (*lppDest);
427 /**************************************************************************
428 * Str_GetPtrW [COMCTL32.235]
439 Str_GetPtrW (LPCWSTR lpSrc, LPWSTR lpDest, INT nMaxLen)
443 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
445 if (!lpDest && lpSrc)
446 return lstrlenW (lpSrc);
456 len = lstrlenW (lpSrc);
460 RtlMoveMemory (lpDest, lpSrc, len*sizeof(WCHAR));
467 /**************************************************************************
468 * Str_SetPtrW [COMCTL32.236]
478 Str_SetPtrW (LPWSTR *lppDest, LPCWSTR lpSrc)
480 TRACE("(%p %p)\n", lppDest, lpSrc);
483 INT len = lstrlenW (lpSrc) + 1;
484 LPWSTR ptr = COMCTL32_ReAlloc (*lppDest, len * sizeof(WCHAR));
487 lstrcpyW (ptr, lpSrc);
492 COMCTL32_Free (*lppDest);
501 /**************************************************************************
502 * The DSA-API is a set of functions to create and manipulate arrays of
503 * fix sized memory blocks. These arrays can store any kind of data
504 * (strings, icons...).
507 /**************************************************************************
508 * DSA_Create [COMCTL32.320] Creates a dynamic storage array
511 * nSize [I] size of the array elements
512 * nGrow [I] number of elements by which the array grows when it is filled
515 * Success: pointer to a array control structure. use this like a handle.
520 DSA_Create (INT nSize, INT nGrow)
524 TRACE("(size=%d grow=%d)\n", nSize, nGrow);
526 hdsa = (HDSA)COMCTL32_Alloc (sizeof(DSA));
529 hdsa->nItemCount = 0;
532 hdsa->nItemSize = nSize;
533 hdsa->nGrow = MAX(1, nGrow);
540 /**************************************************************************
541 * DSA_Destroy [COMCTL32.321] Destroys a dynamic storage array
544 * hdsa [I] pointer to the array control structure
552 DSA_Destroy (const HDSA hdsa)
554 TRACE("(%p)\n", hdsa);
559 if (hdsa->pData && (!COMCTL32_Free (hdsa->pData)))
562 return COMCTL32_Free (hdsa);
566 /**************************************************************************
567 * DSA_GetItem [COMCTL32.322]
570 * hdsa [I] pointer to the array control structure
571 * nIndex [I] number of the Item to get
572 * pDest [O] destination buffer. Has to be >= dwElementSize.
580 DSA_GetItem (const HDSA hdsa, INT nIndex, LPVOID pDest)
584 TRACE("(%p %d %p)\n", hdsa, nIndex, pDest);
588 if ((nIndex < 0) || (nIndex >= hdsa->nItemCount))
591 pSrc = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
592 memmove (pDest, pSrc, hdsa->nItemSize);
598 /**************************************************************************
599 * DSA_GetItemPtr [COMCTL32.323]
601 * Retrieves a pointer to the specified item.
604 * hdsa [I] pointer to the array control structure
605 * nIndex [I] index of the desired item
608 * Success: pointer to an item
613 DSA_GetItemPtr (const HDSA hdsa, INT nIndex)
617 TRACE("(%p %d)\n", hdsa, nIndex);
621 if ((nIndex < 0) || (nIndex >= hdsa->nItemCount))
624 pSrc = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
626 TRACE("-- ret=%p\n", pSrc);
632 /**************************************************************************
633 * DSA_SetItem [COMCTL32.325]
635 * Sets the contents of an item in the array.
638 * hdsa [I] pointer to the array control structure
639 * nIndex [I] index for the item
640 * pSrc [I] pointer to the new item data
648 DSA_SetItem (const HDSA hdsa, INT nIndex, LPVOID pSrc)
650 INT nSize, nNewItems;
651 LPVOID pDest, lpTemp;
653 TRACE("(%p %d %p)\n", hdsa, nIndex, pSrc);
655 if ((!hdsa) || nIndex < 0)
658 if (hdsa->nItemCount <= nIndex) {
659 /* within the old array */
660 if (hdsa->nMaxCount > nIndex) {
661 /* within the allocated space, set a new boundary */
662 hdsa->nItemCount = nIndex + 1;
665 /* resize the block of memory */
667 hdsa->nGrow * ((INT)((nIndex - 1) / hdsa->nGrow) + 1);
668 nSize = hdsa->nItemSize * nNewItems;
670 lpTemp = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
674 hdsa->nMaxCount = nNewItems;
675 hdsa->nItemCount = nIndex + 1;
676 hdsa->pData = lpTemp;
680 /* put the new entry in */
681 pDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
682 TRACE("-- move dest=%p src=%p size=%d\n",
683 pDest, pSrc, hdsa->nItemSize);
684 memmove (pDest, pSrc, hdsa->nItemSize);
690 /**************************************************************************
691 * DSA_InsertItem [COMCTL32.325]
694 * hdsa [I] pointer to the array control structure
695 * nIndex [I] index for the new item
696 * pSrc [I] pointer to the element
699 * Success: position of the new item
704 DSA_InsertItem (const HDSA hdsa, INT nIndex, LPVOID pSrc)
706 INT nNewItems, nSize, i;
707 LPVOID lpTemp, lpDest;
710 TRACE("(%p %d %p)\n", hdsa, nIndex, pSrc);
712 if ((!hdsa) || nIndex < 0)
715 for (i = 0; i < hdsa->nItemSize; i += 4) {
716 p = *(DWORD**)((char *) pSrc + i);
717 if (IsBadStringPtrA ((char*)p, 256))
718 TRACE("-- %d=%p\n", i, (DWORD*)p);
720 TRACE("-- %d=%p [%s]\n", i, p, debugstr_a((char*)p));
723 /* when nIndex > nItemCount then append */
724 if (nIndex >= hdsa->nItemCount)
725 nIndex = hdsa->nItemCount;
727 /* do we need to resize ? */
728 if (hdsa->nItemCount >= hdsa->nMaxCount) {
729 nNewItems = hdsa->nMaxCount + hdsa->nGrow;
730 nSize = hdsa->nItemSize * nNewItems;
732 lpTemp = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
736 hdsa->nMaxCount = nNewItems;
737 hdsa->pData = lpTemp;
740 /* do we need to move elements ? */
741 if (nIndex < hdsa->nItemCount) {
742 lpTemp = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
743 lpDest = (char *) lpTemp + hdsa->nItemSize;
744 nSize = (hdsa->nItemCount - nIndex) * hdsa->nItemSize;
745 TRACE("-- move dest=%p src=%p size=%d\n",
746 lpDest, lpTemp, nSize);
747 memmove (lpDest, lpTemp, nSize);
750 /* ok, we can put the new Item in */
752 lpDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
753 TRACE("-- move dest=%p src=%p size=%d\n",
754 lpDest, pSrc, hdsa->nItemSize);
755 memmove (lpDest, pSrc, hdsa->nItemSize);
757 return hdsa->nItemCount;
761 /**************************************************************************
762 * DSA_DeleteItem [COMCTL32.326]
765 * hdsa [I] pointer to the array control structure
766 * nIndex [I] index for the element to delete
769 * Success: number of the deleted element
774 DSA_DeleteItem (const HDSA hdsa, INT nIndex)
779 TRACE("(%p %d)\n", hdsa, nIndex);
783 if (nIndex < 0 || nIndex >= hdsa->nItemCount)
786 /* do we need to move ? */
787 if (nIndex < hdsa->nItemCount - 1) {
788 lpDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
789 lpSrc = (char *) lpDest + hdsa->nItemSize;
790 nSize = hdsa->nItemSize * (hdsa->nItemCount - nIndex - 1);
791 TRACE("-- move dest=%p src=%p size=%d\n",
792 lpDest, lpSrc, nSize);
793 memmove (lpDest, lpSrc, nSize);
799 if ((hdsa->nMaxCount - hdsa->nItemCount) >= hdsa->nGrow) {
800 nSize = hdsa->nItemSize * hdsa->nItemCount;
802 lpDest = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
806 hdsa->nMaxCount = hdsa->nItemCount;
807 hdsa->pData = lpDest;
814 /**************************************************************************
815 * DSA_DeleteAllItems [COMCTL32.326]
817 * Removes all items and reinitializes the array.
820 * hdsa [I] pointer to the array control structure
828 DSA_DeleteAllItems (const HDSA hdsa)
830 TRACE("(%p)\n", hdsa);
834 if (hdsa->pData && (!COMCTL32_Free (hdsa->pData)))
837 hdsa->nItemCount = 0;
845 /**************************************************************************
846 * The DPA-API is a set of functions to create and manipulate arrays of
850 /**************************************************************************
851 * DPA_Create [COMCTL32.328] Creates a dynamic pointer array
854 * nGrow [I] number of items by which the array grows when it is filled
857 * Success: handle (pointer) to the pointer array.
862 DPA_Create (INT nGrow)
866 TRACE("(%d)\n", nGrow);
868 hdpa = (HDPA)COMCTL32_Alloc (sizeof(DPA));
870 hdpa->nGrow = MAX(8, nGrow);
871 hdpa->hHeap = COMCTL32_hHeap;
872 hdpa->nMaxCount = hdpa->nGrow * 2;
874 (LPVOID*)COMCTL32_Alloc (hdpa->nMaxCount * sizeof(LPVOID));
877 TRACE("-- %p\n", hdpa);
883 /**************************************************************************
884 * DPA_Destroy [COMCTL32.329] Destroys a dynamic pointer array
887 * hdpa [I] handle (pointer) to the pointer array
895 DPA_Destroy (const HDPA hdpa)
897 TRACE("(%p)\n", hdpa);
902 if (hdpa->ptrs && (!HeapFree (hdpa->hHeap, 0, hdpa->ptrs)))
905 return HeapFree (hdpa->hHeap, 0, hdpa);
909 /**************************************************************************
910 * DPA_Grow [COMCTL32.330]
912 * Sets the growth amount.
915 * hdpa [I] handle (pointer) to the existing (source) pointer array
916 * nGrow [I] number of items, the array grows, when it's too small
924 DPA_Grow (const HDPA hdpa, INT nGrow)
926 TRACE("(%p %d)\n", hdpa, nGrow);
931 hdpa->nGrow = MAX(8, nGrow);
937 /**************************************************************************
938 * DPA_Clone [COMCTL32.331]
940 * Copies a pointer array to an other one or creates a copy
943 * hdpa [I] handle (pointer) to the existing (source) pointer array
944 * hdpaNew [O] handle (pointer) to the destination pointer array
947 * Success: pointer to the destination pointer array.
951 * - If the 'hdpaNew' is a NULL-Pointer, a copy of the source pointer
952 * array will be created and it's handle (pointer) is returned.
953 * - If 'hdpa' is a NULL-Pointer, the original implementation crashes,
954 * this implementation just returns NULL.
958 DPA_Clone (const HDPA hdpa, const HDPA hdpaNew)
960 INT nNewItems, nSize;
966 TRACE("(%p %p)\n", hdpa, hdpaNew);
969 /* create a new DPA */
970 hdpaTemp = (HDPA)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
972 hdpaTemp->hHeap = hdpa->hHeap;
973 hdpaTemp->nGrow = hdpa->nGrow;
978 if (hdpaTemp->ptrs) {
979 /* remove old pointer array */
980 HeapFree (hdpaTemp->hHeap, 0, hdpaTemp->ptrs);
981 hdpaTemp->ptrs = NULL;
982 hdpaTemp->nItemCount = 0;
983 hdpaTemp->nMaxCount = 0;
986 /* create a new pointer array */
987 nNewItems = hdpaTemp->nGrow *
988 ((INT)((hdpa->nItemCount - 1) / hdpaTemp->nGrow) + 1);
989 nSize = nNewItems * sizeof(LPVOID);
991 (LPVOID*)HeapAlloc (hdpaTemp->hHeap, HEAP_ZERO_MEMORY, nSize);
992 hdpaTemp->nMaxCount = nNewItems;
994 /* clone the pointer array */
995 hdpaTemp->nItemCount = hdpa->nItemCount;
996 memmove (hdpaTemp->ptrs, hdpa->ptrs,
997 hdpaTemp->nItemCount * sizeof(LPVOID));
1003 /**************************************************************************
1004 * DPA_GetPtr [COMCTL32.332]
1006 * Retrieves a pointer from a dynamic pointer array
1009 * hdpa [I] handle (pointer) to the pointer array
1010 * nIndex [I] array index of the desired pointer
1018 DPA_GetPtr (const HDPA hdpa, INT i)
1020 TRACE("(%p %d)\n", hdpa, i);
1026 if ((i < 0) || (i >= hdpa->nItemCount))
1029 TRACE("-- %p\n", hdpa->ptrs[i]);
1031 return hdpa->ptrs[i];
1035 /**************************************************************************
1036 * DPA_GetPtrIndex [COMCTL32.333]
1038 * Retrieves the index of the specified pointer
1041 * hdpa [I] handle (pointer) to the pointer array
1045 * Success: index of the specified pointer
1050 DPA_GetPtrIndex (const HDPA hdpa, LPVOID p)
1057 for (i = 0; i < hdpa->nItemCount; i++) {
1058 if (hdpa->ptrs[i] == p)
1066 /**************************************************************************
1067 * DPA_InsertPtr [COMCTL32.334]
1069 * Inserts a pointer into a dynamic pointer array
1072 * hdpa [I] handle (pointer) to the array
1074 * p [I] pointer to insert
1077 * Success: index of the inserted pointer
1082 DPA_InsertPtr (const HDPA hdpa, INT i, LPVOID p)
1084 INT nNewItems, nSize, nIndex = 0;
1085 LPVOID *lpTemp, *lpDest;
1087 TRACE("(%p %d %p)\n", hdpa, i, p);
1089 if ((!hdpa) || (i < 0))
1094 (LPVOID*)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1095 2 * hdpa->nGrow * sizeof(LPVOID));
1098 hdpa->nMaxCount = hdpa->nGrow * 2;
1102 if (hdpa->nItemCount >= hdpa->nMaxCount) {
1103 TRACE("-- resizing\n");
1104 nNewItems = hdpa->nMaxCount + hdpa->nGrow;
1105 nSize = nNewItems * sizeof(LPVOID);
1107 lpTemp = (LPVOID*)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1111 hdpa->nMaxCount = nNewItems;
1112 hdpa->ptrs = lpTemp;
1115 if (i >= hdpa->nItemCount) {
1116 nIndex = hdpa->nItemCount;
1117 TRACE("-- appending at %d\n", nIndex);
1120 TRACE("-- inserting at %d\n", i);
1121 lpTemp = hdpa->ptrs + i;
1122 lpDest = lpTemp + 1;
1123 nSize = (hdpa->nItemCount - i) * sizeof(LPVOID);
1124 TRACE("-- move dest=%p src=%p size=%x\n",
1125 lpDest, lpTemp, nSize);
1126 memmove (lpDest, lpTemp, nSize);
1133 hdpa->ptrs[nIndex] = p;
1139 /**************************************************************************
1140 * DPA_SetPtr [COMCTL32.335]
1142 * Sets a pointer in the pointer array
1145 * hdpa [I] handle (pointer) to the pointer array
1146 * i [I] index of the pointer that will be set
1147 * p [I] pointer to be set
1155 DPA_SetPtr (const HDPA hdpa, INT i, LPVOID p)
1159 TRACE("(%p %d %p)\n", hdpa, i, p);
1161 if ((!hdpa) || i < 0)
1164 if (hdpa->nItemCount <= i) {
1165 /* within the old array */
1166 if (hdpa->nMaxCount > i) {
1167 /* within the allocated space, set a new boundary */
1168 hdpa->nItemCount = i;
1171 /* resize the block of memory */
1173 hdpa->nGrow * ((INT)((i - 1) / hdpa->nGrow) + 1);
1174 INT nSize = nNewItems * sizeof(LPVOID);
1176 lpTemp = (LPVOID*)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1181 hdpa->nItemCount = nNewItems;
1182 hdpa->ptrs = lpTemp;
1186 /* put the new entry in */
1193 /**************************************************************************
1194 * DPA_DeletePtr [COMCTL32.336]
1196 * Removes a pointer from the pointer array.
1199 * hdpa [I] handle (pointer) to the pointer array
1200 * i [I] index of the pointer that will be deleted
1203 * Success: deleted pointer
1208 DPA_DeletePtr (const HDPA hdpa, INT i)
1210 LPVOID *lpDest, *lpSrc, lpTemp = NULL;
1213 TRACE("(%p %d)\n", hdpa, i);
1215 if ((!hdpa) || i < 0 || i >= hdpa->nItemCount)
1218 lpTemp = hdpa->ptrs[i];
1220 /* do we need to move ?*/
1221 if (i < hdpa->nItemCount - 1) {
1222 lpDest = hdpa->ptrs + i;
1224 nSize = (hdpa->nItemCount - i - 1) * sizeof(LPVOID);
1225 TRACE("-- move dest=%p src=%p size=%x\n",
1226 lpDest, lpSrc, nSize);
1227 memmove (lpDest, lpSrc, nSize);
1230 hdpa->nItemCount --;
1233 if ((hdpa->nMaxCount - hdpa->nItemCount) >= hdpa->nGrow) {
1234 INT nNewItems = MIN(hdpa->nGrow * 2, hdpa->nItemCount);
1235 nSize = nNewItems * sizeof(LPVOID);
1236 lpDest = (LPVOID)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1241 hdpa->nMaxCount = nNewItems;
1242 hdpa->ptrs = (LPVOID*)lpDest;
1249 /**************************************************************************
1250 * DPA_DeleteAllPtrs [COMCTL32.337]
1252 * Removes all pointers and reinitializes the array.
1255 * hdpa [I] handle (pointer) to the pointer array
1263 DPA_DeleteAllPtrs (const HDPA hdpa)
1265 TRACE("(%p)\n", hdpa);
1270 if (hdpa->ptrs && (!HeapFree (hdpa->hHeap, 0, hdpa->ptrs)))
1273 hdpa->nItemCount = 0;
1274 hdpa->nMaxCount = hdpa->nGrow * 2;
1275 hdpa->ptrs = (LPVOID*)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1276 hdpa->nMaxCount * sizeof(LPVOID));
1282 /**************************************************************************
1283 * DPA_QuickSort [Internal]
1285 * Ordinary quicksort (used by DPA_Sort).
1288 * lpPtrs [I] pointer to the pointer array
1289 * l [I] index of the "left border" of the partition
1290 * r [I] index of the "right border" of the partition
1291 * pfnCompare [I] pointer to the compare function
1292 * lParam [I] user defined value (3rd parameter in compare function)
1299 DPA_QuickSort (LPVOID *lpPtrs, INT l, INT r,
1300 PFNDPACOMPARE pfnCompare, LPARAM lParam)
1305 TRACE("l=%i r=%i\n", l, r);
1309 v = lpPtrs[(int)(l+r)/2];
1311 while ((pfnCompare)(lpPtrs[i], v, lParam) > 0) i++;
1312 while ((pfnCompare)(lpPtrs[j], v, lParam) < 0) j--;
1316 lpPtrs[i++] = lpPtrs[j];
1320 if (l < j) DPA_QuickSort (lpPtrs, l, j, pfnCompare, lParam);
1321 if (i < r) DPA_QuickSort (lpPtrs, i, r, pfnCompare, lParam);
1325 /**************************************************************************
1326 * DPA_Sort [COMCTL32.338]
1328 * Sorts a pointer array using a user defined compare function
1331 * hdpa [I] handle (pointer) to the pointer array
1332 * pfnCompare [I] pointer to the compare function
1333 * lParam [I] user defined value (3rd parameter of compare function)
1341 DPA_Sort (const HDPA hdpa, PFNDPACOMPARE pfnCompare, LPARAM lParam)
1343 if (!hdpa || !pfnCompare)
1346 TRACE("(%p %p 0x%lx)\n", hdpa, pfnCompare, lParam);
1348 if ((hdpa->nItemCount > 1) && (hdpa->ptrs))
1349 DPA_QuickSort (hdpa->ptrs, 0, hdpa->nItemCount - 1,
1350 pfnCompare, lParam);
1356 /**************************************************************************
1357 * DPA_Search [COMCTL32.339]
1359 * Searches a pointer array for a specified pointer
1362 * hdpa [I] handle (pointer) to the pointer array
1363 * pFind [I] pointer to search for
1364 * nStart [I] start index
1365 * pfnCompare [I] pointer to the compare function
1366 * lParam [I] user defined value (3rd parameter of compare function)
1367 * uOptions [I] search options
1370 * Success: index of the pointer in the array.
1374 * Binary search taken from R.Sedgewick "Algorithms in C"!
1375 * Function is NOT tested!
1376 * If something goes wrong, blame HIM not ME! (Eric Kohl)
1380 DPA_Search (const HDPA hdpa, LPVOID pFind, INT nStart,
1381 PFNDPACOMPARE pfnCompare, LPARAM lParam, UINT uOptions)
1383 if (!hdpa || !pfnCompare || !pFind)
1386 TRACE("(%p %p %d %p 0x%08lx 0x%08x)\n",
1387 hdpa, pFind, nStart, pfnCompare, lParam, uOptions);
1389 if (uOptions & DPAS_SORTED) {
1390 /* array is sorted --> use binary search */
1394 TRACE("binary search\n");
1396 l = (nStart == -1) ? 0 : nStart;
1397 r = hdpa->nItemCount - 1;
1401 n = (pfnCompare)(pFind, lpPtr[x], lParam);
1407 TRACE("-- ret=%d\n", n);
1412 if (uOptions & DPAS_INSERTBEFORE) {
1413 TRACE("-- ret=%d\n", r);
1417 if (uOptions & DPAS_INSERTAFTER) {
1418 TRACE("-- ret=%d\n", l);
1423 /* array is not sorted --> use linear search */
1427 TRACE("linear search\n");
1429 nIndex = (nStart == -1)? 0 : nStart;
1431 for (; nIndex < hdpa->nItemCount; nIndex++) {
1432 if ((pfnCompare)(pFind, lpPtr[nIndex], lParam) == 0) {
1433 TRACE("-- ret=%d\n", nIndex);
1439 TRACE("-- not found: ret=-1\n");
1444 /**************************************************************************
1445 * DPA_CreateEx [COMCTL32.340]
1447 * Creates a dynamic pointer array using the specified size and heap.
1450 * nGrow [I] number of items by which the array grows when it is filled
1451 * hHeap [I] handle to the heap where the array is stored
1454 * Success: handle (pointer) to the pointer array.
1459 DPA_CreateEx (INT nGrow, HANDLE hHeap)
1463 TRACE("(%d 0x%x)\n", nGrow, hHeap);
1466 hdpa = (HDPA)HeapAlloc (hHeap, HEAP_ZERO_MEMORY, sizeof(DPA));
1468 hdpa = (HDPA)COMCTL32_Alloc (sizeof(DPA));
1471 hdpa->nGrow = MIN(8, nGrow);
1472 hdpa->hHeap = hHeap ? hHeap : COMCTL32_hHeap;
1473 hdpa->nMaxCount = hdpa->nGrow * 2;
1475 (LPVOID*)HeapAlloc (hHeap, HEAP_ZERO_MEMORY,
1476 hdpa->nMaxCount * sizeof(LPVOID));
1479 TRACE("-- %p\n", hdpa);
1485 /**************************************************************************
1486 * Notification functions
1489 typedef struct tagNOTIFYDATA
1497 } NOTIFYDATA, *LPNOTIFYDATA;
1500 /**************************************************************************
1501 * DoNotify [Internal]
1505 DoNotify (LPNOTIFYDATA lpNotify, UINT uCode, LPNMHDR lpHdr)
1508 LPNMHDR lpNmh = NULL;
1511 TRACE("(0x%04x 0x%04x %d %p 0x%08lx)\n",
1512 lpNotify->hwndFrom, lpNotify->hwndTo, uCode, lpHdr,
1513 lpNotify->dwParam5);
1515 if (!lpNotify->hwndTo)
1518 if (lpNotify->hwndFrom == -1) {
1520 idFrom = lpHdr->idFrom;
1523 if (lpNotify->hwndFrom) {
1524 HWND hwndParent = GetParent (lpNotify->hwndFrom);
1526 hwndParent = GetWindow (lpNotify->hwndFrom, GW_OWNER);
1528 idFrom = GetDlgCtrlID (lpNotify->hwndFrom);
1532 lpNmh = (lpHdr) ? lpHdr : &nmhdr;
1534 lpNmh->hwndFrom = lpNotify->hwndFrom;
1535 lpNmh->idFrom = idFrom;
1536 lpNmh->code = uCode;
1539 return SendMessageA (lpNotify->hwndTo, WM_NOTIFY, idFrom, (LPARAM)lpNmh);
1543 /**************************************************************************
1544 * SendNotify [COMCTL32.341]
1553 * Success: return value from notification
1558 COMCTL32_SendNotify (HWND hwndFrom, HWND hwndTo,
1559 UINT uCode, LPNMHDR lpHdr)
1563 TRACE("(0x%04x 0x%04x %d %p)\n",
1564 hwndFrom, hwndTo, uCode, lpHdr);
1566 notify.hwndFrom = hwndFrom;
1567 notify.hwndTo = hwndTo;
1568 notify.dwParam5 = 0;
1569 notify.dwParam6 = 0;
1571 return DoNotify (¬ify, uCode, lpHdr);
1575 /**************************************************************************
1576 * SendNotifyEx [COMCTL32.342]
1586 * Success: return value from notification
1591 COMCTL32_SendNotifyEx (HWND hwndTo, HWND hwndFrom, UINT uCode,
1592 LPNMHDR lpHdr, DWORD dwParam5)
1597 TRACE("(0x%04x 0x%04x %d %p 0x%08lx)\n",
1598 hwndFrom, hwndTo, uCode, lpHdr, dwParam5);
1600 hwndNotify = hwndTo;
1602 if (IsWindow (hwndFrom)) {
1603 hwndNotify = GetParent (hwndFrom);
1609 notify.hwndFrom = hwndFrom;
1610 notify.hwndTo = hwndNotify;
1611 notify.dwParam5 = dwParam5;
1612 notify.dwParam6 = 0;
1614 return DoNotify (¬ify, uCode, lpHdr);
1618 /**************************************************************************
1619 * StrChrA [COMCTL32.350]
1624 COMCTL32_StrChrA (LPCSTR lpString, CHAR cChar)
1626 return strchr (lpString, cChar);
1630 /**************************************************************************
1631 * StrStrIA [COMCTL32.355]
1635 COMCTL32_StrStrIA (LPCSTR lpStr1, LPCSTR lpStr2)
1641 return ((LPSTR)lpStr1);
1643 while (lpStr1[len1] != 0) ++len1;
1645 while (lpStr2[len2] != 0) ++len2;
1647 return ((LPSTR)(lpStr1 + len1));
1648 first = tolower (*lpStr2);
1649 while (len1 >= len2) {
1650 if (tolower(*lpStr1) == first) {
1651 for (i = 1; i < len2; ++i)
1652 if (tolower (lpStr1[i]) != tolower(lpStr2[i]))
1655 return ((LPSTR)lpStr1);
1663 /**************************************************************************
1664 * StrToIntA [COMCTL32.357] Converts a string to a signed integer.
1668 COMCTL32_StrToIntA (LPSTR lpString)
1670 return atoi(lpString);
1674 /**************************************************************************
1675 * DPA_EnumCallback [COMCTL32.385]
1677 * Enumerates all items in a dynamic pointer array.
1680 * hdpa [I] handle to the dynamic pointer array
1689 DPA_EnumCallback (const HDPA hdpa, DPAENUMPROC enumProc, LPARAM lParam)
1693 TRACE("(%p %p %08lx)\n", hdpa, enumProc, lParam);
1697 if (hdpa->nItemCount <= 0)
1700 for (i = 0; i < hdpa->nItemCount; i++) {
1701 if ((enumProc)(hdpa->ptrs[i], lParam) == 0)
1709 /**************************************************************************
1710 * DPA_DestroyCallback [COMCTL32.386]
1712 * Enumerates all items in a dynamic pointer array and destroys it.
1715 * hdpa [I] handle to the dynamic pointer array
1725 DPA_DestroyCallback (const HDPA hdpa, DPAENUMPROC enumProc, LPARAM lParam)
1727 TRACE("(%p %p %08lx)\n", hdpa, enumProc, lParam);
1729 DPA_EnumCallback (hdpa, enumProc, lParam);
1731 return DPA_Destroy (hdpa);
1735 /**************************************************************************
1736 * DSA_EnumCallback [COMCTL32.387]
1738 * Enumerates all items in a dynamic storage array.
1741 * hdsa [I] handle to the dynamic storage array
1750 DSA_EnumCallback (const HDSA hdsa, DSAENUMPROC enumProc, LPARAM lParam)
1754 TRACE("(%p %p %08lx)\n", hdsa, enumProc, lParam);
1758 if (hdsa->nItemCount <= 0)
1761 for (i = 0; i < hdsa->nItemCount; i++) {
1762 LPVOID lpItem = DSA_GetItemPtr (hdsa, i);
1763 if ((enumProc)(lpItem, lParam) == 0)
1771 /**************************************************************************
1772 * DSA_DestroyCallback [COMCTL32.388]
1774 * Enumerates all items in a dynamic storage array and destroys it.
1777 * hdsa [I] handle to the dynamic storage array
1787 DSA_DestroyCallback (const HDSA hdsa, DSAENUMPROC enumProc, LPARAM lParam)
1789 TRACE("(%p %p %08lx)\n", hdsa, enumProc, lParam);
1791 DSA_EnumCallback (hdsa, enumProc, lParam);
1793 return DSA_Destroy (hdsa);
1796 /**************************************************************************
1797 * StrCSpnA [COMCTL32.356]
1800 INT WINAPI COMCTL32_StrCSpnA( LPCSTR lpStr, LPCSTR lpSet) {
1801 return strcspn(lpStr, lpSet);
1804 /**************************************************************************
1805 * StrChrW [COMCTL32.358]
1808 LPWSTR WINAPI COMCTL32_StrChrW( LPCWSTR lpStart, WORD wMatch) {
1809 return CRTDLL_wcschr(lpStart, wMatch);
1812 /**************************************************************************
1813 * StrCmpNA [COMCTL32.352]
1816 INT WINAPI COMCTL32_StrCmpNA( LPCSTR lpStr1, LPCSTR lpStr2, int nChar) {
1817 return lstrncmpA(lpStr1, lpStr2, nChar);
1820 /**************************************************************************
1821 * StrCmpNW [COMCTL32.360]
1824 INT WINAPI COMCTL32_StrCmpNW( LPCWSTR lpStr1, LPCWSTR lpStr2, int nChar) {
1825 return lstrncmpW(lpStr1, lpStr2, nChar);
1828 /**************************************************************************
1829 * StrRChrA [COMCTL32.351]
1832 LPSTR WINAPI COMCTL32_StrRChrA( LPCSTR lpStart, LPCSTR lpEnd, WORD wMatch) {
1833 return lstrrchr(lpStart, lpEnd, wMatch);
1836 /**************************************************************************
1837 * StrRChrW [COMCTL32.359]
1840 LPWSTR WINAPI COMCTL32_StrRChrW( LPCWSTR lpStart, LPCWSTR lpEnd, WORD wMatch) {
1841 return lstrrchrw(lpStart, lpEnd, wMatch);
1844 /**************************************************************************
1845 * StrStrA [COMCTL32.354]
1848 LPSTR WINAPI COMCTL32_StrStrA( LPCSTR lpFirst, LPCSTR lpSrch) {
1849 return strstr(lpFirst, lpSrch);
1852 /**************************************************************************
1853 * StrStrW [COMCTL32.362]
1856 LPWSTR WINAPI COMCTL32_StrStrW( LPCWSTR lpFirst, LPCWSTR lpSrch) {
1857 return strstrw(lpFirst, lpSrch);
1860 /**************************************************************************
1861 * StrSpnW [COMCTL32.364]
1864 INT WINAPI COMCTL32_StrSpnW( LPWSTR lpStr, LPWSTR lpSet) {
1865 LPWSTR lpLoop = lpStr;
1868 if ((lpStr == 0) || (lpSet == 0)) return 0;
1870 /* while(*lpLoop) { if lpLoop++; } */
1872 for(; (*lpLoop != 0); lpLoop++)
1873 if( CRTDLL_wcschr(lpSet, *(WORD*)lpLoop))
1874 return (INT)(lpLoop-lpStr);
1876 return (INT)(lpLoop-lpStr);
1879 /*************************************************************************
1880 * DPA_LoadStream [COMCTL32.9]
1882 * NOTE: Ordinal is only accurate for Win98 / IE 4 and later
1885 DWORD WINAPI DPA_LoadStream(HDPA *hDpa, DWORD pfnDpaLoadCallback, DWORD param3, DWORD param4)
1887 FIXME("(%p %lx %lx %lx): partial stub!\n", hDpa, pfnDpaLoadCallback, param3, param4);
1889 *hDpa = DPA_Create(8);
1894 /************************************************************************
1895 * DPA_SaveStream [COMCTL32.10]
1897 * NOTE: Ordinal is only accurate for Win98 / IE 4 and later
1900 DWORD WINAPI DPA_SaveStream(DWORD param1, DWORD param2, DWORD param3, DWORD param4)
1902 FIXME("(%lx %lx %lx %lx): stub!\n", param1, param2, param3, param4);