2 * Undocumented functions from COMCTL32.DLL
4 * Copyright 1998 Eric Kohl
5 * 1998 Juergen Schmied <j.schmied@metronet.de>
6 * 2000 Eric Kohl for CodeWeavers
9 * All of these functions are UNDOCUMENTED!! And I mean UNDOCUMENTED!!!!
10 * Do NOT rely on names or contents of undocumented structures and types!!!
11 * These functions are used by EXPLORER.EXE, IEXPLORE.EXE and
12 * COMCTL32.DLL (internally).
15 * - Add more functions.
16 * - Write some documentation.
20 #include <stdlib.h> /* atoi */
30 #include "wine/unicode.h"
33 #include "debugtools.h"
35 DEFAULT_DEBUG_CHANNEL(commctrl);
38 extern HANDLE COMCTL32_hHeap; /* handle to the private heap */
41 typedef struct _STREAMDATA
46 } STREAMDATA, *PSTREAMDATA;
48 typedef struct _LOADDATA
52 } LOADDATA, *LPLOADDATA;
54 typedef HRESULT CALLBACK (*DPALOADPROC)(LPLOADDATA,IStream*,LPARAM);
56 INT __cdecl _wtoi(LPWSTR string);
58 /**************************************************************************
59 * DPA_LoadStream [COMCTL32.9]
61 * Loads a dynamic pointer array from a stream
64 * phDpa [O] pointer to a handle to a dynamic pointer array
65 * loadProc [I] pointer to a callback function
66 * pStream [I] pointer to a stream
67 * lParam [I] application specific value
70 * No more information available yet!
74 DPA_LoadStream (HDPA *phDpa, DPALOADPROC loadProc, IStream *pStream, LPARAM lParam)
77 LARGE_INTEGER position;
78 ULARGE_INTEGER newPosition;
79 STREAMDATA streamData;
85 FIXME ("phDpa=%p loadProc=%p pStream=%p lParam=%lx\n",
86 phDpa, loadProc, pStream, lParam);
88 if (!phDpa || !loadProc || !pStream)
93 position.s.LowPart = 0;
94 position.s.HighPart = 0;
97 * Zero out our streamData
99 memset(&streamData,0,sizeof(STREAMDATA));
101 errCode = IStream_Seek (pStream, position, STREAM_SEEK_CUR, &newPosition);
105 errCode = IStream_Read (pStream, &streamData, sizeof(STREAMDATA), &ulRead);
109 FIXME ("dwSize=%lu dwData2=%lu dwItems=%lu\n",
110 streamData.dwSize, streamData.dwData2, streamData.dwItems);
112 if ( ulRead < sizeof(STREAMDATA) ||
113 lParam < sizeof(STREAMDATA) ||
114 streamData.dwSize < sizeof(STREAMDATA) ||
115 streamData.dwData2 < 1) {
119 if (streamData.dwItems > (UINT_MAX / 2 / sizeof(VOID*))) /* 536870911 */
120 return E_OUTOFMEMORY;
123 hDpa = DPA_Create (streamData.dwItems);
125 return E_OUTOFMEMORY;
127 if (!DPA_Grow (hDpa, streamData.dwItems))
128 return E_OUTOFMEMORY;
130 /* load data from the stream into the dpa */
132 for (loadData.nCount = 0; loadData.nCount < streamData.dwItems; loadData.nCount++) {
133 errCode = (loadProc)(&loadData, pStream, lParam);
134 if (errCode != S_OK) {
143 /* set the number of items */
144 hDpa->nItemCount = loadData.nCount;
146 /* store the handle to the dpa */
148 FIXME ("new hDpa=%p\n", hDpa);
154 /**************************************************************************
155 * DPA_SaveStream [COMCTL32.10]
157 * Saves a dynamic pointer array to a stream
160 * hDpa [I] handle to a dynamic pointer array
161 * loadProc [I] pointer to a callback function
162 * pStream [I] pointer to a stream
163 * lParam [I] application specific value
166 * No more information available yet!
170 DPA_SaveStream (const HDPA hDpa, DPALOADPROC loadProc, IStream *pStream, LPARAM lParam)
173 FIXME ("hDpa=%p loadProc=%p pStream=%p lParam=%lx\n",
174 hDpa, loadProc, pStream, lParam);
180 /**************************************************************************
181 * DPA_Merge [COMCTL32.11]
184 * hdpa1 [I] handle to a dynamic pointer array
185 * hdpa2 [I] handle to a dynamic pointer array
187 * pfnCompare [I] pointer to sort function
188 * pfnMerge [I] pointer to merge function
189 * lParam [I] application specific value
192 * No more information available yet!
196 DPA_Merge (const HDPA hdpa1, const HDPA hdpa2, DWORD dwFlags,
197 PFNDPACOMPARE pfnCompare, PFNDPAMERGE pfnMerge, LPARAM lParam)
200 LPVOID *pWork1, *pWork2;
204 TRACE("%p %p %08lx %p %p %08lx)\n",
205 hdpa1, hdpa2, dwFlags, pfnCompare, pfnMerge, lParam);
207 if (IsBadWritePtr (hdpa1, sizeof(DPA)))
210 if (IsBadWritePtr (hdpa2, sizeof(DPA)))
213 if (IsBadCodePtr ((FARPROC)pfnCompare))
216 if (IsBadCodePtr ((FARPROC)pfnMerge))
219 if (dwFlags & DPAM_SORT) {
220 TRACE("sorting dpa's!\n");
221 if (hdpa1->nItemCount > 0)
222 DPA_Sort (hdpa1, pfnCompare, lParam);
223 TRACE ("dpa 1 sorted!\n");
224 if (hdpa2->nItemCount > 0)
225 DPA_Sort (hdpa2, pfnCompare, lParam);
226 TRACE ("dpa 2 sorted!\n");
229 if (hdpa2->nItemCount < 1)
232 TRACE("hdpa1->nItemCount=%d hdpa2->nItemCount=%d\n",
233 hdpa1->nItemCount, hdpa2->nItemCount);
236 /* working but untrusted implementation */
238 pWork1 = &(hdpa1->ptrs[hdpa1->nItemCount - 1]);
239 pWork2 = &(hdpa2->ptrs[hdpa2->nItemCount - 1]);
241 nIndex = hdpa1->nItemCount - 1;
242 nCount = hdpa2->nItemCount - 1;
246 if (nIndex < 0) break;
247 nResult = (pfnCompare)(*pWork1, *pWork2, lParam);
248 TRACE("compare result=%d, dpa1.cnt=%d, dpa2.cnt=%d\n",
249 nResult, nIndex, nCount);
255 ptr = (pfnMerge)(1, *pWork1, *pWork2, lParam);
265 else if (nResult < 0)
271 ptr = DPA_DeletePtr (hdpa1, hdpa1->nItemCount - 1);
273 (pfnMerge)(2, ptr, NULL, lParam);
284 ptr = (pfnMerge)(3, *pWork2, NULL, lParam);
287 DPA_InsertPtr (hdpa1, nIndex, ptr);
300 /**************************************************************************
301 * Alloc [COMCTL32.71]
303 * Allocates memory block from the dll's private heap
306 * dwSize [I] size of the allocated memory block
309 * Success: pointer to allocated memory block
314 COMCTL32_Alloc (DWORD dwSize)
318 TRACE("(0x%lx)\n", dwSize);
320 lpPtr = HeapAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, dwSize);
322 TRACE("-- ret=%p\n", lpPtr);
328 /**************************************************************************
329 * ReAlloc [COMCTL32.72]
331 * Changes the size of an allocated memory block or allocates a memory
332 * block using the dll's private heap.
335 * lpSrc [I] pointer to memory block which will be resized
336 * dwSize [I] new size of the memory block.
339 * Success: pointer to the resized memory block
343 * If lpSrc is a NULL-pointer, then COMCTL32_ReAlloc allocates a memory
344 * block like COMCTL32_Alloc.
348 COMCTL32_ReAlloc (LPVOID lpSrc, DWORD dwSize)
352 TRACE("(%p 0x%08lx)\n", lpSrc, dwSize);
355 lpDest = HeapReAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, lpSrc, dwSize);
357 lpDest = HeapAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, dwSize);
359 TRACE("-- ret=%p\n", lpDest);
365 /**************************************************************************
368 * Frees an allocated memory block from the dll's private heap.
371 * lpMem [I] pointer to memory block which will be freed
379 COMCTL32_Free (LPVOID lpMem)
381 TRACE("(%p)\n", lpMem);
383 return HeapFree (COMCTL32_hHeap, 0, lpMem);
387 /**************************************************************************
388 * GetSize [COMCTL32.74]
390 * Retrieves the size of the specified memory block from the dll's
394 * lpMem [I] pointer to an allocated memory block
397 * Success: size of the specified memory block
402 COMCTL32_GetSize (LPVOID lpMem)
404 TRACE("(%p)\n", lpMem);
406 return HeapSize (COMCTL32_hHeap, 0, lpMem);
410 /**************************************************************************
411 * The MRU-API is a set of functions to manipulate MRU(Most Recently Used)
414 * Stored in the reg. as a set of values under a single key. Each item in the
415 * list has a value name that is a single char. 'a' - 'z', '{', '|' or '}'.
416 * The order of the list is stored with value name 'MRUList' which is a string
417 * containing the value names (i.e. 'a', 'b', etc.) in the relevant order.
420 typedef struct tagCREATEMRULISTA
422 DWORD cbSize; /* size of struct */
423 DWORD nMaxItems; /* max no. of items in list */
424 DWORD dwFlags; /* see below */
425 HKEY hKey; /* root reg. key under which list is saved */
426 LPCSTR lpszSubKey; /* reg. subkey */
427 PROC lpfnCompare; /* item compare proc */
428 } CREATEMRULISTA, *LPCREATEMRULISTA;
430 typedef struct tagCREATEMRULISTW
432 DWORD cbSize; /* size of struct */
433 DWORD nMaxItems; /* max no. of items in list */
434 DWORD dwFlags; /* see below */
435 HKEY hKey; /* root reg. key under which list is saved */
436 LPCWSTR lpszSubKey; /* reg. subkey */
437 PROC lpfnCompare; /* item compare proc */
438 } CREATEMRULISTW, *LPCREATEMRULISTW;
441 #define MRUF_STRING_LIST 0 /* list will contain strings */
442 #define MRUF_BINARY_LIST 1 /* list will contain binary data */
443 #define MRUF_DELAYED_SAVE 2 /* only save list order to reg. is FreeMRUList */
445 /* If list is a string list lpfnCompare has the following prototype
446 * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
447 * for binary lists the prototype is
448 * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
449 * where cbData is the no. of bytes to compare.
450 * Need to check what return value means identical - 0?
453 typedef struct tagWINEMRUITEM
455 DWORD size; /* size of data stored */
456 DWORD itemFlag; /* flags */
458 } WINEMRUITEM, *LPWINEMRUITEM;
461 #define WMRUIF_CHANGED 0x0001 /* this dataitem changed */
463 typedef struct tagWINEMRULIST
465 CREATEMRULISTW extview; /* original create information */
466 BOOL isUnicode; /* is compare fn Unicode */
467 DWORD wineFlags; /* internal flags */
468 DWORD cursize; /* current size of realMRU */
469 LPSTR realMRU; /* pointer to string of index names */
470 LPWINEMRUITEM *array; /* array of pointers to data */
471 /* in 'a' to 'z' order */
472 } WINEMRULIST, *LPWINEMRULIST;
475 #define WMRUF_CHANGED 0x0001 /* MRU list has changed */
477 /**************************************************************************
478 * MRU_SaveChanged - Localize MRU saving code
481 VOID MRU_SaveChanged( LPWINEMRULIST mp )
487 WCHAR emptyW[] = {'\0'};
489 /* or should we do the following instead of RegOpenKeyEx:
492 /* open the sub key */
493 if ((err = RegOpenKeyExW( mp->extview.hKey, mp->extview.lpszSubKey,
494 0, KEY_WRITE, &newkey))) {
495 /* not present - what to do ??? */
496 ERR("Can not open key, error=%d, attempting to create\n",
498 if ((err = RegCreateKeyExW( mp->extview.hKey, mp->extview.lpszSubKey,
501 REG_OPTION_NON_VOLATILE,
502 KEY_READ | KEY_WRITE,
506 ERR("failed to create key /%s/, err=%d\n",
507 debugstr_w(mp->extview.lpszSubKey), err);
511 if (mp->wineFlags & WMRUF_CHANGED) {
512 mp->wineFlags &= ~WMRUF_CHANGED;
513 err = RegSetValueExA(newkey, "MRUList", 0, REG_SZ,
514 mp->realMRU, strlen(mp->realMRU) + 1);
516 ERR("error saving MRUList, err=%d\n", err);
518 TRACE("saving MRUList=/%s/\n", mp->realMRU);
521 for(i=0; i<mp->cursize; i++) {
522 witem = mp->array[i];
523 if (witem->itemFlag & WMRUIF_CHANGED) {
524 witem->itemFlag &= ~WMRUIF_CHANGED;
525 realname[0] = 'a' + i;
526 err = RegSetValueExW(newkey, realname, 0,
527 (mp->extview.dwFlags & MRUF_BINARY_LIST) ?
529 &witem->datastart, witem->size);
531 ERR("error saving /%s/, err=%d\n", debugstr_w(realname), err);
533 TRACE("saving value for name /%s/ size=%ld\n",
534 debugstr_w(realname), witem->size);
537 RegCloseKey( newkey );
540 /**************************************************************************
541 * FreeMRUList [COMCTL32.152]
544 * hMRUList [I] Handle to list.
548 FreeMRUList (HANDLE hMRUList)
550 LPWINEMRULIST mp = (LPWINEMRULIST)hMRUList;
554 if (mp->wineFlags & WMRUF_CHANGED) {
555 /* need to open key and then save the info */
556 MRU_SaveChanged( mp );
559 for(i=0; i<mp->extview.nMaxItems; i++) {
561 COMCTL32_Free(mp->array[i]);
563 COMCTL32_Free(mp->realMRU);
564 COMCTL32_Free(mp->array);
565 COMCTL32_Free((LPWSTR)mp->extview.lpszSubKey);
566 return COMCTL32_Free(mp);
570 /**************************************************************************
571 * FindMRUData [COMCTL32.169]
573 * Searches binary list for item that matches lpData of length cbData.
574 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
575 * corresponding to item's reg. name will be stored in it ('a' -> 0).
578 * hList [I] list handle
579 * lpData [I] data to find
580 * cbData [I] length of data
581 * lpRegNum [O] position in registry (maybe NULL)
584 * Position in list 0 -> MRU. -1 if item not found.
587 FindMRUData (HANDLE hList, LPCVOID lpData, DWORD cbData, LPINT lpRegNum)
589 LPWINEMRULIST mp = (LPWINEMRULIST)hList;
593 if (!mp->extview.lpfnCompare) {
594 ERR("MRU list not properly created. No compare procedure.\n");
598 if(!(mp->extview.dwFlags & MRUF_BINARY_LIST) && !mp->isUnicode) {
599 DWORD len = WideCharToMultiByte(CP_ACP, 0, lpData, -1,
600 NULL, 0, NULL, NULL);
601 dataA = COMCTL32_Alloc(len);
602 WideCharToMultiByte(CP_ACP, 0, lpData, -1, dataA, len, NULL, NULL);
605 for(i=0; i<mp->cursize; i++) {
606 if (mp->extview.dwFlags & MRUF_BINARY_LIST) {
607 if (!mp->extview.lpfnCompare(lpData, &mp->array[i]->datastart,
613 if (!mp->extview.lpfnCompare(lpData, &mp->array[i]->datastart))
616 DWORD len = WideCharToMultiByte(CP_ACP, 0,
617 (LPWSTR)&mp->array[i]->datastart, -1,
618 NULL, 0, NULL, NULL);
619 LPSTR itemA = COMCTL32_Alloc(len);
621 WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&mp->array[i]->datastart, -1,
622 itemA, len, NULL, NULL);
624 cmp = mp->extview.lpfnCompare(dataA, itemA);
625 COMCTL32_Free(itemA);
632 COMCTL32_Free(dataA);
637 if (lpRegNum && (ret != -1))
640 TRACE("(%08x, %p, %ld, %p) returning %d\n",
641 hList, lpData, cbData, lpRegNum, ret);
647 /**************************************************************************
648 * AddMRUData [COMCTL32.167]
650 * Add item to MRU binary list. If item already exists in list then it is
651 * simply moved up to the top of the list and not added again. If list is
652 * full then the least recently used item is removed to make room.
655 * hList [I] Handle to list.
656 * lpData [I] ptr to data to add.
657 * cbData [I] no. of bytes of data.
660 * No. corresponding to registry name where value is stored 'a' -> 0 etc.
664 AddMRUData (HANDLE hList, LPCVOID lpData, DWORD cbData)
666 LPWINEMRULIST mp = (LPWINEMRULIST)hList;
670 if ((replace = FindMRUData (hList, lpData, cbData, NULL)) < 0) {
671 /* either add a new entry or replace oldest */
672 if (mp->cursize < mp->extview.nMaxItems) {
673 /* Add in a new item */
674 replace = mp->cursize;
678 /* get the oldest entry and replace data */
679 replace = mp->realMRU[mp->cursize - 1] - 'a';
680 COMCTL32_Free(mp->array[replace]);
684 /* free up the old data */
685 COMCTL32_Free(mp->array[replace]);
688 /* Allocate space for new item and move in the data */
689 mp->array[replace] = witem = (LPWINEMRUITEM)COMCTL32_Alloc(cbData +
690 sizeof(WINEMRUITEM));
691 witem->itemFlag |= WMRUIF_CHANGED;
692 witem->size = cbData;
693 memcpy( &witem->datastart, lpData, cbData);
695 /* now rotate MRU list */
696 mp->wineFlags |= WMRUF_CHANGED;
697 for(i=mp->cursize-1; i>=1; i--) {
698 mp->realMRU[i] = mp->realMRU[i-1];
700 mp->realMRU[0] = replace + 'a';
701 TRACE("(%08x, %p, %ld) adding data, /%c/ now most current\n",
702 hList, lpData, cbData, replace+'a');
705 if (!(mp->extview.dwFlags & MRUF_DELAYED_SAVE)) {
706 /* save changed stuff right now */
707 MRU_SaveChanged( mp );
713 /**************************************************************************
714 * AddMRUStringW [COMCTL32.401]
716 * Add item to MRU string list. If item already exists in list them it is
717 * simply moved up to the top of the list and not added again. If list is
718 * full then the least recently used item is removed to make room.
721 * hList [I] Handle to list.
722 * lpszString [I] ptr to string to add.
725 * No. corresponding to registry name where value is stored 'a' -> 0 etc.
729 AddMRUStringW(HANDLE hList, LPCWSTR lpszString)
731 FIXME("(%08x, %s) empty stub!\n", hList, debugstr_w(lpszString));
736 /**************************************************************************
737 * AddMRUStringA [COMCTL32.153]
740 AddMRUStringA(HANDLE hList, LPCSTR lpszString)
742 FIXME("(%08x, %s) empty stub!\n", hList, debugstr_a(lpszString));
747 /**************************************************************************
748 * DelMRUString [COMCTL32.156]
750 * Removes item from either string or binary list (despite its name)
753 * hList [I] list handle
754 * nItemPos [I] item position to remove 0 -> MRU
757 * TRUE if successful, FALSE if nItemPos is out of range.
760 DelMRUString(HANDLE hList, INT nItemPos)
762 FIXME("(%08x, %d): stub\n", hList, nItemPos);
766 /**************************************************************************
767 * FindMRUStringW [COMCTL32.402]
770 FindMRUStringW (HANDLE hList, LPCWSTR lpszString, LPINT lpRegNum)
776 /**************************************************************************
777 * FindMRUStringA [COMCTL32.155]
779 * Searches string list for item that matches lpszString.
780 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
781 * corresponding to item's reg. name will be stored in it ('a' -> 0).
784 * hList [I] list handle
785 * lpszString [I] string to find
786 * lpRegNum [O] position in registry (maybe NULL)
789 * Position in list 0 -> MRU. -1 if item not found.
792 FindMRUStringA (HANDLE hList, LPCSTR lpszString, LPINT lpRegNum)
794 DWORD len = MultiByteToWideChar(CP_ACP, 0, lpszString, -1, NULL, 0);
795 LPWSTR stringW = COMCTL32_Alloc(len * sizeof(WCHAR));
798 MultiByteToWideChar(CP_ACP, 0, lpszString, -1, stringW, len);
799 ret = FindMRUData(hList, stringW, len * sizeof(WCHAR), lpRegNum);
800 COMCTL32_Free(stringW);
804 /*************************************************************************
805 * CreateMRUListLazy_common
807 HANDLE CreateMRUListLazy_common(LPWINEMRULIST mp)
811 DWORD datasize, dwdisp;
815 WCHAR emptyW[] = {'\0'};
817 /* get space to save indices that will turn into names
818 * but in order of most to least recently used
820 mp->realMRU = (LPSTR) COMCTL32_Alloc(mp->extview.nMaxItems + 2);
822 /* get space to save pointers to actual data in order of
823 * 'a' to 'z' (0 to n).
825 mp->array = (LPVOID) COMCTL32_Alloc(mp->extview.nMaxItems *
828 /* open the sub key */
829 if ((err = RegCreateKeyExW( mp->extview.hKey, mp->extview.lpszSubKey,
832 REG_OPTION_NON_VOLATILE,
833 KEY_READ | KEY_WRITE,
837 /* error - what to do ??? */
838 ERR("(%lu %lu %lx %lx \"%s\" %p): Can not open key, error=%d\n",
839 mp->extview.cbSize, mp->extview.nMaxItems, mp->extview.dwFlags,
840 (DWORD)mp->extview.hKey, debugstr_w(mp->extview.lpszSubKey),
841 mp->extview.lpfnCompare, err);
845 /* get values from key 'MRUList' */
847 datasize = mp->extview.nMaxItems + 1;
848 if((err=RegQueryValueExA( newkey, "MRUList", 0, &type, mp->realMRU,
850 /* not present - set size to 1 (will become 0 later) */
855 TRACE("MRU list = %s\n", mp->realMRU);
857 mp->cursize = datasize - 1;
858 /* datasize now has number of items in the MRUList */
860 /* get actual values for each entry */
862 for(i=0; i<mp->cursize; i++) {
863 realname[0] = 'a' + i;
864 if(RegQueryValueExW( newkey, realname, 0, &type, 0, &datasize)) {
865 /* not present - what to do ??? */
866 ERR("Key %s not found 1\n", debugstr_w(realname));
868 mp->array[i] = witem = (LPWINEMRUITEM)COMCTL32_Alloc(datasize +
869 sizeof(WINEMRUITEM));
870 witem->size = datasize;
871 if(RegQueryValueExW( newkey, realname, 0, &type,
872 &witem->datastart, &datasize)) {
873 /* not present - what to do ??? */
874 ERR("Key %s not found 2\n", debugstr_w(realname));
877 RegCloseKey( newkey );
882 TRACE("(%lu %lu %lx %lx \"%s\" %p): Current Size = %ld\n",
883 mp->extview.cbSize, mp->extview.nMaxItems, mp->extview.dwFlags,
884 (DWORD)mp->extview.hKey, debugstr_w(mp->extview.lpszSubKey),
885 mp->extview.lpfnCompare, mp->cursize);
889 /**************************************************************************
890 * CreateMRUListLazyW [COMCTL32.404]
893 CreateMRUListLazyW (LPCREATEMRULISTW lpcml, DWORD dwParam2, DWORD dwParam3, DWORD dwParam4)
900 if (lpcml->cbSize < sizeof(CREATEMRULISTW))
903 mp = (LPWINEMRULIST) COMCTL32_Alloc(sizeof(WINEMRULIST));
904 memcpy(&mp->extview, lpcml, sizeof(CREATEMRULISTW));
905 mp->extview.lpszSubKey = COMCTL32_Alloc((strlenW(lpcml->lpszSubKey) + 1) *
907 strcpyW((LPWSTR)mp->extview.lpszSubKey, lpcml->lpszSubKey);
908 mp->isUnicode = TRUE;
910 return CreateMRUListLazy_common(mp);
913 /**************************************************************************
914 * CreateMRUListLazyA [COMCTL32.157]
917 CreateMRUListLazyA (LPCREATEMRULISTA lpcml, DWORD dwParam2, DWORD dwParam3, DWORD dwParam4)
925 if (lpcml->cbSize < sizeof(CREATEMRULISTA))
928 mp = (LPWINEMRULIST) COMCTL32_Alloc(sizeof(WINEMRULIST));
929 memcpy(&mp->extview, lpcml, sizeof(CREATEMRULISTW));
930 len = MultiByteToWideChar(CP_ACP, 0, lpcml->lpszSubKey, -1, NULL, 0);
931 mp->extview.lpszSubKey = COMCTL32_Alloc(len * sizeof(WCHAR));
932 MultiByteToWideChar(CP_ACP, 0, lpcml->lpszSubKey, -1,
933 (LPWSTR)mp->extview.lpszSubKey, len);
934 mp->isUnicode = FALSE;
935 return CreateMRUListLazy_common(mp);
938 /**************************************************************************
939 * CreateMRUListW [COMCTL32.400]
942 * lpcml [I] ptr to CREATEMRULIST structure.
945 * Handle to MRU list.
948 CreateMRUListW (LPCREATEMRULISTW lpcml)
950 return CreateMRUListLazyW(lpcml, 0, 0, 0);
953 /**************************************************************************
954 * CreateMRUListA [COMCTL32.151]
957 CreateMRUListA (LPCREATEMRULISTA lpcml)
959 return CreateMRUListLazyA (lpcml, 0, 0, 0);
963 /**************************************************************************
964 * EnumMRUListW [COMCTL32.403]
966 * Enumerate item in a list
969 * hList [I] list handle
970 * nItemPos [I] item position to enumerate
971 * lpBuffer [O] buffer to receive item
972 * nBufferSize [I] size of buffer
975 * For binary lists specifies how many bytes were copied to buffer, for
976 * string lists specifies full length of string. Enumerating past the end
977 * of list returns -1.
978 * If lpBuffer == NULL or nItemPos is -ve return value is no. of items in
981 INT WINAPI EnumMRUListW(HANDLE hList, INT nItemPos, LPVOID lpBuffer,
984 LPWINEMRULIST mp = (LPWINEMRULIST) hList;
986 INT desired, datasize;
988 if (nItemPos >= mp->cursize) return -1;
989 if ((nItemPos < 0) || !lpBuffer) return mp->cursize;
990 desired = mp->realMRU[nItemPos];
992 TRACE("nItemPos=%d, desired=%d\n", nItemPos, desired);
993 witem = mp->array[desired];
994 datasize = min( witem->size, nBufferSize );
995 memcpy( lpBuffer, &witem->datastart, datasize);
996 TRACE("(%08x, %d, %p, %ld): returning len=%d\n",
997 hList, nItemPos, lpBuffer, nBufferSize, datasize);
1001 /**************************************************************************
1002 * EnumMRUListA [COMCTL32.154]
1005 INT WINAPI EnumMRUListA(HANDLE hList, INT nItemPos, LPVOID lpBuffer,
1008 LPWINEMRULIST mp = (LPWINEMRULIST) hList;
1009 LPWINEMRUITEM witem;
1010 INT desired, datasize;
1013 if (nItemPos >= mp->cursize) return -1;
1014 if ((nItemPos < 0) || !lpBuffer) return mp->cursize;
1015 desired = mp->realMRU[nItemPos];
1017 TRACE("nItemPos=%d, desired=%d\n", nItemPos, desired);
1018 witem = mp->array[desired];
1019 if(mp->extview.dwFlags & MRUF_BINARY_LIST) {
1020 datasize = min( witem->size, nBufferSize );
1021 memcpy( lpBuffer, &witem->datastart, datasize);
1023 lenA = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&witem->datastart, -1,
1024 NULL, 0, NULL, NULL);
1025 datasize = min( witem->size, nBufferSize );
1026 WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&witem->datastart, -1,
1027 lpBuffer, datasize, NULL, NULL);
1029 TRACE("(%08x, %d, %p, %ld): returning len=%d\n",
1030 hList, nItemPos, lpBuffer, nBufferSize, datasize);
1035 /**************************************************************************
1036 * Str_GetPtrA [COMCTL32.233]
1047 Str_GetPtrA (LPCSTR lpSrc, LPSTR lpDest, INT nMaxLen)
1051 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
1053 if (!lpDest && lpSrc)
1054 return strlen (lpSrc);
1059 if (lpSrc == NULL) {
1064 len = strlen (lpSrc);
1068 RtlMoveMemory (lpDest, lpSrc, len);
1075 /**************************************************************************
1076 * Str_SetPtrA [COMCTL32.234]
1086 Str_SetPtrA (LPSTR *lppDest, LPCSTR lpSrc)
1088 TRACE("(%p %p)\n", lppDest, lpSrc);
1091 LPSTR ptr = COMCTL32_ReAlloc (*lppDest, strlen (lpSrc) + 1);
1094 strcpy (ptr, lpSrc);
1099 COMCTL32_Free (*lppDest);
1108 /**************************************************************************
1109 * Str_GetPtrW [COMCTL32.235]
1120 Str_GetPtrW (LPCWSTR lpSrc, LPWSTR lpDest, INT nMaxLen)
1124 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
1126 if (!lpDest && lpSrc)
1127 return strlenW (lpSrc);
1132 if (lpSrc == NULL) {
1137 len = strlenW (lpSrc);
1141 RtlMoveMemory (lpDest, lpSrc, len*sizeof(WCHAR));
1142 lpDest[len] = L'\0';
1148 /**************************************************************************
1149 * Str_SetPtrW [COMCTL32.236]
1159 Str_SetPtrW (LPWSTR *lppDest, LPCWSTR lpSrc)
1161 TRACE("(%p %p)\n", lppDest, lpSrc);
1164 INT len = strlenW (lpSrc) + 1;
1165 LPWSTR ptr = COMCTL32_ReAlloc (*lppDest, len * sizeof(WCHAR));
1168 strcpyW (ptr, lpSrc);
1173 COMCTL32_Free (*lppDest);
1182 /**************************************************************************
1183 * Str_GetPtrWtoA [internal]
1185 * Converts a unicode string into a multi byte string
1188 * lpSrc [I] Pointer to the unicode source string
1189 * lpDest [O] Pointer to caller supplied storage for the multi byte string
1190 * nMaxLen [I] Size, in bytes, of the destination buffer
1193 * Length, in bytes, of the converted string.
1197 Str_GetPtrWtoA (LPCWSTR lpSrc, LPSTR lpDest, INT nMaxLen)
1201 TRACE("(%s %p %d)\n", debugstr_w(lpSrc), lpDest, nMaxLen);
1203 if (!lpDest && lpSrc)
1204 return WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, 0, 0, NULL, NULL);
1209 if (lpSrc == NULL) {
1214 len = WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, 0, 0, NULL, NULL);
1218 WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, lpDest, len, NULL, NULL);
1225 /**************************************************************************
1226 * Str_SetPtrAtoW [internal]
1228 * Converts a multi byte string to a unicode string.
1229 * If the pointer to the destination buffer is NULL a buffer is allocated.
1230 * If the destination buffer is too small to keep the converted multi byte
1231 * string the destination buffer is reallocated. If the source pointer is
1232 * NULL, the destination buffer is freed.
1235 * lppDest [I/O] pointer to a pointer to the destination buffer
1236 * lpSrc [I] pointer to a multi byte string
1239 * TRUE: conversion successful
1244 Str_SetPtrAtoW (LPWSTR *lppDest, LPCSTR lpSrc)
1246 TRACE("(%p %s)\n", lppDest, lpSrc);
1249 INT len = MultiByteToWideChar(CP_ACP,0,lpSrc,-1,NULL,0);
1250 LPWSTR ptr = COMCTL32_ReAlloc (*lppDest, len*sizeof(WCHAR));
1254 MultiByteToWideChar(CP_ACP,0,lpSrc,-1,ptr,len);
1259 COMCTL32_Free (*lppDest);
1268 /**************************************************************************
1269 * The DSA-API is a set of functions to create and manipulate arrays of
1270 * fixed-size memory blocks. These arrays can store any kind of data
1271 * (strings, icons...).
1274 /**************************************************************************
1275 * DSA_Create [COMCTL32.320] Creates a dynamic storage array
1278 * nSize [I] size of the array elements
1279 * nGrow [I] number of elements by which the array grows when it is filled
1282 * Success: pointer to an array control structure. Use this like a handle.
1287 DSA_Create (INT nSize, INT nGrow)
1291 TRACE("(size=%d grow=%d)\n", nSize, nGrow);
1293 hdsa = (HDSA)COMCTL32_Alloc (sizeof(DSA));
1296 hdsa->nItemCount = 0;
1298 hdsa->nMaxCount = 0;
1299 hdsa->nItemSize = nSize;
1300 hdsa->nGrow = max(1, nGrow);
1307 /**************************************************************************
1308 * DSA_Destroy [COMCTL32.321] Destroys a dynamic storage array
1311 * hdsa [I] pointer to the array control structure
1319 DSA_Destroy (const HDSA hdsa)
1321 TRACE("(%p)\n", hdsa);
1326 if (hdsa->pData && (!COMCTL32_Free (hdsa->pData)))
1329 return COMCTL32_Free (hdsa);
1333 /**************************************************************************
1334 * DSA_GetItem [COMCTL32.322]
1337 * hdsa [I] pointer to the array control structure
1338 * nIndex [I] number of the Item to get
1339 * pDest [O] destination buffer. Has to be >= dwElementSize.
1347 DSA_GetItem (const HDSA hdsa, INT nIndex, LPVOID pDest)
1351 TRACE("(%p %d %p)\n", hdsa, nIndex, pDest);
1355 if ((nIndex < 0) || (nIndex >= hdsa->nItemCount))
1358 pSrc = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1359 memmove (pDest, pSrc, hdsa->nItemSize);
1365 /**************************************************************************
1366 * DSA_GetItemPtr [COMCTL32.323]
1368 * Retrieves a pointer to the specified item.
1371 * hdsa [I] pointer to the array control structure
1372 * nIndex [I] index of the desired item
1375 * Success: pointer to an item
1380 DSA_GetItemPtr (const HDSA hdsa, INT nIndex)
1384 TRACE("(%p %d)\n", hdsa, nIndex);
1388 if ((nIndex < 0) || (nIndex >= hdsa->nItemCount))
1391 pSrc = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1393 TRACE("-- ret=%p\n", pSrc);
1399 /**************************************************************************
1400 * DSA_SetItem [COMCTL32.325]
1402 * Sets the contents of an item in the array.
1405 * hdsa [I] pointer to the array control structure
1406 * nIndex [I] index for the item
1407 * pSrc [I] pointer to the new item data
1415 DSA_SetItem (const HDSA hdsa, INT nIndex, LPVOID pSrc)
1417 INT nSize, nNewItems;
1418 LPVOID pDest, lpTemp;
1420 TRACE("(%p %d %p)\n", hdsa, nIndex, pSrc);
1422 if ((!hdsa) || nIndex < 0)
1425 if (hdsa->nItemCount <= nIndex) {
1426 /* within the old array */
1427 if (hdsa->nMaxCount > nIndex) {
1428 /* within the allocated space, set a new boundary */
1429 hdsa->nItemCount = nIndex + 1;
1432 /* resize the block of memory */
1434 hdsa->nGrow * ((INT)(((nIndex + 1) - 1) / hdsa->nGrow) + 1);
1435 nSize = hdsa->nItemSize * nNewItems;
1437 lpTemp = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
1441 hdsa->nMaxCount = nNewItems;
1442 hdsa->nItemCount = nIndex + 1;
1443 hdsa->pData = lpTemp;
1447 /* put the new entry in */
1448 pDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1449 TRACE("-- move dest=%p src=%p size=%d\n",
1450 pDest, pSrc, hdsa->nItemSize);
1451 memmove (pDest, pSrc, hdsa->nItemSize);
1457 /**************************************************************************
1458 * DSA_InsertItem [COMCTL32.324]
1461 * hdsa [I] pointer to the array control structure
1462 * nIndex [I] index for the new item
1463 * pSrc [I] pointer to the element
1466 * Success: position of the new item
1471 DSA_InsertItem (const HDSA hdsa, INT nIndex, LPVOID pSrc)
1473 INT nNewItems, nSize, i;
1474 LPVOID lpTemp, lpDest;
1477 TRACE("(%p %d %p)\n", hdsa, nIndex, pSrc);
1479 if ((!hdsa) || nIndex < 0)
1482 for (i = 0; i < hdsa->nItemSize; i += 4) {
1483 p = *(DWORD**)((char *) pSrc + i);
1484 if (IsBadStringPtrA ((char*)p, 256))
1485 TRACE("-- %d=%p\n", i, (DWORD*)p);
1487 TRACE("-- %d=%p [%s]\n", i, p, debugstr_a((char*)p));
1490 /* when nIndex >= nItemCount then append */
1491 if (nIndex >= hdsa->nItemCount)
1492 nIndex = hdsa->nItemCount;
1494 /* do we need to resize ? */
1495 if (hdsa->nItemCount >= hdsa->nMaxCount) {
1496 nNewItems = hdsa->nMaxCount + hdsa->nGrow;
1497 nSize = hdsa->nItemSize * nNewItems;
1499 lpTemp = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
1503 hdsa->nMaxCount = nNewItems;
1504 hdsa->pData = lpTemp;
1507 /* do we need to move elements ? */
1508 if (nIndex < hdsa->nItemCount) {
1509 lpTemp = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1510 lpDest = (char *) lpTemp + hdsa->nItemSize;
1511 nSize = (hdsa->nItemCount - nIndex) * hdsa->nItemSize;
1512 TRACE("-- move dest=%p src=%p size=%d\n",
1513 lpDest, lpTemp, nSize);
1514 memmove (lpDest, lpTemp, nSize);
1517 /* ok, we can put the new Item in */
1519 lpDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1520 TRACE("-- move dest=%p src=%p size=%d\n",
1521 lpDest, pSrc, hdsa->nItemSize);
1522 memmove (lpDest, pSrc, hdsa->nItemSize);
1528 /**************************************************************************
1529 * DSA_DeleteItem [COMCTL32.326]
1532 * hdsa [I] pointer to the array control structure
1533 * nIndex [I] index for the element to delete
1536 * Success: number of the deleted element
1541 DSA_DeleteItem (const HDSA hdsa, INT nIndex)
1543 LPVOID lpDest,lpSrc;
1546 TRACE("(%p %d)\n", hdsa, nIndex);
1550 if (nIndex < 0 || nIndex >= hdsa->nItemCount)
1553 /* do we need to move ? */
1554 if (nIndex < hdsa->nItemCount - 1) {
1555 lpDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1556 lpSrc = (char *) lpDest + hdsa->nItemSize;
1557 nSize = hdsa->nItemSize * (hdsa->nItemCount - nIndex - 1);
1558 TRACE("-- move dest=%p src=%p size=%d\n",
1559 lpDest, lpSrc, nSize);
1560 memmove (lpDest, lpSrc, nSize);
1566 if ((hdsa->nMaxCount - hdsa->nItemCount) >= hdsa->nGrow) {
1567 nSize = hdsa->nItemSize * hdsa->nItemCount;
1569 lpDest = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
1573 hdsa->nMaxCount = hdsa->nItemCount;
1574 hdsa->pData = lpDest;
1581 /**************************************************************************
1582 * DSA_DeleteAllItems [COMCTL32.327]
1584 * Removes all items and reinitializes the array.
1587 * hdsa [I] pointer to the array control structure
1595 DSA_DeleteAllItems (const HDSA hdsa)
1597 TRACE("(%p)\n", hdsa);
1601 if (hdsa->pData && (!COMCTL32_Free (hdsa->pData)))
1604 hdsa->nItemCount = 0;
1606 hdsa->nMaxCount = 0;
1612 /**************************************************************************
1613 * The DPA-API is a set of functions to create and manipulate arrays of
1617 /**************************************************************************
1618 * DPA_Create [COMCTL32.328] Creates a dynamic pointer array
1621 * nGrow [I] number of items by which the array grows when it is filled
1624 * Success: handle (pointer) to the pointer array.
1629 DPA_Create (INT nGrow)
1633 TRACE("(%d)\n", nGrow);
1635 hdpa = (HDPA)COMCTL32_Alloc (sizeof(DPA));
1637 hdpa->nGrow = max(8, nGrow);
1638 hdpa->hHeap = COMCTL32_hHeap;
1639 hdpa->nMaxCount = hdpa->nGrow * 2;
1641 (LPVOID*)COMCTL32_Alloc (hdpa->nMaxCount * sizeof(LPVOID));
1644 TRACE("-- %p\n", hdpa);
1650 /**************************************************************************
1651 * DPA_Destroy [COMCTL32.329] Destroys a dynamic pointer array
1654 * hdpa [I] handle (pointer) to the pointer array
1662 DPA_Destroy (const HDPA hdpa)
1664 TRACE("(%p)\n", hdpa);
1669 if (hdpa->ptrs && (!HeapFree (hdpa->hHeap, 0, hdpa->ptrs)))
1672 return HeapFree (hdpa->hHeap, 0, hdpa);
1676 /**************************************************************************
1677 * DPA_Grow [COMCTL32.330]
1679 * Sets the growth amount.
1682 * hdpa [I] handle (pointer) to the existing (source) pointer array
1683 * nGrow [I] number of items by which the array grows when it's too small
1691 DPA_Grow (const HDPA hdpa, INT nGrow)
1693 TRACE("(%p %d)\n", hdpa, nGrow);
1698 hdpa->nGrow = max(8, nGrow);
1704 /**************************************************************************
1705 * DPA_Clone [COMCTL32.331]
1707 * Copies a pointer array to an other one or creates a copy
1710 * hdpa [I] handle (pointer) to the existing (source) pointer array
1711 * hdpaNew [O] handle (pointer) to the destination pointer array
1714 * Success: pointer to the destination pointer array.
1718 * - If the 'hdpaNew' is a NULL-Pointer, a copy of the source pointer
1719 * array will be created and it's handle (pointer) is returned.
1720 * - If 'hdpa' is a NULL-Pointer, the original implementation crashes,
1721 * this implementation just returns NULL.
1725 DPA_Clone (const HDPA hdpa, const HDPA hdpaNew)
1727 INT nNewItems, nSize;
1733 TRACE("(%p %p)\n", hdpa, hdpaNew);
1736 /* create a new DPA */
1737 hdpaTemp = (HDPA)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1739 hdpaTemp->hHeap = hdpa->hHeap;
1740 hdpaTemp->nGrow = hdpa->nGrow;
1745 if (hdpaTemp->ptrs) {
1746 /* remove old pointer array */
1747 HeapFree (hdpaTemp->hHeap, 0, hdpaTemp->ptrs);
1748 hdpaTemp->ptrs = NULL;
1749 hdpaTemp->nItemCount = 0;
1750 hdpaTemp->nMaxCount = 0;
1753 /* create a new pointer array */
1754 nNewItems = hdpaTemp->nGrow *
1755 ((INT)((hdpa->nItemCount - 1) / hdpaTemp->nGrow) + 1);
1756 nSize = nNewItems * sizeof(LPVOID);
1758 (LPVOID*)HeapAlloc (hdpaTemp->hHeap, HEAP_ZERO_MEMORY, nSize);
1759 hdpaTemp->nMaxCount = nNewItems;
1761 /* clone the pointer array */
1762 hdpaTemp->nItemCount = hdpa->nItemCount;
1763 memmove (hdpaTemp->ptrs, hdpa->ptrs,
1764 hdpaTemp->nItemCount * sizeof(LPVOID));
1770 /**************************************************************************
1771 * DPA_GetPtr [COMCTL32.332]
1773 * Retrieves a pointer from a dynamic pointer array
1776 * hdpa [I] handle (pointer) to the pointer array
1777 * nIndex [I] array index of the desired pointer
1785 DPA_GetPtr (const HDPA hdpa, INT i)
1787 TRACE("(%p %d)\n", hdpa, i);
1792 WARN("no pointer array.\n");
1795 if ((i < 0) || (i >= hdpa->nItemCount)) {
1796 WARN("not enough pointers in array (%d vs %d).\n",i,hdpa->nItemCount);
1800 TRACE("-- %p\n", hdpa->ptrs[i]);
1802 return hdpa->ptrs[i];
1806 /**************************************************************************
1807 * DPA_GetPtrIndex [COMCTL32.333]
1809 * Retrieves the index of the specified pointer
1812 * hdpa [I] handle (pointer) to the pointer array
1816 * Success: index of the specified pointer
1821 DPA_GetPtrIndex (const HDPA hdpa, LPVOID p)
1828 for (i = 0; i < hdpa->nItemCount; i++) {
1829 if (hdpa->ptrs[i] == p)
1837 /**************************************************************************
1838 * DPA_InsertPtr [COMCTL32.334]
1840 * Inserts a pointer into a dynamic pointer array
1843 * hdpa [I] handle (pointer) to the array
1845 * p [I] pointer to insert
1848 * Success: index of the inserted pointer
1853 DPA_InsertPtr (const HDPA hdpa, INT i, LPVOID p)
1855 INT nNewItems, nSize, nIndex = 0;
1856 LPVOID *lpTemp, *lpDest;
1858 TRACE("(%p %d %p)\n", hdpa, i, p);
1860 if ((!hdpa) || (i < 0))
1865 (LPVOID*)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1866 2 * hdpa->nGrow * sizeof(LPVOID));
1869 hdpa->nMaxCount = hdpa->nGrow * 2;
1873 if (hdpa->nItemCount >= hdpa->nMaxCount) {
1874 TRACE("-- resizing\n");
1875 nNewItems = hdpa->nMaxCount + hdpa->nGrow;
1876 nSize = nNewItems * sizeof(LPVOID);
1878 lpTemp = (LPVOID*)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1882 hdpa->nMaxCount = nNewItems;
1883 hdpa->ptrs = lpTemp;
1886 if (i >= hdpa->nItemCount) {
1887 nIndex = hdpa->nItemCount;
1888 TRACE("-- appending at %d\n", nIndex);
1891 TRACE("-- inserting at %d\n", i);
1892 lpTemp = hdpa->ptrs + i;
1893 lpDest = lpTemp + 1;
1894 nSize = (hdpa->nItemCount - i) * sizeof(LPVOID);
1895 TRACE("-- move dest=%p src=%p size=%x\n",
1896 lpDest, lpTemp, nSize);
1897 memmove (lpDest, lpTemp, nSize);
1904 hdpa->ptrs[nIndex] = p;
1910 /**************************************************************************
1911 * DPA_SetPtr [COMCTL32.335]
1913 * Sets a pointer in the pointer array
1916 * hdpa [I] handle (pointer) to the pointer array
1917 * i [I] index of the pointer that will be set
1918 * p [I] pointer to be set
1926 DPA_SetPtr (const HDPA hdpa, INT i, LPVOID p)
1930 TRACE("(%p %d %p)\n", hdpa, i, p);
1932 if ((!hdpa) || i < 0)
1935 if (hdpa->nItemCount <= i) {
1936 /* within the old array */
1937 if (hdpa->nMaxCount > i) {
1938 /* within the allocated space, set a new boundary */
1939 hdpa->nItemCount = i+1;
1942 /* resize the block of memory */
1944 hdpa->nGrow * ((INT)(((i+1) - 1) / hdpa->nGrow) + 1);
1945 INT nSize = nNewItems * sizeof(LPVOID);
1947 lpTemp = (LPVOID*)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1952 hdpa->nItemCount = nNewItems;
1953 hdpa->ptrs = lpTemp;
1957 /* put the new entry in */
1964 /**************************************************************************
1965 * DPA_DeletePtr [COMCTL32.336]
1967 * Removes a pointer from the pointer array.
1970 * hdpa [I] handle (pointer) to the pointer array
1971 * i [I] index of the pointer that will be deleted
1974 * Success: deleted pointer
1979 DPA_DeletePtr (const HDPA hdpa, INT i)
1981 LPVOID *lpDest, *lpSrc, lpTemp = NULL;
1984 TRACE("(%p %d)\n", hdpa, i);
1986 if ((!hdpa) || i < 0 || i >= hdpa->nItemCount)
1989 lpTemp = hdpa->ptrs[i];
1991 /* do we need to move ?*/
1992 if (i < hdpa->nItemCount - 1) {
1993 lpDest = hdpa->ptrs + i;
1995 nSize = (hdpa->nItemCount - i - 1) * sizeof(LPVOID);
1996 TRACE("-- move dest=%p src=%p size=%x\n",
1997 lpDest, lpSrc, nSize);
1998 memmove (lpDest, lpSrc, nSize);
2001 hdpa->nItemCount --;
2004 if ((hdpa->nMaxCount - hdpa->nItemCount) >= hdpa->nGrow) {
2005 INT nNewItems = max(hdpa->nGrow * 2, hdpa->nItemCount);
2006 nSize = nNewItems * sizeof(LPVOID);
2007 lpDest = (LPVOID)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
2012 hdpa->nMaxCount = nNewItems;
2013 hdpa->ptrs = (LPVOID*)lpDest;
2020 /**************************************************************************
2021 * DPA_DeleteAllPtrs [COMCTL32.337]
2023 * Removes all pointers and reinitializes the array.
2026 * hdpa [I] handle (pointer) to the pointer array
2034 DPA_DeleteAllPtrs (const HDPA hdpa)
2036 TRACE("(%p)\n", hdpa);
2041 if (hdpa->ptrs && (!HeapFree (hdpa->hHeap, 0, hdpa->ptrs)))
2044 hdpa->nItemCount = 0;
2045 hdpa->nMaxCount = hdpa->nGrow * 2;
2046 hdpa->ptrs = (LPVOID*)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
2047 hdpa->nMaxCount * sizeof(LPVOID));
2053 /**************************************************************************
2054 * DPA_QuickSort [Internal]
2056 * Ordinary quicksort (used by DPA_Sort).
2059 * lpPtrs [I] pointer to the pointer array
2060 * l [I] index of the "left border" of the partition
2061 * r [I] index of the "right border" of the partition
2062 * pfnCompare [I] pointer to the compare function
2063 * lParam [I] user defined value (3rd parameter in compare function)
2070 DPA_QuickSort (LPVOID *lpPtrs, INT l, INT r,
2071 PFNDPACOMPARE pfnCompare, LPARAM lParam)
2076 TRACE("l=%i r=%i\n", l, r);
2078 if (l==r) /* one element is always sorted */
2080 if (r<l) /* oops, got it in the wrong order */
2082 DPA_QuickSort(lpPtrs, r, l, pfnCompare, lParam);
2085 m = (l+r)/2; /* divide by two */
2086 DPA_QuickSort(lpPtrs, l, m, pfnCompare, lParam);
2087 DPA_QuickSort(lpPtrs, m+1, r, pfnCompare, lParam);
2089 /* join the two sides */
2090 while( (l<=m) && (m<r) )
2092 if(pfnCompare(lpPtrs[l],lpPtrs[m+1],lParam)>0)
2095 memmove(&lpPtrs[l+1],&lpPtrs[l],(m-l+1)*sizeof lpPtrs[l]);
2105 /**************************************************************************
2106 * DPA_Sort [COMCTL32.338]
2108 * Sorts a pointer array using a user defined compare function
2111 * hdpa [I] handle (pointer) to the pointer array
2112 * pfnCompare [I] pointer to the compare function
2113 * lParam [I] user defined value (3rd parameter of compare function)
2121 DPA_Sort (const HDPA hdpa, PFNDPACOMPARE pfnCompare, LPARAM lParam)
2123 if (!hdpa || !pfnCompare)
2126 TRACE("(%p %p 0x%lx)\n", hdpa, pfnCompare, lParam);
2128 if ((hdpa->nItemCount > 1) && (hdpa->ptrs))
2129 DPA_QuickSort (hdpa->ptrs, 0, hdpa->nItemCount - 1,
2130 pfnCompare, lParam);
2136 /**************************************************************************
2137 * DPA_Search [COMCTL32.339]
2139 * Searches a pointer array for a specified pointer
2142 * hdpa [I] handle (pointer) to the pointer array
2143 * pFind [I] pointer to search for
2144 * nStart [I] start index
2145 * pfnCompare [I] pointer to the compare function
2146 * lParam [I] user defined value (3rd parameter of compare function)
2147 * uOptions [I] search options
2150 * Success: index of the pointer in the array.
2154 * Binary search taken from R.Sedgewick "Algorithms in C"!
2155 * Function is NOT tested!
2156 * If something goes wrong, blame HIM not ME! (Eric Kohl)
2160 DPA_Search (const HDPA hdpa, LPVOID pFind, INT nStart,
2161 PFNDPACOMPARE pfnCompare, LPARAM lParam, UINT uOptions)
2163 if (!hdpa || !pfnCompare || !pFind)
2166 TRACE("(%p %p %d %p 0x%08lx 0x%08x)\n",
2167 hdpa, pFind, nStart, pfnCompare, lParam, uOptions);
2169 if (uOptions & DPAS_SORTED) {
2170 /* array is sorted --> use binary search */
2174 TRACE("binary search\n");
2176 l = (nStart == -1) ? 0 : nStart;
2177 r = hdpa->nItemCount - 1;
2181 n = (pfnCompare)(pFind, lpPtr[x], lParam);
2187 TRACE("-- ret=%d\n", n);
2192 if (uOptions & DPAS_INSERTBEFORE) {
2193 TRACE("-- ret=%d\n", r);
2197 if (uOptions & DPAS_INSERTAFTER) {
2198 TRACE("-- ret=%d\n", l);
2203 /* array is not sorted --> use linear search */
2207 TRACE("linear search\n");
2209 nIndex = (nStart == -1)? 0 : nStart;
2211 for (; nIndex < hdpa->nItemCount; nIndex++) {
2212 if ((pfnCompare)(pFind, lpPtr[nIndex], lParam) == 0) {
2213 TRACE("-- ret=%d\n", nIndex);
2219 TRACE("-- not found: ret=-1\n");
2224 /**************************************************************************
2225 * DPA_CreateEx [COMCTL32.340]
2227 * Creates a dynamic pointer array using the specified size and heap.
2230 * nGrow [I] number of items by which the array grows when it is filled
2231 * hHeap [I] handle to the heap where the array is stored
2234 * Success: handle (pointer) to the pointer array.
2239 DPA_CreateEx (INT nGrow, HANDLE hHeap)
2243 TRACE("(%d 0x%x)\n", nGrow, hHeap);
2246 hdpa = (HDPA)HeapAlloc (hHeap, HEAP_ZERO_MEMORY, sizeof(DPA));
2248 hdpa = (HDPA)COMCTL32_Alloc (sizeof(DPA));
2251 hdpa->nGrow = min(8, nGrow);
2252 hdpa->hHeap = hHeap ? hHeap : COMCTL32_hHeap;
2253 hdpa->nMaxCount = hdpa->nGrow * 2;
2255 (LPVOID*)HeapAlloc (hHeap, HEAP_ZERO_MEMORY,
2256 hdpa->nMaxCount * sizeof(LPVOID));
2259 TRACE("-- %p\n", hdpa);
2265 /**************************************************************************
2266 * Notification functions
2269 typedef struct tagNOTIFYDATA
2277 } NOTIFYDATA, *LPNOTIFYDATA;
2280 /**************************************************************************
2281 * DoNotify [Internal]
2285 DoNotify (LPNOTIFYDATA lpNotify, UINT uCode, LPNMHDR lpHdr)
2288 LPNMHDR lpNmh = NULL;
2291 TRACE("(0x%04x 0x%04x %d %p 0x%08lx)\n",
2292 lpNotify->hwndFrom, lpNotify->hwndTo, uCode, lpHdr,
2293 lpNotify->dwParam5);
2295 if (!lpNotify->hwndTo)
2298 if (lpNotify->hwndFrom == -1) {
2300 idFrom = lpHdr->idFrom;
2303 if (lpNotify->hwndFrom) {
2304 HWND hwndParent = GetParent (lpNotify->hwndFrom);
2306 hwndParent = GetWindow (lpNotify->hwndFrom, GW_OWNER);
2308 idFrom = GetDlgCtrlID (lpNotify->hwndFrom);
2312 lpNmh = (lpHdr) ? lpHdr : &nmhdr;
2314 lpNmh->hwndFrom = lpNotify->hwndFrom;
2315 lpNmh->idFrom = idFrom;
2316 lpNmh->code = uCode;
2319 return SendMessageA (lpNotify->hwndTo, WM_NOTIFY, idFrom, (LPARAM)lpNmh);
2323 /**************************************************************************
2324 * SendNotify [COMCTL32.341]
2333 * Success: return value from notification
2338 COMCTL32_SendNotify (HWND hwndFrom, HWND hwndTo,
2339 UINT uCode, LPNMHDR lpHdr)
2343 TRACE("(0x%04x 0x%04x %d %p)\n",
2344 hwndFrom, hwndTo, uCode, lpHdr);
2346 notify.hwndFrom = hwndFrom;
2347 notify.hwndTo = hwndTo;
2348 notify.dwParam5 = 0;
2349 notify.dwParam6 = 0;
2351 return DoNotify (¬ify, uCode, lpHdr);
2355 /**************************************************************************
2356 * SendNotifyEx [COMCTL32.342]
2366 * Success: return value from notification
2371 COMCTL32_SendNotifyEx (HWND hwndTo, HWND hwndFrom, UINT uCode,
2372 LPNMHDR lpHdr, DWORD dwParam5)
2377 TRACE("(0x%04x 0x%04x %d %p 0x%08lx)\n",
2378 hwndFrom, hwndTo, uCode, lpHdr, dwParam5);
2380 hwndNotify = hwndTo;
2382 if (IsWindow (hwndFrom)) {
2383 hwndNotify = GetParent (hwndFrom);
2389 notify.hwndFrom = hwndFrom;
2390 notify.hwndTo = hwndNotify;
2391 notify.dwParam5 = dwParam5;
2392 notify.dwParam6 = 0;
2394 return DoNotify (¬ify, uCode, lpHdr);
2398 /**************************************************************************
2399 * StrChrA [COMCTL32.350]
2404 COMCTL32_StrChrA (LPCSTR lpString, CHAR cChar)
2406 return strchr (lpString, cChar);
2410 /**************************************************************************
2411 * StrStrIA [COMCTL32.355]
2415 COMCTL32_StrStrIA (LPCSTR lpStr1, LPCSTR lpStr2)
2421 return ((LPSTR)lpStr1);
2423 while (lpStr1[len1] != 0) ++len1;
2425 while (lpStr2[len2] != 0) ++len2;
2427 return ((LPSTR)(lpStr1 + len1));
2428 first = tolower (*lpStr2);
2429 while (len1 >= len2) {
2430 if (tolower(*lpStr1) == first) {
2431 for (i = 1; i < len2; ++i)
2432 if (tolower (lpStr1[i]) != tolower(lpStr2[i]))
2435 return ((LPSTR)lpStr1);
2443 /**************************************************************************
2444 * StrToIntA [COMCTL32.357] Converts a string to a signed integer.
2448 COMCTL32_StrToIntA (LPSTR lpString)
2450 return atoi(lpString);
2453 /**************************************************************************
2454 * StrToIntW [COMCTL32.365] Converts a wide char string to a signed integer.
2458 COMCTL32_StrToIntW (LPWSTR lpString)
2460 return _wtoi(lpString);
2464 /**************************************************************************
2465 * DPA_EnumCallback [COMCTL32.385]
2467 * Enumerates all items in a dynamic pointer array.
2470 * hdpa [I] handle to the dynamic pointer array
2479 DPA_EnumCallback (const HDPA hdpa, DPAENUMPROC enumProc, LPARAM lParam)
2483 TRACE("(%p %p %08lx)\n", hdpa, enumProc, lParam);
2487 if (hdpa->nItemCount <= 0)
2490 for (i = 0; i < hdpa->nItemCount; i++) {
2491 if ((enumProc)(hdpa->ptrs[i], lParam) == 0)
2499 /**************************************************************************
2500 * DPA_DestroyCallback [COMCTL32.386]
2502 * Enumerates all items in a dynamic pointer array and destroys it.
2505 * hdpa [I] handle to the dynamic pointer array
2515 DPA_DestroyCallback (const HDPA hdpa, DPAENUMPROC enumProc, LPARAM lParam)
2517 TRACE("(%p %p %08lx)\n", hdpa, enumProc, lParam);
2519 DPA_EnumCallback (hdpa, enumProc, lParam);
2521 return DPA_Destroy (hdpa);
2525 /**************************************************************************
2526 * DSA_EnumCallback [COMCTL32.387]
2528 * Enumerates all items in a dynamic storage array.
2531 * hdsa [I] handle to the dynamic storage array
2540 DSA_EnumCallback (const HDSA hdsa, DSAENUMPROC enumProc, LPARAM lParam)
2544 TRACE("(%p %p %08lx)\n", hdsa, enumProc, lParam);
2548 if (hdsa->nItemCount <= 0)
2551 for (i = 0; i < hdsa->nItemCount; i++) {
2552 LPVOID lpItem = DSA_GetItemPtr (hdsa, i);
2553 if ((enumProc)(lpItem, lParam) == 0)
2561 /**************************************************************************
2562 * DSA_DestroyCallback [COMCTL32.388]
2564 * Enumerates all items in a dynamic storage array and destroys it.
2567 * hdsa [I] handle to the dynamic storage array
2577 DSA_DestroyCallback (const HDSA hdsa, DSAENUMPROC enumProc, LPARAM lParam)
2579 TRACE("(%p %p %08lx)\n", hdsa, enumProc, lParam);
2581 DSA_EnumCallback (hdsa, enumProc, lParam);
2583 return DSA_Destroy (hdsa);
2586 /**************************************************************************
2587 * StrCSpnA [COMCTL32.356]
2590 INT WINAPI COMCTL32_StrCSpnA( LPCSTR lpStr, LPCSTR lpSet) {
2591 return strcspn(lpStr, lpSet);
2594 /**************************************************************************
2595 * StrChrW [COMCTL32.358]
2598 LPWSTR WINAPI COMCTL32_StrChrW( LPCWSTR lpStart, WORD wMatch) {
2599 return strchrW(lpStart, wMatch);
2602 /**************************************************************************
2603 * StrCmpNA [COMCTL32.352]
2606 INT WINAPI COMCTL32_StrCmpNA( LPCSTR lpStr1, LPCSTR lpStr2, int nChar) {
2607 return strncmp(lpStr1, lpStr2, nChar);
2610 /**************************************************************************
2611 * StrCmpNIA [COMCTL32.353]
2614 INT WINAPI COMCTL32_StrCmpNIA( LPCSTR lpStr1, LPCSTR lpStr2, int nChar) {
2615 return strncasecmp(lpStr1, lpStr2, nChar);
2618 /**************************************************************************
2619 * StrCmpNW [COMCTL32.360]
2622 INT WINAPI COMCTL32_StrCmpNW( LPCWSTR lpStr1, LPCWSTR lpStr2, int nChar) {
2623 return strncmpW(lpStr1, lpStr2, nChar);
2626 /**************************************************************************
2627 * StrCmpNIW [COMCTL32.361]
2630 INT WINAPI COMCTL32_StrCmpNIW( LPCWSTR lpStr1, LPCWSTR lpStr2, int nChar) {
2631 FIXME("(%s, %s, %i): stub\n", debugstr_w(lpStr1), debugstr_w(lpStr2), nChar);
2635 /**************************************************************************
2636 * StrRChrA [COMCTL32.351]
2639 LPSTR WINAPI COMCTL32_StrRChrA( LPCSTR lpStart, LPCSTR lpEnd, WORD wMatch )
2641 LPCSTR lpGotIt = NULL;
2642 BOOL dbcs = IsDBCSLeadByte( LOBYTE(wMatch) );
2644 TRACE("(%p, %p, %x)\n", lpStart, lpEnd, wMatch);
2646 if (!lpEnd) lpEnd = lpStart + strlen(lpStart);
2648 for(; lpStart < lpEnd; lpStart = CharNextA(lpStart))
2650 if (*lpStart != LOBYTE(wMatch)) continue;
2651 if (dbcs && lpStart[1] != HIBYTE(wMatch)) continue;
2654 return (LPSTR)lpGotIt;
2658 /**************************************************************************
2659 * StrRChrW [COMCTL32.359]
2662 LPWSTR WINAPI COMCTL32_StrRChrW( LPCWSTR lpStart, LPCWSTR lpEnd, WORD wMatch)
2664 LPCWSTR lpGotIt = NULL;
2666 TRACE("(%p, %p, %x)\n", lpStart, lpEnd, wMatch);
2667 if (!lpEnd) lpEnd = lpStart + strlenW(lpStart);
2669 for(; lpStart < lpEnd; lpStart = CharNextW(lpStart))
2670 if (*lpStart == wMatch) lpGotIt = lpStart;
2672 return (LPWSTR)lpGotIt;
2676 /**************************************************************************
2677 * StrStrA [COMCTL32.354]
2680 LPSTR WINAPI COMCTL32_StrStrA( LPCSTR lpFirst, LPCSTR lpSrch) {
2681 return strstr(lpFirst, lpSrch);
2684 /**************************************************************************
2685 * StrStrW [COMCTL32.362]
2688 LPWSTR WINAPI COMCTL32_StrStrW( LPCWSTR lpFirst, LPCWSTR lpSrch) {
2689 return strstrW(lpFirst, lpSrch);
2692 /**************************************************************************
2693 * StrSpnW [COMCTL32.364]
2696 INT WINAPI COMCTL32_StrSpnW( LPWSTR lpStr, LPWSTR lpSet) {
2697 LPWSTR lpLoop = lpStr;
2700 if ((lpStr == 0) || (lpSet == 0)) return 0;
2702 /* while(*lpLoop) { if lpLoop++; } */
2704 for(; (*lpLoop != 0); lpLoop++)
2705 if( strchrW(lpSet, *(WORD*)lpLoop))
2706 return (INT)(lpLoop-lpStr);
2708 return (INT)(lpLoop-lpStr);
2711 /**************************************************************************
2714 * FIXME: What's this supposed to do?
2715 * Parameter 1 is an HWND, you're on your own for the rest.
2718 BOOL WINAPI COMCTL32_410( HWND hw, DWORD b, DWORD c, DWORD d) {
2720 FIXME("(%x, %lx, %lx, %lx): stub!\n", hw, b, c, d);
2725 /**************************************************************************
2728 * FIXME: What's this supposed to do?
2729 * Parameter 1 is an HWND, you're on your own for the rest.
2732 BOOL WINAPI COMCTL32_411( HWND hw, DWORD b, DWORD c) {
2734 FIXME("(%x, %lx, %lx): stub!\n", hw, b, c);
2739 /**************************************************************************
2742 * FIXME: What's this supposed to do?
2743 * Parameter 1 is an HWND, you're on your own for the rest.
2746 BOOL WINAPI COMCTL32_412( HWND hwnd, DWORD b, DWORD c)
2748 FIXME("(%x, %lx, %lx): stub!\n", hwnd, b, c);
2750 if (IsWindow (hwnd) == FALSE)
2760 /**************************************************************************
2763 * FIXME: What's this supposed to do?
2764 * Parameter 1 is an HWND, you're on your own for the rest.
2767 BOOL WINAPI COMCTL32_413( HWND hw, DWORD b, DWORD c, DWORD d) {
2769 FIXME("(%x, %lx, %lx, %lx): stub!\n", hw, b, c, d);
2775 /**************************************************************************
2778 * FIXME: What's this supposed to do?
2779 * Parameter 1 is an HWND, you're on your own for the rest.
2782 BOOL WINAPI COMCTL32_415( HWND hwnd, DWORD b, DWORD c, DWORD d, DWORD e)
2785 FIXME("(%x, %lx, %lx, %lx, %lx): stub!\n", hwnd, b, c, d, e);
2790 /**************************************************************************
2793 * FIXME: What's this supposed to do?
2796 BOOL WINAPI COMCTL32_419( DWORD a, DWORD b, DWORD c, DWORD d)
2799 FIXME("(%lx, %lx, %lx, %lx): stub!\n", a, b, c, d);