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
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * All of these functions are UNDOCUMENTED!! And I mean UNDOCUMENTED!!!!
24 * Do NOT rely on names or contents of undocumented structures and types!!!
25 * These functions are used by EXPLORER.EXE, IEXPLORE.EXE and
26 * COMCTL32.DLL (internally).
29 * - Add more functions.
30 * - Write some documentation.
33 #include "wine/port.h"
36 #include <stdlib.h> /* atoi */
40 #define NONAMELESSUNION
41 #define NONAMELESSSTRUCT
48 #include "wine/unicode.h"
51 #include "wine/debug.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(commctrl);
56 extern HANDLE COMCTL32_hHeap; /* handle to the private heap */
59 typedef struct _STREAMDATA
64 } STREAMDATA, *PSTREAMDATA;
66 typedef struct _LOADDATA
70 } LOADDATA, *LPLOADDATA;
72 typedef HRESULT (CALLBACK *DPALOADPROC)(LPLOADDATA,IStream*,LPARAM);
74 /**************************************************************************
75 * DPA_LoadStream [COMCTL32.9]
77 * Loads a dynamic pointer array from a stream
80 * phDpa [O] pointer to a handle to a dynamic pointer array
81 * loadProc [I] pointer to a callback function
82 * pStream [I] pointer to a stream
83 * lParam [I] application specific value
86 * No more information available yet!
90 DPA_LoadStream (HDPA *phDpa, DPALOADPROC loadProc, IStream *pStream, LPARAM lParam)
93 LARGE_INTEGER position;
94 ULARGE_INTEGER newPosition;
95 STREAMDATA streamData;
101 FIXME ("phDpa=%p loadProc=%p pStream=%p lParam=%lx\n",
102 phDpa, loadProc, pStream, lParam);
104 if (!phDpa || !loadProc || !pStream)
109 position.s.LowPart = 0;
110 position.s.HighPart = 0;
113 * Zero out our streamData
115 memset(&streamData,0,sizeof(STREAMDATA));
117 errCode = IStream_Seek (pStream, position, STREAM_SEEK_CUR, &newPosition);
121 errCode = IStream_Read (pStream, &streamData, sizeof(STREAMDATA), &ulRead);
125 FIXME ("dwSize=%lu dwData2=%lu dwItems=%lu\n",
126 streamData.dwSize, streamData.dwData2, streamData.dwItems);
128 if ( ulRead < sizeof(STREAMDATA) ||
129 lParam < sizeof(STREAMDATA) ||
130 streamData.dwSize < sizeof(STREAMDATA) ||
131 streamData.dwData2 < 1) {
135 if (streamData.dwItems > (UINT_MAX / 2 / sizeof(VOID*))) /* 536870911 */
136 return E_OUTOFMEMORY;
139 hDpa = DPA_Create (streamData.dwItems);
141 return E_OUTOFMEMORY;
143 if (!DPA_Grow (hDpa, streamData.dwItems))
144 return E_OUTOFMEMORY;
146 /* load data from the stream into the dpa */
148 for (loadData.nCount = 0; loadData.nCount < streamData.dwItems; loadData.nCount++) {
149 errCode = (loadProc)(&loadData, pStream, lParam);
150 if (errCode != S_OK) {
159 /* set the number of items */
160 hDpa->nItemCount = loadData.nCount;
162 /* store the handle to the dpa */
164 FIXME ("new hDpa=%p\n", hDpa);
170 /**************************************************************************
171 * DPA_SaveStream [COMCTL32.10]
173 * Saves a dynamic pointer array to a stream
176 * hDpa [I] handle to a dynamic pointer array
177 * loadProc [I] pointer to a callback function
178 * pStream [I] pointer to a stream
179 * lParam [I] application specific value
182 * No more information available yet!
186 DPA_SaveStream (const HDPA hDpa, DPALOADPROC loadProc, IStream *pStream, LPARAM lParam)
189 FIXME ("hDpa=%p loadProc=%p pStream=%p lParam=%lx\n",
190 hDpa, loadProc, pStream, lParam);
196 /**************************************************************************
197 * DPA_Merge [COMCTL32.11]
200 * hdpa1 [I] handle to a dynamic pointer array
201 * hdpa2 [I] handle to a dynamic pointer array
203 * pfnCompare [I] pointer to sort function
204 * pfnMerge [I] pointer to merge function
205 * lParam [I] application specific value
208 * No more information available yet!
212 DPA_Merge (const HDPA hdpa1, const HDPA hdpa2, DWORD dwFlags,
213 PFNDPACOMPARE pfnCompare, PFNDPAMERGE pfnMerge, LPARAM lParam)
216 LPVOID *pWork1, *pWork2;
220 TRACE("%p %p %08lx %p %p %08lx)\n",
221 hdpa1, hdpa2, dwFlags, pfnCompare, pfnMerge, lParam);
223 if (IsBadWritePtr (hdpa1, sizeof(DPA)))
226 if (IsBadWritePtr (hdpa2, sizeof(DPA)))
229 if (IsBadCodePtr ((FARPROC)pfnCompare))
232 if (IsBadCodePtr ((FARPROC)pfnMerge))
235 if (!(dwFlags & DPAM_NOSORT)) {
236 TRACE("sorting dpa's!\n");
237 if (hdpa1->nItemCount > 0)
238 DPA_Sort (hdpa1, pfnCompare, lParam);
239 TRACE ("dpa 1 sorted!\n");
240 if (hdpa2->nItemCount > 0)
241 DPA_Sort (hdpa2, pfnCompare, lParam);
242 TRACE ("dpa 2 sorted!\n");
245 if (hdpa2->nItemCount < 1)
248 TRACE("hdpa1->nItemCount=%d hdpa2->nItemCount=%d\n",
249 hdpa1->nItemCount, hdpa2->nItemCount);
252 /* working but untrusted implementation */
254 pWork1 = &(hdpa1->ptrs[hdpa1->nItemCount - 1]);
255 pWork2 = &(hdpa2->ptrs[hdpa2->nItemCount - 1]);
257 nIndex = hdpa1->nItemCount - 1;
258 nCount = hdpa2->nItemCount - 1;
263 if ((nCount >= 0) && (dwFlags & DPAM_INSERT)) {
264 /* Now insert the remaining new items into DPA 1 */
265 TRACE("%d items to be inserted at start of DPA 1\n",
267 for (i=nCount; i>=0; i--) {
270 ptr = (pfnMerge)(3, *pWork2, NULL, lParam);
273 DPA_InsertPtr (hdpa1, 0, ptr);
279 nResult = (pfnCompare)(*pWork1, *pWork2, lParam);
280 TRACE("compare result=%d, dpa1.cnt=%d, dpa2.cnt=%d\n",
281 nResult, nIndex, nCount);
287 ptr = (pfnMerge)(1, *pWork1, *pWork2, lParam);
297 else if (nResult > 0)
299 /* item in DPA 1 missing from DPA 2 */
300 if (dwFlags & DPAM_DELETE)
302 /* Now delete the extra item in DPA1 */
305 ptr = DPA_DeletePtr (hdpa1, hdpa1->nItemCount - 1);
307 (pfnMerge)(2, ptr, NULL, lParam);
314 /* new item in DPA 2 */
315 if (dwFlags & DPAM_INSERT)
317 /* Now insert the new item in DPA 1 */
320 ptr = (pfnMerge)(3, *pWork2, NULL, lParam);
323 DPA_InsertPtr (hdpa1, nIndex+1, ptr);
336 /**************************************************************************
337 * Alloc [COMCTL32.71]
339 * Allocates memory block from the dll's private heap
342 * dwSize [I] size of the allocated memory block
345 * Success: pointer to allocated memory block
350 COMCTL32_Alloc (DWORD dwSize)
354 TRACE("(0x%lx)\n", dwSize);
356 lpPtr = HeapAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, dwSize);
358 TRACE("-- ret=%p\n", lpPtr);
364 /**************************************************************************
365 * ReAlloc [COMCTL32.72]
367 * Changes the size of an allocated memory block or allocates a memory
368 * block using the dll's private heap.
371 * lpSrc [I] pointer to memory block which will be resized
372 * dwSize [I] new size of the memory block.
375 * Success: pointer to the resized memory block
379 * If lpSrc is a NULL-pointer, then COMCTL32_ReAlloc allocates a memory
380 * block like COMCTL32_Alloc.
384 COMCTL32_ReAlloc (LPVOID lpSrc, DWORD dwSize)
388 TRACE("(%p 0x%08lx)\n", lpSrc, dwSize);
391 lpDest = HeapReAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, lpSrc, dwSize);
393 lpDest = HeapAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, dwSize);
395 TRACE("-- ret=%p\n", lpDest);
401 /**************************************************************************
404 * Frees an allocated memory block from the dll's private heap.
407 * lpMem [I] pointer to memory block which will be freed
415 COMCTL32_Free (LPVOID lpMem)
417 TRACE("(%p)\n", lpMem);
419 return HeapFree (COMCTL32_hHeap, 0, lpMem);
423 /**************************************************************************
424 * GetSize [COMCTL32.74]
426 * Retrieves the size of the specified memory block from the dll's
430 * lpMem [I] pointer to an allocated memory block
433 * Success: size of the specified memory block
438 COMCTL32_GetSize (LPVOID lpMem)
440 TRACE("(%p)\n", lpMem);
442 return HeapSize (COMCTL32_hHeap, 0, lpMem);
446 /**************************************************************************
447 * The MRU-API is a set of functions to manipulate MRU(Most Recently Used)
450 * Stored in the reg. as a set of values under a single key. Each item in the
451 * list has a value name that is a single char. 'a' - 'z', '{', '|' or '}'.
452 * The order of the list is stored with value name 'MRUList' which is a string
453 * containing the value names (i.e. 'a', 'b', etc.) in the relevant order.
456 typedef struct tagCREATEMRULISTA
458 DWORD cbSize; /* size of struct */
459 DWORD nMaxItems; /* max no. of items in list */
460 DWORD dwFlags; /* see below */
461 HKEY hKey; /* root reg. key under which list is saved */
462 LPCSTR lpszSubKey; /* reg. subkey */
463 PROC lpfnCompare; /* item compare proc */
464 } CREATEMRULISTA, *LPCREATEMRULISTA;
466 typedef struct tagCREATEMRULISTW
468 DWORD cbSize; /* size of struct */
469 DWORD nMaxItems; /* max no. of items in list */
470 DWORD dwFlags; /* see below */
471 HKEY hKey; /* root reg. key under which list is saved */
472 LPCWSTR lpszSubKey; /* reg. subkey */
473 PROC lpfnCompare; /* item compare proc */
474 } CREATEMRULISTW, *LPCREATEMRULISTW;
477 #define MRUF_STRING_LIST 0 /* list will contain strings */
478 #define MRUF_BINARY_LIST 1 /* list will contain binary data */
479 #define MRUF_DELAYED_SAVE 2 /* only save list order to reg. is FreeMRUList */
481 /* If list is a string list lpfnCompare has the following prototype
482 * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
483 * for binary lists the prototype is
484 * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
485 * where cbData is the no. of bytes to compare.
486 * Need to check what return value means identical - 0?
489 typedef struct tagWINEMRUITEM
491 DWORD size; /* size of data stored */
492 DWORD itemFlag; /* flags */
494 } WINEMRUITEM, *LPWINEMRUITEM;
497 #define WMRUIF_CHANGED 0x0001 /* this dataitem changed */
499 typedef struct tagWINEMRULIST
501 CREATEMRULISTW extview; /* original create information */
502 BOOL isUnicode; /* is compare fn Unicode */
503 DWORD wineFlags; /* internal flags */
504 DWORD cursize; /* current size of realMRU */
505 LPSTR realMRU; /* pointer to string of index names */
506 LPWINEMRUITEM *array; /* array of pointers to data */
507 /* in 'a' to 'z' order */
508 } WINEMRULIST, *LPWINEMRULIST;
511 #define WMRUF_CHANGED 0x0001 /* MRU list has changed */
513 /**************************************************************************
514 * MRU_SaveChanged - Localize MRU saving code
517 VOID MRU_SaveChanged( LPWINEMRULIST mp )
523 WCHAR emptyW[] = {'\0'};
525 /* or should we do the following instead of RegOpenKeyEx:
528 /* open the sub key */
529 if ((err = RegOpenKeyExW( mp->extview.hKey, mp->extview.lpszSubKey,
530 0, KEY_WRITE, &newkey))) {
531 /* not present - what to do ??? */
532 ERR("Can not open key, error=%d, attempting to create\n",
534 if ((err = RegCreateKeyExW( mp->extview.hKey, mp->extview.lpszSubKey,
537 REG_OPTION_NON_VOLATILE,
538 KEY_READ | KEY_WRITE,
542 ERR("failed to create key /%s/, err=%d\n",
543 debugstr_w(mp->extview.lpszSubKey), err);
547 if (mp->wineFlags & WMRUF_CHANGED) {
548 mp->wineFlags &= ~WMRUF_CHANGED;
549 err = RegSetValueExA(newkey, "MRUList", 0, REG_SZ,
550 mp->realMRU, strlen(mp->realMRU) + 1);
552 ERR("error saving MRUList, err=%d\n", err);
554 TRACE("saving MRUList=/%s/\n", mp->realMRU);
557 for(i=0; i<mp->cursize; i++) {
558 witem = mp->array[i];
559 if (witem->itemFlag & WMRUIF_CHANGED) {
560 witem->itemFlag &= ~WMRUIF_CHANGED;
561 realname[0] = 'a' + i;
562 err = RegSetValueExW(newkey, realname, 0,
563 (mp->extview.dwFlags & MRUF_BINARY_LIST) ?
565 &witem->datastart, witem->size);
567 ERR("error saving /%s/, err=%d\n", debugstr_w(realname), err);
569 TRACE("saving value for name /%s/ size=%ld\n",
570 debugstr_w(realname), witem->size);
573 RegCloseKey( newkey );
576 /**************************************************************************
577 * FreeMRUList [COMCTL32.152]
580 * hMRUList [I] Handle to list.
584 FreeMRUList (HANDLE hMRUList)
586 LPWINEMRULIST mp = (LPWINEMRULIST)hMRUList;
590 if (mp->wineFlags & WMRUF_CHANGED) {
591 /* need to open key and then save the info */
592 MRU_SaveChanged( mp );
595 for(i=0; i<mp->extview.nMaxItems; i++) {
597 COMCTL32_Free(mp->array[i]);
599 COMCTL32_Free(mp->realMRU);
600 COMCTL32_Free(mp->array);
601 COMCTL32_Free((LPWSTR)mp->extview.lpszSubKey);
602 return COMCTL32_Free(mp);
606 /**************************************************************************
607 * FindMRUData [COMCTL32.169]
609 * Searches binary list for item that matches lpData of length cbData.
610 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
611 * corresponding to item's reg. name will be stored in it ('a' -> 0).
614 * hList [I] list handle
615 * lpData [I] data to find
616 * cbData [I] length of data
617 * lpRegNum [O] position in registry (maybe NULL)
620 * Position in list 0 -> MRU. -1 if item not found.
623 FindMRUData (HANDLE hList, LPCVOID lpData, DWORD cbData, LPINT lpRegNum)
625 LPWINEMRULIST mp = (LPWINEMRULIST)hList;
629 if (!mp->extview.lpfnCompare) {
630 ERR("MRU list not properly created. No compare procedure.\n");
634 if(!(mp->extview.dwFlags & MRUF_BINARY_LIST) && !mp->isUnicode) {
635 DWORD len = WideCharToMultiByte(CP_ACP, 0, lpData, -1,
636 NULL, 0, NULL, NULL);
637 dataA = COMCTL32_Alloc(len);
638 WideCharToMultiByte(CP_ACP, 0, lpData, -1, dataA, len, NULL, NULL);
641 for(i=0; i<mp->cursize; i++) {
642 if (mp->extview.dwFlags & MRUF_BINARY_LIST) {
643 if (!mp->extview.lpfnCompare(lpData, &mp->array[i]->datastart,
649 if (!mp->extview.lpfnCompare(lpData, &mp->array[i]->datastart))
652 DWORD len = WideCharToMultiByte(CP_ACP, 0,
653 (LPWSTR)&mp->array[i]->datastart, -1,
654 NULL, 0, NULL, NULL);
655 LPSTR itemA = COMCTL32_Alloc(len);
657 WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&mp->array[i]->datastart, -1,
658 itemA, len, NULL, NULL);
660 cmp = mp->extview.lpfnCompare(dataA, itemA);
661 COMCTL32_Free(itemA);
668 COMCTL32_Free(dataA);
673 if (lpRegNum && (ret != -1))
676 TRACE("(%p, %p, %ld, %p) returning %d\n",
677 hList, lpData, cbData, lpRegNum, ret);
683 /**************************************************************************
684 * AddMRUData [COMCTL32.167]
686 * Add item to MRU binary list. If item already exists in list then it is
687 * simply moved up to the top of the list and not added again. If list is
688 * full then the least recently used item is removed to make room.
691 * hList [I] Handle to list.
692 * lpData [I] ptr to data to add.
693 * cbData [I] no. of bytes of data.
696 * No. corresponding to registry name where value is stored 'a' -> 0 etc.
700 AddMRUData (HANDLE hList, LPCVOID lpData, DWORD cbData)
702 LPWINEMRULIST mp = (LPWINEMRULIST)hList;
706 if ((replace = FindMRUData (hList, lpData, cbData, NULL)) < 0) {
707 /* either add a new entry or replace oldest */
708 if (mp->cursize < mp->extview.nMaxItems) {
709 /* Add in a new item */
710 replace = mp->cursize;
714 /* get the oldest entry and replace data */
715 replace = mp->realMRU[mp->cursize - 1] - 'a';
716 COMCTL32_Free(mp->array[replace]);
720 /* free up the old data */
721 COMCTL32_Free(mp->array[replace]);
724 /* Allocate space for new item and move in the data */
725 mp->array[replace] = witem = (LPWINEMRUITEM)COMCTL32_Alloc(cbData +
726 sizeof(WINEMRUITEM));
727 witem->itemFlag |= WMRUIF_CHANGED;
728 witem->size = cbData;
729 memcpy( &witem->datastart, lpData, cbData);
731 /* now rotate MRU list */
732 mp->wineFlags |= WMRUF_CHANGED;
733 for(i=mp->cursize-1; i>=1; i--) {
734 mp->realMRU[i] = mp->realMRU[i-1];
736 mp->realMRU[0] = replace + 'a';
737 TRACE("(%p, %p, %ld) adding data, /%c/ now most current\n",
738 hList, lpData, cbData, replace+'a');
741 if (!(mp->extview.dwFlags & MRUF_DELAYED_SAVE)) {
742 /* save changed stuff right now */
743 MRU_SaveChanged( mp );
749 /**************************************************************************
750 * AddMRUStringW [COMCTL32.401]
752 * Add item to MRU string list. If item already exists in list them it is
753 * simply moved up to the top of the list and not added again. If list is
754 * full then the least recently used item is removed to make room.
757 * hList [I] Handle to list.
758 * lpszString [I] ptr to string to add.
761 * No. corresponding to registry name where value is stored 'a' -> 0 etc.
765 AddMRUStringW(HANDLE hList, LPCWSTR lpszString)
767 FIXME("(%p, %s) empty stub!\n", hList, debugstr_w(lpszString));
772 /**************************************************************************
773 * AddMRUStringA [COMCTL32.153]
776 AddMRUStringA(HANDLE hList, LPCSTR lpszString)
778 FIXME("(%p, %s) empty stub!\n", hList, debugstr_a(lpszString));
783 /**************************************************************************
784 * DelMRUString [COMCTL32.156]
786 * Removes item from either string or binary list (despite its name)
789 * hList [I] list handle
790 * nItemPos [I] item position to remove 0 -> MRU
793 * TRUE if successful, FALSE if nItemPos is out of range.
796 DelMRUString(HANDLE hList, INT nItemPos)
798 FIXME("(%p, %d): stub\n", hList, nItemPos);
802 /**************************************************************************
803 * FindMRUStringW [COMCTL32.402]
806 FindMRUStringW (HANDLE hList, LPCWSTR lpszString, LPINT lpRegNum)
812 /**************************************************************************
813 * FindMRUStringA [COMCTL32.155]
815 * Searches string list for item that matches lpszString.
816 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
817 * corresponding to item's reg. name will be stored in it ('a' -> 0).
820 * hList [I] list handle
821 * lpszString [I] string to find
822 * lpRegNum [O] position in registry (maybe NULL)
825 * Position in list 0 -> MRU. -1 if item not found.
828 FindMRUStringA (HANDLE hList, LPCSTR lpszString, LPINT lpRegNum)
830 DWORD len = MultiByteToWideChar(CP_ACP, 0, lpszString, -1, NULL, 0);
831 LPWSTR stringW = COMCTL32_Alloc(len * sizeof(WCHAR));
834 MultiByteToWideChar(CP_ACP, 0, lpszString, -1, stringW, len);
835 ret = FindMRUData(hList, stringW, len * sizeof(WCHAR), lpRegNum);
836 COMCTL32_Free(stringW);
840 /*************************************************************************
841 * CreateMRUListLazy_common
843 HANDLE CreateMRUListLazy_common(LPWINEMRULIST mp)
847 DWORD datasize, dwdisp;
851 WCHAR emptyW[] = {'\0'};
853 /* get space to save indices that will turn into names
854 * but in order of most to least recently used
856 mp->realMRU = (LPSTR) COMCTL32_Alloc(mp->extview.nMaxItems + 2);
858 /* get space to save pointers to actual data in order of
859 * 'a' to 'z' (0 to n).
861 mp->array = (LPVOID) COMCTL32_Alloc(mp->extview.nMaxItems *
864 /* open the sub key */
865 if ((err = RegCreateKeyExW( mp->extview.hKey, mp->extview.lpszSubKey,
868 REG_OPTION_NON_VOLATILE,
869 KEY_READ | KEY_WRITE,
873 /* error - what to do ??? */
874 ERR("(%lu %lu %lx %lx \"%s\" %p): Can not open key, error=%d\n",
875 mp->extview.cbSize, mp->extview.nMaxItems, mp->extview.dwFlags,
876 (DWORD)mp->extview.hKey, debugstr_w(mp->extview.lpszSubKey),
877 mp->extview.lpfnCompare, err);
881 /* get values from key 'MRUList' */
883 datasize = mp->extview.nMaxItems + 1;
884 if((err=RegQueryValueExA( newkey, "MRUList", 0, &type, mp->realMRU,
886 /* not present - set size to 1 (will become 0 later) */
891 TRACE("MRU list = %s\n", mp->realMRU);
893 mp->cursize = datasize - 1;
894 /* datasize now has number of items in the MRUList */
896 /* get actual values for each entry */
898 for(i=0; i<mp->cursize; i++) {
899 realname[0] = 'a' + i;
900 if(RegQueryValueExW( newkey, realname, 0, &type, 0, &datasize)) {
901 /* not present - what to do ??? */
902 ERR("Key %s not found 1\n", debugstr_w(realname));
904 mp->array[i] = witem = (LPWINEMRUITEM)COMCTL32_Alloc(datasize +
905 sizeof(WINEMRUITEM));
906 witem->size = datasize;
907 if(RegQueryValueExW( newkey, realname, 0, &type,
908 &witem->datastart, &datasize)) {
909 /* not present - what to do ??? */
910 ERR("Key %s not found 2\n", debugstr_w(realname));
913 RegCloseKey( newkey );
918 TRACE("(%lu %lu %lx %lx \"%s\" %p): Current Size = %ld\n",
919 mp->extview.cbSize, mp->extview.nMaxItems, mp->extview.dwFlags,
920 (DWORD)mp->extview.hKey, debugstr_w(mp->extview.lpszSubKey),
921 mp->extview.lpfnCompare, mp->cursize);
925 /**************************************************************************
926 * CreateMRUListLazyW [COMCTL32.404]
929 CreateMRUListLazyW (LPCREATEMRULISTW lpcml, DWORD dwParam2, DWORD dwParam3, DWORD dwParam4)
936 if (lpcml->cbSize < sizeof(CREATEMRULISTW))
939 mp = (LPWINEMRULIST) COMCTL32_Alloc(sizeof(WINEMRULIST));
940 memcpy(&mp->extview, lpcml, sizeof(CREATEMRULISTW));
941 mp->extview.lpszSubKey = COMCTL32_Alloc((strlenW(lpcml->lpszSubKey) + 1) *
943 strcpyW((LPWSTR)mp->extview.lpszSubKey, lpcml->lpszSubKey);
944 mp->isUnicode = TRUE;
946 return CreateMRUListLazy_common(mp);
949 /**************************************************************************
950 * CreateMRUListLazyA [COMCTL32.157]
953 CreateMRUListLazyA (LPCREATEMRULISTA lpcml, DWORD dwParam2, DWORD dwParam3, DWORD dwParam4)
961 if (lpcml->cbSize < sizeof(CREATEMRULISTA))
964 mp = (LPWINEMRULIST) COMCTL32_Alloc(sizeof(WINEMRULIST));
965 memcpy(&mp->extview, lpcml, sizeof(CREATEMRULISTW));
966 len = MultiByteToWideChar(CP_ACP, 0, lpcml->lpszSubKey, -1, NULL, 0);
967 mp->extview.lpszSubKey = COMCTL32_Alloc(len * sizeof(WCHAR));
968 MultiByteToWideChar(CP_ACP, 0, lpcml->lpszSubKey, -1,
969 (LPWSTR)mp->extview.lpszSubKey, len);
970 mp->isUnicode = FALSE;
971 return CreateMRUListLazy_common(mp);
974 /**************************************************************************
975 * CreateMRUListW [COMCTL32.400]
978 * lpcml [I] ptr to CREATEMRULIST structure.
981 * Handle to MRU list.
984 CreateMRUListW (LPCREATEMRULISTW lpcml)
986 return CreateMRUListLazyW(lpcml, 0, 0, 0);
989 /**************************************************************************
990 * CreateMRUListA [COMCTL32.151]
993 CreateMRUListA (LPCREATEMRULISTA lpcml)
995 return CreateMRUListLazyA (lpcml, 0, 0, 0);
999 /**************************************************************************
1000 * EnumMRUListW [COMCTL32.403]
1002 * Enumerate item in a list
1005 * hList [I] list handle
1006 * nItemPos [I] item position to enumerate
1007 * lpBuffer [O] buffer to receive item
1008 * nBufferSize [I] size of buffer
1011 * For binary lists specifies how many bytes were copied to buffer, for
1012 * string lists specifies full length of string. Enumerating past the end
1013 * of list returns -1.
1014 * If lpBuffer == NULL or nItemPos is -ve return value is no. of items in
1017 INT WINAPI EnumMRUListW(HANDLE hList, INT nItemPos, LPVOID lpBuffer,
1020 LPWINEMRULIST mp = (LPWINEMRULIST) hList;
1021 LPWINEMRUITEM witem;
1022 INT desired, datasize;
1024 if (nItemPos >= mp->cursize) return -1;
1025 if ((nItemPos < 0) || !lpBuffer) return mp->cursize;
1026 desired = mp->realMRU[nItemPos];
1028 TRACE("nItemPos=%d, desired=%d\n", nItemPos, desired);
1029 witem = mp->array[desired];
1030 datasize = min( witem->size, nBufferSize );
1031 memcpy( lpBuffer, &witem->datastart, datasize);
1032 TRACE("(%p, %d, %p, %ld): returning len=%d\n",
1033 hList, nItemPos, lpBuffer, nBufferSize, datasize);
1037 /**************************************************************************
1038 * EnumMRUListA [COMCTL32.154]
1041 INT WINAPI EnumMRUListA(HANDLE hList, INT nItemPos, LPVOID lpBuffer,
1044 LPWINEMRULIST mp = (LPWINEMRULIST) hList;
1045 LPWINEMRUITEM witem;
1046 INT desired, datasize;
1049 if (nItemPos >= mp->cursize) return -1;
1050 if ((nItemPos < 0) || !lpBuffer) return mp->cursize;
1051 desired = mp->realMRU[nItemPos];
1053 TRACE("nItemPos=%d, desired=%d\n", nItemPos, desired);
1054 witem = mp->array[desired];
1055 if(mp->extview.dwFlags & MRUF_BINARY_LIST) {
1056 datasize = min( witem->size, nBufferSize );
1057 memcpy( lpBuffer, &witem->datastart, datasize);
1059 lenA = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&witem->datastart, -1,
1060 NULL, 0, NULL, NULL);
1061 datasize = min( witem->size, nBufferSize );
1062 WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&witem->datastart, -1,
1063 lpBuffer, datasize, NULL, NULL);
1065 TRACE("(%p, %d, %p, %ld): returning len=%d\n",
1066 hList, nItemPos, lpBuffer, nBufferSize, datasize);
1071 /**************************************************************************
1072 * Str_GetPtrA [COMCTL32.233]
1083 Str_GetPtrA (LPCSTR lpSrc, LPSTR lpDest, INT nMaxLen)
1087 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
1089 if (!lpDest && lpSrc)
1090 return strlen (lpSrc);
1095 if (lpSrc == NULL) {
1100 len = strlen (lpSrc);
1104 RtlMoveMemory (lpDest, lpSrc, len);
1111 /**************************************************************************
1112 * Str_SetPtrA [COMCTL32.234]
1122 Str_SetPtrA (LPSTR *lppDest, LPCSTR lpSrc)
1124 TRACE("(%p %p)\n", lppDest, lpSrc);
1127 LPSTR ptr = COMCTL32_ReAlloc (*lppDest, strlen (lpSrc) + 1);
1130 strcpy (ptr, lpSrc);
1135 COMCTL32_Free (*lppDest);
1144 /**************************************************************************
1145 * Str_GetPtrW [COMCTL32.235]
1156 Str_GetPtrW (LPCWSTR lpSrc, LPWSTR lpDest, INT nMaxLen)
1160 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
1162 if (!lpDest && lpSrc)
1163 return strlenW (lpSrc);
1168 if (lpSrc == NULL) {
1173 len = strlenW (lpSrc);
1177 RtlMoveMemory (lpDest, lpSrc, len*sizeof(WCHAR));
1178 lpDest[len] = L'\0';
1184 /**************************************************************************
1185 * Str_SetPtrW [COMCTL32.236]
1195 Str_SetPtrW (LPWSTR *lppDest, LPCWSTR lpSrc)
1197 TRACE("(%p %p)\n", lppDest, lpSrc);
1200 INT len = strlenW (lpSrc) + 1;
1201 LPWSTR ptr = COMCTL32_ReAlloc (*lppDest, len * sizeof(WCHAR));
1204 strcpyW (ptr, lpSrc);
1209 COMCTL32_Free (*lppDest);
1218 /**************************************************************************
1219 * Str_GetPtrWtoA [internal]
1221 * Converts a unicode string into a multi byte string
1224 * lpSrc [I] Pointer to the unicode source string
1225 * lpDest [O] Pointer to caller supplied storage for the multi byte string
1226 * nMaxLen [I] Size, in bytes, of the destination buffer
1229 * Length, in bytes, of the converted string.
1233 Str_GetPtrWtoA (LPCWSTR lpSrc, LPSTR lpDest, INT nMaxLen)
1237 TRACE("(%s %p %d)\n", debugstr_w(lpSrc), lpDest, nMaxLen);
1239 if (!lpDest && lpSrc)
1240 return WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, 0, 0, NULL, NULL);
1245 if (lpSrc == NULL) {
1250 len = WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, 0, 0, NULL, NULL);
1254 WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, lpDest, len, NULL, NULL);
1261 /**************************************************************************
1262 * Str_SetPtrAtoW [internal]
1264 * Converts a multi byte string to a unicode string.
1265 * If the pointer to the destination buffer is NULL a buffer is allocated.
1266 * If the destination buffer is too small to keep the converted multi byte
1267 * string the destination buffer is reallocated. If the source pointer is
1268 * NULL, the destination buffer is freed.
1271 * lppDest [I/O] pointer to a pointer to the destination buffer
1272 * lpSrc [I] pointer to a multi byte string
1275 * TRUE: conversion successful
1280 Str_SetPtrAtoW (LPWSTR *lppDest, LPCSTR lpSrc)
1282 TRACE("(%p %s)\n", lppDest, lpSrc);
1285 INT len = MultiByteToWideChar(CP_ACP,0,lpSrc,-1,NULL,0);
1286 LPWSTR ptr = COMCTL32_ReAlloc (*lppDest, len*sizeof(WCHAR));
1290 MultiByteToWideChar(CP_ACP,0,lpSrc,-1,ptr,len);
1295 COMCTL32_Free (*lppDest);
1304 /**************************************************************************
1305 * The DSA-API is a set of functions to create and manipulate arrays of
1306 * fixed-size memory blocks. These arrays can store any kind of data
1307 * (strings, icons...).
1310 /**************************************************************************
1311 * DSA_Create [COMCTL32.320] Creates a dynamic storage array
1314 * nSize [I] size of the array elements
1315 * nGrow [I] number of elements by which the array grows when it is filled
1318 * Success: pointer to an array control structure. Use this like a handle.
1323 DSA_Create (INT nSize, INT nGrow)
1327 TRACE("(size=%d grow=%d)\n", nSize, nGrow);
1329 hdsa = (HDSA)COMCTL32_Alloc (sizeof(DSA));
1332 hdsa->nItemCount = 0;
1334 hdsa->nMaxCount = 0;
1335 hdsa->nItemSize = nSize;
1336 hdsa->nGrow = max(1, nGrow);
1343 /**************************************************************************
1344 * DSA_Destroy [COMCTL32.321] Destroys a dynamic storage array
1347 * hdsa [I] pointer to the array control structure
1355 DSA_Destroy (const HDSA hdsa)
1357 TRACE("(%p)\n", hdsa);
1362 if (hdsa->pData && (!COMCTL32_Free (hdsa->pData)))
1365 return COMCTL32_Free (hdsa);
1369 /**************************************************************************
1370 * DSA_GetItem [COMCTL32.322]
1373 * hdsa [I] pointer to the array control structure
1374 * nIndex [I] number of the Item to get
1375 * pDest [O] destination buffer. Has to be >= dwElementSize.
1383 DSA_GetItem (const HDSA hdsa, INT nIndex, LPVOID pDest)
1387 TRACE("(%p %d %p)\n", hdsa, nIndex, pDest);
1391 if ((nIndex < 0) || (nIndex >= hdsa->nItemCount))
1394 pSrc = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1395 memmove (pDest, pSrc, hdsa->nItemSize);
1401 /**************************************************************************
1402 * DSA_GetItemPtr [COMCTL32.323]
1404 * Retrieves a pointer to the specified item.
1407 * hdsa [I] pointer to the array control structure
1408 * nIndex [I] index of the desired item
1411 * Success: pointer to an item
1416 DSA_GetItemPtr (const HDSA hdsa, INT nIndex)
1420 TRACE("(%p %d)\n", hdsa, nIndex);
1424 if ((nIndex < 0) || (nIndex >= hdsa->nItemCount))
1427 pSrc = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1429 TRACE("-- ret=%p\n", pSrc);
1435 /**************************************************************************
1436 * DSA_SetItem [COMCTL32.325]
1438 * Sets the contents of an item in the array.
1441 * hdsa [I] pointer to the array control structure
1442 * nIndex [I] index for the item
1443 * pSrc [I] pointer to the new item data
1451 DSA_SetItem (const HDSA hdsa, INT nIndex, LPVOID pSrc)
1453 INT nSize, nNewItems;
1454 LPVOID pDest, lpTemp;
1456 TRACE("(%p %d %p)\n", hdsa, nIndex, pSrc);
1458 if ((!hdsa) || nIndex < 0)
1461 if (hdsa->nItemCount <= nIndex) {
1462 /* within the old array */
1463 if (hdsa->nMaxCount > nIndex) {
1464 /* within the allocated space, set a new boundary */
1465 hdsa->nItemCount = nIndex + 1;
1468 /* resize the block of memory */
1470 hdsa->nGrow * ((INT)(((nIndex + 1) - 1) / hdsa->nGrow) + 1);
1471 nSize = hdsa->nItemSize * nNewItems;
1473 lpTemp = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
1477 hdsa->nMaxCount = nNewItems;
1478 hdsa->nItemCount = nIndex + 1;
1479 hdsa->pData = lpTemp;
1483 /* put the new entry in */
1484 pDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1485 TRACE("-- move dest=%p src=%p size=%d\n",
1486 pDest, pSrc, hdsa->nItemSize);
1487 memmove (pDest, pSrc, hdsa->nItemSize);
1493 /**************************************************************************
1494 * DSA_InsertItem [COMCTL32.324]
1497 * hdsa [I] pointer to the array control structure
1498 * nIndex [I] index for the new item
1499 * pSrc [I] pointer to the element
1502 * Success: position of the new item
1507 DSA_InsertItem (const HDSA hdsa, INT nIndex, LPVOID pSrc)
1509 INT nNewItems, nSize;
1510 LPVOID lpTemp, lpDest;
1512 TRACE("(%p %d %p)\n", hdsa, nIndex, pSrc);
1514 if ((!hdsa) || nIndex < 0)
1517 /* when nIndex >= nItemCount then append */
1518 if (nIndex >= hdsa->nItemCount)
1519 nIndex = hdsa->nItemCount;
1521 /* do we need to resize ? */
1522 if (hdsa->nItemCount >= hdsa->nMaxCount) {
1523 nNewItems = hdsa->nMaxCount + hdsa->nGrow;
1524 nSize = hdsa->nItemSize * nNewItems;
1526 lpTemp = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
1530 hdsa->nMaxCount = nNewItems;
1531 hdsa->pData = lpTemp;
1534 /* do we need to move elements ? */
1535 if (nIndex < hdsa->nItemCount) {
1536 lpTemp = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1537 lpDest = (char *) lpTemp + hdsa->nItemSize;
1538 nSize = (hdsa->nItemCount - nIndex) * hdsa->nItemSize;
1539 TRACE("-- move dest=%p src=%p size=%d\n",
1540 lpDest, lpTemp, nSize);
1541 memmove (lpDest, lpTemp, nSize);
1544 /* ok, we can put the new Item in */
1546 lpDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1547 TRACE("-- move dest=%p src=%p size=%d\n",
1548 lpDest, pSrc, hdsa->nItemSize);
1549 memmove (lpDest, pSrc, hdsa->nItemSize);
1555 /**************************************************************************
1556 * DSA_DeleteItem [COMCTL32.326]
1559 * hdsa [I] pointer to the array control structure
1560 * nIndex [I] index for the element to delete
1563 * Success: number of the deleted element
1568 DSA_DeleteItem (const HDSA hdsa, INT nIndex)
1570 LPVOID lpDest,lpSrc;
1573 TRACE("(%p %d)\n", hdsa, nIndex);
1577 if (nIndex < 0 || nIndex >= hdsa->nItemCount)
1580 /* do we need to move ? */
1581 if (nIndex < hdsa->nItemCount - 1) {
1582 lpDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1583 lpSrc = (char *) lpDest + hdsa->nItemSize;
1584 nSize = hdsa->nItemSize * (hdsa->nItemCount - nIndex - 1);
1585 TRACE("-- move dest=%p src=%p size=%d\n",
1586 lpDest, lpSrc, nSize);
1587 memmove (lpDest, lpSrc, nSize);
1593 if ((hdsa->nMaxCount - hdsa->nItemCount) >= hdsa->nGrow) {
1594 nSize = hdsa->nItemSize * hdsa->nItemCount;
1596 lpDest = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
1600 hdsa->nMaxCount = hdsa->nItemCount;
1601 hdsa->pData = lpDest;
1608 /**************************************************************************
1609 * DSA_DeleteAllItems [COMCTL32.327]
1611 * Removes all items and reinitializes the array.
1614 * hdsa [I] pointer to the array control structure
1622 DSA_DeleteAllItems (const HDSA hdsa)
1624 TRACE("(%p)\n", hdsa);
1628 if (hdsa->pData && (!COMCTL32_Free (hdsa->pData)))
1631 hdsa->nItemCount = 0;
1633 hdsa->nMaxCount = 0;
1639 /**************************************************************************
1640 * The DPA-API is a set of functions to create and manipulate arrays of
1644 /**************************************************************************
1645 * DPA_Create [COMCTL32.328] Creates a dynamic pointer array
1648 * nGrow [I] number of items by which the array grows when it is filled
1651 * Success: handle (pointer) to the pointer array.
1656 DPA_Create (INT nGrow)
1660 TRACE("(%d)\n", nGrow);
1662 hdpa = (HDPA)COMCTL32_Alloc (sizeof(DPA));
1664 hdpa->nGrow = max(8, nGrow);
1665 hdpa->hHeap = COMCTL32_hHeap;
1666 hdpa->nMaxCount = hdpa->nGrow * 2;
1668 (LPVOID*)COMCTL32_Alloc (hdpa->nMaxCount * sizeof(LPVOID));
1671 TRACE("-- %p\n", hdpa);
1677 /**************************************************************************
1678 * DPA_Destroy [COMCTL32.329] Destroys a dynamic pointer array
1681 * hdpa [I] handle (pointer) to the pointer array
1689 DPA_Destroy (const HDPA hdpa)
1691 TRACE("(%p)\n", hdpa);
1696 if (hdpa->ptrs && (!HeapFree (hdpa->hHeap, 0, hdpa->ptrs)))
1699 return HeapFree (hdpa->hHeap, 0, hdpa);
1703 /**************************************************************************
1704 * DPA_Grow [COMCTL32.330]
1706 * Sets the growth amount.
1709 * hdpa [I] handle (pointer) to the existing (source) pointer array
1710 * nGrow [I] number of items by which the array grows when it's too small
1718 DPA_Grow (const HDPA hdpa, INT nGrow)
1720 TRACE("(%p %d)\n", hdpa, nGrow);
1725 hdpa->nGrow = max(8, nGrow);
1731 /**************************************************************************
1732 * DPA_Clone [COMCTL32.331]
1734 * Copies a pointer array to an other one or creates a copy
1737 * hdpa [I] handle (pointer) to the existing (source) pointer array
1738 * hdpaNew [O] handle (pointer) to the destination pointer array
1741 * Success: pointer to the destination pointer array.
1745 * - If the 'hdpaNew' is a NULL-Pointer, a copy of the source pointer
1746 * array will be created and it's handle (pointer) is returned.
1747 * - If 'hdpa' is a NULL-Pointer, the original implementation crashes,
1748 * this implementation just returns NULL.
1752 DPA_Clone (const HDPA hdpa, const HDPA hdpaNew)
1754 INT nNewItems, nSize;
1760 TRACE("(%p %p)\n", hdpa, hdpaNew);
1763 /* create a new DPA */
1764 hdpaTemp = (HDPA)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1766 hdpaTemp->hHeap = hdpa->hHeap;
1767 hdpaTemp->nGrow = hdpa->nGrow;
1772 if (hdpaTemp->ptrs) {
1773 /* remove old pointer array */
1774 HeapFree (hdpaTemp->hHeap, 0, hdpaTemp->ptrs);
1775 hdpaTemp->ptrs = NULL;
1776 hdpaTemp->nItemCount = 0;
1777 hdpaTemp->nMaxCount = 0;
1780 /* create a new pointer array */
1781 nNewItems = hdpaTemp->nGrow *
1782 ((INT)((hdpa->nItemCount - 1) / hdpaTemp->nGrow) + 1);
1783 nSize = nNewItems * sizeof(LPVOID);
1785 (LPVOID*)HeapAlloc (hdpaTemp->hHeap, HEAP_ZERO_MEMORY, nSize);
1786 hdpaTemp->nMaxCount = nNewItems;
1788 /* clone the pointer array */
1789 hdpaTemp->nItemCount = hdpa->nItemCount;
1790 memmove (hdpaTemp->ptrs, hdpa->ptrs,
1791 hdpaTemp->nItemCount * sizeof(LPVOID));
1797 /**************************************************************************
1798 * DPA_GetPtr [COMCTL32.332]
1800 * Retrieves a pointer from a dynamic pointer array
1803 * hdpa [I] handle (pointer) to the pointer array
1804 * nIndex [I] array index of the desired pointer
1812 DPA_GetPtr (const HDPA hdpa, INT nIndex)
1814 TRACE("(%p %d)\n", hdpa, nIndex);
1819 WARN("no pointer array.\n");
1822 if ((nIndex < 0) || (nIndex >= hdpa->nItemCount)) {
1823 WARN("not enough pointers in array (%d vs %d).\n",nIndex,hdpa->nItemCount);
1827 TRACE("-- %p\n", hdpa->ptrs[nIndex]);
1829 return hdpa->ptrs[nIndex];
1833 /**************************************************************************
1834 * DPA_GetPtrIndex [COMCTL32.333]
1836 * Retrieves the index of the specified pointer
1839 * hdpa [I] handle (pointer) to the pointer array
1843 * Success: index of the specified pointer
1848 DPA_GetPtrIndex (const HDPA hdpa, LPVOID p)
1852 if (!hdpa || !hdpa->ptrs)
1855 for (i = 0; i < hdpa->nItemCount; i++) {
1856 if (hdpa->ptrs[i] == p)
1864 /**************************************************************************
1865 * DPA_InsertPtr [COMCTL32.334]
1867 * Inserts a pointer into a dynamic pointer array
1870 * hdpa [I] handle (pointer) to the array
1872 * p [I] pointer to insert
1875 * Success: index of the inserted pointer
1880 DPA_InsertPtr (const HDPA hdpa, INT i, LPVOID p)
1882 TRACE("(%p %d %p)\n", hdpa, i, p);
1884 if (!hdpa || i < 0) return -1;
1887 i = hdpa->nItemCount;
1889 if (i >= hdpa->nItemCount)
1890 return DPA_SetPtr(hdpa, i, p) ? i : -1;
1892 /* create empty spot at the end */
1893 if (!DPA_SetPtr(hdpa, hdpa->nItemCount, 0)) return -1;
1894 memmove (hdpa->ptrs + i + 1, hdpa->ptrs + i, (hdpa->nItemCount - i - 1) * sizeof(LPVOID));
1899 /**************************************************************************
1900 * DPA_SetPtr [COMCTL32.335]
1902 * Sets a pointer in the pointer array
1905 * hdpa [I] handle (pointer) to the pointer array
1906 * i [I] index of the pointer that will be set
1907 * p [I] pointer to be set
1915 DPA_SetPtr (const HDPA hdpa, INT i, LPVOID p)
1919 TRACE("(%p %d %p)\n", hdpa, i, p);
1921 if (!hdpa || i < 0 || i > 0x7fff)
1924 if (hdpa->nItemCount <= i) {
1925 /* within the old array */
1926 if (hdpa->nMaxCount <= i) {
1927 /* resize the block of memory */
1929 hdpa->nGrow * ((INT)(((i+1) - 1) / hdpa->nGrow) + 1);
1930 INT nSize = nNewItems * sizeof(LPVOID);
1933 lpTemp = (LPVOID*)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY, hdpa->ptrs, nSize);
1935 lpTemp = (LPVOID*)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY, nSize);
1940 hdpa->nMaxCount = nNewItems;
1941 hdpa->ptrs = lpTemp;
1943 hdpa->nItemCount = i+1;
1946 /* put the new entry in */
1953 /**************************************************************************
1954 * DPA_DeletePtr [COMCTL32.336]
1956 * Removes a pointer from the pointer array.
1959 * hdpa [I] handle (pointer) to the pointer array
1960 * i [I] index of the pointer that will be deleted
1963 * Success: deleted pointer
1968 DPA_DeletePtr (const HDPA hdpa, INT i)
1970 LPVOID *lpDest, *lpSrc, lpTemp = NULL;
1973 TRACE("(%p %d)\n", hdpa, i);
1975 if ((!hdpa) || i < 0 || i >= hdpa->nItemCount)
1978 lpTemp = hdpa->ptrs[i];
1980 /* do we need to move ?*/
1981 if (i < hdpa->nItemCount - 1) {
1982 lpDest = hdpa->ptrs + i;
1984 nSize = (hdpa->nItemCount - i - 1) * sizeof(LPVOID);
1985 TRACE("-- move dest=%p src=%p size=%x\n",
1986 lpDest, lpSrc, nSize);
1987 memmove (lpDest, lpSrc, nSize);
1990 hdpa->nItemCount --;
1993 if ((hdpa->nMaxCount - hdpa->nItemCount) >= hdpa->nGrow) {
1994 INT nNewItems = max(hdpa->nGrow * 2, hdpa->nItemCount);
1995 nSize = nNewItems * sizeof(LPVOID);
1996 lpDest = (LPVOID)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
2001 hdpa->nMaxCount = nNewItems;
2002 hdpa->ptrs = (LPVOID*)lpDest;
2009 /**************************************************************************
2010 * DPA_DeleteAllPtrs [COMCTL32.337]
2012 * Removes all pointers and reinitializes the array.
2015 * hdpa [I] handle (pointer) to the pointer array
2023 DPA_DeleteAllPtrs (const HDPA hdpa)
2025 TRACE("(%p)\n", hdpa);
2030 if (hdpa->ptrs && (!HeapFree (hdpa->hHeap, 0, hdpa->ptrs)))
2033 hdpa->nItemCount = 0;
2034 hdpa->nMaxCount = hdpa->nGrow * 2;
2035 hdpa->ptrs = (LPVOID*)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
2036 hdpa->nMaxCount * sizeof(LPVOID));
2042 /**************************************************************************
2043 * DPA_QuickSort [Internal]
2045 * Ordinary quicksort (used by DPA_Sort).
2048 * lpPtrs [I] pointer to the pointer array
2049 * l [I] index of the "left border" of the partition
2050 * r [I] index of the "right border" of the partition
2051 * pfnCompare [I] pointer to the compare function
2052 * lParam [I] user defined value (3rd parameter in compare function)
2059 DPA_QuickSort (LPVOID *lpPtrs, INT l, INT r,
2060 PFNDPACOMPARE pfnCompare, LPARAM lParam)
2065 TRACE("l=%i r=%i\n", l, r);
2067 if (l==r) /* one element is always sorted */
2069 if (r<l) /* oops, got it in the wrong order */
2071 DPA_QuickSort(lpPtrs, r, l, pfnCompare, lParam);
2074 m = (l+r)/2; /* divide by two */
2075 DPA_QuickSort(lpPtrs, l, m, pfnCompare, lParam);
2076 DPA_QuickSort(lpPtrs, m+1, r, pfnCompare, lParam);
2078 /* join the two sides */
2079 while( (l<=m) && (m<r) )
2081 if(pfnCompare(lpPtrs[l],lpPtrs[m+1],lParam)>0)
2084 memmove(&lpPtrs[l+1],&lpPtrs[l],(m-l+1)*sizeof lpPtrs[l]);
2094 /**************************************************************************
2095 * DPA_Sort [COMCTL32.338]
2097 * Sorts a pointer array using a user defined compare function
2100 * hdpa [I] handle (pointer) to the pointer array
2101 * pfnCompare [I] pointer to the compare function
2102 * lParam [I] user defined value (3rd parameter of compare function)
2110 DPA_Sort (const HDPA hdpa, PFNDPACOMPARE pfnCompare, LPARAM lParam)
2112 if (!hdpa || !pfnCompare)
2115 TRACE("(%p %p 0x%lx)\n", hdpa, pfnCompare, lParam);
2117 if ((hdpa->nItemCount > 1) && (hdpa->ptrs))
2118 DPA_QuickSort (hdpa->ptrs, 0, hdpa->nItemCount - 1,
2119 pfnCompare, lParam);
2125 /**************************************************************************
2126 * DPA_Search [COMCTL32.339]
2128 * Searches a pointer array for a specified pointer
2131 * hdpa [I] handle (pointer) to the pointer array
2132 * pFind [I] pointer to search for
2133 * nStart [I] start index
2134 * pfnCompare [I] pointer to the compare function
2135 * lParam [I] user defined value (3rd parameter of compare function)
2136 * uOptions [I] search options
2139 * Success: index of the pointer in the array.
2143 * Binary search taken from R.Sedgewick "Algorithms in C"!
2144 * Function is NOT tested!
2145 * If something goes wrong, blame HIM not ME! (Eric Kohl)
2149 DPA_Search (const HDPA hdpa, LPVOID pFind, INT nStart,
2150 PFNDPACOMPARE pfnCompare, LPARAM lParam, UINT uOptions)
2152 if (!hdpa || !pfnCompare || !pFind)
2155 TRACE("(%p %p %d %p 0x%08lx 0x%08x)\n",
2156 hdpa, pFind, nStart, pfnCompare, lParam, uOptions);
2158 if (uOptions & DPAS_SORTED) {
2159 /* array is sorted --> use binary search */
2163 TRACE("binary search\n");
2165 l = (nStart == -1) ? 0 : nStart;
2166 r = hdpa->nItemCount - 1;
2170 n = (pfnCompare)(pFind, lpPtr[x], lParam);
2176 TRACE("-- ret=%d\n", n);
2181 if (uOptions & DPAS_INSERTBEFORE) {
2183 TRACE("-- ret=%d\n", r);
2187 if (uOptions & DPAS_INSERTAFTER) {
2188 TRACE("-- ret=%d\n", l);
2193 /* array is not sorted --> use linear search */
2197 TRACE("linear search\n");
2199 nIndex = (nStart == -1)? 0 : nStart;
2201 for (; nIndex < hdpa->nItemCount; nIndex++) {
2202 if ((pfnCompare)(pFind, lpPtr[nIndex], lParam) == 0) {
2203 TRACE("-- ret=%d\n", nIndex);
2209 TRACE("-- not found: ret=-1\n");
2214 /**************************************************************************
2215 * DPA_CreateEx [COMCTL32.340]
2217 * Creates a dynamic pointer array using the specified size and heap.
2220 * nGrow [I] number of items by which the array grows when it is filled
2221 * hHeap [I] handle to the heap where the array is stored
2224 * Success: handle (pointer) to the pointer array.
2229 DPA_CreateEx (INT nGrow, HANDLE hHeap)
2233 TRACE("(%d %p)\n", nGrow, hHeap);
2236 hdpa = (HDPA)HeapAlloc (hHeap, HEAP_ZERO_MEMORY, sizeof(DPA));
2238 hdpa = (HDPA)COMCTL32_Alloc (sizeof(DPA));
2241 hdpa->nGrow = min(8, nGrow);
2242 hdpa->hHeap = hHeap ? hHeap : COMCTL32_hHeap;
2243 hdpa->nMaxCount = hdpa->nGrow * 2;
2245 (LPVOID*)HeapAlloc (hHeap, HEAP_ZERO_MEMORY,
2246 hdpa->nMaxCount * sizeof(LPVOID));
2249 TRACE("-- %p\n", hdpa);
2255 /**************************************************************************
2256 * Notification functions
2259 typedef struct tagNOTIFYDATA
2267 } NOTIFYDATA, *LPNOTIFYDATA;
2270 /**************************************************************************
2271 * DoNotify [Internal]
2275 DoNotify (LPNOTIFYDATA lpNotify, UINT uCode, LPNMHDR lpHdr)
2278 LPNMHDR lpNmh = NULL;
2281 TRACE("(%p %p %d %p 0x%08lx)\n",
2282 lpNotify->hwndFrom, lpNotify->hwndTo, uCode, lpHdr,
2283 lpNotify->dwParam5);
2285 if (!lpNotify->hwndTo)
2288 if (lpNotify->hwndFrom == (HWND)-1) {
2290 idFrom = lpHdr->idFrom;
2293 if (lpNotify->hwndFrom) {
2294 HWND hwndParent = GetParent (lpNotify->hwndFrom);
2296 hwndParent = GetWindow (lpNotify->hwndFrom, GW_OWNER);
2297 /* the following is done even if the return from above
2298 * is zero. GLA 12/2001 */
2299 idFrom = GetDlgCtrlID (lpNotify->hwndFrom);
2303 lpNmh = (lpHdr) ? lpHdr : &nmhdr;
2305 lpNmh->hwndFrom = lpNotify->hwndFrom;
2306 lpNmh->idFrom = idFrom;
2307 lpNmh->code = uCode;
2310 return SendMessageA (lpNotify->hwndTo, WM_NOTIFY, idFrom, (LPARAM)lpNmh);
2314 /**************************************************************************
2315 * SendNotify [COMCTL32.341]
2324 * Success: return value from notification
2329 COMCTL32_SendNotify (HWND hwndTo, HWND hwndFrom,
2330 UINT uCode, LPNMHDR lpHdr)
2334 TRACE("(%p %p %d %p)\n",
2335 hwndTo, hwndFrom, uCode, lpHdr);
2337 notify.hwndFrom = hwndFrom;
2338 notify.hwndTo = hwndTo;
2339 notify.dwParam5 = 0;
2340 notify.dwParam6 = 0;
2342 return DoNotify (¬ify, uCode, lpHdr);
2346 /**************************************************************************
2347 * SendNotifyEx [COMCTL32.342]
2357 * Success: return value from notification
2362 COMCTL32_SendNotifyEx (HWND hwndTo, HWND hwndFrom, UINT uCode,
2363 LPNMHDR lpHdr, DWORD dwParam5)
2368 TRACE("(%p %p %d %p 0x%08lx)\n",
2369 hwndFrom, hwndTo, uCode, lpHdr, dwParam5);
2371 hwndNotify = hwndTo;
2373 if (IsWindow (hwndFrom)) {
2374 hwndNotify = GetParent (hwndFrom);
2380 notify.hwndFrom = hwndFrom;
2381 notify.hwndTo = hwndNotify;
2382 notify.dwParam5 = dwParam5;
2383 notify.dwParam6 = 0;
2385 return DoNotify (¬ify, uCode, lpHdr);
2389 /**************************************************************************
2390 * StrChrA [COMCTL32.350]
2395 COMCTL32_StrChrA (LPCSTR lpString, CHAR cChar)
2397 return strchr (lpString, cChar);
2401 /**************************************************************************
2402 * StrStrIA [COMCTL32.355]
2406 COMCTL32_StrStrIA (LPCSTR lpStr1, LPCSTR lpStr2)
2412 return ((LPSTR)lpStr1);
2414 while (lpStr1[len1] != 0) ++len1;
2416 while (lpStr2[len2] != 0) ++len2;
2418 return ((LPSTR)(lpStr1 + len1));
2419 first = tolower (*lpStr2);
2420 while (len1 >= len2) {
2421 if (tolower(*lpStr1) == first) {
2422 for (i = 1; i < len2; ++i)
2423 if (tolower (lpStr1[i]) != tolower(lpStr2[i]))
2426 return ((LPSTR)lpStr1);
2433 /**************************************************************************
2434 * StrToIntA [COMCTL32.357] Converts a string to a signed integer.
2438 COMCTL32_StrToIntA (LPSTR lpString)
2440 return atoi(lpString);
2443 /**************************************************************************
2444 * StrStrIW [COMCTL32.363]
2448 COMCTL32_StrStrIW (LPCWSTR lpStr1, LPCWSTR lpStr2)
2454 return ((LPWSTR)lpStr1);
2456 while (lpStr1[len1] != 0) ++len1;
2458 while (lpStr2[len2] != 0) ++len2;
2460 return ((LPWSTR)(lpStr1 + len1));
2461 first = tolowerW (*lpStr2);
2462 while (len1 >= len2) {
2463 if (tolowerW (*lpStr1) == first) {
2464 for (i = 1; i < len2; ++i)
2465 if (tolowerW (lpStr1[i]) != tolowerW(lpStr2[i]))
2468 return ((LPWSTR)lpStr1);
2475 /**************************************************************************
2476 * StrToIntW [COMCTL32.365] Converts a wide char string to a signed integer.
2480 COMCTL32_StrToIntW (LPWSTR lpString)
2482 return atoiW(lpString);
2486 /**************************************************************************
2487 * DPA_EnumCallback [COMCTL32.385]
2489 * Enumerates all items in a dynamic pointer array.
2492 * hdpa [I] handle to the dynamic pointer array
2501 DPA_EnumCallback (const HDPA hdpa, DPAENUMPROC enumProc, LPARAM lParam)
2505 TRACE("(%p %p %08lx)\n", hdpa, enumProc, lParam);
2509 if (hdpa->nItemCount <= 0)
2512 for (i = 0; i < hdpa->nItemCount; i++) {
2513 if ((enumProc)(hdpa->ptrs[i], lParam) == 0)
2521 /**************************************************************************
2522 * DPA_DestroyCallback [COMCTL32.386]
2524 * Enumerates all items in a dynamic pointer array and destroys it.
2527 * hdpa [I] handle to the dynamic pointer array
2537 DPA_DestroyCallback (const HDPA hdpa, DPAENUMPROC enumProc, LPARAM lParam)
2539 TRACE("(%p %p %08lx)\n", hdpa, enumProc, lParam);
2541 DPA_EnumCallback (hdpa, enumProc, lParam);
2543 return DPA_Destroy (hdpa);
2547 /**************************************************************************
2548 * DSA_EnumCallback [COMCTL32.387]
2550 * Enumerates all items in a dynamic storage array.
2553 * hdsa [I] handle to the dynamic storage array
2562 DSA_EnumCallback (const HDSA hdsa, DSAENUMPROC enumProc, LPARAM lParam)
2566 TRACE("(%p %p %08lx)\n", hdsa, enumProc, lParam);
2570 if (hdsa->nItemCount <= 0)
2573 for (i = 0; i < hdsa->nItemCount; i++) {
2574 LPVOID lpItem = DSA_GetItemPtr (hdsa, i);
2575 if ((enumProc)(lpItem, lParam) == 0)
2583 /**************************************************************************
2584 * DSA_DestroyCallback [COMCTL32.388]
2586 * Enumerates all items in a dynamic storage array and destroys it.
2589 * hdsa [I] handle to the dynamic storage array
2599 DSA_DestroyCallback (const HDSA hdsa, DSAENUMPROC enumProc, LPARAM lParam)
2601 TRACE("(%p %p %08lx)\n", hdsa, enumProc, lParam);
2603 DSA_EnumCallback (hdsa, enumProc, lParam);
2605 return DSA_Destroy (hdsa);
2608 /**************************************************************************
2609 * StrCSpnA [COMCTL32.356]
2612 INT WINAPI COMCTL32_StrCSpnA( LPCSTR lpStr, LPCSTR lpSet) {
2613 return strcspn(lpStr, lpSet);
2616 /**************************************************************************
2617 * StrChrW [COMCTL32.358]
2620 LPWSTR WINAPI COMCTL32_StrChrW( LPCWSTR lpStart, WORD wMatch) {
2621 return strchrW(lpStart, wMatch);
2624 /**************************************************************************
2625 * StrCmpNA [COMCTL32.352]
2628 INT WINAPI COMCTL32_StrCmpNA( LPCSTR lpStr1, LPCSTR lpStr2, int nChar) {
2629 return strncmp(lpStr1, lpStr2, nChar);
2632 /**************************************************************************
2633 * StrCmpNIA [COMCTL32.353]
2636 INT WINAPI COMCTL32_StrCmpNIA( LPCSTR lpStr1, LPCSTR lpStr2, int nChar) {
2637 return strncasecmp(lpStr1, lpStr2, nChar);
2640 /**************************************************************************
2641 * StrCmpNW [COMCTL32.360]
2644 INT WINAPI COMCTL32_StrCmpNW( LPCWSTR lpStr1, LPCWSTR lpStr2, int nChar) {
2645 return strncmpW(lpStr1, lpStr2, nChar);
2648 /**************************************************************************
2649 * StrCmpNIW [COMCTL32.361]
2652 INT WINAPI COMCTL32_StrCmpNIW( LPCWSTR lpStr1, LPCWSTR lpStr2, int nChar) {
2653 FIXME("(%s, %s, %i): stub\n", debugstr_w(lpStr1), debugstr_w(lpStr2), nChar);
2657 /**************************************************************************
2658 * StrRChrA [COMCTL32.351]
2661 LPSTR WINAPI COMCTL32_StrRChrA( LPCSTR lpStart, LPCSTR lpEnd, WORD wMatch )
2663 LPCSTR lpGotIt = NULL;
2664 BOOL dbcs = IsDBCSLeadByte( LOBYTE(wMatch) );
2666 TRACE("(%p, %p, %x)\n", lpStart, lpEnd, wMatch);
2668 if (!lpEnd) lpEnd = lpStart + strlen(lpStart);
2670 for(; lpStart < lpEnd; lpStart = CharNextA(lpStart))
2672 if (*lpStart != LOBYTE(wMatch)) continue;
2673 if (dbcs && lpStart[1] != HIBYTE(wMatch)) continue;
2676 return (LPSTR)lpGotIt;
2680 /**************************************************************************
2681 * StrRChrW [COMCTL32.359]
2684 LPWSTR WINAPI COMCTL32_StrRChrW( LPCWSTR lpStart, LPCWSTR lpEnd, WORD wMatch)
2686 LPCWSTR lpGotIt = NULL;
2688 TRACE("(%p, %p, %x)\n", lpStart, lpEnd, wMatch);
2689 if (!lpEnd) lpEnd = lpStart + strlenW(lpStart);
2691 for(; lpStart < lpEnd; lpStart = CharNextW(lpStart))
2692 if (*lpStart == wMatch) lpGotIt = lpStart;
2694 return (LPWSTR)lpGotIt;
2698 /**************************************************************************
2699 * StrStrA [COMCTL32.354]
2702 LPSTR WINAPI COMCTL32_StrStrA( LPCSTR lpFirst, LPCSTR lpSrch) {
2703 return strstr(lpFirst, lpSrch);
2706 /**************************************************************************
2707 * StrStrW [COMCTL32.362]
2710 LPWSTR WINAPI COMCTL32_StrStrW( LPCWSTR lpFirst, LPCWSTR lpSrch) {
2711 return strstrW(lpFirst, lpSrch);
2714 /**************************************************************************
2715 * StrSpnW [COMCTL32.364]
2718 INT WINAPI COMCTL32_StrSpnW( LPWSTR lpStr, LPWSTR lpSet) {
2719 LPWSTR lpLoop = lpStr;
2722 if ((lpStr == 0) || (lpSet == 0)) return 0;
2724 /* while(*lpLoop) { if lpLoop++; } */
2726 for(; (*lpLoop != 0); lpLoop++)
2727 if( strchrW(lpSet, *(WORD*)lpLoop))
2728 return (INT)(lpLoop-lpStr);
2730 return (INT)(lpLoop-lpStr);
2733 /**************************************************************************
2736 * FIXME: What's this supposed to do?
2737 * Parameter 1 is an HWND, you're on your own for the rest.
2740 BOOL WINAPI COMCTL32_415( HWND hwnd, DWORD b, DWORD c, DWORD d, DWORD e)
2743 FIXME("(%p, %lx, %lx, %lx, %lx): stub!\n", hwnd, b, c, d, e);
2748 /**************************************************************************
2752 BOOL WINAPI COMCTL32_417(HDC hdc, INT x, INT y, UINT flags, const RECT *lprect,
2753 LPCWSTR str, UINT count, const INT *lpDx)
2755 return ExtTextOutW(hdc, x, y, flags, lprect, str, count, lpDx);
2758 /**************************************************************************
2761 * FIXME: What's this supposed to do?
2764 BOOL WINAPI COMCTL32_419( DWORD a, DWORD b, DWORD c, DWORD d)
2767 FIXME("(%lx, %lx, %lx, %lx): stub!\n", a, b, c, d);