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 */
82 typedef struct _STREAMDATA
87 } STREAMDATA, *PSTREAMDATA;
89 typedef struct _LOADDATA
93 } LOADDATA, *LPLOADDATA;
95 typedef HRESULT (CALLBACK *DPALOADPROC)(LPLOADDATA,IStream*,LPARAM);
97 /**************************************************************************
98 * DPA_LoadStream [COMCTL32.9]
100 * Loads a dynamic pointer array from a stream
103 * phDpa [O] pointer to a handle to a dynamic pointer array
104 * loadProc [I] pointer to a callback function
105 * pStream [I] pointer to a stream
106 * lParam [I] application specific value
109 * No more information available yet!
113 DPA_LoadStream (HDPA *phDpa, DPALOADPROC loadProc, IStream *pStream, LPARAM lParam)
116 LARGE_INTEGER position;
117 ULARGE_INTEGER newPosition;
118 STREAMDATA streamData;
124 FIXME ("phDpa=%p loadProc=%p pStream=%p lParam=%lx\n",
125 phDpa, loadProc, pStream, lParam);
127 if (!phDpa || !loadProc || !pStream)
132 position.QuadPart = 0;
135 * Zero out our streamData
137 memset(&streamData,0,sizeof(STREAMDATA));
139 errCode = IStream_Seek (pStream, position, STREAM_SEEK_CUR, &newPosition);
143 errCode = IStream_Read (pStream, &streamData, sizeof(STREAMDATA), &ulRead);
147 FIXME ("dwSize=%lu dwData2=%lu dwItems=%lu\n",
148 streamData.dwSize, streamData.dwData2, streamData.dwItems);
150 if ( ulRead < sizeof(STREAMDATA) ||
151 lParam < sizeof(STREAMDATA) ||
152 streamData.dwSize < sizeof(STREAMDATA) ||
153 streamData.dwData2 < 1) {
157 if (streamData.dwItems > (UINT_MAX / 2 / sizeof(VOID*))) /* 536870911 */
158 return E_OUTOFMEMORY;
161 hDpa = DPA_Create (streamData.dwItems);
163 return E_OUTOFMEMORY;
165 if (!DPA_Grow (hDpa, streamData.dwItems))
166 return E_OUTOFMEMORY;
168 /* load data from the stream into the dpa */
170 for (loadData.nCount = 0; loadData.nCount < streamData.dwItems; loadData.nCount++) {
171 errCode = (loadProc)(&loadData, pStream, lParam);
172 if (errCode != S_OK) {
181 /* set the number of items */
182 hDpa->nItemCount = loadData.nCount;
184 /* store the handle to the dpa */
186 FIXME ("new hDpa=%p, errorcode=%lx\n", hDpa, errCode);
192 /**************************************************************************
193 * DPA_SaveStream [COMCTL32.10]
195 * Saves a dynamic pointer array to a stream
198 * hDpa [I] handle to a dynamic pointer array
199 * loadProc [I] pointer to a callback function
200 * pStream [I] pointer to a stream
201 * lParam [I] application specific value
204 * No more information available yet!
208 DPA_SaveStream (const HDPA hDpa, DPALOADPROC loadProc, IStream *pStream, LPARAM lParam)
211 FIXME ("hDpa=%p loadProc=%p pStream=%p lParam=%lx\n",
212 hDpa, loadProc, pStream, lParam);
218 /**************************************************************************
219 * DPA_Merge [COMCTL32.11]
222 * hdpa1 [I] handle to a dynamic pointer array
223 * hdpa2 [I] handle to a dynamic pointer array
225 * pfnCompare [I] pointer to sort function
226 * pfnMerge [I] pointer to merge function
227 * lParam [I] application specific value
230 * No more information available yet!
234 DPA_Merge (const HDPA hdpa1, const HDPA hdpa2, DWORD dwFlags,
235 PFNDPACOMPARE pfnCompare, PFNDPAMERGE pfnMerge, LPARAM lParam)
238 LPVOID *pWork1, *pWork2;
242 TRACE("%p %p %08lx %p %p %08lx)\n",
243 hdpa1, hdpa2, dwFlags, pfnCompare, pfnMerge, lParam);
245 if (IsBadWritePtr (hdpa1, sizeof(*hdpa1)))
248 if (IsBadWritePtr (hdpa2, sizeof(*hdpa2)))
251 if (IsBadCodePtr ((FARPROC)pfnCompare))
254 if (IsBadCodePtr ((FARPROC)pfnMerge))
257 if (!(dwFlags & DPAM_NOSORT)) {
258 TRACE("sorting dpa's!\n");
259 if (hdpa1->nItemCount > 0)
260 DPA_Sort (hdpa1, pfnCompare, lParam);
261 TRACE ("dpa 1 sorted!\n");
262 if (hdpa2->nItemCount > 0)
263 DPA_Sort (hdpa2, pfnCompare, lParam);
264 TRACE ("dpa 2 sorted!\n");
267 if (hdpa2->nItemCount < 1)
270 TRACE("hdpa1->nItemCount=%d hdpa2->nItemCount=%d\n",
271 hdpa1->nItemCount, hdpa2->nItemCount);
274 /* working but untrusted implementation */
276 pWork1 = &(hdpa1->ptrs[hdpa1->nItemCount - 1]);
277 pWork2 = &(hdpa2->ptrs[hdpa2->nItemCount - 1]);
279 nIndex = hdpa1->nItemCount - 1;
280 nCount = hdpa2->nItemCount - 1;
285 if ((nCount >= 0) && (dwFlags & DPAM_INSERT)) {
286 /* Now insert the remaining new items into DPA 1 */
287 TRACE("%d items to be inserted at start of DPA 1\n",
289 for (i=nCount; i>=0; i--) {
292 ptr = (pfnMerge)(3, *pWork2, NULL, lParam);
295 DPA_InsertPtr (hdpa1, 0, ptr);
301 nResult = (pfnCompare)(*pWork1, *pWork2, lParam);
302 TRACE("compare result=%d, dpa1.cnt=%d, dpa2.cnt=%d\n",
303 nResult, nIndex, nCount);
309 ptr = (pfnMerge)(1, *pWork1, *pWork2, lParam);
319 else if (nResult > 0)
321 /* item in DPA 1 missing from DPA 2 */
322 if (dwFlags & DPAM_DELETE)
324 /* Now delete the extra item in DPA1 */
327 ptr = DPA_DeletePtr (hdpa1, hdpa1->nItemCount - 1);
329 (pfnMerge)(2, ptr, NULL, lParam);
336 /* new item in DPA 2 */
337 if (dwFlags & DPAM_INSERT)
339 /* Now insert the new item in DPA 1 */
342 ptr = (pfnMerge)(3, *pWork2, NULL, lParam);
345 DPA_InsertPtr (hdpa1, nIndex+1, ptr);
358 /**************************************************************************
359 * Alloc [COMCTL32.71]
361 * Allocates memory block from the dll's private heap
364 * dwSize [I] size of the allocated memory block
367 * Success: pointer to allocated memory block
371 LPVOID WINAPI Alloc (DWORD dwSize)
375 TRACE("(0x%lx)\n", dwSize);
377 lpPtr = HeapAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, dwSize);
379 TRACE("-- ret=%p\n", lpPtr);
385 /**************************************************************************
386 * ReAlloc [COMCTL32.72]
388 * Changes the size of an allocated memory block or allocates a memory
389 * block using the dll's private heap.
392 * lpSrc [I] pointer to memory block which will be resized
393 * dwSize [I] new size of the memory block.
396 * Success: pointer to the resized memory block
400 * If lpSrc is a NULL-pointer, then ReAlloc allocates a memory
404 LPVOID WINAPI ReAlloc (LPVOID lpSrc, DWORD dwSize)
408 TRACE("(%p 0x%08lx)\n", lpSrc, dwSize);
411 lpDest = HeapReAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, lpSrc, dwSize);
413 lpDest = HeapAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, dwSize);
415 TRACE("-- ret=%p\n", lpDest);
421 /**************************************************************************
424 * Frees an allocated memory block from the dll's private heap.
427 * lpMem [I] pointer to memory block which will be freed
434 BOOL WINAPI Free (LPVOID lpMem)
436 TRACE("(%p)\n", lpMem);
438 return HeapFree (COMCTL32_hHeap, 0, lpMem);
442 /**************************************************************************
443 * GetSize [COMCTL32.74]
445 * Retrieves the size of the specified memory block from the dll's
449 * lpMem [I] pointer to an allocated memory block
452 * Success: size of the specified memory block
456 DWORD WINAPI GetSize (LPVOID lpMem)
458 TRACE("(%p)\n", lpMem);
460 return HeapSize (COMCTL32_hHeap, 0, lpMem);
464 /**************************************************************************
465 * The MRU-API is a set of functions to manipulate MRU(Most Recently Used)
468 * Stored in the reg. as a set of values under a single key. Each item in the
469 * list has a value name that is a single char. 'a' - 'z', '{', '|' or '}'.
470 * The order of the list is stored with value name 'MRUList' which is a string
471 * containing the value names (i.e. 'a', 'b', etc.) in the relevant order.
474 typedef struct tagCREATEMRULISTA
476 DWORD cbSize; /* size of struct */
477 DWORD nMaxItems; /* max no. of items in list */
478 DWORD dwFlags; /* see below */
479 HKEY hKey; /* root reg. key under which list is saved */
480 LPCSTR lpszSubKey; /* reg. subkey */
481 PROC lpfnCompare; /* item compare proc */
482 } CREATEMRULISTA, *LPCREATEMRULISTA;
484 typedef struct tagCREATEMRULISTW
486 DWORD cbSize; /* size of struct */
487 DWORD nMaxItems; /* max no. of items in list */
488 DWORD dwFlags; /* see below */
489 HKEY hKey; /* root reg. key under which list is saved */
490 LPCWSTR lpszSubKey; /* reg. subkey */
491 PROC lpfnCompare; /* item compare proc */
492 } CREATEMRULISTW, *LPCREATEMRULISTW;
495 #define MRUF_STRING_LIST 0 /* list will contain strings */
496 #define MRUF_BINARY_LIST 1 /* list will contain binary data */
497 #define MRUF_DELAYED_SAVE 2 /* only save list order to reg. is FreeMRUList */
499 /* If list is a string list lpfnCompare has the following prototype
500 * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
501 * for binary lists the prototype is
502 * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
503 * where cbData is the no. of bytes to compare.
504 * Need to check what return value means identical - 0?
507 typedef struct tagWINEMRUITEM
509 DWORD size; /* size of data stored */
510 DWORD itemFlag; /* flags */
512 } WINEMRUITEM, *LPWINEMRUITEM;
515 #define WMRUIF_CHANGED 0x0001 /* this dataitem changed */
517 typedef struct tagWINEMRULIST
519 CREATEMRULISTW extview; /* original create information */
520 BOOL isUnicode; /* is compare fn Unicode */
521 DWORD wineFlags; /* internal flags */
522 DWORD cursize; /* current size of realMRU */
523 LPSTR realMRU; /* pointer to string of index names */
524 LPWINEMRUITEM *array; /* array of pointers to data */
525 /* in 'a' to 'z' order */
526 } WINEMRULIST, *LPWINEMRULIST;
529 #define WMRUF_CHANGED 0x0001 /* MRU list has changed */
531 /**************************************************************************
532 * MRU_SaveChanged - Localize MRU saving code
535 VOID MRU_SaveChanged( LPWINEMRULIST mp )
541 WCHAR emptyW[] = {'\0'};
543 /* or should we do the following instead of RegOpenKeyEx:
546 /* open the sub key */
547 if ((err = RegOpenKeyExW( mp->extview.hKey, mp->extview.lpszSubKey,
548 0, KEY_WRITE, &newkey))) {
549 /* not present - what to do ??? */
550 ERR("Can not open key, error=%d, attempting to create\n",
552 if ((err = RegCreateKeyExW( mp->extview.hKey, mp->extview.lpszSubKey,
555 REG_OPTION_NON_VOLATILE,
556 KEY_READ | KEY_WRITE,
560 ERR("failed to create key /%s/, err=%d\n",
561 debugstr_w(mp->extview.lpszSubKey), err);
565 if (mp->wineFlags & WMRUF_CHANGED) {
566 mp->wineFlags &= ~WMRUF_CHANGED;
567 err = RegSetValueExA(newkey, "MRUList", 0, REG_SZ,
568 mp->realMRU, strlen(mp->realMRU) + 1);
570 ERR("error saving MRUList, err=%d\n", err);
572 TRACE("saving MRUList=/%s/\n", mp->realMRU);
575 for(i=0; i<mp->cursize; i++) {
576 witem = mp->array[i];
577 if (witem->itemFlag & WMRUIF_CHANGED) {
578 witem->itemFlag &= ~WMRUIF_CHANGED;
579 realname[0] = 'a' + i;
580 err = RegSetValueExW(newkey, realname, 0,
581 (mp->extview.dwFlags & MRUF_BINARY_LIST) ?
583 &witem->datastart, witem->size);
585 ERR("error saving /%s/, err=%d\n", debugstr_w(realname), err);
587 TRACE("saving value for name /%s/ size=%ld\n",
588 debugstr_w(realname), witem->size);
591 RegCloseKey( newkey );
594 /**************************************************************************
595 * FreeMRUList [COMCTL32.152]
598 * hMRUList [I] Handle to list.
602 FreeMRUList (HANDLE hMRUList)
604 LPWINEMRULIST mp = (LPWINEMRULIST)hMRUList;
608 if (mp->wineFlags & WMRUF_CHANGED) {
609 /* need to open key and then save the info */
610 MRU_SaveChanged( mp );
613 for(i=0; i<mp->extview.nMaxItems; i++) {
619 Free((LPWSTR)mp->extview.lpszSubKey);
624 /**************************************************************************
625 * FindMRUData [COMCTL32.169]
627 * Searches binary list for item that matches lpData of length cbData.
628 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
629 * corresponding to item's reg. name will be stored in it ('a' -> 0).
632 * hList [I] list handle
633 * lpData [I] data to find
634 * cbData [I] length of data
635 * lpRegNum [O] position in registry (maybe NULL)
638 * Position in list 0 -> MRU. -1 if item not found.
641 FindMRUData (HANDLE hList, LPCVOID lpData, DWORD cbData, LPINT lpRegNum)
643 LPWINEMRULIST mp = (LPWINEMRULIST)hList;
647 if (!mp->extview.lpfnCompare) {
648 ERR("MRU list not properly created. No compare procedure.\n");
652 if(!(mp->extview.dwFlags & MRUF_BINARY_LIST) && !mp->isUnicode) {
653 DWORD len = WideCharToMultiByte(CP_ACP, 0, lpData, -1,
654 NULL, 0, NULL, NULL);
656 WideCharToMultiByte(CP_ACP, 0, lpData, -1, dataA, len, NULL, NULL);
659 for(i=0; i<mp->cursize; i++) {
660 if (mp->extview.dwFlags & MRUF_BINARY_LIST) {
661 if (!mp->extview.lpfnCompare(lpData, &mp->array[i]->datastart,
667 if (!mp->extview.lpfnCompare(lpData, &mp->array[i]->datastart))
670 DWORD len = WideCharToMultiByte(CP_ACP, 0,
671 (LPWSTR)&mp->array[i]->datastart, -1,
672 NULL, 0, NULL, NULL);
673 LPSTR itemA = Alloc(len);
675 WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&mp->array[i]->datastart, -1,
676 itemA, len, NULL, NULL);
678 cmp = mp->extview.lpfnCompare(dataA, itemA);
691 if (lpRegNum && (ret != -1))
694 TRACE("(%p, %p, %ld, %p) returning %d\n",
695 hList, lpData, cbData, lpRegNum, ret);
701 /**************************************************************************
702 * AddMRUData [COMCTL32.167]
704 * Add item to MRU binary list. If item already exists in list then it is
705 * simply moved up to the top of the list and not added again. If list is
706 * full then the least recently used item is removed to make room.
709 * hList [I] Handle to list.
710 * lpData [I] ptr to data to add.
711 * cbData [I] no. of bytes of data.
714 * No. corresponding to registry name where value is stored 'a' -> 0 etc.
718 AddMRUData (HANDLE hList, LPCVOID lpData, DWORD cbData)
720 LPWINEMRULIST mp = (LPWINEMRULIST)hList;
724 if ((replace = FindMRUData (hList, lpData, cbData, NULL)) < 0) {
725 /* either add a new entry or replace oldest */
726 if (mp->cursize < mp->extview.nMaxItems) {
727 /* Add in a new item */
728 replace = mp->cursize;
732 /* get the oldest entry and replace data */
733 replace = mp->realMRU[mp->cursize - 1] - 'a';
734 Free(mp->array[replace]);
738 /* free up the old data */
739 Free(mp->array[replace]);
742 /* Allocate space for new item and move in the data */
743 mp->array[replace] = witem = Alloc(cbData + sizeof(WINEMRUITEM));
744 witem->itemFlag |= WMRUIF_CHANGED;
745 witem->size = cbData;
746 memcpy( &witem->datastart, lpData, cbData);
748 /* now rotate MRU list */
749 mp->wineFlags |= WMRUF_CHANGED;
750 for(i=mp->cursize-1; i>=1; i--) {
751 mp->realMRU[i] = mp->realMRU[i-1];
753 mp->realMRU[0] = replace + 'a';
754 TRACE("(%p, %p, %ld) adding data, /%c/ now most current\n",
755 hList, lpData, cbData, replace+'a');
758 if (!(mp->extview.dwFlags & MRUF_DELAYED_SAVE)) {
759 /* save changed stuff right now */
760 MRU_SaveChanged( mp );
766 /**************************************************************************
767 * AddMRUStringW [COMCTL32.401]
769 * Add item to MRU string list. If item already exists in list them it is
770 * simply moved up to the top of the list and not added again. If list is
771 * full then the least recently used item is removed to make room.
774 * hList [I] Handle to list.
775 * lpszString [I] ptr to string to add.
778 * No. corresponding to registry name where value is stored 'a' -> 0 etc.
782 AddMRUStringW(HANDLE hList, LPCWSTR lpszString)
784 FIXME("(%p, %s) empty stub!\n", hList, debugstr_w(lpszString));
789 /**************************************************************************
790 * AddMRUStringA [COMCTL32.153]
793 AddMRUStringA(HANDLE hList, LPCSTR lpszString)
795 FIXME("(%p, %s) empty stub!\n", hList, debugstr_a(lpszString));
800 /**************************************************************************
801 * DelMRUString [COMCTL32.156]
803 * Removes item from either string or binary list (despite its name)
806 * hList [I] list handle
807 * nItemPos [I] item position to remove 0 -> MRU
810 * TRUE if successful, FALSE if nItemPos is out of range.
813 DelMRUString(HANDLE hList, INT nItemPos)
815 FIXME("(%p, %d): stub\n", hList, nItemPos);
819 /**************************************************************************
820 * FindMRUStringW [COMCTL32.402]
823 FindMRUStringW (HANDLE hList, LPCWSTR lpszString, LPINT lpRegNum)
829 /**************************************************************************
830 * FindMRUStringA [COMCTL32.155]
832 * Searches string list for item that matches lpszString.
833 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
834 * corresponding to item's reg. name will be stored in it ('a' -> 0).
837 * hList [I] list handle
838 * lpszString [I] string to find
839 * lpRegNum [O] position in registry (maybe NULL)
842 * Position in list 0 -> MRU. -1 if item not found.
845 FindMRUStringA (HANDLE hList, LPCSTR lpszString, LPINT lpRegNum)
847 DWORD len = MultiByteToWideChar(CP_ACP, 0, lpszString, -1, NULL, 0);
848 LPWSTR stringW = Alloc(len * sizeof(WCHAR));
851 MultiByteToWideChar(CP_ACP, 0, lpszString, -1, stringW, len);
852 ret = FindMRUData(hList, stringW, len * sizeof(WCHAR), lpRegNum);
857 /*************************************************************************
858 * CreateMRUListLazy_common
860 HANDLE CreateMRUListLazy_common(LPWINEMRULIST mp)
864 DWORD datasize, dwdisp;
868 WCHAR emptyW[] = {'\0'};
870 /* get space to save indices that will turn into names
871 * but in order of most to least recently used
873 mp->realMRU = Alloc(mp->extview.nMaxItems + 2);
875 /* get space to save pointers to actual data in order of
876 * 'a' to 'z' (0 to n).
878 mp->array = Alloc(mp->extview.nMaxItems * sizeof(LPVOID));
880 /* open the sub key */
881 if ((err = RegCreateKeyExW( mp->extview.hKey, mp->extview.lpszSubKey,
884 REG_OPTION_NON_VOLATILE,
885 KEY_READ | KEY_WRITE,
889 /* error - what to do ??? */
890 ERR("(%lu %lu %lx %lx \"%s\" %p): Can not open key, error=%d\n",
891 mp->extview.cbSize, mp->extview.nMaxItems, mp->extview.dwFlags,
892 (DWORD)mp->extview.hKey, debugstr_w(mp->extview.lpszSubKey),
893 mp->extview.lpfnCompare, err);
897 /* get values from key 'MRUList' */
899 datasize = mp->extview.nMaxItems + 1;
900 if((err=RegQueryValueExA( newkey, "MRUList", 0, &type, mp->realMRU,
902 /* not present - set size to 1 (will become 0 later) */
907 TRACE("MRU list = %s\n", mp->realMRU);
909 mp->cursize = datasize - 1;
910 /* datasize now has number of items in the MRUList */
912 /* get actual values for each entry */
914 for(i=0; i<mp->cursize; i++) {
915 realname[0] = 'a' + i;
916 if(RegQueryValueExW( newkey, realname, 0, &type, 0, &datasize)) {
917 /* not present - what to do ??? */
918 ERR("Key %s not found 1\n", debugstr_w(realname));
920 mp->array[i] = witem = Alloc(datasize + sizeof(WINEMRUITEM));
921 witem->size = datasize;
922 if(RegQueryValueExW( newkey, realname, 0, &type,
923 &witem->datastart, &datasize)) {
924 /* not present - what to do ??? */
925 ERR("Key %s not found 2\n", debugstr_w(realname));
928 RegCloseKey( newkey );
933 TRACE("(%lu %lu %lx %lx \"%s\" %p): Current Size = %ld\n",
934 mp->extview.cbSize, mp->extview.nMaxItems, mp->extview.dwFlags,
935 (DWORD)mp->extview.hKey, debugstr_w(mp->extview.lpszSubKey),
936 mp->extview.lpfnCompare, mp->cursize);
940 /**************************************************************************
941 * CreateMRUListLazyW [COMCTL32.404]
944 CreateMRUListLazyW (LPCREATEMRULISTW lpcml, DWORD dwParam2, DWORD dwParam3, DWORD dwParam4)
951 if (lpcml->cbSize < sizeof(CREATEMRULISTW))
954 mp = Alloc(sizeof(WINEMRULIST));
955 memcpy(&mp->extview, lpcml, sizeof(CREATEMRULISTW));
956 mp->extview.lpszSubKey = Alloc((strlenW(lpcml->lpszSubKey) + 1) * sizeof(WCHAR));
957 strcpyW((LPWSTR)mp->extview.lpszSubKey, lpcml->lpszSubKey);
958 mp->isUnicode = TRUE;
960 return CreateMRUListLazy_common(mp);
963 /**************************************************************************
964 * CreateMRUListLazyA [COMCTL32.157]
967 CreateMRUListLazyA (LPCREATEMRULISTA lpcml, DWORD dwParam2, DWORD dwParam3, DWORD dwParam4)
975 if (lpcml->cbSize < sizeof(CREATEMRULISTA))
978 mp = Alloc(sizeof(WINEMRULIST));
979 memcpy(&mp->extview, lpcml, sizeof(CREATEMRULISTW));
980 len = MultiByteToWideChar(CP_ACP, 0, lpcml->lpszSubKey, -1, NULL, 0);
981 mp->extview.lpszSubKey = Alloc(len * sizeof(WCHAR));
982 MultiByteToWideChar(CP_ACP, 0, lpcml->lpszSubKey, -1,
983 (LPWSTR)mp->extview.lpszSubKey, len);
984 mp->isUnicode = FALSE;
985 return CreateMRUListLazy_common(mp);
988 /**************************************************************************
989 * CreateMRUListW [COMCTL32.400]
992 * lpcml [I] ptr to CREATEMRULIST structure.
995 * Handle to MRU list.
998 CreateMRUListW (LPCREATEMRULISTW lpcml)
1000 return CreateMRUListLazyW(lpcml, 0, 0, 0);
1003 /**************************************************************************
1004 * CreateMRUListA [COMCTL32.151]
1007 CreateMRUListA (LPCREATEMRULISTA lpcml)
1009 return CreateMRUListLazyA (lpcml, 0, 0, 0);
1013 /**************************************************************************
1014 * EnumMRUListW [COMCTL32.403]
1016 * Enumerate item in a list
1019 * hList [I] list handle
1020 * nItemPos [I] item position to enumerate
1021 * lpBuffer [O] buffer to receive item
1022 * nBufferSize [I] size of buffer
1025 * For binary lists specifies how many bytes were copied to buffer, for
1026 * string lists specifies full length of string. Enumerating past the end
1027 * of list returns -1.
1028 * If lpBuffer == NULL or nItemPos is -ve return value is no. of items in
1031 INT WINAPI EnumMRUListW(HANDLE hList, INT nItemPos, LPVOID lpBuffer,
1034 LPWINEMRULIST mp = (LPWINEMRULIST) hList;
1035 LPWINEMRUITEM witem;
1036 INT desired, datasize;
1038 if (nItemPos >= mp->cursize) return -1;
1039 if ((nItemPos < 0) || !lpBuffer) return mp->cursize;
1040 desired = mp->realMRU[nItemPos];
1042 TRACE("nItemPos=%d, desired=%d\n", nItemPos, desired);
1043 witem = mp->array[desired];
1044 datasize = min( witem->size, nBufferSize );
1045 memcpy( lpBuffer, &witem->datastart, datasize);
1046 TRACE("(%p, %d, %p, %ld): returning len=%d\n",
1047 hList, nItemPos, lpBuffer, nBufferSize, datasize);
1051 /**************************************************************************
1052 * EnumMRUListA [COMCTL32.154]
1055 INT WINAPI EnumMRUListA(HANDLE hList, INT nItemPos, LPVOID lpBuffer,
1058 LPWINEMRULIST mp = (LPWINEMRULIST) hList;
1059 LPWINEMRUITEM witem;
1060 INT desired, datasize;
1063 if (nItemPos >= mp->cursize) return -1;
1064 if ((nItemPos < 0) || !lpBuffer) return mp->cursize;
1065 desired = mp->realMRU[nItemPos];
1067 TRACE("nItemPos=%d, desired=%d\n", nItemPos, desired);
1068 witem = mp->array[desired];
1069 if(mp->extview.dwFlags & MRUF_BINARY_LIST) {
1070 datasize = min( witem->size, nBufferSize );
1071 memcpy( lpBuffer, &witem->datastart, datasize);
1073 lenA = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&witem->datastart, -1,
1074 NULL, 0, NULL, NULL);
1075 datasize = min( witem->size, nBufferSize );
1076 WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&witem->datastart, -1,
1077 lpBuffer, datasize, NULL, NULL);
1079 TRACE("(%p, %d, %p, %ld): returning len=%d\n",
1080 hList, nItemPos, lpBuffer, nBufferSize, datasize);
1085 /**************************************************************************
1086 * Str_GetPtrA [COMCTL32.233]
1097 Str_GetPtrA (LPCSTR lpSrc, LPSTR lpDest, INT nMaxLen)
1101 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
1103 if (!lpDest && lpSrc)
1104 return strlen (lpSrc);
1109 if (lpSrc == NULL) {
1114 len = strlen (lpSrc);
1118 RtlMoveMemory (lpDest, lpSrc, len);
1125 /**************************************************************************
1126 * Str_SetPtrA [COMCTL32.234]
1136 Str_SetPtrA (LPSTR *lppDest, LPCSTR lpSrc)
1138 TRACE("(%p %p)\n", lppDest, lpSrc);
1141 LPSTR ptr = ReAlloc (*lppDest, strlen (lpSrc) + 1);
1144 strcpy (ptr, lpSrc);
1158 /**************************************************************************
1159 * Str_GetPtrW [COMCTL32.235]
1170 Str_GetPtrW (LPCWSTR lpSrc, LPWSTR lpDest, INT nMaxLen)
1174 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
1176 if (!lpDest && lpSrc)
1177 return strlenW (lpSrc);
1182 if (lpSrc == NULL) {
1187 len = strlenW (lpSrc);
1191 RtlMoveMemory (lpDest, lpSrc, len*sizeof(WCHAR));
1192 lpDest[len] = L'\0';
1198 /**************************************************************************
1199 * Str_SetPtrW [COMCTL32.236]
1209 Str_SetPtrW (LPWSTR *lppDest, LPCWSTR lpSrc)
1211 TRACE("(%p %p)\n", lppDest, lpSrc);
1214 INT len = strlenW (lpSrc) + 1;
1215 LPWSTR ptr = ReAlloc (*lppDest, len * sizeof(WCHAR));
1218 strcpyW (ptr, lpSrc);
1232 /**************************************************************************
1233 * Str_GetPtrWtoA [internal]
1235 * Converts a unicode string into a multi byte string
1238 * lpSrc [I] Pointer to the unicode source string
1239 * lpDest [O] Pointer to caller supplied storage for the multi byte string
1240 * nMaxLen [I] Size, in bytes, of the destination buffer
1243 * Length, in bytes, of the converted string.
1247 Str_GetPtrWtoA (LPCWSTR lpSrc, LPSTR lpDest, INT nMaxLen)
1251 TRACE("(%s %p %d)\n", debugstr_w(lpSrc), lpDest, nMaxLen);
1253 if (!lpDest && lpSrc)
1254 return WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, 0, 0, NULL, NULL);
1259 if (lpSrc == NULL) {
1264 len = WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, 0, 0, NULL, NULL);
1268 WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, lpDest, len, NULL, NULL);
1275 /**************************************************************************
1276 * Str_SetPtrAtoW [internal]
1278 * Converts a multi byte string to a unicode string.
1279 * If the pointer to the destination buffer is NULL a buffer is allocated.
1280 * If the destination buffer is too small to keep the converted multi byte
1281 * string the destination buffer is reallocated. If the source pointer is
1282 * NULL, the destination buffer is freed.
1285 * lppDest [I/O] pointer to a pointer to the destination buffer
1286 * lpSrc [I] pointer to a multi byte string
1289 * TRUE: conversion successful
1294 Str_SetPtrAtoW (LPWSTR *lppDest, LPCSTR lpSrc)
1296 TRACE("(%p %s)\n", lppDest, lpSrc);
1299 INT len = MultiByteToWideChar(CP_ACP,0,lpSrc,-1,NULL,0);
1300 LPWSTR ptr = ReAlloc (*lppDest, len*sizeof(WCHAR));
1304 MultiByteToWideChar(CP_ACP,0,lpSrc,-1,ptr,len);
1318 /**************************************************************************
1319 * The DSA-API is a set of functions to create and manipulate arrays of
1320 * fixed-size memory blocks. These arrays can store any kind of data
1321 * (strings, icons...).
1324 /**************************************************************************
1325 * DSA_Create [COMCTL32.320] Creates a dynamic storage array
1328 * nSize [I] size of the array elements
1329 * nGrow [I] number of elements by which the array grows when it is filled
1332 * Success: pointer to an array control structure. Use this like a handle.
1337 DSA_Create (INT nSize, INT nGrow)
1341 TRACE("(size=%d grow=%d)\n", nSize, nGrow);
1343 hdsa = Alloc (sizeof(*hdsa));
1346 hdsa->nItemCount = 0;
1348 hdsa->nMaxCount = 0;
1349 hdsa->nItemSize = nSize;
1350 hdsa->nGrow = max(1, nGrow);
1357 /**************************************************************************
1358 * DSA_Destroy [COMCTL32.321] Destroys a dynamic storage array
1361 * hdsa [I] pointer to the array control structure
1369 DSA_Destroy (const HDSA hdsa)
1371 TRACE("(%p)\n", hdsa);
1376 if (hdsa->pData && (!Free (hdsa->pData)))
1383 /**************************************************************************
1384 * DSA_GetItem [COMCTL32.322]
1387 * hdsa [I] pointer to the array control structure
1388 * nIndex [I] number of the Item to get
1389 * pDest [O] destination buffer. Has to be >= dwElementSize.
1397 DSA_GetItem (const HDSA hdsa, INT nIndex, LPVOID pDest)
1401 TRACE("(%p %d %p)\n", hdsa, nIndex, pDest);
1405 if ((nIndex < 0) || (nIndex >= hdsa->nItemCount))
1408 pSrc = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1409 memmove (pDest, pSrc, hdsa->nItemSize);
1415 /**************************************************************************
1416 * DSA_GetItemPtr [COMCTL32.323]
1418 * Retrieves a pointer to the specified item.
1421 * hdsa [I] pointer to the array control structure
1422 * nIndex [I] index of the desired item
1425 * Success: pointer to an item
1430 DSA_GetItemPtr (const HDSA hdsa, INT nIndex)
1434 TRACE("(%p %d)\n", hdsa, nIndex);
1438 if ((nIndex < 0) || (nIndex >= hdsa->nItemCount))
1441 pSrc = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1443 TRACE("-- ret=%p\n", pSrc);
1449 /**************************************************************************
1450 * DSA_SetItem [COMCTL32.325]
1452 * Sets the contents of an item in the array.
1455 * hdsa [I] pointer to the array control structure
1456 * nIndex [I] index for the item
1457 * pSrc [I] pointer to the new item data
1465 DSA_SetItem (const HDSA hdsa, INT nIndex, LPVOID pSrc)
1467 INT nSize, nNewItems;
1468 LPVOID pDest, lpTemp;
1470 TRACE("(%p %d %p)\n", hdsa, nIndex, pSrc);
1472 if ((!hdsa) || nIndex < 0)
1475 if (hdsa->nItemCount <= nIndex) {
1476 /* within the old array */
1477 if (hdsa->nMaxCount > nIndex) {
1478 /* within the allocated space, set a new boundary */
1479 hdsa->nItemCount = nIndex + 1;
1482 /* resize the block of memory */
1484 hdsa->nGrow * ((INT)(((nIndex + 1) - 1) / hdsa->nGrow) + 1);
1485 nSize = hdsa->nItemSize * nNewItems;
1487 lpTemp = ReAlloc (hdsa->pData, nSize);
1491 hdsa->nMaxCount = nNewItems;
1492 hdsa->nItemCount = nIndex + 1;
1493 hdsa->pData = lpTemp;
1497 /* put the new entry in */
1498 pDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1499 TRACE("-- move dest=%p src=%p size=%d\n",
1500 pDest, pSrc, hdsa->nItemSize);
1501 memmove (pDest, pSrc, hdsa->nItemSize);
1507 /**************************************************************************
1508 * DSA_InsertItem [COMCTL32.324]
1511 * hdsa [I] pointer to the array control structure
1512 * nIndex [I] index for the new item
1513 * pSrc [I] pointer to the element
1516 * Success: position of the new item
1521 DSA_InsertItem (const HDSA hdsa, INT nIndex, LPVOID pSrc)
1523 INT nNewItems, nSize;
1524 LPVOID lpTemp, lpDest;
1526 TRACE("(%p %d %p)\n", hdsa, nIndex, pSrc);
1528 if ((!hdsa) || nIndex < 0)
1531 /* when nIndex >= nItemCount then append */
1532 if (nIndex >= hdsa->nItemCount)
1533 nIndex = hdsa->nItemCount;
1535 /* do we need to resize ? */
1536 if (hdsa->nItemCount >= hdsa->nMaxCount) {
1537 nNewItems = hdsa->nMaxCount + hdsa->nGrow;
1538 nSize = hdsa->nItemSize * nNewItems;
1540 lpTemp = ReAlloc (hdsa->pData, nSize);
1544 hdsa->nMaxCount = nNewItems;
1545 hdsa->pData = lpTemp;
1548 /* do we need to move elements ? */
1549 if (nIndex < hdsa->nItemCount) {
1550 lpTemp = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1551 lpDest = (char *) lpTemp + hdsa->nItemSize;
1552 nSize = (hdsa->nItemCount - nIndex) * hdsa->nItemSize;
1553 TRACE("-- move dest=%p src=%p size=%d\n",
1554 lpDest, lpTemp, nSize);
1555 memmove (lpDest, lpTemp, nSize);
1558 /* ok, we can put the new Item in */
1560 lpDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1561 TRACE("-- move dest=%p src=%p size=%d\n",
1562 lpDest, pSrc, hdsa->nItemSize);
1563 memmove (lpDest, pSrc, hdsa->nItemSize);
1569 /**************************************************************************
1570 * DSA_DeleteItem [COMCTL32.326]
1573 * hdsa [I] pointer to the array control structure
1574 * nIndex [I] index for the element to delete
1577 * Success: number of the deleted element
1582 DSA_DeleteItem (const HDSA hdsa, INT nIndex)
1584 LPVOID lpDest,lpSrc;
1587 TRACE("(%p %d)\n", hdsa, nIndex);
1591 if (nIndex < 0 || nIndex >= hdsa->nItemCount)
1594 /* do we need to move ? */
1595 if (nIndex < hdsa->nItemCount - 1) {
1596 lpDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1597 lpSrc = (char *) lpDest + hdsa->nItemSize;
1598 nSize = hdsa->nItemSize * (hdsa->nItemCount - nIndex - 1);
1599 TRACE("-- move dest=%p src=%p size=%d\n",
1600 lpDest, lpSrc, nSize);
1601 memmove (lpDest, lpSrc, nSize);
1607 if ((hdsa->nMaxCount - hdsa->nItemCount) >= hdsa->nGrow) {
1608 nSize = hdsa->nItemSize * hdsa->nItemCount;
1610 lpDest = ReAlloc (hdsa->pData, nSize);
1614 hdsa->nMaxCount = hdsa->nItemCount;
1615 hdsa->pData = lpDest;
1622 /**************************************************************************
1623 * DSA_DeleteAllItems [COMCTL32.327]
1625 * Removes all items and reinitializes the array.
1628 * hdsa [I] pointer to the array control structure
1636 DSA_DeleteAllItems (const HDSA hdsa)
1638 TRACE("(%p)\n", hdsa);
1642 if (hdsa->pData && (!Free (hdsa->pData)))
1645 hdsa->nItemCount = 0;
1647 hdsa->nMaxCount = 0;
1653 /**************************************************************************
1654 * The DPA-API is a set of functions to create and manipulate arrays of
1658 /**************************************************************************
1659 * DPA_Create [COMCTL32.328] Creates a dynamic pointer array
1662 * nGrow [I] number of items by which the array grows when it is filled
1665 * Success: handle (pointer) to the pointer array.
1670 DPA_Create (INT nGrow)
1674 TRACE("(%d)\n", nGrow);
1676 hdpa = Alloc (sizeof(*hdpa));
1678 hdpa->nGrow = max(8, nGrow);
1679 hdpa->hHeap = COMCTL32_hHeap;
1680 hdpa->nMaxCount = hdpa->nGrow * 2;
1681 hdpa->ptrs = Alloc (hdpa->nMaxCount * sizeof(LPVOID));
1684 TRACE("-- %p\n", hdpa);
1690 /**************************************************************************
1691 * DPA_Destroy [COMCTL32.329] Destroys a dynamic pointer array
1694 * hdpa [I] handle (pointer) to the pointer array
1702 DPA_Destroy (const HDPA hdpa)
1704 TRACE("(%p)\n", hdpa);
1709 if (hdpa->ptrs && (!HeapFree (hdpa->hHeap, 0, hdpa->ptrs)))
1712 return HeapFree (hdpa->hHeap, 0, hdpa);
1716 /**************************************************************************
1717 * DPA_Grow [COMCTL32.330]
1719 * Sets the growth amount.
1722 * hdpa [I] handle (pointer) to the existing (source) pointer array
1723 * nGrow [I] number of items by which the array grows when it's too small
1731 DPA_Grow (const HDPA hdpa, INT nGrow)
1733 TRACE("(%p %d)\n", hdpa, nGrow);
1738 hdpa->nGrow = max(8, nGrow);
1744 /**************************************************************************
1745 * DPA_Clone [COMCTL32.331]
1747 * Copies a pointer array to an other one or creates a copy
1750 * hdpa [I] handle (pointer) to the existing (source) pointer array
1751 * hdpaNew [O] handle (pointer) to the destination pointer array
1754 * Success: pointer to the destination pointer array.
1758 * - If the 'hdpaNew' is a NULL-Pointer, a copy of the source pointer
1759 * array will be created and it's handle (pointer) is returned.
1760 * - If 'hdpa' is a NULL-Pointer, the original implementation crashes,
1761 * this implementation just returns NULL.
1765 DPA_Clone (const HDPA hdpa, const HDPA hdpaNew)
1767 INT nNewItems, nSize;
1773 TRACE("(%p %p)\n", hdpa, hdpaNew);
1776 /* create a new DPA */
1777 hdpaTemp = (HDPA)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1779 hdpaTemp->hHeap = hdpa->hHeap;
1780 hdpaTemp->nGrow = hdpa->nGrow;
1785 if (hdpaTemp->ptrs) {
1786 /* remove old pointer array */
1787 HeapFree (hdpaTemp->hHeap, 0, hdpaTemp->ptrs);
1788 hdpaTemp->ptrs = NULL;
1789 hdpaTemp->nItemCount = 0;
1790 hdpaTemp->nMaxCount = 0;
1793 /* create a new pointer array */
1794 nNewItems = hdpaTemp->nGrow *
1795 ((INT)((hdpa->nItemCount - 1) / hdpaTemp->nGrow) + 1);
1796 nSize = nNewItems * sizeof(LPVOID);
1798 (LPVOID*)HeapAlloc (hdpaTemp->hHeap, HEAP_ZERO_MEMORY, nSize);
1799 hdpaTemp->nMaxCount = nNewItems;
1801 /* clone the pointer array */
1802 hdpaTemp->nItemCount = hdpa->nItemCount;
1803 memmove (hdpaTemp->ptrs, hdpa->ptrs,
1804 hdpaTemp->nItemCount * sizeof(LPVOID));
1810 /**************************************************************************
1811 * DPA_GetPtr [COMCTL32.332]
1813 * Retrieves a pointer from a dynamic pointer array
1816 * hdpa [I] handle (pointer) to the pointer array
1817 * nIndex [I] array index of the desired pointer
1825 DPA_GetPtr (const HDPA hdpa, INT nIndex)
1827 TRACE("(%p %d)\n", hdpa, nIndex);
1832 WARN("no pointer array.\n");
1835 if ((nIndex < 0) || (nIndex >= hdpa->nItemCount)) {
1836 WARN("not enough pointers in array (%d vs %d).\n",nIndex,hdpa->nItemCount);
1840 TRACE("-- %p\n", hdpa->ptrs[nIndex]);
1842 return hdpa->ptrs[nIndex];
1846 /**************************************************************************
1847 * DPA_GetPtrIndex [COMCTL32.333]
1849 * Retrieves the index of the specified pointer
1852 * hdpa [I] handle (pointer) to the pointer array
1856 * Success: index of the specified pointer
1861 DPA_GetPtrIndex (const HDPA hdpa, LPVOID p)
1865 if (!hdpa || !hdpa->ptrs)
1868 for (i = 0; i < hdpa->nItemCount; i++) {
1869 if (hdpa->ptrs[i] == p)
1877 /**************************************************************************
1878 * DPA_InsertPtr [COMCTL32.334]
1880 * Inserts a pointer into a dynamic pointer array
1883 * hdpa [I] handle (pointer) to the array
1885 * p [I] pointer to insert
1888 * Success: index of the inserted pointer
1893 DPA_InsertPtr (const HDPA hdpa, INT i, LPVOID p)
1895 TRACE("(%p %d %p)\n", hdpa, i, p);
1897 if (!hdpa || i < 0) return -1;
1900 i = hdpa->nItemCount;
1902 if (i >= hdpa->nItemCount)
1903 return DPA_SetPtr(hdpa, i, p) ? i : -1;
1905 /* create empty spot at the end */
1906 if (!DPA_SetPtr(hdpa, hdpa->nItemCount, 0)) return -1;
1907 memmove (hdpa->ptrs + i + 1, hdpa->ptrs + i, (hdpa->nItemCount - i - 1) * sizeof(LPVOID));
1912 /**************************************************************************
1913 * DPA_SetPtr [COMCTL32.335]
1915 * Sets a pointer in the pointer array
1918 * hdpa [I] handle (pointer) to the pointer array
1919 * i [I] index of the pointer that will be set
1920 * p [I] pointer to be set
1928 DPA_SetPtr (const HDPA hdpa, INT i, LPVOID p)
1932 TRACE("(%p %d %p)\n", hdpa, i, p);
1934 if (!hdpa || i < 0 || i > 0x7fff)
1937 if (hdpa->nItemCount <= i) {
1938 /* within the old array */
1939 if (hdpa->nMaxCount <= i) {
1940 /* resize the block of memory */
1942 hdpa->nGrow * ((INT)(((i+1) - 1) / hdpa->nGrow) + 1);
1943 INT nSize = nNewItems * sizeof(LPVOID);
1946 lpTemp = (LPVOID*)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY, hdpa->ptrs, nSize);
1948 lpTemp = (LPVOID*)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY, nSize);
1953 hdpa->nMaxCount = nNewItems;
1954 hdpa->ptrs = lpTemp;
1956 hdpa->nItemCount = i+1;
1959 /* put the new entry in */
1966 /**************************************************************************
1967 * DPA_DeletePtr [COMCTL32.336]
1969 * Removes a pointer from the pointer array.
1972 * hdpa [I] handle (pointer) to the pointer array
1973 * i [I] index of the pointer that will be deleted
1976 * Success: deleted pointer
1981 DPA_DeletePtr (const HDPA hdpa, INT i)
1983 LPVOID *lpDest, *lpSrc, lpTemp = NULL;
1986 TRACE("(%p %d)\n", hdpa, i);
1988 if ((!hdpa) || i < 0 || i >= hdpa->nItemCount)
1991 lpTemp = hdpa->ptrs[i];
1993 /* do we need to move ?*/
1994 if (i < hdpa->nItemCount - 1) {
1995 lpDest = hdpa->ptrs + i;
1997 nSize = (hdpa->nItemCount - i - 1) * sizeof(LPVOID);
1998 TRACE("-- move dest=%p src=%p size=%x\n",
1999 lpDest, lpSrc, nSize);
2000 memmove (lpDest, lpSrc, nSize);
2003 hdpa->nItemCount --;
2006 if ((hdpa->nMaxCount - hdpa->nItemCount) >= hdpa->nGrow) {
2007 INT nNewItems = max(hdpa->nGrow * 2, hdpa->nItemCount);
2008 nSize = nNewItems * sizeof(LPVOID);
2009 lpDest = (LPVOID)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
2014 hdpa->nMaxCount = nNewItems;
2015 hdpa->ptrs = (LPVOID*)lpDest;
2022 /**************************************************************************
2023 * DPA_DeleteAllPtrs [COMCTL32.337]
2025 * Removes all pointers and reinitializes the array.
2028 * hdpa [I] handle (pointer) to the pointer array
2036 DPA_DeleteAllPtrs (const HDPA hdpa)
2038 TRACE("(%p)\n", hdpa);
2043 if (hdpa->ptrs && (!HeapFree (hdpa->hHeap, 0, hdpa->ptrs)))
2046 hdpa->nItemCount = 0;
2047 hdpa->nMaxCount = hdpa->nGrow * 2;
2048 hdpa->ptrs = (LPVOID*)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
2049 hdpa->nMaxCount * sizeof(LPVOID));
2055 /**************************************************************************
2056 * DPA_QuickSort [Internal]
2058 * Ordinary quicksort (used by DPA_Sort).
2061 * lpPtrs [I] pointer to the pointer array
2062 * l [I] index of the "left border" of the partition
2063 * r [I] index of the "right border" of the partition
2064 * pfnCompare [I] pointer to the compare function
2065 * lParam [I] user defined value (3rd parameter in compare function)
2072 DPA_QuickSort (LPVOID *lpPtrs, INT l, INT r,
2073 PFNDPACOMPARE pfnCompare, LPARAM lParam)
2078 TRACE("l=%i r=%i\n", l, r);
2080 if (l==r) /* one element is always sorted */
2082 if (r<l) /* oops, got it in the wrong order */
2084 DPA_QuickSort(lpPtrs, r, l, pfnCompare, lParam);
2087 m = (l+r)/2; /* divide by two */
2088 DPA_QuickSort(lpPtrs, l, m, pfnCompare, lParam);
2089 DPA_QuickSort(lpPtrs, m+1, r, pfnCompare, lParam);
2091 /* join the two sides */
2092 while( (l<=m) && (m<r) )
2094 if(pfnCompare(lpPtrs[l],lpPtrs[m+1],lParam)>0)
2097 memmove(&lpPtrs[l+1],&lpPtrs[l],(m-l+1)*sizeof(lpPtrs[l]));
2107 /**************************************************************************
2108 * DPA_Sort [COMCTL32.338]
2110 * Sorts a pointer array using a user defined compare function
2113 * hdpa [I] handle (pointer) to the pointer array
2114 * pfnCompare [I] pointer to the compare function
2115 * lParam [I] user defined value (3rd parameter of compare function)
2123 DPA_Sort (const HDPA hdpa, PFNDPACOMPARE pfnCompare, LPARAM lParam)
2125 if (!hdpa || !pfnCompare)
2128 TRACE("(%p %p 0x%lx)\n", hdpa, pfnCompare, lParam);
2130 if ((hdpa->nItemCount > 1) && (hdpa->ptrs))
2131 DPA_QuickSort (hdpa->ptrs, 0, hdpa->nItemCount - 1,
2132 pfnCompare, lParam);
2138 /**************************************************************************
2139 * DPA_Search [COMCTL32.339]
2141 * Searches a pointer array for a specified pointer
2144 * hdpa [I] handle (pointer) to the pointer array
2145 * pFind [I] pointer to search for
2146 * nStart [I] start index
2147 * pfnCompare [I] pointer to the compare function
2148 * lParam [I] user defined value (3rd parameter of compare function)
2149 * uOptions [I] search options
2152 * Success: index of the pointer in the array.
2156 * Binary search taken from R.Sedgewick "Algorithms in C"!
2157 * Function is NOT tested!
2158 * If something goes wrong, blame HIM not ME! (Eric Kohl)
2162 DPA_Search (const HDPA hdpa, LPVOID pFind, INT nStart,
2163 PFNDPACOMPARE pfnCompare, LPARAM lParam, UINT uOptions)
2165 if (!hdpa || !pfnCompare || !pFind)
2168 TRACE("(%p %p %d %p 0x%08lx 0x%08x)\n",
2169 hdpa, pFind, nStart, pfnCompare, lParam, uOptions);
2171 if (uOptions & DPAS_SORTED) {
2172 /* array is sorted --> use binary search */
2176 TRACE("binary search\n");
2178 l = (nStart == -1) ? 0 : nStart;
2179 r = hdpa->nItemCount - 1;
2183 n = (pfnCompare)(pFind, lpPtr[x], lParam);
2189 TRACE("-- ret=%d\n", n);
2194 if (uOptions & DPAS_INSERTBEFORE) {
2196 TRACE("-- ret=%d\n", r);
2200 if (uOptions & DPAS_INSERTAFTER) {
2201 TRACE("-- ret=%d\n", l);
2206 /* array is not sorted --> use linear search */
2210 TRACE("linear search\n");
2212 nIndex = (nStart == -1)? 0 : nStart;
2214 for (; nIndex < hdpa->nItemCount; nIndex++) {
2215 if ((pfnCompare)(pFind, lpPtr[nIndex], lParam) == 0) {
2216 TRACE("-- ret=%d\n", nIndex);
2222 TRACE("-- not found: ret=-1\n");
2227 /**************************************************************************
2228 * DPA_CreateEx [COMCTL32.340]
2230 * Creates a dynamic pointer array using the specified size and heap.
2233 * nGrow [I] number of items by which the array grows when it is filled
2234 * hHeap [I] handle to the heap where the array is stored
2237 * Success: handle (pointer) to the pointer array.
2242 DPA_CreateEx (INT nGrow, HANDLE hHeap)
2246 TRACE("(%d %p)\n", nGrow, hHeap);
2249 hdpa = (HDPA)HeapAlloc (hHeap, HEAP_ZERO_MEMORY, sizeof(*hdpa));
2251 hdpa = Alloc (sizeof(*hdpa));
2254 hdpa->nGrow = min(8, nGrow);
2255 hdpa->hHeap = hHeap ? hHeap : COMCTL32_hHeap;
2256 hdpa->nMaxCount = hdpa->nGrow * 2;
2258 (LPVOID*)HeapAlloc (hHeap, HEAP_ZERO_MEMORY,
2259 hdpa->nMaxCount * sizeof(LPVOID));
2262 TRACE("-- %p\n", hdpa);
2268 /**************************************************************************
2269 * Notification functions
2272 typedef struct tagNOTIFYDATA
2280 } NOTIFYDATA, *LPNOTIFYDATA;
2283 /**************************************************************************
2284 * DoNotify [Internal]
2288 DoNotify (LPNOTIFYDATA lpNotify, UINT uCode, LPNMHDR lpHdr)
2291 LPNMHDR lpNmh = NULL;
2294 TRACE("(%p %p %d %p 0x%08lx)\n",
2295 lpNotify->hwndFrom, lpNotify->hwndTo, uCode, lpHdr,
2296 lpNotify->dwParam5);
2298 if (!lpNotify->hwndTo)
2301 if (lpNotify->hwndFrom == (HWND)-1) {
2303 idFrom = lpHdr->idFrom;
2306 if (lpNotify->hwndFrom) {
2307 HWND hwndParent = GetParent (lpNotify->hwndFrom);
2309 hwndParent = GetWindow (lpNotify->hwndFrom, GW_OWNER);
2310 /* the following is done even if the return from above
2311 * is zero. GLA 12/2001 */
2312 idFrom = GetDlgCtrlID (lpNotify->hwndFrom);
2316 lpNmh = (lpHdr) ? lpHdr : &nmhdr;
2318 lpNmh->hwndFrom = lpNotify->hwndFrom;
2319 lpNmh->idFrom = idFrom;
2320 lpNmh->code = uCode;
2323 return SendMessageA (lpNotify->hwndTo, WM_NOTIFY, idFrom, (LPARAM)lpNmh);
2327 /**************************************************************************
2328 * SendNotify [COMCTL32.341]
2337 * Success: return value from notification
2341 LRESULT WINAPI SendNotify (HWND hwndTo, HWND hwndFrom, UINT uCode, LPNMHDR lpHdr)
2345 TRACE("(%p %p %d %p)\n",
2346 hwndTo, hwndFrom, uCode, lpHdr);
2348 notify.hwndFrom = hwndFrom;
2349 notify.hwndTo = hwndTo;
2350 notify.dwParam5 = 0;
2351 notify.dwParam6 = 0;
2353 return DoNotify (¬ify, uCode, lpHdr);
2357 /**************************************************************************
2358 * SendNotifyEx [COMCTL32.342]
2368 * Success: return value from notification
2372 LRESULT WINAPI SendNotifyEx (HWND hwndTo, HWND hwndFrom, UINT uCode,
2373 LPNMHDR lpHdr, DWORD dwParam5)
2378 TRACE("(%p %p %d %p 0x%08lx)\n",
2379 hwndFrom, hwndTo, uCode, lpHdr, dwParam5);
2381 hwndNotify = hwndTo;
2383 if (IsWindow (hwndFrom)) {
2384 hwndNotify = GetParent (hwndFrom);
2390 notify.hwndFrom = hwndFrom;
2391 notify.hwndTo = hwndNotify;
2392 notify.dwParam5 = dwParam5;
2393 notify.dwParam6 = 0;
2395 return DoNotify (¬ify, uCode, lpHdr);
2399 /**************************************************************************
2400 * StrChrA [COMCTL32.350]
2404 LPSTR WINAPI StrChrA (LPCSTR lpString, CHAR cChar)
2406 return strchr (lpString, cChar);
2410 /**************************************************************************
2411 * StrStrIA [COMCTL32.355]
2414 LPSTR WINAPI StrStrIA (LPCSTR lpStr1, LPCSTR lpStr2)
2420 return ((LPSTR)lpStr1);
2422 while (lpStr1[len1] != 0) ++len1;
2424 while (lpStr2[len2] != 0) ++len2;
2426 return ((LPSTR)(lpStr1 + len1));
2427 first = tolower (*lpStr2);
2428 while (len1 >= len2) {
2429 if (tolower(*lpStr1) == first) {
2430 for (i = 1; i < len2; ++i)
2431 if (tolower (lpStr1[i]) != tolower(lpStr2[i]))
2434 return ((LPSTR)lpStr1);
2441 /**************************************************************************
2442 * StrToIntA [COMCTL32.357] Converts a string to a signed integer.
2445 INT WINAPI StrToIntA (LPSTR lpString)
2447 return atoi(lpString);
2450 /**************************************************************************
2451 * StrStrIW [COMCTL32.363]
2454 LPWSTR WINAPI StrStrIW (LPCWSTR lpStr1, LPCWSTR lpStr2)
2460 return ((LPWSTR)lpStr1);
2462 while (lpStr1[len1] != 0) ++len1;
2464 while (lpStr2[len2] != 0) ++len2;
2466 return ((LPWSTR)(lpStr1 + len1));
2467 first = tolowerW (*lpStr2);
2468 while (len1 >= len2) {
2469 if (tolowerW (*lpStr1) == first) {
2470 for (i = 1; i < len2; ++i)
2471 if (tolowerW (lpStr1[i]) != tolowerW(lpStr2[i]))
2474 return ((LPWSTR)lpStr1);
2481 /**************************************************************************
2482 * StrToIntW [COMCTL32.365] Converts a wide char string to a signed integer.
2485 INT WINAPI StrToIntW (LPWSTR lpString)
2487 return atoiW(lpString);
2491 /**************************************************************************
2492 * DPA_EnumCallback [COMCTL32.385]
2494 * Enumerates all items in a dynamic pointer array.
2497 * hdpa [I] handle to the dynamic pointer array
2506 DPA_EnumCallback (HDPA hdpa, PFNDPAENUMCALLBACK enumProc, LPVOID lParam)
2510 TRACE("(%p %p %p)\n", hdpa, enumProc, lParam);
2514 if (hdpa->nItemCount <= 0)
2517 for (i = 0; i < hdpa->nItemCount; i++) {
2518 if ((enumProc)(hdpa->ptrs[i], lParam) == 0)
2526 /**************************************************************************
2527 * DPA_DestroyCallback [COMCTL32.386]
2529 * Enumerates all items in a dynamic pointer array and destroys it.
2532 * hdpa [I] handle to the dynamic pointer array
2541 DPA_DestroyCallback (HDPA hdpa, PFNDPAENUMCALLBACK enumProc, LPVOID lParam)
2543 TRACE("(%p %p %p)\n", hdpa, enumProc, lParam);
2545 DPA_EnumCallback (hdpa, enumProc, lParam);
2550 /**************************************************************************
2551 * DSA_EnumCallback [COMCTL32.387]
2553 * Enumerates all items in a dynamic storage array.
2556 * hdsa [I] handle to the dynamic storage array
2565 DSA_EnumCallback (HDSA hdsa, PFNDSAENUMCALLBACK enumProc, LPVOID lParam)
2569 TRACE("(%p %p %p)\n", hdsa, enumProc, lParam);
2573 if (hdsa->nItemCount <= 0)
2576 for (i = 0; i < hdsa->nItemCount; i++) {
2577 LPVOID lpItem = DSA_GetItemPtr (hdsa, i);
2578 if ((enumProc)(lpItem, lParam) == 0)
2586 /**************************************************************************
2587 * DSA_DestroyCallback [COMCTL32.388]
2589 * Enumerates all items in a dynamic storage array and destroys it.
2592 * hdsa [I] handle to the dynamic storage array
2601 DSA_DestroyCallback (HDSA hdsa, PFNDSAENUMCALLBACK enumProc, LPVOID lParam)
2603 TRACE("(%p %p %p)\n", hdsa, enumProc, lParam);
2605 DSA_EnumCallback (hdsa, enumProc, lParam);
2609 /**************************************************************************
2610 * StrCSpnA [COMCTL32.356]
2613 INT WINAPI StrCSpnA( LPCSTR lpStr, LPCSTR lpSet)
2615 return strcspn(lpStr, lpSet);
2618 /**************************************************************************
2619 * StrChrW [COMCTL32.358]
2622 LPWSTR WINAPI StrChrW( LPCWSTR lpStart, WORD wMatch)
2624 return strchrW(lpStart, wMatch);
2627 /**************************************************************************
2628 * StrCmpNA [COMCTL32.352]
2631 INT WINAPI StrCmpNA( LPCSTR lpStr1, LPCSTR lpStr2, int nChar)
2633 return strncmp(lpStr1, lpStr2, nChar);
2636 /**************************************************************************
2637 * StrCmpNIA [COMCTL32.353]
2640 INT WINAPI StrCmpNIA( LPCSTR lpStr1, LPCSTR lpStr2, int nChar)
2642 return strncasecmp(lpStr1, lpStr2, nChar);
2645 /**************************************************************************
2646 * StrCmpNW [COMCTL32.360]
2649 INT WINAPI StrCmpNW( LPCWSTR lpStr1, LPCWSTR lpStr2, int nChar)
2651 return strncmpW(lpStr1, lpStr2, nChar);
2654 /**************************************************************************
2655 * StrCmpNIW [COMCTL32.361]
2658 INT WINAPI StrCmpNIW( LPCWSTR lpStr1, LPCWSTR lpStr2, int nChar)
2660 FIXME("(%s, %s, %i): stub\n", debugstr_w(lpStr1), debugstr_w(lpStr2), nChar);
2664 /**************************************************************************
2665 * StrRChrA [COMCTL32.351]
2668 LPSTR WINAPI StrRChrA( LPCSTR lpStart, LPCSTR lpEnd, WORD wMatch )
2670 LPCSTR lpGotIt = NULL;
2671 BOOL dbcs = IsDBCSLeadByte( LOBYTE(wMatch) );
2673 TRACE("(%p, %p, %x)\n", lpStart, lpEnd, wMatch);
2675 if (!lpEnd) lpEnd = lpStart + strlen(lpStart);
2677 for(; lpStart < lpEnd; lpStart = CharNextA(lpStart))
2679 if (*lpStart != LOBYTE(wMatch)) continue;
2680 if (dbcs && lpStart[1] != HIBYTE(wMatch)) continue;
2683 return (LPSTR)lpGotIt;
2687 /**************************************************************************
2688 * StrRChrW [COMCTL32.359]
2691 LPWSTR WINAPI StrRChrW( LPCWSTR lpStart, LPCWSTR lpEnd, WORD wMatch)
2693 LPCWSTR lpGotIt = NULL;
2695 TRACE("(%p, %p, %x)\n", lpStart, lpEnd, wMatch);
2696 if (!lpEnd) lpEnd = lpStart + strlenW(lpStart);
2698 for(; lpStart < lpEnd; lpStart = CharNextW(lpStart))
2699 if (*lpStart == wMatch) lpGotIt = lpStart;
2701 return (LPWSTR)lpGotIt;
2705 /**************************************************************************
2706 * StrStrA [COMCTL32.354]
2709 LPSTR WINAPI StrStrA( LPCSTR lpFirst, LPCSTR lpSrch)
2711 return strstr(lpFirst, lpSrch);
2714 /**************************************************************************
2715 * StrStrW [COMCTL32.362]
2718 LPWSTR WINAPI StrStrW( LPCWSTR lpFirst, LPCWSTR lpSrch)
2720 return strstrW(lpFirst, lpSrch);
2723 /**************************************************************************
2724 * StrSpnW [COMCTL32.364]
2727 INT WINAPI StrSpnW( LPWSTR lpStr, LPWSTR lpSet)
2729 LPWSTR lpLoop = lpStr;
2732 if ((lpStr == 0) || (lpSet == 0)) return 0;
2734 /* while(*lpLoop) { if lpLoop++; } */
2736 for(; (*lpLoop != 0); lpLoop++)
2737 if( strchrW(lpSet, *(WORD*)lpLoop))
2738 return (INT)(lpLoop-lpStr);
2740 return (INT)(lpLoop-lpStr);
2743 /**************************************************************************
2746 * FIXME: What's this supposed to do?
2747 * Parameter 1 is an HWND, you're on your own for the rest.
2750 BOOL WINAPI DrawTextWrap( HWND hwnd, DWORD b, DWORD c, DWORD d, DWORD e)
2753 FIXME("(%p, %lx, %lx, %lx, %lx): stub!\n", hwnd, b, c, d, e);
2758 /**************************************************************************
2762 BOOL WINAPI ExtTextOutWrap(HDC hdc, INT x, INT y, UINT flags, const RECT *lprect,
2763 LPCWSTR str, UINT count, const INT *lpDx)
2765 return ExtTextOutW(hdc, x, y, flags, lprect, str, count, lpDx);
2768 /**************************************************************************
2771 * FIXME: What's this supposed to do?
2774 BOOL WINAPI GetTextExtentPointWrap( DWORD a, DWORD b, DWORD c, DWORD d)
2777 FIXME("(%lx, %lx, %lx, %lx): stub!\n", a, b, c, d);