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;
1474 LPVOID lpTemp, lpDest;
1476 TRACE("(%p %d %p)\n", hdsa, nIndex, pSrc);
1478 if ((!hdsa) || nIndex < 0)
1481 /* when nIndex >= nItemCount then append */
1482 if (nIndex >= hdsa->nItemCount)
1483 nIndex = hdsa->nItemCount;
1485 /* do we need to resize ? */
1486 if (hdsa->nItemCount >= hdsa->nMaxCount) {
1487 nNewItems = hdsa->nMaxCount + hdsa->nGrow;
1488 nSize = hdsa->nItemSize * nNewItems;
1490 lpTemp = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
1494 hdsa->nMaxCount = nNewItems;
1495 hdsa->pData = lpTemp;
1498 /* do we need to move elements ? */
1499 if (nIndex < hdsa->nItemCount) {
1500 lpTemp = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1501 lpDest = (char *) lpTemp + hdsa->nItemSize;
1502 nSize = (hdsa->nItemCount - nIndex) * hdsa->nItemSize;
1503 TRACE("-- move dest=%p src=%p size=%d\n",
1504 lpDest, lpTemp, nSize);
1505 memmove (lpDest, lpTemp, nSize);
1508 /* ok, we can put the new Item in */
1510 lpDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1511 TRACE("-- move dest=%p src=%p size=%d\n",
1512 lpDest, pSrc, hdsa->nItemSize);
1513 memmove (lpDest, pSrc, hdsa->nItemSize);
1519 /**************************************************************************
1520 * DSA_DeleteItem [COMCTL32.326]
1523 * hdsa [I] pointer to the array control structure
1524 * nIndex [I] index for the element to delete
1527 * Success: number of the deleted element
1532 DSA_DeleteItem (const HDSA hdsa, INT nIndex)
1534 LPVOID lpDest,lpSrc;
1537 TRACE("(%p %d)\n", hdsa, nIndex);
1541 if (nIndex < 0 || nIndex >= hdsa->nItemCount)
1544 /* do we need to move ? */
1545 if (nIndex < hdsa->nItemCount - 1) {
1546 lpDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1547 lpSrc = (char *) lpDest + hdsa->nItemSize;
1548 nSize = hdsa->nItemSize * (hdsa->nItemCount - nIndex - 1);
1549 TRACE("-- move dest=%p src=%p size=%d\n",
1550 lpDest, lpSrc, nSize);
1551 memmove (lpDest, lpSrc, nSize);
1557 if ((hdsa->nMaxCount - hdsa->nItemCount) >= hdsa->nGrow) {
1558 nSize = hdsa->nItemSize * hdsa->nItemCount;
1560 lpDest = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
1564 hdsa->nMaxCount = hdsa->nItemCount;
1565 hdsa->pData = lpDest;
1572 /**************************************************************************
1573 * DSA_DeleteAllItems [COMCTL32.327]
1575 * Removes all items and reinitializes the array.
1578 * hdsa [I] pointer to the array control structure
1586 DSA_DeleteAllItems (const HDSA hdsa)
1588 TRACE("(%p)\n", hdsa);
1592 if (hdsa->pData && (!COMCTL32_Free (hdsa->pData)))
1595 hdsa->nItemCount = 0;
1597 hdsa->nMaxCount = 0;
1603 /**************************************************************************
1604 * The DPA-API is a set of functions to create and manipulate arrays of
1608 /**************************************************************************
1609 * DPA_Create [COMCTL32.328] Creates a dynamic pointer array
1612 * nGrow [I] number of items by which the array grows when it is filled
1615 * Success: handle (pointer) to the pointer array.
1620 DPA_Create (INT nGrow)
1624 TRACE("(%d)\n", nGrow);
1626 hdpa = (HDPA)COMCTL32_Alloc (sizeof(DPA));
1628 hdpa->nGrow = max(8, nGrow);
1629 hdpa->hHeap = COMCTL32_hHeap;
1630 hdpa->nMaxCount = hdpa->nGrow * 2;
1632 (LPVOID*)COMCTL32_Alloc (hdpa->nMaxCount * sizeof(LPVOID));
1635 TRACE("-- %p\n", hdpa);
1641 /**************************************************************************
1642 * DPA_Destroy [COMCTL32.329] Destroys a dynamic pointer array
1645 * hdpa [I] handle (pointer) to the pointer array
1653 DPA_Destroy (const HDPA hdpa)
1655 TRACE("(%p)\n", hdpa);
1660 if (hdpa->ptrs && (!HeapFree (hdpa->hHeap, 0, hdpa->ptrs)))
1663 return HeapFree (hdpa->hHeap, 0, hdpa);
1667 /**************************************************************************
1668 * DPA_Grow [COMCTL32.330]
1670 * Sets the growth amount.
1673 * hdpa [I] handle (pointer) to the existing (source) pointer array
1674 * nGrow [I] number of items by which the array grows when it's too small
1682 DPA_Grow (const HDPA hdpa, INT nGrow)
1684 TRACE("(%p %d)\n", hdpa, nGrow);
1689 hdpa->nGrow = max(8, nGrow);
1695 /**************************************************************************
1696 * DPA_Clone [COMCTL32.331]
1698 * Copies a pointer array to an other one or creates a copy
1701 * hdpa [I] handle (pointer) to the existing (source) pointer array
1702 * hdpaNew [O] handle (pointer) to the destination pointer array
1705 * Success: pointer to the destination pointer array.
1709 * - If the 'hdpaNew' is a NULL-Pointer, a copy of the source pointer
1710 * array will be created and it's handle (pointer) is returned.
1711 * - If 'hdpa' is a NULL-Pointer, the original implementation crashes,
1712 * this implementation just returns NULL.
1716 DPA_Clone (const HDPA hdpa, const HDPA hdpaNew)
1718 INT nNewItems, nSize;
1724 TRACE("(%p %p)\n", hdpa, hdpaNew);
1727 /* create a new DPA */
1728 hdpaTemp = (HDPA)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1730 hdpaTemp->hHeap = hdpa->hHeap;
1731 hdpaTemp->nGrow = hdpa->nGrow;
1736 if (hdpaTemp->ptrs) {
1737 /* remove old pointer array */
1738 HeapFree (hdpaTemp->hHeap, 0, hdpaTemp->ptrs);
1739 hdpaTemp->ptrs = NULL;
1740 hdpaTemp->nItemCount = 0;
1741 hdpaTemp->nMaxCount = 0;
1744 /* create a new pointer array */
1745 nNewItems = hdpaTemp->nGrow *
1746 ((INT)((hdpa->nItemCount - 1) / hdpaTemp->nGrow) + 1);
1747 nSize = nNewItems * sizeof(LPVOID);
1749 (LPVOID*)HeapAlloc (hdpaTemp->hHeap, HEAP_ZERO_MEMORY, nSize);
1750 hdpaTemp->nMaxCount = nNewItems;
1752 /* clone the pointer array */
1753 hdpaTemp->nItemCount = hdpa->nItemCount;
1754 memmove (hdpaTemp->ptrs, hdpa->ptrs,
1755 hdpaTemp->nItemCount * sizeof(LPVOID));
1761 /**************************************************************************
1762 * DPA_GetPtr [COMCTL32.332]
1764 * Retrieves a pointer from a dynamic pointer array
1767 * hdpa [I] handle (pointer) to the pointer array
1768 * nIndex [I] array index of the desired pointer
1776 DPA_GetPtr (const HDPA hdpa, INT i)
1778 TRACE("(%p %d)\n", hdpa, i);
1783 WARN("no pointer array.\n");
1786 if ((i < 0) || (i >= hdpa->nItemCount)) {
1787 WARN("not enough pointers in array (%d vs %d).\n",i,hdpa->nItemCount);
1791 TRACE("-- %p\n", hdpa->ptrs[i]);
1793 return hdpa->ptrs[i];
1797 /**************************************************************************
1798 * DPA_GetPtrIndex [COMCTL32.333]
1800 * Retrieves the index of the specified pointer
1803 * hdpa [I] handle (pointer) to the pointer array
1807 * Success: index of the specified pointer
1812 DPA_GetPtrIndex (const HDPA hdpa, LPVOID p)
1819 for (i = 0; i < hdpa->nItemCount; i++) {
1820 if (hdpa->ptrs[i] == p)
1828 /**************************************************************************
1829 * DPA_InsertPtr [COMCTL32.334]
1831 * Inserts a pointer into a dynamic pointer array
1834 * hdpa [I] handle (pointer) to the array
1836 * p [I] pointer to insert
1839 * Success: index of the inserted pointer
1844 DPA_InsertPtr (const HDPA hdpa, INT i, LPVOID p)
1846 INT nNewItems, nSize, nIndex = 0;
1847 LPVOID *lpTemp, *lpDest;
1849 TRACE("(%p %d %p)\n", hdpa, i, p);
1851 if ((!hdpa) || (i < 0))
1856 (LPVOID*)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1857 2 * hdpa->nGrow * sizeof(LPVOID));
1860 hdpa->nMaxCount = hdpa->nGrow * 2;
1864 if (hdpa->nItemCount >= hdpa->nMaxCount) {
1865 TRACE("-- resizing\n");
1866 nNewItems = hdpa->nMaxCount + hdpa->nGrow;
1867 nSize = nNewItems * sizeof(LPVOID);
1869 lpTemp = (LPVOID*)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1873 hdpa->nMaxCount = nNewItems;
1874 hdpa->ptrs = lpTemp;
1877 if (i >= hdpa->nItemCount) {
1878 nIndex = hdpa->nItemCount;
1879 TRACE("-- appending at %d\n", nIndex);
1882 TRACE("-- inserting at %d\n", i);
1883 lpTemp = hdpa->ptrs + i;
1884 lpDest = lpTemp + 1;
1885 nSize = (hdpa->nItemCount - i) * sizeof(LPVOID);
1886 TRACE("-- move dest=%p src=%p size=%x\n",
1887 lpDest, lpTemp, nSize);
1888 memmove (lpDest, lpTemp, nSize);
1895 hdpa->ptrs[nIndex] = p;
1901 /**************************************************************************
1902 * DPA_SetPtr [COMCTL32.335]
1904 * Sets a pointer in the pointer array
1907 * hdpa [I] handle (pointer) to the pointer array
1908 * i [I] index of the pointer that will be set
1909 * p [I] pointer to be set
1917 DPA_SetPtr (const HDPA hdpa, INT i, LPVOID p)
1921 TRACE("(%p %d %p)\n", hdpa, i, p);
1923 if ((!hdpa) || i < 0)
1926 if (hdpa->nItemCount <= i) {
1927 /* within the old array */
1928 if (hdpa->nMaxCount > i) {
1929 /* within the allocated space, set a new boundary */
1930 hdpa->nItemCount = i+1;
1933 /* resize the block of memory */
1935 hdpa->nGrow * ((INT)(((i+1) - 1) / hdpa->nGrow) + 1);
1936 INT nSize = nNewItems * sizeof(LPVOID);
1938 lpTemp = (LPVOID*)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1943 hdpa->nItemCount = nNewItems;
1944 hdpa->ptrs = lpTemp;
1948 /* put the new entry in */
1955 /**************************************************************************
1956 * DPA_DeletePtr [COMCTL32.336]
1958 * Removes a pointer from the pointer array.
1961 * hdpa [I] handle (pointer) to the pointer array
1962 * i [I] index of the pointer that will be deleted
1965 * Success: deleted pointer
1970 DPA_DeletePtr (const HDPA hdpa, INT i)
1972 LPVOID *lpDest, *lpSrc, lpTemp = NULL;
1975 TRACE("(%p %d)\n", hdpa, i);
1977 if ((!hdpa) || i < 0 || i >= hdpa->nItemCount)
1980 lpTemp = hdpa->ptrs[i];
1982 /* do we need to move ?*/
1983 if (i < hdpa->nItemCount - 1) {
1984 lpDest = hdpa->ptrs + i;
1986 nSize = (hdpa->nItemCount - i - 1) * sizeof(LPVOID);
1987 TRACE("-- move dest=%p src=%p size=%x\n",
1988 lpDest, lpSrc, nSize);
1989 memmove (lpDest, lpSrc, nSize);
1992 hdpa->nItemCount --;
1995 if ((hdpa->nMaxCount - hdpa->nItemCount) >= hdpa->nGrow) {
1996 INT nNewItems = max(hdpa->nGrow * 2, hdpa->nItemCount);
1997 nSize = nNewItems * sizeof(LPVOID);
1998 lpDest = (LPVOID)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
2003 hdpa->nMaxCount = nNewItems;
2004 hdpa->ptrs = (LPVOID*)lpDest;
2011 /**************************************************************************
2012 * DPA_DeleteAllPtrs [COMCTL32.337]
2014 * Removes all pointers and reinitializes the array.
2017 * hdpa [I] handle (pointer) to the pointer array
2025 DPA_DeleteAllPtrs (const HDPA hdpa)
2027 TRACE("(%p)\n", hdpa);
2032 if (hdpa->ptrs && (!HeapFree (hdpa->hHeap, 0, hdpa->ptrs)))
2035 hdpa->nItemCount = 0;
2036 hdpa->nMaxCount = hdpa->nGrow * 2;
2037 hdpa->ptrs = (LPVOID*)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
2038 hdpa->nMaxCount * sizeof(LPVOID));
2044 /**************************************************************************
2045 * DPA_QuickSort [Internal]
2047 * Ordinary quicksort (used by DPA_Sort).
2050 * lpPtrs [I] pointer to the pointer array
2051 * l [I] index of the "left border" of the partition
2052 * r [I] index of the "right border" of the partition
2053 * pfnCompare [I] pointer to the compare function
2054 * lParam [I] user defined value (3rd parameter in compare function)
2061 DPA_QuickSort (LPVOID *lpPtrs, INT l, INT r,
2062 PFNDPACOMPARE pfnCompare, LPARAM lParam)
2067 TRACE("l=%i r=%i\n", l, r);
2069 if (l==r) /* one element is always sorted */
2071 if (r<l) /* oops, got it in the wrong order */
2073 DPA_QuickSort(lpPtrs, r, l, pfnCompare, lParam);
2076 m = (l+r)/2; /* divide by two */
2077 DPA_QuickSort(lpPtrs, l, m, pfnCompare, lParam);
2078 DPA_QuickSort(lpPtrs, m+1, r, pfnCompare, lParam);
2080 /* join the two sides */
2081 while( (l<=m) && (m<r) )
2083 if(pfnCompare(lpPtrs[l],lpPtrs[m+1],lParam)>0)
2086 memmove(&lpPtrs[l+1],&lpPtrs[l],(m-l+1)*sizeof lpPtrs[l]);
2096 /**************************************************************************
2097 * DPA_Sort [COMCTL32.338]
2099 * Sorts a pointer array using a user defined compare function
2102 * hdpa [I] handle (pointer) to the pointer array
2103 * pfnCompare [I] pointer to the compare function
2104 * lParam [I] user defined value (3rd parameter of compare function)
2112 DPA_Sort (const HDPA hdpa, PFNDPACOMPARE pfnCompare, LPARAM lParam)
2114 if (!hdpa || !pfnCompare)
2117 TRACE("(%p %p 0x%lx)\n", hdpa, pfnCompare, lParam);
2119 if ((hdpa->nItemCount > 1) && (hdpa->ptrs))
2120 DPA_QuickSort (hdpa->ptrs, 0, hdpa->nItemCount - 1,
2121 pfnCompare, lParam);
2127 /**************************************************************************
2128 * DPA_Search [COMCTL32.339]
2130 * Searches a pointer array for a specified pointer
2133 * hdpa [I] handle (pointer) to the pointer array
2134 * pFind [I] pointer to search for
2135 * nStart [I] start index
2136 * pfnCompare [I] pointer to the compare function
2137 * lParam [I] user defined value (3rd parameter of compare function)
2138 * uOptions [I] search options
2141 * Success: index of the pointer in the array.
2145 * Binary search taken from R.Sedgewick "Algorithms in C"!
2146 * Function is NOT tested!
2147 * If something goes wrong, blame HIM not ME! (Eric Kohl)
2151 DPA_Search (const HDPA hdpa, LPVOID pFind, INT nStart,
2152 PFNDPACOMPARE pfnCompare, LPARAM lParam, UINT uOptions)
2154 if (!hdpa || !pfnCompare || !pFind)
2157 TRACE("(%p %p %d %p 0x%08lx 0x%08x)\n",
2158 hdpa, pFind, nStart, pfnCompare, lParam, uOptions);
2160 if (uOptions & DPAS_SORTED) {
2161 /* array is sorted --> use binary search */
2165 TRACE("binary search\n");
2167 l = (nStart == -1) ? 0 : nStart;
2168 r = hdpa->nItemCount - 1;
2172 n = (pfnCompare)(pFind, lpPtr[x], lParam);
2178 TRACE("-- ret=%d\n", n);
2183 if (uOptions & DPAS_INSERTBEFORE) {
2184 TRACE("-- ret=%d\n", r);
2188 if (uOptions & DPAS_INSERTAFTER) {
2189 TRACE("-- ret=%d\n", l);
2194 /* array is not sorted --> use linear search */
2198 TRACE("linear search\n");
2200 nIndex = (nStart == -1)? 0 : nStart;
2202 for (; nIndex < hdpa->nItemCount; nIndex++) {
2203 if ((pfnCompare)(pFind, lpPtr[nIndex], lParam) == 0) {
2204 TRACE("-- ret=%d\n", nIndex);
2210 TRACE("-- not found: ret=-1\n");
2215 /**************************************************************************
2216 * DPA_CreateEx [COMCTL32.340]
2218 * Creates a dynamic pointer array using the specified size and heap.
2221 * nGrow [I] number of items by which the array grows when it is filled
2222 * hHeap [I] handle to the heap where the array is stored
2225 * Success: handle (pointer) to the pointer array.
2230 DPA_CreateEx (INT nGrow, HANDLE hHeap)
2234 TRACE("(%d 0x%x)\n", nGrow, hHeap);
2237 hdpa = (HDPA)HeapAlloc (hHeap, HEAP_ZERO_MEMORY, sizeof(DPA));
2239 hdpa = (HDPA)COMCTL32_Alloc (sizeof(DPA));
2242 hdpa->nGrow = min(8, nGrow);
2243 hdpa->hHeap = hHeap ? hHeap : COMCTL32_hHeap;
2244 hdpa->nMaxCount = hdpa->nGrow * 2;
2246 (LPVOID*)HeapAlloc (hHeap, HEAP_ZERO_MEMORY,
2247 hdpa->nMaxCount * sizeof(LPVOID));
2250 TRACE("-- %p\n", hdpa);
2256 /**************************************************************************
2257 * Notification functions
2260 typedef struct tagNOTIFYDATA
2268 } NOTIFYDATA, *LPNOTIFYDATA;
2271 /**************************************************************************
2272 * DoNotify [Internal]
2276 DoNotify (LPNOTIFYDATA lpNotify, UINT uCode, LPNMHDR lpHdr)
2279 LPNMHDR lpNmh = NULL;
2282 TRACE("(0x%04x 0x%04x %d %p 0x%08lx)\n",
2283 lpNotify->hwndFrom, lpNotify->hwndTo, uCode, lpHdr,
2284 lpNotify->dwParam5);
2286 if (!lpNotify->hwndTo)
2289 if (lpNotify->hwndFrom == -1) {
2291 idFrom = lpHdr->idFrom;
2294 if (lpNotify->hwndFrom) {
2295 HWND hwndParent = GetParent (lpNotify->hwndFrom);
2297 hwndParent = GetWindow (lpNotify->hwndFrom, GW_OWNER);
2299 idFrom = GetDlgCtrlID (lpNotify->hwndFrom);
2303 lpNmh = (lpHdr) ? lpHdr : &nmhdr;
2305 lpNmh->hwndFrom = lpNotify->hwndFrom;
2306 lpNmh->idFrom = idFrom;
2307 lpNmh->code = uCode;
2310 return SendMessageA (lpNotify->hwndTo, WM_NOTIFY, idFrom, (LPARAM)lpNmh);
2314 /**************************************************************************
2315 * SendNotify [COMCTL32.341]
2324 * Success: return value from notification
2329 COMCTL32_SendNotify (HWND hwndFrom, HWND hwndTo,
2330 UINT uCode, LPNMHDR lpHdr)
2334 TRACE("(0x%04x 0x%04x %d %p)\n",
2335 hwndFrom, hwndTo, uCode, lpHdr);
2337 notify.hwndFrom = hwndFrom;
2338 notify.hwndTo = hwndTo;
2339 notify.dwParam5 = 0;
2340 notify.dwParam6 = 0;
2342 return DoNotify (¬ify, uCode, lpHdr);
2346 /**************************************************************************
2347 * SendNotifyEx [COMCTL32.342]
2357 * Success: return value from notification
2362 COMCTL32_SendNotifyEx (HWND hwndTo, HWND hwndFrom, UINT uCode,
2363 LPNMHDR lpHdr, DWORD dwParam5)
2368 TRACE("(0x%04x 0x%04x %d %p 0x%08lx)\n",
2369 hwndFrom, hwndTo, uCode, lpHdr, dwParam5);
2371 hwndNotify = hwndTo;
2373 if (IsWindow (hwndFrom)) {
2374 hwndNotify = GetParent (hwndFrom);
2380 notify.hwndFrom = hwndFrom;
2381 notify.hwndTo = hwndNotify;
2382 notify.dwParam5 = dwParam5;
2383 notify.dwParam6 = 0;
2385 return DoNotify (¬ify, uCode, lpHdr);
2389 /**************************************************************************
2390 * StrChrA [COMCTL32.350]
2395 COMCTL32_StrChrA (LPCSTR lpString, CHAR cChar)
2397 return strchr (lpString, cChar);
2401 /**************************************************************************
2402 * StrStrIA [COMCTL32.355]
2406 COMCTL32_StrStrIA (LPCSTR lpStr1, LPCSTR lpStr2)
2412 return ((LPSTR)lpStr1);
2414 while (lpStr1[len1] != 0) ++len1;
2416 while (lpStr2[len2] != 0) ++len2;
2418 return ((LPSTR)(lpStr1 + len1));
2419 first = tolower (*lpStr2);
2420 while (len1 >= len2) {
2421 if (tolower(*lpStr1) == first) {
2422 for (i = 1; i < len2; ++i)
2423 if (tolower (lpStr1[i]) != tolower(lpStr2[i]))
2426 return ((LPSTR)lpStr1);
2434 /**************************************************************************
2435 * StrToIntA [COMCTL32.357] Converts a string to a signed integer.
2439 COMCTL32_StrToIntA (LPSTR lpString)
2441 return atoi(lpString);
2444 /**************************************************************************
2445 * StrToIntW [COMCTL32.365] Converts a wide char string to a signed integer.
2449 COMCTL32_StrToIntW (LPWSTR lpString)
2451 return _wtoi(lpString);
2455 /**************************************************************************
2456 * DPA_EnumCallback [COMCTL32.385]
2458 * Enumerates all items in a dynamic pointer array.
2461 * hdpa [I] handle to the dynamic pointer array
2470 DPA_EnumCallback (const HDPA hdpa, DPAENUMPROC enumProc, LPARAM lParam)
2474 TRACE("(%p %p %08lx)\n", hdpa, enumProc, lParam);
2478 if (hdpa->nItemCount <= 0)
2481 for (i = 0; i < hdpa->nItemCount; i++) {
2482 if ((enumProc)(hdpa->ptrs[i], lParam) == 0)
2490 /**************************************************************************
2491 * DPA_DestroyCallback [COMCTL32.386]
2493 * Enumerates all items in a dynamic pointer array and destroys it.
2496 * hdpa [I] handle to the dynamic pointer array
2506 DPA_DestroyCallback (const HDPA hdpa, DPAENUMPROC enumProc, LPARAM lParam)
2508 TRACE("(%p %p %08lx)\n", hdpa, enumProc, lParam);
2510 DPA_EnumCallback (hdpa, enumProc, lParam);
2512 return DPA_Destroy (hdpa);
2516 /**************************************************************************
2517 * DSA_EnumCallback [COMCTL32.387]
2519 * Enumerates all items in a dynamic storage array.
2522 * hdsa [I] handle to the dynamic storage array
2531 DSA_EnumCallback (const HDSA hdsa, DSAENUMPROC enumProc, LPARAM lParam)
2535 TRACE("(%p %p %08lx)\n", hdsa, enumProc, lParam);
2539 if (hdsa->nItemCount <= 0)
2542 for (i = 0; i < hdsa->nItemCount; i++) {
2543 LPVOID lpItem = DSA_GetItemPtr (hdsa, i);
2544 if ((enumProc)(lpItem, lParam) == 0)
2552 /**************************************************************************
2553 * DSA_DestroyCallback [COMCTL32.388]
2555 * Enumerates all items in a dynamic storage array and destroys it.
2558 * hdsa [I] handle to the dynamic storage array
2568 DSA_DestroyCallback (const HDSA hdsa, DSAENUMPROC enumProc, LPARAM lParam)
2570 TRACE("(%p %p %08lx)\n", hdsa, enumProc, lParam);
2572 DSA_EnumCallback (hdsa, enumProc, lParam);
2574 return DSA_Destroy (hdsa);
2577 /**************************************************************************
2578 * StrCSpnA [COMCTL32.356]
2581 INT WINAPI COMCTL32_StrCSpnA( LPCSTR lpStr, LPCSTR lpSet) {
2582 return strcspn(lpStr, lpSet);
2585 /**************************************************************************
2586 * StrChrW [COMCTL32.358]
2589 LPWSTR WINAPI COMCTL32_StrChrW( LPCWSTR lpStart, WORD wMatch) {
2590 return strchrW(lpStart, wMatch);
2593 /**************************************************************************
2594 * StrCmpNA [COMCTL32.352]
2597 INT WINAPI COMCTL32_StrCmpNA( LPCSTR lpStr1, LPCSTR lpStr2, int nChar) {
2598 return strncmp(lpStr1, lpStr2, nChar);
2601 /**************************************************************************
2602 * StrCmpNIA [COMCTL32.353]
2605 INT WINAPI COMCTL32_StrCmpNIA( LPCSTR lpStr1, LPCSTR lpStr2, int nChar) {
2606 return strncasecmp(lpStr1, lpStr2, nChar);
2609 /**************************************************************************
2610 * StrCmpNW [COMCTL32.360]
2613 INT WINAPI COMCTL32_StrCmpNW( LPCWSTR lpStr1, LPCWSTR lpStr2, int nChar) {
2614 return strncmpW(lpStr1, lpStr2, nChar);
2617 /**************************************************************************
2618 * StrCmpNIW [COMCTL32.361]
2621 INT WINAPI COMCTL32_StrCmpNIW( LPCWSTR lpStr1, LPCWSTR lpStr2, int nChar) {
2622 FIXME("(%s, %s, %i): stub\n", debugstr_w(lpStr1), debugstr_w(lpStr2), nChar);
2626 /**************************************************************************
2627 * StrRChrA [COMCTL32.351]
2630 LPSTR WINAPI COMCTL32_StrRChrA( LPCSTR lpStart, LPCSTR lpEnd, WORD wMatch )
2632 LPCSTR lpGotIt = NULL;
2633 BOOL dbcs = IsDBCSLeadByte( LOBYTE(wMatch) );
2635 TRACE("(%p, %p, %x)\n", lpStart, lpEnd, wMatch);
2637 if (!lpEnd) lpEnd = lpStart + strlen(lpStart);
2639 for(; lpStart < lpEnd; lpStart = CharNextA(lpStart))
2641 if (*lpStart != LOBYTE(wMatch)) continue;
2642 if (dbcs && lpStart[1] != HIBYTE(wMatch)) continue;
2645 return (LPSTR)lpGotIt;
2649 /**************************************************************************
2650 * StrRChrW [COMCTL32.359]
2653 LPWSTR WINAPI COMCTL32_StrRChrW( LPCWSTR lpStart, LPCWSTR lpEnd, WORD wMatch)
2655 LPCWSTR lpGotIt = NULL;
2657 TRACE("(%p, %p, %x)\n", lpStart, lpEnd, wMatch);
2658 if (!lpEnd) lpEnd = lpStart + strlenW(lpStart);
2660 for(; lpStart < lpEnd; lpStart = CharNextW(lpStart))
2661 if (*lpStart == wMatch) lpGotIt = lpStart;
2663 return (LPWSTR)lpGotIt;
2667 /**************************************************************************
2668 * StrStrA [COMCTL32.354]
2671 LPSTR WINAPI COMCTL32_StrStrA( LPCSTR lpFirst, LPCSTR lpSrch) {
2672 return strstr(lpFirst, lpSrch);
2675 /**************************************************************************
2676 * StrStrW [COMCTL32.362]
2679 LPWSTR WINAPI COMCTL32_StrStrW( LPCWSTR lpFirst, LPCWSTR lpSrch) {
2680 return strstrW(lpFirst, lpSrch);
2683 /**************************************************************************
2684 * StrSpnW [COMCTL32.364]
2687 INT WINAPI COMCTL32_StrSpnW( LPWSTR lpStr, LPWSTR lpSet) {
2688 LPWSTR lpLoop = lpStr;
2691 if ((lpStr == 0) || (lpSet == 0)) return 0;
2693 /* while(*lpLoop) { if lpLoop++; } */
2695 for(; (*lpLoop != 0); lpLoop++)
2696 if( strchrW(lpSet, *(WORD*)lpLoop))
2697 return (INT)(lpLoop-lpStr);
2699 return (INT)(lpLoop-lpStr);
2702 /**************************************************************************
2705 * FIXME: What's this supposed to do?
2706 * Parameter 1 is an HWND, you're on your own for the rest.
2709 BOOL WINAPI COMCTL32_410( HWND hw, DWORD b, DWORD c, DWORD d) {
2711 FIXME("(%x, %lx, %lx, %lx): stub!\n", hw, b, c, d);
2716 /**************************************************************************
2719 * FIXME: What's this supposed to do?
2720 * Parameter 1 is an HWND, you're on your own for the rest.
2723 BOOL WINAPI COMCTL32_411( HWND hw, DWORD b, DWORD c) {
2725 FIXME("(%x, %lx, %lx): stub!\n", hw, b, c);
2730 /**************************************************************************
2733 * FIXME: What's this supposed to do?
2734 * Parameter 1 is an HWND, you're on your own for the rest.
2737 BOOL WINAPI COMCTL32_412( HWND hwnd, DWORD b, DWORD c)
2739 FIXME("(%x, %lx, %lx): stub!\n", hwnd, b, c);
2741 if (IsWindow (hwnd) == FALSE)
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_413( HWND hw, DWORD b, DWORD c, DWORD d) {
2760 FIXME("(%x, %lx, %lx, %lx): stub!\n", hw, b, c, d);
2766 /**************************************************************************
2769 * FIXME: What's this supposed to do?
2770 * Parameter 1 is an HWND, you're on your own for the rest.
2773 BOOL WINAPI COMCTL32_415( HWND hwnd, DWORD b, DWORD c, DWORD d, DWORD e)
2776 FIXME("(%x, %lx, %lx, %lx, %lx): stub!\n", hwnd, b, c, d, e);
2781 /**************************************************************************
2784 * FIXME: What's this supposed to do?
2787 BOOL WINAPI COMCTL32_419( DWORD a, DWORD b, DWORD c, DWORD d)
2790 FIXME("(%lx, %lx, %lx, %lx): stub!\n", a, b, c, d);