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 */
26 #include "debugtools.h"
28 DEFAULT_DEBUG_CHANNEL(commctrl)
31 extern HANDLE COMCTL32_hHeap; /* handle to the private heap */
34 * We put some function prototypes here that don't seem to belong in
35 * any header file. When they find their place, we can remove them.
37 extern LPSTR WINAPI lstrrchr(LPCSTR, LPCSTR, WORD);
38 extern LPWSTR WINAPI lstrrchrw(LPCWSTR, LPCWSTR, WORD);
41 typedef struct _STREAMDATA
46 } STREAMDATA, *PSTREAMDATA;
48 typedef struct _LOADDATA
52 } LOADDATA, *LPLOADDATA;
54 typedef HRESULT(CALLBACK *DPALOADPROC)(LPLOADDATA,IStream*,LPARAM);
57 /**************************************************************************
58 * DPA_LoadStream [COMCTL32.9]
60 * Loads a dynamic pointer array from a stream
63 * phDpa [O] pointer to a handle to a dynamic pointer array
64 * loadProc [I] pointer to a callback function
65 * pStream [I] pointer to a stream
66 * lParam [I] application specific value
69 * No more information available yet!
73 DPA_LoadStream (HDPA *phDpa, DPALOADPROC loadProc, IStream *pStream, LPARAM lParam)
76 LARGE_INTEGER position;
77 ULARGE_INTEGER newPosition;
78 STREAMDATA streamData;
84 FIXME ("phDpa=%p loadProc=%p pStream=%p lParam=%lx\n",
85 phDpa, loadProc, pStream, lParam);
87 if (!phDpa || !loadProc || !pStream)
92 position.s.LowPart = 0;
93 position.s.HighPart = 0;
95 errCode = IStream_Seek (pStream, position, STREAM_SEEK_CUR, &newPosition);
99 errCode = IStream_Read (pStream, &streamData, sizeof(STREAMDATA), &ulRead);
103 FIXME ("dwSize=%lu dwData2=%lu dwItems=%lu\n",
104 streamData.dwSize, streamData.dwData2, streamData.dwItems);
106 if (lParam < sizeof(STREAMDATA) ||
107 streamData.dwSize < sizeof(STREAMDATA) ||
108 streamData.dwData2 < 1) {
113 hDpa = DPA_Create (streamData.dwItems);
115 return E_OUTOFMEMORY;
117 if (!DPA_Grow (hDpa, streamData.dwItems))
118 return E_OUTOFMEMORY;
120 /* load data from the stream into the dpa */
122 for (loadData.nCount = 0; loadData.nCount < streamData.dwItems; loadData.nCount++) {
123 errCode = (loadProc)(&loadData, pStream, lParam);
124 if (errCode != S_OK) {
133 /* set the number of items */
134 hDpa->nItemCount = loadData.nCount;
136 /* store the handle to the dpa */
138 FIXME ("new hDpa=%p\n", hDpa);
144 /**************************************************************************
145 * DPA_SaveStream [COMCTL32.10]
147 * Saves a dynamic pointer array to a stream
150 * hDpa [I] handle to a dynamic pointer array
151 * loadProc [I] pointer to a callback function
152 * pStream [I] pointer to a stream
153 * lParam [I] application specific value
156 * No more information available yet!
160 DPA_SaveStream (const HDPA hDpa, DPALOADPROC loadProc, IStream *pStream, LPARAM lParam)
163 FIXME ("hDpa=%p loadProc=%p pStream=%p lParam=%lx\n",
164 hDpa, loadProc, pStream, lParam);
170 /**************************************************************************
171 * DPA_Merge [COMCTL32.11]
174 * hdpa1 [I] handle to a dynamic pointer array
175 * hdpa2 [I] handle to a dynamic pointer array
177 * pfnSort [I] pointer to sort function
178 * pfnMerge [I] pointer to merge function
179 * lParam [I] application specific value
182 * No more information available yet!
186 DPA_Merge (const HDPA hdpa1, const HDPA hdpa2, DWORD dwFlags,
187 PFNDPACOMPARE pfnCompare, PFNDPAMERGE pfnMerge, LPARAM lParam)
191 #if 0 /* these go with the "incomplete implementation" below */
192 LPVOID pWork1, pWork2;
198 TRACE("(%p %p %08lx %p %p %08lx): semi stub!\n",
199 hdpa1, hdpa2, dwFlags, pfnCompare, pfnMerge, lParam);
201 if (IsBadWritePtr (hdpa1, sizeof(DPA)))
204 if (IsBadWritePtr (hdpa2, sizeof(DPA)))
207 if (IsBadCodePtr ((FARPROC)pfnCompare))
210 if (IsBadCodePtr ((FARPROC)pfnMerge))
213 if (dwFlags & DPAM_SORT) {
214 TRACE("sorting dpa's!\n");
215 if (hdpa1->nItemCount > 0)
216 DPA_Sort (hdpa1, pfnCompare, lParam);
217 TRACE ("dpa 1 sorted!\n");
218 if (hdpa2->nItemCount > 0)
219 DPA_Sort (hdpa2, pfnCompare, lParam);
220 TRACE ("dpa 2 sorted!\n");
223 if (hdpa2->nItemCount < 1)
226 TRACE("hdpa1->nItemCount=%d hdpa2->nItemCount=%d\n",
227 hdpa1->nItemCount, hdpa2->nItemCount);
230 /* preliminary hack - simply append the pointer list hdpa2 to hdpa1*/
231 for (nCount = 0; nCount < hdpa2->nItemCount; nCount++)
232 DPA_InsertPtr (hdpa1, hdpa1->nItemCount + 1, hdpa2->ptrs[nCount]);
235 /* incomplete implementation */
237 pWork1 = &(hdpa1->ptrs[hdpa1->nItemCount - 1]);
238 pWork2 = &(hdpa2->ptrs[hdpa2->nItemCount - 1]);
240 nIndex = hdpa1->nItemCount - 1;
241 nCount = hdpa2->nItemCount - 1;
245 nResult = (pfnCompare)(pWork1, pWork2, lParam);
251 ptr = (pfnMerge)(1, pWork1, pWork2, lParam);
259 else if (nResult < 0)
265 ptr = DPA_DeletePtr (hdpa1, hdpa1->nItemCount - 1);
267 (pfnMerge)(2, ptr, NULL, lParam);
276 ptr = (pfnMerge)(3, pWork2, NULL, lParam);
279 DPA_InsertPtr (hdpa1, nIndex, ptr);
296 /**************************************************************************
297 * Alloc [COMCTL32.71]
299 * Allocates memory block from the dll's private heap
302 * dwSize [I] size of the allocated memory block
305 * Success: pointer to allocated memory block
310 COMCTL32_Alloc (DWORD dwSize)
314 TRACE("(0x%lx)\n", dwSize);
316 lpPtr = HeapAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, dwSize);
318 TRACE("-- ret=%p\n", lpPtr);
324 /**************************************************************************
325 * ReAlloc [COMCTL32.72]
327 * Changes the size of an allocated memory block or allocates a memory
328 * block using the dll's private heap.
331 * lpSrc [I] pointer to memory block which will be resized
332 * dwSize [I] new size of the memory block.
335 * Success: pointer to the resized memory block
339 * If lpSrc is a NULL-pointer, then COMCTL32_ReAlloc allocates a memory
340 * block like COMCTL32_Alloc.
344 COMCTL32_ReAlloc (LPVOID lpSrc, DWORD dwSize)
348 TRACE("(%p 0x%08lx)\n", lpSrc, dwSize);
351 lpDest = HeapReAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, lpSrc, dwSize);
353 lpDest = HeapAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, dwSize);
355 TRACE("-- ret=%p\n", lpDest);
361 /**************************************************************************
364 * Frees an allocated memory block from the dll's private heap.
367 * lpMem [I] pointer to memory block which will be freed
375 COMCTL32_Free (LPVOID lpMem)
377 TRACE("(%p)\n", lpMem);
379 return HeapFree (COMCTL32_hHeap, 0, lpMem);
383 /**************************************************************************
384 * GetSize [COMCTL32.74]
386 * Retrieves the size of the specified memory block from the dll's
390 * lpMem [I] pointer to an allocated memory block
393 * Success: size of the specified memory block
398 COMCTL32_GetSize (LPVOID lpMem)
400 TRACE("(%p)\n", lpMem);
402 return HeapSize (COMCTL32_hHeap, 0, lpMem);
406 /**************************************************************************
407 * The MRU-API is a set of functions to manipulate MRU(Most Recently Used)
413 typedef struct tagMRUINFO
421 } MRUINFO, *LPMRUINFO;
424 typedef struct tagMRU
426 DWORD dwParam1; /* some kind of flag */
435 CreateMRUListLazyA (LPMRUINFO lpmi, DWORD dwParam2,
436 DWORD dwParam3, DWORD dwParam4);
439 /**************************************************************************
440 * CreateMRUListA [COMCTL32.151]
449 CreateMRUListA (LPMRUINFO lpmi)
451 return CreateMRUListLazyA (lpmi, 0, 0, 0);
456 FreeMRUListA (HMRU hmru)
458 FIXME("(%p) empty stub!\n", hmru);
461 if (!(hmru->dwParam1 & 1001)) {
462 RegSetValueExA (hmru->hKeyMRU, "MRUList", 0, REG_SZ,
464 lstrlenA (hmru->lpszMRUString));
468 RegClosKey (hmru->hkeyMRU
469 COMCTL32_Free32 (hmru->lpszMRUString);
472 return COMCTL32_Free (hmru);
478 AddMRUData (DWORD dwParam1, DWORD dwParam2, DWORD dwParam3)
481 FIXME("(%lx %lx %lx) empty stub!\n",
482 dwParam1, dwParam2, dwParam3);
489 FindMRUData (DWORD dwParam1, DWORD dwParam2, DWORD dwParam3, DWORD dwParam4)
492 FIXME("(%lx %lx %lx %lx) empty stub!\n",
493 dwParam1, dwParam2, dwParam3, dwParam4);
500 CreateMRUListLazyA (LPMRUINFO lpmi, DWORD dwParam2, DWORD dwParam3, DWORD dwParam4)
509 * DWORD dwDisposition; */
511 /* internal variables */
514 FIXME("(%p) empty stub!\n", lpmi);
517 FIXME("(%lx %lx %lx %lx \"%s\" %lx)\n",
518 lpmi->dwParam1, lpmi->dwParam2, lpmi->dwParam3,
519 (DWORD)lpmi->hkeyMain, lpmi->lpszSubKey, lpmi->dwParam6);
522 /* dummy pointer creation */
523 ptr = COMCTL32_Alloc (32);
525 FIXME("-- ret = %p\n", ptr);
533 /**************************************************************************
534 * Str_GetPtrA [COMCTL32.233]
545 Str_GetPtrA (LPCSTR lpSrc, LPSTR lpDest, INT nMaxLen)
549 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
551 if (!lpDest && lpSrc)
552 return lstrlenA (lpSrc);
562 len = lstrlenA (lpSrc);
566 RtlMoveMemory (lpDest, lpSrc, len);
573 /**************************************************************************
574 * Str_SetPtrA [COMCTL32.234]
584 Str_SetPtrA (LPSTR *lppDest, LPCSTR lpSrc)
586 TRACE("(%p %p)\n", lppDest, lpSrc);
589 LPSTR ptr = COMCTL32_ReAlloc (*lppDest, lstrlenA (lpSrc) + 1);
592 lstrcpyA (ptr, lpSrc);
597 COMCTL32_Free (*lppDest);
606 /**************************************************************************
607 * Str_GetPtrW [COMCTL32.235]
618 Str_GetPtrW (LPCWSTR lpSrc, LPWSTR lpDest, INT nMaxLen)
622 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
624 if (!lpDest && lpSrc)
625 return lstrlenW (lpSrc);
635 len = lstrlenW (lpSrc);
639 RtlMoveMemory (lpDest, lpSrc, len*sizeof(WCHAR));
646 /**************************************************************************
647 * Str_SetPtrW [COMCTL32.236]
657 Str_SetPtrW (LPWSTR *lppDest, LPCWSTR lpSrc)
659 TRACE("(%p %p)\n", lppDest, lpSrc);
662 INT len = lstrlenW (lpSrc) + 1;
663 LPWSTR ptr = COMCTL32_ReAlloc (*lppDest, len * sizeof(WCHAR));
666 lstrcpyW (ptr, lpSrc);
671 COMCTL32_Free (*lppDest);
680 /**************************************************************************
681 * The DSA-API is a set of functions to create and manipulate arrays of
682 * fix sized memory blocks. These arrays can store any kind of data
683 * (strings, icons...).
686 /**************************************************************************
687 * DSA_Create [COMCTL32.320] Creates a dynamic storage array
690 * nSize [I] size of the array elements
691 * nGrow [I] number of elements by which the array grows when it is filled
694 * Success: pointer to a array control structure. use this like a handle.
699 DSA_Create (INT nSize, INT nGrow)
703 TRACE("(size=%d grow=%d)\n", nSize, nGrow);
705 hdsa = (HDSA)COMCTL32_Alloc (sizeof(DSA));
708 hdsa->nItemCount = 0;
711 hdsa->nItemSize = nSize;
712 hdsa->nGrow = MAX(1, nGrow);
719 /**************************************************************************
720 * DSA_Destroy [COMCTL32.321] Destroys a dynamic storage array
723 * hdsa [I] pointer to the array control structure
731 DSA_Destroy (const HDSA hdsa)
733 TRACE("(%p)\n", hdsa);
738 if (hdsa->pData && (!COMCTL32_Free (hdsa->pData)))
741 return COMCTL32_Free (hdsa);
745 /**************************************************************************
746 * DSA_GetItem [COMCTL32.322]
749 * hdsa [I] pointer to the array control structure
750 * nIndex [I] number of the Item to get
751 * pDest [O] destination buffer. Has to be >= dwElementSize.
759 DSA_GetItem (const HDSA hdsa, INT nIndex, LPVOID pDest)
763 TRACE("(%p %d %p)\n", hdsa, nIndex, pDest);
767 if ((nIndex < 0) || (nIndex >= hdsa->nItemCount))
770 pSrc = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
771 memmove (pDest, pSrc, hdsa->nItemSize);
777 /**************************************************************************
778 * DSA_GetItemPtr [COMCTL32.323]
780 * Retrieves a pointer to the specified item.
783 * hdsa [I] pointer to the array control structure
784 * nIndex [I] index of the desired item
787 * Success: pointer to an item
792 DSA_GetItemPtr (const HDSA hdsa, INT nIndex)
796 TRACE("(%p %d)\n", hdsa, nIndex);
800 if ((nIndex < 0) || (nIndex >= hdsa->nItemCount))
803 pSrc = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
805 TRACE("-- ret=%p\n", pSrc);
811 /**************************************************************************
812 * DSA_SetItem [COMCTL32.325]
814 * Sets the contents of an item in the array.
817 * hdsa [I] pointer to the array control structure
818 * nIndex [I] index for the item
819 * pSrc [I] pointer to the new item data
827 DSA_SetItem (const HDSA hdsa, INT nIndex, LPVOID pSrc)
829 INT nSize, nNewItems;
830 LPVOID pDest, lpTemp;
832 TRACE("(%p %d %p)\n", hdsa, nIndex, pSrc);
834 if ((!hdsa) || nIndex < 0)
837 if (hdsa->nItemCount <= nIndex) {
838 /* within the old array */
839 if (hdsa->nMaxCount > nIndex) {
840 /* within the allocated space, set a new boundary */
841 hdsa->nItemCount = nIndex + 1;
844 /* resize the block of memory */
846 hdsa->nGrow * ((INT)(((nIndex + 1) - 1) / hdsa->nGrow) + 1);
847 nSize = hdsa->nItemSize * nNewItems;
849 lpTemp = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
853 hdsa->nMaxCount = nNewItems;
854 hdsa->nItemCount = nIndex + 1;
855 hdsa->pData = lpTemp;
859 /* put the new entry in */
860 pDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
861 TRACE("-- move dest=%p src=%p size=%d\n",
862 pDest, pSrc, hdsa->nItemSize);
863 memmove (pDest, pSrc, hdsa->nItemSize);
869 /**************************************************************************
870 * DSA_InsertItem [COMCTL32.325]
873 * hdsa [I] pointer to the array control structure
874 * nIndex [I] index for the new item
875 * pSrc [I] pointer to the element
878 * Success: position of the new item
883 DSA_InsertItem (const HDSA hdsa, INT nIndex, LPVOID pSrc)
885 INT nNewItems, nSize, i;
886 LPVOID lpTemp, lpDest;
889 TRACE("(%p %d %p)\n", hdsa, nIndex, pSrc);
891 if ((!hdsa) || nIndex < 0)
894 for (i = 0; i < hdsa->nItemSize; i += 4) {
895 p = *(DWORD**)((char *) pSrc + i);
896 if (IsBadStringPtrA ((char*)p, 256))
897 TRACE("-- %d=%p\n", i, (DWORD*)p);
899 TRACE("-- %d=%p [%s]\n", i, p, debugstr_a((char*)p));
902 /* when nIndex > nItemCount then append */
903 if (nIndex >= hdsa->nItemCount)
904 nIndex = hdsa->nItemCount;
906 /* do we need to resize ? */
907 if (hdsa->nItemCount >= hdsa->nMaxCount) {
908 nNewItems = hdsa->nMaxCount + hdsa->nGrow;
909 nSize = hdsa->nItemSize * nNewItems;
911 lpTemp = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
915 hdsa->nMaxCount = nNewItems;
916 hdsa->pData = lpTemp;
919 /* do we need to move elements ? */
920 if (nIndex < hdsa->nItemCount) {
921 lpTemp = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
922 lpDest = (char *) lpTemp + hdsa->nItemSize;
923 nSize = (hdsa->nItemCount - nIndex) * hdsa->nItemSize;
924 TRACE("-- move dest=%p src=%p size=%d\n",
925 lpDest, lpTemp, nSize);
926 memmove (lpDest, lpTemp, nSize);
929 /* ok, we can put the new Item in */
931 lpDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
932 TRACE("-- move dest=%p src=%p size=%d\n",
933 lpDest, pSrc, hdsa->nItemSize);
934 memmove (lpDest, pSrc, hdsa->nItemSize);
936 return hdsa->nItemCount;
940 /**************************************************************************
941 * DSA_DeleteItem [COMCTL32.326]
944 * hdsa [I] pointer to the array control structure
945 * nIndex [I] index for the element to delete
948 * Success: number of the deleted element
953 DSA_DeleteItem (const HDSA hdsa, INT nIndex)
958 TRACE("(%p %d)\n", hdsa, nIndex);
962 if (nIndex < 0 || nIndex >= hdsa->nItemCount)
965 /* do we need to move ? */
966 if (nIndex < hdsa->nItemCount - 1) {
967 lpDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
968 lpSrc = (char *) lpDest + hdsa->nItemSize;
969 nSize = hdsa->nItemSize * (hdsa->nItemCount - nIndex - 1);
970 TRACE("-- move dest=%p src=%p size=%d\n",
971 lpDest, lpSrc, nSize);
972 memmove (lpDest, lpSrc, nSize);
978 if ((hdsa->nMaxCount - hdsa->nItemCount) >= hdsa->nGrow) {
979 nSize = hdsa->nItemSize * hdsa->nItemCount;
981 lpDest = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
985 hdsa->nMaxCount = hdsa->nItemCount;
986 hdsa->pData = lpDest;
993 /**************************************************************************
994 * DSA_DeleteAllItems [COMCTL32.326]
996 * Removes all items and reinitializes the array.
999 * hdsa [I] pointer to the array control structure
1007 DSA_DeleteAllItems (const HDSA hdsa)
1009 TRACE("(%p)\n", hdsa);
1013 if (hdsa->pData && (!COMCTL32_Free (hdsa->pData)))
1016 hdsa->nItemCount = 0;
1018 hdsa->nMaxCount = 0;
1024 /**************************************************************************
1025 * The DPA-API is a set of functions to create and manipulate arrays of
1029 /**************************************************************************
1030 * DPA_Create [COMCTL32.328] Creates a dynamic pointer array
1033 * nGrow [I] number of items by which the array grows when it is filled
1036 * Success: handle (pointer) to the pointer array.
1041 DPA_Create (INT nGrow)
1045 TRACE("(%d)\n", nGrow);
1047 hdpa = (HDPA)COMCTL32_Alloc (sizeof(DPA));
1049 hdpa->nGrow = MAX(8, nGrow);
1050 hdpa->hHeap = COMCTL32_hHeap;
1051 hdpa->nMaxCount = hdpa->nGrow * 2;
1053 (LPVOID*)COMCTL32_Alloc (hdpa->nMaxCount * sizeof(LPVOID));
1056 TRACE("-- %p\n", hdpa);
1062 /**************************************************************************
1063 * DPA_Destroy [COMCTL32.329] Destroys a dynamic pointer array
1066 * hdpa [I] handle (pointer) to the pointer array
1074 DPA_Destroy (const HDPA hdpa)
1076 TRACE("(%p)\n", hdpa);
1081 if (hdpa->ptrs && (!HeapFree (hdpa->hHeap, 0, hdpa->ptrs)))
1084 return HeapFree (hdpa->hHeap, 0, hdpa);
1088 /**************************************************************************
1089 * DPA_Grow [COMCTL32.330]
1091 * Sets the growth amount.
1094 * hdpa [I] handle (pointer) to the existing (source) pointer array
1095 * nGrow [I] number of items, the array grows, when it's too small
1103 DPA_Grow (const HDPA hdpa, INT nGrow)
1105 TRACE("(%p %d)\n", hdpa, nGrow);
1110 hdpa->nGrow = MAX(8, nGrow);
1116 /**************************************************************************
1117 * DPA_Clone [COMCTL32.331]
1119 * Copies a pointer array to an other one or creates a copy
1122 * hdpa [I] handle (pointer) to the existing (source) pointer array
1123 * hdpaNew [O] handle (pointer) to the destination pointer array
1126 * Success: pointer to the destination pointer array.
1130 * - If the 'hdpaNew' is a NULL-Pointer, a copy of the source pointer
1131 * array will be created and it's handle (pointer) is returned.
1132 * - If 'hdpa' is a NULL-Pointer, the original implementation crashes,
1133 * this implementation just returns NULL.
1137 DPA_Clone (const HDPA hdpa, const HDPA hdpaNew)
1139 INT nNewItems, nSize;
1145 TRACE("(%p %p)\n", hdpa, hdpaNew);
1148 /* create a new DPA */
1149 hdpaTemp = (HDPA)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1151 hdpaTemp->hHeap = hdpa->hHeap;
1152 hdpaTemp->nGrow = hdpa->nGrow;
1157 if (hdpaTemp->ptrs) {
1158 /* remove old pointer array */
1159 HeapFree (hdpaTemp->hHeap, 0, hdpaTemp->ptrs);
1160 hdpaTemp->ptrs = NULL;
1161 hdpaTemp->nItemCount = 0;
1162 hdpaTemp->nMaxCount = 0;
1165 /* create a new pointer array */
1166 nNewItems = hdpaTemp->nGrow *
1167 ((INT)((hdpa->nItemCount - 1) / hdpaTemp->nGrow) + 1);
1168 nSize = nNewItems * sizeof(LPVOID);
1170 (LPVOID*)HeapAlloc (hdpaTemp->hHeap, HEAP_ZERO_MEMORY, nSize);
1171 hdpaTemp->nMaxCount = nNewItems;
1173 /* clone the pointer array */
1174 hdpaTemp->nItemCount = hdpa->nItemCount;
1175 memmove (hdpaTemp->ptrs, hdpa->ptrs,
1176 hdpaTemp->nItemCount * sizeof(LPVOID));
1182 /**************************************************************************
1183 * DPA_GetPtr [COMCTL32.332]
1185 * Retrieves a pointer from a dynamic pointer array
1188 * hdpa [I] handle (pointer) to the pointer array
1189 * nIndex [I] array index of the desired pointer
1197 DPA_GetPtr (const HDPA hdpa, INT i)
1199 TRACE("(%p %d)\n", hdpa, i);
1205 if ((i < 0) || (i >= hdpa->nItemCount))
1208 TRACE("-- %p\n", hdpa->ptrs[i]);
1210 return hdpa->ptrs[i];
1214 /**************************************************************************
1215 * DPA_GetPtrIndex [COMCTL32.333]
1217 * Retrieves the index of the specified pointer
1220 * hdpa [I] handle (pointer) to the pointer array
1224 * Success: index of the specified pointer
1229 DPA_GetPtrIndex (const HDPA hdpa, LPVOID p)
1236 for (i = 0; i < hdpa->nItemCount; i++) {
1237 if (hdpa->ptrs[i] == p)
1245 /**************************************************************************
1246 * DPA_InsertPtr [COMCTL32.334]
1248 * Inserts a pointer into a dynamic pointer array
1251 * hdpa [I] handle (pointer) to the array
1253 * p [I] pointer to insert
1256 * Success: index of the inserted pointer
1261 DPA_InsertPtr (const HDPA hdpa, INT i, LPVOID p)
1263 INT nNewItems, nSize, nIndex = 0;
1264 LPVOID *lpTemp, *lpDest;
1266 TRACE("(%p %d %p)\n", hdpa, i, p);
1268 if ((!hdpa) || (i < 0))
1273 (LPVOID*)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1274 2 * hdpa->nGrow * sizeof(LPVOID));
1277 hdpa->nMaxCount = hdpa->nGrow * 2;
1281 if (hdpa->nItemCount >= hdpa->nMaxCount) {
1282 TRACE("-- resizing\n");
1283 nNewItems = hdpa->nMaxCount + hdpa->nGrow;
1284 nSize = nNewItems * sizeof(LPVOID);
1286 lpTemp = (LPVOID*)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1290 hdpa->nMaxCount = nNewItems;
1291 hdpa->ptrs = lpTemp;
1294 if (i >= hdpa->nItemCount) {
1295 nIndex = hdpa->nItemCount;
1296 TRACE("-- appending at %d\n", nIndex);
1299 TRACE("-- inserting at %d\n", i);
1300 lpTemp = hdpa->ptrs + i;
1301 lpDest = lpTemp + 1;
1302 nSize = (hdpa->nItemCount - i) * sizeof(LPVOID);
1303 TRACE("-- move dest=%p src=%p size=%x\n",
1304 lpDest, lpTemp, nSize);
1305 memmove (lpDest, lpTemp, nSize);
1312 hdpa->ptrs[nIndex] = p;
1318 /**************************************************************************
1319 * DPA_SetPtr [COMCTL32.335]
1321 * Sets a pointer in the pointer array
1324 * hdpa [I] handle (pointer) to the pointer array
1325 * i [I] index of the pointer that will be set
1326 * p [I] pointer to be set
1334 DPA_SetPtr (const HDPA hdpa, INT i, LPVOID p)
1338 TRACE("(%p %d %p)\n", hdpa, i, p);
1340 if ((!hdpa) || i < 0)
1343 if (hdpa->nItemCount <= i) {
1344 /* within the old array */
1345 if (hdpa->nMaxCount > i) {
1346 /* within the allocated space, set a new boundary */
1347 hdpa->nItemCount = i;
1350 /* resize the block of memory */
1352 hdpa->nGrow * ((INT)(((i+1) - 1) / hdpa->nGrow) + 1);
1353 INT nSize = nNewItems * sizeof(LPVOID);
1355 lpTemp = (LPVOID*)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1360 hdpa->nItemCount = nNewItems;
1361 hdpa->ptrs = lpTemp;
1365 /* put the new entry in */
1372 /**************************************************************************
1373 * DPA_DeletePtr [COMCTL32.336]
1375 * Removes a pointer from the pointer array.
1378 * hdpa [I] handle (pointer) to the pointer array
1379 * i [I] index of the pointer that will be deleted
1382 * Success: deleted pointer
1387 DPA_DeletePtr (const HDPA hdpa, INT i)
1389 LPVOID *lpDest, *lpSrc, lpTemp = NULL;
1392 TRACE("(%p %d)\n", hdpa, i);
1394 if ((!hdpa) || i < 0 || i >= hdpa->nItemCount)
1397 lpTemp = hdpa->ptrs[i];
1399 /* do we need to move ?*/
1400 if (i < hdpa->nItemCount - 1) {
1401 lpDest = hdpa->ptrs + i;
1403 nSize = (hdpa->nItemCount - i - 1) * sizeof(LPVOID);
1404 TRACE("-- move dest=%p src=%p size=%x\n",
1405 lpDest, lpSrc, nSize);
1406 memmove (lpDest, lpSrc, nSize);
1409 hdpa->nItemCount --;
1412 if ((hdpa->nMaxCount - hdpa->nItemCount) >= hdpa->nGrow) {
1413 INT nNewItems = MIN(hdpa->nGrow * 2, hdpa->nItemCount);
1414 nSize = nNewItems * sizeof(LPVOID);
1415 lpDest = (LPVOID)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1420 hdpa->nMaxCount = nNewItems;
1421 hdpa->ptrs = (LPVOID*)lpDest;
1428 /**************************************************************************
1429 * DPA_DeleteAllPtrs [COMCTL32.337]
1431 * Removes all pointers and reinitializes the array.
1434 * hdpa [I] handle (pointer) to the pointer array
1442 DPA_DeleteAllPtrs (const HDPA hdpa)
1444 TRACE("(%p)\n", hdpa);
1449 if (hdpa->ptrs && (!HeapFree (hdpa->hHeap, 0, hdpa->ptrs)))
1452 hdpa->nItemCount = 0;
1453 hdpa->nMaxCount = hdpa->nGrow * 2;
1454 hdpa->ptrs = (LPVOID*)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1455 hdpa->nMaxCount * sizeof(LPVOID));
1461 /**************************************************************************
1462 * DPA_QuickSort [Internal]
1464 * Ordinary quicksort (used by DPA_Sort).
1467 * lpPtrs [I] pointer to the pointer array
1468 * l [I] index of the "left border" of the partition
1469 * r [I] index of the "right border" of the partition
1470 * pfnCompare [I] pointer to the compare function
1471 * lParam [I] user defined value (3rd parameter in compare function)
1478 DPA_QuickSort (LPVOID *lpPtrs, INT l, INT r,
1479 PFNDPACOMPARE pfnCompare, LPARAM lParam)
1484 TRACE("l=%i r=%i\n", l, r);
1488 v = lpPtrs[(int)(l+r)/2];
1490 while ((pfnCompare)(lpPtrs[i], v, lParam) < 0) i++;
1491 while ((pfnCompare)(lpPtrs[j], v, lParam) > 0) j--;
1495 lpPtrs[i++] = lpPtrs[j];
1499 if (l < j) DPA_QuickSort (lpPtrs, l, j, pfnCompare, lParam);
1500 if (i < r) DPA_QuickSort (lpPtrs, i, r, pfnCompare, lParam);
1504 /**************************************************************************
1505 * DPA_Sort [COMCTL32.338]
1507 * Sorts a pointer array using a user defined compare function
1510 * hdpa [I] handle (pointer) to the pointer array
1511 * pfnCompare [I] pointer to the compare function
1512 * lParam [I] user defined value (3rd parameter of compare function)
1520 DPA_Sort (const HDPA hdpa, PFNDPACOMPARE pfnCompare, LPARAM lParam)
1522 if (!hdpa || !pfnCompare)
1525 TRACE("(%p %p 0x%lx)\n", hdpa, pfnCompare, lParam);
1527 if ((hdpa->nItemCount > 1) && (hdpa->ptrs))
1528 DPA_QuickSort (hdpa->ptrs, 0, hdpa->nItemCount - 1,
1529 pfnCompare, lParam);
1535 /**************************************************************************
1536 * DPA_Search [COMCTL32.339]
1538 * Searches a pointer array for a specified pointer
1541 * hdpa [I] handle (pointer) to the pointer array
1542 * pFind [I] pointer to search for
1543 * nStart [I] start index
1544 * pfnCompare [I] pointer to the compare function
1545 * lParam [I] user defined value (3rd parameter of compare function)
1546 * uOptions [I] search options
1549 * Success: index of the pointer in the array.
1553 * Binary search taken from R.Sedgewick "Algorithms in C"!
1554 * Function is NOT tested!
1555 * If something goes wrong, blame HIM not ME! (Eric Kohl)
1559 DPA_Search (const HDPA hdpa, LPVOID pFind, INT nStart,
1560 PFNDPACOMPARE pfnCompare, LPARAM lParam, UINT uOptions)
1562 if (!hdpa || !pfnCompare || !pFind)
1565 TRACE("(%p %p %d %p 0x%08lx 0x%08x)\n",
1566 hdpa, pFind, nStart, pfnCompare, lParam, uOptions);
1568 if (uOptions & DPAS_SORTED) {
1569 /* array is sorted --> use binary search */
1573 TRACE("binary search\n");
1575 l = (nStart == -1) ? 0 : nStart;
1576 r = hdpa->nItemCount - 1;
1580 n = (pfnCompare)(pFind, lpPtr[x], lParam);
1586 TRACE("-- ret=%d\n", n);
1591 if (uOptions & DPAS_INSERTBEFORE) {
1592 TRACE("-- ret=%d\n", r);
1596 if (uOptions & DPAS_INSERTAFTER) {
1597 TRACE("-- ret=%d\n", l);
1602 /* array is not sorted --> use linear search */
1606 TRACE("linear search\n");
1608 nIndex = (nStart == -1)? 0 : nStart;
1610 for (; nIndex < hdpa->nItemCount; nIndex++) {
1611 if ((pfnCompare)(pFind, lpPtr[nIndex], lParam) == 0) {
1612 TRACE("-- ret=%d\n", nIndex);
1618 TRACE("-- not found: ret=-1\n");
1623 /**************************************************************************
1624 * DPA_CreateEx [COMCTL32.340]
1626 * Creates a dynamic pointer array using the specified size and heap.
1629 * nGrow [I] number of items by which the array grows when it is filled
1630 * hHeap [I] handle to the heap where the array is stored
1633 * Success: handle (pointer) to the pointer array.
1638 DPA_CreateEx (INT nGrow, HANDLE hHeap)
1642 TRACE("(%d 0x%x)\n", nGrow, hHeap);
1645 hdpa = (HDPA)HeapAlloc (hHeap, HEAP_ZERO_MEMORY, sizeof(DPA));
1647 hdpa = (HDPA)COMCTL32_Alloc (sizeof(DPA));
1650 hdpa->nGrow = MIN(8, nGrow);
1651 hdpa->hHeap = hHeap ? hHeap : COMCTL32_hHeap;
1652 hdpa->nMaxCount = hdpa->nGrow * 2;
1654 (LPVOID*)HeapAlloc (hHeap, HEAP_ZERO_MEMORY,
1655 hdpa->nMaxCount * sizeof(LPVOID));
1658 TRACE("-- %p\n", hdpa);
1664 /**************************************************************************
1665 * Notification functions
1668 typedef struct tagNOTIFYDATA
1676 } NOTIFYDATA, *LPNOTIFYDATA;
1679 /**************************************************************************
1680 * DoNotify [Internal]
1684 DoNotify (LPNOTIFYDATA lpNotify, UINT uCode, LPNMHDR lpHdr)
1687 LPNMHDR lpNmh = NULL;
1690 TRACE("(0x%04x 0x%04x %d %p 0x%08lx)\n",
1691 lpNotify->hwndFrom, lpNotify->hwndTo, uCode, lpHdr,
1692 lpNotify->dwParam5);
1694 if (!lpNotify->hwndTo)
1697 if (lpNotify->hwndFrom == -1) {
1699 idFrom = lpHdr->idFrom;
1702 if (lpNotify->hwndFrom) {
1703 HWND hwndParent = GetParent (lpNotify->hwndFrom);
1705 hwndParent = GetWindow (lpNotify->hwndFrom, GW_OWNER);
1707 idFrom = GetDlgCtrlID (lpNotify->hwndFrom);
1711 lpNmh = (lpHdr) ? lpHdr : &nmhdr;
1713 lpNmh->hwndFrom = lpNotify->hwndFrom;
1714 lpNmh->idFrom = idFrom;
1715 lpNmh->code = uCode;
1718 return SendMessageA (lpNotify->hwndTo, WM_NOTIFY, idFrom, (LPARAM)lpNmh);
1722 /**************************************************************************
1723 * SendNotify [COMCTL32.341]
1732 * Success: return value from notification
1737 COMCTL32_SendNotify (HWND hwndFrom, HWND hwndTo,
1738 UINT uCode, LPNMHDR lpHdr)
1742 TRACE("(0x%04x 0x%04x %d %p)\n",
1743 hwndFrom, hwndTo, uCode, lpHdr);
1745 notify.hwndFrom = hwndFrom;
1746 notify.hwndTo = hwndTo;
1747 notify.dwParam5 = 0;
1748 notify.dwParam6 = 0;
1750 return DoNotify (¬ify, uCode, lpHdr);
1754 /**************************************************************************
1755 * SendNotifyEx [COMCTL32.342]
1765 * Success: return value from notification
1770 COMCTL32_SendNotifyEx (HWND hwndTo, HWND hwndFrom, UINT uCode,
1771 LPNMHDR lpHdr, DWORD dwParam5)
1776 TRACE("(0x%04x 0x%04x %d %p 0x%08lx)\n",
1777 hwndFrom, hwndTo, uCode, lpHdr, dwParam5);
1779 hwndNotify = hwndTo;
1781 if (IsWindow (hwndFrom)) {
1782 hwndNotify = GetParent (hwndFrom);
1788 notify.hwndFrom = hwndFrom;
1789 notify.hwndTo = hwndNotify;
1790 notify.dwParam5 = dwParam5;
1791 notify.dwParam6 = 0;
1793 return DoNotify (¬ify, uCode, lpHdr);
1797 /**************************************************************************
1798 * StrChrA [COMCTL32.350]
1803 COMCTL32_StrChrA (LPCSTR lpString, CHAR cChar)
1805 return strchr (lpString, cChar);
1809 /**************************************************************************
1810 * StrStrIA [COMCTL32.355]
1814 COMCTL32_StrStrIA (LPCSTR lpStr1, LPCSTR lpStr2)
1820 return ((LPSTR)lpStr1);
1822 while (lpStr1[len1] != 0) ++len1;
1824 while (lpStr2[len2] != 0) ++len2;
1826 return ((LPSTR)(lpStr1 + len1));
1827 first = tolower (*lpStr2);
1828 while (len1 >= len2) {
1829 if (tolower(*lpStr1) == first) {
1830 for (i = 1; i < len2; ++i)
1831 if (tolower (lpStr1[i]) != tolower(lpStr2[i]))
1834 return ((LPSTR)lpStr1);
1842 /**************************************************************************
1843 * StrToIntA [COMCTL32.357] Converts a string to a signed integer.
1847 COMCTL32_StrToIntA (LPSTR lpString)
1849 return atoi(lpString);
1853 /**************************************************************************
1854 * DPA_EnumCallback [COMCTL32.385]
1856 * Enumerates all items in a dynamic pointer array.
1859 * hdpa [I] handle to the dynamic pointer array
1868 DPA_EnumCallback (const HDPA hdpa, DPAENUMPROC enumProc, LPARAM lParam)
1872 TRACE("(%p %p %08lx)\n", hdpa, enumProc, lParam);
1876 if (hdpa->nItemCount <= 0)
1879 for (i = 0; i < hdpa->nItemCount; i++) {
1880 if ((enumProc)(hdpa->ptrs[i], lParam) == 0)
1888 /**************************************************************************
1889 * DPA_DestroyCallback [COMCTL32.386]
1891 * Enumerates all items in a dynamic pointer array and destroys it.
1894 * hdpa [I] handle to the dynamic pointer array
1904 DPA_DestroyCallback (const HDPA hdpa, DPAENUMPROC enumProc, LPARAM lParam)
1906 TRACE("(%p %p %08lx)\n", hdpa, enumProc, lParam);
1908 DPA_EnumCallback (hdpa, enumProc, lParam);
1910 return DPA_Destroy (hdpa);
1914 /**************************************************************************
1915 * DSA_EnumCallback [COMCTL32.387]
1917 * Enumerates all items in a dynamic storage array.
1920 * hdsa [I] handle to the dynamic storage array
1929 DSA_EnumCallback (const HDSA hdsa, DSAENUMPROC enumProc, LPARAM lParam)
1933 TRACE("(%p %p %08lx)\n", hdsa, enumProc, lParam);
1937 if (hdsa->nItemCount <= 0)
1940 for (i = 0; i < hdsa->nItemCount; i++) {
1941 LPVOID lpItem = DSA_GetItemPtr (hdsa, i);
1942 if ((enumProc)(lpItem, lParam) == 0)
1950 /**************************************************************************
1951 * DSA_DestroyCallback [COMCTL32.388]
1953 * Enumerates all items in a dynamic storage array and destroys it.
1956 * hdsa [I] handle to the dynamic storage array
1966 DSA_DestroyCallback (const HDSA hdsa, DSAENUMPROC enumProc, LPARAM lParam)
1968 TRACE("(%p %p %08lx)\n", hdsa, enumProc, lParam);
1970 DSA_EnumCallback (hdsa, enumProc, lParam);
1972 return DSA_Destroy (hdsa);
1975 /**************************************************************************
1976 * StrCSpnA [COMCTL32.356]
1979 INT WINAPI COMCTL32_StrCSpnA( LPCSTR lpStr, LPCSTR lpSet) {
1980 return strcspn(lpStr, lpSet);
1983 /**************************************************************************
1984 * StrChrW [COMCTL32.358]
1987 LPWSTR WINAPI COMCTL32_StrChrW( LPCWSTR lpStart, WORD wMatch) {
1988 return CRTDLL_wcschr(lpStart, wMatch);
1991 /**************************************************************************
1992 * StrCmpNA [COMCTL32.352]
1995 INT WINAPI COMCTL32_StrCmpNA( LPCSTR lpStr1, LPCSTR lpStr2, int nChar) {
1996 return strncmp(lpStr1, lpStr2, nChar);
1999 /**************************************************************************
2000 * StrCmpNIA [COMCTL32.353]
2003 INT WINAPI COMCTL32_StrCmpNIA( LPCSTR lpStr1, LPCSTR lpStr2, int nChar) {
2004 return strncasecmp(lpStr1, lpStr2, nChar);
2007 /**************************************************************************
2008 * StrCmpNW [COMCTL32.360]
2011 INT WINAPI COMCTL32_StrCmpNW( LPCWSTR lpStr1, LPCWSTR lpStr2, int nChar) {
2012 return CRTDLL_wcsncmp(lpStr1, lpStr2, nChar);
2015 /**************************************************************************
2016 * StrCmpNIW [COMCTL32.361]
2019 INT WINAPI COMCTL32_StrCmpNIW( LPCWSTR lpStr1, LPCWSTR lpStr2, int nChar) {
2020 FIXME("(%s, %s, %i): stub\n", debugstr_w(lpStr1), debugstr_w(lpStr2), nChar);
2024 /**************************************************************************
2025 * StrRChrA [COMCTL32.351]
2028 LPSTR WINAPI COMCTL32_StrRChrA( LPCSTR lpStart, LPCSTR lpEnd, WORD wMatch) {
2029 return lstrrchr(lpStart, lpEnd, wMatch);
2032 /**************************************************************************
2033 * StrRChrW [COMCTL32.359]
2036 LPWSTR WINAPI COMCTL32_StrRChrW( LPCWSTR lpStart, LPCWSTR lpEnd, WORD wMatch) {
2037 return lstrrchrw(lpStart, lpEnd, wMatch);
2040 /**************************************************************************
2041 * StrStrA [COMCTL32.354]
2044 LPSTR WINAPI COMCTL32_StrStrA( LPCSTR lpFirst, LPCSTR lpSrch) {
2045 return strstr(lpFirst, lpSrch);
2048 /**************************************************************************
2049 * StrStrW [COMCTL32.362]
2052 LPWSTR WINAPI COMCTL32_StrStrW( LPCWSTR lpFirst, LPCWSTR lpSrch) {
2053 return CRTDLL_wcsstr(lpFirst, lpSrch);
2056 /**************************************************************************
2057 * StrSpnW [COMCTL32.364]
2060 INT WINAPI COMCTL32_StrSpnW( LPWSTR lpStr, LPWSTR lpSet) {
2061 LPWSTR lpLoop = lpStr;
2064 if ((lpStr == 0) || (lpSet == 0)) return 0;
2066 /* while(*lpLoop) { if lpLoop++; } */
2068 for(; (*lpLoop != 0); lpLoop++)
2069 if( CRTDLL_wcschr(lpSet, *(WORD*)lpLoop))
2070 return (INT)(lpLoop-lpStr);
2072 return (INT)(lpLoop-lpStr);
2075 /**************************************************************************
2076 * comctl32_410 [COMCTL32.410]
2078 * FIXME: What's this supposed to do?
2079 * Parameter 1 is an HWND, you're on your own for the rest.
2082 BOOL WINAPI comctl32_410( HWND hw, DWORD b, DWORD c, DWORD d) {
2084 FIXME_(commctrl)("(%x, %lx, %lx, %lx): stub!\n", hw, b, c, d);
2089 /*************************************************************************
2090 * InitMUILanguage [COMCTL32.70]
2092 * FIXME: What's this supposed to do? Apparently some i18n thing.
2096 BOOL WINAPI InitMUILanguage( DWORD a ) {
2098 FIXME_(commctrl)("(%lx): stub!\n", a);