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).
30 #include "wine/port.h"
38 #define NONAMELESSUNION
39 #define NONAMELESSSTRUCT
51 #include "wine/unicode.h"
54 #include "wine/debug.h"
56 WINE_DEFAULT_DEBUG_CHANNEL(commctrl
);
76 typedef struct _STREAMDATA
81 } STREAMDATA
, *PSTREAMDATA
;
83 typedef struct _LOADDATA
87 } LOADDATA
, *LPLOADDATA
;
89 typedef HRESULT (CALLBACK
*DPALOADPROC
)(LPLOADDATA
,IStream
*,LPARAM
);
91 /**************************************************************************
92 * DPA_LoadStream [COMCTL32.9]
94 * Loads a dynamic pointer array from a stream
97 * phDpa [O] pointer to a handle to a dynamic pointer array
98 * loadProc [I] pointer to a callback function
99 * pStream [I] pointer to a stream
100 * lParam [I] application specific value
107 * No more information available yet!
111 DPA_LoadStream (HDPA
*phDpa
, DPALOADPROC loadProc
, IStream
*pStream
, LPARAM lParam
)
114 LARGE_INTEGER position
;
115 ULARGE_INTEGER newPosition
;
116 STREAMDATA streamData
;
122 FIXME ("phDpa=%p loadProc=%p pStream=%p lParam=%lx\n",
123 phDpa
, loadProc
, pStream
, lParam
);
125 if (!phDpa
|| !loadProc
|| !pStream
)
130 position
.QuadPart
= 0;
133 * Zero out our streamData
135 memset(&streamData
,0,sizeof(STREAMDATA
));
137 errCode
= IStream_Seek (pStream
, position
, STREAM_SEEK_CUR
, &newPosition
);
141 errCode
= IStream_Read (pStream
, &streamData
, sizeof(STREAMDATA
), &ulRead
);
145 FIXME ("dwSize=%lu dwData2=%lu dwItems=%lu\n",
146 streamData
.dwSize
, streamData
.dwData2
, streamData
.dwItems
);
148 if ( ulRead
< sizeof(STREAMDATA
) ||
149 lParam
< sizeof(STREAMDATA
) ||
150 streamData
.dwSize
< sizeof(STREAMDATA
) ||
151 streamData
.dwData2
< 1) {
155 if (streamData
.dwItems
> (UINT_MAX
/ 2 / sizeof(VOID
*))) /* 536870911 */
156 return E_OUTOFMEMORY
;
159 hDpa
= DPA_Create (streamData
.dwItems
);
161 return E_OUTOFMEMORY
;
163 if (!DPA_Grow (hDpa
, streamData
.dwItems
))
164 return E_OUTOFMEMORY
;
166 /* load data from the stream into the dpa */
168 for (loadData
.nCount
= 0; loadData
.nCount
< streamData
.dwItems
; loadData
.nCount
++) {
169 errCode
= (loadProc
)(&loadData
, pStream
, lParam
);
170 if (errCode
!= S_OK
) {
179 /* set the number of items */
180 hDpa
->nItemCount
= loadData
.nCount
;
182 /* store the handle to the dpa */
184 FIXME ("new hDpa=%p, errorcode=%lx\n", hDpa
, errCode
);
190 /**************************************************************************
191 * DPA_SaveStream [COMCTL32.10]
193 * Saves a dynamic pointer array to a stream
196 * hDpa [I] handle to a dynamic pointer array
197 * loadProc [I] pointer to a callback function
198 * pStream [I] pointer to a stream
199 * lParam [I] application specific value
206 * No more information available yet!
210 DPA_SaveStream (const HDPA hDpa
, DPALOADPROC loadProc
, IStream
*pStream
, LPARAM lParam
)
213 FIXME ("hDpa=%p loadProc=%p pStream=%p lParam=%lx\n",
214 hDpa
, loadProc
, pStream
, lParam
);
220 /**************************************************************************
221 * DPA_Merge [COMCTL32.11]
224 * hdpa1 [I] handle to a dynamic pointer array
225 * hdpa2 [I] handle to a dynamic pointer array
227 * pfnCompare [I] pointer to sort function
228 * pfnMerge [I] pointer to merge function
229 * lParam [I] application specific value
236 * No more information available yet!
240 DPA_Merge (const HDPA hdpa1
, const HDPA hdpa2
, DWORD dwFlags
,
241 PFNDPACOMPARE pfnCompare
, PFNDPAMERGE pfnMerge
, LPARAM lParam
)
244 LPVOID
*pWork1
, *pWork2
;
248 TRACE("%p %p %08lx %p %p %08lx)\n",
249 hdpa1
, hdpa2
, dwFlags
, pfnCompare
, pfnMerge
, lParam
);
251 if (IsBadWritePtr (hdpa1
, sizeof(*hdpa1
)))
254 if (IsBadWritePtr (hdpa2
, sizeof(*hdpa2
)))
257 if (IsBadCodePtr ((FARPROC
)pfnCompare
))
260 if (IsBadCodePtr ((FARPROC
)pfnMerge
))
263 if (!(dwFlags
& DPAM_NOSORT
)) {
264 TRACE("sorting dpa's!\n");
265 if (hdpa1
->nItemCount
> 0)
266 DPA_Sort (hdpa1
, pfnCompare
, lParam
);
267 TRACE ("dpa 1 sorted!\n");
268 if (hdpa2
->nItemCount
> 0)
269 DPA_Sort (hdpa2
, pfnCompare
, lParam
);
270 TRACE ("dpa 2 sorted!\n");
273 if (hdpa2
->nItemCount
< 1)
276 TRACE("hdpa1->nItemCount=%d hdpa2->nItemCount=%d\n",
277 hdpa1
->nItemCount
, hdpa2
->nItemCount
);
280 /* working but untrusted implementation */
282 pWork1
= &(hdpa1
->ptrs
[hdpa1
->nItemCount
- 1]);
283 pWork2
= &(hdpa2
->ptrs
[hdpa2
->nItemCount
- 1]);
285 nIndex
= hdpa1
->nItemCount
- 1;
286 nCount
= hdpa2
->nItemCount
- 1;
291 if ((nCount
>= 0) && (dwFlags
& DPAM_INSERT
)) {
292 /* Now insert the remaining new items into DPA 1 */
293 TRACE("%d items to be inserted at start of DPA 1\n",
295 for (i
=nCount
; i
>=0; i
--) {
298 ptr
= (pfnMerge
)(3, *pWork2
, NULL
, lParam
);
301 DPA_InsertPtr (hdpa1
, 0, ptr
);
307 nResult
= (pfnCompare
)(*pWork1
, *pWork2
, lParam
);
308 TRACE("compare result=%d, dpa1.cnt=%d, dpa2.cnt=%d\n",
309 nResult
, nIndex
, nCount
);
315 ptr
= (pfnMerge
)(1, *pWork1
, *pWork2
, lParam
);
325 else if (nResult
> 0)
327 /* item in DPA 1 missing from DPA 2 */
328 if (dwFlags
& DPAM_DELETE
)
330 /* Now delete the extra item in DPA1 */
333 ptr
= DPA_DeletePtr (hdpa1
, hdpa1
->nItemCount
- 1);
335 (pfnMerge
)(2, ptr
, NULL
, lParam
);
342 /* new item in DPA 2 */
343 if (dwFlags
& DPAM_INSERT
)
345 /* Now insert the new item in DPA 1 */
348 ptr
= (pfnMerge
)(3, *pWork2
, NULL
, lParam
);
351 DPA_InsertPtr (hdpa1
, nIndex
+1, ptr
);
364 /**************************************************************************
365 * Alloc [COMCTL32.71]
367 * Allocates memory block from the dll's private heap
370 * dwSize [I] size of the allocated memory block
373 * Success: pointer to allocated memory block
377 LPVOID WINAPI
Alloc (DWORD dwSize
)
379 return LocalAlloc( LMEM_ZEROINIT
, dwSize
);
383 /**************************************************************************
384 * ReAlloc [COMCTL32.72]
386 * Changes the size of an allocated memory block or allocates a memory
387 * block using the dll's private heap.
390 * lpSrc [I] pointer to memory block which will be resized
391 * dwSize [I] new size of the memory block.
394 * Success: pointer to the resized memory block
398 * If lpSrc is a NULL-pointer, then ReAlloc allocates a memory
402 LPVOID WINAPI
ReAlloc (LPVOID lpSrc
, DWORD dwSize
)
405 return LocalReAlloc( lpSrc
, dwSize
, LMEM_ZEROINIT
);
407 return LocalAlloc( LMEM_ZEROINIT
, dwSize
);
411 /**************************************************************************
414 * Frees an allocated memory block from the dll's private heap.
417 * lpMem [I] pointer to memory block which will be freed
424 BOOL WINAPI
Free (LPVOID lpMem
)
426 return !LocalFree( lpMem
);
430 /**************************************************************************
431 * GetSize [COMCTL32.74]
433 * Retrieves the size of the specified memory block from the dll's
437 * lpMem [I] pointer to an allocated memory block
440 * Success: size of the specified memory block
444 DWORD WINAPI
GetSize (LPVOID lpMem
)
446 return LocalSize( 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 (internal)
520 * Localize MRU saving code
522 VOID
MRU_SaveChanged( LPWINEMRULIST mp
)
528 static const WCHAR emptyW
[] = {'\0'};
530 /* or should we do the following instead of RegOpenKeyEx:
533 /* open the sub key */
534 if ((err
= RegOpenKeyExW( mp
->extview
.hKey
, mp
->extview
.lpszSubKey
,
535 0, KEY_WRITE
, &newkey
))) {
536 /* not present - what to do ??? */
537 ERR("Can not open key, error=%d, attempting to create\n",
539 if ((err
= RegCreateKeyExW( mp
->extview
.hKey
, mp
->extview
.lpszSubKey
,
542 REG_OPTION_NON_VOLATILE
,
543 KEY_READ
| KEY_WRITE
,
547 ERR("failed to create key /%s/, err=%d\n",
548 debugstr_w(mp
->extview
.lpszSubKey
), err
);
552 if (mp
->wineFlags
& WMRUF_CHANGED
) {
553 mp
->wineFlags
&= ~WMRUF_CHANGED
;
554 err
= RegSetValueExA(newkey
, "MRUList", 0, REG_SZ
,
555 mp
->realMRU
, strlen(mp
->realMRU
) + 1);
557 ERR("error saving MRUList, err=%d\n", err
);
559 TRACE("saving MRUList=/%s/\n", mp
->realMRU
);
562 for(i
=0; i
<mp
->cursize
; i
++) {
563 witem
= mp
->array
[i
];
564 if (witem
->itemFlag
& WMRUIF_CHANGED
) {
565 witem
->itemFlag
&= ~WMRUIF_CHANGED
;
566 realname
[0] = 'a' + i
;
567 err
= RegSetValueExW(newkey
, realname
, 0,
568 (mp
->extview
.dwFlags
& MRUF_BINARY_LIST
) ?
570 &witem
->datastart
, witem
->size
);
572 ERR("error saving /%s/, err=%d\n", debugstr_w(realname
), err
);
574 TRACE("saving value for name /%s/ size=%ld\n",
575 debugstr_w(realname
), witem
->size
);
578 RegCloseKey( newkey
);
581 /**************************************************************************
582 * FreeMRUList [COMCTL32.152]
584 * Frees a most-recently-used items list.
587 * hMRUList [I] Handle to list.
594 FreeMRUList (HANDLE hMRUList
)
596 LPWINEMRULIST mp
= (LPWINEMRULIST
)hMRUList
;
600 if (mp
->wineFlags
& WMRUF_CHANGED
) {
601 /* need to open key and then save the info */
602 MRU_SaveChanged( mp
);
605 for(i
=0; i
<mp
->extview
.nMaxItems
; i
++) {
611 Free((LPWSTR
)mp
->extview
.lpszSubKey
);
616 /**************************************************************************
617 * FindMRUData [COMCTL32.169]
619 * Searches binary list for item that matches lpData of length cbData.
620 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
621 * corresponding to item's reg. name will be stored in it ('a' -> 0).
624 * hList [I] list handle
625 * lpData [I] data to find
626 * cbData [I] length of data
627 * lpRegNum [O] position in registry (maybe NULL)
630 * Position in list 0 -> MRU. -1 if item not found.
633 FindMRUData (HANDLE hList
, LPCVOID lpData
, DWORD cbData
, LPINT lpRegNum
)
635 LPWINEMRULIST mp
= (LPWINEMRULIST
)hList
;
640 if (!mp
->extview
.lpfnCompare
) {
641 ERR("MRU list not properly created. No compare procedure.\n");
645 if(!(mp
->extview
.dwFlags
& MRUF_BINARY_LIST
) && !mp
->isUnicode
) {
646 DWORD len
= WideCharToMultiByte(CP_ACP
, 0, lpData
, -1,
647 NULL
, 0, NULL
, NULL
);
649 WideCharToMultiByte(CP_ACP
, 0, lpData
, -1, dataA
, len
, NULL
, NULL
);
652 for(i
=0; i
<mp
->cursize
; i
++) {
653 if (mp
->extview
.dwFlags
& MRUF_BINARY_LIST
) {
654 if (!mp
->extview
.lpfnCompare(lpData
, &mp
->array
[i
]->datastart
,
660 if (!mp
->extview
.lpfnCompare(lpData
, &mp
->array
[i
]->datastart
))
663 DWORD len
= WideCharToMultiByte(CP_ACP
, 0,
664 (LPWSTR
)&mp
->array
[i
]->datastart
, -1,
665 NULL
, 0, NULL
, NULL
);
666 LPSTR itemA
= Alloc(len
);
668 WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&mp
->array
[i
]->datastart
, -1,
669 itemA
, len
, NULL
, NULL
);
671 cmp
= mp
->extview
.lpfnCompare(dataA
, itemA
);
684 if (lpRegNum
&& (ret
!= -1))
687 TRACE("(%p, %p, %ld, %p) returning %d\n",
688 hList
, lpData
, cbData
, lpRegNum
, ret
);
694 /**************************************************************************
695 * AddMRUData [COMCTL32.167]
697 * Add item to MRU binary list. If item already exists in list then it is
698 * simply moved up to the top of the list and not added again. If list is
699 * full then the least recently used item is removed to make room.
702 * hList [I] Handle to list.
703 * lpData [I] ptr to data to add.
704 * cbData [I] no. of bytes of data.
707 * No. corresponding to registry name where value is stored 'a' -> 0 etc.
711 AddMRUData (HANDLE hList
, LPCVOID lpData
, DWORD cbData
)
713 LPWINEMRULIST mp
= (LPWINEMRULIST
)hList
;
717 if ((replace
= FindMRUData (hList
, lpData
, cbData
, NULL
)) < 0) {
718 /* either add a new entry or replace oldest */
719 if (mp
->cursize
< mp
->extview
.nMaxItems
) {
720 /* Add in a new item */
721 replace
= mp
->cursize
;
725 /* get the oldest entry and replace data */
726 replace
= mp
->realMRU
[mp
->cursize
- 1] - 'a';
727 Free(mp
->array
[replace
]);
731 /* free up the old data */
732 Free(mp
->array
[replace
]);
735 /* Allocate space for new item and move in the data */
736 mp
->array
[replace
] = witem
= Alloc(cbData
+ sizeof(WINEMRUITEM
));
737 witem
->itemFlag
|= WMRUIF_CHANGED
;
738 witem
->size
= cbData
;
739 memcpy( &witem
->datastart
, lpData
, cbData
);
741 /* now rotate MRU list */
742 mp
->wineFlags
|= WMRUF_CHANGED
;
743 for(i
=mp
->cursize
-1; i
>=1; i
--) {
744 mp
->realMRU
[i
] = mp
->realMRU
[i
-1];
746 mp
->realMRU
[0] = replace
+ 'a';
747 TRACE("(%p, %p, %ld) adding data, /%c/ now most current\n",
748 hList
, lpData
, cbData
, replace
+'a');
751 if (!(mp
->extview
.dwFlags
& MRUF_DELAYED_SAVE
)) {
752 /* save changed stuff right now */
753 MRU_SaveChanged( mp
);
759 /**************************************************************************
760 * AddMRUStringW [COMCTL32.401]
762 * Add item to MRU string list. If item already exists in list them it is
763 * simply moved up to the top of the list and not added again. If list is
764 * full then the least recently used item is removed to make room.
767 * hList [I] Handle to list.
768 * lpszString [I] ptr to string to add.
771 * No. corresponding to registry name where value is stored 'a' -> 0 etc.
775 AddMRUStringW(HANDLE hList
, LPCWSTR lpszString
)
777 FIXME("(%p, %s) empty stub!\n", hList
, debugstr_w(lpszString
));
782 /**************************************************************************
783 * AddMRUStringA [COMCTL32.153]
788 AddMRUStringA(HANDLE hList
, LPCSTR lpszString
)
790 FIXME("(%p, %s) empty stub!\n", hList
, debugstr_a(lpszString
));
795 /**************************************************************************
796 * DelMRUString [COMCTL32.156]
798 * Removes item from either string or binary list (despite its name)
801 * hList [I] list handle
802 * nItemPos [I] item position to remove 0 -> MRU
805 * TRUE if successful, FALSE if nItemPos is out of range.
808 DelMRUString(HANDLE hList
, INT nItemPos
)
810 FIXME("(%p, %d): stub\n", hList
, nItemPos
);
814 /**************************************************************************
815 * FindMRUStringW [COMCTL32.402]
817 * See FindMRUStringA.
820 FindMRUStringW (HANDLE hList
, LPCWSTR lpszString
, LPINT lpRegNum
)
826 /**************************************************************************
827 * FindMRUStringA [COMCTL32.155]
829 * Searches string list for item that matches lpszString.
830 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
831 * corresponding to item's reg. name will be stored in it ('a' -> 0).
834 * hList [I] list handle
835 * lpszString [I] string to find
836 * lpRegNum [O] position in registry (maybe NULL)
839 * Position in list 0 -> MRU. -1 if item not found.
842 FindMRUStringA (HANDLE hList
, LPCSTR lpszString
, LPINT lpRegNum
)
844 DWORD len
= MultiByteToWideChar(CP_ACP
, 0, lpszString
, -1, NULL
, 0);
845 LPWSTR stringW
= Alloc(len
* sizeof(WCHAR
));
848 MultiByteToWideChar(CP_ACP
, 0, lpszString
, -1, stringW
, len
);
849 ret
= FindMRUData(hList
, stringW
, len
* sizeof(WCHAR
), lpRegNum
);
854 /*************************************************************************
855 * CreateMRUListLazy_common (internal)
857 HANDLE
CreateMRUListLazy_common(LPWINEMRULIST mp
)
861 DWORD datasize
, dwdisp
;
865 static const WCHAR emptyW
[] = {'\0'};
867 /* get space to save indices that will turn into names
868 * but in order of most to least recently used
870 mp
->realMRU
= Alloc(mp
->extview
.nMaxItems
+ 2);
872 /* get space to save pointers to actual data in order of
873 * 'a' to 'z' (0 to n).
875 mp
->array
= Alloc(mp
->extview
.nMaxItems
* sizeof(LPVOID
));
877 /* open the sub key */
878 if ((err
= RegCreateKeyExW( mp
->extview
.hKey
, mp
->extview
.lpszSubKey
,
881 REG_OPTION_NON_VOLATILE
,
882 KEY_READ
| KEY_WRITE
,
886 /* error - what to do ??? */
887 ERR("(%lu %lu %lx %lx \"%s\" %p): Can not open key, error=%d\n",
888 mp
->extview
.cbSize
, mp
->extview
.nMaxItems
, mp
->extview
.dwFlags
,
889 (DWORD
)mp
->extview
.hKey
, debugstr_w(mp
->extview
.lpszSubKey
),
890 mp
->extview
.lpfnCompare
, err
);
894 /* get values from key 'MRUList' */
896 datasize
= mp
->extview
.nMaxItems
+ 1;
897 if((err
=RegQueryValueExA( newkey
, "MRUList", 0, &type
, mp
->realMRU
,
899 /* not present - set size to 1 (will become 0 later) */
904 TRACE("MRU list = %s\n", mp
->realMRU
);
906 mp
->cursize
= datasize
- 1;
907 /* datasize now has number of items in the MRUList */
909 /* get actual values for each entry */
911 for(i
=0; i
<mp
->cursize
; i
++) {
912 realname
[0] = 'a' + i
;
913 if(RegQueryValueExW( newkey
, realname
, 0, &type
, 0, &datasize
)) {
914 /* not present - what to do ??? */
915 ERR("Key %s not found 1\n", debugstr_w(realname
));
917 mp
->array
[i
] = witem
= Alloc(datasize
+ sizeof(WINEMRUITEM
));
918 witem
->size
= datasize
;
919 if(RegQueryValueExW( newkey
, realname
, 0, &type
,
920 &witem
->datastart
, &datasize
)) {
921 /* not present - what to do ??? */
922 ERR("Key %s not found 2\n", debugstr_w(realname
));
925 RegCloseKey( newkey
);
930 TRACE("(%lu %lu %lx %lx \"%s\" %p): Current Size = %ld\n",
931 mp
->extview
.cbSize
, mp
->extview
.nMaxItems
, mp
->extview
.dwFlags
,
932 (DWORD
)mp
->extview
.hKey
, debugstr_w(mp
->extview
.lpszSubKey
),
933 mp
->extview
.lpfnCompare
, mp
->cursize
);
937 /**************************************************************************
938 * CreateMRUListLazyW [COMCTL32.404]
940 * See CreateMRUListLazyA.
943 CreateMRUListLazyW (LPCREATEMRULISTW lpcml
, DWORD dwParam2
, DWORD dwParam3
, DWORD dwParam4
)
950 if (lpcml
->cbSize
< sizeof(CREATEMRULISTW
))
953 mp
= Alloc(sizeof(WINEMRULIST
));
954 memcpy(&mp
->extview
, lpcml
, sizeof(CREATEMRULISTW
));
955 mp
->extview
.lpszSubKey
= Alloc((strlenW(lpcml
->lpszSubKey
) + 1) * sizeof(WCHAR
));
956 strcpyW((LPWSTR
)mp
->extview
.lpszSubKey
, lpcml
->lpszSubKey
);
957 mp
->isUnicode
= TRUE
;
959 return CreateMRUListLazy_common(mp
);
962 /**************************************************************************
963 * CreateMRUListLazyA [COMCTL32.157]
965 * Creates a most-recently-used list.
968 * lpcml [I] ptr to CREATEMRULIST structure.
969 * dwParam2 [I] Unknown
970 * dwParam3 [I] Unknown
971 * dwParam4 [I] Unknown
974 * Handle to MRU list.
977 CreateMRUListLazyA (LPCREATEMRULISTA lpcml
, DWORD dwParam2
, DWORD dwParam3
, DWORD dwParam4
)
985 if (lpcml
->cbSize
< sizeof(CREATEMRULISTA
))
988 mp
= Alloc(sizeof(WINEMRULIST
));
989 memcpy(&mp
->extview
, lpcml
, sizeof(CREATEMRULISTW
));
990 len
= MultiByteToWideChar(CP_ACP
, 0, lpcml
->lpszSubKey
, -1, NULL
, 0);
991 mp
->extview
.lpszSubKey
= Alloc(len
* sizeof(WCHAR
));
992 MultiByteToWideChar(CP_ACP
, 0, lpcml
->lpszSubKey
, -1,
993 (LPWSTR
)mp
->extview
.lpszSubKey
, len
);
994 mp
->isUnicode
= FALSE
;
995 return CreateMRUListLazy_common(mp
);
998 /**************************************************************************
999 * CreateMRUListW [COMCTL32.400]
1001 * See CreateMRUListA.
1004 CreateMRUListW (LPCREATEMRULISTW lpcml
)
1006 return CreateMRUListLazyW(lpcml
, 0, 0, 0);
1009 /**************************************************************************
1010 * CreateMRUListA [COMCTL32.151]
1012 * Creates a most-recently-used list.
1015 * lpcml [I] ptr to CREATEMRULIST structure.
1018 * Handle to MRU list.
1021 CreateMRUListA (LPCREATEMRULISTA lpcml
)
1023 return CreateMRUListLazyA (lpcml
, 0, 0, 0);
1027 /**************************************************************************
1028 * EnumMRUListW [COMCTL32.403]
1030 * Enumerate item in a most-recenty-used list
1033 * hList [I] list handle
1034 * nItemPos [I] item position to enumerate
1035 * lpBuffer [O] buffer to receive item
1036 * nBufferSize [I] size of buffer
1039 * For binary lists specifies how many bytes were copied to buffer, for
1040 * string lists specifies full length of string. Enumerating past the end
1041 * of list returns -1.
1042 * If lpBuffer == NULL or nItemPos is -ve return value is no. of items in
1045 INT WINAPI
EnumMRUListW(HANDLE hList
, INT nItemPos
, LPVOID lpBuffer
,
1048 LPWINEMRULIST mp
= (LPWINEMRULIST
) hList
;
1049 LPWINEMRUITEM witem
;
1050 INT desired
, datasize
;
1052 if (nItemPos
>= mp
->cursize
) return -1;
1053 if ((nItemPos
< 0) || !lpBuffer
) return mp
->cursize
;
1054 desired
= mp
->realMRU
[nItemPos
];
1056 TRACE("nItemPos=%d, desired=%d\n", nItemPos
, desired
);
1057 witem
= mp
->array
[desired
];
1058 datasize
= min( witem
->size
, nBufferSize
);
1059 memcpy( lpBuffer
, &witem
->datastart
, datasize
);
1060 TRACE("(%p, %d, %p, %ld): returning len=%d\n",
1061 hList
, nItemPos
, lpBuffer
, nBufferSize
, datasize
);
1065 /**************************************************************************
1066 * EnumMRUListA [COMCTL32.154]
1070 INT WINAPI
EnumMRUListA(HANDLE hList
, INT nItemPos
, LPVOID lpBuffer
,
1073 LPWINEMRULIST mp
= (LPWINEMRULIST
) hList
;
1074 LPWINEMRUITEM witem
;
1075 INT desired
, datasize
;
1078 if (nItemPos
>= mp
->cursize
) return -1;
1079 if ((nItemPos
< 0) || !lpBuffer
) return mp
->cursize
;
1080 desired
= mp
->realMRU
[nItemPos
];
1082 TRACE("nItemPos=%d, desired=%d\n", nItemPos
, desired
);
1083 witem
= mp
->array
[desired
];
1084 if(mp
->extview
.dwFlags
& MRUF_BINARY_LIST
) {
1085 datasize
= min( witem
->size
, nBufferSize
);
1086 memcpy( lpBuffer
, &witem
->datastart
, datasize
);
1088 lenA
= WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&witem
->datastart
, -1,
1089 NULL
, 0, NULL
, NULL
);
1090 datasize
= min( witem
->size
, nBufferSize
);
1091 WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&witem
->datastart
, -1,
1092 lpBuffer
, datasize
, NULL
, NULL
);
1094 TRACE("(%p, %d, %p, %ld): returning len=%d\n",
1095 hList
, nItemPos
, lpBuffer
, nBufferSize
, datasize
);
1100 /**************************************************************************
1101 * Str_GetPtrA [COMCTL32.233]
1103 * Copies a string into a destination buffer.
1106 * lpSrc [I] Source string
1107 * lpDest [O] Destination buffer
1108 * nMaxLen [I] Size of buffer in characters
1111 * The number of characters copied.
1115 Str_GetPtrA (LPCSTR lpSrc
, LPSTR lpDest
, INT nMaxLen
)
1119 TRACE("(%p %p %d)\n", lpSrc
, lpDest
, nMaxLen
);
1121 if (!lpDest
&& lpSrc
)
1122 return strlen (lpSrc
);
1127 if (lpSrc
== NULL
) {
1132 len
= strlen (lpSrc
);
1136 RtlMoveMemory (lpDest
, lpSrc
, len
);
1143 /**************************************************************************
1144 * Str_SetPtrA [COMCTL32.234]
1146 * Makes a copy of a string, allocating memory if necessary.
1149 * lppDest [O] Pointer to destination string
1150 * lpSrc [I] Source string
1157 * Set lpSrc to NULL to free the memory allocated by a previous call
1162 Str_SetPtrA (LPSTR
*lppDest
, LPCSTR lpSrc
)
1164 TRACE("(%p %p)\n", lppDest
, lpSrc
);
1167 LPSTR ptr
= ReAlloc (*lppDest
, strlen (lpSrc
) + 1);
1170 strcpy (ptr
, lpSrc
);
1184 /**************************************************************************
1185 * Str_GetPtrW [COMCTL32.235]
1191 Str_GetPtrW (LPCWSTR lpSrc
, LPWSTR lpDest
, INT nMaxLen
)
1195 TRACE("(%p %p %d)\n", lpSrc
, lpDest
, nMaxLen
);
1197 if (!lpDest
&& lpSrc
)
1198 return strlenW (lpSrc
);
1203 if (lpSrc
== NULL
) {
1208 len
= strlenW (lpSrc
);
1212 RtlMoveMemory (lpDest
, lpSrc
, len
*sizeof(WCHAR
));
1213 lpDest
[len
] = L
'\0';
1219 /**************************************************************************
1220 * Str_SetPtrW [COMCTL32.236]
1226 Str_SetPtrW (LPWSTR
*lppDest
, LPCWSTR lpSrc
)
1228 TRACE("(%p %p)\n", lppDest
, lpSrc
);
1231 INT len
= strlenW (lpSrc
) + 1;
1232 LPWSTR ptr
= ReAlloc (*lppDest
, len
* sizeof(WCHAR
));
1235 strcpyW (ptr
, lpSrc
);
1249 /**************************************************************************
1250 * Str_GetPtrWtoA [internal]
1252 * Converts a unicode string into a multi byte string
1255 * lpSrc [I] Pointer to the unicode source string
1256 * lpDest [O] Pointer to caller supplied storage for the multi byte string
1257 * nMaxLen [I] Size, in bytes, of the destination buffer
1260 * Length, in bytes, of the converted string.
1264 Str_GetPtrWtoA (LPCWSTR lpSrc
, LPSTR lpDest
, INT nMaxLen
)
1268 TRACE("(%s %p %d)\n", debugstr_w(lpSrc
), lpDest
, nMaxLen
);
1270 if (!lpDest
&& lpSrc
)
1271 return WideCharToMultiByte(CP_ACP
, 0, lpSrc
, -1, 0, 0, NULL
, NULL
);
1276 if (lpSrc
== NULL
) {
1281 len
= WideCharToMultiByte(CP_ACP
, 0, lpSrc
, -1, 0, 0, NULL
, NULL
);
1285 WideCharToMultiByte(CP_ACP
, 0, lpSrc
, -1, lpDest
, len
, NULL
, NULL
);
1292 /**************************************************************************
1293 * Str_SetPtrAtoW [internal]
1295 * Converts a multi byte string to a unicode string.
1296 * If the pointer to the destination buffer is NULL a buffer is allocated.
1297 * If the destination buffer is too small to keep the converted multi byte
1298 * string the destination buffer is reallocated. If the source pointer is
1299 * NULL, the destination buffer is freed.
1302 * lppDest [I/O] pointer to a pointer to the destination buffer
1303 * lpSrc [I] pointer to a multi byte string
1306 * TRUE: conversion successful
1311 Str_SetPtrAtoW (LPWSTR
*lppDest
, LPCSTR lpSrc
)
1313 TRACE("(%p %s)\n", lppDest
, lpSrc
);
1316 INT len
= MultiByteToWideChar(CP_ACP
,0,lpSrc
,-1,NULL
,0);
1317 LPWSTR ptr
= ReAlloc (*lppDest
, len
*sizeof(WCHAR
));
1321 MultiByteToWideChar(CP_ACP
,0,lpSrc
,-1,ptr
,len
);
1335 /**************************************************************************
1336 * DSA_Create [COMCTL32.320]
1338 * Creates a dynamic storage array
1341 * nSize [I] size of the array elements
1342 * nGrow [I] number of elements by which the array grows when it is filled
1345 * Success: pointer to an array control structure. Use this like a handle.
1349 * The DSA_ functions can be used to create and manipulate arrays of
1350 * fixed-size memory blocks. These arrays can store any kind of data
1351 * (e.g. strings and icons).
1355 DSA_Create (INT nSize
, INT nGrow
)
1359 TRACE("(size=%d grow=%d)\n", nSize
, nGrow
);
1361 hdsa
= Alloc (sizeof(*hdsa
));
1364 hdsa
->nItemCount
= 0;
1366 hdsa
->nMaxCount
= 0;
1367 hdsa
->nItemSize
= nSize
;
1368 hdsa
->nGrow
= max(1, nGrow
);
1375 /**************************************************************************
1376 * DSA_Destroy [COMCTL32.321]
1378 * Destroys a dynamic storage array
1381 * hdsa [I] pointer to the array control structure
1389 DSA_Destroy (const HDSA hdsa
)
1391 TRACE("(%p)\n", hdsa
);
1396 if (hdsa
->pData
&& (!Free (hdsa
->pData
)))
1403 /**************************************************************************
1404 * DSA_GetItem [COMCTL32.322]
1406 * Copies the specified item into a caller-supplied buffer.
1409 * hdsa [I] pointer to the array control structure
1410 * nIndex [I] number of the Item to get
1411 * pDest [O] destination buffer. Has to be >= dwElementSize.
1419 DSA_GetItem (const HDSA hdsa
, INT nIndex
, LPVOID pDest
)
1423 TRACE("(%p %d %p)\n", hdsa
, nIndex
, pDest
);
1427 if ((nIndex
< 0) || (nIndex
>= hdsa
->nItemCount
))
1430 pSrc
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1431 memmove (pDest
, pSrc
, hdsa
->nItemSize
);
1437 /**************************************************************************
1438 * DSA_GetItemPtr [COMCTL32.323]
1440 * Retrieves a pointer to the specified item.
1443 * hdsa [I] pointer to the array control structure
1444 * nIndex [I] index of the desired item
1447 * Success: pointer to an item
1452 DSA_GetItemPtr (const HDSA hdsa
, INT nIndex
)
1456 TRACE("(%p %d)\n", hdsa
, nIndex
);
1460 if ((nIndex
< 0) || (nIndex
>= hdsa
->nItemCount
))
1463 pSrc
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1465 TRACE("-- ret=%p\n", pSrc
);
1471 /**************************************************************************
1472 * DSA_SetItem [COMCTL32.325]
1474 * Sets the contents of an item in the array.
1477 * hdsa [I] pointer to the array control structure
1478 * nIndex [I] index for the item
1479 * pSrc [I] pointer to the new item data
1487 DSA_SetItem (const HDSA hdsa
, INT nIndex
, LPVOID pSrc
)
1489 INT nSize
, nNewItems
;
1490 LPVOID pDest
, lpTemp
;
1492 TRACE("(%p %d %p)\n", hdsa
, nIndex
, pSrc
);
1494 if ((!hdsa
) || nIndex
< 0)
1497 if (hdsa
->nItemCount
<= nIndex
) {
1498 /* within the old array */
1499 if (hdsa
->nMaxCount
> nIndex
) {
1500 /* within the allocated space, set a new boundary */
1501 hdsa
->nItemCount
= nIndex
+ 1;
1504 /* resize the block of memory */
1506 hdsa
->nGrow
* ((INT
)(((nIndex
+ 1) - 1) / hdsa
->nGrow
) + 1);
1507 nSize
= hdsa
->nItemSize
* nNewItems
;
1509 lpTemp
= ReAlloc (hdsa
->pData
, nSize
);
1513 hdsa
->nMaxCount
= nNewItems
;
1514 hdsa
->nItemCount
= nIndex
+ 1;
1515 hdsa
->pData
= lpTemp
;
1519 /* put the new entry in */
1520 pDest
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1521 TRACE("-- move dest=%p src=%p size=%d\n",
1522 pDest
, pSrc
, hdsa
->nItemSize
);
1523 memmove (pDest
, pSrc
, hdsa
->nItemSize
);
1529 /**************************************************************************
1530 * DSA_InsertItem [COMCTL32.324]
1532 * Inserts an item into the array at the specified index.
1535 * hdsa [I] pointer to the array control structure
1536 * nIndex [I] index for the new item
1537 * pSrc [I] pointer to the element
1540 * Success: position of the new item
1545 DSA_InsertItem (const HDSA hdsa
, INT nIndex
, LPVOID pSrc
)
1547 INT nNewItems
, nSize
;
1548 LPVOID lpTemp
, lpDest
;
1550 TRACE("(%p %d %p)\n", hdsa
, nIndex
, pSrc
);
1552 if ((!hdsa
) || nIndex
< 0)
1555 /* when nIndex >= nItemCount then append */
1556 if (nIndex
>= hdsa
->nItemCount
)
1557 nIndex
= hdsa
->nItemCount
;
1559 /* do we need to resize ? */
1560 if (hdsa
->nItemCount
>= hdsa
->nMaxCount
) {
1561 nNewItems
= hdsa
->nMaxCount
+ hdsa
->nGrow
;
1562 nSize
= hdsa
->nItemSize
* nNewItems
;
1564 lpTemp
= ReAlloc (hdsa
->pData
, nSize
);
1568 hdsa
->nMaxCount
= nNewItems
;
1569 hdsa
->pData
= lpTemp
;
1572 /* do we need to move elements ? */
1573 if (nIndex
< hdsa
->nItemCount
) {
1574 lpTemp
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1575 lpDest
= (char *) lpTemp
+ hdsa
->nItemSize
;
1576 nSize
= (hdsa
->nItemCount
- nIndex
) * hdsa
->nItemSize
;
1577 TRACE("-- move dest=%p src=%p size=%d\n",
1578 lpDest
, lpTemp
, nSize
);
1579 memmove (lpDest
, lpTemp
, nSize
);
1582 /* ok, we can put the new Item in */
1584 lpDest
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1585 TRACE("-- move dest=%p src=%p size=%d\n",
1586 lpDest
, pSrc
, hdsa
->nItemSize
);
1587 memmove (lpDest
, pSrc
, hdsa
->nItemSize
);
1593 /**************************************************************************
1594 * DSA_DeleteItem [COMCTL32.326]
1596 * Deletes the specified item from the array.
1599 * hdsa [I] pointer to the array control structure
1600 * nIndex [I] index for the element to delete
1603 * Success: number of the deleted element
1608 DSA_DeleteItem (const HDSA hdsa
, INT nIndex
)
1610 LPVOID lpDest
,lpSrc
;
1613 TRACE("(%p %d)\n", hdsa
, nIndex
);
1617 if (nIndex
< 0 || nIndex
>= hdsa
->nItemCount
)
1620 /* do we need to move ? */
1621 if (nIndex
< hdsa
->nItemCount
- 1) {
1622 lpDest
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1623 lpSrc
= (char *) lpDest
+ hdsa
->nItemSize
;
1624 nSize
= hdsa
->nItemSize
* (hdsa
->nItemCount
- nIndex
- 1);
1625 TRACE("-- move dest=%p src=%p size=%d\n",
1626 lpDest
, lpSrc
, nSize
);
1627 memmove (lpDest
, lpSrc
, nSize
);
1633 if ((hdsa
->nMaxCount
- hdsa
->nItemCount
) >= hdsa
->nGrow
) {
1634 nSize
= hdsa
->nItemSize
* hdsa
->nItemCount
;
1636 lpDest
= ReAlloc (hdsa
->pData
, nSize
);
1640 hdsa
->nMaxCount
= hdsa
->nItemCount
;
1641 hdsa
->pData
= lpDest
;
1648 /**************************************************************************
1649 * DSA_DeleteAllItems [COMCTL32.327]
1651 * Removes all items and reinitializes the array.
1654 * hdsa [I] pointer to the array control structure
1662 DSA_DeleteAllItems (const HDSA hdsa
)
1664 TRACE("(%p)\n", hdsa
);
1668 if (hdsa
->pData
&& (!Free (hdsa
->pData
)))
1671 hdsa
->nItemCount
= 0;
1673 hdsa
->nMaxCount
= 0;
1679 /**************************************************************************
1680 * DPA_Destroy [COMCTL32.329]
1682 * 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.
2232 * The DPA_ functions can be used to create and manipulate arrays of
2237 DPA_CreateEx (INT nGrow
, HANDLE hHeap
)
2241 TRACE("(%d %p)\n", nGrow
, hHeap
);
2244 hdpa
= (HDPA
)HeapAlloc (hHeap
, HEAP_ZERO_MEMORY
, sizeof(*hdpa
));
2246 hdpa
= Alloc (sizeof(*hdpa
));
2249 hdpa
->nGrow
= max(8, nGrow
);
2250 hdpa
->hHeap
= hHeap
? hHeap
: GetProcessHeap();
2251 hdpa
->nMaxCount
= hdpa
->nGrow
* 2;
2252 hdpa
->ptrs
= HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
2253 hdpa
->nMaxCount
* sizeof(LPVOID
));
2256 TRACE("-- %p\n", hdpa
);
2262 /**************************************************************************
2263 * DPA_Create [COMCTL32.328]
2265 * Creates a dynamic pointer array.
2268 * nGrow [I] number of items by which the array grows when it is filled
2271 * Success: handle (pointer) to the pointer array.
2275 * The DPA_ functions can be used to create and manipulate arrays of
2280 DPA_Create (INT nGrow
)
2282 return DPA_CreateEx( nGrow
, 0 );
2286 /**************************************************************************
2287 * Notification functions
2290 typedef struct tagNOTIFYDATA
2298 } NOTIFYDATA
, *LPNOTIFYDATA
;
2301 /**************************************************************************
2302 * DoNotify [Internal]
2306 DoNotify (LPNOTIFYDATA lpNotify
, UINT uCode
, LPNMHDR lpHdr
)
2309 LPNMHDR lpNmh
= NULL
;
2312 TRACE("(%p %p %d %p 0x%08lx)\n",
2313 lpNotify
->hwndFrom
, lpNotify
->hwndTo
, uCode
, lpHdr
,
2314 lpNotify
->dwParam5
);
2316 if (!lpNotify
->hwndTo
)
2319 if (lpNotify
->hwndFrom
== (HWND
)-1) {
2321 idFrom
= lpHdr
->idFrom
;
2324 if (lpNotify
->hwndFrom
)
2325 idFrom
= GetDlgCtrlID (lpNotify
->hwndFrom
);
2327 lpNmh
= (lpHdr
) ? lpHdr
: &nmhdr
;
2329 lpNmh
->hwndFrom
= lpNotify
->hwndFrom
;
2330 lpNmh
->idFrom
= idFrom
;
2331 lpNmh
->code
= uCode
;
2334 return SendMessageA (lpNotify
->hwndTo
, WM_NOTIFY
, idFrom
, (LPARAM
)lpNmh
);
2338 /**************************************************************************
2339 * SendNotify [COMCTL32.341]
2341 * Sends a WM_NOTIFY message to the specified window.
2344 * hwndTo [I] Window to receive the message
2345 * hwndFrom [I] Window that the message is from (see notes)
2346 * uCode [I] Notification code
2347 * lpHdr [I] The NMHDR and any additional information to send or NULL
2350 * Success: return value from notification
2354 * If hwndFrom is -1 then the identifier of the control sending the
2355 * message is taken from the NMHDR structure.
2356 * If hwndFrom is not -1 then lpHdr can be NULL.
2359 LRESULT WINAPI
SendNotify (HWND hwndTo
, HWND hwndFrom
, UINT uCode
, LPNMHDR lpHdr
)
2363 TRACE("(%p %p %d %p)\n",
2364 hwndTo
, hwndFrom
, uCode
, lpHdr
);
2366 notify
.hwndFrom
= hwndFrom
;
2367 notify
.hwndTo
= hwndTo
;
2368 notify
.dwParam5
= 0;
2369 notify
.dwParam6
= 0;
2371 return DoNotify (¬ify
, uCode
, lpHdr
);
2375 /**************************************************************************
2376 * SendNotifyEx [COMCTL32.342]
2378 * Sends a WM_NOTIFY message to the specified window.
2381 * hwndFrom [I] Window to receive the message
2382 * hwndTo [I] Window that the message is from
2383 * uCode [I] Notification code
2384 * lpHdr [I] The NMHDR and any additional information to send or NULL
2385 * dwParam5 [I] Unknown
2388 * Success: return value from notification
2392 * If hwndFrom is -1 then the identifier of the control sending the
2393 * message is taken from the NMHDR structure.
2394 * If hwndFrom is not -1 then lpHdr can be NULL.
2397 LRESULT WINAPI
SendNotifyEx (HWND hwndTo
, HWND hwndFrom
, UINT uCode
,
2398 LPNMHDR lpHdr
, DWORD dwParam5
)
2403 TRACE("(%p %p %d %p 0x%08lx)\n",
2404 hwndFrom
, hwndTo
, uCode
, lpHdr
, dwParam5
);
2406 hwndNotify
= hwndTo
;
2408 if (IsWindow (hwndFrom
)) {
2409 hwndNotify
= GetParent (hwndFrom
);
2415 notify
.hwndFrom
= hwndFrom
;
2416 notify
.hwndTo
= hwndNotify
;
2417 notify
.dwParam5
= dwParam5
;
2418 notify
.dwParam6
= 0;
2420 return DoNotify (¬ify
, uCode
, lpHdr
);
2426 /**************************************************************************
2427 * DPA_EnumCallback [COMCTL32.385]
2429 * Enumerates all items in a dynamic pointer array.
2432 * hdpa [I] handle to the dynamic pointer array
2441 DPA_EnumCallback (HDPA hdpa
, PFNDPAENUMCALLBACK enumProc
, LPVOID lParam
)
2445 TRACE("(%p %p %p)\n", hdpa
, enumProc
, lParam
);
2449 if (hdpa
->nItemCount
<= 0)
2452 for (i
= 0; i
< hdpa
->nItemCount
; i
++) {
2453 if ((enumProc
)(hdpa
->ptrs
[i
], lParam
) == 0)
2461 /**************************************************************************
2462 * DPA_DestroyCallback [COMCTL32.386]
2464 * Enumerates all items in a dynamic pointer array and destroys it.
2467 * hdpa [I] handle to the dynamic pointer array
2476 DPA_DestroyCallback (HDPA hdpa
, PFNDPAENUMCALLBACK enumProc
, LPVOID lParam
)
2478 TRACE("(%p %p %p)\n", hdpa
, enumProc
, lParam
);
2480 DPA_EnumCallback (hdpa
, enumProc
, lParam
);
2485 /**************************************************************************
2486 * DSA_EnumCallback [COMCTL32.387]
2488 * Enumerates all items in a dynamic storage array.
2491 * hdsa [I] handle to the dynamic storage array
2500 DSA_EnumCallback (HDSA hdsa
, PFNDSAENUMCALLBACK enumProc
, LPVOID lParam
)
2504 TRACE("(%p %p %p)\n", hdsa
, enumProc
, lParam
);
2508 if (hdsa
->nItemCount
<= 0)
2511 for (i
= 0; i
< hdsa
->nItemCount
; i
++) {
2512 LPVOID lpItem
= DSA_GetItemPtr (hdsa
, i
);
2513 if ((enumProc
)(lpItem
, lParam
) == 0)
2521 /**************************************************************************
2522 * DSA_DestroyCallback [COMCTL32.388]
2524 * Enumerates all items in a dynamic storage array and destroys it.
2527 * hdsa [I] handle to the dynamic storage array
2536 DSA_DestroyCallback (HDSA hdsa
, PFNDSAENUMCALLBACK enumProc
, LPVOID lParam
)
2538 TRACE("(%p %p %p)\n", hdsa
, enumProc
, lParam
);
2540 DSA_EnumCallback (hdsa
, enumProc
, lParam
);