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 extern HANDLE32 COMCTL32_hHeap
; /* handle to the private heap */
29 * We put some function prototypes here that don't seem to belong in
30 * any header file. When they find their place, we can remove them.
32 extern LPWSTR __cdecl
CRTDLL_wcschr(LPCWSTR
, WCHAR
);
33 extern LPSTR WINAPI
lstrrchr(LPCSTR
, LPCSTR
, WORD
);
34 extern LPWSTR WINAPI
lstrrchrw(LPCWSTR
, LPCWSTR
, WORD
);
35 extern LPWSTR WINAPI
strstrw(LPCWSTR
, LPCWSTR
);
38 /**************************************************************************
39 * DPA_Merge [COMCTL32.11]
42 * hdpa1 [I] handle to a dynamic pointer array
43 * hdpa2 [I] handle to a dynamic pointer array
45 * pfnSort [I] pointer to sort function
47 * lParam [I] application specific value
50 * No more information available yet!
54 DPA_Merge (const HDPA hdpa1
, const HDPA hdpa2
, DWORD dwFlags
,
55 PFNDPACOMPARE pfnCompare
, LPVOID pfnParam5
, LPARAM lParam
)
57 /* LPVOID *pWork1, *pWork2; */
58 INT32 nCount1
, nCount2
;
60 TRACE (commctrl
, "(%p %p %08lx %p %p %08lx): stub!\n",
61 hdpa1
, hdpa2
, dwFlags
, pfnCompare
, pfnParam5
, lParam
);
63 if (IsBadWritePtr32 (hdpa1
, sizeof(DPA
)))
66 if (IsBadWritePtr32 (hdpa2
, sizeof(DPA
)))
69 if (IsBadCodePtr32 ((FARPROC32
)pfnCompare
))
72 if (IsBadCodePtr32 ((FARPROC32
)pfnParam5
))
75 if (dwFlags
& DPAM_SORT
) {
76 TRACE (commctrl
, "sorting dpa's!\n");
77 DPA_Sort (hdpa1
, pfnCompare
, lParam
);
78 DPA_Sort (hdpa2
, pfnCompare
, lParam
);
81 if (hdpa2
->nItemCount
<= 0)
84 nCount1
= hdpa1
->nItemCount
- 1;
86 nCount2
= hdpa2
->nItemCount
- 1;
88 FIXME (commctrl
, "nCount1=%d nCount2=%d\n", nCount1
, nCount2
);
89 FIXME (commctrl
, "semi stub!\n");
98 else if (nResult
> 0) {
106 while (nCount2
>= 0);
115 /**************************************************************************
116 * Alloc [COMCTL32.71]
118 * Allocates memory block from the dll's private heap
121 * dwSize [I] size of the allocated memory block
124 * Success: pointer to allocated memory block
129 COMCTL32_Alloc (DWORD dwSize
)
133 TRACE (commctrl
, "(0x%lx)\n", dwSize
);
135 lpPtr
= HeapAlloc (COMCTL32_hHeap
, HEAP_ZERO_MEMORY
, dwSize
);
137 TRACE (commctrl
, "-- ret=%p\n", lpPtr
);
143 /**************************************************************************
144 * ReAlloc [COMCTL32.72]
146 * Changes the size of an allocated memory block or allocates a memory
147 * block using the dll's private heap.
150 * lpSrc [I] pointer to memory block which will be resized
151 * dwSize [I] new size of the memory block.
154 * Success: pointer to the resized memory block
158 * If lpSrc is a NULL-pointer, then COMCTL32_ReAlloc allocates a memory
159 * block like COMCTL32_Alloc.
163 COMCTL32_ReAlloc (LPVOID lpSrc
, DWORD dwSize
)
167 TRACE (commctrl
, "(%p 0x%08lx)\n", lpSrc
, dwSize
);
170 lpDest
= HeapReAlloc (COMCTL32_hHeap
, HEAP_ZERO_MEMORY
, lpSrc
, dwSize
);
172 lpDest
= HeapAlloc (COMCTL32_hHeap
, HEAP_ZERO_MEMORY
, dwSize
);
174 TRACE (commctrl
, "-- ret=%p\n", lpDest
);
180 /**************************************************************************
183 * Frees an allocated memory block from the dll's private heap.
186 * lpMem [I] pointer to memory block which will be freed
194 COMCTL32_Free (LPVOID lpMem
)
196 TRACE (commctrl
, "(%p)\n", lpMem
);
198 return HeapFree (COMCTL32_hHeap
, 0, lpMem
);
202 /**************************************************************************
203 * GetSize [COMCTL32.74]
205 * Retrieves the size of the specified memory block from the dll's
209 * lpMem [I] pointer to an allocated memory block
212 * Success: size of the specified memory block
217 COMCTL32_GetSize (LPVOID lpMem
)
219 TRACE (commctrl
, "(%p)\n", lpMem
);
221 return HeapSize (COMCTL32_hHeap
, 0, lpMem
);
225 /**************************************************************************
226 * The MRU-API is a set of functions to manipulate MRU(Most Recently Used)
232 typedef struct tagMRUINFO
240 } MRUINFO
, *LPMRUINFO
;
243 typedef struct tagMRU
245 DWORD dwParam1
; /* some kind of flag */
254 CreateMRUListLazy32A (LPMRUINFO lpmi
, DWORD dwParam2
,
255 DWORD dwParam3
, DWORD dwParam4
);
258 /**************************************************************************
259 * CreateMRUListA [COMCTL32.151]
268 CreateMRUList32A (LPMRUINFO lpmi
)
270 return CreateMRUListLazy32A (lpmi
, 0, 0, 0);
275 FreeMRUList32A (HMRU hmru
)
277 FIXME (commctrl
, "(%p) empty stub!\n", hmru
);
280 if (!(hmru
->dwParam1
& 1001)) {
281 RegSetValueEx32A (hmru
->hKeyMRU
, "MRUList", 0, REG_SZ
,
283 lstrlen32A (hmru
->lpszMRUString
));
287 RegClosKey32 (hmru
->hkeyMRU
288 COMCTL32_Free32 (hmru
->lpszMRUString
);
291 return COMCTL32_Free (hmru
);
297 AddMRUData (DWORD dwParam1
, DWORD dwParam2
, DWORD dwParam3
)
300 FIXME (commctrl
, "(%lx %lx %lx) empty stub!\n",
301 dwParam1
, dwParam2
, dwParam3
);
308 FindMRUData (DWORD dwParam1
, DWORD dwParam2
, DWORD dwParam3
, DWORD dwParam4
)
311 FIXME (commctrl
, "(%lx %lx %lx %lx) empty stub!\n",
312 dwParam1
, dwParam2
, dwParam3
, dwParam4
);
319 CreateMRUListLazy32A (LPMRUINFO lpmi
, DWORD dwParam2
, DWORD dwParam3
, DWORD dwParam4
)
328 * DWORD dwDisposition; */
330 /* internal variables */
333 FIXME (commctrl
, "(%p) empty stub!\n", lpmi
);
336 FIXME (commctrl
, "(%lx %lx %lx %lx \"%s\" %lx)\n",
337 lpmi
->dwParam1
, lpmi
->dwParam2
, lpmi
->dwParam3
,
338 (DWORD
)lpmi
->hkeyMain
, lpmi
->lpszSubKey
, lpmi
->dwParam6
);
341 /* dummy pointer creation */
342 ptr
= COMCTL32_Alloc (32);
344 FIXME (commctrl
, "-- ret = %p\n", ptr
);
352 /**************************************************************************
353 * Str_GetPtrA [COMCTL32.233]
364 Str_GetPtr32A (LPCSTR lpSrc
, LPSTR lpDest
, INT32 nMaxLen
)
368 TRACE (commctrl
, "(%p %p %d)\n", lpSrc
, lpDest
, nMaxLen
);
370 if (!lpDest
&& lpSrc
)
371 return lstrlen32A (lpSrc
);
381 len
= lstrlen32A (lpSrc
);
385 RtlMoveMemory (lpDest
, lpSrc
, len
);
392 /**************************************************************************
393 * Str_SetPtrA [COMCTL32.234]
403 Str_SetPtr32A (LPSTR
*lppDest
, LPCSTR lpSrc
)
405 TRACE (commctrl
, "(%p %p)\n", lppDest
, lpSrc
);
408 LPSTR ptr
= COMCTL32_ReAlloc (*lppDest
, lstrlen32A (lpSrc
) + 1);
411 lstrcpy32A (ptr
, lpSrc
);
416 COMCTL32_Free (*lppDest
);
425 /**************************************************************************
426 * Str_GetPtrW [COMCTL32.235]
437 Str_GetPtr32W (LPCWSTR lpSrc
, LPWSTR lpDest
, INT32 nMaxLen
)
441 TRACE (commctrl
, "(%p %p %d)\n", lpSrc
, lpDest
, nMaxLen
);
443 if (!lpDest
&& lpSrc
)
444 return lstrlen32W (lpSrc
);
454 len
= lstrlen32W (lpSrc
);
458 RtlMoveMemory (lpDest
, lpSrc
, len
*sizeof(WCHAR
));
465 /**************************************************************************
466 * Str_SetPtrW [COMCTL32.236]
476 Str_SetPtr32W (LPWSTR
*lppDest
, LPCWSTR lpSrc
)
478 TRACE (commctrl
, "(%p %p)\n", lppDest
, lpSrc
);
481 INT32 len
= lstrlen32W (lpSrc
) + 1;
482 LPWSTR ptr
= COMCTL32_ReAlloc (*lppDest
, len
* sizeof(WCHAR
));
485 lstrcpy32W (ptr
, lpSrc
);
490 COMCTL32_Free (*lppDest
);
499 /**************************************************************************
500 * The DSA-API is a set of functions to create and manipulate arrays of
501 * fix sized memory blocks. These arrays can store any kind of data
502 * (strings, icons...).
505 /**************************************************************************
506 * DSA_Create [COMCTL32.320] Creates a dynamic storage array
509 * nSize [I] size of the array elements
510 * nGrow [I] number of elements by which the array grows when it is filled
513 * Success: pointer to a array control structure. use this like a handle.
518 DSA_Create (INT32 nSize
, INT32 nGrow
)
522 TRACE (commctrl
, "(size=%d grow=%d)\n", nSize
, nGrow
);
524 hdsa
= (HDSA
)COMCTL32_Alloc (sizeof(DSA
));
527 hdsa
->nItemCount
= 0;
530 hdsa
->nItemSize
= nSize
;
531 hdsa
->nGrow
= MAX(1, nGrow
);
538 /**************************************************************************
539 * DSA_Destroy [COMCTL32.321] Destroys a dynamic storage array
542 * hdsa [I] pointer to the array control structure
550 DSA_Destroy (const HDSA hdsa
)
552 TRACE (commctrl
, "(%p)\n", hdsa
);
557 if (hdsa
->pData
&& (!COMCTL32_Free (hdsa
->pData
)))
560 return COMCTL32_Free (hdsa
);
564 /**************************************************************************
565 * DSA_GetItem [COMCTL32.322]
568 * hdsa [I] pointer to the array control structure
569 * nIndex [I] number of the Item to get
570 * pDest [O] destination buffer. Has to be >= dwElementSize.
578 DSA_GetItem (const HDSA hdsa
, INT32 nIndex
, LPVOID pDest
)
582 TRACE (commctrl
, "(%p %d %p)\n", hdsa
, nIndex
, pDest
);
586 if ((nIndex
< 0) || (nIndex
>= hdsa
->nItemCount
))
589 pSrc
= hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
590 memmove (pDest
, pSrc
, hdsa
->nItemSize
);
596 /**************************************************************************
597 * DSA_GetItemPtr [COMCTL32.323]
599 * Retrieves a pointer to the specified item.
602 * hdsa [I] pointer to the array control structure
603 * nIndex [I] index of the desired item
606 * Success: pointer to an item
611 DSA_GetItemPtr (const HDSA hdsa
, INT32 nIndex
)
615 TRACE (commctrl
, "(%p %d)\n", hdsa
, nIndex
);
619 if ((nIndex
< 0) || (nIndex
>= hdsa
->nItemCount
))
622 pSrc
= hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
624 TRACE (commctrl
, "-- ret=%p\n", pSrc
);
630 /**************************************************************************
631 * DSA_SetItem [COMCTL32.325]
633 * Sets the contents of an item in the array.
636 * hdsa [I] pointer to the array control structure
637 * nIndex [I] index for the item
638 * pSrc [I] pointer to the new item data
646 DSA_SetItem (const HDSA hdsa
, INT32 nIndex
, LPVOID pSrc
)
648 INT32 nSize
, nNewItems
;
649 LPVOID pDest
, lpTemp
;
651 TRACE (commctrl
, "(%p %d %p)\n", hdsa
, nIndex
, pSrc
);
653 if ((!hdsa
) || nIndex
< 0)
656 if (hdsa
->nItemCount
<= nIndex
) {
657 /* within the old array */
658 if (hdsa
->nMaxCount
> nIndex
) {
659 /* within the allocated space, set a new boundary */
660 hdsa
->nItemCount
= nIndex
;
663 /* resize the block of memory */
665 hdsa
->nGrow
* ((INT32
)((nIndex
- 1) / hdsa
->nGrow
) + 1);
666 nSize
= hdsa
->nItemSize
* nNewItems
;
668 lpTemp
= (LPVOID
)COMCTL32_ReAlloc (hdsa
->pData
, nSize
);
672 hdsa
->nMaxCount
= nNewItems
;
673 hdsa
->pData
= lpTemp
;
677 /* put the new entry in */
678 pDest
= hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
679 TRACE (commctrl
, "-- move dest=%p src=%p size=%d\n",
680 pDest
, pSrc
, hdsa
->nItemSize
);
681 memmove (pDest
, pSrc
, hdsa
->nItemSize
);
687 /**************************************************************************
688 * DSA_InsertItem [COMCTL32.325]
691 * hdsa [I] pointer to the array control structure
692 * nIndex [I] index for the new item
693 * pSrc [I] pointer to the element
696 * Success: position of the new item
701 DSA_InsertItem (const HDSA hdsa
, INT32 nIndex
, LPVOID pSrc
)
703 INT32 nNewItems
, nSize
, i
;
704 LPVOID lpTemp
, lpDest
;
707 TRACE(commctrl
, "(%p %d %p)\n", hdsa
, nIndex
, pSrc
);
709 if ((!hdsa
) || nIndex
< 0)
712 for (i
= 0; i
< hdsa
->nItemSize
; i
+= 4) {
713 p
= *(DWORD
**)(pSrc
+ i
);
714 if (IsBadStringPtr32A ((char*)p
, 256))
715 TRACE (commctrl
, "-- %d=%p\n", i
, (DWORD
*)p
);
717 TRACE (commctrl
, "-- %d=%p [%s]\n", i
, p
, debugstr_a((char*)p
));
720 /* when nIndex > nItemCount then append */
721 if (nIndex
>= hdsa
->nItemCount
)
722 nIndex
= hdsa
->nItemCount
;
724 /* do we need to resize ? */
725 if (hdsa
->nItemCount
>= hdsa
->nMaxCount
) {
726 nNewItems
= hdsa
->nMaxCount
+ hdsa
->nGrow
;
727 nSize
= hdsa
->nItemSize
* nNewItems
;
729 lpTemp
= (LPVOID
)COMCTL32_ReAlloc (hdsa
->pData
, nSize
);
733 hdsa
->nMaxCount
= nNewItems
;
734 hdsa
->pData
= lpTemp
;
737 /* do we need to move elements ? */
738 if (nIndex
< hdsa
->nItemCount
) {
739 lpTemp
= hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
740 lpDest
= lpTemp
+ hdsa
->nItemSize
;
741 nSize
= (hdsa
->nItemCount
- nIndex
) * hdsa
->nItemSize
;
742 TRACE (commctrl
, "-- move dest=%p src=%p size=%d\n",
743 lpDest
, lpTemp
, nSize
);
744 memmove (lpDest
, lpTemp
, nSize
);
747 /* ok, we can put the new Item in */
749 lpDest
= hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
750 TRACE (commctrl
, "-- move dest=%p src=%p size=%d\n",
751 lpDest
, pSrc
, hdsa
->nItemSize
);
752 memmove (lpDest
, pSrc
, hdsa
->nItemSize
);
754 return hdsa
->nItemCount
;
758 /**************************************************************************
759 * DSA_DeleteItem [COMCTL32.326]
762 * hdsa [I] pointer to the array control structure
763 * nIndex [I] index for the element to delete
766 * Success: number of the deleted element
771 DSA_DeleteItem (const HDSA hdsa
, INT32 nIndex
)
776 TRACE (commctrl
, "(%p %d)\n", hdsa
, nIndex
);
780 if (nIndex
< 0 || nIndex
>= hdsa
->nItemCount
)
783 /* do we need to move ? */
784 if (nIndex
< hdsa
->nItemCount
- 1) {
785 lpDest
= hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
786 lpSrc
= lpDest
+ hdsa
->nItemSize
;
787 nSize
= hdsa
->nItemSize
* (hdsa
->nItemCount
- nIndex
- 1);
788 TRACE (commctrl
, "-- move dest=%p src=%p size=%d\n",
789 lpDest
, lpSrc
, nSize
);
790 memmove (lpDest
, lpSrc
, nSize
);
796 if ((hdsa
->nMaxCount
- hdsa
->nItemCount
) >= hdsa
->nGrow
) {
797 nSize
= hdsa
->nItemSize
* hdsa
->nItemCount
;
799 lpDest
= (LPVOID
)COMCTL32_ReAlloc (hdsa
->pData
, nSize
);
803 hdsa
->nMaxCount
= hdsa
->nItemCount
;
804 hdsa
->pData
= lpDest
;
811 /**************************************************************************
812 * DSA_DeleteAllItems [COMCTL32.326]
814 * Removes all items and reinitializes the array.
817 * hdsa [I] pointer to the array control structure
825 DSA_DeleteAllItems (const HDSA hdsa
)
827 TRACE (commctrl
, "(%p)\n", hdsa
);
831 if (hdsa
->pData
&& (!COMCTL32_Free (hdsa
->pData
)))
834 hdsa
->nItemCount
= 0;
842 /**************************************************************************
843 * The DPA-API is a set of functions to create and manipulate arrays of
847 /**************************************************************************
848 * DPA_Create [COMCTL32.328] Creates a dynamic pointer array
851 * nGrow [I] number of items by which the array grows when it is filled
854 * Success: handle (pointer) to the pointer array.
859 DPA_Create (INT32 nGrow
)
863 TRACE (commctrl
, "(%d)\n", nGrow
);
865 hdpa
= (HDPA
)COMCTL32_Alloc (sizeof(DPA
));
867 hdpa
->nGrow
= MAX(8, nGrow
);
868 hdpa
->hHeap
= COMCTL32_hHeap
;
869 hdpa
->nMaxCount
= hdpa
->nGrow
* 2;
871 (LPVOID
*)COMCTL32_Alloc (hdpa
->nMaxCount
* sizeof(LPVOID
));
874 TRACE (commctrl
, "-- %p\n", hdpa
);
880 /**************************************************************************
881 * DPA_Destroy [COMCTL32.329] Destroys a dynamic pointer array
884 * hdpa [I] handle (pointer) to the pointer array
892 DPA_Destroy (const HDPA hdpa
)
894 TRACE (commctrl
, "(%p)\n", hdpa
);
899 if (hdpa
->ptrs
&& (!HeapFree (hdpa
->hHeap
, 0, hdpa
->ptrs
)))
902 return HeapFree (hdpa
->hHeap
, 0, hdpa
);
906 /**************************************************************************
907 * DPA_Grow [COMCTL32.330]
909 * Sets the growth amount.
912 * hdpa [I] handle (pointer) to the existing (source) pointer array
913 * nGrow [I] number of items, the array grows, when it's too small
921 DPA_Grow (const HDPA hdpa
, INT32 nGrow
)
923 TRACE (commctrl
, "(%p %d)\n", hdpa
, nGrow
);
928 hdpa
->nGrow
= MAX(8, nGrow
);
934 /**************************************************************************
935 * DPA_Clone [COMCTL32.331]
937 * Copies a pointer array to an other one or creates a copy
940 * hdpa [I] handle (pointer) to the existing (source) pointer array
941 * hdpaNew [O] handle (pointer) to the destination pointer array
944 * Success: pointer to the destination pointer array.
948 * - If the 'hdpaNew' is a NULL-Pointer, a copy of the source pointer
949 * array will be created and it's handle (pointer) is returned.
950 * - If 'hdpa' is a NULL-Pointer, the original implementation crashes,
951 * this implementation just returns NULL.
955 DPA_Clone (const HDPA hdpa
, const HDPA hdpaNew
)
957 INT32 nNewItems
, nSize
;
963 TRACE (commctrl
, "(%p %p)\n", hdpa
, hdpaNew
);
966 /* create a new DPA */
967 hdpaTemp
= (HDPA
)HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
969 hdpaTemp
->hHeap
= hdpa
->hHeap
;
970 hdpaTemp
->nGrow
= hdpa
->nGrow
;
975 if (hdpaTemp
->ptrs
) {
976 /* remove old pointer array */
977 HeapFree (hdpaTemp
->hHeap
, 0, hdpaTemp
->ptrs
);
978 hdpaTemp
->ptrs
= NULL
;
979 hdpaTemp
->nItemCount
= 0;
980 hdpaTemp
->nMaxCount
= 0;
983 /* create a new pointer array */
984 nNewItems
= hdpaTemp
->nGrow
*
985 ((INT32
)((hdpa
->nItemCount
- 1) / hdpaTemp
->nGrow
) + 1);
986 nSize
= nNewItems
* sizeof(LPVOID
);
988 (LPVOID
*)HeapAlloc (hdpaTemp
->hHeap
, HEAP_ZERO_MEMORY
, nSize
);
989 hdpaTemp
->nMaxCount
= nNewItems
;
991 /* clone the pointer array */
992 hdpaTemp
->nItemCount
= hdpa
->nItemCount
;
993 memmove (hdpaTemp
->ptrs
, hdpa
->ptrs
,
994 hdpaTemp
->nItemCount
* sizeof(LPVOID
));
1000 /**************************************************************************
1001 * DPA_GetPtr [COMCTL32.332]
1003 * Retrieves a pointer from a dynamic pointer array
1006 * hdpa [I] handle (pointer) to the pointer array
1007 * nIndex [I] array index of the desired pointer
1015 DPA_GetPtr (const HDPA hdpa
, INT32 i
)
1017 TRACE (commctrl
, "(%p %d)\n", hdpa
, i
);
1023 if ((i
< 0) || (i
>= hdpa
->nItemCount
))
1026 TRACE (commctrl
, "-- %p\n", hdpa
->ptrs
[i
]);
1028 return hdpa
->ptrs
[i
];
1032 /**************************************************************************
1033 * DPA_GetPtrIndex [COMCTL32.333]
1035 * Retrieves the index of the specified pointer
1038 * hdpa [I] handle (pointer) to the pointer array
1042 * Success: index of the specified pointer
1047 DPA_GetPtrIndex (const HDPA hdpa
, LPVOID p
)
1054 for (i
= 0; i
< hdpa
->nItemCount
; i
++) {
1055 if (hdpa
->ptrs
[i
] == p
)
1063 /**************************************************************************
1064 * DPA_InsertPtr [COMCTL32.334]
1066 * Inserts a pointer into a dynamic pointer array
1069 * hdpa [I] handle (pointer) to the array
1071 * p [I] pointer to insert
1074 * Success: index of the inserted pointer
1079 DPA_InsertPtr (const HDPA hdpa
, INT32 i
, LPVOID p
)
1081 INT32 nNewItems
, nSize
, nIndex
= 0;
1082 LPVOID
*lpTemp
, *lpDest
;
1084 TRACE (commctrl
, "(%p %d %p)\n", hdpa
, i
, p
);
1086 if ((!hdpa
) || (i
< 0))
1091 (LPVOID
*)HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
1092 2 * hdpa
->nGrow
* sizeof(LPVOID
));
1095 hdpa
->nMaxCount
= hdpa
->nGrow
* 2;
1099 if (hdpa
->nItemCount
>= hdpa
->nMaxCount
) {
1100 TRACE (commctrl
, "-- resizing\n");
1101 nNewItems
= hdpa
->nMaxCount
+ hdpa
->nGrow
;
1102 nSize
= nNewItems
* sizeof(LPVOID
);
1104 lpTemp
= (LPVOID
*)HeapReAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
1108 hdpa
->nMaxCount
= nNewItems
;
1109 hdpa
->ptrs
= lpTemp
;
1112 if (i
>= hdpa
->nItemCount
) {
1113 nIndex
= hdpa
->nItemCount
;
1114 TRACE (commctrl
, "-- appending at %d\n", nIndex
);
1117 TRACE (commctrl
, "-- inserting at %d\n", i
);
1118 lpTemp
= hdpa
->ptrs
+ i
;
1119 lpDest
= lpTemp
+ 1;
1120 nSize
= (hdpa
->nItemCount
- i
) * sizeof(LPVOID
);
1121 TRACE (commctrl
, "-- move dest=%p src=%p size=%x\n",
1122 lpDest
, lpTemp
, nSize
);
1123 memmove (lpDest
, lpTemp
, nSize
);
1130 hdpa
->ptrs
[nIndex
] = p
;
1136 /**************************************************************************
1137 * DPA_SetPtr [COMCTL32.335]
1139 * Sets a pointer in the pointer array
1142 * hdpa [I] handle (pointer) to the pointer array
1143 * i [I] index of the pointer that will be set
1144 * p [I] pointer to be set
1152 DPA_SetPtr (const HDPA hdpa
, INT32 i
, LPVOID p
)
1156 TRACE (commctrl
, "(%p %d %p)\n", hdpa
, i
, p
);
1158 if ((!hdpa
) || i
< 0)
1161 if (hdpa
->nItemCount
<= i
) {
1162 /* within the old array */
1163 if (hdpa
->nMaxCount
> i
) {
1164 /* within the allocated space, set a new boundary */
1165 hdpa
->nItemCount
= i
;
1168 /* resize the block of memory */
1170 hdpa
->nGrow
* ((INT32
)((i
- 1) / hdpa
->nGrow
) + 1);
1171 INT32 nSize
= nNewItems
* sizeof(LPVOID
);
1173 lpTemp
= (LPVOID
*)HeapReAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
1178 hdpa
->nItemCount
= nNewItems
;
1179 hdpa
->ptrs
= lpTemp
;
1183 /* put the new entry in */
1190 /**************************************************************************
1191 * DPA_DeletePtr [COMCTL32.336]
1193 * Removes a pointer from the pointer array.
1196 * hdpa [I] handle (pointer) to the pointer array
1197 * i [I] index of the pointer that will be deleted
1200 * Success: deleted pointer
1205 DPA_DeletePtr (const HDPA hdpa
, INT32 i
)
1207 LPVOID
*lpDest
, *lpSrc
, lpTemp
= NULL
;
1210 TRACE (commctrl
, "(%p %d)\n", hdpa
, i
);
1212 if ((!hdpa
) || i
< 0 || i
>= hdpa
->nItemCount
)
1215 lpTemp
= hdpa
->ptrs
[i
];
1217 /* do we need to move ?*/
1218 if (i
< hdpa
->nItemCount
- 1) {
1219 lpDest
= hdpa
->ptrs
+ i
;
1221 nSize
= (hdpa
->nItemCount
- i
- 1) * sizeof(LPVOID
);
1222 TRACE (commctrl
,"-- move dest=%p src=%p size=%x\n",
1223 lpDest
, lpSrc
, nSize
);
1224 memmove (lpDest
, lpSrc
, nSize
);
1227 hdpa
->nItemCount
--;
1230 if ((hdpa
->nMaxCount
- hdpa
->nItemCount
) >= hdpa
->nGrow
) {
1231 INT32 nNewItems
= MIN(hdpa
->nGrow
* 2, hdpa
->nItemCount
);
1232 nSize
= nNewItems
* sizeof(LPVOID
);
1233 lpDest
= (LPVOID
)HeapReAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
1238 hdpa
->nMaxCount
= nNewItems
;
1239 hdpa
->ptrs
= (LPVOID
*)lpDest
;
1246 /**************************************************************************
1247 * DPA_DeleteAllPtrs [COMCTL32.337]
1249 * Removes all pointers and reinitializes the array.
1252 * hdpa [I] handle (pointer) to the pointer array
1260 DPA_DeleteAllPtrs (const HDPA hdpa
)
1262 TRACE (commctrl
, "(%p)\n", hdpa
);
1267 if (hdpa
->ptrs
&& (!HeapFree (hdpa
->hHeap
, 0, hdpa
->ptrs
)))
1270 hdpa
->nItemCount
= 0;
1271 hdpa
->nMaxCount
= hdpa
->nGrow
* 2;
1272 hdpa
->ptrs
= (LPVOID
*)HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
1273 hdpa
->nMaxCount
* sizeof(LPVOID
));
1279 /**************************************************************************
1280 * DPA_QuickSort [Internal]
1282 * Ordinary quicksort (used by DPA_Sort).
1285 * lpPtrs [I] pointer to the pointer array
1286 * l [I] index of the "left border" of the partition
1287 * r [I] index of the "right border" of the partition
1288 * pfnCompare [I] pointer to the compare function
1289 * lParam [I] user defined value (3rd parameter in compare function)
1296 DPA_QuickSort (LPVOID
*lpPtrs
, INT32 l
, INT32 r
,
1297 PFNDPACOMPARE pfnCompare
, LPARAM lParam
)
1302 TRACE (commctrl
, "l=%i r=%i\n", l
, r
);
1306 v
= lpPtrs
[(int)(l
+r
)/2];
1308 while ((pfnCompare
)(lpPtrs
[i
], v
, lParam
) < 0) i
++;
1309 while ((pfnCompare
)(lpPtrs
[j
], v
, lParam
) > 0) j
--;
1313 lpPtrs
[i
++] = lpPtrs
[j
];
1317 if (l
< j
) DPA_QuickSort (lpPtrs
, l
, j
, pfnCompare
, lParam
);
1318 if (i
< r
) DPA_QuickSort (lpPtrs
, i
, r
, pfnCompare
, lParam
);
1322 /**************************************************************************
1323 * DPA_Sort [COMCTL32.338]
1325 * Sorts a pointer array using a user defined compare function
1328 * hdpa [I] handle (pointer) to the pointer array
1329 * pfnCompare [I] pointer to the compare function
1330 * lParam [I] user defined value (3rd parameter of compare function)
1338 DPA_Sort (const HDPA hdpa
, PFNDPACOMPARE pfnCompare
, LPARAM lParam
)
1340 if (!hdpa
|| !pfnCompare
)
1343 TRACE (commctrl
, "(%p %p 0x%lx)\n", hdpa
, pfnCompare
, lParam
);
1345 if ((hdpa
->nItemCount
> 1) && (hdpa
->ptrs
))
1346 DPA_QuickSort (hdpa
->ptrs
, 0, hdpa
->nItemCount
- 1,
1347 pfnCompare
, lParam
);
1353 /**************************************************************************
1354 * DPA_Search [COMCTL32.339]
1356 * Searches a pointer array for a specified pointer
1359 * hdpa [I] handle (pointer) to the pointer array
1360 * pFind [I] pointer to search for
1361 * nStart [I] start index
1362 * pfnCompare [I] pointer to the compare function
1363 * lParam [I] user defined value (3rd parameter of compare function)
1364 * uOptions [I] search options
1367 * Success: index of the pointer in the array.
1371 * Binary search taken from R.Sedgewick "Algorithms in C"!
1372 * Function is NOT tested!
1373 * If something goes wrong, blame HIM not ME! (Eric Kohl)
1377 DPA_Search (const HDPA hdpa
, LPVOID pFind
, INT32 nStart
,
1378 PFNDPACOMPARE pfnCompare
, LPARAM lParam
, UINT32 uOptions
)
1380 if (!hdpa
|| !pfnCompare
|| !pFind
)
1383 TRACE (commctrl
, "(%p %p %d %p 0x%08lx 0x%08x)\n",
1384 hdpa
, pFind
, nStart
, pfnCompare
, lParam
, uOptions
);
1386 if (uOptions
& DPAS_SORTED
) {
1387 /* array is sorted --> use binary search */
1391 TRACE (commctrl
, "binary search\n");
1393 l
= (nStart
== -1) ? 0 : nStart
;
1394 r
= hdpa
->nItemCount
- 1;
1398 n
= (pfnCompare
)(pFind
, lpPtr
[x
], lParam
);
1404 TRACE (commctrl
, "-- ret=%d\n", n
);
1409 if (uOptions
& DPAS_INSERTBEFORE
) {
1410 TRACE (commctrl
, "-- ret=%d\n", r
);
1414 if (uOptions
& DPAS_INSERTAFTER
) {
1415 TRACE (commctrl
, "-- ret=%d\n", l
);
1420 /* array is not sorted --> use linear search */
1424 TRACE (commctrl
, "linear search\n");
1426 nIndex
= (nStart
== -1)? 0 : nStart
;
1428 for (; nIndex
< hdpa
->nItemCount
; nIndex
++) {
1429 if ((pfnCompare
)(pFind
, lpPtr
[nIndex
], lParam
) == 0) {
1430 TRACE (commctrl
, "-- ret=%d\n", nIndex
);
1436 TRACE (commctrl
, "-- not found: ret=-1\n");
1441 /**************************************************************************
1442 * DPA_CreateEx [COMCTL32.340]
1444 * Creates a dynamic pointer array using the specified size and heap.
1447 * nGrow [I] number of items by which the array grows when it is filled
1448 * hHeap [I] handle to the heap where the array is stored
1451 * Success: handle (pointer) to the pointer array.
1456 DPA_CreateEx (INT32 nGrow
, HANDLE32 hHeap
)
1460 TRACE (commctrl
, "(%d 0x%x)\n", nGrow
, hHeap
);
1463 hdpa
= (HDPA
)HeapAlloc (hHeap
, HEAP_ZERO_MEMORY
, sizeof(DPA
));
1465 hdpa
= (HDPA
)COMCTL32_Alloc (sizeof(DPA
));
1468 hdpa
->nGrow
= MIN(8, nGrow
);
1469 hdpa
->hHeap
= hHeap
? hHeap
: COMCTL32_hHeap
;
1470 hdpa
->nMaxCount
= hdpa
->nGrow
* 2;
1472 (LPVOID
*)HeapAlloc (hHeap
, HEAP_ZERO_MEMORY
,
1473 hdpa
->nMaxCount
* sizeof(LPVOID
));
1476 TRACE (commctrl
, "-- %p\n", hdpa
);
1482 /**************************************************************************
1483 * Notification functions
1486 typedef struct tagNOTIFYDATA
1494 } NOTIFYDATA
, *LPNOTIFYDATA
;
1497 /**************************************************************************
1498 * DoNotify [Internal]
1502 DoNotify (LPNOTIFYDATA lpNotify
, UINT32 uCode
, LPNMHDR lpHdr
)
1505 LPNMHDR lpNmh
= NULL
;
1508 TRACE (commctrl
, "(0x%04x 0x%04x %d %p 0x%08lx)\n",
1509 lpNotify
->hwndFrom
, lpNotify
->hwndTo
, uCode
, lpHdr
,
1510 lpNotify
->dwParam5
);
1512 if (!lpNotify
->hwndTo
)
1515 if (lpNotify
->hwndFrom
== -1) {
1517 idFrom
= lpHdr
->idFrom
;
1520 if (lpNotify
->hwndFrom
) {
1521 HWND32 hwndParent
= GetParent32 (lpNotify
->hwndFrom
);
1523 hwndParent
= GetWindow32 (lpNotify
->hwndFrom
, GW_OWNER
);
1525 idFrom
= GetDlgCtrlID32 (lpNotify
->hwndFrom
);
1529 lpNmh
= (lpHdr
) ? lpHdr
: &nmhdr
;
1531 lpNmh
->hwndFrom
= lpNotify
->hwndFrom
;
1532 lpNmh
->idFrom
= idFrom
;
1533 lpNmh
->code
= uCode
;
1536 return SendMessage32A (lpNotify
->hwndTo
, WM_NOTIFY
, idFrom
, (LPARAM
)lpNmh
);
1540 /**************************************************************************
1541 * SendNotify [COMCTL32.341]
1550 * Success: return value from notification
1555 COMCTL32_SendNotify (HWND32 hwndFrom
, HWND32 hwndTo
,
1556 UINT32 uCode
, LPNMHDR lpHdr
)
1560 TRACE (commctrl
, "(0x%04x 0x%04x %d %p)\n",
1561 hwndFrom
, hwndTo
, uCode
, lpHdr
);
1563 notify
.hwndFrom
= hwndFrom
;
1564 notify
.hwndTo
= hwndTo
;
1565 notify
.dwParam5
= 0;
1566 notify
.dwParam6
= 0;
1568 return DoNotify (¬ify
, uCode
, lpHdr
);
1572 /**************************************************************************
1573 * SendNotifyEx [COMCTL32.342]
1583 * Success: return value from notification
1588 COMCTL32_SendNotifyEx (HWND32 hwndTo
, HWND32 hwndFrom
, UINT32 uCode
,
1589 LPNMHDR lpHdr
, DWORD dwParam5
)
1594 TRACE (commctrl
, "(0x%04x 0x%04x %d %p 0x%08lx)\n",
1595 hwndFrom
, hwndTo
, uCode
, lpHdr
, dwParam5
);
1597 hwndNotify
= hwndTo
;
1599 if (IsWindow32 (hwndFrom
)) {
1600 hwndNotify
= GetParent32 (hwndFrom
);
1606 notify
.hwndFrom
= hwndFrom
;
1607 notify
.hwndTo
= hwndNotify
;
1608 notify
.dwParam5
= dwParam5
;
1609 notify
.dwParam6
= 0;
1611 return DoNotify (¬ify
, uCode
, lpHdr
);
1615 /**************************************************************************
1616 * StrChrA [COMCTL32.350]
1621 COMCTL32_StrChrA (LPCSTR lpString
, CHAR cChar
)
1623 return strchr (lpString
, cChar
);
1627 /**************************************************************************
1628 * StrStrIA [COMCTL32.355]
1632 COMCTL32_StrStrIA (LPCSTR lpStr1
, LPCSTR lpStr2
)
1634 INT32 len1
, len2
, i
;
1638 return ((LPSTR
)lpStr1
);
1640 while (lpStr1
[len1
] != 0) ++len1
;
1642 while (lpStr2
[len2
] != 0) ++len2
;
1644 return ((LPSTR
)(lpStr1
+ len1
));
1645 first
= tolower (*lpStr2
);
1646 while (len1
>= len2
) {
1647 if (tolower(*lpStr1
) == first
) {
1648 for (i
= 1; i
< len2
; ++i
)
1649 if (tolower (lpStr1
[i
]) != tolower(lpStr2
[i
]))
1652 return ((LPSTR
)lpStr1
);
1660 /**************************************************************************
1661 * StrToIntA [COMCTL32.357] Converts a string to a signed integer.
1665 COMCTL32_StrToIntA (LPSTR lpString
)
1667 return atoi(lpString
);
1671 /**************************************************************************
1672 * DPA_EnumCallback [COMCTL32.385]
1674 * Enumerates all items in a dynamic pointer array.
1677 * hdpa [I] handle to the dynamic pointer array
1686 DPA_EnumCallback (const HDPA hdpa
, DPAENUMPROC enumProc
, LPARAM lParam
)
1690 TRACE (commctrl
, "(%p %p %08lx)\n", hdpa
, enumProc
, lParam
);
1694 if (hdpa
->nItemCount
<= 0)
1697 for (i
= 0; i
< hdpa
->nItemCount
; i
++) {
1698 if ((enumProc
)(hdpa
->ptrs
[i
], lParam
) == 0)
1706 /**************************************************************************
1707 * DPA_DestroyCallback [COMCTL32.386]
1709 * Enumerates all items in a dynamic pointer array and destroys it.
1712 * hdpa [I] handle to the dynamic pointer array
1722 DPA_DestroyCallback (const HDPA hdpa
, DPAENUMPROC enumProc
, LPARAM lParam
)
1724 TRACE (commctrl
, "(%p %p %08lx)\n", hdpa
, enumProc
, lParam
);
1726 DPA_EnumCallback (hdpa
, enumProc
, lParam
);
1728 return DPA_Destroy (hdpa
);
1732 /**************************************************************************
1733 * DSA_EnumCallback [COMCTL32.387]
1735 * Enumerates all items in a dynamic storage array.
1738 * hdsa [I] handle to the dynamic storage array
1747 DSA_EnumCallback (const HDSA hdsa
, DSAENUMPROC enumProc
, LPARAM lParam
)
1751 TRACE (commctrl
, "(%p %p %08lx)\n", hdsa
, enumProc
, lParam
);
1755 if (hdsa
->nItemCount
<= 0)
1758 for (i
= 0; i
< hdsa
->nItemCount
; i
++) {
1759 LPVOID lpItem
= DSA_GetItemPtr (hdsa
, i
);
1760 if ((enumProc
)(lpItem
, lParam
) == 0)
1768 /**************************************************************************
1769 * DSA_DestroyCallback [COMCTL32.388]
1771 * Enumerates all items in a dynamic storage array and destroys it.
1774 * hdsa [I] handle to the dynamic storage array
1784 DSA_DestroyCallback (const HDSA hdsa
, DSAENUMPROC enumProc
, LPARAM lParam
)
1786 TRACE (commctrl
, "(%p %p %08lx)\n", hdsa
, enumProc
, lParam
);
1788 DSA_EnumCallback (hdsa
, enumProc
, lParam
);
1790 return DSA_Destroy (hdsa
);
1793 /**************************************************************************
1794 * StrCSpnA [COMCTL32.356]
1797 INT32 WINAPI
COMCTL32_StrCSpnA( LPCSTR lpStr
, LPCSTR lpSet
) {
1798 return strcspn(lpStr
, lpSet
);
1801 /**************************************************************************
1802 * StrChrW [COMCTL32.358]
1805 LPWSTR WINAPI
COMCTL32_StrChrW( LPCWSTR lpStart
, WORD wMatch
) {
1806 return CRTDLL_wcschr(lpStart
, wMatch
);
1809 /**************************************************************************
1810 * StrCmpNA [COMCTL32.352]
1813 INT32 WINAPI
COMCTL32_StrCmpNA( LPCSTR lpStr1
, LPCSTR lpStr2
, int nChar
) {
1814 return lstrncmp32A(lpStr1
, lpStr2
, nChar
);
1817 /**************************************************************************
1818 * StrCmpNW [COMCTL32.360]
1821 INT32 WINAPI
COMCTL32_StrCmpNW( LPCWSTR lpStr1
, LPCWSTR lpStr2
, int nChar
) {
1822 return lstrncmp32W(lpStr1
, lpStr2
, nChar
);
1825 /**************************************************************************
1826 * StrRChrA [COMCTL32.351]
1829 LPSTR WINAPI
COMCTL32_StrRChrA( LPCSTR lpStart
, LPCSTR lpEnd
, WORD wMatch
) {
1830 return lstrrchr(lpStart
, lpEnd
, wMatch
);
1833 /**************************************************************************
1834 * StrRChrW [COMCTL32.359]
1837 LPWSTR WINAPI
COMCTL32_StrRChrW( LPCWSTR lpStart
, LPCWSTR lpEnd
, WORD wMatch
) {
1838 return lstrrchrw(lpStart
, lpEnd
, wMatch
);
1841 /**************************************************************************
1842 * StrStrA [COMCTL32.354]
1845 LPSTR WINAPI
COMCTL32_StrStrA( LPCSTR lpFirst
, LPCSTR lpSrch
) {
1846 return strstr(lpFirst
, lpSrch
);
1849 /**************************************************************************
1850 * StrStrW [COMCTL32.362]
1853 LPWSTR WINAPI
COMCTL32_StrStrW( LPCWSTR lpFirst
, LPCWSTR lpSrch
) {
1854 return strstrw(lpFirst
, lpSrch
);
1857 /**************************************************************************
1858 * StrSpnW [COMCTL32.364]
1861 INT32 WINAPI
COMCTL32_StrSpnW( LPWSTR lpStr
, LPWSTR lpSet
) {
1862 LPWSTR lpLoop
= lpStr
;
1865 if ((lpStr
== 0) || (lpSet
== 0)) return 0;
1867 /* while(*lpLoop) { if lpLoop++; } */
1869 for(; (*lpLoop
!= 0); lpLoop
++)
1870 if( CRTDLL_wcschr(lpSet
, *(WORD
*)lpLoop
))
1871 return (INT32
)(lpLoop
-lpStr
);
1873 return (INT32
)(lpLoop
-lpStr
);