2 * Undocumented functions from COMCTL32.DLL
4 * Copyright 1998 Eric Kohl
5 * 1998 Juergen Schmied <j.schmied@metronet.de>
6 * 2000 Eric Kohl for CodeWeavers
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * All of these functions are UNDOCUMENTED!! And I mean UNDOCUMENTED!!!!
24 * Do NOT rely on names or contents of undocumented structures and types!!!
25 * These functions are used by EXPLORER.EXE, IEXPLORE.EXE and
26 * COMCTL32.DLL (internally).
29 * - Add more functions.
30 * - Write some documentation.
33 #include "wine/port.h"
37 #include <stdlib.h> /* atoi */
41 #define NONAMELESSUNION
42 #define NONAMELESSSTRUCT
53 #include "wine/unicode.h"
56 #include "wine/debug.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(commctrl);
61 extern HANDLE COMCTL32_hHeap; /* handle to the private heap */
64 typedef struct _STREAMDATA
69 } STREAMDATA, *PSTREAMDATA;
71 typedef struct _LOADDATA
75 } LOADDATA, *LPLOADDATA;
77 typedef HRESULT (CALLBACK *DPALOADPROC)(LPLOADDATA,IStream*,LPARAM);
79 /**************************************************************************
80 * DPA_LoadStream [COMCTL32.9]
82 * Loads a dynamic pointer array from a stream
85 * phDpa [O] pointer to a handle to a dynamic pointer array
86 * loadProc [I] pointer to a callback function
87 * pStream [I] pointer to a stream
88 * lParam [I] application specific value
91 * No more information available yet!
95 DPA_LoadStream (HDPA *phDpa, DPALOADPROC loadProc, IStream *pStream, LPARAM lParam)
98 LARGE_INTEGER position;
99 ULARGE_INTEGER newPosition;
100 STREAMDATA streamData;
106 FIXME ("phDpa=%p loadProc=%p pStream=%p lParam=%lx\n",
107 phDpa, loadProc, pStream, lParam);
109 if (!phDpa || !loadProc || !pStream)
114 position.QuadPart = 0;
117 * Zero out our streamData
119 memset(&streamData,0,sizeof(STREAMDATA));
121 errCode = IStream_Seek (pStream, position, STREAM_SEEK_CUR, &newPosition);
125 errCode = IStream_Read (pStream, &streamData, sizeof(STREAMDATA), &ulRead);
129 FIXME ("dwSize=%lu dwData2=%lu dwItems=%lu\n",
130 streamData.dwSize, streamData.dwData2, streamData.dwItems);
132 if ( ulRead < sizeof(STREAMDATA) ||
133 lParam < sizeof(STREAMDATA) ||
134 streamData.dwSize < sizeof(STREAMDATA) ||
135 streamData.dwData2 < 1) {
139 if (streamData.dwItems > (UINT_MAX / 2 / sizeof(VOID*))) /* 536870911 */
140 return E_OUTOFMEMORY;
143 hDpa = DPA_Create (streamData.dwItems);
145 return E_OUTOFMEMORY;
147 if (!DPA_Grow (hDpa, streamData.dwItems))
148 return E_OUTOFMEMORY;
150 /* load data from the stream into the dpa */
152 for (loadData.nCount = 0; loadData.nCount < streamData.dwItems; loadData.nCount++) {
153 errCode = (loadProc)(&loadData, pStream, lParam);
154 if (errCode != S_OK) {
163 /* set the number of items */
164 hDpa->nItemCount = loadData.nCount;
166 /* store the handle to the dpa */
168 FIXME ("new hDpa=%p, errorcode=%lx\n", hDpa, errCode);
174 /**************************************************************************
175 * DPA_SaveStream [COMCTL32.10]
177 * Saves a dynamic pointer array to a stream
180 * hDpa [I] handle to a dynamic pointer array
181 * loadProc [I] pointer to a callback function
182 * pStream [I] pointer to a stream
183 * lParam [I] application specific value
186 * No more information available yet!
190 DPA_SaveStream (const HDPA hDpa, DPALOADPROC loadProc, IStream *pStream, LPARAM lParam)
193 FIXME ("hDpa=%p loadProc=%p pStream=%p lParam=%lx\n",
194 hDpa, loadProc, pStream, lParam);
200 /**************************************************************************
201 * DPA_Merge [COMCTL32.11]
204 * hdpa1 [I] handle to a dynamic pointer array
205 * hdpa2 [I] handle to a dynamic pointer array
207 * pfnCompare [I] pointer to sort function
208 * pfnMerge [I] pointer to merge function
209 * lParam [I] application specific value
212 * No more information available yet!
216 DPA_Merge (const HDPA hdpa1, const HDPA hdpa2, DWORD dwFlags,
217 PFNDPACOMPARE pfnCompare, PFNDPAMERGE pfnMerge, LPARAM lParam)
220 LPVOID *pWork1, *pWork2;
224 TRACE("%p %p %08lx %p %p %08lx)\n",
225 hdpa1, hdpa2, dwFlags, pfnCompare, pfnMerge, lParam);
227 if (IsBadWritePtr (hdpa1, sizeof(DPA)))
230 if (IsBadWritePtr (hdpa2, sizeof(DPA)))
233 if (IsBadCodePtr ((FARPROC)pfnCompare))
236 if (IsBadCodePtr ((FARPROC)pfnMerge))
239 if (!(dwFlags & DPAM_NOSORT)) {
240 TRACE("sorting dpa's!\n");
241 if (hdpa1->nItemCount > 0)
242 DPA_Sort (hdpa1, pfnCompare, lParam);
243 TRACE ("dpa 1 sorted!\n");
244 if (hdpa2->nItemCount > 0)
245 DPA_Sort (hdpa2, pfnCompare, lParam);
246 TRACE ("dpa 2 sorted!\n");
249 if (hdpa2->nItemCount < 1)
252 TRACE("hdpa1->nItemCount=%d hdpa2->nItemCount=%d\n",
253 hdpa1->nItemCount, hdpa2->nItemCount);
256 /* working but untrusted implementation */
258 pWork1 = &(hdpa1->ptrs[hdpa1->nItemCount - 1]);
259 pWork2 = &(hdpa2->ptrs[hdpa2->nItemCount - 1]);
261 nIndex = hdpa1->nItemCount - 1;
262 nCount = hdpa2->nItemCount - 1;
267 if ((nCount >= 0) && (dwFlags & DPAM_INSERT)) {
268 /* Now insert the remaining new items into DPA 1 */
269 TRACE("%d items to be inserted at start of DPA 1\n",
271 for (i=nCount; i>=0; i--) {
274 ptr = (pfnMerge)(3, *pWork2, NULL, lParam);
277 DPA_InsertPtr (hdpa1, 0, ptr);
283 nResult = (pfnCompare)(*pWork1, *pWork2, lParam);
284 TRACE("compare result=%d, dpa1.cnt=%d, dpa2.cnt=%d\n",
285 nResult, nIndex, nCount);
291 ptr = (pfnMerge)(1, *pWork1, *pWork2, lParam);
301 else if (nResult > 0)
303 /* item in DPA 1 missing from DPA 2 */
304 if (dwFlags & DPAM_DELETE)
306 /* Now delete the extra item in DPA1 */
309 ptr = DPA_DeletePtr (hdpa1, hdpa1->nItemCount - 1);
311 (pfnMerge)(2, ptr, NULL, lParam);
318 /* new item in DPA 2 */
319 if (dwFlags & DPAM_INSERT)
321 /* Now insert the new item in DPA 1 */
324 ptr = (pfnMerge)(3, *pWork2, NULL, lParam);
327 DPA_InsertPtr (hdpa1, nIndex+1, ptr);
340 /**************************************************************************
341 * Alloc [COMCTL32.71]
343 * Allocates memory block from the dll's private heap
346 * dwSize [I] size of the allocated memory block
349 * Success: pointer to allocated memory block
354 COMCTL32_Alloc (DWORD dwSize)
358 TRACE("(0x%lx)\n", dwSize);
360 lpPtr = HeapAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, dwSize);
362 TRACE("-- ret=%p\n", lpPtr);
368 /**************************************************************************
369 * ReAlloc [COMCTL32.72]
371 * Changes the size of an allocated memory block or allocates a memory
372 * block using the dll's private heap.
375 * lpSrc [I] pointer to memory block which will be resized
376 * dwSize [I] new size of the memory block.
379 * Success: pointer to the resized memory block
383 * If lpSrc is a NULL-pointer, then COMCTL32_ReAlloc allocates a memory
384 * block like COMCTL32_Alloc.
388 COMCTL32_ReAlloc (LPVOID lpSrc, DWORD dwSize)
392 TRACE("(%p 0x%08lx)\n", lpSrc, dwSize);
395 lpDest = HeapReAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, lpSrc, dwSize);
397 lpDest = HeapAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, dwSize);
399 TRACE("-- ret=%p\n", lpDest);
405 /**************************************************************************
408 * Frees an allocated memory block from the dll's private heap.
411 * lpMem [I] pointer to memory block which will be freed
419 COMCTL32_Free (LPVOID lpMem)
421 TRACE("(%p)\n", lpMem);
423 return HeapFree (COMCTL32_hHeap, 0, lpMem);
427 /**************************************************************************
428 * GetSize [COMCTL32.74]
430 * Retrieves the size of the specified memory block from the dll's
434 * lpMem [I] pointer to an allocated memory block
437 * Success: size of the specified memory block
442 COMCTL32_GetSize (LPVOID lpMem)
444 TRACE("(%p)\n", lpMem);
446 return HeapSize (COMCTL32_hHeap, 0, lpMem);
450 /**************************************************************************
451 * The MRU-API is a set of functions to manipulate MRU(Most Recently Used)
454 * Stored in the reg. as a set of values under a single key. Each item in the
455 * list has a value name that is a single char. 'a' - 'z', '{', '|' or '}'.
456 * The order of the list is stored with value name 'MRUList' which is a string
457 * containing the value names (i.e. 'a', 'b', etc.) in the relevant order.
460 typedef struct tagCREATEMRULISTA
462 DWORD cbSize; /* size of struct */
463 DWORD nMaxItems; /* max no. of items in list */
464 DWORD dwFlags; /* see below */
465 HKEY hKey; /* root reg. key under which list is saved */
466 LPCSTR lpszSubKey; /* reg. subkey */
467 PROC lpfnCompare; /* item compare proc */
468 } CREATEMRULISTA, *LPCREATEMRULISTA;
470 typedef struct tagCREATEMRULISTW
472 DWORD cbSize; /* size of struct */
473 DWORD nMaxItems; /* max no. of items in list */
474 DWORD dwFlags; /* see below */
475 HKEY hKey; /* root reg. key under which list is saved */
476 LPCWSTR lpszSubKey; /* reg. subkey */
477 PROC lpfnCompare; /* item compare proc */
478 } CREATEMRULISTW, *LPCREATEMRULISTW;
481 #define MRUF_STRING_LIST 0 /* list will contain strings */
482 #define MRUF_BINARY_LIST 1 /* list will contain binary data */
483 #define MRUF_DELAYED_SAVE 2 /* only save list order to reg. is FreeMRUList */
485 /* If list is a string list lpfnCompare has the following prototype
486 * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
487 * for binary lists the prototype is
488 * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
489 * where cbData is the no. of bytes to compare.
490 * Need to check what return value means identical - 0?
493 typedef struct tagWINEMRUITEM
495 DWORD size; /* size of data stored */
496 DWORD itemFlag; /* flags */
498 } WINEMRUITEM, *LPWINEMRUITEM;
501 #define WMRUIF_CHANGED 0x0001 /* this dataitem changed */
503 typedef struct tagWINEMRULIST
505 CREATEMRULISTW extview; /* original create information */
506 BOOL isUnicode; /* is compare fn Unicode */
507 DWORD wineFlags; /* internal flags */
508 DWORD cursize; /* current size of realMRU */
509 LPSTR realMRU; /* pointer to string of index names */
510 LPWINEMRUITEM *array; /* array of pointers to data */
511 /* in 'a' to 'z' order */
512 } WINEMRULIST, *LPWINEMRULIST;
515 #define WMRUF_CHANGED 0x0001 /* MRU list has changed */
517 /**************************************************************************
518 * MRU_SaveChanged - Localize MRU saving code
521 VOID MRU_SaveChanged( LPWINEMRULIST mp )
527 WCHAR emptyW[] = {'\0'};
529 /* or should we do the following instead of RegOpenKeyEx:
532 /* open the sub key */
533 if ((err = RegOpenKeyExW( mp->extview.hKey, mp->extview.lpszSubKey,
534 0, KEY_WRITE, &newkey))) {
535 /* not present - what to do ??? */
536 ERR("Can not open key, error=%d, attempting to create\n",
538 if ((err = RegCreateKeyExW( mp->extview.hKey, mp->extview.lpszSubKey,
541 REG_OPTION_NON_VOLATILE,
542 KEY_READ | KEY_WRITE,
546 ERR("failed to create key /%s/, err=%d\n",
547 debugstr_w(mp->extview.lpszSubKey), err);
551 if (mp->wineFlags & WMRUF_CHANGED) {
552 mp->wineFlags &= ~WMRUF_CHANGED;
553 err = RegSetValueExA(newkey, "MRUList", 0, REG_SZ,
554 mp->realMRU, strlen(mp->realMRU) + 1);
556 ERR("error saving MRUList, err=%d\n", err);
558 TRACE("saving MRUList=/%s/\n", mp->realMRU);
561 for(i=0; i<mp->cursize; i++) {
562 witem = mp->array[i];
563 if (witem->itemFlag & WMRUIF_CHANGED) {
564 witem->itemFlag &= ~WMRUIF_CHANGED;
565 realname[0] = 'a' + i;
566 err = RegSetValueExW(newkey, realname, 0,
567 (mp->extview.dwFlags & MRUF_BINARY_LIST) ?
569 &witem->datastart, witem->size);
571 ERR("error saving /%s/, err=%d\n", debugstr_w(realname), err);
573 TRACE("saving value for name /%s/ size=%ld\n",
574 debugstr_w(realname), witem->size);
577 RegCloseKey( newkey );
580 /**************************************************************************
581 * FreeMRUList [COMCTL32.152]
584 * hMRUList [I] Handle to list.
588 FreeMRUList (HANDLE hMRUList)
590 LPWINEMRULIST mp = (LPWINEMRULIST)hMRUList;
594 if (mp->wineFlags & WMRUF_CHANGED) {
595 /* need to open key and then save the info */
596 MRU_SaveChanged( mp );
599 for(i=0; i<mp->extview.nMaxItems; i++) {
601 COMCTL32_Free(mp->array[i]);
603 COMCTL32_Free(mp->realMRU);
604 COMCTL32_Free(mp->array);
605 COMCTL32_Free((LPWSTR)mp->extview.lpszSubKey);
606 return COMCTL32_Free(mp);
610 /**************************************************************************
611 * FindMRUData [COMCTL32.169]
613 * Searches binary list for item that matches lpData of length cbData.
614 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
615 * corresponding to item's reg. name will be stored in it ('a' -> 0).
618 * hList [I] list handle
619 * lpData [I] data to find
620 * cbData [I] length of data
621 * lpRegNum [O] position in registry (maybe NULL)
624 * Position in list 0 -> MRU. -1 if item not found.
627 FindMRUData (HANDLE hList, LPCVOID lpData, DWORD cbData, LPINT lpRegNum)
629 LPWINEMRULIST mp = (LPWINEMRULIST)hList;
633 if (!mp->extview.lpfnCompare) {
634 ERR("MRU list not properly created. No compare procedure.\n");
638 if(!(mp->extview.dwFlags & MRUF_BINARY_LIST) && !mp->isUnicode) {
639 DWORD len = WideCharToMultiByte(CP_ACP, 0, lpData, -1,
640 NULL, 0, NULL, NULL);
641 dataA = COMCTL32_Alloc(len);
642 WideCharToMultiByte(CP_ACP, 0, lpData, -1, dataA, len, NULL, NULL);
645 for(i=0; i<mp->cursize; i++) {
646 if (mp->extview.dwFlags & MRUF_BINARY_LIST) {
647 if (!mp->extview.lpfnCompare(lpData, &mp->array[i]->datastart,
653 if (!mp->extview.lpfnCompare(lpData, &mp->array[i]->datastart))
656 DWORD len = WideCharToMultiByte(CP_ACP, 0,
657 (LPWSTR)&mp->array[i]->datastart, -1,
658 NULL, 0, NULL, NULL);
659 LPSTR itemA = COMCTL32_Alloc(len);
661 WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&mp->array[i]->datastart, -1,
662 itemA, len, NULL, NULL);
664 cmp = mp->extview.lpfnCompare(dataA, itemA);
665 COMCTL32_Free(itemA);
672 COMCTL32_Free(dataA);
677 if (lpRegNum && (ret != -1))
680 TRACE("(%p, %p, %ld, %p) returning %d\n",
681 hList, lpData, cbData, lpRegNum, ret);
687 /**************************************************************************
688 * AddMRUData [COMCTL32.167]
690 * Add item to MRU binary list. If item already exists in list then it is
691 * simply moved up to the top of the list and not added again. If list is
692 * full then the least recently used item is removed to make room.
695 * hList [I] Handle to list.
696 * lpData [I] ptr to data to add.
697 * cbData [I] no. of bytes of data.
700 * No. corresponding to registry name where value is stored 'a' -> 0 etc.
704 AddMRUData (HANDLE hList, LPCVOID lpData, DWORD cbData)
706 LPWINEMRULIST mp = (LPWINEMRULIST)hList;
710 if ((replace = FindMRUData (hList, lpData, cbData, NULL)) < 0) {
711 /* either add a new entry or replace oldest */
712 if (mp->cursize < mp->extview.nMaxItems) {
713 /* Add in a new item */
714 replace = mp->cursize;
718 /* get the oldest entry and replace data */
719 replace = mp->realMRU[mp->cursize - 1] - 'a';
720 COMCTL32_Free(mp->array[replace]);
724 /* free up the old data */
725 COMCTL32_Free(mp->array[replace]);
728 /* Allocate space for new item and move in the data */
729 mp->array[replace] = witem = (LPWINEMRUITEM)COMCTL32_Alloc(cbData +
730 sizeof(WINEMRUITEM));
731 witem->itemFlag |= WMRUIF_CHANGED;
732 witem->size = cbData;
733 memcpy( &witem->datastart, lpData, cbData);
735 /* now rotate MRU list */
736 mp->wineFlags |= WMRUF_CHANGED;
737 for(i=mp->cursize-1; i>=1; i--) {
738 mp->realMRU[i] = mp->realMRU[i-1];
740 mp->realMRU[0] = replace + 'a';
741 TRACE("(%p, %p, %ld) adding data, /%c/ now most current\n",
742 hList, lpData, cbData, replace+'a');
745 if (!(mp->extview.dwFlags & MRUF_DELAYED_SAVE)) {
746 /* save changed stuff right now */
747 MRU_SaveChanged( mp );
753 /**************************************************************************
754 * AddMRUStringW [COMCTL32.401]
756 * Add item to MRU string list. If item already exists in list them it is
757 * simply moved up to the top of the list and not added again. If list is
758 * full then the least recently used item is removed to make room.
761 * hList [I] Handle to list.
762 * lpszString [I] ptr to string to add.
765 * No. corresponding to registry name where value is stored 'a' -> 0 etc.
769 AddMRUStringW(HANDLE hList, LPCWSTR lpszString)
771 FIXME("(%p, %s) empty stub!\n", hList, debugstr_w(lpszString));
776 /**************************************************************************
777 * AddMRUStringA [COMCTL32.153]
780 AddMRUStringA(HANDLE hList, LPCSTR lpszString)
782 FIXME("(%p, %s) empty stub!\n", hList, debugstr_a(lpszString));
787 /**************************************************************************
788 * DelMRUString [COMCTL32.156]
790 * Removes item from either string or binary list (despite its name)
793 * hList [I] list handle
794 * nItemPos [I] item position to remove 0 -> MRU
797 * TRUE if successful, FALSE if nItemPos is out of range.
800 DelMRUString(HANDLE hList, INT nItemPos)
802 FIXME("(%p, %d): stub\n", hList, nItemPos);
806 /**************************************************************************
807 * FindMRUStringW [COMCTL32.402]
810 FindMRUStringW (HANDLE hList, LPCWSTR lpszString, LPINT lpRegNum)
816 /**************************************************************************
817 * FindMRUStringA [COMCTL32.155]
819 * Searches string list for item that matches lpszString.
820 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
821 * corresponding to item's reg. name will be stored in it ('a' -> 0).
824 * hList [I] list handle
825 * lpszString [I] string to find
826 * lpRegNum [O] position in registry (maybe NULL)
829 * Position in list 0 -> MRU. -1 if item not found.
832 FindMRUStringA (HANDLE hList, LPCSTR lpszString, LPINT lpRegNum)
834 DWORD len = MultiByteToWideChar(CP_ACP, 0, lpszString, -1, NULL, 0);
835 LPWSTR stringW = COMCTL32_Alloc(len * sizeof(WCHAR));
838 MultiByteToWideChar(CP_ACP, 0, lpszString, -1, stringW, len);
839 ret = FindMRUData(hList, stringW, len * sizeof(WCHAR), lpRegNum);
840 COMCTL32_Free(stringW);
844 /*************************************************************************
845 * CreateMRUListLazy_common
847 HANDLE CreateMRUListLazy_common(LPWINEMRULIST mp)
851 DWORD datasize, dwdisp;
855 WCHAR emptyW[] = {'\0'};
857 /* get space to save indices that will turn into names
858 * but in order of most to least recently used
860 mp->realMRU = (LPSTR) COMCTL32_Alloc(mp->extview.nMaxItems + 2);
862 /* get space to save pointers to actual data in order of
863 * 'a' to 'z' (0 to n).
865 mp->array = (LPVOID) COMCTL32_Alloc(mp->extview.nMaxItems *
868 /* open the sub key */
869 if ((err = RegCreateKeyExW( mp->extview.hKey, mp->extview.lpszSubKey,
872 REG_OPTION_NON_VOLATILE,
873 KEY_READ | KEY_WRITE,
877 /* error - what to do ??? */
878 ERR("(%lu %lu %lx %lx \"%s\" %p): Can not open key, error=%d\n",
879 mp->extview.cbSize, mp->extview.nMaxItems, mp->extview.dwFlags,
880 (DWORD)mp->extview.hKey, debugstr_w(mp->extview.lpszSubKey),
881 mp->extview.lpfnCompare, err);
885 /* get values from key 'MRUList' */
887 datasize = mp->extview.nMaxItems + 1;
888 if((err=RegQueryValueExA( newkey, "MRUList", 0, &type, mp->realMRU,
890 /* not present - set size to 1 (will become 0 later) */
895 TRACE("MRU list = %s\n", mp->realMRU);
897 mp->cursize = datasize - 1;
898 /* datasize now has number of items in the MRUList */
900 /* get actual values for each entry */
902 for(i=0; i<mp->cursize; i++) {
903 realname[0] = 'a' + i;
904 if(RegQueryValueExW( newkey, realname, 0, &type, 0, &datasize)) {
905 /* not present - what to do ??? */
906 ERR("Key %s not found 1\n", debugstr_w(realname));
908 mp->array[i] = witem = (LPWINEMRUITEM)COMCTL32_Alloc(datasize +
909 sizeof(WINEMRUITEM));
910 witem->size = datasize;
911 if(RegQueryValueExW( newkey, realname, 0, &type,
912 &witem->datastart, &datasize)) {
913 /* not present - what to do ??? */
914 ERR("Key %s not found 2\n", debugstr_w(realname));
917 RegCloseKey( newkey );
922 TRACE("(%lu %lu %lx %lx \"%s\" %p): Current Size = %ld\n",
923 mp->extview.cbSize, mp->extview.nMaxItems, mp->extview.dwFlags,
924 (DWORD)mp->extview.hKey, debugstr_w(mp->extview.lpszSubKey),
925 mp->extview.lpfnCompare, mp->cursize);
929 /**************************************************************************
930 * CreateMRUListLazyW [COMCTL32.404]
933 CreateMRUListLazyW (LPCREATEMRULISTW lpcml, DWORD dwParam2, DWORD dwParam3, DWORD dwParam4)
940 if (lpcml->cbSize < sizeof(CREATEMRULISTW))
943 mp = (LPWINEMRULIST) COMCTL32_Alloc(sizeof(WINEMRULIST));
944 memcpy(&mp->extview, lpcml, sizeof(CREATEMRULISTW));
945 mp->extview.lpszSubKey = COMCTL32_Alloc((strlenW(lpcml->lpszSubKey) + 1) *
947 strcpyW((LPWSTR)mp->extview.lpszSubKey, lpcml->lpszSubKey);
948 mp->isUnicode = TRUE;
950 return CreateMRUListLazy_common(mp);
953 /**************************************************************************
954 * CreateMRUListLazyA [COMCTL32.157]
957 CreateMRUListLazyA (LPCREATEMRULISTA lpcml, DWORD dwParam2, DWORD dwParam3, DWORD dwParam4)
965 if (lpcml->cbSize < sizeof(CREATEMRULISTA))
968 mp = (LPWINEMRULIST) COMCTL32_Alloc(sizeof(WINEMRULIST));
969 memcpy(&mp->extview, lpcml, sizeof(CREATEMRULISTW));
970 len = MultiByteToWideChar(CP_ACP, 0, lpcml->lpszSubKey, -1, NULL, 0);
971 mp->extview.lpszSubKey = COMCTL32_Alloc(len * sizeof(WCHAR));
972 MultiByteToWideChar(CP_ACP, 0, lpcml->lpszSubKey, -1,
973 (LPWSTR)mp->extview.lpszSubKey, len);
974 mp->isUnicode = FALSE;
975 return CreateMRUListLazy_common(mp);
978 /**************************************************************************
979 * CreateMRUListW [COMCTL32.400]
982 * lpcml [I] ptr to CREATEMRULIST structure.
985 * Handle to MRU list.
988 CreateMRUListW (LPCREATEMRULISTW lpcml)
990 return CreateMRUListLazyW(lpcml, 0, 0, 0);
993 /**************************************************************************
994 * CreateMRUListA [COMCTL32.151]
997 CreateMRUListA (LPCREATEMRULISTA lpcml)
999 return CreateMRUListLazyA (lpcml, 0, 0, 0);
1003 /**************************************************************************
1004 * EnumMRUListW [COMCTL32.403]
1006 * Enumerate item in a list
1009 * hList [I] list handle
1010 * nItemPos [I] item position to enumerate
1011 * lpBuffer [O] buffer to receive item
1012 * nBufferSize [I] size of buffer
1015 * For binary lists specifies how many bytes were copied to buffer, for
1016 * string lists specifies full length of string. Enumerating past the end
1017 * of list returns -1.
1018 * If lpBuffer == NULL or nItemPos is -ve return value is no. of items in
1021 INT WINAPI EnumMRUListW(HANDLE hList, INT nItemPos, LPVOID lpBuffer,
1024 LPWINEMRULIST mp = (LPWINEMRULIST) hList;
1025 LPWINEMRUITEM witem;
1026 INT desired, datasize;
1028 if (nItemPos >= mp->cursize) return -1;
1029 if ((nItemPos < 0) || !lpBuffer) return mp->cursize;
1030 desired = mp->realMRU[nItemPos];
1032 TRACE("nItemPos=%d, desired=%d\n", nItemPos, desired);
1033 witem = mp->array[desired];
1034 datasize = min( witem->size, nBufferSize );
1035 memcpy( lpBuffer, &witem->datastart, datasize);
1036 TRACE("(%p, %d, %p, %ld): returning len=%d\n",
1037 hList, nItemPos, lpBuffer, nBufferSize, datasize);
1041 /**************************************************************************
1042 * EnumMRUListA [COMCTL32.154]
1045 INT WINAPI EnumMRUListA(HANDLE hList, INT nItemPos, LPVOID lpBuffer,
1048 LPWINEMRULIST mp = (LPWINEMRULIST) hList;
1049 LPWINEMRUITEM witem;
1050 INT desired, datasize;
1053 if (nItemPos >= mp->cursize) return -1;
1054 if ((nItemPos < 0) || !lpBuffer) return mp->cursize;
1055 desired = mp->realMRU[nItemPos];
1057 TRACE("nItemPos=%d, desired=%d\n", nItemPos, desired);
1058 witem = mp->array[desired];
1059 if(mp->extview.dwFlags & MRUF_BINARY_LIST) {
1060 datasize = min( witem->size, nBufferSize );
1061 memcpy( lpBuffer, &witem->datastart, datasize);
1063 lenA = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&witem->datastart, -1,
1064 NULL, 0, NULL, NULL);
1065 datasize = min( witem->size, nBufferSize );
1066 WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&witem->datastart, -1,
1067 lpBuffer, datasize, NULL, NULL);
1069 TRACE("(%p, %d, %p, %ld): returning len=%d\n",
1070 hList, nItemPos, lpBuffer, nBufferSize, datasize);
1075 /**************************************************************************
1076 * Str_GetPtrA [COMCTL32.233]
1087 Str_GetPtrA (LPCSTR lpSrc, LPSTR lpDest, INT nMaxLen)
1091 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
1093 if (!lpDest && lpSrc)
1094 return strlen (lpSrc);
1099 if (lpSrc == NULL) {
1104 len = strlen (lpSrc);
1108 RtlMoveMemory (lpDest, lpSrc, len);
1115 /**************************************************************************
1116 * Str_SetPtrA [COMCTL32.234]
1126 Str_SetPtrA (LPSTR *lppDest, LPCSTR lpSrc)
1128 TRACE("(%p %p)\n", lppDest, lpSrc);
1131 LPSTR ptr = COMCTL32_ReAlloc (*lppDest, strlen (lpSrc) + 1);
1134 strcpy (ptr, lpSrc);
1139 COMCTL32_Free (*lppDest);
1148 /**************************************************************************
1149 * Str_GetPtrW [COMCTL32.235]
1160 Str_GetPtrW (LPCWSTR lpSrc, LPWSTR lpDest, INT nMaxLen)
1164 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
1166 if (!lpDest && lpSrc)
1167 return strlenW (lpSrc);
1172 if (lpSrc == NULL) {
1177 len = strlenW (lpSrc);
1181 RtlMoveMemory (lpDest, lpSrc, len*sizeof(WCHAR));
1182 lpDest[len] = L'\0';
1188 /**************************************************************************
1189 * Str_SetPtrW [COMCTL32.236]
1199 Str_SetPtrW (LPWSTR *lppDest, LPCWSTR lpSrc)
1201 TRACE("(%p %p)\n", lppDest, lpSrc);
1204 INT len = strlenW (lpSrc) + 1;
1205 LPWSTR ptr = COMCTL32_ReAlloc (*lppDest, len * sizeof(WCHAR));
1208 strcpyW (ptr, lpSrc);
1213 COMCTL32_Free (*lppDest);
1222 /**************************************************************************
1223 * Str_GetPtrWtoA [internal]
1225 * Converts a unicode string into a multi byte string
1228 * lpSrc [I] Pointer to the unicode source string
1229 * lpDest [O] Pointer to caller supplied storage for the multi byte string
1230 * nMaxLen [I] Size, in bytes, of the destination buffer
1233 * Length, in bytes, of the converted string.
1237 Str_GetPtrWtoA (LPCWSTR lpSrc, LPSTR lpDest, INT nMaxLen)
1241 TRACE("(%s %p %d)\n", debugstr_w(lpSrc), lpDest, nMaxLen);
1243 if (!lpDest && lpSrc)
1244 return WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, 0, 0, NULL, NULL);
1249 if (lpSrc == NULL) {
1254 len = WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, 0, 0, NULL, NULL);
1258 WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, lpDest, len, NULL, NULL);
1265 /**************************************************************************
1266 * Str_SetPtrAtoW [internal]
1268 * Converts a multi byte string to a unicode string.
1269 * If the pointer to the destination buffer is NULL a buffer is allocated.
1270 * If the destination buffer is too small to keep the converted multi byte
1271 * string the destination buffer is reallocated. If the source pointer is
1272 * NULL, the destination buffer is freed.
1275 * lppDest [I/O] pointer to a pointer to the destination buffer
1276 * lpSrc [I] pointer to a multi byte string
1279 * TRUE: conversion successful
1284 Str_SetPtrAtoW (LPWSTR *lppDest, LPCSTR lpSrc)
1286 TRACE("(%p %s)\n", lppDest, lpSrc);
1289 INT len = MultiByteToWideChar(CP_ACP,0,lpSrc,-1,NULL,0);
1290 LPWSTR ptr = COMCTL32_ReAlloc (*lppDest, len*sizeof(WCHAR));
1294 MultiByteToWideChar(CP_ACP,0,lpSrc,-1,ptr,len);
1299 COMCTL32_Free (*lppDest);
1308 /**************************************************************************
1309 * The DSA-API is a set of functions to create and manipulate arrays of
1310 * fixed-size memory blocks. These arrays can store any kind of data
1311 * (strings, icons...).
1314 /**************************************************************************
1315 * DSA_Create [COMCTL32.320] Creates a dynamic storage array
1318 * nSize [I] size of the array elements
1319 * nGrow [I] number of elements by which the array grows when it is filled
1322 * Success: pointer to an array control structure. Use this like a handle.
1327 DSA_Create (INT nSize, INT nGrow)
1331 TRACE("(size=%d grow=%d)\n", nSize, nGrow);
1333 hdsa = (HDSA)COMCTL32_Alloc (sizeof(DSA));
1336 hdsa->nItemCount = 0;
1338 hdsa->nMaxCount = 0;
1339 hdsa->nItemSize = nSize;
1340 hdsa->nGrow = max(1, nGrow);
1347 /**************************************************************************
1348 * DSA_Destroy [COMCTL32.321] Destroys a dynamic storage array
1351 * hdsa [I] pointer to the array control structure
1359 DSA_Destroy (const HDSA hdsa)
1361 TRACE("(%p)\n", hdsa);
1366 if (hdsa->pData && (!COMCTL32_Free (hdsa->pData)))
1369 return COMCTL32_Free (hdsa);
1373 /**************************************************************************
1374 * DSA_GetItem [COMCTL32.322]
1377 * hdsa [I] pointer to the array control structure
1378 * nIndex [I] number of the Item to get
1379 * pDest [O] destination buffer. Has to be >= dwElementSize.
1387 DSA_GetItem (const HDSA hdsa, INT nIndex, LPVOID pDest)
1391 TRACE("(%p %d %p)\n", hdsa, nIndex, pDest);
1395 if ((nIndex < 0) || (nIndex >= hdsa->nItemCount))
1398 pSrc = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1399 memmove (pDest, pSrc, hdsa->nItemSize);
1405 /**************************************************************************
1406 * DSA_GetItemPtr [COMCTL32.323]
1408 * Retrieves a pointer to the specified item.
1411 * hdsa [I] pointer to the array control structure
1412 * nIndex [I] index of the desired item
1415 * Success: pointer to an item
1420 DSA_GetItemPtr (const HDSA hdsa, INT nIndex)
1424 TRACE("(%p %d)\n", hdsa, nIndex);
1428 if ((nIndex < 0) || (nIndex >= hdsa->nItemCount))
1431 pSrc = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1433 TRACE("-- ret=%p\n", pSrc);
1439 /**************************************************************************
1440 * DSA_SetItem [COMCTL32.325]
1442 * Sets the contents of an item in the array.
1445 * hdsa [I] pointer to the array control structure
1446 * nIndex [I] index for the item
1447 * pSrc [I] pointer to the new item data
1455 DSA_SetItem (const HDSA hdsa, INT nIndex, LPVOID pSrc)
1457 INT nSize, nNewItems;
1458 LPVOID pDest, lpTemp;
1460 TRACE("(%p %d %p)\n", hdsa, nIndex, pSrc);
1462 if ((!hdsa) || nIndex < 0)
1465 if (hdsa->nItemCount <= nIndex) {
1466 /* within the old array */
1467 if (hdsa->nMaxCount > nIndex) {
1468 /* within the allocated space, set a new boundary */
1469 hdsa->nItemCount = nIndex + 1;
1472 /* resize the block of memory */
1474 hdsa->nGrow * ((INT)(((nIndex + 1) - 1) / hdsa->nGrow) + 1);
1475 nSize = hdsa->nItemSize * nNewItems;
1477 lpTemp = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
1481 hdsa->nMaxCount = nNewItems;
1482 hdsa->nItemCount = nIndex + 1;
1483 hdsa->pData = lpTemp;
1487 /* put the new entry in */
1488 pDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1489 TRACE("-- move dest=%p src=%p size=%d\n",
1490 pDest, pSrc, hdsa->nItemSize);
1491 memmove (pDest, pSrc, hdsa->nItemSize);
1497 /**************************************************************************
1498 * DSA_InsertItem [COMCTL32.324]
1501 * hdsa [I] pointer to the array control structure
1502 * nIndex [I] index for the new item
1503 * pSrc [I] pointer to the element
1506 * Success: position of the new item
1511 DSA_InsertItem (const HDSA hdsa, INT nIndex, LPVOID pSrc)
1513 INT nNewItems, nSize;
1514 LPVOID lpTemp, lpDest;
1516 TRACE("(%p %d %p)\n", hdsa, nIndex, pSrc);
1518 if ((!hdsa) || nIndex < 0)
1521 /* when nIndex >= nItemCount then append */
1522 if (nIndex >= hdsa->nItemCount)
1523 nIndex = hdsa->nItemCount;
1525 /* do we need to resize ? */
1526 if (hdsa->nItemCount >= hdsa->nMaxCount) {
1527 nNewItems = hdsa->nMaxCount + hdsa->nGrow;
1528 nSize = hdsa->nItemSize * nNewItems;
1530 lpTemp = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
1534 hdsa->nMaxCount = nNewItems;
1535 hdsa->pData = lpTemp;
1538 /* do we need to move elements ? */
1539 if (nIndex < hdsa->nItemCount) {
1540 lpTemp = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1541 lpDest = (char *) lpTemp + hdsa->nItemSize;
1542 nSize = (hdsa->nItemCount - nIndex) * hdsa->nItemSize;
1543 TRACE("-- move dest=%p src=%p size=%d\n",
1544 lpDest, lpTemp, nSize);
1545 memmove (lpDest, lpTemp, nSize);
1548 /* ok, we can put the new Item in */
1550 lpDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1551 TRACE("-- move dest=%p src=%p size=%d\n",
1552 lpDest, pSrc, hdsa->nItemSize);
1553 memmove (lpDest, pSrc, hdsa->nItemSize);
1559 /**************************************************************************
1560 * DSA_DeleteItem [COMCTL32.326]
1563 * hdsa [I] pointer to the array control structure
1564 * nIndex [I] index for the element to delete
1567 * Success: number of the deleted element
1572 DSA_DeleteItem (const HDSA hdsa, INT nIndex)
1574 LPVOID lpDest,lpSrc;
1577 TRACE("(%p %d)\n", hdsa, nIndex);
1581 if (nIndex < 0 || nIndex >= hdsa->nItemCount)
1584 /* do we need to move ? */
1585 if (nIndex < hdsa->nItemCount - 1) {
1586 lpDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1587 lpSrc = (char *) lpDest + hdsa->nItemSize;
1588 nSize = hdsa->nItemSize * (hdsa->nItemCount - nIndex - 1);
1589 TRACE("-- move dest=%p src=%p size=%d\n",
1590 lpDest, lpSrc, nSize);
1591 memmove (lpDest, lpSrc, nSize);
1597 if ((hdsa->nMaxCount - hdsa->nItemCount) >= hdsa->nGrow) {
1598 nSize = hdsa->nItemSize * hdsa->nItemCount;
1600 lpDest = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
1604 hdsa->nMaxCount = hdsa->nItemCount;
1605 hdsa->pData = lpDest;
1612 /**************************************************************************
1613 * DSA_DeleteAllItems [COMCTL32.327]
1615 * Removes all items and reinitializes the array.
1618 * hdsa [I] pointer to the array control structure
1626 DSA_DeleteAllItems (const HDSA hdsa)
1628 TRACE("(%p)\n", hdsa);
1632 if (hdsa->pData && (!COMCTL32_Free (hdsa->pData)))
1635 hdsa->nItemCount = 0;
1637 hdsa->nMaxCount = 0;
1643 /**************************************************************************
1644 * The DPA-API is a set of functions to create and manipulate arrays of
1648 /**************************************************************************
1649 * DPA_Create [COMCTL32.328] Creates a dynamic pointer array
1652 * nGrow [I] number of items by which the array grows when it is filled
1655 * Success: handle (pointer) to the pointer array.
1660 DPA_Create (INT nGrow)
1664 TRACE("(%d)\n", nGrow);
1666 hdpa = (HDPA)COMCTL32_Alloc (sizeof(DPA));
1668 hdpa->nGrow = max(8, nGrow);
1669 hdpa->hHeap = COMCTL32_hHeap;
1670 hdpa->nMaxCount = hdpa->nGrow * 2;
1672 (LPVOID*)COMCTL32_Alloc (hdpa->nMaxCount * sizeof(LPVOID));
1675 TRACE("-- %p\n", hdpa);
1681 /**************************************************************************
1682 * DPA_Destroy [COMCTL32.329] Destroys a dynamic pointer array
1685 * hdpa [I] handle (pointer) to the pointer array
1693 DPA_Destroy (const HDPA hdpa)
1695 TRACE("(%p)\n", hdpa);
1700 if (hdpa->ptrs && (!HeapFree (hdpa->hHeap, 0, hdpa->ptrs)))
1703 return HeapFree (hdpa->hHeap, 0, hdpa);
1707 /**************************************************************************
1708 * DPA_Grow [COMCTL32.330]
1710 * Sets the growth amount.
1713 * hdpa [I] handle (pointer) to the existing (source) pointer array
1714 * nGrow [I] number of items by which the array grows when it's too small
1722 DPA_Grow (const HDPA hdpa, INT nGrow)
1724 TRACE("(%p %d)\n", hdpa, nGrow);
1729 hdpa->nGrow = max(8, nGrow);
1735 /**************************************************************************
1736 * DPA_Clone [COMCTL32.331]
1738 * Copies a pointer array to an other one or creates a copy
1741 * hdpa [I] handle (pointer) to the existing (source) pointer array
1742 * hdpaNew [O] handle (pointer) to the destination pointer array
1745 * Success: pointer to the destination pointer array.
1749 * - If the 'hdpaNew' is a NULL-Pointer, a copy of the source pointer
1750 * array will be created and it's handle (pointer) is returned.
1751 * - If 'hdpa' is a NULL-Pointer, the original implementation crashes,
1752 * this implementation just returns NULL.
1756 DPA_Clone (const HDPA hdpa, const HDPA hdpaNew)
1758 INT nNewItems, nSize;
1764 TRACE("(%p %p)\n", hdpa, hdpaNew);
1767 /* create a new DPA */
1768 hdpaTemp = (HDPA)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1770 hdpaTemp->hHeap = hdpa->hHeap;
1771 hdpaTemp->nGrow = hdpa->nGrow;
1776 if (hdpaTemp->ptrs) {
1777 /* remove old pointer array */
1778 HeapFree (hdpaTemp->hHeap, 0, hdpaTemp->ptrs);
1779 hdpaTemp->ptrs = NULL;
1780 hdpaTemp->nItemCount = 0;
1781 hdpaTemp->nMaxCount = 0;
1784 /* create a new pointer array */
1785 nNewItems = hdpaTemp->nGrow *
1786 ((INT)((hdpa->nItemCount - 1) / hdpaTemp->nGrow) + 1);
1787 nSize = nNewItems * sizeof(LPVOID);
1789 (LPVOID*)HeapAlloc (hdpaTemp->hHeap, HEAP_ZERO_MEMORY, nSize);
1790 hdpaTemp->nMaxCount = nNewItems;
1792 /* clone the pointer array */
1793 hdpaTemp->nItemCount = hdpa->nItemCount;
1794 memmove (hdpaTemp->ptrs, hdpa->ptrs,
1795 hdpaTemp->nItemCount * sizeof(LPVOID));
1801 /**************************************************************************
1802 * DPA_GetPtr [COMCTL32.332]
1804 * Retrieves a pointer from a dynamic pointer array
1807 * hdpa [I] handle (pointer) to the pointer array
1808 * nIndex [I] array index of the desired pointer
1816 DPA_GetPtr (const HDPA hdpa, INT nIndex)
1818 TRACE("(%p %d)\n", hdpa, nIndex);
1823 WARN("no pointer array.\n");
1826 if ((nIndex < 0) || (nIndex >= hdpa->nItemCount)) {
1827 WARN("not enough pointers in array (%d vs %d).\n",nIndex,hdpa->nItemCount);
1831 TRACE("-- %p\n", hdpa->ptrs[nIndex]);
1833 return hdpa->ptrs[nIndex];
1837 /**************************************************************************
1838 * DPA_GetPtrIndex [COMCTL32.333]
1840 * Retrieves the index of the specified pointer
1843 * hdpa [I] handle (pointer) to the pointer array
1847 * Success: index of the specified pointer
1852 DPA_GetPtrIndex (const HDPA hdpa, LPVOID p)
1856 if (!hdpa || !hdpa->ptrs)
1859 for (i = 0; i < hdpa->nItemCount; i++) {
1860 if (hdpa->ptrs[i] == p)
1868 /**************************************************************************
1869 * DPA_InsertPtr [COMCTL32.334]
1871 * Inserts a pointer into a dynamic pointer array
1874 * hdpa [I] handle (pointer) to the array
1876 * p [I] pointer to insert
1879 * Success: index of the inserted pointer
1884 DPA_InsertPtr (const HDPA hdpa, INT i, LPVOID p)
1886 TRACE("(%p %d %p)\n", hdpa, i, p);
1888 if (!hdpa || i < 0) return -1;
1891 i = hdpa->nItemCount;
1893 if (i >= hdpa->nItemCount)
1894 return DPA_SetPtr(hdpa, i, p) ? i : -1;
1896 /* create empty spot at the end */
1897 if (!DPA_SetPtr(hdpa, hdpa->nItemCount, 0)) return -1;
1898 memmove (hdpa->ptrs + i + 1, hdpa->ptrs + i, (hdpa->nItemCount - i - 1) * sizeof(LPVOID));
1903 /**************************************************************************
1904 * DPA_SetPtr [COMCTL32.335]
1906 * Sets a pointer in the pointer array
1909 * hdpa [I] handle (pointer) to the pointer array
1910 * i [I] index of the pointer that will be set
1911 * p [I] pointer to be set
1919 DPA_SetPtr (const HDPA hdpa, INT i, LPVOID p)
1923 TRACE("(%p %d %p)\n", hdpa, i, p);
1925 if (!hdpa || i < 0 || i > 0x7fff)
1928 if (hdpa->nItemCount <= i) {
1929 /* within the old array */
1930 if (hdpa->nMaxCount <= i) {
1931 /* resize the block of memory */
1933 hdpa->nGrow * ((INT)(((i+1) - 1) / hdpa->nGrow) + 1);
1934 INT nSize = nNewItems * sizeof(LPVOID);
1937 lpTemp = (LPVOID*)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY, hdpa->ptrs, nSize);
1939 lpTemp = (LPVOID*)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY, nSize);
1944 hdpa->nMaxCount = nNewItems;
1945 hdpa->ptrs = lpTemp;
1947 hdpa->nItemCount = i+1;
1950 /* put the new entry in */
1957 /**************************************************************************
1958 * DPA_DeletePtr [COMCTL32.336]
1960 * Removes a pointer from the pointer array.
1963 * hdpa [I] handle (pointer) to the pointer array
1964 * i [I] index of the pointer that will be deleted
1967 * Success: deleted pointer
1972 DPA_DeletePtr (const HDPA hdpa, INT i)
1974 LPVOID *lpDest, *lpSrc, lpTemp = NULL;
1977 TRACE("(%p %d)\n", hdpa, i);
1979 if ((!hdpa) || i < 0 || i >= hdpa->nItemCount)
1982 lpTemp = hdpa->ptrs[i];
1984 /* do we need to move ?*/
1985 if (i < hdpa->nItemCount - 1) {
1986 lpDest = hdpa->ptrs + i;
1988 nSize = (hdpa->nItemCount - i - 1) * sizeof(LPVOID);
1989 TRACE("-- move dest=%p src=%p size=%x\n",
1990 lpDest, lpSrc, nSize);
1991 memmove (lpDest, lpSrc, nSize);
1994 hdpa->nItemCount --;
1997 if ((hdpa->nMaxCount - hdpa->nItemCount) >= hdpa->nGrow) {
1998 INT nNewItems = max(hdpa->nGrow * 2, hdpa->nItemCount);
1999 nSize = nNewItems * sizeof(LPVOID);
2000 lpDest = (LPVOID)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
2005 hdpa->nMaxCount = nNewItems;
2006 hdpa->ptrs = (LPVOID*)lpDest;
2013 /**************************************************************************
2014 * DPA_DeleteAllPtrs [COMCTL32.337]
2016 * Removes all pointers and reinitializes the array.
2019 * hdpa [I] handle (pointer) to the pointer array
2027 DPA_DeleteAllPtrs (const HDPA hdpa)
2029 TRACE("(%p)\n", hdpa);
2034 if (hdpa->ptrs && (!HeapFree (hdpa->hHeap, 0, hdpa->ptrs)))
2037 hdpa->nItemCount = 0;
2038 hdpa->nMaxCount = hdpa->nGrow * 2;
2039 hdpa->ptrs = (LPVOID*)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
2040 hdpa->nMaxCount * sizeof(LPVOID));
2046 /**************************************************************************
2047 * DPA_QuickSort [Internal]
2049 * Ordinary quicksort (used by DPA_Sort).
2052 * lpPtrs [I] pointer to the pointer array
2053 * l [I] index of the "left border" of the partition
2054 * r [I] index of the "right border" of the partition
2055 * pfnCompare [I] pointer to the compare function
2056 * lParam [I] user defined value (3rd parameter in compare function)
2063 DPA_QuickSort (LPVOID *lpPtrs, INT l, INT r,
2064 PFNDPACOMPARE pfnCompare, LPARAM lParam)
2069 TRACE("l=%i r=%i\n", l, r);
2071 if (l==r) /* one element is always sorted */
2073 if (r<l) /* oops, got it in the wrong order */
2075 DPA_QuickSort(lpPtrs, r, l, pfnCompare, lParam);
2078 m = (l+r)/2; /* divide by two */
2079 DPA_QuickSort(lpPtrs, l, m, pfnCompare, lParam);
2080 DPA_QuickSort(lpPtrs, m+1, r, pfnCompare, lParam);
2082 /* join the two sides */
2083 while( (l<=m) && (m<r) )
2085 if(pfnCompare(lpPtrs[l],lpPtrs[m+1],lParam)>0)
2088 memmove(&lpPtrs[l+1],&lpPtrs[l],(m-l+1)*sizeof(lpPtrs[l]));
2098 /**************************************************************************
2099 * DPA_Sort [COMCTL32.338]
2101 * Sorts a pointer array using a user defined compare function
2104 * hdpa [I] handle (pointer) to the pointer array
2105 * pfnCompare [I] pointer to the compare function
2106 * lParam [I] user defined value (3rd parameter of compare function)
2114 DPA_Sort (const HDPA hdpa, PFNDPACOMPARE pfnCompare, LPARAM lParam)
2116 if (!hdpa || !pfnCompare)
2119 TRACE("(%p %p 0x%lx)\n", hdpa, pfnCompare, lParam);
2121 if ((hdpa->nItemCount > 1) && (hdpa->ptrs))
2122 DPA_QuickSort (hdpa->ptrs, 0, hdpa->nItemCount - 1,
2123 pfnCompare, lParam);
2129 /**************************************************************************
2130 * DPA_Search [COMCTL32.339]
2132 * Searches a pointer array for a specified pointer
2135 * hdpa [I] handle (pointer) to the pointer array
2136 * pFind [I] pointer to search for
2137 * nStart [I] start index
2138 * pfnCompare [I] pointer to the compare function
2139 * lParam [I] user defined value (3rd parameter of compare function)
2140 * uOptions [I] search options
2143 * Success: index of the pointer in the array.
2147 * Binary search taken from R.Sedgewick "Algorithms in C"!
2148 * Function is NOT tested!
2149 * If something goes wrong, blame HIM not ME! (Eric Kohl)
2153 DPA_Search (const HDPA hdpa, LPVOID pFind, INT nStart,
2154 PFNDPACOMPARE pfnCompare, LPARAM lParam, UINT uOptions)
2156 if (!hdpa || !pfnCompare || !pFind)
2159 TRACE("(%p %p %d %p 0x%08lx 0x%08x)\n",
2160 hdpa, pFind, nStart, pfnCompare, lParam, uOptions);
2162 if (uOptions & DPAS_SORTED) {
2163 /* array is sorted --> use binary search */
2167 TRACE("binary search\n");
2169 l = (nStart == -1) ? 0 : nStart;
2170 r = hdpa->nItemCount - 1;
2174 n = (pfnCompare)(pFind, lpPtr[x], lParam);
2180 TRACE("-- ret=%d\n", n);
2185 if (uOptions & DPAS_INSERTBEFORE) {
2187 TRACE("-- ret=%d\n", r);
2191 if (uOptions & DPAS_INSERTAFTER) {
2192 TRACE("-- ret=%d\n", l);
2197 /* array is not sorted --> use linear search */
2201 TRACE("linear search\n");
2203 nIndex = (nStart == -1)? 0 : nStart;
2205 for (; nIndex < hdpa->nItemCount; nIndex++) {
2206 if ((pfnCompare)(pFind, lpPtr[nIndex], lParam) == 0) {
2207 TRACE("-- ret=%d\n", nIndex);
2213 TRACE("-- not found: ret=-1\n");
2218 /**************************************************************************
2219 * DPA_CreateEx [COMCTL32.340]
2221 * Creates a dynamic pointer array using the specified size and heap.
2224 * nGrow [I] number of items by which the array grows when it is filled
2225 * hHeap [I] handle to the heap where the array is stored
2228 * Success: handle (pointer) to the pointer array.
2233 DPA_CreateEx (INT nGrow, HANDLE hHeap)
2237 TRACE("(%d %p)\n", nGrow, hHeap);
2240 hdpa = (HDPA)HeapAlloc (hHeap, HEAP_ZERO_MEMORY, sizeof(DPA));
2242 hdpa = (HDPA)COMCTL32_Alloc (sizeof(DPA));
2245 hdpa->nGrow = min(8, nGrow);
2246 hdpa->hHeap = hHeap ? hHeap : COMCTL32_hHeap;
2247 hdpa->nMaxCount = hdpa->nGrow * 2;
2249 (LPVOID*)HeapAlloc (hHeap, HEAP_ZERO_MEMORY,
2250 hdpa->nMaxCount * sizeof(LPVOID));
2253 TRACE("-- %p\n", hdpa);
2259 /**************************************************************************
2260 * Notification functions
2263 typedef struct tagNOTIFYDATA
2271 } NOTIFYDATA, *LPNOTIFYDATA;
2274 /**************************************************************************
2275 * DoNotify [Internal]
2279 DoNotify (LPNOTIFYDATA lpNotify, UINT uCode, LPNMHDR lpHdr)
2282 LPNMHDR lpNmh = NULL;
2285 TRACE("(%p %p %d %p 0x%08lx)\n",
2286 lpNotify->hwndFrom, lpNotify->hwndTo, uCode, lpHdr,
2287 lpNotify->dwParam5);
2289 if (!lpNotify->hwndTo)
2292 if (lpNotify->hwndFrom == (HWND)-1) {
2294 idFrom = lpHdr->idFrom;
2297 if (lpNotify->hwndFrom) {
2298 HWND hwndParent = GetParent (lpNotify->hwndFrom);
2300 hwndParent = GetWindow (lpNotify->hwndFrom, GW_OWNER);
2301 /* the following is done even if the return from above
2302 * is zero. GLA 12/2001 */
2303 idFrom = GetDlgCtrlID (lpNotify->hwndFrom);
2307 lpNmh = (lpHdr) ? lpHdr : &nmhdr;
2309 lpNmh->hwndFrom = lpNotify->hwndFrom;
2310 lpNmh->idFrom = idFrom;
2311 lpNmh->code = uCode;
2314 return SendMessageA (lpNotify->hwndTo, WM_NOTIFY, idFrom, (LPARAM)lpNmh);
2318 /**************************************************************************
2319 * SendNotify [COMCTL32.341]
2328 * Success: return value from notification
2333 COMCTL32_SendNotify (HWND hwndTo, HWND hwndFrom,
2334 UINT uCode, LPNMHDR lpHdr)
2338 TRACE("(%p %p %d %p)\n",
2339 hwndTo, hwndFrom, uCode, lpHdr);
2341 notify.hwndFrom = hwndFrom;
2342 notify.hwndTo = hwndTo;
2343 notify.dwParam5 = 0;
2344 notify.dwParam6 = 0;
2346 return DoNotify (¬ify, uCode, lpHdr);
2350 /**************************************************************************
2351 * SendNotifyEx [COMCTL32.342]
2361 * Success: return value from notification
2366 COMCTL32_SendNotifyEx (HWND hwndTo, HWND hwndFrom, UINT uCode,
2367 LPNMHDR lpHdr, DWORD dwParam5)
2372 TRACE("(%p %p %d %p 0x%08lx)\n",
2373 hwndFrom, hwndTo, uCode, lpHdr, dwParam5);
2375 hwndNotify = hwndTo;
2377 if (IsWindow (hwndFrom)) {
2378 hwndNotify = GetParent (hwndFrom);
2384 notify.hwndFrom = hwndFrom;
2385 notify.hwndTo = hwndNotify;
2386 notify.dwParam5 = dwParam5;
2387 notify.dwParam6 = 0;
2389 return DoNotify (¬ify, uCode, lpHdr);
2393 /**************************************************************************
2394 * StrChrA [COMCTL32.350]
2399 COMCTL32_StrChrA (LPCSTR lpString, CHAR cChar)
2401 return strchr (lpString, cChar);
2405 /**************************************************************************
2406 * StrStrIA [COMCTL32.355]
2410 COMCTL32_StrStrIA (LPCSTR lpStr1, LPCSTR lpStr2)
2416 return ((LPSTR)lpStr1);
2418 while (lpStr1[len1] != 0) ++len1;
2420 while (lpStr2[len2] != 0) ++len2;
2422 return ((LPSTR)(lpStr1 + len1));
2423 first = tolower (*lpStr2);
2424 while (len1 >= len2) {
2425 if (tolower(*lpStr1) == first) {
2426 for (i = 1; i < len2; ++i)
2427 if (tolower (lpStr1[i]) != tolower(lpStr2[i]))
2430 return ((LPSTR)lpStr1);
2437 /**************************************************************************
2438 * StrToIntA [COMCTL32.357] Converts a string to a signed integer.
2442 COMCTL32_StrToIntA (LPSTR lpString)
2444 return atoi(lpString);
2447 /**************************************************************************
2448 * StrStrIW [COMCTL32.363]
2452 COMCTL32_StrStrIW (LPCWSTR lpStr1, LPCWSTR lpStr2)
2458 return ((LPWSTR)lpStr1);
2460 while (lpStr1[len1] != 0) ++len1;
2462 while (lpStr2[len2] != 0) ++len2;
2464 return ((LPWSTR)(lpStr1 + len1));
2465 first = tolowerW (*lpStr2);
2466 while (len1 >= len2) {
2467 if (tolowerW (*lpStr1) == first) {
2468 for (i = 1; i < len2; ++i)
2469 if (tolowerW (lpStr1[i]) != tolowerW(lpStr2[i]))
2472 return ((LPWSTR)lpStr1);
2479 /**************************************************************************
2480 * StrToIntW [COMCTL32.365] Converts a wide char string to a signed integer.
2484 COMCTL32_StrToIntW (LPWSTR lpString)
2486 return atoiW(lpString);
2490 /**************************************************************************
2491 * DPA_EnumCallback [COMCTL32.385]
2493 * Enumerates all items in a dynamic pointer array.
2496 * hdpa [I] handle to the dynamic pointer array
2505 DPA_EnumCallback (const HDPA hdpa, DPAENUMPROC enumProc, LPARAM lParam)
2509 TRACE("(%p %p %08lx)\n", hdpa, enumProc, lParam);
2513 if (hdpa->nItemCount <= 0)
2516 for (i = 0; i < hdpa->nItemCount; i++) {
2517 if ((enumProc)(hdpa->ptrs[i], lParam) == 0)
2525 /**************************************************************************
2526 * DPA_DestroyCallback [COMCTL32.386]
2528 * Enumerates all items in a dynamic pointer array and destroys it.
2531 * hdpa [I] handle to the dynamic pointer array
2541 DPA_DestroyCallback (const HDPA hdpa, DPAENUMPROC enumProc, LPARAM lParam)
2543 TRACE("(%p %p %08lx)\n", hdpa, enumProc, lParam);
2545 DPA_EnumCallback (hdpa, enumProc, lParam);
2547 return DPA_Destroy (hdpa);
2551 /**************************************************************************
2552 * DSA_EnumCallback [COMCTL32.387]
2554 * Enumerates all items in a dynamic storage array.
2557 * hdsa [I] handle to the dynamic storage array
2566 DSA_EnumCallback (const HDSA hdsa, DSAENUMPROC enumProc, LPARAM lParam)
2570 TRACE("(%p %p %08lx)\n", hdsa, enumProc, lParam);
2574 if (hdsa->nItemCount <= 0)
2577 for (i = 0; i < hdsa->nItemCount; i++) {
2578 LPVOID lpItem = DSA_GetItemPtr (hdsa, i);
2579 if ((enumProc)(lpItem, lParam) == 0)
2587 /**************************************************************************
2588 * DSA_DestroyCallback [COMCTL32.388]
2590 * Enumerates all items in a dynamic storage array and destroys it.
2593 * hdsa [I] handle to the dynamic storage array
2603 DSA_DestroyCallback (const HDSA hdsa, DSAENUMPROC enumProc, LPARAM lParam)
2605 TRACE("(%p %p %08lx)\n", hdsa, enumProc, lParam);
2607 DSA_EnumCallback (hdsa, enumProc, lParam);
2609 return DSA_Destroy (hdsa);
2612 /**************************************************************************
2613 * StrCSpnA [COMCTL32.356]
2616 INT WINAPI COMCTL32_StrCSpnA( LPCSTR lpStr, LPCSTR lpSet) {
2617 return strcspn(lpStr, lpSet);
2620 /**************************************************************************
2621 * StrChrW [COMCTL32.358]
2624 LPWSTR WINAPI COMCTL32_StrChrW( LPCWSTR lpStart, WORD wMatch) {
2625 return strchrW(lpStart, wMatch);
2628 /**************************************************************************
2629 * StrCmpNA [COMCTL32.352]
2632 INT WINAPI COMCTL32_StrCmpNA( LPCSTR lpStr1, LPCSTR lpStr2, int nChar) {
2633 return strncmp(lpStr1, lpStr2, nChar);
2636 /**************************************************************************
2637 * StrCmpNIA [COMCTL32.353]
2640 INT WINAPI COMCTL32_StrCmpNIA( LPCSTR lpStr1, LPCSTR lpStr2, int nChar) {
2641 return strncasecmp(lpStr1, lpStr2, nChar);
2644 /**************************************************************************
2645 * StrCmpNW [COMCTL32.360]
2648 INT WINAPI COMCTL32_StrCmpNW( LPCWSTR lpStr1, LPCWSTR lpStr2, int nChar) {
2649 return strncmpW(lpStr1, lpStr2, nChar);
2652 /**************************************************************************
2653 * StrCmpNIW [COMCTL32.361]
2656 INT WINAPI COMCTL32_StrCmpNIW( LPCWSTR lpStr1, LPCWSTR lpStr2, int nChar) {
2657 FIXME("(%s, %s, %i): stub\n", debugstr_w(lpStr1), debugstr_w(lpStr2), nChar);
2661 /**************************************************************************
2662 * StrRChrA [COMCTL32.351]
2665 LPSTR WINAPI COMCTL32_StrRChrA( LPCSTR lpStart, LPCSTR lpEnd, WORD wMatch )
2667 LPCSTR lpGotIt = NULL;
2668 BOOL dbcs = IsDBCSLeadByte( LOBYTE(wMatch) );
2670 TRACE("(%p, %p, %x)\n", lpStart, lpEnd, wMatch);
2672 if (!lpEnd) lpEnd = lpStart + strlen(lpStart);
2674 for(; lpStart < lpEnd; lpStart = CharNextA(lpStart))
2676 if (*lpStart != LOBYTE(wMatch)) continue;
2677 if (dbcs && lpStart[1] != HIBYTE(wMatch)) continue;
2680 return (LPSTR)lpGotIt;
2684 /**************************************************************************
2685 * StrRChrW [COMCTL32.359]
2688 LPWSTR WINAPI COMCTL32_StrRChrW( LPCWSTR lpStart, LPCWSTR lpEnd, WORD wMatch)
2690 LPCWSTR lpGotIt = NULL;
2692 TRACE("(%p, %p, %x)\n", lpStart, lpEnd, wMatch);
2693 if (!lpEnd) lpEnd = lpStart + strlenW(lpStart);
2695 for(; lpStart < lpEnd; lpStart = CharNextW(lpStart))
2696 if (*lpStart == wMatch) lpGotIt = lpStart;
2698 return (LPWSTR)lpGotIt;
2702 /**************************************************************************
2703 * StrStrA [COMCTL32.354]
2706 LPSTR WINAPI COMCTL32_StrStrA( LPCSTR lpFirst, LPCSTR lpSrch) {
2707 return strstr(lpFirst, lpSrch);
2710 /**************************************************************************
2711 * StrStrW [COMCTL32.362]
2714 LPWSTR WINAPI COMCTL32_StrStrW( LPCWSTR lpFirst, LPCWSTR lpSrch) {
2715 return strstrW(lpFirst, lpSrch);
2718 /**************************************************************************
2719 * StrSpnW [COMCTL32.364]
2722 INT WINAPI COMCTL32_StrSpnW( LPWSTR lpStr, LPWSTR lpSet) {
2723 LPWSTR lpLoop = lpStr;
2726 if ((lpStr == 0) || (lpSet == 0)) return 0;
2728 /* while(*lpLoop) { if lpLoop++; } */
2730 for(; (*lpLoop != 0); lpLoop++)
2731 if( strchrW(lpSet, *(WORD*)lpLoop))
2732 return (INT)(lpLoop-lpStr);
2734 return (INT)(lpLoop-lpStr);
2737 /**************************************************************************
2740 * FIXME: What's this supposed to do?
2741 * Parameter 1 is an HWND, you're on your own for the rest.
2744 BOOL WINAPI DrawTextWrap( HWND hwnd, DWORD b, DWORD c, DWORD d, DWORD e)
2747 FIXME("(%p, %lx, %lx, %lx, %lx): stub!\n", hwnd, b, c, d, e);
2752 /**************************************************************************
2756 BOOL WINAPI ExtTextOutWrap(HDC hdc, INT x, INT y, UINT flags, const RECT *lprect,
2757 LPCWSTR str, UINT count, const INT *lpDx)
2759 return ExtTextOutW(hdc, x, y, flags, lprect, str, count, lpDx);
2762 /**************************************************************************
2765 * FIXME: What's this supposed to do?
2768 BOOL WINAPI GetTextExtentPointWrap( DWORD a, DWORD b, DWORD c, DWORD d)
2771 FIXME("(%lx, %lx, %lx, %lx): stub!\n", a, b, c, d);