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 INT __cdecl _wtoi(LPWSTR string);
72 /**************************************************************************
73 * DPA_LoadStream [COMCTL32.9]
75 * Loads a dynamic pointer array from a stream
78 * phDpa [O] pointer to a handle to a dynamic pointer array
79 * loadProc [I] pointer to a callback function
80 * pStream [I] pointer to a stream
81 * lParam [I] application specific value
84 * No more information available yet!
88 DPA_LoadStream (HDPA *phDpa, DPALOADPROC loadProc, IStream *pStream, LPARAM lParam)
91 LARGE_INTEGER position;
92 ULARGE_INTEGER newPosition;
93 STREAMDATA streamData;
99 FIXME ("phDpa=%p loadProc=%p pStream=%p lParam=%lx\n",
100 phDpa, loadProc, pStream, lParam);
102 if (!phDpa || !loadProc || !pStream)
107 position.s.LowPart = 0;
108 position.s.HighPart = 0;
111 * Zero out our streamData
113 memset(&streamData,0,sizeof(STREAMDATA));
115 errCode = IStream_Seek (pStream, position, STREAM_SEEK_CUR, &newPosition);
119 errCode = IStream_Read (pStream, &streamData, sizeof(STREAMDATA), &ulRead);
123 FIXME ("dwSize=%lu dwData2=%lu dwItems=%lu\n",
124 streamData.dwSize, streamData.dwData2, streamData.dwItems);
126 if ( ulRead < sizeof(STREAMDATA) ||
127 lParam < sizeof(STREAMDATA) ||
128 streamData.dwSize < sizeof(STREAMDATA) ||
129 streamData.dwData2 < 1) {
133 if (streamData.dwItems > (UINT_MAX / 2 / sizeof(VOID*))) /* 536870911 */
134 return E_OUTOFMEMORY;
137 hDpa = DPA_Create (streamData.dwItems);
139 return E_OUTOFMEMORY;
141 if (!DPA_Grow (hDpa, streamData.dwItems))
142 return E_OUTOFMEMORY;
144 /* load data from the stream into the dpa */
146 for (loadData.nCount = 0; loadData.nCount < streamData.dwItems; loadData.nCount++) {
147 errCode = (loadProc)(&loadData, pStream, lParam);
148 if (errCode != S_OK) {
157 /* set the number of items */
158 hDpa->nItemCount = loadData.nCount;
160 /* store the handle to the dpa */
162 FIXME ("new hDpa=%p\n", hDpa);
168 /**************************************************************************
169 * DPA_SaveStream [COMCTL32.10]
171 * Saves a dynamic pointer array to a stream
174 * hDpa [I] handle to a dynamic pointer array
175 * loadProc [I] pointer to a callback function
176 * pStream [I] pointer to a stream
177 * lParam [I] application specific value
180 * No more information available yet!
184 DPA_SaveStream (const HDPA hDpa, DPALOADPROC loadProc, IStream *pStream, LPARAM lParam)
187 FIXME ("hDpa=%p loadProc=%p pStream=%p lParam=%lx\n",
188 hDpa, loadProc, pStream, lParam);
194 /**************************************************************************
195 * DPA_Merge [COMCTL32.11]
198 * hdpa1 [I] handle to a dynamic pointer array
199 * hdpa2 [I] handle to a dynamic pointer array
201 * pfnCompare [I] pointer to sort function
202 * pfnMerge [I] pointer to merge function
203 * lParam [I] application specific value
206 * No more information available yet!
210 DPA_Merge (const HDPA hdpa1, const HDPA hdpa2, DWORD dwFlags,
211 PFNDPACOMPARE pfnCompare, PFNDPAMERGE pfnMerge, LPARAM lParam)
214 LPVOID *pWork1, *pWork2;
218 TRACE("%p %p %08lx %p %p %08lx)\n",
219 hdpa1, hdpa2, dwFlags, pfnCompare, pfnMerge, lParam);
221 if (IsBadWritePtr (hdpa1, sizeof(DPA)))
224 if (IsBadWritePtr (hdpa2, sizeof(DPA)))
227 if (IsBadCodePtr ((FARPROC)pfnCompare))
230 if (IsBadCodePtr ((FARPROC)pfnMerge))
233 if (!(dwFlags & DPAM_NOSORT)) {
234 TRACE("sorting dpa's!\n");
235 if (hdpa1->nItemCount > 0)
236 DPA_Sort (hdpa1, pfnCompare, lParam);
237 TRACE ("dpa 1 sorted!\n");
238 if (hdpa2->nItemCount > 0)
239 DPA_Sort (hdpa2, pfnCompare, lParam);
240 TRACE ("dpa 2 sorted!\n");
243 if (hdpa2->nItemCount < 1)
246 TRACE("hdpa1->nItemCount=%d hdpa2->nItemCount=%d\n",
247 hdpa1->nItemCount, hdpa2->nItemCount);
250 /* working but untrusted implementation */
252 pWork1 = &(hdpa1->ptrs[hdpa1->nItemCount - 1]);
253 pWork2 = &(hdpa2->ptrs[hdpa2->nItemCount - 1]);
255 nIndex = hdpa1->nItemCount - 1;
256 nCount = hdpa2->nItemCount - 1;
261 if ((nCount >= 0) && (dwFlags & DPAM_INSERT)) {
262 /* Now insert the remaining new items into DPA 1 */
263 TRACE("%d items to be inserted at start of DPA 1\n",
265 for (i=nCount; i>=0; i--) {
268 ptr = (pfnMerge)(3, *pWork2, NULL, lParam);
271 DPA_InsertPtr (hdpa1, 0, ptr);
277 nResult = (pfnCompare)(*pWork1, *pWork2, lParam);
278 TRACE("compare result=%d, dpa1.cnt=%d, dpa2.cnt=%d\n",
279 nResult, nIndex, nCount);
285 ptr = (pfnMerge)(1, *pWork1, *pWork2, lParam);
295 else if (nResult > 0)
297 /* item in DPA 1 missing from DPA 2 */
298 if (dwFlags & DPAM_DELETE)
300 /* Now delete the extra item in DPA1 */
303 ptr = DPA_DeletePtr (hdpa1, hdpa1->nItemCount - 1);
305 (pfnMerge)(2, ptr, NULL, lParam);
312 /* new item in DPA 2 */
313 if (dwFlags & DPAM_INSERT)
315 /* Now insert the new item in DPA 1 */
318 ptr = (pfnMerge)(3, *pWork2, NULL, lParam);
321 DPA_InsertPtr (hdpa1, nIndex+1, ptr);
334 /**************************************************************************
335 * Alloc [COMCTL32.71]
337 * Allocates memory block from the dll's private heap
340 * dwSize [I] size of the allocated memory block
343 * Success: pointer to allocated memory block
348 COMCTL32_Alloc (DWORD dwSize)
352 TRACE("(0x%lx)\n", dwSize);
354 lpPtr = HeapAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, dwSize);
356 TRACE("-- ret=%p\n", lpPtr);
362 /**************************************************************************
363 * ReAlloc [COMCTL32.72]
365 * Changes the size of an allocated memory block or allocates a memory
366 * block using the dll's private heap.
369 * lpSrc [I] pointer to memory block which will be resized
370 * dwSize [I] new size of the memory block.
373 * Success: pointer to the resized memory block
377 * If lpSrc is a NULL-pointer, then COMCTL32_ReAlloc allocates a memory
378 * block like COMCTL32_Alloc.
382 COMCTL32_ReAlloc (LPVOID lpSrc, DWORD dwSize)
386 TRACE("(%p 0x%08lx)\n", lpSrc, dwSize);
389 lpDest = HeapReAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, lpSrc, dwSize);
391 lpDest = HeapAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, dwSize);
393 TRACE("-- ret=%p\n", lpDest);
399 /**************************************************************************
402 * Frees an allocated memory block from the dll's private heap.
405 * lpMem [I] pointer to memory block which will be freed
413 COMCTL32_Free (LPVOID lpMem)
415 TRACE("(%p)\n", lpMem);
417 return HeapFree (COMCTL32_hHeap, 0, lpMem);
421 /**************************************************************************
422 * GetSize [COMCTL32.74]
424 * Retrieves the size of the specified memory block from the dll's
428 * lpMem [I] pointer to an allocated memory block
431 * Success: size of the specified memory block
436 COMCTL32_GetSize (LPVOID lpMem)
438 TRACE("(%p)\n", lpMem);
440 return HeapSize (COMCTL32_hHeap, 0, lpMem);
444 /**************************************************************************
445 * The MRU-API is a set of functions to manipulate MRU(Most Recently Used)
448 * Stored in the reg. as a set of values under a single key. Each item in the
449 * list has a value name that is a single char. 'a' - 'z', '{', '|' or '}'.
450 * The order of the list is stored with value name 'MRUList' which is a string
451 * containing the value names (i.e. 'a', 'b', etc.) in the relevant order.
454 typedef struct tagCREATEMRULISTA
456 DWORD cbSize; /* size of struct */
457 DWORD nMaxItems; /* max no. of items in list */
458 DWORD dwFlags; /* see below */
459 HKEY hKey; /* root reg. key under which list is saved */
460 LPCSTR lpszSubKey; /* reg. subkey */
461 PROC lpfnCompare; /* item compare proc */
462 } CREATEMRULISTA, *LPCREATEMRULISTA;
464 typedef struct tagCREATEMRULISTW
466 DWORD cbSize; /* size of struct */
467 DWORD nMaxItems; /* max no. of items in list */
468 DWORD dwFlags; /* see below */
469 HKEY hKey; /* root reg. key under which list is saved */
470 LPCWSTR lpszSubKey; /* reg. subkey */
471 PROC lpfnCompare; /* item compare proc */
472 } CREATEMRULISTW, *LPCREATEMRULISTW;
475 #define MRUF_STRING_LIST 0 /* list will contain strings */
476 #define MRUF_BINARY_LIST 1 /* list will contain binary data */
477 #define MRUF_DELAYED_SAVE 2 /* only save list order to reg. is FreeMRUList */
479 /* If list is a string list lpfnCompare has the following prototype
480 * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
481 * for binary lists the prototype is
482 * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
483 * where cbData is the no. of bytes to compare.
484 * Need to check what return value means identical - 0?
487 typedef struct tagWINEMRUITEM
489 DWORD size; /* size of data stored */
490 DWORD itemFlag; /* flags */
492 } WINEMRUITEM, *LPWINEMRUITEM;
495 #define WMRUIF_CHANGED 0x0001 /* this dataitem changed */
497 typedef struct tagWINEMRULIST
499 CREATEMRULISTW extview; /* original create information */
500 BOOL isUnicode; /* is compare fn Unicode */
501 DWORD wineFlags; /* internal flags */
502 DWORD cursize; /* current size of realMRU */
503 LPSTR realMRU; /* pointer to string of index names */
504 LPWINEMRUITEM *array; /* array of pointers to data */
505 /* in 'a' to 'z' order */
506 } WINEMRULIST, *LPWINEMRULIST;
509 #define WMRUF_CHANGED 0x0001 /* MRU list has changed */
511 /**************************************************************************
512 * MRU_SaveChanged - Localize MRU saving code
515 VOID MRU_SaveChanged( LPWINEMRULIST mp )
521 WCHAR emptyW[] = {'\0'};
523 /* or should we do the following instead of RegOpenKeyEx:
526 /* open the sub key */
527 if ((err = RegOpenKeyExW( mp->extview.hKey, mp->extview.lpszSubKey,
528 0, KEY_WRITE, &newkey))) {
529 /* not present - what to do ??? */
530 ERR("Can not open key, error=%d, attempting to create\n",
532 if ((err = RegCreateKeyExW( mp->extview.hKey, mp->extview.lpszSubKey,
535 REG_OPTION_NON_VOLATILE,
536 KEY_READ | KEY_WRITE,
540 ERR("failed to create key /%s/, err=%d\n",
541 debugstr_w(mp->extview.lpszSubKey), err);
545 if (mp->wineFlags & WMRUF_CHANGED) {
546 mp->wineFlags &= ~WMRUF_CHANGED;
547 err = RegSetValueExA(newkey, "MRUList", 0, REG_SZ,
548 mp->realMRU, strlen(mp->realMRU) + 1);
550 ERR("error saving MRUList, err=%d\n", err);
552 TRACE("saving MRUList=/%s/\n", mp->realMRU);
555 for(i=0; i<mp->cursize; i++) {
556 witem = mp->array[i];
557 if (witem->itemFlag & WMRUIF_CHANGED) {
558 witem->itemFlag &= ~WMRUIF_CHANGED;
559 realname[0] = 'a' + i;
560 err = RegSetValueExW(newkey, realname, 0,
561 (mp->extview.dwFlags & MRUF_BINARY_LIST) ?
563 &witem->datastart, witem->size);
565 ERR("error saving /%s/, err=%d\n", debugstr_w(realname), err);
567 TRACE("saving value for name /%s/ size=%ld\n",
568 debugstr_w(realname), witem->size);
571 RegCloseKey( newkey );
574 /**************************************************************************
575 * FreeMRUList [COMCTL32.152]
578 * hMRUList [I] Handle to list.
582 FreeMRUList (HANDLE hMRUList)
584 LPWINEMRULIST mp = (LPWINEMRULIST)hMRUList;
588 if (mp->wineFlags & WMRUF_CHANGED) {
589 /* need to open key and then save the info */
590 MRU_SaveChanged( mp );
593 for(i=0; i<mp->extview.nMaxItems; i++) {
595 COMCTL32_Free(mp->array[i]);
597 COMCTL32_Free(mp->realMRU);
598 COMCTL32_Free(mp->array);
599 COMCTL32_Free((LPWSTR)mp->extview.lpszSubKey);
600 return COMCTL32_Free(mp);
604 /**************************************************************************
605 * FindMRUData [COMCTL32.169]
607 * Searches binary list for item that matches lpData of length cbData.
608 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
609 * corresponding to item's reg. name will be stored in it ('a' -> 0).
612 * hList [I] list handle
613 * lpData [I] data to find
614 * cbData [I] length of data
615 * lpRegNum [O] position in registry (maybe NULL)
618 * Position in list 0 -> MRU. -1 if item not found.
621 FindMRUData (HANDLE hList, LPCVOID lpData, DWORD cbData, LPINT lpRegNum)
623 LPWINEMRULIST mp = (LPWINEMRULIST)hList;
627 if (!mp->extview.lpfnCompare) {
628 ERR("MRU list not properly created. No compare procedure.\n");
632 if(!(mp->extview.dwFlags & MRUF_BINARY_LIST) && !mp->isUnicode) {
633 DWORD len = WideCharToMultiByte(CP_ACP, 0, lpData, -1,
634 NULL, 0, NULL, NULL);
635 dataA = COMCTL32_Alloc(len);
636 WideCharToMultiByte(CP_ACP, 0, lpData, -1, dataA, len, NULL, NULL);
639 for(i=0; i<mp->cursize; i++) {
640 if (mp->extview.dwFlags & MRUF_BINARY_LIST) {
641 if (!mp->extview.lpfnCompare(lpData, &mp->array[i]->datastart,
647 if (!mp->extview.lpfnCompare(lpData, &mp->array[i]->datastart))
650 DWORD len = WideCharToMultiByte(CP_ACP, 0,
651 (LPWSTR)&mp->array[i]->datastart, -1,
652 NULL, 0, NULL, NULL);
653 LPSTR itemA = COMCTL32_Alloc(len);
655 WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&mp->array[i]->datastart, -1,
656 itemA, len, NULL, NULL);
658 cmp = mp->extview.lpfnCompare(dataA, itemA);
659 COMCTL32_Free(itemA);
666 COMCTL32_Free(dataA);
671 if (lpRegNum && (ret != -1))
674 TRACE("(%08x, %p, %ld, %p) returning %d\n",
675 hList, lpData, cbData, lpRegNum, ret);
681 /**************************************************************************
682 * AddMRUData [COMCTL32.167]
684 * Add item to MRU binary list. If item already exists in list then it is
685 * simply moved up to the top of the list and not added again. If list is
686 * full then the least recently used item is removed to make room.
689 * hList [I] Handle to list.
690 * lpData [I] ptr to data to add.
691 * cbData [I] no. of bytes of data.
694 * No. corresponding to registry name where value is stored 'a' -> 0 etc.
698 AddMRUData (HANDLE hList, LPCVOID lpData, DWORD cbData)
700 LPWINEMRULIST mp = (LPWINEMRULIST)hList;
704 if ((replace = FindMRUData (hList, lpData, cbData, NULL)) < 0) {
705 /* either add a new entry or replace oldest */
706 if (mp->cursize < mp->extview.nMaxItems) {
707 /* Add in a new item */
708 replace = mp->cursize;
712 /* get the oldest entry and replace data */
713 replace = mp->realMRU[mp->cursize - 1] - 'a';
714 COMCTL32_Free(mp->array[replace]);
718 /* free up the old data */
719 COMCTL32_Free(mp->array[replace]);
722 /* Allocate space for new item and move in the data */
723 mp->array[replace] = witem = (LPWINEMRUITEM)COMCTL32_Alloc(cbData +
724 sizeof(WINEMRUITEM));
725 witem->itemFlag |= WMRUIF_CHANGED;
726 witem->size = cbData;
727 memcpy( &witem->datastart, lpData, cbData);
729 /* now rotate MRU list */
730 mp->wineFlags |= WMRUF_CHANGED;
731 for(i=mp->cursize-1; i>=1; i--) {
732 mp->realMRU[i] = mp->realMRU[i-1];
734 mp->realMRU[0] = replace + 'a';
735 TRACE("(%08x, %p, %ld) adding data, /%c/ now most current\n",
736 hList, lpData, cbData, replace+'a');
739 if (!(mp->extview.dwFlags & MRUF_DELAYED_SAVE)) {
740 /* save changed stuff right now */
741 MRU_SaveChanged( mp );
747 /**************************************************************************
748 * AddMRUStringW [COMCTL32.401]
750 * Add item to MRU string list. If item already exists in list them it is
751 * simply moved up to the top of the list and not added again. If list is
752 * full then the least recently used item is removed to make room.
755 * hList [I] Handle to list.
756 * lpszString [I] ptr to string to add.
759 * No. corresponding to registry name where value is stored 'a' -> 0 etc.
763 AddMRUStringW(HANDLE hList, LPCWSTR lpszString)
765 FIXME("(%08x, %s) empty stub!\n", hList, debugstr_w(lpszString));
770 /**************************************************************************
771 * AddMRUStringA [COMCTL32.153]
774 AddMRUStringA(HANDLE hList, LPCSTR lpszString)
776 FIXME("(%08x, %s) empty stub!\n", hList, debugstr_a(lpszString));
781 /**************************************************************************
782 * DelMRUString [COMCTL32.156]
784 * Removes item from either string or binary list (despite its name)
787 * hList [I] list handle
788 * nItemPos [I] item position to remove 0 -> MRU
791 * TRUE if successful, FALSE if nItemPos is out of range.
794 DelMRUString(HANDLE hList, INT nItemPos)
796 FIXME("(%08x, %d): stub\n", hList, nItemPos);
800 /**************************************************************************
801 * FindMRUStringW [COMCTL32.402]
804 FindMRUStringW (HANDLE hList, LPCWSTR lpszString, LPINT lpRegNum)
810 /**************************************************************************
811 * FindMRUStringA [COMCTL32.155]
813 * Searches string list for item that matches lpszString.
814 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
815 * corresponding to item's reg. name will be stored in it ('a' -> 0).
818 * hList [I] list handle
819 * lpszString [I] string to find
820 * lpRegNum [O] position in registry (maybe NULL)
823 * Position in list 0 -> MRU. -1 if item not found.
826 FindMRUStringA (HANDLE hList, LPCSTR lpszString, LPINT lpRegNum)
828 DWORD len = MultiByteToWideChar(CP_ACP, 0, lpszString, -1, NULL, 0);
829 LPWSTR stringW = COMCTL32_Alloc(len * sizeof(WCHAR));
832 MultiByteToWideChar(CP_ACP, 0, lpszString, -1, stringW, len);
833 ret = FindMRUData(hList, stringW, len * sizeof(WCHAR), lpRegNum);
834 COMCTL32_Free(stringW);
838 /*************************************************************************
839 * CreateMRUListLazy_common
841 HANDLE CreateMRUListLazy_common(LPWINEMRULIST mp)
845 DWORD datasize, dwdisp;
849 WCHAR emptyW[] = {'\0'};
851 /* get space to save indices that will turn into names
852 * but in order of most to least recently used
854 mp->realMRU = (LPSTR) COMCTL32_Alloc(mp->extview.nMaxItems + 2);
856 /* get space to save pointers to actual data in order of
857 * 'a' to 'z' (0 to n).
859 mp->array = (LPVOID) COMCTL32_Alloc(mp->extview.nMaxItems *
862 /* open the sub key */
863 if ((err = RegCreateKeyExW( mp->extview.hKey, mp->extview.lpszSubKey,
866 REG_OPTION_NON_VOLATILE,
867 KEY_READ | KEY_WRITE,
871 /* error - what to do ??? */
872 ERR("(%lu %lu %lx %lx \"%s\" %p): Can not open key, error=%d\n",
873 mp->extview.cbSize, mp->extview.nMaxItems, mp->extview.dwFlags,
874 (DWORD)mp->extview.hKey, debugstr_w(mp->extview.lpszSubKey),
875 mp->extview.lpfnCompare, err);
879 /* get values from key 'MRUList' */
881 datasize = mp->extview.nMaxItems + 1;
882 if((err=RegQueryValueExA( newkey, "MRUList", 0, &type, mp->realMRU,
884 /* not present - set size to 1 (will become 0 later) */
889 TRACE("MRU list = %s\n", mp->realMRU);
891 mp->cursize = datasize - 1;
892 /* datasize now has number of items in the MRUList */
894 /* get actual values for each entry */
896 for(i=0; i<mp->cursize; i++) {
897 realname[0] = 'a' + i;
898 if(RegQueryValueExW( newkey, realname, 0, &type, 0, &datasize)) {
899 /* not present - what to do ??? */
900 ERR("Key %s not found 1\n", debugstr_w(realname));
902 mp->array[i] = witem = (LPWINEMRUITEM)COMCTL32_Alloc(datasize +
903 sizeof(WINEMRUITEM));
904 witem->size = datasize;
905 if(RegQueryValueExW( newkey, realname, 0, &type,
906 &witem->datastart, &datasize)) {
907 /* not present - what to do ??? */
908 ERR("Key %s not found 2\n", debugstr_w(realname));
911 RegCloseKey( newkey );
916 TRACE("(%lu %lu %lx %lx \"%s\" %p): Current Size = %ld\n",
917 mp->extview.cbSize, mp->extview.nMaxItems, mp->extview.dwFlags,
918 (DWORD)mp->extview.hKey, debugstr_w(mp->extview.lpszSubKey),
919 mp->extview.lpfnCompare, mp->cursize);
923 /**************************************************************************
924 * CreateMRUListLazyW [COMCTL32.404]
927 CreateMRUListLazyW (LPCREATEMRULISTW lpcml, DWORD dwParam2, DWORD dwParam3, DWORD dwParam4)
934 if (lpcml->cbSize < sizeof(CREATEMRULISTW))
937 mp = (LPWINEMRULIST) COMCTL32_Alloc(sizeof(WINEMRULIST));
938 memcpy(&mp->extview, lpcml, sizeof(CREATEMRULISTW));
939 mp->extview.lpszSubKey = COMCTL32_Alloc((strlenW(lpcml->lpszSubKey) + 1) *
941 strcpyW((LPWSTR)mp->extview.lpszSubKey, lpcml->lpszSubKey);
942 mp->isUnicode = TRUE;
944 return CreateMRUListLazy_common(mp);
947 /**************************************************************************
948 * CreateMRUListLazyA [COMCTL32.157]
951 CreateMRUListLazyA (LPCREATEMRULISTA lpcml, DWORD dwParam2, DWORD dwParam3, DWORD dwParam4)
959 if (lpcml->cbSize < sizeof(CREATEMRULISTA))
962 mp = (LPWINEMRULIST) COMCTL32_Alloc(sizeof(WINEMRULIST));
963 memcpy(&mp->extview, lpcml, sizeof(CREATEMRULISTW));
964 len = MultiByteToWideChar(CP_ACP, 0, lpcml->lpszSubKey, -1, NULL, 0);
965 mp->extview.lpszSubKey = COMCTL32_Alloc(len * sizeof(WCHAR));
966 MultiByteToWideChar(CP_ACP, 0, lpcml->lpszSubKey, -1,
967 (LPWSTR)mp->extview.lpszSubKey, len);
968 mp->isUnicode = FALSE;
969 return CreateMRUListLazy_common(mp);
972 /**************************************************************************
973 * CreateMRUListW [COMCTL32.400]
976 * lpcml [I] ptr to CREATEMRULIST structure.
979 * Handle to MRU list.
982 CreateMRUListW (LPCREATEMRULISTW lpcml)
984 return CreateMRUListLazyW(lpcml, 0, 0, 0);
987 /**************************************************************************
988 * CreateMRUListA [COMCTL32.151]
991 CreateMRUListA (LPCREATEMRULISTA lpcml)
993 return CreateMRUListLazyA (lpcml, 0, 0, 0);
997 /**************************************************************************
998 * EnumMRUListW [COMCTL32.403]
1000 * Enumerate item in a list
1003 * hList [I] list handle
1004 * nItemPos [I] item position to enumerate
1005 * lpBuffer [O] buffer to receive item
1006 * nBufferSize [I] size of buffer
1009 * For binary lists specifies how many bytes were copied to buffer, for
1010 * string lists specifies full length of string. Enumerating past the end
1011 * of list returns -1.
1012 * If lpBuffer == NULL or nItemPos is -ve return value is no. of items in
1015 INT WINAPI EnumMRUListW(HANDLE hList, INT nItemPos, LPVOID lpBuffer,
1018 LPWINEMRULIST mp = (LPWINEMRULIST) hList;
1019 LPWINEMRUITEM witem;
1020 INT desired, datasize;
1022 if (nItemPos >= mp->cursize) return -1;
1023 if ((nItemPos < 0) || !lpBuffer) return mp->cursize;
1024 desired = mp->realMRU[nItemPos];
1026 TRACE("nItemPos=%d, desired=%d\n", nItemPos, desired);
1027 witem = mp->array[desired];
1028 datasize = min( witem->size, nBufferSize );
1029 memcpy( lpBuffer, &witem->datastart, datasize);
1030 TRACE("(%08x, %d, %p, %ld): returning len=%d\n",
1031 hList, nItemPos, lpBuffer, nBufferSize, datasize);
1035 /**************************************************************************
1036 * EnumMRUListA [COMCTL32.154]
1039 INT WINAPI EnumMRUListA(HANDLE hList, INT nItemPos, LPVOID lpBuffer,
1042 LPWINEMRULIST mp = (LPWINEMRULIST) hList;
1043 LPWINEMRUITEM witem;
1044 INT desired, datasize;
1047 if (nItemPos >= mp->cursize) return -1;
1048 if ((nItemPos < 0) || !lpBuffer) return mp->cursize;
1049 desired = mp->realMRU[nItemPos];
1051 TRACE("nItemPos=%d, desired=%d\n", nItemPos, desired);
1052 witem = mp->array[desired];
1053 if(mp->extview.dwFlags & MRUF_BINARY_LIST) {
1054 datasize = min( witem->size, nBufferSize );
1055 memcpy( lpBuffer, &witem->datastart, datasize);
1057 lenA = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&witem->datastart, -1,
1058 NULL, 0, NULL, NULL);
1059 datasize = min( witem->size, nBufferSize );
1060 WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&witem->datastart, -1,
1061 lpBuffer, datasize, NULL, NULL);
1063 TRACE("(%08x, %d, %p, %ld): returning len=%d\n",
1064 hList, nItemPos, lpBuffer, nBufferSize, datasize);
1069 /**************************************************************************
1070 * Str_GetPtrA [COMCTL32.233]
1081 Str_GetPtrA (LPCSTR lpSrc, LPSTR lpDest, INT nMaxLen)
1085 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
1087 if (!lpDest && lpSrc)
1088 return strlen (lpSrc);
1093 if (lpSrc == NULL) {
1098 len = strlen (lpSrc);
1102 RtlMoveMemory (lpDest, lpSrc, len);
1109 /**************************************************************************
1110 * Str_SetPtrA [COMCTL32.234]
1120 Str_SetPtrA (LPSTR *lppDest, LPCSTR lpSrc)
1122 TRACE("(%p %p)\n", lppDest, lpSrc);
1125 LPSTR ptr = COMCTL32_ReAlloc (*lppDest, strlen (lpSrc) + 1);
1128 strcpy (ptr, lpSrc);
1133 COMCTL32_Free (*lppDest);
1142 /**************************************************************************
1143 * Str_GetPtrW [COMCTL32.235]
1154 Str_GetPtrW (LPCWSTR lpSrc, LPWSTR lpDest, INT nMaxLen)
1158 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
1160 if (!lpDest && lpSrc)
1161 return strlenW (lpSrc);
1166 if (lpSrc == NULL) {
1171 len = strlenW (lpSrc);
1175 RtlMoveMemory (lpDest, lpSrc, len*sizeof(WCHAR));
1176 lpDest[len] = L'\0';
1182 /**************************************************************************
1183 * Str_SetPtrW [COMCTL32.236]
1193 Str_SetPtrW (LPWSTR *lppDest, LPCWSTR lpSrc)
1195 TRACE("(%p %p)\n", lppDest, lpSrc);
1198 INT len = strlenW (lpSrc) + 1;
1199 LPWSTR ptr = COMCTL32_ReAlloc (*lppDest, len * sizeof(WCHAR));
1202 strcpyW (ptr, lpSrc);
1207 COMCTL32_Free (*lppDest);
1216 /**************************************************************************
1217 * Str_GetPtrWtoA [internal]
1219 * Converts a unicode string into a multi byte string
1222 * lpSrc [I] Pointer to the unicode source string
1223 * lpDest [O] Pointer to caller supplied storage for the multi byte string
1224 * nMaxLen [I] Size, in bytes, of the destination buffer
1227 * Length, in bytes, of the converted string.
1231 Str_GetPtrWtoA (LPCWSTR lpSrc, LPSTR lpDest, INT nMaxLen)
1235 TRACE("(%s %p %d)\n", debugstr_w(lpSrc), lpDest, nMaxLen);
1237 if (!lpDest && lpSrc)
1238 return WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, 0, 0, NULL, NULL);
1243 if (lpSrc == NULL) {
1248 len = WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, 0, 0, NULL, NULL);
1252 WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, lpDest, len, NULL, NULL);
1259 /**************************************************************************
1260 * Str_SetPtrAtoW [internal]
1262 * Converts a multi byte string to a unicode string.
1263 * If the pointer to the destination buffer is NULL a buffer is allocated.
1264 * If the destination buffer is too small to keep the converted multi byte
1265 * string the destination buffer is reallocated. If the source pointer is
1266 * NULL, the destination buffer is freed.
1269 * lppDest [I/O] pointer to a pointer to the destination buffer
1270 * lpSrc [I] pointer to a multi byte string
1273 * TRUE: conversion successful
1278 Str_SetPtrAtoW (LPWSTR *lppDest, LPCSTR lpSrc)
1280 TRACE("(%p %s)\n", lppDest, lpSrc);
1283 INT len = MultiByteToWideChar(CP_ACP,0,lpSrc,-1,NULL,0);
1284 LPWSTR ptr = COMCTL32_ReAlloc (*lppDest, len*sizeof(WCHAR));
1288 MultiByteToWideChar(CP_ACP,0,lpSrc,-1,ptr,len);
1293 COMCTL32_Free (*lppDest);
1302 /**************************************************************************
1303 * The DSA-API is a set of functions to create and manipulate arrays of
1304 * fixed-size memory blocks. These arrays can store any kind of data
1305 * (strings, icons...).
1308 /**************************************************************************
1309 * DSA_Create [COMCTL32.320] Creates a dynamic storage array
1312 * nSize [I] size of the array elements
1313 * nGrow [I] number of elements by which the array grows when it is filled
1316 * Success: pointer to an array control structure. Use this like a handle.
1321 DSA_Create (INT nSize, INT nGrow)
1325 TRACE("(size=%d grow=%d)\n", nSize, nGrow);
1327 hdsa = (HDSA)COMCTL32_Alloc (sizeof(DSA));
1330 hdsa->nItemCount = 0;
1332 hdsa->nMaxCount = 0;
1333 hdsa->nItemSize = nSize;
1334 hdsa->nGrow = max(1, nGrow);
1341 /**************************************************************************
1342 * DSA_Destroy [COMCTL32.321] Destroys a dynamic storage array
1345 * hdsa [I] pointer to the array control structure
1353 DSA_Destroy (const HDSA hdsa)
1355 TRACE("(%p)\n", hdsa);
1360 if (hdsa->pData && (!COMCTL32_Free (hdsa->pData)))
1363 return COMCTL32_Free (hdsa);
1367 /**************************************************************************
1368 * DSA_GetItem [COMCTL32.322]
1371 * hdsa [I] pointer to the array control structure
1372 * nIndex [I] number of the Item to get
1373 * pDest [O] destination buffer. Has to be >= dwElementSize.
1381 DSA_GetItem (const HDSA hdsa, INT nIndex, LPVOID pDest)
1385 TRACE("(%p %d %p)\n", hdsa, nIndex, pDest);
1389 if ((nIndex < 0) || (nIndex >= hdsa->nItemCount))
1392 pSrc = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1393 memmove (pDest, pSrc, hdsa->nItemSize);
1399 /**************************************************************************
1400 * DSA_GetItemPtr [COMCTL32.323]
1402 * Retrieves a pointer to the specified item.
1405 * hdsa [I] pointer to the array control structure
1406 * nIndex [I] index of the desired item
1409 * Success: pointer to an item
1414 DSA_GetItemPtr (const HDSA hdsa, INT nIndex)
1418 TRACE("(%p %d)\n", hdsa, nIndex);
1422 if ((nIndex < 0) || (nIndex >= hdsa->nItemCount))
1425 pSrc = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1427 TRACE("-- ret=%p\n", pSrc);
1433 /**************************************************************************
1434 * DSA_SetItem [COMCTL32.325]
1436 * Sets the contents of an item in the array.
1439 * hdsa [I] pointer to the array control structure
1440 * nIndex [I] index for the item
1441 * pSrc [I] pointer to the new item data
1449 DSA_SetItem (const HDSA hdsa, INT nIndex, LPVOID pSrc)
1451 INT nSize, nNewItems;
1452 LPVOID pDest, lpTemp;
1454 TRACE("(%p %d %p)\n", hdsa, nIndex, pSrc);
1456 if ((!hdsa) || nIndex < 0)
1459 if (hdsa->nItemCount <= nIndex) {
1460 /* within the old array */
1461 if (hdsa->nMaxCount > nIndex) {
1462 /* within the allocated space, set a new boundary */
1463 hdsa->nItemCount = nIndex + 1;
1466 /* resize the block of memory */
1468 hdsa->nGrow * ((INT)(((nIndex + 1) - 1) / hdsa->nGrow) + 1);
1469 nSize = hdsa->nItemSize * nNewItems;
1471 lpTemp = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
1475 hdsa->nMaxCount = nNewItems;
1476 hdsa->nItemCount = nIndex + 1;
1477 hdsa->pData = lpTemp;
1481 /* put the new entry in */
1482 pDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1483 TRACE("-- move dest=%p src=%p size=%d\n",
1484 pDest, pSrc, hdsa->nItemSize);
1485 memmove (pDest, pSrc, hdsa->nItemSize);
1491 /**************************************************************************
1492 * DSA_InsertItem [COMCTL32.324]
1495 * hdsa [I] pointer to the array control structure
1496 * nIndex [I] index for the new item
1497 * pSrc [I] pointer to the element
1500 * Success: position of the new item
1505 DSA_InsertItem (const HDSA hdsa, INT nIndex, LPVOID pSrc)
1507 INT nNewItems, nSize;
1508 LPVOID lpTemp, lpDest;
1510 TRACE("(%p %d %p)\n", hdsa, nIndex, pSrc);
1512 if ((!hdsa) || nIndex < 0)
1515 /* when nIndex >= nItemCount then append */
1516 if (nIndex >= hdsa->nItemCount)
1517 nIndex = hdsa->nItemCount;
1519 /* do we need to resize ? */
1520 if (hdsa->nItemCount >= hdsa->nMaxCount) {
1521 nNewItems = hdsa->nMaxCount + hdsa->nGrow;
1522 nSize = hdsa->nItemSize * nNewItems;
1524 lpTemp = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
1528 hdsa->nMaxCount = nNewItems;
1529 hdsa->pData = lpTemp;
1532 /* do we need to move elements ? */
1533 if (nIndex < hdsa->nItemCount) {
1534 lpTemp = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1535 lpDest = (char *) lpTemp + hdsa->nItemSize;
1536 nSize = (hdsa->nItemCount - nIndex) * hdsa->nItemSize;
1537 TRACE("-- move dest=%p src=%p size=%d\n",
1538 lpDest, lpTemp, nSize);
1539 memmove (lpDest, lpTemp, nSize);
1542 /* ok, we can put the new Item in */
1544 lpDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1545 TRACE("-- move dest=%p src=%p size=%d\n",
1546 lpDest, pSrc, hdsa->nItemSize);
1547 memmove (lpDest, pSrc, hdsa->nItemSize);
1553 /**************************************************************************
1554 * DSA_DeleteItem [COMCTL32.326]
1557 * hdsa [I] pointer to the array control structure
1558 * nIndex [I] index for the element to delete
1561 * Success: number of the deleted element
1566 DSA_DeleteItem (const HDSA hdsa, INT nIndex)
1568 LPVOID lpDest,lpSrc;
1571 TRACE("(%p %d)\n", hdsa, nIndex);
1575 if (nIndex < 0 || nIndex >= hdsa->nItemCount)
1578 /* do we need to move ? */
1579 if (nIndex < hdsa->nItemCount - 1) {
1580 lpDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1581 lpSrc = (char *) lpDest + hdsa->nItemSize;
1582 nSize = hdsa->nItemSize * (hdsa->nItemCount - nIndex - 1);
1583 TRACE("-- move dest=%p src=%p size=%d\n",
1584 lpDest, lpSrc, nSize);
1585 memmove (lpDest, lpSrc, nSize);
1591 if ((hdsa->nMaxCount - hdsa->nItemCount) >= hdsa->nGrow) {
1592 nSize = hdsa->nItemSize * hdsa->nItemCount;
1594 lpDest = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
1598 hdsa->nMaxCount = hdsa->nItemCount;
1599 hdsa->pData = lpDest;
1606 /**************************************************************************
1607 * DSA_DeleteAllItems [COMCTL32.327]
1609 * Removes all items and reinitializes the array.
1612 * hdsa [I] pointer to the array control structure
1620 DSA_DeleteAllItems (const HDSA hdsa)
1622 TRACE("(%p)\n", hdsa);
1626 if (hdsa->pData && (!COMCTL32_Free (hdsa->pData)))
1629 hdsa->nItemCount = 0;
1631 hdsa->nMaxCount = 0;
1637 /**************************************************************************
1638 * The DPA-API is a set of functions to create and manipulate arrays of
1642 /**************************************************************************
1643 * DPA_Create [COMCTL32.328] Creates a dynamic pointer array
1646 * nGrow [I] number of items by which the array grows when it is filled
1649 * Success: handle (pointer) to the pointer array.
1654 DPA_Create (INT nGrow)
1658 TRACE("(%d)\n", nGrow);
1660 hdpa = (HDPA)COMCTL32_Alloc (sizeof(DPA));
1662 hdpa->nGrow = max(8, nGrow);
1663 hdpa->hHeap = COMCTL32_hHeap;
1664 hdpa->nMaxCount = hdpa->nGrow * 2;
1666 (LPVOID*)COMCTL32_Alloc (hdpa->nMaxCount * sizeof(LPVOID));
1669 TRACE("-- %p\n", hdpa);
1675 /**************************************************************************
1676 * DPA_Destroy [COMCTL32.329] Destroys a dynamic pointer array
1679 * hdpa [I] handle (pointer) to the pointer array
1687 DPA_Destroy (const HDPA hdpa)
1689 TRACE("(%p)\n", hdpa);
1694 if (hdpa->ptrs && (!HeapFree (hdpa->hHeap, 0, hdpa->ptrs)))
1697 return HeapFree (hdpa->hHeap, 0, hdpa);
1701 /**************************************************************************
1702 * DPA_Grow [COMCTL32.330]
1704 * Sets the growth amount.
1707 * hdpa [I] handle (pointer) to the existing (source) pointer array
1708 * nGrow [I] number of items by which the array grows when it's too small
1716 DPA_Grow (const HDPA hdpa, INT nGrow)
1718 TRACE("(%p %d)\n", hdpa, nGrow);
1723 hdpa->nGrow = max(8, nGrow);
1729 /**************************************************************************
1730 * DPA_Clone [COMCTL32.331]
1732 * Copies a pointer array to an other one or creates a copy
1735 * hdpa [I] handle (pointer) to the existing (source) pointer array
1736 * hdpaNew [O] handle (pointer) to the destination pointer array
1739 * Success: pointer to the destination pointer array.
1743 * - If the 'hdpaNew' is a NULL-Pointer, a copy of the source pointer
1744 * array will be created and it's handle (pointer) is returned.
1745 * - If 'hdpa' is a NULL-Pointer, the original implementation crashes,
1746 * this implementation just returns NULL.
1750 DPA_Clone (const HDPA hdpa, const HDPA hdpaNew)
1752 INT nNewItems, nSize;
1758 TRACE("(%p %p)\n", hdpa, hdpaNew);
1761 /* create a new DPA */
1762 hdpaTemp = (HDPA)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1764 hdpaTemp->hHeap = hdpa->hHeap;
1765 hdpaTemp->nGrow = hdpa->nGrow;
1770 if (hdpaTemp->ptrs) {
1771 /* remove old pointer array */
1772 HeapFree (hdpaTemp->hHeap, 0, hdpaTemp->ptrs);
1773 hdpaTemp->ptrs = NULL;
1774 hdpaTemp->nItemCount = 0;
1775 hdpaTemp->nMaxCount = 0;
1778 /* create a new pointer array */
1779 nNewItems = hdpaTemp->nGrow *
1780 ((INT)((hdpa->nItemCount - 1) / hdpaTemp->nGrow) + 1);
1781 nSize = nNewItems * sizeof(LPVOID);
1783 (LPVOID*)HeapAlloc (hdpaTemp->hHeap, HEAP_ZERO_MEMORY, nSize);
1784 hdpaTemp->nMaxCount = nNewItems;
1786 /* clone the pointer array */
1787 hdpaTemp->nItemCount = hdpa->nItemCount;
1788 memmove (hdpaTemp->ptrs, hdpa->ptrs,
1789 hdpaTemp->nItemCount * sizeof(LPVOID));
1795 /**************************************************************************
1796 * DPA_GetPtr [COMCTL32.332]
1798 * Retrieves a pointer from a dynamic pointer array
1801 * hdpa [I] handle (pointer) to the pointer array
1802 * nIndex [I] array index of the desired pointer
1810 DPA_GetPtr (const HDPA hdpa, INT i)
1812 TRACE("(%p %d)\n", hdpa, i);
1817 WARN("no pointer array.\n");
1820 if ((i < 0) || (i >= hdpa->nItemCount)) {
1821 WARN("not enough pointers in array (%d vs %d).\n",i,hdpa->nItemCount);
1825 TRACE("-- %p\n", hdpa->ptrs[i]);
1827 return hdpa->ptrs[i];
1831 /**************************************************************************
1832 * DPA_GetPtrIndex [COMCTL32.333]
1834 * Retrieves the index of the specified pointer
1837 * hdpa [I] handle (pointer) to the pointer array
1841 * Success: index of the specified pointer
1846 DPA_GetPtrIndex (const HDPA hdpa, LPVOID p)
1853 for (i = 0; i < hdpa->nItemCount; i++) {
1854 if (hdpa->ptrs[i] == p)
1862 /**************************************************************************
1863 * DPA_InsertPtr [COMCTL32.334]
1865 * Inserts a pointer into a dynamic pointer array
1868 * hdpa [I] handle (pointer) to the array
1870 * p [I] pointer to insert
1873 * Success: index of the inserted pointer
1878 DPA_InsertPtr (const HDPA hdpa, INT i, LPVOID p)
1880 INT nNewItems, nSize, nIndex = 0;
1881 LPVOID *lpTemp, *lpDest;
1883 TRACE("(%p %d %p)\n", hdpa, i, p);
1885 if ((!hdpa) || (i < 0))
1890 (LPVOID*)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1891 2 * hdpa->nGrow * sizeof(LPVOID));
1894 hdpa->nMaxCount = hdpa->nGrow * 2;
1898 if (hdpa->nItemCount >= hdpa->nMaxCount) {
1899 TRACE("-- resizing\n");
1900 nNewItems = hdpa->nMaxCount + hdpa->nGrow;
1901 nSize = nNewItems * sizeof(LPVOID);
1903 lpTemp = (LPVOID*)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1907 hdpa->nMaxCount = nNewItems;
1908 hdpa->ptrs = lpTemp;
1911 if (i >= hdpa->nItemCount) {
1912 nIndex = hdpa->nItemCount;
1913 TRACE("-- appending at %d\n", nIndex);
1916 TRACE("-- inserting at %d\n", i);
1917 lpTemp = hdpa->ptrs + i;
1918 lpDest = lpTemp + 1;
1919 nSize = (hdpa->nItemCount - i) * sizeof(LPVOID);
1920 TRACE("-- move dest=%p src=%p size=%x\n",
1921 lpDest, lpTemp, nSize);
1922 memmove (lpDest, lpTemp, nSize);
1929 hdpa->ptrs[nIndex] = p;
1935 /**************************************************************************
1936 * DPA_SetPtr [COMCTL32.335]
1938 * Sets a pointer in the pointer array
1941 * hdpa [I] handle (pointer) to the pointer array
1942 * i [I] index of the pointer that will be set
1943 * p [I] pointer to be set
1951 DPA_SetPtr (const HDPA hdpa, INT i, LPVOID p)
1955 TRACE("(%p %d %p)\n", hdpa, i, p);
1957 if ((!hdpa) || i < 0)
1960 if (hdpa->nItemCount <= i) {
1961 /* within the old array */
1962 if (hdpa->nMaxCount > i) {
1963 /* within the allocated space, set a new boundary */
1964 hdpa->nItemCount = i+1;
1967 /* resize the block of memory */
1969 hdpa->nGrow * ((INT)(((i+1) - 1) / hdpa->nGrow) + 1);
1970 INT nSize = nNewItems * sizeof(LPVOID);
1972 lpTemp = (LPVOID*)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1977 hdpa->nItemCount = nNewItems;
1978 hdpa->ptrs = lpTemp;
1982 /* put the new entry in */
1989 /**************************************************************************
1990 * DPA_DeletePtr [COMCTL32.336]
1992 * Removes a pointer from the pointer array.
1995 * hdpa [I] handle (pointer) to the pointer array
1996 * i [I] index of the pointer that will be deleted
1999 * Success: deleted pointer
2004 DPA_DeletePtr (const HDPA hdpa, INT i)
2006 LPVOID *lpDest, *lpSrc, lpTemp = NULL;
2009 TRACE("(%p %d)\n", hdpa, i);
2011 if ((!hdpa) || i < 0 || i >= hdpa->nItemCount)
2014 lpTemp = hdpa->ptrs[i];
2016 /* do we need to move ?*/
2017 if (i < hdpa->nItemCount - 1) {
2018 lpDest = hdpa->ptrs + i;
2020 nSize = (hdpa->nItemCount - i - 1) * sizeof(LPVOID);
2021 TRACE("-- move dest=%p src=%p size=%x\n",
2022 lpDest, lpSrc, nSize);
2023 memmove (lpDest, lpSrc, nSize);
2026 hdpa->nItemCount --;
2029 if ((hdpa->nMaxCount - hdpa->nItemCount) >= hdpa->nGrow) {
2030 INT nNewItems = max(hdpa->nGrow * 2, hdpa->nItemCount);
2031 nSize = nNewItems * sizeof(LPVOID);
2032 lpDest = (LPVOID)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
2037 hdpa->nMaxCount = nNewItems;
2038 hdpa->ptrs = (LPVOID*)lpDest;
2045 /**************************************************************************
2046 * DPA_DeleteAllPtrs [COMCTL32.337]
2048 * Removes all pointers and reinitializes the array.
2051 * hdpa [I] handle (pointer) to the pointer array
2059 DPA_DeleteAllPtrs (const HDPA hdpa)
2061 TRACE("(%p)\n", hdpa);
2066 if (hdpa->ptrs && (!HeapFree (hdpa->hHeap, 0, hdpa->ptrs)))
2069 hdpa->nItemCount = 0;
2070 hdpa->nMaxCount = hdpa->nGrow * 2;
2071 hdpa->ptrs = (LPVOID*)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
2072 hdpa->nMaxCount * sizeof(LPVOID));
2078 /**************************************************************************
2079 * DPA_QuickSort [Internal]
2081 * Ordinary quicksort (used by DPA_Sort).
2084 * lpPtrs [I] pointer to the pointer array
2085 * l [I] index of the "left border" of the partition
2086 * r [I] index of the "right border" of the partition
2087 * pfnCompare [I] pointer to the compare function
2088 * lParam [I] user defined value (3rd parameter in compare function)
2095 DPA_QuickSort (LPVOID *lpPtrs, INT l, INT r,
2096 PFNDPACOMPARE pfnCompare, LPARAM lParam)
2101 TRACE("l=%i r=%i\n", l, r);
2103 if (l==r) /* one element is always sorted */
2105 if (r<l) /* oops, got it in the wrong order */
2107 DPA_QuickSort(lpPtrs, r, l, pfnCompare, lParam);
2110 m = (l+r)/2; /* divide by two */
2111 DPA_QuickSort(lpPtrs, l, m, pfnCompare, lParam);
2112 DPA_QuickSort(lpPtrs, m+1, r, pfnCompare, lParam);
2114 /* join the two sides */
2115 while( (l<=m) && (m<r) )
2117 if(pfnCompare(lpPtrs[l],lpPtrs[m+1],lParam)>0)
2120 memmove(&lpPtrs[l+1],&lpPtrs[l],(m-l+1)*sizeof lpPtrs[l]);
2130 /**************************************************************************
2131 * DPA_Sort [COMCTL32.338]
2133 * Sorts a pointer array using a user defined compare function
2136 * hdpa [I] handle (pointer) to the pointer array
2137 * pfnCompare [I] pointer to the compare function
2138 * lParam [I] user defined value (3rd parameter of compare function)
2146 DPA_Sort (const HDPA hdpa, PFNDPACOMPARE pfnCompare, LPARAM lParam)
2148 if (!hdpa || !pfnCompare)
2151 TRACE("(%p %p 0x%lx)\n", hdpa, pfnCompare, lParam);
2153 if ((hdpa->nItemCount > 1) && (hdpa->ptrs))
2154 DPA_QuickSort (hdpa->ptrs, 0, hdpa->nItemCount - 1,
2155 pfnCompare, lParam);
2161 /**************************************************************************
2162 * DPA_Search [COMCTL32.339]
2164 * Searches a pointer array for a specified pointer
2167 * hdpa [I] handle (pointer) to the pointer array
2168 * pFind [I] pointer to search for
2169 * nStart [I] start index
2170 * pfnCompare [I] pointer to the compare function
2171 * lParam [I] user defined value (3rd parameter of compare function)
2172 * uOptions [I] search options
2175 * Success: index of the pointer in the array.
2179 * Binary search taken from R.Sedgewick "Algorithms in C"!
2180 * Function is NOT tested!
2181 * If something goes wrong, blame HIM not ME! (Eric Kohl)
2185 DPA_Search (const HDPA hdpa, LPVOID pFind, INT nStart,
2186 PFNDPACOMPARE pfnCompare, LPARAM lParam, UINT uOptions)
2188 if (!hdpa || !pfnCompare || !pFind)
2191 TRACE("(%p %p %d %p 0x%08lx 0x%08x)\n",
2192 hdpa, pFind, nStart, pfnCompare, lParam, uOptions);
2194 if (uOptions & DPAS_SORTED) {
2195 /* array is sorted --> use binary search */
2199 TRACE("binary search\n");
2201 l = (nStart == -1) ? 0 : nStart;
2202 r = hdpa->nItemCount - 1;
2206 n = (pfnCompare)(pFind, lpPtr[x], lParam);
2212 TRACE("-- ret=%d\n", n);
2217 if (uOptions & DPAS_INSERTBEFORE) {
2218 TRACE("-- ret=%d\n", r);
2222 if (uOptions & DPAS_INSERTAFTER) {
2223 TRACE("-- ret=%d\n", l);
2228 /* array is not sorted --> use linear search */
2232 TRACE("linear search\n");
2234 nIndex = (nStart == -1)? 0 : nStart;
2236 for (; nIndex < hdpa->nItemCount; nIndex++) {
2237 if ((pfnCompare)(pFind, lpPtr[nIndex], lParam) == 0) {
2238 TRACE("-- ret=%d\n", nIndex);
2244 TRACE("-- not found: ret=-1\n");
2249 /**************************************************************************
2250 * DPA_CreateEx [COMCTL32.340]
2252 * Creates a dynamic pointer array using the specified size and heap.
2255 * nGrow [I] number of items by which the array grows when it is filled
2256 * hHeap [I] handle to the heap where the array is stored
2259 * Success: handle (pointer) to the pointer array.
2264 DPA_CreateEx (INT nGrow, HANDLE hHeap)
2268 TRACE("(%d 0x%x)\n", nGrow, hHeap);
2271 hdpa = (HDPA)HeapAlloc (hHeap, HEAP_ZERO_MEMORY, sizeof(DPA));
2273 hdpa = (HDPA)COMCTL32_Alloc (sizeof(DPA));
2276 hdpa->nGrow = min(8, nGrow);
2277 hdpa->hHeap = hHeap ? hHeap : COMCTL32_hHeap;
2278 hdpa->nMaxCount = hdpa->nGrow * 2;
2280 (LPVOID*)HeapAlloc (hHeap, HEAP_ZERO_MEMORY,
2281 hdpa->nMaxCount * sizeof(LPVOID));
2284 TRACE("-- %p\n", hdpa);
2290 /**************************************************************************
2291 * Notification functions
2294 typedef struct tagNOTIFYDATA
2302 } NOTIFYDATA, *LPNOTIFYDATA;
2305 /**************************************************************************
2306 * DoNotify [Internal]
2310 DoNotify (LPNOTIFYDATA lpNotify, UINT uCode, LPNMHDR lpHdr)
2313 LPNMHDR lpNmh = NULL;
2316 TRACE("(0x%04x 0x%04x %d %p 0x%08lx)\n",
2317 lpNotify->hwndFrom, lpNotify->hwndTo, uCode, lpHdr,
2318 lpNotify->dwParam5);
2320 if (!lpNotify->hwndTo)
2323 if (lpNotify->hwndFrom == -1) {
2325 idFrom = lpHdr->idFrom;
2328 if (lpNotify->hwndFrom) {
2329 HWND hwndParent = GetParent (lpNotify->hwndFrom);
2331 hwndParent = GetWindow (lpNotify->hwndFrom, GW_OWNER);
2332 /* the following is done even if the return from above
2333 * is zero. GLA 12/2001 */
2334 idFrom = GetDlgCtrlID (lpNotify->hwndFrom);
2338 lpNmh = (lpHdr) ? lpHdr : &nmhdr;
2340 lpNmh->hwndFrom = lpNotify->hwndFrom;
2341 lpNmh->idFrom = idFrom;
2342 lpNmh->code = uCode;
2345 return SendMessageA (lpNotify->hwndTo, WM_NOTIFY, idFrom, (LPARAM)lpNmh);
2349 /**************************************************************************
2350 * SendNotify [COMCTL32.341]
2359 * Success: return value from notification
2364 COMCTL32_SendNotify (HWND hwndTo, HWND hwndFrom,
2365 UINT uCode, LPNMHDR lpHdr)
2369 TRACE("(0x%04x 0x%04x %d %p)\n",
2370 hwndTo, hwndFrom, uCode, lpHdr);
2372 notify.hwndFrom = hwndFrom;
2373 notify.hwndTo = hwndTo;
2374 notify.dwParam5 = 0;
2375 notify.dwParam6 = 0;
2377 return DoNotify (¬ify, uCode, lpHdr);
2381 /**************************************************************************
2382 * SendNotifyEx [COMCTL32.342]
2392 * Success: return value from notification
2397 COMCTL32_SendNotifyEx (HWND hwndTo, HWND hwndFrom, UINT uCode,
2398 LPNMHDR lpHdr, DWORD dwParam5)
2403 TRACE("(0x%04x 0x%04x %d %p 0x%08lx)\n",
2404 hwndFrom, hwndTo, uCode, lpHdr, dwParam5);
2406 hwndNotify = hwndTo;
2408 if (IsWindow (hwndFrom)) {
2409 hwndNotify = GetParent (hwndFrom);
2415 notify.hwndFrom = hwndFrom;
2416 notify.hwndTo = hwndNotify;
2417 notify.dwParam5 = dwParam5;
2418 notify.dwParam6 = 0;
2420 return DoNotify (¬ify, uCode, lpHdr);
2424 /**************************************************************************
2425 * StrChrA [COMCTL32.350]
2430 COMCTL32_StrChrA (LPCSTR lpString, CHAR cChar)
2432 return strchr (lpString, cChar);
2436 /**************************************************************************
2437 * StrStrIA [COMCTL32.355]
2441 COMCTL32_StrStrIA (LPCSTR lpStr1, LPCSTR lpStr2)
2447 return ((LPSTR)lpStr1);
2449 while (lpStr1[len1] != 0) ++len1;
2451 while (lpStr2[len2] != 0) ++len2;
2453 return ((LPSTR)(lpStr1 + len1));
2454 first = tolower (*lpStr2);
2455 while (len1 >= len2) {
2456 if (tolower(*lpStr1) == first) {
2457 for (i = 1; i < len2; ++i)
2458 if (tolower (lpStr1[i]) != tolower(lpStr2[i]))
2461 return ((LPSTR)lpStr1);
2469 /**************************************************************************
2470 * StrToIntA [COMCTL32.357] Converts a string to a signed integer.
2474 COMCTL32_StrToIntA (LPSTR lpString)
2476 return atoi(lpString);
2479 /**************************************************************************
2480 * StrToIntW [COMCTL32.365] Converts a wide char string to a signed integer.
2484 COMCTL32_StrToIntW (LPWSTR lpString)
2486 return _wtoi(lpString);
2490 /**************************************************************************
2491 * DPA_EnumCallback [COMCTL32.385]
2493 * Enumerates all items in a dynamic pointer array.
2496 * hdpa [I] handle to the dynamic pointer array
2505 DPA_EnumCallback (const HDPA hdpa, DPAENUMPROC enumProc, LPARAM lParam)
2509 TRACE("(%p %p %08lx)\n", hdpa, enumProc, lParam);
2513 if (hdpa->nItemCount <= 0)
2516 for (i = 0; i < hdpa->nItemCount; i++) {
2517 if ((enumProc)(hdpa->ptrs[i], lParam) == 0)
2525 /**************************************************************************
2526 * DPA_DestroyCallback [COMCTL32.386]
2528 * Enumerates all items in a dynamic pointer array and destroys it.
2531 * hdpa [I] handle to the dynamic pointer array
2541 DPA_DestroyCallback (const HDPA hdpa, DPAENUMPROC enumProc, LPARAM lParam)
2543 TRACE("(%p %p %08lx)\n", hdpa, enumProc, lParam);
2545 DPA_EnumCallback (hdpa, enumProc, lParam);
2547 return DPA_Destroy (hdpa);
2551 /**************************************************************************
2552 * DSA_EnumCallback [COMCTL32.387]
2554 * Enumerates all items in a dynamic storage array.
2557 * hdsa [I] handle to the dynamic storage array
2566 DSA_EnumCallback (const HDSA hdsa, DSAENUMPROC enumProc, LPARAM lParam)
2570 TRACE("(%p %p %08lx)\n", hdsa, enumProc, lParam);
2574 if (hdsa->nItemCount <= 0)
2577 for (i = 0; i < hdsa->nItemCount; i++) {
2578 LPVOID lpItem = DSA_GetItemPtr (hdsa, i);
2579 if ((enumProc)(lpItem, lParam) == 0)
2587 /**************************************************************************
2588 * DSA_DestroyCallback [COMCTL32.388]
2590 * Enumerates all items in a dynamic storage array and destroys it.
2593 * hdsa [I] handle to the dynamic storage array
2603 DSA_DestroyCallback (const HDSA hdsa, DSAENUMPROC enumProc, LPARAM lParam)
2605 TRACE("(%p %p %08lx)\n", hdsa, enumProc, lParam);
2607 DSA_EnumCallback (hdsa, enumProc, lParam);
2609 return DSA_Destroy (hdsa);
2612 /**************************************************************************
2613 * StrCSpnA [COMCTL32.356]
2616 INT WINAPI COMCTL32_StrCSpnA( LPCSTR lpStr, LPCSTR lpSet) {
2617 return strcspn(lpStr, lpSet);
2620 /**************************************************************************
2621 * StrChrW [COMCTL32.358]
2624 LPWSTR WINAPI COMCTL32_StrChrW( LPCWSTR lpStart, WORD wMatch) {
2625 return strchrW(lpStart, wMatch);
2628 /**************************************************************************
2629 * StrCmpNA [COMCTL32.352]
2632 INT WINAPI COMCTL32_StrCmpNA( LPCSTR lpStr1, LPCSTR lpStr2, int nChar) {
2633 return strncmp(lpStr1, lpStr2, nChar);
2636 /**************************************************************************
2637 * StrCmpNIA [COMCTL32.353]
2640 INT WINAPI COMCTL32_StrCmpNIA( LPCSTR lpStr1, LPCSTR lpStr2, int nChar) {
2641 return strncasecmp(lpStr1, lpStr2, nChar);
2644 /**************************************************************************
2645 * StrCmpNW [COMCTL32.360]
2648 INT WINAPI COMCTL32_StrCmpNW( LPCWSTR lpStr1, LPCWSTR lpStr2, int nChar) {
2649 return strncmpW(lpStr1, lpStr2, nChar);
2652 /**************************************************************************
2653 * StrCmpNIW [COMCTL32.361]
2656 INT WINAPI COMCTL32_StrCmpNIW( LPCWSTR lpStr1, LPCWSTR lpStr2, int nChar) {
2657 FIXME("(%s, %s, %i): stub\n", debugstr_w(lpStr1), debugstr_w(lpStr2), nChar);
2661 /**************************************************************************
2662 * StrRChrA [COMCTL32.351]
2665 LPSTR WINAPI COMCTL32_StrRChrA( LPCSTR lpStart, LPCSTR lpEnd, WORD wMatch )
2667 LPCSTR lpGotIt = NULL;
2668 BOOL dbcs = IsDBCSLeadByte( LOBYTE(wMatch) );
2670 TRACE("(%p, %p, %x)\n", lpStart, lpEnd, wMatch);
2672 if (!lpEnd) lpEnd = lpStart + strlen(lpStart);
2674 for(; lpStart < lpEnd; lpStart = CharNextA(lpStart))
2676 if (*lpStart != LOBYTE(wMatch)) continue;
2677 if (dbcs && lpStart[1] != HIBYTE(wMatch)) continue;
2680 return (LPSTR)lpGotIt;
2684 /**************************************************************************
2685 * StrRChrW [COMCTL32.359]
2688 LPWSTR WINAPI COMCTL32_StrRChrW( LPCWSTR lpStart, LPCWSTR lpEnd, WORD wMatch)
2690 LPCWSTR lpGotIt = NULL;
2692 TRACE("(%p, %p, %x)\n", lpStart, lpEnd, wMatch);
2693 if (!lpEnd) lpEnd = lpStart + strlenW(lpStart);
2695 for(; lpStart < lpEnd; lpStart = CharNextW(lpStart))
2696 if (*lpStart == wMatch) lpGotIt = lpStart;
2698 return (LPWSTR)lpGotIt;
2702 /**************************************************************************
2703 * StrStrA [COMCTL32.354]
2706 LPSTR WINAPI COMCTL32_StrStrA( LPCSTR lpFirst, LPCSTR lpSrch) {
2707 return strstr(lpFirst, lpSrch);
2710 /**************************************************************************
2711 * StrStrW [COMCTL32.362]
2714 LPWSTR WINAPI COMCTL32_StrStrW( LPCWSTR lpFirst, LPCWSTR lpSrch) {
2715 return strstrW(lpFirst, lpSrch);
2718 /**************************************************************************
2719 * StrSpnW [COMCTL32.364]
2722 INT WINAPI COMCTL32_StrSpnW( LPWSTR lpStr, LPWSTR lpSet) {
2723 LPWSTR lpLoop = lpStr;
2726 if ((lpStr == 0) || (lpSet == 0)) return 0;
2728 /* while(*lpLoop) { if lpLoop++; } */
2730 for(; (*lpLoop != 0); lpLoop++)
2731 if( strchrW(lpSet, *(WORD*)lpLoop))
2732 return (INT)(lpLoop-lpStr);
2734 return (INT)(lpLoop-lpStr);
2737 /**************************************************************************
2740 * FIXME: What's this supposed to do?
2741 * Parameter 1 is an HWND, you're on your own for the rest.
2744 BOOL WINAPI COMCTL32_410( HWND hw, DWORD b, DWORD c, DWORD d) {
2746 FIXME("(%x, %lx, %lx, %lx): stub!\n", hw, b, c, d);
2751 /**************************************************************************
2754 * FIXME: What's this supposed to do?
2755 * Parameter 1 is an HWND, you're on your own for the rest.
2758 BOOL WINAPI COMCTL32_411( HWND hw, DWORD b, DWORD c) {
2760 FIXME("(%x, %lx, %lx): stub!\n", hw, b, c);
2765 /**************************************************************************
2768 * FIXME: What's this supposed to do?
2769 * Parameter 1 is an HWND, you're on your own for the rest.
2772 BOOL WINAPI COMCTL32_412( HWND hwnd, DWORD b, DWORD c)
2774 FIXME("(%x, %lx, %lx): stub!\n", hwnd, b, c);
2776 if (IsWindow (hwnd) == FALSE)
2786 /**************************************************************************
2789 * FIXME: What's this supposed to do?
2790 * Parameter 1 is an HWND, you're on your own for the rest.
2793 BOOL WINAPI COMCTL32_413( HWND hw, DWORD b, DWORD c, DWORD d) {
2795 FIXME("(%x, %lx, %lx, %lx): stub!\n", hw, b, c, d);
2801 /**************************************************************************
2804 * FIXME: What's this supposed to do?
2805 * Parameter 1 is an HWND, you're on your own for the rest.
2808 BOOL WINAPI COMCTL32_415( HWND hwnd, DWORD b, DWORD c, DWORD d, DWORD e)
2811 FIXME("(%x, %lx, %lx, %lx, %lx): stub!\n", hwnd, b, c, d, e);
2816 /**************************************************************************
2819 * FIXME: What's this supposed to do?
2822 BOOL WINAPI COMCTL32_419( DWORD a, DWORD b, DWORD c, DWORD d)
2825 FIXME("(%lx, %lx, %lx, %lx): stub!\n", a, b, c, d);