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"
37 #define NONAMELESSUNION
38 #define NONAMELESSSTRUCT
49 #include "wine/unicode.h"
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(commctrl
);
74 typedef struct _STREAMDATA
79 } STREAMDATA
, *PSTREAMDATA
;
81 typedef struct _LOADDATA
85 } LOADDATA
, *LPLOADDATA
;
87 typedef HRESULT (CALLBACK
*DPALOADPROC
)(LPLOADDATA
,IStream
*,LPARAM
);
89 /**************************************************************************
90 * DPA_LoadStream [COMCTL32.9]
92 * Loads a dynamic pointer array from a stream
95 * phDpa [O] pointer to a handle to a dynamic pointer array
96 * loadProc [I] pointer to a callback function
97 * pStream [I] pointer to a stream
98 * lParam [I] application specific value
105 * No more information available yet!
109 DPA_LoadStream (HDPA
*phDpa
, DPALOADPROC loadProc
, IStream
*pStream
, LPARAM lParam
)
112 LARGE_INTEGER position
;
113 ULARGE_INTEGER newPosition
;
114 STREAMDATA streamData
;
120 FIXME ("phDpa=%p loadProc=%p pStream=%p lParam=%lx\n",
121 phDpa
, loadProc
, pStream
, lParam
);
123 if (!phDpa
|| !loadProc
|| !pStream
)
128 position
.QuadPart
= 0;
131 * Zero out our streamData
133 memset(&streamData
,0,sizeof(STREAMDATA
));
135 errCode
= IStream_Seek (pStream
, position
, STREAM_SEEK_CUR
, &newPosition
);
139 errCode
= IStream_Read (pStream
, &streamData
, sizeof(STREAMDATA
), &ulRead
);
143 FIXME ("dwSize=%lu dwData2=%lu dwItems=%lu\n",
144 streamData
.dwSize
, streamData
.dwData2
, streamData
.dwItems
);
146 if ( ulRead
< sizeof(STREAMDATA
) ||
147 lParam
< sizeof(STREAMDATA
) ||
148 streamData
.dwSize
< sizeof(STREAMDATA
) ||
149 streamData
.dwData2
< 1) {
153 if (streamData
.dwItems
> (UINT_MAX
/ 2 / sizeof(VOID
*))) /* 536870911 */
154 return E_OUTOFMEMORY
;
157 hDpa
= DPA_Create (streamData
.dwItems
);
159 return E_OUTOFMEMORY
;
161 if (!DPA_Grow (hDpa
, streamData
.dwItems
))
162 return E_OUTOFMEMORY
;
164 /* load data from the stream into the dpa */
166 for (loadData
.nCount
= 0; loadData
.nCount
< streamData
.dwItems
; loadData
.nCount
++) {
167 errCode
= (loadProc
)(&loadData
, pStream
, lParam
);
168 if (errCode
!= S_OK
) {
177 /* set the number of items */
178 hDpa
->nItemCount
= loadData
.nCount
;
180 /* store the handle to the dpa */
182 FIXME ("new hDpa=%p, errorcode=%lx\n", hDpa
, errCode
);
188 /**************************************************************************
189 * DPA_SaveStream [COMCTL32.10]
191 * Saves a dynamic pointer array to a stream
194 * hDpa [I] handle to a dynamic pointer array
195 * loadProc [I] pointer to a callback function
196 * pStream [I] pointer to a stream
197 * 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
234 * No more information available yet!
238 DPA_Merge (const HDPA hdpa1
, const HDPA hdpa2
, DWORD dwFlags
,
239 PFNDPACOMPARE pfnCompare
, PFNDPAMERGE pfnMerge
, LPARAM lParam
)
242 LPVOID
*pWork1
, *pWork2
;
246 TRACE("%p %p %08lx %p %p %08lx)\n",
247 hdpa1
, hdpa2
, dwFlags
, pfnCompare
, pfnMerge
, lParam
);
249 if (IsBadWritePtr (hdpa1
, sizeof(*hdpa1
)))
252 if (IsBadWritePtr (hdpa2
, sizeof(*hdpa2
)))
255 if (IsBadCodePtr ((FARPROC
)pfnCompare
))
258 if (IsBadCodePtr ((FARPROC
)pfnMerge
))
261 if (!(dwFlags
& DPAM_NOSORT
)) {
262 TRACE("sorting dpa's!\n");
263 if (hdpa1
->nItemCount
> 0)
264 DPA_Sort (hdpa1
, pfnCompare
, lParam
);
265 TRACE ("dpa 1 sorted!\n");
266 if (hdpa2
->nItemCount
> 0)
267 DPA_Sort (hdpa2
, pfnCompare
, lParam
);
268 TRACE ("dpa 2 sorted!\n");
271 if (hdpa2
->nItemCount
< 1)
274 TRACE("hdpa1->nItemCount=%d hdpa2->nItemCount=%d\n",
275 hdpa1
->nItemCount
, hdpa2
->nItemCount
);
278 /* working but untrusted implementation */
280 pWork1
= &(hdpa1
->ptrs
[hdpa1
->nItemCount
- 1]);
281 pWork2
= &(hdpa2
->ptrs
[hdpa2
->nItemCount
- 1]);
283 nIndex
= hdpa1
->nItemCount
- 1;
284 nCount
= hdpa2
->nItemCount
- 1;
289 if ((nCount
>= 0) && (dwFlags
& DPAM_INSERT
)) {
290 /* Now insert the remaining new items into DPA 1 */
291 TRACE("%d items to be inserted at start of DPA 1\n",
293 for (i
=nCount
; i
>=0; i
--) {
296 ptr
= (pfnMerge
)(3, *pWork2
, NULL
, lParam
);
299 DPA_InsertPtr (hdpa1
, 0, ptr
);
305 nResult
= (pfnCompare
)(*pWork1
, *pWork2
, lParam
);
306 TRACE("compare result=%d, dpa1.cnt=%d, dpa2.cnt=%d\n",
307 nResult
, nIndex
, nCount
);
313 ptr
= (pfnMerge
)(1, *pWork1
, *pWork2
, lParam
);
323 else if (nResult
> 0)
325 /* item in DPA 1 missing from DPA 2 */
326 if (dwFlags
& DPAM_DELETE
)
328 /* Now delete the extra item in DPA1 */
331 ptr
= DPA_DeletePtr (hdpa1
, hdpa1
->nItemCount
- 1);
333 (pfnMerge
)(2, ptr
, NULL
, lParam
);
340 /* new item in DPA 2 */
341 if (dwFlags
& DPAM_INSERT
)
343 /* Now insert the new item in DPA 1 */
346 ptr
= (pfnMerge
)(3, *pWork2
, NULL
, lParam
);
349 DPA_InsertPtr (hdpa1
, nIndex
+1, ptr
);
362 /**************************************************************************
363 * Alloc [COMCTL32.71]
365 * Allocates memory block from the dll's private heap
368 * dwSize [I] size of the allocated memory block
371 * Success: pointer to allocated memory block
375 LPVOID WINAPI
Alloc (DWORD dwSize
)
377 return LocalAlloc( LMEM_ZEROINIT
, dwSize
);
381 /**************************************************************************
382 * ReAlloc [COMCTL32.72]
384 * Changes the size of an allocated memory block or allocates a memory
385 * block using the dll's private heap.
388 * lpSrc [I] pointer to memory block which will be resized
389 * dwSize [I] new size of the memory block.
392 * Success: pointer to the resized memory block
396 * If lpSrc is a NULL-pointer, then ReAlloc allocates a memory
400 LPVOID WINAPI
ReAlloc (LPVOID lpSrc
, DWORD dwSize
)
403 return LocalReAlloc( lpSrc
, dwSize
, LMEM_ZEROINIT
);
405 return LocalAlloc( LMEM_ZEROINIT
, dwSize
);
409 /**************************************************************************
412 * Frees an allocated memory block from the dll's private heap.
415 * lpMem [I] pointer to memory block which will be freed
422 BOOL WINAPI
Free (LPVOID lpMem
)
424 return !LocalFree( lpMem
);
428 /**************************************************************************
429 * GetSize [COMCTL32.74]
431 * Retrieves the size of the specified memory block from the dll's
435 * lpMem [I] pointer to an allocated memory block
438 * Success: size of the specified memory block
442 DWORD WINAPI
GetSize (LPVOID lpMem
)
444 return LocalSize( lpMem
);
448 /**************************************************************************
449 * The MRU-API is a set of functions to manipulate MRU(Most Recently Used)
452 * Stored in the reg. as a set of values under a single key. Each item in the
453 * list has a value name that is a single char. 'a' - 'z', '{', '|' or '}'.
454 * The order of the list is stored with value name 'MRUList' which is a string
455 * containing the value names (i.e. 'a', 'b', etc.) in the relevant order.
458 typedef struct tagCREATEMRULISTA
460 DWORD cbSize
; /* size of struct */
461 DWORD nMaxItems
; /* max no. of items in list */
462 DWORD dwFlags
; /* see below */
463 HKEY hKey
; /* root reg. key under which list is saved */
464 LPCSTR lpszSubKey
; /* reg. subkey */
465 PROC lpfnCompare
; /* item compare proc */
466 } CREATEMRULISTA
, *LPCREATEMRULISTA
;
468 typedef struct tagCREATEMRULISTW
470 DWORD cbSize
; /* size of struct */
471 DWORD nMaxItems
; /* max no. of items in list */
472 DWORD dwFlags
; /* see below */
473 HKEY hKey
; /* root reg. key under which list is saved */
474 LPCWSTR lpszSubKey
; /* reg. subkey */
475 PROC lpfnCompare
; /* item compare proc */
476 } CREATEMRULISTW
, *LPCREATEMRULISTW
;
479 #define MRUF_STRING_LIST 0 /* list will contain strings */
480 #define MRUF_BINARY_LIST 1 /* list will contain binary data */
481 #define MRUF_DELAYED_SAVE 2 /* only save list order to reg. is FreeMRUList */
483 /* If list is a string list lpfnCompare has the following prototype
484 * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
485 * for binary lists the prototype is
486 * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
487 * where cbData is the no. of bytes to compare.
488 * Need to check what return value means identical - 0?
491 typedef struct tagWINEMRUITEM
493 DWORD size
; /* size of data stored */
494 DWORD itemFlag
; /* flags */
496 } WINEMRUITEM
, *LPWINEMRUITEM
;
499 #define WMRUIF_CHANGED 0x0001 /* this dataitem changed */
501 typedef struct tagWINEMRULIST
503 CREATEMRULISTW extview
; /* original create information */
504 BOOL isUnicode
; /* is compare fn Unicode */
505 DWORD wineFlags
; /* internal flags */
506 DWORD cursize
; /* current size of realMRU */
507 LPSTR realMRU
; /* pointer to string of index names */
508 LPWINEMRUITEM
*array
; /* array of pointers to data */
509 /* in 'a' to 'z' order */
510 } WINEMRULIST
, *LPWINEMRULIST
;
513 #define WMRUF_CHANGED 0x0001 /* MRU list has changed */
515 /**************************************************************************
516 * MRU_SaveChanged (internal)
518 * Localize MRU saving code
520 VOID
MRU_SaveChanged( LPWINEMRULIST mp
)
526 WCHAR emptyW
[] = {'\0'};
528 /* or should we do the following instead of RegOpenKeyEx:
531 /* open the sub key */
532 if ((err
= RegOpenKeyExW( mp
->extview
.hKey
, mp
->extview
.lpszSubKey
,
533 0, KEY_WRITE
, &newkey
))) {
534 /* not present - what to do ??? */
535 ERR("Can not open key, error=%d, attempting to create\n",
537 if ((err
= RegCreateKeyExW( mp
->extview
.hKey
, mp
->extview
.lpszSubKey
,
540 REG_OPTION_NON_VOLATILE
,
541 KEY_READ
| KEY_WRITE
,
545 ERR("failed to create key /%s/, err=%d\n",
546 debugstr_w(mp
->extview
.lpszSubKey
), err
);
550 if (mp
->wineFlags
& WMRUF_CHANGED
) {
551 mp
->wineFlags
&= ~WMRUF_CHANGED
;
552 err
= RegSetValueExA(newkey
, "MRUList", 0, REG_SZ
,
553 mp
->realMRU
, strlen(mp
->realMRU
) + 1);
555 ERR("error saving MRUList, err=%d\n", err
);
557 TRACE("saving MRUList=/%s/\n", mp
->realMRU
);
560 for(i
=0; i
<mp
->cursize
; i
++) {
561 witem
= mp
->array
[i
];
562 if (witem
->itemFlag
& WMRUIF_CHANGED
) {
563 witem
->itemFlag
&= ~WMRUIF_CHANGED
;
564 realname
[0] = 'a' + i
;
565 err
= RegSetValueExW(newkey
, realname
, 0,
566 (mp
->extview
.dwFlags
& MRUF_BINARY_LIST
) ?
568 &witem
->datastart
, witem
->size
);
570 ERR("error saving /%s/, err=%d\n", debugstr_w(realname
), err
);
572 TRACE("saving value for name /%s/ size=%ld\n",
573 debugstr_w(realname
), witem
->size
);
576 RegCloseKey( newkey
);
579 /**************************************************************************
580 * FreeMRUList [COMCTL32.152]
582 * Frees a most-recently-used items list.
585 * hMRUList [I] Handle to list.
592 FreeMRUList (HANDLE hMRUList
)
594 LPWINEMRULIST mp
= (LPWINEMRULIST
)hMRUList
;
598 if (mp
->wineFlags
& WMRUF_CHANGED
) {
599 /* need to open key and then save the info */
600 MRU_SaveChanged( mp
);
603 for(i
=0; i
<mp
->extview
.nMaxItems
; i
++) {
609 Free((LPWSTR
)mp
->extview
.lpszSubKey
);
614 /**************************************************************************
615 * FindMRUData [COMCTL32.169]
617 * Searches binary list for item that matches lpData of length cbData.
618 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
619 * corresponding to item's reg. name will be stored in it ('a' -> 0).
622 * hList [I] list handle
623 * lpData [I] data to find
624 * cbData [I] length of data
625 * lpRegNum [O] position in registry (maybe NULL)
628 * Position in list 0 -> MRU. -1 if item not found.
631 FindMRUData (HANDLE hList
, LPCVOID lpData
, DWORD cbData
, LPINT lpRegNum
)
633 LPWINEMRULIST mp
= (LPWINEMRULIST
)hList
;
637 if (!mp
->extview
.lpfnCompare
) {
638 ERR("MRU list not properly created. No compare procedure.\n");
642 if(!(mp
->extview
.dwFlags
& MRUF_BINARY_LIST
) && !mp
->isUnicode
) {
643 DWORD len
= WideCharToMultiByte(CP_ACP
, 0, lpData
, -1,
644 NULL
, 0, NULL
, NULL
);
646 WideCharToMultiByte(CP_ACP
, 0, lpData
, -1, dataA
, len
, NULL
, NULL
);
649 for(i
=0; i
<mp
->cursize
; i
++) {
650 if (mp
->extview
.dwFlags
& MRUF_BINARY_LIST
) {
651 if (!mp
->extview
.lpfnCompare(lpData
, &mp
->array
[i
]->datastart
,
657 if (!mp
->extview
.lpfnCompare(lpData
, &mp
->array
[i
]->datastart
))
660 DWORD len
= WideCharToMultiByte(CP_ACP
, 0,
661 (LPWSTR
)&mp
->array
[i
]->datastart
, -1,
662 NULL
, 0, NULL
, NULL
);
663 LPSTR itemA
= Alloc(len
);
665 WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&mp
->array
[i
]->datastart
, -1,
666 itemA
, len
, NULL
, NULL
);
668 cmp
= mp
->extview
.lpfnCompare(dataA
, itemA
);
681 if (lpRegNum
&& (ret
!= -1))
684 TRACE("(%p, %p, %ld, %p) returning %d\n",
685 hList
, lpData
, cbData
, lpRegNum
, ret
);
691 /**************************************************************************
692 * AddMRUData [COMCTL32.167]
694 * Add item to MRU binary list. If item already exists in list then it is
695 * simply moved up to the top of the list and not added again. If list is
696 * full then the least recently used item is removed to make room.
699 * hList [I] Handle to list.
700 * lpData [I] ptr to data to add.
701 * cbData [I] no. of bytes of data.
704 * No. corresponding to registry name where value is stored 'a' -> 0 etc.
708 AddMRUData (HANDLE hList
, LPCVOID lpData
, DWORD cbData
)
710 LPWINEMRULIST mp
= (LPWINEMRULIST
)hList
;
714 if ((replace
= FindMRUData (hList
, lpData
, cbData
, NULL
)) < 0) {
715 /* either add a new entry or replace oldest */
716 if (mp
->cursize
< mp
->extview
.nMaxItems
) {
717 /* Add in a new item */
718 replace
= mp
->cursize
;
722 /* get the oldest entry and replace data */
723 replace
= mp
->realMRU
[mp
->cursize
- 1] - 'a';
724 Free(mp
->array
[replace
]);
728 /* free up the old data */
729 Free(mp
->array
[replace
]);
732 /* Allocate space for new item and move in the data */
733 mp
->array
[replace
] = witem
= Alloc(cbData
+ sizeof(WINEMRUITEM
));
734 witem
->itemFlag
|= WMRUIF_CHANGED
;
735 witem
->size
= cbData
;
736 memcpy( &witem
->datastart
, lpData
, cbData
);
738 /* now rotate MRU list */
739 mp
->wineFlags
|= WMRUF_CHANGED
;
740 for(i
=mp
->cursize
-1; i
>=1; i
--) {
741 mp
->realMRU
[i
] = mp
->realMRU
[i
-1];
743 mp
->realMRU
[0] = replace
+ 'a';
744 TRACE("(%p, %p, %ld) adding data, /%c/ now most current\n",
745 hList
, lpData
, cbData
, replace
+'a');
748 if (!(mp
->extview
.dwFlags
& MRUF_DELAYED_SAVE
)) {
749 /* save changed stuff right now */
750 MRU_SaveChanged( mp
);
756 /**************************************************************************
757 * AddMRUStringW [COMCTL32.401]
759 * Add item to MRU string list. If item already exists in list them it is
760 * simply moved up to the top of the list and not added again. If list is
761 * full then the least recently used item is removed to make room.
764 * hList [I] Handle to list.
765 * lpszString [I] ptr to string to add.
768 * No. corresponding to registry name where value is stored 'a' -> 0 etc.
772 AddMRUStringW(HANDLE hList
, LPCWSTR lpszString
)
774 FIXME("(%p, %s) empty stub!\n", hList
, debugstr_w(lpszString
));
779 /**************************************************************************
780 * AddMRUStringA [COMCTL32.153]
785 AddMRUStringA(HANDLE hList
, LPCSTR lpszString
)
787 FIXME("(%p, %s) empty stub!\n", hList
, debugstr_a(lpszString
));
792 /**************************************************************************
793 * DelMRUString [COMCTL32.156]
795 * Removes item from either string or binary list (despite its name)
798 * hList [I] list handle
799 * nItemPos [I] item position to remove 0 -> MRU
802 * TRUE if successful, FALSE if nItemPos is out of range.
805 DelMRUString(HANDLE hList
, INT nItemPos
)
807 FIXME("(%p, %d): stub\n", hList
, nItemPos
);
811 /**************************************************************************
812 * FindMRUStringW [COMCTL32.402]
814 * See FindMRUStringA.
817 FindMRUStringW (HANDLE hList
, LPCWSTR lpszString
, LPINT lpRegNum
)
823 /**************************************************************************
824 * FindMRUStringA [COMCTL32.155]
826 * Searches string list for item that matches lpszString.
827 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
828 * corresponding to item's reg. name will be stored in it ('a' -> 0).
831 * hList [I] list handle
832 * lpszString [I] string to find
833 * lpRegNum [O] position in registry (maybe NULL)
836 * Position in list 0 -> MRU. -1 if item not found.
839 FindMRUStringA (HANDLE hList
, LPCSTR lpszString
, LPINT lpRegNum
)
841 DWORD len
= MultiByteToWideChar(CP_ACP
, 0, lpszString
, -1, NULL
, 0);
842 LPWSTR stringW
= Alloc(len
* sizeof(WCHAR
));
845 MultiByteToWideChar(CP_ACP
, 0, lpszString
, -1, stringW
, len
);
846 ret
= FindMRUData(hList
, stringW
, len
* sizeof(WCHAR
), lpRegNum
);
851 /*************************************************************************
852 * CreateMRUListLazy_common (internal)
854 HANDLE
CreateMRUListLazy_common(LPWINEMRULIST mp
)
858 DWORD datasize
, dwdisp
;
862 WCHAR emptyW
[] = {'\0'};
864 /* get space to save indices that will turn into names
865 * but in order of most to least recently used
867 mp
->realMRU
= Alloc(mp
->extview
.nMaxItems
+ 2);
869 /* get space to save pointers to actual data in order of
870 * 'a' to 'z' (0 to n).
872 mp
->array
= Alloc(mp
->extview
.nMaxItems
* sizeof(LPVOID
));
874 /* open the sub key */
875 if ((err
= RegCreateKeyExW( mp
->extview
.hKey
, mp
->extview
.lpszSubKey
,
878 REG_OPTION_NON_VOLATILE
,
879 KEY_READ
| KEY_WRITE
,
883 /* error - what to do ??? */
884 ERR("(%lu %lu %lx %lx \"%s\" %p): Can not open key, error=%d\n",
885 mp
->extview
.cbSize
, mp
->extview
.nMaxItems
, mp
->extview
.dwFlags
,
886 (DWORD
)mp
->extview
.hKey
, debugstr_w(mp
->extview
.lpszSubKey
),
887 mp
->extview
.lpfnCompare
, err
);
891 /* get values from key 'MRUList' */
893 datasize
= mp
->extview
.nMaxItems
+ 1;
894 if((err
=RegQueryValueExA( newkey
, "MRUList", 0, &type
, mp
->realMRU
,
896 /* not present - set size to 1 (will become 0 later) */
901 TRACE("MRU list = %s\n", mp
->realMRU
);
903 mp
->cursize
= datasize
- 1;
904 /* datasize now has number of items in the MRUList */
906 /* get actual values for each entry */
908 for(i
=0; i
<mp
->cursize
; i
++) {
909 realname
[0] = 'a' + i
;
910 if(RegQueryValueExW( newkey
, realname
, 0, &type
, 0, &datasize
)) {
911 /* not present - what to do ??? */
912 ERR("Key %s not found 1\n", debugstr_w(realname
));
914 mp
->array
[i
] = witem
= Alloc(datasize
+ sizeof(WINEMRUITEM
));
915 witem
->size
= datasize
;
916 if(RegQueryValueExW( newkey
, realname
, 0, &type
,
917 &witem
->datastart
, &datasize
)) {
918 /* not present - what to do ??? */
919 ERR("Key %s not found 2\n", debugstr_w(realname
));
922 RegCloseKey( newkey
);
927 TRACE("(%lu %lu %lx %lx \"%s\" %p): Current Size = %ld\n",
928 mp
->extview
.cbSize
, mp
->extview
.nMaxItems
, mp
->extview
.dwFlags
,
929 (DWORD
)mp
->extview
.hKey
, debugstr_w(mp
->extview
.lpszSubKey
),
930 mp
->extview
.lpfnCompare
, mp
->cursize
);
934 /**************************************************************************
935 * CreateMRUListLazyW [COMCTL32.404]
937 * See CreateMRUListLazyA.
940 CreateMRUListLazyW (LPCREATEMRULISTW lpcml
, DWORD dwParam2
, DWORD dwParam3
, DWORD dwParam4
)
947 if (lpcml
->cbSize
< sizeof(CREATEMRULISTW
))
950 mp
= Alloc(sizeof(WINEMRULIST
));
951 memcpy(&mp
->extview
, lpcml
, sizeof(CREATEMRULISTW
));
952 mp
->extview
.lpszSubKey
= Alloc((strlenW(lpcml
->lpszSubKey
) + 1) * sizeof(WCHAR
));
953 strcpyW((LPWSTR
)mp
->extview
.lpszSubKey
, lpcml
->lpszSubKey
);
954 mp
->isUnicode
= TRUE
;
956 return CreateMRUListLazy_common(mp
);
959 /**************************************************************************
960 * CreateMRUListLazyA [COMCTL32.157]
962 * Creates a most-recently-used list.
965 * lpcml [I] ptr to CREATEMRULIST structure.
966 * dwParam2 [I] Unknown
967 * dwParam3 [I] Unknown
968 * dwParam4 [I] Unknown
971 * Handle to MRU list.
974 CreateMRUListLazyA (LPCREATEMRULISTA lpcml
, DWORD dwParam2
, DWORD dwParam3
, DWORD dwParam4
)
982 if (lpcml
->cbSize
< sizeof(CREATEMRULISTA
))
985 mp
= Alloc(sizeof(WINEMRULIST
));
986 memcpy(&mp
->extview
, lpcml
, sizeof(CREATEMRULISTW
));
987 len
= MultiByteToWideChar(CP_ACP
, 0, lpcml
->lpszSubKey
, -1, NULL
, 0);
988 mp
->extview
.lpszSubKey
= Alloc(len
* sizeof(WCHAR
));
989 MultiByteToWideChar(CP_ACP
, 0, lpcml
->lpszSubKey
, -1,
990 (LPWSTR
)mp
->extview
.lpszSubKey
, len
);
991 mp
->isUnicode
= FALSE
;
992 return CreateMRUListLazy_common(mp
);
995 /**************************************************************************
996 * CreateMRUListW [COMCTL32.400]
998 * See CreateMRUListA.
1001 CreateMRUListW (LPCREATEMRULISTW lpcml
)
1003 return CreateMRUListLazyW(lpcml
, 0, 0, 0);
1006 /**************************************************************************
1007 * CreateMRUListA [COMCTL32.151]
1009 * Creates a most-recently-used list.
1012 * lpcml [I] ptr to CREATEMRULIST structure.
1015 * Handle to MRU list.
1018 CreateMRUListA (LPCREATEMRULISTA lpcml
)
1020 return CreateMRUListLazyA (lpcml
, 0, 0, 0);
1024 /**************************************************************************
1025 * EnumMRUListW [COMCTL32.403]
1027 * Enumerate item in a most-recenty-used list
1030 * hList [I] list handle
1031 * nItemPos [I] item position to enumerate
1032 * lpBuffer [O] buffer to receive item
1033 * nBufferSize [I] size of buffer
1036 * For binary lists specifies how many bytes were copied to buffer, for
1037 * string lists specifies full length of string. Enumerating past the end
1038 * of list returns -1.
1039 * If lpBuffer == NULL or nItemPos is -ve return value is no. of items in
1042 INT WINAPI
EnumMRUListW(HANDLE hList
, INT nItemPos
, LPVOID lpBuffer
,
1045 LPWINEMRULIST mp
= (LPWINEMRULIST
) hList
;
1046 LPWINEMRUITEM witem
;
1047 INT desired
, datasize
;
1049 if (nItemPos
>= mp
->cursize
) return -1;
1050 if ((nItemPos
< 0) || !lpBuffer
) return mp
->cursize
;
1051 desired
= mp
->realMRU
[nItemPos
];
1053 TRACE("nItemPos=%d, desired=%d\n", nItemPos
, desired
);
1054 witem
= mp
->array
[desired
];
1055 datasize
= min( witem
->size
, nBufferSize
);
1056 memcpy( lpBuffer
, &witem
->datastart
, datasize
);
1057 TRACE("(%p, %d, %p, %ld): returning len=%d\n",
1058 hList
, nItemPos
, lpBuffer
, nBufferSize
, datasize
);
1062 /**************************************************************************
1063 * EnumMRUListA [COMCTL32.154]
1067 INT WINAPI
EnumMRUListA(HANDLE hList
, INT nItemPos
, LPVOID lpBuffer
,
1070 LPWINEMRULIST mp
= (LPWINEMRULIST
) hList
;
1071 LPWINEMRUITEM witem
;
1072 INT desired
, datasize
;
1075 if (nItemPos
>= mp
->cursize
) return -1;
1076 if ((nItemPos
< 0) || !lpBuffer
) return mp
->cursize
;
1077 desired
= mp
->realMRU
[nItemPos
];
1079 TRACE("nItemPos=%d, desired=%d\n", nItemPos
, desired
);
1080 witem
= mp
->array
[desired
];
1081 if(mp
->extview
.dwFlags
& MRUF_BINARY_LIST
) {
1082 datasize
= min( witem
->size
, nBufferSize
);
1083 memcpy( lpBuffer
, &witem
->datastart
, datasize
);
1085 lenA
= WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&witem
->datastart
, -1,
1086 NULL
, 0, NULL
, NULL
);
1087 datasize
= min( witem
->size
, nBufferSize
);
1088 WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&witem
->datastart
, -1,
1089 lpBuffer
, datasize
, NULL
, NULL
);
1091 TRACE("(%p, %d, %p, %ld): returning len=%d\n",
1092 hList
, nItemPos
, lpBuffer
, nBufferSize
, datasize
);
1097 /**************************************************************************
1098 * Str_GetPtrA [COMCTL32.233]
1100 * Copies a string into a destination buffer.
1103 * lpSrc [I] Source string
1104 * lpDest [O] Destination buffer
1105 * nMaxLen [I] Size of buffer in characters
1108 * The number of characters copied.
1112 Str_GetPtrA (LPCSTR lpSrc
, LPSTR lpDest
, INT nMaxLen
)
1116 TRACE("(%p %p %d)\n", lpSrc
, lpDest
, nMaxLen
);
1118 if (!lpDest
&& lpSrc
)
1119 return strlen (lpSrc
);
1124 if (lpSrc
== NULL
) {
1129 len
= strlen (lpSrc
);
1133 RtlMoveMemory (lpDest
, lpSrc
, len
);
1140 /**************************************************************************
1141 * Str_SetPtrA [COMCTL32.234]
1143 * Makes a copy of a string, allocating memory if necessary.
1146 * lppDest [O] Pointer to destination string
1147 * lpSrc [I] Source string
1154 * Set lpSrc to NULL to free the memory allocated by a previous call
1159 Str_SetPtrA (LPSTR
*lppDest
, LPCSTR lpSrc
)
1161 TRACE("(%p %p)\n", lppDest
, lpSrc
);
1164 LPSTR ptr
= ReAlloc (*lppDest
, strlen (lpSrc
) + 1);
1167 strcpy (ptr
, lpSrc
);
1181 /**************************************************************************
1182 * Str_GetPtrW [COMCTL32.235]
1188 Str_GetPtrW (LPCWSTR lpSrc
, LPWSTR lpDest
, INT nMaxLen
)
1192 TRACE("(%p %p %d)\n", lpSrc
, lpDest
, nMaxLen
);
1194 if (!lpDest
&& lpSrc
)
1195 return strlenW (lpSrc
);
1200 if (lpSrc
== NULL
) {
1205 len
= strlenW (lpSrc
);
1209 RtlMoveMemory (lpDest
, lpSrc
, len
*sizeof(WCHAR
));
1210 lpDest
[len
] = L
'\0';
1216 /**************************************************************************
1217 * Str_SetPtrW [COMCTL32.236]
1223 Str_SetPtrW (LPWSTR
*lppDest
, LPCWSTR lpSrc
)
1225 TRACE("(%p %p)\n", lppDest
, lpSrc
);
1228 INT len
= strlenW (lpSrc
) + 1;
1229 LPWSTR ptr
= ReAlloc (*lppDest
, len
* sizeof(WCHAR
));
1232 strcpyW (ptr
, lpSrc
);
1246 /**************************************************************************
1247 * Str_GetPtrWtoA [internal]
1249 * Converts a unicode string into a multi byte string
1252 * lpSrc [I] Pointer to the unicode source string
1253 * lpDest [O] Pointer to caller supplied storage for the multi byte string
1254 * nMaxLen [I] Size, in bytes, of the destination buffer
1257 * Length, in bytes, of the converted string.
1261 Str_GetPtrWtoA (LPCWSTR lpSrc
, LPSTR lpDest
, INT nMaxLen
)
1265 TRACE("(%s %p %d)\n", debugstr_w(lpSrc
), lpDest
, nMaxLen
);
1267 if (!lpDest
&& lpSrc
)
1268 return WideCharToMultiByte(CP_ACP
, 0, lpSrc
, -1, 0, 0, NULL
, NULL
);
1273 if (lpSrc
== NULL
) {
1278 len
= WideCharToMultiByte(CP_ACP
, 0, lpSrc
, -1, 0, 0, NULL
, NULL
);
1282 WideCharToMultiByte(CP_ACP
, 0, lpSrc
, -1, lpDest
, len
, NULL
, NULL
);
1289 /**************************************************************************
1290 * Str_SetPtrAtoW [internal]
1292 * Converts a multi byte string to a unicode string.
1293 * If the pointer to the destination buffer is NULL a buffer is allocated.
1294 * If the destination buffer is too small to keep the converted multi byte
1295 * string the destination buffer is reallocated. If the source pointer is
1296 * NULL, the destination buffer is freed.
1299 * lppDest [I/O] pointer to a pointer to the destination buffer
1300 * lpSrc [I] pointer to a multi byte string
1303 * TRUE: conversion successful
1308 Str_SetPtrAtoW (LPWSTR
*lppDest
, LPCSTR lpSrc
)
1310 TRACE("(%p %s)\n", lppDest
, lpSrc
);
1313 INT len
= MultiByteToWideChar(CP_ACP
,0,lpSrc
,-1,NULL
,0);
1314 LPWSTR ptr
= ReAlloc (*lppDest
, len
*sizeof(WCHAR
));
1318 MultiByteToWideChar(CP_ACP
,0,lpSrc
,-1,ptr
,len
);
1332 /**************************************************************************
1333 * DSA_Create [COMCTL32.320]
1335 * Creates a dynamic storage array
1338 * nSize [I] size of the array elements
1339 * nGrow [I] number of elements by which the array grows when it is filled
1342 * Success: pointer to an array control structure. Use this like a handle.
1346 * The DSA_ functions can be used to create and manipulate arrays of
1347 * fixed-size memory blocks. These arrays can store any kind of data
1348 * (e.g. strings and icons).
1352 DSA_Create (INT nSize
, INT nGrow
)
1356 TRACE("(size=%d grow=%d)\n", nSize
, nGrow
);
1358 hdsa
= Alloc (sizeof(*hdsa
));
1361 hdsa
->nItemCount
= 0;
1363 hdsa
->nMaxCount
= 0;
1364 hdsa
->nItemSize
= nSize
;
1365 hdsa
->nGrow
= max(1, nGrow
);
1372 /**************************************************************************
1373 * DSA_Destroy [COMCTL32.321]
1375 * Destroys a dynamic storage array
1378 * hdsa [I] pointer to the array control structure
1386 DSA_Destroy (const HDSA hdsa
)
1388 TRACE("(%p)\n", hdsa
);
1393 if (hdsa
->pData
&& (!Free (hdsa
->pData
)))
1400 /**************************************************************************
1401 * DSA_GetItem [COMCTL32.322]
1403 * Copies the specified item into a caller-supplied buffer.
1406 * hdsa [I] pointer to the array control structure
1407 * nIndex [I] number of the Item to get
1408 * pDest [O] destination buffer. Has to be >= dwElementSize.
1416 DSA_GetItem (const HDSA hdsa
, INT nIndex
, LPVOID pDest
)
1420 TRACE("(%p %d %p)\n", hdsa
, nIndex
, pDest
);
1424 if ((nIndex
< 0) || (nIndex
>= hdsa
->nItemCount
))
1427 pSrc
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1428 memmove (pDest
, pSrc
, hdsa
->nItemSize
);
1434 /**************************************************************************
1435 * DSA_GetItemPtr [COMCTL32.323]
1437 * Retrieves a pointer to the specified item.
1440 * hdsa [I] pointer to the array control structure
1441 * nIndex [I] index of the desired item
1444 * Success: pointer to an item
1449 DSA_GetItemPtr (const HDSA hdsa
, INT nIndex
)
1453 TRACE("(%p %d)\n", hdsa
, nIndex
);
1457 if ((nIndex
< 0) || (nIndex
>= hdsa
->nItemCount
))
1460 pSrc
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1462 TRACE("-- ret=%p\n", pSrc
);
1468 /**************************************************************************
1469 * DSA_SetItem [COMCTL32.325]
1471 * Sets the contents of an item in the array.
1474 * hdsa [I] pointer to the array control structure
1475 * nIndex [I] index for the item
1476 * pSrc [I] pointer to the new item data
1484 DSA_SetItem (const HDSA hdsa
, INT nIndex
, LPVOID pSrc
)
1486 INT nSize
, nNewItems
;
1487 LPVOID pDest
, lpTemp
;
1489 TRACE("(%p %d %p)\n", hdsa
, nIndex
, pSrc
);
1491 if ((!hdsa
) || nIndex
< 0)
1494 if (hdsa
->nItemCount
<= nIndex
) {
1495 /* within the old array */
1496 if (hdsa
->nMaxCount
> nIndex
) {
1497 /* within the allocated space, set a new boundary */
1498 hdsa
->nItemCount
= nIndex
+ 1;
1501 /* resize the block of memory */
1503 hdsa
->nGrow
* ((INT
)(((nIndex
+ 1) - 1) / hdsa
->nGrow
) + 1);
1504 nSize
= hdsa
->nItemSize
* nNewItems
;
1506 lpTemp
= ReAlloc (hdsa
->pData
, nSize
);
1510 hdsa
->nMaxCount
= nNewItems
;
1511 hdsa
->nItemCount
= nIndex
+ 1;
1512 hdsa
->pData
= lpTemp
;
1516 /* put the new entry in */
1517 pDest
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1518 TRACE("-- move dest=%p src=%p size=%d\n",
1519 pDest
, pSrc
, hdsa
->nItemSize
);
1520 memmove (pDest
, pSrc
, hdsa
->nItemSize
);
1526 /**************************************************************************
1527 * DSA_InsertItem [COMCTL32.324]
1529 * Inserts an item into the array at the specified index.
1532 * hdsa [I] pointer to the array control structure
1533 * nIndex [I] index for the new item
1534 * pSrc [I] pointer to the element
1537 * Success: position of the new item
1542 DSA_InsertItem (const HDSA hdsa
, INT nIndex
, LPVOID pSrc
)
1544 INT nNewItems
, nSize
;
1545 LPVOID lpTemp
, lpDest
;
1547 TRACE("(%p %d %p)\n", hdsa
, nIndex
, pSrc
);
1549 if ((!hdsa
) || nIndex
< 0)
1552 /* when nIndex >= nItemCount then append */
1553 if (nIndex
>= hdsa
->nItemCount
)
1554 nIndex
= hdsa
->nItemCount
;
1556 /* do we need to resize ? */
1557 if (hdsa
->nItemCount
>= hdsa
->nMaxCount
) {
1558 nNewItems
= hdsa
->nMaxCount
+ hdsa
->nGrow
;
1559 nSize
= hdsa
->nItemSize
* nNewItems
;
1561 lpTemp
= ReAlloc (hdsa
->pData
, nSize
);
1565 hdsa
->nMaxCount
= nNewItems
;
1566 hdsa
->pData
= lpTemp
;
1569 /* do we need to move elements ? */
1570 if (nIndex
< hdsa
->nItemCount
) {
1571 lpTemp
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1572 lpDest
= (char *) lpTemp
+ hdsa
->nItemSize
;
1573 nSize
= (hdsa
->nItemCount
- nIndex
) * hdsa
->nItemSize
;
1574 TRACE("-- move dest=%p src=%p size=%d\n",
1575 lpDest
, lpTemp
, nSize
);
1576 memmove (lpDest
, lpTemp
, nSize
);
1579 /* ok, we can put the new Item in */
1581 lpDest
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1582 TRACE("-- move dest=%p src=%p size=%d\n",
1583 lpDest
, pSrc
, hdsa
->nItemSize
);
1584 memmove (lpDest
, pSrc
, hdsa
->nItemSize
);
1590 /**************************************************************************
1591 * DSA_DeleteItem [COMCTL32.326]
1593 * Deletes the specified item from the array.
1596 * hdsa [I] pointer to the array control structure
1597 * nIndex [I] index for the element to delete
1600 * Success: number of the deleted element
1605 DSA_DeleteItem (const HDSA hdsa
, INT nIndex
)
1607 LPVOID lpDest
,lpSrc
;
1610 TRACE("(%p %d)\n", hdsa
, nIndex
);
1614 if (nIndex
< 0 || nIndex
>= hdsa
->nItemCount
)
1617 /* do we need to move ? */
1618 if (nIndex
< hdsa
->nItemCount
- 1) {
1619 lpDest
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1620 lpSrc
= (char *) lpDest
+ hdsa
->nItemSize
;
1621 nSize
= hdsa
->nItemSize
* (hdsa
->nItemCount
- nIndex
- 1);
1622 TRACE("-- move dest=%p src=%p size=%d\n",
1623 lpDest
, lpSrc
, nSize
);
1624 memmove (lpDest
, lpSrc
, nSize
);
1630 if ((hdsa
->nMaxCount
- hdsa
->nItemCount
) >= hdsa
->nGrow
) {
1631 nSize
= hdsa
->nItemSize
* hdsa
->nItemCount
;
1633 lpDest
= ReAlloc (hdsa
->pData
, nSize
);
1637 hdsa
->nMaxCount
= hdsa
->nItemCount
;
1638 hdsa
->pData
= lpDest
;
1645 /**************************************************************************
1646 * DSA_DeleteAllItems [COMCTL32.327]
1648 * Removes all items and reinitializes the array.
1651 * hdsa [I] pointer to the array control structure
1659 DSA_DeleteAllItems (const HDSA hdsa
)
1661 TRACE("(%p)\n", hdsa
);
1665 if (hdsa
->pData
&& (!Free (hdsa
->pData
)))
1668 hdsa
->nItemCount
= 0;
1670 hdsa
->nMaxCount
= 0;
1676 /**************************************************************************
1677 * DPA_Destroy [COMCTL32.329]
1679 * Destroys a dynamic pointer array
1682 * hdpa [I] handle (pointer) to the pointer array
1690 DPA_Destroy (const HDPA hdpa
)
1692 TRACE("(%p)\n", hdpa
);
1697 if (hdpa
->ptrs
&& (!HeapFree (hdpa
->hHeap
, 0, hdpa
->ptrs
)))
1700 return HeapFree (hdpa
->hHeap
, 0, hdpa
);
1704 /**************************************************************************
1705 * DPA_Grow [COMCTL32.330]
1707 * Sets the growth amount.
1710 * hdpa [I] handle (pointer) to the existing (source) pointer array
1711 * nGrow [I] number of items by which the array grows when it's too small
1719 DPA_Grow (const HDPA hdpa
, INT nGrow
)
1721 TRACE("(%p %d)\n", hdpa
, nGrow
);
1726 hdpa
->nGrow
= max(8, nGrow
);
1732 /**************************************************************************
1733 * DPA_Clone [COMCTL32.331]
1735 * Copies a pointer array to an other one or creates a copy
1738 * hdpa [I] handle (pointer) to the existing (source) pointer array
1739 * hdpaNew [O] handle (pointer) to the destination pointer array
1742 * Success: pointer to the destination pointer array.
1746 * - If the 'hdpaNew' is a NULL-Pointer, a copy of the source pointer
1747 * array will be created and it's handle (pointer) is returned.
1748 * - If 'hdpa' is a NULL-Pointer, the original implementation crashes,
1749 * this implementation just returns NULL.
1753 DPA_Clone (const HDPA hdpa
, const HDPA hdpaNew
)
1755 INT nNewItems
, nSize
;
1761 TRACE("(%p %p)\n", hdpa
, hdpaNew
);
1764 /* create a new DPA */
1765 hdpaTemp
= (HDPA
)HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
1767 hdpaTemp
->hHeap
= hdpa
->hHeap
;
1768 hdpaTemp
->nGrow
= hdpa
->nGrow
;
1773 if (hdpaTemp
->ptrs
) {
1774 /* remove old pointer array */
1775 HeapFree (hdpaTemp
->hHeap
, 0, hdpaTemp
->ptrs
);
1776 hdpaTemp
->ptrs
= NULL
;
1777 hdpaTemp
->nItemCount
= 0;
1778 hdpaTemp
->nMaxCount
= 0;
1781 /* create a new pointer array */
1782 nNewItems
= hdpaTemp
->nGrow
*
1783 ((INT
)((hdpa
->nItemCount
- 1) / hdpaTemp
->nGrow
) + 1);
1784 nSize
= nNewItems
* sizeof(LPVOID
);
1786 (LPVOID
*)HeapAlloc (hdpaTemp
->hHeap
, HEAP_ZERO_MEMORY
, nSize
);
1787 hdpaTemp
->nMaxCount
= nNewItems
;
1789 /* clone the pointer array */
1790 hdpaTemp
->nItemCount
= hdpa
->nItemCount
;
1791 memmove (hdpaTemp
->ptrs
, hdpa
->ptrs
,
1792 hdpaTemp
->nItemCount
* sizeof(LPVOID
));
1798 /**************************************************************************
1799 * DPA_GetPtr [COMCTL32.332]
1801 * Retrieves a pointer from a dynamic pointer array
1804 * hdpa [I] handle (pointer) to the pointer array
1805 * nIndex [I] array index of the desired pointer
1813 DPA_GetPtr (const HDPA hdpa
, INT nIndex
)
1815 TRACE("(%p %d)\n", hdpa
, nIndex
);
1820 WARN("no pointer array.\n");
1823 if ((nIndex
< 0) || (nIndex
>= hdpa
->nItemCount
)) {
1824 WARN("not enough pointers in array (%d vs %d).\n",nIndex
,hdpa
->nItemCount
);
1828 TRACE("-- %p\n", hdpa
->ptrs
[nIndex
]);
1830 return hdpa
->ptrs
[nIndex
];
1834 /**************************************************************************
1835 * DPA_GetPtrIndex [COMCTL32.333]
1837 * Retrieves the index of the specified pointer
1840 * hdpa [I] handle (pointer) to the pointer array
1844 * Success: index of the specified pointer
1849 DPA_GetPtrIndex (const HDPA hdpa
, LPVOID p
)
1853 if (!hdpa
|| !hdpa
->ptrs
)
1856 for (i
= 0; i
< hdpa
->nItemCount
; i
++) {
1857 if (hdpa
->ptrs
[i
] == p
)
1865 /**************************************************************************
1866 * DPA_InsertPtr [COMCTL32.334]
1868 * Inserts a pointer into a dynamic pointer array
1871 * hdpa [I] handle (pointer) to the array
1873 * p [I] pointer to insert
1876 * Success: index of the inserted pointer
1881 DPA_InsertPtr (const HDPA hdpa
, INT i
, LPVOID p
)
1883 TRACE("(%p %d %p)\n", hdpa
, i
, p
);
1885 if (!hdpa
|| i
< 0) return -1;
1888 i
= hdpa
->nItemCount
;
1890 if (i
>= hdpa
->nItemCount
)
1891 return DPA_SetPtr(hdpa
, i
, p
) ? i
: -1;
1893 /* create empty spot at the end */
1894 if (!DPA_SetPtr(hdpa
, hdpa
->nItemCount
, 0)) return -1;
1895 memmove (hdpa
->ptrs
+ i
+ 1, hdpa
->ptrs
+ i
, (hdpa
->nItemCount
- i
- 1) * sizeof(LPVOID
));
1900 /**************************************************************************
1901 * DPA_SetPtr [COMCTL32.335]
1903 * Sets a pointer in the pointer array
1906 * hdpa [I] handle (pointer) to the pointer array
1907 * i [I] index of the pointer that will be set
1908 * p [I] pointer to be set
1916 DPA_SetPtr (const HDPA hdpa
, INT i
, LPVOID p
)
1920 TRACE("(%p %d %p)\n", hdpa
, i
, p
);
1922 if (!hdpa
|| i
< 0 || i
> 0x7fff)
1925 if (hdpa
->nItemCount
<= i
) {
1926 /* within the old array */
1927 if (hdpa
->nMaxCount
<= i
) {
1928 /* resize the block of memory */
1930 hdpa
->nGrow
* ((INT
)(((i
+1) - 1) / hdpa
->nGrow
) + 1);
1931 INT nSize
= nNewItems
* sizeof(LPVOID
);
1934 lpTemp
= (LPVOID
*)HeapReAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
, hdpa
->ptrs
, nSize
);
1936 lpTemp
= (LPVOID
*)HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
, nSize
);
1941 hdpa
->nMaxCount
= nNewItems
;
1942 hdpa
->ptrs
= lpTemp
;
1944 hdpa
->nItemCount
= i
+1;
1947 /* put the new entry in */
1954 /**************************************************************************
1955 * DPA_DeletePtr [COMCTL32.336]
1957 * Removes a pointer from the pointer array.
1960 * hdpa [I] handle (pointer) to the pointer array
1961 * i [I] index of the pointer that will be deleted
1964 * Success: deleted pointer
1969 DPA_DeletePtr (const HDPA hdpa
, INT i
)
1971 LPVOID
*lpDest
, *lpSrc
, lpTemp
= NULL
;
1974 TRACE("(%p %d)\n", hdpa
, i
);
1976 if ((!hdpa
) || i
< 0 || i
>= hdpa
->nItemCount
)
1979 lpTemp
= hdpa
->ptrs
[i
];
1981 /* do we need to move ?*/
1982 if (i
< hdpa
->nItemCount
- 1) {
1983 lpDest
= hdpa
->ptrs
+ i
;
1985 nSize
= (hdpa
->nItemCount
- i
- 1) * sizeof(LPVOID
);
1986 TRACE("-- move dest=%p src=%p size=%x\n",
1987 lpDest
, lpSrc
, nSize
);
1988 memmove (lpDest
, lpSrc
, nSize
);
1991 hdpa
->nItemCount
--;
1994 if ((hdpa
->nMaxCount
- hdpa
->nItemCount
) >= hdpa
->nGrow
) {
1995 INT nNewItems
= max(hdpa
->nGrow
* 2, hdpa
->nItemCount
);
1996 nSize
= nNewItems
* sizeof(LPVOID
);
1997 lpDest
= (LPVOID
)HeapReAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
2002 hdpa
->nMaxCount
= nNewItems
;
2003 hdpa
->ptrs
= (LPVOID
*)lpDest
;
2010 /**************************************************************************
2011 * DPA_DeleteAllPtrs [COMCTL32.337]
2013 * Removes all pointers and reinitializes the array.
2016 * hdpa [I] handle (pointer) to the pointer array
2024 DPA_DeleteAllPtrs (const HDPA hdpa
)
2026 TRACE("(%p)\n", hdpa
);
2031 if (hdpa
->ptrs
&& (!HeapFree (hdpa
->hHeap
, 0, hdpa
->ptrs
)))
2034 hdpa
->nItemCount
= 0;
2035 hdpa
->nMaxCount
= hdpa
->nGrow
* 2;
2036 hdpa
->ptrs
= (LPVOID
*)HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
2037 hdpa
->nMaxCount
* sizeof(LPVOID
));
2043 /**************************************************************************
2044 * DPA_QuickSort [Internal]
2046 * Ordinary quicksort (used by DPA_Sort).
2049 * lpPtrs [I] pointer to the pointer array
2050 * l [I] index of the "left border" of the partition
2051 * r [I] index of the "right border" of the partition
2052 * pfnCompare [I] pointer to the compare function
2053 * lParam [I] user defined value (3rd parameter in compare function)
2060 DPA_QuickSort (LPVOID
*lpPtrs
, INT l
, INT r
,
2061 PFNDPACOMPARE pfnCompare
, LPARAM lParam
)
2066 TRACE("l=%i r=%i\n", l
, r
);
2068 if (l
==r
) /* one element is always sorted */
2070 if (r
<l
) /* oops, got it in the wrong order */
2072 DPA_QuickSort(lpPtrs
, r
, l
, pfnCompare
, lParam
);
2075 m
= (l
+r
)/2; /* divide by two */
2076 DPA_QuickSort(lpPtrs
, l
, m
, pfnCompare
, lParam
);
2077 DPA_QuickSort(lpPtrs
, m
+1, r
, pfnCompare
, lParam
);
2079 /* join the two sides */
2080 while( (l
<=m
) && (m
<r
) )
2082 if(pfnCompare(lpPtrs
[l
],lpPtrs
[m
+1],lParam
)>0)
2085 memmove(&lpPtrs
[l
+1],&lpPtrs
[l
],(m
-l
+1)*sizeof(lpPtrs
[l
]));
2095 /**************************************************************************
2096 * DPA_Sort [COMCTL32.338]
2098 * Sorts a pointer array using a user defined compare function
2101 * hdpa [I] handle (pointer) to the pointer array
2102 * pfnCompare [I] pointer to the compare function
2103 * lParam [I] user defined value (3rd parameter of compare function)
2111 DPA_Sort (const HDPA hdpa
, PFNDPACOMPARE pfnCompare
, LPARAM lParam
)
2113 if (!hdpa
|| !pfnCompare
)
2116 TRACE("(%p %p 0x%lx)\n", hdpa
, pfnCompare
, lParam
);
2118 if ((hdpa
->nItemCount
> 1) && (hdpa
->ptrs
))
2119 DPA_QuickSort (hdpa
->ptrs
, 0, hdpa
->nItemCount
- 1,
2120 pfnCompare
, lParam
);
2126 /**************************************************************************
2127 * DPA_Search [COMCTL32.339]
2129 * Searches a pointer array for a specified pointer
2132 * hdpa [I] handle (pointer) to the pointer array
2133 * pFind [I] pointer to search for
2134 * nStart [I] start index
2135 * pfnCompare [I] pointer to the compare function
2136 * lParam [I] user defined value (3rd parameter of compare function)
2137 * uOptions [I] search options
2140 * Success: index of the pointer in the array.
2144 * Binary search taken from R.Sedgewick "Algorithms in C"!
2145 * Function is NOT tested!
2146 * If something goes wrong, blame HIM not ME! (Eric Kohl)
2150 DPA_Search (const HDPA hdpa
, LPVOID pFind
, INT nStart
,
2151 PFNDPACOMPARE pfnCompare
, LPARAM lParam
, UINT uOptions
)
2153 if (!hdpa
|| !pfnCompare
|| !pFind
)
2156 TRACE("(%p %p %d %p 0x%08lx 0x%08x)\n",
2157 hdpa
, pFind
, nStart
, pfnCompare
, lParam
, uOptions
);
2159 if (uOptions
& DPAS_SORTED
) {
2160 /* array is sorted --> use binary search */
2164 TRACE("binary search\n");
2166 l
= (nStart
== -1) ? 0 : nStart
;
2167 r
= hdpa
->nItemCount
- 1;
2171 n
= (pfnCompare
)(pFind
, lpPtr
[x
], lParam
);
2177 TRACE("-- ret=%d\n", n
);
2182 if (uOptions
& DPAS_INSERTBEFORE
) {
2184 TRACE("-- ret=%d\n", r
);
2188 if (uOptions
& DPAS_INSERTAFTER
) {
2189 TRACE("-- ret=%d\n", l
);
2194 /* array is not sorted --> use linear search */
2198 TRACE("linear search\n");
2200 nIndex
= (nStart
== -1)? 0 : nStart
;
2202 for (; nIndex
< hdpa
->nItemCount
; nIndex
++) {
2203 if ((pfnCompare
)(pFind
, lpPtr
[nIndex
], lParam
) == 0) {
2204 TRACE("-- ret=%d\n", nIndex
);
2210 TRACE("-- not found: ret=-1\n");
2215 /**************************************************************************
2216 * DPA_CreateEx [COMCTL32.340]
2218 * Creates a dynamic pointer array using the specified size and heap.
2221 * nGrow [I] number of items by which the array grows when it is filled
2222 * hHeap [I] handle to the heap where the array is stored
2225 * Success: handle (pointer) to the pointer array.
2229 * The DPA_ functions can be used to create and manipulate arrays of
2234 DPA_CreateEx (INT nGrow
, HANDLE hHeap
)
2238 TRACE("(%d %p)\n", nGrow
, hHeap
);
2241 hdpa
= (HDPA
)HeapAlloc (hHeap
, HEAP_ZERO_MEMORY
, sizeof(*hdpa
));
2243 hdpa
= Alloc (sizeof(*hdpa
));
2246 hdpa
->nGrow
= max(8, nGrow
);
2247 hdpa
->hHeap
= hHeap
? hHeap
: GetProcessHeap();
2248 hdpa
->nMaxCount
= hdpa
->nGrow
* 2;
2249 hdpa
->ptrs
= HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
2250 hdpa
->nMaxCount
* sizeof(LPVOID
));
2253 TRACE("-- %p\n", hdpa
);
2259 /**************************************************************************
2260 * DPA_Create [COMCTL32.328]
2262 * Creates a dynamic pointer array.
2265 * nGrow [I] number of items by which the array grows when it is filled
2268 * Success: handle (pointer) to the pointer array.
2272 * The DPA_ functions can be used to create and manipulate arrays of
2277 DPA_Create (INT nGrow
)
2279 return DPA_CreateEx( nGrow
, 0 );
2283 /**************************************************************************
2284 * Notification functions
2287 typedef struct tagNOTIFYDATA
2295 } NOTIFYDATA
, *LPNOTIFYDATA
;
2298 /**************************************************************************
2299 * DoNotify [Internal]
2303 DoNotify (LPNOTIFYDATA lpNotify
, UINT uCode
, LPNMHDR lpHdr
)
2306 LPNMHDR lpNmh
= NULL
;
2309 TRACE("(%p %p %d %p 0x%08lx)\n",
2310 lpNotify
->hwndFrom
, lpNotify
->hwndTo
, uCode
, lpHdr
,
2311 lpNotify
->dwParam5
);
2313 if (!lpNotify
->hwndTo
)
2316 if (lpNotify
->hwndFrom
== (HWND
)-1) {
2318 idFrom
= lpHdr
->idFrom
;
2321 if (lpNotify
->hwndFrom
)
2322 idFrom
= GetDlgCtrlID (lpNotify
->hwndFrom
);
2324 lpNmh
= (lpHdr
) ? lpHdr
: &nmhdr
;
2326 lpNmh
->hwndFrom
= lpNotify
->hwndFrom
;
2327 lpNmh
->idFrom
= idFrom
;
2328 lpNmh
->code
= uCode
;
2331 return SendMessageA (lpNotify
->hwndTo
, WM_NOTIFY
, idFrom
, (LPARAM
)lpNmh
);
2335 /**************************************************************************
2336 * SendNotify [COMCTL32.341]
2338 * Sends a WM_NOTIFY message to the specified window.
2341 * hwndTo [I] Window to receive the message
2342 * hwndFrom [I] Window that the message is from (see notes)
2343 * uCode [I] Notification code
2344 * lpHdr [I] The NMHDR and any additional information to send or NULL
2347 * Success: return value from notification
2351 * If hwndFrom is -1 then the identifier of the control sending the
2352 * message is taken from the NMHDR structure.
2353 * If hwndFrom is not -1 then lpHdr can be NULL.
2356 LRESULT WINAPI
SendNotify (HWND hwndTo
, HWND hwndFrom
, UINT uCode
, LPNMHDR lpHdr
)
2360 TRACE("(%p %p %d %p)\n",
2361 hwndTo
, hwndFrom
, uCode
, lpHdr
);
2363 notify
.hwndFrom
= hwndFrom
;
2364 notify
.hwndTo
= hwndTo
;
2365 notify
.dwParam5
= 0;
2366 notify
.dwParam6
= 0;
2368 return DoNotify (¬ify
, uCode
, lpHdr
);
2372 /**************************************************************************
2373 * SendNotifyEx [COMCTL32.342]
2375 * Sends a WM_NOTIFY message to the specified window.
2378 * hwndFrom [I] Window to receive the message
2379 * hwndTo [I] Window that the message is from
2380 * uCode [I] Notification code
2381 * lpHdr [I] The NMHDR and any additional information to send or NULL
2382 * dwParam5 [I] Unknown
2385 * Success: return value from notification
2389 * If hwndFrom is -1 then the identifier of the control sending the
2390 * message is taken from the NMHDR structure.
2391 * If hwndFrom is not -1 then lpHdr can be NULL.
2394 LRESULT WINAPI
SendNotifyEx (HWND hwndTo
, HWND hwndFrom
, UINT uCode
,
2395 LPNMHDR lpHdr
, DWORD dwParam5
)
2400 TRACE("(%p %p %d %p 0x%08lx)\n",
2401 hwndFrom
, hwndTo
, uCode
, lpHdr
, dwParam5
);
2403 hwndNotify
= hwndTo
;
2405 if (IsWindow (hwndFrom
)) {
2406 hwndNotify
= GetParent (hwndFrom
);
2412 notify
.hwndFrom
= hwndFrom
;
2413 notify
.hwndTo
= hwndNotify
;
2414 notify
.dwParam5
= dwParam5
;
2415 notify
.dwParam6
= 0;
2417 return DoNotify (¬ify
, uCode
, lpHdr
);
2423 /**************************************************************************
2424 * DPA_EnumCallback [COMCTL32.385]
2426 * Enumerates all items in a dynamic pointer array.
2429 * hdpa [I] handle to the dynamic pointer array
2438 DPA_EnumCallback (HDPA hdpa
, PFNDPAENUMCALLBACK enumProc
, LPVOID lParam
)
2442 TRACE("(%p %p %p)\n", hdpa
, enumProc
, lParam
);
2446 if (hdpa
->nItemCount
<= 0)
2449 for (i
= 0; i
< hdpa
->nItemCount
; i
++) {
2450 if ((enumProc
)(hdpa
->ptrs
[i
], lParam
) == 0)
2458 /**************************************************************************
2459 * DPA_DestroyCallback [COMCTL32.386]
2461 * Enumerates all items in a dynamic pointer array and destroys it.
2464 * hdpa [I] handle to the dynamic pointer array
2473 DPA_DestroyCallback (HDPA hdpa
, PFNDPAENUMCALLBACK enumProc
, LPVOID lParam
)
2475 TRACE("(%p %p %p)\n", hdpa
, enumProc
, lParam
);
2477 DPA_EnumCallback (hdpa
, enumProc
, lParam
);
2482 /**************************************************************************
2483 * DSA_EnumCallback [COMCTL32.387]
2485 * Enumerates all items in a dynamic storage array.
2488 * hdsa [I] handle to the dynamic storage array
2497 DSA_EnumCallback (HDSA hdsa
, PFNDSAENUMCALLBACK enumProc
, LPVOID lParam
)
2501 TRACE("(%p %p %p)\n", hdsa
, enumProc
, lParam
);
2505 if (hdsa
->nItemCount
<= 0)
2508 for (i
= 0; i
< hdsa
->nItemCount
; i
++) {
2509 LPVOID lpItem
= DSA_GetItemPtr (hdsa
, i
);
2510 if ((enumProc
)(lpItem
, lParam
) == 0)
2518 /**************************************************************************
2519 * DSA_DestroyCallback [COMCTL32.388]
2521 * Enumerates all items in a dynamic storage array and destroys it.
2524 * hdsa [I] handle to the dynamic storage array
2533 DSA_DestroyCallback (HDSA hdsa
, PFNDSAENUMCALLBACK enumProc
, LPVOID lParam
)
2535 TRACE("(%p %p %p)\n", hdsa
, enumProc
, lParam
);
2537 DSA_EnumCallback (hdsa
, enumProc
, lParam
);