2 * Undocumented functions from COMCTL32.DLL
4 * Copyright 1998 Eric Kohl
5 * 1998 Juergen Schmied <j.schmied@metronet.de>
6 * 2000 Eric Kohl for CodeWeavers
9 * All of these functions are UNDOCUMENTED!! And I mean UNDOCUMENTED!!!!
10 * Do NOT rely on names or contents of undocumented structures and types!!!
11 * These functions are used by EXPLORER.EXE, IEXPLORE.EXE and
12 * COMCTL32.DLL (internally).
15 * - Add more functions.
16 * - Write some documentation.
20 #include <stdlib.h> /* atoi */
29 #include "wine/unicode.h"
32 #include "debugtools.h"
34 DEFAULT_DEBUG_CHANNEL(commctrl);
37 extern HANDLE COMCTL32_hHeap; /* handle to the private heap */
40 typedef struct _STREAMDATA
45 } STREAMDATA, *PSTREAMDATA;
47 typedef struct _LOADDATA
51 } LOADDATA, *LPLOADDATA;
53 typedef HRESULT CALLBACK (*DPALOADPROC)(LPLOADDATA,IStream*,LPARAM);
55 INT __cdecl _wtoi(LPWSTR string);
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 * pfnCompare [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)
190 LPVOID *pWork1, *pWork2;
194 TRACE("%p %p %08lx %p %p %08lx)\n",
195 hdpa1, hdpa2, dwFlags, pfnCompare, pfnMerge, lParam);
197 if (IsBadWritePtr (hdpa1, sizeof(DPA)))
200 if (IsBadWritePtr (hdpa2, sizeof(DPA)))
203 if (IsBadCodePtr ((FARPROC)pfnCompare))
206 if (IsBadCodePtr ((FARPROC)pfnMerge))
209 if (dwFlags & DPAM_SORT) {
210 TRACE("sorting dpa's!\n");
211 if (hdpa1->nItemCount > 0)
212 DPA_Sort (hdpa1, pfnCompare, lParam);
213 TRACE ("dpa 1 sorted!\n");
214 if (hdpa2->nItemCount > 0)
215 DPA_Sort (hdpa2, pfnCompare, lParam);
216 TRACE ("dpa 2 sorted!\n");
219 if (hdpa2->nItemCount < 1)
222 TRACE("hdpa1->nItemCount=%d hdpa2->nItemCount=%d\n",
223 hdpa1->nItemCount, hdpa2->nItemCount);
226 /* working but untrusted implementation */
228 pWork1 = &(hdpa1->ptrs[hdpa1->nItemCount - 1]);
229 pWork2 = &(hdpa2->ptrs[hdpa2->nItemCount - 1]);
231 nIndex = hdpa1->nItemCount - 1;
232 nCount = hdpa2->nItemCount - 1;
236 if (nIndex < 0) break;
237 nResult = (pfnCompare)(*pWork1, *pWork2, lParam);
238 TRACE("compare result=%d, dpa1.cnt=%d, dpa2.cnt=%d\n",
239 nResult, nIndex, nCount);
245 ptr = (pfnMerge)(1, *pWork1, *pWork2, lParam);
255 else if (nResult < 0)
261 ptr = DPA_DeletePtr (hdpa1, hdpa1->nItemCount - 1);
263 (pfnMerge)(2, ptr, NULL, lParam);
274 ptr = (pfnMerge)(3, *pWork2, NULL, lParam);
277 DPA_InsertPtr (hdpa1, nIndex, ptr);
290 /**************************************************************************
291 * Alloc [COMCTL32.71]
293 * Allocates memory block from the dll's private heap
296 * dwSize [I] size of the allocated memory block
299 * Success: pointer to allocated memory block
304 COMCTL32_Alloc (DWORD dwSize)
308 TRACE("(0x%lx)\n", dwSize);
310 lpPtr = HeapAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, dwSize);
312 TRACE("-- ret=%p\n", lpPtr);
318 /**************************************************************************
319 * ReAlloc [COMCTL32.72]
321 * Changes the size of an allocated memory block or allocates a memory
322 * block using the dll's private heap.
325 * lpSrc [I] pointer to memory block which will be resized
326 * dwSize [I] new size of the memory block.
329 * Success: pointer to the resized memory block
333 * If lpSrc is a NULL-pointer, then COMCTL32_ReAlloc allocates a memory
334 * block like COMCTL32_Alloc.
338 COMCTL32_ReAlloc (LPVOID lpSrc, DWORD dwSize)
342 TRACE("(%p 0x%08lx)\n", lpSrc, dwSize);
345 lpDest = HeapReAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, lpSrc, dwSize);
347 lpDest = HeapAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, dwSize);
349 TRACE("-- ret=%p\n", lpDest);
355 /**************************************************************************
358 * Frees an allocated memory block from the dll's private heap.
361 * lpMem [I] pointer to memory block which will be freed
369 COMCTL32_Free (LPVOID lpMem)
371 TRACE("(%p)\n", lpMem);
373 return HeapFree (COMCTL32_hHeap, 0, lpMem);
377 /**************************************************************************
378 * GetSize [COMCTL32.74]
380 * Retrieves the size of the specified memory block from the dll's
384 * lpMem [I] pointer to an allocated memory block
387 * Success: size of the specified memory block
392 COMCTL32_GetSize (LPVOID lpMem)
394 TRACE("(%p)\n", lpMem);
396 return HeapSize (COMCTL32_hHeap, 0, lpMem);
400 /**************************************************************************
401 * The MRU-API is a set of functions to manipulate MRU(Most Recently Used)
404 * Stored in the reg. as a set of values under a single key. Each item in the
405 * list has a value name that is a single char. 'a' - 'z', '{', '|' or '}'.
406 * The order of the list is stored with value name 'MRUList' which is a string
407 * containing the value names (i.e. 'a', 'b', etc.) in the relevant order.
410 typedef struct tagCREATEMRULIST
412 DWORD cbSize; /* size of struct */
413 DWORD nMaxItems; /* max no. of items in list */
414 DWORD dwFlags; /* see below */
415 HKEY hKey; /* root reg. key under which list is saved */
416 LPCSTR lpszSubKey; /* reg. subkey */
417 PROC lpfnCompare; /* item compare proc */
418 } CREATEMRULIST, *LPCREATEMRULIST;
421 #define MRUF_STRING_LIST 0 /* list will contain strings */
422 #define MRUF_BINARY_LIST 1 /* list will contain binary data */
423 #define MRUF_DELAYED_SAVE 2 /* only save list order to reg. is FreeMRUList */
425 /* If list is a string list lpfnCompare has the following prototype
426 * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
427 * for binary lists the prototype is
428 * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
429 * where cbData is the no. of bytes to compare.
430 * Need to check what return value means identical - 0?
433 typedef struct tagWINEMRUITEM
435 DWORD size; /* size of data stored */
436 DWORD itemFlag; /* flags */
438 } WINEMRUITEM, *LPWINEMRUITEM;
441 #define WMRUIF_CHANGED 0x0001 /* this dataitem changed */
443 typedef struct tagWINEMRULIST
445 CREATEMRULIST extview; /* original create information */
446 DWORD wineFlags; /* internal flags */
447 DWORD cursize; /* current size of realMRU */
448 LPSTR realMRU; /* pointer to string of index names */
449 LPWINEMRUITEM *array; /* array of pointers to data */
450 /* in 'a' to 'z' order */
451 } WINEMRULIST, *LPWINEMRULIST;
454 #define WMRUF_CHANGED 0x0001 /* MRU list has changed */
457 CreateMRUListLazyA (LPCREATEMRULIST lpcml, DWORD dwParam2,
458 DWORD dwParam3, DWORD dwParam4);
460 /**************************************************************************
461 * MRU_SaveChanged - Localize MRU saving code
464 VOID MRU_SaveChanged( LPWINEMRULIST mp )
471 /* or should we do the following instead of RegOpenKeyEx:
474 /* open the sub key */
475 if ((err = RegOpenKeyExA( mp->extview.hKey, mp->extview.lpszSubKey,
476 0, KEY_WRITE, &newkey))) {
477 /* not present - what to do ??? */
478 ERR("Can not open key, error=%d, attempting to create\n",
480 if ((err = RegCreateKeyExA( mp->extview.hKey, mp->extview.lpszSubKey,
483 REG_OPTION_NON_VOLATILE,
484 KEY_READ | KEY_WRITE,
488 ERR("failed to create key /%s/, err=%d\n",
489 mp->extview.lpszSubKey, err);
493 if (mp->wineFlags & WMRUF_CHANGED) {
494 mp->wineFlags &= ~WMRUF_CHANGED;
495 err = RegSetValueExA(newkey, "MRUList", 0, REG_SZ,
496 mp->realMRU, lstrlenA(mp->realMRU) + 1);
498 ERR("error saving MRUList, err=%d\n", err);
500 TRACE("saving MRUList=/%s/\n", mp->realMRU);
503 for(i=0; i<mp->cursize; i++) {
504 witem = mp->array[i];
505 if (witem->itemFlag & WMRUIF_CHANGED) {
506 witem->itemFlag &= ~WMRUIF_CHANGED;
507 realname[0] = 'a' + i;
508 err = RegSetValueExA(newkey, realname, 0,
509 (mp->extview.dwFlags & MRUF_BINARY_LIST) ?
511 &witem->datastart, witem->size);
513 ERR("error saving /%s/, err=%d\n", realname, err);
515 TRACE("saving value for name /%s/ size=%ld\n",
516 realname, witem->size);
519 RegCloseKey( newkey );
522 /**************************************************************************
523 * CreateMRUListA [COMCTL32.151]
526 * lpcml [I] ptr to CREATEMRULIST structure.
529 * Handle to MRU list.
532 CreateMRUListA (LPCREATEMRULIST lpcml)
534 return CreateMRUListLazyA (lpcml, 0, 0, 0);
537 /**************************************************************************
538 * FreeMRUList [COMCTL32.152]
541 * hMRUList [I] Handle to list.
545 FreeMRUListA (HANDLE hMRUList)
547 LPWINEMRULIST mp = (LPWINEMRULIST)hMRUList;
551 if (mp->wineFlags & WMRUF_CHANGED) {
552 /* need to open key and then save the info */
553 MRU_SaveChanged( mp );
556 for(i=0; i<mp->extview.nMaxItems; i++) {
558 COMCTL32_Free(mp->array[i]);
560 COMCTL32_Free(mp->realMRU);
561 COMCTL32_Free(mp->array);
562 return COMCTL32_Free(mp);
566 /**************************************************************************
567 * FindMRUData [COMCTL32.169]
569 * Searches binary list for item that matches lpData of length cbData.
570 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
571 * corresponding to item's reg. name will be stored in it ('a' -> 0).
574 * hList [I] list handle
575 * lpData [I] data to find
576 * cbData [I] length of data
577 * lpRegNum [O] position in registry (maybe NULL)
580 * Position in list 0 -> MRU. -1 if item not found.
583 FindMRUData (HANDLE hList, LPCVOID lpData, DWORD cbData, LPINT lpRegNum)
585 LPWINEMRULIST mp = (LPWINEMRULIST)hList;
588 if (!mp->extview.lpfnCompare) {
589 ERR("MRU list not properly created. No compare procedure.\n");
593 for(i=0; i<mp->cursize; i++) {
594 if (mp->extview.dwFlags & MRUF_BINARY_LIST) {
595 if (!mp->extview.lpfnCompare(lpData, &mp->array[i]->datastart,
600 if (!mp->extview.lpfnCompare(lpData, &mp->array[i]->datastart))
608 if (lpRegNum && (ret != -1))
611 TRACE("(%08x, %p, %ld, %p) returning %d\n",
612 hList, lpData, cbData, lpRegNum, ret);
618 /**************************************************************************
619 * AddMRUData [COMCTL32.167]
621 * Add item to MRU binary list. If item already exists in list then it is
622 * simply moved up to the top of the list and not added again. If list is
623 * full then the least recently used item is removed to make room.
626 * hList [I] Handle to list.
627 * lpData [I] ptr to data to add.
628 * cbData [I] no. of bytes of data.
631 * No. corresponding to registry name where value is stored 'a' -> 0 etc.
635 AddMRUData (HANDLE hList, LPCVOID lpData, DWORD cbData)
637 LPWINEMRULIST mp = (LPWINEMRULIST)hList;
641 if ((replace = FindMRUData (hList, lpData, cbData, NULL)) < 0) {
642 /* either add a new entry or replace oldest */
643 if (mp->cursize < mp->extview.nMaxItems) {
644 /* Add in a new item */
645 replace = mp->cursize;
649 /* get the oldest entry and replace data */
650 replace = mp->realMRU[mp->cursize - 1] - 'a';
651 COMCTL32_Free(mp->array[replace]);
655 /* free up the old data */
656 COMCTL32_Free(mp->array[replace]);
659 /* Allocate space for new item and move in the data */
660 mp->array[replace] = witem = (LPWINEMRUITEM)COMCTL32_Alloc(cbData +
661 sizeof(WINEMRUITEM));
662 witem->itemFlag |= WMRUIF_CHANGED;
663 witem->size = cbData;
664 memcpy( &witem->datastart, lpData, cbData);
666 /* now rotate MRU list */
667 mp->wineFlags |= WMRUF_CHANGED;
668 for(i=mp->cursize-1; i>=1; i--) {
669 mp->realMRU[i] = mp->realMRU[i-1];
671 mp->realMRU[0] = replace + 'a';
672 TRACE("(%08x, %p, %ld) adding data, /%c/ now most current\n",
673 hList, lpData, cbData, replace+'a');
676 if (!(mp->extview.dwFlags & MRUF_DELAYED_SAVE)) {
677 /* save changed stuff right now */
678 MRU_SaveChanged( mp );
684 /**************************************************************************
685 * AddMRUStringA [COMCTL32.153]
687 * Add item to MRU string list. If item already exists in list them it is
688 * simply moved up to the top of the list and not added again. If list is
689 * full then the least recently used item is removed to make room.
692 * hList [I] Handle to list.
693 * lpszString [I] ptr to string to add.
696 * No. corresponding to registry name where value is stored 'a' -> 0 etc.
700 AddMRUStringA(HANDLE hList, LPCSTR lpszString)
702 FIXME("(%08x, %s) empty stub!\n", hList, debugstr_a(lpszString));
707 /**************************************************************************
708 * DelMRUString [COMCTL32.156]
710 * Removes item from either string or binary list (despite its name)
713 * hList [I] list handle
714 * nItemPos [I] item position to remove 0 -> MRU
717 * TRUE if successful, FALSE if nItemPos is out of range.
720 DelMRUString(HANDLE hList, INT nItemPos)
722 FIXME("(%08x, %d): stub\n", hList, nItemPos);
726 /**************************************************************************
727 * FindMRUStringA [COMCTL32.155]
729 * Searches string list for item that matches lpszString.
730 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
731 * corresponding to item's reg. name will be stored in it ('a' -> 0).
734 * hList [I] list handle
735 * lpszString [I] string to find
736 * lpRegNum [O] position in registry (maybe NULL)
739 * Position in list 0 -> MRU. -1 if item not found.
742 FindMRUStringA (HANDLE hList, LPCSTR lpszString, LPINT lpRegNum)
744 return FindMRUData(hList, (LPVOID)lpszString, lstrlenA(lpszString),
748 /**************************************************************************
749 * CreateMRUListLazyA [COMCTL32.157]
752 CreateMRUListLazyA (LPCREATEMRULIST lpcml, DWORD dwParam2, DWORD dwParam3, DWORD dwParam4)
757 DWORD datasize, dwdisp;
765 if (lpcml->cbSize < sizeof(CREATEMRULIST))
768 mp = (LPWINEMRULIST) COMCTL32_Alloc(sizeof(WINEMRULIST));
769 memcpy(mp, lpcml, sizeof(CREATEMRULIST));
771 /* get space to save indexes that will turn into names
772 * but in order of most to least recently used
774 mp->realMRU = (LPSTR) COMCTL32_Alloc(mp->extview.nMaxItems + 2);
776 /* get space to save pointers to actual data in order of
777 * 'a' to 'z' (0 to n).
779 mp->array = (LPVOID) COMCTL32_Alloc(mp->extview.nMaxItems *
782 /* open the sub key */
783 if ((err = RegCreateKeyExA( mp->extview.hKey, mp->extview.lpszSubKey,
786 REG_OPTION_NON_VOLATILE,
787 KEY_READ | KEY_WRITE,
791 /* error - what to do ??? */
792 ERR("(%lu %lu %lx %lx \"%s\" %p): Can not open key, error=%d\n",
793 lpcml->cbSize, lpcml->nMaxItems, lpcml->dwFlags,
794 (DWORD)lpcml->hKey, lpcml->lpszSubKey, lpcml->lpfnCompare,
799 /* get values from key 'MRUList' */
801 datasize = mp->extview.nMaxItems + 1;
802 if((err=RegQueryValueExA( newkey, "MRUList", 0, &type, mp->realMRU,
804 /* not present - set size to 1 (will become 0 later) */
809 TRACE("MRU list = %s\n", mp->realMRU);
811 mp->cursize = datasize - 1;
812 /* datasize now has number of items in the MRUList */
814 /* get actual values for each entry */
816 for(i=0; i<mp->cursize; i++) {
817 realname[0] = 'a' + i;
818 if(RegQueryValueExA( newkey, realname, 0, &type, 0, &datasize)) {
819 /* not present - what to do ??? */
820 ERR("Key %s not found 1\n", realname);
822 mp->array[i] = witem = (LPWINEMRUITEM)COMCTL32_Alloc(datasize +
823 sizeof(WINEMRUITEM));
824 witem->size = datasize;
825 if(RegQueryValueExA( newkey, realname, 0, &type,
826 &witem->datastart, &datasize)) {
827 /* not present - what to do ??? */
828 ERR("Key %s not found 2\n", realname);
831 RegCloseKey( newkey );
836 TRACE("(%lu %lu %lx %lx \"%s\" %p): Current Size = %ld\n",
837 lpcml->cbSize, lpcml->nMaxItems, lpcml->dwFlags,
838 (DWORD)lpcml->hKey, lpcml->lpszSubKey, lpcml->lpfnCompare,
844 /**************************************************************************
845 * EnumMRUListA [COMCTL32.154]
847 * Enumerate item in a list
850 * hList [I] list handle
851 * nItemPos [I] item position to enumerate
852 * lpBuffer [O] buffer to receive item
853 * nBufferSize [I] size of buffer
856 * For binary lists specifies how many bytes were copied to buffer, for
857 * string lists specifies full length of string. Enumerating past the end
858 * of list returns -1.
859 * If lpBuffer == NULL or nItemPos is -ve return value is no. of items in
862 INT WINAPI EnumMRUListA(HANDLE hList, INT nItemPos, LPVOID lpBuffer,
865 LPWINEMRULIST mp = (LPWINEMRULIST) hList;
867 INT desired, datasize;
869 if (nItemPos >= mp->cursize) return -1;
870 if ((nItemPos < 0) || !lpBuffer) return mp->cursize;
871 desired = mp->realMRU[nItemPos];
873 TRACE("nItemPos=%d, desired=%d\n", nItemPos, desired);
874 witem = mp->array[desired];
875 datasize = min( witem->size, nBufferSize );
876 memcpy( lpBuffer, &witem->datastart, datasize);
877 TRACE("(%08x, %d, %p, %ld): returning len=%d\n",
878 hList, nItemPos, lpBuffer, nBufferSize, datasize);
882 /**************************************************************************
883 * Str_GetPtrA [COMCTL32.233]
894 Str_GetPtrA (LPCSTR lpSrc, LPSTR lpDest, INT nMaxLen)
898 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
900 if (!lpDest && lpSrc)
901 return strlen (lpSrc);
911 len = strlen (lpSrc);
915 RtlMoveMemory (lpDest, lpSrc, len);
922 /**************************************************************************
923 * Str_SetPtrA [COMCTL32.234]
933 Str_SetPtrA (LPSTR *lppDest, LPCSTR lpSrc)
935 TRACE("(%p %p)\n", lppDest, lpSrc);
938 LPSTR ptr = COMCTL32_ReAlloc (*lppDest, strlen (lpSrc) + 1);
946 COMCTL32_Free (*lppDest);
955 /**************************************************************************
956 * Str_GetPtrW [COMCTL32.235]
967 Str_GetPtrW (LPCWSTR lpSrc, LPWSTR lpDest, INT nMaxLen)
971 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
973 if (!lpDest && lpSrc)
974 return strlenW (lpSrc);
984 len = strlenW (lpSrc);
988 RtlMoveMemory (lpDest, lpSrc, len*sizeof(WCHAR));
995 /**************************************************************************
996 * Str_SetPtrW [COMCTL32.236]
1006 Str_SetPtrW (LPWSTR *lppDest, LPCWSTR lpSrc)
1008 TRACE("(%p %p)\n", lppDest, lpSrc);
1011 INT len = strlenW (lpSrc) + 1;
1012 LPWSTR ptr = COMCTL32_ReAlloc (*lppDest, len * sizeof(WCHAR));
1015 strcpyW (ptr, lpSrc);
1020 COMCTL32_Free (*lppDest);
1029 /**************************************************************************
1030 * Str_GetPtrWtoA [internal]
1032 * Converts a unicode string into a multi byte string
1035 * lpSrc [I] Pointer to the unicode source string
1036 * lpDest [O] Pointer to caller supplied storage for the multi byte string
1037 * nMaxLen [I] Size, in bytes, of the destination buffer
1040 * Length, in bytes, of the converted string.
1044 Str_GetPtrWtoA (LPCWSTR lpSrc, LPSTR lpDest, INT nMaxLen)
1048 TRACE("(%s %p %d)\n", debugstr_w(lpSrc), lpDest, nMaxLen);
1050 if (!lpDest && lpSrc)
1051 return WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, 0, 0, NULL, NULL);
1056 if (lpSrc == NULL) {
1061 len = WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, 0, 0, NULL, NULL);
1065 WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, lpDest, len, NULL, NULL);
1072 /**************************************************************************
1073 * Str_SetPtrAtoW [internal]
1075 * Converts a multi byte string to a unicode string.
1076 * If the pointer to the destination buffer is NULL a buffer is allocated.
1077 * If the destination buffer is too small to keep the converted multi byte
1078 * string the destination buffer is reallocated. If the source pointer is
1079 * NULL, the destination buffer is freed.
1082 * lppDest [I/O] pointer to a pointer to the destination buffer
1083 * lpSrc [I] pointer to a multi byte string
1086 * TRUE: conversion successful
1091 Str_SetPtrAtoW (LPWSTR *lppDest, LPCSTR lpSrc)
1093 TRACE("(%p %s)\n", lppDest, lpSrc);
1096 INT len = MultiByteToWideChar(CP_ACP,0,lpSrc,-1,NULL,0);
1097 LPWSTR ptr = COMCTL32_ReAlloc (*lppDest, len*sizeof(WCHAR));
1101 MultiByteToWideChar(CP_ACP,0,lpSrc,-1,ptr,len);
1106 COMCTL32_Free (*lppDest);
1115 /**************************************************************************
1116 * The DSA-API is a set of functions to create and manipulate arrays of
1117 * fixed-size memory blocks. These arrays can store any kind of data
1118 * (strings, icons...).
1121 /**************************************************************************
1122 * DSA_Create [COMCTL32.320] Creates a dynamic storage array
1125 * nSize [I] size of the array elements
1126 * nGrow [I] number of elements by which the array grows when it is filled
1129 * Success: pointer to an array control structure. Use this like a handle.
1134 DSA_Create (INT nSize, INT nGrow)
1138 TRACE("(size=%d grow=%d)\n", nSize, nGrow);
1140 hdsa = (HDSA)COMCTL32_Alloc (sizeof(DSA));
1143 hdsa->nItemCount = 0;
1145 hdsa->nMaxCount = 0;
1146 hdsa->nItemSize = nSize;
1147 hdsa->nGrow = max(1, nGrow);
1154 /**************************************************************************
1155 * DSA_Destroy [COMCTL32.321] Destroys a dynamic storage array
1158 * hdsa [I] pointer to the array control structure
1166 DSA_Destroy (const HDSA hdsa)
1168 TRACE("(%p)\n", hdsa);
1173 if (hdsa->pData && (!COMCTL32_Free (hdsa->pData)))
1176 return COMCTL32_Free (hdsa);
1180 /**************************************************************************
1181 * DSA_GetItem [COMCTL32.322]
1184 * hdsa [I] pointer to the array control structure
1185 * nIndex [I] number of the Item to get
1186 * pDest [O] destination buffer. Has to be >= dwElementSize.
1194 DSA_GetItem (const HDSA hdsa, INT nIndex, LPVOID pDest)
1198 TRACE("(%p %d %p)\n", hdsa, nIndex, pDest);
1202 if ((nIndex < 0) || (nIndex >= hdsa->nItemCount))
1205 pSrc = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1206 memmove (pDest, pSrc, hdsa->nItemSize);
1212 /**************************************************************************
1213 * DSA_GetItemPtr [COMCTL32.323]
1215 * Retrieves a pointer to the specified item.
1218 * hdsa [I] pointer to the array control structure
1219 * nIndex [I] index of the desired item
1222 * Success: pointer to an item
1227 DSA_GetItemPtr (const HDSA hdsa, INT nIndex)
1231 TRACE("(%p %d)\n", hdsa, nIndex);
1235 if ((nIndex < 0) || (nIndex >= hdsa->nItemCount))
1238 pSrc = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1240 TRACE("-- ret=%p\n", pSrc);
1246 /**************************************************************************
1247 * DSA_SetItem [COMCTL32.325]
1249 * Sets the contents of an item in the array.
1252 * hdsa [I] pointer to the array control structure
1253 * nIndex [I] index for the item
1254 * pSrc [I] pointer to the new item data
1262 DSA_SetItem (const HDSA hdsa, INT nIndex, LPVOID pSrc)
1264 INT nSize, nNewItems;
1265 LPVOID pDest, lpTemp;
1267 TRACE("(%p %d %p)\n", hdsa, nIndex, pSrc);
1269 if ((!hdsa) || nIndex < 0)
1272 if (hdsa->nItemCount <= nIndex) {
1273 /* within the old array */
1274 if (hdsa->nMaxCount > nIndex) {
1275 /* within the allocated space, set a new boundary */
1276 hdsa->nItemCount = nIndex + 1;
1279 /* resize the block of memory */
1281 hdsa->nGrow * ((INT)(((nIndex + 1) - 1) / hdsa->nGrow) + 1);
1282 nSize = hdsa->nItemSize * nNewItems;
1284 lpTemp = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
1288 hdsa->nMaxCount = nNewItems;
1289 hdsa->nItemCount = nIndex + 1;
1290 hdsa->pData = lpTemp;
1294 /* put the new entry in */
1295 pDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1296 TRACE("-- move dest=%p src=%p size=%d\n",
1297 pDest, pSrc, hdsa->nItemSize);
1298 memmove (pDest, pSrc, hdsa->nItemSize);
1304 /**************************************************************************
1305 * DSA_InsertItem [COMCTL32.324]
1308 * hdsa [I] pointer to the array control structure
1309 * nIndex [I] index for the new item
1310 * pSrc [I] pointer to the element
1313 * Success: position of the new item
1318 DSA_InsertItem (const HDSA hdsa, INT nIndex, LPVOID pSrc)
1320 INT nNewItems, nSize, i;
1321 LPVOID lpTemp, lpDest;
1324 TRACE("(%p %d %p)\n", hdsa, nIndex, pSrc);
1326 if ((!hdsa) || nIndex < 0)
1329 for (i = 0; i < hdsa->nItemSize; i += 4) {
1330 p = *(DWORD**)((char *) pSrc + i);
1331 if (IsBadStringPtrA ((char*)p, 256))
1332 TRACE("-- %d=%p\n", i, (DWORD*)p);
1334 TRACE("-- %d=%p [%s]\n", i, p, debugstr_a((char*)p));
1337 /* when nIndex >= nItemCount then append */
1338 if (nIndex >= hdsa->nItemCount)
1339 nIndex = hdsa->nItemCount;
1341 /* do we need to resize ? */
1342 if (hdsa->nItemCount >= hdsa->nMaxCount) {
1343 nNewItems = hdsa->nMaxCount + hdsa->nGrow;
1344 nSize = hdsa->nItemSize * nNewItems;
1346 lpTemp = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
1350 hdsa->nMaxCount = nNewItems;
1351 hdsa->pData = lpTemp;
1354 /* do we need to move elements ? */
1355 if (nIndex < hdsa->nItemCount) {
1356 lpTemp = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1357 lpDest = (char *) lpTemp + hdsa->nItemSize;
1358 nSize = (hdsa->nItemCount - nIndex) * hdsa->nItemSize;
1359 TRACE("-- move dest=%p src=%p size=%d\n",
1360 lpDest, lpTemp, nSize);
1361 memmove (lpDest, lpTemp, nSize);
1364 /* ok, we can put the new Item in */
1366 lpDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1367 TRACE("-- move dest=%p src=%p size=%d\n",
1368 lpDest, pSrc, hdsa->nItemSize);
1369 memmove (lpDest, pSrc, hdsa->nItemSize);
1375 /**************************************************************************
1376 * DSA_DeleteItem [COMCTL32.326]
1379 * hdsa [I] pointer to the array control structure
1380 * nIndex [I] index for the element to delete
1383 * Success: number of the deleted element
1388 DSA_DeleteItem (const HDSA hdsa, INT nIndex)
1390 LPVOID lpDest,lpSrc;
1393 TRACE("(%p %d)\n", hdsa, nIndex);
1397 if (nIndex < 0 || nIndex >= hdsa->nItemCount)
1400 /* do we need to move ? */
1401 if (nIndex < hdsa->nItemCount - 1) {
1402 lpDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1403 lpSrc = (char *) lpDest + hdsa->nItemSize;
1404 nSize = hdsa->nItemSize * (hdsa->nItemCount - nIndex - 1);
1405 TRACE("-- move dest=%p src=%p size=%d\n",
1406 lpDest, lpSrc, nSize);
1407 memmove (lpDest, lpSrc, nSize);
1413 if ((hdsa->nMaxCount - hdsa->nItemCount) >= hdsa->nGrow) {
1414 nSize = hdsa->nItemSize * hdsa->nItemCount;
1416 lpDest = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
1420 hdsa->nMaxCount = hdsa->nItemCount;
1421 hdsa->pData = lpDest;
1428 /**************************************************************************
1429 * DSA_DeleteAllItems [COMCTL32.327]
1431 * Removes all items and reinitializes the array.
1434 * hdsa [I] pointer to the array control structure
1442 DSA_DeleteAllItems (const HDSA hdsa)
1444 TRACE("(%p)\n", hdsa);
1448 if (hdsa->pData && (!COMCTL32_Free (hdsa->pData)))
1451 hdsa->nItemCount = 0;
1453 hdsa->nMaxCount = 0;
1459 /**************************************************************************
1460 * The DPA-API is a set of functions to create and manipulate arrays of
1464 /**************************************************************************
1465 * DPA_Create [COMCTL32.328] Creates a dynamic pointer array
1468 * nGrow [I] number of items by which the array grows when it is filled
1471 * Success: handle (pointer) to the pointer array.
1476 DPA_Create (INT nGrow)
1480 TRACE("(%d)\n", nGrow);
1482 hdpa = (HDPA)COMCTL32_Alloc (sizeof(DPA));
1484 hdpa->nGrow = max(8, nGrow);
1485 hdpa->hHeap = COMCTL32_hHeap;
1486 hdpa->nMaxCount = hdpa->nGrow * 2;
1488 (LPVOID*)COMCTL32_Alloc (hdpa->nMaxCount * sizeof(LPVOID));
1491 TRACE("-- %p\n", hdpa);
1497 /**************************************************************************
1498 * DPA_Destroy [COMCTL32.329] Destroys a dynamic pointer array
1501 * hdpa [I] handle (pointer) to the pointer array
1509 DPA_Destroy (const HDPA hdpa)
1511 TRACE("(%p)\n", hdpa);
1516 if (hdpa->ptrs && (!HeapFree (hdpa->hHeap, 0, hdpa->ptrs)))
1519 return HeapFree (hdpa->hHeap, 0, hdpa);
1523 /**************************************************************************
1524 * DPA_Grow [COMCTL32.330]
1526 * Sets the growth amount.
1529 * hdpa [I] handle (pointer) to the existing (source) pointer array
1530 * nGrow [I] number of items by which the array grows when it's too small
1538 DPA_Grow (const HDPA hdpa, INT nGrow)
1540 TRACE("(%p %d)\n", hdpa, nGrow);
1545 hdpa->nGrow = max(8, nGrow);
1551 /**************************************************************************
1552 * DPA_Clone [COMCTL32.331]
1554 * Copies a pointer array to an other one or creates a copy
1557 * hdpa [I] handle (pointer) to the existing (source) pointer array
1558 * hdpaNew [O] handle (pointer) to the destination pointer array
1561 * Success: pointer to the destination pointer array.
1565 * - If the 'hdpaNew' is a NULL-Pointer, a copy of the source pointer
1566 * array will be created and it's handle (pointer) is returned.
1567 * - If 'hdpa' is a NULL-Pointer, the original implementation crashes,
1568 * this implementation just returns NULL.
1572 DPA_Clone (const HDPA hdpa, const HDPA hdpaNew)
1574 INT nNewItems, nSize;
1580 TRACE("(%p %p)\n", hdpa, hdpaNew);
1583 /* create a new DPA */
1584 hdpaTemp = (HDPA)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1586 hdpaTemp->hHeap = hdpa->hHeap;
1587 hdpaTemp->nGrow = hdpa->nGrow;
1592 if (hdpaTemp->ptrs) {
1593 /* remove old pointer array */
1594 HeapFree (hdpaTemp->hHeap, 0, hdpaTemp->ptrs);
1595 hdpaTemp->ptrs = NULL;
1596 hdpaTemp->nItemCount = 0;
1597 hdpaTemp->nMaxCount = 0;
1600 /* create a new pointer array */
1601 nNewItems = hdpaTemp->nGrow *
1602 ((INT)((hdpa->nItemCount - 1) / hdpaTemp->nGrow) + 1);
1603 nSize = nNewItems * sizeof(LPVOID);
1605 (LPVOID*)HeapAlloc (hdpaTemp->hHeap, HEAP_ZERO_MEMORY, nSize);
1606 hdpaTemp->nMaxCount = nNewItems;
1608 /* clone the pointer array */
1609 hdpaTemp->nItemCount = hdpa->nItemCount;
1610 memmove (hdpaTemp->ptrs, hdpa->ptrs,
1611 hdpaTemp->nItemCount * sizeof(LPVOID));
1617 /**************************************************************************
1618 * DPA_GetPtr [COMCTL32.332]
1620 * Retrieves a pointer from a dynamic pointer array
1623 * hdpa [I] handle (pointer) to the pointer array
1624 * nIndex [I] array index of the desired pointer
1632 DPA_GetPtr (const HDPA hdpa, INT i)
1634 TRACE("(%p %d)\n", hdpa, i);
1639 WARN("no pointer array.\n");
1642 if ((i < 0) || (i >= hdpa->nItemCount)) {
1643 WARN("not enough pointers in array (%d vs %d).\n",i,hdpa->nItemCount);
1647 TRACE("-- %p\n", hdpa->ptrs[i]);
1649 return hdpa->ptrs[i];
1653 /**************************************************************************
1654 * DPA_GetPtrIndex [COMCTL32.333]
1656 * Retrieves the index of the specified pointer
1659 * hdpa [I] handle (pointer) to the pointer array
1663 * Success: index of the specified pointer
1668 DPA_GetPtrIndex (const HDPA hdpa, LPVOID p)
1675 for (i = 0; i < hdpa->nItemCount; i++) {
1676 if (hdpa->ptrs[i] == p)
1684 /**************************************************************************
1685 * DPA_InsertPtr [COMCTL32.334]
1687 * Inserts a pointer into a dynamic pointer array
1690 * hdpa [I] handle (pointer) to the array
1692 * p [I] pointer to insert
1695 * Success: index of the inserted pointer
1700 DPA_InsertPtr (const HDPA hdpa, INT i, LPVOID p)
1702 INT nNewItems, nSize, nIndex = 0;
1703 LPVOID *lpTemp, *lpDest;
1705 TRACE("(%p %d %p)\n", hdpa, i, p);
1707 if ((!hdpa) || (i < 0))
1712 (LPVOID*)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1713 2 * hdpa->nGrow * sizeof(LPVOID));
1716 hdpa->nMaxCount = hdpa->nGrow * 2;
1720 if (hdpa->nItemCount >= hdpa->nMaxCount) {
1721 TRACE("-- resizing\n");
1722 nNewItems = hdpa->nMaxCount + hdpa->nGrow;
1723 nSize = nNewItems * sizeof(LPVOID);
1725 lpTemp = (LPVOID*)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1729 hdpa->nMaxCount = nNewItems;
1730 hdpa->ptrs = lpTemp;
1733 if (i >= hdpa->nItemCount) {
1734 nIndex = hdpa->nItemCount;
1735 TRACE("-- appending at %d\n", nIndex);
1738 TRACE("-- inserting at %d\n", i);
1739 lpTemp = hdpa->ptrs + i;
1740 lpDest = lpTemp + 1;
1741 nSize = (hdpa->nItemCount - i) * sizeof(LPVOID);
1742 TRACE("-- move dest=%p src=%p size=%x\n",
1743 lpDest, lpTemp, nSize);
1744 memmove (lpDest, lpTemp, nSize);
1751 hdpa->ptrs[nIndex] = p;
1757 /**************************************************************************
1758 * DPA_SetPtr [COMCTL32.335]
1760 * Sets a pointer in the pointer array
1763 * hdpa [I] handle (pointer) to the pointer array
1764 * i [I] index of the pointer that will be set
1765 * p [I] pointer to be set
1773 DPA_SetPtr (const HDPA hdpa, INT i, LPVOID p)
1777 TRACE("(%p %d %p)\n", hdpa, i, p);
1779 if ((!hdpa) || i < 0)
1782 if (hdpa->nItemCount <= i) {
1783 /* within the old array */
1784 if (hdpa->nMaxCount > i) {
1785 /* within the allocated space, set a new boundary */
1786 hdpa->nItemCount = i+1;
1789 /* resize the block of memory */
1791 hdpa->nGrow * ((INT)(((i+1) - 1) / hdpa->nGrow) + 1);
1792 INT nSize = nNewItems * sizeof(LPVOID);
1794 lpTemp = (LPVOID*)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1799 hdpa->nItemCount = nNewItems;
1800 hdpa->ptrs = lpTemp;
1804 /* put the new entry in */
1811 /**************************************************************************
1812 * DPA_DeletePtr [COMCTL32.336]
1814 * Removes a pointer from the pointer array.
1817 * hdpa [I] handle (pointer) to the pointer array
1818 * i [I] index of the pointer that will be deleted
1821 * Success: deleted pointer
1826 DPA_DeletePtr (const HDPA hdpa, INT i)
1828 LPVOID *lpDest, *lpSrc, lpTemp = NULL;
1831 TRACE("(%p %d)\n", hdpa, i);
1833 if ((!hdpa) || i < 0 || i >= hdpa->nItemCount)
1836 lpTemp = hdpa->ptrs[i];
1838 /* do we need to move ?*/
1839 if (i < hdpa->nItemCount - 1) {
1840 lpDest = hdpa->ptrs + i;
1842 nSize = (hdpa->nItemCount - i - 1) * sizeof(LPVOID);
1843 TRACE("-- move dest=%p src=%p size=%x\n",
1844 lpDest, lpSrc, nSize);
1845 memmove (lpDest, lpSrc, nSize);
1848 hdpa->nItemCount --;
1851 if ((hdpa->nMaxCount - hdpa->nItemCount) >= hdpa->nGrow) {
1852 INT nNewItems = max(hdpa->nGrow * 2, hdpa->nItemCount);
1853 nSize = nNewItems * sizeof(LPVOID);
1854 lpDest = (LPVOID)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1859 hdpa->nMaxCount = nNewItems;
1860 hdpa->ptrs = (LPVOID*)lpDest;
1867 /**************************************************************************
1868 * DPA_DeleteAllPtrs [COMCTL32.337]
1870 * Removes all pointers and reinitializes the array.
1873 * hdpa [I] handle (pointer) to the pointer array
1881 DPA_DeleteAllPtrs (const HDPA hdpa)
1883 TRACE("(%p)\n", hdpa);
1888 if (hdpa->ptrs && (!HeapFree (hdpa->hHeap, 0, hdpa->ptrs)))
1891 hdpa->nItemCount = 0;
1892 hdpa->nMaxCount = hdpa->nGrow * 2;
1893 hdpa->ptrs = (LPVOID*)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1894 hdpa->nMaxCount * sizeof(LPVOID));
1900 /**************************************************************************
1901 * DPA_QuickSort [Internal]
1903 * Ordinary quicksort (used by DPA_Sort).
1906 * lpPtrs [I] pointer to the pointer array
1907 * l [I] index of the "left border" of the partition
1908 * r [I] index of the "right border" of the partition
1909 * pfnCompare [I] pointer to the compare function
1910 * lParam [I] user defined value (3rd parameter in compare function)
1917 DPA_QuickSort (LPVOID *lpPtrs, INT l, INT r,
1918 PFNDPACOMPARE pfnCompare, LPARAM lParam)
1923 TRACE("l=%i r=%i\n", l, r);
1925 if (l==r) /* one element is always sorted */
1927 if (r<l) /* oops, got it in the wrong order */
1929 DPA_QuickSort(lpPtrs, r, l, pfnCompare, lParam);
1932 m = (l+r)/2; /* divide by two */
1933 DPA_QuickSort(lpPtrs, l, m, pfnCompare, lParam);
1934 DPA_QuickSort(lpPtrs, m+1, r, pfnCompare, lParam);
1936 /* join the two sides */
1937 while( (l<=m) && (m<r) )
1939 if(pfnCompare(lpPtrs[l],lpPtrs[m+1],lParam)>0)
1942 memmove(&lpPtrs[l+1],&lpPtrs[l],(m-l+1)*sizeof lpPtrs[l]);
1952 /**************************************************************************
1953 * DPA_Sort [COMCTL32.338]
1955 * Sorts a pointer array using a user defined compare function
1958 * hdpa [I] handle (pointer) to the pointer array
1959 * pfnCompare [I] pointer to the compare function
1960 * lParam [I] user defined value (3rd parameter of compare function)
1968 DPA_Sort (const HDPA hdpa, PFNDPACOMPARE pfnCompare, LPARAM lParam)
1970 if (!hdpa || !pfnCompare)
1973 TRACE("(%p %p 0x%lx)\n", hdpa, pfnCompare, lParam);
1975 if ((hdpa->nItemCount > 1) && (hdpa->ptrs))
1976 DPA_QuickSort (hdpa->ptrs, 0, hdpa->nItemCount - 1,
1977 pfnCompare, lParam);
1983 /**************************************************************************
1984 * DPA_Search [COMCTL32.339]
1986 * Searches a pointer array for a specified pointer
1989 * hdpa [I] handle (pointer) to the pointer array
1990 * pFind [I] pointer to search for
1991 * nStart [I] start index
1992 * pfnCompare [I] pointer to the compare function
1993 * lParam [I] user defined value (3rd parameter of compare function)
1994 * uOptions [I] search options
1997 * Success: index of the pointer in the array.
2001 * Binary search taken from R.Sedgewick "Algorithms in C"!
2002 * Function is NOT tested!
2003 * If something goes wrong, blame HIM not ME! (Eric Kohl)
2007 DPA_Search (const HDPA hdpa, LPVOID pFind, INT nStart,
2008 PFNDPACOMPARE pfnCompare, LPARAM lParam, UINT uOptions)
2010 if (!hdpa || !pfnCompare || !pFind)
2013 TRACE("(%p %p %d %p 0x%08lx 0x%08x)\n",
2014 hdpa, pFind, nStart, pfnCompare, lParam, uOptions);
2016 if (uOptions & DPAS_SORTED) {
2017 /* array is sorted --> use binary search */
2021 TRACE("binary search\n");
2023 l = (nStart == -1) ? 0 : nStart;
2024 r = hdpa->nItemCount - 1;
2028 n = (pfnCompare)(pFind, lpPtr[x], lParam);
2034 TRACE("-- ret=%d\n", n);
2039 if (uOptions & DPAS_INSERTBEFORE) {
2040 TRACE("-- ret=%d\n", r);
2044 if (uOptions & DPAS_INSERTAFTER) {
2045 TRACE("-- ret=%d\n", l);
2050 /* array is not sorted --> use linear search */
2054 TRACE("linear search\n");
2056 nIndex = (nStart == -1)? 0 : nStart;
2058 for (; nIndex < hdpa->nItemCount; nIndex++) {
2059 if ((pfnCompare)(pFind, lpPtr[nIndex], lParam) == 0) {
2060 TRACE("-- ret=%d\n", nIndex);
2066 TRACE("-- not found: ret=-1\n");
2071 /**************************************************************************
2072 * DPA_CreateEx [COMCTL32.340]
2074 * Creates a dynamic pointer array using the specified size and heap.
2077 * nGrow [I] number of items by which the array grows when it is filled
2078 * hHeap [I] handle to the heap where the array is stored
2081 * Success: handle (pointer) to the pointer array.
2086 DPA_CreateEx (INT nGrow, HANDLE hHeap)
2090 TRACE("(%d 0x%x)\n", nGrow, hHeap);
2093 hdpa = (HDPA)HeapAlloc (hHeap, HEAP_ZERO_MEMORY, sizeof(DPA));
2095 hdpa = (HDPA)COMCTL32_Alloc (sizeof(DPA));
2098 hdpa->nGrow = min(8, nGrow);
2099 hdpa->hHeap = hHeap ? hHeap : COMCTL32_hHeap;
2100 hdpa->nMaxCount = hdpa->nGrow * 2;
2102 (LPVOID*)HeapAlloc (hHeap, HEAP_ZERO_MEMORY,
2103 hdpa->nMaxCount * sizeof(LPVOID));
2106 TRACE("-- %p\n", hdpa);
2112 /**************************************************************************
2113 * Notification functions
2116 typedef struct tagNOTIFYDATA
2124 } NOTIFYDATA, *LPNOTIFYDATA;
2127 /**************************************************************************
2128 * DoNotify [Internal]
2132 DoNotify (LPNOTIFYDATA lpNotify, UINT uCode, LPNMHDR lpHdr)
2135 LPNMHDR lpNmh = NULL;
2138 TRACE("(0x%04x 0x%04x %d %p 0x%08lx)\n",
2139 lpNotify->hwndFrom, lpNotify->hwndTo, uCode, lpHdr,
2140 lpNotify->dwParam5);
2142 if (!lpNotify->hwndTo)
2145 if (lpNotify->hwndFrom == -1) {
2147 idFrom = lpHdr->idFrom;
2150 if (lpNotify->hwndFrom) {
2151 HWND hwndParent = GetParent (lpNotify->hwndFrom);
2153 hwndParent = GetWindow (lpNotify->hwndFrom, GW_OWNER);
2155 idFrom = GetDlgCtrlID (lpNotify->hwndFrom);
2159 lpNmh = (lpHdr) ? lpHdr : &nmhdr;
2161 lpNmh->hwndFrom = lpNotify->hwndFrom;
2162 lpNmh->idFrom = idFrom;
2163 lpNmh->code = uCode;
2166 return SendMessageA (lpNotify->hwndTo, WM_NOTIFY, idFrom, (LPARAM)lpNmh);
2170 /**************************************************************************
2171 * SendNotify [COMCTL32.341]
2180 * Success: return value from notification
2185 COMCTL32_SendNotify (HWND hwndFrom, HWND hwndTo,
2186 UINT uCode, LPNMHDR lpHdr)
2190 TRACE("(0x%04x 0x%04x %d %p)\n",
2191 hwndFrom, hwndTo, uCode, lpHdr);
2193 notify.hwndFrom = hwndFrom;
2194 notify.hwndTo = hwndTo;
2195 notify.dwParam5 = 0;
2196 notify.dwParam6 = 0;
2198 return DoNotify (¬ify, uCode, lpHdr);
2202 /**************************************************************************
2203 * SendNotifyEx [COMCTL32.342]
2213 * Success: return value from notification
2218 COMCTL32_SendNotifyEx (HWND hwndTo, HWND hwndFrom, UINT uCode,
2219 LPNMHDR lpHdr, DWORD dwParam5)
2224 TRACE("(0x%04x 0x%04x %d %p 0x%08lx)\n",
2225 hwndFrom, hwndTo, uCode, lpHdr, dwParam5);
2227 hwndNotify = hwndTo;
2229 if (IsWindow (hwndFrom)) {
2230 hwndNotify = GetParent (hwndFrom);
2236 notify.hwndFrom = hwndFrom;
2237 notify.hwndTo = hwndNotify;
2238 notify.dwParam5 = dwParam5;
2239 notify.dwParam6 = 0;
2241 return DoNotify (¬ify, uCode, lpHdr);
2245 /**************************************************************************
2246 * StrChrA [COMCTL32.350]
2251 COMCTL32_StrChrA (LPCSTR lpString, CHAR cChar)
2253 return strchr (lpString, cChar);
2257 /**************************************************************************
2258 * StrStrIA [COMCTL32.355]
2262 COMCTL32_StrStrIA (LPCSTR lpStr1, LPCSTR lpStr2)
2268 return ((LPSTR)lpStr1);
2270 while (lpStr1[len1] != 0) ++len1;
2272 while (lpStr2[len2] != 0) ++len2;
2274 return ((LPSTR)(lpStr1 + len1));
2275 first = tolower (*lpStr2);
2276 while (len1 >= len2) {
2277 if (tolower(*lpStr1) == first) {
2278 for (i = 1; i < len2; ++i)
2279 if (tolower (lpStr1[i]) != tolower(lpStr2[i]))
2282 return ((LPSTR)lpStr1);
2290 /**************************************************************************
2291 * StrToIntA [COMCTL32.357] Converts a string to a signed integer.
2295 COMCTL32_StrToIntA (LPSTR lpString)
2297 return atoi(lpString);
2300 /**************************************************************************
2301 * StrToIntW [COMCTL32.365] Converts a wide char string to a signed integer.
2305 COMCTL32_StrToIntW (LPWSTR lpString)
2307 return _wtoi(lpString);
2311 /**************************************************************************
2312 * DPA_EnumCallback [COMCTL32.385]
2314 * Enumerates all items in a dynamic pointer array.
2317 * hdpa [I] handle to the dynamic pointer array
2326 DPA_EnumCallback (const HDPA hdpa, DPAENUMPROC enumProc, LPARAM lParam)
2330 TRACE("(%p %p %08lx)\n", hdpa, enumProc, lParam);
2334 if (hdpa->nItemCount <= 0)
2337 for (i = 0; i < hdpa->nItemCount; i++) {
2338 if ((enumProc)(hdpa->ptrs[i], lParam) == 0)
2346 /**************************************************************************
2347 * DPA_DestroyCallback [COMCTL32.386]
2349 * Enumerates all items in a dynamic pointer array and destroys it.
2352 * hdpa [I] handle to the dynamic pointer array
2362 DPA_DestroyCallback (const HDPA hdpa, DPAENUMPROC enumProc, LPARAM lParam)
2364 TRACE("(%p %p %08lx)\n", hdpa, enumProc, lParam);
2366 DPA_EnumCallback (hdpa, enumProc, lParam);
2368 return DPA_Destroy (hdpa);
2372 /**************************************************************************
2373 * DSA_EnumCallback [COMCTL32.387]
2375 * Enumerates all items in a dynamic storage array.
2378 * hdsa [I] handle to the dynamic storage array
2387 DSA_EnumCallback (const HDSA hdsa, DSAENUMPROC enumProc, LPARAM lParam)
2391 TRACE("(%p %p %08lx)\n", hdsa, enumProc, lParam);
2395 if (hdsa->nItemCount <= 0)
2398 for (i = 0; i < hdsa->nItemCount; i++) {
2399 LPVOID lpItem = DSA_GetItemPtr (hdsa, i);
2400 if ((enumProc)(lpItem, lParam) == 0)
2408 /**************************************************************************
2409 * DSA_DestroyCallback [COMCTL32.388]
2411 * Enumerates all items in a dynamic storage array and destroys it.
2414 * hdsa [I] handle to the dynamic storage array
2424 DSA_DestroyCallback (const HDSA hdsa, DSAENUMPROC enumProc, LPARAM lParam)
2426 TRACE("(%p %p %08lx)\n", hdsa, enumProc, lParam);
2428 DSA_EnumCallback (hdsa, enumProc, lParam);
2430 return DSA_Destroy (hdsa);
2433 /**************************************************************************
2434 * StrCSpnA [COMCTL32.356]
2437 INT WINAPI COMCTL32_StrCSpnA( LPCSTR lpStr, LPCSTR lpSet) {
2438 return strcspn(lpStr, lpSet);
2441 /**************************************************************************
2442 * StrChrW [COMCTL32.358]
2445 LPWSTR WINAPI COMCTL32_StrChrW( LPCWSTR lpStart, WORD wMatch) {
2446 return strchrW(lpStart, wMatch);
2449 /**************************************************************************
2450 * StrCmpNA [COMCTL32.352]
2453 INT WINAPI COMCTL32_StrCmpNA( LPCSTR lpStr1, LPCSTR lpStr2, int nChar) {
2454 return strncmp(lpStr1, lpStr2, nChar);
2457 /**************************************************************************
2458 * StrCmpNIA [COMCTL32.353]
2461 INT WINAPI COMCTL32_StrCmpNIA( LPCSTR lpStr1, LPCSTR lpStr2, int nChar) {
2462 return strncasecmp(lpStr1, lpStr2, nChar);
2465 /**************************************************************************
2466 * StrCmpNW [COMCTL32.360]
2469 INT WINAPI COMCTL32_StrCmpNW( LPCWSTR lpStr1, LPCWSTR lpStr2, int nChar) {
2470 return strncmpW(lpStr1, lpStr2, nChar);
2473 /**************************************************************************
2474 * StrCmpNIW [COMCTL32.361]
2477 INT WINAPI COMCTL32_StrCmpNIW( LPCWSTR lpStr1, LPCWSTR lpStr2, int nChar) {
2478 FIXME("(%s, %s, %i): stub\n", debugstr_w(lpStr1), debugstr_w(lpStr2), nChar);
2482 /**************************************************************************
2483 * StrRChrA [COMCTL32.351]
2486 LPSTR WINAPI COMCTL32_StrRChrA( LPCSTR lpStart, LPCSTR lpEnd, WORD wMatch )
2488 LPCSTR lpGotIt = NULL;
2489 BOOL dbcs = IsDBCSLeadByte( LOBYTE(wMatch) );
2491 TRACE("(%p, %p, %x)\n", lpStart, lpEnd, wMatch);
2493 if (!lpEnd) lpEnd = lpStart + strlen(lpStart);
2495 for(; lpStart < lpEnd; lpStart = CharNextA(lpStart))
2497 if (*lpStart != LOBYTE(wMatch)) continue;
2498 if (dbcs && lpStart[1] != HIBYTE(wMatch)) continue;
2501 return (LPSTR)lpGotIt;
2505 /**************************************************************************
2506 * StrRChrW [COMCTL32.359]
2509 LPWSTR WINAPI COMCTL32_StrRChrW( LPCWSTR lpStart, LPCWSTR lpEnd, WORD wMatch)
2511 LPCWSTR lpGotIt = NULL;
2513 TRACE("(%p, %p, %x)\n", lpStart, lpEnd, wMatch);
2514 if (!lpEnd) lpEnd = lpStart + strlenW(lpStart);
2516 for(; lpStart < lpEnd; lpStart = CharNextW(lpStart))
2517 if (*lpStart == wMatch) lpGotIt = lpStart;
2519 return (LPWSTR)lpGotIt;
2523 /**************************************************************************
2524 * StrStrA [COMCTL32.354]
2527 LPSTR WINAPI COMCTL32_StrStrA( LPCSTR lpFirst, LPCSTR lpSrch) {
2528 return strstr(lpFirst, lpSrch);
2531 /**************************************************************************
2532 * StrStrW [COMCTL32.362]
2535 LPWSTR WINAPI COMCTL32_StrStrW( LPCWSTR lpFirst, LPCWSTR lpSrch) {
2536 return strstrW(lpFirst, lpSrch);
2539 /**************************************************************************
2540 * StrSpnW [COMCTL32.364]
2543 INT WINAPI COMCTL32_StrSpnW( LPWSTR lpStr, LPWSTR lpSet) {
2544 LPWSTR lpLoop = lpStr;
2547 if ((lpStr == 0) || (lpSet == 0)) return 0;
2549 /* while(*lpLoop) { if lpLoop++; } */
2551 for(; (*lpLoop != 0); lpLoop++)
2552 if( strchrW(lpSet, *(WORD*)lpLoop))
2553 return (INT)(lpLoop-lpStr);
2555 return (INT)(lpLoop-lpStr);
2558 /**************************************************************************
2561 * FIXME: What's this supposed to do?
2562 * Parameter 1 is an HWND, you're on your own for the rest.
2565 BOOL WINAPI COMCTL32_410( HWND hw, DWORD b, DWORD c, DWORD d) {
2567 FIXME("(%x, %lx, %lx, %lx): stub!\n", hw, b, c, d);
2572 /**************************************************************************
2575 * FIXME: What's this supposed to do?
2576 * Parameter 1 is an HWND, you're on your own for the rest.
2579 BOOL WINAPI COMCTL32_411( HWND hw, DWORD b, DWORD c) {
2581 FIXME("(%x, %lx, %lx): stub!\n", hw, b, c);
2586 /**************************************************************************
2589 * FIXME: What's this supposed to do?
2590 * Parameter 1 is an HWND, you're on your own for the rest.
2593 BOOL WINAPI COMCTL32_412( HWND hwnd, DWORD b, DWORD c)
2595 FIXME("(%x, %lx, %lx): stub!\n", hwnd, b, c);
2597 if (IsWindow (hwnd) == FALSE)
2607 /**************************************************************************
2610 * FIXME: What's this supposed to do?
2611 * Parameter 1 is an HWND, you're on your own for the rest.
2614 BOOL WINAPI COMCTL32_413( HWND hw, DWORD b, DWORD c, DWORD d) {
2616 FIXME("(%x, %lx, %lx, %lx): stub!\n", hw, b, c, d);
2622 /**************************************************************************
2625 * FIXME: What's this supposed to do?
2626 * Parameter 1 is an HWND, you're on your own for the rest.
2629 BOOL WINAPI COMCTL32_415( HWND hwnd, DWORD b, DWORD c, DWORD d, DWORD e)
2632 FIXME("(%x, %lx, %lx, %lx, %lx): stub!\n", hwnd, b, c, d, e);