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.
34 #include <stdlib.h> /* atoi */
44 #include "wine/unicode.h"
47 #include "wine/debug.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(commctrl);
52 extern HANDLE COMCTL32_hHeap; /* handle to the private heap */
55 typedef struct _STREAMDATA
60 } STREAMDATA, *PSTREAMDATA;
62 typedef struct _LOADDATA
66 } LOADDATA, *LPLOADDATA;
68 typedef HRESULT (CALLBACK *DPALOADPROC)(LPLOADDATA,IStream*,LPARAM);
70 /**************************************************************************
71 * DPA_LoadStream [COMCTL32.9]
73 * Loads a dynamic pointer array from a stream
76 * phDpa [O] pointer to a handle to a dynamic pointer array
77 * loadProc [I] pointer to a callback function
78 * pStream [I] pointer to a stream
79 * lParam [I] application specific value
82 * No more information available yet!
86 DPA_LoadStream (HDPA *phDpa, DPALOADPROC loadProc, IStream *pStream, LPARAM lParam)
89 LARGE_INTEGER position;
90 ULARGE_INTEGER newPosition;
91 STREAMDATA streamData;
97 FIXME ("phDpa=%p loadProc=%p pStream=%p lParam=%lx\n",
98 phDpa, loadProc, pStream, lParam);
100 if (!phDpa || !loadProc || !pStream)
105 position.s.LowPart = 0;
106 position.s.HighPart = 0;
109 * Zero out our streamData
111 memset(&streamData,0,sizeof(STREAMDATA));
113 errCode = IStream_Seek (pStream, position, STREAM_SEEK_CUR, &newPosition);
117 errCode = IStream_Read (pStream, &streamData, sizeof(STREAMDATA), &ulRead);
121 FIXME ("dwSize=%lu dwData2=%lu dwItems=%lu\n",
122 streamData.dwSize, streamData.dwData2, streamData.dwItems);
124 if ( ulRead < sizeof(STREAMDATA) ||
125 lParam < sizeof(STREAMDATA) ||
126 streamData.dwSize < sizeof(STREAMDATA) ||
127 streamData.dwData2 < 1) {
131 if (streamData.dwItems > (UINT_MAX / 2 / sizeof(VOID*))) /* 536870911 */
132 return E_OUTOFMEMORY;
135 hDpa = DPA_Create (streamData.dwItems);
137 return E_OUTOFMEMORY;
139 if (!DPA_Grow (hDpa, streamData.dwItems))
140 return E_OUTOFMEMORY;
142 /* load data from the stream into the dpa */
144 for (loadData.nCount = 0; loadData.nCount < streamData.dwItems; loadData.nCount++) {
145 errCode = (loadProc)(&loadData, pStream, lParam);
146 if (errCode != S_OK) {
155 /* set the number of items */
156 hDpa->nItemCount = loadData.nCount;
158 /* store the handle to the dpa */
160 FIXME ("new hDpa=%p\n", hDpa);
166 /**************************************************************************
167 * DPA_SaveStream [COMCTL32.10]
169 * Saves a dynamic pointer array to a stream
172 * hDpa [I] handle to a dynamic pointer array
173 * loadProc [I] pointer to a callback function
174 * pStream [I] pointer to a stream
175 * lParam [I] application specific value
178 * No more information available yet!
182 DPA_SaveStream (const HDPA hDpa, DPALOADPROC loadProc, IStream *pStream, LPARAM lParam)
185 FIXME ("hDpa=%p loadProc=%p pStream=%p lParam=%lx\n",
186 hDpa, loadProc, pStream, lParam);
192 /**************************************************************************
193 * DPA_Merge [COMCTL32.11]
196 * hdpa1 [I] handle to a dynamic pointer array
197 * hdpa2 [I] handle to a dynamic pointer array
199 * pfnCompare [I] pointer to sort function
200 * pfnMerge [I] pointer to merge function
201 * lParam [I] application specific value
204 * No more information available yet!
208 DPA_Merge (const HDPA hdpa1, const HDPA hdpa2, DWORD dwFlags,
209 PFNDPACOMPARE pfnCompare, PFNDPAMERGE pfnMerge, LPARAM lParam)
212 LPVOID *pWork1, *pWork2;
216 TRACE("%p %p %08lx %p %p %08lx)\n",
217 hdpa1, hdpa2, dwFlags, pfnCompare, pfnMerge, lParam);
219 if (IsBadWritePtr (hdpa1, sizeof(DPA)))
222 if (IsBadWritePtr (hdpa2, sizeof(DPA)))
225 if (IsBadCodePtr ((FARPROC)pfnCompare))
228 if (IsBadCodePtr ((FARPROC)pfnMerge))
231 if (!(dwFlags & DPAM_NOSORT)) {
232 TRACE("sorting dpa's!\n");
233 if (hdpa1->nItemCount > 0)
234 DPA_Sort (hdpa1, pfnCompare, lParam);
235 TRACE ("dpa 1 sorted!\n");
236 if (hdpa2->nItemCount > 0)
237 DPA_Sort (hdpa2, pfnCompare, lParam);
238 TRACE ("dpa 2 sorted!\n");
241 if (hdpa2->nItemCount < 1)
244 TRACE("hdpa1->nItemCount=%d hdpa2->nItemCount=%d\n",
245 hdpa1->nItemCount, hdpa2->nItemCount);
248 /* working but untrusted implementation */
250 pWork1 = &(hdpa1->ptrs[hdpa1->nItemCount - 1]);
251 pWork2 = &(hdpa2->ptrs[hdpa2->nItemCount - 1]);
253 nIndex = hdpa1->nItemCount - 1;
254 nCount = hdpa2->nItemCount - 1;
259 if ((nCount >= 0) && (dwFlags & DPAM_INSERT)) {
260 /* Now insert the remaining new items into DPA 1 */
261 TRACE("%d items to be inserted at start of DPA 1\n",
263 for (i=nCount; i>=0; i--) {
266 ptr = (pfnMerge)(3, *pWork2, NULL, lParam);
269 DPA_InsertPtr (hdpa1, 0, ptr);
275 nResult = (pfnCompare)(*pWork1, *pWork2, lParam);
276 TRACE("compare result=%d, dpa1.cnt=%d, dpa2.cnt=%d\n",
277 nResult, nIndex, nCount);
283 ptr = (pfnMerge)(1, *pWork1, *pWork2, lParam);
293 else if (nResult > 0)
295 /* item in DPA 1 missing from DPA 2 */
296 if (dwFlags & DPAM_DELETE)
298 /* Now delete the extra item in DPA1 */
301 ptr = DPA_DeletePtr (hdpa1, hdpa1->nItemCount - 1);
303 (pfnMerge)(2, ptr, NULL, lParam);
310 /* new item in DPA 2 */
311 if (dwFlags & DPAM_INSERT)
313 /* Now insert the new item in DPA 1 */
316 ptr = (pfnMerge)(3, *pWork2, NULL, lParam);
319 DPA_InsertPtr (hdpa1, nIndex+1, ptr);
332 /**************************************************************************
333 * Alloc [COMCTL32.71]
335 * Allocates memory block from the dll's private heap
338 * dwSize [I] size of the allocated memory block
341 * Success: pointer to allocated memory block
346 COMCTL32_Alloc (DWORD dwSize)
350 TRACE("(0x%lx)\n", dwSize);
352 lpPtr = HeapAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, dwSize);
354 TRACE("-- ret=%p\n", lpPtr);
360 /**************************************************************************
361 * ReAlloc [COMCTL32.72]
363 * Changes the size of an allocated memory block or allocates a memory
364 * block using the dll's private heap.
367 * lpSrc [I] pointer to memory block which will be resized
368 * dwSize [I] new size of the memory block.
371 * Success: pointer to the resized memory block
375 * If lpSrc is a NULL-pointer, then COMCTL32_ReAlloc allocates a memory
376 * block like COMCTL32_Alloc.
380 COMCTL32_ReAlloc (LPVOID lpSrc, DWORD dwSize)
384 TRACE("(%p 0x%08lx)\n", lpSrc, dwSize);
387 lpDest = HeapReAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, lpSrc, dwSize);
389 lpDest = HeapAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, dwSize);
391 TRACE("-- ret=%p\n", lpDest);
397 /**************************************************************************
400 * Frees an allocated memory block from the dll's private heap.
403 * lpMem [I] pointer to memory block which will be freed
411 COMCTL32_Free (LPVOID lpMem)
413 TRACE("(%p)\n", lpMem);
415 return HeapFree (COMCTL32_hHeap, 0, lpMem);
419 /**************************************************************************
420 * GetSize [COMCTL32.74]
422 * Retrieves the size of the specified memory block from the dll's
426 * lpMem [I] pointer to an allocated memory block
429 * Success: size of the specified memory block
434 COMCTL32_GetSize (LPVOID lpMem)
436 TRACE("(%p)\n", lpMem);
438 return HeapSize (COMCTL32_hHeap, 0, lpMem);
442 /**************************************************************************
443 * The MRU-API is a set of functions to manipulate MRU(Most Recently Used)
446 * Stored in the reg. as a set of values under a single key. Each item in the
447 * list has a value name that is a single char. 'a' - 'z', '{', '|' or '}'.
448 * The order of the list is stored with value name 'MRUList' which is a string
449 * containing the value names (i.e. 'a', 'b', etc.) in the relevant order.
452 typedef struct tagCREATEMRULISTA
454 DWORD cbSize; /* size of struct */
455 DWORD nMaxItems; /* max no. of items in list */
456 DWORD dwFlags; /* see below */
457 HKEY hKey; /* root reg. key under which list is saved */
458 LPCSTR lpszSubKey; /* reg. subkey */
459 PROC lpfnCompare; /* item compare proc */
460 } CREATEMRULISTA, *LPCREATEMRULISTA;
462 typedef struct tagCREATEMRULISTW
464 DWORD cbSize; /* size of struct */
465 DWORD nMaxItems; /* max no. of items in list */
466 DWORD dwFlags; /* see below */
467 HKEY hKey; /* root reg. key under which list is saved */
468 LPCWSTR lpszSubKey; /* reg. subkey */
469 PROC lpfnCompare; /* item compare proc */
470 } CREATEMRULISTW, *LPCREATEMRULISTW;
473 #define MRUF_STRING_LIST 0 /* list will contain strings */
474 #define MRUF_BINARY_LIST 1 /* list will contain binary data */
475 #define MRUF_DELAYED_SAVE 2 /* only save list order to reg. is FreeMRUList */
477 /* If list is a string list lpfnCompare has the following prototype
478 * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
479 * for binary lists the prototype is
480 * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
481 * where cbData is the no. of bytes to compare.
482 * Need to check what return value means identical - 0?
485 typedef struct tagWINEMRUITEM
487 DWORD size; /* size of data stored */
488 DWORD itemFlag; /* flags */
490 } WINEMRUITEM, *LPWINEMRUITEM;
493 #define WMRUIF_CHANGED 0x0001 /* this dataitem changed */
495 typedef struct tagWINEMRULIST
497 CREATEMRULISTW extview; /* original create information */
498 BOOL isUnicode; /* is compare fn Unicode */
499 DWORD wineFlags; /* internal flags */
500 DWORD cursize; /* current size of realMRU */
501 LPSTR realMRU; /* pointer to string of index names */
502 LPWINEMRUITEM *array; /* array of pointers to data */
503 /* in 'a' to 'z' order */
504 } WINEMRULIST, *LPWINEMRULIST;
507 #define WMRUF_CHANGED 0x0001 /* MRU list has changed */
509 /**************************************************************************
510 * MRU_SaveChanged - Localize MRU saving code
513 VOID MRU_SaveChanged( LPWINEMRULIST mp )
519 WCHAR emptyW[] = {'\0'};
521 /* or should we do the following instead of RegOpenKeyEx:
524 /* open the sub key */
525 if ((err = RegOpenKeyExW( mp->extview.hKey, mp->extview.lpszSubKey,
526 0, KEY_WRITE, &newkey))) {
527 /* not present - what to do ??? */
528 ERR("Can not open key, error=%d, attempting to create\n",
530 if ((err = RegCreateKeyExW( mp->extview.hKey, mp->extview.lpszSubKey,
533 REG_OPTION_NON_VOLATILE,
534 KEY_READ | KEY_WRITE,
538 ERR("failed to create key /%s/, err=%d\n",
539 debugstr_w(mp->extview.lpszSubKey), err);
543 if (mp->wineFlags & WMRUF_CHANGED) {
544 mp->wineFlags &= ~WMRUF_CHANGED;
545 err = RegSetValueExA(newkey, "MRUList", 0, REG_SZ,
546 mp->realMRU, strlen(mp->realMRU) + 1);
548 ERR("error saving MRUList, err=%d\n", err);
550 TRACE("saving MRUList=/%s/\n", mp->realMRU);
553 for(i=0; i<mp->cursize; i++) {
554 witem = mp->array[i];
555 if (witem->itemFlag & WMRUIF_CHANGED) {
556 witem->itemFlag &= ~WMRUIF_CHANGED;
557 realname[0] = 'a' + i;
558 err = RegSetValueExW(newkey, realname, 0,
559 (mp->extview.dwFlags & MRUF_BINARY_LIST) ?
561 &witem->datastart, witem->size);
563 ERR("error saving /%s/, err=%d\n", debugstr_w(realname), err);
565 TRACE("saving value for name /%s/ size=%ld\n",
566 debugstr_w(realname), witem->size);
569 RegCloseKey( newkey );
572 /**************************************************************************
573 * FreeMRUList [COMCTL32.152]
576 * hMRUList [I] Handle to list.
580 FreeMRUList (HANDLE hMRUList)
582 LPWINEMRULIST mp = (LPWINEMRULIST)hMRUList;
586 if (mp->wineFlags & WMRUF_CHANGED) {
587 /* need to open key and then save the info */
588 MRU_SaveChanged( mp );
591 for(i=0; i<mp->extview.nMaxItems; i++) {
593 COMCTL32_Free(mp->array[i]);
595 COMCTL32_Free(mp->realMRU);
596 COMCTL32_Free(mp->array);
597 COMCTL32_Free((LPWSTR)mp->extview.lpszSubKey);
598 return COMCTL32_Free(mp);
602 /**************************************************************************
603 * FindMRUData [COMCTL32.169]
605 * Searches binary list for item that matches lpData of length cbData.
606 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
607 * corresponding to item's reg. name will be stored in it ('a' -> 0).
610 * hList [I] list handle
611 * lpData [I] data to find
612 * cbData [I] length of data
613 * lpRegNum [O] position in registry (maybe NULL)
616 * Position in list 0 -> MRU. -1 if item not found.
619 FindMRUData (HANDLE hList, LPCVOID lpData, DWORD cbData, LPINT lpRegNum)
621 LPWINEMRULIST mp = (LPWINEMRULIST)hList;
625 if (!mp->extview.lpfnCompare) {
626 ERR("MRU list not properly created. No compare procedure.\n");
630 if(!(mp->extview.dwFlags & MRUF_BINARY_LIST) && !mp->isUnicode) {
631 DWORD len = WideCharToMultiByte(CP_ACP, 0, lpData, -1,
632 NULL, 0, NULL, NULL);
633 dataA = COMCTL32_Alloc(len);
634 WideCharToMultiByte(CP_ACP, 0, lpData, -1, dataA, len, NULL, NULL);
637 for(i=0; i<mp->cursize; i++) {
638 if (mp->extview.dwFlags & MRUF_BINARY_LIST) {
639 if (!mp->extview.lpfnCompare(lpData, &mp->array[i]->datastart,
645 if (!mp->extview.lpfnCompare(lpData, &mp->array[i]->datastart))
648 DWORD len = WideCharToMultiByte(CP_ACP, 0,
649 (LPWSTR)&mp->array[i]->datastart, -1,
650 NULL, 0, NULL, NULL);
651 LPSTR itemA = COMCTL32_Alloc(len);
653 WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&mp->array[i]->datastart, -1,
654 itemA, len, NULL, NULL);
656 cmp = mp->extview.lpfnCompare(dataA, itemA);
657 COMCTL32_Free(itemA);
664 COMCTL32_Free(dataA);
669 if (lpRegNum && (ret != -1))
672 TRACE("(%08x, %p, %ld, %p) returning %d\n",
673 hList, lpData, cbData, lpRegNum, ret);
679 /**************************************************************************
680 * AddMRUData [COMCTL32.167]
682 * Add item to MRU binary list. If item already exists in list then it is
683 * simply moved up to the top of the list and not added again. If list is
684 * full then the least recently used item is removed to make room.
687 * hList [I] Handle to list.
688 * lpData [I] ptr to data to add.
689 * cbData [I] no. of bytes of data.
692 * No. corresponding to registry name where value is stored 'a' -> 0 etc.
696 AddMRUData (HANDLE hList, LPCVOID lpData, DWORD cbData)
698 LPWINEMRULIST mp = (LPWINEMRULIST)hList;
702 if ((replace = FindMRUData (hList, lpData, cbData, NULL)) < 0) {
703 /* either add a new entry or replace oldest */
704 if (mp->cursize < mp->extview.nMaxItems) {
705 /* Add in a new item */
706 replace = mp->cursize;
710 /* get the oldest entry and replace data */
711 replace = mp->realMRU[mp->cursize - 1] - 'a';
712 COMCTL32_Free(mp->array[replace]);
716 /* free up the old data */
717 COMCTL32_Free(mp->array[replace]);
720 /* Allocate space for new item and move in the data */
721 mp->array[replace] = witem = (LPWINEMRUITEM)COMCTL32_Alloc(cbData +
722 sizeof(WINEMRUITEM));
723 witem->itemFlag |= WMRUIF_CHANGED;
724 witem->size = cbData;
725 memcpy( &witem->datastart, lpData, cbData);
727 /* now rotate MRU list */
728 mp->wineFlags |= WMRUF_CHANGED;
729 for(i=mp->cursize-1; i>=1; i--) {
730 mp->realMRU[i] = mp->realMRU[i-1];
732 mp->realMRU[0] = replace + 'a';
733 TRACE("(%08x, %p, %ld) adding data, /%c/ now most current\n",
734 hList, lpData, cbData, replace+'a');
737 if (!(mp->extview.dwFlags & MRUF_DELAYED_SAVE)) {
738 /* save changed stuff right now */
739 MRU_SaveChanged( mp );
745 /**************************************************************************
746 * AddMRUStringW [COMCTL32.401]
748 * Add item to MRU string list. If item already exists in list them it is
749 * simply moved up to the top of the list and not added again. If list is
750 * full then the least recently used item is removed to make room.
753 * hList [I] Handle to list.
754 * lpszString [I] ptr to string to add.
757 * No. corresponding to registry name where value is stored 'a' -> 0 etc.
761 AddMRUStringW(HANDLE hList, LPCWSTR lpszString)
763 FIXME("(%08x, %s) empty stub!\n", hList, debugstr_w(lpszString));
768 /**************************************************************************
769 * AddMRUStringA [COMCTL32.153]
772 AddMRUStringA(HANDLE hList, LPCSTR lpszString)
774 FIXME("(%08x, %s) empty stub!\n", hList, debugstr_a(lpszString));
779 /**************************************************************************
780 * DelMRUString [COMCTL32.156]
782 * Removes item from either string or binary list (despite its name)
785 * hList [I] list handle
786 * nItemPos [I] item position to remove 0 -> MRU
789 * TRUE if successful, FALSE if nItemPos is out of range.
792 DelMRUString(HANDLE hList, INT nItemPos)
794 FIXME("(%08x, %d): stub\n", hList, nItemPos);
798 /**************************************************************************
799 * FindMRUStringW [COMCTL32.402]
802 FindMRUStringW (HANDLE hList, LPCWSTR lpszString, LPINT lpRegNum)
808 /**************************************************************************
809 * FindMRUStringA [COMCTL32.155]
811 * Searches string list for item that matches lpszString.
812 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
813 * corresponding to item's reg. name will be stored in it ('a' -> 0).
816 * hList [I] list handle
817 * lpszString [I] string to find
818 * lpRegNum [O] position in registry (maybe NULL)
821 * Position in list 0 -> MRU. -1 if item not found.
824 FindMRUStringA (HANDLE hList, LPCSTR lpszString, LPINT lpRegNum)
826 DWORD len = MultiByteToWideChar(CP_ACP, 0, lpszString, -1, NULL, 0);
827 LPWSTR stringW = COMCTL32_Alloc(len * sizeof(WCHAR));
830 MultiByteToWideChar(CP_ACP, 0, lpszString, -1, stringW, len);
831 ret = FindMRUData(hList, stringW, len * sizeof(WCHAR), lpRegNum);
832 COMCTL32_Free(stringW);
836 /*************************************************************************
837 * CreateMRUListLazy_common
839 HANDLE CreateMRUListLazy_common(LPWINEMRULIST mp)
843 DWORD datasize, dwdisp;
847 WCHAR emptyW[] = {'\0'};
849 /* get space to save indices that will turn into names
850 * but in order of most to least recently used
852 mp->realMRU = (LPSTR) COMCTL32_Alloc(mp->extview.nMaxItems + 2);
854 /* get space to save pointers to actual data in order of
855 * 'a' to 'z' (0 to n).
857 mp->array = (LPVOID) COMCTL32_Alloc(mp->extview.nMaxItems *
860 /* open the sub key */
861 if ((err = RegCreateKeyExW( mp->extview.hKey, mp->extview.lpszSubKey,
864 REG_OPTION_NON_VOLATILE,
865 KEY_READ | KEY_WRITE,
869 /* error - what to do ??? */
870 ERR("(%lu %lu %lx %lx \"%s\" %p): Can not open key, error=%d\n",
871 mp->extview.cbSize, mp->extview.nMaxItems, mp->extview.dwFlags,
872 (DWORD)mp->extview.hKey, debugstr_w(mp->extview.lpszSubKey),
873 mp->extview.lpfnCompare, err);
877 /* get values from key 'MRUList' */
879 datasize = mp->extview.nMaxItems + 1;
880 if((err=RegQueryValueExA( newkey, "MRUList", 0, &type, mp->realMRU,
882 /* not present - set size to 1 (will become 0 later) */
887 TRACE("MRU list = %s\n", mp->realMRU);
889 mp->cursize = datasize - 1;
890 /* datasize now has number of items in the MRUList */
892 /* get actual values for each entry */
894 for(i=0; i<mp->cursize; i++) {
895 realname[0] = 'a' + i;
896 if(RegQueryValueExW( newkey, realname, 0, &type, 0, &datasize)) {
897 /* not present - what to do ??? */
898 ERR("Key %s not found 1\n", debugstr_w(realname));
900 mp->array[i] = witem = (LPWINEMRUITEM)COMCTL32_Alloc(datasize +
901 sizeof(WINEMRUITEM));
902 witem->size = datasize;
903 if(RegQueryValueExW( newkey, realname, 0, &type,
904 &witem->datastart, &datasize)) {
905 /* not present - what to do ??? */
906 ERR("Key %s not found 2\n", debugstr_w(realname));
909 RegCloseKey( newkey );
914 TRACE("(%lu %lu %lx %lx \"%s\" %p): Current Size = %ld\n",
915 mp->extview.cbSize, mp->extview.nMaxItems, mp->extview.dwFlags,
916 (DWORD)mp->extview.hKey, debugstr_w(mp->extview.lpszSubKey),
917 mp->extview.lpfnCompare, mp->cursize);
921 /**************************************************************************
922 * CreateMRUListLazyW [COMCTL32.404]
925 CreateMRUListLazyW (LPCREATEMRULISTW lpcml, DWORD dwParam2, DWORD dwParam3, DWORD dwParam4)
932 if (lpcml->cbSize < sizeof(CREATEMRULISTW))
935 mp = (LPWINEMRULIST) COMCTL32_Alloc(sizeof(WINEMRULIST));
936 memcpy(&mp->extview, lpcml, sizeof(CREATEMRULISTW));
937 mp->extview.lpszSubKey = COMCTL32_Alloc((strlenW(lpcml->lpszSubKey) + 1) *
939 strcpyW((LPWSTR)mp->extview.lpszSubKey, lpcml->lpszSubKey);
940 mp->isUnicode = TRUE;
942 return CreateMRUListLazy_common(mp);
945 /**************************************************************************
946 * CreateMRUListLazyA [COMCTL32.157]
949 CreateMRUListLazyA (LPCREATEMRULISTA lpcml, DWORD dwParam2, DWORD dwParam3, DWORD dwParam4)
957 if (lpcml->cbSize < sizeof(CREATEMRULISTA))
960 mp = (LPWINEMRULIST) COMCTL32_Alloc(sizeof(WINEMRULIST));
961 memcpy(&mp->extview, lpcml, sizeof(CREATEMRULISTW));
962 len = MultiByteToWideChar(CP_ACP, 0, lpcml->lpszSubKey, -1, NULL, 0);
963 mp->extview.lpszSubKey = COMCTL32_Alloc(len * sizeof(WCHAR));
964 MultiByteToWideChar(CP_ACP, 0, lpcml->lpszSubKey, -1,
965 (LPWSTR)mp->extview.lpszSubKey, len);
966 mp->isUnicode = FALSE;
967 return CreateMRUListLazy_common(mp);
970 /**************************************************************************
971 * CreateMRUListW [COMCTL32.400]
974 * lpcml [I] ptr to CREATEMRULIST structure.
977 * Handle to MRU list.
980 CreateMRUListW (LPCREATEMRULISTW lpcml)
982 return CreateMRUListLazyW(lpcml, 0, 0, 0);
985 /**************************************************************************
986 * CreateMRUListA [COMCTL32.151]
989 CreateMRUListA (LPCREATEMRULISTA lpcml)
991 return CreateMRUListLazyA (lpcml, 0, 0, 0);
995 /**************************************************************************
996 * EnumMRUListW [COMCTL32.403]
998 * Enumerate item in a list
1001 * hList [I] list handle
1002 * nItemPos [I] item position to enumerate
1003 * lpBuffer [O] buffer to receive item
1004 * nBufferSize [I] size of buffer
1007 * For binary lists specifies how many bytes were copied to buffer, for
1008 * string lists specifies full length of string. Enumerating past the end
1009 * of list returns -1.
1010 * If lpBuffer == NULL or nItemPos is -ve return value is no. of items in
1013 INT WINAPI EnumMRUListW(HANDLE hList, INT nItemPos, LPVOID lpBuffer,
1016 LPWINEMRULIST mp = (LPWINEMRULIST) hList;
1017 LPWINEMRUITEM witem;
1018 INT desired, datasize;
1020 if (nItemPos >= mp->cursize) return -1;
1021 if ((nItemPos < 0) || !lpBuffer) return mp->cursize;
1022 desired = mp->realMRU[nItemPos];
1024 TRACE("nItemPos=%d, desired=%d\n", nItemPos, desired);
1025 witem = mp->array[desired];
1026 datasize = min( witem->size, nBufferSize );
1027 memcpy( lpBuffer, &witem->datastart, datasize);
1028 TRACE("(%08x, %d, %p, %ld): returning len=%d\n",
1029 hList, nItemPos, lpBuffer, nBufferSize, datasize);
1033 /**************************************************************************
1034 * EnumMRUListA [COMCTL32.154]
1037 INT WINAPI EnumMRUListA(HANDLE hList, INT nItemPos, LPVOID lpBuffer,
1040 LPWINEMRULIST mp = (LPWINEMRULIST) hList;
1041 LPWINEMRUITEM witem;
1042 INT desired, datasize;
1045 if (nItemPos >= mp->cursize) return -1;
1046 if ((nItemPos < 0) || !lpBuffer) return mp->cursize;
1047 desired = mp->realMRU[nItemPos];
1049 TRACE("nItemPos=%d, desired=%d\n", nItemPos, desired);
1050 witem = mp->array[desired];
1051 if(mp->extview.dwFlags & MRUF_BINARY_LIST) {
1052 datasize = min( witem->size, nBufferSize );
1053 memcpy( lpBuffer, &witem->datastart, datasize);
1055 lenA = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&witem->datastart, -1,
1056 NULL, 0, NULL, NULL);
1057 datasize = min( witem->size, nBufferSize );
1058 WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&witem->datastart, -1,
1059 lpBuffer, datasize, NULL, NULL);
1061 TRACE("(%08x, %d, %p, %ld): returning len=%d\n",
1062 hList, nItemPos, lpBuffer, nBufferSize, datasize);
1067 /**************************************************************************
1068 * Str_GetPtrA [COMCTL32.233]
1079 Str_GetPtrA (LPCSTR lpSrc, LPSTR lpDest, INT nMaxLen)
1083 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
1085 if (!lpDest && lpSrc)
1086 return strlen (lpSrc);
1091 if (lpSrc == NULL) {
1096 len = strlen (lpSrc);
1100 RtlMoveMemory (lpDest, lpSrc, len);
1107 /**************************************************************************
1108 * Str_SetPtrA [COMCTL32.234]
1118 Str_SetPtrA (LPSTR *lppDest, LPCSTR lpSrc)
1120 TRACE("(%p %p)\n", lppDest, lpSrc);
1123 LPSTR ptr = COMCTL32_ReAlloc (*lppDest, strlen (lpSrc) + 1);
1126 strcpy (ptr, lpSrc);
1131 COMCTL32_Free (*lppDest);
1140 /**************************************************************************
1141 * Str_GetPtrW [COMCTL32.235]
1152 Str_GetPtrW (LPCWSTR lpSrc, LPWSTR lpDest, INT nMaxLen)
1156 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
1158 if (!lpDest && lpSrc)
1159 return strlenW (lpSrc);
1164 if (lpSrc == NULL) {
1169 len = strlenW (lpSrc);
1173 RtlMoveMemory (lpDest, lpSrc, len*sizeof(WCHAR));
1174 lpDest[len] = L'\0';
1180 /**************************************************************************
1181 * Str_SetPtrW [COMCTL32.236]
1191 Str_SetPtrW (LPWSTR *lppDest, LPCWSTR lpSrc)
1193 TRACE("(%p %p)\n", lppDest, lpSrc);
1196 INT len = strlenW (lpSrc) + 1;
1197 LPWSTR ptr = COMCTL32_ReAlloc (*lppDest, len * sizeof(WCHAR));
1200 strcpyW (ptr, lpSrc);
1205 COMCTL32_Free (*lppDest);
1214 /**************************************************************************
1215 * Str_GetPtrWtoA [internal]
1217 * Converts a unicode string into a multi byte string
1220 * lpSrc [I] Pointer to the unicode source string
1221 * lpDest [O] Pointer to caller supplied storage for the multi byte string
1222 * nMaxLen [I] Size, in bytes, of the destination buffer
1225 * Length, in bytes, of the converted string.
1229 Str_GetPtrWtoA (LPCWSTR lpSrc, LPSTR lpDest, INT nMaxLen)
1233 TRACE("(%s %p %d)\n", debugstr_w(lpSrc), lpDest, nMaxLen);
1235 if (!lpDest && lpSrc)
1236 return WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, 0, 0, NULL, NULL);
1241 if (lpSrc == NULL) {
1246 len = WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, 0, 0, NULL, NULL);
1250 WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, lpDest, len, NULL, NULL);
1257 /**************************************************************************
1258 * Str_SetPtrAtoW [internal]
1260 * Converts a multi byte string to a unicode string.
1261 * If the pointer to the destination buffer is NULL a buffer is allocated.
1262 * If the destination buffer is too small to keep the converted multi byte
1263 * string the destination buffer is reallocated. If the source pointer is
1264 * NULL, the destination buffer is freed.
1267 * lppDest [I/O] pointer to a pointer to the destination buffer
1268 * lpSrc [I] pointer to a multi byte string
1271 * TRUE: conversion successful
1276 Str_SetPtrAtoW (LPWSTR *lppDest, LPCSTR lpSrc)
1278 TRACE("(%p %s)\n", lppDest, lpSrc);
1281 INT len = MultiByteToWideChar(CP_ACP,0,lpSrc,-1,NULL,0);
1282 LPWSTR ptr = COMCTL32_ReAlloc (*lppDest, len*sizeof(WCHAR));
1286 MultiByteToWideChar(CP_ACP,0,lpSrc,-1,ptr,len);
1291 COMCTL32_Free (*lppDest);
1300 /**************************************************************************
1301 * The DSA-API is a set of functions to create and manipulate arrays of
1302 * fixed-size memory blocks. These arrays can store any kind of data
1303 * (strings, icons...).
1306 /**************************************************************************
1307 * DSA_Create [COMCTL32.320] Creates a dynamic storage array
1310 * nSize [I] size of the array elements
1311 * nGrow [I] number of elements by which the array grows when it is filled
1314 * Success: pointer to an array control structure. Use this like a handle.
1319 DSA_Create (INT nSize, INT nGrow)
1323 TRACE("(size=%d grow=%d)\n", nSize, nGrow);
1325 hdsa = (HDSA)COMCTL32_Alloc (sizeof(DSA));
1328 hdsa->nItemCount = 0;
1330 hdsa->nMaxCount = 0;
1331 hdsa->nItemSize = nSize;
1332 hdsa->nGrow = max(1, nGrow);
1339 /**************************************************************************
1340 * DSA_Destroy [COMCTL32.321] Destroys a dynamic storage array
1343 * hdsa [I] pointer to the array control structure
1351 DSA_Destroy (const HDSA hdsa)
1353 TRACE("(%p)\n", hdsa);
1358 if (hdsa->pData && (!COMCTL32_Free (hdsa->pData)))
1361 return COMCTL32_Free (hdsa);
1365 /**************************************************************************
1366 * DSA_GetItem [COMCTL32.322]
1369 * hdsa [I] pointer to the array control structure
1370 * nIndex [I] number of the Item to get
1371 * pDest [O] destination buffer. Has to be >= dwElementSize.
1379 DSA_GetItem (const HDSA hdsa, INT nIndex, LPVOID pDest)
1383 TRACE("(%p %d %p)\n", hdsa, nIndex, pDest);
1387 if ((nIndex < 0) || (nIndex >= hdsa->nItemCount))
1390 pSrc = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1391 memmove (pDest, pSrc, hdsa->nItemSize);
1397 /**************************************************************************
1398 * DSA_GetItemPtr [COMCTL32.323]
1400 * Retrieves a pointer to the specified item.
1403 * hdsa [I] pointer to the array control structure
1404 * nIndex [I] index of the desired item
1407 * Success: pointer to an item
1412 DSA_GetItemPtr (const HDSA hdsa, INT nIndex)
1416 TRACE("(%p %d)\n", hdsa, nIndex);
1420 if ((nIndex < 0) || (nIndex >= hdsa->nItemCount))
1423 pSrc = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1425 TRACE("-- ret=%p\n", pSrc);
1431 /**************************************************************************
1432 * DSA_SetItem [COMCTL32.325]
1434 * Sets the contents of an item in the array.
1437 * hdsa [I] pointer to the array control structure
1438 * nIndex [I] index for the item
1439 * pSrc [I] pointer to the new item data
1447 DSA_SetItem (const HDSA hdsa, INT nIndex, LPVOID pSrc)
1449 INT nSize, nNewItems;
1450 LPVOID pDest, lpTemp;
1452 TRACE("(%p %d %p)\n", hdsa, nIndex, pSrc);
1454 if ((!hdsa) || nIndex < 0)
1457 if (hdsa->nItemCount <= nIndex) {
1458 /* within the old array */
1459 if (hdsa->nMaxCount > nIndex) {
1460 /* within the allocated space, set a new boundary */
1461 hdsa->nItemCount = nIndex + 1;
1464 /* resize the block of memory */
1466 hdsa->nGrow * ((INT)(((nIndex + 1) - 1) / hdsa->nGrow) + 1);
1467 nSize = hdsa->nItemSize * nNewItems;
1469 lpTemp = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
1473 hdsa->nMaxCount = nNewItems;
1474 hdsa->nItemCount = nIndex + 1;
1475 hdsa->pData = lpTemp;
1479 /* put the new entry in */
1480 pDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1481 TRACE("-- move dest=%p src=%p size=%d\n",
1482 pDest, pSrc, hdsa->nItemSize);
1483 memmove (pDest, pSrc, hdsa->nItemSize);
1489 /**************************************************************************
1490 * DSA_InsertItem [COMCTL32.324]
1493 * hdsa [I] pointer to the array control structure
1494 * nIndex [I] index for the new item
1495 * pSrc [I] pointer to the element
1498 * Success: position of the new item
1503 DSA_InsertItem (const HDSA hdsa, INT nIndex, LPVOID pSrc)
1505 INT nNewItems, nSize;
1506 LPVOID lpTemp, lpDest;
1508 TRACE("(%p %d %p)\n", hdsa, nIndex, pSrc);
1510 if ((!hdsa) || nIndex < 0)
1513 /* when nIndex >= nItemCount then append */
1514 if (nIndex >= hdsa->nItemCount)
1515 nIndex = hdsa->nItemCount;
1517 /* do we need to resize ? */
1518 if (hdsa->nItemCount >= hdsa->nMaxCount) {
1519 nNewItems = hdsa->nMaxCount + hdsa->nGrow;
1520 nSize = hdsa->nItemSize * nNewItems;
1522 lpTemp = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
1526 hdsa->nMaxCount = nNewItems;
1527 hdsa->pData = lpTemp;
1530 /* do we need to move elements ? */
1531 if (nIndex < hdsa->nItemCount) {
1532 lpTemp = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1533 lpDest = (char *) lpTemp + hdsa->nItemSize;
1534 nSize = (hdsa->nItemCount - nIndex) * hdsa->nItemSize;
1535 TRACE("-- move dest=%p src=%p size=%d\n",
1536 lpDest, lpTemp, nSize);
1537 memmove (lpDest, lpTemp, nSize);
1540 /* ok, we can put the new Item in */
1542 lpDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1543 TRACE("-- move dest=%p src=%p size=%d\n",
1544 lpDest, pSrc, hdsa->nItemSize);
1545 memmove (lpDest, pSrc, hdsa->nItemSize);
1551 /**************************************************************************
1552 * DSA_DeleteItem [COMCTL32.326]
1555 * hdsa [I] pointer to the array control structure
1556 * nIndex [I] index for the element to delete
1559 * Success: number of the deleted element
1564 DSA_DeleteItem (const HDSA hdsa, INT nIndex)
1566 LPVOID lpDest,lpSrc;
1569 TRACE("(%p %d)\n", hdsa, nIndex);
1573 if (nIndex < 0 || nIndex >= hdsa->nItemCount)
1576 /* do we need to move ? */
1577 if (nIndex < hdsa->nItemCount - 1) {
1578 lpDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1579 lpSrc = (char *) lpDest + hdsa->nItemSize;
1580 nSize = hdsa->nItemSize * (hdsa->nItemCount - nIndex - 1);
1581 TRACE("-- move dest=%p src=%p size=%d\n",
1582 lpDest, lpSrc, nSize);
1583 memmove (lpDest, lpSrc, nSize);
1589 if ((hdsa->nMaxCount - hdsa->nItemCount) >= hdsa->nGrow) {
1590 nSize = hdsa->nItemSize * hdsa->nItemCount;
1592 lpDest = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
1596 hdsa->nMaxCount = hdsa->nItemCount;
1597 hdsa->pData = lpDest;
1604 /**************************************************************************
1605 * DSA_DeleteAllItems [COMCTL32.327]
1607 * Removes all items and reinitializes the array.
1610 * hdsa [I] pointer to the array control structure
1618 DSA_DeleteAllItems (const HDSA hdsa)
1620 TRACE("(%p)\n", hdsa);
1624 if (hdsa->pData && (!COMCTL32_Free (hdsa->pData)))
1627 hdsa->nItemCount = 0;
1629 hdsa->nMaxCount = 0;
1635 /**************************************************************************
1636 * The DPA-API is a set of functions to create and manipulate arrays of
1640 /**************************************************************************
1641 * DPA_Create [COMCTL32.328] Creates a dynamic pointer array
1644 * nGrow [I] number of items by which the array grows when it is filled
1647 * Success: handle (pointer) to the pointer array.
1652 DPA_Create (INT nGrow)
1656 TRACE("(%d)\n", nGrow);
1658 hdpa = (HDPA)COMCTL32_Alloc (sizeof(DPA));
1660 hdpa->nGrow = max(8, nGrow);
1661 hdpa->hHeap = COMCTL32_hHeap;
1662 hdpa->nMaxCount = hdpa->nGrow * 2;
1664 (LPVOID*)COMCTL32_Alloc (hdpa->nMaxCount * sizeof(LPVOID));
1667 TRACE("-- %p\n", hdpa);
1673 /**************************************************************************
1674 * DPA_Destroy [COMCTL32.329] Destroys a dynamic pointer array
1677 * hdpa [I] handle (pointer) to the pointer array
1685 DPA_Destroy (const HDPA hdpa)
1687 TRACE("(%p)\n", hdpa);
1692 if (hdpa->ptrs && (!HeapFree (hdpa->hHeap, 0, hdpa->ptrs)))
1695 return HeapFree (hdpa->hHeap, 0, hdpa);
1699 /**************************************************************************
1700 * DPA_Grow [COMCTL32.330]
1702 * Sets the growth amount.
1705 * hdpa [I] handle (pointer) to the existing (source) pointer array
1706 * nGrow [I] number of items by which the array grows when it's too small
1714 DPA_Grow (const HDPA hdpa, INT nGrow)
1716 TRACE("(%p %d)\n", hdpa, nGrow);
1721 hdpa->nGrow = max(8, nGrow);
1727 /**************************************************************************
1728 * DPA_Clone [COMCTL32.331]
1730 * Copies a pointer array to an other one or creates a copy
1733 * hdpa [I] handle (pointer) to the existing (source) pointer array
1734 * hdpaNew [O] handle (pointer) to the destination pointer array
1737 * Success: pointer to the destination pointer array.
1741 * - If the 'hdpaNew' is a NULL-Pointer, a copy of the source pointer
1742 * array will be created and it's handle (pointer) is returned.
1743 * - If 'hdpa' is a NULL-Pointer, the original implementation crashes,
1744 * this implementation just returns NULL.
1748 DPA_Clone (const HDPA hdpa, const HDPA hdpaNew)
1750 INT nNewItems, nSize;
1756 TRACE("(%p %p)\n", hdpa, hdpaNew);
1759 /* create a new DPA */
1760 hdpaTemp = (HDPA)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1762 hdpaTemp->hHeap = hdpa->hHeap;
1763 hdpaTemp->nGrow = hdpa->nGrow;
1768 if (hdpaTemp->ptrs) {
1769 /* remove old pointer array */
1770 HeapFree (hdpaTemp->hHeap, 0, hdpaTemp->ptrs);
1771 hdpaTemp->ptrs = NULL;
1772 hdpaTemp->nItemCount = 0;
1773 hdpaTemp->nMaxCount = 0;
1776 /* create a new pointer array */
1777 nNewItems = hdpaTemp->nGrow *
1778 ((INT)((hdpa->nItemCount - 1) / hdpaTemp->nGrow) + 1);
1779 nSize = nNewItems * sizeof(LPVOID);
1781 (LPVOID*)HeapAlloc (hdpaTemp->hHeap, HEAP_ZERO_MEMORY, nSize);
1782 hdpaTemp->nMaxCount = nNewItems;
1784 /* clone the pointer array */
1785 hdpaTemp->nItemCount = hdpa->nItemCount;
1786 memmove (hdpaTemp->ptrs, hdpa->ptrs,
1787 hdpaTemp->nItemCount * sizeof(LPVOID));
1793 /**************************************************************************
1794 * DPA_GetPtr [COMCTL32.332]
1796 * Retrieves a pointer from a dynamic pointer array
1799 * hdpa [I] handle (pointer) to the pointer array
1800 * nIndex [I] array index of the desired pointer
1808 DPA_GetPtr (const HDPA hdpa, INT i)
1810 TRACE("(%p %d)\n", hdpa, i);
1815 WARN("no pointer array.\n");
1818 if ((i < 0) || (i >= hdpa->nItemCount)) {
1819 WARN("not enough pointers in array (%d vs %d).\n",i,hdpa->nItemCount);
1823 TRACE("-- %p\n", hdpa->ptrs[i]);
1825 return hdpa->ptrs[i];
1829 /**************************************************************************
1830 * DPA_GetPtrIndex [COMCTL32.333]
1832 * Retrieves the index of the specified pointer
1835 * hdpa [I] handle (pointer) to the pointer array
1839 * Success: index of the specified pointer
1844 DPA_GetPtrIndex (const HDPA hdpa, LPVOID p)
1851 for (i = 0; i < hdpa->nItemCount; i++) {
1852 if (hdpa->ptrs[i] == p)
1860 /**************************************************************************
1861 * DPA_InsertPtr [COMCTL32.334]
1863 * Inserts a pointer into a dynamic pointer array
1866 * hdpa [I] handle (pointer) to the array
1868 * p [I] pointer to insert
1871 * Success: index of the inserted pointer
1876 DPA_InsertPtr (const HDPA hdpa, INT i, LPVOID p)
1878 INT nNewItems, nSize, nIndex = 0;
1879 LPVOID *lpTemp, *lpDest;
1881 TRACE("(%p %d %p)\n", hdpa, i, p);
1883 if ((!hdpa) || (i < 0))
1888 (LPVOID*)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1889 2 * hdpa->nGrow * sizeof(LPVOID));
1892 hdpa->nMaxCount = hdpa->nGrow * 2;
1896 if (hdpa->nItemCount >= hdpa->nMaxCount) {
1897 TRACE("-- resizing\n");
1898 nNewItems = hdpa->nMaxCount + hdpa->nGrow;
1899 nSize = nNewItems * sizeof(LPVOID);
1901 lpTemp = (LPVOID*)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1905 hdpa->nMaxCount = nNewItems;
1906 hdpa->ptrs = lpTemp;
1909 if (i >= hdpa->nItemCount) {
1910 nIndex = hdpa->nItemCount;
1911 TRACE("-- appending at %d\n", nIndex);
1914 TRACE("-- inserting at %d\n", i);
1915 lpTemp = hdpa->ptrs + i;
1916 lpDest = lpTemp + 1;
1917 nSize = (hdpa->nItemCount - i) * sizeof(LPVOID);
1918 TRACE("-- move dest=%p src=%p size=%x\n",
1919 lpDest, lpTemp, nSize);
1920 memmove (lpDest, lpTemp, nSize);
1927 hdpa->ptrs[nIndex] = p;
1933 /**************************************************************************
1934 * DPA_SetPtr [COMCTL32.335]
1936 * Sets a pointer in the pointer array
1939 * hdpa [I] handle (pointer) to the pointer array
1940 * i [I] index of the pointer that will be set
1941 * p [I] pointer to be set
1949 DPA_SetPtr (const HDPA hdpa, INT i, LPVOID p)
1953 TRACE("(%p %d %p)\n", hdpa, i, p);
1955 if ((!hdpa) || i < 0)
1958 if (hdpa->nItemCount <= i) {
1959 /* within the old array */
1960 if (hdpa->nMaxCount > i) {
1961 /* within the allocated space, set a new boundary */
1962 hdpa->nItemCount = i+1;
1965 /* resize the block of memory */
1967 hdpa->nGrow * ((INT)(((i+1) - 1) / hdpa->nGrow) + 1);
1968 INT nSize = nNewItems * sizeof(LPVOID);
1970 lpTemp = (LPVOID*)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1975 hdpa->nItemCount = nNewItems;
1976 hdpa->ptrs = lpTemp;
1980 /* put the new entry in */
1987 /**************************************************************************
1988 * DPA_DeletePtr [COMCTL32.336]
1990 * Removes a pointer from the pointer array.
1993 * hdpa [I] handle (pointer) to the pointer array
1994 * i [I] index of the pointer that will be deleted
1997 * Success: deleted pointer
2002 DPA_DeletePtr (const HDPA hdpa, INT i)
2004 LPVOID *lpDest, *lpSrc, lpTemp = NULL;
2007 TRACE("(%p %d)\n", hdpa, i);
2009 if ((!hdpa) || i < 0 || i >= hdpa->nItemCount)
2012 lpTemp = hdpa->ptrs[i];
2014 /* do we need to move ?*/
2015 if (i < hdpa->nItemCount - 1) {
2016 lpDest = hdpa->ptrs + i;
2018 nSize = (hdpa->nItemCount - i - 1) * sizeof(LPVOID);
2019 TRACE("-- move dest=%p src=%p size=%x\n",
2020 lpDest, lpSrc, nSize);
2021 memmove (lpDest, lpSrc, nSize);
2024 hdpa->nItemCount --;
2027 if ((hdpa->nMaxCount - hdpa->nItemCount) >= hdpa->nGrow) {
2028 INT nNewItems = max(hdpa->nGrow * 2, hdpa->nItemCount);
2029 nSize = nNewItems * sizeof(LPVOID);
2030 lpDest = (LPVOID)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
2035 hdpa->nMaxCount = nNewItems;
2036 hdpa->ptrs = (LPVOID*)lpDest;
2043 /**************************************************************************
2044 * DPA_DeleteAllPtrs [COMCTL32.337]
2046 * Removes all pointers and reinitializes the array.
2049 * hdpa [I] handle (pointer) to the pointer array
2057 DPA_DeleteAllPtrs (const HDPA hdpa)
2059 TRACE("(%p)\n", hdpa);
2064 if (hdpa->ptrs && (!HeapFree (hdpa->hHeap, 0, hdpa->ptrs)))
2067 hdpa->nItemCount = 0;
2068 hdpa->nMaxCount = hdpa->nGrow * 2;
2069 hdpa->ptrs = (LPVOID*)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
2070 hdpa->nMaxCount * sizeof(LPVOID));
2076 /**************************************************************************
2077 * DPA_QuickSort [Internal]
2079 * Ordinary quicksort (used by DPA_Sort).
2082 * lpPtrs [I] pointer to the pointer array
2083 * l [I] index of the "left border" of the partition
2084 * r [I] index of the "right border" of the partition
2085 * pfnCompare [I] pointer to the compare function
2086 * lParam [I] user defined value (3rd parameter in compare function)
2093 DPA_QuickSort (LPVOID *lpPtrs, INT l, INT r,
2094 PFNDPACOMPARE pfnCompare, LPARAM lParam)
2099 TRACE("l=%i r=%i\n", l, r);
2101 if (l==r) /* one element is always sorted */
2103 if (r<l) /* oops, got it in the wrong order */
2105 DPA_QuickSort(lpPtrs, r, l, pfnCompare, lParam);
2108 m = (l+r)/2; /* divide by two */
2109 DPA_QuickSort(lpPtrs, l, m, pfnCompare, lParam);
2110 DPA_QuickSort(lpPtrs, m+1, r, pfnCompare, lParam);
2112 /* join the two sides */
2113 while( (l<=m) && (m<r) )
2115 if(pfnCompare(lpPtrs[l],lpPtrs[m+1],lParam)>0)
2118 memmove(&lpPtrs[l+1],&lpPtrs[l],(m-l+1)*sizeof lpPtrs[l]);
2128 /**************************************************************************
2129 * DPA_Sort [COMCTL32.338]
2131 * Sorts a pointer array using a user defined compare function
2134 * hdpa [I] handle (pointer) to the pointer array
2135 * pfnCompare [I] pointer to the compare function
2136 * lParam [I] user defined value (3rd parameter of compare function)
2144 DPA_Sort (const HDPA hdpa, PFNDPACOMPARE pfnCompare, LPARAM lParam)
2146 if (!hdpa || !pfnCompare)
2149 TRACE("(%p %p 0x%lx)\n", hdpa, pfnCompare, lParam);
2151 if ((hdpa->nItemCount > 1) && (hdpa->ptrs))
2152 DPA_QuickSort (hdpa->ptrs, 0, hdpa->nItemCount - 1,
2153 pfnCompare, lParam);
2159 /**************************************************************************
2160 * DPA_Search [COMCTL32.339]
2162 * Searches a pointer array for a specified pointer
2165 * hdpa [I] handle (pointer) to the pointer array
2166 * pFind [I] pointer to search for
2167 * nStart [I] start index
2168 * pfnCompare [I] pointer to the compare function
2169 * lParam [I] user defined value (3rd parameter of compare function)
2170 * uOptions [I] search options
2173 * Success: index of the pointer in the array.
2177 * Binary search taken from R.Sedgewick "Algorithms in C"!
2178 * Function is NOT tested!
2179 * If something goes wrong, blame HIM not ME! (Eric Kohl)
2183 DPA_Search (const HDPA hdpa, LPVOID pFind, INT nStart,
2184 PFNDPACOMPARE pfnCompare, LPARAM lParam, UINT uOptions)
2186 if (!hdpa || !pfnCompare || !pFind)
2189 TRACE("(%p %p %d %p 0x%08lx 0x%08x)\n",
2190 hdpa, pFind, nStart, pfnCompare, lParam, uOptions);
2192 if (uOptions & DPAS_SORTED) {
2193 /* array is sorted --> use binary search */
2197 TRACE("binary search\n");
2199 l = (nStart == -1) ? 0 : nStart;
2200 r = hdpa->nItemCount - 1;
2204 n = (pfnCompare)(pFind, lpPtr[x], lParam);
2210 TRACE("-- ret=%d\n", n);
2215 if (uOptions & DPAS_INSERTBEFORE) {
2216 TRACE("-- ret=%d\n", r);
2220 if (uOptions & DPAS_INSERTAFTER) {
2221 TRACE("-- ret=%d\n", l);
2226 /* array is not sorted --> use linear search */
2230 TRACE("linear search\n");
2232 nIndex = (nStart == -1)? 0 : nStart;
2234 for (; nIndex < hdpa->nItemCount; nIndex++) {
2235 if ((pfnCompare)(pFind, lpPtr[nIndex], lParam) == 0) {
2236 TRACE("-- ret=%d\n", nIndex);
2242 TRACE("-- not found: ret=-1\n");
2247 /**************************************************************************
2248 * DPA_CreateEx [COMCTL32.340]
2250 * Creates a dynamic pointer array using the specified size and heap.
2253 * nGrow [I] number of items by which the array grows when it is filled
2254 * hHeap [I] handle to the heap where the array is stored
2257 * Success: handle (pointer) to the pointer array.
2262 DPA_CreateEx (INT nGrow, HANDLE hHeap)
2266 TRACE("(%d 0x%x)\n", nGrow, hHeap);
2269 hdpa = (HDPA)HeapAlloc (hHeap, HEAP_ZERO_MEMORY, sizeof(DPA));
2271 hdpa = (HDPA)COMCTL32_Alloc (sizeof(DPA));
2274 hdpa->nGrow = min(8, nGrow);
2275 hdpa->hHeap = hHeap ? hHeap : COMCTL32_hHeap;
2276 hdpa->nMaxCount = hdpa->nGrow * 2;
2278 (LPVOID*)HeapAlloc (hHeap, HEAP_ZERO_MEMORY,
2279 hdpa->nMaxCount * sizeof(LPVOID));
2282 TRACE("-- %p\n", hdpa);
2288 /**************************************************************************
2289 * Notification functions
2292 typedef struct tagNOTIFYDATA
2300 } NOTIFYDATA, *LPNOTIFYDATA;
2303 /**************************************************************************
2304 * DoNotify [Internal]
2308 DoNotify (LPNOTIFYDATA lpNotify, UINT uCode, LPNMHDR lpHdr)
2311 LPNMHDR lpNmh = NULL;
2314 TRACE("(0x%04x 0x%04x %d %p 0x%08lx)\n",
2315 lpNotify->hwndFrom, lpNotify->hwndTo, uCode, lpHdr,
2316 lpNotify->dwParam5);
2318 if (!lpNotify->hwndTo)
2321 if (lpNotify->hwndFrom == -1) {
2323 idFrom = lpHdr->idFrom;
2326 if (lpNotify->hwndFrom) {
2327 HWND hwndParent = GetParent (lpNotify->hwndFrom);
2329 hwndParent = GetWindow (lpNotify->hwndFrom, GW_OWNER);
2330 /* the following is done even if the return from above
2331 * is zero. GLA 12/2001 */
2332 idFrom = GetDlgCtrlID (lpNotify->hwndFrom);
2336 lpNmh = (lpHdr) ? lpHdr : &nmhdr;
2338 lpNmh->hwndFrom = lpNotify->hwndFrom;
2339 lpNmh->idFrom = idFrom;
2340 lpNmh->code = uCode;
2343 return SendMessageA (lpNotify->hwndTo, WM_NOTIFY, idFrom, (LPARAM)lpNmh);
2347 /**************************************************************************
2348 * SendNotify [COMCTL32.341]
2357 * Success: return value from notification
2362 COMCTL32_SendNotify (HWND hwndTo, HWND hwndFrom,
2363 UINT uCode, LPNMHDR lpHdr)
2367 TRACE("(0x%04x 0x%04x %d %p)\n",
2368 hwndTo, hwndFrom, uCode, lpHdr);
2370 notify.hwndFrom = hwndFrom;
2371 notify.hwndTo = hwndTo;
2372 notify.dwParam5 = 0;
2373 notify.dwParam6 = 0;
2375 return DoNotify (¬ify, uCode, lpHdr);
2379 /**************************************************************************
2380 * SendNotifyEx [COMCTL32.342]
2390 * Success: return value from notification
2395 COMCTL32_SendNotifyEx (HWND hwndTo, HWND hwndFrom, UINT uCode,
2396 LPNMHDR lpHdr, DWORD dwParam5)
2401 TRACE("(0x%04x 0x%04x %d %p 0x%08lx)\n",
2402 hwndFrom, hwndTo, uCode, lpHdr, dwParam5);
2404 hwndNotify = hwndTo;
2406 if (IsWindow (hwndFrom)) {
2407 hwndNotify = GetParent (hwndFrom);
2413 notify.hwndFrom = hwndFrom;
2414 notify.hwndTo = hwndNotify;
2415 notify.dwParam5 = dwParam5;
2416 notify.dwParam6 = 0;
2418 return DoNotify (¬ify, uCode, lpHdr);
2422 /**************************************************************************
2423 * StrChrA [COMCTL32.350]
2428 COMCTL32_StrChrA (LPCSTR lpString, CHAR cChar)
2430 return strchr (lpString, cChar);
2434 /**************************************************************************
2435 * StrStrIA [COMCTL32.355]
2439 COMCTL32_StrStrIA (LPCSTR lpStr1, LPCSTR lpStr2)
2445 return ((LPSTR)lpStr1);
2447 while (lpStr1[len1] != 0) ++len1;
2449 while (lpStr2[len2] != 0) ++len2;
2451 return ((LPSTR)(lpStr1 + len1));
2452 first = tolower (*lpStr2);
2453 while (len1 >= len2) {
2454 if (tolower(*lpStr1) == first) {
2455 for (i = 1; i < len2; ++i)
2456 if (tolower (lpStr1[i]) != tolower(lpStr2[i]))
2459 return ((LPSTR)lpStr1);
2467 /**************************************************************************
2468 * StrToIntA [COMCTL32.357] Converts a string to a signed integer.
2472 COMCTL32_StrToIntA (LPSTR lpString)
2474 return atoi(lpString);
2477 /**************************************************************************
2478 * StrToIntW [COMCTL32.365] Converts a wide char string to a signed integer.
2482 COMCTL32_StrToIntW (LPWSTR lpString)
2484 return atoiW(lpString);
2488 /**************************************************************************
2489 * DPA_EnumCallback [COMCTL32.385]
2491 * Enumerates all items in a dynamic pointer array.
2494 * hdpa [I] handle to the dynamic pointer array
2503 DPA_EnumCallback (const HDPA hdpa, DPAENUMPROC enumProc, LPARAM lParam)
2507 TRACE("(%p %p %08lx)\n", hdpa, enumProc, lParam);
2511 if (hdpa->nItemCount <= 0)
2514 for (i = 0; i < hdpa->nItemCount; i++) {
2515 if ((enumProc)(hdpa->ptrs[i], lParam) == 0)
2523 /**************************************************************************
2524 * DPA_DestroyCallback [COMCTL32.386]
2526 * Enumerates all items in a dynamic pointer array and destroys it.
2529 * hdpa [I] handle to the dynamic pointer array
2539 DPA_DestroyCallback (const HDPA hdpa, DPAENUMPROC enumProc, LPARAM lParam)
2541 TRACE("(%p %p %08lx)\n", hdpa, enumProc, lParam);
2543 DPA_EnumCallback (hdpa, enumProc, lParam);
2545 return DPA_Destroy (hdpa);
2549 /**************************************************************************
2550 * DSA_EnumCallback [COMCTL32.387]
2552 * Enumerates all items in a dynamic storage array.
2555 * hdsa [I] handle to the dynamic storage array
2564 DSA_EnumCallback (const HDSA hdsa, DSAENUMPROC enumProc, LPARAM lParam)
2568 TRACE("(%p %p %08lx)\n", hdsa, enumProc, lParam);
2572 if (hdsa->nItemCount <= 0)
2575 for (i = 0; i < hdsa->nItemCount; i++) {
2576 LPVOID lpItem = DSA_GetItemPtr (hdsa, i);
2577 if ((enumProc)(lpItem, lParam) == 0)
2585 /**************************************************************************
2586 * DSA_DestroyCallback [COMCTL32.388]
2588 * Enumerates all items in a dynamic storage array and destroys it.
2591 * hdsa [I] handle to the dynamic storage array
2601 DSA_DestroyCallback (const HDSA hdsa, DSAENUMPROC enumProc, LPARAM lParam)
2603 TRACE("(%p %p %08lx)\n", hdsa, enumProc, lParam);
2605 DSA_EnumCallback (hdsa, enumProc, lParam);
2607 return DSA_Destroy (hdsa);
2610 /**************************************************************************
2611 * StrCSpnA [COMCTL32.356]
2614 INT WINAPI COMCTL32_StrCSpnA( LPCSTR lpStr, LPCSTR lpSet) {
2615 return strcspn(lpStr, lpSet);
2618 /**************************************************************************
2619 * StrChrW [COMCTL32.358]
2622 LPWSTR WINAPI COMCTL32_StrChrW( LPCWSTR lpStart, WORD wMatch) {
2623 return strchrW(lpStart, wMatch);
2626 /**************************************************************************
2627 * StrCmpNA [COMCTL32.352]
2630 INT WINAPI COMCTL32_StrCmpNA( LPCSTR lpStr1, LPCSTR lpStr2, int nChar) {
2631 return strncmp(lpStr1, lpStr2, nChar);
2634 /**************************************************************************
2635 * StrCmpNIA [COMCTL32.353]
2638 INT WINAPI COMCTL32_StrCmpNIA( LPCSTR lpStr1, LPCSTR lpStr2, int nChar) {
2639 return strncasecmp(lpStr1, lpStr2, nChar);
2642 /**************************************************************************
2643 * StrCmpNW [COMCTL32.360]
2646 INT WINAPI COMCTL32_StrCmpNW( LPCWSTR lpStr1, LPCWSTR lpStr2, int nChar) {
2647 return strncmpW(lpStr1, lpStr2, nChar);
2650 /**************************************************************************
2651 * StrCmpNIW [COMCTL32.361]
2654 INT WINAPI COMCTL32_StrCmpNIW( LPCWSTR lpStr1, LPCWSTR lpStr2, int nChar) {
2655 FIXME("(%s, %s, %i): stub\n", debugstr_w(lpStr1), debugstr_w(lpStr2), nChar);
2659 /**************************************************************************
2660 * StrRChrA [COMCTL32.351]
2663 LPSTR WINAPI COMCTL32_StrRChrA( LPCSTR lpStart, LPCSTR lpEnd, WORD wMatch )
2665 LPCSTR lpGotIt = NULL;
2666 BOOL dbcs = IsDBCSLeadByte( LOBYTE(wMatch) );
2668 TRACE("(%p, %p, %x)\n", lpStart, lpEnd, wMatch);
2670 if (!lpEnd) lpEnd = lpStart + strlen(lpStart);
2672 for(; lpStart < lpEnd; lpStart = CharNextA(lpStart))
2674 if (*lpStart != LOBYTE(wMatch)) continue;
2675 if (dbcs && lpStart[1] != HIBYTE(wMatch)) continue;
2678 return (LPSTR)lpGotIt;
2682 /**************************************************************************
2683 * StrRChrW [COMCTL32.359]
2686 LPWSTR WINAPI COMCTL32_StrRChrW( LPCWSTR lpStart, LPCWSTR lpEnd, WORD wMatch)
2688 LPCWSTR lpGotIt = NULL;
2690 TRACE("(%p, %p, %x)\n", lpStart, lpEnd, wMatch);
2691 if (!lpEnd) lpEnd = lpStart + strlenW(lpStart);
2693 for(; lpStart < lpEnd; lpStart = CharNextW(lpStart))
2694 if (*lpStart == wMatch) lpGotIt = lpStart;
2696 return (LPWSTR)lpGotIt;
2700 /**************************************************************************
2701 * StrStrA [COMCTL32.354]
2704 LPSTR WINAPI COMCTL32_StrStrA( LPCSTR lpFirst, LPCSTR lpSrch) {
2705 return strstr(lpFirst, lpSrch);
2708 /**************************************************************************
2709 * StrStrW [COMCTL32.362]
2712 LPWSTR WINAPI COMCTL32_StrStrW( LPCWSTR lpFirst, LPCWSTR lpSrch) {
2713 return strstrW(lpFirst, lpSrch);
2716 /**************************************************************************
2717 * StrSpnW [COMCTL32.364]
2720 INT WINAPI COMCTL32_StrSpnW( LPWSTR lpStr, LPWSTR lpSet) {
2721 LPWSTR lpLoop = lpStr;
2724 if ((lpStr == 0) || (lpSet == 0)) return 0;
2726 /* while(*lpLoop) { if lpLoop++; } */
2728 for(; (*lpLoop != 0); lpLoop++)
2729 if( strchrW(lpSet, *(WORD*)lpLoop))
2730 return (INT)(lpLoop-lpStr);
2732 return (INT)(lpLoop-lpStr);
2735 /**************************************************************************
2738 * FIXME: What's this supposed to do?
2739 * Parameter 1 is an HWND, you're on your own for the rest.
2742 BOOL WINAPI COMCTL32_410( HWND hw, DWORD b, DWORD c, DWORD d) {
2744 FIXME("(%x, %lx, %lx, %lx): stub!\n", hw, b, c, d);
2749 /**************************************************************************
2752 * FIXME: What's this supposed to do?
2753 * Parameter 1 is an HWND, you're on your own for the rest.
2756 BOOL WINAPI COMCTL32_411( HWND hw, DWORD b, DWORD c) {
2758 FIXME("(%x, %lx, %lx): stub!\n", hw, b, c);
2763 /**************************************************************************
2766 * FIXME: What's this supposed to do?
2767 * Parameter 1 is an HWND, you're on your own for the rest.
2770 BOOL WINAPI COMCTL32_412( HWND hwnd, DWORD b, DWORD c)
2772 FIXME("(%x, %lx, %lx): stub!\n", hwnd, b, c);
2774 if (IsWindow (hwnd) == FALSE)
2784 /**************************************************************************
2787 * FIXME: What's this supposed to do?
2788 * Parameter 1 is an HWND, you're on your own for the rest.
2791 BOOL WINAPI COMCTL32_413( HWND hw, DWORD b, DWORD c, DWORD d) {
2793 FIXME("(%x, %lx, %lx, %lx): stub!\n", hw, b, c, d);
2799 /**************************************************************************
2802 * FIXME: What's this supposed to do?
2803 * Parameter 1 is an HWND, you're on your own for the rest.
2806 BOOL WINAPI COMCTL32_415( HWND hwnd, DWORD b, DWORD c, DWORD d, DWORD e)
2809 FIXME("(%x, %lx, %lx, %lx, %lx): stub!\n", hwnd, b, c, d, e);
2814 /**************************************************************************
2817 * FIXME: What's this supposed to do?
2820 BOOL WINAPI COMCTL32_419( DWORD a, DWORD b, DWORD c, DWORD d)
2823 FIXME("(%lx, %lx, %lx, %lx): stub!\n", a, b, c, d);